@atlaskit/media-client 28.5.0 → 29.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/client/file-fetcher/error.js +5 -7
  3. package/dist/cjs/client/file-fetcher/index.js +181 -71
  4. package/dist/cjs/client/media-client.js +1 -2
  5. package/dist/cjs/client/media-store/MediaStore.js +34 -24
  6. package/dist/cjs/client/media-store/error.js +5 -7
  7. package/dist/cjs/client/mobile-upload.js +1 -2
  8. package/dist/cjs/client/stargate-client.js +1 -2
  9. package/dist/cjs/file-streams-cache.js +1 -2
  10. package/dist/cjs/models/errors/index.js +6 -8
  11. package/dist/cjs/upload-controller.js +1 -2
  12. package/dist/cjs/uploader/error.js +5 -7
  13. package/dist/cjs/utils/createCopyIntentRegisterationBatcher.js +123 -0
  14. package/dist/cjs/utils/hashing/sha256SimpleHasher.js +1 -2
  15. package/dist/cjs/utils/hashing/simpleHasher.js +1 -2
  16. package/dist/cjs/utils/hashing/workerHasher.js +1 -2
  17. package/dist/cjs/utils/mobileUpload/error.js +5 -7
  18. package/dist/cjs/utils/polling/errors.js +5 -7
  19. package/dist/cjs/utils/polling/index.js +1 -2
  20. package/dist/cjs/utils/request/errors.js +5 -7
  21. package/dist/cjs/utils/request/helpers.js +10 -4
  22. package/dist/es2019/client/file-fetcher/index.js +60 -8
  23. package/dist/es2019/client/media-store/MediaStore.js +17 -14
  24. package/dist/es2019/utils/createCopyIntentRegisterationBatcher.js +75 -0
  25. package/dist/es2019/utils/request/helpers.js +7 -2
  26. package/dist/esm/client/file-fetcher/error.js +5 -7
  27. package/dist/esm/client/file-fetcher/index.js +181 -71
  28. package/dist/esm/client/media-client.js +1 -2
  29. package/dist/esm/client/media-store/MediaStore.js +36 -26
  30. package/dist/esm/client/media-store/error.js +5 -7
  31. package/dist/esm/client/mobile-upload.js +1 -2
  32. package/dist/esm/client/stargate-client.js +1 -2
  33. package/dist/esm/file-streams-cache.js +1 -2
  34. package/dist/esm/models/errors/index.js +6 -8
  35. package/dist/esm/upload-controller.js +1 -2
  36. package/dist/esm/uploader/error.js +5 -7
  37. package/dist/esm/utils/createCopyIntentRegisterationBatcher.js +115 -0
  38. package/dist/esm/utils/hashing/sha256SimpleHasher.js +1 -2
  39. package/dist/esm/utils/hashing/simpleHasher.js +1 -2
  40. package/dist/esm/utils/hashing/workerHasher.js +1 -2
  41. package/dist/esm/utils/mobileUpload/error.js +5 -7
  42. package/dist/esm/utils/polling/errors.js +5 -7
  43. package/dist/esm/utils/polling/index.js +1 -2
  44. package/dist/esm/utils/request/errors.js +5 -7
  45. package/dist/esm/utils/request/helpers.js +9 -4
  46. package/dist/types/client/file-fetcher/index.d.ts +7 -2
  47. package/dist/types/client/media-store/MediaStore.d.ts +4 -1
  48. package/dist/types/client/media-store/types.d.ts +5 -1
  49. package/dist/types/utils/createCopyIntentRegisterationBatcher.d.ts +20 -0
  50. package/dist/types/utils/request/helpers.d.ts +1 -0
  51. package/dist/types/utils/request/types.d.ts +1 -0
  52. package/dist/types-ts4.5/client/file-fetcher/index.d.ts +7 -2
  53. package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +4 -1
  54. package/dist/types-ts4.5/client/media-store/types.d.ts +5 -1
  55. package/dist/types-ts4.5/utils/createCopyIntentRegisterationBatcher.d.ts +20 -0
  56. package/dist/types-ts4.5/utils/request/helpers.d.ts +1 -0
  57. package/dist/types-ts4.5/utils/request/types.d.ts +1 -0
  58. package/package.json +4 -4
