@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
@@ -9,8 +9,6 @@ exports.uploadFile = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
13
 
16
14
  var _chunkinator = require("@atlaskit/chunkinator");
@@ -27,12 +25,6 @@ var _constants = require("../constants");
27
25
 
28
26
  var _calculateChunkSize = require("./calculateChunkSize");
29
27
 
30
- var _mediaCommon = require("@atlaskit/media-common");
31
-
32
- 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; }
33
-
34
- 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) { (0, _defineProperty2.default)(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; }
35
-
36
28
  var hashingFunction = /*#__PURE__*/function () {
37
29
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(blob) {
38
30
  var hasher;
@@ -60,7 +52,7 @@ var hashingFunction = /*#__PURE__*/function () {
60
52
  };
61
53
  }();
62
54
 
63
- var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName) {
55
+ var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName, traceContext) {
64
56
  return /*#__PURE__*/function () {
65
57
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(chunks) {
66
58
  var response, results;
@@ -71,40 +63,27 @@ var createProbingFunction = function createProbingFunction(store, deferredUpload
71
63
  _context2.t0 = store;
72
64
  _context2.t1 = hashedChunks(chunks);
73
65
  _context2.t2 = collectionName;
74
-
75
- if (!(0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
76
- _context2.next = 9;
77
- break;
78
- }
79
-
80
- _context2.next = 6;
66
+ _context2.next = 5;
81
67
  return deferredUploadId;
82
68
 
83
- case 6:
69
+ case 5:
84
70
  _context2.t3 = _context2.sent;
85
- _context2.next = 10;
86
- break;
87
-
88
- case 9:
89
- _context2.t3 = undefined;
90
-
91
- case 10:
92
- _context2.t4 = _context2.t3;
93
- _context2.t5 = {
71
+ _context2.t4 = {
94
72
  collectionName: _context2.t2,
95
- uploadId: _context2.t4
73
+ uploadId: _context2.t3
96
74
  };
97
- _context2.next = 14;
98
- return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t5);
75
+ _context2.t5 = traceContext;
76
+ _context2.next = 10;
77
+ return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t4, _context2.t5);
99
78
 
100
- case 14:
79
+ case 10:
101
80
  response = _context2.sent;
102
81
  results = response.data.results;
103
82
  return _context2.abrupt("return", Object.values(results).map(function (result) {
104
83
  return result.exists;
105
84
  }));
106
85
 
107
- case 17:
86
+ case 13:
108
87
  case "end":
109
88
  return _context2.stop();
110
89
  }
@@ -118,41 +97,31 @@ var createProbingFunction = function createProbingFunction(store, deferredUpload
118
97
  }();
119
98
  };
120
99
 
121
- var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName) {
100
+ var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName, traceContext) {
122
101
  return /*#__PURE__*/function () {
123
102
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(chunk) {
124
- var options;
125
103
  return _regenerator.default.wrap(function _callee3$(_context3) {
126
104
  while (1) {
127
105
  switch (_context3.prev = _context3.next) {
128
106
  case 0:
129
- if (!(0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
130
- _context3.next = 8;
131
- break;
132
- }
133
-
134
- _context3.t1 = chunk.partNumber;
135
- _context3.next = 4;
107
+ _context3.t0 = store;
108
+ _context3.t1 = chunk.hash;
109
+ _context3.t2 = chunk.blob;
110
+ _context3.t3 = collectionName;
111
+ _context3.t4 = chunk.partNumber;
112
+ _context3.next = 7;
136
113
  return deferredUploadId;
137
114
 
138
- case 4:
139
- _context3.t2 = _context3.sent;
140
- _context3.t0 = {
141
- partNumber: _context3.t1,
142
- uploadId: _context3.t2
115
+ case 7:
116
+ _context3.t5 = _context3.sent;
117
+ _context3.t6 = {
118
+ collectionName: _context3.t3,
119
+ partNumber: _context3.t4,
120
+ uploadId: _context3.t5
143
121
  };
144
- _context3.next = 9;
145
- break;
146
-
147
- case 8:
148
- _context3.t0 = {};
149
-
150
- case 9:
151
- options = _context3.t0;
122
+ _context3.t7 = traceContext;
152
123
  _context3.next = 12;
153
- return store.uploadChunk(chunk.hash, chunk.blob, _objectSpread({
154
- collectionName: collectionName
155
- }, options));
124
+ return _context3.t0.uploadChunk.call(_context3.t0, _context3.t1, _context3.t2, _context3.t6, _context3.t7);
156
125
 
157
126
  case 12:
158
127
  return _context3.abrupt("return", _context3.sent);
@@ -171,7 +140,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
171
140
  }();
172
141
  };
173
142
 
174
- var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection) {
143
+ var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
175
144
  var offset = 0;
176
145
  return /*#__PURE__*/function () {
177
146
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(chunks) {
@@ -190,13 +159,14 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
190
159
  offset: offset
191
160
  };
192
161
  _context4.t3 = collection;
193
- _context4.next = 8;
194
- return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3);
162
+ _context4.t4 = traceContext;
163
+ _context4.next = 9;
164
+ return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
195
165
 
196
- case 8:
166
+ case 9:
197
167
  offset += chunks.length;
198
168
 
199
- case 9:
169
+ case 10:
200
170
  case "end":
201
171
  return _context4.stop();
202
172
  }
@@ -211,7 +181,7 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
211
181
  };
212
182
 
213
183
  var createFileFromUpload = /*#__PURE__*/function () {
214
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId) {
184
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
215
185
  var collection, name, mimeType, id, occurrenceKey;
216
186
  return _regenerator.default.wrap(function _callee5$(_context5) {
217
187
  while (1) {
@@ -227,7 +197,7 @@ var createFileFromUpload = /*#__PURE__*/function () {
227
197
  occurrenceKey: occurrenceKey,
228
198
  collection: collection,
229
199
  replaceFileId: id
230
- }));
200
+ }, traceContext));
231
201
 
232
202
  case 3:
233
203
  case "end":
@@ -237,12 +207,12 @@ var createFileFromUpload = /*#__PURE__*/function () {
237
207
  }, _callee5);
238
208
  }));
239
209
 
240
- return function createFileFromUpload(_x5, _x6, _x7, _x8) {
210
+ return function createFileFromUpload(_x5, _x6, _x7, _x8, _x9) {
241
211
  return _ref5.apply(this, arguments);
242
212
  };
243
213
  }();
244
214
 
245
- var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks) {
215
+ var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks, traceContext) {
246
216
  var content = file.content,
247
217
  collection = file.collection;
248
218
  var deferredUploadId = uploadableFileUpfrontIds.deferredUploadId,
@@ -251,7 +221,7 @@ var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, call
251
221
  var chunkSize = _constants.CHUNK_SIZE;
252
222
 
253
223
  try {
254
- if (content instanceof Blob && (0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
224
+ if (content instanceof Blob) {
255
225
  chunkSize = (0, _calculateChunkSize.calculateChunkSize)(content.size);
256
226
  }
257
227
  } catch (err) {
@@ -275,10 +245,10 @@ var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, call
275
245
  probingBatchSize: 100,
276
246
  chunkSize: chunkSize,
277
247
  uploadingConcurrency: 3,
278
- uploadingFunction: createUploadingFunction(store, deferredUploadId, collection),
279
- probingFunction: createProbingFunction(store, deferredUploadId, collection),
248
+ uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
249
+ probingFunction: createProbingFunction(store, deferredUploadId, collection, traceContext),
280
250
  processingBatchSize: _constants.PROCESSING_BATCH_SIZE,
281
- processingFunction: createProcessingFunction(store, deferredUploadId, collection)
251
+ processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
282
252
  }, {
283
253
  onProgress: function onProgress(progress) {
284
254
  if (callbacks) {
@@ -291,7 +261,7 @@ var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, call
291
261
 
292
262
  var subscription = (0, _from.from)(deferredUploadId).pipe((0, _concatMap.concatMap)(function (uploadId) {
293
263
  return chunkinatorObservable.pipe((0, _concatMap.concatMap)(function () {
294
- return (0, _from.from)(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId));
264
+ return (0, _from.from)(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId, traceContext));
295
265
  }));
296
266
  })).subscribe({
297
267
  error: function error(err) {
@@ -16,12 +16,18 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
16
16
 
17
17
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
18
18
 
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+
19
21
  require("setimmediate");
20
22
 
21
23
  var _dataloader = _interopRequireDefault(require("dataloader"));
22
24
 
23
- // import setimmediate to temporary fix dataloader 2.0.0 bug
24
- // @see https://github.com/graphql/dataloader/issues/249
25
+ var _mediaCommon = require("@atlaskit/media-common");
26
+
27
+ 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; }
28
+
29
+ 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) { (0, _defineProperty2.default)(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; }
30
+
25
31
  var MAX_BATCH_SIZE = 100;
26
32
  exports.MAX_BATCH_SIZE = MAX_BATCH_SIZE;
27
33
 
@@ -38,7 +44,9 @@ var getItemsFromKeys = function getItemsFromKeys(dataloaderKeys, fileItems) {
38
44
  var id = fileItem.id,
39
45
  collection = fileItem.collection;
40
46
  var key = makeCacheKey(id, collection);
41
- prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : fileItem.details;
47
+ prev[key] = isBatchLoadingErrorResult(fileItem) ? fileItem.error : _objectSpread(_objectSpread({}, fileItem.details), {}, {
48
+ metadataTraceContext: fileItem.metadataTraceContext
49
+ });
42
50
  return prev;
43
51
  }, {});
44
52
  return dataloaderKeys.map(function (dataloaderKey) {
@@ -84,26 +92,35 @@ function createBatchLoadingFunc(mediaStore) {
84
92
  _context2.next = 5;
85
93
  return Promise.all(Object.keys(fileIdsByCollection).map( /*#__PURE__*/function () {
86
94
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(collectionNameKey) {
87
- var fileIds, collectionName, response;
95
+ var metadataTraceContext, fileIds, collectionName, response, itemsWithMetadataTraceContext;
88
96
  return _regenerator.default.wrap(function _callee$(_context) {
89
97
  while (1) {
90
98
  switch (_context.prev = _context.next) {
91
99
  case 0:
100
+ metadataTraceContext = {
101
+ traceId: (0, _mediaCommon.getRandomHex)(8),
102
+ spanId: (0, _mediaCommon.getRandomHex)(8)
103
+ };
92
104
  fileIds = fileIdsByCollection[collectionNameKey];
93
105
  collectionName = collectionNameKey === nonCollectionName ? undefined : collectionNameKey;
94
- _context.prev = 2;
95
- _context.next = 5;
96
- return mediaStore.getItems(fileIds, collectionName);
106
+ _context.prev = 3;
107
+ _context.next = 6;
108
+ return mediaStore.getItems(fileIds, collectionName, metadataTraceContext);
97
109
 
98
- case 5:
110
+ case 6:
99
111
  response = _context.sent;
100
- items.push.apply(items, (0, _toConsumableArray2.default)(response.data.items));
101
- _context.next = 12;
112
+ itemsWithMetadataTraceContext = response.data.items.map(function (item) {
113
+ return _objectSpread(_objectSpread({}, item), {}, {
114
+ metadataTraceContext: metadataTraceContext
115
+ });
116
+ });
117
+ items.push.apply(items, (0, _toConsumableArray2.default)(itemsWithMetadataTraceContext));
118
+ _context.next = 14;
102
119
  break;
103
120
 
104
- case 9:
105
- _context.prev = 9;
106
- _context.t0 = _context["catch"](2);
121
+ case 11:
122
+ _context.prev = 11;
123
+ _context.t0 = _context["catch"](3);
107
124
  fileIds.forEach(function (fileId) {
108
125
  items.push({
109
126
  id: fileId,
@@ -112,12 +129,12 @@ function createBatchLoadingFunc(mediaStore) {
112
129
  });
113
130
  });
114
131
 
115
- case 12:
132
+ case 14:
116
133
  case "end":
117
134
  return _context.stop();
118
135
  }
119
136
  }
120
- }, _callee, null, [[2, 9]]);
137
+ }, _callee, null, [[3, 11]]);
121
138
  }));
122
139
 
123
140
  return function (_x2) {
@@ -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,6 +14,7 @@ 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;
19
20
  exports.isAbortedRequestError = isAbortedRequestError;
@@ -24,7 +25,6 @@ exports.mapResponseToBlob = mapResponseToBlob;
24
25
  exports.mapResponseToJson = mapResponseToJson;
25
26
  exports.mapResponseToVoid = mapResponseToVoid;
26
27
  exports.waitPromise = waitPromise;
27
- exports.withAuth = withAuth;
28
28
 
29
29
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
30
 
@@ -71,7 +71,26 @@ function isRateLimitedError(error) {
71
71
  return !!error && (0, _errors.isRequestError)(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
72
72
  }
73
73
 
74
+ var ZipkinHeaderKeys = {
75
+ traceId: 'x-b3-traceid',
76
+ spanId: 'x-b3-spanid',
77
+ parentSpanId: 'x-b3-parentspanid',
78
+ sampled: 'x-b3-sampled',
79
+ flags: 'x-b3-flags'
80
+ };
81
+ exports.ZipkinHeaderKeys = ZipkinHeaderKeys;
82
+
83
+ var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
84
+ var _ref;
85
+
86
+ return traceContext ? (_ref = {}, (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
87
+ };
88
+
74
89
  function mapAuthToRequestHeaders(auth) {
90
+ if (!auth) {
91
+ return {};
92
+ }
93
+
75
94
  if ((0, _mediaCore.isClientBasedAuth)(auth)) {
76
95
  return {
77
96
  'X-Client-Id': auth.clientId,
@@ -85,18 +104,18 @@ function mapAuthToRequestHeaders(auth) {
85
104
  };
86
105
  }
87
106
 
88
- function createUrl(url, _ref) {
89
- var params = _ref.params,
90
- auth = _ref.auth;
107
+ function createUrl(url, _ref2) {
108
+ var params = _ref2.params,
109
+ auth = _ref2.auth;
91
110
  var parsedUrl = new URL(url);
92
111
  var authParams = auth && (0, _authQueryParameters.mapAuthToQueryParameters)(auth) || {};
93
112
 
94
113
  var paramsToAppend = _objectSpread(_objectSpread({}, params), authParams);
95
114
 
96
- Object.entries(paramsToAppend).filter(function (_ref2) {
97
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
98
- _ = _ref3[0],
99
- value = _ref3[1];
115
+ Object.entries(paramsToAppend).filter(function (_ref3) {
116
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
117
+ _ = _ref4[0],
118
+ value = _ref4[1];
100
119
 
101
120
  return value != null;
102
121
  }).forEach(function (pair) {
@@ -108,14 +127,12 @@ function createUrl(url, _ref) {
108
127
  return parsedUrl.toString();
109
128
  }
110
129
 
111
- function withAuth(auth) {
112
- return function (headers) {
113
- if (auth) {
114
- return _objectSpread(_objectSpread({}, headers || {}), mapAuthToRequestHeaders(auth));
115
- }
130
+ function extendHeaders(headers, auth, traceContext) {
131
+ if (!auth && !traceContext && !headers) {
132
+ return undefined;
133
+ }
116
134
 
117
- return headers;
118
- };
135
+ return _objectSpread(_objectSpread(_objectSpread({}, headers !== null && headers !== void 0 ? headers : {}), mapAuthToRequestHeaders(auth)), mapTraceIdToRequestHeaders(traceContext));
119
136
  }
120
137
  /**
121
138
  * @deprecated Helper is deprecated and will be removed in the next major version.
@@ -213,7 +230,7 @@ function mapResponseToVoid() {
213
230
 
214
231
  function createMapResponseToJson(metadata) {
215
232
  return /*#__PURE__*/function () {
216
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response) {
233
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response) {
217
234
  return _regenerator.default.wrap(function _callee$(_context) {
218
235
  while (1) {
219
236
  switch (_context.prev = _context.next) {
@@ -241,14 +258,14 @@ function createMapResponseToJson(metadata) {
241
258
  }));
242
259
 
243
260
  return function (_x3) {
244
- return _ref4.apply(this, arguments);
261
+ return _ref5.apply(this, arguments);
245
262
  };
246
263
  }();
247
264
  }
248
265
 
249
266
  function createMapResponseToBlob(metadata) {
250
267
  return /*#__PURE__*/function () {
251
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(response) {
268
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(response) {
252
269
  return _regenerator.default.wrap(function _callee2$(_context2) {
253
270
  while (1) {
254
271
  switch (_context2.prev = _context2.next) {
@@ -276,7 +293,7 @@ function createMapResponseToBlob(metadata) {
276
293
  }));
277
294
 
278
295
  return function (_x4) {
279
- return _ref5.apply(this, arguments);
296
+ return _ref6.apply(this, arguments);
280
297
  };
281
298
  }();
282
299
  }
@@ -325,7 +342,7 @@ function _fetchRetry() {
325
342
  timeoutInMs = startTimeoutInMs;
326
343
 
327
344
  waitAndBumpTimeout = /*#__PURE__*/function () {
328
- var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
345
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
329
346
  return _regenerator.default.wrap(function _callee5$(_context5) {
330
347
  while (1) {
331
348
  switch (_context5.prev = _context5.next) {
@@ -346,7 +363,7 @@ function _fetchRetry() {
346
363
  }));
347
364
 
348
365
  return function waitAndBumpTimeout() {
349
- return _ref6.apply(this, arguments);
366
+ return _ref7.apply(this, arguments);
350
367
  };
351
368
  }();
352
369
 
@@ -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,11 +62,12 @@ 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,
68
- endpoint: endpoint
69
+ endpoint: endpoint,
70
+ traceContext: traceContext
69
71
  }; // TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
70
72
 
71
73
  doFetch = function doFetch() {
@@ -74,7 +76,7 @@ function _request() {
74
76
  }), {
75
77
  method: method,
76
78
  body: body,
77
- headers: (0, _helpers.withAuth)(auth)(headers),
79
+ headers: (0, _helpers.extendHeaders)(headers, auth, traceContext),
78
80
  signal: controller && controller.signal
79
81
  }).then((0, _helpers.createProcessFetchResponse)(metadata));
80
82
  };
@@ -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
  }
@@ -46,7 +46,7 @@ export class CollectionFetcher {
46
46
  collectionCache[collectionName].items.splice(collectionCacheIndex, 1);
47
47
  }
48
48
 
49
- getItems(collectionName, params) {
49
+ getItems(collectionName, params, traceContext) {
50
50
  if (!collectionCache[collectionName]) {
51
51
  collectionCache[collectionName] = createCacheEntry();
52
52
  }
@@ -55,7 +55,7 @@ export class CollectionFetcher {
55
55
  const subject = collection.subject;
56
56
  this.mediaStore.getCollectionItems(collectionName, { ...params,
57
57
  details: 'full'
58
- }).then(items => {
58
+ }, traceContext).then(items => {
59
59
  const {
60
60
  contents,
61
61
  nextInclusiveStartKey
@@ -70,14 +70,14 @@ export class CollectionFetcher {
70
70
  return fromObservable(subject);
71
71
  }
72
72
 
73
- async removeFile(id, collectionName, occurrenceKey) {
74
- await this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey);
73
+ async removeFile(id, collectionName, occurrenceKey, traceContext) {
74
+ await this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey, traceContext);
75
75
  this.removeFromCache(id, collectionName);
76
76
  const collection = collectionCache[collectionName];
77
77
  collection.subject.next(collection.items);
78
78
  }
79
79
 
80
- async loadNextPage(collectionName, params) {
80
+ async loadNextPage(collectionName, params, traceContext) {
81
81
  const collection = collectionCache[collectionName];
82
82
  const isLoading = collection ? collection.isLoadingNextPage : false;
83
83
 
@@ -94,7 +94,7 @@ export class CollectionFetcher {
94
94
  const response = await this.mediaStore.getCollectionItems(collectionName, { ...params,
95
95
  inclusiveStartKey,
96
96
  details: 'full'
97
- });
97
+ }, traceContext);
98
98
  const {
99
99
  contents,
100
100
  nextInclusiveStartKey
@@ -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 ? {