Skip to content

Commit 0445c49

Browse files
committed
fix(storage): improve docs and tests
1 parent d5dbca4 commit 0445c49

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
393393
/**
394394
* Purges the CDN cache for an entire bucket.
395395
*
396-
* Maps to `DELETE /cdn/{bucket}/{path}` on the Storage API. The server
397-
* issues a CDN invalidation for the object and returns `{ message: 'success' }`.
396+
* Maps to `DELETE /cdn/{bucket}` on the Storage API. The server
397+
* issues a CDN invalidation for the bucket and returns `{ message: 'success' }`.
398398
*
399399
* **Requires the `service_role` key.** The underlying endpoint enforces
400400
* `service_role` JWT — calls made with the anon key or a user JWT will be
@@ -404,12 +404,9 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
404404
* have `CDN_PURGE_ENDPOINT_URL` configured and the `purgeCache` tenant
405405
* feature enabled, otherwise the server returns an error.
406406
*
407-
* Operates on a single object path. There is no wildcard or recursion: pass
408-
* the exact path of the object you want invalidated.
409-
*
410407
* @category Storage
411408
* @subcategory File Buckets
412-
* @param path The path (relative to the bucket) of the object to purge, e.g. `folder/avatar.png`.
409+
* @param id The unique identifier of the bucket you would like to purge from cache.
413410
* @param parameters Optional fetch parameters such as an `AbortController` signal.
414411
* @returns Promise with `{ data: { message }, error: null }` on success or `{ data: null, error }` on failure.
415412
*

packages/core/storage-js/test/storageBucketApi.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,22 +569,24 @@ describe('Bucket API Error Handling', () => {
569569
})
570570

571571
it('surfaces server errors via StorageApiError', async () => {
572-
const fetchMock = jest
573-
.fn()
574-
.mockResolvedValue(
575-
new Response(
576-
JSON.stringify({ statusCode: '404', error: 'Not Found', message: 'Object not found' }),
577-
{ status: 404, headers: { 'Content-Type': 'application/json' } }
578-
)
572+
const fetchMock = jest.fn().mockResolvedValue(
573+
new Response(
574+
JSON.stringify({
575+
statusCode: '403',
576+
error: 'Forbidden',
577+
message: 'Feature not enabled',
578+
}),
579+
{ status: 403, headers: { 'Content-Type': 'application/json' } }
579580
)
581+
)
580582
global.fetch = fetchMock
581583

582584
const client = new StorageClient(PURGE_URL, { apikey: 'service-role-token' })
583585
const { data, error } = await client.purgeBucketCache(BUCKET)
584586

585587
expect(data).toBeNull()
586588
expect(error).toBeInstanceOf(StorageApiError)
587-
expect(error?.message).toBe('Object not found')
589+
expect(error?.message).toBe('Feature not enabled')
588590
})
589591

590592
it('forwards the AbortController signal to fetch', async () => {

packages/core/storage-js/test/storageFileApi.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,8 @@ describe('purgeCache', () => {
10581058
.fn()
10591059
.mockResolvedValue(
10601060
new Response(
1061-
JSON.stringify({ statusCode: '404', error: 'Not Found', message: 'Object not found' }),
1062-
{ status: 404, headers: { 'Content-Type': 'application/json' } }
1061+
JSON.stringify({ statusCode: '403', error: 'Forbidden', message: 'Feature not enabled' }),
1062+
{ status: 403, headers: { 'Content-Type': 'application/json' } }
10631063
)
10641064
)
10651065
global.fetch = fetchMock
@@ -1069,7 +1069,7 @@ describe('purgeCache', () => {
10691069

10701070
expect(data).toBeNull()
10711071
expect(error).toBeInstanceOf(StorageApiError)
1072-
expect(error?.message).toBe('Object not found')
1072+
expect(error?.message).toBe('Feature not enabled')
10731073
})
10741074

10751075
it('forwards the AbortController signal to fetch', async () => {

0 commit comments

Comments
 (0)