@uploadcare/upload-client 4.1.0 → 4.2.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.
- package/README.md +13 -11
- package/dist/index.browser.js +63 -41
- package/dist/index.node.js +63 -41
- package/dist/index.react-native.js +64 -42
- package/dist/types.d.ts +44 -45
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Uploadcare Upload Client
|
|
2
2
|
|
|
3
|
-
<a href="https://uploadcare.com/?utm_source=github&utm_campaign=uploadcare-
|
|
3
|
+
<a href="https://uploadcare.com/?utm_source=github&utm_campaign=uploadcare-js-api-clients">
|
|
4
4
|
<img align="right" width="64" height="64"
|
|
5
5
|
src="https://ucarecdn.com/edfdf045-34c0-4087-bbdd-e3834921f890/userpiccircletransparent.svg"
|
|
6
6
|
alt="">
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
This is an Uploadcare [Upload API][uc-docs-upload-api] wrapper to work with
|
|
10
10
|
Node.js and browser.
|
|
11
11
|
|
|
12
|
+
[API Reference](https://uploadcare.github.io/uploadcare-js-api-clients/upload-client/)
|
|
13
|
+
|
|
12
14
|
[![Build Status][badge-build]][build-url]
|
|
13
15
|
[![NPM version][npm-img]][npm-url]
|
|
14
16
|
[![GitHub release][badge-release-img]][badge-release-url]
|
|
@@ -227,11 +229,11 @@ fromUrlStatus(
|
|
|
227
229
|
```
|
|
228
230
|
|
|
229
231
|
```typescript
|
|
230
|
-
|
|
232
|
+
group(uuids: Uuid[], options: GroupOptions): Promise<GroupInfo>
|
|
231
233
|
```
|
|
232
234
|
|
|
233
235
|
```typescript
|
|
234
|
-
|
|
236
|
+
groupInfo(id: GroupId, options: GroupInfoOptions): Promise<GroupInfo>
|
|
235
237
|
```
|
|
236
238
|
|
|
237
239
|
```typescript
|
|
@@ -461,16 +463,16 @@ request at [hello@uploadcare.com][uc-email-hello].
|
|
|
461
463
|
|
|
462
464
|
[uc-email-bounty]: mailto:bugbounty@uploadcare.com
|
|
463
465
|
[uc-email-hello]: mailto:hello@uploadcare.com
|
|
464
|
-
[github-releases]: https://github.com/uploadcare/uploadcare-
|
|
465
|
-
[github-branch-release]: https://github.com/uploadcare/uploadcare-
|
|
466
|
-
[github-contributors]: https://github.com/uploadcare/uploadcare-
|
|
466
|
+
[github-releases]: https://github.com/uploadcare/uploadcare-js-api-clients/releases
|
|
467
|
+
[github-branch-release]: https://github.com/uploadcare/uploadcare-js-api-clients/tree/release
|
|
468
|
+
[github-contributors]: https://github.com/uploadcare/uploadcare-js-api-clients/graphs/contributors
|
|
467
469
|
[badge-stack-img]: https://img.shields.io/badge/tech-stack-0690fa.svg?style=flat
|
|
468
470
|
[badge-stack-url]: https://stackshare.io/uploadcare/stacks/
|
|
469
|
-
[badge-release-img]: https://img.shields.io/github/release/uploadcare/uploadcare-
|
|
470
|
-
[badge-release-url]: https://github.com/uploadcare/uploadcare-
|
|
471
|
+
[badge-release-img]: https://img.shields.io/github/release/uploadcare/uploadcare-js-api-clients.svg
|
|
472
|
+
[badge-release-url]: https://github.com/uploadcare/uploadcare-js-api-clients/releases
|
|
471
473
|
[npm-img]: http://img.shields.io/npm/v/@uploadcare/upload-client.svg
|
|
472
474
|
[npm-url]: https://www.npmjs.org/package/@uploadcare/upload-client
|
|
473
|
-
[badge-build]: https://github.com/uploadcare/uploadcare-
|
|
474
|
-
[build-url]: https://github.com/uploadcare/uploadcare-
|
|
475
|
-
[uc-docs-upload-api]: https://uploadcare.com/docs/api_reference/upload/?utm_source=github&utm_campaign=uploadcare-
|
|
475
|
+
[badge-build]: https://github.com/uploadcare/uploadcare-js-api-clients/actions/workflows/checks.yml/badge.svg
|
|
476
|
+
[build-url]: https://github.com/uploadcare/uploadcare-js-api-clients/actions/workflows/checks.yml
|
|
477
|
+
[uc-docs-upload-api]: https://uploadcare.com/docs/api_reference/upload/?utm_source=github&utm_campaign=uploadcare-js-api-clients
|
|
476
478
|
[uc-docs-metadata]: https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-Metadata
|
package/dist/index.browser.js
CHANGED
|
@@ -248,14 +248,59 @@ const defaultSettings = {
|
|
|
248
248
|
const defaultContentType = 'application/octet-stream';
|
|
249
249
|
const defaultFilename = 'original';
|
|
250
250
|
|
|
251
|
-
var version = '4.
|
|
251
|
+
var version = '4.2.0';
|
|
252
|
+
|
|
253
|
+
function isObject(o) {
|
|
254
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const SEPARATOR = /\W|_/g;
|
|
258
|
+
function camelizeString(text) {
|
|
259
|
+
return text
|
|
260
|
+
.split(SEPARATOR)
|
|
261
|
+
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
262
|
+
word.slice(1))
|
|
263
|
+
.join('');
|
|
264
|
+
}
|
|
265
|
+
function camelizeArrayItems(array, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
266
|
+
if (!Array.isArray(array)) {
|
|
267
|
+
return array;
|
|
268
|
+
}
|
|
269
|
+
return array.map((item) => camelizeKeys(item, { ignoreKeys }));
|
|
270
|
+
}
|
|
271
|
+
function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
272
|
+
if (Array.isArray(source)) {
|
|
273
|
+
return camelizeArrayItems(source, { ignoreKeys });
|
|
274
|
+
}
|
|
275
|
+
if (!isObject(source)) {
|
|
276
|
+
return source;
|
|
277
|
+
}
|
|
278
|
+
const result = {};
|
|
279
|
+
for (const key of Object.keys(source)) {
|
|
280
|
+
let value = source[key];
|
|
281
|
+
if (ignoreKeys.includes(key)) {
|
|
282
|
+
result[key] = value;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (isObject(value)) {
|
|
286
|
+
value = camelizeKeys(value, { ignoreKeys });
|
|
287
|
+
}
|
|
288
|
+
else if (Array.isArray(value)) {
|
|
289
|
+
value = camelizeArrayItems(value, { ignoreKeys });
|
|
290
|
+
}
|
|
291
|
+
result[camelizeString(key)] = value;
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
252
295
|
|
|
253
296
|
/**
|
|
254
|
-
*
|
|
297
|
+
* setTimeout as Promise.
|
|
298
|
+
*
|
|
299
|
+
* @param {number} ms Timeout in milliseconds.
|
|
255
300
|
*/
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
301
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
302
|
+
|
|
303
|
+
function getUserAgent$1({ libraryName, libraryVersion, userAgent, publicKey = '', integration = '' }) {
|
|
259
304
|
const languageName = 'JavaScript';
|
|
260
305
|
if (typeof userAgent === 'string') {
|
|
261
306
|
return userAgent;
|
|
@@ -276,39 +321,6 @@ function getUserAgent({ userAgent, publicKey = '', integration = '' } = {}) {
|
|
|
276
321
|
return `${mainInfo} (${additionInfo})`;
|
|
277
322
|
}
|
|
278
323
|
|
|
279
|
-
/**
|
|
280
|
-
* setTimeout as Promise.
|
|
281
|
-
*
|
|
282
|
-
* @param {number} ms Timeout in milliseconds.
|
|
283
|
-
*/
|
|
284
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
285
|
-
|
|
286
|
-
const SEPARATOR = /\W|_/g;
|
|
287
|
-
/**
|
|
288
|
-
* Transforms a string to camelCased.
|
|
289
|
-
*/
|
|
290
|
-
function camelize(text) {
|
|
291
|
-
return text
|
|
292
|
-
.split(SEPARATOR)
|
|
293
|
-
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
294
|
-
word.slice(1))
|
|
295
|
-
.join('');
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Transforms keys of an object to camelCased recursively.
|
|
299
|
-
*/
|
|
300
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
301
|
-
function camelizeKeys(source) {
|
|
302
|
-
if (!source || typeof source !== 'object') {
|
|
303
|
-
return source;
|
|
304
|
-
}
|
|
305
|
-
return Object.keys(source).reduce((accumulator, key) => {
|
|
306
|
-
accumulator[camelize(key)] =
|
|
307
|
-
typeof source[key] === 'object' ? camelizeKeys(source[key]) : source[key];
|
|
308
|
-
return accumulator;
|
|
309
|
-
}, {});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
324
|
const defaultOptions = {
|
|
313
325
|
factor: 2,
|
|
314
326
|
time: 100
|
|
@@ -329,6 +341,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
329
341
|
return runAttempt(fn);
|
|
330
342
|
}
|
|
331
343
|
|
|
344
|
+
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
345
|
+
const LIBRARY_VERSION = version;
|
|
346
|
+
function getUserAgent(options) {
|
|
347
|
+
return getUserAgent$1({
|
|
348
|
+
libraryName: LIBRARY_NAME,
|
|
349
|
+
libraryVersion: LIBRARY_VERSION,
|
|
350
|
+
...options
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
332
354
|
const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
333
355
|
const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
334
356
|
function getTimeoutFromThrottledRequest(error) {
|
|
@@ -671,9 +693,9 @@ class UploadcareFile {
|
|
|
671
693
|
this.mimeType = fileInfo.mimeType;
|
|
672
694
|
this.cdnUrl = cdnUrl;
|
|
673
695
|
this.originalFilename = fileInfo.originalFilename;
|
|
674
|
-
this.imageInfo =
|
|
675
|
-
this.videoInfo =
|
|
676
|
-
this.contentInfo =
|
|
696
|
+
this.imageInfo = fileInfo.imageInfo;
|
|
697
|
+
this.videoInfo = fileInfo.videoInfo;
|
|
698
|
+
this.contentInfo = fileInfo.contentInfo;
|
|
677
699
|
this.metadata = fileInfo.metadata || null;
|
|
678
700
|
this.s3Bucket = s3Bucket || null;
|
|
679
701
|
this.s3Url = s3Url;
|
package/dist/index.node.js
CHANGED
|
@@ -282,14 +282,59 @@ const defaultSettings = {
|
|
|
282
282
|
const defaultContentType = 'application/octet-stream';
|
|
283
283
|
const defaultFilename = 'original';
|
|
284
284
|
|
|
285
|
-
var version = '4.
|
|
285
|
+
var version = '4.2.0';
|
|
286
|
+
|
|
287
|
+
function isObject(o) {
|
|
288
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const SEPARATOR = /\W|_/g;
|
|
292
|
+
function camelizeString(text) {
|
|
293
|
+
return text
|
|
294
|
+
.split(SEPARATOR)
|
|
295
|
+
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
296
|
+
word.slice(1))
|
|
297
|
+
.join('');
|
|
298
|
+
}
|
|
299
|
+
function camelizeArrayItems(array, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
300
|
+
if (!Array.isArray(array)) {
|
|
301
|
+
return array;
|
|
302
|
+
}
|
|
303
|
+
return array.map((item) => camelizeKeys(item, { ignoreKeys }));
|
|
304
|
+
}
|
|
305
|
+
function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
306
|
+
if (Array.isArray(source)) {
|
|
307
|
+
return camelizeArrayItems(source, { ignoreKeys });
|
|
308
|
+
}
|
|
309
|
+
if (!isObject(source)) {
|
|
310
|
+
return source;
|
|
311
|
+
}
|
|
312
|
+
const result = {};
|
|
313
|
+
for (const key of Object.keys(source)) {
|
|
314
|
+
let value = source[key];
|
|
315
|
+
if (ignoreKeys.includes(key)) {
|
|
316
|
+
result[key] = value;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (isObject(value)) {
|
|
320
|
+
value = camelizeKeys(value, { ignoreKeys });
|
|
321
|
+
}
|
|
322
|
+
else if (Array.isArray(value)) {
|
|
323
|
+
value = camelizeArrayItems(value, { ignoreKeys });
|
|
324
|
+
}
|
|
325
|
+
result[camelizeString(key)] = value;
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
286
329
|
|
|
287
330
|
/**
|
|
288
|
-
*
|
|
331
|
+
* setTimeout as Promise.
|
|
332
|
+
*
|
|
333
|
+
* @param {number} ms Timeout in milliseconds.
|
|
289
334
|
*/
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
335
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
336
|
+
|
|
337
|
+
function getUserAgent$1({ libraryName, libraryVersion, userAgent, publicKey = '', integration = '' }) {
|
|
293
338
|
const languageName = 'JavaScript';
|
|
294
339
|
if (typeof userAgent === 'string') {
|
|
295
340
|
return userAgent;
|
|
@@ -310,39 +355,6 @@ function getUserAgent({ userAgent, publicKey = '', integration = '' } = {}) {
|
|
|
310
355
|
return `${mainInfo} (${additionInfo})`;
|
|
311
356
|
}
|
|
312
357
|
|
|
313
|
-
/**
|
|
314
|
-
* setTimeout as Promise.
|
|
315
|
-
*
|
|
316
|
-
* @param {number} ms Timeout in milliseconds.
|
|
317
|
-
*/
|
|
318
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
319
|
-
|
|
320
|
-
const SEPARATOR = /\W|_/g;
|
|
321
|
-
/**
|
|
322
|
-
* Transforms a string to camelCased.
|
|
323
|
-
*/
|
|
324
|
-
function camelize(text) {
|
|
325
|
-
return text
|
|
326
|
-
.split(SEPARATOR)
|
|
327
|
-
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
328
|
-
word.slice(1))
|
|
329
|
-
.join('');
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Transforms keys of an object to camelCased recursively.
|
|
333
|
-
*/
|
|
334
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
335
|
-
function camelizeKeys(source) {
|
|
336
|
-
if (!source || typeof source !== 'object') {
|
|
337
|
-
return source;
|
|
338
|
-
}
|
|
339
|
-
return Object.keys(source).reduce((accumulator, key) => {
|
|
340
|
-
accumulator[camelize(key)] =
|
|
341
|
-
typeof source[key] === 'object' ? camelizeKeys(source[key]) : source[key];
|
|
342
|
-
return accumulator;
|
|
343
|
-
}, {});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
358
|
const defaultOptions = {
|
|
347
359
|
factor: 2,
|
|
348
360
|
time: 100
|
|
@@ -363,6 +375,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
363
375
|
return runAttempt(fn);
|
|
364
376
|
}
|
|
365
377
|
|
|
378
|
+
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
379
|
+
const LIBRARY_VERSION = version;
|
|
380
|
+
function getUserAgent(options) {
|
|
381
|
+
return getUserAgent$1({
|
|
382
|
+
libraryName: LIBRARY_NAME,
|
|
383
|
+
libraryVersion: LIBRARY_VERSION,
|
|
384
|
+
...options
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
366
388
|
const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
367
389
|
const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
368
390
|
function getTimeoutFromThrottledRequest(error) {
|
|
@@ -705,9 +727,9 @@ class UploadcareFile {
|
|
|
705
727
|
this.mimeType = fileInfo.mimeType;
|
|
706
728
|
this.cdnUrl = cdnUrl;
|
|
707
729
|
this.originalFilename = fileInfo.originalFilename;
|
|
708
|
-
this.imageInfo =
|
|
709
|
-
this.videoInfo =
|
|
710
|
-
this.contentInfo =
|
|
730
|
+
this.imageInfo = fileInfo.imageInfo;
|
|
731
|
+
this.videoInfo = fileInfo.videoInfo;
|
|
732
|
+
this.contentInfo = fileInfo.contentInfo;
|
|
711
733
|
this.metadata = fileInfo.metadata || null;
|
|
712
734
|
this.s3Bucket = s3Bucket || null;
|
|
713
735
|
this.s3Url = s3Url;
|
|
@@ -251,14 +251,59 @@ const defaultSettings = {
|
|
|
251
251
|
const defaultContentType = 'application/octet-stream';
|
|
252
252
|
const defaultFilename = 'original';
|
|
253
253
|
|
|
254
|
-
var version = '4.
|
|
254
|
+
var version = '4.2.0';
|
|
255
|
+
|
|
256
|
+
function isObject(o) {
|
|
257
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const SEPARATOR = /\W|_/g;
|
|
261
|
+
function camelizeString(text) {
|
|
262
|
+
return text
|
|
263
|
+
.split(SEPARATOR)
|
|
264
|
+
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
265
|
+
word.slice(1))
|
|
266
|
+
.join('');
|
|
267
|
+
}
|
|
268
|
+
function camelizeArrayItems(array, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
269
|
+
if (!Array.isArray(array)) {
|
|
270
|
+
return array;
|
|
271
|
+
}
|
|
272
|
+
return array.map((item) => camelizeKeys(item, { ignoreKeys }));
|
|
273
|
+
}
|
|
274
|
+
function camelizeKeys(source, { ignoreKeys } = { ignoreKeys: [] }) {
|
|
275
|
+
if (Array.isArray(source)) {
|
|
276
|
+
return camelizeArrayItems(source, { ignoreKeys });
|
|
277
|
+
}
|
|
278
|
+
if (!isObject(source)) {
|
|
279
|
+
return source;
|
|
280
|
+
}
|
|
281
|
+
const result = {};
|
|
282
|
+
for (const key of Object.keys(source)) {
|
|
283
|
+
let value = source[key];
|
|
284
|
+
if (ignoreKeys.includes(key)) {
|
|
285
|
+
result[key] = value;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (isObject(value)) {
|
|
289
|
+
value = camelizeKeys(value, { ignoreKeys });
|
|
290
|
+
}
|
|
291
|
+
else if (Array.isArray(value)) {
|
|
292
|
+
value = camelizeArrayItems(value, { ignoreKeys });
|
|
293
|
+
}
|
|
294
|
+
result[camelizeString(key)] = value;
|
|
295
|
+
}
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
255
298
|
|
|
256
299
|
/**
|
|
257
|
-
*
|
|
300
|
+
* setTimeout as Promise.
|
|
301
|
+
*
|
|
302
|
+
* @param {number} ms Timeout in milliseconds.
|
|
258
303
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
304
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
305
|
+
|
|
306
|
+
function getUserAgent$1({ libraryName, libraryVersion, userAgent, publicKey = '', integration = '' }) {
|
|
262
307
|
const languageName = 'JavaScript';
|
|
263
308
|
if (typeof userAgent === 'string') {
|
|
264
309
|
return userAgent;
|
|
@@ -279,39 +324,6 @@ function getUserAgent({ userAgent, publicKey = '', integration = '' } = {}) {
|
|
|
279
324
|
return `${mainInfo} (${additionInfo})`;
|
|
280
325
|
}
|
|
281
326
|
|
|
282
|
-
/**
|
|
283
|
-
* setTimeout as Promise.
|
|
284
|
-
*
|
|
285
|
-
* @param {number} ms Timeout in milliseconds.
|
|
286
|
-
*/
|
|
287
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
288
|
-
|
|
289
|
-
const SEPARATOR = /\W|_/g;
|
|
290
|
-
/**
|
|
291
|
-
* Transforms a string to camelCased.
|
|
292
|
-
*/
|
|
293
|
-
function camelize(text) {
|
|
294
|
-
return text
|
|
295
|
-
.split(SEPARATOR)
|
|
296
|
-
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
297
|
-
word.slice(1))
|
|
298
|
-
.join('');
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Transforms keys of an object to camelCased recursively.
|
|
302
|
-
*/
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
304
|
-
function camelizeKeys(source) {
|
|
305
|
-
if (!source || typeof source !== 'object') {
|
|
306
|
-
return source;
|
|
307
|
-
}
|
|
308
|
-
return Object.keys(source).reduce((accumulator, key) => {
|
|
309
|
-
accumulator[camelize(key)] =
|
|
310
|
-
typeof source[key] === 'object' ? camelizeKeys(source[key]) : source[key];
|
|
311
|
-
return accumulator;
|
|
312
|
-
}, {});
|
|
313
|
-
}
|
|
314
|
-
|
|
315
327
|
const defaultOptions = {
|
|
316
328
|
factor: 2,
|
|
317
329
|
time: 100
|
|
@@ -332,6 +344,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
332
344
|
return runAttempt(fn);
|
|
333
345
|
}
|
|
334
346
|
|
|
347
|
+
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
348
|
+
const LIBRARY_VERSION = version;
|
|
349
|
+
function getUserAgent(options) {
|
|
350
|
+
return getUserAgent$1({
|
|
351
|
+
libraryName: LIBRARY_NAME,
|
|
352
|
+
libraryVersion: LIBRARY_VERSION,
|
|
353
|
+
...options
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
335
357
|
const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
336
358
|
const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
337
359
|
function getTimeoutFromThrottledRequest(error) {
|
|
@@ -674,9 +696,9 @@ class UploadcareFile {
|
|
|
674
696
|
this.mimeType = fileInfo.mimeType;
|
|
675
697
|
this.cdnUrl = cdnUrl;
|
|
676
698
|
this.originalFilename = fileInfo.originalFilename;
|
|
677
|
-
this.imageInfo =
|
|
678
|
-
this.videoInfo =
|
|
679
|
-
this.contentInfo =
|
|
699
|
+
this.imageInfo = fileInfo.imageInfo;
|
|
700
|
+
this.videoInfo = fileInfo.videoInfo;
|
|
701
|
+
this.contentInfo = fileInfo.contentInfo;
|
|
680
702
|
this.metadata = fileInfo.metadata || null;
|
|
681
703
|
this.s3Bucket = s3Bucket || null;
|
|
682
704
|
this.s3Url = s3Url;
|
|
@@ -1150,7 +1172,7 @@ const sliceChunk = (file, index, fileSize, chunkSize) => {
|
|
|
1150
1172
|
* being deallocated until uploading complete. Access to deallocated blob
|
|
1151
1173
|
* causes app crash.
|
|
1152
1174
|
*
|
|
1153
|
-
* See https://github.com/uploadcare/uploadcare-
|
|
1175
|
+
* See https://github.com/uploadcare/uploadcare-js-api-clients/issues/306
|
|
1154
1176
|
* and https://github.com/facebook/react-native/issues/27543
|
|
1155
1177
|
*/
|
|
1156
1178
|
function prepareChunks(file, fileSize, chunkSize) {
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import NodeFormData from 'form-data';
|
|
4
4
|
|
|
5
|
+
export declare type CustomUserAgentOptions = {
|
|
6
|
+
publicKey: string;
|
|
7
|
+
libraryName: string;
|
|
8
|
+
libraryVersion: string;
|
|
9
|
+
languageName: string;
|
|
10
|
+
integration?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type CustomUserAgentFn = (options: CustomUserAgentOptions) => string;
|
|
13
|
+
export declare type CustomUserAgent = string | CustomUserAgentFn;
|
|
5
14
|
export declare type GeoLocation = {
|
|
6
15
|
latitude: number;
|
|
7
16
|
longitude: number;
|
|
@@ -39,16 +48,15 @@ export declare type VideoInfo = {
|
|
|
39
48
|
codec: string;
|
|
40
49
|
};
|
|
41
50
|
};
|
|
51
|
+
export declare type MimeInfo = {
|
|
52
|
+
mime: string;
|
|
53
|
+
type: string;
|
|
54
|
+
subtype: string;
|
|
55
|
+
};
|
|
42
56
|
export declare type ContentInfo = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
type: string;
|
|
47
|
-
subtype: string;
|
|
48
|
-
};
|
|
49
|
-
image?: ImageInfo;
|
|
50
|
-
video?: VideoInfo;
|
|
51
|
-
};
|
|
57
|
+
mime?: MimeInfo;
|
|
58
|
+
image?: ImageInfo;
|
|
59
|
+
video?: VideoInfo;
|
|
52
60
|
};
|
|
53
61
|
export declare type FileInfo = {
|
|
54
62
|
size: number;
|
|
@@ -92,42 +100,6 @@ export declare type ProgressCallback<T = ComputableProgressInfo | UnknownProgres
|
|
|
92
100
|
export declare type Metadata = {
|
|
93
101
|
[key: string]: string;
|
|
94
102
|
};
|
|
95
|
-
export interface DefaultSettings {
|
|
96
|
-
baseCDN: string;
|
|
97
|
-
baseURL: string;
|
|
98
|
-
maxContentLength: number;
|
|
99
|
-
retryThrottledRequestMaxTimes: number;
|
|
100
|
-
multipartMinFileSize: number;
|
|
101
|
-
multipartChunkSize: number;
|
|
102
|
-
multipartMinLastPartSize: number;
|
|
103
|
-
maxConcurrentRequests: number;
|
|
104
|
-
multipartMaxAttempts: number;
|
|
105
|
-
pollingTimeoutMilliseconds: number;
|
|
106
|
-
pusherKey: string;
|
|
107
|
-
}
|
|
108
|
-
export interface Settings extends Partial<DefaultSettings> {
|
|
109
|
-
publicKey: string;
|
|
110
|
-
fileName?: string;
|
|
111
|
-
contentType?: string;
|
|
112
|
-
store?: boolean;
|
|
113
|
-
secureSignature?: string;
|
|
114
|
-
secureExpire?: string;
|
|
115
|
-
integration?: string;
|
|
116
|
-
userAgent?: CustomUserAgent;
|
|
117
|
-
checkForUrlDuplicates?: boolean;
|
|
118
|
-
saveUrlForRecurrentUploads?: boolean;
|
|
119
|
-
source?: string;
|
|
120
|
-
jsonpCallback?: string;
|
|
121
|
-
}
|
|
122
|
-
export declare type CustomUserAgentOptions = {
|
|
123
|
-
publicKey: string;
|
|
124
|
-
libraryName: string;
|
|
125
|
-
libraryVersion: string;
|
|
126
|
-
languageName: string;
|
|
127
|
-
integration?: string;
|
|
128
|
-
};
|
|
129
|
-
export declare type CustomUserAgentFn = (options: CustomUserAgentOptions) => string;
|
|
130
|
-
export declare type CustomUserAgent = string | CustomUserAgentFn;
|
|
131
103
|
export declare type Headers = {
|
|
132
104
|
[key: string]: string | string[] | undefined;
|
|
133
105
|
};
|
|
@@ -454,6 +426,33 @@ export declare type GroupFromOptions = {
|
|
|
454
426
|
jsonpCallback?: string;
|
|
455
427
|
};
|
|
456
428
|
export function uploadFileGroup(data: (NodeFile | BrowserFile)[] | Url[] | Uuid[], { publicKey, fileName, baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, contentType, multipartChunkSize, baseCDN, jsonpCallback }: FileFromOptions & GroupFromOptions): Promise<UploadcareGroup>;
|
|
429
|
+
export interface DefaultSettings {
|
|
430
|
+
baseCDN: string;
|
|
431
|
+
baseURL: string;
|
|
432
|
+
maxContentLength: number;
|
|
433
|
+
retryThrottledRequestMaxTimes: number;
|
|
434
|
+
multipartMinFileSize: number;
|
|
435
|
+
multipartChunkSize: number;
|
|
436
|
+
multipartMinLastPartSize: number;
|
|
437
|
+
maxConcurrentRequests: number;
|
|
438
|
+
multipartMaxAttempts: number;
|
|
439
|
+
pollingTimeoutMilliseconds: number;
|
|
440
|
+
pusherKey: string;
|
|
441
|
+
}
|
|
442
|
+
export interface Settings extends Partial<DefaultSettings> {
|
|
443
|
+
publicKey: string;
|
|
444
|
+
fileName?: string;
|
|
445
|
+
contentType?: string;
|
|
446
|
+
store?: boolean;
|
|
447
|
+
secureSignature?: string;
|
|
448
|
+
secureExpire?: string;
|
|
449
|
+
integration?: string;
|
|
450
|
+
userAgent?: CustomUserAgent;
|
|
451
|
+
checkForUrlDuplicates?: boolean;
|
|
452
|
+
saveUrlForRecurrentUploads?: boolean;
|
|
453
|
+
source?: string;
|
|
454
|
+
jsonpCallback?: string;
|
|
455
|
+
}
|
|
457
456
|
export declare class UploadClient {
|
|
458
457
|
private settings;
|
|
459
458
|
constructor(settings: Settings);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadcare/upload-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Library for work with Uploadcare Upload API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
"node": ">=16"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"mock:start": "node --loader ts-node/esm ./mock-server/server.ts --silent",
|
|
17
|
+
"mock:start": "ts-node-esm --experimentalSpecifierResolution node ./mock-server/server.ts --silent",
|
|
19
18
|
"clean": "rimraf dist",
|
|
20
19
|
"test": "start-server-and-test mock:start :3000 test:jest",
|
|
21
|
-
"test:production": "
|
|
20
|
+
"test:production": "TEST_ENV=production npm run test:jest",
|
|
22
21
|
"test:jest": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
|
|
23
22
|
"prebuild": "npm run clean",
|
|
24
23
|
"build": "npm run build:types && npm run build:compile",
|
|
@@ -27,14 +26,14 @@
|
|
|
27
26
|
},
|
|
28
27
|
"repository": {
|
|
29
28
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/uploadcare/uploadcare-
|
|
29
|
+
"url": "git+https://github.com/uploadcare/uploadcare-js-api-clients.git"
|
|
31
30
|
},
|
|
32
31
|
"author": "Uploadcare",
|
|
33
32
|
"license": "MIT",
|
|
34
33
|
"bugs": {
|
|
35
|
-
"url": "https://github.com/uploadcare/uploadcare-
|
|
34
|
+
"url": "https://github.com/uploadcare/uploadcare-js-api-clients/issues"
|
|
36
35
|
},
|
|
37
|
-
"homepage": "https://github.com/uploadcare/uploadcare-
|
|
36
|
+
"homepage": "https://github.com/uploadcare/uploadcare-js-api-clients#readme",
|
|
38
37
|
"keywords": [
|
|
39
38
|
"uploadcare",
|
|
40
39
|
"file",
|
|
@@ -52,15 +51,15 @@
|
|
|
52
51
|
"@types/ws": "8.5.3",
|
|
53
52
|
"data-uri-to-buffer": "3.0.1",
|
|
54
53
|
"dataurl-to-blob": "0.0.1",
|
|
55
|
-
"dotenv": "8.2.0",
|
|
56
54
|
"jest-environment-jsdom": "28.1.0",
|
|
57
55
|
"jest-websocket-mock": "2.3.0",
|
|
58
56
|
"koa": "2.13.4",
|
|
59
57
|
"koa-add-trailing-slashes": "2.0.1",
|
|
60
58
|
"koa-body": "5.0.0",
|
|
61
59
|
"mock-socket": "9.0.3",
|
|
62
|
-
"start-server-and-test": "1.
|
|
63
|
-
"@uploadcare/api-client-utils": "^4.
|
|
60
|
+
"start-server-and-test": "1.14.0",
|
|
61
|
+
"@uploadcare/api-client-utils": "^4.2.0",
|
|
62
|
+
"chalk": "^4.1.2"
|
|
64
63
|
},
|
|
65
64
|
"dependencies": {
|
|
66
65
|
"form-data": "^4.0.0",
|