@uploadcare/upload-client 6.11.1 → 6.12.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.
@@ -91,13 +91,16 @@ function retrier(fn, options = defaultOptions) {
91
91
  return runAttempt(fn);
92
92
  }
93
93
 
94
- class UploadcareNetworkError extends Error {
94
+ class UploadcareError extends Error {
95
+ }
96
+
97
+ class NetworkError extends UploadcareError {
95
98
  originalProgressEvent;
96
99
  constructor(progressEvent) {
97
100
  super();
98
- this.name = 'UploadcareNetworkError';
101
+ this.name = 'NetworkError';
99
102
  this.message = 'Network error';
100
- Object.setPrototypeOf(this, UploadcareNetworkError.prototype);
103
+ Object.setPrototypeOf(this, NetworkError.prototype);
101
104
  this.originalProgressEvent = progressEvent;
102
105
  }
103
106
  }
@@ -113,10 +116,11 @@ const onCancel = (signal, callback) => {
113
116
  }
114
117
  };
115
118
 
116
- class CancelError extends Error {
119
+ class CancelError extends UploadcareError {
117
120
  isCancel = true;
118
121
  constructor(message = 'Request canceled') {
119
122
  super(message);
123
+ this.name = 'CancelError';
120
124
  Object.setPrototypeOf(this, CancelError.prototype);
121
125
  }
122
126
  }
@@ -249,7 +253,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
249
253
  if (aborted)
250
254
  return;
251
255
  // only triggers if the request couldn't be made at all
252
- reject(new UploadcareNetworkError(progressEvent));
256
+ reject(new NetworkError(progressEvent));
253
257
  };
