@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.
- package/CHANGELOG.md +35 -0
- package/dist/cjs/client/file-fetcher/error.js +4 -4
- package/dist/cjs/client/file-fetcher/index.js +275 -287
- package/dist/cjs/client/media-client.js +48 -34
- package/dist/cjs/client/media-store/index.js +367 -314
- package/dist/cjs/client/media-store/resolveAuth.js +30 -32
- package/dist/cjs/client/stargate-client.js +14 -16
- package/dist/cjs/index.js +6 -13
- package/dist/cjs/models/media.js +8 -9
- package/dist/cjs/uploader/error.js +4 -4
- package/dist/cjs/uploader/index.js +88 -96
- package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
- package/dist/cjs/utils/createFileDataLoader.js +67 -70
- package/dist/cjs/utils/getDimensionsFromBlob.js +23 -25
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +24 -26
- package/dist/cjs/utils/hashing/hasherCreator.js +32 -34
- package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/cjs/utils/mobileUpload/error.js +4 -4
- package/dist/cjs/utils/mobileUpload/helpers.js +41 -43
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +14 -16
- package/dist/cjs/utils/parseJwt.js +52 -0
- package/dist/cjs/utils/polling/index.js +40 -42
- package/dist/cjs/utils/request/errors.js +9 -9
- package/dist/cjs/utils/request/helpers.js +143 -155
- package/dist/cjs/utils/request/index.js +24 -26
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +39 -41
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +1 -3
- package/dist/es2019/client/media-client.js +3 -2
- package/dist/es2019/client/media-store/index.js +58 -15
- package/dist/es2019/index.js +2 -3
- package/dist/es2019/models/media.js +6 -4
- package/dist/es2019/uploader/index.js +3 -0
- package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/es2019/utils/mediaSubscribable/toPromise.js +10 -12
- package/dist/es2019/utils/parseJwt.js +46 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/error.js +4 -4
- package/dist/esm/client/file-fetcher/index.js +273 -286
- package/dist/esm/client/media-client.js +46 -32
- package/dist/esm/client/media-store/index.js +367 -314
- package/dist/esm/client/media-store/resolveAuth.js +30 -32
- package/dist/esm/client/stargate-client.js +14 -16
- package/dist/esm/index.js +2 -3
- package/dist/esm/models/media.js +6 -6
- package/dist/esm/uploader/error.js +4 -4
- package/dist/esm/uploader/index.js +89 -96
- package/dist/esm/utils/convertBase64ToBlob.js +2 -2
- package/dist/esm/utils/createFileDataLoader.js +65 -69
- package/dist/esm/utils/getDimensionsFromBlob.js +23 -25
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +24 -26
- package/dist/esm/utils/hashing/hasherCreator.js +28 -30
- package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/esm/utils/mobileUpload/error.js +4 -4
- package/dist/esm/utils/mobileUpload/helpers.js +41 -43
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +14 -16
- package/dist/esm/utils/parseJwt.js +46 -0
- package/dist/esm/utils/polling/index.js +40 -42
- package/dist/esm/utils/request/errors.js +9 -9
- package/dist/esm/utils/request/helpers.js +143 -155
- package/dist/esm/utils/request/index.js +24 -26
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +39 -41
- package/dist/esm/version.json +1 -1
- package/dist/types/client/__mocks__/media-client.d.ts +0 -2
- package/dist/types/client/file-fetcher/index.d.ts +4 -4
- package/dist/types/client/media-client.d.ts +1 -2
- package/dist/types/client/media-store/index.d.ts +17 -13
- package/dist/types/index.d.ts +4 -6
- package/dist/types/models/file-state.d.ts +2 -2
- package/dist/types/models/media.d.ts +1 -21
- package/dist/types/utils/createFileDataLoader.d.ts +2 -2
- package/dist/types/utils/createMediaSubject.d.ts +2 -2
- package/dist/types/utils/detectEmptyFile.d.ts +2 -2
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +3 -3
- package/dist/types/utils/mediaSubscribable/toPromise.d.ts +2 -2
- package/dist/types/utils/mediaSubscribable/types.d.ts +9 -8
- package/dist/types/utils/parseJwt.d.ts +1 -0
- package/package.json +2 -2
- package/report.api.md +77 -126
- package/dist/cjs/client/collection-fetcher.js +0 -98
- package/dist/cjs/models/media-subscribable.js +0 -5
- package/dist/cjs/utils/deprecatedEndpointError.js +0 -43
- package/dist/es2019/client/collection-fetcher.js +0 -38
- package/dist/es2019/models/media-subscribable.js +0 -1
- package/dist/es2019/utils/deprecatedEndpointError.js +0 -20
- package/dist/esm/client/collection-fetcher.js +0 -89
- package/dist/esm/models/media-subscribable.js +0 -1
- package/dist/esm/utils/deprecatedEndpointError.js +0 -34
- package/dist/types/client/collection-fetcher.d.ts +0 -42
- package/dist/types/models/media-subscribable.d.ts +0 -3
- 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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
}));
|
package/dist/cjs/version.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
164
|
-
|
|
189
|
+
body: JSON.stringify({
|
|
190
|
+
...body,
|
|
191
|
+
descriptors: filteredDescriptors
|
|
192
|
+
}),
|
|
193
|
+
traceContext,
|
|
194
|
+
resolvedAuth: auth
|
|
165
195
|
};
|
|
166
|
-
|
|
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)
|