@uploadcare/upload-client 4.0.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 +15 -13
- package/dist/index.browser.js +140 -119
- package/dist/index.node.js +140 -119
- package/dist/index.react-native.js +141 -120
- package/dist/types.d.ts +45 -46
- package/package.json +15 -41
- package/LICENSE +0 -21
|
@@ -29,7 +29,7 @@ const onCancel = (signal, callback) => {
|
|
|
29
29
|
|
|
30
30
|
const request = ({ method, url, data, headers = {}, signal, onProgress }) => new Promise((resolve, reject) => {
|
|
31
31
|
const xhr = new XMLHttpRequest();
|
|
32
|
-
const requestMethod =
|
|
32
|
+
const requestMethod = method?.toUpperCase() || 'GET';
|
|
33
33
|
let aborted = false;
|
|
34
34
|
xhr.open(requestMethod, url);
|
|
35
35
|
if (headers) {
|
|
@@ -200,34 +200,36 @@ function buildFormData(options) {
|
|
|
200
200
|
return formData;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
203
|
+
const buildSearchParams = (query) => {
|
|
204
|
+
const searchParams = new URLSearchParams();
|
|
205
|
+
for (const [key, value] of Object.entries(query)) {
|
|
206
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
207
|
+
Object.entries(value)
|
|
208
|
+
.filter((entry) => entry[1] ?? false)
|
|
209
|
+
.forEach((entry) => searchParams.set(`${key}[${entry[0]}]`, String(entry[1])));
|
|
210
|
+
}
|
|
211
|
+
else if (Array.isArray(value)) {
|
|
212
|
+
value.forEach((val) => {
|
|
213
|
+
searchParams.append(`${key}[]`, val);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else if (typeof value === 'string' && value) {
|
|
217
|
+
searchParams.set(key, value);
|
|
218
|
+
}
|
|
219
|
+
else if (typeof value === 'number') {
|
|
220
|
+
searchParams.set(key, value.toString());
|
|
221
|
+
}
|
|
215
222
|
}
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
return searchParams.toString();
|
|
224
|
+
};
|
|
225
|
+
const getUrl = (base, path, query) => {
|
|
226
|
+
const url = new URL(base);
|
|
227
|
+
url.pathname = path;
|
|
228
|
+
if (query) {
|
|
229
|
+
url.search = buildSearchParams(query);
|
|
218
230
|
}
|
|
219
|
-
return
|
|
220
|
-
}
|
|
221
|
-
.filter((x) => !!x)
|
|
222
|
-
.join('&');
|
|
223
|
-
const getUrl = (base, path, query) => [
|
|
224
|
-
base,
|
|
225
|
-
path,
|
|
226
|
-
query && Object.keys(query).length > 0 ? '?' : '',
|
|
227
|
-
query && createQuery(query)
|
|
228
|
-
]
|
|
229
|
-
.filter(Boolean)
|
|
230
|
-
.join('');
|
|
231
|
+
return url.toString();
|
|
232
|
+
};
|
|
231
233
|
|
|
232
234
|
/*
|
|
233
235
|
Settings for future support:
|
|
@@ -249,14 +251,59 @@ const defaultSettings = {
|
|
|
249
251
|
const defaultContentType = 'application/octet-stream';
|
|
250
252
|
const defaultFilename = 'original';
|
|
251
253
|
|
|
252
|
-
var version = '
|
|
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
|
+
}
|
|
253
298
|
|
|
254
299
|
/**
|
|
255
|
-
*
|
|
300
|
+
* setTimeout as Promise.
|
|
301
|
+
*
|
|
302
|
+
* @param {number} ms Timeout in milliseconds.
|
|
256
303
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
304
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
305
|
+
|
|
306
|
+
function getUserAgent$1({ libraryName, libraryVersion, userAgent, publicKey = '', integration = '' }) {
|
|
260
307
|
const languageName = 'JavaScript';
|
|
261
308
|
if (typeof userAgent === 'string') {
|
|
262
309
|
return userAgent;
|
|
@@ -277,39 +324,6 @@ function getUserAgent({ userAgent, publicKey = '', integration = '' } = {}) {
|
|
|
277
324
|
return `${mainInfo} (${additionInfo})`;
|
|
278
325
|
}
|
|
279
326
|
|
|
280
|
-
const SEPARATOR = /\W|_/g;
|
|
281
|
-
/**
|
|
282
|
-
* Transforms a string to camelCased.
|
|
283
|
-
*/
|
|
284
|
-
function camelize(text) {
|
|
285
|
-
return text
|
|
286
|
-
.split(SEPARATOR)
|
|
287
|
-
.map((word, index) => word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
288
|
-
word.slice(1))
|
|
289
|
-
.join('');
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Transforms keys of an object to camelCased recursively.
|
|
293
|
-
*/
|
|
294
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
295
|
-
function camelizeKeys(source) {
|
|
296
|
-
if (!source || typeof source !== 'object') {
|
|
297
|
-
return source;
|
|
298
|
-
}
|
|
299
|
-
return Object.keys(source).reduce((accumulator, key) => {
|
|
300
|
-
accumulator[camelize(key)] =
|
|
301
|
-
typeof source[key] === 'object' ? camelizeKeys(source[key]) : source[key];
|
|
302
|
-
return accumulator;
|
|
303
|
-
}, {});
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* setTimeout as Promise.
|
|
308
|
-
*
|
|
309
|
-
* @param {number} ms Timeout in milliseconds.
|
|
310
|
-
*/
|
|
311
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
312
|
-
|
|
313
327
|
const defaultOptions = {
|
|
314
328
|
factor: 2,
|
|
315
329
|
time: 100
|
|
@@ -317,8 +331,8 @@ const defaultOptions = {
|
|
|
317
331
|
function retrier(fn, options = defaultOptions) {
|
|
318
332
|
let attempts = 0;
|
|
319
333
|
function runAttempt(fn) {
|
|
320
|
-
const defaultDelayTime = Math.round(options.time *
|
|
321
|
-
const retry = (ms) => delay(ms
|
|
334
|
+
const defaultDelayTime = Math.round(options.time * options.factor ** attempts);
|
|
335
|
+
const retry = (ms) => delay(ms ?? defaultDelayTime).then(() => {
|
|
322
336
|
attempts += 1;
|
|
323
337
|
return runAttempt(fn);
|
|
324
338
|
});
|
|
@@ -330,6 +344,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
330
344
|
return runAttempt(fn);
|
|
331
345
|
}
|
|
332
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
|
+
|
|
333
357
|
const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
334
358
|
const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
335
359
|
function getTimeoutFromThrottledRequest(error) {
|
|
@@ -341,7 +365,7 @@ function getTimeoutFromThrottledRequest(error) {
|
|
|
341
365
|
function retryIfThrottled(fn, retryThrottledMaxTimes) {
|
|
342
366
|
return retrier(({ attempt, retry }) => fn().catch((error) => {
|
|
343
367
|
if ('response' in error &&
|
|
344
|
-
|
|
368
|
+
error?.code === REQUEST_WAS_THROTTLED_CODE &&
|
|
345
369
|
attempt < retryThrottledMaxTimes) {
|
|
346
370
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
347
371
|
}
|
|
@@ -358,41 +382,38 @@ function getStoreValue(store) {
|
|
|
358
382
|
* Can be canceled and has progress.
|
|
359
383
|
*/
|
|
360
384
|
function base(file, { publicKey, fileName, contentType, baseURL = defaultSettings.baseURL, secureSignature, secureExpire, store, signal, onProgress, source = 'local', integration, userAgent, retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes, metadata }) {
|
|
361
|
-
return retryIfThrottled(() => {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
|
|
385
|
+
return retryIfThrottled(() => request({
|
|
386
|
+
method: 'POST',
|
|
387
|
+
url: getUrl(baseURL, '/base/', {
|
|
388
|
+
jsonerrors: 1
|
|
389
|
+
}),
|
|
390
|
+
headers: {
|
|
391
|
+
'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent })
|
|
392
|
+
},
|
|
393
|
+
data: buildFormData({
|
|
394
|
+
file: {
|
|
395
|
+
data: file,
|
|
396
|
+
name: fileName ?? file.name ?? defaultFilename,
|
|
397
|
+
contentType
|
|
370
398
|
},
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
return response;
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
}, retryThrottledRequestMaxTimes);
|
|
399
|
+
UPLOADCARE_PUB_KEY: publicKey,
|
|
400
|
+
UPLOADCARE_STORE: getStoreValue(store),
|
|
401
|
+
signature: secureSignature,
|
|
402
|
+
expire: secureExpire,
|
|
403
|
+
source: source,
|
|
404
|
+
metadata
|
|
405
|
+
}),
|
|
406
|
+
signal,
|
|
407
|
+
onProgress
|
|
408
|
+
}).then(({ data, headers, request }) => {
|
|
409
|
+
const response = camelizeKeys(JSON.parse(data));
|
|
410
|
+
if ('error' in response) {
|
|
411
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
return response;
|
|
415
|
+
}
|
|
416
|
+
}), retryThrottledRequestMaxTimes);
|
|
396
417
|
}
|
|
397
418
|
|
|
398
419
|
var TypeEnum;
|
|
@@ -571,9 +592,9 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
|
|
|
571
592
|
'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent })
|
|
572
593
|
},
|
|
573
594
|
data: buildFormData({
|
|
574
|
-
filename: fileName
|
|
595
|
+
filename: fileName ?? defaultFilename,
|
|
575
596
|
size: size,
|
|
576
|
-
content_type: contentType
|
|
597
|
+
content_type: contentType ?? defaultContentType,
|
|
577
598
|
part_size: multipartChunkSize,
|
|
578
599
|
UPLOADCARE_STORE: getStoreValue(store),
|
|
579
600
|
UPLOADCARE_PUB_KEY: publicKey,
|
|
@@ -675,9 +696,9 @@ class UploadcareFile {
|
|
|
675
696
|
this.mimeType = fileInfo.mimeType;
|
|
676
697
|
this.cdnUrl = cdnUrl;
|
|
677
698
|
this.originalFilename = fileInfo.originalFilename;
|
|
678
|
-
this.imageInfo =
|
|
679
|
-
this.videoInfo =
|
|
680
|
-
this.contentInfo =
|
|
699
|
+
this.imageInfo = fileInfo.imageInfo;
|
|
700
|
+
this.videoInfo = fileInfo.videoInfo;
|
|
701
|
+
this.contentInfo = fileInfo.contentInfo;
|
|
681
702
|
this.metadata = fileInfo.metadata || null;
|
|
682
703
|
this.s3Bucket = s3Bucket || null;
|
|
683
704
|
this.s3Url = s3Url;
|
|
@@ -805,8 +826,7 @@ class Events {
|
|
|
805
826
|
this.events = Object.create({});
|
|
806
827
|
}
|
|
807
828
|
emit(event, data) {
|
|
808
|
-
|
|
809
|
-
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.forEach((fn) => fn(data));
|
|
829
|
+
this.events[event]?.forEach((fn) => fn(data));
|
|
810
830
|
}
|
|
811
831
|
on(event, callback) {
|
|
812
832
|
this.events[event] = this.events[event] || [];
|
|
@@ -824,12 +844,12 @@ class Events {
|
|
|
824
844
|
|
|
825
845
|
const response = (type, data) => {
|
|
826
846
|
if (type === 'success') {
|
|
827
|
-
return
|
|
847
|
+
return { status: Status.Success, ...data };
|
|
828
848
|
}
|
|
829
849
|
if (type === 'progress') {
|
|
830
|
-
return
|
|
850
|
+
return { status: Status.Progress, ...data };
|
|
831
851
|
}
|
|
832
|
-
return
|
|
852
|
+
return { status: Status.Error, ...data };
|
|
833
853
|
};
|
|
834
854
|
class Pusher {
|
|
835
855
|
constructor(pusherKey, disconnectTime = 30000) {
|
|
@@ -877,8 +897,7 @@ class Pusher {
|
|
|
877
897
|
}
|
|
878
898
|
disconnect() {
|
|
879
899
|
const actualDisconect = () => {
|
|
880
|
-
|
|
881
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
|
|
900
|
+
this.ws?.close();
|
|
882
901
|
this.ws = undefined;
|
|
883
902
|
this.isConnected = false;
|
|
884
903
|
};
|
|
@@ -892,9 +911,8 @@ class Pusher {
|
|
|
892
911
|
}
|
|
893
912
|
}
|
|
894
913
|
send(event, data) {
|
|
895
|
-
var _a;
|
|
896
914
|
const str = JSON.stringify({ event, data });
|
|
897
|
-
|
|
915
|
+
this.ws?.send(str);
|
|
898
916
|
}
|
|
899
917
|
subscribe(token, handler) {
|
|
900
918
|
this.subscribers += 1;
|
|
@@ -1061,7 +1079,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1061
1079
|
}))
|
|
1062
1080
|
.catch((error) => {
|
|
1063
1081
|
const pusher = getPusher(pusherKey);
|
|
1064
|
-
pusher
|
|
1082
|
+
pusher?.disconnect();
|
|
1065
1083
|
return Promise.reject(error);
|
|
1066
1084
|
})
|
|
1067
1085
|
.then((urlResponse) => {
|
|
@@ -1154,7 +1172,7 @@ const sliceChunk = (file, index, fileSize, chunkSize) => {
|
|
|
1154
1172
|
* being deallocated until uploading complete. Access to deallocated blob
|
|
1155
1173
|
* causes app crash.
|
|
1156
1174
|
*
|
|
1157
|
-
* See https://github.com/uploadcare/uploadcare-
|
|
1175
|
+
* See https://github.com/uploadcare/uploadcare-js-api-clients/issues/306
|
|
1158
1176
|
* and https://github.com/facebook/react-native/issues/27543
|
|
1159
1177
|
*/
|
|
1160
1178
|
function prepareChunks(file, fileSize, chunkSize) {
|
|
@@ -1234,7 +1252,7 @@ const uploadMultipart = (file, { publicKey, fileName, fileSize, baseURL, secureS
|
|
|
1234
1252
|
return multipartStart(size, {
|
|
1235
1253
|
publicKey,
|
|
1236
1254
|
contentType,
|
|
1237
|
-
fileName: fileName
|
|
1255
|
+
fileName: fileName ?? file.name,
|
|
1238
1256
|
baseURL,
|
|
1239
1257
|
secureSignature,
|
|
1240
1258
|
secureExpire,
|
|
@@ -1486,7 +1504,10 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1486
1504
|
/**
|
|
1487
1505
|
* Populate options with settings.
|
|
1488
1506
|
*/
|
|
1489
|
-
const populateOptionsWithSettings = (options, settings) => (
|
|
1507
|
+
const populateOptionsWithSettings = (options, settings) => ({
|
|
1508
|
+
...settings,
|
|
1509
|
+
...options
|
|
1510
|
+
});
|
|
1490
1511
|
class UploadClient {
|
|
1491
1512
|
constructor(settings) {
|
|
1492
1513
|
this.settings = Object.assign({}, defaultSettings, settings);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v6.
|
|
1
|
+
// Generated by dts-bundle-generator v6.12.0
|
|
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",
|
|
@@ -9,34 +9,31 @@
|
|
|
9
9
|
"react-native": "dist/index.react-native.js",
|
|
10
10
|
"types": "dist/types.d.ts",
|
|
11
11
|
"sideEffects": false,
|
|
12
|
-
"files": [
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"files": ["dist/*"],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16"
|
|
15
|
+
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"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",
|
|
18
18
|
"clean": "rimraf dist",
|
|
19
|
-
"lint": "eslint ./src ./mock-server --ext=ts",
|
|
20
19
|
"test": "start-server-and-test mock:start :3000 test:jest",
|
|
21
|
-
"test:production": "npm run
|
|
22
|
-
"test:jest": "jest",
|
|
20
|
+
"test:production": "TEST_ENV=production npm run test:jest",
|
|
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",
|
|
25
24
|
"build:types": "dts-bundle-generator --project tsconfig.dts.json -o dist/types.d.ts src/index.ts",
|
|
26
|
-
"build:compile": "rollup -c"
|
|
27
|
-
"release:prepare": "shipjs prepare",
|
|
28
|
-
"release:trigger": "shipjs trigger"
|
|
25
|
+
"build:compile": "rollup -c"
|
|
29
26
|
},
|
|
30
27
|
"repository": {
|
|
31
28
|
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/uploadcare/uploadcare-
|
|
29
|
+
"url": "git+https://github.com/uploadcare/uploadcare-js-api-clients.git"
|
|
33
30
|
},
|
|
34
31
|
"author": "Uploadcare",
|
|
35
32
|
"license": "MIT",
|
|
36
33
|
"bugs": {
|
|
37
|
-
"url": "https://github.com/uploadcare/uploadcare-
|
|
34
|
+
"url": "https://github.com/uploadcare/uploadcare-js-api-clients/issues"
|
|
38
35
|
},
|
|
39
|
-
"homepage": "https://github.com/uploadcare/uploadcare-
|
|
36
|
+
"homepage": "https://github.com/uploadcare/uploadcare-js-api-clients#readme",
|
|
40
37
|
"keywords": [
|
|
41
38
|
"uploadcare",
|
|
42
39
|
"file",
|
|
@@ -49,43 +46,20 @@
|
|
|
49
46
|
"devDependencies": {
|
|
50
47
|
"@koa/cors": "3.3.0",
|
|
51
48
|
"@koa/router": "10.1.1",
|
|
52
|
-
"@rollup/plugin-alias": "^3.1.9",
|
|
53
|
-
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
54
|
-
"@rollup/plugin-typescript": "^8.3.2",
|
|
55
49
|
"@types/express-serve-static-core": "^4.17.28",
|
|
56
|
-
"@types/form-data": "2.5.0",
|
|
57
|
-
"@types/jest": "27.0.0",
|
|
58
50
|
"@types/koa": "2.13.4",
|
|
59
|
-
"@types/node": "17.0.38",
|
|
60
|
-
"@types/promise": "7.1.30",
|
|
61
51
|
"@types/ws": "8.5.3",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "5.27.0",
|
|
63
|
-
"@typescript-eslint/parser": "5.27.0",
|
|
64
|
-
"chalk": "4.1.0",
|
|
65
52
|
"data-uri-to-buffer": "3.0.1",
|
|
66
53
|
"dataurl-to-blob": "0.0.1",
|
|
67
|
-
"dotenv": "8.2.0",
|
|
68
|
-
"dts-bundle-generator": "6.9.0",
|
|
69
|
-
"eslint": "8.2.0",
|
|
70
|
-
"eslint-config-prettier": "8.3.0",
|
|
71
|
-
"eslint-plugin-prettier": "4.0.0",
|
|
72
|
-
"jest": "^28.1.0",
|
|
73
54
|
"jest-environment-jsdom": "28.1.0",
|
|
74
55
|
"jest-websocket-mock": "2.3.0",
|
|
75
56
|
"koa": "2.13.4",
|
|
76
57
|
"koa-add-trailing-slashes": "2.0.1",
|
|
77
58
|
"koa-body": "5.0.0",
|
|
78
59
|
"mock-socket": "9.0.3",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"rollup": "^2.75.5",
|
|
83
|
-
"shipjs": "0.24.0",
|
|
84
|
-
"start-server-and-test": "1.11.7",
|
|
85
|
-
"ts-jest": "28.0.3",
|
|
86
|
-
"ts-node": "^10.8.0",
|
|
87
|
-
"tslib": "^2.4.0",
|
|
88
|
-
"typescript": "^4.7.2"
|
|
60
|
+
"start-server-and-test": "1.14.0",
|
|
61
|
+
"@uploadcare/api-client-utils": "^4.2.0",
|
|
62
|
+
"chalk": "^4.1.2"
|
|
89
63
|
},
|
|
90
64
|
"dependencies": {
|
|
91
65
|
"form-data": "^4.0.0",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|