@atlaskit/media-client 25.0.3 → 26.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 (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/client/media-store/MediaStore.js +0 -22
  3. package/dist/cjs/test-helpers/MockedMediaApi/MockedMediaApi.js +432 -0
  4. package/dist/cjs/test-helpers/MockedMediaApi/helpers.js +184 -0
  5. package/dist/cjs/test-helpers/MockedMediaApi/index.js +55 -0
  6. package/dist/cjs/test-helpers/index.js +49 -0
  7. package/dist/cjs/uploader/index.js +36 -72
  8. package/dist/es2019/client/media-store/MediaStore.js +0 -21
  9. package/dist/es2019/test-helpers/MockedMediaApi/MockedMediaApi.js +161 -0
  10. package/dist/es2019/test-helpers/MockedMediaApi/helpers.js +166 -0
  11. package/dist/es2019/test-helpers/MockedMediaApi/index.js +2 -0
  12. package/dist/es2019/test-helpers/index.js +2 -1
  13. package/dist/es2019/uploader/index.js +0 -7
  14. package/dist/esm/client/media-store/MediaStore.js +0 -22
  15. package/dist/esm/test-helpers/MockedMediaApi/MockedMediaApi.js +425 -0
  16. package/dist/esm/test-helpers/MockedMediaApi/helpers.js +176 -0
  17. package/dist/esm/test-helpers/MockedMediaApi/index.js +2 -0
  18. package/dist/esm/test-helpers/index.js +2 -1
  19. package/dist/esm/uploader/index.js +36 -72
  20. package/dist/types/client/media-store/MediaStore.d.ts +1 -2
  21. package/dist/types/client/media-store/types.d.ts +1 -2
  22. package/dist/types/index.d.ts +1 -1
  23. package/dist/types/models/media.d.ts +0 -7
  24. package/dist/types/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
  25. package/dist/types/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
  26. package/dist/types/test-helpers/MockedMediaApi/index.d.ts +3 -0
  27. package/dist/types/test-helpers/index.d.ts +2 -0
  28. package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +1 -2
  29. package/dist/types-ts4.5/client/media-store/types.d.ts +1 -2
  30. package/dist/types-ts4.5/index.d.ts +1 -1
  31. package/dist/types-ts4.5/models/media.d.ts +0 -7
  32. package/dist/types-ts4.5/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
  33. package/dist/types-ts4.5/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
  34. package/dist/types-ts4.5/test-helpers/MockedMediaApi/index.d.ts +3 -0
  35. package/dist/types-ts4.5/test-helpers/index.d.ts +2 -0
  36. package/package.json +3 -3
  37. package/tmp/api-report-tmp.d.ts +0 -1199
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "copy", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _helpers.copy;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "createEmptyFileItem", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _helpers.createEmptyFileItem;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "createErrorFileState", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _helpers.createErrorFileState;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "createFileState", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _helpers.createFileState;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "createMockedMediaApi", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _MockedMediaApi.createMockedMediaApi;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "createProcessingFileItem", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _helpers.createProcessingFileItem;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "createUploadingFileState", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _helpers.createUploadingFileState;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "getIdentifier", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _helpers.getIdentifier;
52
+ }
53
+ });
54
+ var _MockedMediaApi = require("./MockedMediaApi");
55
+ var _helpers = require("./helpers");
@@ -64,6 +64,42 @@ Object.defineProperty(exports, "collectionNames", {
64
64
  return _collectionNames.collectionNames;
65
65
  }
66
66
  });
