@atlaskit/media-client 16.0.1 → 17.1.1

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 (79) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/cjs/client/collection-fetcher.js +4 -4
  3. package/dist/cjs/client/file-fetcher/index.js +5 -7
  4. package/dist/cjs/client/media-store/index.js +35 -16
  5. package/dist/cjs/constants.js +11 -2
  6. package/dist/cjs/index.js +2 -2
  7. package/dist/cjs/models/media.js +10 -2
  8. package/dist/cjs/uploader/calculateChunkSize.js +45 -0
  9. package/dist/cjs/uploader/error.js +67 -0
  10. package/dist/cjs/uploader/index.js +318 -0
  11. package/dist/cjs/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +4 -4
  12. package/dist/cjs/utils/mediaSubscribable/index.js +27 -0
  13. package/dist/cjs/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +3 -3
  14. package/dist/cjs/utils/mediaSubscribable/types.js +5 -0
  15. package/dist/cjs/version.json +1 -1
  16. package/dist/es2019/client/collection-fetcher.js +2 -2
  17. package/dist/es2019/client/file-fetcher/index.js +5 -6
  18. package/dist/es2019/client/media-store/index.js +16 -2
  19. package/dist/es2019/constants.js +5 -1
  20. package/dist/es2019/index.js +1 -1
  21. package/dist/es2019/models/media.js +8 -1
  22. package/dist/es2019/uploader/calculateChunkSize.js +32 -0
  23. package/dist/es2019/uploader/error.js +30 -0
  24. package/dist/es2019/{uploader.js → uploader/index.js} +47 -10
  25. package/dist/es2019/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
  26. package/dist/es2019/utils/mediaSubscribable/index.js +2 -0
  27. package/dist/es2019/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
  28. package/dist/es2019/utils/mediaSubscribable/types.js +1 -0
  29. package/dist/es2019/version.json +1 -1
  30. package/dist/esm/client/collection-fetcher.js +3 -3
  31. package/dist/esm/client/file-fetcher/index.js +6 -7
  32. package/dist/esm/client/media-client.js +1 -1
  33. package/dist/esm/client/media-store/index.js +36 -17
  34. package/dist/esm/client/media-store/resolveAuth.js +1 -1
  35. package/dist/esm/client/stargate-client.js +1 -1
  36. package/dist/esm/constants.js +5 -1
  37. package/dist/esm/index.js +1 -1
  38. package/dist/esm/models/media.js +8 -1
  39. package/dist/esm/uploader/calculateChunkSize.js +32 -0
  40. package/dist/esm/uploader/error.js +51 -0
  41. package/dist/esm/uploader/index.js +298 -0
  42. package/dist/esm/utils/createFileDataLoader.js +1 -1
  43. package/dist/esm/utils/getDimensionsFromBlob.js +1 -1
  44. package/dist/esm/utils/getVideoDimensionsFromBlob.js +1 -1
  45. package/dist/esm/utils/hashing/hasherCreator.js +1 -1
  46. package/dist/esm/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
  47. package/dist/esm/utils/mediaSubscribable/index.js +2 -0
  48. package/dist/esm/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
  49. package/dist/esm/utils/mediaSubscribable/types.js +1 -0
  50. package/dist/esm/utils/mobileUpload/helpers.js +1 -1
  51. package/dist/esm/utils/mobileUpload/stateMachine/index.js +1 -1
  52. package/dist/esm/utils/polling/index.js +1 -1
  53. package/dist/esm/utils/request/helpers.js +1 -1
  54. package/dist/esm/utils/request/index.js +1 -1
  55. package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -1
  56. package/dist/esm/version.json +1 -1
  57. package/dist/types/client/collection-fetcher.d.ts +1 -1
  58. package/dist/types/client/file-fetcher/index.d.ts +1 -1
  59. package/dist/types/client/media-store/index.d.ts +9 -2
  60. package/dist/types/constants.d.ts +3 -0
  61. package/dist/types/index.d.ts +2 -2
  62. package/dist/types/models/errors/types.d.ts +1 -1
  63. package/dist/types/models/media.d.ts +5 -0
  64. package/dist/types/uploader/calculateChunkSize.d.ts +11 -0
  65. package/dist/types/uploader/error.d.ts +29 -0
  66. package/dist/types/{uploader.d.ts → uploader/index.d.ts} +2 -2
  67. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +5 -0
  68. package/dist/types/utils/mediaSubscribable/index.d.ts +3 -0
  69. package/dist/types/utils/{mediaSubscribableToPromise.d.ts → mediaSubscribable/toPromise.d.ts} +3 -3
  70. package/dist/types/utils/mediaSubscribable/types.d.ts +16 -0
  71. package/dist/types/utils/safeUnsubscribe.d.ts +1 -1
  72. package/example-helpers/styles.ts +99 -0
  73. package/example-helpers/stylesWrapper.tsx +82 -0
  74. package/package.json +8 -7
  75. package/report.api.md +1389 -0
  76. package/dist/cjs/uploader.js +0 -210
  77. package/dist/esm/uploader.js +0 -194
  78. package/dist/types/utils/toMediaSubscribable.d.ts +0 -20
  79. package/example-helpers/styled.ts +0 -77
