@atlaskit/media-client 28.0.8 → 28.1.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 (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/client/file-fetcher/error.js +11 -3
  3. package/dist/cjs/client/file-fetcher/index.js +29 -11
  4. package/dist/cjs/models/media.js +4 -1
  5. package/dist/cjs/utils/createFileDataLoader.js +43 -10
  6. package/dist/cjs/utils/mobileUpload/error.js +6 -2
  7. package/dist/cjs/utils/mobileUpload/helpers.js +6 -3
  8. package/dist/cjs/utils/request/errors.js +4 -0
  9. package/dist/es2019/client/file-fetcher/error.js +8 -2
  10. package/dist/es2019/client/file-fetcher/index.js +42 -17
  11. package/dist/es2019/models/media.js +3 -0
  12. package/dist/es2019/utils/createFileDataLoader.js +34 -5
  13. package/dist/es2019/utils/mobileUpload/error.js +6 -2
  14. package/dist/es2019/utils/mobileUpload/helpers.js +6 -3
  15. package/dist/es2019/utils/request/errors.js +5 -1
  16. package/dist/esm/client/file-fetcher/error.js +11 -3
  17. package/dist/esm/client/file-fetcher/index.js +30 -12
  18. package/dist/esm/models/media.js +3 -0
  19. package/dist/esm/utils/createFileDataLoader.js +43 -10
  20. package/dist/esm/utils/mobileUpload/error.js +6 -2
  21. package/dist/esm/utils/mobileUpload/helpers.js +6 -3
  22. package/dist/esm/utils/request/errors.js +4 -0
  23. package/dist/types/client/file-fetcher/error.d.ts +7 -0
  24. package/dist/types/client/media-store/index.d.ts +1 -1
  25. package/dist/types/client/media-store/types.d.ts +6 -0
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/models/media.d.ts +7 -0
  28. package/dist/types/utils/createFileDataLoader.d.ts +4 -4
  29. package/dist/types/utils/mobileUpload/error.d.ts +7 -0
  30. package/dist/types/utils/request/errors.d.ts +3 -0
  31. package/dist/types-ts4.5/client/file-fetcher/error.d.ts +7 -0
  32. package/dist/types-ts4.5/client/media-store/index.d.ts +1 -1
  33. package/dist/types-ts4.5/client/media-store/types.d.ts +6 -0
  34. package/dist/types-ts4.5/index.d.ts +1 -1
  35. package/dist/types-ts4.5/models/media.d.ts +7 -0
  36. package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +4 -4
  37. package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +7 -0
  38. package/dist/types-ts4.5/utils/request/errors.d.ts +3 -0
  39. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 28.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#156454](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/156454)
8
+ [`cfba72d9716f0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cfba72d9716f0) -
9
+ Logs trace context for metadata error events
10
+
3
11
  ## 28.0.8
4
12
 
5
13
  ### Patch Changes
@@ -6,12 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.FileFetcherError = void 0;
8
8
  exports.isFileFetcherError = isFileFetcherError;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
12
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
13
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
14
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
15
  var _errors = require("../../models/errors");
16
+ 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; }
17
+ 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) { (0, _defineProperty2.default)(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; }
15
18
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
16
19
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
20
  var FileFetcherError = exports.FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
@@ -34,13 +37,18 @@ var FileFetcherError = exports.FileFetcherError = /*#__PURE__*/function (_BaseMe
34
37
  _this$metadata = this.metadata,
35
38
  _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
36
39
  collectionName = _this$metadata2.collectionName,
37
- occurrenceKey = _this$metadata2.occurrenceKey;
38
- return {
40
+ occurrenceKey = _this$metadata2.occurrenceKey,
41
+ traceContext = _this$metadata2.traceContext;
42
+ return _objectSpread({
39
43
  reason: reason,
40
44
  id: id,
41
45
  collectionName: collectionName,
42
46
  occurrenceKey: occurrenceKey
43
- };
47
+ }, traceContext && {
48
+ metadata: {
49
+ traceContext: traceContext
50
+ }
51
+ });
44
52
  }
45
53
  }]);
46
54
  return FileFetcherError;
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "isFileFetcherError", {
19
19
  });
20
20
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
21
21
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
22
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
22
23
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
23
24
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
24
25
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -29,6 +30,7 @@ var _mediaCore = require("@atlaskit/media-core");
29
30
  var _downloadUrl = require("@atlaskit/media-common/downloadUrl");
30
31
  var _mediaStore = require("../media-store");
31
32
  var _fileState2 = require("../../models/file-state");
33
+ var _media = require("../../models/media");
32
34
  var _error = require("./error");
33
35
  var _uploader = require("../../uploader");
34
36
  var _fileStreamsCache = require("../../file-streams-cache");
@@ -47,6 +49,8 @@ var _shouldFetchRemoteFileStates = require("../../utils/shouldFetchRemoteFileSta
47
49
  var _polling = require("../../utils/polling");
48
50
  var _detectEmptyFile = require("../../utils/detectEmptyFile");
49
51
  var _mediaState = require("@atlaskit/media-state");
52
+ var _excluded = ["metadata"],
53
+ _excluded2 = ["metadata"];
50
54
  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; }
51
55
  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) { (0, _defineProperty2.default)(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; }
52
56
  var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
@@ -55,6 +59,10 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
55
59
  var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _mediaState.mediaStore;
56
60
  (0, _classCallCheck2.default)(this, FileFetcherImpl);
57
61
  (0, _defineProperty2.default)(this, "getErrorFileState", function (error, id, occurrenceKey) {
62
+ var _error$attributes;
63
+ var _ref = (_error$attributes = error === null || error === void 0 ? void 0 : error.attributes) !== null && _error$attributes !== void 0 ? _error$attributes : {},
64
+ metadata = _ref.metadata,
65
+ attributes = (0, _objectWithoutProperties2.default)(_ref, _excluded);
58
66
  return typeof error === 'string' ? {
59
67
  status: 'error',
60
68
  id: id,
@@ -65,7 +73,9 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
65
73
  status: 'error',
66
74
  id: id,
67
75
  reason: error === null || error === void 0 ? void 0 : error.reason,
68
- details: error === null || error === void 0 ? void 0 : error.attributes,
76
+ details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
77
+ metadata: metadata
78
+ }),
69
79
  occurrenceKey: occurrenceKey,
70
80
  message: error === null || error === void 0 ? void 0 : error.message
71
81
  };
@@ -96,13 +106,14 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
96
106
  });
97
107
  case 2:
98
108
  response = _context.sent;
99
- if (response) {
109
+ if (!(0, _media.isNotFoundMediaItemDetails)(response)) {
100
110
  _context.next = 5;
101
111
  break;
102
112
  }
103
113
  throw new _error.FileFetcherError('emptyItems', id, {
104
114
  collectionName: collectionName,
105
- occurrenceKey: occurrenceKey
115
+ occurrenceKey: occurrenceKey,
116
+ traceContext: response.metadataTraceContext
106
117
  });
107
118
  case 5:
108
119
  if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
@@ -111,7 +122,8 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
111
122
  }
112
123
  throw new _error.FileFetcherError('zeroVersionFile', id, {
113
124
  collectionName: collectionName,
114
- occurrenceKey: occurrenceKey
125
+ occurrenceKey: occurrenceKey,
126
+ traceContext: response.metadataTraceContext
115
127
  });
116
128
  case 7:
117
129
  fileState = (0, _fileState2.mapMediaItemToFileState)(id, response);
@@ -179,18 +191,24 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
179
191
  var collectionName = options.collectionName,
180
192
  occurrenceKey = options.occurrenceKey;
181
193
  if (!(0, _uuidValidate.default)(id)) {
194
+ var _err$attributes;
182
195
  var subject = (0, _createMediaSubject.createMediaSubject)();
183
196
  var err = new _error.FileFetcherError('invalidFileId', id, {
184
197
  collectionName: collectionName,
185
198
  occurrenceKey: occurrenceKey
186
199
  });
200
+ var _ref3 = (_err$attributes = err === null || err === void 0 ? void 0 : err.attributes) !== null && _err$attributes !== void 0 ? _err$attributes : {},
201
+ metadata = _ref3.metadata,
202
+ attributes = (0, _objectWithoutProperties2.default)(_ref3, _excluded2);
187
203
  var errorFileState = {
188
204
  status: 'error',
189
205
  id: id,
190
206
  reason: err === null || err === void 0 ? void 0 : err.reason,
191
207
  message: err === null || err === void 0 ? void 0 : err.message,
192
208
  occurrenceKey: occurrenceKey,
193
- details: err === null || err === void 0 ? void 0 : err.attributes
209
+ details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
210
+ metadata: metadata
211
+ })
194
212
  };
195
213
  subject.error(err);
196
214
  this.setFileState(id, errorFileState);
@@ -232,8 +250,8 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
232
250
  descriptors: descriptors
233
251
  }, {
234
252
  collection: collection
235
- }, traceContext).then(function (_ref2) {
236
- var data = _ref2.data;
253
+ }, traceContext).then(function (_ref4) {
254
+ var data = _ref4.data;
237
255
  return data;
238
256
  });
239
257
  }
@@ -274,7 +292,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
274
292
  return undefined;
275
293
  });
276
294
  preview = new Promise( /*#__PURE__*/function () {
277
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
295
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
278
296
  var blob;
279
297
  return _regenerator.default.wrap(function _callee2$(_context2) {
280
298
  while (1) switch (_context2.prev = _context2.next) {
@@ -297,7 +315,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
297
315
  }, _callee2);
298
316
  }));
299
317
  return function (_x4, _x5) {
300
- return _ref3.apply(this, arguments);
318
+ return _ref5.apply(this, arguments);
301
319
  };
302
320
  }());
303
321
  name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
@@ -316,7 +334,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
316
334
  (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
317
335
  this.setFileState(id, fileState);
318
336
  return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
319
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
337
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
320
338
  var blob, type, size, file, mediaType, dimensions;
321
339
  return _regenerator.default.wrap(function _callee3$(_context3) {
322
340
  while (1) switch (_context3.prev = _context3.next) {
@@ -377,7 +395,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
377
395
  }, _callee3, null, [[10, 16]]);
378
396
  }));
379
397
  return function (_x6, _x7) {
380
- return _ref4.apply(this, arguments);
398
+ return _ref6.apply(this, arguments);
381
399
  };
382
400
  }()));
383
401
  case 11:
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isPreviewableType = exports.DATA_UNIT = void 0;
6
+ exports.isPreviewableType = exports.isNotFoundMediaItemDetails = exports.DATA_UNIT = void 0;
7
7
  // Warning! You can't add new media file processing status!
8
8
  // See packages/media/media-core/src/__tests__/cache-backward-compatibility.spec.ts
9
9
 
@@ -11,6 +11,9 @@ var isPreviewableType = exports.isPreviewableType = function isPreviewableType(t
11
11
  var defaultPreviewableTypes = ['audio', 'video', 'image', 'doc'];
12
12
  return defaultPreviewableTypes.indexOf(type) > -1;
13
13
  };
14
+ var isNotFoundMediaItemDetails = exports.isNotFoundMediaItemDetails = function isNotFoundMediaItemDetails(itemDetails) {
15
+ return 'type' in itemDetails && itemDetails.type === 'not-found';
16
+ };
14
17
  var DATA_UNIT = exports.DATA_UNIT = /*#__PURE__*/function (DATA_UNIT) {
15
18
  DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
16
19
  DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
@@ -20,6 +20,9 @@ var MAX_BATCH_SIZE = exports.MAX_BATCH_SIZE = 100;
20
20
  var isBatchLoadingErrorResult = function isBatchLoadingErrorResult(result) {
21
21
  return result.error instanceof Error;
22
22
  };
23
+ var isResponseFileItem = function isResponseFileItem(fileItem) {
24
+ return 'details' in fileItem;
25
+ };
23
26
  var makeCacheKey = function makeCacheKey(id, collection) {
24
27
  return collection ? "".concat(id, "-").concat(collection) : id;
25
28
  };
@@ -28,16 +31,30 @@ var getItemsFromKeys = exports.getItemsFromKeys = function getItemsFromKeys(data
28
31
  var id = fileItem.id,
29
32
  collection = fileItem.collection;
30
33
  var key = makeCacheKey(id, collection);
31
- prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : _objectSpread(_objectSpread({}, fileItem.details), {}, {
32
- metadataTraceContext: fileItem.metadataTraceContext
33
- });
34
+ if (isBatchLoadingErrorResult(fileItem)) {
35
+ prev[key] = fileItem.error;
36
+ } else if (isResponseFileItem(fileItem)) {
37
+ prev[key] = _objectSpread(_objectSpread({}, fileItem.details), {}, {
38
+ metadataTraceContext: fileItem.metadataTraceContext
39
+ });
40
+ } else {
41
+ prev[key] = {
42
+ id: id,
43
+ collection: collection,
44
+ type: 'not-found',
45
+ metadataTraceContext: fileItem.metadataTraceContext
46
+ };
47
+ }
34
48
  return prev;
35
49
  }, {});
36
50
  return dataloaderKeys.map(function (dataloaderKey) {
37
51
  var id = dataloaderKey.id,
38
52
  collectionName = dataloaderKey.collectionName;
39
53
  var key = makeCacheKey(id, collectionName);
40
- return itemsByKey[key] || null;
54
+ return itemsByKey[key] || {
55
+ id: id,
56
+ type: 'not-found'
57
+ };
41
58
  });
42
59
  };
43
60
  /**
@@ -72,7 +89,7 @@ function createBatchLoadingFunc(mediaStore) {
72
89
  _context2.next = 5;
73
90
  return Promise.all(Object.keys(fileIdsByCollection).map( /*#__PURE__*/function () {
74
91
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(collectionNameKey) {
75
- var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext;
92
+ var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext, itemsIds, fileIdsNotFound;
76
93
  return _regenerator.default.wrap(function _callee$(_context) {
77
94
  while (1) switch (_context.prev = _context.next) {
78
95
  case 0:
@@ -93,10 +110,26 @@ function createBatchLoadingFunc(mediaStore) {
93
110
  });
94
111
  });
95
112
  items.push.apply(items, (0, _toConsumableArray2.default)(itemsWithMetadataTraceContext));
96
- _context.next = 14;
113
+
114
+ // add EmptyResponseFileItem for each file ID not included in /items response
115
+ itemsIds = itemsWithMetadataTraceContext.map(function (item) {
116
+ return item.id;
117
+ });
118
+ fileIdsNotFound = fileIds.filter(function (id) {
119
+ return !itemsIds.includes(id);
120
+ });
121
+ fileIdsNotFound.forEach(function (fileId) {
122
+ items.push({
123
+ id: fileId,
124
+ collection: collectionName,
125
+ type: 'not-found',
126
+ metadataTraceContext: metadataTraceContext
127
+ });
128
+ });
129
+ _context.next = 17;
97
130
  break;
98
- case 11:
99
- _context.prev = 11;
131
+ case 14:
132
+ _context.prev = 14;
100
133
  _context.t0 = _context["catch"](3);
101
134
  fileIds.forEach(function (fileId) {
102
135
  items.push({
@@ -105,11 +138,11 @@ function createBatchLoadingFunc(mediaStore) {
105
138
  error: _context.t0
106
139
  });
107
140
  });
108
- case 14:
141
+ case 17:
109
142
  case "end":
110
143
  return _context.stop();
111
144
  }
112
- }, _callee, null, [[3, 11]]);
145
+ }, _callee, null, [[3, 14]]);
113
146
  }));
114
147
  return function (_x2) {
115
148
  return _ref2.apply(this, arguments);
@@ -34,12 +34,16 @@ var MobileUploadError = exports.MobileUploadError = /*#__PURE__*/function (_Base
34
34
  _this$metadata = this.metadata,
35
35
  _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
36
36
  collectionName = _this$metadata2.collectionName,
37
- occurrenceKey = _this$metadata2.occurrenceKey;
37
+ occurrenceKey = _this$metadata2.occurrenceKey,
38
+ traceContext = _this$metadata2.traceContext;
38
39
  return {
39
40
  reason: reason,
40
41
  id: id,
41
42
  collectionName: collectionName,
42
- occurrenceKey: occurrenceKey
43
+ occurrenceKey: occurrenceKey,
44
+ metadata: {
45
+ traceContext: traceContext
46
+ }
43
47
  };
44
48
  }
45
49
  }]);
@@ -15,6 +15,7 @@ var _createMediaSubject = require("../createMediaSubject");
15
15
  var _detectEmptyFile = require("../detectEmptyFile");
16
16
  var _polling = require("../polling");
17
17
  var _error = require("./error");
18
+ var _media = require("../../models/media");
18
19
  var createMobileFileStateSubject = exports.createMobileFileStateSubject = function createMobileFileStateSubject(service) {
19
20
  var subject = new _ReplaySubject.ReplaySubject(1);
20
21
  (0, _from.from)(service.start()).pipe((0, _map.map)(function (state) {
@@ -42,13 +43,14 @@ var createMobileDownloadFileStream = exports.createMobileDownloadFileStream = fu
42
43
  });
43
44
  case 2:
44
45
  response = _context.sent;
45
- if (response) {
46
+ if (!(0, _media.isNotFoundMediaItemDetails)(response)) {
46
47
  _context.next = 5;
47
48
  break;
48
49
  }
49
50
  throw new _error.MobileUploadError('emptyItems', id, {
50
51
  collectionName: collectionName,
51
- occurrenceKey: occurrenceKey
52
+ occurrenceKey: occurrenceKey,
53
+ traceContext: response.metadataTraceContext
52
54
  });
53
55
  case 5:
54
56
  if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
@@ -57,7 +59,8 @@ var createMobileDownloadFileStream = exports.createMobileDownloadFileStream = fu
57
59
  }
58
60
  throw new _error.MobileUploadError('zeroVersionFile', id, {
59
61
  collectionName: collectionName,
60
- occurrenceKey: occurrenceKey
62
+ occurrenceKey: occurrenceKey,
63
+ traceContext: response.metadataTraceContext
61
64
  });
62
65
  case 7:
63
66
  fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
@@ -39,6 +39,7 @@ var RequestError = exports.RequestError = /*#__PURE__*/function (_BaseMediaClien
39
39
  attempts = _this$metadata2.attempts,
40
40
  clientExhaustedRetries = _this$metadata2.clientExhaustedRetries,
41
41
  statusCode = _this$metadata2.statusCode,
42
+ traceContext = _this$metadata2.traceContext,
42
43
  innerError = this.innerError;
43
44
  return {
44
45
  reason: reason,
@@ -49,6 +50,9 @@ var RequestError = exports.RequestError = /*#__PURE__*/function (_BaseMediaClien
49
50
  attempts: attempts,
50
51
  clientExhaustedRetries: clientExhaustedRetries,
51
52
  statusCode: statusCode,
53
+ metadata: {
54
+ traceContext: traceContext
55
+ },
52
56
  innerError: innerError
53
57
  };
54
58
  }
@@ -12,14 +12,20 @@ export class FileFetcherError extends BaseMediaClientError {
12
12
  id,
13
13
  metadata: {
14
14
  collectionName,
15
- occurrenceKey
15
+ occurrenceKey,
16
+ traceContext
16
17
  } = {}
17
18
  } = this;
18
19
  return {
19
20
  reason,
20
21
  id,
21
22
  collectionName,
22
- occurrenceKey
23
+ occurrenceKey,
24
+ ...(traceContext && {
25
+ metadata: {
26
+ traceContext
27
+ }
28
+ })
23
29
  };
24
30
  }
25
31
  }
@@ -6,6 +6,7 @@ import { authToOwner } from '@atlaskit/media-core';
6
6
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
7
7
  import { MediaStore as MediaApi } from '../media-store';
8
8
  import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
9
+ import { isNotFoundMediaItemDetails } from '../../models/media';
9
10
  import { FileFetcherError } from './error';
10
11
  import { uploadFile } from '../../uploader';
11
12
  import { getFileStreamsCache } from '../../file-streams-cache';
@@ -27,19 +28,31 @@ import { mediaStore } from '@atlaskit/media-state';
27
28
  export { isFileFetcherError, FileFetcherError } from './error';
28
29
  export class FileFetcherImpl {
29
30
  constructor(mediaApi, store = mediaStore) {
30
- _defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
31
- status: 'error',
32
- id,
33
- reason: error,
34
- occurrenceKey,
35
- message: error
36
- } : {
37
- status: 'error',
38
- id,
39
- reason: error === null || error === void 0 ? void 0 : error.reason,
40
- details: error === null || error === void 0 ? void 0 : error.attributes,
41
- occurrenceKey,
42
- message: error === null || error === void 0 ? void 0 : error.message
31
+ _defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => {
32
+ var _error$attributes;
33
+ const {
34
+ metadata,
35
+ ...attributes
36
+ } = (_error$attributes = error === null || error === void 0 ? void 0 : error.attributes) !== null && _error$attributes !== void 0 ? _error$attributes : {};
37
+ return typeof error === 'string' ? {
38
+ status: 'error',
39
+ id,
40
+ reason: error,
41
+ occurrenceKey,
42
+ message: error
43
+ } : {
44
+ status: 'error',
45
+ id,
46
+ reason: error === null || error === void 0 ? void 0 : error.reason,
47
+ details: {
48
+ ...attributes,
49
+ ...((metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
50
+ metadata
51
+ })
52
+ },
53
+ occurrenceKey,
54
+ message: error === null || error === void 0 ? void 0 : error.message
55
+ };
43
56
  });
44
57
  _defineProperty(this, "setFileState", (id, fileState) => {
45
58
  this.store.setState(state => {
@@ -58,16 +71,18 @@ export class FileFetcherImpl {
58
71
  id,
59
72
  collectionName
60
73
  });
61
- if (!response) {
74
+ if (isNotFoundMediaItemDetails(response)) {
62
75
  throw new FileFetcherError('emptyItems', id, {
63
76
  collectionName,
64
- occurrenceKey
77
+ occurrenceKey,
78
+ traceContext: response.metadataTraceContext
65
79
  });
66
80
  }
67
81
  if (isEmptyFile(response)) {
68
82
  throw new FileFetcherError('zeroVersionFile', id, {
69
83
  collectionName,
70
- occurrenceKey
84
+ occurrenceKey,
85
+ traceContext: response.metadataTraceContext
71
86
  });
72
87
  }
73
88
  const fileState = mapMediaItemToFileState(id, response);
@@ -130,18 +145,28 @@ export class FileFetcherImpl {
130
145
  occurrenceKey
131
146
  } = options;
132
147
  if (!isValidId(id)) {
148
+ var _err$attributes;
133
149
  const subject = createMediaSubject();
134
150
  const err = new FileFetcherError('invalidFileId', id, {
135
151
  collectionName,
136
152
  occurrenceKey
137
153
  });
154
+ const {
155
+ metadata,
156
+ ...attributes
157
+ } = (_err$attributes = err === null || err === void 0 ? void 0 : err.attributes) !== null && _err$attributes !== void 0 ? _err$attributes : {};
138
158
  const errorFileState = {
139
159
  status: 'error',
140
160
  id,
141
161
  reason: err === null || err === void 0 ? void 0 : err.reason,
142
162
  message: err === null || err === void 0 ? void 0 : err.message,
143
163
  occurrenceKey,
144
- details: err === null || err === void 0 ? void 0 : err.attributes
164
+ details: {
165
+ ...attributes,
166
+ ...((metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
167
+ metadata
168
+ })
169
+ }
145
170
  };
146
171
  subject.error(err);
147
172
  this.setFileState(id, errorFileState);
@@ -5,6 +5,9 @@ export const isPreviewableType = type => {
5
5
  const defaultPreviewableTypes = ['audio', 'video', 'image', 'doc'];
6
6
  return defaultPreviewableTypes.indexOf(type) > -1;
7
7
  };
8
+ export const isNotFoundMediaItemDetails = itemDetails => {
9
+ return 'type' in itemDetails && itemDetails.type === 'not-found';
10
+ };
8
11
  export let DATA_UNIT = /*#__PURE__*/function (DATA_UNIT) {
9
12
  DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
10
13
  DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
@@ -4,6 +4,9 @@ export const MAX_BATCH_SIZE = 100;
4
4
  const isBatchLoadingErrorResult = result => {
5
5
  return result.error instanceof Error;
6
6
  };
7
+ const isResponseFileItem = fileItem => {
8
+ return 'details' in fileItem;
9
+ };
7
10
  const makeCacheKey = (id, collection) => collection ? `${id}-${collection}` : id;
8
11
  export const getItemsFromKeys = (dataloaderKeys, fileItems) => {
9
12
  const itemsByKey = fileItems.reduce((prev, fileItem) => {
@@ -12,10 +15,21 @@ export const getItemsFromKeys = (dataloaderKeys, fileItems) => {
12
15
  collection
13
16
  } = fileItem;
14
17
  const key = makeCacheKey(id, collection);
15
- prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : {
16
- ...fileItem.details,
17
- metadataTraceContext: fileItem.metadataTraceContext
18
- };
18
+ if (isBatchLoadingErrorResult(fileItem)) {
19
+ prev[key] = fileItem.error;
20
+ } else if (isResponseFileItem(fileItem)) {
21
+ prev[key] = {
22
+ ...fileItem.details,
23
+ metadataTraceContext: fileItem.metadataTraceContext
24
+ };
25
+ } else {
26
+ prev[key] = {
27
+ id,
28
+ collection,
29
+ type: 'not-found',
30
+ metadataTraceContext: fileItem.metadataTraceContext
31
+ };
32
+ }
19
33
  return prev;
20
34
  }, {});
21
35
  return dataloaderKeys.map(dataloaderKey => {
@@ -24,7 +38,10 @@ export const getItemsFromKeys = (dataloaderKeys, fileItems) => {
24
38
  collectionName
25
39
  } = dataloaderKey;
26
40
  const key = makeCacheKey(id, collectionName);
27
- return itemsByKey[key] || null;
41
+ return itemsByKey[key] || {
42
+ id,
43
+ type: 'not-found'
44
+ };
28
45
  });
29
46
  };
30
47
  /**
@@ -65,6 +82,18 @@ export function createBatchLoadingFunc(mediaStore) {
65
82
  metadataTraceContext
66
83
  }));
67
84
  items.push(...itemsWithMetadataTraceContext);
85
+
86
+ // add EmptyResponseFileItem for each file ID not included in /items response
87
+ const itemsIds = itemsWithMetadataTraceContext.map(item => item.id);
88
+ const fileIdsNotFound = fileIds.filter(id => !itemsIds.includes(id));
89
+ fileIdsNotFound.forEach(fileId => {
90
+ items.push({
91
+ id: fileId,
92
+ collection: collectionName,
93
+ type: 'not-found',
94
+ metadataTraceContext
95
+ });
96
+ });
68
97
  } catch (error) {
69
98
  fileIds.forEach(fileId => {
70
99
  items.push({
@@ -12,14 +12,18 @@ export class MobileUploadError extends BaseMediaClientError {
12
12
  id,
13
13
  metadata: {
14
14
  collectionName,
15
- occurrenceKey
15
+ occurrenceKey,
16
+ traceContext
16
17
  } = {}
17
18
  } = this;
18
19
  return {
19
20
  reason,
20
21
  id,
21
22
  collectionName,
22
- occurrenceKey
23
+ occurrenceKey,
24
+ metadata: {
25
+ traceContext
26
+ }
23
27
  };
24
28
  }
25
29
  }
@@ -6,6 +6,7 @@ import { createMediaSubject } from '../createMediaSubject';
6
6
  import { isEmptyFile } from '../detectEmptyFile';
7
7
  import { PollingFunction } from '../polling';
8
8
  import { MobileUploadError } from './error';
9
+ import { isNotFoundMediaItemDetails } from '../../models/media';
9
10
  export const createMobileFileStateSubject = service => {
10
11
  const subject = new ReplaySubject(1);
11
12
  from(service.start()).pipe(map(state => state.context.currentFileState)).subscribe(subject);
@@ -22,16 +23,18 @@ export const createMobileDownloadFileStream = (dataloader, id, collectionName, o
22
23
  id,
23
24
  collectionName
24
25
  });
25
- if (!response) {
26
+ if (isNotFoundMediaItemDetails(response)) {
26
27
  throw new MobileUploadError('emptyItems', id, {
27
28
  collectionName,
28
- occurrenceKey
29
+ occurrenceKey,
30
+ traceContext: response.metadataTraceContext
29
31
  });
30
32
  }
31
33
  if (isEmptyFile(response)) {
32
34
  throw new MobileUploadError('zeroVersionFile', id, {
33
35
  collectionName,
34
- occurrenceKey
36
+ occurrenceKey,
37
+ traceContext: response.metadataTraceContext
35
38
  });
36
39
  }
37
40
  const fileState = mapMediaItemToFileState(id, response);