@atlaskit/media-client 18.1.0 → 19.1.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/client/collection-fetcher.js +8 -8
  3. package/dist/cjs/client/file-fetcher/index.js +40 -36
  4. package/dist/cjs/client/media-client.js +2 -2
  5. package/dist/cjs/client/media-store/index.js +69 -52
  6. package/dist/cjs/models/file-state.js +4 -2
  7. package/dist/cjs/uploader/index.js +40 -70
  8. package/dist/cjs/utils/createFileDataLoader.js +32 -15
  9. package/dist/cjs/utils/request/helpers.js +39 -22
  10. package/dist/cjs/utils/request/index.js +5 -3
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/client/collection-fetcher.js +6 -6
  13. package/dist/es2019/client/file-fetcher/index.js +16 -14
  14. package/dist/es2019/client/media-client.js +2 -2
  15. package/dist/es2019/client/media-store/index.js +50 -41
  16. package/dist/es2019/models/file-state.js +4 -2
  17. package/dist/es2019/uploader/index.js +17 -21
  18. package/dist/es2019/utils/createFileDataLoader.js +13 -3
  19. package/dist/es2019/utils/request/helpers.js +26 -8
  20. package/dist/es2019/utils/request/index.js +6 -4
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/client/collection-fetcher.js +8 -8
  23. package/dist/esm/client/file-fetcher/index.js +40 -36
  24. package/dist/esm/client/media-client.js +2 -2
  25. package/dist/esm/client/media-store/index.js +68 -50
  26. package/dist/esm/models/file-state.js +4 -2
  27. package/dist/esm/uploader/index.js +40 -69
  28. package/dist/esm/utils/createFileDataLoader.js +31 -13
  29. package/dist/esm/utils/request/helpers.js +36 -20
  30. package/dist/esm/utils/request/index.js +6 -4
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/client/collection-fetcher.d.ts +4 -3
  33. package/dist/types/client/file-fetcher/index.d.ts +9 -8
  34. package/dist/types/client/media-client.d.ts +2 -2
  35. package/dist/types/client/media-store/index.d.ts +16 -21
  36. package/dist/types/models/file-state.d.ts +9 -6
  37. package/dist/types/models/media.d.ts +3 -1
  38. package/dist/types/uploader/index.d.ts +2 -1
  39. package/dist/types/utils/request/helpers.d.ts +10 -2
  40. package/dist/types/utils/request/types.d.ts +3 -0
  41. package/package.json +7 -15
  42. package/report.api.md +116 -75
  43. package/dist/types-ts4.0/client/__mocks__/collection-fetcher.d.ts +0 -8
  44. package/dist/types-ts4.0/client/__mocks__/file-fetcher.d.ts +0 -10
  45. package/dist/types-ts4.0/client/__mocks__/media-client.d.ts +0 -13
  46. package/dist/types-ts4.0/client/collection-fetcher.d.ts +0 -35
  47. package/dist/types-ts4.0/client/events.d.ts +0 -14
  48. package/dist/types-ts4.0/client/file-fetcher/error.d.ts +0 -29
  49. package/dist/types-ts4.0/client/file-fetcher/index.d.ts +0 -56
  50. package/dist/types-ts4.0/client/media-client.d.ts +0 -28
  51. package/dist/types-ts4.0/client/media-store/error.d.ts +0 -16
  52. package/dist/types-ts4.0/client/media-store/index.d.ts +0 -174
  53. package/dist/types-ts4.0/client/media-store/resolveAuth.d.ts +0 -4
  54. package/dist/types-ts4.0/client/mobile-upload.d.ts +0 -11
  55. package/dist/types-ts4.0/client/stargate-client.d.ts +0 -15
  56. package/dist/types-ts4.0/constants.d.ts +0 -6
  57. package/dist/types-ts4.0/file-streams-cache.d.ts +0 -15
  58. package/dist/types-ts4.0/globalMediaEventEmitter.d.ts +0 -6
  59. package/dist/types-ts4.0/identifier.d.ts +0 -15
  60. package/dist/types-ts4.0/index.d.ts +0 -89
  61. package/dist/types-ts4.0/models/artifacts.d.ts +0 -12
  62. package/dist/types-ts4.0/models/auth-headers.d.ts +0 -11
  63. package/dist/types-ts4.0/models/auth-query-parameters.d.ts +0 -11
  64. package/dist/types-ts4.0/models/errors/helpers.d.ts +0 -6
  65. package/dist/types-ts4.0/models/errors/index.d.ts +0 -11
  66. package/dist/types-ts4.0/models/errors/types.d.ts +0 -15
  67. package/dist/types-ts4.0/models/file-state.d.ts +0 -91
  68. package/dist/types-ts4.0/models/item.d.ts +0 -25
  69. package/dist/types-ts4.0/models/media-subscribable.d.ts +0 -3
  70. package/dist/types-ts4.0/models/media.d.ts +0 -66
  71. package/dist/types-ts4.0/models/mobile-upload.d.ts +0 -28
  72. package/dist/types-ts4.0/upload-controller.d.ts +0 -7
  73. package/dist/types-ts4.0/uploader/calculateChunkSize.d.ts +0 -11
  74. package/dist/types-ts4.0/uploader/error.d.ts +0 -29
  75. package/dist/types-ts4.0/uploader/index.d.ts +0 -21
  76. package/dist/types-ts4.0/utils/checkWebpSupport.d.ts +0 -1
  77. package/dist/types-ts4.0/utils/convertBase64ToBlob.d.ts +0 -1
  78. package/dist/types-ts4.0/utils/createFileDataLoader.d.ts +0 -30
  79. package/dist/types-ts4.0/utils/createMediaSubject.d.ts +0 -3
  80. package/dist/types-ts4.0/utils/detectEmptyFile.d.ts +0 -16
  81. package/dist/types-ts4.0/utils/getDimensionsFromBlob.d.ts +0 -6
  82. package/dist/types-ts4.0/utils/getImageDimensionsFromBlob.d.ts +0 -5
  83. package/dist/types-ts4.0/utils/getMediaTypeFromUploadableFile.d.ts +0 -3
  84. package/dist/types-ts4.0/utils/getVideoDimensionsFromBlob.d.ts +0 -5
  85. package/dist/types-ts4.0/utils/hashing/hasher.d.ts +0 -3
  86. package/dist/types-ts4.0/utils/hashing/hasherCreator.d.ts +0 -3
  87. package/dist/types-ts4.0/utils/hashing/simpleHasher.d.ts +0 -4
  88. package/dist/types-ts4.0/utils/hashing/workerHasher.d.ts +0 -16
  89. package/dist/types-ts4.0/utils/imageResizeModeToFileImageMode.d.ts +0 -3
  90. package/dist/types-ts4.0/utils/isImageRemote.d.ts +0 -1
  91. package/dist/types-ts4.0/utils/mediaSubscribable/fromObservable.d.ts +0 -5
  92. package/dist/types-ts4.0/utils/mediaSubscribable/index.d.ts +0 -3
  93. package/dist/types-ts4.0/utils/mediaSubscribable/toPromise.d.ts +0 -10
  94. package/dist/types-ts4.0/utils/mediaSubscribable/types.d.ts +0 -16
  95. package/dist/types-ts4.0/utils/mobileUpload/error.d.ts +0 -29
  96. package/dist/types-ts4.0/utils/mobileUpload/helpers.d.ts +0 -8
  97. package/dist/types-ts4.0/utils/mobileUpload/index.d.ts +0 -5
  98. package/dist/types-ts4.0/utils/mobileUpload/servicesCache.d.ts +0 -4
  99. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/index.d.ts +0 -7
  100. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/error.d.ts +0 -3
  101. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processed.d.ts +0 -3
  102. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processing.d.ts +0 -3
  103. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +0 -3
  104. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/uploading.d.ts +0 -3
  105. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/types.d.ts +0 -69
  106. package/dist/types-ts4.0/utils/overrideMediaTypeIfUnknown.d.ts +0 -5
  107. package/dist/types-ts4.0/utils/polling/errors.d.ts +0 -12
  108. package/dist/types-ts4.0/utils/polling/index.d.ts +0 -33
  109. package/dist/types-ts4.0/utils/polling/types.d.ts +0 -7
  110. package/dist/types-ts4.0/utils/request/errors.d.ts +0 -20
  111. package/dist/types-ts4.0/utils/request/helpers.d.ts +0 -38
  112. package/dist/types-ts4.0/utils/request/index.d.ts +0 -5
  113. package/dist/types-ts4.0/utils/request/types.d.ts +0 -43
  114. package/dist/types-ts4.0/utils/safeUnsubscribe.d.ts +0 -2
  115. package/dist/types-ts4.0/utils/setTimeoutPromise.d.ts +0 -2
  116. package/dist/types-ts4.0/utils/shouldFetchRemoteFileStates.d.ts +0 -16
  117. package/dist/types-ts4.0/utils/url.d.ts +0 -17
  118. package/dist/types-ts4.0/utils/with-media-client-hoc.d.ts +0 -16