@@ -1,21 +1,35 @@
1
1
  import { chunkinator } from '@atlaskit/chunkinator';
2
2
  import { from } from 'rxjs/observable/from';
3
3
  import { concatMap } from 'rxjs/operators/concatMap';
4
- import { createHasher } from './utils/hashing/hasherCreator'; // TODO: Allow to pass multiple files
4
+ import { createHasher } from '../utils/hashing/hasherCreator';
5
+ import { UploaderError } from './error';
6
+ import { CHUNK_SIZE, PROCESSING_BATCH_SIZE } from '../constants';
7
+ import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
8
+ import { getMediaFeatureFlag } from '@atlaskit/media-common'; // TODO: Allow to pass multiple files
5
9
 
6
10
  const hashingFunction = async blob => {
7
11
  const hasher = await createHasher();
8
12
  return hasher.hash(blob);
9
13
  };
10
14
 
11
- const createProbingFunction = (store, collection) => async chunks => {
12
- const response = await store.probeChunks(hashedChunks(chunks), collection);
15
+ const createProbingFunction = (store, deferredUploadId, collectionName) => async chunks => {
16
+ const response = await store.probeChunks(hashedChunks(chunks), {
17
+ collectionName,
18
+ uploadId: getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags) ? await deferredUploadId : undefined
19
+ });
13
20
  const results = response.data.results;
14
21
  return Object.values(results).map(result => result.exists);
15
22
  };
16
23
 
17
- const createUploadingFunction = (store, collection) => {
18
- return chunk => store.uploadChunk(chunk.hash, chunk.blob, collection);
24
+ const createUploadingFunction = (store, deferredUploadId, collectionName) => async chunk => {
25
+ const options = getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags) ? {
26
+ partNumber: chunk.partNumber,
27
+ uploadId: await deferredUploadId
28
+ } : {};
29
+ return await store.uploadChunk(chunk.hash, chunk.blob, {
30
+ collectionName,
31
+ ...options
32
+ });
19
33
  };
20
34
 
21
35
  const createProcessingFunction = (store, deferredUploadId, collection) => {
@@ -50,23 +64,46 @@ const createFileFromUpload = async (file, store, uploadableFileUpfrontIds, uploa
50
64
  });
51
65
  };
52
66
 
