@atlaskit/media-client 28.0.8 → 28.2.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 (44) hide show
  1. package/CHANGELOG.md +15 -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/client/media-store/MediaStore.js +11 -11
  5. package/dist/cjs/models/media.js +4 -1
  6. package/dist/cjs/utils/createFileDataLoader.js +43 -10
  7. package/dist/cjs/utils/mobileUpload/error.js +6 -2
  8. package/dist/cjs/utils/mobileUpload/helpers.js +6 -3
  9. package/dist/cjs/utils/request/errors.js +4 -0
  10. package/dist/es2019/client/file-fetcher/error.js +8 -2
  11. package/dist/es2019/client/file-fetcher/index.js +42 -17
  12. package/dist/es2019/client/media-store/MediaStore.js +2 -2
  13. package/dist/es2019/models/media.js +3 -0
  14. package/dist/es2019/utils/createFileDataLoader.js +34 -5
  15. package/dist/es2019/utils/mobileUpload/error.js +6 -2
  16. package/dist/es2019/utils/mobileUpload/helpers.js +6 -3
  17. package/dist/es2019/utils/request/errors.js +5 -1
  18. package/dist/esm/client/file-fetcher/error.js +11 -3
  19. package/dist/esm/client/file-fetcher/index.js +30 -12
  20. package/dist/esm/client/media-store/MediaStore.js +11 -11
  21. package/dist/esm/models/media.js +3 -0
  22. package/dist/esm/utils/createFileDataLoader.js +43 -10
  23. package/dist/esm/utils/mobileUpload/error.js +6 -2
  24. package/dist/esm/utils/mobileUpload/helpers.js +6 -3
  25. package/dist/esm/utils/request/errors.js +4 -0
  26. package/dist/types/client/file-fetcher/error.d.ts +7 -0
  27. package/dist/types/client/media-store/MediaStore.d.ts +1 -1
  28. package/dist/types/client/media-store/index.d.ts +1 -1
  29. package/dist/types/client/media-store/types.d.ts +7 -1
  30. package/dist/types/index.d.ts +1 -1
  31. package/dist/types/models/media.d.ts +7 -0
  32. package/dist/types/utils/createFileDataLoader.d.ts +4 -4
  33. package/dist/types/utils/mobileUpload/error.d.ts +7 -0
  34. package/dist/types/utils/request/errors.d.ts +3 -0
  35. package/dist/types-ts4.5/client/file-fetcher/error.d.ts +7 -0
  36. package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +1 -1
  37. package/dist/types-ts4.5/client/media-store/index.d.ts +1 -1
  38. package/dist/types-ts4.5/client/media-store/types.d.ts +7 -1
  39. package/dist/types-ts4.5/index.d.ts +1 -1
  40. package/dist/types-ts4.5/models/media.d.ts +7 -0
  41. package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +4 -4
  42. package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +7 -0
  43. package/dist/types-ts4.5/utils/request/errors.d.ts +3 -0
  44. package/package.json +2 -2
@@ -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);
@@ -16,7 +16,8 @@ export class RequestError extends BaseMediaClientError {
16
16
  mediaEnv,
17
17
  attempts,
18
18
  clientExhaustedRetries,
19
- statusCode
19
+ statusCode,
20
+ traceContext
20
21
  } = {},
21
22
  innerError
22
23
  } = this;
@@ -29,6 +30,9 @@ export class RequestError extends BaseMediaClientError {
29
30
  attempts,
30
31
  clientExhaustedRetries,
31
32
  statusCode,
33
+ metadata: {
34
+ traceContext
35
+ },
32
36
  innerError
33
37
  };
34
38
  }
@@ -1,8 +1,11 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/createClass";
3
4
  import _inherits from "@babel/runtime/helpers/inherits";
4
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ 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; }
8
+ 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; }
6
9
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
7
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
11
  import { BaseMediaClientError } from '../../models/errors';
@@ -26,13 +29,18 @@ export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
26
29
  _this$metadata = this.metadata,
27
30
  _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
28
31
  collectionName = _this$metadata2.collectionName,
29
- occurrenceKey = _this$metadata2.occurrenceKey;
30
- return {
32
+ occurrenceKey = _this$metadata2.occurrenceKey,
33
+ traceContext = _this$metadata2.traceContext;
34
+ return _objectSpread({
31
35
  reason: reason,
32
36
  id: id,
33
37
  collectionName: collectionName,
34
38
  occurrenceKey: occurrenceKey
35
- };
39
+ }, traceContext && {
40
+ metadata: {
41
+ traceContext: traceContext
42
+ }
43
+ });
36
44
  }
