Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/storage_client/lib/src/storage_bucket_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ class StorageBucketApi {
return (response as Map<String, dynamic>)['message'] as String;
}

/// Purges the CDN cache for an entire bucket.
///
/// Invalidates the CDN cache for every object in the bucket [id]. Maps to
/// `DELETE /cdn/{bucket}` on the storage server.
///
/// When [transformations] is `true`, only the resized/formatted variants are
/// purged, leaving the original cached files intact. When omitted the bucket
/// cache is purged.
///
/// Requires the service-role key and the tenant `purgeCache` feature to be
/// enabled on the storage server.
Future<String> purgeBucketCache(
String id, {
bool transformations = false,
}) async {
var requestUrl = Uri.parse('$url/cdn/$id');
if (transformations) {
requestUrl = requestUrl.replace(
queryParameters: {'transformations': 'true'},
);
}
final response = await storageFetch.delete(
requestUrl.toString(),
{},
options: FetchOptions(headers),
);
return (response as Map<String, dynamic>)['message'] as String;
}

/// Creates a new analytics bucket backed by the Apache Iceberg table format.
///
/// [id] is the unique identifier for the bucket you are creating.
Expand Down
31 changes: 31 additions & 0 deletions packages/storage_client/lib/src/storage_file_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,37 @@ class StorageFileApi {
return fileObjects;
}

/// Purges the CDN cache for a single object.
///
/// Invalidates the CDN cache for the object at [path] (relative to the
/// bucket). There is no wildcard or recursion; pass the exact path of the
/// object to invalidate. For example: `purgeCache('folder/avatar.png')`.
///
/// When [transformations] is `true`, only the resized/formatted variants are
/// purged, leaving the original cached file intact. When omitted the object
/// cache is purged.
///
/// Requires the service-role key and the tenant `purgeCache` feature to be
/// enabled on the storage server.
Future<String> purgeCache(
String path, {
bool transformations = false,
}) async {
final finalPath = _getFinalPath(path);
var requestUrl = Uri.parse('$url/cdn/$finalPath');
if (transformations) {
requestUrl = requestUrl.replace(
queryParameters: {'transformations': 'true'},
);
}
final response = await _storageFetch.delete(
requestUrl.toString(),
{},
options: _fetchOptions,
);
return (response as Map<String, dynamic>)['message'] as String;
}

/// Lists all the files within a bucket.
///
/// [path] The folder path.
Expand Down
60 changes: 60 additions & 0 deletions packages/storage_client/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,35 @@ void main() {
expect(response, 'Deleted');
});

test('should purgeBucketCache issuing DELETE to /cdn/{bucket}', () async {
customHttpClient.response = {'message': 'success'};

final response = await client.purgeBucketCache('test_bucket');

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(
request.url.toString(),
endsWith('/storage/v1/cdn/test_bucket'),
);
expect(request.url.query, isEmpty);
expect(response, 'success');
});

test('should purgeBucketCache with transformations query param', () async {
customHttpClient.response = {'message': 'success'};

final response = await client.purgeBucketCache(
'test_bucket',
transformations: true,
);

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(request.url.queryParameters['transformations'], 'true');
expect(response, 'success');
});

test('should create analytics bucket', () async {
customHttpClient.response = testAnalyticsBucketJson;

Expand Down Expand Up @@ -248,6 +277,37 @@ void main() {
expect(response, 'Move');
});

test('should purgeCache issuing DELETE to /cdn/{bucket}/{path}', () async {
customHttpClient.response = {'message': 'success'};

final response = await client.from('public').purgeCache('folder/a.txt');

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(
request.url.toString(),
endsWith('/storage/v1/cdn/public/folder/a.txt'),
);
expect(request.url.query, isEmpty);
expect(response, 'success');
});

test('should purgeCache with transformations query param', () async {
customHttpClient.response = {'message': 'success'};

final response = await client
.from('public')
.purgeCache('folder/a.txt', transformations: true);

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(
request.url.queryParameters['transformations'],
'true',
);
expect(response, 'success');
});

test('should createSignedUrl file', () async {
customHttpClient.response = {'signedURL': '/signed/url'};

Expand Down
8 changes: 8 additions & 0 deletions sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

features:
# auth — sign in / sign up
auth.sign_in.sign_up: implemented

Check warning on line 25 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_up: marked implemented but has no registered symbols to verify
auth.sign_in.sign_in_with_password: implemented

Check warning on line 26 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_in_with_password: marked implemented but has no registered symbols to verify
auth.sign_in.sign_in_with_otp: implemented

Check warning on line 27 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_in_with_otp: marked implemented but has no registered symbols to verify
auth.sign_in.sign_in_with_oauth:
status: implemented
symbols:
- OAuthProvider
- OAuthProvider.OAuthProvider
auth.sign_in.sign_in_with_id_token: implemented

Check warning on line 33 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_in_with_id_token: marked implemented but has no registered symbols to verify
auth.sign_in.sign_in_with_sso:

Check warning on line 34 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_in_with_sso: marked implemented but has no registered symbols to verify
status: implemented
note: "Exposed as getSSOSignInUrl, which returns Future<String> (the URL) rather than the structured {url} response used by JS."
auth.sign_in.sign_in_with_web3:
Expand All @@ -40,11 +40,11 @@
symbols:
- GoTrueClient.signInWithWeb3
- Web3Chain
auth.sign_in.sign_in_anonymously: implemented

Check warning on line 43 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.sign_in_anonymously: marked implemented but has no registered symbols to verify
auth.sign_in.verify_otp: implemented

Check warning on line 44 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.verify_otp: marked implemented but has no registered symbols to verify
auth.sign_in.exchange_code_for_session: implemented

Check warning on line 45 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.exchange_code_for_session: marked implemented but has no registered symbols to verify
auth.sign_in.resend_confirmation: implemented

Check warning on line 46 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.resend_confirmation: marked implemented but has no registered symbols to verify
auth.sign_in.reauthenticate: implemented

Check warning on line 47 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.sign_in.reauthenticate: marked implemented but has no registered symbols to verify
auth.sign_in.reset_password: implemented

# auth — session & user
Expand Down Expand Up @@ -438,6 +438,14 @@
storage.file_buckets.copy: implemented
storage.file_buckets.copy_cross_bucket: implemented
storage.file_buckets.remove: implemented
storage.file_buckets.purge_cache:
status: implemented
symbols:
- StorageFileApi.purgeCache
storage.file_buckets.purge_bucket_cache:
status: implemented
symbols:
- StorageBucketApi.purgeBucketCache
storage.file_buckets.create_signed_url:
status: implemented
symbols:
Expand Down
Loading