@atlaskit/media-client 28.0.0 → 28.0.2

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,21 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 28.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149473](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/149473)
8
+ [`4c74b6716ded9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4c74b6716ded9) -
9
+ Remove global jest override to fix runtime type error in jest tests
10
+
11
+ ## 28.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#147039](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/147039)
16
+ [`f29b4d6055c5e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f29b4d6055c5e) -
17
+ fix media cdn errors caused by excessive media token length
18
+
3
19
  ## 28.0.0
4
20
 
5
21
  ### Major Changes
@@ -294,7 +294,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
294
294
  auth: auth
295
295
  };
296
296
  var imageEndpoint = !(0, _isFedRamp.isFedRamp)() && (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
297
- return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
297
+ return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
298
298
  }
299
299
  }, {
300
300
  key: "getFileBinary",
@@ -366,7 +366,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
366
366
  auth: auth
367
367
  };
368
368
  binaryEndpoint = !(0, _isFedRamp.isFedRamp)() && (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
369
- return _context6.abrupt("return", (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options)));
369
+ return _context6.abrupt("return", (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options), auth.token));
370
370
  case 7:
371
371
  case "end":
372
372
  return _context6.stop();
@@ -406,7 +406,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
406
406
  },
407
407
  auth: auth
408
408
  };
409
- return _context7.abrupt("return", (0, _helpers.createUrl)(artifactUrl, options));
409
+ return _context7.abrupt("return", (0, _helpers.createUrl)((0, _mediaCdn.mapToMediaCdnUrl)(artifactUrl, auth.token), options));
410
410
  case 8:
411
411
  case "end":
412
412
  return _context7.stop();
@@ -627,7 +627,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
627
627
  }) : undefined;
628
628
  url = "".concat(auth.baseUrl).concat(path);
629
629
  if (useMediaCdn) {
630
- url = (0, _mediaCdn.mapToMediaCdnUrl)(url);
630
+ url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
631
631
  }
632
632
  _context12.next = 13;
