@atlaskit/media-client 18.1.0 → 19.0.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 (110) hide show
  1. package/CHANGELOG.md +10 -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/uploader/index.js +22 -20
  7. package/dist/cjs/utils/request/helpers.js +39 -22
  8. package/dist/cjs/utils/request/index.js +3 -2
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/client/collection-fetcher.js +6 -6
  11. package/dist/es2019/client/file-fetcher/index.js +16 -14
  12. package/dist/es2019/client/media-client.js +2 -2
  13. package/dist/es2019/client/media-store/index.js +50 -41
  14. package/dist/es2019/uploader/index.js +13 -13
  15. package/dist/es2019/utils/request/helpers.js +26 -8
  16. package/dist/es2019/utils/request/index.js +4 -3
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/client/collection-fetcher.js +8 -8
  19. package/dist/esm/client/file-fetcher/index.js +40 -36
  20. package/dist/esm/client/media-client.js +2 -2
  21. package/dist/esm/client/media-store/index.js +68 -50
  22. package/dist/esm/uploader/index.js +22 -20
  23. package/dist/esm/utils/request/helpers.js +36 -20
  24. package/dist/esm/utils/request/index.js +4 -3
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/client/collection-fetcher.d.ts +4 -3
  27. package/dist/types/client/file-fetcher/index.d.ts +9 -8
  28. package/dist/types/client/media-client.d.ts +2 -2
  29. package/dist/types/client/media-store/index.d.ts +15 -21
  30. package/dist/types/uploader/index.d.ts +2 -1
  31. package/dist/types/utils/request/helpers.d.ts +10 -2
  32. package/dist/types/utils/request/types.d.ts +2 -0
  33. package/package.json +4 -12
  34. package/report.api.md +101 -70
  35. package/dist/types-ts4.0/client/__mocks__/collection-fetcher.d.ts +0 -8
  36. package/dist/types-ts4.0/client/__mocks__/file-fetcher.d.ts +0 -10
  37. package/dist/types-ts4.0/client/__mocks__/media-client.d.ts +0 -13
  38. package/dist/types-ts4.0/client/collection-fetcher.d.ts +0 -35
  39. package/dist/types-ts4.0/client/events.d.ts +0 -14
  40. package/dist/types-ts4.0/client/file-fetcher/error.d.ts +0 -29
  41. package/dist/types-ts4.0/client/file-fetcher/index.d.ts +0 -56
  42. package/dist/types-ts4.0/client/media-client.d.ts +0 -28
  43. package/dist/types-ts4.0/client/media-store/error.d.ts +0 -16
  44. package/dist/types-ts4.0/client/media-store/index.d.ts +0 -174
  45. package/dist/types-ts4.0/client/media-store/resolveAuth.d.ts +0 -4
  46. package/dist/types-ts4.0/client/mobile-upload.d.ts +0 -11
  47. package/dist/types-ts4.0/client/stargate-client.d.ts +0 -15
  48. package/dist/types-ts4.0/constants.d.ts +0 -6
  49. package/dist/types-ts4.0/file-streams-cache.d.ts +0 -15
  50. package/dist/types-ts4.0/globalMediaEventEmitter.d.ts +0 -6
  51. package/dist/types-ts4.0/identifier.d.ts +0 -15
  52. package/dist/types-ts4.0/index.d.ts +0 -89
  53. package/dist/types-ts4.0/models/artifacts.d.ts +0 -12
  54. package/dist/types-ts4.0/models/auth-headers.d.ts +0 -11
  55. package/dist/types-ts4.0/models/auth-query-parameters.d.ts +0 -11
  56. package/dist/types-ts4.0/models/errors/helpers.d.ts +0 -6
  57. package/dist/types-ts4.0/models/errors/index.d.ts +0 -11
  58. package/dist/types-ts4.0/models/errors/types.d.ts +0 -15
  59. package/dist/types-ts4.0/models/file-state.d.ts +0 -91
  60. package/dist/types-ts4.0/models/item.d.ts +0 -25
  61. package/dist/types-ts4.0/models/media-subscribable.d.ts +0 -3
  62. package/dist/types-ts4.0/models/media.d.ts +0 -66
  63. package/dist/types-ts4.0/models/mobile-upload.d.ts +0 -28
  64. package/dist/types-ts4.0/upload-controller.d.ts +0 -7
  65. package/dist/types-ts4.0/uploader/calculateChunkSize.d.ts +0 -11
  66. package/dist/types-ts4.0/uploader/error.d.ts +0 -29
  67. package/dist/types-ts4.0/uploader/index.d.ts +0 -21
  68. package/dist/types-ts4.0/utils/checkWebpSupport.d.ts +0 -1
  69. package/dist/types-ts4.0/utils/convertBase64ToBlob.d.ts +0 -1
  70. package/dist/types-ts4.0/utils/createFileDataLoader.d.ts +0 -30
  71. package/dist/types-ts4.0/utils/createMediaSubject.d.ts +0 -3
  72. package/dist/types-ts4.0/utils/detectEmptyFile.d.ts +0 -16
  73. package/dist/types-ts4.0/utils/getDimensionsFromBlob.d.ts +0 -6
  74. package/dist/types-ts4.0/utils/getImageDimensionsFromBlob.d.ts +0 -5
  75. package/dist/types-ts4.0/utils/getMediaTypeFromUploadableFile.d.ts +0 -3
  76. package/dist/types-ts4.0/utils/getVideoDimensionsFromBlob.d.ts +0 -5
  77. package/dist/types-ts4.0/utils/hashing/hasher.d.ts +0 -3
  78. package/dist/types-ts4.0/utils/hashing/hasherCreator.d.ts +0 -3
  79. package/dist/types-ts4.0/utils/hashing/simpleHasher.d.ts +0 -4
  80. package/dist/types-ts4.0/utils/hashing/workerHasher.d.ts +0 -16
  81. package/dist/types-ts4.0/utils/imageResizeModeToFileImageMode.d.ts +0 -3
  82. package/dist/types-ts4.0/utils/isImageRemote.d.ts +0 -1
  83. package/dist/types-ts4.0/utils/mediaSubscribable/fromObservable.d.ts +0 -5
  84. package/dist/types-ts4.0/utils/mediaSubscribable/index.d.ts +0 -3
  85. package/dist/types-ts4.0/utils/mediaSubscribable/toPromise.d.ts +0 -10
  86. package/dist/types-ts4.0/utils/mediaSubscribable/types.d.ts +0 -16
  87. package/dist/types-ts4.0/utils/mobileUpload/error.d.ts +0 -29
  88. package/dist/types-ts4.0/utils/mobileUpload/helpers.d.ts +0 -8
  89. package/dist/types-ts4.0/utils/mobileUpload/index.d.ts +0 -5
  90. package/dist/types-ts4.0/utils/mobileUpload/servicesCache.d.ts +0 -4
  91. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/index.d.ts +0 -7
  92. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/error.d.ts +0 -3
  93. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processed.d.ts +0 -3
  94. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processing.d.ts +0 -3
  95. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +0 -3
  96. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/uploading.d.ts +0 -3
  97. package/dist/types-ts4.0/utils/mobileUpload/stateMachine/types.d.ts +0 -69
  98. package/dist/types-ts4.0/utils/overrideMediaTypeIfUnknown.d.ts +0 -5
  99. package/dist/types-ts4.0/utils/polling/errors.d.ts +0 -12
  100. package/dist/types-ts4.0/utils/polling/index.d.ts +0 -33
  101. package/dist/types-ts4.0/utils/polling/types.d.ts +0 -7
  102. package/dist/types-ts4.0/utils/request/errors.d.ts +0 -20
  103. package/dist/types-ts4.0/utils/request/helpers.d.ts +0 -38
  104. package/dist/types-ts4.0/utils/request/index.d.ts +0 -5
  105. package/dist/types-ts4.0/utils/request/types.d.ts +0 -43
  106. package/dist/types-ts4.0/utils/safeUnsubscribe.d.ts +0 -2
  107. package/dist/types-ts4.0/utils/setTimeoutPromise.d.ts +0 -2
  108. package/dist/types-ts4.0/utils/shouldFetchRemoteFileStates.d.ts +0 -16
  109. package/dist/types-ts4.0/utils/url.d.ts +0 -17
  110. package/dist/types-ts4.0/utils/with-media-client-hoc.d.ts +0 -16
