@uploadcare/upload-client 6.2.0 → 6.3.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.
@@ -42,7 +42,7 @@ function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
42
42
  }
43
43
 
44
44
  /**
45
- * setTimeout as Promise.
45
+ * SetTimeout as Promise.
46
46
  *
47
47
  * @param {number} ms Timeout in milliseconds.
48
48
  */
@@ -182,10 +182,10 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
182
182
  const requestMethod = method?.toUpperCase() || 'GET';
183
183
  let aborted = false;
184
184
  /**
185
- * Force synchronous flag to be off
186
- * Some chrome versions gets `InvalidAccessError` error when we set `responseType`
187
- * See https://xhr.spec.whatwg.org/#synchronous-flag
188
- * and https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
185
+ * Force synchronous flag to be off Some chrome versions gets
186
+ * `InvalidAccessError` error when we set `responseType` See
187
+ * https://xhr.spec.whatwg.org/#synchronous-flag and
188
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
189
189
  */
190
190
  xhr.open(requestMethod, url, true);
191
191
  if (headers) {
@@ -390,7 +390,7 @@ const getUrl = (base, path, query) => {
390
390
  return url.toString();
391
391
  };
392
392
 
393
- var version = '6.2.0';
393
+ var version = '6.3.0';
394
394
 
395
395
  const LIBRARY_NAME = 'UploadcareUploadClient';
396
396
  const LIBRARY_VERSION = version;
@@ -462,8 +462,8 @@ function getStoreValue(store) {
462
462
  }
463
463
 
464
464
  /**
465
- * Performs file uploading request to Uploadcare Upload API.
466
- * Can be canceled and has progress.
465
+ * Performs file uploading request to Uploadcare Upload API. Can be canceled and
466
+ * has progress.
467
467
  */
468
468
  function base(file, { publicKey, fileName, contentType, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
469
469
  return retryIfFailed(() => request({
@@ -505,9 +505,7 @@ var TypeEnum;
505
505
  TypeEnum["Token"] = "token";
506
506
  TypeEnum["FileInfo"] = "file_info";
507
507
  })(TypeEnum || (TypeEnum = {}));
508
- /**
509
- * Uploading files from URL.
510
- */
508
+ /** Uploading files from URL. */
511
509
  function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source = 'url', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
512
510
  return retryIfFailed(() => request({
513
511
  method: 'POST',
@@ -550,9 +548,7 @@ var Status;
550
548
  const isErrorResponse = (response) => {
551
549
  return 'status' in response && response.status === Status.Error;
552
550
  };
553
- /**
554
- * Checking upload status and working with file tokens.
555
- */
551
+ /** Checking upload status and working with file tokens. */
556
552
  function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes } = {}) {
557
553
  return retryIfFailed(() => request({
558
554
  method: 'GET',
@@ -581,9 +577,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
581
577
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
582
578
  }
583
579
 
584
- /**
585
- * Create files group.
586
- */
580
+ /** Create files group. */
587
581
  function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallback, secureSignature, secureExpire, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
588
582
  return retryIfFailed(() => request({
589
583
  method: 'POST',
@@ -611,9 +605,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
611
605
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
612
606
  }
613
607
 
614
- /**
615
- * Get info about group.
616
- */
608
+ /** Get info about group. */
617
609
  function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
618
610
  return retryIfFailed(() => request({
619
611
  method: 'GET',
@@ -638,9 +630,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
638
630
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
639
631
  }
640
632
 
641
- /**
642
- * Returns a JSON dictionary holding file info.
643
- */
633
+ /** Returns a JSON dictionary holding file info. */
644
634
  function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
645
635
  return retryIfFailed(() => request({
646
636
  method: 'GET',
@@ -665,9 +655,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
665
655
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
666
656
  }
667
657
 
668
- /**
669
- * Start multipart uploading.
670
- */
658
+ /** Start multipart uploading. */
671
659
  function multipartStart(size, { publicKey, contentType, fileName, multipartChunkSize = defaultSettings.multipartChunkSize, baseURL = '', secureSignature, secureExpire, store, signal, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
672
660
  return retryIfFailed(() => request({
673
661
  method: 'POST',
@@ -701,9 +689,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
701
689
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
702
690
  }
703
691
 
704
- /**
705
- * Complete multipart uploading.
706
- */
692
+ /** Complete multipart uploading. */
707
693
  function multipartUpload(part, url, { contentType, signal, onProgress, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
708
694
  return retryIfFailed(() => request({
709
695
  method: 'PUT',
@@ -731,9 +717,7 @@ function multipartUpload(part, url, { contentType, signal, onProgress, retryThro
731
717
  });
732
718
  }
733
719
 
734
- /**
735
- * Complete multipart uploading.
736
- */
720
+ /** Complete multipart uploading. */
737
721
  function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL, source = 'local', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
738
722
  return retryIfFailed(() => request({
739
723
  method: 'POST',
@@ -781,7 +765,7 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
781
765
  }
782
766
 
783
767
  class UploadcareFile {
784
- constructor(fileInfo, { baseCDN, fileName }) {
768
+ constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
785
769
  this.name = null;
786
770
  this.size = null;
787
771
  this.isStored = null;
@@ -796,9 +780,9 @@ class UploadcareFile {
796
780
  this.metadata = null;
797
781
  this.s3Bucket = null;
798
782
  const { uuid, s3Bucket } = fileInfo;
799
- const cdnUrl = `${baseCDN}/${uuid}/`;
783
+ const cdnUrl = getUrl(baseCDN, `${uuid}/`);
800
784
  const s3Url = s3Bucket
801
- ? `https://${s3Bucket}.s3.amazonaws.com/${uuid}/${fileInfo.filename}`
785
+ ? getUrl(`https://${s3Bucket}.s3.amazonaws.com/`, `${uuid}/${fileInfo.filename}`)
802
786
  : null;
803
787
  this.uuid = uuid;
804
788
  this.name = fileName || fileInfo.filename;
@@ -1238,16 +1222,12 @@ const getFileSize = async (file) => {
1238
1222
  throw new Error(`Unknown file type. Cannot determine file size.`);
1239
1223
  };
1240
1224
 
1241
- /**
1242
- * Check if FileData is multipart data.
1243
- */
1225
+ /** Check if FileData is multipart data. */
1244
1226
  const isMultipart = (fileSize, multipartMinFileSize = defaultSettings.multipartMinFileSize) => {
1245
1227
  return fileSize >= multipartMinFileSize;
1246
1228
  };
1247
1229
 
1248
- /**
1249
- * Uuid type guard.
1250
- */
1230
+ /** Uuid type guard. */
1251
1231
  const isUuid = (data) => {
1252
1232
  const UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}';
1253
1233
  const regExp = new RegExp(UUID_REGEX);
@@ -1402,9 +1382,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
1402
1382
  .then((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1403
1383
  };
1404
1384
 
1405
- /**
1406
- * Uploads file from provided data.
1407
- */
1385
+ /** Uploads file from provided data. */
1408
1386
  async function uploadFile(data, { publicKey, fileName, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartMinFileSize, multipartChunkSize, maxConcurrentRequests, baseCDN = defaultSettings.baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, pusherKey, metadata }) {
1409
1387
  if (isFileData(data)) {
1410
1388
  const fileSize = await getFileSize(data);
@@ -1505,9 +1483,7 @@ class UploadcareGroup {
1505
1483
  }
1506
1484
  }
1507
1485
 
1508
- /**
1509
- * FileData type guard.
1510
- */
1486
+ /** FileData type guard. */
1511
1487
  const isFileDataArray = (data) => {
1512
1488
  for (const item of data) {
1513
1489
  if (!isFileData(item)) {
@@ -1516,9 +1492,7 @@ const isFileDataArray = (data) => {
1516
1492
  }
1517
1493
  return true;
1518
1494
  };
1519
- /**
1520
- * Uuid type guard.
1521
- */
1495
+ /** Uuid type guard. */
1522
1496
  const isUuidArray = (data) => {
1523
1497
  for (const item of data) {
1524
1498
  if (!isUuid(item)) {
@@ -1527,9 +1501,7 @@ const isUuidArray = (data) => {
1527
1501
  }
1528
1502
  return true;
1529
1503
  };
1530
- /**
1531
- * Url type guard.
1532
- */
1504
+ /** Url type guard. */
1533
1505
  const isUrlArray = (data) => {
1534
1506
  for (const item of data) {
1535
1507
  if (!isUrl(item)) {
@@ -1603,9 +1575,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1603
1575
  });
1604
1576
  }
1605
1577
 
1606
- /**
1607
- * Populate options with settings.
1608
- */
1578
+ /** Populate options with settings. */
1609
1579
  const populateOptionsWithSettings = (options, settings) => ({
1610
1580
  ...settings,
1611
1581
  ...options
package/dist/index.d.ts CHANGED
@@ -168,8 +168,8 @@ export declare type BaseOptions = {
168
168
  metadata?: Metadata;
169
169
  };
170
170
  /**
171
- * Performs file uploading request to Uploadcare Upload API.
172
- * Can be canceled and has progress.
171
+ * Performs file uploading request to Uploadcare Upload API. Can be canceled and
172
+ * has progress.
173
173
  */
174
174
  export function base(file: SupportedFileInput, { publicKey, fileName, contentType, baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: BaseOptions): Promise<BaseResponse>;
175
175
  export declare enum TypeEnum {
@@ -202,9 +202,7 @@ export declare type FromUrlOptions = {
202
202
  retryNetworkErrorMaxTimes?: number;
203
203
  metadata?: Metadata;
204
204
  };
205
- /**
206
- * Uploading files from URL.
207
- */
205
+ /** Uploading files from URL. */
208
206
  export function fromUrl(sourceUrl: Url, { publicKey, baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: FromUrlOptions): Promise<FromUrlSuccessResponse>;
209
207
  export declare enum Status {
210
208
  Unknown = "unknown",
@@ -243,9 +241,7 @@ export declare type FromUrlStatusOptions = {
243
241
  retryThrottledRequestMaxTimes?: number;
244
242
  retryNetworkErrorMaxTimes?: number;
245
243
  };
246
- /**
247
- * Checking upload status and working with file tokens.
248
- */
244
+ /** Checking upload status and working with file tokens. */
249
245
  export function fromUrlStatus(token: Token, { publicKey, baseURL, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }?: FromUrlStatusOptions): Promise<FromUrlStatusResponse>;
250
246
  export declare type GroupOptions = {
251
247
  publicKey: string;
@@ -260,9 +256,7 @@ export declare type GroupOptions = {
260
256
  retryThrottledRequestMaxTimes?: number;
261
257
  retryNetworkErrorMaxTimes?: number;
262
258
  };
263
- /**
264
- * Create files group.
265
- */
259
+ /** Create files group. */
266
260
  export function group(uuids: Uuid[], { publicKey, baseURL, jsonpCallback, secureSignature, secureExpire, signal, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }: GroupOptions): Promise<GroupInfo>;
267
261
  export declare type GroupInfoOptions = {
268
262
  publicKey: string;
@@ -274,9 +268,7 @@ export declare type GroupInfoOptions = {
274
268
  retryThrottledRequestMaxTimes?: number;
275
269
  retryNetworkErrorMaxTimes?: number;
276
270
  };
277
- /**
278
- * Get info about group.
279
- */
271
+ /** Get info about group. */
280
272
  export function groupInfo(id: GroupId, { publicKey, baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }: GroupInfoOptions): Promise<GroupInfo>;
281
273
  export declare type InfoOptions = {
282
274
  publicKey: string;
@@ -288,9 +280,7 @@ export declare type InfoOptions = {
288
280
  retryThrottledRequestMaxTimes?: number;
289
281
  retryNetworkErrorMaxTimes?: number;
290
282
  };
291
- /**
292
- * Returns a JSON dictionary holding file info.
293
- */
283
+ /** Returns a JSON dictionary holding file info. */
294
284
  export function info(uuid: Uuid, { publicKey, baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }: InfoOptions): Promise<FileInfo>;
295
285
  export declare type MultipartStartOptions = {
296
286
  publicKey: string;
@@ -314,9 +304,7 @@ export declare type MultipartStartResponse = {
314
304
  parts: MultipartPart[];
315
305
  uuid: Uuid;
316
306
  };
317
- /**
318
- * Start multipart uploading.
319
- */
307
+ /** Start multipart uploading. */
320
308
  export function multipartStart(size: number, { publicKey, contentType, fileName, multipartChunkSize, baseURL, secureSignature, secureExpire, store, signal, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: MultipartStartOptions): Promise<MultipartStartResponse>;
321
309
  export declare type MultipartUploadOptions = {
322
310
  publicKey?: string;
@@ -330,9 +318,7 @@ export declare type MultipartUploadOptions = {
330
318
  export declare type MultipartUploadResponse = {
331
319
  code?: number;
332
320
  };
333
- /**
334
- * Complete multipart uploading.
335
- */
321
+ /** Complete multipart uploading. */
336
322
  export function multipartUpload(part: SupportedFileInput, url: MultipartPart, { contentType, signal, onProgress, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }: MultipartUploadOptions): Promise<MultipartUploadResponse>;
337
323
  export declare type MultipartCompleteOptions = {
338
324
  publicKey: string;
@@ -344,9 +330,7 @@ export declare type MultipartCompleteOptions = {
344
330
  retryThrottledRequestMaxTimes?: number;
345
331
  retryNetworkErrorMaxTimes?: number;
346
332
  };
347
- /**
348
- * Complete multipart uploading.
349
- */
333
+ /** Complete multipart uploading. */
350
334
  export function multipartComplete(uuid: Uuid, { publicKey, baseURL, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes }: MultipartCompleteOptions): Promise<FileInfo>;
351
335
  export declare class UploadcareFile {
352
336
  readonly uuid: Uuid;
@@ -363,7 +347,7 @@ export declare class UploadcareFile {
363
347
  readonly contentInfo: null | ContentInfo;
364
348
  readonly metadata: null | Metadata;
365
349
  readonly s3Bucket: null | string;
366
- constructor(fileInfo: FileInfo, { baseCDN, fileName }: {
350
+ constructor(fileInfo: FileInfo, { baseCDN, fileName }?: {
367
351
  baseCDN?: string;
368
352
  fileName?: string;
369
353
  });
@@ -392,9 +376,7 @@ export declare type FileFromOptions = {
392
376
  pusherKey?: string;
393
377
  metadata?: Metadata;
394
378
  };
395
- /**
396
- * Uploads file from provided data.
397
- */
379
+ /** Uploads file from provided data. */
398
380
  export declare function uploadFile(data: SupportedFileInput | Url | Uuid, { publicKey, fileName, baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartMinFileSize, multipartChunkSize, maxConcurrentRequests, baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, pusherKey, metadata }: FileFromOptions): Promise<UploadcareFile>;
399
381
  export declare type DirectOptions = {
400
382
  publicKey: string;
@@ -49,7 +49,7 @@ function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
49
49
  }
50
50
 
51
51
  /**
52
- * setTimeout as Promise.
52
+ * SetTimeout as Promise.
53
53
  *
54
54
  * @param {number} ms Timeout in milliseconds.
55
55
  */
@@ -418,7 +418,7 @@ const getUrl = (base, path, query) => {
418
418
  return url.toString();
419
419
  };
420
420
 
421
- var version = '6.2.0';
421
+ var version = '6.3.0';
422
422
 
423
423
  const LIBRARY_NAME = 'UploadcareUploadClient';
424
424
  const LIBRARY_VERSION = version;
@@ -490,8 +490,8 @@ function getStoreValue(store) {
490
490
  }
491
491
 
492
492
  /**
493
- * Performs file uploading request to Uploadcare Upload API.
494
- * Can be canceled and has progress.
493
+ * Performs file uploading request to Uploadcare Upload API. Can be canceled and
494
+ * has progress.
495
495
  */
496
496
  function base(file, { publicKey, fileName, contentType, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
497
497
  return retryIfFailed(() => request({
@@ -533,9 +533,7 @@ var TypeEnum;
533
533
  TypeEnum["Token"] = "token";
534
534
  TypeEnum["FileInfo"] = "file_info";
535
535
  })(TypeEnum || (TypeEnum = {}));
536
- /**
537
- * Uploading files from URL.
538
- */
536
+ /** Uploading files from URL. */
539
537
  function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source = 'url', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
540
538
  return retryIfFailed(() => request({
541
539
  method: 'POST',
@@ -578,9 +576,7 @@ var Status;
578
576
  const isErrorResponse = (response) => {
579
577
  return 'status' in response && response.status === Status.Error;
580
578
  };
581
- /**
582
- * Checking upload status and working with file tokens.
583
- */
579
+ /** Checking upload status and working with file tokens. */
584
580
  function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes } = {}) {
585
581
  return retryIfFailed(() => request({
586
582
  method: 'GET',
@@ -609,9 +605,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
609
605
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
610
606
  }
611
607
 
612
- /**
613
- * Create files group.
614
- */
608
+ /** Create files group. */
615
609
  function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallback, secureSignature, secureExpire, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
616
610
  return retryIfFailed(() => request({
617
611
  method: 'POST',
@@ -639,9 +633,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
639
633
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
640
634
  }
641
635
 
642
- /**
643
- * Get info about group.
644
- */
636
+ /** Get info about group. */
645
637
  function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
646
638
  return retryIfFailed(() => request({
647
639
  method: 'GET',
@@ -666,9 +658,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
666
658
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
667
659
  }
668
660
 
669
- /**
670
- * Returns a JSON dictionary holding file info.
671
- */
661
+ /** Returns a JSON dictionary holding file info. */
672
662
  function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
673
663
  return retryIfFailed(() => request({
674
664
  method: 'GET',
@@ -693,9 +683,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
693
683
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
694
684
  }
695
685
 
696
- /**
697
- * Start multipart uploading.
698
- */
686
+ /** Start multipart uploading. */
699
687
  function multipartStart(size, { publicKey, contentType, fileName, multipartChunkSize = defaultSettings.multipartChunkSize, baseURL = '', secureSignature, secureExpire, store, signal, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
700
688
  return retryIfFailed(() => request({
701
689
  method: 'POST',
@@ -729,9 +717,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
729
717
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
730
718
  }
731
719
 
732
- /**
733
- * Complete multipart uploading.
734
- */
720
+ /** Complete multipart uploading. */
735
721
  function multipartUpload(part, url, { contentType, signal, onProgress, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
736
722
  return retryIfFailed(() => request({
737
723
  method: 'PUT',
@@ -759,9 +745,7 @@ function multipartUpload(part, url, { contentType, signal, onProgress, retryThro
759
745
  });
760
746
  }
761
747
 
762
- /**
763
- * Complete multipart uploading.
764
- */
748
+ /** Complete multipart uploading. */
765
749
  function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL, source = 'local', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
766
750
  return retryIfFailed(() => request({
767
751
  method: 'POST',
@@ -809,7 +793,7 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
809
793
  }
810
794
 
811
795
  class UploadcareFile {
812
- constructor(fileInfo, { baseCDN, fileName }) {
796
+ constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
813
797
  this.name = null;
814
798
  this.size = null;
815
799
  this.isStored = null;
@@ -824,9 +808,9 @@ class UploadcareFile {
824
808
  this.metadata = null;
825
809
  this.s3Bucket = null;
826
810
  const { uuid, s3Bucket } = fileInfo;
827
- const cdnUrl = `${baseCDN}/${uuid}/`;
811
+ const cdnUrl = getUrl(baseCDN, `${uuid}/`);
828
812
  const s3Url = s3Bucket
829
- ? `https://${s3Bucket}.s3.amazonaws.com/${uuid}/${fileInfo.filename}`
813
+ ? getUrl(`https://${s3Bucket}.s3.amazonaws.com/`, `${uuid}/${fileInfo.filename}`)
830
814
  : null;
831
815
  this.uuid = uuid;
832
816
  this.name = fileName || fileInfo.filename;
@@ -1264,16 +1248,12 @@ const getFileSize = async (file) => {
1264
1248
  throw new Error(`Unknown file type. Cannot determine file size.`);
1265
1249
  };
1266
1250
 
1267
- /**
1268
- * Check if FileData is multipart data.
1269
- */
1251
+ /** Check if FileData is multipart data. */
1270
1252
  const isMultipart = (fileSize, multipartMinFileSize = defaultSettings.multipartMinFileSize) => {
1271
1253
  return fileSize >= multipartMinFileSize;
1272
1254
  };
1273
1255
 
1274
- /**
1275
- * Uuid type guard.
1276
- */
1256
+ /** Uuid type guard. */
1277
1257
  const isUuid = (data) => {
1278
1258
  const UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}';
1279
1259
  const regExp = new RegExp(UUID_REGEX);
@@ -1428,9 +1408,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
1428
1408
  .then((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1429
1409
  };
1430
1410
 
1431
- /**
1432
- * Uploads file from provided data.
1433
- */
1411
+ /** Uploads file from provided data. */
1434
1412
  async function uploadFile(data, { publicKey, fileName, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartMinFileSize, multipartChunkSize, maxConcurrentRequests, baseCDN = defaultSettings.baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, pusherKey, metadata }) {
1435
1413
  if (isFileData(data)) {
1436
1414
  const fileSize = await getFileSize(data);
@@ -1531,9 +1509,7 @@ class UploadcareGroup {
1531
1509
  }
1532
1510
  }
1533
1511
 
1534
- /**
1535
- * FileData type guard.
1536
- */
1512
+ /** FileData type guard. */
1537
1513
  const isFileDataArray = (data) => {
1538
1514
  for (const item of data) {
1539
1515
  if (!isFileData(item)) {
@@ -1542,9 +1518,7 @@ const isFileDataArray = (data) => {
1542
1518
  }
1543
1519
  return true;
1544
1520
  };
1545
- /**
1546
- * Uuid type guard.
1547
- */
1521
+ /** Uuid type guard. */
1548
1522
  const isUuidArray = (data) => {
1549
1523
  for (const item of data) {
1550
1524
  if (!isUuid(item)) {
@@ -1553,9 +1527,7 @@ const isUuidArray = (data) => {
1553
1527
  }
1554
1528
  return true;
1555
1529
  };
1556
- /**
1557
- * Url type guard.
1558
- */
1530
+ /** Url type guard. */
1559
1531
  const isUrlArray = (data) => {
1560
1532
  for (const item of data) {
1561
1533
  if (!isUrl(item)) {
@@ -1629,9 +1601,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1629
1601
  });
1630
1602
  }
1631
1603
 
1632
- /**
1633
- * Populate options with settings.
1634
- */
1604
+ /** Populate options with settings. */
1635
1605
  const populateOptionsWithSettings = (options, settings) => ({
1636
1606
  ...settings,
1637
1607
  ...options
@@ -42,7 +42,7 @@ function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
42
42
  }
43
43
 
44
44
  /**
45
- * setTimeout as Promise.
45
+ * SetTimeout as Promise.
46
46
  *
47
47
  * @param {number} ms Timeout in milliseconds.
48
48
  */
@@ -182,10 +182,10 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
182
182
  const requestMethod = method?.toUpperCase() || 'GET';
183
183
  let aborted = false;
184
184
  /**
185
- * Force synchronous flag to be off
186
- * Some chrome versions gets `InvalidAccessError` error when we set `responseType`
187
- * See https://xhr.spec.whatwg.org/#synchronous-flag
188
- * and https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
185
+ * Force synchronous flag to be off Some chrome versions gets
186
+ * `InvalidAccessError` error when we set `responseType` See
187
+ * https://xhr.spec.whatwg.org/#synchronous-flag and
188
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
189
189
  */
190
190
  xhr.open(requestMethod, url, true);
191
191
  if (headers) {
@@ -398,7 +398,7 @@ const getUrl = (base, path, query) => {
398
398
  return url.toString();
399
399
  };
400
400
 
401
- var version = '6.2.0';
401
+ var version = '6.3.0';
402
402
 
403
403
  const LIBRARY_NAME = 'UploadcareUploadClient';
404
404
  const LIBRARY_VERSION = version;
@@ -470,8 +470,8 @@ function getStoreValue(store) {
470
470
  }
471
471
 
472
472
  /**
473
- * Performs file uploading request to Uploadcare Upload API.
474
- * Can be canceled and has progress.
473
+ * Performs file uploading request to Uploadcare Upload API. Can be canceled and
474
+ * has progress.
475
475
  */
476
476
  function base(file, { publicKey, fileName, contentType, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
477
477
  return retryIfFailed(() => request({
@@ -513,9 +513,7 @@ var TypeEnum;
513
513
  TypeEnum["Token"] = "token";
514
514
  TypeEnum["FileInfo"] = "file_info";
515
515
  })(TypeEnum || (TypeEnum = {}));
516
- /**
517
- * Uploading files from URL.
518
- */
516
+ /** Uploading files from URL. */
519
517
  function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source = 'url', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
520
518
  return retryIfFailed(() => request({
521
519
  method: 'POST',
@@ -558,9 +556,7 @@ var Status;
558
556
  const isErrorResponse = (response) => {
559
557
  return 'status' in response && response.status === Status.Error;
560
558
  };
561
- /**
562
- * Checking upload status and working with file tokens.
563
- */
559
+ /** Checking upload status and working with file tokens. */
564
560
  function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes } = {}) {
565
561
  return retryIfFailed(() => request({
566
562
  method: 'GET',
@@ -589,9 +585,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
589
585
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
590
586
  }
591
587
 
592
- /**
593
- * Create files group.
594
- */
588
+ /** Create files group. */
595
589
  function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallback, secureSignature, secureExpire, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
596
590
  return retryIfFailed(() => request({
597
591
  method: 'POST',
@@ -619,9 +613,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
619
613
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
620
614
  }
621
615
 
622
- /**
623
- * Get info about group.
624
- */
616
+ /** Get info about group. */
625
617
  function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
626
618
  return retryIfFailed(() => request({
627
619
  method: 'GET',
@@ -646,9 +638,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
646
638
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
647
639
  }
648
640
 
649
- /**
650
- * Returns a JSON dictionary holding file info.
651
- */
641
+ /** Returns a JSON dictionary holding file info. */
652
642
  function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, source, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
653
643
  return retryIfFailed(() => request({
654
644
  method: 'GET',
@@ -673,9 +663,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
673
663
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
674
664
  }
675
665
 
676
- /**
677
- * Start multipart uploading.
678
- */
666
+ /** Start multipart uploading. */
679
667
  function multipartStart(size, { publicKey, contentType, fileName, multipartChunkSize = defaultSettings.multipartChunkSize, baseURL = '', secureSignature, secureExpire, store, signal, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes, metadata }) {
680
668
  return retryIfFailed(() => request({
681
669
  method: 'POST',
@@ -709,9 +697,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
709
697
  }), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
710
698
  }
711
699
 
712
- /**
713
- * Complete multipart uploading.
714
- */
700
+ /** Complete multipart uploading. */
715
701
  function multipartUpload(part, url, { contentType, signal, onProgress, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
716
702
  return retryIfFailed(() => request({
717
703
  method: 'PUT',
@@ -739,9 +725,7 @@ function multipartUpload(part, url, { contentType, signal, onProgress, retryThro
739
725
  });
740
726
  }
741
727
 
742
- /**
743
- * Complete multipart uploading.
744
- */
728
+ /** Complete multipart uploading. */
745
729
  function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL, source = 'local', signal, integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes = defaultSettings.retryNetworkErrorMaxTimes }) {
746
730
  return retryIfFailed(() => request({
747
731
  method: 'POST',
@@ -789,7 +773,7 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
789
773
  }
790
774
 
791
775
  class UploadcareFile {
792
- constructor(fileInfo, { baseCDN, fileName }) {
776
+ constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
793
777
  this.name = null;
794
778
  this.size = null;
795
779
  this.isStored = null;
@@ -804,9 +788,9 @@ class UploadcareFile {
804
788
  this.metadata = null;
805
789
  this.s3Bucket = null;
806
790
  const { uuid, s3Bucket } = fileInfo;
807
- const cdnUrl = `${baseCDN}/${uuid}/`;
791
+ const cdnUrl = getUrl(baseCDN, `${uuid}/`);
808
792
  const s3Url = s3Bucket
809
- ? `https://${s3Bucket}.s3.amazonaws.com/${uuid}/${fileInfo.filename}`
793
+ ? getUrl(`https://${s3Bucket}.s3.amazonaws.com/`, `${uuid}/${fileInfo.filename}`)
810
794
  : null;
811
795
  this.uuid = uuid;
812
796
  this.name = fileName || fileInfo.filename;
@@ -1246,16 +1230,12 @@ const getFileSize = async (file) => {
1246
1230
  throw new Error(`Unknown file type. Cannot determine file size.`);
1247
1231
  };
1248
1232
 
1249
- /**
1250
- * Check if FileData is multipart data.
1251
- */
1233
+ /** Check if FileData is multipart data. */
1252
1234
  const isMultipart = (fileSize, multipartMinFileSize = defaultSettings.multipartMinFileSize) => {
1253
1235
  return fileSize >= multipartMinFileSize;
1254
1236
  };
1255
1237
 
1256
- /**
1257
- * Uuid type guard.
1258
- */
1238
+ /** Uuid type guard. */
1259
1239
  const isUuid = (data) => {
1260
1240
  const UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}';
1261
1241
  const regExp = new RegExp(UUID_REGEX);
@@ -1316,12 +1296,12 @@ const sliceChunk = (file, index, fileSize, chunkSize) => {
1316
1296
  /**
1317
1297
  * React-native hack for blob slicing
1318
1298
  *
1319
- * We need to store references to sliced blobs to prevent source blob from
1320
- * being deallocated until uploading complete. Access to deallocated blob
1321
- * causes app crash.
1299
+ * We need to store references to sliced blobs to prevent source blob from being
1300
+ * deallocated until uploading complete. Access to deallocated blob causes app
1301
+ * crash.
1322
1302
  *
1323
- * See https://github.com/uploadcare/uploadcare-js-api-clients/issues/306
1324
- * and https://github.com/facebook/react-native/issues/27543
1303
+ * See https://github.com/uploadcare/uploadcare-js-api-clients/issues/306 and
1304
+ * https://github.com/facebook/react-native/issues/27543
1325
1305
  */
1326
1306
  const prepareChunks = async (file, fileSize, chunkSize) => {
1327
1307
  let blob;
@@ -1430,9 +1410,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
1430
1410
  .then((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1431
1411
  };
1432
1412
 
1433
- /**
1434
- * Uploads file from provided data.
1435
- */
1413
+ /** Uploads file from provided data. */
1436
1414
  async function uploadFile(data, { publicKey, fileName, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartMinFileSize, multipartChunkSize, maxConcurrentRequests, baseCDN = defaultSettings.baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, pusherKey, metadata }) {
1437
1415
  if (isFileData(data)) {
1438
1416
  const fileSize = await getFileSize(data);
@@ -1533,9 +1511,7 @@ class UploadcareGroup {
1533
1511
  }
1534
1512
  }
1535
1513
 
1536
- /**
1537
- * FileData type guard.
1538
- */
1514
+ /** FileData type guard. */
1539
1515
  const isFileDataArray = (data) => {
1540
1516
  for (const item of data) {
1541
1517
  if (!isFileData(item)) {
@@ -1544,9 +1520,7 @@ const isFileDataArray = (data) => {
1544
1520
  }
1545
1521
  return true;
1546
1522
  };
1547
- /**
1548
- * Uuid type guard.
1549
- */
1523
+ /** Uuid type guard. */
1550
1524
  const isUuidArray = (data) => {
1551
1525
  for (const item of data) {
1552
1526
  if (!isUuid(item)) {
@@ -1555,9 +1529,7 @@ const isUuidArray = (data) => {
1555
1529
  }
1556
1530
  return true;
1557
1531
  };
1558
- /**
1559
- * Url type guard.
1560
- */
1532
+ /** Url type guard. */
1561
1533
  const isUrlArray = (data) => {
1562
1534
  for (const item of data) {
1563
1535
  if (!isUrl(item)) {
@@ -1631,9 +1603,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1631
1603
  });
1632
1604
  }
1633
1605
 
1634
- /**
1635
- * Populate options with settings.
1636
- */
1606
+ /** Populate options with settings. */
1637
1607
  const populateOptionsWithSettings = (options, settings) => ({
1638
1608
  ...settings,
1639
1609
  ...options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/upload-client",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "Library for work with Uploadcare Upload API",
5
5
  "type": "module",
6
6
  "module": "./dist/index.node.js",
@@ -78,7 +78,7 @@
78
78
  "koa-body": "5.0.0",
79
79
  "mock-socket": "9.0.3",
80
80
  "start-server-and-test": "1.14.0",
81
- "@uploadcare/api-client-utils": "^6.2.0",
81
+ "@uploadcare/api-client-utils": "^6.3.0",
82
82
  "chalk": "^4.1.2"
83
83
  },
84
84
  "dependencies": {