633
633
  return (0, _request3.request)(url, {
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getArtifactUrl = void 0;
7
7
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
- var _mediaCdn = require("../utils/mediaCdn");
9
8
  var _isFedRamp = require("../utils/isFedRamp");
10
9
  var getArtifactUrl = exports.getArtifactUrl = function getArtifactUrl(artifacts, prop) {
11
10
  var _artifacts$prop2;
12
11
  if (!(0, _isFedRamp.isFedRamp)() && (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery')) {
13
12
  var _artifacts$prop;
14
- return (0, _mediaCdn.mapToMediaCdnUrl)("".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn"));
13
+ return "".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn");
15
14
  }
16
15
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
17
16
  };
@@ -11,9 +11,19 @@ var MEDIA_CDN_MAP = exports.MEDIA_CDN_MAP = {
11
11
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
12
12
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
13
13
  };
14
- function mapToMediaCdnUrl(url) {
14
+
15
+ // Cloudfront has a hard limit of 8,192 bytes
16
+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
17
+ // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
18
+ var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
19
+ function mapToMediaCdnUrl(url, token) {
20
+ var _token$length;
21
+ var tokenLength = (_token$length = token === null || token === void 0 ? void 0 : token.length) !== null && _token$length !== void 0 ? _token$length : 0;
22
+ if ((0, _isFedRamp.isFedRamp)() || tokenLength > MEDIA_TOKEN_LENGTH_LIMIT) {
23
+ return url;
24
+ }
15
25
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
16
- if (!(0, _isFedRamp.isFedRamp)() && (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') && (0, _platformFeatureFlags.fg)('platform.media-cdn-single-host')) {
26
+ if ((0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') && (0, _platformFeatureFlags.fg)('platform.media-cdn-single-host')) {
17
27
  try {
18
28
  var parsedUrl = new URL(url);
19
29
  var cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
@@ -189,7 +189,7 @@ export class MediaStore {
189
189
  auth
190
190
  };
191
191
  const imageEndpoint = !isFedRamp() && fg('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
192
- return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options));
192
+ return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options), auth.token);
193
193
  }
194
194
  async getFileBinary(id, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
195
195
  const headers = {};
@@ -224,7 +224,7 @@ export class MediaStore {
224
224
  auth
225
225
  };
226
226
  const binaryEndpoint = !isFedRamp() && fg('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
227
- return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options));
227
+ return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options), auth.token);
228
228
  }
229
229
  async getArtifactURL(artifacts, artifactName, collectionName) {
230
230
  const artifactUrl = getArtifactUrl(artifacts, artifactName);
@@ -241,7 +241,7 @@ export class MediaStore {
241
241
  },
242
242
  auth
243
243
  };
244
- return createUrl(artifactUrl, options);
244
+ return createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options);
245
245
  }
246
246
  async getImage(id, params, controller, fetchMaxRes, traceContext) {
247
247
  // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
@@ -365,7 +365,7 @@ export class MediaStore {
365
365
  } : undefined;
366
366
  let url = `${auth.baseUrl}${path}`;
367
367
  if (useMediaCdn) {
368
- url = mapToMediaCdnUrl(url);
368
+ url = mapToMediaCdnUrl(url, auth.token);
369
369
  }
370
370
  const response = await request(url, {
371
371
  method,
@@ -1,11 +1,10 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
- import { mapToMediaCdnUrl } from '../utils/mediaCdn';
3
2
  import { isFedRamp } from '../utils/isFedRamp';
4
3
  export const getArtifactUrl = (artifacts, prop) => {
5
4
  var _artifacts$prop2;
6
5
  if (!isFedRamp() && fg('platform.media-cdn-delivery')) {
7
6
  var _artifacts$prop;
8
- return mapToMediaCdnUrl(`${(_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url}/cdn`);
7
+ return `${(_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url}/cdn`;
9
8
  }
10
9
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
11
10
  };
@@ -4,9 +4,19 @@ export const MEDIA_CDN_MAP = {
4
4
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
5
5
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
6
6
  };
7
- export function mapToMediaCdnUrl(url) {
7
+
8
+ // Cloudfront has a hard limit of 8,192 bytes
9
+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
10
+ // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
11
+ const MEDIA_TOKEN_LENGTH_LIMIT = 7000;
12
+ export function mapToMediaCdnUrl(url, token) {
13
+ var _token$length;
14
+ const tokenLength = (_token$length = token === null || token === void 0 ? void 0 : token.length) !== null && _token$length !== void 0 ? _token$length : 0;
15
+ if (isFedRamp() || tokenLength > MEDIA_TOKEN_LENGTH_LIMIT) {
16
+ return url;
17
+ }
8
18
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
9
- if (!isFedRamp() && fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
19
+ if (fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
10
20
  try {
11
21
  const parsedUrl = new URL(url);
12
22
  const cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
@@ -288,7 +288,7 @@ export var MediaStore = /*#__PURE__*/function () {
288
288
  auth: auth
289
289
  };
290
290
  var imageEndpoint = !isFedRamp() && fg('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
291
- return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
291
+ return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
292
292
  }
293
293
  }, {
294
294
  key: "getFileBinary",
@@ -360,7 +360,7 @@ export var MediaStore = /*#__PURE__*/function () {
360
360
  auth: auth
361
361
  };
362
362
  binaryEndpoint = !isFedRamp() && fg('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
363
- return _context6.abrupt("return", mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options)));
363
+ return _context6.abrupt("return", mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options), auth.token));
364
364
  case 7:
365
365
  case "end":
366
366
  return _context6.stop();
@@ -400,7 +400,7 @@ export var MediaStore = /*#__PURE__*/function () {
400
400
  },
401
401
  auth: auth
402
402
  };
403
- return _context7.abrupt("return", createUrl(artifactUrl, options));
403
+ return _context7.abrupt("return", createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options));
404
404
  case 8:
405
405
  case "end":
406
406
  return _context7.stop();
@@ -621,7 +621,7 @@ export var MediaStore = /*#__PURE__*/function () {
621
621
  }) : undefined;
622
622
  url = "".concat(auth.baseUrl).concat(path);
623
623
  if (useMediaCdn) {
624
- url = mapToMediaCdnUrl(url);
624
+ url = mapToMediaCdnUrl(url, auth.token);
625
625
  }
626
626
  _context12.next = 13;
627
627
  return _request(url, {
@@ -1,11 +1,10 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
- import { mapToMediaCdnUrl } from '../utils/mediaCdn';
3
2
  import { isFedRamp } from '../utils/isFedRamp';
4
3
  export var getArtifactUrl = function getArtifactUrl(artifacts, prop) {
5
4
  var _artifacts$prop2;
6
5
  if (!isFedRamp() && fg('platform.media-cdn-delivery')) {
7
6
  var _artifacts$prop;
8
- return mapToMediaCdnUrl("".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn"));
7
+ return "".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn");
9
8
  }
10
9
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
11
10
  };
@@ -4,9 +4,19 @@ export var MEDIA_CDN_MAP = {
4
4
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
5
5
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
6
6
  };
7
- export function mapToMediaCdnUrl(url) {
7
+
8
+ // Cloudfront has a hard limit of 8,192 bytes
9
+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
10
+ // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
11
+ var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
12
+ export function mapToMediaCdnUrl(url, token) {
13
+ var _token$length;
14
+ var tokenLength = (_token$length = token === null || token === void 0 ? void 0 : token.length) !== null && _token$length !== void 0 ? _token$length : 0;
15
+ if (isFedRamp() || tokenLength > MEDIA_TOKEN_LENGTH_LIMIT) {
16
+ return url;
17
+ }
8
18
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
9
- if (!isFedRamp() && fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
19
+ if (fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
10
20
  try {
11
21
  var parsedUrl = new URL(url);
12
22
  var cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
@@ -1,4 +1,4 @@
1
1
  export declare const MEDIA_CDN_MAP: {
2
2
  [key: string]: string;
3
3
  };
4
- export declare function mapToMediaCdnUrl(url: string): string;
4
+ export declare function mapToMediaCdnUrl(url: string, token: string): string;
@@ -1,4 +1,4 @@
1
1
  export declare const MEDIA_CDN_MAP: {
2
2
  [key: string]: string;
3
3
  };
4
- export declare function mapToMediaCdnUrl(url: string): string;
4
+ export declare function mapToMediaCdnUrl(url: string, token: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "28.0.0",
3
+ "version": "28.0.2",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@atlaskit/chunkinator": "^6.1.0",
38
- "@atlaskit/media-common": "^11.4.0",
38
+ "@atlaskit/media-common": "^11.5.0",
39
39
  "@atlaskit/platform-feature-flags": "0.3.0",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "dataloader": "^2.1.0",
@@ -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": "^1.59.0",
60
+ "@atlaskit/tokens": "^2.0.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",