@@ -1,10 +1,17 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
+
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
+
4
10
  // import setimmediate to temporary fix dataloader 2.0.0 bug
5
11
  // @see https://github.com/graphql/dataloader/issues/249
6
12
  import 'setimmediate';
7
13
  import Dataloader from 'dataloader';
14
+ import { getRandomHex } from '@atlaskit/media-common';
8
15
  export var MAX_BATCH_SIZE = 100;
9
16
 
10
17
  var isBatchLoadingErrorResult = function isBatchLoadingErrorResult(result) {
@@ -20,7 +27,9 @@ export var getItemsFromKeys = function getItemsFromKeys(dataloaderKeys, fileItem
20
27
  var id = fileItem.id,
21
28
  collection = fileItem.collection;
22
29
  var key = makeCacheKey(id, collection);
23
- prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : fileItem.details;
30
+ prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : _objectSpread(_objectSpread({}, fileItem.details), {}, {
31
+ metadataTraceContext: fileItem.metadataTraceContext
32
+ });
24
33
  return prev;
25
34
  }, {});
26
35
  return dataloaderKeys.map(function (dataloaderKey) {
@@ -64,26 +73,35 @@ export function createBatchLoadingFunc(mediaStore) {
64
73
  _context2.next = 5;
65
74
  return Promise.all(Object.keys(fileIdsByCollection).map( /*#__PURE__*/function () {
66
75
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionNameKey) {
67
- var fileIds, collectionName, response;
76
+ var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext;
68
77
  return _regeneratorRuntime.wrap(function _callee$(_context) {
69
78
  while (1) {
70
79
  switch (_context.prev = _context.next) {
71
80
  case 0:
81
+ metadataTraceContext = {
82
+ traceId: getRandomHex(8),
83
+ spanId: getRandomHex(8)
84
+ };
72
85
  fileIds = fileIdsByCollection[collectionNameKey];
73
86
  collectionName = collectionNameKey === nonCollectionName ? undefined : collectionNameKey;
74
- _context.prev = 2;
75
- _context.next = 5;
76
- return mediaStore.getItems(fileIds, collectionName);
87
+ _context.prev = 3;
88
+ _context.next = 6;
89
+ return mediaStore.getItems(fileIds, collectionName, metadataTraceContext);
77
90
 
78
- case 5:
91
+ case 6:
79
92
  response = _context.sent;
80
- items.push.apply(items, _toConsumableArray(response.data.items));
81
- _context.next = 12;
93
+ itemsWithMetadataTraceContext = response.data.items.map(function (item) {
94
+ return _objectSpread(_objectSpread({}, item), {}, {
95
+ metadataTraceContext: metadataTraceContext
96
+ });
97
+ });
98
+ items.push.apply(items, _toConsumableArray(itemsWithMetadataTraceContext));
99
+ _context.next = 14;
82
100
  break;
83
101
 
84
- case 9:
85
- _context.prev = 9;
86
- _context.t0 = _context["catch"](2);
102
+ case 11:
103
+ _context.prev = 11;
104
+ _context.t0 = _context["catch"](3);
87
105
  fileIds.forEach(function (fileId) {
88
106
  items.push({
89
107
  id: fileId,
@@ -92,12 +110,12 @@ export function createBatchLoadingFunc(mediaStore) {
92
110
  });
93
111
  });
94
112
 
95
- case 12:
113
+ case 14:
96
114
  case "end":
97
115
  return _context.stop();
98
116
  }
99
117
  }
100
- }, _callee, null, [[2, 9]]);
118
+ }, _callee, null, [[3, 11]]);
101
119
  }));
102
120
 
103
121
  return function (_x2) {
@@ -31,7 +31,25 @@ export function isFetchNetworkError(err) {
31
31
  export function isRateLimitedError(error) {
32
32
  return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
33
33
  }
34
+ export var ZipkinHeaderKeys = {
35
+ traceId: 'x-b3-traceid',
36
+ spanId: 'x-b3-spanid',
37
+ parentSpanId: 'x-b3-parentspanid',
38
+ sampled: 'x-b3-sampled',
39
+ flags: 'x-b3-flags'
40
+ };
41
+
42
+ var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
43
+ var _ref;
44
+
45
+ return traceContext ? (_ref = {}, _defineProperty(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), _defineProperty(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
46
+ };
47
+
34
48
  export function mapAuthToRequestHeaders(auth) {
49
+ if (!auth) {
50
+ return {};
51
+ }
52
+
35
53
  if (isClientBasedAuth(auth)) {
36
54
  return {
37
55
  'X-Client-Id': auth.clientId,
@@ -44,18 +62,18 @@ export function mapAuthToRequestHeaders(auth) {
44
62
  Authorization: "Bearer ".concat(auth.token)
45
63
  };
46
64
  }
47
- export function createUrl(url, _ref) {
48
- var params = _ref.params,
49
- auth = _ref.auth;
65
+ export function createUrl(url, _ref2) {
66
+ var params = _ref2.params,
67
+ auth = _ref2.auth;
50
68
  var parsedUrl = new URL(url);
51
69
  var authParams = auth && mapAuthToQueryParameters(auth) || {};
52
70
 
53
71
  var paramsToAppend = _objectSpread(_objectSpread({}, params), authParams);
54
72
 
55
- Object.entries(paramsToAppend).filter(function (_ref2) {
56
- var _ref3 = _slicedToArray(_ref2, 2),
57
- _ = _ref3[0],
58
- value = _ref3[1];
73
+ Object.entries(paramsToAppend).filter(function (_ref3) {
74
+ var _ref4 = _slicedToArray(_ref3, 2),
75
+ _ = _ref4[0],
76
+ value = _ref4[1];
59
77
 
60
78
  return value != null;
61
79
  }).forEach(function (pair) {
@@ -66,14 +84,12 @@ export function createUrl(url, _ref) {
66
84
  parsedUrl.searchParams.sort();
67
85
  return parsedUrl.toString();
68
86
  }
69
- export function withAuth(auth) {
70
- return function (headers) {
71
- if (auth) {
72
- return _objectSpread(_objectSpread({}, headers || {}), mapAuthToRequestHeaders(auth));
73
- }
87
+ export function extendHeaders(headers, auth, traceContext) {
88
+ if (!auth && !traceContext && !headers) {
89
+ return undefined;
90
+ }
74
91
 
75
- return headers;
76
- };
92
+ return _objectSpread(_objectSpread(_objectSpread({}, headers !== null && headers !== void 0 ? headers : {}), mapAuthToRequestHeaders(auth)), mapTraceIdToRequestHeaders(traceContext));
77
93
  }
78
94
  /**
79
95
  * @deprecated Helper is deprecated and will be removed in the next major version.
@@ -167,7 +183,7 @@ export function mapResponseToVoid() {
167
183
  }
168
184
  export function createMapResponseToJson(metadata) {
169
185
  return /*#__PURE__*/function () {
170
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response) {
186
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response) {
171
187
  return _regeneratorRuntime.wrap(function _callee$(_context) {
172
188
  while (1) {
173
189
  switch (_context.prev = _context.next) {
@@ -195,13 +211,13 @@ export function createMapResponseToJson(metadata) {
195
211
  }));
196
212
 
197
213
  return function (_x3) {
198
- return _ref4.apply(this, arguments);
214
+ return _ref5.apply(this, arguments);
199
215
  };
200
216
  }();
201
217
  }
202
218
  export function createMapResponseToBlob(metadata) {
203
219
  return /*#__PURE__*/function () {
204
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(response) {
220
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(response) {
205
221
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
206
222
  while (1) {
207
223
  switch (_context2.prev = _context2.next) {
@@ -229,7 +245,7 @@ export function createMapResponseToBlob(metadata) {
229
245
  }));
230
246
 
231
247
  return function (_x4) {
232
- return _ref5.apply(this, arguments);
248
+ return _ref6.apply(this, arguments);
233
249
  };
234
250
  }();
235
251
  }
@@ -274,7 +290,7 @@ function _fetchRetry() {
274
290
  timeoutInMs = startTimeoutInMs;
275
291
 
276
292
  waitAndBumpTimeout = /*#__PURE__*/function () {
277
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
293
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
278
294
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
279
295
  while (1) {
280
296
  switch (_context5.prev = _context5.next) {
@@ -295,7 +311,7 @@ function _fetchRetry() {
295
311
  }));
296
312
 
297
313
  return function waitAndBumpTimeout() {
298
- return _ref6.apply(this, arguments);
314
+ return _ref7.apply(this, arguments);
299
315
  };
300
316
  }();
301
317
 
@@ -2,7 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  export { RequestError, isRequestError } from './errors';
4
4
  export { isRateLimitedError } from './helpers';
5
- import { createUrl, fetchRetry, createProcessFetchResponse, withAuth } from './helpers';
5
+ import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders } from './helpers';
6
6
  export function request(_x) {
7
7
  return _request.apply(this, arguments);
8
8
  }
@@ -20,6 +20,7 @@ function _request() {
20
20
  body,
21
21
  _options$clientOption,
22
22
  clientOptions,
23
+ traceContext,
23
24
  retryOptions,
24
25
  metadata,
25
26
  doFetch,
@@ -31,11 +32,12 @@ function _request() {
31
32
  case 0:
32
33
  options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
33
34
  controller = _args.length > 2 ? _args[2] : undefined;
34
- _options$method = options.method, method = _options$method === void 0 ? 'GET' : _options$method, endpoint = options.endpoint, auth = options.auth, params = options.params, headers = options.headers, body = options.body, _options$clientOption = options.clientOptions, clientOptions = _options$clientOption === void 0 ? {} : _options$clientOption;
35
+ _options$method = options.method, method = _options$method === void 0 ? 'GET' : _options$method, endpoint = options.endpoint, auth = options.auth, params = options.params, headers = options.headers, body = options.body, _options$clientOption = options.clientOptions, clientOptions = _options$clientOption === void 0 ? {} : _options$clientOption, traceContext = options.traceContext;
35
36
  retryOptions = clientOptions.retryOptions;
36
37
  metadata = {
37
38
  method: method,
38
- endpoint: endpoint
39
+ endpoint: endpoint,
40
+ traceContext: traceContext
39
41
  }; // TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
40
42
 
41
43
  doFetch = function doFetch() {
@@ -44,7 +46,7 @@ function _request() {
44
46
  }), {
45
47
  method: method,
46
48
  body: body,
47
- headers: withAuth(auth)(headers),
49
+ headers: extendHeaders(headers, auth, traceContext),
48
50
  signal: controller && controller.signal
49
51
  }).then(createProcessFetchResponse(metadata));
50
52
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "18.1.0",
3
+ "version": "19.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -3,6 +3,7 @@ import { FileDetails, FileItem } from '../models/item';
3
3
  import { MediaCollectionItem } from '../models/media';
4
4
  import { MediaStore, MediaStoreGetCollectionItemsParams } from './media-store';
5
5
  import { MediaSubscribable } from '../utils/mediaSubscribable';
6
+ import { MediaTraceContext } from '@atlaskit/media-common';
6
7
  export interface MediaCollectionFileItemDetails extends FileDetails {
7
8
  occurrenceKey: string;
8
9
  }
@@ -29,7 +30,7 @@ export declare class CollectionFetcher {
29
30
  private createFileStateObserver;
30
31
  private populateCache;
31
32
  private removeFromCache;
32
- getItems(collectionName: string, params?: MediaStoreGetCollectionItemsParams): MediaSubscribable<MediaCollectionItem[]>;
33
- removeFile(id: string, collectionName: string, occurrenceKey?: string): Promise<void>;
34
- loadNextPage(collectionName: string, params?: MediaStoreGetCollectionItemsParams): Promise<void>;
33
+ getItems(collectionName: string, params?: MediaStoreGetCollectionItemsParams, traceContext?: MediaTraceContext): MediaSubscribable<MediaCollectionItem[]>;
34
+ removeFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
35
+ loadNextPage(collectionName: string, params?: MediaStoreGetCollectionItemsParams, traceContext?: MediaTraceContext): Promise<void>;
35
36
  }
@@ -8,6 +8,7 @@ import { MediaFileArtifacts } from '../../models/artifacts';
8
8
  import { UploadController } from '../../upload-controller';
9
9
  import { MediaSubscribable } from '../../utils/mediaSubscribable';
10
10
  import { Dimensions } from '../../utils/getDimensionsFromBlob';
11
+ import { MediaTraceContext } from '@atlaskit/media-common';
11
12
  export type { FileFetcherErrorAttributes, FileFetcherErrorReason, } from './error';
12
13
  export { isFileFetcherError, FileFetcherError } from './error';
13
14
  export interface CopySourceFile {
@@ -30,12 +31,12 @@ export declare type ExternalUploadPayload = {
30
31
  export interface FileFetcher {
31
32
  getFileState(id: string, options?: GetFileOptions): MediaSubscribable<FileState>;
32
33
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
33
- touchFiles(descriptors: TouchFileDescriptor[], collection?: string): Promise<TouchedFiles>;
34
- upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds): MediaSubscribable<FileState>;
35
- uploadExternal(url: string, collection?: string): Promise<ExternalUploadPayload>;
34
+ touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
35
+ upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable<FileState>;
36
+ uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
36
37
  downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
37
38
  getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
38
- copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions): Promise<MediaFile>;
39
+ copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
39
40
  getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
40
41
  }
41
42
  export declare class FileFetcherImpl implements FileFetcher {
@@ -47,10 +48,10 @@ export declare class FileFetcherImpl implements FileFetcher {
47
48
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
48
49
  getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
49
50
  private createDownloadFileStream;
50
- touchFiles(descriptors: TouchFileDescriptor[], collection?: string): Promise<TouchedFiles>;
51
+ touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
51
52
  private generateUploadableFileUpfrontIds;
52
- uploadExternal(url: string, collection?: string): Promise<ExternalUploadPayload>;
53
- upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds): MediaSubscribable<FileState>;
53
+ uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
54
+ upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable<FileState>;
54
55
  downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
55
- copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions): Promise<MediaFile>;
56
+ copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
56
57
  }
@@ -1,5 +1,5 @@
1
1
  import { MediaClientConfig } from '@atlaskit/media-core';
2
- import { MediaFeatureFlags } from '@atlaskit/media-common';
2
+ import { MediaFeatureFlags, MediaTraceContext } from '@atlaskit/media-common';
3
3
  import { MediaStore, MediaStoreGetFileImageParams, ImageMetadata } from './media-store';
4
4
  import { CollectionFetcher } from './collection-fetcher';
5
5
  import { FileFetcher } from './file-fetcher';
@@ -17,7 +17,7 @@ export declare class MediaClient {
17
17
  private mobileUpload?;
18
18
  readonly config: MediaClientConfig;
19
19
  constructor(mediaClientConfig: MediaClientConfig, featureFlags?: MediaFeatureFlags | undefined);
20
- getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceId?: string): Promise<Blob>;
20
+ getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
21
21
  getImageUrl(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
22
22
  getImageUrlSync(id: string, params?: MediaStoreGetFileImageParams): string;
23
23
  getImageMetadata(id: string, params?: MediaStoreGetFileImageParams): Promise<ImageMetadata>;
@@ -1,48 +1,41 @@
1
1
  import { AsapBasedAuth, AuthContext, ClientAltBasedAuth, MediaApiConfig, Auth } from '@atlaskit/media-core';
2
- import { MediaFeatureFlags } from '@atlaskit/media-common';
2
+ import { MediaFeatureFlags, MediaTraceContext } from '@atlaskit/media-common';
3
3
  import { MediaFileArtifacts } from '../../models/artifacts';
4
4
  import { MediaChunksProbe, MediaCollectionItemFullDetails, MediaCollectionItems, MediaFile, MediaUpload } from '../../models/media';
5
5
  import { ClientOptions, RequestHeaders, RequestMethod, RequestParams, RequestMetadata } from '../../utils/request/types';
6
6
  export type { MediaStoreErrorReason, MediaStoreErrorAttributes } from './error';
7
7
  export { MediaStoreError, isMediaStoreError } from './error';
8
- export declare const ZipkinHeaderKeys: {
9
- traceId: string;
10
- spanId: string;
11
- parentSpanId: string;
12
- sampled: string;
13
- flags: string;
14
- };
15
8
  export declare class MediaStore {
16
9
  private readonly config;
17
10
  readonly featureFlags?: MediaFeatureFlags | undefined;
18
11
  constructor(config: MediaApiConfig, featureFlags?: MediaFeatureFlags | undefined);
19
- getCollectionItems(collectionName: string, params?: MediaStoreGetCollectionItemsParams): Promise<MediaStoreResponse<MediaCollectionItems>>;
20
- removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string): Promise<void>;
21
- createUpload(createUpTo?: number, collectionName?: string): Promise<MediaStoreResponse<MediaUpload[]>>;
12
+ getCollectionItems(collectionName: string, params?: MediaStoreGetCollectionItemsParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaCollectionItems>>;
13
+ removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
14
+ createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
22
15
  uploadChunk(etag: string, blob: Blob, { collectionName, uploadId, partNumber, }?: {
23
16
  collectionName?: string;
24
17
  uploadId?: string;
25
18
  partNumber?: number;
26
- }): Promise<void>;
19
+ }, traceContext?: MediaTraceContext): Promise<void>;
27
20
  probeChunks(chunks: string[], { collectionName, uploadId, }?: {
28
21
  collectionName?: string;
29
22
  uploadId?: string;
30
- }): Promise<MediaStoreResponse<MediaChunksProbe>>;
31
- createFileFromUpload(body: MediaStoreCreateFileFromUploadBody, params?: MediaStoreCreateFileFromUploadParams): Promise<MediaStoreResponse<MediaFile>>;
32
- touchFiles(body: MediaStoreTouchFileBody, params?: MediaStoreTouchFileParams): Promise<MediaStoreResponse<TouchedFiles>>;
33
- getFile(fileId: string, params?: MediaStoreGetFileParams): Promise<MediaStoreResponse<MediaFile>>;
23
+ }, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaChunksProbe>>;
24
+ createFileFromUpload(body: MediaStoreCreateFileFromUploadBody, params?: MediaStoreCreateFileFromUploadParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
25
+ touchFiles(body: MediaStoreTouchFileBody, params?: MediaStoreTouchFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<TouchedFiles>>;
26
+ getFile(fileId: string, params?: MediaStoreGetFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
34
27
  getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
35
28
  getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
36
29
  private createFileImageURL;
37
30
  getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
38
31
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
39
- getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceId?: string): Promise<Blob>;
40
- getItems(ids: string[], collectionName?: string): Promise<MediaStoreResponse<ItemsPayload>>;
41
- getImageMetadata(id: string, params?: MediaStoreGetFileImageParams): Promise<{
32
+ getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
33
+ getItems(ids: string[], collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<ItemsPayload>>;
34
+ getImageMetadata(id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext): Promise<{
42
35
  metadata: ImageMetadata;
43
36
  }>;
44
- appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string): Promise<void>;
45
- copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams): Promise<MediaStoreResponse<MediaFile>>;
37
+ appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
38
+ copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
46
39
  request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
47
40
  resolveAuth: (authContext?: AuthContext | undefined) => Promise<Auth>;
48
41
  resolveInitialAuth: () => Auth;
@@ -54,6 +47,7 @@ export interface ResponseFileItem {
54
47
  type: 'file';
55
48
  details: MediaCollectionItemFullDetails;
56
49
  collection?: string;
50
+ metadataTraceContext?: MediaTraceContext;
57
51
  }
58
52
  export interface ItemsPayload {
59
53
  items: ResponseFileItem[];
@@ -79,6 +73,7 @@ export declare type MediaStoreRequestOptions = RequestMetadata & {
79
73
  readonly headers?: RequestHeaders;
80
74
  readonly body?: any;
81
75
  readonly clientOptions?: ClientOptions;
76
+ readonly traceContext?: MediaTraceContext;
82
77
  };
83
78
  export declare type MediaStoreCreateFileFromUploadParams = {
84
79
  readonly collection?: string;
@@ -1,7 +1,10 @@
1
- import { FileStatus as CommonFileStatus } from '@atlaskit/media-common';
1
+ import { FileStatus as CommonFileStatus, MediaTraceContext } from '@atlaskit/media-common';
2
2
  import { MediaStoreResponse } from '../client/media-store';
3
3
  import { MediaFileArtifacts } from './artifacts';
4
4
  import { MediaCollectionItemFullDetails, MediaFile, MediaRepresentations, MediaType } from './media';
5
+ export declare type BaseFileState = {
6
+ metadataTraceContext?: MediaTraceContext;
7
+ };
5
8
  export declare type FileStatus = CommonFileStatus;
6
9
  export interface FilePreview {
7
10
  value: Blob | string;
@@ -18,7 +21,7 @@ export interface GetFileOptions {
18
21
  collectionName?: string;
19
22
  occurrenceKey?: string;
20
23
  }
21
- export interface UploadingFileState {
24
+ export interface UploadingFileState extends BaseFileState {
22
25
  status: 'uploading';
23
26
  id: string;
24
27
  occurrenceKey?: string;
@@ -33,7 +36,7 @@ export interface UploadingFileState {
33
36
  export interface PreviewableFileState {
34
37
  preview: FilePreview | Promise<FilePreview>;
35
38
  }
36
- export interface ProcessingFileState {
39
+ export interface ProcessingFileState extends BaseFileState {
37
40
  status: 'processing';
38
41
  id: string;
39
42
  occurrenceKey?: string;
@@ -46,7 +49,7 @@ export interface ProcessingFileState {
46
49
  representations?: MediaRepresentations;
47
50
  createdAt?: number;
48
51
  }
49
- export interface ProcessedFileState {
52
+ export interface ProcessedFileState extends BaseFileState {
50
53
  status: 'processed';
51
54
  id: string;
52
55
  occurrenceKey?: string;
@@ -59,7 +62,7 @@ export interface ProcessedFileState {
59
62
  representations?: MediaRepresentations;
60
63
  createdAt?: number;
61
64
  }
62
- export interface ProcessingFailedState {
65
+ export interface ProcessingFailedState extends BaseFileState {
63
66
  status: 'failed-processing';
64
67
  id: string;
65
68
  occurrenceKey?: string;
@@ -72,7 +75,7 @@ export interface ProcessingFailedState {
72
75
  representations?: MediaRepresentations;
73
76
  createdAt?: number;
74
77
  }
75
- export interface ErrorFileState {
78
+ export interface ErrorFileState extends BaseFileState {
76
79
  status: 'error';
77
80
  id: string;
78
81
  occurrenceKey?: string;
@@ -1,4 +1,4 @@
1
- import { MediaFeatureFlags, MediaType } from '@atlaskit/media-common';
1
+ import { MediaFeatureFlags, MediaTraceContext, MediaType } from '@atlaskit/media-common';
2
2
  import type { MediaFileArtifacts } from './artifacts';
3
3
  export declare type MediaFileProcessingStatus = 'pending' | 'succeeded' | 'failed';
4
4
  export type { MediaType } from '@atlaskit/media-common';
@@ -13,6 +13,7 @@ export declare type MediaFile = {
13
13
  readonly artifacts: MediaFileArtifacts;
14
14
  readonly representations: MediaRepresentations;
15
15
  readonly createdAt?: number;
16
+ readonly metadataTraceContext?: MediaTraceContext;
16
17
  };
17
18
  export declare type MediaCollection = {
18
19
  readonly name: string;
@@ -41,6 +42,7 @@ export declare type MediaCollectionItemFullDetails = {
41
42
  readonly artifacts: MediaFileArtifacts;
42
43
  readonly representations: MediaRepresentations;
43
44
  readonly createdAt?: number;
45
+ readonly metadataTraceContext?: MediaTraceContext;
44
46
  };
45
47
  export declare type MediaRepresentations = {
46
48
  image?: Object;
@@ -1,5 +1,6 @@
1
1
  import { ChunkinatorFile } from '@atlaskit/chunkinator';
2
2
  import { MediaStore } from '../client/media-store';
3
+ import { MediaTraceContext } from '@atlaskit/media-common';
3
4
  export declare type UploadableFile = {
4
5
  content: ChunkinatorFile;
5
6
  name?: string;
@@ -18,4 +19,4 @@ export declare type UploadFileCallbacks = {
18
19
  export interface UploadFileResult {
19
20
  cancel: () => void;
20
21
  }
21
- export declare const uploadFile: (file: UploadableFile, store: MediaStore, uploadableFileUpfrontIds: UploadableFileUpfrontIds, callbacks?: UploadFileCallbacks | undefined) => UploadFileResult;
22
+ export declare const uploadFile: (file: UploadableFile, store: MediaStore, uploadableFileUpfrontIds: UploadableFileUpfrontIds, callbacks?: UploadFileCallbacks | undefined, traceContext?: MediaTraceContext | undefined) => UploadFileResult;
@@ -1,4 +1,5 @@
1
1
  import { Auth } from '@atlaskit/media-core';
2
+ import { MediaTraceContext } from '@atlaskit/media-common';
2
3
  import { RequestError } from './errors';
3
4
  import { CreateUrlOptions, RequestErrorReason, RequestErrorMetadata, RequestHeaders, RequestMetadata, RetryOptions } from './types';
4
5
  export declare function clientTimeoutPromise(timeout: number): Promise<Response>;
@@ -6,9 +7,16 @@ export declare function waitPromise(timeout: number): Promise<void>;
6
7
  export declare function isAbortedRequestError(err: any): boolean;
7
8
  export declare function isFetchNetworkError(err: any): err is TypeError;
8
9
  export declare function isRateLimitedError(error: Error | undefined): boolean;
9
- export declare function mapAuthToRequestHeaders(auth: Auth): RequestHeaders;
10
+ export declare const ZipkinHeaderKeys: {
11
+ traceId: string;
12
+ spanId: string;
13
+ parentSpanId: string;
14
+ sampled: string;
15
+ flags: string;
16
+ };
17
+ export declare function mapAuthToRequestHeaders(auth?: Auth): RequestHeaders;
10
18
  export declare function createUrl(url: string, { params, auth }: CreateUrlOptions): string;
11
- export declare function withAuth(auth?: Auth): (headers?: RequestHeaders | undefined) => Record<string, string> | undefined;
19
+ export declare function extendHeaders(headers?: RequestHeaders, auth?: Auth, traceContext?: Required<MediaTraceContext>): RequestHeaders | undefined;
12
20
  /**
13
21
  * @deprecated Helper is deprecated and will be removed in the next major version.
14
22
  * TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
@@ -1,4 +1,5 @@
1
1
  import { Auth } from '@atlaskit/media-core';
2
+ import type { MediaTraceContext } from '@atlaskit/media-common';
2
3
  export declare type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
3
4
  export declare type RequestParams = {
4
5
  [key: string]: any;
@@ -20,9 +21,11 @@ export declare type RequestMetadata = {
20
21
  readonly endpoint?: string;
21
22
  readonly mediaRegion?: string;
22
23
  readonly mediaEnv?: string;
24
+ readonly traceContext?: MediaTraceContext;
23
25
  };
24
26
  export declare type RequestOptions = RequestMetadata & {
25
27
  readonly auth?: Auth;
28
+ readonly traceContext?: Required<MediaTraceContext>;
26
29
  readonly params?: RequestParams;
27
30
  readonly headers?: RequestHeaders;
28
31
  readonly body?: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "18.1.0",
3
+ "version": "19.1.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -12,14 +12,6 @@
12
12
  "module": "dist/esm/index.js",
13
13
  "module:es2019": "dist/es2019/index.js",
14
14
  "types": "dist/types/index.d.ts",
15
- "typesVersions": {
16
- ">=4.0 <4.5": {
17
- "*": [
18
- "dist/types-ts4.0/*",
19
- "dist/types-ts4.0/index.d.ts"
20
- ]
21
- }
22
- },
23
15
  "sideEffects": false,
24
16
  "atlaskit:src": "src/index.ts",
25
17
  "af:exports": {
@@ -36,7 +28,7 @@
36
28
  },
37
29
  "dependencies": {
38
30
  "@atlaskit/chunkinator": "^4.1.0",
39
- "@atlaskit/media-common": "^2.17.0",
31
+ "@atlaskit/media-common": "^2.18.0",
40
32
  "@babel/runtime": "^7.0.0",
41
33
  "dataloader": "^2.0.0",
42
34
  "deep-equal": "^1.0.1",
@@ -50,18 +42,18 @@
50
42
  "xstate": "^4.20.0"
51
43
  },
52
44
  "peerDependencies": {
53
- "@atlaskit/media-core": "^34.0.0",
45
+ "@atlaskit/media-core": "^34.0.1",
54
46
  "@emotion/react": "^11.7.1",
55
47
  "react": "^16.8.0"
56
48
  },
57
49
  "devDependencies": {
58
- "@atlaskit/button": "^16.4.0",
50
+ "@atlaskit/button": "^16.5.0",
59
51
  "@atlaskit/docs": "*",
60
- "@atlaskit/media-card": "^74.2.0",
52
+ "@atlaskit/media-card": "^74.4.0",
61
53
  "@atlaskit/media-core": "^34.0.0",
62
- "@atlaskit/media-test-helpers": "^30.0.0",
54
+ "@atlaskit/media-test-helpers": "^30.1.0",
63
55
  "@atlaskit/ssr": "*",
64
- "@atlaskit/tokens": "^0.10.20",
56
+ "@atlaskit/tokens": "^0.13.0",
65
57
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
66
58
  "@emotion/react": "^11.7.1",
67
59
  "@types/deep-equal": "^1.0.1",