67
+ Object.defineProperty(exports, "copy", {
68
+ enumerable: true,
69
+ get: function get() {
70
+ return _MockedMediaApi.copy;
71
+ }
72
+ });
73
+ Object.defineProperty(exports, "createEmptyFileItem", {
74
+ enumerable: true,
75
+ get: function get() {
76
+ return _MockedMediaApi.createEmptyFileItem;
77
+ }
78
+ });
79
+ Object.defineProperty(exports, "createErrorFileState", {
80
+ enumerable: true,
81
+ get: function get() {
82
+ return _MockedMediaApi.createErrorFileState;
83
+ }
84
+ });
85
+ Object.defineProperty(exports, "createFileState", {
86
+ enumerable: true,
87
+ get: function get() {
88
+ return _MockedMediaApi.createFileState;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, "createMockedMediaApi", {
92
+ enumerable: true,
93
+ get: function get() {
94
+ return _MockedMediaApi.createMockedMediaApi;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, "createProcessingFileItem", {
98
+ enumerable: true,
99
+ get: function get() {
100
+ return _MockedMediaApi.createProcessingFileItem;
101
+ }
102
+ });
67
103
  Object.defineProperty(exports, "createStorybookMediaClient", {
68
104
  enumerable: true,
69
105
  get: function get() {
@@ -88,6 +124,12 @@ Object.defineProperty(exports, "createUploadMediaClientConfig", {
88
124
  return _mediaClientProvider.createUploadMediaClientConfig;
89
125
  }
90
126
  });
127
+ Object.defineProperty(exports, "createUploadingFileState", {
128
+ enumerable: true,
129
+ get: function get() {
130
+ return _MockedMediaApi.createUploadingFileState;
131
+ }
132
+ });
91
133
  Object.defineProperty(exports, "defaultBaseUrl", {
92
134
  enumerable: true,
93
135
  get: function get() {
@@ -202,6 +244,12 @@ Object.defineProperty(exports, "genericFileId", {
202
244
  return _exampleMediaItems.genericFileId;
203
245
  }
204
246
  });
247
+ Object.defineProperty(exports, "getIdentifier", {
248
+ enumerable: true,
249
+ get: function get() {
250
+ return _MockedMediaApi.getIdentifier;
251
+ }
252
+ });
205
253
  Object.defineProperty(exports, "gifFileId", {
206
254
  enumerable: true,
207
255
  get: function get() {
@@ -370,4 +418,5 @@ var _collectionNames = require("./collectionNames");
370
418
  var _exampleMediaItems = require("./exampleMediaItems");
371
419
  var _mediaPickerAuthProvider = require("./mediaPickerAuthProvider");
372
420
  var _fakeMediaClient = require("./fakeMediaClient");
421
+ var _MockedMediaApi = require("./MockedMediaApi");
373
422
  var authProviderBaseURL = exports.authProviderBaseURL = 'https://media.dev.atl-paas.net';
@@ -37,29 +37,26 @@ var hashingFunction = /*#__PURE__*/function () {
37
37
  return _ref.apply(this, arguments);
38
38
  };
39
39
  }();
40
- var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName, traceContext) {
40
+ var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName, traceContext) {
41
41
  return /*#__PURE__*/function () {
42
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(chunks) {
43
- var response, results;
42
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(chunk) {
44
43
  return _regenerator.default.wrap(function _callee2$(_context2) {
45
44
  while (1) switch (_context2.prev = _context2.next) {
46
45
  case 0:
47
46
  _context2.t0 = store;
48
- _context2.t1 = hashedChunks(chunks);
49
- _context2.next = 4;
47
+ _context2.t1 = chunk.hash;
48
+ _context2.t2 = chunk.blob;
49
+ _context2.next = 5;
50
50
  return deferredUploadId;
51
- case 4:
52
- _context2.t2 = _context2.sent;
53
- _context2.t3 = collectionName;
54
- _context2.t4 = traceContext;
55
- _context2.next = 9;
56
- return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t2, _context2.t3, _context2.t4);
57
- case 9:
58
- response = _context2.sent;
59
- results = response.data.results;
60
- return _context2.abrupt("return", Object.values(results).map(function (result) {
61
- return result.exists;
62
- }));
51
+ case 5:
52
+ _context2.t3 = _context2.sent;
53
+ _context2.t4 = chunk.partNumber;
54
+ _context2.t5 = collectionName;
55
+ _context2.t6 = traceContext;
56
+ _context2.next = 11;
57
+ return _context2.t0.uploadChunk.call(_context2.t0, _context2.t1, _context2.t2, _context2.t3, _context2.t4, _context2.t5, _context2.t6);
58
+ case 11:
59
+ return _context2.abrupt("return", _context2.sent);
63
60
  case 12:
64
61
  case "end":
65
62
  return _context2.stop();
@@ -71,75 +68,44 @@ var createProbingFunction = function createProbingFunction(store, deferredUpload
71
68
  };
72
69
  }();
73
70
  };
74
- var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName, traceContext) {
71
+ var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
72
+ var offset = 0;
75
73
  return /*#__PURE__*/function () {
76
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(chunk) {
74
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(chunks) {
77
75
  return _regenerator.default.wrap(function _callee3$(_context3) {
78
76
  while (1) switch (_context3.prev = _context3.next) {
79
77
  case 0:
80
78
  _context3.t0 = store;
81
- _context3.t1 = chunk.hash;
82
- _context3.t2 = chunk.blob;
83
- _context3.next = 5;
84
- return deferredUploadId;
85
- case 5:
86
- _context3.t3 = _context3.sent;
87
- _context3.t4 = chunk.partNumber;
88
- _context3.t5 = collectionName;
89
- _context3.t6 = traceContext;
90
- _context3.next = 11;
91
- return _context3.t0.uploadChunk.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4, _context3.t5, _context3.t6);
92
- case 11:
93
- return _context3.abrupt("return", _context3.sent);
94
- case 12:
95
- case "end":
96
- return _context3.stop();
97
- }
98
- }, _callee3);
99
- }));
100
- return function (_x3) {
101
- return _ref3.apply(this, arguments);
102
- };
103
- }();
104
- };
105
- var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
106
- var offset = 0;
107
- return /*#__PURE__*/function () {
108
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(chunks) {
109
- return _regenerator.default.wrap(function _callee4$(_context4) {
110
- while (1) switch (_context4.prev = _context4.next) {
111
- case 0:
112
- _context4.t0 = store;
113
- _context4.next = 3;
79
+ _context3.next = 3;
114
80
  return deferredUploadId;
115
81
  case 3:
116
- _context4.t1 = _context4.sent;
117
- _context4.t2 = {
82
+ _context3.t1 = _context3.sent;
83
+ _context3.t2 = {
118
84
  chunks: hashedChunks(chunks),
119
85
  offset: offset
120
86
  };
121
- _context4.t3 = collection;
122
- _context4.t4 = traceContext;
123
- _context4.next = 9;
124
- return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
87
+ _context3.t3 = collection;
88
+ _context3.t4 = traceContext;
89
+ _context3.next = 9;
90
+ return _context3.t0.appendChunksToUpload.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4);
125
91
  case 9:
126
92
  offset += chunks.length;
127
93
  case 10:
128
94
  case "end":
129
- return _context4.stop();
95
+ return _context3.stop();
130
96
  }
131
- }, _callee4);
97
+ }, _callee3);
132
98
  }));
133
- return function (_x4) {
134
- return _ref4.apply(this, arguments);
99
+ return function (_x3) {
100
+ return _ref3.apply(this, arguments);
135
101
  };
136
102
  }();
137
103
  };
138
104
  var createFileFromUpload = /*#__PURE__*/function () {
139
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
105
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
140
106
  var collection, name, mimeType, id, occurrenceKey, body;
141
- return _regenerator.default.wrap(function _callee5$(_context5) {
142
- while (1) switch (_context5.prev = _context5.next) {
107
+ return _regenerator.default.wrap(function _callee4$(_context4) {
108
+ while (1) switch (_context4.prev = _context4.next) {
143
109
  case 0:
144
110
  collection = file.collection, name = file.name, mimeType = file.mimeType;
145
111
  id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
@@ -155,19 +121,19 @@ var createFileFromUpload = /*#__PURE__*/function () {
155
121
  name: name,
156
122
  mimeType: mimeType
157
123
  };
158
- return _context5.abrupt("return", store.createFileFromUpload(body, {
124
+ return _context4.abrupt("return", store.createFileFromUpload(body, {
159
125
  occurrenceKey: occurrenceKey,
160
126
  collection: collection,
161
127
  replaceFileId: id
162
128
  }, traceContext));
163
129
  case 4:
164
130
  case "end":
165
- return _context5.stop();
131
+ return _context4.stop();
166
132
  }
167
- }, _callee5);
133
+ }, _callee4);
168
134
  }));
169
- return function createFileFromUpload(_x5, _x6, _x7, _x8, _x9) {
170
- return _ref5.apply(this, arguments);
135
+ return function createFileFromUpload(_x4, _x5, _x6, _x7, _x8) {
136
+ return _ref4.apply(this, arguments);
171
137
  };
172
138
  }();
173
139
  var uploadFile = exports.uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks, traceContext) {
@@ -197,11 +163,9 @@ var uploadFile = exports.uploadFile = function uploadFile(file, store, uploadabl
197
163
  var chunkinatorObservable = (0, _chunkinator.chunkinator)(content, {
198
164
  hashingFunction: hashingFunction,
199
165
  hashingConcurrency: 5,
200
- probingBatchSize: 100,
201
166
  chunkSize: chunkSize,
202
167
  uploadingConcurrency: 3,
203
168
  uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
204
- probingFunction: createProbingFunction(store, deferredUploadId, collection, traceContext),
205
169
  processingBatchSize: _constants.PROCESSING_BATCH_SIZE,
206
170
  processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
207
171
  }, {
@@ -100,27 +100,6 @@ export class MediaStore {
100
100
  };
101
101
  await this.request(`/chunk/${etag}`, options);
102
102
  }
103
- probeChunks(chunks, uploadId, collectionName, traceContext) {
104
- const metadata = {
105
- method: 'POST',
106
- endpoint: '/chunk/probe'
107
- };
108
- const options = {
109
- ...metadata,
110
- params: {
111
- uploadId
112
- },
113
- authContext: {
114
- collectionName
115
- },
116
- headers: jsonHeaders,
117
- body: JSON.stringify({
118
- chunks
119
- }),
120
- traceContext
121
- };
122
- return this.request(`/chunk/probe`, options).then(createMapResponseToJson(metadata));
123
- }
124
103
  createFileFromUpload(body, params = {}, traceContext) {
125
104
  const metadata = {
126
105
  method: 'POST',
@@ -0,0 +1,161 @@
1
+ import { getMediaFile, normaliseInput } from './helpers';
2
+ const getMediaApi = ({
3
+ getFileItem
4
+ }) => ({
5
+ // --------------------------------------------------------
6
+ // UPLOAD ENDPOINTS - None is supported
7
+ // --------------------------------------------------------
8
+
9
+ touchFiles: async ({
10
+ descriptors
11
+ }) => {
12
+ throw new Error('500 - MockedMediaApi.touchFiles: method not implemented');
13
+ },
14
+ uploadChunk: async (_etag, _blob, uploadId) => {
15
+ throw new Error('500 - MockedMediaApi.uploadChunk: method not implemented');
16
+ },
17
+ appendChunksToUpload: async () => {
18
+ throw new Error('500 - MockedMediaApi.appendChunksToUpload: method not implemented');
19
+ },
20
+ createFileFromUpload: async ({
21
+ uploadId
22
+ }, {
23
+ collection
24
+ }) => {
25
+ throw new Error('500 - MockedMediaApi.createFileFromUpload: method not implemented');
26
+ },
27
+ // Used by Media Picker as a fallback for conflicted file Ids
28
+ createUpload: async () => {
29
+ throw new Error('500 - MockedMediaApi.createUpload: method not implemented');
30
+ },
31
+ // For File size limits
32
+ getRejectedResponseFromDescriptor: () => {
33
+ throw new Error('500 - MockedMediaApi.getRejectedResponseFromDescriptor: method not implemented');
34
+ },
35
+ // --------------------------------------------------------
36
+ // METADATA ENDPOINTS
37
+ // --------------------------------------------------------
38
+
39
+ getFile: async fileId => {
40
+ const fileItem = getFileItem(fileId);
41
+ if (!fileItem) {
42
+ throw new Error('404 - MockedMediaApi.getFile: file not found');
43
+ }
44
+ return {
45
+ data: getMediaFile(fileItem)
46
+ };
47
+ },
48
+ getItems: async ids => {
49
+ const items = ids.map(id => getFileItem(id)).filter(fileState => !!fileState);
50
+ return {
51
+ data: {
52
+ items
53
+ }
54
+ };
55
+ },
56
+ // TODO
57
+ getImageMetadata: async () => {
58
+ throw new Error('500 - MockedMediaApi.getImageMetadata: method not implemented');
59
+ },
60
+ // --------------------------------------------------------
61
+ // URL ENDPOINTS
62
+ // --------------------------------------------------------
63
+
64
+ // TODO
65
+ getFileImageURL: async () => {
66
+ throw new Error('500 - MockedMediaApi.getFileImageURL: method not implemented');
67
+ },
68
+ // TODO
69
+ getFileImageURLSync: () => {
70
+ throw new Error('500 - MockedMediaApi.getFileImageURLSync: method not implemented');
71
+ },
72
+ getFileBinaryURL: async id => {
73
+ const fileItem = getFileItem(id);
74
+ if (!fileItem) {
75
+ throw new Error('404 - MockedMediaApi.getFileBinaryURL: file not found');
76
+ }
77
+ if (fileItem.details.size === 0) {
78
+ // TODO veryify if this is the correct answer for an uploading file
79
+ throw new Error('404 - MockedMediaApi.getFileBinaryURL: file is empty');
80
+ }
81
+ return `/file/${id}/binary`;
82
+ },
83
+ getArtifactURL: async (artifacts, artifactName) => {
84
+ var _artifacts$artifactNa;
85
+ const artifactUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.url;
86
+ if (!artifactUrl) {
87
+ throw new Error(`404 - MockedMediaApi.getArtifactURL: artifact ${artifactName} not found`);
88
+ }
89
+ return artifactUrl;
90
+ },
91
+ // --------------------------------------------------------
92
+ // BINARY ENDPOINTS
93
+ // --------------------------------------------------------
94
+ getImage: async fileId => {
95
+ const fileItem = getFileItem(fileId);
96
+ if (!fileItem) {
97
+ throw new Error('404 - MockedMediaApi.getImage: file not found');
98
+ }
99
+ if (!fileItem.details.representations.image) {
100
+ throw new Error('404 - MockedMediaApi.getImage: image not found');
101
+ }
102
+
103
+ // Empty Blob. Might have to change for a real one if TLR loads the image
104
+ return new Blob();
105
+ },
106
+ // --------------------------------------------------------
107
+ // OTHER ENDPOINTS
108
+ // --------------------------------------------------------
109
+
110
+ // TODO
111
+ copyFileWithToken: async body => {
112
+ const fileId = body.sourceFile.id;
113
+ const fileItem = getFileItem(fileId);
114
+ if (!fileItem) {
115
+ throw new Error('404 - MockedMediaApi.copyFileWithToken: file not found');
116
+ }
117
+ return {
118
+ data: getMediaFile(fileItem)
119
+ };
120
+ },
121
+ // TODO
122
+ removeCollectionFile: async () => {},
123
+ // --------------------------------------------------------
124
+ // OTHER ENDPOINTS
125
+ // --------------------------------------------------------
126
+ request: async () => new Response(),
127
+ resolveAuth: async () => ({
128
+ asapIssuer: '',
129
+ token: '',
130
+ baseUrl: ''
131
+ }),
132
+ resolveInitialAuth: () => ({
133
+ asapIssuer: '',
134
+ token: '',
135
+ baseUrl: ''
136
+ })
137
+ });
138
+
139
+ /**
140
+ * Mocked Media API
141
+ */
142
+ export const createMockedMediaApi = initialFileItems => {
143
+ const storedFileItems = new Map();
144
+ const getFileItem = fileId => storedFileItems.get(fileId);
145
+ const setFileItems = fileItems => {
146
+ const normalised = normaliseInput(fileItems);
147
+ normalised.forEach(fileItem => storedFileItems.set(fileItem.id, fileItem));
148
+ };
149
+ if (initialFileItems) {
150
+ setFileItems(initialFileItems);
151
+ }
152
+ const mediaApi = getMediaApi({
153
+ setFileItems,
154
+ getFileItem
155
+ });
156
+ return {
157
+ setFileItems,
158
+ getFileItem,
159
+ mediaApi
160
+ };
161
+ };
@@ -0,0 +1,166 @@
1
+ import uuid from 'uuid/v4';
2
+ // --------------------------------------------------------
3
+ // Factory Utils
4
+ // --------------------------------------------------------
5
+ export const normaliseInput = input => !input ? [] : input instanceof Array ? input : [input];
6
+
7
+ // --------------------------------------------------------
8
+ // Utils for the main class
9
+ // --------------------------------------------------------
10
+
11
+ export const getMediaFile = fileItem => ({
12
+ id: fileItem.id,
13
+ ...fileItem.details
14
+ });
15
+
16
+ // --------------------------------------------------------
17
+ // Utils for creating file descriptors for tests
18
+ // --------------------------------------------------------
19
+
20
+ export const createEmptyFileItem = (id, collection) => {
21
+ const emptyFileItem = {
22
+ type: 'file',
23
+ id,
24
+ details: {
25
+ mediaType: 'unknown',
26
+ mimeType: 'binary/octet-stream',
27
+ name: '',
28
+ size: 0,
29
+ processingStatus: 'pending',
30
+ artifacts: {},
31
+ representations: {},
32
+ createdAt: 1699488941974
33
+ }
34
+ };
35
+ if (collection) {
36
+ emptyFileItem.collection = collection;
37
+ }
38
+ return emptyFileItem;
39
+ };
40
+
41
+ /**
42
+ * Simulates the processing of the file by updating the processing status of the artifacts by a percentage
43
+ * Percent must be between 0 and 1
44
+ */
45
+ export const createProcessingFileItem = (fileItem, percent) => {
46
+ if (percent < 0 || percent > 1) {
47
+ throw new Error('Error createProcessingFileItem: percent must be between 0 and 1');
48
+ }
49
+
50
+ /**
51
+ * This behaviour has to be confirmed
52
+ * Artifacts show up immediately after processed or they have a
53
+ * "processing time"?
54
+ */
55
+
56
+ if (percent === 1) {
57
+ return fileItem;
58
+ }
59
+
60
+ // No artifacts for 0% processing
61
+ if (percent === 0) {
62
+ return {
63
+ ...fileItem,
64
+ details: {
65
+ ...fileItem.details,
66
+ processingStatus: 'pending',
67
+ artifacts: {},
68
+ // The preview will only be ready at 100% -> TODO verify against backend
69
+ representations: {}
70
+ }
71
+ };
72
+ }
73
+ const artifactsKeys = Object.keys(fileItem.details.artifacts);
74
+ const artifactsEntries = Object.entries({
75
+ ...fileItem.details.artifacts // Spreading to make TS happy
76
+ });
77
+
78
+ // Get a % of the total artifacts to be set as processed
79
+ const processedArtifactKeys = artifactsKeys.slice(0, Math.ceil(artifactsKeys.length * percent));
80
+ const processedArtifactEntries = artifactsEntries.map(([key, artifact]) => [key, {
81
+ ...artifact,
82
+ processingStatus: processedArtifactKeys.includes(key) ? 'succeeded' : 'pending'
83
+ }]);
84
+ const artifactsProcessingPercent = Object.fromEntries(processedArtifactEntries);
85
+ return {
86
+ ...fileItem,
87
+ details: {
88
+ ...fileItem.details,
89
+ processingStatus: 'pending',
90
+ artifacts: artifactsProcessingPercent,
91
+ // The preview will only be ready at 100% -> TODO verify against backend
92
+ representations: {}
93
+ }
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Makes a copy of the provided file item with a random file id
99
+ * */
100
+ export const copy = fileItem => JSON.parse(JSON.stringify(fileItem).replace(new RegExp(fileItem.id, 'g'), uuid()));
101
+ /**
102
+ * Extracts the file identifier from the provided file item
103
+ */
104
+ export const getIdentifier = fileItem => ({
105
+ mediaItemType: 'file',
106
+ id: fileItem.id,
107
+ collectionName: fileItem.collection
108
+ });
109
+ export const createFileState = ({
110
+ id,
111
+ details: {
112
+ name,
113
+ size,
114
+ mediaType,
115
+ mimeType,
116
+ createdAt,
117
+ processingStatus,
118
+ artifacts,
119
+ representations
120
+ }
121
+ }) => ({
122
+ status: processingStatus === 'succeeded' ? 'processed' : 'processing',
123
+ id,
124
+ name,
125
+ size,
126
+ mediaType,
127
+ mimeType,
128
+ createdAt,
129
+ artifacts,
130
+ representations
131
+ });
132
+ export const createUploadingFileState = ({
133
+ id,
134
+ details: {
135
+ name,
136
+ size,
137
+ mediaType,
138
+ mimeType,
139
+ createdAt
140
+ }
141
+ }, progress) => ({
142
+ status: 'uploading',
143
+ progress,
144
+ id,
145
+ name,
146
+ size,
147
+ mediaType,
148
+ mimeType,
149
+ createdAt,
150
+ preview: {
151
+ value: new Blob(['some-content'], {
152
+ type: mimeType
153
+ })
154
+ }
155
+ });
156
+ export const createErrorFileState = ({
157
+ id
158
+ }) => ({
159
+ status: 'error',
160
+ id,
161
+ reason: 'a random error',
162
+ message: 'a random error message',
163
+ details: {
164
+ some: 'mocked error detail'
165
+ }
166
+ });
@@ -0,0 +1,2 @@
1
+ export { createMockedMediaApi } from './MockedMediaApi';
2
+ export { copy, getIdentifier, createEmptyFileItem, createUploadingFileState, createErrorFileState, createFileState, createProcessingFileItem } from './helpers';
@@ -4,4 +4,5 @@ export { collectionNames, defaultCollectionName, defaultMediaPickerCollectionNam
4
4
  export { animatedFileId, archiveFileId, atlassianLogoUrl, audioFileDetails, audioFileId, audioNoCoverFileId, bigDocFileId, docFileDetails, docFileId, emptyImageFileId, errorFileId, externalImageIdentifier, externalSmallImageIdentifier, externaBrokenlIdentifier, genericDataURI, genericFileDetails, genericFileId, gifFileId, imageFileDetails, imageFileId, largeImageFileId, largePdfFileId, noMetadataFileId, passwordProtectedPdfFileId, smallImageFileId, unknownFileDetails, unknownFileId, verticalImageFileId, videoFileDetails, videoFileId, videoHorizontalFileId, videoLargeFileId, videoProcessingFailedId, videoSquareFileId, wideImageFileId, zipFileId, zipFileWithNestedFolderId, zipItemLargeInnerFileId, zipItemMultipleFoldersAtRootId, zipJiraArchiveFileId, zipEncryptedFileId, codeFileId, emailFileId, emailUnsupportedFileId, vrVideoDetails } from './exampleMediaItems';
5
5
  export const authProviderBaseURL = 'https://media.dev.atl-paas.net';
6
6
  export { mediaPickerAuthProvider, defaultMediaPickerAuthProvider } from './mediaPickerAuthProvider';
7
- export { fakeMediaClient } from './fakeMediaClient';
7
+ export { fakeMediaClient } from './fakeMediaClient';
8
+ export { createMockedMediaApi, copy, getIdentifier, createProcessingFileItem, createEmptyFileItem, createUploadingFileState, createFileState, createErrorFileState } from './MockedMediaApi';