@atlaskit/media-client 28.1.0 → 28.3.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,20 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 28.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#163838](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/163838)
8
+ [`c3fcf9a7c2028`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3fcf9a7c2028) -
9
+ Media Client File Download throws Request errors due to failed connection (Not streaming errors)
10
+
11
+ ## 28.2.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`6099ac032dd30`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6099ac032dd30) -
16
+ Added viewerOptions to override file preview renderer in media components
17
+
3
18
  ## 28.1.0
4
19
 
5
20
  ### Minor Changes
@@ -474,6 +474,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
474
474
  var _downloadBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id) {
475
475
  var name,
476
476
  collectionName,
477
+ traceContext,
477
478
  url,
478
479
  _args5 = arguments;
479
480
  return _regenerator.default.wrap(function _callee5$(_context5) {
@@ -481,9 +482,10 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
481
482
  case 0:
482
483
  name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
483
484
  collectionName = _args5.length > 2 ? _args5[2] : undefined;
484
- _context5.next = 4;
485
+ traceContext = _args5.length > 3 ? _args5[3] : undefined;
486
+ _context5.next = 5;
485
487
  return this.mediaApi.getFileBinaryURL(id, collectionName);
486
- case 4:
488
+ case 5:
487
489
  url = _context5.sent;
488
490
  (0, _downloadUrl.downloadUrl)(url, {
489
491
  name: name
@@ -493,7 +495,12 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
493
495
  isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
494
496
  viewingLevel: 'download'
495
497
  });
496
- case 7:
498
+ // Test the download after initiated the Browser process to catch any potential errors.
499
+ _context5.next = 10;
500
+ return this.mediaApi.testUrl(url, {
501
+ traceContext: traceContext
502
+ });
503
+ case 10:
497
504
  case "end":
498
505
  return _context5.stop();
499
506
  }
@@ -11,7 +11,6 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
  var _mediaCore = require("@atlaskit/media-core");
14
- var _mediaCommon = require("@atlaskit/media-common");
15
14
  var _constants = require("../../constants");
16
15
  var _artifacts = require("../../models/artifacts");
17
16
  var _request3 = require("../../utils/request");
@@ -308,7 +307,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
308
307
  }, {
309
308
  key: "getFileBinary",
310
309
  value: function () {
311
- var _getFileBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id, collectionName) {
310
+ var _getFileBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id, collectionName, abortController) {
312
311
  var maxAge,
313
312
  headers,
314
313
  binaryEndpoint,
@@ -318,7 +317,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
318
317
  return _regenerator.default.wrap(function _callee5$(_context5) {
319
318
  while (1) switch (_context5.prev = _context5.next) {
320
319
  case 0:
321
- maxAge = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : _constants.FILE_CACHE_MAX_AGE;
320
+ maxAge = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : _constants.FILE_CACHE_MAX_AGE;
322
321
  headers = {};
323
322
  binaryEndpoint = cdnFeatureFlag('binary');
324
323
  metadata = {
@@ -335,14 +334,14 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
335
334
  'max-age': "".concat(maxAge)
336
335
  }
337
336
  });
338
- return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, undefined, true).then((0, _helpers.createMapResponseToBlob)(metadata)));
337
+ return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, abortController, true).then((0, _helpers.createMapResponseToBlob)(metadata)));
339
338
  case 6:
340
339
  case "end":
341
340
  return _context5.stop();
342
341
  }
343
342
  }, _callee5, this);
344
343
  }));
345
- function getFileBinary(_x14, _x15) {
344
+ function getFileBinary(_x14, _x15, _x16) {
346
345
  return _getFileBinary.apply(this, arguments);
347
346
  }
348
347
  return getFileBinary;
@@ -382,7 +381,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
382
381
  }
383
382
  }, _callee6, this);
384
383
  }));
385
- function getFileBinaryURL(_x16, _x17) {
384
+ function getFileBinaryURL(_x17, _x18) {
386
385
  return _getFileBinaryURL.apply(this, arguments);
387
386
  }
388
387
  return getFileBinaryURL;
@@ -422,7 +421,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
422
421
  }