@@ -0,0 +1,75 @@
1
+ import Dataloader from 'dataloader';
2
+ import { getRandomHex } from '@atlaskit/media-common';
3
+ export const MAX_BATCH_SIZE = 100;
4
+ /**
5
+ * Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
6
+ * Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
7
+ *
8
+ * If an Error is resolved in the results, it must be at same position then their corresponding key:
9
+ * - Dataloader will re-throw that Error when accessing/loading that particular key
10
+ *
11
+ * @param mediaStore instance of MediaStore
12
+ */
13
+ function createBatchCopyIntentRegisterationFunc(mediaStore) {
14
+ return async keys => {
15
+ const keysByToken = keys.reduce((acc, key) => {
16
+ const token = key.resolvedAuth.token;
17
+ acc[token] = acc[token] || [];
18
+
19
+ // de-duplicate ids in collection
20
+ const hasDuplicates = acc[token].some(({
21
+ id,
22
+ collectionName
23
+ }) => key.id === id && collectionName === key.collectionName);
24
+ if (!hasDuplicates) {
25
+ acc[token].push(key);
26
+ }
27
+ return acc;
28
+ }, {});
29
+ const items = [];
30
+ await Promise.all(Object.keys(keysByToken).map(async batchKey => {
31
+ const metadataTraceContext = {
32
+ traceId: getRandomHex(8),
33
+ spanId: getRandomHex(8)
34
+ };
35
+ const files = keysByToken[batchKey].map(key => ({
36
+ id: key.id,
37
+ collection: key.collectionName
38
+ }));
39
+
40
+ // given these are batched by the token the assumption is that they have the same details.
41
+ const resolvedAuth = keysByToken[batchKey][0].resolvedAuth;
42
+ try {
43
+ await mediaStore.registerCopyIntents(files, metadataTraceContext, resolvedAuth);
44
+ } catch (error) {
45
+ files.forEach(({
46
+ id,
47
+ collection
48
+ }) => {
49
+ items.push({
50
+ id,
51
+ collection,
52
+ error: error
53
+ });
54
+ });
55
+ }
56
+ }));
57
+ return keys.map(({
58
+ id,
59
+ collectionName
60
+ }) => {
61
+ var _items$find;
62
+ return (_items$find = items.find(item => item.id === id && item.collection === collectionName)) === null || _items$find === void 0 ? void 0 : _items$find.error;
63
+ });
64
+ };
65
+ }
66
+ export function createCopyIntentRegisterationBatcher(mediaStore) {
67
+ return new Dataloader(createBatchCopyIntentRegisterationFunc(mediaStore), {
68
+ maxBatchSize: MAX_BATCH_SIZE,
69
+ cacheKeyFn: ({
70
+ id,
71
+ collectionName = 'default',
72
+ resolvedAuth
73
+ }) => `${id}-${collectionName}-${resolvedAuth.token}`
74
+ });
75
+ }
@@ -100,6 +100,10 @@ export function createMapResponseToBlob(metadata) {
100
100
  }
101
101
  };
102
102
  }