53
- export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, chunkSize = 4 * 1024 * 1024, processingBatchSize = 1000) => {
67
+ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks) => {
54
68
  const {
55
69
  content,
56
70
  collection
57
71
  } = file;
58
72
  const {
59
- deferredUploadId
73
+ deferredUploadId,
74
+ id,
75
+ occurrenceKey
60
76
  } = uploadableFileUpfrontIds;
77
+ let chunkSize = CHUNK_SIZE;
78
+
79
+ try {
80
+ if (content instanceof Blob && getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags)) {
81
+ chunkSize = calculateChunkSize(content.size);
82
+ }
83
+ } catch (err) {
84
+ if (err instanceof Error && err.message === fileSizeError) {
85
+ callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new UploaderError(err.message, id, {
86
+ collectionName: collection,
87
+ occurrenceKey: occurrenceKey
88
+ }));
89
+ }
90
+
91
+ return {
92
+ cancel: () => {
93
+ callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish('canceled');
94
+ }
95
+ };
96
+ }
97
+
61
98
  const chunkinatorObservable = chunkinator(content, {
62
99
  hashingFunction,
63
100
  hashingConcurrency: 5,
64
101
  probingBatchSize: 100,
65
102
  chunkSize,
66
103
  uploadingConcurrency: 3,
67
- uploadingFunction: createUploadingFunction(store, collection),
68
- probingFunction: createProbingFunction(store, collection),
69
- processingBatchSize,
104
+ uploadingFunction: createUploadingFunction(store, deferredUploadId, collection),
105
+ probingFunction: createProbingFunction(store, deferredUploadId, collection),
106
+ processingBatchSize: PROCESSING_BATCH_SIZE,
70
107
  processingFunction: createProcessingFunction(store, deferredUploadId, collection)
71
108
  }, {
72
109
  onProgress(progress) {
@@ -1,5 +1,5 @@
1
- import { createMediaSubject } from './createMediaSubject';
2
- export function toMediaSubscribable(observable) {
1
+ import { createMediaSubject } from '../createMediaSubject';
2
+ export function fromObservable(observable) {
3
3
  return {
4
4
  subscribe: observer => {
5
5
  const subscription = // This is needed to handle "subscribe" function overload.
@@ -14,5 +14,5 @@ export function toMediaSubscribable(observable) {
14
14
  };
15
15
  }
16
16
  export function createMediaSubscribable(mediaSubscribableItem) {
17
- return toMediaSubscribable(createMediaSubject(mediaSubscribableItem));
17
+ return fromObservable(createMediaSubject(mediaSubscribableItem));
18
18
  }
@@ -0,0 +1,2 @@
1
+ export { toPromise } from './toPromise';
2
+ export { createMediaSubscribable, fromObservable } from './fromObservable';
@@ -6,7 +6,7 @@ import { Subscription } from 'rxjs/Subscription';
6
6
  * @param mediaSubscribable a given MediaSubscribable<MediaSubscribableItem>
7
7
  * @param subscription a default Subscription (this parameter exists for testing purpose)
8
8
  */
9
- export const mediaSubscribableToPromise = (mediaSubscribable, subscription = new Subscription()) => {
9
+ export const toPromise = (mediaSubscribable, subscription = new Subscription()) => {
10
10
  return new Promise((resolve, reject) => subscription.add(mediaSubscribable.subscribe({
11
11
  next: state => {
12
12
  resolve(state);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "16.0.1",
3
+ "version": "17.1.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,9 +1,9 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
4
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
6
5
  import _createClass from "@babel/runtime/helpers/createClass";
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
7
 
8
8
  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; }
9
9
 
@@ -12,7 +12,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
  import { ReplaySubject } from 'rxjs/ReplaySubject';
13
13
  import { getFileStreamsCache } from '../file-streams-cache';
14
14
  import { mapMediaFileToFileState } from '../models/file-state';
15
- import { toMediaSubscribable } from '../utils/toMediaSubscribable';
15
+ import { fromObservable } from '../utils/mediaSubscribable';
16
16
  export var collectionCache = {};
17
17
 
18
18
  var createCacheEntry = function createCacheEntry() {
@@ -98,7 +98,7 @@ export var CollectionFetcher = /*#__PURE__*/function () {
98
98
  }).catch(function (error) {
99
99
  return subject.error(error);
100
100
  });
101
- return toMediaSubscribable(subject);
101
+ return fromObservable(subject);
102
102
  }
103
103
  }, {
104
104
  key: "removeFile",
@@ -1,4 +1,3 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
@@ -8,6 +7,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
8
7
 
9
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
9
 
10
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
11
11
  import { Subscription } from 'rxjs/Subscription';
12
12
  import { of } from 'rxjs/observable/of';
13
13
  import { map } from 'rxjs/operators/map';
@@ -30,14 +30,13 @@ import { createFileDataloader } from '../../utils/createFileDataLoader';
30
30
  import { getMediaTypeFromUploadableFile } from '../../utils/getMediaTypeFromUploadableFile';
31
31
  import { overrideMediaTypeIfUnknown } from '../../utils/overrideMediaTypeIfUnknown';
32
32
  import { convertBase64ToBlob } from '../../utils/convertBase64ToBlob';
33
- import { mediaSubscribableToPromise } from '../../utils/mediaSubscribableToPromise';
33
+ import { toPromise, fromObservable } from '../../utils/mediaSubscribable';
34
34
  import { getDimensionsFromBlob } from '../../utils/getDimensionsFromBlob';
35
35
  import { createMediaSubject } from '../../utils/createMediaSubject';
36
36
  import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaskit/media-common/mediaTypeUtils';
37
37
  import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
38
38
  import { PollingFunction } from '../../utils/polling';
39
39
  import { isEmptyFile } from '../../utils/detectEmptyFile';
40
- import { toMediaSubscribable } from '../../utils/toMediaSubscribable';
41
40
  export { isFileFetcherError, FileFetcherError } from './error';
42
41
  export var FileFetcherImpl = /*#__PURE__*/function () {
43
42
  function FileFetcherImpl(mediaStore) {
@@ -134,17 +133,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
134
133
  collectionName: collectionName,
135
134
  occurrenceKey: occurrenceKey
136
135
  }));
137
- return toMediaSubscribable(subject);
136
+ return fromObservable(subject);
138
137
  }
139
138
 
140
- return toMediaSubscribable(getFileStreamsCache().getOrInsert(id, function () {
139
+ return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
141
140
  return _this2.createDownloadFileStream(id, collectionName);
142
141
  }));
143
142
  }
144
143
  }, {
145
144
  key: "getCurrentState",
146
145
  value: function getCurrentState(id, options) {
147
- return mediaSubscribableToPromise(this.getFileState(id, options));
146
+ return toPromise(this.getFileState(id, options));
148
147
  }
149
148
  }, {
150
149
  key: "getArtifactURL",
@@ -432,7 +431,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
432
431
  });
433
432
  }
434
433
 
435
- return toMediaSubscribable(subject);
434
+ return fromObservable(subject);
436
435
  }
437
436
  }, {
438
437
  key: "downloadBinary",
@@ -1,7 +1,7 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import { EventEmitter2 } from 'eventemitter2';
6
6
  import { MediaStore } from './media-store';
7
7
  import { CollectionFetcher } from './collection-fetcher';
@@ -1,8 +1,8 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
5
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
 
7
7
  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; }
8
8
 
@@ -195,26 +195,38 @@ export var MediaStore = /*#__PURE__*/function () {
195
195
  }, {
196
196
  key: "uploadChunk",
197
197
  value: function () {
198
- var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(etag, blob, collectionName) {
199
- var metadata, options;
198
+ var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(etag, blob) {
199
+ var _ref,
200
+ collectionName,
201
+ uploadId,
202
+ partNumber,
203
+ metadata,
204
+ options,
205
+ _args3 = arguments;
206
+
200
207
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
201
208
  while (1) {
202
209
  switch (_context3.prev = _context3.next) {
203
210
  case 0:
211
+ _ref = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {}, collectionName = _ref.collectionName, uploadId = _ref.uploadId, partNumber = _ref.partNumber;
204
212
  metadata = {
205
213
  method: 'PUT',
206
214
  endpoint: '/chunk/{etag}'
207
215
  };
208
216
  options = _objectSpread(_objectSpread({}, metadata), {}, {
217
+ params: {
218
+ uploadId: uploadId,
219
+ partNumber: partNumber
220
+ },
209
221
  authContext: {
210
222
  collectionName: collectionName
211
223
  },
212
224
  body: blob
213
225
  });
214
- _context3.next = 4;
226
+ _context3.next = 5;
215
227
  return this.request("/chunk/".concat(etag), options);
216
228
 
217
- case 4:
229
+ case 5:
218
230
  case "end":
219
231
  return _context3.stop();
220
232
  }
@@ -222,7 +234,7 @@ export var MediaStore = /*#__PURE__*/function () {
222
234
  }, _callee3, this);
223
235
  }));
224
236
 
225
- function uploadChunk(_x6, _x7, _x8) {
237
+ function uploadChunk(_x6, _x7) {
226
238
  return _uploadChunk.apply(this, arguments);
227
239
  }
228
240
 
@@ -230,13 +242,20 @@ export var MediaStore = /*#__PURE__*/function () {
230
242
  }()
231
243
  }, {
232
244
  key: "probeChunks",
233
- value: function probeChunks(chunks, collectionName) {
245
+ value: function probeChunks(chunks) {
246
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
247
+ collectionName = _ref2.collectionName,
248
+ uploadId = _ref2.uploadId;
249
+
234
250
  var metadata = {
235
251
  method: 'POST',
236
252
  endpoint: '/chunk/probe'
237
253
  };
238
254
 
239
255
  var options = _objectSpread(_objectSpread({}, metadata), {}, {
256
+ params: {
257
+ uploadId: uploadId
258
+ },
240
259
  authContext: {
241
260
  collectionName: collectionName
242
261
  },
@@ -309,13 +328,13 @@ export var MediaStore = /*#__PURE__*/function () {
309
328
  key: "getFileImageURL",
310
329
  value: function () {
311
330
  var _getFileImageURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, params) {
312
- var _ref, collectionName, auth;
331
+ var _ref3, collectionName, auth;
313
332
 
314
333
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
315
334
  while (1) {
316
335
  switch (_context4.prev = _context4.next) {
317
336
  case 0:
318
- _ref = params || {}, collectionName = _ref.collection;
337
+ _ref3 = params || {}, collectionName = _ref3.collection;
319
338
  _context4.next = 3;
320
339
  return this.resolveAuth({
321
340
  collectionName: collectionName
@@ -333,7 +352,7 @@ export var MediaStore = /*#__PURE__*/function () {
333
352
  }, _callee4, this);
334
353
  }));
335
354
 
336
- function getFileImageURL(_x9, _x10) {
355
+ function getFileImageURL(_x8, _x9) {
337
356
  return _getFileImageURL.apply(this, arguments);
338
357
  }
339
358
 
@@ -388,7 +407,7 @@ export var MediaStore = /*#__PURE__*/function () {
388
407
  }, _callee5, this);
389
408
  }));
390
409
 
391
- function getFileBinaryURL(_x11, _x12) {
410
+ function getFileBinaryURL(_x10, _x11) {
392
411
  return _getFileBinaryURL.apply(this, arguments);
393
412
  }
394
413
 
@@ -437,7 +456,7 @@ export var MediaStore = /*#__PURE__*/function () {
437
456
  }, _callee6, this);
438
457
  }));
439
458
 
440
- function getArtifactURL(_x13, _x14, _x15) {
459
+ function getArtifactURL(_x12, _x13, _x14) {
441
460
  return _getArtifactURL.apply(this, arguments);
442
461
  }
443
462
 
@@ -482,7 +501,7 @@ export var MediaStore = /*#__PURE__*/function () {
482
501
  }, _callee7, this);
483
502
  }));
484
503
 
485
- function getImage(_x16, _x17, _x18, _x19) {
504
+ function getImage(_x15, _x16, _x17, _x18) {
486
505
  return _getImage.apply(this, arguments);
487
506
  }
488
507
 
@@ -527,7 +546,7 @@ export var MediaStore = /*#__PURE__*/function () {
527
546
  }, _callee8, this);
528
547
  }));