37
45
  }]);
38
46
  return FileFetcherError;
@@ -1,10 +1,13 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/createClass";
4
5
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
+ var _excluded = ["metadata"],
7
+ _excluded2 = ["metadata"];
8
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
9
  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; }
6
10
  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";
8
11
  import { Subscription } from 'rxjs/Subscription';
9
12
  import { map } from 'rxjs/operators/map';
10
13
  import uuid from 'uuid/v4';
@@ -12,6 +15,7 @@ import { authToOwner } from '@atlaskit/media-core';
12
15
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
13
16
  import { MediaStore as MediaApi } from '../media-store';
14
17
  import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
18
+ import { isNotFoundMediaItemDetails } from '../../models/media';
15
19
  import { FileFetcherError } from './error';
16
20
  import { uploadFile } from '../../uploader';
17
21
  import { getFileStreamsCache } from '../../file-streams-cache';
@@ -37,6 +41,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
37
41
  var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mediaStore;
38
42
  _classCallCheck(this, FileFetcherImpl);
39
43
  _defineProperty(this, "getErrorFileState", function (error, id, occurrenceKey) {
44
+ var _error$attributes;
45
+ var _ref = (_error$attributes = error === null || error === void 0 ? void 0 : error.attributes) !== null && _error$attributes !== void 0 ? _error$attributes : {},
46
+ metadata = _ref.metadata,
47
+ attributes = _objectWithoutProperties(_ref, _excluded);
40
48
  return typeof error === 'string' ? {
41
49
  status: 'error',
42
50
  id: id,
@@ -47,7 +55,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
47
55
  status: 'error',
48
56
  id: id,
49
57
  reason: error === null || error === void 0 ? void 0 : error.reason,
50
- details: error === null || error === void 0 ? void 0 : error.attributes,
58
+ details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
59
+ metadata: metadata
60
+ }),
51
61
  occurrenceKey: occurrenceKey,
52
62
  message: error === null || error === void 0 ? void 0 : error.message
53
63
  };
@@ -78,13 +88,14 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
78
88
  });
79
89
  case 2:
80
90
  response = _context.sent;
81
- if (response) {
91
+ if (!isNotFoundMediaItemDetails(response)) {
82
92
  _context.next = 5;
83
93
  break;
84
94
  }
85
95
  throw new FileFetcherError('emptyItems', id, {
86
96
  collectionName: collectionName,
87
- occurrenceKey: occurrenceKey
97
+ occurrenceKey: occurrenceKey,
98
+ traceContext: response.metadataTraceContext
88
99
  });
89
100
  case 5:
90
101
  if (!isEmptyFile(response)) {
@@ -93,7 +104,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
93
104
  }
94
105
  throw new FileFetcherError('zeroVersionFile', id, {
95
106
  collectionName: collectionName,
96
- occurrenceKey: occurrenceKey
107
+ occurrenceKey: occurrenceKey,
108
+ traceContext: response.metadataTraceContext
97
109
  });
98
110
  case 7:
99
111
  fileState = mapMediaItemToFileState(id, response);
@@ -161,18 +173,24 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
161
173
  var collectionName = options.collectionName,
162
174
  occurrenceKey = options.occurrenceKey;
163
175
  if (!isValidId(id)) {
176
+ var _err$attributes;
164
177
  var subject = createMediaSubject();
165
178
  var err = new FileFetcherError('invalidFileId', id, {
166
179
  collectionName: collectionName,
167
180
  occurrenceKey: occurrenceKey
168
181
  });
182
+ var _ref3 = (_err$attributes = err === null || err === void 0 ? void 0 : err.attributes) !== null && _err$attributes !== void 0 ? _err$attributes : {},
183
+ metadata = _ref3.metadata,
184
+ attributes = _objectWithoutProperties(_ref3, _excluded2);
169
185
  var errorFileState = {
170
186
  status: 'error',
171
187
  id: id,
172
188
  reason: err === null || err === void 0 ? void 0 : err.reason,
173
189
  message: err === null || err === void 0 ? void 0 : err.message,
174
190
  occurrenceKey: occurrenceKey,
175
- details: err === null || err === void 0 ? void 0 : err.attributes
191
+ details: _objectSpread(_objectSpread({}, attributes), (metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
192
+ metadata: metadata
193
+ })
176
194
  };
177
195
  subject.error(err);
178
196
  this.setFileState(id, errorFileState);
@@ -214,8 +232,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
214
232
  descriptors: descriptors
215
233
  }, {
216
234
  collection: collection
217
- }, traceContext).then(function (_ref2) {
218
- var data = _ref2.data;
235
+ }, traceContext).then(function (_ref4) {
236
+ var data = _ref4.data;
219
237
  return data;
220
238
  });
