@atlaskit/media-client 35.3.1 → 35.3.3
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 +15 -0
- package/dist/cjs/client/media-store/MediaStore.js +11 -3
- package/dist/cjs/utils/getDocument.js +15 -0
- package/dist/cjs/utils/getNavigator.js +15 -0
- package/dist/cjs/utils/mediaCdn.js +1 -2
- package/dist/cjs/utils/pathBasedUrl.js +43 -0
- package/dist/cjs/utils/request/index.js +50 -2
- package/dist/es2019/client/media-store/MediaStore.js +8 -0
- package/dist/es2019/utils/getDocument.js +9 -0
- package/dist/es2019/utils/getNavigator.js +9 -0
- package/dist/es2019/utils/mediaCdn.js +1 -2
- package/dist/es2019/utils/pathBasedUrl.js +35 -0
- package/dist/es2019/utils/request/index.js +33 -1
- package/dist/esm/client/media-store/MediaStore.js +11 -3
- package/dist/esm/utils/getDocument.js +9 -0
- package/dist/esm/utils/getNavigator.js +9 -0
- package/dist/esm/utils/mediaCdn.js +1 -2
- package/dist/esm/utils/pathBasedUrl.js +35 -0
- package/dist/esm/utils/request/index.js +51 -3
- package/dist/types/utils/getDocument.d.ts +2 -0
- package/dist/types/utils/getNavigator.d.ts +2 -0
- package/dist/types/utils/pathBasedUrl.d.ts +2 -0
- package/dist/types-ts4.5/utils/getDocument.d.ts +2 -0
- package/dist/types-ts4.5/utils/getNavigator.d.ts +2 -0
- package/dist/types-ts4.5/utils/pathBasedUrl.d.ts +2 -0
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 35.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`f03a6554f340c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f03a6554f340c) -
|
|
8
|
+
Fixed the resolution of path based routing in SSR
|
|
9
|
+
|
|
10
|
+
## 35.3.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`b87ad4064e4f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b87ad4064e4f8) -
|
|
15
|
+
Added path based routing support to media client behind a feature flag and added retry logic for
|
|
16
|
+
serverUnexpectedError for Edge due to hot
|
|
17
|
+
|
|
3
18
|
## 35.3.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -17,6 +17,8 @@ var _request3 = require("../../utils/request");
|
|
|
17
17
|
var _helpers = require("../../utils/request/helpers");
|
|
18
18
|
var _mediaCdn = require("../../utils/mediaCdn");
|
|
19
19
|
var _resolveAuth = require("./resolveAuth");
|
|
20
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
21
|
+
var _pathBasedUrl = require("../../utils/pathBasedUrl");
|
|
20
22
|
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; }
|
|
21
23
|
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) { (0, _defineProperty2.default)(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; }
|
|
22
24
|
var MEDIA_API_REGION = 'media-api-region';
|
|
@@ -409,6 +411,9 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
409
411
|
auth: auth
|
|
410
412
|
};
|
|
411
413
|
var imageEndpoint = cdnFeatureFlag('image');
|
|
414
|
+
if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
|
|
415
|
+
return (0, _pathBasedUrl.mapToPathBasedUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
|
|
416
|
+
}
|
|
412
417
|
return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
|
|
413
418
|
}
|
|
414
419
|
}, {
|
|
@@ -926,7 +931,10 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
926
931
|
if (useMediaCdn) {
|
|
927
932
|
url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
|
|
928
933
|
}
|
|
929
|
-
|
|
934
|
+
if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
|
|
935
|
+
url = (0, _pathBasedUrl.mapToPathBasedUrl)(url);
|
|
936
|
+
}
|
|
937
|
+
_context16.next = 20;
|
|
930
938
|
return (0, _request3.request)(url, {
|
|
931
939
|
method: method,
|
|
932
940
|
endpoint: endpoint,
|
|
@@ -937,12 +945,12 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
937
945
|
clientOptions: clientOptions,
|
|
938
946
|
traceContext: extendedTraceContext
|
|
939
947
|
}, controller);
|
|
940
|
-
case
|
|
948
|
+
case 20:
|
|
941
949
|
response = _context16.sent;
|
|
942
950
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
943
951
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
944
952
|
return _context16.abrupt("return", response);
|
|
945
|
-
case
|
|
953
|
+
case 24:
|
|
946
954
|
case "end":
|
|
947
955
|
return _context16.stop();
|
|
948
956
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = function _default() {
|
|
8
|
+
if (typeof window === 'undefined') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof window.document === 'undefined') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return window.document;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = function _default() {
|
|
8
|
+
if (typeof window === 'undefined') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof window.navigator === 'undefined') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return window.navigator;
|
|
15
|
+
};
|
|
@@ -19,8 +19,7 @@ var MEDIA_CDN_MAP = exports.MEDIA_CDN_MAP = {
|
|
|
19
19
|
// Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
|
|
20
20
|
var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
|
|
21
21
|
function isCDNEnabled() {
|
|
22
|
-
|
|
23
|
-
return (0, _isCommercial.isCommercial)() && !isIsolatedCloudWithDisabledCDN && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery');
|
|
22
|
+
return (0, _isCommercial.isCommercial)() && !(0, _atlassianContext.isIsolatedCloud)() && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery') && !(0, _platformFeatureFlags.fg)('platform_media_path_based_route');
|
|
24
23
|
}
|
|
25
24
|
function mapToMediaCdnUrl(url, token) {
|
|
26
25
|
var _token$length;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.mapRetryUrlToPathBasedUrl = mapRetryUrlToPathBasedUrl;
|
|
8
|
+
exports.mapToPathBasedUrl = mapToPathBasedUrl;
|
|
9
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
|
+
var _getDocument3 = _interopRequireDefault(require("./getDocument"));
|
|
11
|
+
function getRelativeUrl(absoluteUrl) {
|
|
12
|
+
var url = new URL(absoluteUrl);
|
|
13
|
+
return "".concat(url.pathname).concat(url.search).concat(url.hash);
|
|
14
|
+
}
|
|
15
|
+
function mapToPathBasedUrl(url) {
|
|
16
|
+
if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
|
|
17
|
+
var _getDocument;
|
|
18
|
+
var parsedUrl = new URL(url);
|
|
19
|
+
parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
|
|
20
|
+
var location = (_getDocument = (0, _getDocument3.default)()) === null || _getDocument === void 0 ? void 0 : _getDocument.location;
|
|
21
|
+
|
|
22
|
+
// in this case we are most likely in SSR / a non browser environment so just return a relative URL
|
|
23
|
+
if (!location) {
|
|
24
|
+
return getRelativeUrl(url);
|
|
25
|
+
}
|
|
26
|
+
parsedUrl.host = location.host;
|
|
27
|
+
return parsedUrl.toString();
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
function mapRetryUrlToPathBasedUrl(url) {
|
|
32
|
+
var _getDocument$location, _getDocument2;
|
|
33
|
+
var parsedUrl = new URL(url);
|
|
34
|
+
parsedUrl.host = (_getDocument$location = (_getDocument2 = (0, _getDocument3.default)()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
|
|
35
|
+
|
|
36
|
+
// remove CDN from the URL for retry if it exists
|
|
37
|
+
var pathname = parsedUrl.pathname;
|
|
38
|
+
if (pathname.endsWith('/cdn')) {
|
|
39
|
+
parsedUrl.pathname = pathname.replace('/cdn', '');
|
|
40
|
+
}
|
|
41
|
+
parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
|
|
42
|
+
return parsedUrl;
|
|
43
|
+
}
|
|
@@ -30,9 +30,15 @@ Object.defineProperty(exports, "isRequestError", {
|
|
|
30
30
|
});
|
|
31
31
|
exports.request = request;
|
|
32
32
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
33
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
33
34
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
34
35
|
var _errors = require("./errors");
|
|
35
36
|
var _helpers = require("./helpers");
|
|
37
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
38
|
+
var _pathBasedUrl = require("../pathBasedUrl");
|
|
39
|
+
var _getNavigator3 = _interopRequireDefault(require("../getNavigator"));
|
|
40
|
+
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; }
|
|
41
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
36
42
|
function request(_x) {
|
|
37
43
|
return _request.apply(this, arguments);
|
|
38
44
|
}
|
|
@@ -53,6 +59,9 @@ function _request() {
|
|
|
53
59
|
retryOptions,
|
|
54
60
|
metadata,
|
|
55
61
|
doFetch,
|
|
62
|
+
shouldRetryError,
|
|
63
|
+
_getNavigator2,
|
|
64
|
+
doFetchWithPathBasedUrl,
|
|
56
65
|
_args = arguments;
|
|
57
66
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
58
67
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -76,12 +85,51 @@ function _request() {
|
|
|
76
85
|
signal: controller && controller.signal
|
|
77
86
|
}).then((0, _helpers.createProcessFetchResponse)(metadata));
|
|
78
87
|
};
|
|
88
|
+
if (!(0, _platformFeatureFlags.fg)('platform_media_retry_edge_error')) {
|
|
89
|
+
_context.next = 20;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
shouldRetryError = function shouldRetryError(err) {
|
|
93
|
+
var _getNavigator;
|
|
94
|
+
if ((0, _helpers.isFetchNetworkError)(err) && (_getNavigator = (0, _getNavigator3.default)()) !== null && _getNavigator !== void 0 && _getNavigator.userAgent.includes('Edg/')) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return (0, _helpers.defaultShouldRetryError)(err);
|
|
98
|
+
};
|
|
99
|
+
_context.prev = 8;
|
|
100
|
+
_context.next = 11;
|
|
101
|
+
return (0, _helpers.fetchRetry)(doFetch, metadata, _objectSpread(_objectSpread({}, retryOptions), {}, {
|
|
102
|
+
shouldRetryError: shouldRetryError
|
|
103
|
+
}));
|
|
104
|
+
case 11:
|
|
105
|
+
return _context.abrupt("return", _context.sent);
|
|
106
|
+
case 14:
|
|
107
|
+
_context.prev = 14;
|
|
108
|
+
_context.t0 = _context["catch"](8);
|
|
109
|
+
if (!((0, _helpers.isFetchNetworkError)(_context.t0) && (_getNavigator2 = (0, _getNavigator3.default)()) !== null && _getNavigator2 !== void 0 && _getNavigator2.userAgent.includes('Edg/'))) {
|
|
110
|
+
_context.next = 19;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
doFetchWithPathBasedUrl = function doFetchWithPathBasedUrl() {
|
|
114
|
+
return fetch((0, _helpers.createUrl)((0, _pathBasedUrl.mapRetryUrlToPathBasedUrl)(url).toString(), {
|
|
115
|
+
params: params
|
|
116
|
+
}), {
|
|
117
|
+
method: method,
|
|
118
|
+
body: body,
|
|
119
|
+
headers: (0, _helpers.extendHeaders)(headers, auth, traceContext),
|
|
120
|
+
signal: controller && controller.signal
|
|
121
|
+
}).then((0, _helpers.createProcessFetchResponse)(metadata));
|
|
122
|
+
};
|
|
123
|
+
return _context.abrupt("return", (0, _helpers.fetchRetry)(doFetchWithPathBasedUrl, metadata, retryOptions));
|
|
124
|
+
case 19:
|
|
125
|
+
throw _context.t0;
|
|
126
|
+
case 20:
|
|
79
127
|
return _context.abrupt("return", (0, _helpers.fetchRetry)(doFetch, metadata, retryOptions));
|
|
80
|
-
case
|
|
128
|
+
case 21:
|
|
81
129
|
case "end":
|
|
82
130
|
return _context.stop();
|
|
83
131
|
}
|
|
84
|
-
}, _callee);
|
|
132
|
+
}, _callee, null, [[8, 14]]);
|
|
85
133
|
}));
|
|
86
134
|
return _request.apply(this, arguments);
|
|
87
135
|
}
|
|
@@ -7,6 +7,8 @@ import { createUrl, createMapResponseToJson, createMapResponseToBlob, defaultSho
|
|
|
7
7
|
import { isCDNEnabled, mapToMediaCdnUrl } from '../../utils/mediaCdn';
|
|
8
8
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
9
9
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
10
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
import { mapToPathBasedUrl } from '../../utils/pathBasedUrl';
|
|
10
12
|
const MEDIA_API_REGION = 'media-api-region';
|
|
11
13
|
const MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
12
14
|
const extendImageParams = (params, fetchMaxRes = false) => {
|
|
@@ -266,6 +268,9 @@ export class MediaStore {
|
|
|
266
268
|
auth
|
|
267
269
|
};
|
|
268
270
|
const imageEndpoint = cdnFeatureFlag('image');
|
|
271
|
+
if (fg('platform_media_path_based_route')) {
|
|
272
|
+
return mapToPathBasedUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options));
|
|
273
|
+
}
|
|
269
274
|
return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options), auth.token);
|
|
270
275
|
}
|
|
271
276
|
async getFileBinary(id, collectionName, abortController, maxAge = FILE_CACHE_MAX_AGE) {
|
|
@@ -561,6 +566,9 @@ export class MediaStore {
|
|
|
561
566
|
if (useMediaCdn) {
|
|
562
567
|
url = mapToMediaCdnUrl(url, auth.token);
|
|
563
568
|
}
|
|
569
|
+
if (fg('platform_media_path_based_route')) {
|
|
570
|
+
url = mapToPathBasedUrl(url);
|
|
571
|
+
}
|
|
564
572
|
const response = await request(url, {
|
|
565
573
|
method,
|
|
566
574
|
endpoint,
|
|
@@ -11,8 +11,7 @@ export const MEDIA_CDN_MAP = {
|
|
|
11
11
|
// Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
|
|
12
12
|
const MEDIA_TOKEN_LENGTH_LIMIT = 7000;
|
|
13
13
|
export function isCDNEnabled() {
|
|
14
|
-
|
|
15
|
-
return isCommercial() && !isIsolatedCloudWithDisabledCDN && fg('platform_media_cdn_delivery');
|
|
14
|
+
return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
|
|
16
15
|
}
|
|
17
16
|
export function mapToMediaCdnUrl(url, token) {
|
|
18
17
|
var _token$length;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import getDocument from './getDocument';
|
|
3
|
+
function getRelativeUrl(absoluteUrl) {
|
|
4
|
+
const url = new URL(absoluteUrl);
|
|
5
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
6
|
+
}
|
|
7
|
+
export function mapToPathBasedUrl(url) {
|
|
8
|
+
if (fg('platform_media_path_based_route')) {
|
|
9
|
+
var _getDocument;
|
|
10
|
+
const parsedUrl = new URL(url);
|
|
11
|
+
parsedUrl.pathname = `/media-api${parsedUrl.pathname}`;
|
|
12
|
+
const location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location;
|
|
13
|
+
|
|
14
|
+
// in this case we are most likely in SSR / a non browser environment so just return a relative URL
|
|
15
|
+
if (!location) {
|
|
16
|
+
return getRelativeUrl(url);
|
|
17
|
+
}
|
|
18
|
+
parsedUrl.host = location.host;
|
|
19
|
+
return parsedUrl.toString();
|
|
20
|
+
}
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
export function mapRetryUrlToPathBasedUrl(url) {
|
|
24
|
+
var _getDocument$location, _getDocument2;
|
|
25
|
+
const parsedUrl = new URL(url);
|
|
26
|
+
parsedUrl.host = (_getDocument$location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
|
|
27
|
+
|
|
28
|
+
// remove CDN from the URL for retry if it exists
|
|
29
|
+
const pathname = parsedUrl.pathname;
|
|
30
|
+
if (pathname.endsWith('/cdn')) {
|
|
31
|
+
parsedUrl.pathname = pathname.replace('/cdn', '');
|
|
32
|
+
}
|
|
33
|
+
parsedUrl.pathname = `/media-api${parsedUrl.pathname}`;
|
|
34
|
+
return parsedUrl;
|
|
35
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { RequestError, isRequestError } from './errors';
|
|
2
2
|
export { isRateLimitedError, createRequestErrorReason } from './helpers';
|
|
3
|
-
import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders } from './helpers';
|
|
3
|
+
import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders, isFetchNetworkError, defaultShouldRetryError } from './helpers';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
+
import { mapRetryUrlToPathBasedUrl } from '../pathBasedUrl';
|
|
6
|
+
import getNavigator from '../getNavigator';
|
|
4
7
|
export async function request(url, options = {}, controller) {
|
|
5
8
|
const {
|
|
6
9
|
method = 'GET',
|
|
@@ -30,5 +33,34 @@ export async function request(url, options = {}, controller) {
|
|
|
30
33
|
headers: extendHeaders(headers, auth, traceContext),
|
|
31
34
|
signal: controller && controller.signal
|
|
32
35
|
}).then(createProcessFetchResponse(metadata));
|
|
36
|
+
if (fg('platform_media_retry_edge_error')) {
|
|
37
|
+
const shouldRetryError = err => {
|
|
38
|
+
var _getNavigator;
|
|
39
|
+
if (isFetchNetworkError(err) && (_getNavigator = getNavigator()) !== null && _getNavigator !== void 0 && _getNavigator.userAgent.includes('Edg/')) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return defaultShouldRetryError(err);
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
return await fetchRetry(doFetch, metadata, {
|
|
46
|
+
...retryOptions,
|
|
47
|
+
shouldRetryError
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
var _getNavigator2;
|
|
51
|
+
if (isFetchNetworkError(error) && (_getNavigator2 = getNavigator()) !== null && _getNavigator2 !== void 0 && _getNavigator2.userAgent.includes('Edg/')) {
|
|
52
|
+
const doFetchWithPathBasedUrl = () => fetch(createUrl(mapRetryUrlToPathBasedUrl(url).toString(), {
|
|
53
|
+
params
|
|
54
|
+
}), {
|
|
55
|
+
method,
|
|
56
|
+
body,
|
|
57
|
+
headers: extendHeaders(headers, auth, traceContext),
|
|
58
|
+
signal: controller && controller.signal
|
|
59
|
+
}).then(createProcessFetchResponse(metadata));
|
|
60
|
+
return fetchRetry(doFetchWithPathBasedUrl, metadata, retryOptions);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
33
65
|
return fetchRetry(doFetch, metadata, retryOptions);
|
|
34
66
|
}
|
|
@@ -13,6 +13,8 @@ import { createUrl, createMapResponseToJson, createMapResponseToBlob, defaultSho
|
|
|
13
13
|
import { isCDNEnabled, mapToMediaCdnUrl } from '../../utils/mediaCdn';
|
|
14
14
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
15
15
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
16
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
17
|
+
import { mapToPathBasedUrl } from '../../utils/pathBasedUrl';
|
|
16
18
|
var MEDIA_API_REGION = 'media-api-region';
|
|
17
19
|
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
18
20
|
var extendImageParams = function extendImageParams(params) {
|
|
@@ -403,6 +405,9 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
403
405
|
auth: auth
|
|
404
406
|
};
|
|
405
407
|
var imageEndpoint = cdnFeatureFlag('image');
|
|
408
|
+
if (fg('platform_media_path_based_route')) {
|
|
409
|
+
return mapToPathBasedUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
|
|
410
|
+
}
|
|
406
411
|
return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
|
|
407
412
|
}
|
|
408
413
|
}, {
|
|
@@ -920,7 +925,10 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
920
925
|
if (useMediaCdn) {
|
|
921
926
|
url = mapToMediaCdnUrl(url, auth.token);
|
|
922
927
|
}
|
|
923
|
-
|
|
928
|
+
if (fg('platform_media_path_based_route')) {
|
|
929
|
+
url = mapToPathBasedUrl(url);
|
|
930
|
+
}
|
|
931
|
+
_context16.next = 20;
|
|
924
932
|
return _request(url, {
|
|
925
933
|
method: method,
|
|
926
934
|
endpoint: endpoint,
|
|
@@ -931,12 +939,12 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
931
939
|
clientOptions: clientOptions,
|
|
932
940
|
traceContext: extendedTraceContext
|
|
933
941
|
}, controller);
|
|
934
|
-
case
|
|
942
|
+
case 20:
|
|
935
943
|
response = _context16.sent;
|
|
936
944
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
937
945
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
938
946
|
return _context16.abrupt("return", response);
|
|
939
|
-
case
|
|
947
|
+
case 24:
|
|
940
948
|
case "end":
|
|
941
949
|
return _context16.stop();
|
|
942
950
|
}
|
|
@@ -11,8 +11,7 @@ export var MEDIA_CDN_MAP = {
|
|
|
11
11
|
// Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
|
|
12
12
|
var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
|
|
13
13
|
export function isCDNEnabled() {
|
|
14
|
-
|
|
15
|
-
return isCommercial() && !isIsolatedCloudWithDisabledCDN && fg('platform_media_cdn_delivery');
|
|
14
|
+
return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
|
|
16
15
|
}
|
|
17
16
|
export function mapToMediaCdnUrl(url, token) {
|
|
18
17
|
var _token$length;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import getDocument from './getDocument';
|
|
3
|
+
function getRelativeUrl(absoluteUrl) {
|
|
4
|
+
var url = new URL(absoluteUrl);
|
|
5
|
+
return "".concat(url.pathname).concat(url.search).concat(url.hash);
|
|
6
|
+
}
|
|
7
|
+
export function mapToPathBasedUrl(url) {
|
|
8
|
+
if (fg('platform_media_path_based_route')) {
|
|
9
|
+
var _getDocument;
|
|
10
|
+
var parsedUrl = new URL(url);
|
|
11
|
+
parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
|
|
12
|
+
var location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location;
|
|
13
|
+
|
|
14
|
+
// in this case we are most likely in SSR / a non browser environment so just return a relative URL
|
|
15
|
+
if (!location) {
|
|
16
|
+
return getRelativeUrl(url);
|
|
17
|
+
}
|
|
18
|
+
parsedUrl.host = location.host;
|
|
19
|
+
return parsedUrl.toString();
|
|
20
|
+
}
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
export function mapRetryUrlToPathBasedUrl(url) {
|
|
24
|
+
var _getDocument$location, _getDocument2;
|
|
25
|
+
var parsedUrl = new URL(url);
|
|
26
|
+
parsedUrl.host = (_getDocument$location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
|
|
27
|
+
|
|
28
|
+
// remove CDN from the URL for retry if it exists
|
|
29
|
+
var pathname = parsedUrl.pathname;
|
|
30
|
+
if (pathname.endsWith('/cdn')) {
|
|
31
|
+
parsedUrl.pathname = pathname.replace('/cdn', '');
|
|
32
|
+
}
|
|
33
|
+
parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
|
|
34
|
+
return parsedUrl;
|
|
35
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
3
6
|
export { RequestError, isRequestError } from './errors';
|
|
4
7
|
export { isRateLimitedError, createRequestErrorReason } from './helpers';
|
|
5
|
-
import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders } from './helpers';
|
|
8
|
+
import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders, isFetchNetworkError, defaultShouldRetryError } from './helpers';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
|
+
import { mapRetryUrlToPathBasedUrl } from '../pathBasedUrl';
|
|
11
|
+
import getNavigator from '../getNavigator';
|
|
6
12
|
export function request(_x) {
|
|
7
13
|
return _request.apply(this, arguments);
|
|
8
14
|
}
|
|
@@ -23,6 +29,9 @@ function _request() {
|
|
|
23
29
|
retryOptions,
|
|
24
30
|
metadata,
|
|
25
31
|
doFetch,
|
|
32
|
+
shouldRetryError,
|
|
33
|
+
_getNavigator2,
|
|
34
|
+
doFetchWithPathBasedUrl,
|
|
26
35
|
_args = arguments;
|
|
27
36
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
28
37
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -46,12 +55,51 @@ function _request() {
|
|
|
46
55
|
signal: controller && controller.signal
|
|
47
56
|
}).then(createProcessFetchResponse(metadata));
|
|
48
57
|
};
|
|
58
|
+
if (!fg('platform_media_retry_edge_error')) {
|
|
59
|
+
_context.next = 20;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
shouldRetryError = function shouldRetryError(err) {
|
|
63
|
+
var _getNavigator;
|
|
64
|
+
if (isFetchNetworkError(err) && (_getNavigator = getNavigator()) !== null && _getNavigator !== void 0 && _getNavigator.userAgent.includes('Edg/')) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return defaultShouldRetryError(err);
|
|
68
|
+
};
|
|
69
|
+
_context.prev = 8;
|
|
70
|
+
_context.next = 11;
|
|
71
|
+
return fetchRetry(doFetch, metadata, _objectSpread(_objectSpread({}, retryOptions), {}, {
|
|
72
|
+
shouldRetryError: shouldRetryError
|
|
73
|
+
}));
|
|
74
|
+
case 11:
|
|
75
|
+
return _context.abrupt("return", _context.sent);
|
|
76
|
+
case 14:
|
|
77
|
+
_context.prev = 14;
|
|
78
|
+
_context.t0 = _context["catch"](8);
|
|
79
|
+
if (!(isFetchNetworkError(_context.t0) && (_getNavigator2 = getNavigator()) !== null && _getNavigator2 !== void 0 && _getNavigator2.userAgent.includes('Edg/'))) {
|
|
80
|
+
_context.next = 19;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
doFetchWithPathBasedUrl = function doFetchWithPathBasedUrl() {
|
|
84
|
+
return fetch(createUrl(mapRetryUrlToPathBasedUrl(url).toString(), {
|
|
85
|
+
params: params
|
|
86
|
+
}), {
|
|
87
|
+
method: method,
|
|
88
|
+
body: body,
|
|
89
|
+
headers: extendHeaders(headers, auth, traceContext),
|
|
90
|
+
signal: controller && controller.signal
|
|
91
|
+
}).then(createProcessFetchResponse(metadata));
|
|
92
|
+
};
|
|
93
|
+
return _context.abrupt("return", fetchRetry(doFetchWithPathBasedUrl, metadata, retryOptions));
|
|
94
|
+
case 19:
|
|
95
|
+
throw _context.t0;
|
|
96
|
+
case 20:
|
|
49
97
|
return _context.abrupt("return", fetchRetry(doFetch, metadata, retryOptions));
|
|
50
|
-
case
|
|
98
|
+
case 21:
|
|
51
99
|
case "end":
|
|
52
100
|
return _context.stop();
|
|
53
101
|
}
|
|
54
|
-
}, _callee);
|
|
102
|
+
}, _callee, null, [[8, 14]]);
|
|
55
103
|
}));
|
|
56
104
|
return _request.apply(this, arguments);
|
|
57
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "35.3.
|
|
3
|
+
"version": "35.3.3",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -22,11 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"atlaskit:src": "src/index.ts",
|
|
25
|
-
"af:exports": {
|
|
26
|
-
"./constants": "./src/constants.ts",
|
|
27
|
-
"./test-helpers": "./src/test-helpers/index.ts",
|
|
28
|
-
".": "./src/index.ts"
|
|
29
|
-
},
|
|
30
25
|
"atlassian": {
|
|
31
26
|
"team": "Media Exif",
|
|
32
27
|
"website": {
|
|
@@ -58,7 +53,7 @@
|
|
|
58
53
|
"@atlaskit/media-core": "^37.0.0",
|
|
59
54
|
"@atlaskit/media-state": "^1.8.0",
|
|
60
55
|
"@atlaskit/ssr": "workspace:^",
|
|
61
|
-
"@atlaskit/tokens": "^6.
|
|
56
|
+
"@atlaskit/tokens": "^6.3.0",
|
|
62
57
|
"@atlassian/feature-flags-test-utils": "^0.3.0",
|
|
63
58
|
"@emotion/react": "^11.7.1",
|
|
64
59
|
"@types/deep-equal": "^1.0.1",
|
|
@@ -87,6 +82,12 @@
|
|
|
87
82
|
"platform_media_cdn_delivery": {
|
|
88
83
|
"type": "boolean"
|
|
89
84
|
},
|
|
85
|
+
"platform_media_path_based_route": {
|
|
86
|
+
"type": "boolean"
|
|
87
|
+
},
|
|
88
|
+
"platform_media_retry_edge_error": {
|
|
89
|
+
"type": "boolean"
|
|
90
|
+
},
|
|
90
91
|
"platform_disable_isolated_cloud_media_cdn_delivery": {
|
|
91
92
|
"type": "boolean"
|
|
92
93
|
}
|