103
+ export const defaultShouldRetryError = err => {
104
+ var _err$metadata;
105
+ return isFetchNetworkError(err) || isRequestError(err) && !!(err !== null && err !== void 0 && (_err$metadata = err.metadata) !== null && _err$metadata !== void 0 && _err$metadata.statusCode) && err.metadata.statusCode >= 500;
106
+ };
103
107
  export const DEFAULT_RETRY_OPTIONS = {
104
108
  startTimeoutInMs: 1000,
105
109
  // 1 second is generally a good timeout to start
@@ -126,7 +130,8 @@ export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {
126
130
  const {
127
131
  startTimeoutInMs,
128
132
  maxAttempts,
129
- factor
133
+ factor,
134
+ shouldRetryError = defaultShouldRetryError
130
135
  } = options;
131
136
  let attempts = 0;
132
137
  let timeoutInMs = startTimeoutInMs;
@@ -146,7 +151,7 @@ export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {
146
151
  if (isAbortedRequestError(err)) {
147
152
  throw new RequestError('clientAbortedRequest', metadata, err);
148
153
  }
149
- if (!isFetchNetworkError(err) && !isRequestError(err) || isRequestError(err) && (!err.metadata || !err.metadata.statusCode || err.metadata.statusCode < 500)) {
154
+ if (!shouldRetryError(err)) {
150
155
  throw err;
151
156
  }
152
157
  await waitAndBumpTimeout();
@@ -1,27 +1,26 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
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
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; }
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); }; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
11
  import { BaseMediaClientError } from '../../models/errors';
12
12
  export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
13
- _inherits(FileFetcherError, _BaseMediaClientError);
14
- var _super = _createSuper(FileFetcherError);
15
13
  function FileFetcherError(reason, id, metadata) {
16
14
  var _this;
17
15
  _classCallCheck(this, FileFetcherError);
18
- _this = _super.call(this, reason);
16
+ _this = _callSuper(this, FileFetcherError, [reason]);
19
17
  _this.reason = reason;
20
18
  _this.id = id;
21
19
  _this.metadata = metadata;
22
20
  return _this;
23
21
  }
24
- _createClass(FileFetcherError, [{
22
+ _inherits(FileFetcherError, _BaseMediaClientError);
23
+ return _createClass(FileFetcherError, [{
25
24
  key: "attributes",
26
25
  get: function get() {
27
26
  var reason = this.reason,
@@ -43,7 +42,6 @@ export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
43
42
  });
44
43
  }
45
44
  }]);
46
- return FileFetcherError;
47
45
  }(BaseMediaClientError);
48
46
  export function isFileFetcherError(err) {
49
47
  return err instanceof FileFetcherError;
@@ -34,7 +34,15 @@ import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileSt
34
34
  import { PollingFunction } from '../../utils/polling';
35
35
  import { isEmptyFile } from '../../utils/detectEmptyFile';
36
36
  import { mediaStore } from '@atlaskit/media-state';
37
+ import { createCopyIntentRegisterationBatcher } from '../../utils/createCopyIntentRegisterationBatcher';
38
+ import { defaultShouldRetryError } from '../../utils/request/helpers';
37
39
  export { isFileFetcherError, FileFetcherError } from './error';
40
+ var isCopySourceFileWithToken = function isCopySourceFileWithToken(token) {
41
+ return !!token.authProvider;
42
+ };
43
+ var isCopyDestinationWithToken = function isCopyDestinationWithToken(token) {
44
+ return !!token.authProvider;
45
+ };
38
46
  export var FileFetcherImpl = /*#__PURE__*/function () {
39
47
  function FileFetcherImpl(mediaApi) {
40
48
  var _this = this;
@@ -165,8 +173,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
165
173
  this.mediaApi = mediaApi;
166
174
  this.store = store;
167
175
  this.dataloader = createFileDataloader(mediaApi);
176
+ this.copyIntentRegisterationBatcher = createCopyIntentRegisterationBatcher(mediaApi);
168
177
  }
169
- _createClass(FileFetcherImpl, [{
178
+ return _createClass(FileFetcherImpl, [{
170
179
  key: "getFileState",
171
180
  value: function getFileState(id) {
172
181
  var _this2 = this;
@@ -495,29 +504,143 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
495
504
  }
496
505
  return downloadBinary;
497
506
  }()
507
+ }, {
508
+ key: "registerCopyIntent",
509
+ value: function () {
510
+ var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(id, collectionName) {
511
+ var auth, key, error;
512
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
513
+ while (1) switch (_context6.prev = _context6.next) {
514
+ case 0:
515
+ _context6.next = 2;
516
+ return this.mediaApi.resolveAuth({
517
+ collectionName: collectionName
518
+ });
519
+ case 2:
520
+ auth = _context6.sent;
521
+ key = {
522
+ id: id,
523
+ collectionName: collectionName,
524
+ resolvedAuth: auth
525
+ };
526
+ _context6.next = 6;
527
+ return this.copyIntentRegisterationBatcher.load(key);
528
+ case 6:
529
+ error = _context6.sent;
530
+ if (!error) {
531
+ _context6.next = 10;
532
+ break;
533
+ }
534
+ // if the error is retryable then it should not be cached
535
+ if (defaultShouldRetryError(error)) {
536
+ this.copyIntentRegisterationBatcher.clear(key);
537
+ }
538
+ throw error;
539
+ case 10:
540
+ case "end":
541
+ return _context6.stop();
542
+ }
543
+ }, _callee6, this);
544
+ }));
545
+ function registerCopyIntent(_x9, _x10) {
546
+ return _registerCopyIntent.apply(this, arguments);
547
+ }
548
+ return registerCopyIntent;
549
+ }()
550
+ }, {
551
+ key: "copyFileWithToken",
552
+ value: function () {
553
+ var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(source, destination, traceContext) {
554
+ var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
555
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
556
+ while (1) switch (_context7.prev = _context7.next) {
557
+ case 0:
558
+ authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
559
+ destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
560
+ mediaStore = destination.mediaStore || new MediaApi({
561
+ authProvider: destinationAuthProvider
562
+ });
563
+ _context7.t0 = authToOwner;
564
+ _context7.next = 6;
565
+ return authProvider({
566
+ collectionName: sourceCollection
567
+ });
568
+ case 6:
569
+ _context7.t1 = _context7.sent;
570
+ owner = (0, _context7.t0)(_context7.t1);
571
+ body = {
572
+ sourceFile: {
573
+ id: id,
574
+ collection: sourceCollection,
575
+ owner: owner
576
+ }
577
+ };
578
+ params = {
579
+ collection: destinationCollectionName,
580
+ replaceFileId: replaceFileId,
581
+ occurrenceKey: occurrenceKey
582
+ };
583
+ _context7.next = 12;
584
+ return mediaStore.copyFileWithToken(body, params, traceContext);
585
+ case 12:
586
+ _yield$mediaStore$cop = _context7.sent;
587
+ data = _yield$mediaStore$cop.data;
588
+ return _context7.abrupt("return", data);
589
+ case 15:
590
+ case "end":
591
+ return _context7.stop();
592
+ }
593
+ }, _callee7);
594
+ }));
595
+ function copyFileWithToken(_x11, _x12, _x13) {
596
+ return _copyFileWithToken.apply(this, arguments);
597
+ }
598
+ return copyFileWithToken;
599
+ }()
600
+ }, {
601
+ key: "copyFileWithIntent",
602
+ value: function () {
603
+ var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(source, destination, traceContext) {
604
+ var res, data;
605
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
606
+ while (1) switch (_context8.prev = _context8.next) {
607
+ case 0:
608
+ _context8.next = 2;
609
+ return this.mediaApi.copyFile(source.id, {
610
+ sourceCollection: source.collection,
611
+ collection: destination.collection,
612
+ replaceFileId: destination.replaceFileId
613
+ }, traceContext);
614
+ case 2:
615
+ res = _context8.sent;
616
+ data = res.data;
617
+ return _context8.abrupt("return", data);
618
+ case 5:
619
+ case "end":
620
+ return _context8.stop();
621
+ }
622
+ }, _callee8, this);
623
+ }));
624
+ function copyFileWithIntent(_x14, _x15, _x16) {
625
+ return _copyFileWithIntent.apply(this, arguments);
626
+ }
627
+ return copyFileWithIntent;
628
+ }()
498
629
  }, {
499
630
  key: "copyFile",
500
631
  value: function () {
501
- var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, destination) {
632
+ var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(source, destination) {
502
633
  var _this5 = this;
503
634
  var options,
504
635
  traceContext,
505
- authProvider,
506
- sourceCollection,
507
636
  id,
508
- destinationAuthProvider,
509
637
  destinationCollectionName,
510
638
  replaceFileId,
511
639
  occurrenceKey,
512
640
  preview,
513
641
  mimeType,
514
- mediaStore,
515
- owner,
516
- body,
517
- params,
518
642
  cache,
519
643
  processingSubscription,
520
- _yield$mediaStore$cop,
521
644
  copiedFile,
522
645
  copiedFileWithMimeType,
523
646
  copiedId,
@@ -533,45 +656,33 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
533
656
  replaceFileState,
534
657
  key,
535
658
  errorFileState,
536
- _args6 = arguments;
537
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
538
- while (1) switch (_context6.prev = _context6.next) {
659
+ _args9 = arguments;
660
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
661
+ while (1) switch (_context9.prev = _context9.next) {
539
662
  case 0:
540
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
541
- traceContext = _args6.length > 3 ? _args6[3] : undefined;
542
- authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
543
- destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
663
+ options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
664
+ traceContext = _args9.length > 3 ? _args9[3] : undefined;
665
+ id = source.id;
666
+ destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
544
667
  preview = options.preview, mimeType = options.mimeType;
545
- mediaStore = destination.mediaStore || new MediaApi({
546
- authProvider: destinationAuthProvider
547
- });
548
- _context6.t0 = authToOwner;
549
- _context6.next = 9;
550
- return authProvider({
551
- collectionName: sourceCollection
552
- });
553
- case 9:
554
- _context6.t1 = _context6.sent;
555
- owner = (0, _context6.t0)(_context6.t1);
556
- body = {
557
- sourceFile: {
558
- id: id,
559
- collection: sourceCollection,
560
- owner: owner
561
- }
562
- };
563
- params = {
564
- collection: destinationCollectionName,
565
- replaceFileId: replaceFileId,
566
- occurrenceKey: occurrenceKey
567
- };
568
668
  cache = getFileStreamsCache();
569
- _context6.prev = 14;
570
- _context6.next = 17;
571
- return mediaStore.copyFileWithToken(body, params, traceContext);
572
- case 17:
573
- _yield$mediaStore$cop = _context6.sent;
574
- copiedFile = _yield$mediaStore$cop.data;
669
+ _context9.prev = 6;
670
+ if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
671
+ _context9.next = 13;
672
+ break;
673
+ }
674
+ _context9.next = 10;
675
+ return this.copyFileWithToken(source, destination, traceContext);
676
+ case 10:
677
+ copiedFile = _context9.sent;
678
+ _context9.next = 16;
679
+ break;
680
+ case 13:
681
+ _context9.next = 15;
682
+ return this.copyFileWithIntent(source, destination, traceContext);
683
+ case 15:
684
+ copiedFile = _context9.sent;
685
+ case 16:
575
686
  // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
576
687
  copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
577
688
  mimeType: mimeType
@@ -587,21 +698,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
587
698
  previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
588
699
  preview: preview
589
700
  } : {};
590
- _context6.t2 = !isFinalFileState(copiedFileState) &&
701
+ _context9.t0 = !isFinalFileState(copiedFileState) &&
591
702
  // mimeType should always be returned by "copyFileWithToken"
592
703
  // but in case it's not, we don't want to penalize "copyFile"
593
704
  copiedMimeType;
594
- if (!_context6.t2) {
595
- _context6.next = 31;
705
+ if (!_context9.t0) {
706
+ _context9.next = 28;
596
707
  break;
597
708
  }
598
- _context6.next = 30;
709
+ _context9.next = 27;
599
710
  return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
600
- case 30:
601
- _context6.t2 = _context6.sent;
602
- case 31:
603
- if (!_context6.t2) {
604
- _context6.next = 38;
711
+ case 27:
712
+ _context9.t0 = _context9.sent;
713
+ case 28:
714
+ if (!_context9.t0) {
715
+ _context9.next = 35;
605
716
  break;
606
717
  }
607
718
  fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride);
@@ -622,22 +733,22 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
622
733
  return subject.complete();
623
734
  }
624
735
  });
625
- _context6.next = 39;
736
+ _context9.next = 36;
626
737
  break;
627
- case 38:
738
+ case 35:
628
739
  if (!isProcessingFileState(copiedFileState)) {
629
740
  _fileState = _objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride);
630
741
  subject.next(_fileState);
631
742
  this.setFileState(copiedId, _fileState);
632
743
  }
