@atlaskit/media-client 29.1.0 → 30.0.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/client/file-fetcher/error.js +12 -10
  3. package/dist/cjs/client/file-fetcher/index.js +28 -46
  4. package/dist/cjs/client/media-store/error.js +4 -5
  5. package/dist/cjs/index.js +12 -0
  6. package/dist/cjs/models/errors/index.js +68 -5
  7. package/dist/cjs/models/errors/types.js +5 -1
  8. package/dist/cjs/uploader/error.js +11 -9
  9. package/dist/cjs/uploader/index.js +2 -1
  10. package/dist/cjs/utils/mobileUpload/error.js +12 -10
  11. package/dist/cjs/utils/mobileUpload/helpers.js +4 -2
  12. package/dist/cjs/utils/polling/errors.js +6 -7
  13. package/dist/cjs/utils/polling/index.js +6 -2
  14. package/dist/cjs/utils/request/errors.js +4 -6
  15. package/dist/cjs/utils/request/helpers.js +8 -3
  16. package/dist/es2019/client/file-fetcher/error.js +10 -7
  17. package/dist/es2019/client/file-fetcher/index.js +22 -45
  18. package/dist/es2019/client/media-store/error.js +4 -3
  19. package/dist/es2019/index.js +1 -1
  20. package/dist/es2019/models/errors/index.js +62 -5
  21. package/dist/es2019/models/errors/types.js +1 -0
  22. package/dist/es2019/uploader/error.js +10 -7
  23. package/dist/es2019/uploader/index.js +2 -1
  24. package/dist/es2019/utils/mobileUpload/error.js +10 -7
  25. package/dist/es2019/utils/mobileUpload/helpers.js +4 -2
  26. package/dist/es2019/utils/polling/errors.js +8 -5
  27. package/dist/es2019/utils/polling/index.js +6 -2
  28. package/dist/es2019/utils/request/errors.js +4 -4
  29. package/dist/es2019/utils/request/helpers.js +8 -3
  30. package/dist/esm/client/file-fetcher/error.js +12 -10
  31. package/dist/esm/client/file-fetcher/index.js +29 -47
  32. package/dist/esm/client/media-store/error.js +4 -5
  33. package/dist/esm/index.js +1 -1
  34. package/dist/esm/models/errors/index.js +67 -4
  35. package/dist/esm/models/errors/types.js +1 -0
  36. package/dist/esm/uploader/error.js +11 -9
  37. package/dist/esm/uploader/index.js +2 -1
  38. package/dist/esm/utils/mobileUpload/error.js +12 -10
  39. package/dist/esm/utils/mobileUpload/helpers.js +4 -2
  40. package/dist/esm/utils/polling/errors.js +6 -7
  41. package/dist/esm/utils/polling/index.js +6 -2
  42. package/dist/esm/utils/request/errors.js +4 -6
  43. package/dist/esm/utils/request/helpers.js +8 -3
  44. package/dist/types/client/file-fetcher/error.d.ts +9 -12
  45. package/dist/types/client/media-store/error.d.ts +3 -4
  46. package/dist/types/index.d.ts +1 -1
  47. package/dist/types/models/errors/index.d.ts +17 -4
  48. package/dist/types/models/errors/types.d.ts +7 -0
  49. package/dist/types/uploader/error.d.ts +8 -10
  50. package/dist/types/utils/mobileUpload/error.d.ts +9 -12
  51. package/dist/types/utils/polling/errors.d.ts +4 -5
  52. package/dist/types/utils/polling/types.d.ts +3 -0
  53. package/dist/types/utils/request/errors.d.ts +3 -5
  54. package/dist/types-ts4.5/client/file-fetcher/error.d.ts +9 -12
  55. package/dist/types-ts4.5/client/media-store/error.d.ts +3 -4
  56. package/dist/types-ts4.5/index.d.ts +1 -1
  57. package/dist/types-ts4.5/models/errors/index.d.ts +17 -4
  58. package/dist/types-ts4.5/models/errors/types.d.ts +7 -0
  59. package/dist/types-ts4.5/uploader/error.d.ts +8 -10
  60. package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +9 -12
  61. package/dist/types-ts4.5/utils/polling/errors.d.ts +4 -5
  62. package/dist/types-ts4.5/utils/polling/types.d.ts +3 -0
  63. package/dist/types-ts4.5/utils/request/errors.d.ts +3 -5
  64. package/package.json +2 -2
