@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
@@ -121,26 +121,24 @@ function mapResponseToJson(_x) {
121
121
  function _mapResponseToJson() {
122
122
  _mapResponseToJson = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(response) {
123
123
  return _regenerator.default.wrap(function _callee3$(_context3) {
124
- while (1) {
125
- switch (_context3.prev = _context3.next) {
126
- case 0:
127
- // eslint-disable-next-line no-console
128
- console.warn('Helper is deprecated and will be remove in the next major version');
129
- _context3.prev = 1;
130
- _context3.next = 4;
131
- return response.json();
132
- case 4:
133
- return _context3.abrupt("return", _context3.sent);
134
- case 7:
135
- _context3.prev = 7;
136
- _context3.t0 = _context3["catch"](1);
137
- throw new _errors.RequestError('serverInvalidBody', {
138
- statusCode: response.status
139
- }, _context3.t0 instanceof Error ? _context3.t0 : undefined);
140
- case 10:
141
- case "end":
142
- return _context3.stop();
143
- }
124
+ while (1) switch (_context3.prev = _context3.next) {
125
+ case 0:
126
+ // eslint-disable-next-line no-console
127
+ console.warn('Helper is deprecated and will be remove in the next major version');
128
+ _context3.prev = 1;
129
+ _context3.next = 4;
130
+ return response.json();
131
+ case 4:
132
+ return _context3.abrupt("return", _context3.sent);
133
+ case 7:
134
+ _context3.prev = 7;
135
+ _context3.t0 = _context3["catch"](1);
136
+ throw new _errors.RequestError('serverInvalidBody', {
137
+ statusCode: response.status
138
+ }, _context3.t0 instanceof Error ? _context3.t0 : undefined);
139
+ case 10:
140
+ case "end":
141
+ return _context3.stop();
144
142
  }
145
143
  }, _callee3, null, [[1, 7]]);
146
144
  }));
@@ -156,26 +154,24 @@ function mapResponseToBlob(_x2) {
156
154
  function _mapResponseToBlob() {
157
155
  _mapResponseToBlob = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(response) {
158
156
  return _regenerator.default.wrap(function _callee4$(_context4) {
159
- while (1) {
160
- switch (_context4.prev = _context4.next) {
161
- case 0:
162
- // eslint-disable-next-line no-console
163
- console.warn('Helper is deprecated and will be remove in the next major version');
164
- _context4.prev = 1;
165
- _context4.next = 4;
166
- return response.blob();
167
- case 4:
168
- return _context4.abrupt("return", _context4.sent);
169
- case 7:
170
- _context4.prev = 7;
171
- _context4.t0 = _context4["catch"](1);
172
- throw new _errors.RequestError('serverInvalidBody', {
173
- statusCode: response.status
174
- }, _context4.t0 instanceof Error ? _context4.t0 : undefined);
175
- case 10:
176
- case "end":
177
- return _context4.stop();
178
- }
157
+ while (1) switch (_context4.prev = _context4.next) {
158
+ case 0:
159
+ // eslint-disable-next-line no-console
160
+ console.warn('Helper is deprecated and will be remove in the next major version');
161
+ _context4.prev = 1;
162
+ _context4.next = 4;
163
+ return response.blob();
164
+ case 4:
165
+ return _context4.abrupt("return", _context4.sent);
166
+ case 7:
167
+ _context4.prev = 7;
168
+ _context4.t0 = _context4["catch"](1);
169
+ throw new _errors.RequestError('serverInvalidBody', {
170
+ statusCode: response.status
171
+ }, _context4.t0 instanceof Error ? _context4.t0 : undefined);
172
+ case 10:
173
+ case "end":
174
+ return _context4.stop();
179
175
  }
180
176
  }, _callee4, null, [[1, 7]]);
181
177
  }));
@@ -190,24 +186,22 @@ function createMapResponseToJson(metadata) {
190
186
  return /*#__PURE__*/function () {
191
187
  var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response) {
192
188
  return _regenerator.default.wrap(function _callee$(_context) {
193
- while (1) {
194
- switch (_context.prev = _context.next) {
195
- case 0:
196
- _context.prev = 0;
197
- _context.next = 3;
198
- return response.json();
199
- case 3:
200
- return _context.abrupt("return", _context.sent);
201
- case 6:
202
- _context.prev = 6;
203
- _context.t0 = _context["catch"](0);
204
- throw new _errors.RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
205
- statusCode: response.status
206
- }), _context.t0 instanceof Error ? _context.t0 : undefined);
207
- case 9:
208
- case "end":
209
- return _context.stop();
210
- }
189
+ while (1) switch (_context.prev = _context.next) {
190
+ case 0:
191
+ _context.prev = 0;
192
+ _context.next = 3;
193
+ return response.json();
194
+ case 3:
195
+ return _context.abrupt("return", _context.sent);
196
+ case 6:
197
+ _context.prev = 6;
198
+ _context.t0 = _context["catch"](0);
199
+ throw new _errors.RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
200
+ statusCode: response.status
201
+ }), _context.t0 instanceof Error ? _context.t0 : undefined);
202
+ case 9:
203
+ case "end":
204
+ return _context.stop();
211
205
  }
212
206
  }, _callee, null, [[0, 6]]);