@@ -39,13 +39,6 @@ var jsonHeaders = {
39
39
  Accept: 'application/json',
40
40
  'Content-Type': 'application/json'
41
41
  };
42
- export var ZipkinHeaderKeys = {
43
- traceId: 'x-b3-traceid',
44
- spanId: 'x-b3-spanid',
45
- parentSpanId: 'x-b3-parentspanid',
46
- sampled: 'x-b3-sampled',
47
- flags: 'x-b3-flags'
48
- };
49
42
  export var MediaStore = /*#__PURE__*/function () {
50
43
  function MediaStore(config, featureFlags) {
51
44
  var _this = this;
@@ -67,7 +60,7 @@ export var MediaStore = /*#__PURE__*/function () {
67
60
  _createClass(MediaStore, [{
68
61
  key: "getCollectionItems",
69
62
  value: function () {
70
- var _getCollectionItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionName, params) {
63
+ var _getCollectionItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionName, params, traceContext) {
71
64
  var metadata, options, response, _yield$createMapRespo, _yield$createMapRespo2, contents, nextInclusiveStartKey, contentsWithoutEmptyFiles;
72
65
 
73
66
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -85,7 +78,8 @@ export var MediaStore = /*#__PURE__*/function () {
85
78
  params: _objectSpread(_objectSpread({}, defaultGetCollectionItems), params),
86
79
  headers: {
87
80
  Accept: 'application/json'
88
- }
81
+ },
82
+ traceContext: traceContext
89
83
  });
90
84
  _context.next = 4;
91
85
  return this.request("/collection/".concat(collectionName, "/items"), options);
@@ -120,7 +114,7 @@ export var MediaStore = /*#__PURE__*/function () {
120
114
  }, _callee, this);
121
115
  }));
122
116
 
123
- function getCollectionItems(_x, _x2) {
117
+ function getCollectionItems(_x, _x2, _x3) {
124
118
  return _getCollectionItems.apply(this, arguments);
125
119
  }
126
120
 
@@ -129,7 +123,7 @@ export var MediaStore = /*#__PURE__*/function () {
129
123
  }, {
130
124
  key: "removeCollectionFile",
131
125
  value: function () {
132
- var _removeCollectionFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, collectionName, occurrenceKey) {
126
+ var _removeCollectionFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, collectionName, occurrenceKey, traceContext) {
133
127
  var metadata, body, options;
134
128
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
135
129
  while (1) {
@@ -157,7 +151,8 @@ export var MediaStore = /*#__PURE__*/function () {
157
151
  Accept: 'application/json',
158
152
  'Content-Type': 'application/json'
159
153
  },
160
- body: JSON.stringify(body)
154
+ body: JSON.stringify(body),
155
+ traceContext: traceContext
161
156
  });
162
157
  _context2.next = 5;
163
158
  return this.request("/collection/".concat(collectionName), options);
@@ -170,7 +165,7 @@ export var MediaStore = /*#__PURE__*/function () {
170
165
  }, _callee2, this);
171
166
  }));
