@atlaskit/media-client 17.1.2 → 17.1.4

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 (33) hide show
  1. package/CHANGELOG.md +0 -13
  2. package/dist/cjs/client/file-fetcher/index.js +40 -36
  3. package/dist/cjs/client/media-client.js +2 -2
  4. package/dist/cjs/client/media-store/index.js +70 -44
  5. package/dist/cjs/index.js +6 -0
  6. package/dist/cjs/uploader/index.js +22 -20
  7. package/dist/cjs/utils/request/helpers.js +46 -22
  8. package/dist/cjs/utils/request/index.js +3 -2
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/client/file-fetcher/index.js +16 -14
  11. package/dist/es2019/client/media-client.js +2 -2
  12. package/dist/es2019/client/media-store/index.js +52 -35
  13. package/dist/es2019/index.js +1 -1
  14. package/dist/es2019/uploader/index.js +14 -14
  15. package/dist/es2019/utils/request/helpers.js +29 -8
  16. package/dist/es2019/utils/request/index.js +4 -3
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/client/file-fetcher/index.js +40 -36
  19. package/dist/esm/client/media-client.js +2 -2
  20. package/dist/esm/client/media-store/index.js +71 -45
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/uploader/index.js +23 -21
  23. package/dist/esm/utils/request/helpers.js +41 -20
  24. package/dist/esm/utils/request/index.js +4 -3
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/client/file-fetcher/index.d.ts +9 -8
  27. package/dist/types/client/media-client.d.ts +2 -1
  28. package/dist/types/client/media-store/index.d.ts +15 -14
  29. package/dist/types/index.d.ts +3 -3
  30. package/dist/types/uploader/index.d.ts +2 -1
  31. package/dist/types/utils/request/helpers.d.ts +11 -3
  32. package/dist/types/utils/request/types.d.ts +5 -0
  33. package/package.json +5 -5
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.DEFAULT_RETRY_OPTIONS = void 0;
8
+ exports.ZipkinHeaderKeys = exports.DEFAULT_RETRY_OPTIONS = void 0;
9
9
  exports.clientTimeoutPromise = clientTimeoutPromise;
10
10
  exports.cloneRequestError = cloneRequestError;
11
11
  exports.createMapResponseToBlob = createMapResponseToBlob;
@@ -14,8 +14,10 @@ exports.createProcessFetchResponse = createProcessFetchResponse;
14
14
  exports.createRequestErrorFromResponse = createRequestErrorFromResponse;
15
15
  exports.createRequestErrorReason = createRequestErrorReason;
16
16
  exports.createUrl = createUrl;
17
+ exports.extendHeaders = extendHeaders;
17
18
  exports.extractMediaHeaders = extractMediaHeaders;
18
19
  exports.fetchRetry = fetchRetry;
20
+ exports.getRandomHex = getRandomHex;
19
21
  exports.isAbortedRequestError = isAbortedRequestError;
20
22
  exports.isFetchNetworkError = isFetchNetworkError;
21
23
  exports.isRateLimitedError = isRateLimitedError;
@@ -24,7 +26,6 @@ exports.mapResponseToBlob = mapResponseToBlob;
24
26
  exports.mapResponseToJson = mapResponseToJson;
25
27
  exports.mapResponseToVoid = mapResponseToVoid;
26
28
  exports.waitPromise = waitPromise;
27
- exports.withAuth = withAuth;
28
29
 
29
30
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
31
 