221
239
  }
@@ -256,7 +274,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
256
274
  return undefined;
257
275
  });
258
276
  preview = new Promise( /*#__PURE__*/function () {
259
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
277
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
260
278
  var blob;
261
279
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
262
280
  while (1) switch (_context2.prev = _context2.next) {
@@ -279,7 +297,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
279
297
  }, _callee2);
280
298
  }));
281
299
  return function (_x4, _x5) {
282
- return _ref3.apply(this, arguments);
300
+ return _ref5.apply(this, arguments);
283
301
  };
284
302
  }());
285
303
  name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
@@ -298,7 +316,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
298
316
  getFileStreamsCache().set(id, subject);
299
317
  this.setFileState(id, fileState);
300
318
  return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
301
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
319
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
302
320
  var blob, type, size, file, mediaType, dimensions;
303
321
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
304
322
  while (1) switch (_context3.prev = _context3.next) {
@@ -359,7 +377,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
359
377
  }, _callee3, null, [[10, 16]]);
360
378
  }));
361
379
  return function (_x6, _x7) {
362
- return _ref4.apply(this, arguments);
380
+ return _ref6.apply(this, arguments);
363
381
  };
364
382
  }()));
365
383
  case 11:
@@ -302,7 +302,7 @@ export var MediaStore = /*#__PURE__*/function () {
302
302
  }, {
303
303
  key: "getFileBinary",
304
304
  value: function () {
305
- var _getFileBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName) {
305
+ var _getFileBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName, abortController) {
306
306
  var maxAge,
307
307
  headers,
308
308
  binaryEndpoint,
@@ -312,7 +312,7 @@ export var MediaStore = /*#__PURE__*/function () {
312
312
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
313
313
  while (1) switch (_context5.prev = _context5.next) {
314
314
  case 0:
315
- maxAge = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : FILE_CACHE_MAX_AGE;
315
+ maxAge = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : FILE_CACHE_MAX_AGE;
316
316
  headers = {};
317
317
  binaryEndpoint = cdnFeatureFlag('binary');
318
318
  metadata = {
@@ -329,14 +329,14 @@ export var MediaStore = /*#__PURE__*/function () {
329
329
  'max-age': "".concat(maxAge)
330
330
  }
331
331
  });
332
- return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, undefined, true).then(createMapResponseToBlob(metadata)));
332
+ return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, abortController, true).then(createMapResponseToBlob(metadata)));
333
333
  case 6:
334
334
  case "end":
335
335
  return _context5.stop();
336
336
  }
337
337
  }, _callee5, this);
338
338
  }));
339
- function getFileBinary(_x14, _x15) {
339
+ function getFileBinary(_x14, _x15, _x16) {
340
340
  return _getFileBinary.apply(this, arguments);
341
341
  }
342
342
  return getFileBinary;
@@ -376,7 +376,7 @@ export var MediaStore = /*#__PURE__*/function () {
376
376
  }
377
377
  }, _callee6, this);
378
378
  }));
379
- function getFileBinaryURL(_x16, _x17) {
379
+ function getFileBinaryURL(_x17, _x18) {
380
380
  return _getFileBinaryURL.apply(this, arguments);
381
381
  }
382
382
  return getFileBinaryURL;
@@ -416,7 +416,7 @@ export var MediaStore = /*#__PURE__*/function () {
416
416
  }
417
417
  }, _callee7, this);
418
418
  }));
419
- function getArtifactURL(_x18, _x19, _x20) {
419
+ function getArtifactURL(_x19, _x20, _x21) {
420
420
  return _getArtifactURL.apply(this, arguments);
421
421
  }
422
422
  return getArtifactURL;
@@ -456,7 +456,7 @@ export var MediaStore = /*#__PURE__*/function () {
456
456
  }
457
457
  }, _callee8, this);
458
458
  }));
