@atlaskit/media-client 28.4.0 → 28.6.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 (53) 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 +135 -71
  4. package/dist/cjs/client/media-client.js +1 -2
  5. package/dist/cjs/client/media-store/MediaStore.js +94 -26
  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/hashing/sha256SimpleHasher.js +1 -2
  14. package/dist/cjs/utils/hashing/simpleHasher.js +1 -2
  15. package/dist/cjs/utils/hashing/workerHasher.js +1 -2
  16. package/dist/cjs/utils/mobileUpload/error.js +5 -7
  17. package/dist/cjs/utils/polling/errors.js +5 -7
  18. package/dist/cjs/utils/polling/index.js +1 -2
  19. package/dist/cjs/utils/request/errors.js +5 -7
  20. package/dist/cjs/utils/request/helpers.js +10 -4
  21. package/dist/es2019/client/file-fetcher/index.js +38 -8
  22. package/dist/es2019/client/media-store/MediaStore.js +51 -2
  23. package/dist/es2019/utils/request/helpers.js +7 -2
  24. package/dist/esm/client/file-fetcher/error.js +5 -7
  25. package/dist/esm/client/file-fetcher/index.js +135 -71
  26. package/dist/esm/client/media-client.js +1 -2
  27. package/dist/esm/client/media-store/MediaStore.js +96 -28
  28. package/dist/esm/client/media-store/error.js +5 -7
  29. package/dist/esm/client/mobile-upload.js +1 -2
  30. package/dist/esm/client/stargate-client.js +1 -2
  31. package/dist/esm/file-streams-cache.js +1 -2
  32. package/dist/esm/models/errors/index.js +6 -8
  33. package/dist/esm/upload-controller.js +1 -2
  34. package/dist/esm/uploader/error.js +5 -7
  35. package/dist/esm/utils/hashing/sha256SimpleHasher.js +1 -2
  36. package/dist/esm/utils/hashing/simpleHasher.js +1 -2
  37. package/dist/esm/utils/hashing/workerHasher.js +1 -2
  38. package/dist/esm/utils/mobileUpload/error.js +5 -7
  39. package/dist/esm/utils/polling/errors.js +5 -7
  40. package/dist/esm/utils/polling/index.js +1 -2
  41. package/dist/esm/utils/request/errors.js +5 -7
  42. package/dist/esm/utils/request/helpers.js +9 -4
  43. package/dist/types/client/file-fetcher/index.d.ts +4 -2
  44. package/dist/types/client/media-store/MediaStore.d.ts +3 -1
  45. package/dist/types/client/media-store/types.d.ts +7 -0
  46. package/dist/types/utils/request/helpers.d.ts +1 -0
  47. package/dist/types/utils/request/types.d.ts +1 -0
  48. package/dist/types-ts4.5/client/file-fetcher/index.d.ts +4 -2
  49. package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +3 -1
  50. package/dist/types-ts4.5/client/media-store/types.d.ts +7 -0
  51. package/dist/types-ts4.5/utils/request/helpers.d.ts +1 -0
  52. package/dist/types-ts4.5/utils/request/types.d.ts +1 -0
  53. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 28.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#179378](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/179378)