@@ -71,7 +72,26 @@ function isRateLimitedError(error) {
71
72
  return !!error && (0, _errors.isRequestError)(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
72
73
  }
73
74
 
75
+ var ZipkinHeaderKeys = {
76
+ traceId: 'x-b3-traceid',
77
+ spanId: 'x-b3-spanid',
78
+ parentSpanId: 'x-b3-parentspanid',
79
+ sampled: 'x-b3-sampled',
80
+ flags: 'x-b3-flags'
81
+ };
82
+ exports.ZipkinHeaderKeys = ZipkinHeaderKeys;
83
+
84
+ var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
85
+ var _ref;
86
+
87
+ return traceContext ? (_ref = {}, (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
88
+ };
89
+
74
90
  function mapAuthToRequestHeaders(auth) {
91
+ if (!auth) {
92
+ return {};
93
+ }
94
+
75
95
  if ((0, _mediaCore.isClientBasedAuth)(auth)) {
76
96
  return {
77
97
  'X-Client-Id': auth.clientId,
@@ -85,18 +105,18 @@ function mapAuthToRequestHeaders(auth) {
85
105
  };
86
106
  }
87
107
 
88
- function createUrl(url, _ref) {
89
- var params = _ref.params,
90
- auth = _ref.auth;
108
+ function createUrl(url, _ref2) {
109
+ var params = _ref2.params,
110
+ auth = _ref2.auth;
91
111
  var parsedUrl = new URL(url);
92
112
  var authParams = auth && (0, _authQueryParameters.mapAuthToQueryParameters)(auth) || {};
93
113
 
94
114
  var paramsToAppend = _objectSpread(_objectSpread({}, params), authParams);
95
115
 
96
- Object.entries(paramsToAppend).filter(function (_ref2) {
97
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
98
- _ = _ref3[0],
99
- value = _ref3[1];
116
+ Object.entries(paramsToAppend).filter(function (_ref3) {
117
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
118
+ _ = _ref4[0],
119
+ value = _ref4[1];
100
120
 
101
121
  return value != null;
102
122
  }).forEach(function (pair) {
@@ -108,14 +128,12 @@ function createUrl(url, _ref) {
108
128
  return parsedUrl.toString();
109
129
  }
110
130
 
111
- function withAuth(auth) {
112
- return function (headers) {
113
- if (auth) {
114
- return _objectSpread(_objectSpread({}, headers || {}), mapAuthToRequestHeaders(auth));
115
- }
131
+ function extendHeaders(headers, auth, traceContext) {
132
+ if (!auth && !traceContext && !headers) {
133
+ return undefined;
134
+ }
116
135
 
117
- return headers;
118
- };
136
+ return _objectSpread(_objectSpread(_objectSpread({}, headers !== null && headers !== void 0 ? headers : {}), mapAuthToRequestHeaders(auth)), mapTraceIdToRequestHeaders(traceContext));
119
137
  }
120
138
  /**
121
139
  * @deprecated Helper is deprecated and will be removed in the next major version.
@@ -213,7 +231,7 @@ function mapResponseToVoid() {
213
231
 
214
232
  function createMapResponseToJson(metadata) {
215
233
  return /*#__PURE__*/function () {
216
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response) {
234
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response) {
217
235
  return _regenerator.default.wrap(function _callee$(_context) {
218
236
  while (1) {
219
237
  switch (_context.prev = _context.next) {
@@ -241,14 +259,14 @@ function createMapResponseToJson(metadata) {
241
259
  }));
242
260
 
243
261
  return function (_x3) {
244
- return _ref4.apply(this, arguments);
262
+ return _ref5.apply(this, arguments);
245
263
  };
246
264
  }();
247
265
  }
248
266
 
249
267
  function createMapResponseToBlob(metadata) {
250
268
  return /*#__PURE__*/function () {
251
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(response) {
269
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(response) {
252
270
  return _regenerator.default.wrap(function _callee2$(_context2) {
253
271
  while (1) {
254
272
  switch (_context2.prev = _context2.next) {
@@ -276,7 +294,7 @@ function createMapResponseToBlob(metadata) {
276
294
  }));
277
295
 
278
296
  return function (_x4) {
279
- return _ref5.apply(this, arguments);
297
+ return _ref6.apply(this, arguments);
280
298
  };
281
299
  }();
282
300
  }
@@ -325,7 +343,7 @@ function _fetchRetry() {
325
343
  timeoutInMs = startTimeoutInMs;
326
344
 
327
345
  waitAndBumpTimeout = /*#__PURE__*/function () {
328
- var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
346
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
329
347
  return _regenerator.default.wrap(function _callee5$(_context5) {
330
348
  while (1) {
331
349
  switch (_context5.prev = _context5.next) {
@@ -346,7 +364,7 @@ function _fetchRetry() {
346
364
  }));
347
365
 
348
366
  return function waitAndBumpTimeout() {
349
- return _ref6.apply(this, arguments);
367
+ return _ref7.apply(this, arguments);
350
368
  };
351
369
  }();
352
370
 
@@ -473,4 +491,10 @@ function extractMediaHeaders(response) {
473
491
  mediaRegion: mediaRegion,
474
492
  mediaEnv: mediaEnv
475
493
  };
494
+ }
495
+
496
+ function getRandomHex(size) {
497
+ return (0, _toConsumableArray2.default)(Array(size)).map(function () {
498
+ return Math.floor(Math.random() * 16).toString(16);
499
+ }).join('');
476
500
  }
@@ -50,6 +50,7 @@ function _request() {
50
50
  body,
51
51
  _options$clientOption,
52
52
  clientOptions,
53
+ traceContext,
53
54
  retryOptions,
54
55
  metadata,
55
56
  doFetch,
@@ -61,7 +62,7 @@ function _request() {
61
62
  case 0:
62
63
  options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
63
64
  controller = _args.length > 2 ? _args[2] : undefined;
64
- _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;
65
+ _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;
65
66
  retryOptions = clientOptions.retryOptions;
66
67
  metadata = {
67
68
  method: method,
@@ -74,7 +75,7 @@ function _request() {
74
75
  }), {
75
76
  method: method,
76
77
  body: body,
77
- headers: (0, _helpers.withAuth)(auth)(headers),
78
+ headers: (0, _helpers.extendHeaders)(headers, auth, traceContext),
78
79
  signal: controller && controller.signal
79
80
  }).then((0, _helpers.createProcessFetchResponse)(metadata));
80
81
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "17.1.2",
3
+ "version": "17.1.4",
4
4
  "sideEffects": false
5
5
  }
@@ -106,19 +106,20 @@ export class FileFetcherImpl {
106
106
 
107
107
  getFileBinaryURL(id, collectionName) {
108
108
  return this.mediaStore.getFileBinaryURL(id, collectionName);
109
- }
109
+ } // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
110
+
110
111
 
111
- touchFiles(descriptors, collection) {
112
+ touchFiles(descriptors, collection, traceContext) {
112
113
  return this.mediaStore.touchFiles({
113
114
  descriptors
114
115
  }, {
115
116
  collection
116
- }).then(({
117
+ }, traceContext).then(({
117
118
  data
118
119
  }) => data);
119
120
  }
120
121
 
121
- generateUploadableFileUpfrontIds(collection) {
122
+ generateUploadableFileUpfrontIds(collection, traceContext) {
122
123
  const id = uuid();
123
124
  const occurrenceKey = uuid();
124
125
  const touchFileDescriptor = {
@@ -126,7 +127,7 @@ export class FileFetcherImpl {
126
127
  occurrenceKey,
127
128
  collection
128
129
  };
129
- const deferredUploadId = this.touchFiles([touchFileDescriptor], collection).then(touchedFiles => touchedFiles.created[0].uploadId);
130
+ const deferredUploadId = this.touchFiles([touchFileDescriptor], collection, traceContext).then(touchedFiles => touchedFiles.created[0].uploadId);
130
131
  return {
131
132
  id,
132
133
  occurrenceKey,
@@ -134,8 +135,8 @@ export class FileFetcherImpl {
134
135
  };
135
136
  }
136
137
 
137
- async uploadExternal(url, collection) {
138
- const uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection);
138
+ async uploadExternal(url, collection, traceContext) {
139
+ const uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
139
140
  const {
140
141
  id,
141
142
  occurrenceKey
@@ -199,7 +200,7 @@ export class FileFetcherImpl {
199
200
  preview
200
201
  }); // we don't want to wait for the file to be upload
201
202
 
202
- this.upload(file, undefined, uploadableFileUpfrontIds);
203
+ this.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
203
204
  const dimensions = await getDimensionsFromBlob(mediaType, blob);
204
205
  resolve({
205
206
  dimensions,
@@ -208,7 +209,7 @@ export class FileFetcherImpl {
208
209
  });
209
210
  }
210
211
 
211
- upload(file, controller, uploadableFileUpfrontIds) {
212
+ upload(file, controller, uploadableFileUpfrontIds, traceContext) {
212
213
  if (typeof file.content === 'string') {
213
214
  file.content = convertBase64ToBlob(file.content);
214
215
  }
@@ -221,7 +222,7 @@ export class FileFetcherImpl {
221
222
  } = file;
222
223
 
223
224
  if (!uploadableFileUpfrontIds) {
224
- uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection);
225
+ uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
225
226
  }
226
227
 
227
228
  const id = uploadableFileUpfrontIds.id;
@@ -291,7 +292,7 @@ export class FileFetcherImpl {
291
292
  } = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
292
293
  onUploadFinish,
293
294
  onProgress
294
- });
295
+ }, traceContext);
295
296
  getFileStreamsCache().set(id, subject); // We should report progress asynchronously, since this is what consumer expects
296
297
  // (otherwise in newUploadService file-converting event will be emitted before files-added)
297
298
 
@@ -307,7 +308,8 @@ export class FileFetcherImpl {
307
308
  }
308
309
 
309
310
  return fromObservable(subject);
310
- }
311
+ } // TODO: ----- ADD TICKET
312
+
311
313
 
312
314
  async downloadBinary(id, name = 'download', collectionName) {
313
315
  const url = await this.mediaStore.getFileBinaryURL(id, collectionName);
@@ -321,7 +323,7 @@ export class FileFetcherImpl {
321
323
  });
322
324
  }
323
325
 
324
- async copyFile(source, destination, options = {}) {
326
+ async copyFile(source, destination, options = {}, traceContext) {
325
327
  const {
326
328
  authProvider,
327
329
  collection: sourceCollection,
@@ -361,7 +363,7 @@ export class FileFetcherImpl {
361
363
  try {
362
364
  const {
363
365
  data: copiedFile
364
- } = await mediaStore.copyFileWithToken(body, params); // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
366
+ } = await mediaStore.copyFileWithToken(body, params, traceContext); // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
365
367
 
366
368
  const copiedFileWithMimeType = { ...copiedFile,
367
369
  ...(mimeType ? {
@@ -20,8 +20,8 @@ export class MediaClient {
20
20
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
21
21
  }
22
22
 
23
- getImage(id, params, controller, fetchMaxRes) {
24
- return this.mediaStore.getImage(id, params, controller, fetchMaxRes);
23
+ getImage(id, params, controller, fetchMaxRes, traceContext) {
24
+ return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
25
25
  }
26
26
 
27
27
  getImageUrl(id, params) {
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
3
3
  import { getArtifactUrl } from '../../models/artifacts';
4
4
  import { request } from '../../utils/request';
5
- import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
5
+ import { createUrl, createMapResponseToJson, createMapResponseToBlob, getRandomHex } from '../../utils/request/helpers';
6
6
  import { resolveAuth, resolveInitialAuth } from './resolveAuth';
7
7
  export { MediaStoreError, isMediaStoreError } from './error';
8
8
  const MEDIA_API_REGION = 'media-api-region';
@@ -41,7 +41,7 @@ export class MediaStore {
41
41
  this.featureFlags = featureFlags;
42
42
  }
43
43
 
44
- async getCollectionItems(collectionName, params) {
44
+ async getCollectionItems(collectionName, params, traceContext) {
45
45
  const metadata = {
46
46
  method: 'GET',
47
47
  endpoint: '/collection/{collectionName}/items'
@@ -55,7 +55,8 @@ export class MediaStore {
55
55
  },
56
56
  headers: {
57
57
  Accept: 'application/json'
58
- }
58
+ },
59
+ traceContext
59
60
  };
60
61
  const response = await this.request(`/collection/${collectionName}/items`, options);
61
62
  const {
@@ -75,7 +76,7 @@ export class MediaStore {
75
76
  };
76
77
  }
77
78
 
78
- async removeCollectionFile(id, collectionName, occurrenceKey) {
79
+ async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
79
80
  const metadata = {
80
81
  method: 'PUT',
81
82
  endpoint: '/collection/{collectionName}'
@@ -98,12 +99,13 @@ export class MediaStore {
98
99
  Accept: 'application/json',
99
100
  'Content-Type': 'application/json'
100
101
  },
101
- body: JSON.stringify(body)
102
+ body: JSON.stringify(body),
103
+ traceContext
102
104
  };
103
105
  await this.request(`/collection/${collectionName}`, options);
104
106
  }
105
107
 
106
- createUpload(createUpTo = 1, collectionName) {
108
+ createUpload(createUpTo = 1, collectionName, traceContext) {
107
109
  const metadata = {
108
110
  method: 'POST',
109
111
  endpoint: '/upload'
@@ -117,7 +119,8 @@ export class MediaStore {
117
119
  },
118
120
  headers: {
119
121
  Accept: 'application/json'
120
- }
122
+ },
123
+ traceContext
121
124
  };
122
125
  return this.request(`/upload`, options).then(createMapResponseToJson(metadata));
123
126
  }
@@ -126,7 +129,7 @@ export class MediaStore {
126
129
  collectionName,
127
130
  uploadId,
128
131
  partNumber
129
- } = {}) {
132
+ } = {}, traceContext) {
130
133
  const metadata = {
131
134
  method: 'PUT',
132
135
  endpoint: '/chunk/{etag}'
@@ -139,7 +142,8 @@ export class MediaStore {
139
142
  authContext: {
140
143
  collectionName
141
144
  },
142
- body: blob
145
+ body: blob,
146
+ traceContext
143
147
  };
144
148
  await this.request(`/chunk/${etag}`, options);
145
149
  }
@@ -147,7 +151,7 @@ export class MediaStore {
147
151
  probeChunks(chunks, {
148
152
  collectionName,
149
153
  uploadId
150
- } = {}) {
154
+ } = {}, traceContext) {
151
155
  const metadata = {
152
156
  method: 'POST',
153
157
  endpoint: '/chunk/probe'
@@ -162,12 +166,13 @@ export class MediaStore {
162
166
  headers: jsonHeaders,
163
167
  body: JSON.stringify({
164
168
  chunks
165
- })
169
+ }),
170
+ traceContext
166
171
  };
167
172
  return this.request(`/chunk/probe`, options).then(createMapResponseToJson(metadata));
168
173
  }
169
174
 
170
- createFileFromUpload(body, params = {}) {
175
+ createFileFromUpload(body, params = {}, traceContext) {
171
176
  const metadata = {
172
177
  method: 'POST',
173
178
  endpoint: '/file/upload'
@@ -178,12 +183,13 @@ export class MediaStore {
178
183
  },
179
184
  params,
180
185
  headers: jsonHeaders,
181
- body: JSON.stringify(body)
186
+ body: JSON.stringify(body),
187
+ traceContext
182
188
  };
183
189
  return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
184
190
  }
185
191
 
186
- touchFiles(body, params = {}) {
192
+ touchFiles(body, params = {}, traceContext) {
187
193
  const metadata = {
188
194
  method: 'POST',
189
195
  endpoint: '/upload/createWithFiles'
@@ -193,12 +199,13 @@ export class MediaStore {
193
199
  collectionName: params.collection
194
200
  },
195
201
  headers: jsonHeaders,
196
- body: JSON.stringify(body)
202
+ body: JSON.stringify(body),
203
+ traceContext
197
204
  };
198
205
  return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
199
206
  }
200
207
 
201
- getFile(fileId, params = {}) {
208
+ getFile(fileId, params = {}, traceContext) {
202
209
  const metadata = {
203
210
  method: 'GET',
204
211
  endpoint: '/file/{fileId}'
@@ -207,7 +214,8 @@ export class MediaStore {
207
214
  authContext: {
208
215
  collectionName: params.collection
209
216
  },
210
- params
217
+ params,
218
+ traceContext
211
219
  };
212
220
  return this.request(`/file/${fileId}`, options).then(createMapResponseToJson(metadata));
213
221
  }
@@ -220,7 +228,8 @@ export class MediaStore {
220
228
  collectionName
221
229
  });
222
230
  return this.createFileImageURL(id, auth, params);
223
- }
231
+ } // TODO Create ticket in case Trace Id can be supported through query params
232
+
224
233
 
225
234
  getFileImageURLSync(id, params) {
226
235
  const auth = this.resolveInitialAuth();
@@ -270,15 +279,13 @@ export class MediaStore {
270
279
  return createUrl(`${auth.baseUrl}${artifactUrl}`, options);
271
280
  }
272
281
 
273
- async getImage(id, params, controller, fetchMaxRes) {
282
+ async getImage(id, params, controller, fetchMaxRes, traceContext) {
274
283
  // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
275
284
  const isWebpSupported = false;
276
- let headers;
285
+ const headers = {};
277
286
 
278
287
  if (isWebpSupported) {
279
- headers = {
280
- accept: 'image/webp,image/*,*/*;q=0.8'
281
- };
288
+ headers.accept = 'image/webp,image/*,*/*;q=0.8';
282
289
  }
283
290
 
284
291
  const metadata = {
@@ -290,12 +297,13 @@ export class MediaStore {
290
297
  collectionName: params && params.collection
291
298
  },
292
299
  params: extendImageParams(params, fetchMaxRes),
293
- headers
300
+ headers,
301
+ traceContext
294
302
  };
295
303
  return this.request(`/file/${id}/image`, options, controller).then(createMapResponseToBlob(metadata));
296
304
  }
297
305
 
298
- async getItems(ids, collectionName) {
306
+ async getItems(ids, collectionName, traceContext) {
299
307
  const descriptors = ids.map(id => ({
300
308
  type: 'file',
301
309
  id,
@@ -312,12 +320,13 @@ export class MediaStore {
312
320
  headers: jsonHeaders,
313
321
  body: JSON.stringify({
314
322
  descriptors
315
- })
323
+ }),
324
+ traceContext
316
325
  };
317
326
  return this.request('/items', options).then(createMapResponseToJson(metadata));
318
327
  }
319
328
 
320
- async getImageMetadata(id, params) {
329
+ async getImageMetadata(id, params, traceContext) {
321
330
  const metadata = {
322
331
  method: 'GET',
323
332
  endpoint: '/file/{fileId}/image/metadata'
@@ -326,12 +335,13 @@ export class MediaStore {
326
335
  authContext: {
327
336
  collectionName: params && params.collection
328
337
  },
329
- params
338
+ params,
339
+ traceContext
330
340
  };
331
341
  return this.request(`/file/${id}/image/metadata`, options).then(createMapResponseToJson(metadata));
332
342
  }
333
343
 
334
- async appendChunksToUpload(uploadId, body, collectionName) {
344
+ async appendChunksToUpload(uploadId, body, collectionName, traceContext) {
335
345
  const metadata = {
336
346
  method: 'PUT',
337
347
  endpoint: '/upload/{uploadId}/chunks'
@@ -341,12 +351,13 @@ export class MediaStore {
341
351
  collectionName
342
352
  },
343
353
  headers: jsonHeaders,
344
- body: JSON.stringify(body)
354
+ body: JSON.stringify(body),
355
+ traceContext
345
356
  };
346
357
  await this.request(`/upload/${uploadId}/chunks`, options);
347
358
  }
348
359
 
349
- copyFileWithToken(body, params) {
360
+ copyFileWithToken(body, params, traceContext) {
350
361
  const metadata = {
351
362
  method: 'POST',
352
363
  endpoint: '/file/copy/withToken'
@@ -359,8 +370,9 @@ export class MediaStore {
359
370
  params,
360
371
  // Contains collection name to write to
361
372
  headers: jsonHeaders,
362
- body: JSON.stringify(body) // Contains collection name to read from
363
-
373
+ body: JSON.stringify(body),
374
+ // Contains collection name to read from
375
+ traceContext
364
376
  };
365
377
  return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
366
378
  }
@@ -377,9 +389,13 @@ export class MediaStore {
377
389
  params,
378
390
  headers,
379
391
  body,
380
- clientOptions
392
+ clientOptions,
393
+ traceContext
381
394
  } = options;
382
395
  const auth = await this.resolveAuth(authContext);
396
+ const extendedTraceContext = traceContext ? { ...traceContext,
397
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(16)
398
+ } : undefined;
383
399
  const response = await request(`${auth.baseUrl}${path}`, {
384
400
  method,
385
401
  endpoint,
@@ -387,7 +403,8 @@ export class MediaStore {
387
403
  params,
388
404
  headers,
389
405
  body,
390
- clientOptions
406
+ clientOptions,
407
+ traceContext: extendedTraceContext
391
408
  }, controller);
392
409
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
393
410
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
@@ -8,7 +8,7 @@ export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isEr
8
8
  export { StreamsCache } from './file-streams-cache';
9
9
  export { uploadFile } from './uploader';
10
10
  export { request, RequestError, isRequestError, isRateLimitedError } from './utils/request';
11
- export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl } from './utils/request/helpers';
11
+ export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl, getRandomHex } from './utils/request/helpers';
12
12
  export { PollingFunction } from './utils/polling';
13
13
  export { isPollingError, PollingError } from './utils/polling/errors';
14
14
  export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';