@uploadcare/upload-client 6.6.1 → 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.
@@ -397,7 +397,7 @@ const getUrl = (base, path, query) => {
397
397
  return url.toString();
398
398
  };
399
399
 
400
- var version = '6.6.1';
400
+ var version = '6.7.0';
401
401
 
402
402
  const LIBRARY_NAME = 'UploadcareUploadClient';
403
403
  const LIBRARY_VERSION = version;
@@ -771,6 +771,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
771
771
  });
772
772
  }
773
773
 
774
+ function isGroupFileInfo(fileInfo) {
775
+ return 'defaultEffects' in fileInfo;
776
+ }
774
777
  class UploadcareFile {
775
778
  uuid;
776
779
  name = null;
@@ -786,6 +789,7 @@ class UploadcareFile {
786
789
  contentInfo = null;
787
790
  metadata = null;
788
791
  s3Bucket = null;
792
+ defaultEffects = null;
789
793
  constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
790
794
  const { uuid, s3Bucket } = fileInfo;
791
795
  const cdnUrl = getUrl(baseCDN, `${uuid}/`);
@@ -806,6 +810,9 @@ class UploadcareFile {
806
810
  this.metadata = fileInfo.metadata || null;
807
811
  this.s3Bucket = s3Bucket || null;
808
812
  this.s3Url = s3Url;
813
+ if (isGroupFileInfo(fileInfo)) {
814
+ this.defaultEffects = fileInfo.defaultEffects;
815
+ }
809
816
  }
810
817
  }
811
818
 
@@ -1483,14 +1490,16 @@ class UploadcareGroup {
1483
1490
  files;
1484
1491
  createdAt;
1485
1492
  storedAt = null;
1486
- constructor(groupInfo, files) {
1493
+ constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
1487
1494
  this.uuid = groupInfo.id;
1488
1495
  this.filesCount = groupInfo.filesCount;
1489
- 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);
1490
1498
  this.isStored = !!groupInfo.datetimeStored;
1491
- this.isImage = !!Object.values(groupInfo.files).filter((file) => file.isImage).length;
1499
+ this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
1500
+ .length;
1492
1501
  this.cdnUrl = groupInfo.cdnUrl;
1493
- this.files = files;
1502
+ this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1494
1503
  this.createdAt = groupInfo.datetimeCreated;
1495
1504
  this.storedAt = groupInfo.datetimeStored;
1496
1505
  }
@@ -1548,27 +1557,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1548
1557
  onProgress({ isComputable: true, value: normalize(progressValues) });
1549
1558
  };
1550
1559
  };
