@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
@@ -1,23 +1,22 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var MediaStoreError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- _inherits(MediaStoreError, _BaseMediaClientError);
11
- var _super = _createSuper(MediaStoreError);
12
10
  function MediaStoreError(reason, innerError) {
13
11
  var _this;
14
12
  _classCallCheck(this, MediaStoreError);
15
- _this = _super.call(this, reason);
13
+ _this = _callSuper(this, MediaStoreError, [reason]);
16
14
  _this.reason = reason;
17
15
  _this.innerError = innerError;
18
16
  return _this;
19
17
  }
20
- _createClass(MediaStoreError, [{
18
+ _inherits(MediaStoreError, _BaseMediaClientError);
19
+ return _createClass(MediaStoreError, [{
21
20
  key: "attributes",
22
21
  get: function get() {
23
22
  var reason = this.reason,
@@ -28,7 +27,6 @@ export var MediaStoreError = /*#__PURE__*/function (_BaseMediaClientError) {
28
27
  };
29
28
  }
30
29
  }]);
31
- return MediaStoreError;
32
30
  }(BaseMediaClientError);
33
31
  export function isMediaStoreError(err) {
34
32
  return err instanceof MediaStoreError;
@@ -36,7 +36,7 @@ export var MobileUploadImpl = /*#__PURE__*/function () {
36
36
  this.dataloader = createFileDataloader(mediaApi);
37
37
  this.servicesCache = createServicesCache();
38
38
  }
39
- _createClass(MobileUploadImpl, [{
39
+ return _createClass(MobileUploadImpl, [{
40
40
  key: "notifyUploadStart",
41
41
  value: function notifyUploadStart(event) {
42
42
  var _this2 = this;
@@ -109,5 +109,4 @@ export var MobileUploadImpl = /*#__PURE__*/function () {
109
109
  }
110
110
  }
111
111
  }]);
112
- return MobileUploadImpl;
113
112
  }();
@@ -7,7 +7,7 @@ export var StargateClient = /*#__PURE__*/function () {
7
7
  _classCallCheck(this, StargateClient);
8
8
  this.baseUrl = baseUrl || '/gateway/api';
9
9
  }
10
- _createClass(StargateClient, [{
10
+ return _createClass(StargateClient, [{
11
11
  key: "fetchToken",
12
12
  value: function () {
13
13
  var _fetchToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(clientId) {
@@ -41,5 +41,4 @@ export var StargateClient = /*#__PURE__*/function () {
41
41
  return token.data.iat + token.data.expiresIn - currentTimeInSeconds < 0;
42
42
  }
43
43
  }]);
44
- return StargateClient;
45
44
  }();
@@ -5,7 +5,7 @@ export var StreamsCache = /*#__PURE__*/function () {
5
5
  _classCallCheck(this, StreamsCache);
6
6
  this.streams = streams;
7
7
  }
8
- _createClass(StreamsCache, [{
8
+ return _createClass(StreamsCache, [{
9
9
  key: "has",
10
10
  value: function has(id) {
11
11
  return !!this.streams.find(id);
@@ -44,7 +44,6 @@ export var StreamsCache = /*#__PURE__*/function () {
44
44
  return this.streams.size;
45
45
  }
46
46
  }]);
47
- return StreamsCache;
48
47
  }();
49
48
  var streamCache;
50
49
  export var getFileStreamsCache = function getFileStreamsCache() {
@@ -1,11 +1,10 @@
1
1
  import _createClass from "@babel/runtime/helpers/createClass";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
7
6
  import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
8
- 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
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
9
8
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10
9
  export { isMediaClientError, getMediaClientErrorReason } from './helpers';
11
10
 
@@ -13,22 +12,21 @@ export { isMediaClientError, getMediaClientErrorReason } from './helpers';
13
12
  * Base class for media errors
14
13
  */
15
14
  export var BaseMediaClientError = /*#__PURE__*/function (_Error) {
16
- _inherits(BaseMediaClientError, _Error);
17
- var _super = _createSuper(BaseMediaClientError);
18
15
  function BaseMediaClientError(message) {
19
16
  var _this;
20
17
  _classCallCheck(this, BaseMediaClientError);
21
- _this = _super.call(this, message);
18
+ _this = _callSuper(this, BaseMediaClientError, [message]);
22
19
 
23
20
  // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
24
21
  _this.message = message;
25
- Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof BaseMediaClientError ? this.constructor : void 0).prototype);
22
+ Object.setPrototypeOf(_this, (this instanceof BaseMediaClientError ? this.constructor : void 0).prototype);
26
23
 
27
24
  // https://v8.dev/docs/stack-trace-api
28
25
  if ('captureStackTrace' in Error) {
29
- Error.captureStackTrace(_assertThisInitialized(_this), this instanceof BaseMediaClientError ? this.constructor : void 0);
26
+ Error.captureStackTrace(_this, this instanceof BaseMediaClientError ? this.constructor : void 0);
30
27
  }
31
28
  return _this;
32
29
  }
30
+ _inherits(BaseMediaClientError, _Error);
33
31
  return _createClass(BaseMediaClientError);
34
32
  }( /*#__PURE__*/_wrapNativeSuper(Error));
@@ -4,7 +4,7 @@ export var UploadController = /*#__PURE__*/function () {
4
4
  function UploadController() {
5
5
  _classCallCheck(this, UploadController);
6
6
  }
7
- _createClass(UploadController, [{
7
+ return _createClass(UploadController, [{
8
8
  key: "setAbort",
9
9
  value: function setAbort(abortFunction) {
10
10
  this.abortFunction = abortFunction;
@@ -17,5 +17,4 @@ export var UploadController = /*#__PURE__*/function () {
17
17
  }
18
18
  }
19
19
  }]);
20
- return UploadController;
21
20
  }();
@@ -1,24 +1,23 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../models/errors';
9
9
  export var UploaderError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- _inherits(UploaderError, _BaseMediaClientError);
11
- var _super = _createSuper(UploaderError);
12
10
  function UploaderError(reason, id, metadata) {
13
11
  var _this;
14
12
  _classCallCheck(this, UploaderError);
15
- _this = _super.call(this, reason);
13
+ _this = _callSuper(this, UploaderError, [reason]);
16
14
  _this.reason = reason;
17
15
  _this.id = id;
18
16
  _this.metadata = metadata;
19
17
  return _this;
20
18
  }
21
- _createClass(UploaderError, [{
19
+ _inherits(UploaderError, _BaseMediaClientError);
20
+ return _createClass(UploaderError, [{
22
21
  key: "attributes",
23
22
  get: function get() {
24
23
  var reason = this.reason,
@@ -35,7 +34,6 @@ export var UploaderError = /*#__PURE__*/function (_BaseMediaClientError) {
35
34
  };
36
35
  }
37
36
  }]);
38
- return UploaderError;
39
37
  }(BaseMediaClientError);
40
38
  export function isUploaderError(err) {
41
39
  return err instanceof UploaderError;
@@ -0,0 +1,115 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import Dataloader from 'dataloader';
4
+ import { getRandomHex } from '@atlaskit/media-common';
5
+ export var MAX_BATCH_SIZE = 100;
6
+ /**
7
+ * Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
8
+ * Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
9
+ *
10
+ * If an Error is resolved in the results, it must be at same position then their corresponding key:
11
+ * - Dataloader will re-throw that Error when accessing/loading that particular key
12
+ *
13
+ * @param mediaStore instance of MediaStore
14
+ */
15
+ function createBatchCopyIntentRegisterationFunc(mediaStore) {
16
+ return /*#__PURE__*/function () {
17
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(keys) {
18
+ var keysByToken, items;
19
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
20
+ while (1) switch (_context2.prev = _context2.next) {
21
+ case 0:
22
+ keysByToken = keys.reduce(function (acc, key) {
23
+ var token = key.resolvedAuth.token;
24
+ acc[token] = acc[token] || [];
25
+
26
+ // de-duplicate ids in collection
27
+ var hasDuplicates = acc[token].some(function (_ref2) {
28
+ var id = _ref2.id,
29
+ collectionName = _ref2.collectionName;
30
+ return key.id === id && collectionName === key.collectionName;
31
+ });
32
+ if (!hasDuplicates) {
33
+ acc[token].push(key);
34
+ }
35
+ return acc;
36
+ }, {});
37
+ items = [];
38
+ _context2.next = 4;
39
+ return Promise.all(Object.keys(keysByToken).map( /*#__PURE__*/function () {
40
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(batchKey) {
41
+ var metadataTraceContext, files, resolvedAuth;
42
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ metadataTraceContext = {
46
+ traceId: getRandomHex(8),
47
+ spanId: getRandomHex(8)
48
+ };
49
+ files = keysByToken[batchKey].map(function (key) {
50
+ return {
51
+ id: key.id,
52
+ collection: key.collectionName
53
+ };
54
+ }); // given these are batched by the token the assumption is that they have the same details.
55
+ resolvedAuth = keysByToken[batchKey][0].resolvedAuth;
56
+ _context.prev = 3;
57
+ _context.next = 6;
58
+ return mediaStore.registerCopyIntents(files, metadataTraceContext, resolvedAuth);
59
+ case 6:
60
+ _context.next = 11;
61
+ break;
62
+ case 8:
63
+ _context.prev = 8;
64
+ _context.t0 = _context["catch"](3);
65
+ files.forEach(function (_ref4) {
66
+ var id = _ref4.id,
67
+ collection = _ref4.collection;
68
+ items.push({
69
+ id: id,
70
+ collection: collection,
71
+ error: _context.t0
72
+ });
73
+ });
74
+ case 11:
75
+ case "end":
76
+ return _context.stop();
77
+ }
78
+ }, _callee, null, [[3, 8]]);
79
+ }));
80
+ return function (_x2) {
81
+ return _ref3.apply(this, arguments);
82
+ };
83
+ }()));
84
+ case 4:
85
+ return _context2.abrupt("return", keys.map(function (_ref5) {
86
+ var _items$find;
87
+ var id = _ref5.id,
88
+ collectionName = _ref5.collectionName;
89
+ return (_items$find = items.find(function (item) {
90
+ return item.id === id && item.collection === collectionName;
91
+ })) === null || _items$find === void 0 ? void 0 : _items$find.error;
92
+ }));
93
+ case 5:
94
+ case "end":
95
+ return _context2.stop();
96
+ }
97
+ }, _callee2);
98
+ }));
99
+ return function (_x) {
100
+ return _ref.apply(this, arguments);
101
+ };
102
+ }();
103
+ }
104
+ export function createCopyIntentRegisterationBatcher(mediaStore) {
105
+ return new Dataloader(createBatchCopyIntentRegisterationFunc(mediaStore), {
106
+ maxBatchSize: MAX_BATCH_SIZE,
107
+ cacheKeyFn: function cacheKeyFn(_ref6) {
108
+ var id = _ref6.id,
109
+ _ref6$collectionName = _ref6.collectionName,
110
+ collectionName = _ref6$collectionName === void 0 ? 'default' : _ref6$collectionName,
111
+ resolvedAuth = _ref6.resolvedAuth;
112
+ return "".concat(id, "-").concat(collectionName, "-").concat(resolvedAuth.token);
113
+ }
114
+ });
115
+ }
@@ -5,7 +5,7 @@ export var SimpleHasher = /*#__PURE__*/function () {
5
5
  function SimpleHasher() {
6
6
  _classCallCheck(this, SimpleHasher);
7
7
  }
8
- _createClass(SimpleHasher, [{
8
+ return _createClass(SimpleHasher, [{
9
9
  key: "hash",
10
10
  value: function hash(blob) {
11
11
  return new Promise(function (resolve, reject) {
@@ -19,5 +19,4 @@ export var SimpleHasher = /*#__PURE__*/function () {
19
19
  });
20
20
  }
21
21
  }]);
22
- return SimpleHasher;
23
22
  }();
@@ -5,7 +5,7 @@ export var SimpleHasher = /*#__PURE__*/function () {
5
5
  function SimpleHasher() {
6
6
  _classCallCheck(this, SimpleHasher);
7
7
  }
8
- _createClass(SimpleHasher, [{
8
+ return _createClass(SimpleHasher, [{
9
9
  key: "hash",
10
10
  value: function hash(blob) {
11
11
  return new Promise(function (resolve, reject) {
@@ -19,5 +19,4 @@ export var SimpleHasher = /*#__PURE__*/function () {
19
19
  });
20
20
  }
21
21
  }]);
22
- return SimpleHasher;
23
22
  }();
@@ -12,7 +12,7 @@ export var WorkerHasher = /*#__PURE__*/function () {
12
12
  this.workers.push(this.createWorker());
13
13
  }
14
14
  }
15
- _createClass(WorkerHasher, [{
15
+ return _createClass(WorkerHasher, [{
16
16
  key: "hash",
17
17
  value: function hash(chunk) {
18
18
  return this.calculateHashInWorker(chunk);
@@ -103,5 +103,4 @@ export var WorkerHasher = /*#__PURE__*/function () {
103
103
  }, this.workers[0]);
104
104
  }
105
105
  }]);
106
- return WorkerHasher;
107
106
  }();
@@ -1,24 +1,23 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- _inherits(MobileUploadError, _BaseMediaClientError);
11
- var _super = _createSuper(MobileUploadError);
12
10
  function MobileUploadError(reason, id, metadata) {
13
11
  var _this;
14
12
  _classCallCheck(this, MobileUploadError);
15
- _this = _super.call(this, reason);
13
+ _this = _callSuper(this, MobileUploadError, [reason]);
16
14
  _this.reason = reason;
17
15
  _this.id = id;
18
16
  _this.metadata = metadata;
19
17
  return _this;
20
18
  }
21
- _createClass(MobileUploadError, [{
19
+ _inherits(MobileUploadError, _BaseMediaClientError);
20
+ return _createClass(MobileUploadError, [{
22
21
  key: "attributes",
23
22
  get: function get() {
24
23
  var reason = this.reason,
@@ -39,7 +38,6 @@ export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
39
38
  };
40
39
  }
41
40
  }]);
42
- return MobileUploadError;
43
41
  }(BaseMediaClientError);
44
42
  export function isMobileUploadError(err) {
45
43
  return err instanceof MobileUploadError;
@@ -1,23 +1,22 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var PollingError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- _inherits(PollingError, _BaseMediaClientError);
11
- var _super = _createSuper(PollingError);
12
10
  function PollingError(reason, attempts) {
13
11
  var _this;
14
12
  _classCallCheck(this, PollingError);
15
- _this = _super.call(this, reason);
13
+ _this = _callSuper(this, PollingError, [reason]);
16
14
  _this.reason = reason;
17
15
  _this.attempts = attempts;
18
16
  return _this;
19
17
  }
20
- _createClass(PollingError, [{
18
+ _inherits(PollingError, _BaseMediaClientError);
19
+ return _createClass(PollingError, [{
21
20
  key: "attributes",
22
21
  get: function get() {
23
22
  var reason = this.reason,
@@ -28,7 +27,6 @@ export var PollingError = /*#__PURE__*/function (_BaseMediaClientError) {
28
27
  };
29
28
  }
30
29
  }]);
31
- return PollingError;
32
30
  }(BaseMediaClientError);
33
31
  export function isPollingError(err) {
34
32
  return err instanceof PollingError;
@@ -36,7 +36,7 @@ export var PollingFunction = /*#__PURE__*/function () {
36
36
  this.options = _objectSpread(_objectSpread({}, defaultPollingOptions), options);
37
37
  this.poll_intervalMs = this.options.poll_intervalMs;
38
38
  }
39
- _createClass(PollingFunction, [{
39
+ return _createClass(PollingFunction, [{
40
40
  key: "execute",
41
41
  value: function () {
42
42
  var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(executor) {
@@ -123,5 +123,4 @@ export var PollingFunction = /*#__PURE__*/function () {
123
123
  this.timeoutId = 0;
124
124
  }
125
125
  }]);
126
- return PollingFunction;
127
126
  }();
@@ -1,24 +1,23 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { BaseMediaClientError } from '../../models/errors';
9
9
  export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
10
- _inherits(RequestError, _BaseMediaClientError);
11
- var _super = _createSuper(RequestError);
12
10
  function RequestError(reason, metadata, innerError) {
13
11
  var _this;
14
12
  _classCallCheck(this, RequestError);
15
- _this = _super.call(this, reason);
13
+ _this = _callSuper(this, RequestError, [reason]);
16
14
  _this.reason = reason;
17
15
  _this.metadata = metadata;
18
16
  _this.innerError = innerError;
19
17
  return _this;
20
18
  }
21
- _createClass(RequestError, [{
19
+ _inherits(RequestError, _BaseMediaClientError);
20
+ return _createClass(RequestError, [{
22
21
  key: "attributes",
23
22
  get: function get() {
24
23
  var reason = this.reason,
@@ -49,7 +48,6 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
49
48
  };
50
49
  }
51
50
  }]);
52
- return RequestError;
53
51
  }(BaseMediaClientError);
54
52
  export function isRequestError(err) {
55
53
  return err instanceof RequestError;
@@ -38,8 +38,7 @@ export var ZipkinHeaderKeys = {
38
38
  flags: 'x-b3-flags'
39
39
  };
40
40
  var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
41
- var _ref;
42
- return traceContext ? (_ref = {}, _defineProperty(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), _defineProperty(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
41
+ return traceContext ? _defineProperty(_defineProperty({}, ZipkinHeaderKeys.traceId, traceContext.traceId), ZipkinHeaderKeys.spanId, traceContext.spanId) : {};
43
42
  };
44
43
  export function mapAuthToRequestHeaders(auth) {
45
44
  if (!auth) {
@@ -136,6 +135,10 @@ export function createMapResponseToBlob(metadata) {
136
135
  };
137
136
  }();
138
137
  }
138
+ export var defaultShouldRetryError = function defaultShouldRetryError(err) {
139
+ var _err$metadata;
140
+ 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;
141
+ };
139
142
  export var DEFAULT_RETRY_OPTIONS = {
140
143
  startTimeoutInMs: 1000,
141
144
  // 1 second is generally a good timeout to start
@@ -159,6 +162,8 @@ function _fetchRetry() {
159
162
  startTimeoutInMs,
160
163
  maxAttempts,
161
164
  factor,
165
+ _options$shouldRetryE,
166
+ shouldRetryError,
162
167
  attempts,
163
168
  timeoutInMs,
164
169
  lastError,
@@ -169,7 +174,7 @@ function _fetchRetry() {
169
174
  case 0:
170
175
  overwriteOptions = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
171
176
  options = _objectSpread(_objectSpread({}, DEFAULT_RETRY_OPTIONS), overwriteOptions);
172
- startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor;
177
+ startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor, _options$shouldRetryE = options.shouldRetryError, shouldRetryError = _options$shouldRetryE === void 0 ? defaultShouldRetryError : _options$shouldRetryE;
173
178
  attempts = 0;
174
179
  timeoutInMs = startTimeoutInMs;
175
180
  waitAndBumpTimeout = /*#__PURE__*/function () {
@@ -214,7 +219,7 @@ function _fetchRetry() {
214
219
  }
215
220
  throw new RequestError('clientAbortedRequest', metadata, _context4.t0);
216
221
  case 18:
217
- if (!(!isFetchNetworkError(_context4.t0) && !isRequestError(_context4.t0) || isRequestError(_context4.t0) && (!_context4.t0.metadata || !_context4.t0.metadata.statusCode || _context4.t0.metadata.statusCode < 500))) {
222
+ if (shouldRetryError(_context4.t0)) {
218
223
  _context4.next = 20;
219
224
  break;
220
225
  }
@@ -14,10 +14,10 @@ export { isFileFetcherError, FileFetcherError } from './error';
14
14
  export interface CopySourceFile {
15
15
  id: string;
16
16
  collection?: string;
17
- authProvider: AuthProvider;
17
+ authProvider?: AuthProvider;
18
18
  }
19
19
  export interface CopyDestination extends MediaStoreCopyFileWithTokenParams {
20
- authProvider: AuthProvider;
20
+ authProvider?: AuthProvider;
21
21
  mediaStore?: MediaApi;
22
22
  }
23
23
  export interface CopyFileOptions {
@@ -39,11 +39,13 @@ export interface FileFetcher {
39
39
  getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
40
40
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
41
41
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
42
+ registerCopyIntent(id: string, collectionName?: string): Promise<void>;
42
43
  }
43
44
  export declare class FileFetcherImpl implements FileFetcher {
44
45
  private readonly mediaApi;
45
46
  private readonly store;
46
47
  private readonly dataloader;
48
+ private readonly copyIntentRegisterationBatcher;
47
49
  constructor(mediaApi: MediaApi, store?: MediaStore);
48
50
  private getErrorFileState;
49
51
  private setFileState;
@@ -58,5 +60,8 @@ export declare class FileFetcherImpl implements FileFetcher {
58
60
  private getUploadingFileStateBase;
59
61
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
60
62
  downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
63
+ registerCopyIntent(id: string, collectionName?: string): Promise<void>;
64
+ private copyFileWithToken;
65
+ private copyFileWithIntent;
61
66
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
62
67
  }
@@ -29,7 +29,10 @@ export declare class MediaStore implements MediaApi {
29
29
  appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
30
30
  copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
31
31
  copyFile(id: string, params: CopyFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
32
- registerCopyIntents(ids: string[], collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
32
+ registerCopyIntents(files: Array<{
33
+ id: string;
34
+ collection?: string;
35
+ }>, traceContext?: MediaTraceContext, resolvedAuth?: Auth): Promise<void>;
33
36
  request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
34
37
  testUrl(url: string, options?: {
35
38
  traceContext?: MediaTraceContext;
@@ -37,6 +37,7 @@ export interface MediaStoreResponse<Data> {
37
37
  export type MediaStoreRequestOptions = RequestMetadata & {
38
38
  readonly method?: RequestMethod;
39
39
  readonly authContext?: AuthContext;
40
+ readonly resolvedAuth?: Auth;
40
41
  readonly params?: RequestParams;
41
42
  readonly headers?: RequestHeaders;
42
43
  readonly body?: any;
@@ -172,7 +173,10 @@ export interface MediaApi {
172
173
  appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
173
174
  copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
174
175
  copyFile: (id: string, params: CopyFileParams) => Promise<MediaStoreResponse<MediaFile>>;
175
- registerCopyIntents: (ids: string[], collectionName: string) => Promise<void>;
176
+ registerCopyIntents: (files: Array<{
177
+ id: string;
178
+ collection: string;
179
+ }>, traceContext?: MediaTraceContext, resolvedAuth?: Auth) => Promise<void>;
176
180
  request: (path: string, options: MediaStoreRequestOptions, controller?: AbortController) => Promise<Response>;
177
181
  testUrl: (url: string, options?: {
178
182
  traceContext?: MediaTraceContext;
@@ -0,0 +1,20 @@
1
+ import Dataloader from 'dataloader';
2
+ import { type MediaStore } from '../client/media-store';
3
+ import { type NotFoundMediaItemDetails, type MediaItemDetails } from '../models/media';
4
+ import { type Auth } from '@atlaskit/media-core';
5
+ export declare const MAX_BATCH_SIZE = 100;
6
+ export type CopyIntentKey = {
7
+ readonly id: string;
8
+ readonly resolvedAuth: Auth;
9
+ readonly collectionName?: string;
10
+ };
11
+ export type DataloaderResult = MediaItemDetails | NotFoundMediaItemDetails;
12
+ export type BatchLoadingErrorResult = {
13
+ readonly id: string;
14
+ readonly collection?: string;
15
+ readonly error: Error;
16
+ };
17
+ export type FilesByToken = {
18
+ [token: string]: CopyIntentKey[];
19
+ };
20
+ export declare function createCopyIntentRegisterationBatcher(mediaStore: MediaStore): Dataloader<CopyIntentKey, Error | undefined, string>;
@@ -19,6 +19,7 @@ export declare function createUrl(url: string, { params, auth }: CreateUrlOption
19
19
  export declare function extendHeaders(headers?: RequestHeaders, auth?: Auth, traceContext?: Required<MediaTraceContext>): RequestHeaders | undefined;
20
20
  export declare function createMapResponseToJson(metadata: RequestMetadata): (response: Response) => Promise<any>;
21
21
  export declare function createMapResponseToBlob(metadata: RequestMetadata): (response: Response) => Promise<Blob>;
22
+ export declare const defaultShouldRetryError: (err: any) => boolean;
22
23
  export declare const DEFAULT_RETRY_OPTIONS: RetryOptions;
23
24
  export declare function cloneRequestError(error: RequestError, extraMetadata: Partial<RequestErrorMetadata>): RequestError;
24
25
  export declare function fetchRetry(functionToRetry: () => Promise<Response>, metadata: RequestMetadata, overwriteOptions?: Partial<RetryOptions>): Promise<Response>;
@@ -11,6 +11,7 @@ export type RetryOptions = {
11
11
  readonly startTimeoutInMs: number;
12
12
  readonly maxAttempts: number;
13
13
  readonly factor: number;
14
+ readonly shouldRetryError?: (err: any) => boolean;
14
15
  };
15
16
  export type ClientOptions = {
16
17
  readonly retryOptions?: Partial<RetryOptions>;