423
422
  }, _callee7, this);
424
423
  }));
425
- function getArtifactURL(_x18, _x19, _x20) {
424
+ function getArtifactURL(_x19, _x20, _x21) {
426
425
  return _getArtifactURL.apply(this, arguments);
427
426
  }
428
427
  return getArtifactURL;
@@ -462,7 +461,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
462
461
  }
463
462
  }, _callee8, this);
464
463
  }));
465
- function getImage(_x21, _x22, _x23, _x24, _x25) {
464
+ function getImage(_x22, _x23, _x24, _x25, _x26) {
466
465
  return _getImage.apply(this, arguments);
467
466
  }
468
467
  return getImage;
@@ -503,7 +502,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
503
502
  }
504
503
  }, _callee9, this);
505
504
  }));
506
- function getItems(_x26, _x27, _x28) {
505
+ function getItems(_x27, _x28, _x29) {
507
506
  return _getItems.apply(this, arguments);
508
507
  }
509
508
  return getItems;
@@ -534,7 +533,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
534
533
  }
535
534
  }, _callee10, this);
536
535
  }));
537
- function getImageMetadata(_x29, _x30, _x31) {
536
+ function getImageMetadata(_x30, _x31, _x32) {
538
537
  return _getImageMetadata.apply(this, arguments);
539
538
  }
540
539
  return getImageMetadata;
@@ -567,7 +566,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
567
566
  }
568
567
  }, _callee11, this);
569
568
  }));
570
- function appendChunksToUpload(_x32, _x33, _x34, _x35) {
569
+ function appendChunksToUpload(_x33, _x34, _x35, _x36) {
571
570
  return _appendChunksToUpload.apply(this, arguments);
572
571
  }
573
572
  return appendChunksToUpload;
@@ -612,6 +611,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
612
611
  auth,
613
612
  clientId,
614
613
  extendedTraceContext,
614
+ extendedParams,
615
615
  url,
616
616
  response,
617
617
  _args12 = arguments;
@@ -631,42 +631,74 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
631
631
  case 6:
632
632
  auth = _context12.sent;
633
633
  clientId = (0, _mediaCore.isClientBasedAuth)(auth) ? auth.clientId : undefined;
634
- extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
635
- spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
636
- }) : undefined;
634
+ extendedTraceContext = (0, _helpers.extendTraceContext)(traceContext);
635
+ extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
636
+ clientId: clientId
637
+ }) : params;
637
638
  url = "".concat(auth.baseUrl).concat(path);
638
639
  if (useMediaCdn) {
639
640
  url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
640
641
  }
641
- _context12.next = 13;
642
+ _context12.next = 14;
642
643
  return (0, _request3.request)(url, {
643
644
  method: method,
644
645
  endpoint: endpoint,
645
646
  auth: auth,
646
- params: addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
647
- clientId: clientId
648
- }) : params,
647
+ params: extendedParams,
649
648
  headers: headers,
650
649
  body: body,
651
650
  clientOptions: clientOptions,
652
651
  traceContext: extendedTraceContext
653
652
  }, controller);
654
- case 13:
653
+ case 14:
655
654
  response = _context12.sent;
656
655
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
657
656
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
658
657
  return _context12.abrupt("return", response);
659
- case 17:
658
+ case 18:
660
659
  case "end":
661
660
  return _context12.stop();
662
661
  }
663
662
  }, _callee12, this);
664
663
  }));
665
- function request(_x36) {
664
+ function request(_x37) {
666
665
  return _request2.apply(this, arguments);
667
666
  }
668
667
  return request;
669
668
  }()
