@supabase/storage-js 2.12.2 → 2.71.2-canary.0

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.
Files changed (115) hide show
  1. package/README.md +0 -15
  2. package/package.json +11 -17
  3. package/src/index.ts +1 -2
  4. package/src/lib/types.ts +0 -12
  5. package/src/lib/version.ts +2 -2
  6. package/src/packages/StorageBucketApi.ts +3 -36
  7. package/src/packages/StorageFileApi.ts +30 -64
  8. package/LICENSE +0 -201
  9. package/dist/main/StorageClient.d.ts +0 -18
  10. package/dist/main/StorageClient.d.ts.map +0 -1
  11. package/dist/main/StorageClient.js +0 -23
  12. package/dist/main/StorageClient.js.map +0 -1
  13. package/dist/main/index.d.ts +0 -5
  14. package/dist/main/index.d.ts.map +0 -1
  15. package/dist/main/index.js +0 -22
  16. package/dist/main/index.js.map +0 -1
  17. package/dist/main/lib/constants.d.ts +0 -4
  18. package/dist/main/lib/constants.d.ts.map +0 -1
  19. package/dist/main/lib/constants.js +0 -6
  20. package/dist/main/lib/constants.js.map +0 -1
  21. package/dist/main/lib/errors.d.ts +0 -21
  22. package/dist/main/lib/errors.d.ts.map +0 -1
  23. package/dist/main/lib/errors.js +0 -41
  24. package/dist/main/lib/errors.js.map +0 -1
  25. package/dist/main/lib/fetch.d.ts +0 -16
  26. package/dist/main/lib/fetch.d.ts.map +0 -1
  27. package/dist/main/lib/fetch.js +0 -97
  28. package/dist/main/lib/fetch.js.map +0 -1
  29. package/dist/main/lib/helpers.d.ts +0 -12
  30. package/dist/main/lib/helpers.d.ts.map +0 -1
  31. package/dist/main/lib/helpers.js +0 -90
  32. package/dist/main/lib/helpers.js.map +0 -1
  33. package/dist/main/lib/index.d.ts +0 -5
  34. package/dist/main/lib/index.d.ts.map +0 -1
  35. package/dist/main/lib/index.js +0 -21
  36. package/dist/main/lib/index.js.map +0 -1
  37. package/dist/main/lib/types.d.ts +0 -156
  38. package/dist/main/lib/types.d.ts.map +0 -1
  39. package/dist/main/lib/types.js +0 -3
  40. package/dist/main/lib/types.js.map +0 -1
  41. package/dist/main/lib/version.d.ts +0 -2
  42. package/dist/main/lib/version.d.ts.map +0 -1
  43. package/dist/main/lib/version.js +0 -6
  44. package/dist/main/lib/version.js.map +0 -1
  45. package/dist/main/packages/BlobDownloadBuilder.d.ts +0 -11
  46. package/dist/main/packages/BlobDownloadBuilder.d.ts.map +0 -1
  47. package/dist/main/packages/BlobDownloadBuilder.js +0 -50
  48. package/dist/main/packages/BlobDownloadBuilder.js.map +0 -1
  49. package/dist/main/packages/StorageBucketApi.d.ts +0 -123
  50. package/dist/main/packages/StorageBucketApi.d.ts.map +0 -1
  51. package/dist/main/packages/StorageBucketApi.js +0 -204
  52. package/dist/main/packages/StorageBucketApi.js.map +0 -1
  53. package/dist/main/packages/StorageFileApi.d.ts +0 -271
  54. package/dist/main/packages/StorageFileApi.d.ts.map +0 -1
  55. package/dist/main/packages/StorageFileApi.js +0 -593
  56. package/dist/main/packages/StorageFileApi.js.map +0 -1
  57. package/dist/main/packages/StreamDownloadBuilder.d.ts +0 -9
  58. package/dist/main/packages/StreamDownloadBuilder.d.ts.map +0 -1
  59. package/dist/main/packages/StreamDownloadBuilder.js +0 -43
  60. package/dist/main/packages/StreamDownloadBuilder.js.map +0 -1
  61. package/dist/module/StorageClient.d.ts +0 -18
  62. package/dist/module/StorageClient.d.ts.map +0 -1
  63. package/dist/module/StorageClient.js +0 -16
  64. package/dist/module/StorageClient.js.map +0 -1
  65. package/dist/module/index.d.ts +0 -5
  66. package/dist/module/index.d.ts.map +0 -1
  67. package/dist/module/index.js +0 -4
  68. package/dist/module/index.js.map +0 -1
  69. package/dist/module/lib/constants.d.ts +0 -4
  70. package/dist/module/lib/constants.d.ts.map +0 -1
  71. package/dist/module/lib/constants.js +0 -3
  72. package/dist/module/lib/constants.js.map +0 -1
  73. package/dist/module/lib/errors.d.ts +0 -21
  74. package/dist/module/lib/errors.d.ts.map +0 -1
  75. package/dist/module/lib/errors.js +0 -34
  76. package/dist/module/lib/errors.js.map +0 -1
  77. package/dist/module/lib/fetch.d.ts +0 -16
  78. package/dist/module/lib/fetch.d.ts.map +0 -1
  79. package/dist/module/lib/fetch.js +0 -89
  80. package/dist/module/lib/fetch.js.map +0 -1
  81. package/dist/module/lib/helpers.d.ts +0 -12
  82. package/dist/module/lib/helpers.d.ts.map +0 -1
  83. package/dist/module/lib/helpers.js +0 -60
  84. package/dist/module/lib/helpers.js.map +0 -1
  85. package/dist/module/lib/index.d.ts +0 -5
  86. package/dist/module/lib/index.d.ts.map +0 -1
  87. package/dist/module/lib/index.js +0 -5
  88. package/dist/module/lib/index.js.map +0 -1
  89. package/dist/module/lib/types.d.ts +0 -156
  90. package/dist/module/lib/types.d.ts.map +0 -1
  91. package/dist/module/lib/types.js +0 -2
  92. package/dist/module/lib/types.js.map +0 -1
  93. package/dist/module/lib/version.d.ts +0 -2
  94. package/dist/module/lib/version.d.ts.map +0 -1
  95. package/dist/module/lib/version.js +0 -3
  96. package/dist/module/lib/version.js.map +0 -1
  97. package/dist/module/packages/BlobDownloadBuilder.d.ts +0 -11
  98. package/dist/module/packages/BlobDownloadBuilder.d.ts.map +0 -1
  99. package/dist/module/packages/BlobDownloadBuilder.js +0 -44
  100. package/dist/module/packages/BlobDownloadBuilder.js.map +0 -1
  101. package/dist/module/packages/StorageBucketApi.d.ts +0 -123
  102. package/dist/module/packages/StorageBucketApi.d.ts.map +0 -1
  103. package/dist/module/packages/StorageBucketApi.js +0 -201
  104. package/dist/module/packages/StorageBucketApi.js.map +0 -1
  105. package/dist/module/packages/StorageFileApi.d.ts +0 -271
  106. package/dist/module/packages/StorageFileApi.d.ts.map +0 -1
  107. package/dist/module/packages/StorageFileApi.js +0 -587
  108. package/dist/module/packages/StorageFileApi.js.map +0 -1
  109. package/dist/module/packages/StreamDownloadBuilder.d.ts +0 -9
  110. package/dist/module/packages/StreamDownloadBuilder.d.ts.map +0 -1
  111. package/dist/module/packages/StreamDownloadBuilder.js +0 -40
  112. package/dist/module/packages/StreamDownloadBuilder.js.map +0 -1
  113. package/dist/umd/supabase.js +0 -1
  114. package/src/packages/BlobDownloadBuilder.ts +0 -39
  115. package/src/packages/StreamDownloadBuilder.ts +0 -36
