@uploadcare/upload-client 4.1.0 → 4.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.
- package/LICENSE +21 -0
- package/README.md +13 -11
- package/dist/index.browser.js +64 -42
- package/dist/index.node.js +64 -42
- package/dist/index.react-native.js +65 -43
- package/dist/types.d.ts +52 -45
- package/package.json +22 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Uploadcare Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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.3.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;
|
|
@@ -1526,4 +1548,4 @@ class UploadClient {
|
|
|
1526
1548
|
}
|
|
1527
1549
|
}
|
|
1528
1550
|
|
|
1529
|
-
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
1551
|
+
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
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.3.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;
|
|
@@ -1558,4 +1580,4 @@ class UploadClient {
|
|
|
1558
1580
|
}
|
|
1559
1581
|
}
|
|
1560
1582
|
|
|
1561
|
-
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
1583
|
+
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
@@ -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.3.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) {
|
|
@@ -1542,4 +1564,4 @@ class UploadClient {
|
|
|
1542
1564
|
}
|
|
1543
1565
|
}
|
|
1544
1566
|
|
|
1545
|
-
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
1567
|
+
export { UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
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;
|
|
14
|
+
export declare type GetUserAgentOptions = {
|
|
15
|
+
libraryName: string;
|
|
16
|
+
libraryVersion: string;
|
|
17
|
+
publicKey?: string;
|
|
18
|
+
integration?: string;
|
|
19
|
+
userAgent?: CustomUserAgent | null;
|
|
20
|
+
};
|
|
21
|
+
export declare function getUserAgent({ libraryName, libraryVersion, userAgent, publicKey, integration }: GetUserAgentOptions): string;
|
|
5
22
|
export declare type GeoLocation = {
|
|
6
23
|
latitude: number;
|
|
7
24
|
longitude: number;
|
|
@@ -39,16 +56,15 @@ export declare type VideoInfo = {
|
|
|
39
56
|
codec: string;
|
|
40
57
|
};
|
|
41
58
|
};
|
|
59
|
+
export declare type MimeInfo = {
|
|
60
|
+
mime: string;
|
|
61
|
+
type: string;
|
|
62
|
+
subtype: string;
|
|
63
|
+
};
|
|
42
64
|
export declare type ContentInfo = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
type: string;
|
|
47
|
-
subtype: string;
|
|
48
|
-
};
|
|
49
|
-
image?: ImageInfo;
|
|
50
|
-
video?: VideoInfo;
|
|
51
|
-
};
|
|
65
|
+
mime?: MimeInfo;
|
|
66
|
+
image?: ImageInfo;
|
|
67
|
+
video?: VideoInfo;
|
|
52
68
|
};
|
|
53
69
|
export declare type FileInfo = {
|
|
54
70
|
size: number;
|
|
@@ -92,42 +108,6 @@ export declare type ProgressCallback<T = ComputableProgressInfo | UnknownProgres
|
|
|
92
108
|
export declare type Metadata = {
|
|
93
109
|
[key: string]: string;
|
|
94
110
|
};
|
|
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
111
|
export declare type Headers = {
|
|
132
112
|
[key: string]: string | string[] | undefined;
|
|
133
113
|
};
|
|
@@ -454,6 +434,33 @@ export declare type GroupFromOptions = {
|
|
|
454
434
|
jsonpCallback?: string;
|
|
455
435
|
};
|
|
456
436
|
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>;
|
|
437
|
+
export interface DefaultSettings {
|
|
438
|
+
baseCDN: string;
|
|
439
|
+
baseURL: string;
|
|
440
|
+
maxContentLength: number;
|
|
441
|
+
retryThrottledRequestMaxTimes: number;
|
|
442
|
+
multipartMinFileSize: number;
|
|
443
|
+
multipartChunkSize: number;
|
|
444
|
+
multipartMinLastPartSize: number;
|
|
445
|
+
maxConcurrentRequests: number;
|
|
446
|
+
multipartMaxAttempts: number;
|
|
447
|
+
pollingTimeoutMilliseconds: number;
|
|
448
|
+
pusherKey: string;
|
|
449
|
+
}
|
|
450
|
+
export interface Settings extends Partial<DefaultSettings> {
|
|
451
|
+
publicKey: string;
|
|
452
|
+
fileName?: string;
|
|
453
|
+
contentType?: string;
|
|
454
|
+
store?: boolean;
|
|
455
|
+
secureSignature?: string;
|
|
456
|
+
secureExpire?: string;
|
|
457
|
+
integration?: string;
|
|
458
|
+
userAgent?: CustomUserAgent;
|
|
459
|
+
checkForUrlDuplicates?: boolean;
|
|
460
|
+
saveUrlForRecurrentUploads?: boolean;
|
|
461
|
+
source?: string;
|
|
462
|
+
jsonpCallback?: string;
|
|
463
|
+
}
|
|
457
464
|
export declare class UploadClient {
|
|
458
465
|
private settings;
|
|
459
466
|
constructor(settings: Settings);
|
package/package.json
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadcare/upload-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Library for work with Uploadcare Upload API",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.node.js",
|
|
7
|
-
"module": "dist/index.node.js",
|
|
8
|
-
"browser": "dist/index.browser.js",
|
|
9
|
-
"react-native": "dist/index.react-native.js",
|
|
10
|
-
"types": "dist/types.d.ts",
|
|
6
|
+
"main": "./dist/index.node.js",
|
|
7
|
+
"module": "./dist/index.node.js",
|
|
8
|
+
"browser": "./dist/index.browser.js",
|
|
9
|
+
"react-native": "./dist/index.react-native.js",
|
|
10
|
+
"types": "./dist/types.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"node": "./dist/index.node.js",
|
|
14
|
+
"browser": "./dist/index.browser.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
11
17
|
"sideEffects": false,
|
|
12
|
-
"files": ["dist/*"],
|
|
18
|
+
"files": ["dist/*", "README.md", "LICENSE"],
|
|
13
19
|
"engines": {
|
|
14
20
|
"node": ">=16"
|
|
15
21
|
},
|
|
16
22
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"mock:start": "node --
|
|
23
|
+
"prepack": "cp ../../LICENSE ./LICENSE",
|
|
24
|
+
"mock:start": "ts-node-esm --experimentalSpecifierResolution node ./mock-server/server.ts --silent",
|
|
19
25
|
"clean": "rimraf dist",
|
|
20
26
|
"test": "start-server-and-test mock:start :3000 test:jest",
|
|
21
|
-
"test:production": "
|
|
27
|
+
"test:production": "TEST_ENV=production npm run test:jest",
|
|
22
28
|
"test:jest": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
|
|
23
29
|
"prebuild": "npm run clean",
|
|
24
30
|
"build": "npm run build:types && npm run build:compile",
|
|
@@ -27,14 +33,14 @@
|
|
|
27
33
|
},
|
|
28
34
|
"repository": {
|
|
29
35
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/uploadcare/uploadcare-
|
|
36
|
+
"url": "git+https://github.com/uploadcare/uploadcare-js-api-clients.git"
|
|
31
37
|
},
|
|
32
38
|
"author": "Uploadcare",
|
|
33
39
|
"license": "MIT",
|
|
34
40
|
"bugs": {
|
|
35
|
-
"url": "https://github.com/uploadcare/uploadcare-
|
|
41
|
+
"url": "https://github.com/uploadcare/uploadcare-js-api-clients/issues"
|
|
36
42
|
},
|
|
37
|
-
"homepage": "https://github.com/uploadcare/uploadcare-
|
|
43
|
+
"homepage": "https://github.com/uploadcare/uploadcare-js-api-clients#readme",
|
|
38
44
|
"keywords": [
|
|
39
45
|
"uploadcare",
|
|
40
46
|
"file",
|
|
@@ -52,15 +58,15 @@
|
|
|
52
58
|
"@types/ws": "8.5.3",
|
|
53
59
|
"data-uri-to-buffer": "3.0.1",
|
|
54
60
|
"dataurl-to-blob": "0.0.1",
|
|
55
|
-
"dotenv": "8.2.0",
|
|
56
61
|
"jest-environment-jsdom": "28.1.0",
|
|
57
62
|
"jest-websocket-mock": "2.3.0",
|
|
58
63
|
"koa": "2.13.4",
|
|
59
64
|
"koa-add-trailing-slashes": "2.0.1",
|
|
60
65
|
"koa-body": "5.0.0",
|
|
61
66
|
"mock-socket": "9.0.3",
|
|
62
|
-
"start-server-and-test": "1.
|
|
63
|
-
"@uploadcare/api-client-utils": "^4.
|
|
67
|
+
"start-server-and-test": "1.14.0",
|
|
68
|
+
"@uploadcare/api-client-utils": "^4.3.0",
|
|
69
|
+
"chalk": "^4.1.2"
|
|
64
70
|
},
|
|
65
71
|
"dependencies": {
|
|
66
72
|
"form-data": "^4.0.0",
|