@atlaskit/media-client 20.2.1 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/cjs/client/file-fetcher/error.js +4 -4
  3. package/dist/cjs/client/file-fetcher/index.js +275 -287
  4. package/dist/cjs/client/media-client.js +48 -34
  5. package/dist/cjs/client/media-store/index.js +367 -314
  6. package/dist/cjs/client/media-store/resolveAuth.js +30 -32
  7. package/dist/cjs/client/stargate-client.js +14 -16
  8. package/dist/cjs/index.js +6 -13
  9. package/dist/cjs/models/media.js +8 -9
  10. package/dist/cjs/uploader/error.js +4 -4
  11. package/dist/cjs/uploader/index.js +88 -96
  12. package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
  13. package/dist/cjs/utils/createFileDataLoader.js +67 -70
  14. package/dist/cjs/utils/getDimensionsFromBlob.js +23 -25
  15. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +24 -26
  16. package/dist/cjs/utils/hashing/hasherCreator.js +32 -34
  17. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -2
  18. package/dist/cjs/utils/mobileUpload/error.js +4 -4
  19. package/dist/cjs/utils/mobileUpload/helpers.js +41 -43
  20. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +14 -16
  21. package/dist/cjs/utils/parseJwt.js +52 -0
  22. package/dist/cjs/utils/polling/index.js +40 -42
  23. package/dist/cjs/utils/request/errors.js +9 -9
  24. package/dist/cjs/utils/request/helpers.js +143 -155
  25. package/dist/cjs/utils/request/index.js +24 -26
  26. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +39 -41
  27. package/dist/cjs/version.json +1 -1
  28. package/dist/es2019/client/file-fetcher/index.js +1 -3
  29. package/dist/es2019/client/media-client.js +3 -2
  30. package/dist/es2019/client/media-store/index.js +58 -15
  31. package/dist/es2019/index.js +2 -3
  32. package/dist/es2019/models/media.js +6 -4
  33. package/dist/es2019/uploader/index.js +3 -0
  34. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -2
  35. package/dist/es2019/utils/mediaSubscribable/toPromise.js +10 -12
  36. package/dist/es2019/utils/parseJwt.js +46 -0
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/client/file-fetcher/error.js +4 -4
  39. package/dist/esm/client/file-fetcher/index.js +273 -286
  40. package/dist/esm/client/media-client.js +46 -32
  41. package/dist/esm/client/media-store/index.js +367 -314
  42. package/dist/esm/client/media-store/resolveAuth.js +30 -32
  43. package/dist/esm/client/stargate-client.js +14 -16
  44. package/dist/esm/index.js +2 -3
  45. package/dist/esm/models/media.js +6 -6
  46. package/dist/esm/uploader/error.js +4 -4
  47. package/dist/esm/uploader/index.js +89 -96
  48. package/dist/esm/utils/convertBase64ToBlob.js +2 -2
  49. package/dist/esm/utils/createFileDataLoader.js +65 -69
  50. package/dist/esm/utils/getDimensionsFromBlob.js +23 -25
  51. package/dist/esm/utils/getVideoDimensionsFromBlob.js +24 -26
  52. package/dist/esm/utils/hashing/hasherCreator.js +28 -30
  53. package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -2
  54. package/dist/esm/utils/mobileUpload/error.js +4 -4
  55. package/dist/esm/utils/mobileUpload/helpers.js +41 -43
  56. package/dist/esm/utils/mobileUpload/stateMachine/index.js +14 -16
  57. package/dist/esm/utils/parseJwt.js +46 -0
  58. package/dist/esm/utils/polling/index.js +40 -42
  59. package/dist/esm/utils/request/errors.js +9 -9
  60. package/dist/esm/utils/request/helpers.js +143 -155
  61. package/dist/esm/utils/request/index.js +24 -26
  62. package/dist/esm/utils/shouldFetchRemoteFileStates.js +39 -41
  63. package/dist/esm/version.json +1 -1
  64. package/dist/types/client/__mocks__/media-client.d.ts +0 -2
  65. package/dist/types/client/file-fetcher/index.d.ts +4 -4
  66. package/dist/types/client/media-client.d.ts +1 -2
  67. package/dist/types/client/media-store/index.d.ts +17 -13
  68. package/dist/types/index.d.ts +4 -6
  69. package/dist/types/models/file-state.d.ts +2 -2
  70. package/dist/types/models/media.d.ts +1 -21
  71. package/dist/types/utils/createFileDataLoader.d.ts +2 -2
  72. package/dist/types/utils/createMediaSubject.d.ts +2 -2
  73. package/dist/types/utils/detectEmptyFile.d.ts +2 -2
  74. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +3 -3
  75. package/dist/types/utils/mediaSubscribable/toPromise.d.ts +2 -2
  76. package/dist/types/utils/mediaSubscribable/types.d.ts +9 -8
  77. package/dist/types/utils/parseJwt.d.ts +1 -0
  78. package/package.json +2 -2
  79. package/report.api.md +77 -126
  80. package/dist/cjs/client/collection-fetcher.js +0 -98
  81. package/dist/cjs/models/media-subscribable.js +0 -5
  82. package/dist/cjs/utils/deprecatedEndpointError.js +0 -43
  83. package/dist/es2019/client/collection-fetcher.js +0 -38
  84. package/dist/es2019/models/media-subscribable.js +0 -1
  85. package/dist/es2019/utils/deprecatedEndpointError.js +0 -20
  86. package/dist/esm/client/collection-fetcher.js +0 -89
  87. package/dist/esm/models/media-subscribable.js +0 -1
  88. package/dist/esm/utils/deprecatedEndpointError.js +0 -34
  89. package/dist/types/client/collection-fetcher.d.ts +0 -42
  90. package/dist/types/models/media-subscribable.d.ts +0 -3
  91. package/dist/types/utils/deprecatedEndpointError.d.ts +0 -16