@@ -1,9 +1,12 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _createClass from "@babel/runtime/helpers/createClass";
2
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
6
  import _inherits from "@babel/runtime/helpers/inherits";
6
7
  import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
10
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
11
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
12
  export { isMediaClientError, getMediaClientErrorReason } from './helpers';
@@ -12,13 +15,15 @@ export { isMediaClientError, getMediaClientErrorReason } from './helpers';
12
15
  * Base class for media errors
13
16
  */
14
17
  export var BaseMediaClientError = /*#__PURE__*/function (_Error) {
15
- function BaseMediaClientError(message) {
18
+ function BaseMediaClientError(reason, metadata, innerError) {
16
19
  var _this;
17
20
  _classCallCheck(this, BaseMediaClientError);
18
- _this = _callSuper(this, BaseMediaClientError, [message]);
21
+ _this = _callSuper(this, BaseMediaClientError, [reason]);
19
22
 
20
23
  // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
21
- _this.message = message;
24
+ _this.reason = reason;
25
+ _this.metadata = metadata;
26
+ _this.innerError = innerError;
22
27
  Object.setPrototypeOf(_this, (this instanceof BaseMediaClientError ? this.constructor : void 0).prototype);
23
28
 
24
29
  // https://v8.dev/docs/stack-trace-api
@@ -27,6 +32,64 @@ export var BaseMediaClientError = /*#__PURE__*/function (_Error) {
27
32
  }
28
33
  return _this;
29
34
  }
35
+
36
+ // TODO: Deprecate attributes getter https://product-fabric.atlassian.net/browse/CXP-4665
30
37
  _inherits(BaseMediaClientError, _Error);
31
38
  return _createClass(BaseMediaClientError);
32
- }( /*#__PURE__*/_wrapNativeSuper(Error));
39
+ }( /*#__PURE__*/_wrapNativeSuper(Error
40
+ // TODO: Deprecate attributes getter https://product-fabric.atlassian.net/browse/CXP-4665
41
+ ));
42
+
43
+ // The only reason why this class exists is because BaseMediaClientError is abstract class, so it can't be used to deserialize ErrorFileState. We can refactor and simplify this later.
44
+ /** Generic Media Client Erorr. All errors extending BaseMediaClientError match CommonMediaClientError attributes. Used to deserialize ErrorFileState */
45
+ export var CommonMediaClientError = /*#__PURE__*/function (_BaseMediaClientError) {
46
+ function CommonMediaClientError(reason, metadata, innerError) {
47
+ _classCallCheck(this, CommonMediaClientError);
48
+ return _callSuper(this, CommonMediaClientError, [reason, metadata, innerError]);
49
+ }
50
+ _inherits(CommonMediaClientError, _BaseMediaClientError);
51
+ return _createClass(CommonMediaClientError, [{
52
+ key: "attributes",
53
+ get: function get() {
54
+ return {
55
+ reason: this.reason
56
+ };
57
+ }
58
+ }]);
59
+ }(BaseMediaClientError);
60
+ export function isCommonMediaClientError(error) {
61
+ if (!error) {
62
+ return false;
63
+ }
64
+ // Check if the error is an instance of Error
65
+ if (error instanceof CommonMediaClientError) {
66
+ return true;
67
+ }
68
+ return typeof error.reason === 'string' && ('metadata' in error || error.metadata === undefined) && ('innerError' in error || error.innerError === undefined);
69
+ }
70
+
71
+ /** Deserializer ErrorFileState -> CommonMediaClientError */
72
+ export var toCommonMediaClientError = function toCommonMediaClientError(errorFileState) {
73
+ var _errorFileState$detai;
74
+ var error = (_errorFileState$detai = errorFileState.details) === null || _errorFileState$detai === void 0 ? void 0 : _errorFileState$detai.error;
75
+ return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error.metadata, error.innerError);
76
+ };
77
+
78
+ /** Serializer CommonMediaClientError -> ErrorFileState */
79
+ export var fromCommonMediaClientError = function fromCommonMediaClientError(id, occurrenceKey, error) {
80
+ return {
81
+ status: 'error',
82
+ id: id,
83
+ occurrenceKey: occurrenceKey,
84
+ reason: error.reason,
85
+ details: _objectSpread({
86
+ /** Use this attr to translate back into CommonMediaClientError (toCommonMediaClientError) */
87
+ error: {
88
+ reason: error === null || error === void 0 ? void 0 : error.reason,
89
+ metadata: error === null || error === void 0 ? void 0 : error.metadata,
90
+ innerError: error === null || error === void 0 ? void 0 : error.innerError
91
+ }
92
+ }, error === null || error === void 0 ? void 0 : error.attributes),
93
+ message: error === null || error === void 0 ? void 0 : error.message
94
+ };
95
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -7,25 +7,27 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../models/errors';
9
9
  export var UploaderError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- function UploaderError(reason, id, metadata) {
10
+ // Legacy Attribute. Should be removed
11
+
12
+ function UploaderError(reason, metadata) {
11
13
  var _this;
12
14
  _classCallCheck(this, UploaderError);
13
- _this = _callSuper(this, UploaderError, [reason]);
14
- _this.reason = reason;
15
- _this.id = id;
16
- _this.metadata = metadata;
15
+ _this = _callSuper(this, UploaderError, [reason, metadata, undefined]);
16
+ _this.id = metadata.id;
17
17
  return _this;
18
18
  }
19
+
20
+ // TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
21
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
19
22
  _inherits(UploaderError, _BaseMediaClientError);
20
23
  return _createClass(UploaderError, [{
21
24
  key: "attributes",
22
25
  get: function get() {
23
26
  var reason = this.reason,
24
- id = this.id,
25
27
  _this$metadata = this.metadata,
26
- _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
27
- collectionName = _this$metadata2.collectionName,
28
- occurrenceKey = _this$metadata2.occurrenceKey;
28
+ id = _this$metadata.id,
29
+ collectionName = _this$metadata.collectionName,
30
+ occurrenceKey = _this$metadata.occurrenceKey;
29
31
  return {
30
32
  reason: reason,
31
33
  id: id,
@@ -143,7 +143,8 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
143
143
  }
144
144
  } catch (err) {
145
145
  if (err instanceof Error && err.message === fileSizeError) {
146
- callbacks === null || callbacks === void 0 || callbacks.onUploadFinish(new UploaderError(err.message, id, {
146
+ callbacks === null || callbacks === void 0 || callbacks.onUploadFinish(new UploaderError(err.message, {
147
+ id: id,
147
148
  collectionName: collection,
148
149
  occurrenceKey: occurrenceKey
149
150
  }));
@@ -7,26 +7,28 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- function MobileUploadError(reason, id, metadata) {
10
+ // Legacy Attribute. Should be removed
11
+
12
+ function MobileUploadError(reason, metadata) {
11
13
  var _this;
12
14
  _classCallCheck(this, MobileUploadError);
13
- _this = _callSuper(this, MobileUploadError, [reason]);
14
- _this.reason = reason;
15
- _this.id = id;
16
- _this.metadata = metadata;
15
+ _this = _callSuper(this, MobileUploadError, [reason, metadata, undefined]);
16
+ _this.id = metadata.id;
17
17
  return _this;
18
18
  }
19
+
20
+ // TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
21
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
19
22
  _inherits(MobileUploadError, _BaseMediaClientError);
20
23
  return _createClass(MobileUploadError, [{
21
24
  key: "attributes",
22
25
  get: function get() {
23
26
  var reason = this.reason,
24
- id = this.id,
25
27
  _this$metadata = this.metadata,
26
- _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
27
- collectionName = _this$metadata2.collectionName,
28
- occurrenceKey = _this$metadata2.occurrenceKey,
29
- traceContext = _this$metadata2.traceContext;
28
+ id = _this$metadata.id,
29
+ collectionName = _this$metadata.collectionName,
30
+ occurrenceKey = _this$metadata.occurrenceKey,
31
+ traceContext = _this$metadata.traceContext;
30
32
  return {
31
33
  reason: reason,
32
34
  id: id,
@@ -40,7 +40,8 @@ export var createMobileDownloadFileStream = function createMobileDownloadFileStr
40
40
  _context.next = 5;
41
41
  break;
42
42
  }
43
- throw new MobileUploadError('emptyItems', id, {
43
+ throw new MobileUploadError('emptyItems', {
44
+ id: id,
44
45
  collectionName: collectionName,
45
46
  occurrenceKey: occurrenceKey,
46
47
  traceContext: response.metadataTraceContext
@@ -50,7 +51,8 @@ export var createMobileDownloadFileStream = function createMobileDownloadFileStr
50
51
  _context.next = 7;
51
52
  break;
52
53
  }
53
- throw new MobileUploadError('zeroVersionFile', id, {
54
+ throw new MobileUploadError('zeroVersionFile', {
55
+ id: id,
54
56
  collectionName: collectionName,
55
57
  occurrenceKey: occurrenceKey,
56
58
  traceContext: response.metadataTraceContext
@@ -7,20 +7,19 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var PollingError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- function PollingError(reason, attempts) {
11
- var _this;
10
+ function PollingError(reason, metadata) {
12
11
  _classCallCheck(this, PollingError);
13
- _this = _callSuper(this, PollingError, [reason]);
14
- _this.reason = reason;
15
- _this.attempts = attempts;
16
- return _this;
12
+ return _callSuper(this, PollingError, [reason, metadata, undefined]);
17
13
  }
14
+
15
+ // TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
16
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
18
17
  _inherits(PollingError, _BaseMediaClientError);
19
18
  return _createClass(PollingError, [{
20
19
  key: "attributes",
21
20
  get: function get() {
22
21
  var reason = this.reason,
23
- attempts = this.attempts;
22
+ attempts = this.metadata.attempts;
24
23
  return {
25
24
  reason: reason,
26
25
  attempts: attempts
@@ -50,7 +50,9 @@ export var PollingFunction = /*#__PURE__*/function () {
50
50
  _context.next = 3;
51
51
  break;
52
52
  }
53
- return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', this.attempt)));
53
+ return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', {
54
+ attempts: this.attempt
55
+ })));
54
56
  case 3:
55
57
  _context.prev = 3;
56
58
  // executor must explicitly call this.next() for triggering next iteration (pull)
@@ -68,7 +70,9 @@ export var PollingFunction = /*#__PURE__*/function () {
68
70
  _context.next = 11;
69
71
  break;
70
72
  }
71
- return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', this.attempt)));
73
+ return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', {
74
+ attempts: this.attempt
75
+ })));
72
76
  case 11:
73
77
  this.poll_intervalMs = this.getIntervalMsForIteration(this.attempt);
74
78
  this.attempt++;
@@ -8,14 +8,12 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
10
10
  function RequestError(reason, metadata, innerError) {
11
- var _this;
12
11
  _classCallCheck(this, RequestError);
13
- _this = _callSuper(this, RequestError, [reason]);
14
- _this.reason = reason;
15
- _this.metadata = metadata;
16
- _this.innerError = innerError;
17
- return _this;
12
+ return _callSuper(this, RequestError, [reason, metadata, innerError]);
18
13
  }
14
+
15
+ // TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
16
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
19
17
  _inherits(RequestError, _BaseMediaClientError);
20
18
  return _createClass(RequestError, [{
21
19
  key: "attributes",
@@ -9,6 +9,10 @@ import { isClientBasedAuth } from '@atlaskit/media-core';
9
9
  import { getRandomHex } from '@atlaskit/media-common';
10
10
  import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
11
11
  import { RequestError, isRequestError } from './errors';
12
+ var getStatusCode = function getStatusCode(error) {
13
+ var _error$metadata;
14
+ return isRequestError(error) && ((_error$metadata = error.metadata) === null || _error$metadata === void 0 ? void 0 : _error$metadata.statusCode) && error.metadata.statusCode;
15
+ };
12
16
  export function waitPromise(timeout) {
13
17
  return new Promise(function (resolve) {
14
18
  return setTimeout(resolve, timeout);
@@ -23,7 +27,8 @@ export function isFetchNetworkError(err) {
23
27
  return err instanceof TypeError;
24
28
  }
25
29
  export function isRateLimitedError(error) {
26
- return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
30
+ var statusCode = error && getStatusCode(error);
31
+ return statusCode === 429 || !!error && !!error.message && error.message.includes('429');
27
32
  }
28
33
  export var extendTraceContext = function extendTraceContext(traceContext) {
29
34
  return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
@@ -136,8 +141,8 @@ export function createMapResponseToBlob(metadata) {
136
141
  }();
137
142
  }
138
143
  export var defaultShouldRetryError = function defaultShouldRetryError(err) {
139
- var _err$metadata;
140
- return isFetchNetworkError(err) || isRequestError(err) && !!(err !== null && err !== void 0 && (_err$metadata = err.metadata) !== null && _err$metadata !== void 0 && _err$metadata.statusCode) && err.metadata.statusCode >= 500;
144
+ var statusCode = getStatusCode(err);
145
+ return isFetchNetworkError(err) || (statusCode ? statusCode >= 500 : false);
141
146
  };
142
147
  export var DEFAULT_RETRY_OPTIONS = {
143
148
  startTimeoutInMs: 1000,
@@ -10,19 +10,16 @@ export type FileFetcherErrorAttributes = {
10
10
  readonly traceContext?: MediaTraceContext;
11
11
  };
12
12
  };
13
- export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorAttributes> {
14
- readonly reason: FileFetcherErrorReason;
13
+ export type FileFetcherErrorMetadata = {
15
14
  readonly id: string;
16
- readonly metadata?: {
17
- readonly collectionName?: string | undefined;
18
- readonly occurrenceKey?: string | undefined;
19
- readonly traceContext?: MediaTraceContext | undefined;
20
- } | undefined;
21
- constructor(reason: FileFetcherErrorReason, id: string, metadata?: {
22
- readonly collectionName?: string | undefined;
23
- readonly occurrenceKey?: string | undefined;
24
- readonly traceContext?: MediaTraceContext | undefined;
25
- } | undefined);
15
+ readonly collectionName?: string;
16
+ readonly occurrenceKey?: string;
17
+ readonly traceContext?: MediaTraceContext;
18
+ };
19
+ export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorReason, FileFetcherErrorMetadata, undefined, FileFetcherErrorAttributes> {
20
+ readonly id: string;
21
+ constructor(reason: FileFetcherErrorReason, metadata: FileFetcherErrorMetadata);
22
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
26
23
  get attributes(): {
27
24
  metadata?: {
28
25
  traceContext: MediaTraceContext;
@@ -4,10 +4,9 @@ export type MediaStoreErrorAttributes = {
4
4
  readonly reason: MediaStoreErrorReason;
5
5
  readonly innerError?: Error;
6
6
  };
7
- export declare class MediaStoreError extends BaseMediaClientError<MediaStoreErrorAttributes> {
8
- readonly reason: MediaStoreErrorReason;
9
- readonly innerError?: Error | undefined;
10
- constructor(reason: MediaStoreErrorReason, innerError?: Error | undefined);
7
+ export declare class MediaStoreError extends BaseMediaClientError<MediaStoreErrorReason, undefined, Error | undefined, MediaStoreErrorAttributes> {
8
+ constructor(reason: MediaStoreErrorReason, innerError?: Error);
9
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
11
10
  get attributes(): {
12
11
  reason: MediaStoreErrorReason;
13
12
  innerError: Error | undefined;
@@ -6,7 +6,7 @@ export type { MediaItemType, FileItem, FileProcessingStatus, MediaArtifact, Arti
6
6
  export { isPreviewableType } from './models/media';
7
7
  export type { MediaFileProcessingStatus, MediaType, MediaFile, MediaRepresentations, MediaItemDetails, MediaUpload, } from './models/media';
8
8
  export { getArtifactUrl } from './models/artifacts';
9
- export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
9
+ export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError, } from './models/errors';
10
10
  export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './models/errors';
11
11
  export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
12
12
  export type { FileStatus, PreviewOptions, GetFileOptions, NonErrorFileState, PreviewableFileState, } from './models/file-state';
@@ -1,11 +1,24 @@
1
- import { type MediaClientError, type MediaClientErrorAttributes } from './types';
1
+ import type { ErrorFileState } from '@atlaskit/media-state';
2
+ import type { MediaClientError, MediaClientErrorAttributes, MediaClientErrorReason, MediaClientErrorMetadata } from './types';
2
3
  export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes } from './types';
3
4
  export { isMediaClientError, getMediaClientErrorReason } from './helpers';
4
5
  /**
5
6
  * Base class for media errors
6
7
  */
7
- export declare abstract class BaseMediaClientError<Attributes extends MediaClientErrorAttributes> extends Error implements MediaClientError<Attributes> {
8
- readonly message: string;
9
- constructor(message: string);
8
+ export declare abstract class BaseMediaClientError<Reason extends MediaClientErrorReason, Metadata extends MediaClientErrorMetadata | undefined, InnerError extends Error | undefined, Attributes extends MediaClientErrorAttributes> extends Error implements MediaClientError<Attributes> {
9
+ readonly reason: Reason;
10
+ readonly metadata: Metadata;
11
+ readonly innerError: InnerError;
12
+ constructor(reason: Reason, metadata: Metadata, innerError: InnerError);
10
13
  abstract get attributes(): Attributes;
11
14
  }
15
+ /** Generic Media Client Erorr. All errors extending BaseMediaClientError match CommonMediaClientError attributes. Used to deserialize ErrorFileState */
16
+ export declare class CommonMediaClientError extends BaseMediaClientError<MediaClientErrorReason, MediaClientErrorMetadata | undefined, Error | undefined, MediaClientErrorAttributes> {
17
+ constructor(reason: MediaClientErrorReason, metadata?: MediaClientErrorMetadata, innerError?: Error);
18
+ get attributes(): MediaClientErrorAttributes;
19
+ }
20
+ export declare function isCommonMediaClientError(error: any): error is BaseMediaClientError<MediaClientErrorReason, MediaClientErrorMetadata | undefined, Error | undefined, MediaClientErrorAttributes>;
21
+ /** Deserializer ErrorFileState -> CommonMediaClientError */
22
+ export declare const toCommonMediaClientError: (errorFileState: ErrorFileState) => CommonMediaClientError;
23
+ /** Serializer CommonMediaClientError -> ErrorFileState */
24
+ export declare const fromCommonMediaClientError: (id: string, occurrenceKey: string | undefined, error: CommonMediaClientError) => ErrorFileState;
@@ -1,4 +1,11 @@
1
+ import { type MediaTraceContext } from '@atlaskit/media-common';
2
+ export interface SerializableObject {
3
+ [key: string]: string | number | boolean | null | undefined | SerializableObject;
4
+ }
1
5
  export type MediaClientErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError' | 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut' | 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'emptyFileName' | 'pollingMaxAttemptsExceeded' | 'fileSizeExceedsLimit' | 'deprecatedEndpoint';
6
+ export type MediaClientErrorMetadata = SerializableObject & {
7
+ traceContext?: MediaTraceContext;
8
+ };
2
9
  export interface MediaClientErrorAttributes {
3
10
  reason: MediaClientErrorReason;
4
11
  }
@@ -8,17 +8,15 @@ export type UploaderErrorAttributes = {
8
8
  readonly occurrenceKey?: string;
9
9
  };
10
10
  };
11
- export declare class UploaderError extends BaseMediaClientError<UploaderErrorAttributes> {
12
- readonly reason: UploaderErrorReason;
11
+ export type UploaderErrorMetadata = {
13
12
  readonly id: string;
14
- readonly metadata?: {
15
- readonly collectionName?: string | undefined;
16
- readonly occurrenceKey?: string | undefined;
17
- } | undefined;
18
- constructor(reason: UploaderErrorReason, id: string, metadata?: {
19
- readonly collectionName?: string | undefined;
20
- readonly occurrenceKey?: string | undefined;
21
- } | undefined);
13
+ readonly collectionName?: string;
14
+ readonly occurrenceKey?: string;
15
+ };
16
+ export declare class UploaderError extends BaseMediaClientError<UploaderErrorReason, UploaderErrorMetadata, undefined, UploaderErrorAttributes> {
17
+ readonly id: string;
18
+ constructor(reason: UploaderErrorReason, metadata: UploaderErrorMetadata);
19
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
22
20
  get attributes(): {
23
21
  reason: "fileSizeExceedsLimit";
24
22
  id: string;
@@ -10,19 +10,16 @@ export type MobileUploadErrorAttributes = {
10
10
  readonly traceContext?: MediaTraceContext;
11
11
  };
12
12
  };
13
- export declare class MobileUploadError extends BaseMediaClientError<MobileUploadErrorAttributes> {
14
- readonly reason: MobileUploadErrorReason;
13
+ export type MobileUploadErrorMetadata = {
15
14
  readonly id: string;
16
- readonly metadata?: {
17
- readonly collectionName?: string | undefined;
18
- readonly occurrenceKey?: string | undefined;
19
- readonly traceContext?: MediaTraceContext | undefined;
20
- } | undefined;
21
- constructor(reason: MobileUploadErrorReason, id: string, metadata?: {
22
- readonly collectionName?: string | undefined;
23
- readonly occurrenceKey?: string | undefined;
24
- readonly traceContext?: MediaTraceContext | undefined;
25
- } | undefined);
15
+ readonly collectionName?: string;
16
+ readonly occurrenceKey?: string;
17
+ readonly traceContext?: MediaTraceContext;
18
+ };
19
+ export declare class MobileUploadError extends BaseMediaClientError<MobileUploadErrorReason, MobileUploadErrorMetadata, undefined, MobileUploadErrorAttributes> {
20
+ readonly id: string;
21
+ constructor(reason: MobileUploadErrorReason, metadata: MobileUploadErrorMetadata);
22
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
26
23
  get attributes(): {
27
24
  reason: MobileUploadErrorReason;
28
25
  id: string;
@@ -1,9 +1,8 @@
1
1
  import { BaseMediaClientError } from '../../models/errors';
2
- import { type PollingErrorReason, type PollingErrorAttributes } from './types';
3
- export declare class PollingError extends BaseMediaClientError<PollingErrorAttributes> {
4
- readonly reason: PollingErrorReason;
5
- readonly attempts: number;
6
- constructor(reason: PollingErrorReason, attempts: number);
2
+ import { type PollingErrorReason, type PollingErrorAttributes, type PollingErrorMetadata } from './types';
3
+ export declare class PollingError extends BaseMediaClientError<PollingErrorReason, PollingErrorMetadata, undefined, PollingErrorAttributes> {
4
+ constructor(reason: PollingErrorReason, metadata: PollingErrorMetadata);
5
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
7
6
  get attributes(): {
8
7
  reason: "pollingMaxAttemptsExceeded";
9
8
  attempts: number;
@@ -1,5 +1,8 @@
1
1
  export type Executor = () => Promise<void>;
2
2
  export type PollingErrorReason = 'pollingMaxAttemptsExceeded';
3
+ export type PollingErrorMetadata = {
4
+ attempts: number;
5
+ };
3
6
  export type PollingErrorAttributes = {
4
7
  readonly reason: PollingErrorReason;
5
8
  readonly attempts: number;
@@ -1,10 +1,8 @@
1
1
  import { BaseMediaClientError } from '../../models/errors';
2
2
  import { type RequestErrorReason, type RequestErrorMetadata, type RequestErrorAttributes } from './types';
3
- export declare class RequestError extends BaseMediaClientError<RequestErrorAttributes> {
4
- readonly reason: RequestErrorReason;
5
- readonly metadata?: RequestErrorMetadata | undefined;
6
- readonly innerError?: Error | undefined;
7
- constructor(reason: RequestErrorReason, metadata?: RequestErrorMetadata | undefined, innerError?: Error | undefined);
3
+ export declare class RequestError extends BaseMediaClientError<RequestErrorReason, RequestErrorMetadata | undefined, Error | undefined, RequestErrorAttributes> {
4
+ constructor(reason: RequestErrorReason, metadata?: RequestErrorMetadata, innerError?: Error);
5
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
8
6
  get attributes(): {
9
7
  reason: RequestErrorReason;
10
8
  method: import("./types").RequestMethod | undefined;
@@ -10,19 +10,16 @@ export type FileFetcherErrorAttributes = {
10
10
  readonly traceContext?: MediaTraceContext;
11
11
  };
12
12
  };
13
- export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorAttributes> {
14
- readonly reason: FileFetcherErrorReason;
13
+ export type FileFetcherErrorMetadata = {
15
14
  readonly id: string;
16
- readonly metadata?: {
17
- readonly collectionName?: string | undefined;
18
- readonly occurrenceKey?: string | undefined;
19
- readonly traceContext?: MediaTraceContext | undefined;
20
- } | undefined;
21
- constructor(reason: FileFetcherErrorReason, id: string, metadata?: {
22
- readonly collectionName?: string | undefined;
23
- readonly occurrenceKey?: string | undefined;
24
- readonly traceContext?: MediaTraceContext | undefined;
25
- } | undefined);
15
+ readonly collectionName?: string;
16
+ readonly occurrenceKey?: string;
17
+ readonly traceContext?: MediaTraceContext;
18
+ };
19
+ export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorReason, FileFetcherErrorMetadata, undefined, FileFetcherErrorAttributes> {
20
+ readonly id: string;
21
+ constructor(reason: FileFetcherErrorReason, metadata: FileFetcherErrorMetadata);
22
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
26
23
  get attributes(): {
27
24
  metadata?: {
28
25
  traceContext: MediaTraceContext;
@@ -4,10 +4,9 @@ export type MediaStoreErrorAttributes = {
4
4
  readonly reason: MediaStoreErrorReason;
5
5
  readonly innerError?: Error;
6
6
  };
7
- export declare class MediaStoreError extends BaseMediaClientError<MediaStoreErrorAttributes> {
8
- readonly reason: MediaStoreErrorReason;
9
- readonly innerError?: Error | undefined;
10
- constructor(reason: MediaStoreErrorReason, innerError?: Error | undefined);
7
+ export declare class MediaStoreError extends BaseMediaClientError<MediaStoreErrorReason, undefined, Error | undefined, MediaStoreErrorAttributes> {
8
+ constructor(reason: MediaStoreErrorReason, innerError?: Error);
9
+ /** Will be deprecated. Use the properties `reason` and `metadata` instead */
11
10
  get attributes(): {
12
11
  reason: MediaStoreErrorReason;
13
12
  innerError: Error | undefined;
@@ -6,7 +6,7 @@ export type { MediaItemType, FileItem, FileProcessingStatus, MediaArtifact, Arti
6
6
  export { isPreviewableType } from './models/media';
7
7
  export type { MediaFileProcessingStatus, MediaType, MediaFile, MediaRepresentations, MediaItemDetails, MediaUpload, } from './models/media';
8
8
  export { getArtifactUrl } from './models/artifacts';
9
- export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
9
+ export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError, } from './models/errors';
10
10
  export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './models/errors';
11
11
  export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
12
12
  export type { FileStatus, PreviewOptions, GetFileOptions, NonErrorFileState, PreviewableFileState, } from './models/file-state';
@@ -1,11 +1,24 @@
1
- import { type MediaClientError, type MediaClientErrorAttributes } from './types';
1
+ import type { ErrorFileState } from '@atlaskit/media-state';
2
+ import type { MediaClientError, MediaClientErrorAttributes, MediaClientErrorReason, MediaClientErrorMetadata } from './types';
2
3
  export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes } from './types';
3
4
  export { isMediaClientError, getMediaClientErrorReason } from './helpers';
4
5
  /**
5
6
  * Base class for media errors
6
7
  */
7
- export declare abstract class BaseMediaClientError<Attributes extends MediaClientErrorAttributes> extends Error implements MediaClientError<Attributes> {
8
- readonly message: string;
9
- constructor(message: string);
8
+ export declare abstract class BaseMediaClientError<Reason extends MediaClientErrorReason, Metadata extends MediaClientErrorMetadata | undefined, InnerError extends Error | undefined, Attributes extends MediaClientErrorAttributes> extends Error implements MediaClientError<Attributes> {
9
+ readonly reason: Reason;
10
+ readonly metadata: Metadata;
11
+ readonly innerError: InnerError;
12
+ constructor(reason: Reason, metadata: Metadata, innerError: InnerError);
10
13
  abstract get attributes(): Attributes;
11
14
  }
15
+ /** Generic Media Client Erorr. All errors extending BaseMediaClientError match CommonMediaClientError attributes. Used to deserialize ErrorFileState */
16
+ export declare class CommonMediaClientError extends BaseMediaClientError<MediaClientErrorReason, MediaClientErrorMetadata | undefined, Error | undefined, MediaClientErrorAttributes> {
17
+ constructor(reason: MediaClientErrorReason, metadata?: MediaClientErrorMetadata, innerError?: Error);
18
+ get attributes(): MediaClientErrorAttributes;
19
+ }
20
+ export declare function isCommonMediaClientError(error: any): error is BaseMediaClientError<MediaClientErrorReason, MediaClientErrorMetadata | undefined, Error | undefined, MediaClientErrorAttributes>;
21
+ /** Deserializer ErrorFileState -> CommonMediaClientError */
22
+ export declare const toCommonMediaClientError: (errorFileState: ErrorFileState) => CommonMediaClientError;
23
+ /** Serializer CommonMediaClientError -> ErrorFileState */
24
+ export declare const fromCommonMediaClientError: (id: string, occurrenceKey: string | undefined, error: CommonMediaClientError) => ErrorFileState;
@@ -1,4 +1,11 @@
1
+ import { type MediaTraceContext } from '@atlaskit/media-common';
2
+ export interface SerializableObject {
3
+ [key: string]: string | number | boolean | null | undefined | SerializableObject;
4
+ }
1
5
  export type MediaClientErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError' | 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut' | 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'emptyFileName' | 'pollingMaxAttemptsExceeded' | 'fileSizeExceedsLimit' | 'deprecatedEndpoint';
6
+ export type MediaClientErrorMetadata = SerializableObject & {
7
+ traceContext?: MediaTraceContext;
8
+ };
2
9
  export interface MediaClientErrorAttributes {
3
10
  reason: MediaClientErrorReason;
4
11
  }