@atlaskit/media-client 35.3.2 → 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 CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## 35.3.2
4
11
 
5
12
  ### Patch Changes
@@ -411,6 +411,9 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
411
411
  auth: auth
412
412
  };
413
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
+ }
414
417
  return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
415
418
  }
416
419
  }, {
@@ -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
- var isIsolatedCloudWithDisabledCDN = (0, _platformFeatureFlags.fg)('platform_disable_isolated_cloud_media_cdn_delivery') && (0, _atlassianContext.isIsolatedCloud)();
23
- return (0, _isCommercial.isCommercial)() && !isIsolatedCloudWithDisabledCDN && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery') && !(0, _platformFeatureFlags.fg)('platform_media_path_based_route');
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;
@@ -8,20 +8,30 @@ exports.mapRetryUrlToPathBasedUrl = mapRetryUrlToPathBasedUrl;
8
8
  exports.mapToPathBasedUrl = mapToPathBasedUrl;
9
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
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
+ }
11
15
  function mapToPathBasedUrl(url) {
12
16
  if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
13
- var _getDocument$location, _getDocument;
17
+ var _getDocument;
14
18
  var parsedUrl = new URL(url);
15
- parsedUrl.host = (_getDocument$location = (_getDocument = (0, _getDocument3.default)()) === null || _getDocument === void 0 ? void 0 : _getDocument.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : parsedUrl.host;
16
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;
17
27
  return parsedUrl.toString();
18
28
  }
19
29
  return url;
20
30
  }
21
31
  function mapRetryUrlToPathBasedUrl(url) {
22
- var _getDocument$location2, _getDocument2;
32
+ var _getDocument$location, _getDocument2;
23
33
  var parsedUrl = new URL(url);
24
- parsedUrl.host = (_getDocument$location2 = (_getDocument2 = (0, _getDocument3.default)()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location2 !== void 0 ? _getDocument$location2 : parsedUrl.host;
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 : '';
25
35
 
26
36
  // remove CDN from the URL for retry if it exists
27
37
  var pathname = parsedUrl.pathname;
@@ -268,6 +268,9 @@ export class MediaStore {
268
268
  auth
269
269
  };
270
270
  const imageEndpoint = cdnFeatureFlag('image');
271
+ if (fg('platform_media_path_based_route')) {
272
+ return mapToPathBasedUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options));
273
+ }
271
274
  return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options), auth.token);
272
275
  }
273
276
  async getFileBinary(id, collectionName, abortController, maxAge = FILE_CACHE_MAX_AGE) {
@@ -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
- const isIsolatedCloudWithDisabledCDN = fg('platform_disable_isolated_cloud_media_cdn_delivery') && isIsolatedCloud();
15
- return isCommercial() && !isIsolatedCloudWithDisabledCDN && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
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;
@@ -1,19 +1,29 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import getDocument from './getDocument';
3
+ function getRelativeUrl(absoluteUrl) {
4
+ const url = new URL(absoluteUrl);
5
+ return `${url.pathname}${url.search}${url.hash}`;
6
+ }
3
7
  export function mapToPathBasedUrl(url) {
4
8
  if (fg('platform_media_path_based_route')) {
5
- var _getDocument$location, _getDocument;
9
+ var _getDocument;
6
10
  const parsedUrl = new URL(url);
7
- parsedUrl.host = (_getDocument$location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : parsedUrl.host;
8
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;
9
19
  return parsedUrl.toString();
10
20
  }
11
21
  return url;
12
22
  }
13
23
  export function mapRetryUrlToPathBasedUrl(url) {
14
- var _getDocument$location2, _getDocument2;
24
+ var _getDocument$location, _getDocument2;
15
25
  const parsedUrl = new URL(url);
16
- parsedUrl.host = (_getDocument$location2 = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location2 !== void 0 ? _getDocument$location2 : parsedUrl.host;
26
+ parsedUrl.host = (_getDocument$location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
17
27
 
18
28
  // remove CDN from the URL for retry if it exists
19
29
  const pathname = parsedUrl.pathname;
@@ -405,6 +405,9 @@ export var MediaStore = /*#__PURE__*/function () {
405
405
  auth: auth
406
406
  };
407
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
+ }
408
411
  return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
409
412
  }
410
413
  }, {
@@ -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
- var isIsolatedCloudWithDisabledCDN = fg('platform_disable_isolated_cloud_media_cdn_delivery') && isIsolatedCloud();
15
- return isCommercial() && !isIsolatedCloudWithDisabledCDN && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
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;
@@ -1,19 +1,29 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
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
+ }
3
7
  export function mapToPathBasedUrl(url) {
4
8
  if (fg('platform_media_path_based_route')) {
5
- var _getDocument$location, _getDocument;
9
+ var _getDocument;
6
10
  var parsedUrl = new URL(url);
7
- parsedUrl.host = (_getDocument$location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : parsedUrl.host;
8
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;
9
19
  return parsedUrl.toString();
10
20
  }
11
21
  return url;
12
22
  }
13
23
  export function mapRetryUrlToPathBasedUrl(url) {
14
- var _getDocument$location2, _getDocument2;
24
+ var _getDocument$location, _getDocument2;
15
25
  var parsedUrl = new URL(url);
16
- parsedUrl.host = (_getDocument$location2 = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location2 !== void 0 ? _getDocument$location2 : parsedUrl.host;
26
+ parsedUrl.host = (_getDocument$location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
17
27
 
18
28
  // remove CDN from the URL for retry if it exists
19
29
  var pathname = parsedUrl.pathname;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "35.3.2",
3
+ "version": "35.3.3",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"