@atlaskit/media-client 35.4.0 → 35.6.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,19 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 35.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`b3183021fdece`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b3183021fdece) -
8
+ Bug fix for path based routing - "/media-api" getting prepended twice resolved"
9
+
10
+ ## 35.5.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`3d3db676b30c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3d3db676b30c1) -
15
+ Add support for path based routing for artifact urls
16
+
3
17
  ## 35.4.0
4
18
 
5
19
  ### Minor Changes
@@ -292,7 +306,6 @@
292
306
  - [#102527](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102527)
293
307
  [`a90d34cd14faf`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a90d34cd14faf) -
294
308
  Updated the constructor of the following classes. Consult the type definitions for details.
295
-
296
309
  - `RequestError`
297
310
 
298
311
  - `PollingError`
@@ -304,7 +317,6 @@
304
317
  - [#102527](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102527)
305
318
  [`a90d34cd14faf`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a90d34cd14faf) - -
306
319
  New error verification helper `isCommonMediaClientError`
307
-
308
320
  - `ErrorFileState` is now deserializable into a `CommonMediaClientError` using new export
309
321
  `toCommonMediaClientError`
310
322
 
@@ -484,7 +496,6 @@
484
496
  - [#134882](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/134882)
485
497
  [`ba204702f8e32`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ba204702f8e32) -
486
498
  [ED-24567]
487
-
488
499
  - **@atlaskit/editor-common** Add MEDIA_PICKER as a variable fo analytics
489
500
  - **@atlaskit/media-client** Return the mime-type from when calling the `uploadExternal` function
490
501
 
@@ -912,7 +923,6 @@
912
923
  - [#32424](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/32424)
913
924
  [`0f99ed9df35`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0f99ed9df35) - BREAKING
914
925
  CHANGES:
915
-
916
926
  - Media Store class no longer exposes getCollectionItems method
917
927
 
918
928
  - `MediaClient.collection.removeFile` method is now accessible through the replacement method
@@ -920,7 +930,6 @@
920
930
 
921
931
  - `MediaClient.collection` has been fully removed. The following classes, types and utils have
922
932
  been also removed:
923
-
924
933
  - MediaCollection
925
934
  - MediaCollectionItem
926
935
  - MediaCollectionItems
@@ -1125,7 +1134,6 @@
1125
1134
  Client Uploader enforces a hard limit of 2Tb files.
1126
1135
 
1127
1136
  To mitigate these changes:
1128
-
1129
1137
  - Set the feature flag mediaUploadApiV2 as false or Revert to a previous version for affected
1130
1138
  consumers and methods; Media Client uploadFile method. Media Client File Fetcher upload method.
1131
1139
  Media Picker.
@@ -1430,7 +1438,6 @@
1430
1438
  pollingMaxFailuresExceeded error from implementation and feature flags
1431
1439
  - [`50cc05dde71`](https://bitbucket.org/atlassian/atlassian-frontend/commits/50cc05dde71) - Mark the
1432
1440
  following members as deprecated:
1433
-
1434
1441
  - getMediaTypeFromMimeType
1435
1442
  - isImageMimeTypeSupportedByBrowser
1436
1443
  - isDocumentMimeTypeSupportedByBrowser
@@ -1878,7 +1885,6 @@
1878
1885
  ### Minor Changes
1879
1886
 
1880
1887
  - [minor][eb962d2c36](https://bitbucket.org/atlassian/atlassian-frontend/commits/eb962d2c36):
1881
-
1882
1888
  - Add MAX_RESOLUTION constant. Can be imported via direct entry point
1883
1889
  `import { MAX_RESOLUTION } from '@atlaskit/media-client/constants';`
1884
1890
  - `Preview` class (`preview` prop in most `FileState`) now has optional field `origin` that can be
@@ -1974,7 +1980,6 @@
1974
1980
 
1975
1981
  Remove namespace imports from React, ReactDom, and PropTypes- Updated dependencies
1976
1982
  [6548261c9a](https://bitbucket.org/atlassian/atlassian-frontend/commits/6548261c9a):
1977
-
1978
1983
  - @atlaskit/docs@8.3.2
1979
1984
  - @atlaskit/button@13.3.7
1980
1985
  - @atlaskit/type-helpers@4.2.3
@@ -2067,7 +2072,6 @@
2067
2072
  Check if the subscription is defined before calling unsubscribe in utils observableToPromise-
2068
2073
  Updated dependencies
2069
2074
  [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
2070
-
2071
2075
  - @atlaskit/media-card@66.1.2
2072
2076
 
2073
2077
  ## 4.1.1
@@ -2223,7 +2227,6 @@ Bumped dependencies.
2223
2227
  ### Changed
2224
2228
 
2225
2229
  **getMediaClient**
2226
-
2227
2230
  - Before
2228
2231
 
2229
2232
  > works with passing either mediaClientConfig or context
@@ -2294,7 +2297,6 @@ Bumped dependencies.
2294
2297
  - [minor][65ada7f318](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/65ada7f318):
2295
2298
 
2296
2299
  **FABDODGEM-12 Editor Cashmere Release**
2297
-
2298
2300
  - [Internal post](http://go.atlassian.com/cashmere-release)
2299
2301
 
2300
2302
  **Affected editor components:**
@@ -2302,19 +2304,16 @@ Bumped dependencies.
2302
2304
  tables, media, mobile, text color, emoji, copy/paste, analytics
2303
2305
 
2304
2306
  **Performance**
2305
-
2306
2307
  - Async import for code blocks and task items on renderer
2307
2308
  - https://product-fabric.atlassian.net/browse/ED-7155
2308
2309
 
2309
2310
  **Table**
2310
-
2311
2311
  - Add support to sort tables that contains smart links
2312
2312
  - https://product-fabric.atlassian.net/browse/ED-7449
2313
2313
  - Scale table when changing to full width mode
2314
2314
  - https://product-fabric.atlassian.net/browse/ED-7724
2315
2315
 
2316
2316
  **Text color**
2317
-
2318
2317
  - Update text color toolbar with right color when text is inside a list, panel, etc.
2319
2318
  - https://product-fabric.atlassian.net/browse/FM-1752
2320
2319
 
@@ -2501,7 +2500,6 @@ https://product-fabric.atlassian.net/browse/FM-2393
2501
2500
  - [patch][18dfac7332](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/18dfac7332):
2502
2501
 
2503
2502
  In this PR, we are:
2504
-
2505
2503
  - Re-introducing dist build folders
2506
2504
  - Adding back cjs
2507
2505
  - Replacing es5 by cjs and es2015 by esm
@@ -2560,14 +2558,12 @@ https://product-fabric.atlassian.net/browse/FM-2393
2560
2558
  ## 1.2.1
2561
2559
 
2562
2560
  - [patch][b0ef06c685](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/b0ef06c685):
2563
-
2564
2561
  - This is just a safety release in case anything strange happened in in the previous one. See Pull
2565
2562
  Request #5942 for details
2566
2563
 
2567
2564
  ## 1.2.0
2568
2565
 
2569
2566
  - [minor][dcda79d48c](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/dcda79d48c):
2570
-
2571
2567
  - `withMediaClient` and associated Props are introduced to make possible soft transition from
2572
2568
  Context based media components to Media Client Config ones.
2573
2569
 
@@ -2580,13 +2576,11 @@ https://product-fabric.atlassian.net/browse/FM-2393
2580
2576
  ## 1.1.5
2581
2577
 
2582
2578
  - [patch][af1cbd4ce4](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/af1cbd4ce4):
2583
-
2584
2579
  - Removing unnecessary deps and dev deps in media-core and media-client
2585
2580
 
2586
2581
  ## 1.1.4
2587
2582
 
2588
2583
  - [patch][12aa76d5b5](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/12aa76d5b5):
2589
-
2590
2584
  - ED-6814: fixed rendering mediaSingle without collection
2591
2585
 
2592
2586
  ## 1.1.3
@@ -2600,27 +2594,23 @@ https://product-fabric.atlassian.net/browse/FM-2393
2600
2594
  ## 1.1.2
2601
2595
 
2602
2596
  - [patch][7c17b35107](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/7c17b35107):
2603
-
2604
2597
  - Updates react and react-dom peer dependencies to react@^16.8.0 and react-dom@^16.8.0. To use
2605
2598
  this package, please ensure you use at least this version of react and react-dom.
2606
2599
 
2607
2600
  ## 1.1.1
2608
2601
 
2609
2602
  - [patch][2f58d39758](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/2f58d39758):
2610
-
2611
2603
  - Fix problem with double exporting one of the existing items
2612
2604
 
2613
2605
  ## 1.1.0
2614
2606
 
2615
2607
  - [minor][8536258182](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/8536258182):
2616
-
2617
2608
  - expose on + off + emit methods on client in order to communicate events with integrators. At
2618
2609
  this point the only emitted event is 'file-added'
2619
2610
 
2620
2611
  ## 1.0.0
2621
2612
 
2622
2613
  - [major][e38d662f7d](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/e38d662f7d):
2623
-
2624
2614
  - Media API Web Client Library initial release. It contains mostly combined code from media-core
2625
2615
  and media-store.
2626
2616
 
package/compass.yml CHANGED
@@ -10,6 +10,9 @@ fields:
10
10
  labels:
11
11
  - atlassian-platform
12
12
  links:
13
+ - name: Root Repository
14
+ type: REPOSITORY
15
+ url: https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master
13
16
  - name: ''
14
17
  type: REPOSITORY
15
18
  url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/media/media-client/'
@@ -52,7 +52,7 @@ var _createCopyIntentRegisterationBatcher = require("../../utils/createCopyInten
52
52
  var _helpers = require("../../utils/request/helpers");
53
53
  var _errors = require("../../models/errors");
54
54
  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; }
55
- 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; }
55
+ 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; } // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
56
56
  var isCopySourceFileWithToken = function isCopySourceFileWithToken(token) {
57
57
  return !!token.authProvider;
58
58
  };
@@ -297,7 +297,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
297
297
  }
298
298
  throw new Error('File is not a video');
299
299
  case 5:
300
- if (!((_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration)) {
300
+ if (!('mediaMetadata' in fileState && (_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration)) {
301
301
  _context5.next = 7;
302
302
  break;
303
303
  }
@@ -523,7 +523,9 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
523
523
  }, {
524
524
  key: "generateUploadableFileUpfrontIds",
525
525
  value: function generateUploadableFileUpfrontIds(collection, traceContext) {
526
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
526
527
  var id = (0, _v.default)();
528
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
527
529
  var occurrenceKey = (0, _v.default)();
528
530
  var touchFileDescriptor = {
529
531
  fileId: id,
@@ -17,7 +17,6 @@ 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
20
  var _pathBasedUrl = require("../../utils/pathBasedUrl");
22
21
  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; }
23
22
  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; }
@@ -411,7 +410,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
411
410
  auth: auth
412
411
  };
413
412
  var imageEndpoint = cdnFeatureFlag('image');
414
- if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
413
+ if ((0, _pathBasedUrl.isPathBasedEnabled)()) {
415
414
  return (0, _pathBasedUrl.mapToPathBasedUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
416
415
  }
417
416
  return (0, _mediaCdn.mapToMediaCdnUrl)((0, _helpers.createUrl)("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
@@ -486,7 +485,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
486
485
  auth: auth
487
486
  };
488
487
  binaryEndpoint = cdnFeatureFlag('binary');
489
- if (!(0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
488
+ if (!(0, _pathBasedUrl.isPathBasedEnabled)()) {
490
489
  _context9.next = 8;
491
490
  break;
492
491
  }
@@ -512,6 +511,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
512
511
  artifactUrl,
513
512
  auth,
514
513
  options,
514
+ url,
515
515
  _args0 = arguments;
516
516
  return _regenerator.default.wrap(function _callee0$(_context0) {
517
517
  while (1) switch (_context0.prev = _context0.next) {
@@ -549,8 +549,15 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
549
549
  },
550
550
  auth: auth
551
551
  };
552
- return _context0.abrupt("return", (0, _helpers.createUrl)((0, _mediaCdn.mapToMediaCdnUrl)(artifactUrl, auth.token), options));
553
- case 9:
552
+ url = (0, _helpers.createUrl)((0, _mediaCdn.mapToMediaCdnUrl)(artifactUrl, auth.token), options);
553
+ if (!(0, _pathBasedUrl.isPathBasedEnabled)()) {
554
+ _context0.next = 11;
555
+ break;
556
+ }
557
+ return _context0.abrupt("return", (0, _pathBasedUrl.mapToPathBasedUrl)(url));
558
+ case 11:
559
+ return _context0.abrupt("return", url);
560
+ case 12:
554
561
  case "end":
555
562
  return _context0.stop();
556
563
  }
@@ -937,7 +944,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
937
944
  if (useMediaCdn) {
938
945
  url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
939
946
  }
940
- if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
947
+ if ((0, _pathBasedUrl.isPathBasedEnabled)()) {
941
948
  url = (0, _pathBasedUrl.mapToPathBasedUrl)(url);
942
949
  }
943
950
  _context16.next = 20;
@@ -90,7 +90,7 @@ function isCommonMediaClientError(error) {
90
90
  var toCommonMediaClientError = exports.toCommonMediaClientError = function toCommonMediaClientError(errorFileState) {
91
91
  var _errorFileState$detai;
92
92
  var error = (_errorFileState$detai = errorFileState.details) === null || _errorFileState$detai === void 0 ? void 0 : _errorFileState$detai.error;
93
- return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error.metadata, error.innerError);
93
+ return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
94
94
  };
95
95
 
96
96
  /** Serializer CommonMediaClientError -> ErrorFileState */
@@ -9,6 +9,7 @@ exports.mapToMediaCdnUrl = mapToMediaCdnUrl;
9
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
10
  var _isCommercial = require("./isCommercial");
11
11
  var _atlassianContext = require("@atlaskit/atlassian-context");
12
+ var _pathBasedUrl = require("./pathBasedUrl");
12
13
  var MEDIA_CDN_MAP = exports.MEDIA_CDN_MAP = {
13
14
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
14
15
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
@@ -19,7 +20,7 @@ var MEDIA_CDN_MAP = exports.MEDIA_CDN_MAP = {
19
20
  // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
20
21
  var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
21
22
  function isCDNEnabled() {
22
- return (0, _isCommercial.isCommercial)() && !(0, _atlassianContext.isIsolatedCloud)() && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery') && !(0, _platformFeatureFlags.fg)('platform_media_path_based_route');
23
+ return (0, _isCommercial.isCommercial)() && !(0, _atlassianContext.isIsolatedCloud)() && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery') && !(0, _pathBasedUrl.isPathBasedEnabled)();
23
24
  }
24
25
  function mapToMediaCdnUrl(url, token) {
25
26
  var _token$length;
@@ -4,20 +4,29 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.isPathBasedEnabled = isPathBasedEnabled;
7
8
  exports.mapRetryUrlToPathBasedUrl = mapRetryUrlToPathBasedUrl;
8
9
  exports.mapToPathBasedUrl = mapToPathBasedUrl;
9
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
- var _getDocument3 = _interopRequireDefault(require("./getDocument"));
11
+ var _getDocument4 = _interopRequireDefault(require("./getDocument"));
12
+ var mediaApiPathPrefix = '/media-api';
11
13
  function getRelativeUrl(absoluteUrl) {
12
14
  var url = new URL(absoluteUrl);
13
15
  return "".concat(url.pathname).concat(url.search).concat(url.hash);
14
16
  }
17
+ function isPathBasedEnabled() {
18
+ var _getDocument;
19
+ var isLocalhost = ((_getDocument = (0, _getDocument4.default)()) === null || _getDocument === void 0 || (_getDocument = _getDocument.location) === null || _getDocument === void 0 ? void 0 : _getDocument.hostname) === 'localhost';
20
+ return (0, _platformFeatureFlags.fg)('platform_media_path_based_route') && !isLocalhost;
21
+ }
15
22
  function mapToPathBasedUrl(url) {
16
- if ((0, _platformFeatureFlags.fg)('platform_media_path_based_route')) {
17
- var _getDocument;
23
+ if (isPathBasedEnabled()) {
24
+ var _getDocument2;
18
25
  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;
26
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
27
+ parsedUrl.pathname = "".concat(mediaApiPathPrefix).concat(parsedUrl.pathname);
28
+ }
29
+ var location = (_getDocument2 = (0, _getDocument4.default)()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location;
21
30
 
22
31
  // in this case we are most likely in SSR / a non browser environment so just return a relative URL
23
32
  if (!location) {
@@ -29,15 +38,17 @@ function mapToPathBasedUrl(url) {
29
38
  return url;
30
39
  }
31
40
  function mapRetryUrlToPathBasedUrl(url) {
32
- var _getDocument$location, _getDocument2;
41
+ var _getDocument$location, _getDocument3;
33
42
  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 : '';
43
+ parsedUrl.host = (_getDocument$location = (_getDocument3 = (0, _getDocument4.default)()) === null || _getDocument3 === void 0 ? void 0 : _getDocument3.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
35
44
 
36
45
  // remove CDN from the URL for retry if it exists
37
46
  var pathname = parsedUrl.pathname;
38
47
  if (pathname.endsWith('/cdn')) {
39
48
  parsedUrl.pathname = pathname.replace('/cdn', '');
40
49
  }
41
- parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
50
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
51
+ parsedUrl.pathname = "".concat(mediaApiPathPrefix).concat(parsedUrl.pathname);
52
+ }
42
53
  return parsedUrl;
43
54
  }
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { Subscription } from 'rxjs/Subscription';
3
3
  import { map } from 'rxjs/operators/map';
4
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
4
5
  import uuid from 'uuid/v4';
5
6
  import { authToOwner } from '@atlaskit/media-core';
6
7
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
@@ -184,7 +185,7 @@ export class FileFetcherImpl {
184
185
  if (fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4']) {
185
186
  throw new Error('File is not a video');
186
187
  }
187
- if ((_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration) {
188
+ if ('mediaMetadata' in fileState && (_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration) {
188
189
  return fileState.mediaMetadata.duration;
189
190
  }
190
191
 
@@ -323,7 +324,9 @@ export class FileFetcherImpl {
323
324
  }) => data);
324
325
  }
325
326
  generateUploadableFileUpfrontIds(collection, traceContext) {
327
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
326
328
  const id = uuid();
329
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
327
330
  const occurrenceKey = uuid();
328
331
  const touchFileDescriptor = {
329
332
  fileId: id,
@@ -7,8 +7,7 @@ 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
+ import { isPathBasedEnabled, mapToPathBasedUrl } from '../../utils/pathBasedUrl';
12
11
  const MEDIA_API_REGION = 'media-api-region';
13
12
  const MEDIA_API_ENVIRONMENT = 'media-api-environment';
14
13
  const extendImageParams = (params, fetchMaxRes = false) => {
@@ -268,7 +267,7 @@ export class MediaStore {
268
267
  auth
269
268
  };
270
269
  const imageEndpoint = cdnFeatureFlag('image');
271
- if (fg('platform_media_path_based_route')) {
270
+ if (isPathBasedEnabled()) {
272
271
  return mapToPathBasedUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options));
273
272
  }
274
273
  return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options), auth.token);
@@ -306,7 +305,7 @@ export class MediaStore {
306
305
  auth
307
306
  };
308
307
  const binaryEndpoint = cdnFeatureFlag('binary');
309
- if (fg('platform_media_path_based_route')) {
308
+ if (isPathBasedEnabled()) {
310
309
  return mapToPathBasedUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options));
311
310
  }
312
311
  return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options), auth.token);
@@ -339,7 +338,11 @@ export class MediaStore {
339
338
  },
340
339
  auth
341
340
  };
342
- return createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options);
341
+ const url = createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options);
342
+ if (isPathBasedEnabled()) {
343
+ return mapToPathBasedUrl(url);
344
+ }
345
+ return url;
343
346
  }
344
347
  async getImage(id, params, controller, fetchMaxRes, traceContext) {
345
348
  // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
@@ -569,7 +572,7 @@ export class MediaStore {
569
572
  if (useMediaCdn) {
570
573
  url = mapToMediaCdnUrl(url, auth.token);
571
574
  }
572
- if (fg('platform_media_path_based_route')) {
575
+ if (isPathBasedEnabled()) {
573
576
  url = mapToPathBasedUrl(url);
574
577
  }
575
578
  const response = await request(url, {
@@ -51,7 +51,7 @@ export function isCommonMediaClientError(error) {
51
51
  export const toCommonMediaClientError = errorFileState => {
52
52
  var _errorFileState$detai;
53
53
  const error = (_errorFileState$detai = errorFileState.details) === null || _errorFileState$detai === void 0 ? void 0 : _errorFileState$detai.error;
54
- return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error.metadata, error.innerError);
54
+ return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
55
55
  };
56
56
 
57
57
  /** Serializer CommonMediaClientError -> ErrorFileState */
@@ -1,6 +1,7 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import { isCommercial } from './isCommercial';
3
3
  import { isIsolatedCloud } from '@atlaskit/atlassian-context';
4
+ import { isPathBasedEnabled } from './pathBasedUrl';
4
5
  export const MEDIA_CDN_MAP = {
5
6
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
6
7
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
@@ -11,7 +12,7 @@ export const MEDIA_CDN_MAP = {
11
12
  // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
12
13
  const MEDIA_TOKEN_LENGTH_LIMIT = 7000;
13
14
  export function isCDNEnabled() {
14
- return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
15
+ return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !isPathBasedEnabled();
15
16
  }
16
17
  export function mapToMediaCdnUrl(url, token) {
17
18
  var _token$length;
@@ -1,15 +1,23 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import getDocument from './getDocument';
3
+ const mediaApiPathPrefix = '/media-api';
3
4
  function getRelativeUrl(absoluteUrl) {
4
5
  const url = new URL(absoluteUrl);
5
6
  return `${url.pathname}${url.search}${url.hash}`;
6
7
  }
8
+ export function isPathBasedEnabled() {
9
+ var _getDocument, _getDocument$location;
10
+ const isLocalhost = ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : (_getDocument$location = _getDocument.location) === null || _getDocument$location === void 0 ? void 0 : _getDocument$location.hostname) === 'localhost';
11
+ return fg('platform_media_path_based_route') && !isLocalhost;
12
+ }
7
13
  export function mapToPathBasedUrl(url) {
8
- if (fg('platform_media_path_based_route')) {
9
- var _getDocument;
14
+ if (isPathBasedEnabled()) {
15
+ var _getDocument2;
10
16
  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;
17
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
18
+ parsedUrl.pathname = `${mediaApiPathPrefix}${parsedUrl.pathname}`;
19
+ }
20
+ const location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location;
13
21
 
14
22
  // in this case we are most likely in SSR / a non browser environment so just return a relative URL
15
23
  if (!location) {
@@ -21,15 +29,17 @@ export function mapToPathBasedUrl(url) {
21
29
  return url;
22
30
  }
23
31
  export function mapRetryUrlToPathBasedUrl(url) {
24
- var _getDocument$location, _getDocument2;
32
+ var _getDocument$location2, _getDocument3;
25
33
  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 : '';
34
+ parsedUrl.host = (_getDocument$location2 = (_getDocument3 = getDocument()) === null || _getDocument3 === void 0 ? void 0 : _getDocument3.location.host) !== null && _getDocument$location2 !== void 0 ? _getDocument$location2 : '';
27
35
 
28
36
  // remove CDN from the URL for retry if it exists
29
37
  const pathname = parsedUrl.pathname;
30
38
  if (pathname.endsWith('/cdn')) {
31
39
  parsedUrl.pathname = pathname.replace('/cdn', '');
32
40
  }
33
- parsedUrl.pathname = `/media-api${parsedUrl.pathname}`;
41
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
42
+ parsedUrl.pathname = `${mediaApiPathPrefix}${parsedUrl.pathname}`;
43
+ }
34
44
  return parsedUrl;
35
45
  }
@@ -7,6 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
8
  import { Subscription } from 'rxjs/Subscription';
9
9
  import { map } from 'rxjs/operators/map';
10
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
10
11
  import uuid from 'uuid/v4';
11
12
  import { authToOwner } from '@atlaskit/media-core';
12
13
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
@@ -279,7 +280,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
279
280
  }
280
281
  throw new Error('File is not a video');
281
282
  case 5:
282
- if (!((_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration)) {
283
+ if (!('mediaMetadata' in fileState && (_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration)) {
283
284
  _context5.next = 7;
284
285
  break;
285
286
  }
@@ -505,7 +506,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
505
506
  }, {
506
507
  key: "generateUploadableFileUpfrontIds",
507
508
  value: function generateUploadableFileUpfrontIds(collection, traceContext) {
509
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
508
510
  var id = uuid();
511
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
509
512
  var occurrenceKey = uuid();
510
513
  var touchFileDescriptor = {
511
514
  fileId: id,
@@ -13,8 +13,7 @@ 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
+ import { isPathBasedEnabled, mapToPathBasedUrl } from '../../utils/pathBasedUrl';
18
17
  var MEDIA_API_REGION = 'media-api-region';
19
18
  var MEDIA_API_ENVIRONMENT = 'media-api-environment';
20
19
  var extendImageParams = function extendImageParams(params) {
@@ -405,7 +404,7 @@ export var MediaStore = /*#__PURE__*/function () {
405
404
  auth: auth
406
405
  };
407
406
  var imageEndpoint = cdnFeatureFlag('image');
408
- if (fg('platform_media_path_based_route')) {
407
+ if (isPathBasedEnabled()) {
409
408
  return mapToPathBasedUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options));
410
409
  }
411
410
  return mapToMediaCdnUrl(createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/").concat(imageEndpoint), options), auth.token);
@@ -480,7 +479,7 @@ export var MediaStore = /*#__PURE__*/function () {
480
479
  auth: auth
481
480
  };
482
481
  binaryEndpoint = cdnFeatureFlag('binary');
483
- if (!fg('platform_media_path_based_route')) {
482
+ if (!isPathBasedEnabled()) {
484
483
  _context9.next = 8;
485
484
  break;
486
485
  }
@@ -506,6 +505,7 @@ export var MediaStore = /*#__PURE__*/function () {
506
505
  artifactUrl,
507
506
  auth,
508
507
  options,
508
+ url,
509
509
  _args0 = arguments;
510
510
  return _regeneratorRuntime.wrap(function _callee0$(_context0) {
511
511
  while (1) switch (_context0.prev = _context0.next) {
@@ -543,8 +543,15 @@ export var MediaStore = /*#__PURE__*/function () {
543
543
  },
544
544
  auth: auth
545
545
  };
546
- return _context0.abrupt("return", createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options));
547
- case 9:
546
+ url = createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options);
547
+ if (!isPathBasedEnabled()) {
548
+ _context0.next = 11;
549
+ break;
550
+ }
551
+ return _context0.abrupt("return", mapToPathBasedUrl(url));
552
+ case 11:
553
+ return _context0.abrupt("return", url);
554
+ case 12:
548
555
  case "end":
549
556
  return _context0.stop();
550
557
  }
@@ -931,7 +938,7 @@ export var MediaStore = /*#__PURE__*/function () {
931
938
  if (useMediaCdn) {
932
939
  url = mapToMediaCdnUrl(url, auth.token);
933
940
  }
934
- if (fg('platform_media_path_based_route')) {
941
+ if (isPathBasedEnabled()) {
935
942
  url = mapToPathBasedUrl(url);
936
943
  }
937
944
  _context16.next = 20;
@@ -72,7 +72,7 @@ export function isCommonMediaClientError(error) {
72
72
  export var toCommonMediaClientError = function toCommonMediaClientError(errorFileState) {
73
73
  var _errorFileState$detai;
74
74
  var error = (_errorFileState$detai = errorFileState.details) === null || _errorFileState$detai === void 0 ? void 0 : _errorFileState$detai.error;
75
- return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error.metadata, error.innerError);
75
+ return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
76
76
  };
77
77
 
78
78
  /** Serializer CommonMediaClientError -> ErrorFileState */
@@ -1,6 +1,7 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import { isCommercial } from './isCommercial';
3
3
  import { isIsolatedCloud } from '@atlaskit/atlassian-context';
4
+ import { isPathBasedEnabled } from './pathBasedUrl';
4
5
  export var MEDIA_CDN_MAP = {
5
6
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
6
7
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
@@ -11,7 +12,7 @@ export var MEDIA_CDN_MAP = {
11
12
  // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
12
13
  var MEDIA_TOKEN_LENGTH_LIMIT = 7000;
13
14
  export function isCDNEnabled() {
14
- return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !fg('platform_media_path_based_route');
15
+ return isCommercial() && !isIsolatedCloud() && fg('platform_media_cdn_delivery') && !isPathBasedEnabled();
15
16
  }
16
17
  export function mapToMediaCdnUrl(url, token) {
17
18
  var _token$length;
@@ -1,15 +1,23 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import getDocument from './getDocument';
3
+ var mediaApiPathPrefix = '/media-api';
3
4
  function getRelativeUrl(absoluteUrl) {
4
5
  var url = new URL(absoluteUrl);
5
6
  return "".concat(url.pathname).concat(url.search).concat(url.hash);
6
7
  }
8
+ export function isPathBasedEnabled() {
9
+ var _getDocument;
10
+ var isLocalhost = ((_getDocument = getDocument()) === null || _getDocument === void 0 || (_getDocument = _getDocument.location) === null || _getDocument === void 0 ? void 0 : _getDocument.hostname) === 'localhost';
11
+ return fg('platform_media_path_based_route') && !isLocalhost;
12
+ }
7
13
  export function mapToPathBasedUrl(url) {
8
- if (fg('platform_media_path_based_route')) {
9
- var _getDocument;
14
+ if (isPathBasedEnabled()) {
15
+ var _getDocument2;
10
16
  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;
17
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
18
+ parsedUrl.pathname = "".concat(mediaApiPathPrefix).concat(parsedUrl.pathname);
19
+ }
20
+ var location = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.location;
13
21
 
14
22
  // in this case we are most likely in SSR / a non browser environment so just return a relative URL
15
23
  if (!location) {
@@ -21,15 +29,17 @@ export function mapToPathBasedUrl(url) {
21
29
  return url;
22
30
  }
23
31
  export function mapRetryUrlToPathBasedUrl(url) {
24
- var _getDocument$location, _getDocument2;
32
+ var _getDocument$location, _getDocument3;
25
33
  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 : '';
34
+ parsedUrl.host = (_getDocument$location = (_getDocument3 = getDocument()) === null || _getDocument3 === void 0 ? void 0 : _getDocument3.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
27
35
 
28
36
  // remove CDN from the URL for retry if it exists
29
37
  var pathname = parsedUrl.pathname;
30
38
  if (pathname.endsWith('/cdn')) {
31
39
  parsedUrl.pathname = pathname.replace('/cdn', '');
32
40
  }
33
- parsedUrl.pathname = "/media-api".concat(parsedUrl.pathname);
41
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
42
+ parsedUrl.pathname = "".concat(mediaApiPathPrefix).concat(parsedUrl.pathname);
43
+ }
34
44
  return parsedUrl;
35
45
  }
@@ -1,2 +1,3 @@
1
+ export declare function isPathBasedEnabled(): boolean;
1
2
  export declare function mapToPathBasedUrl(url: string): string;
2
3
  export declare function mapRetryUrlToPathBasedUrl(url: string): URL;
@@ -1,2 +1,3 @@
1
+ export declare function isPathBasedEnabled(): boolean;
1
2
  export declare function mapToPathBasedUrl(url: string): string;
2
3
  export declare function mapRetryUrlToPathBasedUrl(url: string): URL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "35.4.0",
3
+ "version": "35.6.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -53,8 +53,8 @@
53
53
  "@atlaskit/media-core": "^37.0.0",
54
54
  "@atlaskit/media-state": "^1.8.0",
55
55
  "@atlaskit/ssr": "workspace:^",
56
- "@atlaskit/tokens": "^6.4.0",
57
- "@atlassian/feature-flags-test-utils": "^0.3.0",
56
+ "@atlaskit/tokens": "^8.0.0",
57
+ "@atlassian/feature-flags-test-utils": "^1.0.0",
58
58
  "@emotion/react": "^11.7.1",
59
59
  "@types/deep-equal": "^1.0.1",
60
60
  "@types/uuid-validate": "^0.0.2",