633
- case 39:
744
+ case 36:
634
745
  if (!cache.has(copiedId)) {
635
746
  getFileStreamsCache().set(copiedId, subject);
636
747
  }
637
- return _context6.abrupt("return", copiedFile);
638
- case 43:
639
- _context6.prev = 43;
640
- _context6.t3 = _context6["catch"](14);
748
+ return _context9.abrupt("return", copiedFile);
749
+ case 40:
750
+ _context9.prev = 40;
751
+ _context9.t1 = _context9["catch"](6);
641
752
  if (processingSubscription) {
642
753
  processingSubscription.unsubscribe();
643
754
  }
@@ -645,27 +756,26 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
645
756
  _fileCache = cache.get(replaceFileId);
646
757
  replaceFileState = this.store.getState().files[replaceFileId];
647
758
  if (_fileCache) {
648
- _fileCache.error(_context6.t3);
759
+ _fileCache.error(_context9.t1);
649
760
  } else {
650
761
  // Create a new subject with the error state for new subscriptions
651
- cache.set(id, createMediaSubject(_context6.t3));
762
+ cache.set(id, createMediaSubject(_context9.t1));
652
763
  }
653
764
  key = replaceFileState ? replaceFileId : id;
654
- errorFileState = this.getErrorFileState(_context6.t3, id, occurrenceKey);
765
+ errorFileState = this.getErrorFileState(_context9.t1, id, occurrenceKey);
655
766
  this.setFileState(key, errorFileState);