172
167
 
173
- function removeCollectionFile(_x3, _x4, _x5) {
168
+ function removeCollectionFile(_x4, _x5, _x6, _x7) {
174
169
  return _removeCollectionFile.apply(this, arguments);
175
170
  }
176
171
 
@@ -181,6 +176,7 @@ export var MediaStore = /*#__PURE__*/function () {
181
176
  value: function createUpload() {
182
177
  var createUpTo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
183
178
  var collectionName = arguments.length > 1 ? arguments[1] : undefined;
179
+ var traceContext = arguments.length > 2 ? arguments[2] : undefined;
184
180
  var metadata = {
185
181
  method: 'POST',
186
182
  endpoint: '/upload'
@@ -195,7 +191,8 @@ export var MediaStore = /*#__PURE__*/function () {
195
191
  },
196
192
  headers: {
197
193
  Accept: 'application/json'
198
- }
194
+ },
195
+ traceContext: traceContext
199
196
  });
200
197
 
201
198
  return this.request("/upload", options).then(createMapResponseToJson(metadata));
@@ -208,6 +205,7 @@ export var MediaStore = /*#__PURE__*/function () {
208
205
  collectionName,
209
206
  uploadId,
210
207
  partNumber,
208
+ traceContext,
211
209
  metadata,
212
210
  options,
213
211
  _args3 = arguments;
@@ -217,6 +215,7 @@ export var MediaStore = /*#__PURE__*/function () {
217
215
  switch (_context3.prev = _context3.next) {
218
216
  case 0:
219
217
  _ref = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {}, collectionName = _ref.collectionName, uploadId = _ref.uploadId, partNumber = _ref.partNumber;
218
+ traceContext = _args3.length > 3 ? _args3[3] : undefined;
220
219
  metadata = {
221
220
  method: 'PUT',
222
221
  endpoint: '/chunk/{etag}'
@@ -229,12 +228,13 @@ export var MediaStore = /*#__PURE__*/function () {
229
228
  authContext: {
230
229
  collectionName: collectionName
231
230
  },
232
- body: blob
231
+ body: blob,
232
+ traceContext: traceContext
233
233
  });
234
- _context3.next = 5;
234
+ _context3.next = 6;
235
235
  return this.request("/chunk/".concat(etag), options);
236
236
 
237
- case 5:
237
+ case 6:
238
238
  case "end":
239
239
  return _context3.stop();
240
240
  }
@@ -242,7 +242,7 @@ export var MediaStore = /*#__PURE__*/function () {
242
242
  }, _callee3, this);
243
243
  }));