@@ -18,7 +18,10 @@ Object.defineProperty(exports, "isMediaStoreError", {
18
18
  return _error.isMediaStoreError;
19
19
  }
20
20
  });
21
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
22
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
21
23
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
24
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
22
25
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
23
26
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
24
27
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -29,8 +32,9 @@ var _artifacts = require("../../models/artifacts");
29
32
  var _request3 = require("../../utils/request");
30
33
  var _helpers = require("../../utils/request/helpers");
31
34
  var _resolveAuth = require("./resolveAuth");
32
- var _deprecatedEndpointError = require("../../utils/deprecatedEndpointError");
35
+ var _parseJwt = _interopRequireDefault(require("../../utils/parseJwt"));
33
36
  var _error = require("./error");
37
+ var _excluded = ["size"];
34
38
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
39
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
36
40
  var MEDIA_API_REGION = 'media-api-region';
@@ -64,76 +68,48 @@ var MediaStore = /*#__PURE__*/function () {
64
68
  this.config = config;
65
69
  this.featureFlags = featureFlags;
66
70
  }
67
-
68
- /**
69
- * @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-170 Internal documentation for deprecation (no external access)}
70
- * This method is no longer working. Will be removed in the next release
71
- */
72
71
  (0, _createClass2.default)(MediaStore, [{
73
- key: "getCollectionItems",
74
- value: function () {
75
- var _getCollectionItems = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(collectionName, params, traceContext) {
76
- return _regenerator.default.wrap(function _callee$(_context) {
77
- while (1) {
78
- switch (_context.prev = _context.next) {
79
- case 0:
80
- throw new _deprecatedEndpointError.DeprecatedError('collection/:name/items');
81
- case 1:
82
- case "end":
83
- return _context.stop();
84
- }
85
- }
86
- }, _callee);
87
- }));
88
- function getCollectionItems(_x, _x2, _x3) {
89
- return _getCollectionItems.apply(this, arguments);
90
- }
91
- return getCollectionItems;
92
- }()
93
- }, {
94
72
  key: "removeCollectionFile",
95
73
  value: function () {
96
- var _removeCollectionFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(id, collectionName, occurrenceKey, traceContext) {
74
+ var _removeCollectionFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(id, collectionName, occurrenceKey, traceContext) {
97
75
  var metadata, body, options;
98
- return _regenerator.default.wrap(function _callee2$(_context2) {
99
- while (1) {
100
- switch (_context2.prev = _context2.next) {
101
- case 0:
102
- metadata = {
103
- method: 'PUT',
104
- endpoint: '/collection/{collectionName}'
105
- };
106
- body = {
107
- actions: [{
108
- action: 'remove',
109
- item: {
110
- type: 'file',
111
- id: id,
112
- occurrenceKey: occurrenceKey
113
- }
114
- }]
115
- };
116
- options = _objectSpread(_objectSpread({}, metadata), {}, {
117
- authContext: {
118
- collectionName: collectionName
119
- },
120
- headers: {
121
- Accept: 'application/json',
122
- 'Content-Type': 'application/json'
123
- },
124
- body: JSON.stringify(body),
125
- traceContext: traceContext
126
- });
127
- _context2.next = 5;
128
- return this.request("/collection/".concat(collectionName), options);
129
- case 5:
130
- case "end":
131
- return _context2.stop();
132
- }
76
+ return _regenerator.default.wrap(function _callee$(_context) {
77
+ while (1) switch (_context.prev = _context.next) {
78
+ case 0:
79
+ metadata = {
80
+ method: 'PUT',
81
+ endpoint: '/collection/{collectionName}'
82
+ };
83
+ body = {
84
+ actions: [{
85
+ action: 'remove',
86
+ item: {
87
+ type: 'file',
88
+ id: id,
89
+ occurrenceKey: occurrenceKey
90
+ }
91
+ }]
92
+ };
93
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
94
+ authContext: {
95
+ collectionName: collectionName
96
+ },
97
+ headers: {
98
+ Accept: 'application/json',
99
+ 'Content-Type': 'application/json'
100
+ },
101
+ body: JSON.stringify(body),
102
+ traceContext: traceContext
103
+ });
104
+ _context.next = 5;
105
+ return this.request("/collection/".concat(collectionName), options);
106
+ case 5:
107
+ case "end":
108
+ return _context.stop();
133
109
  }
134
- }, _callee2, this);
110
+ }, _callee, this);
135
111
  }));