213
207
  }));
@@ -220,24 +214,22 @@ function createMapResponseToBlob(metadata) {
220
214
  return /*#__PURE__*/function () {
221
215
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(response) {
222
216
  return _regenerator.default.wrap(function _callee2$(_context2) {
223
- while (1) {
224
- switch (_context2.prev = _context2.next) {
225
- case 0:
226
- _context2.prev = 0;
227
- _context2.next = 3;
228
- return response.blob();
229
- case 3:
230
- return _context2.abrupt("return", _context2.sent);
231
- case 6:
232
- _context2.prev = 6;
233
- _context2.t0 = _context2["catch"](0);
234
- throw new _errors.RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
235
- statusCode: response.status
236
- }), _context2.t0 instanceof Error ? _context2.t0 : undefined);
237
- case 9:
238
- case "end":
239
- return _context2.stop();
240
- }
217
+ while (1) switch (_context2.prev = _context2.next) {
218
+ case 0:
219
+ _context2.prev = 0;
220
+ _context2.next = 3;
221
+ return response.blob();
222
+ case 3:
223
+ return _context2.abrupt("return", _context2.sent);
224
+ case 6:
225
+ _context2.prev = 6;
226
+ _context2.t0 = _context2["catch"](0);
227
+ throw new _errors.RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
228
+ statusCode: response.status
229
+ }), _context2.t0 instanceof Error ? _context2.t0 : undefined);
230
+ case 9:
231
+ case "end":
232
+ return _context2.stop();
241
233
  }
242
234
  }, _callee2, null, [[0, 6]]);
243
235
  }));
@@ -276,87 +268,83 @@ function _fetchRetry() {
276
268
  waitAndBumpTimeout,
277
269
  _args6 = arguments;
278
270
  return _regenerator.default.wrap(function _callee6$(_context6) {
279
- while (1) {
280
- switch (_context6.prev = _context6.next) {
281
- case 0:
282
- overwriteOptions = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
283
- options = _objectSpread(_objectSpread({}, DEFAULT_RETRY_OPTIONS), overwriteOptions);
284
- startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor;
285
- attempts = 0;
286
- timeoutInMs = startTimeoutInMs;
287
- waitAndBumpTimeout = /*#__PURE__*/function () {
288
- var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
289
- return _regenerator.default.wrap(function _callee5$(_context5) {
290
- while (1) {
291
- switch (_context5.prev = _context5.next) {
292
- case 0:
293
- _context5.next = 2;
294
- return waitPromise(timeoutInMs);
295
- case 2:
296
- timeoutInMs *= factor;
297
- attempts += 1;
298
- case 4:
299
- case "end":
300
- return _context5.stop();
301
- }
302
- }
303
- }, _callee5);
304
- }));
305
- return function waitAndBumpTimeout() {
306
- return _ref7.apply(this, arguments);
307
- };
308
- }();
309
- case 6:
310
- if (!(attempts < maxAttempts)) {
311
- _context6.next = 24;
312
- break;
313
- }
314
- _context6.prev = 7;
315
- _context6.next = 10;
316
- return functionToRetry();
317
- case 10:
318
- return _context6.abrupt("return", _context6.sent);
319
- case 13:
320
- _context6.prev = 13;
321
- _context6.t0 = _context6["catch"](7);
322
- lastError = _context6.t0;
271
+ while (1) switch (_context6.prev = _context6.next) {
272
+ case 0:
273
+ overwriteOptions = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
274
+ options = _objectSpread(_objectSpread({}, DEFAULT_RETRY_OPTIONS), overwriteOptions);
275
+ startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor;
276
+ attempts = 0;
277
+ timeoutInMs = startTimeoutInMs;
278
+ waitAndBumpTimeout = /*#__PURE__*/function () {
279
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
280
+ return _regenerator.default.wrap(function _callee5$(_context5) {
281
+ while (1) switch (_context5.prev = _context5.next) {
282
+ case 0:
283
+ _context5.next = 2;
284
+ return waitPromise(timeoutInMs);
285
+ case 2:
286
+ timeoutInMs *= factor;
287
+ attempts += 1;
288
+ case 4:
289
+ case "end":
290
+ return _context5.stop();
291
+ }
292
+ }, _callee5);
293
+ }));
294
+ return function waitAndBumpTimeout() {
295
+ return _ref7.apply(this, arguments);
296
+ };
297
+ }();
298
+ case 6:
299
+ if (!(attempts < maxAttempts)) {
300
+ _context6.next = 24;
301
+ break;
302
+ }
303
+ _context6.prev = 7;
304
+ _context6.next = 10;
305
+ return functionToRetry();
306
+ case 10:
307
+ return _context6.abrupt("return", _context6.sent);
308
+ case 13:
309
+ _context6.prev = 13;
310
+ _context6.t0 = _context6["catch"](7);
311
+ lastError = _context6.t0;
323
312
 