244
244
 
245
- function uploadChunk(_x6, _x7) {
245
+ function uploadChunk(_x8, _x9) {
246
246
  return _uploadChunk.apply(this, arguments);
247
247
  }
248
248
 
@@ -255,6 +255,7 @@ export var MediaStore = /*#__PURE__*/function () {
255
255
  collectionName = _ref2.collectionName,
256
256
  uploadId = _ref2.uploadId;
257
257
 
258
+ var traceContext = arguments.length > 2 ? arguments[2] : undefined;
258
259
  var metadata = {
259
260
  method: 'POST',
260
261
  endpoint: '/chunk/probe'
@@ -270,7 +271,8 @@ export var MediaStore = /*#__PURE__*/function () {
270
271
  headers: jsonHeaders,
271
272
  body: JSON.stringify({
272
273
  chunks: chunks
273
- })
274
+ }),
275
+ traceContext: traceContext
274
276
  });
275
277
 
276
278
  return this.request("/chunk/probe", options).then(createMapResponseToJson(metadata));
@@ -279,6 +281,7 @@ export var MediaStore = /*#__PURE__*/function () {
279
281
  key: "createFileFromUpload",
280
282
  value: function createFileFromUpload(body) {
281
283
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
284
+ var traceContext = arguments.length > 2 ? arguments[2] : undefined;
282
285
  var metadata = {
283
286
  method: 'POST',
284
287
  endpoint: '/file/upload'
@@ -290,7 +293,8 @@ export var MediaStore = /*#__PURE__*/function () {
290
293
  },
291
294
  params: params,
292
295
  headers: jsonHeaders,
293
- body: JSON.stringify(body)
296
+ body: JSON.stringify(body),
297
+ traceContext: traceContext
294
298
  });
295
299
 
296
300
  return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
@@ -299,6 +303,7 @@ export var MediaStore = /*#__PURE__*/function () {
299
303
  key: "touchFiles",
300
304
  value: function touchFiles(body) {
301
305
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
306
+ var traceContext = arguments.length > 2 ? arguments[2] : undefined;
302
307
  var metadata = {
303
308
  method: 'POST',
304
309
  endpoint: '/upload/createWithFiles'
@@ -309,7 +314,8 @@ export var MediaStore = /*#__PURE__*/function () {
309
314
  collectionName: params.collection
310
315
  },
311
316
  headers: jsonHeaders,
312
- body: JSON.stringify(body)
317
+ body: JSON.stringify(body),
318
+ traceContext: traceContext
313
319
  });
314
320
 
315
321
  return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
@@ -318,6 +324,7 @@ export var MediaStore = /*#__PURE__*/function () {
318
324
  key: "getFile",
319
325
  value: function getFile(fileId) {
320
326
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
327
+ var traceContext = arguments.length > 2 ? arguments[2] : undefined;
321
328
  var metadata = {
322
329
  method: 'GET',
323
330
  endpoint: '/file/{fileId}'
@@ -327,7 +334,8 @@ export var MediaStore = /*#__PURE__*/function () {
327
334
  authContext: {
328
335
  collectionName: params.collection
329
336
  },
330
- params: params
337
+ params: params,
338
+ traceContext: traceContext
331
339
  });
332
340
 
333
341
  return this.request("/file/".concat(fileId), options).then(createMapResponseToJson(metadata));
@@ -360,12 +368,13 @@ export var MediaStore = /*#__PURE__*/function () {
360
368
  }, _callee4, this);
361
369
  }));
