@supabase/storage-js 2.115.1-canary.0 → 2.116.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,7 @@
51
51
  - **Image Transformations**: On-the-fly image resizing and optimization
52
52
  - **Vector Embeddings**: Store and query high-dimensional embeddings with similarity search
53
53
  - **Analytics Buckets**: Iceberg table-based buckets optimized for analytical queries and data processing
54
+ - **Lifecycle**: Expire previous versions of objects after a number of days
54
55
 
55
56
  ## Quick Start Guide
56
57
 
@@ -229,6 +230,27 @@ await storageClient.analytics.deleteBucket('analytics-data')
229
230
  })
230
231
  ```
231
232
 
233
+ - Manage a bucket's lifecycle policy. Rules expire **previous versions** of objects after a number of days, so versioning needs to be enabled or the policy has nothing to act on. This is Standard buckets only, and the project must have lifecycle enabled.
234
+
235
+ ```js
236
+ // Replaces every existing rule
237
+ const { data, error } = await storageClient.updateBucketLifecycle('test_bucket', {
238
+ rules: [
239
+ {
240
+ id: 'expire-old-versions',
241
+ status: 'Enabled',
242
+ filter: {},
243
+ noncurrentVersionExpiration: { noncurrentDays: 30 },
244
+ },
245
+ ],
246
+ })
247
+
248
+ // Fails with NoSuchLifecycleConfiguration when the bucket has no policy
249
+ const { data: config, error: configError } = await storageClient.getBucketLifecycle('test_bucket')
250
+
251
+ await storageClient.deleteBucketLifecycle('test_bucket')
252
+ ```
253
+
232
254
  #### Handling Files
233
255
 
234
256
  - Upload a file to an existing bucket:
package/dist/index.cjs CHANGED
@@ -1629,7 +1629,7 @@ var StorageFileApi = class extends BaseApiClient {
1629
1629
 
1630
1630
  //#endregion
1631
1631
  //#region src/lib/version.ts
1632
- const version = "2.115.1-canary.0";
1632
+ const version = "2.116.0-canary.1";
1633
1633
 
1634
1634
  //#endregion
1635
1635
  //#region src/lib/constants.ts
@@ -1932,6 +1932,153 @@ var StorageBucketApi = class extends BaseApiClient {
1932
1932
  });
1933
1933
  }
1934
1934
  /**
1935
+ * Returns the lifecycle policy stored on a bucket.
1936
+ *
1937
+ * Fails with `NoSuchLifecycleConfiguration` when the bucket has no policy.
1938
+ *
1939
+ * These rules expire previous versions of objects, not the current one.
1940
+ * Turn versioning on or there is nothing for the policy to act on.
1941
+ * Standard buckets only. Returns `FeatureNotEnabled` if lifecycle is off
1942
+ * for the project.
1943
+ *
1944
+ * @category Storage
1945
+ * @subcategory File Buckets
1946
+ * @param id The unique identifier of the bucket.
1947
+ * @returns Promise with the lifecycle configuration or error
1948
+ *
1949
+ * @example Get lifecycle configuration
1950
+ * ```js
1951
+ * const { data, error } = await supabase
1952
+ * .storage
1953
+ * .getBucketLifecycle('avatars')
1954
+ * ```
1955
+ *
1956
+ * Response:
1957
+ * ```json
1958
+ * {
1959
+ * "data": {
1960
+ * "rules": [
1961
+ * {
1962
+ * "id": "expire-history",
1963
+ * "status": "Enabled",
1964
+ * "filter": {},
1965
+ * "noncurrentVersionExpiration": {
1966
+ * "noncurrentDays": 30,
1967
+ * "newerNoncurrentVersions": 2
1968
+ * }
1969
+ * }
1970
+ * ]
1971
+ * },
1972
+ * "error": null
1973
+ * }
1974
+ * ```
1975
+ *
1976
+ * @remarks
1977
+ * - RLS policy permissions required:
1978
+ * - `buckets` table permissions: `select`
1979
+ * - `objects` table permissions: none
1980
+ * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
1981
+ */
1982
+ async getBucketLifecycle(id) {
1983
+ var _this7 = this;
1984
+ return _this7.handleOperation(async () => {
1985
+ return await get(_this7.fetch, _this7.bucketLifecycleUrl(id), { headers: _this7.headers });
1986
+ });
1987
+ }
1988
+ /**
1989
+ * Replaces the lifecycle policy on a bucket.
1990
+ *
1991
+ * The `rules` array you send is the whole policy. Anything previously stored
1992
+ * is overwritten. Send at least one rule. Call {@link deleteBucketLifecycle}
1993
+ * to remove the policy.
1994
+ *
1995
+ * Each rule currently supports only `noncurrentVersionExpiration`. Set
1996
+ * `filter` to `{}`. Prefix filters, tag filters, and current-object
1997
+ * expiration are rejected. Rule IDs must be unique. Omit `id` and the
1998
+ * server generates one.
1999
+ *
2000
+ * Standard buckets only. Returns `FeatureNotEnabled` if lifecycle is off
2001
+ * for the project.
2002
+ *
2003
+ * @category Storage
2004
+ * @subcategory File Buckets
2005
+ * @param id The unique identifier of the bucket.
2006
+ * @param configuration The full lifecycle configuration to store.
2007
+ * @returns Promise with the stored configuration or error
2008
+ *
2009
+ * @example Replace lifecycle configuration
2010
+ * ```js
2011
+ * const { data, error } = await supabase
2012
+ * .storage
2013
+ * .updateBucketLifecycle('avatars', {
2014
+ * rules: [
2015
+ * {
2016
+ * id: 'expire-history',
2017
+ * status: 'Enabled',
2018
+ * filter: {},
2019
+ * noncurrentVersionExpiration: {
2020
+ * noncurrentDays: 30,
2021
+ * newerNoncurrentVersions: 2,
2022
+ * },
2023
+ * },
2024
+ * ],
2025
+ * })
2026
+ * ```
2027
+ *
2028
+ * @remarks
2029
+ * - RLS policy permissions required:
2030
+ * - `buckets` table permissions: `select` and `update`
2031
+ * - `objects` table permissions: none
2032
+ * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
2033
+ */
2034
+ async updateBucketLifecycle(id, configuration) {
2035
+ var _this8 = this;
2036
+ return _this8.handleOperation(async () => {
2037
+ return await put(_this8.fetch, _this8.bucketLifecycleUrl(id), configuration, { headers: _this8.headers });
2038
+ });
2039
+ }
2040
+ /**
2041
+ * Removes the lifecycle policy from a bucket.
2042
+ *
2043
+ * Safe to call when no policy is stored. The response is still success.
2044
+ * Standard buckets only. Returns `FeatureNotEnabled` if lifecycle is off
2045
+ * for the project.
2046
+ *
2047
+ * @category Storage
2048
+ * @subcategory File Buckets
2049
+ * @param id The unique identifier of the bucket.
2050
+ * @returns Promise with success message or error
2051
+ *
2052
+ * @example Delete lifecycle configuration
2053
+ * ```js
2054
+ * const { data, error } = await supabase
2055
+ * .storage
2056
+ * .deleteBucketLifecycle('avatars')
2057
+ * ```
2058
+ *
2059
+ * Response:
2060
+ * ```json
2061
+ * {
2062
+ * "data": {
2063
+ * "message": "Successfully deleted"
2064
+ * },
2065
+ * "error": null
2066
+ * }
2067
+ * ```
2068
+ *
2069
+ * @remarks
2070
+ * - RLS policy permissions required:
2071
+ * - `buckets` table permissions: `select` and `update`
2072
+ * - `objects` table permissions: none
2073
+ * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
2074
+ */
2075
+ async deleteBucketLifecycle(id) {
2076
+ var _this9 = this;
2077
+ return _this9.handleOperation(async () => {
2078
+ return await remove(_this9.fetch, _this9.bucketLifecycleUrl(id), {}, { headers: _this9.headers });
2079
+ });
2080
+ }
2081
+ /**
1935
2082
  * Purges the CDN cache for an entire bucket.
1936
2083
  *
1937
2084
  * Maps to `DELETE /cdn/{bucket}` on the Storage API. The server
@@ -1968,14 +2115,17 @@ var StorageBucketApi = class extends BaseApiClient {
1968
2115
  * ```
1969
2116
  */
1970
2117
  async purgeBucketCache(id, options, parameters) {
1971
- var _this7 = this;
1972
- return _this7.handleOperation(async () => {
2118
+ var _this10 = this;
2119
+ return _this10.handleOperation(async () => {
1973
2120
  const query = new URLSearchParams();
1974
2121
  if (options === null || options === void 0 ? void 0 : options.transformations) query.set("transformations", "true");
1975
2122
  const queryString = query.toString();
1976
- return await remove(_this7.fetch, `${_this7.url}/cdn/${encodeStoragePath(id)}${queryString ? `?${queryString}` : ""}`, {}, { headers: _this7.headers }, parameters);
2123
+ return await remove(_this10.fetch, `${_this10.url}/cdn/${encodeStoragePath(id)}${queryString ? `?${queryString}` : ""}`, {}, { headers: _this10.headers }, parameters);
1977
2124
  });
1978
2125
  }
2126
+ bucketLifecycleUrl(id) {
2127
+ return `${this.url}/bucket/${encodeStoragePath(id)}/lifecycle`;
2128
+ }
1979
2129
  listBucketOptionsToQueryString(options) {
1980
2130
  const params = {};
1981
2131
  if (options) {