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