8
+ [`cb26b4db4b6ad`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cb26b4db4b6ad) -
9
+ Calling the /v2/file/copy endpoint in file.copyFile if auth providers are not given
10
+
11
+ ## 28.5.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#170974](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/170974)
16
+ [`215eb993c1ea3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/215eb993c1ea3) -
17
+ Added `registerCopyIntents` and `copyFile` endpoints to meida client to enable cross client copy
18
+ and paste
19
+
3
20
  ## 28.4.0
4
21
 
5
22
  ### Minor Changes
@@ -9,27 +9,26 @@ exports.isFileFetcherError = isFileFetcherError;
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
12
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
15
  var _errors = require("../../models/errors");
16
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
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; }
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); }; }
18
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
19
19
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
20
20
  var FileFetcherError = exports.FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
21
- (0, _inherits2.default)(FileFetcherError, _BaseMediaClientError);
22
- var _super = _createSuper(FileFetcherError);
23
21
  function FileFetcherError(reason, id, metadata) {
24
22
  var _this;
25
23
  (0, _classCallCheck2.default)(this, FileFetcherError);
26
- _this = _super.call(this, reason);
24
+ _this = _callSuper(this, FileFetcherError, [reason]);
27
25
  _this.reason = reason;
28
26
  _this.id = id;
29
27
  _this.metadata = metadata;
30
28
  return _this;
31
29
  }
32
- (0, _createClass2.default)(FileFetcherError, [{
30
+ (0, _inherits2.default)(FileFetcherError, _BaseMediaClientError);
31
+ return (0, _createClass2.default)(FileFetcherError, [{
33
32
  key: "attributes",
34
33
  get: function get() {
35
34
  var reason = this.reason,
@@ -51,7 +50,6 @@ var FileFetcherError = exports.FileFetcherError = /*#__PURE__*/function (_BaseMe
51
50
  });
52
51
  }
53
52
  }]);
54
- return FileFetcherError;
55
53
  }(_errors.BaseMediaClientError);
56
54
  function isFileFetcherError(err) {
57
55
  return err instanceof FileFetcherError;
@@ -53,6 +53,12 @@ var _excluded = ["metadata"],
53
53
  _excluded2 = ["metadata"];
54
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; }
55
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; }
56
+ var isCopySourceFileWithToken = function isCopySourceFileWithToken(token) {
57
+ return !!token.authProvider;
58
+ };
59
+ var isCopyDestinationWithToken = function isCopyDestinationWithToken(token) {
60
+ return !!token.authProvider;
61
+ };
56
62
  var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
57
63
  function FileFetcherImpl(mediaApi) {
58
64
  var _this = this;
@@ -184,7 +190,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
184
190
  this.store = store;
185
191
  this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaApi);
186
192
  }
187
- (0, _createClass2.default)(FileFetcherImpl, [{
193
+ return (0, _createClass2.default)(FileFetcherImpl, [{
188
194
  key: "getFileState",
189
195
  value: function getFileState(id) {
190
196
  var _this2 = this;
@@ -513,29 +519,100 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
513
519
  }
514
520
  return downloadBinary;
515
521
  }()
522
+ }, {
523
+ key: "copyFileWithToken",
524
+ value: function () {
525
+ var _copyFileWithToken = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(source, destination, traceContext) {
526
+ var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
527
+ return _regenerator.default.wrap(function _callee6$(_context6) {
528
+ while (1) switch (_context6.prev = _context6.next) {
529
+ case 0:
530
+ authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
531
+ destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
532
+ mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
533
+ authProvider: destinationAuthProvider
534
+ });
535
+ _context6.t0 = _mediaCore.authToOwner;
536
+ _context6.next = 6;
537
+ return authProvider({
538
+ collectionName: sourceCollection
539
+ });
540
+ case 6:
541
+ _context6.t1 = _context6.sent;
542
+ owner = (0, _context6.t0)(_context6.t1);
543
+ body = {
544
+ sourceFile: {
545
+ id: id,
546
+ collection: sourceCollection,
547
+ owner: owner
548
+ }
549
+ };
550
+ params = {
551
+ collection: destinationCollectionName,
552
+ replaceFileId: replaceFileId,
553
+ occurrenceKey: occurrenceKey
554
+ };
555
+ _context6.next = 12;
556
+ return mediaStore.copyFileWithToken(body, params, traceContext);
557
+ case 12:
558
+ _yield$mediaStore$cop = _context6.sent;
559
+ data = _yield$mediaStore$cop.data;
560
+ return _context6.abrupt("return", data);
561
+ case 15:
562
+ case "end":
563
+ return _context6.stop();
564
+ }
565
+ }, _callee6);
566
+ }));
567
+ function copyFileWithToken(_x9, _x10, _x11) {
568
+ return _copyFileWithToken.apply(this, arguments);
569
+ }
570
+ return copyFileWithToken;
571
+ }()
572
+ }, {
573
+ key: "copyFileWithIntent",
574
+ value: function () {
575
+ var _copyFileWithIntent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(source, destination, traceContext) {
576
+ var res, data;
577
+ return _regenerator.default.wrap(function _callee7$(_context7) {
578
+ while (1) switch (_context7.prev = _context7.next) {
579
+ case 0:
580
+ _context7.next = 2;
581
+ return this.mediaApi.copyFile(source.id, {
582
+ sourceCollection: source.collection,
583
+ collection: destination.collection,
584
+ replaceFileId: destination.replaceFileId
585
+ }, traceContext);
586
+ case 2:
587
+ res = _context7.sent;
588
+ data = res.data;
589
+ return _context7.abrupt("return", data);
590
+ case 5:
591
+ case "end":
592
+ return _context7.stop();
593
+ }
594
+ }, _callee7, this);
595
+ }));
596
+ function copyFileWithIntent(_x12, _x13, _x14) {
597
+ return _copyFileWithIntent.apply(this, arguments);
598
+ }
599
+ return copyFileWithIntent;
600
+ }()
516
601
  }, {
517
602
  key: "copyFile",
518
603
  value: function () {
519
- var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(source, destination) {
604
+ var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(source, destination) {
520
605
  var _this5 = this;
521
606
  var options,
522
607
  traceContext,
523
- authProvider,
524
- sourceCollection,
525
608
  id,
526
- destinationAuthProvider,
527
609
  destinationCollectionName,
528
610
  replaceFileId,
529
611
  occurrenceKey,
530
612
  preview,
531
613
  mimeType,
532
- mediaStore,
533
- owner,
534
- body,
535
- params,
536
614
  cache,
537
615
  processingSubscription,
538
- _yield$mediaStore$cop,
539
616
  copiedFile,
540
617
  copiedFileWithMimeType,
541
618
  copiedId,
@@ -551,45 +628,33 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
551
628
  replaceFileState,
552
629
  key,
553
630
  errorFileState,
554
- _args6 = arguments;
555
- return _regenerator.default.wrap(function _callee6$(_context6) {
556
- while (1) switch (_context6.prev = _context6.next) {
631
+ _args8 = arguments;
632
+ return _regenerator.default.wrap(function _callee8$(_context8) {
633
+ while (1) switch (_context8.prev = _context8.next) {
557
634
  case 0:
558
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
559
- traceContext = _args6.length > 3 ? _args6[3] : undefined;
560
- authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
561
- destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
635
+ options = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : {};
636
+ traceContext = _args8.length > 3 ? _args8[3] : undefined;
637
+ id = source.id;
638
+ destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
562
639
  preview = options.preview, mimeType = options.mimeType;
563
- mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
564
- authProvider: destinationAuthProvider
565
- });
566
- _context6.t0 = _mediaCore.authToOwner;
567
- _context6.next = 9;
568
- return authProvider({
569
- collectionName: sourceCollection
570
- });
571
- case 9:
572
- _context6.t1 = _context6.sent;
573
- owner = (0, _context6.t0)(_context6.t1);
574
- body = {
575
- sourceFile: {
576
- id: id,
577
- collection: sourceCollection,
578
- owner: owner
579
- }
580
- };
581
- params = {
582
- collection: destinationCollectionName,
583
- replaceFileId: replaceFileId,
584
- occurrenceKey: occurrenceKey
585
- };
586
640
  cache = (0, _fileStreamsCache.getFileStreamsCache)();
587
- _context6.prev = 14;
588
- _context6.next = 17;
589
- return mediaStore.copyFileWithToken(body, params, traceContext);
590
- case 17:
591
- _yield$mediaStore$cop = _context6.sent;
592
- copiedFile = _yield$mediaStore$cop.data;
641
+ _context8.prev = 6;
642
+ if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
643
+ _context8.next = 13;
644
+ break;
645
+ }
646
+ _context8.next = 10;
647
+ return this.copyFileWithToken(source, destination, traceContext);
648
+ case 10:
649
+ copiedFile = _context8.sent;
650
+ _context8.next = 16;
651
+ break;
652
+ case 13:
653
+ _context8.next = 15;
654
+ return this.copyFileWithIntent(source, destination, traceContext);
655
+ case 15:
656
+ copiedFile = _context8.sent;
657
+ case 16:
593
658
  // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
594
659
  copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
595
660
  mimeType: mimeType
@@ -605,21 +670,21 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
605
670
  previewOverride = !(0, _fileState2.isErrorFileState)(copiedFileState) && !!preview ? {
606
671
  preview: preview
607
672
  } : {};
608
- _context6.t2 = !(0, _fileState2.isFinalFileState)(copiedFileState) &&
673
+ _context8.t0 = !(0, _fileState2.isFinalFileState)(copiedFileState) &&
609
674
  // mimeType should always be returned by "copyFileWithToken"
610
675
  // but in case it's not, we don't want to penalize "copyFile"
611
676
  copiedMimeType;
612
- if (!_context6.t2) {
613
- _context6.next = 31;
677
+ if (!_context8.t0) {
678
+ _context8.next = 28;
614
679
  break;
615
680
  }
616
- _context6.next = 30;
681
+ _context8.next = 27;
617
682
  return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
618
- case 30:
619
- _context6.t2 = _context6.sent;
620
- case 31:
621
- if (!_context6.t2) {
622
- _context6.next = 38;
683
+ case 27:
684
+ _context8.t0 = _context8.sent;
685
+ case 28:
686
+ if (!_context8.t0) {
687
+ _context8.next = 35;
623
688
  break;
624
689
  }
625
690
  fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride);
@@ -640,22 +705,22 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
640
705
  return subject.complete();
641
706
  }
642
707
  });
643
- _context6.next = 39;
708
+ _context8.next = 36;
644
709
  break;
645
- case 38:
710
+ case 35:
646
711
  if (!(0, _fileState2.isProcessingFileState)(copiedFileState)) {
647
712
  _fileState = _objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState2.isErrorFileState)(copiedFileState) && previewOverride);
648
713
  subject.next(_fileState);
649
714
  this.setFileState(copiedId, _fileState);
650
715
  }
651
- case 39:
716
+ case 36:
652
717
  if (!cache.has(copiedId)) {
653
718
  (0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
654
719
  }
655
- return _context6.abrupt("return", copiedFile);
656
- case 43:
657
- _context6.prev = 43;
658
- _context6.t3 = _context6["catch"](14);
720
+ return _context8.abrupt("return", copiedFile);
721
+ case 40:
722
+ _context8.prev = 40;
723
+ _context8.t1 = _context8["catch"](6);
659
724
  if (processingSubscription) {
660
725
  processingSubscription.unsubscribe();
661
726
  }
@@ -663,27 +728,26 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
663
728
  _fileCache = cache.get(replaceFileId);
664
729
  replaceFileState = this.store.getState().files[replaceFileId];
665
730
  if (_fileCache) {
666
- _fileCache.error(_context6.t3);
731
+ _fileCache.error(_context8.t1);
667
732
  } else {
668
733
  // Create a new subject with the error state for new subscriptions
669
- cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
734
+ cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context8.t1));
670
735
  }
671
736
  key = replaceFileState ? replaceFileId : id;
672
- errorFileState = this.getErrorFileState(_context6.t3, id, occurrenceKey);
737
+ errorFileState = this.getErrorFileState(_context8.t1, id, occurrenceKey);
673
738
  this.setFileState(key, errorFileState);
674
739
  }
675
- throw _context6.t3;
676
- case 48:
740
+ throw _context8.t1;
741
+ case 45:
677
742
  case "end":
678
- return _context6.stop();
743
+ return _context8.stop();
679
744
  }
680
- }, _callee6, this, [[14, 43]]);
745
+ }, _callee8, this, [[6, 40]]);
681
746
  }));
682
- function copyFile(_x9, _x10) {
747
+ function copyFile(_x15, _x16) {
683
748
  return _copyFile.apply(this, arguments);
684
749
  }
685
750
  return copyFile;
686
751
  }()
687
752
  }]);
688
- return FileFetcherImpl;
689
753
  }();
@@ -44,7 +44,7 @@ var MediaClient = exports.MediaClient = /*#__PURE__*/function () {
44
44
  /**
45
45
  * @internal
46
46
  */
47
- (0, _createClass2.default)(MediaClient, [{
47
+ return (0, _createClass2.default)(MediaClient, [{
48
48
  key: "__DO_NOT_USE__getMediaStore",
49
49
  value: function __DO_NOT_USE__getMediaStore() {
50
50
  return this.store;
@@ -155,5 +155,4 @@ var MediaClient = exports.MediaClient = /*#__PURE__*/function () {
155
155
  return this.eventEmitter.emit(event, payload);
156
156
  }
157
157
  }]);
158
- return MediaClient;
159
158
  }();
@@ -61,7 +61,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
61
61
  this.config = config;
62
62
  this._chunkHashAlgorithm = config.chunkHashAlgorithm || _mediaCore.ChunkHashAlgorithm.Sha1;
63
63
  }
64
- (0, _createClass2.default)(MediaStore, [{
64
+ return (0, _createClass2.default)(MediaStore, [{
65
65
  key: "removeCollectionFile",
66
66
  value: function () {
67
67
  var _removeCollectionFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(id, collectionName, occurrenceKey, traceContext) {
@@ -593,10 +593,79 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
593
593
  });
594
594
  return this.request('/file/copy/withToken', options).then((0, _helpers.createMapResponseToJson)(metadata));
595
595
  }
596
+ }, {
597
+ key: "copyFile",
598
+ value: function copyFile(id, params, traceContext) {
599
+ var metadata = {
600
+ method: 'POST',
601
+ endpoint: '/v2/file/copy'
602
+ };
603
+ var options = _objectSpread(_objectSpread({}, metadata), {}, {
604
+ authContext: {
605
+ collectionName: params.collection
606
+ },
607
+ params: params,
608
+ headers: jsonHeaders,
609
+ body: JSON.stringify({
610
+ id: id
611
+ }),
612
+ traceContext: traceContext,
613
+ clientOptions: {
614
+ retryOptions: {
615
+ shouldRetryError: function shouldRetryError(err) {
616
+ var _err$metadata;
617
+ return (0, _helpers.defaultShouldRetryError)(err) || (0, _request3.isRequestError)(err) && (err === null || err === void 0 || (_err$metadata = err.metadata) === null || _err$metadata === void 0 ? void 0 : _err$metadata.statusCode) === 401;
618
+ }
619
+ }
620
+ }
621
+ });
622
+ return this.request('/v2/file/copy', options).then((0, _helpers.createMapResponseToJson)(metadata));
623
+ }
624
+ }, {
625
+ key: "registerCopyIntents",
626
+ value: function () {
627
+ var _registerCopyIntents = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(ids, collectionName, traceContext) {
628
+ var files, metadata, options;
629
+ return _regenerator.default.wrap(function _callee12$(_context12) {
630
+ while (1) switch (_context12.prev = _context12.next) {
631
+ case 0:
632
+ files = ids.map(function (id) {
633
+ return {
634
+ id: id,
635
+ collection: collectionName
636
+ };
637
+ });
638
+ metadata = {
639
+ method: 'POST',
640
+ endpoint: '/file/copy/intents'
641
+ };
642
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
643
+ authContext: {
644
+ collectionName: collectionName
645
+ },
646
+ headers: jsonHeaders,
647
+ body: JSON.stringify({
648
+ files: files
649
+ }),
650
+ traceContext: traceContext
651
+ });
652
+ _context12.next = 5;
653
+ return this.request('/file/copy/intents', options);
654
+ case 5:
655
+ case "end":
656
+ return _context12.stop();
657
+ }
658
+ }, _callee12, this);
659
+ }));
660
+ function registerCopyIntents(_x38, _x39, _x40) {
661
+ return _registerCopyIntents.apply(this, arguments);
662
+ }
663
+ return registerCopyIntents;
664
+ }()
596
665
  }, {
597
666
  key: "request",
598
667
  value: function () {
599
- var _request2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(path) {
668
+ var _request2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(path) {
600
669
  var options,
601
670
  controller,
602
671
  useMediaCdn,
@@ -615,22 +684,22 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
615
684
  extendedParams,
616
685
  url,
617
686
  response,
618
- _args12 = arguments;
619
- return _regenerator.default.wrap(function _callee12$(_context12) {
620
- while (1) switch (_context12.prev = _context12.next) {
687
+ _args13 = arguments;
688
+ return _regenerator.default.wrap(function _callee13$(_context13) {
689
+ while (1) switch (_context13.prev = _context13.next) {
621
690
  case 0:
622
- options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {
691
+ options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {
623
692
  method: 'GET',
624
693
  endpoint: undefined,
625
694
  authContext: {}
626
695
  };
627
- controller = _args12.length > 2 ? _args12[2] : undefined;
628
- useMediaCdn = _args12.length > 3 ? _args12[3] : undefined;
696
+ controller = _args13.length > 2 ? _args13[2] : undefined;
697
+ useMediaCdn = _args13.length > 3 ? _args13[3] : undefined;
629
698
  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;
630
- _context12.next = 6;
699
+ _context13.next = 6;
631
700
  return this.resolveAuth(authContext);
632
701
  case 6:
633
- auth = _context12.sent;
702
+ auth = _context13.sent;
634
703
  clientId = (0, _mediaCore.isClientBasedAuth)(auth) ? auth.clientId : undefined;
635
704
  extendedTraceContext = (0, _helpers.extendTraceContext)(traceContext);
636
705
  extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
@@ -640,7 +709,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
640
709
  if (useMediaCdn) {
641
710
  url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
642
711
  }
643
- _context12.next = 14;
712
+ _context13.next = 14;
644
713
  return (0, _request3.request)(url, {
645
714
  method: method,
646
715
  endpoint: endpoint,
@@ -652,17 +721,17 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
652
721
  traceContext: extendedTraceContext
653
722
  }, controller);
654
723
  case 14:
655
- response = _context12.sent;
724
+ response = _context13.sent;
656
725
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
657
726
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
658
- return _context12.abrupt("return", response);
727
+ return _context13.abrupt("return", response);
659
728
  case 18:
660
729
  case "end":
661
- return _context12.stop();
730
+ return _context13.stop();
662
731
  }
663
- }, _callee12, this);
732
+ }, _callee13, this);
664
733
  }));
665
- function request(_x38) {
734
+ function request(_x41) {
666
735
  return _request2.apply(this, arguments);
667
736
  }
668
737
  return request;
@@ -670,16 +739,16 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
670
739
  }, {
671
740
  key: "testUrl",
672
741
  value: function () {
673
- var _testUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(url) {
742
+ var _testUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(url) {
674
743
  var options,
675
744
  traceContext,
676
- _args13 = arguments;
677
- return _regenerator.default.wrap(function _callee13$(_context13) {
678
- while (1) switch (_context13.prev = _context13.next) {
745
+ _args14 = arguments;
746
+ return _regenerator.default.wrap(function _callee14$(_context14) {
747
+ while (1) switch (_context14.prev = _context14.next) {
679
748
  case 0:
680
- options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
749
+ options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
681
750
  traceContext = options.traceContext;
682
- _context13.next = 4;
751
+ _context14.next = 4;
683
752
  return (0, _request3.request)(url, {
684
753
  method: 'HEAD',
685
754
  traceContext: (0, _helpers.extendTraceContext)(traceContext),
@@ -691,11 +760,11 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
691
760
  });
692
761
  case 4:
693
762
  case "end":
694
- return _context13.stop();
763
+ return _context14.stop();
695
764
  }
696
- }, _callee13);
765
+ }, _callee14);
697
766
  }));
698
- function testUrl(_x39) {
767
+ function testUrl(_x42) {
699
768
  return _testUrl.apply(this, arguments);
700
769
  }
701
770
  return testUrl;
@@ -706,7 +775,6 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
706
775
  return this._chunkHashAlgorithm;
707
776
  }
708
777
  }]);
709
- return MediaStore;
710
778
  }();
711
779
  var getValueFromSessionStorage = function getValueFromSessionStorage(key) {
712
780
  return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
@@ -8,24 +8,23 @@ exports.MediaStoreError = void 0;
8
8
  exports.isMediaStoreError = isMediaStoreError;
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
11
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
14
  var _errors = require("../../models/errors");
15
- 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); }; }
15
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
16
16
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
17
  var MediaStoreError = exports.MediaStoreError = /*#__PURE__*/function (_BaseMediaClientError) {
18
- (0, _inherits2.default)(MediaStoreError, _BaseMediaClientError);
19
- var _super = _createSuper(MediaStoreError);
20
18
  function MediaStoreError(reason, innerError) {
21
19
  var _this;
22
20
  (0, _classCallCheck2.default)(this, MediaStoreError);
23
- _this = _super.call(this, reason);
21
+ _this = _callSuper(this, MediaStoreError, [reason]);
24
22
  _this.reason = reason;
25
23
  _this.innerError = innerError;
26
24
  return _this;
27
25
  }
28
- (0, _createClass2.default)(MediaStoreError, [{
26
+ (0, _inherits2.default)(MediaStoreError, _BaseMediaClientError);
27
+ return (0, _createClass2.default)(MediaStoreError, [{
29
28
  key: "attributes",
30
29
  get: function get() {
31
30
  var reason = this.reason,
@@ -36,7 +35,6 @@ var MediaStoreError = exports.MediaStoreError = /*#__PURE__*/function (_BaseMedi
36
35
  };
37
36
  }
38
37
  }]);
39
- return MediaStoreError;
40
38
  }(_errors.BaseMediaClientError);
41
39
  function isMediaStoreError(err) {
42
40
  return err instanceof MediaStoreError;
@@ -43,7 +43,7 @@ var MobileUploadImpl = exports.MobileUploadImpl = /*#__PURE__*/function () {
43
43
  this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaApi);
44
44
  this.servicesCache = (0, _mobileUpload.createServicesCache)();
45
45
  }
46
- (0, _createClass2.default)(MobileUploadImpl, [{
46
+ return (0, _createClass2.default)(MobileUploadImpl, [{
47
47
  key: "notifyUploadStart",
48
48
  value: function notifyUploadStart(event) {
49
49
  var _this2 = this;
@@ -116,5 +116,4 @@ var MobileUploadImpl = exports.MobileUploadImpl = /*#__PURE__*/function () {
116
116
  }
117
117
  }
118
118
  }]);
119
- return MobileUploadImpl;
120
119
  }();
@@ -14,7 +14,7 @@ var StargateClient = exports.StargateClient = /*#__PURE__*/function () {
14
14
  (0, _classCallCheck2.default)(this, StargateClient);
15
15
  this.baseUrl = baseUrl || '/gateway/api';
16
16
  }
17
- (0, _createClass2.default)(StargateClient, [{
17
+ return (0, _createClass2.default)(StargateClient, [{
18
18
  key: "fetchToken",
19
19
  value: function () {
20
20
  var _fetchToken = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(clientId) {
@@ -48,5 +48,4 @@ var StargateClient = exports.StargateClient = /*#__PURE__*/function () {
48
48
  return token.data.iat + token.data.expiresIn - currentTimeInSeconds < 0;
49
49
  }
50
50
  }]);
51
- return StargateClient;
52
51
  }();