459
- function getImage(_x21, _x22, _x23, _x24, _x25) {
459
+ function getImage(_x22, _x23, _x24, _x25, _x26) {
460
460
  return _getImage.apply(this, arguments);
461
461
  }
462
462
  return getImage;
@@ -497,7 +497,7 @@ export var MediaStore = /*#__PURE__*/function () {
497
497
  }
498
498
  }, _callee9, this);
499
499
  }));
500
- function getItems(_x26, _x27, _x28) {
500
+ function getItems(_x27, _x28, _x29) {
501
501
  return _getItems.apply(this, arguments);
502
502
  }
503
503
  return getItems;
@@ -528,7 +528,7 @@ export var MediaStore = /*#__PURE__*/function () {
528
528
  }
529
529
  }, _callee10, this);
530
530
  }));
531
- function getImageMetadata(_x29, _x30, _x31) {
531
+ function getImageMetadata(_x30, _x31, _x32) {
532
532
  return _getImageMetadata.apply(this, arguments);
533
533
  }
534
534
  return getImageMetadata;
@@ -561,7 +561,7 @@ export var MediaStore = /*#__PURE__*/function () {
561
561
  }
562
562
  }, _callee11, this);
563
563
  }));
564
- function appendChunksToUpload(_x32, _x33, _x34, _x35) {
564
+ function appendChunksToUpload(_x33, _x34, _x35, _x36) {
565
565
  return _appendChunksToUpload.apply(this, arguments);
566
566
  }
567
567
  return appendChunksToUpload;
@@ -656,7 +656,7 @@ export var MediaStore = /*#__PURE__*/function () {
656
656
  }
657
657
  }, _callee12, this);
658
658
  }));
659
- function request(_x36) {
659
+ function request(_x37) {
660
660
  return _request2.apply(this, arguments);
661
661
  }
662
662
  return request;
@@ -5,6 +5,9 @@ export var isPreviewableType = function isPreviewableType(type) {
5
5
  var defaultPreviewableTypes = ['audio', 'video', 'image', 'doc'];
6
6
  return defaultPreviewableTypes.indexOf(type) > -1;
7
7
  };
8
+ export var isNotFoundMediaItemDetails = function isNotFoundMediaItemDetails(itemDetails) {
9
+ return 'type' in itemDetails && itemDetails.type === 'not-found';
10
+ };
8
11
  export var DATA_UNIT = /*#__PURE__*/function (DATA_UNIT) {
9
12
  DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
10
13
  DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
@@ -10,6 +10,9 @@ export var MAX_BATCH_SIZE = 100;
10
10
  var isBatchLoadingErrorResult = function isBatchLoadingErrorResult(result) {
11
11
  return result.error instanceof Error;
12
12
  };
13
+ var isResponseFileItem = function isResponseFileItem(fileItem) {
14
+ return 'details' in fileItem;
15
+ };
13
16
  var makeCacheKey = function makeCacheKey(id, collection) {
14
17
  return collection ? "".concat(id, "-").concat(collection) : id;
15
18
  };
@@ -18,16 +21,30 @@ export var getItemsFromKeys = function getItemsFromKeys(dataloaderKeys, fileItem
18
21
  var id = fileItem.id,
19
22
  collection = fileItem.collection;
20
23
  var key = makeCacheKey(id, collection);
21
- prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : _objectSpread(_objectSpread({}, fileItem.details), {}, {
22
- metadataTraceContext: fileItem.metadataTraceContext
23
- });
24
+ if (isBatchLoadingErrorResult(fileItem)) {
25
+ prev[key] = fileItem.error;
26
+ } else if (isResponseFileItem(fileItem)) {
27
+ prev[key] = _objectSpread(_objectSpread({}, fileItem.details), {}, {
28
+ metadataTraceContext: fileItem.metadataTraceContext
29
+ });
30
+ } else {
31
+ prev[key] = {
32
+ id: id,
33
+ collection: collection,
34
+ type: 'not-found',
35
+ metadataTraceContext: fileItem.metadataTraceContext
36
+ };
37
+ }
24
38
  return prev;
25
39
  }, {});
26
40
  return dataloaderKeys.map(function (dataloaderKey) {
27
41
  var id = dataloaderKey.id,
28
42
  collectionName = dataloaderKey.collectionName;
29
43
  var key = makeCacheKey(id, collectionName);
30
- return itemsByKey[key] || null;
44
+ return itemsByKey[key] || {
45
+ id: id,
46
+ type: 'not-found'
47
+ };
31
48
  });
32
49
  };
