@atlaskit/media-client 29.1.0 → 31.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.
- package/CHANGELOG.md +39 -0
- package/dist/cjs/client/file-fetcher/error.js +12 -10
- package/dist/cjs/client/file-fetcher/index.js +54 -61
- package/dist/cjs/client/media-store/error.js +4 -5
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/models/errors/index.js +68 -5
- package/dist/cjs/models/errors/types.js +5 -1
- package/dist/cjs/models/file-state.js +4 -1
- package/dist/cjs/uploader/error.js +11 -9
- package/dist/cjs/uploader/index.js +2 -1
- package/dist/cjs/utils/mobileUpload/error.js +12 -10
- package/dist/cjs/utils/mobileUpload/helpers.js +4 -2
- package/dist/cjs/utils/polling/errors.js +6 -7
- package/dist/cjs/utils/polling/index.js +6 -2
- package/dist/cjs/utils/request/errors.js +4 -6
- package/dist/cjs/utils/request/helpers.js +8 -3
- package/dist/es2019/client/file-fetcher/error.js +10 -7
- package/dist/es2019/client/file-fetcher/index.js +36 -48
- package/dist/es2019/client/media-store/error.js +4 -3
- package/dist/es2019/index.js +2 -2
- package/dist/es2019/models/errors/index.js +62 -5
- package/dist/es2019/models/errors/types.js +1 -0
- package/dist/es2019/models/file-state.js +1 -0
- package/dist/es2019/uploader/error.js +10 -7
- package/dist/es2019/uploader/index.js +2 -1
- package/dist/es2019/utils/mobileUpload/error.js +10 -7
- package/dist/es2019/utils/mobileUpload/helpers.js +4 -2
- package/dist/es2019/utils/polling/errors.js +8 -5
- package/dist/es2019/utils/polling/index.js +6 -2
- package/dist/es2019/utils/request/errors.js +4 -4
- package/dist/es2019/utils/request/helpers.js +8 -3
- package/dist/esm/client/file-fetcher/error.js +12 -10
- package/dist/esm/client/file-fetcher/index.js +55 -62
- package/dist/esm/client/media-store/error.js +4 -5
- package/dist/esm/index.js +2 -2
- package/dist/esm/models/errors/index.js +67 -4
- package/dist/esm/models/errors/types.js +1 -0
- package/dist/esm/models/file-state.js +3 -0
- package/dist/esm/uploader/error.js +11 -9
- package/dist/esm/uploader/index.js +2 -1
- package/dist/esm/utils/mobileUpload/error.js +12 -10
- package/dist/esm/utils/mobileUpload/helpers.js +4 -2
- package/dist/esm/utils/polling/errors.js +6 -7
- package/dist/esm/utils/polling/index.js +6 -2
- package/dist/esm/utils/request/errors.js +4 -6
- package/dist/esm/utils/request/helpers.js +8 -3
- package/dist/types/client/file-fetcher/error.d.ts +9 -12
- package/dist/types/client/media-store/error.d.ts +3 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/models/errors/index.d.ts +17 -4
- package/dist/types/models/errors/types.d.ts +7 -0
- package/dist/types/models/file-state.d.ts +2 -0
- package/dist/types/uploader/error.d.ts +8 -10
- package/dist/types/utils/mobileUpload/error.d.ts +9 -12
- package/dist/types/utils/polling/errors.d.ts +4 -5
- package/dist/types/utils/polling/types.d.ts +3 -0
- package/dist/types/utils/request/errors.d.ts +3 -5
- package/dist/types-ts4.5/client/file-fetcher/error.d.ts +9 -12
- package/dist/types-ts4.5/client/media-store/error.d.ts +3 -4
- package/dist/types-ts4.5/index.d.ts +2 -2
- package/dist/types-ts4.5/models/errors/index.d.ts +17 -4
- package/dist/types-ts4.5/models/errors/types.d.ts +7 -0
- package/dist/types-ts4.5/models/file-state.d.ts +2 -0
- package/dist/types-ts4.5/uploader/error.d.ts +8 -10
- package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +9 -12
- package/dist/types-ts4.5/utils/polling/errors.d.ts +4 -5
- package/dist/types-ts4.5/utils/polling/types.d.ts +3 -0
- package/dist/types-ts4.5/utils/request/errors.d.ts +3 -5
- package/package.json +3 -3
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
|
-
var _excluded = ["metadata"],
|
|
7
|
-
_excluded2 = ["metadata"];
|
|
8
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
5
|
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; }
|
|
10
6
|
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
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
8
|
import { Subscription } from 'rxjs/Subscription';
|
|
12
9
|
import { map } from 'rxjs/operators/map';
|
|
13
10
|
import uuid from 'uuid/v4';
|
|
@@ -36,6 +33,7 @@ import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
|
36
33
|
import { mediaStore } from '@atlaskit/media-state';
|
|
37
34
|
import { createCopyIntentRegisterationBatcher } from '../../utils/createCopyIntentRegisterationBatcher';
|
|
38
35
|
import { defaultShouldRetryError } from '../../utils/request/helpers';
|
|
36
|
+
import { isCommonMediaClientError, CommonMediaClientError, fromCommonMediaClientError } from '../../models/errors';
|
|
39
37
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
40
38
|
var isCopySourceFileWithToken = function isCopySourceFileWithToken(token) {
|
|
41
39
|
return !!token.authProvider;
|
|
@@ -49,26 +47,20 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
49
47
|
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mediaStore;
|
|
50
48
|
_classCallCheck(this, FileFetcherImpl);
|
|
51
49
|
_defineProperty(this, "getErrorFileState", function (error, id, occurrenceKey) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
|
|
67
|
-
metadata: metadata
|
|
68
|
-
}),
|
|
69
|
-
occurrenceKey: occurrenceKey,
|
|
70
|
-
message: error === null || error === void 0 ? void 0 : error.message
|
|
71
|
-
};
|
|
50
|
+
if (isCommonMediaClientError(error)) {
|
|
51
|
+
return fromCommonMediaClientError(id, occurrenceKey, error);
|
|
52
|
+
}
|
|
53
|
+
// ________________________________________________
|
|
54
|
+
// Legacy serializers
|
|
55
|
+
// We need to revisit all the incoming error types and ensure all the "reason" values are known
|
|
56
|
+
// We need to change the input error: any for a known type.
|
|
57
|
+
if (typeof error === 'string') {
|
|
58
|
+
var err = new CommonMediaClientError(error);
|
|
59
|
+
return fromCommonMediaClientError(id, occurrenceKey, err);
|
|
60
|
+
} else {
|
|
61
|
+
var _err = new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
|
|
62
|
+
return fromCommonMediaClientError(id, occurrenceKey, _err);
|
|
63
|
+
}
|
|
72
64
|
});
|
|
73
65
|
_defineProperty(this, "setFileState", function (id, fileState) {
|
|
74
66
|
_this.store.setState(function (state) {
|
|
@@ -76,7 +68,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
76
68
|
});
|
|
77
69
|
});
|
|
78
70
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
79
|
-
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey, includeHashForDuplicateFiles) {
|
|
71
|
+
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey, includeHashForDuplicateFiles, forceRefresh) {
|
|
80
72
|
var subject = createMediaSubject();
|
|
81
73
|
var poll = new PollingFunction();
|
|
82
74
|
|
|
@@ -89,47 +81,56 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
89
81
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
90
82
|
while (1) switch (_context.prev = _context.next) {
|
|
91
83
|
case 0:
|
|
92
|
-
|
|
84
|
+
if (forceRefresh) {
|
|
85
|
+
_this.dataloader.clear({
|
|
86
|
+
id: id,
|
|
87
|
+
collectionName: collectionName,
|
|
88
|
+
includeHashForDuplicateFiles: includeHashForDuplicateFiles
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
_context.next = 3;
|
|
93
92
|
return _this.dataloader.load({
|
|
94
93
|
id: id,
|
|
95
94
|
collectionName: collectionName,
|
|
96
95
|
includeHashForDuplicateFiles: includeHashForDuplicateFiles
|
|
97
96
|
});
|
|
98
|
-
case
|
|
97
|
+
case 3:
|
|
99
98
|
response = _context.sent;
|
|
100
99
|
if (!isNotFoundMediaItemDetails(response)) {
|
|
101
|
-
_context.next =
|
|
100
|
+
_context.next = 6;
|
|
102
101
|
break;
|
|
103
102
|
}
|
|
104
|
-
throw new FileFetcherError('emptyItems',
|
|
103
|
+
throw new FileFetcherError('emptyItems', {
|
|
104
|
+
id: id,
|
|
105
105
|
collectionName: collectionName,
|
|
106
106
|
occurrenceKey: occurrenceKey,
|
|
107
107
|
traceContext: response.metadataTraceContext
|
|
108
108
|
});
|
|
109
|
-
case
|
|
109
|
+
case 6:
|
|
110
110
|
if (!isEmptyFile(response)) {
|
|
111
|
-
_context.next =
|
|
111
|
+
_context.next = 8;
|
|
112
112
|
break;
|
|
113
113
|
}
|
|
114
|
-
throw new FileFetcherError('zeroVersionFile',
|
|
114
|
+
throw new FileFetcherError('zeroVersionFile', {
|
|
115
|
+
id: id,
|
|
115
116
|
collectionName: collectionName,
|
|
116
117
|
occurrenceKey: occurrenceKey,
|
|
117
118
|
traceContext: response.metadataTraceContext
|
|
118
119
|
});
|
|
119
|
-
case
|
|
120
|
+
case 8:
|
|
120
121
|
fileState = mapMediaItemToFileState(id, response);
|
|
121
122
|
subject.next(fileState);
|
|
122
123
|
_context.t0 = fileState.status;
|
|
123
|
-
_context.next = _context.t0 === 'processing' ?
|
|
124
|
+
_context.next = _context.t0 === 'processing' ? 13 : _context.t0 === 'processed' ? 15 : 17;
|
|
124
125
|
break;
|
|
125
|
-
case
|
|
126
|
+
case 13:
|
|
126
127
|
// the only case for continuing polling, otherwise this function is run once only
|
|
127
128
|
poll.next();
|
|
128
|
-
return _context.abrupt("break",
|
|
129
|
-
case
|
|
129
|
+
return _context.abrupt("break", 17);
|
|
130
|
+
case 15:
|
|
130
131
|
subject.complete();
|
|
131
|
-
return _context.abrupt("break",
|
|
132
|
-
case
|
|
132
|
+
return _context.abrupt("break", 17);
|
|
133
|
+
case 17:
|
|
133
134
|
case "end":
|
|
134
135
|
return _context.stop();
|
|
135
136
|
}
|
|
@@ -182,33 +183,25 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
182
183
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
183
184
|
var collectionName = options.collectionName,
|
|
184
185
|
occurrenceKey = options.occurrenceKey,
|
|
185
|
-
includeHashForDuplicateFiles = options.includeHashForDuplicateFiles
|
|
186
|
+
includeHashForDuplicateFiles = options.includeHashForDuplicateFiles,
|
|
187
|
+
forceRefresh = options.forceRefresh;
|
|
186
188
|
if (!isValidId(id)) {
|
|
187
|
-
var _err$attributes;
|
|
188
189
|
var subject = createMediaSubject();
|
|
189
|
-
var err = new FileFetcherError('invalidFileId',
|
|
190
|
+
var err = new FileFetcherError('invalidFileId', {
|
|
191
|
+
id: id,
|
|
190
192
|
collectionName: collectionName,
|
|
191
193
|
occurrenceKey: occurrenceKey
|
|
192
194
|
});
|
|
193
|
-
var
|
|
194
|
-
metadata = _ref3.metadata,
|
|
195
|
-
attributes = _objectWithoutProperties(_ref3, _excluded2);
|
|
196
|
-
var errorFileState = {
|
|
197
|
-
status: 'error',
|
|
198
|
-
id: id,
|
|
199
|
-
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
200
|
-
message: err === null || err === void 0 ? void 0 : err.message,
|
|
201
|
-
occurrenceKey: occurrenceKey,
|
|
202
|
-
details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
|
|
203
|
-
metadata: metadata
|
|
204
|
-
})
|
|
205
|
-
};
|
|
195
|
+
var errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
206
196
|
subject.error(err);
|
|
207
197
|
this.setFileState(id, errorFileState);
|
|
208
198
|
return fromObservable(subject);
|
|
209
199
|
}
|
|
200
|
+
if (forceRefresh) {
|
|
201
|
+
getFileStreamsCache().remove(id);
|
|
202
|
+
}
|
|
210
203
|
return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
|
|
211
|
-
var subject = _this2.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles);
|
|
204
|
+
var subject = _this2.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles, forceRefresh);
|
|
212
205
|
subject.subscribe({
|
|
213
206
|
next: function next(fileState) {
|
|
214
207
|
_this2.setFileState(id, fileState);
|
|
@@ -243,8 +236,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
243
236
|
descriptors: descriptors
|
|
244
237
|
}, {
|
|
245
238
|
collection: collection
|
|
246
|
-
}, traceContext).then(function (
|
|
247
|
-
var data =
|
|
239
|
+
}, traceContext).then(function (_ref2) {
|
|
240
|
+
var data = _ref2.data;
|
|
248
241
|
return data;
|
|
249
242
|
});
|
|
250
243
|
}
|
|
@@ -285,7 +278,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
285
278
|
return undefined;
|
|
286
279
|
});
|
|
287
280
|
preview = new Promise( /*#__PURE__*/function () {
|
|
288
|
-
var
|
|
281
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
|
|
289
282
|
var blob;
|
|
290
283
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
291
284
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -308,7 +301,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
308
301
|
}, _callee2);
|
|
309
302
|
}));
|
|
310
303
|
return function (_x4, _x5) {
|
|
311
|
-
return
|
|
304
|
+
return _ref3.apply(this, arguments);
|
|
312
305
|
};
|
|
313
306
|
}());
|
|
314
307
|
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
@@ -327,7 +320,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
327
320
|
getFileStreamsCache().set(id, subject);
|
|
328
321
|
this.setFileState(id, fileState);
|
|
329
322
|
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
330
|
-
var
|
|
323
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
|
|
331
324
|
var blob, type, size, file, mediaType, dimensions;
|
|
332
325
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
333
326
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -388,7 +381,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
388
381
|
}, _callee3, null, [[10, 16]]);
|
|
389
382
|
}));
|
|
390
383
|
return function (_x6, _x7) {
|
|
391
|
-
return
|
|
384
|
+
return _ref4.apply(this, arguments);
|
|
392
385
|
};
|
|
393
386
|
}()));
|
|
394
387
|
case 11:
|
|
@@ -8,13 +8,12 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
8
8
|
import { BaseMediaClientError } from '../../models/errors';
|
|
9
9
|
export var MediaStoreError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
10
10
|
function MediaStoreError(reason, innerError) {
|
|
11
|
-
var _this;
|
|
12
11
|
_classCallCheck(this, MediaStoreError);
|
|
13
|
-
|
|
14
|
-
_this.reason = reason;
|
|
15
|
-
_this.innerError = innerError;
|
|
16
|
-
return _this;
|
|
12
|
+
return _callSuper(this, MediaStoreError, [reason, undefined, innerError]);
|
|
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(MediaStoreError, _BaseMediaClientError);
|
|
19
18
|
return _createClass(MediaStoreError, [{
|
|
20
19
|
key: "attributes",
|
package/dist/esm/index.js
CHANGED
|
@@ -2,8 +2,8 @@ export { MediaStore, MediaStoreError, isMediaStoreError, getMediaEnvironment, ge
|
|
|
2
2
|
export { UploadController } from './upload-controller';
|
|
3
3
|
export { isPreviewableType } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
|
-
export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
|
|
6
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
5
|
+
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError } from './models/errors';
|
|
6
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
7
7
|
export { uploadFile } from './uploader';
|
|
8
8
|
export { request, RequestError, isRequestError, isRateLimitedError, createRequestErrorReason } from './utils/request';
|
|
9
9
|
export { isAbortedRequestError, createUrl } from './utils/request/helpers';
|
|
@@ -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(
|
|
18
|
+
function BaseMediaClientError(reason, metadata, innerError) {
|
|
16
19
|
var _this;
|
|
17
20
|
_classCallCheck(this, BaseMediaClientError);
|
|
18
|
-
_this = _callSuper(this, BaseMediaClientError, [
|
|
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.
|
|
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 {};
|
|
@@ -19,6 +19,9 @@ export var isPreviewableFileState = function isPreviewableFileState(fileState) {
|
|
|
19
19
|
export var isFinalFileState = function isFinalFileState(fileState) {
|
|
20
20
|
return ['processed', 'failed-processing', 'error'].includes(fileState.status);
|
|
21
21
|
};
|
|
22
|
+
export var isNonErrorFinalFileState = function isNonErrorFinalFileState(fileState) {
|
|
23
|
+
return ['processed', 'failed-processing'].includes(fileState.status);
|
|
24
|
+
};
|
|
22
25
|
export var isImageRepresentationReady = function isImageRepresentationReady(fileState) {
|
|
23
26
|
switch (fileState.status) {
|
|
24
27
|
case 'processing':
|
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
27
|
-
collectionName = _this$
|
|
28
|
-
occurrenceKey = _this$
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
27
|
-
collectionName = _this$
|
|
28
|
-
occurrenceKey = _this$
|
|
29
|
-
traceContext = _this$
|
|
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',
|
|
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',
|
|
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,
|
|
11
|
-
var _this;
|
|
10
|
+
function PollingError(reason, metadata) {
|
|
12
11
|
_classCallCheck(this, PollingError);
|
|
13
|
-
|
|
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',
|
|
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',
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
140
|
-
return isFetchNetworkError(err) ||
|
|
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
|
|
14
|
-
readonly reason: FileFetcherErrorReason;
|
|
13
|
+
export type FileFetcherErrorMetadata = {
|
|
15
14
|
readonly id: string;
|
|
16
|
-
readonly
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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;
|