@atlaskit/media-client 27.3.4 → 27.5.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 27.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#132649](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/132649)
8
+ [`ab55ae1b17d7d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ab55ae1b17d7d) -
9
+ add media cdn single host redirect
10
+
11
+ ## 27.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#130787](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130787)
16
+ [`64a680780dc57`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/64a680780dc57) -
17
+ Add performance observer metrics for Media Card to assist investigation into hot-110955
18
+
3
19
  ## 27.3.4
4
20
 
5
21
  ### Patch Changes
@@ -154,7 +154,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
154
154
  if (content instanceof Blob) {
155
155
  size = content.size;
156
156
  mimeType = content.type;
157
- if ((0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(content.type) || (0, _platformFeatureFlags.getBooleanFF)('platform.media-svg-rendering')) {
157
+ if ((0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(content.type) || (0, _platformFeatureFlags.fg)('platform.media-svg-rendering')) {
158
158
  preview = {
159
159
  value: content,
160
160
  origin: 'local'
@@ -10,13 +10,14 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _mediaCore = require("@atlaskit/media-core");
13
14
  var _mediaCommon = require("@atlaskit/media-common");
14
15
  var _constants = require("../../constants");
15
16
  var _artifacts = require("../../models/artifacts");
16
17
  var _request3 = require("../../utils/request");
17
18
  var _helpers = require("../../utils/request/helpers");
19
+ var _mediaCdn = require("../../utils/mediaCdn");
18
20
  var _resolveAuth = require("./resolveAuth");
19
- var _mediaCore = require("@atlaskit/media-core");
20
21
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
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; }
22
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; }
@@ -292,7 +293,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
292
293
  auth: auth
293
294
  };
294
295
  var imageEndpoint = (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
295
- return (0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options);
296
+ return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
296
297
  }
297
298
  }, {
298
299
  key: "getFileBinary",
@@ -324,7 +325,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
324
325
  'max-age': "".concat(maxAge)
325
326
  }
326
327
  });
327
- return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options).then((0, _helpers.createMapResponseToBlob)(metadata)));
328
+ return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, undefined, true).then((0, _helpers.createMapResponseToBlob)(metadata)));
328
329
  case 6:
329
330
  case "end":
330
331
  return _context5.stop();
@@ -364,7 +365,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
364
365
  auth: auth
365
366
  };
366
367
  binaryEndpoint = (0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
367
- return _context6.abrupt("return", (0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options));
368
+ return _context6.abrupt("return", (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options)));
368
369
  case 7:
369
370
  case "end":
370
371
  return _context6.stop();
@@ -441,9 +442,10 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
441
442
  },
442
443
  params: extendImageParams(params, fetchMaxRes),
443
444
  headers: headers,
444
- traceContext: traceContext
445
+ traceContext: traceContext,
446
+ addMediaClientParam: (0, _platformFeatureFlags.fg)('platform.media-card-performance-observer_lgc7b') && true
445
447
  });
446
- return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller).then((0, _helpers.createMapResponseToBlob)(metadata)));
448
+ return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller, true).then((0, _helpers.createMapResponseToBlob)(metadata)));
447
449
  case 7:
448
450
  case "end":
449
451
  return _context8.stop();
@@ -587,6 +589,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
587
589
  var _request2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(path) {
588
590
  var options,
589
591
  controller,
592
+ useMediaCdn,
590
593
  method,
591
594
  endpoint,
592
595
  authContext,
@@ -595,8 +598,11 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
595
598
  body,
596
599
  clientOptions,
597
600
  traceContext,
601
+ addMediaClientParam,
598
602
  auth,
603
+ clientId,
599
604
  extendedTraceContext,
605
+ url,
600
606
  response,
601
607
  _args12 = arguments;
602
608
  return _regenerator.default.wrap(function _callee12$(_context12) {
@@ -608,31 +614,39 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
608
614
  authContext: {}
609
615
  };
610
616
  controller = _args12.length > 2 ? _args12[2] : undefined;
611
- method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
612
- _context12.next = 5;
617
+ useMediaCdn = _args12.length > 3 ? _args12[3] : undefined;
618
+ method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam;
619
+ _context12.next = 6;
613
620
  return this.resolveAuth(authContext);
614
- case 5:
621
+ case 6:
615
622
  auth = _context12.sent;
623
+ clientId = (0, _mediaCore.isClientBasedAuth)(auth) ? auth.clientId : undefined;
616
624
  extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
617
625
  spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
618
626
  }) : undefined;
619
- _context12.next = 9;
620
- return (0, _request3.request)("".concat(auth.baseUrl).concat(path), {
627
+ url = "".concat(auth.baseUrl).concat(path);
628
+ if (useMediaCdn) {
629
+ url = (0, _mediaCdn.mapToMediaCdnUrl)(url);
630
+ }
631
+ _context12.next = 13;
632
+ return (0, _request3.request)(url, {
621
633
  method: method,
622
634
  endpoint: endpoint,
623
635
  auth: auth,
624
- params: params,
636
+ params: addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
637
+ clientId: clientId
638
+ }) : params,
625
639
  headers: headers,
626
640
  body: body,
627
641
  clientOptions: clientOptions,
628
642
  traceContext: extendedTraceContext
629
643
  }, controller);
630
- case 9:
644
+ case 13:
631
645
  response = _context12.sent;
632
646
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
633
647
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
634
648
  return _context12.abrupt("return", response);
635
- case 13:
649
+ case 17:
636
650
  case "end":
637
651
  return _context12.stop();
638
652
  }
@@ -5,11 +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");
8
9
  var getArtifactUrl = exports.getArtifactUrl = function getArtifactUrl(artifacts, prop) {
9
10
  var _artifacts$prop2;
10
11
  if ((0, _platformFeatureFlags.fg)('platform.media-cdn-delivery')) {
11
12
  var _artifacts$prop;
12
- return "".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn");
13
+ return (0, _mediaCdn.mapToMediaCdnUrl)("".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn"));
13
14
  }
14
15
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
15
16
  };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MEDIA_CDN_MAP = void 0;
7
+ exports.mapToMediaCdnUrl = mapToMediaCdnUrl;
8
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
+ var MEDIA_CDN_MAP = exports.MEDIA_CDN_MAP = {
10
+ 'api.media.atlassian.com': 'media-cdn.atlassian.com',
11
+ 'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
12
+ };
13
+ function mapToMediaCdnUrl(url) {
14
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
15
+ if ((0, _platformFeatureFlags.fg)('platform.media-cdn-delivery') && (0, _platformFeatureFlags.fg)('platform.media-cdn-single-host')) {
16
+ try {
17
+ var parsedUrl = new URL(url);
18
+ var cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
19
+
20
+ // If no mapping is found, return the original URL
21
+ if (!cdnHost) {
22
+ return url;
23
+ }
24
+
25
+ // Replace the host with the CDN host in the original URL
26
+ parsedUrl.host = cdnHost;
27
+ return parsedUrl.toString();
28
+ } catch (error) {
29
+ return url;
30
+ }
31
+ }
32
+ return url;
33
+ }
@@ -27,7 +27,7 @@ import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileSt
27
27
  import { PollingFunction } from '../../utils/polling';
28
28
  import { isEmptyFile } from '../../utils/detectEmptyFile';
29
29
  import { mediaStore } from '@atlaskit/media-state';
30
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
30
+ import { fg } from '@atlaskit/platform-feature-flags';
31
31
  export { isFileFetcherError, FileFetcherError } from './error';
32
32
  export class FileFetcherImpl {
33
33
  constructor(mediaApi, store = mediaStore) {
@@ -108,7 +108,7 @@ export class FileFetcherImpl {
108
108
  if (content instanceof Blob) {
109
109
  size = content.size;
110
110
  mimeType = content.type;
111
- if (isMimeTypeSupportedByBrowser(content.type) || getBooleanFF('platform.media-svg-rendering')) {
111
+ if (isMimeTypeSupportedByBrowser(content.type) || fg('platform.media-svg-rendering')) {
112
112
  preview = {
113
113
  value: content,
114
114
  origin: 'local'
@@ -1,9 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { isClientBasedAuth } from '@atlaskit/media-core';
2
3
  import { getRandomHex } from '@atlaskit/media-common';
3
4
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
4
5
  import { getArtifactUrl } from '../../models/artifacts';
5
6
  import { request } from '../../utils/request';
6
7
  import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
8
+ import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
7
9
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
8
10
  import { ChunkHashAlgorithm } from '@atlaskit/media-core';
9
11
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -186,7 +188,7 @@ export class MediaStore {
186
188
  auth
187
189
  };
188
190
  const imageEndpoint = fg('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
189
- return createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options);
191
+ return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options));
190
192
  }
191
193
  async getFileBinary(id, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
192
194
  const headers = {};
@@ -206,7 +208,7 @@ export class MediaStore {
206
208
  'max-age': `${maxAge}`
207
209
  }
208
210
  };
209
- return this.request(`/file/${id}/${binaryEndpoint}`, options).then(createMapResponseToBlob(metadata));
211
+ return this.request(`/file/${id}/${binaryEndpoint}`, options, undefined, true).then(createMapResponseToBlob(metadata));
210
212
  }
211
213
  async getFileBinaryURL(id, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
212
214
  const auth = await this.resolveAuth({
@@ -221,7 +223,7 @@ export class MediaStore {
221
223
  auth
222
224
  };
223
225
  const binaryEndpoint = fg('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
224
- return createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options);
226
+ return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options));
225
227
  }
226
228
  async getArtifactURL(artifacts, artifactName, collectionName) {
227
229
  const artifactUrl = getArtifactUrl(artifacts, artifactName);
@@ -259,9 +261,10 @@ export class MediaStore {
259
261
  },
260
262
  params: extendImageParams(params, fetchMaxRes),
261
263
  headers,
262
- traceContext
264
+ traceContext,
265
+ addMediaClientParam: fg('platform.media-card-performance-observer_lgc7b') && true
263
266
  };
264
- return this.request(`/file/${id}/${imageEndpoint}`, options, controller).then(createMapResponseToBlob(metadata));
267
+ return this.request(`/file/${id}/${imageEndpoint}`, options, controller, true).then(createMapResponseToBlob(metadata));
265
268
  }
266
269
  async getItems(ids, collectionName, traceContext) {
267
270
  const descriptors = ids.map(id => ({
@@ -341,7 +344,7 @@ export class MediaStore {
341
344
  method: 'GET',
342
345
  endpoint: undefined,
343
346
  authContext: {}
344
- }, controller) {
347
+ }, controller, useMediaCdn) {
345
348
  const {
346
349
  method,
347
350
  endpoint,
@@ -350,18 +353,27 @@ export class MediaStore {
350
353
  headers,
351
354
  body,
352
355
  clientOptions,
353
- traceContext
356
+ traceContext,
357
+ addMediaClientParam
354
358
  } = options;
355
359
  const auth = await this.resolveAuth(authContext);
360
+ const clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
356
361
  const extendedTraceContext = traceContext ? {
357
362
  ...traceContext,
358
363
  spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
359
364
  } : undefined;
360
- const response = await request(`${auth.baseUrl}${path}`, {
365
+ let url = `${auth.baseUrl}${path}`;
366
+ if (useMediaCdn) {
367
+ url = mapToMediaCdnUrl(url);
368
+ }
369
+ const response = await request(url, {
361
370
  method,
362
371
  endpoint,
363
372
  auth,
364
- params,
373
+ params: addMediaClientParam ? {
374
+ ...params,
375
+ clientId
376
+ } : params,
365
377
  headers,
366
378
  body,
367
379
  clientOptions,
@@ -1,9 +1,10 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { mapToMediaCdnUrl } from '../utils/mediaCdn';
2
3
  export const getArtifactUrl = (artifacts, prop) => {
3
4
  var _artifacts$prop2;
4
5
  if (fg('platform.media-cdn-delivery')) {
5
6
  var _artifacts$prop;
6
- return `${(_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url}/cdn`;
7
+ return mapToMediaCdnUrl(`${(_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url}/cdn`);
7
8
  }
8
9
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
9
10
  };
@@ -0,0 +1,26 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ export const MEDIA_CDN_MAP = {
3
+ 'api.media.atlassian.com': 'media-cdn.atlassian.com',
4
+ 'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
5
+ };
6
+ export function mapToMediaCdnUrl(url) {
7
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
8
+ if (fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
9
+ try {
10
+ const parsedUrl = new URL(url);
11
+ const cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
12
+
13
+ // If no mapping is found, return the original URL
14
+ if (!cdnHost) {
15
+ return url;
16
+ }
17
+
18
+ // Replace the host with the CDN host in the original URL
19
+ parsedUrl.host = cdnHost;
20
+ return parsedUrl.toString();
21
+ } catch (error) {
22
+ return url;
23
+ }
24
+ }
25
+ return url;
26
+ }
@@ -33,7 +33,7 @@ import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileSt
33
33
  import { PollingFunction } from '../../utils/polling';
34
34
  import { isEmptyFile } from '../../utils/detectEmptyFile';
35
35
  import { mediaStore } from '@atlaskit/media-state';
36
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
36
+ import { fg } from '@atlaskit/platform-feature-flags';
37
37
  export { isFileFetcherError, FileFetcherError } from './error';
38
38
  export var FileFetcherImpl = /*#__PURE__*/function () {
39
39
  function FileFetcherImpl(mediaApi) {
@@ -137,7 +137,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
137
137
  if (content instanceof Blob) {
138
138
  size = content.size;
139
139
  mimeType = content.type;
140
- if (isMimeTypeSupportedByBrowser(content.type) || getBooleanFF('platform.media-svg-rendering')) {
140
+ if (isMimeTypeSupportedByBrowser(content.type) || fg('platform.media-svg-rendering')) {
141
141
  preview = {
142
142
  value: content,
143
143
  origin: 'local'
@@ -5,11 +5,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  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
+ import { isClientBasedAuth } from '@atlaskit/media-core';
8
9
  import { getRandomHex } from '@atlaskit/media-common';
9
10
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
10
11
  import { getArtifactUrl } from '../../models/artifacts';
11
12
  import { request as _request } from '../../utils/request';
12
13
  import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
14
+ import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
13
15
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
14
16
  import { ChunkHashAlgorithm } from '@atlaskit/media-core';
15
17
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -285,7 +287,7 @@ export var MediaStore = /*#__PURE__*/function () {
285
287
  auth: auth
286
288
  };
287
289
  var imageEndpoint = fg('platform.media-cdn-delivery') ? 'image/cdn' : 'image';
288
- return createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options);
290
+ return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
289
291
  }
290
292
  }, {
291
293
  key: "getFileBinary",
@@ -317,7 +319,7 @@ export var MediaStore = /*#__PURE__*/function () {
317
319
  'max-age': "".concat(maxAge)
318
320
  }
319
321
  });
320
- return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options).then(createMapResponseToBlob(metadata)));
322
+ return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, undefined, true).then(createMapResponseToBlob(metadata)));
321
323
  case 6:
322
324
  case "end":
323
325
  return _context5.stop();
@@ -357,7 +359,7 @@ export var MediaStore = /*#__PURE__*/function () {
357
359
  auth: auth
358
360
  };
359
361
  binaryEndpoint = fg('platform.media-cdn-delivery') ? 'binary/cdn' : 'binary';
360
- return _context6.abrupt("return", createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options));
362
+ return _context6.abrupt("return", mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(binaryEndpoint), options)));
361
363
  case 7:
362
364
  case "end":
363
365
  return _context6.stop();
@@ -434,9 +436,10 @@ export var MediaStore = /*#__PURE__*/function () {
434
436
  },
435
437
  params: extendImageParams(params, fetchMaxRes),
436
438
  headers: headers,
437
- traceContext: traceContext
439
+ traceContext: traceContext,
440
+ addMediaClientParam: fg('platform.media-card-performance-observer_lgc7b') && true
438
441
  });
439
- return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller).then(createMapResponseToBlob(metadata)));
442
+ return _context8.abrupt("return", this.request("/file/".concat(id, "/").concat(imageEndpoint), options, controller, true).then(createMapResponseToBlob(metadata)));
440
443
  case 7:
441
444
  case "end":
442
445
  return _context8.stop();
@@ -580,6 +583,7 @@ export var MediaStore = /*#__PURE__*/function () {
580
583
  var _request2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(path) {
581
584
  var options,
582
585
  controller,
586
+ useMediaCdn,
583
587
  method,
584
588
  endpoint,
585
589
  authContext,
@@ -588,8 +592,11 @@ export var MediaStore = /*#__PURE__*/function () {
588
592
  body,
589
593
  clientOptions,
590
594
  traceContext,
595
+ addMediaClientParam,
591
596
  auth,
597
+ clientId,
592
598
  extendedTraceContext,
599
+ url,
593
600
  response,
594
601
  _args12 = arguments;
595
602
  return _regeneratorRuntime.wrap(function _callee12$(_context12) {
@@ -601,31 +608,39 @@ export var MediaStore = /*#__PURE__*/function () {
601
608
  authContext: {}
602
609
  };
603
610
  controller = _args12.length > 2 ? _args12[2] : undefined;
604
- method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
605
- _context12.next = 5;
611
+ useMediaCdn = _args12.length > 3 ? _args12[3] : undefined;
612
+ method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam;
613
+ _context12.next = 6;
606
614
  return this.resolveAuth(authContext);
607
- case 5:
615
+ case 6:
608
616
  auth = _context12.sent;
617
+ clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
609
618
  extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
610
619
  spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
611
620
  }) : undefined;
612
- _context12.next = 9;
613
- return _request("".concat(auth.baseUrl).concat(path), {
621
+ url = "".concat(auth.baseUrl).concat(path);
622
+ if (useMediaCdn) {
623
+ url = mapToMediaCdnUrl(url);
624
+ }
625
+ _context12.next = 13;
626
+ return _request(url, {
614
627
  method: method,
615
628
  endpoint: endpoint,
616
629
  auth: auth,
617
- params: params,
630
+ params: addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
631
+ clientId: clientId
632
+ }) : params,
618
633
  headers: headers,
619
634
  body: body,
620
635
  clientOptions: clientOptions,
621
636
  traceContext: extendedTraceContext
622
637
  }, controller);
623
- case 9:
638
+ case 13:
624
639
  response = _context12.sent;
625
640
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
626
641
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
627
642
  return _context12.abrupt("return", response);
628
- case 13:
643
+ case 17:
629
644
  case "end":
630
645
  return _context12.stop();
631
646
  }
@@ -1,9 +1,10 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { mapToMediaCdnUrl } from '../utils/mediaCdn';
2
3
  export var getArtifactUrl = function getArtifactUrl(artifacts, prop) {
3
4
  var _artifacts$prop2;
4
5
  if (fg('platform.media-cdn-delivery')) {
5
6
  var _artifacts$prop;
6
- return "".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn");
7
+ return mapToMediaCdnUrl("".concat((_artifacts$prop = artifacts[prop]) === null || _artifacts$prop === void 0 ? void 0 : _artifacts$prop.url, "/cdn"));
7
8
  }
8
9
  return (_artifacts$prop2 = artifacts[prop]) === null || _artifacts$prop2 === void 0 ? void 0 : _artifacts$prop2.url;
9
10
  };
@@ -0,0 +1,26 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ export var MEDIA_CDN_MAP = {
3
+ 'api.media.atlassian.com': 'media-cdn.atlassian.com',
4
+ 'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
5
+ };
6
+ export function mapToMediaCdnUrl(url) {
7
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
8
+ if (fg('platform.media-cdn-delivery') && fg('platform.media-cdn-single-host')) {
9
+ try {
10
+ var parsedUrl = new URL(url);
11
+ var cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
12
+
13
+ // If no mapping is found, return the original URL
14
+ if (!cdnHost) {
15
+ return url;
16
+ }
17
+
18
+ // Replace the host with the CDN host in the original URL
19
+ parsedUrl.host = cdnHost;
20
+ return parsedUrl.toString();
21
+ } catch (error) {
22
+ return url;
23
+ }
24
+ }
25
+ return url;
26
+ }
@@ -28,7 +28,7 @@ export declare class MediaStore implements MediaApi {
28
28
  }>;
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
- request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
31
+ request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
32
32
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
33
33
  resolveInitialAuth: () => Auth;
34
34
  get chunkHashAlgorithm(): ChunkHashAlgorithm;
@@ -1,5 +1,5 @@
1
1
  import { type Auth, type AsapBasedAuth, type AuthContext, type ClientAltBasedAuth } from '@atlaskit/media-core';
2
- import { type MediaTraceContext } from '@atlaskit/media-common';
2
+ import { type SSR, type MediaTraceContext } from '@atlaskit/media-common';
3
3
  import { type MediaFileArtifacts } from '@atlaskit/media-state';
4
4
  import { type MediaItemDetails, type MediaFile, type MediaUpload } from '../../models/media';
5
5
  import { type ClientOptions, type RequestHeaders, type RequestMethod, type RequestParams, type RequestMetadata } from '../../utils/request/types';
@@ -37,6 +37,7 @@ export type MediaStoreRequestOptions = RequestMetadata & {
37
37
  readonly clientOptions?: ClientOptions;
38
38
  readonly traceContext?: MediaTraceContext;
39
39
  readonly ChunkhashAlgorithm?: ChunkHashAlgorithm;
40
+ readonly addMediaClientParam?: boolean;
40
41
  };
41
42
  export type MediaStoreCreateFileFromUploadParams = {
42
43
  readonly collection?: string;
@@ -94,6 +95,8 @@ export type MediaStoreGetFileImageParams = {
94
95
  readonly mode?: 'fit' | 'full-fit' | 'crop';
95
96
  readonly upscale?: boolean;
96
97
  readonly 'max-age'?: number;
98
+ readonly source?: string;
99
+ readonly ssr?: SSR;
97
100
  };
98
101
  export interface SourceFile {
99
102
  id: string;
@@ -0,0 +1,4 @@
1
+ export declare const MEDIA_CDN_MAP: {
2
+ [key: string]: string;
3
+ };
4
+ export declare function mapToMediaCdnUrl(url: string): string;
@@ -28,7 +28,7 @@ export declare class MediaStore implements MediaApi {
28
28
  }>;
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
- request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
31
+ request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
32
32
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
33
33
  resolveInitialAuth: () => Auth;
34
34
  get chunkHashAlgorithm(): ChunkHashAlgorithm;
@@ -1,5 +1,5 @@
1
1
  import { type Auth, type AsapBasedAuth, type AuthContext, type ClientAltBasedAuth } from '@atlaskit/media-core';
2
- import { type MediaTraceContext } from '@atlaskit/media-common';
2
+ import { type SSR, type MediaTraceContext } from '@atlaskit/media-common';
3
3
  import { type MediaFileArtifacts } from '@atlaskit/media-state';
4
4
  import { type MediaItemDetails, type MediaFile, type MediaUpload } from '../../models/media';
5
5
  import { type ClientOptions, type RequestHeaders, type RequestMethod, type RequestParams, type RequestMetadata } from '../../utils/request/types';
@@ -37,6 +37,7 @@ export type MediaStoreRequestOptions = RequestMetadata & {
37
37
  readonly clientOptions?: ClientOptions;
38
38
  readonly traceContext?: MediaTraceContext;
39
39
  readonly ChunkhashAlgorithm?: ChunkHashAlgorithm;
40
+ readonly addMediaClientParam?: boolean;
40
41
  };
41
42
  export type MediaStoreCreateFileFromUploadParams = {
42
43
  readonly collection?: string;
@@ -94,6 +95,8 @@ export type MediaStoreGetFileImageParams = {
94
95
  readonly mode?: 'fit' | 'full-fit' | 'crop';
95
96
  readonly upscale?: boolean;
96
97
  readonly 'max-age'?: number;
98
+ readonly source?: string;
99
+ readonly ssr?: SSR;
97
100
  };
98
101
  export interface SourceFile {
99
102
  id: string;
@@ -0,0 +1,4 @@
1
+ export declare const MEDIA_CDN_MAP: {
2
+ [key: string]: string;
3
+ };
4
+ export declare function mapToMediaCdnUrl(url: string): string;
@@ -1,4 +1,7 @@
1
- /** @jsx jsx */
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
2
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
6
  import { jsx } from '@emotion/react';
4
7
  import { type ChangeEvent, type ReactNode } from 'react';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "27.3.4",
3
+ "version": "27.5.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -36,8 +36,8 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@atlaskit/chunkinator": "^6.0.0",
40
- "@atlaskit/media-common": "^11.3.0",
39
+ "@atlaskit/chunkinator": "^6.1.0",
40
+ "@atlaskit/media-common": "^11.4.0",
41
41
  "@atlaskit/platform-feature-flags": "0.3.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "dataloader": "^2.0.0",
@@ -53,14 +53,14 @@
53
53
  "xstate": "4.20.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@atlaskit/media-core": "^34.1.2",
56
+ "@atlaskit/media-core": "^34.3.0",
57
57
  "@atlaskit/media-state": "^1.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@atlaskit/media-core": "^34.2.0",
60
+ "@atlaskit/media-core": "^34.3.0",
61
61
  "@atlaskit/media-state": "^1.1.0",
62
62
  "@atlaskit/ssr": "*",
63
- "@atlaskit/tokens": "^1.56.0",
63
+ "@atlaskit/tokens": "^1.59.0",
64
64
  "@atlassian/feature-flags-test-utils": "0.2.3",
65
65
  "@emotion/react": "^11.7.1",
66
66
  "@types/deep-equal": "^1.0.1",
@@ -89,6 +89,12 @@
89
89
  },
90
90
  "platform.media-cdn-delivery": {
91
91
  "type": "boolean"
92
+ },
93
+ "platform.media-card-performance-observer_lgc7b": {
94
+ "type": "boolean"
95
+ },
96
+ "platform.media-cdn-single-host": {
97
+ "type": "boolean"
92
98
  }
93
99
  }
94
100
  }