@atlaskit/media-client 28.2.0 → 28.3.1
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 +16 -0
- package/dist/cjs/client/file-fetcher/index.js +10 -3
- package/dist/cjs/client/media-store/MediaStore.js +43 -11
- package/dist/cjs/utils/request/helpers.js +7 -0
- package/dist/es2019/client/file-fetcher/index.js +5 -1
- package/dist/es2019/client/media-store/MediaStore.js +22 -11
- package/dist/es2019/utils/request/helpers.js +5 -0
- package/dist/esm/client/file-fetcher/index.js +10 -3
- package/dist/esm/client/media-store/MediaStore.js +44 -12
- package/dist/esm/utils/request/helpers.js +6 -0
- package/dist/types/client/file-fetcher/index.d.ts +2 -2
- package/dist/types/client/media-store/MediaStore.d.ts +3 -0
- package/dist/types/client/media-store/types.d.ts +3 -0
- package/dist/types/utils/request/helpers.d.ts +1 -0
- package/dist/types/utils/request/types.d.ts +1 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +2 -2
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +3 -0
- package/dist/types-ts4.5/client/media-store/types.d.ts +3 -0
- package/dist/types-ts4.5/utils/request/helpers.d.ts +1 -0
- package/dist/types-ts4.5/utils/request/types.d.ts +1 -1
- package/package.json +2 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 28.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#165609](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165609)
|
|
8
|
+
[`b29c0cc4fef46`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b29c0cc4fef46) -
|
|
9
|
+
Cleaned up media card perf observer feature flag
|
|
10
|
+
|
|
11
|
+
## 28.3.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#163838](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/163838)
|
|
16
|
+
[`c3fcf9a7c2028`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3fcf9a7c2028) -
|
|
17
|
+
Media Client File Download throws Request errors due to failed connection (Not streaming errors)
|
|
18
|
+
|
|
3
19
|
## 28.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -474,6 +474,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
474
474
|
var _downloadBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id) {
|
|
475
475
|
var name,
|
|
476
476
|
collectionName,
|
|
477
|
+
traceContext,
|
|
477
478
|
url,
|
|
478
479
|
_args5 = arguments;
|
|
479
480
|
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
@@ -481,9 +482,10 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
481
482
|
case 0:
|
|
482
483
|
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
483
484
|
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
484
|
-
|
|
485
|
+
traceContext = _args5.length > 3 ? _args5[3] : undefined;
|
|
486
|
+
_context5.next = 5;
|
|
485
487
|
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
486
|
-
case
|
|
488
|
+
case 5:
|
|
487
489
|
url = _context5.sent;
|
|
488
490
|
(0, _downloadUrl.downloadUrl)(url, {
|
|
489
491
|
name: name
|
|
@@ -493,7 +495,12 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
493
495
|
isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
|
|
494
496
|
viewingLevel: 'download'
|
|
495
497
|
});
|
|
496
|
-
|
|
498
|
+
// Test the download after initiated the Browser process to catch any potential errors.
|
|
499
|
+
_context5.next = 10;
|
|
500
|
+
return this.mediaApi.testUrl(url, {
|
|
501
|
+
traceContext: traceContext
|
|
502
|
+
});
|
|
503
|
+
case 10:
|
|
497
504
|
case "end":
|
|
498
505
|
return _context5.stop();
|
|
499
506
|
}
|
|
@@ -11,7 +11,6 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
13
|
var _mediaCore = require("@atlaskit/media-core");
|
|
14
|
-
var _mediaCommon = require("@atlaskit/media-common");
|
|
15
14
|
var _constants = require("../../constants");
|
|
16
15
|
var _artifacts = require("../../models/artifacts");
|
|
17
16
|
var _request3 = require("../../utils/request");
|
|
@@ -453,7 +452,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
453
452
|
params: extendImageParams(params, fetchMaxRes),
|
|
454
453
|
headers: headers,
|
|
455
454
|
traceContext: traceContext,
|
|
456
|
-
addMediaClientParam:
|
|
455
|
+
addMediaClientParam: true
|
|
457
456
|
});
|
|
458
457
|
return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller, true).then((0, _helpers.createMapResponseToBlob)(metadata)));
|
|
459
458
|
case 7:
|
|
@@ -612,6 +611,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
612
611
|
auth,
|
|
613
612
|
clientId,
|
|
614
613
|
extendedTraceContext,
|
|
614
|
+
extendedParams,
|
|
615
615
|
url,
|
|
616
616
|
response,
|
|
617
617
|
_args12 = arguments;
|
|
@@ -631,32 +631,31 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
631
631
|
case 6:
|
|
632
632
|
auth = _context12.sent;
|
|
633
633
|
clientId = (0, _mediaCore.isClientBasedAuth)(auth) ? auth.clientId : undefined;
|
|
634
|
-
extendedTraceContext =
|
|
635
|
-
|
|
636
|
-
|
|
634
|
+
extendedTraceContext = (0, _helpers.extendTraceContext)(traceContext);
|
|
635
|
+
extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
|
|
636
|
+
clientId: clientId
|
|
637
|
+
}) : params;
|
|
637
638
|
url = "".concat(auth.baseUrl).concat(path);
|
|
638
639
|
if (useMediaCdn) {
|
|
639
640
|
url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
|
|
640
641
|
}
|
|
641
|
-
_context12.next =
|
|
642
|
+
_context12.next = 14;
|
|
642
643
|
return (0, _request3.request)(url, {
|
|
643
644
|
method: method,
|
|
644
645
|
endpoint: endpoint,
|
|
645
646
|
auth: auth,
|
|
646
|
-
params:
|
|
647
|
-
clientId: clientId
|
|
648
|
-
}) : params,
|
|
647
|
+
params: extendedParams,
|
|
649
648
|
headers: headers,
|
|
650
649
|
body: body,
|
|
651
650
|
clientOptions: clientOptions,
|
|
652
651
|
traceContext: extendedTraceContext
|
|
653
652
|
}, controller);
|
|
654
|
-
case
|
|
653
|
+
case 14:
|
|
655
654
|
response = _context12.sent;
|
|
656
655
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
657
656
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
658
657
|
return _context12.abrupt("return", response);
|
|
659
|
-
case
|
|
658
|
+
case 18:
|
|
660
659
|
case "end":
|
|
661
660
|
return _context12.stop();
|
|
662
661
|
}
|
|
@@ -667,6 +666,39 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
667
666
|
}
|
|
668
667
|
return request;
|
|
669
668
|
}()
|
|
669
|
+
}, {
|
|
670
|
+
key: "testUrl",
|
|
671
|
+
value: function () {
|
|
672
|
+
var _testUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(url) {
|
|
673
|
+
var options,
|
|
674
|
+
traceContext,
|
|
675
|
+
_args13 = arguments;
|
|
676
|
+
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
677
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
678
|
+
case 0:
|
|
679
|
+
options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
|
|
680
|
+
traceContext = options.traceContext;
|
|
681
|
+
_context13.next = 4;
|
|
682
|
+
return (0, _request3.request)(url, {
|
|
683
|
+
method: 'HEAD',
|
|
684
|
+
traceContext: (0, _helpers.extendTraceContext)(traceContext),
|
|
685
|
+
clientOptions: {
|
|
686
|
+
retryOptions: {
|
|
687
|
+
maxAttempts: 1
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
case 4:
|
|
692
|
+
case "end":
|
|
693
|
+
return _context13.stop();
|
|
694
|
+
}
|
|
695
|
+
}, _callee13);
|
|
696
|
+
}));
|
|
697
|
+
function testUrl(_x38) {
|
|
698
|
+
return _testUrl.apply(this, arguments);
|
|
699
|
+
}
|
|
700
|
+
return testUrl;
|
|
701
|
+
}()
|
|
670
702
|
}, {
|
|
671
703
|
key: "chunkHashAlgorithm",
|
|
672
704
|
get: function get() {
|
|
@@ -13,6 +13,7 @@ exports.createRequestErrorFromResponse = createRequestErrorFromResponse;
|
|
|
13
13
|
exports.createRequestErrorReason = createRequestErrorReason;
|
|
14
14
|
exports.createUrl = createUrl;
|
|
15
15
|
exports.extendHeaders = extendHeaders;
|
|
16
|
+
exports.extendTraceContext = void 0;
|
|
16
17
|
exports.extractMediaHeaders = extractMediaHeaders;
|
|
17
18
|
exports.fetchRetry = fetchRetry;
|
|
18
19
|
exports.isAbortedRequestError = isAbortedRequestError;
|
|
@@ -26,6 +27,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
26
27
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
27
28
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
28
29
|
var _mediaCore = require("@atlaskit/media-core");
|
|
30
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
29
31
|
var _authQueryParameters = require("../../models/auth-query-parameters");
|
|
30
32
|
var _errors = require("./errors");
|
|
31
33
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -46,6 +48,11 @@ function isFetchNetworkError(err) {
|
|
|
46
48
|
function isRateLimitedError(error) {
|
|
47
49
|
return !!error && (0, _errors.isRequestError)(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
48
50
|
}
|
|
51
|
+
var extendTraceContext = exports.extendTraceContext = function extendTraceContext(traceContext) {
|
|
52
|
+
return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
53
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
|
|
54
|
+
}) : undefined;
|
|
55
|
+
};
|
|
49
56
|
var ZipkinHeaderKeys = exports.ZipkinHeaderKeys = {
|
|
50
57
|
traceId: 'x-b3-traceid',
|
|
51
58
|
spanId: 'x-b3-spanid',
|
|
@@ -362,7 +362,7 @@ export class FileFetcherImpl {
|
|
|
362
362
|
setTimeout(onProgress, 0, 0);
|
|
363
363
|
return fromObservable(subject);
|
|
364
364
|
}
|
|
365
|
-
async downloadBinary(id, name = 'download', collectionName) {
|
|
365
|
+
async downloadBinary(id, name = 'download', collectionName, traceContext) {
|
|
366
366
|
const url = await this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
367
367
|
downloadUrl(url, {
|
|
368
368
|
name
|
|
@@ -372,6 +372,10 @@ export class FileFetcherImpl {
|
|
|
372
372
|
isUserCollection: collectionName === RECENTS_COLLECTION,
|
|
373
373
|
viewingLevel: 'download'
|
|
374
374
|
});
|
|
375
|
+
// Test the download after initiated the Browser process to catch any potential errors.
|
|
376
|
+
await this.mediaApi.testUrl(url, {
|
|
377
|
+
traceContext
|
|
378
|
+
});
|
|
375
379
|
}
|
|
376
380
|
async copyFile(source, destination, options = {}, traceContext) {
|
|
377
381
|
const {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
3
|
-
import { getRandomHex } from '@atlaskit/media-common';
|
|
4
3
|
import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
|
|
5
4
|
import { getArtifactUrl } from '../../models/artifacts';
|
|
6
5
|
import { request } from '../../utils/request';
|
|
7
|
-
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
6
|
+
import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
|
|
8
7
|
import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
|
|
9
8
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
10
9
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -272,7 +271,7 @@ export class MediaStore {
|
|
|
272
271
|
params: extendImageParams(params, fetchMaxRes),
|
|
273
272
|
headers,
|
|
274
273
|
traceContext,
|
|
275
|
-
addMediaClientParam:
|
|
274
|
+
addMediaClientParam: true
|
|
276
275
|
};
|
|
277
276
|
return this.request(`/file/${id}/${imageEndpoint}`, options, controller, true).then(createMapResponseToBlob(metadata));
|
|
278
277
|
}
|
|
@@ -368,10 +367,11 @@ export class MediaStore {
|
|
|
368
367
|
} = options;
|
|
369
368
|
const auth = await this.resolveAuth(authContext);
|
|
370
369
|
const clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
|
|
371
|
-
const extendedTraceContext = traceContext
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
370
|
+
const extendedTraceContext = extendTraceContext(traceContext);
|
|
371
|
+
const extendedParams = addMediaClientParam ? {
|
|
372
|
+
...params,
|
|
373
|
+
clientId
|
|
374
|
+
} : params;
|
|
375
375
|
let url = `${auth.baseUrl}${path}`;
|
|
376
376
|
if (useMediaCdn) {
|
|
377
377
|
url = mapToMediaCdnUrl(url, auth.token);
|
|
@@ -380,10 +380,7 @@ export class MediaStore {
|
|
|
380
380
|
method,
|
|
381
381
|
endpoint,
|
|
382
382
|
auth,
|
|
383
|
-
params:
|
|
384
|
-
...params,
|
|
385
|
-
clientId
|
|
386
|
-
} : params,
|
|
383
|
+
params: extendedParams,
|
|
387
384
|
headers,
|
|
388
385
|
body,
|
|
389
386
|
clientOptions,
|
|
@@ -393,6 +390,20 @@ export class MediaStore {
|
|
|
393
390
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
394
391
|
return response;
|
|
395
392
|
}
|
|
393
|
+
async testUrl(url, options = {}) {
|
|
394
|
+
const {
|
|
395
|
+
traceContext
|
|
396
|
+
} = options;
|
|
397
|
+
await request(url, {
|
|
398
|
+
method: 'HEAD',
|
|
399
|
+
traceContext: extendTraceContext(traceContext),
|
|
400
|
+
clientOptions: {
|
|
401
|
+
retryOptions: {
|
|
402
|
+
maxAttempts: 1
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
396
407
|
get chunkHashAlgorithm() {
|
|
397
408
|
return this._chunkHashAlgorithm;
|
|
398
409
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
2
|
+
import { getRandomHex } from '@atlaskit/media-common';
|
|
2
3
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
3
4
|
import { RequestError, isRequestError } from './errors';
|
|
4
5
|
export function waitPromise(timeout) {
|
|
@@ -15,6 +16,10 @@ export function isFetchNetworkError(err) {
|
|
|
15
16
|
export function isRateLimitedError(error) {
|
|
16
17
|
return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
17
18
|
}
|
|
19
|
+
export const extendTraceContext = traceContext => traceContext ? {
|
|
20
|
+
...traceContext,
|
|
21
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
22
|
+
} : undefined;
|
|
18
23
|
export const ZipkinHeaderKeys = {
|
|
19
24
|
traceId: 'x-b3-traceid',
|
|
20
25
|
spanId: 'x-b3-spanid',
|
|
@@ -456,6 +456,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
456
456
|
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
|
|
457
457
|
var name,
|
|
458
458
|
collectionName,
|
|
459
|
+
traceContext,
|
|
459
460
|
url,
|
|
460
461
|
_args5 = arguments;
|
|
461
462
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
@@ -463,9 +464,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
463
464
|
case 0:
|
|
464
465
|
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
465
466
|
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
466
|
-
|
|
467
|
+
traceContext = _args5.length > 3 ? _args5[3] : undefined;
|
|
468
|
+
_context5.next = 5;
|
|
467
469
|
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
468
|
-
case
|
|
470
|
+
case 5:
|
|
469
471
|
url = _context5.sent;
|
|
470
472
|
downloadUrl(url, {
|
|
471
473
|
name: name
|
|
@@ -475,7 +477,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
475
477
|
isUserCollection: collectionName === RECENTS_COLLECTION,
|
|
476
478
|
viewingLevel: 'download'
|
|
477
479
|
});
|
|
478
|
-
|
|
480
|
+
// Test the download after initiated the Browser process to catch any potential errors.
|
|
481
|
+
_context5.next = 10;
|
|
482
|
+
return this.mediaApi.testUrl(url, {
|
|
483
|
+
traceContext: traceContext
|
|
484
|
+
});
|
|
485
|
+
case 10:
|
|
479
486
|
case "end":
|
|
480
487
|
return _context5.stop();
|
|
481
488
|
}
|
|
@@ -6,11 +6,10 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
6
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
9
|
-
import { getRandomHex } from '@atlaskit/media-common';
|
|
10
9
|
import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
|
|
11
10
|
import { getArtifactUrl } from '../../models/artifacts';
|
|
12
11
|
import { request as _request } from '../../utils/request';
|
|
13
|
-
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
12
|
+
import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
|
|
14
13
|
import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
|
|
15
14
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
16
15
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -447,7 +446,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
447
446
|
params: extendImageParams(params, fetchMaxRes),
|
|
448
447
|
headers: headers,
|
|
449
448
|
traceContext: traceContext,
|
|
450
|
-
addMediaClientParam:
|
|
449
|
+
addMediaClientParam: true
|
|
451
450
|
});
|
|
452
451
|
return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller, true).then(createMapResponseToBlob(metadata)));
|
|
453
452
|
case 7:
|
|
@@ -606,6 +605,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
606
605
|
auth,
|
|
607
606
|
clientId,
|
|
608
607
|
extendedTraceContext,
|
|
608
|
+
extendedParams,
|
|
609
609
|
url,
|
|
610
610
|
response,
|
|
611
611
|
_args12 = arguments;
|
|
@@ -625,32 +625,31 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
625
625
|
case 6:
|
|
626
626
|
auth = _context12.sent;
|
|
627
627
|
clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
|
|
628
|
-
extendedTraceContext =
|
|
629
|
-
|
|
630
|
-
|
|
628
|
+
extendedTraceContext = extendTraceContext(traceContext);
|
|
629
|
+
extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
|
|
630
|
+
clientId: clientId
|
|
631
|
+
}) : params;
|
|
631
632
|
url = "".concat(auth.baseUrl).concat(path);
|
|
632
633
|
if (useMediaCdn) {
|
|
633
634
|
url = mapToMediaCdnUrl(url, auth.token);
|
|
634
635
|
}
|
|
635
|
-
_context12.next =
|
|
636
|
+
_context12.next = 14;
|
|
636
637
|
return _request(url, {
|
|
637
638
|
method: method,
|
|
638
639
|
endpoint: endpoint,
|
|
639
640
|
auth: auth,
|
|
640
|
-
params:
|
|
641
|
-
clientId: clientId
|
|
642
|
-
}) : params,
|
|
641
|
+
params: extendedParams,
|
|
643
642
|
headers: headers,
|
|
644
643
|
body: body,
|
|
645
644
|
clientOptions: clientOptions,
|
|
646
645
|
traceContext: extendedTraceContext
|
|
647
646
|
}, controller);
|
|
648
|
-
case
|
|
647
|
+
case 14:
|
|
649
648
|
response = _context12.sent;
|
|
650
649
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
651
650
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
652
651
|
return _context12.abrupt("return", response);
|
|
653
|
-
case
|
|
652
|
+
case 18:
|
|
654
653
|
case "end":
|
|
655
654
|
return _context12.stop();
|
|
656
655
|
}
|
|
@@ -661,6 +660,39 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
661
660
|
}
|
|
662
661
|
return request;
|
|
663
662
|
}()
|
|
663
|
+
}, {
|
|
664
|
+
key: "testUrl",
|
|
665
|
+
value: function () {
|
|
666
|
+
var _testUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(url) {
|
|
667
|
+
var options,
|
|
668
|
+
traceContext,
|
|
669
|
+
_args13 = arguments;
|
|
670
|
+
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
671
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
672
|
+
case 0:
|
|
673
|
+
options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
|
|
674
|
+
traceContext = options.traceContext;
|
|
675
|
+
_context13.next = 4;
|
|
676
|
+
return _request(url, {
|
|
677
|
+
method: 'HEAD',
|
|
678
|
+
traceContext: extendTraceContext(traceContext),
|
|
679
|
+
clientOptions: {
|
|
680
|
+
retryOptions: {
|
|
681
|
+
maxAttempts: 1
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
case 4:
|
|
686
|
+
case "end":
|
|
687
|
+
return _context13.stop();
|
|
688
|
+
}
|
|
689
|
+
}, _callee13);
|
|
690
|
+
}));
|
|
691
|
+
function testUrl(_x38) {
|
|
692
|
+
return _testUrl.apply(this, arguments);
|
|
693
|
+
}
|
|
694
|
+
return testUrl;
|
|
695
|
+
}()
|
|
664
696
|
}, {
|
|
665
697
|
key: "chunkHashAlgorithm",
|
|
666
698
|
get: function get() {
|
|
@@ -6,6 +6,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
6
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
9
|
+
import { getRandomHex } from '@atlaskit/media-common';
|
|
9
10
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
10
11
|
import { RequestError, isRequestError } from './errors';
|
|
11
12
|
export function waitPromise(timeout) {
|
|
@@ -24,6 +25,11 @@ export function isFetchNetworkError(err) {
|
|
|
24
25
|
export function isRateLimitedError(error) {
|
|
25
26
|
return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
26
27
|
}
|
|
28
|
+
export var extendTraceContext = function extendTraceContext(traceContext) {
|
|
29
|
+
return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
30
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
31
|
+
}) : undefined;
|
|
32
|
+
};
|
|
27
33
|
export var ZipkinHeaderKeys = {
|
|
28
34
|
traceId: 'x-b3-traceid',
|
|
29
35
|
spanId: 'x-b3-spanid',
|
|
@@ -35,7 +35,7 @@ export interface FileFetcher {
|
|
|
35
35
|
touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
|
|
36
36
|
upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
|
|
37
37
|
uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
|
|
38
|
-
downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
|
|
38
|
+
downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
39
39
|
getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
|
|
40
40
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
41
41
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
@@ -57,6 +57,6 @@ export declare class FileFetcherImpl implements FileFetcher {
|
|
|
57
57
|
uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
|
|
58
58
|
private getUploadingFileStateBase;
|
|
59
59
|
upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
|
|
60
|
-
downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
|
|
60
|
+
downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
61
61
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
62
62
|
}
|
|
@@ -29,6 +29,9 @@ export declare class MediaStore implements MediaApi {
|
|
|
29
29
|
appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
30
30
|
copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
|
|
31
31
|
request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
|
|
32
|
+
testUrl(url: string, options?: {
|
|
33
|
+
traceContext?: MediaTraceContext;
|
|
34
|
+
}): Promise<void>;
|
|
32
35
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
33
36
|
resolveInitialAuth: () => Auth;
|
|
34
37
|
get chunkHashAlgorithm(): ChunkHashAlgorithm;
|
|
@@ -167,6 +167,9 @@ export interface MediaApi {
|
|
|
167
167
|
appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
168
168
|
copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
|
|
169
169
|
request: (path: string, options: MediaStoreRequestOptions, controller?: AbortController) => Promise<Response>;
|
|
170
|
+
testUrl: (url: string, options?: {
|
|
171
|
+
traceContext?: MediaTraceContext;
|
|
172
|
+
}) => Promise<void>;
|
|
170
173
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
171
174
|
resolveInitialAuth: () => Auth;
|
|
172
175
|
}
|
|
@@ -6,6 +6,7 @@ export declare function waitPromise(timeout: number): Promise<void>;
|
|
|
6
6
|
export declare function isAbortedRequestError(err: any): boolean;
|
|
7
7
|
export declare function isFetchNetworkError(err: any): err is TypeError;
|
|
8
8
|
export declare function isRateLimitedError(error: Error | undefined): boolean;
|
|
9
|
+
export declare const extendTraceContext: (traceContext?: MediaTraceContext) => Required<MediaTraceContext> | undefined;
|
|
9
10
|
export declare const ZipkinHeaderKeys: {
|
|
10
11
|
traceId: string;
|
|
11
12
|
spanId: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Auth } from '@atlaskit/media-core';
|
|
2
2
|
import type { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
|
|
4
4
|
export type RequestParams = {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
};
|
|
@@ -35,7 +35,7 @@ export interface FileFetcher {
|
|
|
35
35
|
touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
|
|
36
36
|
upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
|
|
37
37
|
uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
|
|
38
|
-
downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
|
|
38
|
+
downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
39
39
|
getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
|
|
40
40
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
41
41
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
@@ -57,6 +57,6 @@ export declare class FileFetcherImpl implements FileFetcher {
|
|
|
57
57
|
uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
|
|
58
58
|
private getUploadingFileStateBase;
|
|
59
59
|
upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
|
|
60
|
-
downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
|
|
60
|
+
downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
61
61
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
62
62
|
}
|
|
@@ -29,6 +29,9 @@ export declare class MediaStore implements MediaApi {
|
|
|
29
29
|
appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
30
30
|
copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
|
|
31
31
|
request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
|
|
32
|
+
testUrl(url: string, options?: {
|
|
33
|
+
traceContext?: MediaTraceContext;
|
|
34
|
+
}): Promise<void>;
|
|
32
35
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
33
36
|
resolveInitialAuth: () => Auth;
|
|
34
37
|
get chunkHashAlgorithm(): ChunkHashAlgorithm;
|
|
@@ -167,6 +167,9 @@ export interface MediaApi {
|
|
|
167
167
|
appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
168
168
|
copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
|
|
169
169
|
request: (path: string, options: MediaStoreRequestOptions, controller?: AbortController) => Promise<Response>;
|
|
170
|
+
testUrl: (url: string, options?: {
|
|
171
|
+
traceContext?: MediaTraceContext;
|
|
172
|
+
}) => Promise<void>;
|
|
170
173
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
171
174
|
resolveInitialAuth: () => Auth;
|
|
172
175
|
}
|
|
@@ -6,6 +6,7 @@ export declare function waitPromise(timeout: number): Promise<void>;
|
|
|
6
6
|
export declare function isAbortedRequestError(err: any): boolean;
|
|
7
7
|
export declare function isFetchNetworkError(err: any): err is TypeError;
|
|
8
8
|
export declare function isRateLimitedError(error: Error | undefined): boolean;
|
|
9
|
+
export declare const extendTraceContext: (traceContext?: MediaTraceContext) => Required<MediaTraceContext> | undefined;
|
|
9
10
|
export declare const ZipkinHeaderKeys: {
|
|
10
11
|
traceId: string;
|
|
11
12
|
spanId: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Auth } from '@atlaskit/media-core';
|
|
2
2
|
import type { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
|
|
4
4
|
export type RequestParams = {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.3.1",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@atlaskit/media-core": "^34.3.0",
|
|
58
58
|
"@atlaskit/media-state": "^1.1.0",
|
|
59
59
|
"@atlaskit/ssr": "*",
|
|
60
|
-
"@atlaskit/tokens": "^2.
|
|
60
|
+
"@atlaskit/tokens": "^2.4.0",
|
|
61
61
|
"@atlassian/feature-flags-test-utils": "0.2.3",
|
|
62
62
|
"@emotion/react": "^11.7.1",
|
|
63
63
|
"@types/deep-equal": "^1.0.1",
|
|
@@ -81,9 +81,6 @@
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"platform-feature-flags": {
|
|
84
|
-
"platform.media-card-performance-observer_a803k": {
|
|
85
|
-
"type": "boolean"
|
|
86
|
-
},
|
|
87
84
|
"platform_media_cdn_single_host": {
|
|
88
85
|
"type": "boolean"
|
|
89
86
|
},
|