@uploadcare/upload-client 6.11.1 → 6.12.1
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/dist/cjs/index.browser.cjs +36 -23
- package/dist/cjs/index.browser.d.cts +18 -7
- package/dist/cjs/index.node.cjs +35 -22
- package/dist/cjs/index.node.d.cts +18 -7
- package/dist/cjs/index.react-native.cjs +36 -23
- package/dist/cjs/index.react-native.d.cts +18 -7
- package/dist/esm/index.browser.d.mts +18 -7
- package/dist/esm/index.browser.mjs +33 -24
- package/dist/esm/index.node.d.mts +18 -7
- package/dist/esm/index.node.mjs +32 -23
- package/dist/esm/index.react-native.d.mts +18 -7
- package/dist/esm/index.react-native.mjs +33 -24
- package/dist/index.d.ts +18 -7
- package/package.json +2 -2
package/dist/esm/index.node.mjs
CHANGED
|
@@ -96,13 +96,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
96
96
|
return runAttempt(fn);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
class
|
|
99
|
+
class UploadcareError extends Error {
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
class NetworkError extends UploadcareError {
|
|
100
103
|
originalProgressEvent;
|
|
101
104
|
constructor(progressEvent) {
|
|
102
105
|
super();
|
|
103
|
-
this.name = '
|
|
106
|
+
this.name = 'NetworkError';
|
|
104
107
|
this.message = 'Network error';
|
|
105
|
-
Object.setPrototypeOf(this,
|
|
108
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
106
109
|
this.originalProgressEvent = progressEvent;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
@@ -118,10 +121,11 @@ const onCancel = (signal, callback) => {
|
|
|
118
121
|
}
|
|
119
122
|
};
|
|
120
123
|
|
|
121
|
-
class CancelError extends
|
|
124
|
+
class CancelError extends UploadcareError {
|
|
122
125
|
isCancel = true;
|
|
123
126
|
constructor(message = 'Request canceled') {
|
|
124
127
|
super(message);
|
|
128
|
+
this.name = 'CancelError';
|
|
125
129
|
Object.setPrototypeOf(this, CancelError.prototype);
|
|
126
130
|
}
|
|
127
131
|
}
|
|
@@ -377,21 +381,20 @@ function buildFormData(options) {
|
|
|
377
381
|
return formData;
|
|
378
382
|
}
|
|
379
383
|
|
|
380
|
-
class
|
|
381
|
-
isCancel;
|
|
384
|
+
class UploadError extends UploadcareError {
|
|
382
385
|
code;
|
|
383
386
|
request;
|
|
384
387
|
response;
|
|
385
388
|
headers;
|
|
386
389
|
constructor(message, code, request, response, headers) {
|
|
387
390
|
super();
|
|
388
|
-
this.name = '
|
|
391
|
+
this.name = 'UploadError';
|
|
389
392
|
this.message = message;
|
|
390
393
|
this.code = code;
|
|
391
394
|
this.request = request;
|
|
392
395
|
this.response = response;
|
|
393
396
|
this.headers = headers;
|
|
394
|
-
Object.setPrototypeOf(this,
|
|
397
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
395
398
|
}
|
|
396
399
|
}
|
|
397
400
|
|
|
@@ -426,7 +429,7 @@ const getUrl = (base, path, query) => {
|
|
|
426
429
|
return url.toString();
|
|
427
430
|
};
|
|
428
431
|
|
|
429
|
-
var version = '6.
|
|
432
|
+
var version = '6.12.1';
|
|
430
433
|
|
|
431
434
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
432
435
|
const LIBRARY_VERSION = version;
|
|
@@ -460,7 +463,7 @@ function retryIfFailed(fn, options) {
|
|
|
460
463
|
attempt < retryThrottledRequestMaxTimes) {
|
|
461
464
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
462
465
|
}
|
|
463
|
-
if (error instanceof
|
|
466
|
+
if (error instanceof NetworkError &&
|
|
464
467
|
attempt < retryNetworkErrorMaxTimes) {
|
|
465
468
|
return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
|
|
466
469
|
}
|
|
@@ -528,7 +531,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
528
531
|
}).then(({ data, headers, request }) => {
|
|
529
532
|
const response = camelizeKeys(JSON.parse(data));
|
|
530
533
|
if ('error' in response) {
|
|
531
|
-
throw new
|
|
534
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
532
535
|
}
|
|
533
536
|
else {
|
|
534
537
|
return response;
|
|
@@ -565,7 +568,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
|
|
|
565
568
|
}).then(({ data, headers, request }) => {
|
|
566
569
|
const response = camelizeKeys(JSON.parse(data));
|
|
567
570
|
if ('error' in response) {
|
|
568
|
-
throw new
|
|
571
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
569
572
|
}
|
|
570
573
|
else {
|
|
571
574
|
return response;
|
|
@@ -605,7 +608,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
|
|
|
605
608
|
}).then(({ data, headers, request }) => {
|
|
606
609
|
const response = camelizeKeys(JSON.parse(data));
|
|
607
610
|
if ('error' in response && !isErrorResponse(response)) {
|
|
608
|
-
throw new
|
|
611
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
609
612
|
}
|
|
610
613
|
else {
|
|
611
614
|
return response;
|
|
@@ -633,7 +636,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
|
|
|
633
636
|
}).then(({ data, headers, request }) => {
|
|
634
637
|
const response = camelizeKeys(JSON.parse(data));
|
|
635
638
|
if ('error' in response) {
|
|
636
|
-
throw new
|
|
639
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
637
640
|
}
|
|
638
641
|
else {
|
|
639
642
|
return response;
|
|
@@ -658,7 +661,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
|
|
|
658
661
|
}).then(({ data, headers, request }) => {
|
|
659
662
|
const response = camelizeKeys(JSON.parse(data));
|
|
660
663
|
if ('error' in response) {
|
|
661
|
-
throw new
|
|
664
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
662
665
|
}
|
|
663
666
|
else {
|
|
664
667
|
return response;
|
|
@@ -683,7 +686,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
|
|
|
683
686
|
}).then(({ data, headers, request }) => {
|
|
684
687
|
const response = camelizeKeys(JSON.parse(data));
|
|
685
688
|
if ('error' in response) {
|
|
686
|
-
throw new
|
|
689
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
687
690
|
}
|
|
688
691
|
else {
|
|
689
692
|
return response;
|
|
@@ -715,7 +718,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
|
|
|
715
718
|
}).then(({ data, headers, request }) => {
|
|
716
719
|
const response = camelizeKeys(JSON.parse(data));
|
|
717
720
|
if ('error' in response) {
|
|
718
|
-
throw new
|
|
721
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
719
722
|
}
|
|
720
723
|
else {
|
|
721
724
|
// convert to array
|
|
@@ -770,7 +773,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
770
773
|
}).then(({ data, headers, request }) => {
|
|
771
774
|
const response = camelizeKeys(JSON.parse(data));
|
|
772
775
|
if ('error' in response) {
|
|
773
|
-
throw new
|
|
776
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
774
777
|
}
|
|
775
778
|
else {
|
|
776
779
|
return response;
|
|
@@ -1093,13 +1096,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
|
|
|
1093
1096
|
}).then((response) => {
|
|
1094
1097
|
switch (response.status) {
|
|
1095
1098
|
case Status.Error: {
|
|
1096
|
-
return new
|
|
1099
|
+
return new UploadError(response.error, response.errorCode);
|
|
1097
1100
|
}
|
|
1098
1101
|
case Status.Waiting: {
|
|
1099
1102
|
return false;
|
|
1100
1103
|
}
|
|
1101
1104
|
case Status.Unknown: {
|
|
1102
|
-
return new
|
|
1105
|
+
return new UploadError(`Token "${token}" was not found.`);
|
|
1103
1106
|
}
|
|
1104
1107
|
case Status.Progress: {
|
|
1105
1108
|
if (onProgress) {
|
|
@@ -1170,7 +1173,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
|
|
|
1170
1173
|
}
|
|
1171
1174
|
case Status.Error: {
|
|
1172
1175
|
destroy();
|
|
1173
|
-
reject(new
|
|
1176
|
+
reject(new UploadError(result.msg, result.error_code));
|
|
1174
1177
|
}
|
|
1175
1178
|
}
|
|
1176
1179
|
});
|
|
@@ -1223,7 +1226,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1223
1226
|
}
|
|
1224
1227
|
})
|
|
1225
1228
|
.then((result) => {
|
|
1226
|
-
if (result instanceof
|
|
1229
|
+
if (result instanceof UploadError)
|
|
1227
1230
|
throw result;
|
|
1228
1231
|
return result;
|
|
1229
1232
|
})
|
|
@@ -1754,4 +1757,10 @@ class Queue {
|
|
|
1754
1757
|
}
|
|
1755
1758
|
}
|
|
1756
1759
|
|
|
1757
|
-
|
|
1760
|
+
/* Low-Level API */
|
|
1761
|
+
/** @deprecated Please use NetworkError instead. */
|
|
1762
|
+
const UploadcareNetworkError = NetworkError;
|
|
1763
|
+
/** @deprecated Please use UploadError instead. */
|
|
1764
|
+
const UploadClientError = UploadError;
|
|
1765
|
+
|
|
1766
|
+
export { CancelError, NetworkError, Queue, UploadClient, UploadClientError, UploadError, UploadcareError, UploadcareFile, UploadcareGroup, UploadcareNetworkError, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, isReadyPoll, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
@@ -19,7 +19,9 @@ export type GetUserAgentOptions = {
|
|
|
19
19
|
userAgent?: CustomUserAgent | null;
|
|
20
20
|
};
|
|
21
21
|
export declare function getUserAgent({ libraryName, libraryVersion, userAgent, publicKey, integration }: GetUserAgentOptions): string;
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class UploadcareError extends Error {
|
|
23
|
+
}
|
|
24
|
+
export declare class NetworkError extends UploadcareError {
|
|
23
25
|
originalProgressEvent: ProgressEvent;
|
|
24
26
|
constructor(progressEvent: ProgressEvent);
|
|
25
27
|
}
|
|
@@ -72,6 +74,10 @@ export type ContentInfo = {
|
|
|
72
74
|
};
|
|
73
75
|
export type Metadata = Record<string, string>;
|
|
74
76
|
export type StoreValue = "auto" | boolean;
|
|
77
|
+
export declare class CancelError extends UploadcareError {
|
|
78
|
+
isCancel: boolean;
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
75
81
|
export interface DefaultSettings {
|
|
76
82
|
baseCDN: string;
|
|
77
83
|
baseURL: string;
|
|
@@ -207,6 +213,8 @@ export type FromUrlOptions = {
|
|
|
207
213
|
};
|
|
208
214
|
/** Uploading files from URL. */
|
|
209
215
|
export function fromUrl(sourceUrl: Url, { publicKey, baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: FromUrlOptions): Promise<FromUrlSuccessResponse>;
|
|
216
|
+
/** @see https://uploadcare.com/api-refs/upload-api/#tag/Errors */
|
|
217
|
+
export type ServerErrorCode = "AccountBlockedError" | "AccountLimitsExceededError" | "AccountUnpaidError" | "AutostoreDisabledError" | "BaseViewsError" | "FileMetadataKeyDuplicatedError" | "FileMetadataKeyEmptyError" | "FileMetadataKeyForbiddenError" | "FileMetadataKeyLengthTooBigError" | "FileMetadataKeysNumberTooBigError" | "FileMetadataValueEmptyError" | "FileMetadataValueForbiddenError" | "FileMetadataValueLengthTooBigError" | "FileSizeLimitExceededError" | "MethodNotAllowedError" | "NullCharactersForbiddenError" | "PostRequestParserFailedError" | "ProjectPublicKeyInvalidError" | "ProjectPublicKeyRemovedError" | "ProjectPublicKeyRequiredError" | "RequestFileNumberLimitExceededError" | "RequestFiledsNumberLimitExceededError" | "RequestSizeLimitExceededError" | "RequestThrottledError" | "SignatureExpirationError" | "SignatureExpirationInvalidError" | "SignatureExpirationRequiredError" | "SignatureInvalidError" | "SignatureRequiredError" | "UploadAPIError" | "UploadFailedError" | "DownloadFileError" | "DownloadFileHTTPClientError" | "DownloadFileHTTPNetworkError" | "DownloadFileHTTPServerError" | "DownloadFileHTTPURLValidationError" | "DownloadFileInternalServerError" | "DownloadFileNotFoundError" | "DownloadFileSizeLimitExceededError" | "DownloadFileTaskFailedError" | "DownloadFileTimeLimitExceededError" | "DownloadFileValidationFailedError" | "FileIdInvalidError" | "FileIdNotUniqueError" | "FileIdRequiredError" | "FileNotFoundError" | "FileRequiredError" | "FilesNumberLimitExceededError" | "FilesRequiredError" | "InternalRequestForbiddenError" | "InternalRequestInvalidError" | "MultipartFileAlreadyUploadedError" | "MultipartFileCompletionFailedError" | "MultipartFileIdRequiredError" | "MultipartFileNotFoundError" | "MultipartFileSizeLimitExceededError" | "MultipartFileSizeTooSmallError" | "MultipartPartSizeInvalidError" | "MultipartPartSizeTooBigError" | "MultipartPartSizeTooSmallError" | "MultipartSizeInvalidError" | "MultipartUploadSizeTooLargeError" | "MultipartUploadSizeTooSmallError" | "RequestParamRequiredError" | "SourceURLRequiredError" | "TokenRequiredError" | "UUIDInvalidError" | "UploadViewsError" | "UploadcareFileIdDuplicatedError" | "UploadcareFileIdInvalidError" | "UploadcareFileIdRequiredError" | "GroupFileURLParsingFailedError" | "GroupFilesInvalidError" | "GroupFilesNotFoundError" | "GroupIdRequiredError" | "GroupNotFoundError" | "GroupViewsError" | "FileInfectedError" | "FileTypeForbiddenError" | "HostnameNotFoundError" | "URLBlacklistedError" | "URLHostMalformedError" | "URLHostPrivateIPForbiddenError" | "URLHostRequiredError" | "URLParsingFailedError" | "URLRedirectsLimitExceededError" | "URLSchemeInvalidError" | "URLSchemeRequiredError" | "URLValidationError";
|
|
210
218
|
export declare enum Status {
|
|
211
219
|
Unknown = "unknown",
|
|
212
220
|
Waiting = "waiting",
|
|
@@ -229,7 +237,7 @@ export type StatusProgressResponse = {
|
|
|
229
237
|
export type StatusErrorResponse = {
|
|
230
238
|
status: Status.Error;
|
|
231
239
|
error: string;
|
|
232
|
-
errorCode:
|
|
240
|
+
errorCode: ServerErrorCode;
|
|
233
241
|
};
|
|
234
242
|
export type StatusSuccessResponse = {
|
|
235
243
|
status: Status.Success;
|
|
@@ -520,16 +528,19 @@ export type ErrorResponseInfo = {
|
|
|
520
528
|
error?: {
|
|
521
529
|
statusCode: number;
|
|
522
530
|
content: string;
|
|
523
|
-
errorCode:
|
|
531
|
+
errorCode: ServerErrorCode;
|
|
524
532
|
};
|
|
525
533
|
};
|
|
526
|
-
export declare class
|
|
527
|
-
|
|
528
|
-
readonly code?: string;
|
|
534
|
+
export declare class UploadError extends UploadcareError {
|
|
535
|
+
readonly code?: ServerErrorCode;
|
|
529
536
|
readonly request?: ErrorRequestInfo;
|
|
530
537
|
readonly response?: ErrorResponseInfo;
|
|
531
538
|
readonly headers?: Headers;
|
|
532
|
-
constructor(message: string, code?:
|
|
539
|
+
constructor(message: string, code?: ServerErrorCode, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
|
|
533
540
|
}
|
|
541
|
+
/** @deprecated Please use NetworkError instead. */
|
|
542
|
+
export declare const UploadcareNetworkError: typeof NetworkError;
|
|
543
|
+
/** @deprecated Please use UploadError instead. */
|
|
544
|
+
export declare const UploadClientError: typeof UploadError;
|
|
534
545
|
|
|
535
546
|
export {};
|
|
@@ -89,13 +89,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
89
89
|
return runAttempt(fn);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
class
|
|
92
|
+
class UploadcareError extends Error {
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class NetworkError extends UploadcareError {
|
|
93
96
|
originalProgressEvent;
|
|
94
97
|
constructor(progressEvent) {
|
|
95
98
|
super();
|
|
96
|
-
this.name = '
|
|
99
|
+
this.name = 'NetworkError';
|
|
97
100
|
this.message = 'Network error';
|
|
98
|
-
Object.setPrototypeOf(this,
|
|
101
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
99
102
|
this.originalProgressEvent = progressEvent;
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -111,10 +114,11 @@ const onCancel = (signal, callback) => {
|
|
|
111
114
|
}
|
|
112
115
|
};
|
|
113
116
|
|
|
114
|
-
class CancelError extends
|
|
117
|
+
class CancelError extends UploadcareError {
|
|
115
118
|
isCancel = true;
|
|
116
119
|
constructor(message = 'Request canceled') {
|
|
117
120
|
super(message);
|
|
121
|
+
this.name = 'CancelError';
|
|
118
122
|
Object.setPrototypeOf(this, CancelError.prototype);
|
|
119
123
|
}
|
|
120
124
|
}
|
|
@@ -247,7 +251,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
247
251
|
if (aborted)
|
|
248
252
|
return;
|
|
249
253
|
// only triggers if the request couldn't be made at all
|
|
250
|
-
reject(new
|
|
254
|
+
reject(new NetworkError(progressEvent));
|
|
251
255
|
};
|
|
252
256
|
if (onProgress && typeof onProgress === 'function') {
|
|
253
257
|
xhr.upload.onprogress = (event) => {
|
|
@@ -354,21 +358,20 @@ function buildFormData(options) {
|
|
|
354
358
|
return formData;
|
|
355
359
|
}
|
|
356
360
|
|
|
357
|
-
class
|
|
358
|
-
isCancel;
|
|
361
|
+
class UploadError extends UploadcareError {
|
|
359
362
|
code;
|
|
360
363
|
request;
|
|
361
364
|
response;
|
|
362
365
|
headers;
|
|
363
366
|
constructor(message, code, request, response, headers) {
|
|
364
367
|
super();
|
|
365
|
-
this.name = '
|
|
368
|
+
this.name = 'UploadError';
|
|
366
369
|
this.message = message;
|
|
367
370
|
this.code = code;
|
|
368
371
|
this.request = request;
|
|
369
372
|
this.response = response;
|
|
370
373
|
this.headers = headers;
|
|
371
|
-
Object.setPrototypeOf(this,
|
|
374
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
372
375
|
}
|
|
373
376
|
}
|
|
374
377
|
|
|
@@ -403,7 +406,7 @@ const getUrl = (base, path, query) => {
|
|
|
403
406
|
return url.toString();
|
|
404
407
|
};
|
|
405
408
|
|
|
406
|
-
var version = '6.
|
|
409
|
+
var version = '6.12.1';
|
|
407
410
|
|
|
408
411
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
409
412
|
const LIBRARY_VERSION = version;
|
|
@@ -437,7 +440,7 @@ function retryIfFailed(fn, options) {
|
|
|
437
440
|
attempt < retryThrottledRequestMaxTimes) {
|
|
438
441
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
439
442
|
}
|
|
440
|
-
if (error instanceof
|
|
443
|
+
if (error instanceof NetworkError &&
|
|
441
444
|
attempt < retryNetworkErrorMaxTimes) {
|
|
442
445
|
return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
|
|
443
446
|
}
|
|
@@ -505,7 +508,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
505
508
|
}).then(({ data, headers, request }) => {
|
|
506
509
|
const response = camelizeKeys(JSON.parse(data));
|
|
507
510
|
if ('error' in response) {
|
|
508
|
-
throw new
|
|
511
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
509
512
|
}
|
|
510
513
|
else {
|
|
511
514
|
return response;
|
|
@@ -542,7 +545,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
|
|
|
542
545
|
}).then(({ data, headers, request }) => {
|
|
543
546
|
const response = camelizeKeys(JSON.parse(data));
|
|
544
547
|
if ('error' in response) {
|
|
545
|
-
throw new
|
|
548
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
546
549
|
}
|
|
547
550
|
else {
|
|
548
551
|
return response;
|
|
@@ -582,7 +585,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
|
|
|
582
585
|
}).then(({ data, headers, request }) => {
|
|
583
586
|
const response = camelizeKeys(JSON.parse(data));
|
|
584
587
|
if ('error' in response && !isErrorResponse(response)) {
|
|
585
|
-
throw new
|
|
588
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
586
589
|
}
|
|
587
590
|
else {
|
|
588
591
|
return response;
|
|
@@ -610,7 +613,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
|
|
|
610
613
|
}).then(({ data, headers, request }) => {
|
|
611
614
|
const response = camelizeKeys(JSON.parse(data));
|
|
612
615
|
if ('error' in response) {
|
|
613
|
-
throw new
|
|
616
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
614
617
|
}
|
|
615
618
|
else {
|
|
616
619
|
return response;
|
|
@@ -635,7 +638,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
|
|
|
635
638
|
}).then(({ data, headers, request }) => {
|
|
636
639
|
const response = camelizeKeys(JSON.parse(data));
|
|
637
640
|
if ('error' in response) {
|
|
638
|
-
throw new
|
|
641
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
639
642
|
}
|
|
640
643
|
else {
|
|
641
644
|
return response;
|
|
@@ -660,7 +663,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
|
|
|
660
663
|
}).then(({ data, headers, request }) => {
|
|
661
664
|
const response = camelizeKeys(JSON.parse(data));
|
|
662
665
|
if ('error' in response) {
|
|
663
|
-
throw new
|
|
666
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
664
667
|
}
|
|
665
668
|
else {
|
|
666
669
|
return response;
|
|
@@ -692,7 +695,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
|
|
|
692
695
|
}).then(({ data, headers, request }) => {
|
|
693
696
|
const response = camelizeKeys(JSON.parse(data));
|
|
694
697
|
if ('error' in response) {
|
|
695
|
-
throw new
|
|
698
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
696
699
|
}
|
|
697
700
|
else {
|
|
698
701
|
// convert to array
|
|
@@ -747,7 +750,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
747
750
|
}).then(({ data, headers, request }) => {
|
|
748
751
|
const response = camelizeKeys(JSON.parse(data));
|
|
749
752
|
if ('error' in response) {
|
|
750
|
-
throw new
|
|
753
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
751
754
|
}
|
|
752
755
|
else {
|
|
753
756
|
return response;
|
|
@@ -1072,13 +1075,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
|
|
|
1072
1075
|
}).then((response) => {
|
|
1073
1076
|
switch (response.status) {
|
|
1074
1077
|
case Status.Error: {
|
|
1075
|
-
return new
|
|
1078
|
+
return new UploadError(response.error, response.errorCode);
|
|
1076
1079
|
}
|
|
1077
1080
|
case Status.Waiting: {
|
|
1078
1081
|
return false;
|
|
1079
1082
|
}
|
|
1080
1083
|
case Status.Unknown: {
|
|
1081
|
-
return new
|
|
1084
|
+
return new UploadError(`Token "${token}" was not found.`);
|
|
1082
1085
|
}
|
|
1083
1086
|
case Status.Progress: {
|
|
1084
1087
|
if (onProgress) {
|
|
@@ -1149,7 +1152,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
|
|
|
1149
1152
|
}
|
|
1150
1153
|
case Status.Error: {
|
|
1151
1154
|
destroy();
|
|
1152
|
-
reject(new
|
|
1155
|
+
reject(new UploadError(result.msg, result.error_code));
|
|
1153
1156
|
}
|
|
1154
1157
|
}
|
|
1155
1158
|
});
|
|
@@ -1202,7 +1205,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1202
1205
|
}
|
|
1203
1206
|
})
|
|
1204
1207
|
.then((result) => {
|
|
1205
|
-
if (result instanceof
|
|
1208
|
+
if (result instanceof UploadError)
|
|
1206
1209
|
throw result;
|
|
1207
1210
|
return result;
|
|
1208
1211
|
})
|
|
@@ -1750,4 +1753,10 @@ class Queue {
|
|
|
1750
1753
|
}
|
|
1751
1754
|
}
|
|
1752
1755
|
|
|
1753
|
-
|
|
1756
|
+
/* Low-Level API */
|
|
1757
|
+
/** @deprecated Please use NetworkError instead. */
|
|
1758
|
+
const UploadcareNetworkError = NetworkError;
|
|
1759
|
+
/** @deprecated Please use UploadError instead. */
|
|
1760
|
+
const UploadClientError = UploadError;
|
|
1761
|
+
|
|
1762
|
+
export { CancelError, NetworkError, Queue, UploadClient, UploadClientError, UploadError, UploadcareError, UploadcareFile, UploadcareGroup, UploadcareNetworkError, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, isReadyPoll, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ export type GetUserAgentOptions = {
|
|
|
19
19
|
userAgent?: CustomUserAgent | null;
|
|
20
20
|
};
|
|
21
21
|
export declare function getUserAgent({ libraryName, libraryVersion, userAgent, publicKey, integration }: GetUserAgentOptions): string;
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class UploadcareError extends Error {
|
|
23
|
+
}
|
|
24
|
+
export declare class NetworkError extends UploadcareError {
|
|
23
25
|
originalProgressEvent: ProgressEvent;
|
|
24
26
|
constructor(progressEvent: ProgressEvent);
|
|
25
27
|
}
|
|
@@ -72,6 +74,10 @@ export type ContentInfo = {
|
|
|
72
74
|
};
|
|
73
75
|
export type Metadata = Record<string, string>;
|
|
74
76
|
export type StoreValue = "auto" | boolean;
|
|
77
|
+
export declare class CancelError extends UploadcareError {
|
|
78
|
+
isCancel: boolean;
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
75
81
|
export interface DefaultSettings {
|
|
76
82
|
baseCDN: string;
|
|
77
83
|
baseURL: string;
|
|
@@ -207,6 +213,8 @@ export type FromUrlOptions = {
|
|
|
207
213
|
};
|
|
208
214
|
/** Uploading files from URL. */
|
|
209
215
|
export function fromUrl(sourceUrl: Url, { publicKey, baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: FromUrlOptions): Promise<FromUrlSuccessResponse>;
|
|
216
|
+
/** @see https://uploadcare.com/api-refs/upload-api/#tag/Errors */
|
|
217
|
+
export type ServerErrorCode = "AccountBlockedError" | "AccountLimitsExceededError" | "AccountUnpaidError" | "AutostoreDisabledError" | "BaseViewsError" | "FileMetadataKeyDuplicatedError" | "FileMetadataKeyEmptyError" | "FileMetadataKeyForbiddenError" | "FileMetadataKeyLengthTooBigError" | "FileMetadataKeysNumberTooBigError" | "FileMetadataValueEmptyError" | "FileMetadataValueForbiddenError" | "FileMetadataValueLengthTooBigError" | "FileSizeLimitExceededError" | "MethodNotAllowedError" | "NullCharactersForbiddenError" | "PostRequestParserFailedError" | "ProjectPublicKeyInvalidError" | "ProjectPublicKeyRemovedError" | "ProjectPublicKeyRequiredError" | "RequestFileNumberLimitExceededError" | "RequestFiledsNumberLimitExceededError" | "RequestSizeLimitExceededError" | "RequestThrottledError" | "SignatureExpirationError" | "SignatureExpirationInvalidError" | "SignatureExpirationRequiredError" | "SignatureInvalidError" | "SignatureRequiredError" | "UploadAPIError" | "UploadFailedError" | "DownloadFileError" | "DownloadFileHTTPClientError" | "DownloadFileHTTPNetworkError" | "DownloadFileHTTPServerError" | "DownloadFileHTTPURLValidationError" | "DownloadFileInternalServerError" | "DownloadFileNotFoundError" | "DownloadFileSizeLimitExceededError" | "DownloadFileTaskFailedError" | "DownloadFileTimeLimitExceededError" | "DownloadFileValidationFailedError" | "FileIdInvalidError" | "FileIdNotUniqueError" | "FileIdRequiredError" | "FileNotFoundError" | "FileRequiredError" | "FilesNumberLimitExceededError" | "FilesRequiredError" | "InternalRequestForbiddenError" | "InternalRequestInvalidError" | "MultipartFileAlreadyUploadedError" | "MultipartFileCompletionFailedError" | "MultipartFileIdRequiredError" | "MultipartFileNotFoundError" | "MultipartFileSizeLimitExceededError" | "MultipartFileSizeTooSmallError" | "MultipartPartSizeInvalidError" | "MultipartPartSizeTooBigError" | "MultipartPartSizeTooSmallError" | "MultipartSizeInvalidError" | "MultipartUploadSizeTooLargeError" | "MultipartUploadSizeTooSmallError" | "RequestParamRequiredError" | "SourceURLRequiredError" | "TokenRequiredError" | "UUIDInvalidError" | "UploadViewsError" | "UploadcareFileIdDuplicatedError" | "UploadcareFileIdInvalidError" | "UploadcareFileIdRequiredError" | "GroupFileURLParsingFailedError" | "GroupFilesInvalidError" | "GroupFilesNotFoundError" | "GroupIdRequiredError" | "GroupNotFoundError" | "GroupViewsError" | "FileInfectedError" | "FileTypeForbiddenError" | "HostnameNotFoundError" | "URLBlacklistedError" | "URLHostMalformedError" | "URLHostPrivateIPForbiddenError" | "URLHostRequiredError" | "URLParsingFailedError" | "URLRedirectsLimitExceededError" | "URLSchemeInvalidError" | "URLSchemeRequiredError" | "URLValidationError";
|
|
210
218
|
export declare enum Status {
|
|
211
219
|
Unknown = "unknown",
|
|
212
220
|
Waiting = "waiting",
|
|
@@ -229,7 +237,7 @@ export type StatusProgressResponse = {
|
|
|
229
237
|
export type StatusErrorResponse = {
|
|
230
238
|
status: Status.Error;
|
|
231
239
|
error: string;
|
|
232
|
-
errorCode:
|
|
240
|
+
errorCode: ServerErrorCode;
|
|
233
241
|
};
|
|
234
242
|
export type StatusSuccessResponse = {
|
|
235
243
|
status: Status.Success;
|
|
@@ -520,16 +528,19 @@ export type ErrorResponseInfo = {
|
|
|
520
528
|
error?: {
|
|
521
529
|
statusCode: number;
|
|
522
530
|
content: string;
|
|
523
|
-
errorCode:
|
|
531
|
+
errorCode: ServerErrorCode;
|
|
524
532
|
};
|
|
525
533
|
};
|
|
526
|
-
export declare class
|
|
527
|
-
|
|
528
|
-
readonly code?: string;
|
|
534
|
+
export declare class UploadError extends UploadcareError {
|
|
535
|
+
readonly code?: ServerErrorCode;
|
|
529
536
|
readonly request?: ErrorRequestInfo;
|
|
530
537
|
readonly response?: ErrorResponseInfo;
|
|
531
538
|
readonly headers?: Headers;
|
|
532
|
-
constructor(message: string, code?:
|
|
539
|
+
constructor(message: string, code?: ServerErrorCode, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
|
|
533
540
|
}
|
|
541
|
+
/** @deprecated Please use NetworkError instead. */
|
|
542
|
+
export declare const UploadcareNetworkError: typeof NetworkError;
|
|
543
|
+
/** @deprecated Please use UploadError instead. */
|
|
544
|
+
export declare const UploadClientError: typeof UploadError;
|
|
534
545
|
|
|
535
546
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadcare/upload-client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.1",
|
|
4
4
|
"description": "Library for work with Uploadcare Upload API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.node.mjs",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"koa-body": "5.0.0",
|
|
91
91
|
"mock-socket": "9.0.3",
|
|
92
92
|
"start-server-and-test": "1.14.0",
|
|
93
|
-
"@uploadcare/api-client-utils": "^6.
|
|
93
|
+
"@uploadcare/api-client-utils": "^6.12.1",
|
|
94
94
|
"chalk": "^4.1.2"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|