656
767
  }
657
- throw _context6.t3;
658
- case 48:
768
+ throw _context9.t1;
769
+ case 45:
659
770
  case "end":
660
- return _context6.stop();
771
+ return _context9.stop();
661
772
  }
662
- }, _callee6, this, [[14, 43]]);
773
+ }, _callee9, this, [[6, 40]]);
663
774
  }));
664
- function copyFile(_x9, _x10) {
775
+ function copyFile(_x17, _x18) {
665
776
  return _copyFile.apply(this, arguments);
666
777
  }
667
778
  return copyFile;
668
779
  }()
669
780
  }]);
670
- return FileFetcherImpl;
671
781
  }();
@@ -34,7 +34,7 @@ export var MediaClient = /*#__PURE__*/function () {
34
34
  /**
35
35
  * @internal
36
36
  */
37
- _createClass(MediaClient, [{
37
+ return _createClass(MediaClient, [{
38
38
  key: "__DO_NOT_USE__getMediaStore",
39
39
  value: function __DO_NOT_USE__getMediaStore() {
40
40
  return this.store;
@@ -143,5 +143,4 @@ export var MediaClient = /*#__PURE__*/function () {
143
143
  return this.eventEmitter.emit(event, payload);
144
144
  }
145
145
  }]);
146
- return MediaClient;
147
146
  }();
@@ -8,8 +8,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
8
8
  import { isClientBasedAuth } from '@atlaskit/media-core';
9
9
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
10
10
  import { getArtifactUrl } from '../../models/artifacts';
11
- import { request as _request } from '../../utils/request';
12
- import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
11
+ import { isRequestError, request as _request } from '../../utils/request';
12
+ import { createUrl, createMapResponseToJson, createMapResponseToBlob, defaultShouldRetryError, extendTraceContext } from '../../utils/request/helpers';
13
13
  import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
14
14
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
15
15
  import { ChunkHashAlgorithm } from '@atlaskit/media-core';
@@ -55,7 +55,7 @@ export var MediaStore = /*#__PURE__*/function () {
55
55
  this.config = config;
56
56
  this._chunkHashAlgorithm = config.chunkHashAlgorithm || ChunkHashAlgorithm.Sha1;
57
57
  }
58
- _createClass(MediaStore, [{
58
+ return _createClass(MediaStore, [{
59
59
  key: "removeCollectionFile",
60
60
  value: function () {
61
61
  var _removeCollectionFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(id, collectionName, occurrenceKey, traceContext) {
@@ -603,41 +603,41 @@ export var MediaStore = /*#__PURE__*/function () {
603
603
  body: JSON.stringify({
604
604
  id: id
605
605
  }),
606
- traceContext: traceContext
606
+ traceContext: traceContext,
607
+ clientOptions: {
608
+ retryOptions: {
609
+ shouldRetryError: function shouldRetryError(err) {
610
+ var _err$metadata;
611
+ return defaultShouldRetryError(err) || isRequestError(err) && (err === null || err === void 0 || (_err$metadata = err.metadata) === null || _err$metadata === void 0 ? void 0 : _err$metadata.statusCode) === 401;
612
+ }
613
+ }
614
+ }
607
615
  });
608
616
  return this.request('/v2/file/copy', options).then(createMapResponseToJson(metadata));
609
617
  }
610
618
  }, {
611
619
  key: "registerCopyIntents",
612
620
  value: function () {
613
- var _registerCopyIntents = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(ids, collectionName, traceContext) {
614
- var files, metadata, options;
621
+ var _registerCopyIntents = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(files, traceContext, resolvedAuth) {
622
+ var metadata, options;
615
623
  return _regeneratorRuntime.wrap(function _callee12$(_context12) {
616
624
  while (1) switch (_context12.prev = _context12.next) {
617
625
  case 0:
618
- files = ids.map(function (id) {
619
- return {
620
- id: id,
621
- collection: collectionName
622
- };
623
- });
624
626
  metadata = {
625
627
  method: 'POST',
626
628
  endpoint: '/file/copy/intents'
627
629
  };
628
630
  options = _objectSpread(_objectSpread({}, metadata), {}, {
629
- authContext: {
630
- collectionName: collectionName
631
- },
632
631
  headers: jsonHeaders,
633
632
  body: JSON.stringify({
634
633
  files: files
635
634
  }),
636
- traceContext: traceContext
635
+ traceContext: traceContext,
636
+ resolvedAuth: resolvedAuth
637
637
  });
638
- _context12.next = 5;
638
+ _context12.next = 4;
639
639
  return this.request('/file/copy/intents', options);
640
- case 5:
640
+ case 4:
641
641
  case "end":
642
642
  return _context12.stop();
643
643
  }
@@ -664,6 +664,7 @@ export var MediaStore = /*#__PURE__*/function () {
664
664
  clientOptions,
665
665
  traceContext,
666
666
  addMediaClientParam,
667
+ resolvedAuth,
667
668
  auth,
668
669
  clientId,
669
670
  extendedTraceContext,
@@ -681,11 +682,21 @@ export var MediaStore = /*#__PURE__*/function () {
681
682
  };
682
683
  controller = _args13.length > 2 ? _args13[2] : undefined;
683
684
  useMediaCdn = _args13.length > 3 ? _args13[3] : undefined;
684
- method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam;
685
- _context13.next = 6;
685
+ method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam, resolvedAuth = options.resolvedAuth;
686
+ if (!(resolvedAuth !== null && resolvedAuth !== void 0)) {
687
+ _context13.next = 8;
688
+ break;
689
+ }
690
+ _context13.t0 = resolvedAuth;
691
+ _context13.next = 11;
692
+ break;
693
+ case 8:
694
+ _context13.next = 10;
686
695
  return this.resolveAuth(authContext);
687
- case 6:
688
- auth = _context13.sent;
696
+ case 10:
697
+ _context13.t0 = _context13.sent;
698
+ case 11:
699
+ auth = _context13.t0;
689
700
  clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
690
701
  extendedTraceContext = extendTraceContext(traceContext);
691
702
  extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
@@ -695,7 +706,7 @@ export var MediaStore = /*#__PURE__*/function () {
695
706
  if (useMediaCdn) {
696
707
  url = mapToMediaCdnUrl(url, auth.token);
697
708
  }
698
- _context13.next = 14;
709
+ _context13.next = 19;
699
710
  return _request(url, {
700
711
  method: method,
701
712
  endpoint: endpoint,
@@ -706,12 +717,12 @@ export var MediaStore = /*#__PURE__*/function () {
706
717
  clientOptions: clientOptions,
707
718
  traceContext: extendedTraceContext
708
719
  }, controller);
709
- case 14:
720
+ case 19:
710
721
  response = _context13.sent;
711
722
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
712
723
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
713
724
  return _context13.abrupt("return", response);
714
- case 18:
725
+ case 23:
715
726
  case "end":
716
727
  return _context13.stop();
717
728
  }
@@ -761,7 +772,6 @@ export var MediaStore = /*#__PURE__*/function () {
761
772
  return this._chunkHashAlgorithm;
762
773
  }
763
774
  }]);
764
- return MediaStore;
765
775
  }();
766
776
  var getValueFromSessionStorage = function getValueFromSessionStorage(key) {
767
777
  return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;