@supabase/storage-js 2.71.2-canary.7 → 2.72.1-canary.2
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 +250 -0
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +7 -2
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +7 -2
- package/dist/module/lib/version.js.map +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +2 -2
- package/src/lib/version.ts +7 -2
package/README.md
CHANGED
|
@@ -156,6 +156,256 @@ const storageClient = new StorageClient(STORAGE_URL, {
|
|
|
156
156
|
const { data, error } = await storageClient.from('public-bucket').getPublicUrl('path/to/file')
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
This package is part of the [Supabase JavaScript monorepo](https://github.com/supabase/supabase-js-libs). To work on this package:
|
|
162
|
+
|
|
163
|
+
### Building
|
|
164
|
+
|
|
165
|
+
#### Build Scripts Overview
|
|
166
|
+
|
|
167
|
+
The storage-js package uses multiple build scripts to generate different module formats for various JavaScript environments:
|
|
168
|
+
|
|
169
|
+
| Script | Description | Output |
|
|
170
|
+
| -------------- | --------------------------- | --------------------------------------------------------------- |
|
|
171
|
+
| `build` | **Complete build pipeline** | Runs all build steps in sequence |
|
|
172
|
+
| `build:main` | **CommonJS build** | `dist/main/` - Node.js compatible CommonJS modules |
|
|
173
|
+
| `build:module` | **ES Modules build** | `dist/module/` - Modern ES6 modules with TypeScript definitions |
|
|
174
|
+
| `build:umd` | **UMD build** | `dist/umd/` - Universal Module Definition for browsers/CDN |
|
|
175
|
+
| `clean` | **Clean build artifacts** | Removes `dist/` and `docs/v2/` directories |
|
|
176
|
+
| `format` | **Format code** | Runs Prettier on all TypeScript files |
|
|
177
|
+
|
|
178
|
+
#### Running Builds
|
|
179
|
+
|
|
180
|
+
##### Complete Build (Recommended)
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# From the monorepo root
|
|
184
|
+
npx nx build storage-js
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This command executes the full build pipeline:
|
|
188
|
+
|
|
189
|
+
1. **Cleans** - Removes any existing build artifacts
|
|
190
|
+
2. **Formats** - Ensures consistent code formatting
|
|
191
|
+
3. **Builds CommonJS** - For Node.js environments (`dist/main/`)
|
|
192
|
+
4. **Builds ES Modules** - For modern bundlers (`dist/module/`)
|
|
193
|
+
5. **Builds UMD** - For browser script tags (`dist/umd/`)
|
|
194
|
+
|
|
195
|
+
##### Development Build with Watch Mode
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Continuously rebuild on file changes (from monorepo root)
|
|
199
|
+
npx nx build storage-js --watch
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
##### Individual Build Targets
|
|
203
|
+
|
|
204
|
+
For specific build outputs during development:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Build CommonJS only (Node.js)
|
|
208
|
+
npx nx build:main storage-js
|
|
209
|
+
|
|
210
|
+
# Build ES Modules only (Modern bundlers)
|
|
211
|
+
npx nx build:module storage-js
|
|
212
|
+
|
|
213
|
+
# Build UMD only (Browser/CDN)
|
|
214
|
+
npx nx build:umd storage-js
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
##### Other Useful Commands
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Clean build artifacts
|
|
221
|
+
npx nx clean storage-js
|
|
222
|
+
|
|
223
|
+
# Format code
|
|
224
|
+
npx nx format storage-js
|
|
225
|
+
|
|
226
|
+
# Type checking
|
|
227
|
+
npx nx typecheck storage-js
|
|
228
|
+
|
|
229
|
+
# Generate documentation
|
|
230
|
+
npx nx docs storage-js
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Build Outputs Explained
|
|
234
|
+
|
|
235
|
+
##### CommonJS (`dist/main/`)
|
|
236
|
+
|
|
237
|
+
- **Used by:** Node.js applications, older build tools
|
|
238
|
+
- **Entry point:** `dist/main/index.js`
|
|
239
|
+
- **Module format:** `require()` and `module.exports`
|
|
240
|
+
- **TypeScript definitions:** Included
|
|
241
|
+
|
|
242
|
+
##### ES Modules (`dist/module/`)
|
|
243
|
+
|
|
244
|
+
- **Used by:** Modern bundlers (Webpack, Rollup, Vite)
|
|
245
|
+
- **Entry point:** `dist/module/index.js`
|
|
246
|
+
- **Module format:** `import` and `export`
|
|
247
|
+
- **TypeScript definitions:** `dist/module/index.d.ts`
|
|
248
|
+
- **Benefits:** Tree-shaking, better static analysis
|
|
249
|
+
|
|
250
|
+
##### UMD (`dist/umd/`)
|
|
251
|
+
|
|
252
|
+
- **Used by:** Browser `<script>` tags, CDNs
|
|
253
|
+
- **Entry point:** `dist/umd/supabase.js`
|
|
254
|
+
- **Global variable:** `window.supabase`
|
|
255
|
+
- **Size:** Larger (includes all dependencies)
|
|
256
|
+
- **Usage example:**
|
|
257
|
+
```html
|
|
258
|
+
<script src="https://unpkg.com/@supabase/storage-js/dist/umd/supabase.js"></script>
|
|
259
|
+
<script>
|
|
260
|
+
const { StorageClient } = window.supabase
|
|
261
|
+
</script>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Package Exports
|
|
265
|
+
|
|
266
|
+
The package.json exports are configured to provide the right format for each environment:
|
|
267
|
+
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"main": "dist/main/index.js",
|
|
271
|
+
"module": "dist/module/index.js",
|
|
272
|
+
"types": "dist/module/index.d.ts",
|
|
273
|
+
"jsdelivr": "dist/umd/supabase.js",
|
|
274
|
+
"unpkg": "dist/umd/supabase.js"
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- **main** → Node.js environments (CommonJS format)
|
|
279
|
+
- **module** → Modern bundlers like Webpack, Vite, Rollup (ES Modules)
|
|
280
|
+
- **types** → TypeScript type definitions
|
|
281
|
+
- **jsdelivr/unpkg** → CDN usage via `<script>` tags (UMD format)
|
|
282
|
+
|
|
283
|
+
### Testing
|
|
284
|
+
|
|
285
|
+
**Important:** The storage-js tests require a local test infrastructure running in Docker. This is **NOT** the same as a regular Supabase instance - it's a specialized test setup with its own storage API, database, and Kong gateway.
|
|
286
|
+
|
|
287
|
+
#### Prerequisites
|
|
288
|
+
|
|
289
|
+
1. **Docker** must be installed and running
|
|
290
|
+
2. **Port availability** - The following ports must be free:
|
|
291
|
+
- 5432 (PostgreSQL database)
|
|
292
|
+
- 5050 (Storage API - sometimes 5000 conflicts macOS AirPlay conflict)
|
|
293
|
+
- 8000 (Kong API Gateway)
|
|
294
|
+
- 50020 (imgproxy for image transformations)
|
|
295
|
+
|
|
296
|
+
**Note:** If port 5000 conflicts with macOS AirPlay Receiver, the docker-compose.yml has been configured to use port 5050 instead.
|
|
297
|
+
|
|
298
|
+
#### Test Scripts Overview
|
|
299
|
+
|
|
300
|
+
| Script | Description | What it does |
|
|
301
|
+
| -------------- | --------------------------------- | ----------------------------------------------------------------- |
|
|
302
|
+
| `test:storage` | **Complete test workflow** | Runs the full test cycle: clean → start infra → run tests → clean |
|
|
303
|
+
| `test:suite` | **Jest tests only** | Runs Jest tests with coverage (requires infra to be running) |
|
|
304
|
+
| `test:infra` | **Start test infrastructure** | Starts Docker containers for storage API, database, and Kong |
|
|
305
|
+
| `test:clean` | **Stop and clean infrastructure** | Stops all Docker containers and removes them |
|
|
306
|
+
|
|
307
|
+
#### Running Tests
|
|
308
|
+
|
|
309
|
+
##### Option 1: Complete Test Run (Recommended)
|
|
310
|
+
|
|
311
|
+
This handles everything automatically - starting infrastructure, running tests, and cleaning up:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# From monorepo root
|
|
315
|
+
npx nx test:storage storage-js
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
This command will:
|
|
319
|
+
|
|
320
|
+
1. Stop any existing test containers
|
|
321
|
+
2. Build and start fresh test infrastructure
|
|
322
|
+
3. Wait for services to be ready
|
|
323
|
+
4. Run all Jest tests with coverage
|
|
324
|
+
5. Clean up all containers after tests complete
|
|
325
|
+
|
|
326
|
+
##### Option 2: Manual Infrastructure Management
|
|
327
|
+
|
|
328
|
+
Useful for development when you want to run tests multiple times without restarting Docker:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Step 1: Start the test infrastructure
|
|
332
|
+
# From root
|
|
333
|
+
npx nx test:infra storage-js
|
|
334
|
+
# This starts: PostgreSQL, Storage API, Kong Gateway, and imgproxy
|
|
335
|
+
|
|
336
|
+
# Step 2: Run tests (can run multiple times)
|
|
337
|
+
npx nx test:suite storage-js
|
|
338
|
+
|
|
339
|
+
# Step 3: When done, clean up the infrastructure
|
|
340
|
+
npx nx test:clean storage-js
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
##### Option 3: Development Mode
|
|
344
|
+
|
|
345
|
+
For actively developing and debugging tests:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
# Start infrastructure once (from root)
|
|
349
|
+
npx nx test:infra storage-js
|
|
350
|
+
|
|
351
|
+
# Run tests in watch mode
|
|
352
|
+
npx nx test:suite storage-js --watch
|
|
353
|
+
|
|
354
|
+
# Clean up when done
|
|
355
|
+
npx nx test:clean storage-js
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Test Infrastructure Details
|
|
359
|
+
|
|
360
|
+
The test infrastructure (`infra/docker-compose.yml`) includes:
|
|
361
|
+
|
|
362
|
+
- **PostgreSQL Database** (port 5432)
|
|
363
|
+
- Initialized with storage schema and test data
|
|
364
|
+
- Contains bucket configurations and permissions
|
|
365
|
+
|
|
366
|
+
- **Storage API** (port 5050, internal 5000)
|
|
367
|
+
- Supabase Storage service for handling file operations
|
|
368
|
+
- Configured with test authentication keys
|
|
369
|
+
|
|
370
|
+
- **Kong Gateway** (port 8000)
|
|
371
|
+
- API gateway that routes requests to storage service
|
|
372
|
+
- Handles authentication and CORS
|
|
373
|
+
|
|
374
|
+
- **imgproxy** (port 50020)
|
|
375
|
+
- Image transformation service for on-the-fly image processing
|
|
376
|
+
|
|
377
|
+
#### Common Issues and Solutions
|
|
378
|
+
|
|
379
|
+
| Issue | Solution |
|
|
380
|
+
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
381
|
+
| Port 5000 already in use | macOS AirPlay uses this port. Either disable AirPlay Receiver in System Settings or use the modified docker-compose.yml with port 5050 |
|
|
382
|
+
| Port 5432 already in use | Another PostgreSQL instance is running. Stop it or modify the port in docker-compose.yml |
|
|
383
|
+
| "request failed, reason:" errors | Infrastructure isn't running. Run `npx nx test:infra storage-js` first |
|
|
384
|
+
| Tests fail with connection errors | Ensure Docker is running and healthy |
|
|
385
|
+
| "Container name already exists" | Run `npx nx test:clean storage-js` to remove existing containers |
|
|
386
|
+
|
|
387
|
+
#### Understanding Test Failures
|
|
388
|
+
|
|
389
|
+
- **StorageUnknownError with "request failed"**: Infrastructure not running
|
|
390
|
+
- **Port binding errors**: Ports are already in use by other services
|
|
391
|
+
- **Snapshot failures**: Expected test data has changed - review and update snapshots if needed
|
|
392
|
+
|
|
393
|
+
#### What About Supabase CLI?
|
|
394
|
+
|
|
395
|
+
**No**, you don't need `supabase start` or a regular Supabase instance for these tests. The storage-js tests use their own specialized Docker setup that's lighter and focused specifically on testing the storage client library. This test infrastructure:
|
|
396
|
+
|
|
397
|
+
- Is completely independent from any Supabase CLI projects
|
|
398
|
+
- Uses fixed test authentication keys
|
|
399
|
+
- Has predictable test data and bucket configurations
|
|
400
|
+
- Runs faster than a full Supabase stack
|
|
401
|
+
- Doesn't interfere with your local Supabase development projects
|
|
402
|
+
|
|
403
|
+
### Contributing
|
|
404
|
+
|
|
405
|
+
We welcome contributions! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details on how to get started.
|
|
406
|
+
|
|
407
|
+
For major changes or if you're unsure about something, please open an issue first to discuss your proposed changes.
|
|
408
|
+
|
|
159
409
|
## Sponsors
|
|
160
410
|
|
|
161
411
|
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "2.72.1-canary.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
|
package/dist/main/lib/version.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.version = void 0;
|
|
4
|
-
// Generated by
|
|
5
|
-
|
|
4
|
+
// Generated automatically during releases by scripts/update-version-files.js
|
|
5
|
+
// This file provides runtime access to the package version for:
|
|
6
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
7
|
+
// - Debugging and support (identifying which version is running)
|
|
8
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
9
|
+
// - Ensuring build artifacts match the published package version
|
|
10
|
+
exports.version = '2.72.1-canary.2';
|
|
6
11
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACpD,QAAA,OAAO,GAAG,iBAAiB,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "2.72.1-canary.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
// Generated by
|
|
2
|
-
|
|
1
|
+
// Generated automatically during releases by scripts/update-version-files.js
|
|
2
|
+
// This file provides runtime access to the package version for:
|
|
3
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
4
|
+
// - Debugging and support (identifying which version is running)
|
|
5
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
|
+
// - Ensuring build artifacts match the published package version
|
|
7
|
+
export const version = '2.72.1-canary.2';
|
|
3
8
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA"}
|
package/dist/umd/supabase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,()=>(()=>{var t={97:t=>{function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=97,t.exports=e},251:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_HEADERS=void 0;const o=r(822);e.DEFAULT_HEADERS={"X-Client-Info":`storage-js/${o.version}`}},411:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},442:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.get=function(t,e,r,n){return o(this,void 0,void 0,function*(){return c(t,"GET",e,r,n)})},e.post=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"POST",e,n,i,r)})},e.put=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"PUT",e,n,i,r)})},e.head=function(t,e,r,n){return o(this,void 0,void 0,function*(){return c(t,"HEAD",e,Object.assign(Object.assign({},r),{noResolveJson:!0}),n)})},e.remove=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"DELETE",e,n,i,r)})};const n=r(607),i=r(819),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t),a=(t,e,r)=>o(void 0,void 0,void 0,function*(){const o=yield(0,i.resolveResponse)();t instanceof o&&!(null==r?void 0:r.noResolveJson)?t.json().then(r=>{const o=t.status||500,i=(null==r?void 0:r.statusCode)||o+"";e(new n.StorageApiError(s(r),o,i))}).catch(t=>{e(new n.StorageUnknownError(s(t),t))}):e(new n.StorageUnknownError(s(t),t))}),u=(t,e,r,o)=>{const n={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"!==t&&o?((0,i.isPlainObject)(o)?(n.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),n.body=JSON.stringify(o)):n.body=o,(null==e?void 0:e.duplex)&&(n.duplex=e.duplex),Object.assign(Object.assign({},n),r)):n};function c(t,e,r,n,i,s){return o(this,void 0,void 0,function*(){return new Promise((o,c)=>{t(r,u(e,n,i,s)).then(t=>{if(!t.ok)throw t;return(null==n?void 0:n.noResolveJson)?t:t.json()}).then(t=>o(t)).catch(t=>a(t,c,n))})})}},456:function(t,e,r){"use strict";var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageClient=void 0;const n=o(r(781)),i=o(r(485));class s extends i.default{constructor(t,e={},r,o){super(t,e,r,o)}from(t){return new n.default(this.url,this.headers,t,this.fetch)}}e.StorageClient=s},485:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const n=r(251),i=r(607),s=r(442),a=r(819);e.default=class{constructor(t,e={},r,o){const i=new URL(t);(null==o?void 0:o.useNewHostname)&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes("storage.supabase.")&&(i.hostname=i.hostname.replace("supabase.","storage.supabase.")),this.url=i.href,this.headers=Object.assign(Object.assign({},n.DEFAULT_HEADERS),e),this.fetch=(0,a.resolveFetch)(r)}listBuckets(){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}getBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}createBucket(t){return o(this,arguments,void 0,function*(t,e={public:!1}){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket`,{id:t,name:t,type:e.type,public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}updateBucket(t,e){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.put)(this.fetch,`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}emptyBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}deleteBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.remove)(this.fetch,`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}}},607:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.StorageUnknownError=e.StorageApiError=e.StorageError=void 0,e.isStorageError=function(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t};class r extends Error{constructor(t){super(t),this.__isStorageError=!0,this.name="StorageError"}}e.StorageError=r,e.StorageApiError=class extends r{constructor(t,e,r){super(t),this.name="StorageApiError",this.status=e,this.statusCode=r}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},e.StorageUnknownError=class extends r{constructor(t,e){super(t),this.name="StorageUnknownError",this.originalError=e}}},646:function(t,e,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),n=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||o(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageClient=void 0;var i=r(456);Object.defineProperty(e,"StorageClient",{enumerable:!0,get:function(){return i.StorageClient}}),n(r(411),e),n(r(607),e)},781:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const n=r(607),i=r(442),s=r(819),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};e.default=class{constructor(t,e={},r,o){this.url=t,this.headers=e,this.bucketId=r,this.fetch=(0,s.resolveFetch)(o)}uploadOrUpdate(t,e,r,s){return o(this,void 0,void 0,function*(){try{let o;const n=Object.assign(Object.assign({},u),s);let a=Object.assign(Object.assign({},this.headers),"POST"===t&&{"x-upsert":String(n.upsert)});const c=n.metadata;"undefined"!=typeof Blob&&r instanceof Blob?(o=new FormData,o.append("cacheControl",n.cacheControl),c&&o.append("metadata",this.encodeMetadata(c)),o.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(o=r,o.append("cacheControl",n.cacheControl),c&&o.append("metadata",this.encodeMetadata(c))):(o=r,a["cache-control"]=`max-age=${n.cacheControl}`,a["content-type"]=n.contentType,c&&(a["x-metadata"]=this.toBase64(this.encodeMetadata(c)))),(null==s?void 0:s.headers)&&(a=Object.assign(Object.assign({},a),s.headers));const l=this._removeEmptyFolders(e),d=this._getFinalPath(l),h=yield("PUT"==t?i.put:i.post)(this.fetch,`${this.url}/object/${d}`,o,Object.assign({headers:a},(null==n?void 0:n.duplex)?{duplex:n.duplex}:{}));return{data:{path:l,id:h.Id,fullPath:h.Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}upload(t,e,r){return o(this,void 0,void 0,function*(){return this.uploadOrUpdate("POST",t,e,r)})}uploadToSignedUrl(t,e,r,s){return o(this,void 0,void 0,function*(){const o=this._removeEmptyFolders(t),a=this._getFinalPath(o),c=new URL(this.url+`/object/upload/sign/${a}`);c.searchParams.set("token",e);try{let t;const e=Object.assign({upsert:u.upsert},s),n=Object.assign(Object.assign({},this.headers),{"x-upsert":String(e.upsert)});return"undefined"!=typeof Blob&&r instanceof Blob?(t=new FormData,t.append("cacheControl",e.cacheControl),t.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(t=r,t.append("cacheControl",e.cacheControl)):(t=r,n["cache-control"]=`max-age=${e.cacheControl}`,n["content-type"]=e.contentType),{data:{path:o,fullPath:(yield(0,i.put)(this.fetch,c.toString(),t,{headers:n})).Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUploadUrl(t,e){return o(this,void 0,void 0,function*(){try{let r=this._getFinalPath(t);const o=Object.assign({},this.headers);(null==e?void 0:e.upsert)&&(o["x-upsert"]="true");const s=yield(0,i.post)(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:o}),a=new URL(this.url+s.url),u=a.searchParams.get("token");if(!u)throw new n.StorageError("No token returned by API");return{data:{signedUrl:a.toString(),path:t,token:u},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}update(t,e,r){return o(this,void 0,void 0,function*(){return this.uploadOrUpdate("PUT",t,e,r)})}move(t,e,r){return o(this,void 0,void 0,function*(){try{return{data:yield(0,i.post)(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers}),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}copy(t,e,r){return o(this,void 0,void 0,function*(){try{return{data:{path:(yield(0,i.post)(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers})).Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUrl(t,e,r){return o(this,void 0,void 0,function*(){try{let o=this._getFinalPath(t),n=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${o}`,Object.assign({expiresIn:e},(null==r?void 0:r.transform)?{transform:r.transform}:{}),{headers:this.headers});const s=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return n={signedUrl:encodeURI(`${this.url}${n.signedURL}${s}`)},{data:n,error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUrls(t,e,r){return o(this,void 0,void 0,function*(){try{const o=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:e,paths:t},{headers:this.headers}),n=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return{data:o.map(t=>Object.assign(Object.assign({},t),{signedUrl:t.signedURL?encodeURI(`${this.url}${t.signedURL}${n}`):null})),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}download(t,e){return o(this,void 0,void 0,function*(){const r=void 0!==(null==e?void 0:e.transform)?"render/image/authenticated":"object",o=this.transformOptsToQueryString((null==e?void 0:e.transform)||{}),s=o?`?${o}`:"";try{const e=this._getFinalPath(t),o=yield(0,i.get)(this.fetch,`${this.url}/${r}/${e}${s}`,{headers:this.headers,noResolveJson:!0});return{data:yield o.blob(),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}info(t){return o(this,void 0,void 0,function*(){const e=this._getFinalPath(t);try{const t=yield(0,i.get)(this.fetch,`${this.url}/object/info/${e}`,{headers:this.headers});return{data:(0,s.recursiveToCamel)(t),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}exists(t){return o(this,void 0,void 0,function*(){const e=this._getFinalPath(t);try{return yield(0,i.head)(this.fetch,`${this.url}/object/${e}`,{headers:this.headers}),{data:!0,error:null}}catch(t){if((0,n.isStorageError)(t)&&t instanceof n.StorageUnknownError){const e=t.originalError;if([400,404].includes(null==e?void 0:e.status))return{data:!1,error:t}}throw t}})}getPublicUrl(t,e){const r=this._getFinalPath(t),o=[],n=(null==e?void 0:e.download)?`download=${!0===e.download?"":e.download}`:"";""!==n&&o.push(n);const i=void 0!==(null==e?void 0:e.transform)?"render/image":"object",s=this.transformOptsToQueryString((null==e?void 0:e.transform)||{});""!==s&&o.push(s);let a=o.join("&");return""!==a&&(a=`?${a}`),{data:{publicUrl:encodeURI(`${this.url}/${i}/public/${r}${a}`)}}}remove(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,i.remove)(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}list(t,e,r){return o(this,void 0,void 0,function*(){try{const o=Object.assign(Object.assign(Object.assign({},a),e),{prefix:t||""});return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list/${this.bucketId}`,o,{headers:this.headers},r),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}listV2(t,e){return o(this,void 0,void 0,function*(){try{const r=Object.assign({},t);return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,r,{headers:this.headers},e),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}encodeMetadata(t){return JSON.stringify(t)}toBase64(t){return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):btoa(t)}_getFinalPath(t){return`${this.bucketId}/${t.replace(/^\/+/,"")}`}_removeEmptyFolders(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")}transformOptsToQueryString(t){const e=[];return t.width&&e.push(`width=${t.width}`),t.height&&e.push(`height=${t.height}`),t.resize&&e.push(`resize=${t.resize}`),t.format&&e.push(`format=${t.format}`),t.quality&&e.push(`quality=${t.quality}`),e.join("&")}}},819:function(t,e,r){"use strict";var o,n=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||(o=function(t){return o=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},o(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=o(t),s=0;s<r.length;s++)"default"!==r[s]&&n(e,t,r[s]);return i(e,t),e}),a=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.isPlainObject=e.recursiveToCamel=e.resolveResponse=e.resolveFetch=void 0,e.resolveFetch=t=>{let e;return e=t||("undefined"==typeof fetch?(...t)=>Promise.resolve("@supabase/node-fetch").then(t=>s(r(97)(t))).then(({default:e})=>e(...t)):fetch),(...t)=>e(...t)},e.resolveResponse=()=>a(void 0,void 0,void 0,function*(){return"undefined"==typeof Response?(yield Promise.resolve("@supabase/node-fetch").then(t=>s(r(97)(t)))).Response:Response}),e.recursiveToCamel=t=>{if(Array.isArray(t))return t.map(t=>(0,e.recursiveToCamel)(t));if("function"==typeof t||t!==Object(t))return t;const r={};return Object.entries(t).forEach(([t,o])=>{const n=t.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace(/[-_]/g,""));r[n]=(0,e.recursiveToCamel)(o)}),r},e.isPlainObject=t=>{if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return!(null!==e&&e!==Object.prototype&&null!==Object.getPrototypeOf(e)||Symbol.toStringTag in t||Symbol.iterator in t)}},822:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.version=void 0,e.version="0.0.0"}},e={};function r(o){var n=e[o];if(void 0!==n)return n.exports;var i=e[o]={exports:{}};return t[o].call(i.exports,i,i.exports,r),i.exports}return r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r(646)})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,()=>(()=>{var t={97:t=>{function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=97,t.exports=e},251:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_HEADERS=void 0;const o=r(822);e.DEFAULT_HEADERS={"X-Client-Info":`storage-js/${o.version}`}},411:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},442:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.get=function(t,e,r,n){return o(this,void 0,void 0,function*(){return c(t,"GET",e,r,n)})},e.post=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"POST",e,n,i,r)})},e.put=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"PUT",e,n,i,r)})},e.head=function(t,e,r,n){return o(this,void 0,void 0,function*(){return c(t,"HEAD",e,Object.assign(Object.assign({},r),{noResolveJson:!0}),n)})},e.remove=function(t,e,r,n,i){return o(this,void 0,void 0,function*(){return c(t,"DELETE",e,n,i,r)})};const n=r(607),i=r(819),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t),a=(t,e,r)=>o(void 0,void 0,void 0,function*(){const o=yield(0,i.resolveResponse)();t instanceof o&&!(null==r?void 0:r.noResolveJson)?t.json().then(r=>{const o=t.status||500,i=(null==r?void 0:r.statusCode)||o+"";e(new n.StorageApiError(s(r),o,i))}).catch(t=>{e(new n.StorageUnknownError(s(t),t))}):e(new n.StorageUnknownError(s(t),t))}),u=(t,e,r,o)=>{const n={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"!==t&&o?((0,i.isPlainObject)(o)?(n.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),n.body=JSON.stringify(o)):n.body=o,(null==e?void 0:e.duplex)&&(n.duplex=e.duplex),Object.assign(Object.assign({},n),r)):n};function c(t,e,r,n,i,s){return o(this,void 0,void 0,function*(){return new Promise((o,c)=>{t(r,u(e,n,i,s)).then(t=>{if(!t.ok)throw t;return(null==n?void 0:n.noResolveJson)?t:t.json()}).then(t=>o(t)).catch(t=>a(t,c,n))})})}},456:function(t,e,r){"use strict";var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageClient=void 0;const n=o(r(781)),i=o(r(485));class s extends i.default{constructor(t,e={},r,o){super(t,e,r,o)}from(t){return new n.default(this.url,this.headers,t,this.fetch)}}e.StorageClient=s},485:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const n=r(251),i=r(607),s=r(442),a=r(819);e.default=class{constructor(t,e={},r,o){const i=new URL(t);(null==o?void 0:o.useNewHostname)&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes("storage.supabase.")&&(i.hostname=i.hostname.replace("supabase.","storage.supabase.")),this.url=i.href,this.headers=Object.assign(Object.assign({},n.DEFAULT_HEADERS),e),this.fetch=(0,a.resolveFetch)(r)}listBuckets(){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}getBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}createBucket(t){return o(this,arguments,void 0,function*(t,e={public:!1}){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket`,{id:t,name:t,type:e.type,public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}updateBucket(t,e){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.put)(this.fetch,`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}emptyBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}deleteBucket(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,s.remove)(this.fetch,`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){if((0,i.isStorageError)(t))return{data:null,error:t};throw t}})}}},607:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.StorageUnknownError=e.StorageApiError=e.StorageError=void 0,e.isStorageError=function(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t};class r extends Error{constructor(t){super(t),this.__isStorageError=!0,this.name="StorageError"}}e.StorageError=r,e.StorageApiError=class extends r{constructor(t,e,r){super(t),this.name="StorageApiError",this.status=e,this.statusCode=r}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},e.StorageUnknownError=class extends r{constructor(t,e){super(t),this.name="StorageUnknownError",this.originalError=e}}},646:function(t,e,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),n=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||o(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageClient=void 0;var i=r(456);Object.defineProperty(e,"StorageClient",{enumerable:!0,get:function(){return i.StorageClient}}),n(r(411),e),n(r(607),e)},781:function(t,e,r){"use strict";var o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const n=r(607),i=r(442),s=r(819),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};e.default=class{constructor(t,e={},r,o){this.url=t,this.headers=e,this.bucketId=r,this.fetch=(0,s.resolveFetch)(o)}uploadOrUpdate(t,e,r,s){return o(this,void 0,void 0,function*(){try{let o;const n=Object.assign(Object.assign({},u),s);let a=Object.assign(Object.assign({},this.headers),"POST"===t&&{"x-upsert":String(n.upsert)});const c=n.metadata;"undefined"!=typeof Blob&&r instanceof Blob?(o=new FormData,o.append("cacheControl",n.cacheControl),c&&o.append("metadata",this.encodeMetadata(c)),o.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(o=r,o.append("cacheControl",n.cacheControl),c&&o.append("metadata",this.encodeMetadata(c))):(o=r,a["cache-control"]=`max-age=${n.cacheControl}`,a["content-type"]=n.contentType,c&&(a["x-metadata"]=this.toBase64(this.encodeMetadata(c)))),(null==s?void 0:s.headers)&&(a=Object.assign(Object.assign({},a),s.headers));const l=this._removeEmptyFolders(e),d=this._getFinalPath(l),h=yield("PUT"==t?i.put:i.post)(this.fetch,`${this.url}/object/${d}`,o,Object.assign({headers:a},(null==n?void 0:n.duplex)?{duplex:n.duplex}:{}));return{data:{path:l,id:h.Id,fullPath:h.Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}upload(t,e,r){return o(this,void 0,void 0,function*(){return this.uploadOrUpdate("POST",t,e,r)})}uploadToSignedUrl(t,e,r,s){return o(this,void 0,void 0,function*(){const o=this._removeEmptyFolders(t),a=this._getFinalPath(o),c=new URL(this.url+`/object/upload/sign/${a}`);c.searchParams.set("token",e);try{let t;const e=Object.assign({upsert:u.upsert},s),n=Object.assign(Object.assign({},this.headers),{"x-upsert":String(e.upsert)});return"undefined"!=typeof Blob&&r instanceof Blob?(t=new FormData,t.append("cacheControl",e.cacheControl),t.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(t=r,t.append("cacheControl",e.cacheControl)):(t=r,n["cache-control"]=`max-age=${e.cacheControl}`,n["content-type"]=e.contentType),{data:{path:o,fullPath:(yield(0,i.put)(this.fetch,c.toString(),t,{headers:n})).Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUploadUrl(t,e){return o(this,void 0,void 0,function*(){try{let r=this._getFinalPath(t);const o=Object.assign({},this.headers);(null==e?void 0:e.upsert)&&(o["x-upsert"]="true");const s=yield(0,i.post)(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:o}),a=new URL(this.url+s.url),u=a.searchParams.get("token");if(!u)throw new n.StorageError("No token returned by API");return{data:{signedUrl:a.toString(),path:t,token:u},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}update(t,e,r){return o(this,void 0,void 0,function*(){return this.uploadOrUpdate("PUT",t,e,r)})}move(t,e,r){return o(this,void 0,void 0,function*(){try{return{data:yield(0,i.post)(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers}),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}copy(t,e,r){return o(this,void 0,void 0,function*(){try{return{data:{path:(yield(0,i.post)(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers})).Key},error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUrl(t,e,r){return o(this,void 0,void 0,function*(){try{let o=this._getFinalPath(t),n=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${o}`,Object.assign({expiresIn:e},(null==r?void 0:r.transform)?{transform:r.transform}:{}),{headers:this.headers});const s=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return n={signedUrl:encodeURI(`${this.url}${n.signedURL}${s}`)},{data:n,error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}createSignedUrls(t,e,r){return o(this,void 0,void 0,function*(){try{const o=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:e,paths:t},{headers:this.headers}),n=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return{data:o.map(t=>Object.assign(Object.assign({},t),{signedUrl:t.signedURL?encodeURI(`${this.url}${t.signedURL}${n}`):null})),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}download(t,e){return o(this,void 0,void 0,function*(){const r=void 0!==(null==e?void 0:e.transform)?"render/image/authenticated":"object",o=this.transformOptsToQueryString((null==e?void 0:e.transform)||{}),s=o?`?${o}`:"";try{const e=this._getFinalPath(t),o=yield(0,i.get)(this.fetch,`${this.url}/${r}/${e}${s}`,{headers:this.headers,noResolveJson:!0});return{data:yield o.blob(),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}info(t){return o(this,void 0,void 0,function*(){const e=this._getFinalPath(t);try{const t=yield(0,i.get)(this.fetch,`${this.url}/object/info/${e}`,{headers:this.headers});return{data:(0,s.recursiveToCamel)(t),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}exists(t){return o(this,void 0,void 0,function*(){const e=this._getFinalPath(t);try{return yield(0,i.head)(this.fetch,`${this.url}/object/${e}`,{headers:this.headers}),{data:!0,error:null}}catch(t){if((0,n.isStorageError)(t)&&t instanceof n.StorageUnknownError){const e=t.originalError;if([400,404].includes(null==e?void 0:e.status))return{data:!1,error:t}}throw t}})}getPublicUrl(t,e){const r=this._getFinalPath(t),o=[],n=(null==e?void 0:e.download)?`download=${!0===e.download?"":e.download}`:"";""!==n&&o.push(n);const i=void 0!==(null==e?void 0:e.transform)?"render/image":"object",s=this.transformOptsToQueryString((null==e?void 0:e.transform)||{});""!==s&&o.push(s);let a=o.join("&");return""!==a&&(a=`?${a}`),{data:{publicUrl:encodeURI(`${this.url}/${i}/public/${r}${a}`)}}}remove(t){return o(this,void 0,void 0,function*(){try{return{data:yield(0,i.remove)(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}list(t,e,r){return o(this,void 0,void 0,function*(){try{const o=Object.assign(Object.assign(Object.assign({},a),e),{prefix:t||""});return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list/${this.bucketId}`,o,{headers:this.headers},r),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}listV2(t,e){return o(this,void 0,void 0,function*(){try{const r=Object.assign({},t);return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,r,{headers:this.headers},e),error:null}}catch(t){if((0,n.isStorageError)(t))return{data:null,error:t};throw t}})}encodeMetadata(t){return JSON.stringify(t)}toBase64(t){return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):btoa(t)}_getFinalPath(t){return`${this.bucketId}/${t.replace(/^\/+/,"")}`}_removeEmptyFolders(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")}transformOptsToQueryString(t){const e=[];return t.width&&e.push(`width=${t.width}`),t.height&&e.push(`height=${t.height}`),t.resize&&e.push(`resize=${t.resize}`),t.format&&e.push(`format=${t.format}`),t.quality&&e.push(`quality=${t.quality}`),e.join("&")}}},819:function(t,e,r){"use strict";var o,n=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||(o=function(t){return o=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},o(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=o(t),s=0;s<r.length;s++)"default"!==r[s]&&n(e,t,r[s]);return i(e,t),e}),a=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))(function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0}),e.isPlainObject=e.recursiveToCamel=e.resolveResponse=e.resolveFetch=void 0,e.resolveFetch=t=>{let e;return e=t||("undefined"==typeof fetch?(...t)=>Promise.resolve("@supabase/node-fetch").then(t=>s(r(97)(t))).then(({default:e})=>e(...t)):fetch),(...t)=>e(...t)},e.resolveResponse=()=>a(void 0,void 0,void 0,function*(){return"undefined"==typeof Response?(yield Promise.resolve("@supabase/node-fetch").then(t=>s(r(97)(t)))).Response:Response}),e.recursiveToCamel=t=>{if(Array.isArray(t))return t.map(t=>(0,e.recursiveToCamel)(t));if("function"==typeof t||t!==Object(t))return t;const r={};return Object.entries(t).forEach(([t,o])=>{const n=t.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace(/[-_]/g,""));r[n]=(0,e.recursiveToCamel)(o)}),r},e.isPlainObject=t=>{if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return!(null!==e&&e!==Object.prototype&&null!==Object.getPrototypeOf(e)||Symbol.toStringTag in t||Symbol.iterator in t)}},822:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.version=void 0,e.version="2.72.1-canary.2"}},e={};function r(o){var n=e[o];if(void 0!==n)return n.exports;var i=e[o]={exports:{}};return t[o].call(i.exports,i,i.exports,r),i.exports}return r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r(646)})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/storage-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.72.1-canary.2",
|
|
4
4
|
"description": "Isomorphic storage client for Supabase.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"clean": "rimraf dist docs/v2",
|
|
29
29
|
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
|
30
|
-
"build": "
|
|
30
|
+
"build": "npm run clean && npm run format && npm run build:main && npm run build:module && npm run build:umd",
|
|
31
31
|
"build:main": "tsc -p tsconfig.json",
|
|
32
32
|
"build:module": "tsc -p tsconfig.module.json",
|
|
33
33
|
"build:umd": "webpack",
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
// Generated by
|
|
2
|
-
|
|
1
|
+
// Generated automatically during releases by scripts/update-version-files.js
|
|
2
|
+
// This file provides runtime access to the package version for:
|
|
3
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
4
|
+
// - Debugging and support (identifying which version is running)
|
|
5
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
|
+
// - Ensuring build artifacts match the published package version
|
|
7
|
+
export const version = '2.72.1-canary.2'
|