324
- // don't retry if request was aborted by user
325
- if (!isAbortedRequestError(_context6.t0)) {
326
- _context6.next = 18;
327
- break;
328
- }
329
- throw new _errors.RequestError('clientAbortedRequest', metadata, _context6.t0);
330
- case 18:
331
- if (!(!isFetchNetworkError(_context6.t0) && !(0, _errors.isRequestError)(_context6.t0) || (0, _errors.isRequestError)(_context6.t0) && (!_context6.t0.metadata || !_context6.t0.metadata.statusCode || _context6.t0.metadata.statusCode < 500))) {
332
- _context6.next = 20;
333
- break;
334
- }
335
- throw _context6.t0;
336
- case 20:
337
- _context6.next = 22;
338
- return waitAndBumpTimeout();
339
- case 22:
340
- _context6.next = 6;
313
+ // don't retry if request was aborted by user
314
+ if (!isAbortedRequestError(_context6.t0)) {
315
+ _context6.next = 18;
341
316
  break;
342
- case 24:
343
- if (!(0, _errors.isRequestError)(lastError)) {
344
- _context6.next = 26;
345
- break;
346
- }
347
- throw cloneRequestError(lastError, {
348
- attempts: attempts,
349
- clientExhaustedRetries: true
350
- });
351
- case 26:
352
- throw new _errors.RequestError('serverUnexpectedError', _objectSpread(_objectSpread({}, metadata), {}, {
353
- attempts: attempts,
354
- clientExhaustedRetries: true
355
- }), lastError);
356
- case 27:
357
- case "end":
358
- return _context6.stop();
359
- }
317
+ }
318
+ throw new _errors.RequestError('clientAbortedRequest', metadata, _context6.t0);
319
+ case 18:
320
+ if (!(!isFetchNetworkError(_context6.t0) && !(0, _errors.isRequestError)(_context6.t0) || (0, _errors.isRequestError)(_context6.t0) && (!_context6.t0.metadata || !_context6.t0.metadata.statusCode || _context6.t0.metadata.statusCode < 500))) {
321
+ _context6.next = 20;
322
+ break;
323
+ }
324
+ throw _context6.t0;
325
+ case 20:
326
+ _context6.next = 22;
327
+ return waitAndBumpTimeout();
328
+ case 22:
329
+ _context6.next = 6;
330
+ break;
331
+ case 24:
332
+ if (!(0, _errors.isRequestError)(lastError)) {
333
+ _context6.next = 26;
334
+ break;
335
+ }
336
+ throw cloneRequestError(lastError, {
337
+ attempts: attempts,
338
+ clientExhaustedRetries: true
339
+ });
340
+ case 26:
341
+ throw new _errors.RequestError('serverUnexpectedError', _objectSpread(_objectSpread({}, metadata), {}, {
342
+ attempts: attempts,
343
+ clientExhaustedRetries: true
344
+ }), lastError);
345
+ case 27:
346
+ case "end":
347
+ return _context6.stop();
360
348
  }