362
370
 
363
- function getFileImageURL(_x8, _x9) {
371
+ function getFileImageURL(_x10, _x11) {
364
372
  return _getFileImageURL.apply(this, arguments);
365
373
  }
366
374
 
367
375
  return getFileImageURL;
368
- }()
376
+ }() // TODO Create ticket in case Trace Id can be supported through query params
377
+
369
378
  }, {
370
379
  key: "getFileImageURLSync",
371
380
  value: function getFileImageURLSync(id, params) {
@@ -415,7 +424,7 @@ export var MediaStore = /*#__PURE__*/function () {
415
424
  }, _callee5, this);
416
425
  }));
417
426
 
418
- function getFileBinaryURL(_x10, _x11) {
427
+ function getFileBinaryURL(_x12, _x13) {
419
428
  return _getFileBinaryURL.apply(this, arguments);
420
429
  }
421
430
 
@@ -464,7 +473,7 @@ export var MediaStore = /*#__PURE__*/function () {
464
473
  }, _callee6, this);
465
474
  }));
466
475
 
467
- function getArtifactURL(_x12, _x13, _x14) {
476
+ function getArtifactURL(_x14, _x15, _x16) {
468
477
  return _getArtifactURL.apply(this, arguments);
469
478
  }
470
479
 
@@ -473,9 +482,7 @@ export var MediaStore = /*#__PURE__*/function () {
473
482
  }, {
474
483
  key: "getImage",
475
484
  value: function () {
476
- var _getImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(id, params, controller, fetchMaxRes, traceId) {
477
- var _ref4;
478
-
485
+ var _getImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(id, params, controller, fetchMaxRes, traceContext) {
479
486
  var isWebpSupported, headers, metadata, options;
480
487
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
481
488
  while (1) {
@@ -483,7 +490,7 @@ export var MediaStore = /*#__PURE__*/function () {
483
490
  case 0:
484
491
  // TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
485
492
  isWebpSupported = false;
486
- headers = !!traceId ? (_ref4 = {}, _defineProperty(_ref4, ZipkinHeaderKeys.traceId, traceId), _defineProperty(_ref4, ZipkinHeaderKeys.spanId, getRandomHex(16)), _ref4) : {};
493
+ headers = {};
487
494
 
488
495
  if (isWebpSupported) {
489
496
  headers.accept = 'image/webp,image/*,*/*;q=0.8';
@@ -498,7 +505,8 @@ export var MediaStore = /*#__PURE__*/function () {
498
505
  collectionName: params && params.collection
499
506
  },
500
507
  params: extendImageParams(params, fetchMaxRes),
501
- headers: headers
508
+ headers: headers,
509
+ traceContext: traceContext
502
510
  });
503
511
  return _context7.abrupt("return", this.request("/file/".concat(id, "/image"), options, controller).then(createMapResponseToBlob(metadata)));
504
512
 
@@ -510,7 +518,7 @@ export var MediaStore = /*#__PURE__*/function () {
510
518
  }, _callee7, this);
511
519
  }));
512
520
 
513
- function getImage(_x15, _x16, _x17, _x18, _x19) {
521
+ function getImage(_x17, _x18, _x19, _x20, _x21) {
514
522
  return _getImage.apply(this, arguments);
515
523
  }
516
524
 
@@ -519,7 +527,7 @@ export var MediaStore = /*#__PURE__*/function () {
519
527
  }, {
520
528
  key: "getItems",
521
529
  value: function () {
522
- var _getItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(ids, collectionName) {
530
+ var _getItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(ids, collectionName, traceContext) {
523
531
  var descriptors, metadata, options;
524
532
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
525
533
  while (1) {
@@ -543,7 +551,8 @@ export var MediaStore = /*#__PURE__*/function () {
543
551
  headers: jsonHeaders,
544
552
  body: JSON.stringify({
545
553
  descriptors: descriptors
546
- })
554
+ }),
555
+ traceContext: traceContext
547
556
  });
548
557
  return _context8.abrupt("return", this.request('/items', options).then(createMapResponseToJson(metadata)));
549
558
 
@@ -555,7 +564,7 @@ export var MediaStore = /*#__PURE__*/function () {
555
564
  }, _callee8, this);
556
565
  }));
557
566
 
558
- function getItems(_x20, _x21) {
567
+ function getItems(_x22, _x23, _x24) {
559
568
  return _getItems.apply(this, arguments);
560
569
  }
561
570
 
@@ -564,7 +573,7 @@ export var MediaStore = /*#__PURE__*/function () {
564
573
  }, {
565
574
  key: "getImageMetadata",
566
575
  value: function () {
567
- var _getImageMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(id, params) {
576
+ var _getImageMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(id, params, traceContext) {
568
577
  var metadata, options;
569
578
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
570
579
  while (1) {
@@ -578,7 +587,8 @@ export var MediaStore = /*#__PURE__*/function () {
578
587
  authContext: {
579
588
  collectionName: params && params.collection
580
589
  },
581
- params: params
590
+ params: params,
591
+ traceContext: traceContext
582
592
  });
583
593
  return _context9.abrupt("return", this.request("/file/".concat(id, "/image/metadata"), options).then(createMapResponseToJson(metadata)));
584
594
 
@@ -590,7 +600,7 @@ export var MediaStore = /*#__PURE__*/function () {
590
600
  }, _callee9, this);
591
601
  }));
592
602
 
593
- function getImageMetadata(_x22, _x23) {
603
+ function getImageMetadata(_x25, _x26, _x27) {
594
604
  return _getImageMetadata.apply(this, arguments);
595
605
  }
596
606
 
@@ -599,7 +609,7 @@ export var MediaStore = /*#__PURE__*/function () {
599
609
  }, {
600
610
  key: "appendChunksToUpload",
601
611
  value: function () {
602
- var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(uploadId, body, collectionName) {
612
+ var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(uploadId, body, collectionName, traceContext) {
603
613
  var metadata, options;
604
614
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
605
615
  while (1) {
@@ -614,7 +624,8 @@ export var MediaStore = /*#__PURE__*/function () {
614
624
  collectionName: collectionName
615
625
  },
616
626
  headers: jsonHeaders,
617
- body: JSON.stringify(body)
627
+ body: JSON.stringify(body),
628
+ traceContext: traceContext
618
629
  });
619
630
  _context10.next = 4;
620
631
  return this.request("/upload/".concat(uploadId, "/chunks"), options);
@@ -627,7 +638,7 @@ export var MediaStore = /*#__PURE__*/function () {
627
638
  }, _callee10, this);
628
639
  }));
629
640
 
630
- function appendChunksToUpload(_x24, _x25, _x26) {
641
+ function appendChunksToUpload(_x28, _x29, _x30, _x31) {
631
642
  return _appendChunksToUpload.apply(this, arguments);
632
643
  }
633
644
 
@@ -635,7 +646,7 @@ export var MediaStore = /*#__PURE__*/function () {
635
646
  }()
636
647
  }, {
637
648
  key: "copyFileWithToken",
638
- value: function copyFileWithToken(body, params) {
649
+ value: function copyFileWithToken(body, params, traceContext) {
639
650
  var metadata = {
640
651
  method: 'POST',
641
652
  endpoint: '/file/copy/withToken'
@@ -649,8 +660,9 @@ export var MediaStore = /*#__PURE__*/function () {
649
660
  params: params,
650
661
  // Contains collection name to write to
651
662
  headers: jsonHeaders,
652
- body: JSON.stringify(body) // Contains collection name to read from
653
-
663
+ body: JSON.stringify(body),
664
+ // Contains collection name to read from
665
+ traceContext: traceContext
654
666
  });
655
667
 
656
668
  return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
@@ -668,7 +680,9 @@ export var MediaStore = /*#__PURE__*/function () {
668
680
  headers,
669
681
  body,
670
682
  clientOptions,
683
+ traceContext,
671
684
  auth,
685
+ extendedTraceContext,
672
686
  response,
673
687
  _args11 = arguments;
674
688
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
@@ -681,13 +695,16 @@ export var MediaStore = /*#__PURE__*/function () {
681
695
  authContext: {}
682
696
  };
683
697
  controller = _args11.length > 2 ? _args11[2] : undefined;
684
- method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions;
698
+ method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
685
699
  _context11.next = 5;
686
700
  return this.resolveAuth(authContext);
687
701
 
688
702
  case 5:
689
703
  auth = _context11.sent;
690
- _context11.next = 8;
704
+ extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
705
+ spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(16)
706
+ }) : undefined;
707
+ _context11.next = 9;
691
708
  return _request("".concat(auth.baseUrl).concat(path), {
692
709
  method: method,
693
710
  endpoint: endpoint,
@@ -695,16 +712,17 @@ export var MediaStore = /*#__PURE__*/function () {
695
712
  params: params,
696
713
  headers: headers,
697
714
  body: body,
698
- clientOptions: clientOptions
715
+ clientOptions: clientOptions,
716
+ traceContext: extendedTraceContext
699
717
  }, controller);
700
718
 
701
- case 8:
719
+ case 9:
702
720
  response = _context11.sent;
703
721
  setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
704
722
  setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
705
723
  return _context11.abrupt("return", response);
706
724
 
707
- case 12:
725
+ case 13:
708
726
  case "end":
709
727
  return _context11.stop();
710
728
  }
@@ -712,7 +730,7 @@ export var MediaStore = /*#__PURE__*/function () {
712
730
  }, _callee11, this);
713
731
  }));