529
548
 
530
- function getItems(_x20, _x21) {
549
+ function getItems(_x19, _x20) {
531
550
  return _getItems.apply(this, arguments);
532
551
  }
533
552
 
@@ -562,7 +581,7 @@ export var MediaStore = /*#__PURE__*/function () {
562
581
  }, _callee9, this);
563
582
  }));
564
583
 
565
- function getImageMetadata(_x22, _x23) {
584
+ function getImageMetadata(_x21, _x22) {
566
585
  return _getImageMetadata.apply(this, arguments);
567
586
  }
568
587
 
@@ -599,7 +618,7 @@ export var MediaStore = /*#__PURE__*/function () {
599
618
  }, _callee10, this);
600
619
  }));
601
620
 
602
- function appendChunksToUpload(_x24, _x25, _x26) {
621
+ function appendChunksToUpload(_x23, _x24, _x25) {
603
622
  return _appendChunksToUpload.apply(this, arguments);
604
623
  }
605
624
 
@@ -684,7 +703,7 @@ export var MediaStore = /*#__PURE__*/function () {
684
703
  }, _callee11, this);
685
704
  }));
686
705
 
687
- function request(_x27) {
706
+ function request(_x26) {
688
707
  return _request2.apply(this, arguments);
689
708
  }
690
709
 
@@ -1,5 +1,5 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { MediaStoreError } from './error';
4
4
  import { rejectTimeout } from '../../utils/setTimeoutPromise';
5
5
  export var DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
@@ -1,7 +1,7 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  export var StargateClient = /*#__PURE__*/function () {
6
6
  function StargateClient(baseUrl) {
7
7
  _classCallCheck(this, StargateClient);
@@ -1,4 +1,8 @@
1
+ import { DATA_UNIT } from './models/media';
1
2
  export var RECENTS_COLLECTION = 'recents';
2
3
  export var FILE_CACHE_MAX_AGE = 60 * 60 * 24 * 30; // Retain for 30 days
3
4
 
4
- export var MAX_RESOLUTION = 4096;
5
+ export var MAX_RESOLUTION = 4096;
6
+ export var CHUNK_SIZE = 4 * DATA_UNIT.MB;
7
+ export var PROCESSING_BATCH_SIZE = 1000;
8
+ export var MAX_UPLOAD_FILE_SIZE = 2 * DATA_UNIT.TB;
package/dist/esm/index.js CHANGED
@@ -25,7 +25,7 @@ export { isFileIdentifier, isExternalImageIdentifier, isDifferentIdentifier } fr
25
25
  export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
26
26
  export { globalMediaEventEmitter } from './globalMediaEventEmitter';
27
27
  export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
28
- export { createMediaSubscribable } from './utils/toMediaSubscribable';
28
+ export { createMediaSubscribable } from './utils/mediaSubscribable';
29
29
  export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants'; // TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
30
30
 
31
31
  import { getMediaTypeFromMimeType as _getMediaTypeFromMimeType, isImageMimeTypeSupportedByBrowser as _isImageMimeTypeSupportedByBrowser, isDocumentMimeTypeSupportedByBrowser as _isDocumentMimeTypeSupportedByBrowser, isMimeTypeSupportedByBrowser as _isMimeTypeSupportedByBrowser, isImageMimeTypeSupportedByServer as _isImageMimeTypeSupportedByServer, isDocumentMimeTypeSupportedByServer as _isDocumentMimeTypeSupportedByServer, isAudioMimeTypeSupportedByServer as _isAudioMimeTypeSupportedByServer, isVideoMimeTypeSupportedByServer as _isVideoMimeTypeSupportedByServer, isUnknownMimeTypeSupportedByServer as _isUnknownMimeTypeSupportedByServer, isMimeTypeSupportedByServer as _isMimeTypeSupportedByServer } from '@atlaskit/media-common/mediaTypeUtils';
@@ -11,4 +11,11 @@ export var isPreviewableType = function isPreviewableType(type, featureFlags) {
11
11
  };
12
12
  export var isMediaCollectionItemFullDetails = function isMediaCollectionItemFullDetails(mediaCollectionItem) {
13
13
  return !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
14
- };
14
+ };
15
+ export var DATA_UNIT;
16
+
17
+ (function (DATA_UNIT) {
18
+ DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
19
+ DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
20
+ DATA_UNIT[DATA_UNIT["TB"] = 1099511627776] = "TB";
21
+ })(DATA_UNIT || (DATA_UNIT = {}));
@@ -0,0 +1,32 @@
1
+ import { DATA_UNIT } from '../models/media';
2
+ import { MAX_UPLOAD_FILE_SIZE } from '../constants';
3
+ export var fileSizeError = 'fileSizeExceedsLimit';
4
+ /**
5
+ * This is a helper to dynamically calculate the chunk size for a given file size.
6
+ *
7
+ * @param fileSize The size of a file to calculate the chunk size for.
8
+ * @returns A number of bytes per chunk or Throws an Error if the file size exceeds 2TB
9
+ *
10
+ * @see {@link https://product-fabric.atlassian.net/wiki/spaces/FIL/pages/3221881143/Rule+of+thumb+for+chunk+sizes#Given-the-following-conditions}
11
+ *
12
+ */
13
+
14
+ export var calculateChunkSize = function calculateChunkSize(fileSize) {
15
+ if (fileSize > MAX_UPLOAD_FILE_SIZE) {
16
+ throw new Error(fileSizeError);
17
+ }
18
+
19
+ if (fileSize <= 5 * DATA_UNIT.GB) {
20
+ return 5 * DATA_UNIT.MB;
21
+ }
22
+
23
+ if (fileSize > 5 * DATA_UNIT.GB && fileSize <= 50 * DATA_UNIT.GB) {
24
+ return 50 * DATA_UNIT.MB;
25
+ }
26
+
27
+ if (fileSize > 50 * DATA_UNIT.GB && fileSize <= 0.95 * DATA_UNIT.TB) {
28
+ return 100 * DATA_UNIT.MB;
29
+ }
30
+
31
+ return 210 * DATA_UNIT.MB;
32
+ };
@@ -0,0 +1,51 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+
11
+ import { BaseMediaClientError } from '../models/errors';
12
+ export var UploaderError = /*#__PURE__*/function (_BaseMediaClientError) {
13
+ _inherits(UploaderError, _BaseMediaClientError);
14
+
15
+ var _super = _createSuper(UploaderError);
16
+
17
+ function UploaderError(reason, id, metadata) {
18
+ var _this;
19
+
20
+ _classCallCheck(this, UploaderError);
21
+
22
+ _this = _super.call(this, reason);
23
+ _this.reason = reason;
24
+ _this.id = id;
25
+ _this.metadata = metadata;
26
+ return _this;
27
+ }
28
+
29
+ _createClass(UploaderError, [{
30
+ key: "attributes",
31
+ get: function get() {
32
+ var reason = this.reason,
33
+ id = this.id,
34
+ _this$metadata = this.metadata;
35
+ _this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
36
+ var collectionName = _this$metadata.collectionName,
37
+ occurrenceKey = _this$metadata.occurrenceKey;
38
+ return {
39
+ reason: reason,
40
+ id: id,
41
+ collectionName: collectionName,
42
+ occurrenceKey: occurrenceKey
43
+ };
44
+ }
45
+ }]);
46
+
47
+ return UploaderError;
48
+ }(BaseMediaClientError);
49
+ export function isUploaderError(err) {
50
+ return err instanceof UploaderError;
51
+ }