361
349
  }, _callee6, null, [[7, 13]]);
362
350
  }));
@@ -49,33 +49,31 @@ function _request() {
49
49
  doFetch,
50
50
  _args = arguments;
51
51
  return _regenerator.default.wrap(function _callee$(_context) {
52
- while (1) {
53
- switch (_context.prev = _context.next) {
54
- case 0:
55
- options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
56
- controller = _args.length > 2 ? _args[2] : undefined;
57
- _options$method = options.method, method = _options$method === void 0 ? 'GET' : _options$method, endpoint = options.endpoint, auth = options.auth, params = options.params, headers = options.headers, body = options.body, _options$clientOption = options.clientOptions, clientOptions = _options$clientOption === void 0 ? {} : _options$clientOption, traceContext = options.traceContext;
58
- retryOptions = clientOptions.retryOptions;
59
- metadata = {
52
+ while (1) switch (_context.prev = _context.next) {
53
+ case 0:
54
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
55
+ controller = _args.length > 2 ? _args[2] : undefined;
56
+ _options$method = options.method, method = _options$method === void 0 ? 'GET' : _options$method, endpoint = options.endpoint, auth = options.auth, params = options.params, headers = options.headers, body = options.body, _options$clientOption = options.clientOptions, clientOptions = _options$clientOption === void 0 ? {} : _options$clientOption, traceContext = options.traceContext;
57
+ retryOptions = clientOptions.retryOptions;
58
+ metadata = {
59
+ method: method,
60
+ endpoint: endpoint,
61
+ traceContext: traceContext
62
+ }; // TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
63
+ doFetch = function doFetch() {
64
+ return fetch((0, _helpers.createUrl)(url, {
65
+ params: params
66
+ }), {
60
67
  method: method,
61
- endpoint: endpoint,
62
- traceContext: traceContext
63
- }; // TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
64
- doFetch = function doFetch() {
65
- return fetch((0, _helpers.createUrl)(url, {
66
- params: params
67
- }), {
68
- method: method,
69
- body: body,
70
- headers: (0, _helpers.extendHeaders)(headers, auth, traceContext),
71
- signal: controller && controller.signal
72
- }).then((0, _helpers.createProcessFetchResponse)(metadata));
73
- };
74
- return _context.abrupt("return", (0, _helpers.fetchRetry)(doFetch, metadata, retryOptions));
75
- case 7:
76
- case "end":
77
- return _context.stop();
78
- }
68
+ body: body,
69
+ headers: (0, _helpers.extendHeaders)(headers, auth, traceContext),
70
+ signal: controller && controller.signal
71
+ }).then((0, _helpers.createProcessFetchResponse)(metadata));
72
+ };
73
+ return _context.abrupt("return", (0, _helpers.fetchRetry)(doFetch, metadata, retryOptions));
74
+ case 7:
75
+ case "end":
76
+ return _context.stop();
79
77
  }
80
78
  }, _callee);
81
79
  }));