1551
- return Promise.all(data.map((file, index) => uploadFile(file, {
1552
- publicKey,
1553
- fileName,
1554
- baseURL,
1555
- secureSignature,
1556
- secureExpire,
1557
- store,
1558
- signal,
1559
- onProgress: createProgressHandler(filesCount, index),
1560
- source,
1561
- integration,
1562
- userAgent,
1563
- retryThrottledRequestMaxTimes,
1564
- retryNetworkErrorMaxTimes,
1565
- contentType,
1566
- multipartChunkSize,
1567
- baseCDN,
1568
- checkForUrlDuplicates,
1569
- saveUrlForRecurrentUploads
1570
- }))).then((files) => {
1571
- 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) => {
1572
1588
  return group(uuids, {
1573
1589
  publicKey,
1574
1590
  baseURL,
@@ -1582,7 +1598,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1582
1598
  retryThrottledRequestMaxTimes,
1583
1599
  retryNetworkErrorMaxTimes
1584
1600
  })
1585
- .then((groupInfo) => new UploadcareGroup(groupInfo, files))
1601
+ .then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
1586
1602
  .then((group) => {
1587
1603
  onProgress && onProgress({ isComputable: true, value: 1 });
1588
1604
  return group;
@@ -1653,32 +1669,32 @@ class UploadClient {
1653
1669
  }
1654
1670
 
1655
1671
  class Queue {
1656
- #concurrency = 1;
1657
- #pending = [];
1658
- #running = 0;
1659
- #resolvers = new WeakMap();
1660
- #rejectors = new WeakMap();
1672
+ _concurrency = 1;
1673
+ _pending = [];
1674
+ _running = 0;
1675
+ _resolvers = new Map();
1676
+ _rejectors = new Map();
1661
1677
  constructor(concurrency) {
1662
- this.#concurrency = concurrency;
1678
+ this._concurrency = concurrency;
1663
1679
  }
1664
- #run() {
1665
- const tasksLeft = this.#concurrency - this.#running;
1680
+ _run() {
1681
+ const tasksLeft = this._concurrency - this._running;
1666
1682
  for (let i = 0; i < tasksLeft; i++) {
1667
- const task = this.#pending.shift();
1683
+ const task = this._pending.shift();
1668
1684
  if (!task) {
1669
1685
  return;
1670
1686
  }
1671
- const resolver = this.#resolvers.get(task);
1672
- const rejector = this.#rejectors.get(task);
1687
+ const resolver = this._resolvers.get(task);
1688
+ const rejector = this._rejectors.get(task);
1673
1689
  if (!resolver || !rejector)
1674
1690
  throw new Error('Unexpected behavior: resolver or rejector is undefined');
1675
- this.#running += 1;
1691
+ this._running += 1;
1676
1692
  task()
1677
1693
  .finally(() => {
1678
- this.#resolvers.delete(task);
1679
- this.#rejectors.delete(task);
1680
- this.#running -= 1;
1681
- this.#run();
1694
+ this._resolvers.delete(task);
1695
+ this._rejectors.delete(task);
1696
+ this._running -= 1;
1697
+ this._run();
1682
1698
  })
1683
1699
  .then((value) => resolver(value))
1684
1700
  .catch((error) => rejector(error));
@@ -1686,24 +1702,24 @@ class Queue {
1686
1702
  }
1687
1703
  add(task) {
1688
1704
  return new Promise((resolve, reject) => {
1689
- this.#resolvers.set(task, resolve);
1690
- this.#rejectors.set(task, reject);
1691
- this.#pending.push(task);
1692
- this.#run();
1705
+ this._resolvers.set(task, resolve);
1706
+ this._rejectors.set(task, reject);
1707
+ this._pending.push(task);
1708
+ this._run();
1693
1709
  });
1694
1710
  }
1695
1711
  get pending() {
1696
- return this.#pending.length;
1712
+ return this._pending.length;
1697
1713
  }
1698
1714
  get running() {
1699
- return this.#running;
1715
+ return this._running;
1700
1716
  }
1701
1717
  set concurrency(value) {
1702
- this.#concurrency = value;
1703
- this.#run();
1718
+ this._concurrency = value;
1719
+ this._run();
1704
1720
  }
1705
1721
  get concurrency() {
1706
- return this.#concurrency;
1722
+ return this._concurrency;
1707
1723
  }
1708
1724
  }
1709
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;
@@ -428,7 +428,7 @@ const getUrl = (base, path, query) => {
428
428
  return url.toString();
429
429
  };
430
430
 
431
- var version = '6.6.1';
431
+ var version = '6.7.0';
432
432
 
433
433
  const LIBRARY_NAME = 'UploadcareUploadClient';
434
434
  const LIBRARY_VERSION = version;
@@ -802,6 +802,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
802
802
  });
803
803
  }
804
804
 
805
+ function isGroupFileInfo(fileInfo) {
806
+ return 'defaultEffects' in fileInfo;
807
+ }
805
808
  class UploadcareFile {
806
809
  uuid;
807
810
  name = null;
@@ -817,6 +820,7 @@ class UploadcareFile {
817
820
  contentInfo = null;
818
821
  metadata = null;
819
822
  s3Bucket = null;
823
+ defaultEffects = null;
820
824
  constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
821
825
  const { uuid, s3Bucket } = fileInfo;
822
826
  const cdnUrl = getUrl(baseCDN, `${uuid}/`);
@@ -837,6 +841,9 @@ class UploadcareFile {
837
841
  this.metadata = fileInfo.metadata || null;
838
842
  this.s3Bucket = s3Bucket || null;
839
843
  this.s3Url = s3Url;
844
+ if (isGroupFileInfo(fileInfo)) {
845
+ this.defaultEffects = fileInfo.defaultEffects;
846
+ }
840
847
  }
841
848
  }
842
849
 
@@ -1515,14 +1522,16 @@ class UploadcareGroup {
1515
1522
  files;
1516
1523
  createdAt;
1517
1524
  storedAt = null;
1518
- constructor(groupInfo, files) {
1525
+ constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
1519
1526
  this.uuid = groupInfo.id;
1520
1527
  this.filesCount = groupInfo.filesCount;
1521
- 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);
1522
1530
  this.isStored = !!groupInfo.datetimeStored;
1523
- this.isImage = !!Object.values(groupInfo.files).filter((file) => file.isImage).length;
1531
+ this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
1532
+ .length;
1524
1533
  this.cdnUrl = groupInfo.cdnUrl;
1525
- this.files = files;
1534
+ this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
1526
1535
  this.createdAt = groupInfo.datetimeCreated;
1527
1536
  this.storedAt = groupInfo.datetimeStored;
1528
1537
  }
@@ -1580,27 +1589,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1580
1589
  onProgress({ isComputable: true, value: normalize(progressValues) });
1581
1590
  };
1582
1591
  };
1583
- return Promise.all(data.map((file, index) => uploadFile(file, {
1584
- publicKey,
1585
- fileName,
1586
- baseURL,
1587
- secureSignature,
1588
- secureExpire,
1589
- store,
1590
- signal,
1591
- onProgress: createProgressHandler(filesCount, index),
1592
- source,
1593
- integration,
1594
- userAgent,
1595
- retryThrottledRequestMaxTimes,
1596
- retryNetworkErrorMaxTimes,
1597
- contentType,
1598
- multipartChunkSize,
1599
- baseCDN,
1600
- checkForUrlDuplicates,
1601
- saveUrlForRecurrentUploads
1602
- }))).then((files) => {
1603
- 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) => {
1604
1620
  return group(uuids, {
1605
1621
  publicKey,
1606
1622
  baseURL,
@@ -1614,7 +1630,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
1614
1630
  retryThrottledRequestMaxTimes,
1615
1631
  retryNetworkErrorMaxTimes
1616
1632
  })
1617
- .then((groupInfo) => new UploadcareGroup(groupInfo, files))
1633
+ .then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
1618
1634
  .then((group) => {
1619
1635
  onProgress && onProgress({ isComputable: true, value: 1 });
1620
1636
  return group;
@@ -1685,32 +1701,32 @@ class UploadClient {
1685
1701
  }
1686
1702
 
1687
1703
  class Queue {
1688
- #concurrency = 1;
1689
- #pending = [];
1690
- #running = 0;
1691
- #resolvers = new WeakMap();
1692
- #rejectors = new WeakMap();
1704
+ _concurrency = 1;
1705
+ _pending = [];
1706
+ _running = 0;
1707
+ _resolvers = new Map();
1708
+ _rejectors = new Map();
1693
1709
  constructor(concurrency) {
1694
- this.#concurrency = concurrency;
1710
+ this._concurrency = concurrency;
1695
1711
  }
1696
- #run() {
1697
- const tasksLeft = this.#concurrency - this.#running;
1712
+ _run() {
1713
+ const tasksLeft = this._concurrency - this._running;
1698
1714
  for (let i = 0; i < tasksLeft; i++) {
1699
- const task = this.#pending.shift();
1715
+ const task = this._pending.shift();
1700
1716
  if (!task) {
1701
1717
  return;
1702
1718
  }
1703
- const resolver = this.#resolvers.get(task);
1704
- const rejector = this.#rejectors.get(task);
1719
+ const resolver = this._resolvers.get(task);
1720
+ const rejector = this._rejectors.get(task);
1705
1721
  if (!resolver || !rejector)
1706
1722
  throw new Error('Unexpected behavior: resolver or rejector is undefined');
1707
- this.#running += 1;
1723
+ this._running += 1;
1708
1724
  task()
1709
1725
  .finally(() => {
1710
- this.#resolvers.delete(task);
1711
- this.#rejectors.delete(task);
1712
- this.#running -= 1;
1713
- this.#run();
1726
+ this._resolvers.delete(task);
1727
+ this._rejectors.delete(task);
1728
+ this._running -= 1;
1729
+ this._run();
1714
1730
  })
1715
1731
  .then((value) => resolver(value))
1716
1732
  .catch((error) => rejector(error));
@@ -1718,24 +1734,24 @@ class Queue {
1718
1734
  }
1719
1735
  add(task) {
1720
1736
  return new Promise((resolve, reject) => {
1721
- this.#resolvers.set(task, resolve);
1722
- this.#rejectors.set(task, reject);
1723
- this.#pending.push(task);
1724
- this.#run();
1737
+ this._resolvers.set(task, resolve);
1738
+ this._rejectors.set(task, reject);
1739
+ this._pending.push(task);
1740
+ this._run();
1725
1741
  });
1726
1742
  }
1727
1743
  get pending() {
1728
- return this.#pending.length;
1744
+ return this._pending.length;
1729
1745
  }
1730
1746
  get running() {
1731
- return this.#running;
1747
+ return this._running;
1732
1748
  }
1733
1749
  set concurrency(value) {
1734
- this.#concurrency = value;
1735
- this.#run();
1750
+ this._concurrency = value;
1751
+ this._run();
1736
1752
  }
1737
1753
  get concurrency() {
1738
- return this.#concurrency;
1754
+ return this._concurrency;
1739
1755
  }
1740
1756
  }
1741
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;