669
+ }, {
670
+ key: "testUrl",
671
+ value: function () {
672
+ var _testUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(url) {
673
+ var options,
674
+ traceContext,
675
+ _args13 = arguments;
676
+ return _regenerator.default.wrap(function _callee13$(_context13) {
677
+ while (1) switch (_context13.prev = _context13.next) {
678
+ case 0:
679
+ options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
680
+ traceContext = options.traceContext;
681
+ _context13.next = 4;
682
+ return (0, _request3.request)(url, {
683
+ method: 'HEAD',
684
+ traceContext: (0, _helpers.extendTraceContext)(traceContext),
685
+ clientOptions: {
686
+ retryOptions: {
687
+ maxAttempts: 1
688
+ }
689
+ }
690
+ });
691
+ case 4:
692
+ case "end":
693
+ return _context13.stop();
694
+ }
695
+ }, _callee13);
696
+ }));
697
+ function testUrl(_x38) {
698
+ return _testUrl.apply(this, arguments);
699
+ }
700
+ return testUrl;
701
+ }()
670
702
  }, {
671
703
  key: "chunkHashAlgorithm",
672
704
  get: function get() {
@@ -13,6 +13,7 @@ exports.createRequestErrorFromResponse = createRequestErrorFromResponse;
13
13
  exports.createRequestErrorReason = createRequestErrorReason;
14
14
  exports.createUrl = createUrl;
15
15
  exports.extendHeaders = extendHeaders;
16
+ exports.extendTraceContext = void 0;
16
17
  exports.extractMediaHeaders = extractMediaHeaders;
17
18
  exports.fetchRetry = fetchRetry;
18
19
  exports.isAbortedRequestError = isAbortedRequestError;
@@ -26,6 +27,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
26
27
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
27
28
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
29
  var _mediaCore = require("@atlaskit/media-core");
30
+ var _mediaCommon = require("@atlaskit/media-common");
29
31
  var _authQueryParameters = require("../../models/auth-query-parameters");
30
32
  var _errors = require("./errors");
31
33
  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; }
@@ -46,6 +48,11 @@ function isFetchNetworkError(err) {
46
48
  function isRateLimitedError(error) {
47
49
  return !!error && (0, _errors.isRequestError)(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
48
50
  }
51
+ var extendTraceContext = exports.extendTraceContext = function extendTraceContext(traceContext) {
52
+ return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
53
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
54
+ }) : undefined;
55
+ };
49
56
  var ZipkinHeaderKeys = exports.ZipkinHeaderKeys = {
50
57
  traceId: 'x-b3-traceid',
51
58
  spanId: 'x-b3-spanid',
@@ -362,7 +362,7 @@ export class FileFetcherImpl {
362
362
  setTimeout(onProgress, 0, 0);
363
363
  return fromObservable(subject);
364
364
  }
365
- async downloadBinary(id, name = 'download', collectionName) {
365
+ async downloadBinary(id, name = 'download', collectionName, traceContext) {
366
366
  const url = await this.mediaApi.getFileBinaryURL(id, collectionName);
367
367
  downloadUrl(url, {
368
368
  name
@@ -372,6 +372,10 @@ export class FileFetcherImpl {
372
372
  isUserCollection: collectionName === RECENTS_COLLECTION,
373
373
  viewingLevel: 'download'
374
374
  });
375
+ // Test the download after initiated the Browser process to catch any potential errors.
376
+ await this.mediaApi.testUrl(url, {
377
+ traceContext
378
+ });
375
379
  }
376
380
  async copyFile(source, destination, options = {}, traceContext) {
377
381
  const {
@@ -1,10 +1,9 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { isClientBasedAuth } from '@atlaskit/media-core';
3
- import { getRandomHex } from '@atlaskit/media-common';
4
3
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
5
4
  import { getArtifactUrl } from '../../models/artifacts';
6
5
  import { request } from '../../utils/request';
7
- import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
6
+ import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
8
7
  import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
9
8
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
10
9
  import { ChunkHashAlgorithm } from '@atlaskit/media-core';
@@ -200,7 +199,7 @@ export class MediaStore {
200
199
  const imageEndpoint = cdnFeatureFlag('image');
201
200
  return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${imageEndpoint}`, options), auth.token);
202
201
  }
203
- async getFileBinary(id, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
202
+ async getFileBinary(id, collectionName, abortController, maxAge = FILE_CACHE_MAX_AGE) {
204
203
  const headers = {};
205
204
  const binaryEndpoint = cdnFeatureFlag('binary');
206
205
  const metadata = {
@@ -218,7 +217,7 @@ export class MediaStore {
218
217
  'max-age': `${maxAge}`
219
218
  }
220
219
  };
221
- return this.request(`/file/${id}/${binaryEndpoint}`, options, undefined, true).then(createMapResponseToBlob(metadata));
220
+ return this.request(`/file/${id}/${binaryEndpoint}`, options, abortController, true).then(createMapResponseToBlob(metadata));
222
221
  }
223
222
  async getFileBinaryURL(id, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
224
223
  const auth = await this.resolveAuth({
@@ -368,10 +367,11 @@ export class MediaStore {
368
367
  } = options;
369
368
  const auth = await this.resolveAuth(authContext);
370
369
  const clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
371
- const extendedTraceContext = traceContext ? {
372
- ...traceContext,
373
- spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
374
- } : undefined;
370
+ const extendedTraceContext = extendTraceContext(traceContext);
371
+ const extendedParams = addMediaClientParam ? {
372
+ ...params,
373
+ clientId
374
+ } : params;
375
375
  let url = `${auth.baseUrl}${path}`;
376
376
  if (useMediaCdn) {
377
377
  url = mapToMediaCdnUrl(url, auth.token);
@@ -380,10 +380,7 @@ export class MediaStore {
380
380
  method,
381
381
  endpoint,
382
382
  auth,
383
- params: addMediaClientParam ? {
384
- ...params,
385
- clientId
386
- } : params,
383
+ params: extendedParams,
387
384
  headers,
388
385
  body,
389
386
  clientOptions,
@@ -393,6 +390,20 @@ export class MediaStore {
393
390
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
394
391
  return response;
395
392
  }
393
+ async testUrl(url, options = {}) {
394
+ const {
395
+ traceContext
396
+ } = options;
397
+ await request(url, {
398
+ method: 'HEAD',
399
+ traceContext: extendTraceContext(traceContext),
400
+ clientOptions: {
401
+ retryOptions: {
402
+ maxAttempts: 1
403
+ }
404
+ }
405
+ });
406
+ }
396
407
  get chunkHashAlgorithm() {
397
408
  return this._chunkHashAlgorithm;
398
409
  }
@@ -1,4 +1,5 @@
1
1
  import { isClientBasedAuth } from '@atlaskit/media-core';
2
+ import { getRandomHex } from '@atlaskit/media-common';
2
3
  import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
3
4
  import { RequestError, isRequestError } from './errors';
4
5
  export function waitPromise(timeout) {
@@ -15,6 +16,10 @@ export function isFetchNetworkError(err) {
15
16
  export function isRateLimitedError(error) {
16
17
  return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
17
18
  }
19
+ export const extendTraceContext = traceContext => traceContext ? {
20
+ ...traceContext,
21
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
22
+ } : undefined;
18
23
  export const ZipkinHeaderKeys = {
19
24
  traceId: 'x-b3-traceid',
20
25
  spanId: 'x-b3-spanid',
@@ -456,6 +456,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
456
456
  var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
457
457
  var name,
458
458
  collectionName,
459
+ traceContext,
459
460
  url,
460
461
  _args5 = arguments;
461
462
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
@@ -463,9 +464,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
463
464
  case 0:
464
465
  name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
465
466
  collectionName = _args5.length > 2 ? _args5[2] : undefined;
466
- _context5.next = 4;
467
+ traceContext = _args5.length > 3 ? _args5[3] : undefined;
468
+ _context5.next = 5;
467
469
  return this.mediaApi.getFileBinaryURL(id, collectionName);
468
- case 4:
470
+ case 5:
469
471
  url = _context5.sent;
470
472
  downloadUrl(url, {
471
473
  name: name
@@ -475,7 +477,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
475
477
  isUserCollection: collectionName === RECENTS_COLLECTION,
476
478
  viewingLevel: 'download'
477
479
  });
478
- case 7:
480
+ // Test the download after initiated the Browser process to catch any potential errors.
481
+ _context5.next = 10;
482
+ return this.mediaApi.testUrl(url, {
483
+ traceContext: traceContext
484
+ });
485
+ case 10:
479
486
  case "end":
480
487
  return _context5.stop();
481
488
  }
@@ -6,11 +6,10 @@ 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
8
  import { isClientBasedAuth } from '@atlaskit/media-core';
9
- import { getRandomHex } from '@atlaskit/media-common';
10
9
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
11
10
  import { getArtifactUrl } from '../../models/artifacts';
12
11
  import { request as _request } from '../../utils/request';
13
- import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
12
+ import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
14
13
  import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
15
14
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
16
15
  import { ChunkHashAlgorithm } from '@atlaskit/media-core';
@@ -302,7 +301,7 @@ export var MediaStore = /*#__PURE__*/function () {
302
301
  }, {
303
302
  key: "getFileBinary",
304
303
  value: function () {
305
- var _getFileBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName) {
304
+ var _getFileBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName, abortController) {
306
305
  var maxAge,
307
306
  headers,
308
307
  binaryEndpoint,
@@ -312,7 +311,7 @@ export var MediaStore = /*#__PURE__*/function () {
312
311
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
313
312
  while (1) switch (_context5.prev = _context5.next) {
314
313
  case 0:
315
- maxAge = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : FILE_CACHE_MAX_AGE;
314
+ maxAge = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : FILE_CACHE_MAX_AGE;
316
315
  headers = {};
317
316
  binaryEndpoint = cdnFeatureFlag('binary');
318
317
  metadata = {
@@ -329,14 +328,14 @@ export var MediaStore = /*#__PURE__*/function () {
329
328
  'max-age': "".concat(maxAge)
330
329
  }
331
330
  });
332
- return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, undefined, true).then(createMapResponseToBlob(metadata)));
331
+ return _context5.abrupt("return", this.request("/file/".concat(id, "/").concat(binaryEndpoint), options, abortController, true).then(createMapResponseToBlob(metadata)));
333
332
  case 6:
334
333
  case "end":
335
334
  return _context5.stop();
336
335
  }
337
336
  }, _callee5, this);
338
337
  }));
339
- function getFileBinary(_x14, _x15) {
338
+ function getFileBinary(_x14, _x15, _x16) {
340
339
  return _getFileBinary.apply(this, arguments);
341
340
  }
342
341
  return getFileBinary;
@@ -376,7 +375,7 @@ export var MediaStore = /*#__PURE__*/function () {
376
375
  }
377
376
  }, _callee6, this);
378
377
  }));
379
- function getFileBinaryURL(_x16, _x17) {
378
+ function getFileBinaryURL(_x17, _x18) {
380
379
  return _getFileBinaryURL.apply(this, arguments);
381
380
  }
382
381
  return getFileBinaryURL;
@@ -416,7 +415,7 @@ export var MediaStore = /*#__PURE__*/function () {
416
415
  }
417
416
  }, _callee7, this);
418
417
  }));
419
- function getArtifactURL(_x18, _x19, _x20) {
418
+ function getArtifactURL(_x19, _x20, _x21) {
420
419
  return _getArtifactURL.apply(this, arguments);
421
420
  }
422
421
  return getArtifactURL;
@@ -456,7 +455,7 @@ export var MediaStore = /*#__PURE__*/function () {
456
455
  }
457
456
  }, _callee8, this);
458
457
  }));
459
- function getImage(_x21, _x22, _x23, _x24, _x25) {
458
+ function getImage(_x22, _x23, _x24, _x25, _x26) {
460
459
  return _getImage.apply(this, arguments);
461
460
  }
462
461
  return getImage;
@@ -497,7 +496,7 @@ export var MediaStore = /*#__PURE__*/function () {
497
496
  }
498
497
  }, _callee9, this);
499
498
  }));
500
- function getItems(_x26, _x27, _x28) {
499
+ function getItems(_x27, _x28, _x29) {
501
500
  return _getItems.apply(this, arguments);
502
501
  }
503
502
  return getItems;
@@ -528,7 +527,7 @@ export var MediaStore = /*#__PURE__*/function () {
528
527
  }
529
528
  }, _callee10, this);
530
529
  }));
531
- function getImageMetadata(_x29, _x30, _x31) {
530
+ function getImageMetadata(_x30, _x31, _x32) {
532
531
  return _getImageMetadata.apply(this, arguments);
533
532
  }
534
533
  return getImageMetadata;
@@ -561,7 +560,7 @@ export var MediaStore = /*#__PURE__*/function () {
561
560
  }
562
561
  }, _callee11, this);
563
562
  }));
564
- function appendChunksToUpload(_x32, _x33, _x34, _x35) {
563
+ function appendChunksToUpload(_x33, _x34, _x35, _x36) {
565
564
  return _appendChunksToUpload.apply(this, arguments);
566
565
  }
567
566
  return appendChunksToUpload;
@@ -606,6 +605,7 @@ export var MediaStore = /*#__PURE__*/function () {
606
605
  auth,
607
606
  clientId,
608
607
  extendedTraceContext,
608
+ extendedParams,
609
609
  url,
610
610
  response,
611
611
  _args12 = arguments;
@@ -625,42 +625,74 @@ export var MediaStore = /*#__PURE__*/function () {
625
625
  case 6:
626
626
  auth = _context12.sent;
627
627
  clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
628
- extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
629
- spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
630
- }) : undefined;
628
+ extendedTraceContext = extendTraceContext(traceContext);
629
+ extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
630
+ clientId: clientId
631
+ }) : params;
631
632
  url = "".concat(auth.baseUrl).concat(path);
632
633
  if (useMediaCdn) {
633
634
  url = mapToMediaCdnUrl(url, auth.token);
634
635
  }
635
- _context12.next = 13;
636
+ _context12.next = 14;
636
637
  return _request(url, {
637
638
  method: method,
638
639
  endpoint: endpoint,
639
640
  auth: auth,
640
- params: addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
641
- clientId: clientId
642
- }) : params,
641
+ params: extendedParams,
643
642
  headers: headers,
644
643
  body: body,
645
644
  clientOptions: clientOptions,
646
645
  traceContext: extendedTraceContext
647
646
  }, controller);
648
- case 13:
647
+ case 14:
649
648
  response = _context12.sent;
650
649
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
651
650
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
652
651
  return _context12.abrupt("return", response);
653
- case 17:
652
+ case 18:
654
653
  case "end":
655
654
  return _context12.stop();
656
655
  }
657
656
  }, _callee12, this);
658
657
  }));
659
- function request(_x36) {
658
+ function request(_x37) {
660
659
  return _request2.apply(this, arguments);
661
660
  }
662
661
  return request;
663
662
  }()
663
+ }, {
664
+ key: "testUrl",
665
+ value: function () {
666
+ var _testUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(url) {
667
+ var options,
668
+ traceContext,
669
+ _args13 = arguments;
670
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
671
+ while (1) switch (_context13.prev = _context13.next) {
672
+ case 0:
673
+ options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
674
+ traceContext = options.traceContext;
675
+ _context13.next = 4;
676
+ return _request(url, {
677
+ method: 'HEAD',
678
+ traceContext: extendTraceContext(traceContext),
679
+ clientOptions: {
680
+ retryOptions: {
681
+ maxAttempts: 1
682
+ }
683
+ }
684
+ });
685
+ case 4:
686
+ case "end":
687
+ return _context13.stop();
688
+ }
689
+ }, _callee13);
690
+ }));
691
+ function testUrl(_x38) {
692
+ return _testUrl.apply(this, arguments);
693
+ }
694
+ return testUrl;
695
+ }()
664
696
  }, {
665
697
  key: "chunkHashAlgorithm",
666
698
  get: function get() {
@@ -6,6 +6,7 @@ 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
8
  import { isClientBasedAuth } from '@atlaskit/media-core';
9
+ import { getRandomHex } from '@atlaskit/media-common';
9
10
  import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
10
11
  import { RequestError, isRequestError } from './errors';
11
12
  export function waitPromise(timeout) {
@@ -24,6 +25,11 @@ export function isFetchNetworkError(err) {
24
25
  export function isRateLimitedError(error) {
25
26
  return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
26
27
  }
28
+ export var extendTraceContext = function extendTraceContext(traceContext) {
29
+ return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
30
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
31
+ }) : undefined;
32
+ };
27
33
  export var ZipkinHeaderKeys = {
28
34
  traceId: 'x-b3-traceid',
29
35
  spanId: 'x-b3-spanid',
@@ -35,7 +35,7 @@ export interface FileFetcher {
35
35
  touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
36
36
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
37
37
  uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
38
- downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
38
+ downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
39
39
  getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
40
40
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
41
41
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
@@ -57,6 +57,6 @@ export declare class FileFetcherImpl implements FileFetcher {
57
57
  uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
58
58
  private getUploadingFileStateBase;
59
59
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
60
- downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
60
+ downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
61
61
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
62
62
  }
@@ -18,7 +18,7 @@ export declare class MediaStore implements MediaApi {
18
18
  getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
19
19
  getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
20
20
  private createFileImageURL;
21
- getFileBinary(id: string, collectionName?: string, maxAge?: number): Promise<Blob>;
21
+ getFileBinary(id: string, collectionName?: string, abortController?: AbortController, maxAge?: number): Promise<Blob>;
22
22
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
23
23
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
24
24
  getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
@@ -29,6 +29,9 @@ export declare class MediaStore implements MediaApi {
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
31
  request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
32
+ testUrl(url: string, options?: {
33
+ traceContext?: MediaTraceContext;
34
+ }): Promise<void>;
32
35
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
33
36
  resolveInitialAuth: () => Auth;
34
37
  get chunkHashAlgorithm(): ChunkHashAlgorithm;
@@ -156,7 +156,7 @@ export interface MediaApi {
156
156
  getFile: (fileId: string, params: MediaStoreGetFileParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
157
157
  getFileImageURL: (id: string, params?: MediaStoreGetFileImageParams) => Promise<string>;
158
158
  getFileImageURLSync: (id: string, params?: MediaStoreGetFileImageParams) => string;
159
- getFileBinary: (id: string, collectionName?: string) => Promise<Blob>;
159
+ getFileBinary: (id: string, collectionName?: string, abortController?: AbortController) => Promise<Blob>;
160
160
  getFileBinaryURL: (id: string, collectionName?: string) => Promise<string>;
161
161
  getArtifactURL: (artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string) => Promise<string>;
162
162
  getImage: (id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext) => Promise<Blob>;
@@ -167,6 +167,9 @@ export interface MediaApi {
167
167
  appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
168
168
  copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
169
169
  request: (path: string, options: MediaStoreRequestOptions, controller?: AbortController) => Promise<Response>;
170
+ testUrl: (url: string, options?: {
171
+ traceContext?: MediaTraceContext;
172
+ }) => Promise<void>;
170
173
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
171
174
  resolveInitialAuth: () => Auth;
172
175
  }
@@ -6,6 +6,7 @@ export declare function waitPromise(timeout: number): Promise<void>;
6
6
  export declare function isAbortedRequestError(err: any): boolean;
7
7
  export declare function isFetchNetworkError(err: any): err is TypeError;
8
8
  export declare function isRateLimitedError(error: Error | undefined): boolean;
9
+ export declare const extendTraceContext: (traceContext?: MediaTraceContext) => Required<MediaTraceContext> | undefined;
9
10
  export declare const ZipkinHeaderKeys: {
10
11
  traceId: string;
11
12
  spanId: string;
@@ -1,6 +1,6 @@
1
1
  import { type Auth } from '@atlaskit/media-core';
2
2
  import type { MediaTraceContext } from '@atlaskit/media-common';
3
- export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
4
4
  export type RequestParams = {
5
5
  [key: string]: any;
6
6
  };
@@ -35,7 +35,7 @@ export interface FileFetcher {
35
35
  touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
36
36
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
37
37
  uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
38
- downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
38
+ downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
39
39
  getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
40
40
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
41
41
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
@@ -57,6 +57,6 @@ export declare class FileFetcherImpl implements FileFetcher {
57
57
  uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
58
58
  private getUploadingFileStateBase;
59
59
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
60
- downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
60
+ downloadBinary(id: string, name?: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
61
61
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
62
62
  }
@@ -18,7 +18,7 @@ export declare class MediaStore implements MediaApi {
18
18
  getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
19
19
  getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
20
20
  private createFileImageURL;
21
- getFileBinary(id: string, collectionName?: string, maxAge?: number): Promise<Blob>;
21
+ getFileBinary(id: string, collectionName?: string, abortController?: AbortController, maxAge?: number): Promise<Blob>;
22
22
  getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
23
23
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
24
24
  getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
@@ -29,6 +29,9 @@ export declare class MediaStore implements MediaApi {
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
31
  request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController, useMediaCdn?: boolean): Promise<Response>;
32
+ testUrl(url: string, options?: {
33
+ traceContext?: MediaTraceContext;
34
+ }): Promise<void>;
32
35
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
33
36
  resolveInitialAuth: () => Auth;
34
37
  get chunkHashAlgorithm(): ChunkHashAlgorithm;
@@ -156,7 +156,7 @@ export interface MediaApi {
156
156
  getFile: (fileId: string, params: MediaStoreGetFileParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
157
157
  getFileImageURL: (id: string, params?: MediaStoreGetFileImageParams) => Promise<string>;
158
158
  getFileImageURLSync: (id: string, params?: MediaStoreGetFileImageParams) => string;
159
- getFileBinary: (id: string, collectionName?: string) => Promise<Blob>;
159
+ getFileBinary: (id: string, collectionName?: string, abortController?: AbortController) => Promise<Blob>;
160
160
  getFileBinaryURL: (id: string, collectionName?: string) => Promise<string>;
161
161
  getArtifactURL: (artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string) => Promise<string>;
162
162
  getImage: (id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext) => Promise<Blob>;
@@ -167,6 +167,9 @@ export interface MediaApi {
167
167
  appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
168
168
  copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
169
169
  request: (path: string, options: MediaStoreRequestOptions, controller?: AbortController) => Promise<Response>;
170
+ testUrl: (url: string, options?: {
171
+ traceContext?: MediaTraceContext;
172
+ }) => Promise<void>;
170
173
  resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
171
174
  resolveInitialAuth: () => Auth;
172
175
  }
@@ -6,6 +6,7 @@ export declare function waitPromise(timeout: number): Promise<void>;
6
6
  export declare function isAbortedRequestError(err: any): boolean;
7
7
  export declare function isFetchNetworkError(err: any): err is TypeError;
8
8
  export declare function isRateLimitedError(error: Error | undefined): boolean;
9
+ export declare const extendTraceContext: (traceContext?: MediaTraceContext) => Required<MediaTraceContext> | undefined;
9
10
  export declare const ZipkinHeaderKeys: {
10
11
  traceId: string;
11
12
  spanId: string;
@@ -1,6 +1,6 @@
1
1
  import { type Auth } from '@atlaskit/media-core';
2
2
  import type { MediaTraceContext } from '@atlaskit/media-common';
3
- export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
4
4
  export type RequestParams = {
5
5
  [key: string]: any;
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "28.1.0",
3
+ "version": "28.3.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"