@@ -29,47 +29,45 @@ function _shouldFetchRemoteFileStates() {
29
29
  _shouldFetchRemoteFileStates = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaType, mimeType, preview) {
30
30
  var content, _yield$getVideoDimens, width, height;
31
31
  return _regenerator.default.wrap(function _callee$(_context) {
32
- while (1) {
33
- switch (_context.prev = _context.next) {
34
- case 0:
35
- if (!((mediaType === 'doc' || !(0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(mimeType) || !preview) && (0, _mediaTypeUtils.isMimeTypeSupportedByServer)(mimeType))) {
36
- _context.next = 2;
37
- break;
38
- }
39
- return _context.abrupt("return", true);
40
- case 2:
41
- if (!(mediaType === 'video' && !!preview)) {
42
- _context.next = 20;
43
- break;
44
- }
45
- _context.next = 5;
46
- return preview;
47
- case 5:
48
- content = _context.sent.value;
49
- if (content instanceof Blob) {
50
- _context.next = 8;
51
- break;
52
- }
53
- return _context.abrupt("return", false);
54
- case 8:
55
- _context.prev = 8;
56
- _context.next = 11;
57
- return (0, _getVideoDimensionsFromBlob.getVideoDimensionsFromBlob)(content);
58
- case 11:
59
- _yield$getVideoDimens = _context.sent;
60
- width = _yield$getVideoDimens.width;
61
- height = _yield$getVideoDimens.height;
62
- return _context.abrupt("return", !width && !height);
63
- case 17:
64
- _context.prev = 17;
65
- _context.t0 = _context["catch"](8);
66
- return _context.abrupt("return", true);
67
- case 20:
68
- return _context.abrupt("return", false);
69
- case 21:
70
- case "end":
71
- return _context.stop();
72
- }
32
+ while (1) switch (_context.prev = _context.next) {
33
+ case 0:
34
+ if (!((mediaType === 'doc' || !(0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(mimeType) || !preview) && (0, _mediaTypeUtils.isMimeTypeSupportedByServer)(mimeType))) {
35
+ _context.next = 2;
36
+ break;
37
+ }
38
+ return _context.abrupt("return", true);
39
+ case 2:
40
+ if (!(mediaType === 'video' && !!preview)) {
41
+ _context.next = 20;
42
+ break;
43
+ }
44
+ _context.next = 5;
45
+ return preview;
46
+ case 5:
47
+ content = _context.sent.value;
48
+ if (content instanceof Blob) {
49
+ _context.next = 8;
50
+ break;
51
+ }
52
+ return _context.abrupt("return", false);
53
+ case 8:
54
+ _context.prev = 8;
55
+ _context.next = 11;
56
+ return (0, _getVideoDimensionsFromBlob.getVideoDimensionsFromBlob)(content);
57
+ case 11:
58
+ _yield$getVideoDimens = _context.sent;
59
+ width = _yield$getVideoDimens.width;
60
+ height = _yield$getVideoDimens.height;
61
+ return _context.abrupt("return", !width && !height);
62
+ case 17:
63
+ _context.prev = 17;
64
+ _context.t0 = _context["catch"](8);
65
+ return _context.abrupt("return", true);
66
+ case 20:
67
+ return _context.abrupt("return", false);
68
+ case 21:
69
+ case "end":
70
+ return _context.stop();
73
71
  }
74
72
  }, _callee, null, [[8, 17]]);
75
73
  }));
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.2.1",
3
+ "version": "21.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -32,6 +32,7 @@ import { getMediaFeatureFlag } from '@atlaskit/media-common';
32
32
  export { isFileFetcherError, FileFetcherError } from './error';
33
33
  export class FileFetcherImpl {
34
34
  constructor(mediaStore, featureFlags) {
35
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
35
36
  _defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
36
37
  const subject = createMediaSubject();
37
38
  const poll = new PollingFunction();
@@ -135,9 +136,6 @@ export class FileFetcherImpl {
135
136
  getFileBinaryURL(id, collectionName) {
136
137
  return this.mediaStore.getFileBinaryURL(id, collectionName);
137
138
  }
138
-
139
- // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
140
-
141
139
  touchFiles(descriptors, collection, traceContext) {
142
140
  return this.mediaStore.touchFiles({
143
141
  descriptors
@@ -1,6 +1,5 @@
1
1
  import { EventEmitter2 } from 'eventemitter2';
2
2
  import { MediaStore } from './media-store';
3
- import { CollectionFetcher } from './collection-fetcher';
4
3
  import { FileFetcherImpl } from './file-fetcher';
5
4
  import { StargateClient } from './stargate-client';
6
5
  export class MediaClient {
@@ -16,7 +15,6 @@ export class MediaClient {
16
15
  initialAuth: mediaClientConfig.initialAuth
17
16
  }, featureFlags);
18
17
  this.config = mediaClientConfig;
19
- this.collection = new CollectionFetcher(this.mediaStore);
20
18
  this.file = new FileFetcherImpl(this.mediaStore, featureFlags);
21
19
  this.eventEmitter = new EventEmitter2();
22
20
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
@@ -41,6 +39,9 @@ export class MediaClient {
41
39
  this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
42
40
  return this.mobileUpload;
43
41
  }
42
+ async removeFileFromCollection(id, collectionName, occurrenceKey, traceContext) {
43
+ await this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey, traceContext);
44
+ }
44
45
  on(event, listener) {
45
46
  this.eventEmitter.on(event, listener);
46
47
  }
@@ -5,7 +5,7 @@ import { getArtifactUrl } from '../../models/artifacts';
5
5
  import { request } from '../../utils/request';
6
6
  import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
7
7
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
8
- import { DeprecatedError } from '../../utils/deprecatedEndpointError';
8
+ import parseJwt from '../../utils/parseJwt';
9
9
  export { MediaStoreError, isMediaStoreError } from './error';
10
10
  const MEDIA_API_REGION = 'media-api-region';
11
11
  const MEDIA_API_ENVIRONMENT = 'media-api-environment';
@@ -35,14 +35,6 @@ export class MediaStore {
35
35
  this.config = config;
36
36
  this.featureFlags = featureFlags;
37
37
  }
38
-
39
- /**
40
- * @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-170 Internal documentation for deprecation (no external access)}
41
- * This method is no longer working. Will be removed in the next release
42
- */
43
- async getCollectionItems(collectionName, params, traceContext) {
44
- throw new DeprecatedError('collection/:name/items');
45
- }
46
38
  async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
47
39
  const metadata = {
48
40
  method: 'PUT',
@@ -149,21 +141,71 @@ export class MediaStore {
149
141
  };
150
142
  return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
151
143
  }
152
- touchFiles(body, params = {}, traceContext) {
144
+ getRejectedResponseFromDescriptor(descriptor, limit) {
145
+ return {
146
+ fileId: descriptor.fileId,
147
+ error: {
148
+ code: 'ExceedMaxFileSizeLimit',
149
+ title: 'The expected file size exceeded the maximum size limit.',
150
+ href: 'https://dt-api-filestore--app.ap-southeast-2.dev.atl-paas.net/api.html#BadRequest',
151
+ limit,
152
+ size: descriptor.size
153
+ }
154
+ };
155
+ }
156
+ async touchFiles(body, params = {}, traceContext) {
153
157
  const metadata = {
154
158
  method: 'POST',
155
159
  endpoint: '/upload/createWithFiles'
156
160
  };
161
+ const auth = await this.resolveAuth({
162
+ collectionName: params.collection
163
+ });
164
+ let maxFileSize;
165
+ try {
166
+ const decoded = parseJwt(auth.token);
167
+ maxFileSize = decoded.fileSizeLimit;
168
+ } catch (error) {
169
+ // we're relying on the backend to throw an error when there's an invalid token
170
+ }
171
+
172
+ // TODO MEX-2318: backend eventually will allow `size` in the body of this request, then some of this logic will need to be altered
173
+ const [filteredDescriptors, rejectedResponse] = body.descriptors.reduce(([filtered, rejected], curr) => {
174
+ const {
175
+ size,
176
+ ...descriptor
177
+ } = curr;
178
+ if (maxFileSize && size && size > maxFileSize) {
179
+ return [filtered, [...rejected, this.getRejectedResponseFromDescriptor(curr, maxFileSize)]];
180
+ }
181
+ return [[...filtered, descriptor], rejected];
182
+ }, [[], []]);
157
183
  const options = {
158
184
  ...metadata,
159
185
  authContext: {
160
186
  collectionName: params.collection
161
187
  },
162
188
  headers: jsonHeaders,
163
- body: JSON.stringify(body),
164
- traceContext
189
+ body: JSON.stringify({
190
+ ...body,
191
+ descriptors: filteredDescriptors
192
+ }),
193
+ traceContext,
194
+ resolvedAuth: auth
165
195
  };
166
- return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
196
+ if (filteredDescriptors.length === 0) {
197
+ return {
198
+ data: {
199
+ created: [],
200
+ rejected: rejectedResponse
201
+ }
202
+ };
203
+ }
204
+ return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata)).then(res => {
205
+ // TODO MEX-2318: backend eventually will include `rejected`, then this logic will need to be removed
206
+ res.data.rejected = rejectedResponse;
207
+ return res;
208
+ });
167
209
  }
168
210
  getFile(fileId, params = {}, traceContext) {
169
211
  const metadata = {
@@ -342,9 +384,10 @@ export class MediaStore {
342
384
  headers,
343
385
  body,
344
386
  clientOptions,
345
- traceContext
387
+ traceContext,
388
+ resolvedAuth
346
389
  } = options;
347
- const auth = await this.resolveAuth(authContext);
390
+ const auth = resolvedAuth !== null && resolvedAuth !== void 0 ? resolvedAuth : await this.resolveAuth(authContext);
348
391
  const extendedTraceContext = traceContext ? {
349
392
  ...traceContext,
350
393
  spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)