33
50
  /**
@@ -62,7 +79,7 @@ export function createBatchLoadingFunc(mediaStore) {
62
79
  _context2.next = 5;
63
80
  return Promise.all(Object.keys(fileIdsByCollection).map( /*#__PURE__*/function () {
64
81
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionNameKey) {
65
- var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext;
82
+ var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext, itemsIds, fileIdsNotFound;
66
83
  return _regeneratorRuntime.wrap(function _callee$(_context) {
67
84
  while (1) switch (_context.prev = _context.next) {
68
85
  case 0:
@@ -83,10 +100,26 @@ export function createBatchLoadingFunc(mediaStore) {
83
100
  });
84
101
  });
85
102
  items.push.apply(items, _toConsumableArray(itemsWithMetadataTraceContext));
86
- _context.next = 14;
103
+
104
+ // add EmptyResponseFileItem for each file ID not included in /items response
105
+ itemsIds = itemsWithMetadataTraceContext.map(function (item) {
106
+ return item.id;
107
+ });
108
+ fileIdsNotFound = fileIds.filter(function (id) {
109
+ return !itemsIds.includes(id);
110
+ });
111
+ fileIdsNotFound.forEach(function (fileId) {
112
+ items.push({
113
+ id: fileId,
114
+ collection: collectionName,
115
+ type: 'not-found',
116
+ metadataTraceContext: metadataTraceContext
117
+ });
118
+ });
119
+ _context.next = 17;
87
120
  break;
88
- case 11:
89
- _context.prev = 11;
121
+ case 14:
122
+ _context.prev = 14;
90
123
  _context.t0 = _context["catch"](3);
91
124
  fileIds.forEach(function (fileId) {
92
125
  items.push({
@@ -95,11 +128,11 @@ export function createBatchLoadingFunc(mediaStore) {
95
128
  error: _context.t0
96
129
  });
97
130
  });
98
- case 14:
131
+ case 17:
99
132
  case "end":
100
133
  return _context.stop();
101
134
  }
102
- }, _callee, null, [[3, 11]]);
135
+ }, _callee, null, [[3, 14]]);
103
136
  }));
104
137
  return function (_x2) {
105
138
  return _ref2.apply(this, arguments);
@@ -26,12 +26,16 @@ export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
26
26
  _this$metadata = this.metadata,
27
27
  _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
28
28
  collectionName = _this$metadata2.collectionName,
29
- occurrenceKey = _this$metadata2.occurrenceKey;
29
+ occurrenceKey = _this$metadata2.occurrenceKey,
30
+ traceContext = _this$metadata2.traceContext;
30
31
  return {
31
32
  reason: reason,
32
33
  id: id,
33
34
  collectionName: collectionName,
34
- occurrenceKey: occurrenceKey
35
+ occurrenceKey: occurrenceKey,
36
+ metadata: {
37
+ traceContext: traceContext
38
+ }
35
39
  };
36
40
  }
37
41
  }]);
@@ -8,6 +8,7 @@ import { createMediaSubject } from '../createMediaSubject';
8
8
  import { isEmptyFile } from '../detectEmptyFile';
9
9
  import { PollingFunction } from '../polling';
10
10
  import { MobileUploadError } from './error';