714
732
 
715
- function request(_x27) {
733
+ function request(_x32) {
716
734
  return _request2.apply(this, arguments);
717
735
  }
718
736
 
@@ -42,7 +42,7 @@ var hashingFunction = /*#__PURE__*/function () {
42
42
  };
43
43
  }();
44
44
 
45
- var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName) {
45
+ var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName, traceContext) {
46
46
  return /*#__PURE__*/function () {
47
47
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chunks) {
48
48
  var response, results;
@@ -76,17 +76,18 @@ var createProbingFunction = function createProbingFunction(store, deferredUpload
76
76
  collectionName: _context2.t2,
77
77
  uploadId: _context2.t4
78
78
  };
79
- _context2.next = 14;
80
- return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t5);
79
+ _context2.t6 = traceContext;
80
+ _context2.next = 15;
81
+ return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t5, _context2.t6);
81
82
 
82
- case 14:
83
+ case 15:
83
84
  response = _context2.sent;
84
85
  results = response.data.results;
85
86
  return _context2.abrupt("return", Object.values(results).map(function (result) {
86
87
  return result.exists;
87
88
  }));
88
89
 
89
- case 17:
90
+ case 18:
90
91
  case "end":
91
92
  return _context2.stop();
92
93
  }
@@ -100,7 +101,7 @@ var createProbingFunction = function createProbingFunction(store, deferredUpload
100
101
  }();