@@ -1,587 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { isStorageError, StorageError, StorageUnknownError } from '../lib/errors';
11
- import { get, head, post, put, remove } from '../lib/fetch';
12
- import { recursiveToCamel, resolveFetch } from '../lib/helpers';
13
- import BlobDownloadBuilder from './BlobDownloadBuilder';
14
- const DEFAULT_SEARCH_OPTIONS = {
15
- limit: 100,
16
- offset: 0,
17
- sortBy: {
18
- column: 'name',
19
- order: 'asc',
20
- },
21
- };
22
- const DEFAULT_FILE_OPTIONS = {
23
- cacheControl: '3600',
24
- contentType: 'text/plain;charset=UTF-8',
25
- upsert: false,
26
- };
27
- export default class StorageFileApi {
28
- constructor(url, headers = {}, bucketId, fetch) {
29
- this.shouldThrowOnError = false;
30
- this.url = url;
31
- this.headers = headers;
32
- this.bucketId = bucketId;
33
- this.fetch = resolveFetch(fetch);
34
- }
35
- /**
36
- * Enable throwing errors instead of returning them.
37
- */
38
- throwOnError() {
39
- this.shouldThrowOnError = true;
40
- return this;
41
- }
42
- /**
43
- * Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
44
- *
45
- * @param method HTTP method.
46
- * @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
47
- * @param fileBody The body of the file to be stored in the bucket.
48
- */
49
- uploadOrUpdate(method, path, fileBody, fileOptions) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- try {
52
- let body;
53
- const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
54
- let headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
55
- const metadata = options.metadata;
56
- if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
57
- body = new FormData();
58
- body.append('cacheControl', options.cacheControl);
59
- if (metadata) {
60
- body.append('metadata', this.encodeMetadata(metadata));
61
- }
62
- body.append('', fileBody);
63
- }
64
- else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
65
- body = fileBody;
66
- body.append('cacheControl', options.cacheControl);
67
- if (metadata) {
68
- body.append('metadata', this.encodeMetadata(metadata));
69
- }
70
- }
71
- else {
72
- body = fileBody;
73
- headers['cache-control'] = `max-age=${options.cacheControl}`;
74
- headers['content-type'] = options.contentType;
75
- if (metadata) {
76
- headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata));
77
- }
78
- }
79
- if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) {
80
- headers = Object.assign(Object.assign({}, headers), fileOptions.headers);
81
- }
82
- const cleanPath = this._removeEmptyFolders(path);
83
- const _path = this._getFinalPath(cleanPath);
84
- const data = yield (method == 'PUT' ? put : post)(this.fetch, `${this.url}/object/${_path}`, body, Object.assign({ headers }, ((options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {})));
85
- return {
86
- data: { path: cleanPath, id: data.Id, fullPath: data.Key },
87
- error: null,
88
- };
89
- }
90
- catch (error) {
91
- if (this.shouldThrowOnError) {
92
- throw error;
93
- }
94
- if (isStorageError(error)) {
95
- return { data: null, error };
96
- }
97
- throw error;
98
- }
99
- });
100
- }
101
- /**
102
- * Uploads a file to an existing bucket.
103
- *
104
- * @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
105
- * @param fileBody The body of the file to be stored in the bucket.
106
- */
107
- upload(path, fileBody, fileOptions) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- return this.uploadOrUpdate('POST', path, fileBody, fileOptions);
110
- });
111
- }
112
- /**
113
- * Upload a file with a token generated from `createSignedUploadUrl`.
114
- * @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
115
- * @param token The token generated from `createSignedUploadUrl`
116
- * @param fileBody The body of the file to be stored in the bucket.
117
- */
118
- uploadToSignedUrl(path, token, fileBody, fileOptions) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- const cleanPath = this._removeEmptyFolders(path);
121
- const _path = this._getFinalPath(cleanPath);
122
- const url = new URL(this.url + `/object/upload/sign/${_path}`);
123
- url.searchParams.set('token', token);
124
- try {
125
- let body;
126
- const options = Object.assign({ upsert: DEFAULT_FILE_OPTIONS.upsert }, fileOptions);
127
- const headers = Object.assign(Object.assign({}, this.headers), { 'x-upsert': String(options.upsert) });
128
- if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
129
- body = new FormData();
130
- body.append('cacheControl', options.cacheControl);
131
- body.append('', fileBody);
132
- }
133
- else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
134
- body = fileBody;
135
- body.append('cacheControl', options.cacheControl);
136
- }
137
- else {
138
- body = fileBody;
139
- headers['cache-control'] = `max-age=${options.cacheControl}`;
140
- headers['content-type'] = options.contentType;
141
- }
142
- const data = yield put(this.fetch, url.toString(), body, { headers });
143
- return {
144
- data: { path: cleanPath, fullPath: data.Key },
145
- error: null,
146
- };
147
- }
148
- catch (error) {
149
- if (this.shouldThrowOnError) {
150
- throw error;
151
- }
152
- if (isStorageError(error)) {
153
- return { data: null, error };
154
- }
155
- throw error;
156
- }
157
- });
158
- }
159
- /**
160
- * Creates a signed upload URL.
161
- * Signed upload URLs can be used to upload files to the bucket without further authentication.
162
- * They are valid for 2 hours.
163
- * @param path The file path, including the current file name. For example `folder/image.png`.
164
- * @param options.upsert If set to true, allows the file to be overwritten if it already exists.
165
- */
166
- createSignedUploadUrl(path, options) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- try {
169
- let _path = this._getFinalPath(path);
170
- const headers = Object.assign({}, this.headers);
171
- if (options === null || options === void 0 ? void 0 : options.upsert) {
172
- headers['x-upsert'] = 'true';
173
- }
174
- const data = yield post(this.fetch, `${this.url}/object/upload/sign/${_path}`, {}, { headers });
175
- const url = new URL(this.url + data.url);
176
- const token = url.searchParams.get('token');
177
- if (!token) {
178
- throw new StorageError('No token returned by API');
179
- }
180
- return { data: { signedUrl: url.toString(), path, token }, error: null };
181
- }
182
- catch (error) {
183
- if (this.shouldThrowOnError) {
184
- throw error;
185
- }
186
- if (isStorageError(error)) {
187
- return { data: null, error };
188
- }
189
- throw error;
190
- }
191
- });
192
- }
193
- /**
194
- * Replaces an existing file at the specified path with a new one.
195
- *
196
- * @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
197
- * @param fileBody The body of the file to be stored in the bucket.
198
- */
199
- update(path, fileBody, fileOptions) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- return this.uploadOrUpdate('PUT', path, fileBody, fileOptions);
202
- });
203
- }
204
- /**
205
- * Moves an existing file to a new path in the same bucket.
206
- *
207
- * @param fromPath The original file path, including the current file name. For example `folder/image.png`.
208
- * @param toPath The new file path, including the new file name. For example `folder/image-new.png`.
209
- * @param options The destination options.
210
- */
211
- move(fromPath, toPath, options) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- try {
214
- const data = yield post(this.fetch, `${this.url}/object/move`, {
215
- bucketId: this.bucketId,
216
- sourceKey: fromPath,
217
- destinationKey: toPath,
218
- destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
219
- }, { headers: this.headers });
220
- return { data, error: null };
221
- }
222
- catch (error) {
223
- if (this.shouldThrowOnError) {
224
- throw error;
225
- }
226
- if (isStorageError(error)) {
227
- return { data: null, error };
228
- }
229
- throw error;
230
- }
231
- });
232
- }
233
- /**
234
- * Copies an existing file to a new path in the same bucket.
235
- *
236
- * @param fromPath The original file path, including the current file name. For example `folder/image.png`.
237
- * @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
238
- * @param options The destination options.
239
- */
240
- copy(fromPath, toPath, options) {
241
- return __awaiter(this, void 0, void 0, function* () {
242
- try {
243
- const data = yield post(this.fetch, `${this.url}/object/copy`, {
244
- bucketId: this.bucketId,
245
- sourceKey: fromPath,
246
- destinationKey: toPath,
247
- destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
248
- }, { headers: this.headers });
249
- return { data: { path: data.Key }, error: null };
250
- }
251
- catch (error) {
252
- if (this.shouldThrowOnError) {
253
- throw error;
254
- }
255
- if (isStorageError(error)) {
256
- return { data: null, error };
257
- }
258
- throw error;
259
- }
260
- });
261
- }
262
- /**
263
- * Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
264
- *
265
- * @param path The file path, including the current file name. For example `folder/image.png`.
266
- * @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
267
- * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
268
- * @param options.transform Transform the asset before serving it to the client.
269
- */
270
- createSignedUrl(path, expiresIn, options) {
271
- return __awaiter(this, void 0, void 0, function* () {
272
- try {
273
- let _path = this._getFinalPath(path);
274
- let data = yield post(this.fetch, `${this.url}/object/sign/${_path}`, Object.assign({ expiresIn }, ((options === null || options === void 0 ? void 0 : options.transform) ? { transform: options.transform } : {})), { headers: this.headers });
275
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
276
- ? `&download=${options.download === true ? '' : options.download}`
277
- : '';
278
- const signedUrl = encodeURI(`${this.url}${data.signedURL}${downloadQueryParam}`);
279
- data = { signedUrl };
280
- return { data, error: null };
281
- }
282
- catch (error) {
283
- if (this.shouldThrowOnError) {
284
- throw error;
285
- }
286
- if (isStorageError(error)) {
287
- return { data: null, error };
288
- }
289
- throw error;
290
- }
291
- });
292
- }
293
- /**
294
- * Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
295
- *
296
- * @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`.
297
- * @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
298
- * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
299
- */
300
- createSignedUrls(paths, expiresIn, options) {
301
- return __awaiter(this, void 0, void 0, function* () {
302
- try {
303
- const data = yield post(this.fetch, `${this.url}/object/sign/${this.bucketId}`, { expiresIn, paths }, { headers: this.headers });
304
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
305
- ? `&download=${options.download === true ? '' : options.download}`
306
- : '';
307
- return {
308
- data: data.map((datum) => (Object.assign(Object.assign({}, datum), { signedUrl: datum.signedURL
309
- ? encodeURI(`${this.url}${datum.signedURL}${downloadQueryParam}`)
310
- : null }))),
311
- error: null,
312
- };
313
- }
314
- catch (error) {
315
- if (this.shouldThrowOnError) {
316
- throw error;
317
- }
318
- if (isStorageError(error)) {
319
- return { data: null, error };
320
- }
321
- throw error;
322
- }
323
- });
324
- }
325
- /**
326
- * Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead.
327
- *
328
- * @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
329
- * @param options.transform Transform the asset before serving it to the client.
330
- */
331
- download(path, options) {
332
- const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== 'undefined';
333
- const renderPath = wantsTransformation ? 'render/image/authenticated' : 'object';
334
- const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
335
- const queryString = transformationQuery ? `?${transformationQuery}` : '';
336
- const _path = this._getFinalPath(path);
337
- const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString}`, {
338
- headers: this.headers,
339
- noResolveJson: true,
340
- });
341
- return new BlobDownloadBuilder(downloadFn, this.shouldThrowOnError);
342
- }
343
- /**
344
- * Retrieves the details of an existing file.
345
- * @param path
346
- */
347
- info(path) {
348
- return __awaiter(this, void 0, void 0, function* () {
349
- const _path = this._getFinalPath(path);
350
- try {
351
- const data = yield get(this.fetch, `${this.url}/object/info/${_path}`, {
352
- headers: this.headers,
353
- });
354
- return { data: recursiveToCamel(data), error: null };
355
- }
356
- catch (error) {
357
- if (this.shouldThrowOnError) {
358
- throw error;
359
- }
360
- if (isStorageError(error)) {
361
- return { data: null, error };
362
- }
363
- throw error;
364
- }
365
- });
366
- }
367
- /**
368
- * Checks the existence of a file.
369
- * @param path
370
- */
371
- exists(path) {
372
- return __awaiter(this, void 0, void 0, function* () {
373
- const _path = this._getFinalPath(path);
374
- try {
375
- yield head(this.fetch, `${this.url}/object/${_path}`, {
376
- headers: this.headers,
377
- });
378
- return { data: true, error: null };
379
- }
380
- catch (error) {
381
- if (this.shouldThrowOnError) {
382
- throw error;
383
- }
384
- if (isStorageError(error) && error instanceof StorageUnknownError) {
385
- const originalError = error.originalError;
386
- if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) {
387
- return { data: false, error };
388
- }
389
- }
390
- throw error;
391
- }
392
- });
393
- }
394
- /**
395
- * A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
396
- * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
397
- *
398
- * @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
399
- * @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
400
- * @param options.transform Transform the asset before serving it to the client.
401
- */
402
- getPublicUrl(path, options) {
403
- const _path = this._getFinalPath(path);
404
- const _queryString = [];
405
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
406
- ? `download=${options.download === true ? '' : options.download}`
407
- : '';
408
- if (downloadQueryParam !== '') {
409
- _queryString.push(downloadQueryParam);
410
- }
411
- const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== 'undefined';
412
- const renderPath = wantsTransformation ? 'render/image' : 'object';
413
- const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
414
- if (transformationQuery !== '') {
415
- _queryString.push(transformationQuery);
416
- }
417
- let queryString = _queryString.join('&');
418
- if (queryString !== '') {
419
- queryString = `?${queryString}`;
420
- }
421
- return {
422
- data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) },
423
- };
424
- }
425
- /**
426
- * Deletes files within the same bucket
427
- *
428
- * @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`].
429
- */
430
- remove(paths) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- try {
433
- const data = yield remove(this.fetch, `${this.url}/object/${this.bucketId}`, { prefixes: paths }, { headers: this.headers });
434
- return { data, error: null };
435
- }
436
- catch (error) {
437
- if (this.shouldThrowOnError) {
438
- throw error;
439
- }
440
- if (isStorageError(error)) {
441
- return { data: null, error };
442
- }
443
- throw error;
444
- }
445
- });
446
- }
447
- /**
448
- * Get file metadata
449
- * @param id the file id to retrieve metadata
450
- */
451
- // async getMetadata(
452
- // id: string
453
- // ): Promise<
454
- // | {
455
- // data: Metadata
456
- // error: null
457
- // }
458
- // | {
459
- // data: null
460
- // error: StorageError
461
- // }
462
- // > {
463
- // try {
464
- // const data = await get(this.fetch, `${this.url}/metadata/${id}`, { headers: this.headers })
465
- // return { data, error: null }
466
- // } catch (error) {
467
- // if (isStorageError(error)) {
468
- // return { data: null, error }
469
- // }
470
- // throw error
471
- // }
472
- // }
473
- /**
474
- * Update file metadata
475
- * @param id the file id to update metadata
476
- * @param meta the new file metadata
477
- */
478
- // async updateMetadata(
479
- // id: string,
480
- // meta: Metadata
481
- // ): Promise<
482
- // | {
483
- // data: Metadata
484
- // error: null
485
- // }
486
- // | {
487
- // data: null
488
- // error: StorageError
489
- // }
490
- // > {
491
- // try {
492
- // const data = await post(
493
- // this.fetch,
494
- // `${this.url}/metadata/${id}`,
495
- // { ...meta },
496
- // { headers: this.headers }
497
- // )
498
- // return { data, error: null }
499
- // } catch (error) {
500
- // if (isStorageError(error)) {
501
- // return { data: null, error }
502
- // }
503
- // throw error
504
- // }
505
- // }
506
- /**
507
- * Lists all the files and folders within a path of the bucket.
508
- * @param path The folder path.
509
- * @param options Search options including limit (defaults to 100), offset, sortBy, and search
510
- */
511
- list(path, options, parameters) {
512
- return __awaiter(this, void 0, void 0, function* () {
513
- try {
514
- const body = Object.assign(Object.assign(Object.assign({}, DEFAULT_SEARCH_OPTIONS), options), { prefix: path || '' });
515
- const data = yield post(this.fetch, `${this.url}/object/list/${this.bucketId}`, body, { headers: this.headers }, parameters);
516
- return { data, error: null };
517
- }
518
- catch (error) {
519
- if (this.shouldThrowOnError) {
520
- throw error;
521
- }
522
- if (isStorageError(error)) {
523
- return { data: null, error };
524
- }
525
- throw error;
526
- }
527
- });
528
- }
529
- /**
530
- * @experimental this method signature might change in the future
531
- * @param options search options
532
- * @param parameters
533
- */
534
- listV2(options, parameters) {
535
- return __awaiter(this, void 0, void 0, function* () {
536
- try {
537
- const body = Object.assign({}, options);
538
- const data = yield post(this.fetch, `${this.url}/object/list-v2/${this.bucketId}`, body, { headers: this.headers }, parameters);
539
- return { data, error: null };
540
- }
541
- catch (error) {
542
- if (this.shouldThrowOnError) {
543
- throw error;
544
- }
545
- if (isStorageError(error)) {
546
- return { data: null, error };
547
- }
548
- throw error;
549
- }
550
- });
551
- }
552
- encodeMetadata(metadata) {
553
- return JSON.stringify(metadata);
554
- }
555
- toBase64(data) {
556
- if (typeof Buffer !== 'undefined') {
557
- return Buffer.from(data).toString('base64');
558
- }
559
- return btoa(data);
560
- }
561
- _getFinalPath(path) {
562
- return `${this.bucketId}/${path.replace(/^\/+/, '')}`;
563
- }
564
- _removeEmptyFolders(path) {
565
- return path.replace(/^\/|\/$/g, '').replace(/\/+/g, '/');
566
- }
567
- transformOptsToQueryString(transform) {
568
- const params = [];
569
- if (transform.width) {
570
- params.push(`width=${transform.width}`);
571
- }
572
- if (transform.height) {
573
- params.push(`height=${transform.height}`);
574
- }
575
- if (transform.resize) {
576
- params.push(`resize=${transform.resize}`);
577
- }
578
- if (transform.format) {
579
- params.push(`format=${transform.format}`);
580
- }
581
- if (transform.quality) {
582
- params.push(`quality=${transform.quality}`);
583
- }
584
- return params.join('&');
585
- }
586
- }
587
- //# sourceMappingURL=StorageFileApi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageFileApi.js","sourceRoot":"","sources":["../../../src/packages/StorageFileApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAa/D,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AAEvD,MAAM,sBAAsB,GAAG;IAC7B,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,CAAC;IACT,MAAM,EAAE;QACN,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,KAAK;KACb;CACF,CAAA;AAED,MAAM,oBAAoB,GAAgB;IACxC,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,0BAA0B;IACvC,MAAM,EAAE,KAAK;CACd,CAAA;AAcD,MAAM,CAAC,OAAO,OAAO,cAAc;IAOjC,YACE,GAAW,EACX,UAAqC,EAAE,EACvC,QAAiB,EACjB,KAAa;QANL,uBAAkB,GAAG,KAAK,CAAA;QAQlC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ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
- import { DownloadResult } from '../lib/types';
2
- export default class StreamDownloadBuilder implements PromiseLike<DownloadResult<ReadableStream>> {
3
- private downloadFn;
4
- private shouldThrowOnError;
5
- constructor(downloadFn: () => Promise<Response>, shouldThrowOnError: boolean);
6
- then<TResult1 = DownloadResult<ReadableStream>, TResult2 = never>(onfulfilled?: ((value: DownloadResult<ReadableStream>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
7
- private execute;
8
- }
9
- //# sourceMappingURL=StreamDownloadBuilder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StreamDownloadBuilder.d.ts","sourceRoot":"","sources":["../../../src/packages/StreamDownloadBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,WAAW,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IACnF,OAAO,CAAC,UAAU;IAA2B,OAAO,CAAC,kBAAkB;gBAA/D,UAAU,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,EAAU,kBAAkB,EAAE,OAAO;IAE5F,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,cAAc,CAAC,EAAE,QAAQ,GAAG,KAAK,EAC9D,WAAW,CAAC,EACR,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAC7E,IAAI,EACR,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GACtE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAIjB,OAAO;CAoBtB"}
@@ -1,40 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { isStorageError } from '../lib/errors';
11
- export default class StreamDownloadBuilder {
12
- constructor(downloadFn, shouldThrowOnError) {
13
- this.downloadFn = downloadFn;
14
- this.shouldThrowOnError = shouldThrowOnError;
15
- }
16
- then(onfulfilled, onrejected) {
17
- return this.execute().then(onfulfilled, onrejected);
18
- }
19
- execute() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- try {
22
- const result = yield this.downloadFn();
23
- return {
24
- data: result.body,
25
- error: null,
26
- };
27
- }
28
- catch (error) {
29
- if (this.shouldThrowOnError) {
30
- throw error;
31
- }
32
- if (isStorageError(error)) {
33
- return { data: null, error };
34
- }
35
- throw error;
36
- }
37
- });
38
- }
39
- }
40
- //# sourceMappingURL=StreamDownloadBuilder.js.map