11
+ import { isNotFoundMediaItemDetails } from '../../models/media';
11
12
  export var createMobileFileStateSubject = function createMobileFileStateSubject(service) {
12
13
  var subject = new ReplaySubject(1);
13
14
  from(service.start()).pipe(map(function (state) {
@@ -35,13 +36,14 @@ export var createMobileDownloadFileStream = function createMobileDownloadFileStr
35
36
  });
36
37
  case 2:
37
38
  response = _context.sent;
38
- if (response) {
39
+ if (!isNotFoundMediaItemDetails(response)) {
39
40
  _context.next = 5;
40
41
  break;
41
42
  }
42
43
  throw new MobileUploadError('emptyItems', id, {
43
44
  collectionName: collectionName,
44
- occurrenceKey: occurrenceKey
45
+ occurrenceKey: occurrenceKey,
46
+ traceContext: response.metadataTraceContext
45
47
  });
46
48
  case 5:
47
49
  if (!isEmptyFile(response)) {
@@ -50,7 +52,8 @@ export var createMobileDownloadFileStream = function createMobileDownloadFileStr
50
52
  }
51
53
  throw new MobileUploadError('zeroVersionFile', id, {
52
54
  collectionName: collectionName,
53
- occurrenceKey: occurrenceKey
55
+ occurrenceKey: occurrenceKey,
56
+ traceContext: response.metadataTraceContext
54
57
  });
55
58
  case 7:
56
59
  fileState = mapMediaItemToFileState(id, response);
@@ -31,6 +31,7 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
31
31
  attempts = _this$metadata2.attempts,
32
32
  clientExhaustedRetries = _this$metadata2.clientExhaustedRetries,
33
33
  statusCode = _this$metadata2.statusCode,
34
+ traceContext = _this$metadata2.traceContext,
34
35
  innerError = this.innerError;
35
36
  return {
36
37
  reason: reason,
@@ -41,6 +42,9 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
41
42
  attempts: attempts,
42
43
  clientExhaustedRetries: clientExhaustedRetries,
43
44
  statusCode: statusCode,
45
+ metadata: {
46
+ traceContext: traceContext
47
+ },
44
48
  innerError: innerError
45
49
  };
46
50
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseMediaClientError } from '../../models/errors';
2
+ import { type MediaTraceContext } from '@atlaskit/media-common';
2
3
  export type FileFetcherErrorReason = 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'emptyFileName';
3
4
  export type FileFetcherErrorAttributes = {
4
5
  readonly reason: FileFetcherErrorReason;
@@ -6,6 +7,7 @@ export type FileFetcherErrorAttributes = {
6
7
  readonly metadata?: {
7
8
  readonly collectionName?: string;
8
9
  readonly occurrenceKey?: string;
10
+ readonly traceContext?: MediaTraceContext;
9
11
  };
10
12
  };
11
13
  export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorAttributes> {
@@ -14,12 +16,17 @@ export declare class FileFetcherError extends BaseMediaClientError<FileFetcherEr
14
16
  readonly metadata?: {
15
17
  readonly collectionName?: string | undefined;
16
18
  readonly occurrenceKey?: string | undefined;
19
+ readonly traceContext?: MediaTraceContext | undefined;
17
20
  } | undefined;
18
21
  constructor(reason: FileFetcherErrorReason, id: string, metadata?: {
19
22
  readonly collectionName?: string | undefined;
20
23
  readonly occurrenceKey?: string | undefined;
24
+ readonly traceContext?: MediaTraceContext | undefined;
21
25
  } | undefined);
22
26
  get attributes(): {
27
+ metadata?: {
28
+ traceContext: MediaTraceContext;
29
+ } | undefined;
23
30
  reason: FileFetcherErrorReason;
24
31
  id: string;
25
32
  collectionName: string | undefined;
@@ -18,7 +18,7 @@ export declare class MediaStore implements MediaApi {
18
18
  getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
19
19
  getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
20
20
  private createFileImageURL;
21
- getFileBinary(id: string, collectionName?: string, maxAge?: number): Promise<Blob>;
21
+ getFileBinary(id: string, collectionName?: string, abortController?: AbortController, maxAge?: number): Promise<Blob>;
22
22
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
23
23
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
24
24
  getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
@@ -1,4 +1,4 @@
1
1
  export type { MediaStoreErrorReason, MediaStoreErrorAttributes } from './error';
2
2
  export { MediaStoreError, isMediaStoreError } from './error';
3
3
  export { MediaStore, getMediaEnvironment, getMediaRegion } from './MediaStore';
4
- export type { ResponseFileItem, ItemsPayload, ImageMetadataArtifact, ImageMetadata, MediaStoreResponse, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileParams, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, MediaStoreCreateFileFromBinaryParams, MediaStoreCreateFileFromUploadConditions, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, SourceFile, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, CreatedTouchedFile, RejectedTouchFile, RejectionError, TouchedFiles, EmptyFile, MediaApi, } from './types';
4
+ export type { ResponseFileItem, EmptyResponseFileItem, ItemsPayload, ImageMetadataArtifact, ImageMetadata, MediaStoreResponse, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileParams, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, MediaStoreCreateFileFromBinaryParams, MediaStoreCreateFileFromUploadConditions, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, SourceFile, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, CreatedTouchedFile, RejectedTouchFile, RejectionError, TouchedFiles, EmptyFile, MediaApi, } from './types';