101
102
  };
102
103
 
103
- var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName) {
104
+ var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName, traceContext) {
104
105
  return /*#__PURE__*/function () {
105
106
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(chunk) {
106
107
  var options;
@@ -134,7 +135,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
134
135
  _context3.next = 12;
135
136
  return store.uploadChunk(chunk.hash, chunk.blob, _objectSpread({
136
137
  collectionName: collectionName
137
- }, options));
138
+ }, options), traceContext);
138
139
 
139
140
  case 12:
140
141
  return _context3.abrupt("return", _context3.sent);
@@ -153,7 +154,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
153
154
  }();
154
155
  };
155
156
 
156
- var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection) {
157
+ var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
157
158
  var offset = 0;
158
159
  return /*#__PURE__*/function () {
159
160
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(chunks) {
@@ -172,13 +173,14 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
172
173
  offset: offset
173
174
  };
174
175
  _context4.t3 = collection;
175
- _context4.next = 8;
176
- return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3);
176
+ _context4.t4 = traceContext;
177
+ _context4.next = 9;
178
+ return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
177
179
 
178
- case 8:
180
+ case 9:
179
181
  offset += chunks.length;
180
182
 
181
- case 9:
183
+ case 10:
182
184
  case "end":
183
185
  return _context4.stop();
184
186
  }