254
258
  if (onProgress && typeof onProgress === 'function') {
255
259
  xhr.upload.onprogress = (event) => {
@@ -356,21 +360,20 @@ function buildFormData(options) {
356
360
  return formData;
357
361
  }
358
362
 
359
- class UploadClientError extends Error {
360
- isCancel;
363
+ class UploadError extends UploadcareError {
361
364
  code;
362
365
  request;
363
366
  response;
364
367
  headers;
365
368
  constructor(message, code, request, response, headers) {
366
369
  super();
367
- this.name = 'UploadClientError';
370
+ this.name = 'UploadError';
368
371
  this.message = message;
369
372
  this.code = code;
370
373
  this.request = request;
371
374
  this.response = response;
372
375
  this.headers = headers;
373
- Object.setPrototypeOf(this, UploadClientError.prototype);
376
+ Object.setPrototypeOf(this, UploadError.prototype);
374
377
  }
375
378
  }
376
379
 
@@ -405,7 +408,7 @@ const getUrl = (base, path, query) => {
405
408
  return url.toString();
406
409
  };
407
410
 
408
- var version = '6.11.1';
411
+ var version = '6.12.0';
409
412
 
410
413
  const LIBRARY_NAME = 'UploadcareUploadClient';
411
414
  const LIBRARY_VERSION = version;
@@ -439,7 +442,7 @@ function retryIfFailed(fn, options) {
439
442
  attempt < retryThrottledRequestMaxTimes) {
440
443
  return retry(getTimeoutFromThrottledRequest(error));
441
444
  }
442
- if (error instanceof UploadcareNetworkError &&
445
+ if (error instanceof NetworkError &&
443
446
  attempt < retryNetworkErrorMaxTimes) {
444
447
  return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
445
448
  }
@@ -507,7 +510,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
507
510
  }).then(({ data, headers, request }) => {
508
511
  const response = camelizeKeys(JSON.parse(data));
509
512
  if ('error' in response) {
510
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
513
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
511
514
  }
512
515
  else {
513
516
  return response;
@@ -544,7 +547,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
544
547
  }).then(({ data, headers, request }) => {
545
548
  const response = camelizeKeys(JSON.parse(data));
546
549
  if ('error' in response) {
547
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
550
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
548
551
  }
549
552
  else {
550
553
  return response;
@@ -584,7 +587,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
584
587
  }).then(({ data, headers, request }) => {
585
588
  const response = camelizeKeys(JSON.parse(data));
586
589
  if ('error' in response && !isErrorResponse(response)) {
587
- throw new UploadClientError(response.error.content, undefined, request, response, headers);
590
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
588
591
  }
589
592
  else {
590
593
  return response;
@@ -612,7 +615,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
612
615
  }).then(({ data, headers, request }) => {
613
616
  const response = camelizeKeys(JSON.parse(data));
614
617
  if ('error' in response) {
615
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
618
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
616
619
  }
617
620
  else {
618
621
  return response;
@@ -637,7 +640,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
637
640
  }).then(({ data, headers, request }) => {
638
641
  const response = camelizeKeys(JSON.parse(data));
639
642
  if ('error' in response) {
640
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
643
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
641
644
  }
642
645
  else {
643
646
  return response;
@@ -662,7 +665,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
662
665
  }).then(({ data, headers, request }) => {
663
666
  const response = camelizeKeys(JSON.parse(data));
664
667
  if ('error' in response) {
665
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
668
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
666
669
  }
667
670
  else {
668
671
  return response;
@@ -694,7 +697,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
694
697
  }).then(({ data, headers, request }) => {
695
698
  const response = camelizeKeys(JSON.parse(data));
696
699
  if ('error' in response) {
697
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
700
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
698
701
  }
699
702
  else {
700
703
  // convert to array
@@ -749,7 +752,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
749
752
  }).then(({ data, headers, request }) => {
750
753
  const response = camelizeKeys(JSON.parse(data));
751
754
  if ('error' in response) {
752
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
755
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
753
756
  }
754
757
  else {
755
758
  return response;
@@ -1074,13 +1077,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
1074
1077
  }).then((response) => {
1075
1078
  switch (response.status) {
1076
1079
  case Status.Error: {
1077
- return new UploadClientError(response.error, response.errorCode);
1080
+ return new UploadError(response.error, response.errorCode);
1078
1081
  }
1079
1082
  case Status.Waiting: {
1080
1083
  return false;
1081
1084
  }
1082
1085
  case Status.Unknown: {
1083
- return new UploadClientError(`Token "${token}" was not found.`);
1086
+ return new UploadError(`Token "${token}" was not found.`);
1084
1087
  }
1085
1088
  case Status.Progress: {
1086
1089
  if (onProgress) {
@@ -1151,7 +1154,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
1151
1154
  }
1152
1155
  case Status.Error: {
1153
1156
  destroy();
1154
- reject(new UploadClientError(result.msg, result.error_code));
1157
+ reject(new UploadError(result.msg, result.error_code));
1155
1158
  }
1156
1159
  }
1157
1160
  });
@@ -1204,7 +1207,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
1204
1207
  }
1205
1208
  })
1206
1209
  .then((result) => {
1207
- if (result instanceof UploadClientError)
1210
+ if (result instanceof UploadError)
1208
1211
  throw result;
1209
1212
  return result;
1210
1213
  })
@@ -1752,9 +1755,19 @@ class Queue {
1752
1755
  }
1753
1756
  }
1754
1757
 
1758
+ /* Low-Level API */
1759
+ /** @deprecated Please use NetworkError instead. */
1760
+ const UploadcareNetworkError = NetworkError;
1761
+ /** @deprecated Please use UploadError instead. */
1762
+ const UploadClientError = UploadError;
1763
+
1764
+ exports.CancelError = CancelError;
1765
+ exports.NetworkError = NetworkError;
1755
1766
  exports.Queue = Queue;
1756
1767
  exports.UploadClient = UploadClient;
1757
1768
  exports.UploadClientError = UploadClientError;
1769
+ exports.UploadError = UploadError;
1770
+ exports.UploadcareError = UploadcareError;
1758
1771
  exports.UploadcareFile = UploadcareFile;
1759
1772
  exports.UploadcareGroup = UploadcareGroup;
1760
1773
  exports.UploadcareNetworkError = UploadcareNetworkError;
@@ -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 UploadcareNetworkError extends Error {
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: string;
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: string;
531
+ errorCode: ServerErrorCode;
524
532
  };
525
533
  };
526
- export declare class UploadClientError extends Error {
527
- isCancel?: boolean;
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?: string, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
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 {};
@@ -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 UploadcareNetworkError extends Error {
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: string;
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: string;
531
+ errorCode: ServerErrorCode;
524
532
  };
525
533
  };
526
- export declare class UploadClientError extends Error {
527
- isCancel?: boolean;
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?: string, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
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 UploadcareNetworkError extends Error {
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 = 'UploadcareNetworkError';
99
+ this.name = 'NetworkError';
97
100
  this.message = 'Network error';
98
- Object.setPrototypeOf(this, UploadcareNetworkError.prototype);
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 Error {
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 UploadcareNetworkError(progressEvent));
254
+ reject(new NetworkError(progressEvent));
251
255
  };
252
256
  if (onProgress && typeof onProgress === 'function') {
253
257
  xhr.upload.onprogress = (event) => {
@@ -346,21 +350,20 @@ function buildFormData(options) {
346
350
  return formData;
347
351
  }
348
352
 
349
- class UploadClientError extends Error {
350
- isCancel;
353
+ class UploadError extends UploadcareError {
351
354
  code;
352
355
  request;
353
356
  response;
354
357
  headers;
355
358
  constructor(message, code, request, response, headers) {
356
359
  super();
357
- this.name = 'UploadClientError';
360
+ this.name = 'UploadError';
358
361
  this.message = message;
359
362
  this.code = code;
360
363
  this.request = request;
361
364
  this.response = response;
362
365
  this.headers = headers;
363
- Object.setPrototypeOf(this, UploadClientError.prototype);
366
+ Object.setPrototypeOf(this, UploadError.prototype);
364
367
  }
365
368
  }
366
369
 
@@ -395,7 +398,7 @@ const getUrl = (base, path, query) => {
395
398
  return url.toString();
396
399
  };
397
400
 
398
- var version = '6.11.1';
401
+ var version = '6.12.0';
399
402
 
400
403
  const LIBRARY_NAME = 'UploadcareUploadClient';
401
404
  const LIBRARY_VERSION = version;
@@ -429,7 +432,7 @@ function retryIfFailed(fn, options) {
429
432
  attempt < retryThrottledRequestMaxTimes) {
430
433
  return retry(getTimeoutFromThrottledRequest(error));
431
434
  }
432
- if (error instanceof UploadcareNetworkError &&
435
+ if (error instanceof NetworkError &&
433
436
  attempt < retryNetworkErrorMaxTimes) {
434
437
  return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
435
438
  }
@@ -497,7 +500,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
497
500
  }).then(({ data, headers, request }) => {
498
501
  const response = camelizeKeys(JSON.parse(data));
499
502
  if ('error' in response) {
500
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
503
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
501
504
  }
502
505
  else {
503
506
  return response;
@@ -534,7 +537,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
534
537
  }).then(({ data, headers, request }) => {
535
538
  const response = camelizeKeys(JSON.parse(data));
536
539
  if ('error' in response) {
537
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
540
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
538
541
  }
539
542
  else {
540
543
  return response;
@@ -574,7 +577,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
574
577
  }).then(({ data, headers, request }) => {
575
578
  const response = camelizeKeys(JSON.parse(data));
576
579
  if ('error' in response && !isErrorResponse(response)) {
577
- throw new UploadClientError(response.error.content, undefined, request, response, headers);
580
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
578
581
  }
579
582
  else {
580
583
  return response;
@@ -602,7 +605,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
602
605
  }).then(({ data, headers, request }) => {
603
606
  const response = camelizeKeys(JSON.parse(data));
604
607
  if ('error' in response) {
605
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
608
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
606
609
  }
607
610
  else {
608
611
  return response;
@@ -627,7 +630,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
627
630
  }).then(({ data, headers, request }) => {
628
631
  const response = camelizeKeys(JSON.parse(data));
629
632
  if ('error' in response) {
630
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
633
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
631
634
  }
632
635
  else {
633
636
  return response;
@@ -652,7 +655,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
652
655
  }).then(({ data, headers, request }) => {
653
656
  const response = camelizeKeys(JSON.parse(data));
654
657
  if ('error' in response) {
655
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
658
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
656
659
  }
657
660
  else {
658
661
  return response;
@@ -684,7 +687,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
684
687
  }).then(({ data, headers, request }) => {
685
688
  const response = camelizeKeys(JSON.parse(data));
686
689
  if ('error' in response) {
687
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
690
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
688
691
  }
689
692
  else {
690
693
  // convert to array
@@ -739,7 +742,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
739
742
  }).then(({ data, headers, request }) => {
740
743
  const response = camelizeKeys(JSON.parse(data));
741
744
  if ('error' in response) {
742
- throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
745
+ throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
743
746
  }
744
747
  else {
745
748
  return response;
@@ -1064,13 +1067,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
1064
1067
  }).then((response) => {
1065
1068
  switch (response.status) {
1066
1069
  case Status.Error: {
1067
- return new UploadClientError(response.error, response.errorCode);
1070
+ return new UploadError(response.error, response.errorCode);
1068
1071
  }
1069
1072
  case Status.Waiting: {
1070
1073
  return false;
1071
1074
  }
1072
1075
  case Status.Unknown: {
1073
- return new UploadClientError(`Token "${token}" was not found.`);
1076
+ return new UploadError(`Token "${token}" was not found.`);
1074
1077
  }
1075
1078
  case Status.Progress: {
1076
1079
  if (onProgress) {
@@ -1141,7 +1144,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
1141
1144
  }
1142
1145
  case Status.Error: {
1143
1146
  destroy();
1144
- reject(new UploadClientError(result.msg, result.error_code));
1147
+ reject(new UploadError(result.msg, result.error_code));
1145
1148
  }
1146
1149
  }
1147
1150
  });
@@ -1194,7 +1197,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
1194
1197
  }
1195
1198
  })
1196
1199
  .then((result) => {
1197
- if (result instanceof UploadClientError)
1200
+ if (result instanceof UploadError)
1198
1201
  throw result;
1199
1202
  return result;
1200
1203
  })
@@ -1722,4 +1725,10 @@ class Queue {
1722
1725
  }
1723
1726
  }
1724
1727
 
1725
- export { Queue, UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, UploadcareNetworkError, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, isReadyPoll, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
1728
+ /* Low-Level API */
1729
+ /** @deprecated Please use NetworkError instead. */
1730
+ const UploadcareNetworkError = NetworkError;
1731
+ /** @deprecated Please use UploadError instead. */
1732
+ const UploadClientError = UploadError;
1733
+
1734
+ 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 UploadcareNetworkError extends Error {
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: string;
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: string;
531
+ errorCode: ServerErrorCode;
524
532
  };
525
533
  };
526
- export declare class UploadClientError extends Error {
527
- isCancel?: boolean;
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?: string, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
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 {};