136
- function removeCollectionFile(_x4, _x5, _x6, _x7) {
112
+ function removeCollectionFile(_x, _x2, _x3, _x4) {
137
113
  return _removeCollectionFile.apply(this, arguments);
138
114
  }
139
115
  return removeCollectionFile;
@@ -165,37 +141,35 @@ var MediaStore = /*#__PURE__*/function () {
165
141
  }, {
166
142
  key: "uploadChunk",
167
143
  value: function () {
168
- var _uploadChunk = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(etag, blob, uploadId, partNumber, collectionName, traceContext) {
144
+ var _uploadChunk = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(etag, blob, uploadId, partNumber, collectionName, traceContext) {
169
145
  var metadata, options;
170
- return _regenerator.default.wrap(function _callee3$(_context3) {
171
- while (1) {
172
- switch (_context3.prev = _context3.next) {
173
- case 0:
174
- metadata = {
175
- method: 'PUT',
176
- endpoint: '/chunk/{etag}'
177
- };
178
- options = _objectSpread(_objectSpread({}, metadata), {}, {
179
- params: {
180
- uploadId: uploadId,
181
- partNumber: partNumber
182
- },
183
- authContext: {
184
- collectionName: collectionName
185
- },
186
- body: blob,
187
- traceContext: traceContext
188
- });
189
- _context3.next = 4;
190
- return this.request("/chunk/".concat(etag), options);
191
- case 4:
192
- case "end":
193
- return _context3.stop();
194
- }
146
+ return _regenerator.default.wrap(function _callee2$(_context2) {
147
+ while (1) switch (_context2.prev = _context2.next) {
148
+ case 0:
149
+ metadata = {
150
+ method: 'PUT',
151
+ endpoint: '/chunk/{etag}'
152
+ };
153
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
154
+ params: {
155
+ uploadId: uploadId,
156
+ partNumber: partNumber
157
+ },
158
+ authContext: {
159
+ collectionName: collectionName
160
+ },
161
+ body: blob,
162
+ traceContext: traceContext
163
+ });
164
+ _context2.next = 4;
165
+ return this.request("/chunk/".concat(etag), options);
166
+ case 4:
167
+ case "end":
168
+ return _context2.stop();
195
169
  }
196
- }, _callee3, this);
170
+ }, _callee2, this);
197
171
  }));
198
- function uploadChunk(_x8, _x9, _x10, _x11, _x12, _x13) {
172
+ function uploadChunk(_x5, _x6, _x7, _x8, _x9, _x10) {
199
173
  return _uploadChunk.apply(this, arguments);
200
174
  }
201
175
  return uploadChunk;
@@ -243,24 +217,108 @@ var MediaStore = /*#__PURE__*/function () {
243
217
  return this.request('/file/upload', options).then((0, _helpers.createMapResponseToJson)(metadata));
244
218
  }
245
219
  }, {
246
- key: "touchFiles",
247
- value: function touchFiles(body) {
248
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
249
- var traceContext = arguments.length > 2 ? arguments[2] : undefined;
250
- var metadata = {
251
- method: 'POST',
252
- endpoint: '/upload/createWithFiles'
220
+ key: "getRejectedResponseFromDescriptor",
221
+ value: function getRejectedResponseFromDescriptor(descriptor, limit) {
222
+ return {
223
+ fileId: descriptor.fileId,
224
+ error: {
225
+ code: 'ExceedMaxFileSizeLimit',
226
+ title: 'The expected file size exceeded the maximum size limit.',
227
+ href: 'https://dt-api-filestore--app.ap-southeast-2.dev.atl-paas.net/api.html#BadRequest',
228
+ limit: limit,
229
+ size: descriptor.size
230
+ }
253
231
  };
254
- var options = _objectSpread(_objectSpread({}, metadata), {}, {
255
- authContext: {
256
- collectionName: params.collection
257
- },
258
- headers: jsonHeaders,
259
- body: JSON.stringify(body),
260
- traceContext: traceContext
261
- });
262
- return this.request('/upload/createWithFiles', options).then((0, _helpers.createMapResponseToJson)(metadata));
263
232
  }
233
+ }, {
234
+ key: "touchFiles",
235
+ value: function () {
236
+ var _touchFiles = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(body) {
237
+ var _this2 = this;
238
+ var params,
239
+ traceContext,
240
+ metadata,
241
+ auth,
242
+ maxFileSize,
243
+ decoded,
244
+ _body$descriptors$red,
245
+ _body$descriptors$red2,
246
+ filteredDescriptors,
247
+ rejectedResponse,
248
+ options,
249
+ _args3 = arguments;
250
+ return _regenerator.default.wrap(function _callee3$(_context3) {
251
+ while (1) switch (_context3.prev = _context3.next) {
252
+ case 0:
253
+ params = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
254
+ traceContext = _args3.length > 2 ? _args3[2] : undefined;
255
+ metadata = {
256
+ method: 'POST',
257
+ endpoint: '/upload/createWithFiles'
258
+ };
259
+ _context3.next = 5;
260
+ return this.resolveAuth({
261
+ collectionName: params.collection
262
+ });
263
+ case 5:
264
+ auth = _context3.sent;
265
+ try {
266
+ decoded = (0, _parseJwt.default)(auth.token);
267
+ maxFileSize = decoded.fileSizeLimit;
268
+ } catch (error) {
269
+ // we're relying on the backend to throw an error when there's an invalid token
270
+ }
271
+
272
+ // TODO MEX-2318: backend eventually will allow `size` in the body of this request, then some of this logic will need to be altered
273
+ _body$descriptors$red = body.descriptors.reduce(function (_ref, curr) {
274
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
275
+ filtered = _ref2[0],
276
+ rejected = _ref2[1];
277
+ var size = curr.size,
278
+ descriptor = (0, _objectWithoutProperties2.default)(curr, _excluded);
279
+ if (maxFileSize && size && size > maxFileSize) {
280
+ return [filtered, [].concat((0, _toConsumableArray2.default)(rejected), [_this2.getRejectedResponseFromDescriptor(curr, maxFileSize)])];
281
+ }
282
+ return [[].concat((0, _toConsumableArray2.default)(filtered), [descriptor]), rejected];
283
+ }, [[], []]), _body$descriptors$red2 = (0, _slicedToArray2.default)(_body$descriptors$red, 2), filteredDescriptors = _body$descriptors$red2[0], rejectedResponse = _body$descriptors$red2[1];
284
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
285
+ authContext: {
286
+ collectionName: params.collection
287
+ },
288
+ headers: jsonHeaders,
289
+ body: JSON.stringify(_objectSpread(_objectSpread({}, body), {}, {
290
+ descriptors: filteredDescriptors
291
+ })),
292
+ traceContext: traceContext,
293
+ resolvedAuth: auth
294
+ });
295
+ if (!(filteredDescriptors.length === 0)) {
296
+ _context3.next = 11;
297
+ break;
298
+ }
299
+ return _context3.abrupt("return", {
300
+ data: {
301
+ created: [],
302
+ rejected: rejectedResponse
303
+ }
304
+ });
305
+ case 11:
306
+ return _context3.abrupt("return", this.request('/upload/createWithFiles', options).then((0, _helpers.createMapResponseToJson)(metadata)).then(function (res) {
307
+ // TODO MEX-2318: backend eventually will include `rejected`, then this logic will need to be removed
308
+ res.data.rejected = rejectedResponse;
309
+ return res;
310
+ }));
311
+ case 12:
312
+ case "end":
313
+ return _context3.stop();
314
+ }
315
+ }, _callee3, this);
316
+ }));
317
+ function touchFiles(_x11) {
318
+ return _touchFiles.apply(this, arguments);
319
+ }
320
+ return touchFiles;
321
+ }()
264
322
  }, {
265
323
  key: "getFile",
266
324
  value: function getFile(fileId) {
@@ -283,27 +341,25 @@ var MediaStore = /*#__PURE__*/function () {
283
341
  key: "getFileImageURL",
284
342
  value: function () {
285
343
  var _getFileImageURL = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(id, params) {
286
- var _ref, collectionName, auth;
344
+ var _ref3, collectionName, auth;
287
345
  return _regenerator.default.wrap(function _callee4$(_context4) {
288
- while (1) {
289
- switch (_context4.prev = _context4.next) {
290
- case 0:
291
- _ref = params || {}, collectionName = _ref.collection;
292
- _context4.next = 3;
293
- return this.resolveAuth({
294
- collectionName: collectionName
295
- });
296
- case 3:
297
- auth = _context4.sent;
298
- return _context4.abrupt("return", this.createFileImageURL(id, auth, params));
299
- case 5:
300
- case "end":
301
- return _context4.stop();
302
- }
346
+ while (1) switch (_context4.prev = _context4.next) {
347
+ case 0:
348
+ _ref3 = params || {}, collectionName = _ref3.collection;
349
+ _context4.next = 3;
350
+ return this.resolveAuth({
351
+ collectionName: collectionName
352
+ });
353
+ case 3:
354
+ auth = _context4.sent;
355
+ return _context4.abrupt("return", this.createFileImageURL(id, auth, params));
356
+ case 5:
357
+ case "end":
358
+ return _context4.stop();
303
359
  }
304
360
  }, _callee4, this);
305
361
  }));
306
- function getFileImageURL(_x14, _x15) {
362
+ function getFileImageURL(_x12, _x13) {
307
363
  return _getFileImageURL.apply(this, arguments);
308
364
  }
309
365
  return getFileImageURL;
@@ -329,32 +385,30 @@ var MediaStore = /*#__PURE__*/function () {
329
385
  var _getFileBinaryURL = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id, collectionName) {
330
386
  var auth, options;
331
387
  return _regenerator.default.wrap(function _callee5$(_context5) {
332
- while (1) {
333
- switch (_context5.prev = _context5.next) {
334
- case 0:
335
- _context5.next = 2;
336
- return this.resolveAuth({
337
- collectionName: collectionName
338
- });
339
- case 2:
340
- auth = _context5.sent;
341
- options = {
342
- params: {
343
- dl: true,
344
- collection: collectionName,
345
- 'max-age': _constants.FILE_CACHE_MAX_AGE
346
- },
347
- auth: auth
348
- };
349
- return _context5.abrupt("return", (0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/binary"), options));
350
- case 5:
351
- case "end":
352
- return _context5.stop();
353
- }
388
+ while (1) switch (_context5.prev = _context5.next) {
389
+ case 0:
390
+ _context5.next = 2;
391
+ return this.resolveAuth({
392
+ collectionName: collectionName
393
+ });
394
+ case 2:
395
+ auth = _context5.sent;
396
+ options = {
397
+ params: {
398
+ dl: true,
399
+ collection: collectionName,
400
+ 'max-age': _constants.FILE_CACHE_MAX_AGE
401
+ },
402
+ auth: auth
403
+ };
404
+ return _context5.abrupt("return", (0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/binary"), options));
405
+ case 5:
406
+ case "end":
407
+ return _context5.stop();
354
408
  }
355
409
  }, _callee5, this);
356
410
  }));
357
- function getFileBinaryURL(_x16, _x17) {
411
+ function getFileBinaryURL(_x14, _x15) {
358
412
  return _getFileBinaryURL.apply(this, arguments);
359
413
  }
360
414
  return getFileBinaryURL;
@@ -365,38 +419,36 @@ var MediaStore = /*#__PURE__*/function () {
365
419
  var _getArtifactURL = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(artifacts, artifactName, collectionName) {
366
420
  var artifactUrl, auth, options;
367
421
  return _regenerator.default.wrap(function _callee6$(_context6) {
368
- while (1) {
369
- switch (_context6.prev = _context6.next) {
370
- case 0:
371
- artifactUrl = (0, _artifacts.getArtifactUrl)(artifacts, artifactName);
372
- if (artifactUrl) {
373
- _context6.next = 3;
374
- break;
375
- }
376
- throw new Error("artifact ".concat(artifactName, " not found"));
377
- case 3:
378
- _context6.next = 5;
379
- return this.resolveAuth({
380
- collectionName: collectionName
381
- });
382
- case 5:
383
- auth = _context6.sent;
384
- options = {
385
- params: {
386
- collection: collectionName,
387
- 'max-age': _constants.FILE_CACHE_MAX_AGE
388
- },
389
- auth: auth
390
- };
391
- return _context6.abrupt("return", (0, _helpers.createUrl)("".concat(auth.baseUrl).concat(artifactUrl), options));
392
- case 8:
393
- case "end":
394
- return _context6.stop();
395
- }
422
+ while (1) switch (_context6.prev = _context6.next) {
423
+ case 0:
424
+ artifactUrl = (0, _artifacts.getArtifactUrl)(artifacts, artifactName);
425
+ if (artifactUrl) {
426
+ _context6.next = 3;
427
+ break;
428
+ }
429
+ throw new Error("artifact ".concat(artifactName, " not found"));
430
+ case 3:
431
+ _context6.next = 5;
432
+ return this.resolveAuth({
433
+ collectionName: collectionName
434
+ });
435
+ case 5:
436
+ auth = _context6.sent;
437
+ options = {
438
+ params: {
439
+ collection: collectionName,
440
+ 'max-age': _constants.FILE_CACHE_MAX_AGE
441
+ },
442
+ auth: auth
443
+ };
444
+ return _context6.abrupt("return", (0, _helpers.createUrl)("".concat(auth.baseUrl).concat(artifactUrl), options));
445
+ case 8:
446
+ case "end":
447
+ return _context6.stop();
396
448
  }
397
449
  }, _callee6, this);
398
450
  }));
399
- function getArtifactURL(_x18, _x19, _x20) {
451
+ function getArtifactURL(_x16, _x17, _x18) {
400
452
  return _getArtifactURL.apply(this, arguments);
401
453
  }
402
454
  return getArtifactURL;
@@ -407,36 +459,34 @@ var MediaStore = /*#__PURE__*/function () {
407
459
  var _getImage = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(id, params, controller, fetchMaxRes, traceContext) {
408
460
  var isWebpSupported, headers, metadata, options;
409
461
  return _regenerator.default.wrap(function _callee7$(_context7) {
410
- while (1) {
411
- switch (_context7.prev = _context7.next) {
412
- case 0:
413
- // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
414
- isWebpSupported = false;
415
- headers = {};
416
- if (isWebpSupported) {
417
- headers.accept = 'image/webp,image/*,*/*;q=0.8';
418
- }
419
- metadata = {
420
- method: 'GET',
421
- endpoint: '/file/{fileId}/image'
422
- };
423
- options = _objectSpread(_objectSpread({}, metadata), {}, {
424
- authContext: {
425
- collectionName: params && params.collection
426
- },
427
- params: extendImageParams(params, fetchMaxRes),
428
- headers: headers,
429
- traceContext: traceContext
430
- });
431
- return _context7.abrupt("return", this.request("/file/".concat(id, "/image"), options, controller).then((0, _helpers.createMapResponseToBlob)(metadata)));
432
- case 6:
433
- case "end":
434
- return _context7.stop();
435
- }
462
+ while (1) switch (_context7.prev = _context7.next) {
463
+ case 0:
464
+ // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
465
+ isWebpSupported = false;
466
+ headers = {};
467
+ if (isWebpSupported) {
468
+ headers.accept = 'image/webp,image/*,*/*;q=0.8';
469
+ }
470
+ metadata = {
471
+ method: 'GET',
472
+ endpoint: '/file/{fileId}/image'
473
+ };
474
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
475
+ authContext: {
476
+ collectionName: params && params.collection
477
+ },
478
+ params: extendImageParams(params, fetchMaxRes),
479
+ headers: headers,
480
+ traceContext: traceContext
481
+ });
482
+ return _context7.abrupt("return", this.request("/file/".concat(id, "/image"), options, controller).then((0, _helpers.createMapResponseToBlob)(metadata)));
483
+ case 6:
484
+ case "end":
485
+ return _context7.stop();
436
486
  }
437
487
  }, _callee7, this);
438
488
  }));
439
- function getImage(_x21, _x22, _x23, _x24, _x25) {
489
+ function getImage(_x19, _x20, _x21, _x22, _x23) {
440
490
  return _getImage.apply(this, arguments);
441
491
  }
442
492
  return getImage;
@@ -447,39 +497,37 @@ var MediaStore = /*#__PURE__*/function () {
447
497
  var _getItems = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(ids, collectionName, traceContext) {
448
498
  var descriptors, metadata, options;
449
499
  return _regenerator.default.wrap(function _callee8$(_context8) {
450
- while (1) {
451
- switch (_context8.prev = _context8.next) {
452
- case 0:
453
- descriptors = ids.map(function (id) {
454
- return {
455
- type: 'file',
456
- id: id,
457
- collection: collectionName
458
- };
459
- });
460
- metadata = {
461
- method: 'POST',
462
- endpoint: '/items'
500
+ while (1) switch (_context8.prev = _context8.next) {
501
+ case 0:
502
+ descriptors = ids.map(function (id) {
503
+ return {
504
+ type: 'file',
505
+ id: id,
506
+ collection: collectionName
463
507
  };
464
- options = _objectSpread(_objectSpread({}, metadata), {}, {
465
- authContext: {
466
- collectionName: collectionName
467
- },
468
- headers: jsonHeaders,
469
- body: JSON.stringify({
470
- descriptors: descriptors
471
- }),
472
- traceContext: traceContext
473
- });
474
- return _context8.abrupt("return", this.request('/items', options).then((0, _helpers.createMapResponseToJson)(metadata)));
475
- case 4:
476
- case "end":
477
- return _context8.stop();
478
- }
508
+ });
509
+ metadata = {
510
+ method: 'POST',
511
+ endpoint: '/items'
512
+ };
513
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
514
+ authContext: {
515
+ collectionName: collectionName
516
+ },
517
+ headers: jsonHeaders,
518
+ body: JSON.stringify({
519
+ descriptors: descriptors
520
+ }),
521
+ traceContext: traceContext
522
+ });
523
+ return _context8.abrupt("return", this.request('/items', options).then((0, _helpers.createMapResponseToJson)(metadata)));
524
+ case 4:
525
+ case "end":
526
+ return _context8.stop();
479
527
  }
480
528
  }, _callee8, this);
481
529
  }));
482
- function getItems(_x26, _x27, _x28) {
530
+ function getItems(_x24, _x25, _x26) {
483
531
  return _getItems.apply(this, arguments);
484
532
  }
485
533
  return getItems;
@@ -490,29 +538,27 @@ var MediaStore = /*#__PURE__*/function () {
490
538
  var _getImageMetadata = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(id, params, traceContext) {
491
539
  var metadata, options;
492
540
  return _regenerator.default.wrap(function _callee9$(_context9) {
493
- while (1) {
494
- switch (_context9.prev = _context9.next) {
495
- case 0:
496
- metadata = {
497
- method: 'GET',
498
- endpoint: '/file/{fileId}/image/metadata'
499
- };
500
- options = _objectSpread(_objectSpread({}, metadata), {}, {
501
- authContext: {
502
- collectionName: params && params.collection
503
- },
504
- params: params,
505
- traceContext: traceContext
506
- });
507
- return _context9.abrupt("return", this.request("/file/".concat(id, "/image/metadata"), options).then((0, _helpers.createMapResponseToJson)(metadata)));
508
- case 3:
509
- case "end":
510
- return _context9.stop();
511
- }
541
+ while (1) switch (_context9.prev = _context9.next) {
542
+ case 0:
543
+ metadata = {
544
+ method: 'GET',
545
+ endpoint: '/file/{fileId}/image/metadata'
546
+ };
547
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
548
+ authContext: {
549
+ collectionName: params && params.collection
550
+ },
551
+ params: params,
552
+ traceContext: traceContext
553
+ });
554
+ return _context9.abrupt("return", this.request("/file/".concat(id, "/image/metadata"), options).then((0, _helpers.createMapResponseToJson)(metadata)));
555
+ case 3:
556
+ case "end":
557
+ return _context9.stop();
512
558
  }
513
559
  }, _callee9, this);
514
560
  }));
515
- function getImageMetadata(_x29, _x30, _x31) {
561
+ function getImageMetadata(_x27, _x28, _x29) {
516
562
  return _getImageMetadata.apply(this, arguments);
517
563
  }
518
564
  return getImageMetadata;
@@ -523,31 +569,29 @@ var MediaStore = /*#__PURE__*/function () {
523
569
  var _appendChunksToUpload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(uploadId, body, collectionName, traceContext) {
524
570
  var metadata, options;
525
571
  return _regenerator.default.wrap(function _callee10$(_context10) {
526
- while (1) {
527
- switch (_context10.prev = _context10.next) {
528
- case 0:
529
- metadata = {
530
- method: 'PUT',
531
- endpoint: '/upload/{uploadId}/chunks'
532
- };
533
- options = _objectSpread(_objectSpread({}, metadata), {}, {
534
- authContext: {
535
- collectionName: collectionName
536
- },
537
- headers: jsonHeaders,
538
- body: JSON.stringify(body),
539
- traceContext: traceContext
540
- });
541
- _context10.next = 4;
542
- return this.request("/upload/".concat(uploadId, "/chunks"), options);
543
- case 4:
544
- case "end":
545
- return _context10.stop();
546
- }
572
+ while (1) switch (_context10.prev = _context10.next) {
573
+ case 0:
574
+ metadata = {
575
+ method: 'PUT',
576
+ endpoint: '/upload/{uploadId}/chunks'
577
+ };
578
+ options = _objectSpread(_objectSpread({}, metadata), {}, {
579
+ authContext: {
580
+ collectionName: collectionName
581
+ },
582
+ headers: jsonHeaders,
583
+ body: JSON.stringify(body),
584
+ traceContext: traceContext
585
+ });
586
+ _context10.next = 4;
587
+ return this.request("/upload/".concat(uploadId, "/chunks"), options);
588
+ case 4:
589
+ case "end":
590
+ return _context10.stop();
547
591
  }
548
592
  }, _callee10, this);
549
593
  }));
550
- function appendChunksToUpload(_x32, _x33, _x34, _x35) {
594
+ function appendChunksToUpload(_x30, _x31, _x32, _x33) {
551
595
  return _appendChunksToUpload.apply(this, arguments);
552
596
  }
553
597
  return appendChunksToUpload;
@@ -587,52 +631,61 @@ var MediaStore = /*#__PURE__*/function () {
587
631
  body,
588
632
  clientOptions,
589
633
  traceContext,
634
+ resolvedAuth,
590
635
  auth,
591
636
  extendedTraceContext,
592
637
  response,
593
638
  _args11 = arguments;
594
639
  return _regenerator.default.wrap(function _callee11$(_context11) {
595
- while (1) {
596
- switch (_context11.prev = _context11.next) {
597
- case 0:
598
- options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {
599
- method: 'GET',
600
- endpoint: undefined,
601
- authContext: {}
602
- };
603
- controller = _args11.length > 2 ? _args11[2] : undefined;
604
- method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
605
- _context11.next = 5;
606
- return this.resolveAuth(authContext);
607
- case 5:
608
- auth = _context11.sent;
609
- extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
610
- spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
611
- }) : undefined;
612
- _context11.next = 9;
613
- return (0, _request3.request)("".concat(auth.baseUrl).concat(path), {
614
- method: method,
615
- endpoint: endpoint,
616
- auth: auth,
617
- params: params,
618
- headers: headers,
619
- body: body,
620
- clientOptions: clientOptions,
621
- traceContext: extendedTraceContext
622
- }, controller);
623
- case 9:
624
- response = _context11.sent;
625
- setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
626
- setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
627
- return _context11.abrupt("return", response);
628
- case 13:
629
- case "end":
630
- return _context11.stop();
631
- }
640
+ while (1) switch (_context11.prev = _context11.next) {
641
+ case 0:
642
+ options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {
643
+ method: 'GET',
644
+ endpoint: undefined,
645
+ authContext: {}
646
+ };
647
+ controller = _args11.length > 2 ? _args11[2] : undefined;
648
+ method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, resolvedAuth = options.resolvedAuth;
649
+ if (!(resolvedAuth !== null && resolvedAuth !== void 0)) {
650
+ _context11.next = 7;
651
+ break;
652
+ }
653
+ _context11.t0 = resolvedAuth;
654
+ _context11.next = 10;
655
+ break;
656
+ case 7:
657
+ _context11.next = 9;
658
+ return this.resolveAuth(authContext);
659
+ case 9:
660
+ _context11.t0 = _context11.sent;
661
+ case 10:
662
+ auth = _context11.t0;
663
+ extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
664
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
665
+ }) : undefined;
666
+ _context11.next = 14;
667
+ return (0, _request3.request)("".concat(auth.baseUrl).concat(path), {
668
+ method: method,
669
+ endpoint: endpoint,
670
+ auth: auth,
671
+ params: params,
672
+ headers: headers,
673
+ body: body,
674
+ clientOptions: clientOptions,
675
+ traceContext: extendedTraceContext
676
+ }, controller);
677
+ case 14:
678
+ response = _context11.sent;
679
+ setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
680
+ setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
681
+ return _context11.abrupt("return", response);
682
+ case 18:
683
+ case "end":
684
+ return _context11.stop();
632
685
  }
633
686
  }, _callee11, this);
634
687
  }));
635
- function request(_x36) {
688
+ function request(_x34) {
636
689
  return _request2.apply(this, arguments);
637
690
  }
638
691
  return request;