@uploadcare/upload-client 6.6.0 → 6.7.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.
@@ -281,15 +281,14 @@ const getFileOptions = ({ name }) => name ? [name] : [];
281
281
  const transformFile = identity;
282
282
  var getFormData = () => new FormData();
283
283
 
284
+ const isBuffer = (data) => false;
285
+
284
286
  const isBlob = (data) => {
285
287
  return typeof Blob !== 'undefined' && data instanceof Blob;
286
288
  };
287
289
  const isFile = (data) => {
288
290
  return typeof File !== 'undefined' && data instanceof File;
289
291
  };
290
- const isBuffer = (data) => {
291
- return typeof Buffer !== 'undefined' && data instanceof Buffer;
292
- };
293
292
  const isReactNativeAsset = (data) => {
294
293
  return (!!data &&
295
294
  typeof data === 'object' &&
@@ -298,7 +297,7 @@ const isReactNativeAsset = (data) => {
298
297
  typeof data.uri === 'string');
299
298
  };
300
299
  const isFileData = (data) => {
301
- return (isBlob(data) || isFile(data) || isBuffer(data) || isReactNativeAsset(data));
300
+ return (isBlob(data) || isFile(data) || isBuffer() || isReactNativeAsset(data));
302
301
  };
303
302
 
304
303
  const isSimpleValue = (value) => {
@@ -398,7 +397,7 @@ const getUrl = (base, path, query) => {
398
397
  return url.toString();
399
398
  };
400
399
 
401
- var version = '6.6.0';
400
+ var version = '6.7.0';
402
401
 
403
402
  const LIBRARY_NAME = 'UploadcareUploadClient';
404
403
  const LIBRARY_VERSION = version;
@@ -453,7 +452,7 @@ const getFileName = (file) => {
453
452
  if (isFile(file) && file.name) {
454
453
  filename = file.name;
455
454
  }
456
- else if (isBlob(file) || isBuffer(file)) {
455
+ else if (isBlob(file) || isBuffer()) {
457
456
  filename = '';
458
457
  }
459
458
  else if (isReactNativeAsset(file) && file.name) {
@@ -772,6 +771,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
772
771
  });
773
772
  }
774
773
 
774
+ function isGroupFileInfo(fileInfo) {
775
+ return 'defaultEffects' in fileInfo;
776
+ }
775
777
  class UploadcareFile {
776
778
  uuid;
777
779
  name = null;
@@ -787,6 +789,7 @@ class UploadcareFile {
787
789
  contentInfo = null;
788
790
  metadata = null;
789
791
  s3Bucket = null;
792
+ defaultEffects = null;
790
793
  constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
791
794
  const { uuid, s3Bucket } = fileInfo;
792
795
  const cdnUrl = getUrl(baseCDN, `${uuid}/`);
@@ -807,6 +810,9 @@ class UploadcareFile {
807
810
  this.metadata = fileInfo.metadata || null;
808
811
  this.s3Bucket = s3Bucket || null;
809
812
  this.s3Url = s3Url;
813
+ if (isGroupFileInfo(fileInfo)) {
814
+ this.defaultEffects = fileInfo.defaultEffects;
815
+ }
810
816
  }
811
817
  }
812
818
 
@@ -1218,9 +1224,6 @@ const getBlobFromReactNativeAsset = async (asset) => {
1218
1224
  };
1219
1225
 
1220
1226
  const getFileSize = async (file) => {
1221
- if (isBuffer(file)) {
1222
- return file.length;
1223
- }
1224
1227
  if (isFile(file) || isBlob(file)) {
1225
1228
  return file.size;
1226
1229
  }
@@ -1487,14 +1490,16 @@ class UploadcareGroup {
1487
1490
  files;
1488
1491
  createdAt;
1489
1492
  storedAt = null;
1490
- constructor(groupInfo, files) {
1493
+ constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
1491
1494
  this.uuid = groupInfo.id;
1492
1495
  this.filesCount = groupInfo.filesCount;
1493
- this.totalSize = Object.values(groupInfo.files).reduce((acc, file) => acc + file.size, 0);
1496
+ const groupFiles = groupInfo.files.filter(Boolean);
1497
+ this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
1494
1498
  this.isStored = !!groupInfo.datetimeStored;
1495
- this.isImage = !!Object.values(groupInfo.files).filter((file) => file.isImage).length;
1499
+ this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
1500
+ .length;
1496
1501
  this.cdnUrl = groupInfo.cdnUrl;
1497
- this.files = files;
1502
+ this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1498
1503
  this.createdAt = groupInfo.datetimeCreated;
1499
1504
  this.storedAt = groupInfo.datetimeStored;
1500
1505
  }
@@ -1552,27 +1557,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1552
1557
  onProgress({ isComputable: true, value: normalize(progressValues) });
1553
1558
  };
1554
1559
  };
1555
- return Promise.all(data.map((file, index) => uploadFile(file, {
1556
- publicKey,
1557
- fileName,
1558
- baseURL,
1559
- secureSignature,
1560
- secureExpire,
1561
- store,
1562
- signal,
1563
- onProgress: createProgressHandler(filesCount, index),
1564
- source,
1565
- integration,
1566
- userAgent,
1567
- retryThrottledRequestMaxTimes,
1568
- retryNetworkErrorMaxTimes,
1569
- contentType,
1570
- multipartChunkSize,
1571
- baseCDN,
1572
- checkForUrlDuplicates,
1573
- saveUrlForRecurrentUploads
1574
- }))).then((files) => {
1575
- const uuids = files.map((file) => file.uuid);
1560
+ return Promise.all(data.map((file, index) => {
1561
+ if (isFileData(file) || isUrl(file)) {
1562
+ return uploadFile(file, {
1563
+ publicKey,
1564
+ fileName,
1565
+ baseURL,
1566
+ secureSignature,
1567
+ secureExpire,
1568
+ store,
1569
+ signal,
1570
+ onProgress: createProgressHandler(filesCount, index),
1571
+ source,
1572
+ integration,
1573
+ userAgent,
1574
+ retryThrottledRequestMaxTimes,
1575
+ retryNetworkErrorMaxTimes,
1576
+ contentType,
1577
+ multipartChunkSize,
1578
+ baseCDN,
1579
+ checkForUrlDuplicates,
1580
+ saveUrlForRecurrentUploads
1581
+ }).then((fileInfo) => fileInfo.uuid);
1582
+ }
1583
+ else {
1584
+ // Do not request file info by uuid before creating group because this isn't necessary
1585
+ return file;
1586
+ }
1587
+ })).then((uuids) => {
1576
1588
  return group(uuids, {
1577
1589
  publicKey,
1578
1590
  baseURL,
@@ -1586,7 +1598,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1586
1598
  retryThrottledRequestMaxTimes,
1587
1599
  retryNetworkErrorMaxTimes
1588
1600
  })
1589
- .then((groupInfo) => new UploadcareGroup(groupInfo, files))
1601
+ .then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
1590
1602
  .then((group) => {
1591
1603
  onProgress && onProgress({ isComputable: true, value: 1 });
1592
1604
  return group;
@@ -1657,32 +1669,32 @@ class UploadClient {
1657
1669
  }
1658
1670
 
1659
1671
  class Queue {
1660
- #concurrency = 1;
1661
- #pending = [];
1662
- #running = 0;
1663
- #resolvers = new WeakMap();
1664
- #rejectors = new WeakMap();
1672
+ _concurrency = 1;
1673
+ _pending = [];
1674
+ _running = 0;
1675
+ _resolvers = new Map();
1676
+ _rejectors = new Map();
1665
1677
  constructor(concurrency) {
1666
- this.#concurrency = concurrency;
1678
+ this._concurrency = concurrency;
1667
1679
  }
1668
- #run() {
1669
- const tasksLeft = this.#concurrency - this.#running;
1680
+ _run() {
1681
+ const tasksLeft = this._concurrency - this._running;
1670
1682
  for (let i = 0; i < tasksLeft; i++) {
1671
- const task = this.#pending.shift();
1683
+ const task = this._pending.shift();
1672
1684
  if (!task) {
1673
1685
  return;
1674
1686
  }
1675
- const resolver = this.#resolvers.get(task);
1676
- const rejector = this.#rejectors.get(task);
1687
+ const resolver = this._resolvers.get(task);
1688
+ const rejector = this._rejectors.get(task);
1677
1689
  if (!resolver || !rejector)
1678
1690
  throw new Error('Unexpected behavior: resolver or rejector is undefined');
1679
- this.#running += 1;
1691
+ this._running += 1;
1680
1692
  task()
1681
1693
  .finally(() => {
1682
- this.#resolvers.delete(task);
1683
- this.#rejectors.delete(task);
1684
- this.#running -= 1;
1685
- this.#run();
1694
+ this._resolvers.delete(task);
1695
+ this._rejectors.delete(task);
1696
+ this._running -= 1;
1697
+ this._run();
1686
1698
  })
1687
1699
  .then((value) => resolver(value))
1688
1700
  .catch((error) => rejector(error));
@@ -1690,24 +1702,24 @@ class Queue {
1690
1702
  }
1691
1703
  add(task) {
1692
1704
  return new Promise((resolve, reject) => {
1693
- this.#resolvers.set(task, resolve);
1694
- this.#rejectors.set(task, reject);
1695
- this.#pending.push(task);
1696
- this.#run();
1705
+ this._resolvers.set(task, resolve);
1706
+ this._rejectors.set(task, reject);
1707
+ this._pending.push(task);
1708
+ this._run();
1697
1709
  });
1698
1710
  }
1699
1711
  get pending() {
1700
- return this.#pending.length;
1712
+ return this._pending.length;
1701
1713
  }
1702
1714
  get running() {
1703
- return this.#running;
1715
+ return this._running;
1704
1716
  }
1705
1717
  set concurrency(value) {
1706
- this.#concurrency = value;
1707
- this.#run();
1718
+ this._concurrency = value;
1719
+ this._run();
1708
1720
  }
1709
1721
  get concurrency() {
1710
- return this.#concurrency;
1722
+ return this._concurrency;
1711
1723
  }
1712
1724
  }
1713
1725
 
@@ -126,12 +126,15 @@ export type FileInfo = {
126
126
  s3Bucket?: string;
127
127
  metadata?: Metadata;
128
128
  };
129
+ export type GroupFileInfo = FileInfo & {
130
+ defaultEffects: string;
131
+ };
129
132
  export type GroupInfo = {
130
133
  datetimeCreated: string;
131
134
  datetimeStored: string | null;
132
135
  filesCount: string;
133
136
  cdnUrl: string;
134
- files: FileInfo[];
137
+ files: (GroupFileInfo | null)[];
135
138
  url: string;
136
139
  id: GroupId;
137
140
  };
@@ -347,7 +350,8 @@ export declare class UploadcareFile {
347
350
  readonly contentInfo: null | ContentInfo;
348
351
  readonly metadata: null | Metadata;
349
352
  readonly s3Bucket: null | string;
350
- constructor(fileInfo: FileInfo, { baseCDN, fileName }?: {
353
+ readonly defaultEffects: null | string;
354
+ constructor(fileInfo: FileInfo | GroupFileInfo, { baseCDN, fileName }?: {
351
355
  baseCDN?: string;
352
356
  fileName?: string;
353
357
  });
@@ -449,7 +453,9 @@ export declare class UploadcareGroup {
449
453
  readonly files: UploadcareFile[];
450
454
  readonly createdAt: string;
451
455
  readonly storedAt: string | null;
452
- constructor(groupInfo: GroupInfo, files: UploadcareFile[]);
456
+ constructor(groupInfo: GroupInfo, { baseCDN }?: {
457
+ baseCDN?: string;
458
+ });
453
459
  }
454
460
  export type GroupFromOptions = {
455
461
  jsonpCallback?: string;
@@ -474,8 +480,13 @@ export declare class UploadClient {
474
480
  }
475
481
  export type Task<T = unknown> = () => Promise<T>;
476
482
  export declare class Queue {
477
- #private;
483
+ private _concurrency;
484
+ private _pending;
485
+ private _running;
486
+ private _resolvers;
487
+ private _rejectors;
478
488
  constructor(concurrency: number);
489
+ private _run;
479
490
  add<T>(task: Task<T>): Promise<T>;
480
491
  get pending(): number;
481
492
  get running(): number;
@@ -312,15 +312,14 @@ const getFileOptions = ({ name, contentType }) => [
312
312
  const transformFile = identity;
313
313
  var getFormData = () => new NodeFormData();
314
314
 
315
+ const isBuffer = (data) => data instanceof Buffer;
316
+
315
317
  const isBlob = (data) => {
316
318
  return typeof Blob !== 'undefined' && data instanceof Blob;
317
319
  };
318
320
  const isFile = (data) => {
319
321
  return typeof File !== 'undefined' && data instanceof File;
320
322
  };
321
- const isBuffer = (data) => {
322
- return typeof Buffer !== 'undefined' && data instanceof Buffer;
323
- };
324
323
  const isReactNativeAsset = (data) => {
325
324
  return (!!data &&
326
325
  typeof data === 'object' &&
@@ -429,7 +428,7 @@ const getUrl = (base, path, query) => {
429
428
  return url.toString();
430
429
  };
431
430
 
432
- var version = '6.6.0';
431
+ var version = '6.7.0';
433
432
 
434
433
  const LIBRARY_NAME = 'UploadcareUploadClient';
435
434
  const LIBRARY_VERSION = version;
@@ -803,6 +802,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
803
802
  });
804
803
  }
805
804
 
805
+ function isGroupFileInfo(fileInfo) {
806
+ return 'defaultEffects' in fileInfo;
807
+ }
806
808
  class UploadcareFile {
807
809
  uuid;
808
810
  name = null;
@@ -818,6 +820,7 @@ class UploadcareFile {
818
820
  contentInfo = null;
819
821
  metadata = null;
820
822
  s3Bucket = null;
823
+ defaultEffects = null;
821
824
  constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
822
825
  const { uuid, s3Bucket } = fileInfo;
823
826
  const cdnUrl = getUrl(baseCDN, `${uuid}/`);
@@ -838,6 +841,9 @@ class UploadcareFile {
838
841
  this.metadata = fileInfo.metadata || null;
839
842
  this.s3Bucket = s3Bucket || null;
840
843
  this.s3Url = s3Url;
844
+ if (isGroupFileInfo(fileInfo)) {
845
+ this.defaultEffects = fileInfo.defaultEffects;
846
+ }
841
847
  }
842
848
  }
843
849
 
@@ -1516,14 +1522,16 @@ class UploadcareGroup {
1516
1522
  files;
1517
1523
  createdAt;
1518
1524
  storedAt = null;
1519
- constructor(groupInfo, files) {
1525
+ constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
1520
1526
  this.uuid = groupInfo.id;
1521
1527
  this.filesCount = groupInfo.filesCount;
1522
- this.totalSize = Object.values(groupInfo.files).reduce((acc, file) => acc + file.size, 0);
1528
+ const groupFiles = groupInfo.files.filter(Boolean);
1529
+ this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
1523
1530
  this.isStored = !!groupInfo.datetimeStored;
1524
- this.isImage = !!Object.values(groupInfo.files).filter((file) => file.isImage).length;
1531
+ this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
1532
+ .length;
1525
1533
  this.cdnUrl = groupInfo.cdnUrl;
1526
- this.files = files;
1534
+ this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1527
1535
  this.createdAt = groupInfo.datetimeCreated;
1528
1536
  this.storedAt = groupInfo.datetimeStored;
1529
1537
  }
@@ -1581,27 +1589,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1581
1589
  onProgress({ isComputable: true, value: normalize(progressValues) });
1582
1590
  };
1583
1591
  };
1584
- return Promise.all(data.map((file, index) => uploadFile(file, {
1585
- publicKey,
1586
- fileName,
1587
- baseURL,
1588
- secureSignature,
1589
- secureExpire,
1590
- store,
1591
- signal,
1592
- onProgress: createProgressHandler(filesCount, index),
1593
- source,
1594
- integration,
1595
- userAgent,
1596
- retryThrottledRequestMaxTimes,
1597
- retryNetworkErrorMaxTimes,
1598
- contentType,
1599
- multipartChunkSize,
1600
- baseCDN,
1601
- checkForUrlDuplicates,
1602
- saveUrlForRecurrentUploads
1603
- }))).then((files) => {
1604
- const uuids = files.map((file) => file.uuid);
1592
+ return Promise.all(data.map((file, index) => {
1593
+ if (isFileData(file) || isUrl(file)) {
1594
+ return uploadFile(file, {
1595
+ publicKey,
1596
+ fileName,
1597
+ baseURL,
1598
+ secureSignature,
1599
+ secureExpire,
1600
+ store,
1601
+ signal,
1602
+ onProgress: createProgressHandler(filesCount, index),
1603
+ source,
1604
+ integration,
1605
+ userAgent,
1606
+ retryThrottledRequestMaxTimes,
1607
+ retryNetworkErrorMaxTimes,
1608
+ contentType,
1609
+ multipartChunkSize,
1610
+ baseCDN,
1611
+ checkForUrlDuplicates,
1612
+ saveUrlForRecurrentUploads
1613
+ }).then((fileInfo) => fileInfo.uuid);
1614
+ }
1615
+ else {
1616
+ // Do not request file info by uuid before creating group because this isn't necessary
1617
+ return file;
1618
+ }
1619
+ })).then((uuids) => {
1605
1620
  return group(uuids, {
1606
1621
  publicKey,
1607
1622
  baseURL,
@@ -1615,7 +1630,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1615
1630
  retryThrottledRequestMaxTimes,
1616
1631
  retryNetworkErrorMaxTimes
1617
1632
  })
1618
- .then((groupInfo) => new UploadcareGroup(groupInfo, files))
1633
+ .then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
1619
1634
  .then((group) => {
1620
1635
  onProgress && onProgress({ isComputable: true, value: 1 });
1621
1636
  return group;
@@ -1686,32 +1701,32 @@ class UploadClient {
1686
1701
  }
1687
1702
 
1688
1703
  class Queue {
1689
- #concurrency = 1;
1690
- #pending = [];
1691
- #running = 0;
1692
- #resolvers = new WeakMap();
1693
- #rejectors = new WeakMap();
1704
+ _concurrency = 1;
1705
+ _pending = [];
1706
+ _running = 0;
1707
+ _resolvers = new Map();
1708
+ _rejectors = new Map();
1694
1709
  constructor(concurrency) {
1695
- this.#concurrency = concurrency;
1710
+ this._concurrency = concurrency;
1696
1711
  }
1697
- #run() {
1698
- const tasksLeft = this.#concurrency - this.#running;
1712
+ _run() {
1713
+ const tasksLeft = this._concurrency - this._running;
1699
1714
  for (let i = 0; i < tasksLeft; i++) {
1700
- const task = this.#pending.shift();
1715
+ const task = this._pending.shift();
1701
1716
  if (!task) {
1702
1717
  return;
1703
1718
  }
1704
- const resolver = this.#resolvers.get(task);
1705
- const rejector = this.#rejectors.get(task);
1719
+ const resolver = this._resolvers.get(task);
1720
+ const rejector = this._rejectors.get(task);
1706
1721
  if (!resolver || !rejector)
1707
1722
  throw new Error('Unexpected behavior: resolver or rejector is undefined');
1708
- this.#running += 1;
1723
+ this._running += 1;
1709
1724
  task()
1710
1725
  .finally(() => {
1711
- this.#resolvers.delete(task);
1712
- this.#rejectors.delete(task);
1713
- this.#running -= 1;
1714
- this.#run();
1726
+ this._resolvers.delete(task);
1727
+ this._rejectors.delete(task);
1728
+ this._running -= 1;
1729
+ this._run();
1715
1730
  })
1716
1731
  .then((value) => resolver(value))
1717
1732
  .catch((error) => rejector(error));
@@ -1719,24 +1734,24 @@ class Queue {
1719
1734
  }
1720
1735
  add(task) {
1721
1736
  return new Promise((resolve, reject) => {
1722
- this.#resolvers.set(task, resolve);
1723
- this.#rejectors.set(task, reject);
1724
- this.#pending.push(task);
1725
- this.#run();
1737
+ this._resolvers.set(task, resolve);
1738
+ this._rejectors.set(task, reject);
1739
+ this._pending.push(task);
1740
+ this._run();
1726
1741
  });
1727
1742
  }
1728
1743
  get pending() {
1729
- return this.#pending.length;
1744
+ return this._pending.length;
1730
1745
  }
1731
1746
  get running() {
1732
- return this.#running;
1747
+ return this._running;
1733
1748
  }
1734
1749
  set concurrency(value) {
1735
- this.#concurrency = value;
1736
- this.#run();
1750
+ this._concurrency = value;
1751
+ this._run();
1737
1752
  }
1738
1753
  get concurrency() {
1739
- return this.#concurrency;
1754
+ return this._concurrency;
1740
1755
  }
1741
1756
  }
1742
1757
 
@@ -126,12 +126,15 @@ export type FileInfo = {
126
126
  s3Bucket?: string;
127
127
  metadata?: Metadata;
128
128
  };
129
+ export type GroupFileInfo = FileInfo & {
130
+ defaultEffects: string;
131
+ };
129
132
  export type GroupInfo = {
130
133
  datetimeCreated: string;
131
134
  datetimeStored: string | null;
132
135
  filesCount: string;
133
136
  cdnUrl: string;
134
- files: FileInfo[];
137
+ files: (GroupFileInfo | null)[];
135
138
  url: string;
136
139
  id: GroupId;
137
140
  };
@@ -347,7 +350,8 @@ export declare class UploadcareFile {
347
350
  readonly contentInfo: null | ContentInfo;
348
351
  readonly metadata: null | Metadata;
349
352
  readonly s3Bucket: null | string;
350
- constructor(fileInfo: FileInfo, { baseCDN, fileName }?: {
353
+ readonly defaultEffects: null | string;
354
+ constructor(fileInfo: FileInfo | GroupFileInfo, { baseCDN, fileName }?: {
351
355
  baseCDN?: string;
352
356
  fileName?: string;
353
357
  });
@@ -449,7 +453,9 @@ export declare class UploadcareGroup {
449
453
  readonly files: UploadcareFile[];
450
454
  readonly createdAt: string;
451
455
  readonly storedAt: string | null;
452
- constructor(groupInfo: GroupInfo, files: UploadcareFile[]);
456
+ constructor(groupInfo: GroupInfo, { baseCDN }?: {
457
+ baseCDN?: string;
458
+ });
453
459
  }
454
460
  export type GroupFromOptions = {
455
461
  jsonpCallback?: string;
@@ -474,8 +480,13 @@ export declare class UploadClient {
474
480
  }
475
481
  export type Task<T = unknown> = () => Promise<T>;
476
482
  export declare class Queue {
477
- #private;
483
+ private _concurrency;
484
+ private _pending;
485
+ private _running;
486
+ private _resolvers;
487
+ private _rejectors;
478
488
  constructor(concurrency: number);
489
+ private _run;
479
490
  add<T>(task: Task<T>): Promise<T>;
480
491
  get pending(): number;
481
492
  get running(): number;