Skip to content

Commit ad5b553

Browse files
authored
docs(storage): overrides and rendering issues (#1896)
1 parent 33c0b1e commit ad5b553

File tree

5 files changed

+145
-32
lines changed

5 files changed

+145
-32
lines changed

packages/core/storage-js/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ If you're already using `@supabase/supabase-js`, access storage through the clie
6767
```js
6868
import { createClient } from '@supabase/supabase-js'
6969

70-
const supabase = createClient('https://<project_ref>.supabase.co', '<your-anon-key>')
70+
// Use publishable/anon key for frontend applications
71+
const supabase = createClient('https://<project_ref>.supabase.co', '<your-publishable-key>')
7172

7273
// Access storage
7374
const storage = supabase.storage
@@ -80,13 +81,13 @@ const analyticsBucket = storage.analytics // Analytics API
8081

8182
#### Option 2: Standalone StorageClient
8283

83-
For applications that only need storage functionality:
84+
For backend applications or when you need to bypass Row Level Security:
8485

8586
```js
8687
import { StorageClient } from '@supabase/storage-js'
8788

8889
const STORAGE_URL = 'https://<project_ref>.supabase.co/storage/v1'
89-
const SERVICE_KEY = '<service_role>' //! service key, not anon key
90+
const SERVICE_KEY = '<your-secret-key>' // Use secret key for backend operations
9091

9192
const storageClient = new StorageClient(STORAGE_URL, {
9293
apikey: SERVICE_KEY,
@@ -101,8 +102,10 @@ const analyticsBucket = storageClient.analytics // Analytics API
101102

102103
> **When to use each approach:**
103104
>
104-
> - Use `supabase.storage` when working with other Supabase features (auth, database, etc.)
105-
> - Use `new StorageClient()` for storage-only applications or when you need fine-grained control
105+
> - Use `supabase.storage` when working with other Supabase features (auth, database, etc.) in frontend applications
106+
> - Use `new StorageClient()` for backend applications, Edge Functions, or when you need to bypass RLS policies
107+
108+
> **Note:** Refer to the [Storage Access Control guide](https://supabase.com/docs/guides/storage/access-control) for detailed information on creating RLS policies.
106109
107110
### Understanding Bucket Types
108111

@@ -340,7 +343,7 @@ You can access analytics functionality through the `analytics` property on your
340343
```typescript
341344
import { createClient } from '@supabase/supabase-js'
342345

343-
const supabase = createClient('https://your-project.supabase.co', 'your-anon-key')
346+
const supabase = createClient('https://your-project.supabase.co', 'your-publishable-key')
344347

345348
// Access analytics operations
346349
const analytics = supabase.storage.analytics
@@ -646,7 +649,7 @@ If you're using the full Supabase client:
646649
```typescript
647650
import { createClient } from '@supabase/supabase-js'
648651

649-
const supabase = createClient('https://your-project.supabase.co', 'your-anon-key')
652+
const supabase = createClient('https://your-project.supabase.co', 'your-publishable-key')
650653

651654
// Access vector operations through storage
652655
const vectors = supabase.storage.vectors

packages/core/storage-js/src/lib/vectors/StorageVectorsClient.ts

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import VectorDataApi from './VectorDataApi'
33
import { Fetch } from './fetch'
44
import VectorBucketApi from './VectorBucketApi'
55
import {
6+
ApiResponse,
67
DeleteVectorsOptions,
78
GetVectorsOptions,
89
ListIndexesOptions,
910
ListVectorsOptions,
11+
ListVectorBucketsOptions,
12+
ListVectorBucketsResponse,
1013
PutVectorsOptions,
1114
QueryVectorsOptions,
15+
VectorBucket,
1216
} from './types'
1317

1418
/**
@@ -116,6 +120,112 @@ export class StorageVectorsClient extends VectorBucketApi {
116120
from(vectorBucketName: string): VectorBucketScope {
117121
return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch)
118122
}
123+
124+
/**
125+
*
126+
* @alpha
127+
*
128+
* Creates a new vector bucket
129+
* Vector buckets are containers for vector indexes and their data
130+
*
131+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
132+
*
133+
* @category Vector Buckets
134+
* @param vectorBucketName - Unique name for the vector bucket
135+
* @returns Promise with empty response on success or error
136+
*
137+
* @example
138+
* ```typescript
139+
* const { data, error } = await supabase
140+
* .storage
141+
* .vectors
142+
* .createBucket('embeddings-prod')
143+
* ```
144+
*/
145+
async createBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
146+
return super.createBucket(vectorBucketName)
147+
}
148+
149+
/**
150+
*
151+
* @alpha
152+
*
153+
* Retrieves metadata for a specific vector bucket
154+
*
155+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
156+
*
157+
* @category Vector Buckets
158+
* @param vectorBucketName - Name of the vector bucket
159+
* @returns Promise with bucket metadata or error
160+
*
161+
* @example
162+
* ```typescript
163+
* const { data, error } = await supabase
164+
* .storage
165+
* .vectors
166+
* .getBucket('embeddings-prod')
167+
*
168+
* console.log('Bucket created:', data?.vectorBucket.creationTime)
169+
* ```
170+
*/
171+
async getBucket(vectorBucketName: string): Promise<ApiResponse<{ vectorBucket: VectorBucket }>> {
172+
return super.getBucket(vectorBucketName)
173+
}
174+
175+
/**
176+
*
177+
* @alpha
178+
*
179+
* Lists all vector buckets with optional filtering and pagination
180+
*
181+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
182+
*
183+
* @category Vector Buckets
184+
* @param options - Optional filters (prefix, maxResults, nextToken)
185+
* @returns Promise with list of buckets or error
186+
*
187+
* @example
188+
* ```typescript
189+
* const { data, error } = await supabase
190+
* .storage
191+
* .vectors
192+
* .listBuckets({ prefix: 'embeddings-' })
193+
*
194+
* data?.vectorBuckets.forEach(bucket => {
195+
* console.log(bucket.vectorBucketName)
196+
* })
197+
* ```
198+
*/
199+
async listBuckets(
200+
options: ListVectorBucketsOptions = {}
201+
): Promise<ApiResponse<ListVectorBucketsResponse>> {
202+
return super.listBuckets(options)
203+
}
204+
205+
/**
206+
*
207+
* @alpha
208+
*
209+
* Deletes a vector bucket (bucket must be empty)
210+
* All indexes must be deleted before deleting the bucket
211+
*
212+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
213+
*
214+
* @category Vector Buckets
215+
* @param vectorBucketName - Name of the vector bucket to delete
216+
* @returns Promise with empty response on success or error
217+
*
218+
* @example
219+
* ```typescript
220+
* const { data, error } = await supabase
221+
* .storage
222+
* .vectors
223+
* .deleteBucket('embeddings-old')
224+
* ```
225+
*/
226+
async deleteBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
227+
return super.deleteBucket(vectorBucketName)
228+
}
119229
}
120230

121231
/**
@@ -198,7 +308,7 @@ export class VectorBucketScope extends VectorIndexApi {
198308
*
199309
* @category Vector Buckets
200310
* @param options - Listing options (vectorBucketName is automatically set)
201-
* @returns Promise with list of indexes or error
311+
* @returns Promise with response containing indexes array and pagination token or error
202312
*
203313
* @example
204314
* ```typescript
@@ -387,7 +497,7 @@ export class VectorIndexScope extends VectorDataApi {
387497
*
388498
* @category Vector Buckets
389499
* @param options - Vector retrieval options (bucket and index names automatically set)
390-
* @returns Promise with array of vectors or error
500+
* @returns Promise with response containing vectors array or error
391501
*
392502
* @example
393503
* ```typescript
@@ -417,7 +527,7 @@ export class VectorIndexScope extends VectorDataApi {
417527
*
418528
* @category Vector Buckets
419529
* @param options - Listing options (bucket and index names automatically set)
420-
* @returns Promise with array of vectors and pagination token
530+
* @returns Promise with response containing vectors array and pagination token or error
421531
*
422532
* @example
423533
* ```typescript
@@ -449,7 +559,7 @@ export class VectorIndexScope extends VectorDataApi {
449559
*
450560
* @category Vector Buckets
451561
* @param options - Query options (bucket and index names automatically set)
452-
* @returns Promise with array of similar vectors ordered by distance
562+
* @returns Promise with response containing matches array of similar vectors ordered by distance or error
453563
*
454564
* @example
455565
* ```typescript

packages/core/storage-js/src/packages/StorageAnalyticsClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class StorageAnalyticsClient {
6363
*
6464
* @category Analytics Buckets
6565
* @param name A unique name for the bucket you are creating
66-
* @returns Promise with newly created bucket name or error
66+
* @returns Promise with response containing newly created analytics bucket or error
6767
*
6868
* @example Create analytics bucket
6969
* ```js
@@ -124,10 +124,10 @@ export default class StorageAnalyticsClient {
124124
* @param options Query parameters for listing buckets
125125
* @param options.limit Maximum number of buckets to return
126126
* @param options.offset Number of buckets to skip
127-
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
127+
* @param options.sortColumn Column to sort by ('name', 'created_at', 'updated_at')
128128
* @param options.sortOrder Sort order ('asc' or 'desc')
129129
* @param options.search Search term to filter bucket names
130-
* @returns Promise with list of analytics buckets or error
130+
* @returns Promise with response containing array of analytics buckets or error
131131
*
132132
* @example List analytics buckets
133133
* ```js
@@ -161,7 +161,7 @@ export default class StorageAnalyticsClient {
161161
async listBuckets(options?: {
162162
limit?: number
163163
offset?: number
164-
sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
164+
sortColumn?: 'name' | 'created_at' | 'updated_at'
165165
sortOrder?: 'asc' | 'desc'
166166
search?: string
167167
}): Promise<
@@ -212,7 +212,7 @@ export default class StorageAnalyticsClient {
212212
*
213213
* @category Analytics Buckets
214214
* @param bucketName The unique identifier of the bucket you would like to delete
215-
* @returns Promise with success message or error
215+
* @returns Promise with response containing success message or error
216216
*
217217
* @example Delete analytics bucket
218218
* ```js

packages/core/storage-js/src/packages/StorageBucketApi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class StorageBucketApi {
5353
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
5454
* @param options.sortOrder Sort order ('asc' or 'desc')
5555
* @param options.search Search term to filter bucket names
56-
* @returns Promise with list of buckets or error
56+
* @returns Promise with response containing array of buckets or error
5757
*
5858
* @example List buckets
5959
* ```js
@@ -108,7 +108,7 @@ export default class StorageBucketApi {
108108
*
109109
* @category File Buckets
110110
* @param id The unique identifier of the bucket you would like to retrieve.
111-
* @returns Promise with bucket details or error
111+
* @returns Promise with response containing bucket details or error
112112
*
113113
* @example Get bucket
114114
* ```js
@@ -175,7 +175,7 @@ export default class StorageBucketApi {
175175
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
176176
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
177177
* - default bucket type is `STANDARD`
178-
* @returns Promise with newly created bucket id or error
178+
* @returns Promise with response containing newly created bucket name or error
179179
*
180180
* @example Create bucket
181181
* ```js
@@ -257,7 +257,7 @@ export default class StorageBucketApi {
257257
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
258258
* The default value is null, which allows files with all mime types to be uploaded.
259259
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
260-
* @returns Promise with success message or error
260+
* @returns Promise with response containing success message or error
261261
*
262262
* @example Update bucket
263263
* ```js

0 commit comments

Comments
 (0)