@@ -193,7 +195,7 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
193
195
  };
194
196
 
195
197
  var createFileFromUpload = /*#__PURE__*/function () {
196
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId) {
198
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
197
199
  var collection, name, mimeType, id, occurrenceKey;
198
200
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
199
201
  while (1) {
@@ -209,7 +211,7 @@ var createFileFromUpload = /*#__PURE__*/function () {
209
211
  occurrenceKey: occurrenceKey,
210
212
  collection: collection,
211
213
  replaceFileId: id
212
- }));
214
+ }, traceContext));
213
215
 
214
216
  case 3:
215
217
  case "end":
@@ -219,12 +221,12 @@ var createFileFromUpload = /*#__PURE__*/function () {
219
221
  }, _callee5);
220
222
  }));
221
223
 
222
- return function createFileFromUpload(_x5, _x6, _x7, _x8) {
224
+ return function createFileFromUpload(_x5, _x6, _x7, _x8, _x9) {
223
225
  return _ref5.apply(this, arguments);
224
226
  };
225
227
  }();
226
228
 
227
- export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks) {
229
+ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks, traceContext) {
228
230
  var content = file.content,
229
231
  collection = file.collection;
230
232
  var deferredUploadId = uploadableFileUpfrontIds.deferredUploadId,
@@ -257,10 +259,10 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
257
259
  probingBatchSize: 100,
258
260
  chunkSize: chunkSize,
259
261
  uploadingConcurrency: 3,
260
- uploadingFunction: createUploadingFunction(store, deferredUploadId, collection),
261
- probingFunction: createProbingFunction(store, deferredUploadId, collection),
262
+ uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
263
+ probingFunction: createProbingFunction(store, deferredUploadId, collection, traceContext),
262
264
  processingBatchSize: PROCESSING_BATCH_SIZE,
263
- processingFunction: createProcessingFunction(store, deferredUploadId, collection)
265
+ processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
264
266
  }, {
265
267
  onProgress: function onProgress(progress) {
266
268
  if (callbacks) {
@@ -273,7 +275,7 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
273
275
 
274
276
  var subscription = from(deferredUploadId).pipe(concatMap(function (uploadId) {
275
277
  return chunkinatorObservable.pipe(concatMap(function () {
276
- return from(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId));
278
+ return from(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId, traceContext));
277
279
  }));
278
280
  })).subscribe({
279
281
  error: function error(err) {
@@ -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