@atlaskit/media-client 25.0.3 → 25.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/test-helpers/MockedMediaApi/MockedMediaApi.js +449 -0
- package/dist/cjs/test-helpers/MockedMediaApi/helpers.js +184 -0
- package/dist/cjs/test-helpers/MockedMediaApi/index.js +55 -0
- package/dist/cjs/test-helpers/index.js +49 -0
- package/dist/es2019/test-helpers/MockedMediaApi/MockedMediaApi.js +164 -0
- package/dist/es2019/test-helpers/MockedMediaApi/helpers.js +166 -0
- package/dist/es2019/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/es2019/test-helpers/index.js +2 -1
- package/dist/esm/test-helpers/MockedMediaApi/MockedMediaApi.js +442 -0
- package/dist/esm/test-helpers/MockedMediaApi/helpers.js +176 -0
- package/dist/esm/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/esm/test-helpers/index.js +2 -1
- package/dist/types/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types/test-helpers/index.d.ts +2 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types-ts4.5/test-helpers/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -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';
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
probeChunks: async (...args) => {
|
|
15
|
+
throw new Error('500 - MockedMediaApi.probeChunks: method not implemented');
|
|
16
|
+
},
|
|
17
|
+
uploadChunk: async (_etag, _blob, uploadId) => {
|
|
18
|
+
throw new Error('500 - MockedMediaApi.uploadChunk: method not implemented');
|
|
19
|
+
},
|
|
20
|
+
appendChunksToUpload: async () => {
|
|
21
|
+
throw new Error('500 - MockedMediaApi.appendChunksToUpload: method not implemented');
|
|
22
|
+
},
|
|
23
|
+
createFileFromUpload: async ({
|
|
24
|
+
uploadId
|
|
25
|
+
}, {
|
|
26
|
+
collection
|
|
27
|
+
}) => {
|
|
28
|
+
throw new Error('500 - MockedMediaApi.createFileFromUpload: method not implemented');
|
|
29
|
+
},
|
|
30
|
+
// Used by Media Picker as a fallback for conflicted file Ids
|
|
31
|
+
createUpload: async () => {
|
|
32
|
+
throw new Error('500 - MockedMediaApi.createUpload: method not implemented');
|
|
33
|
+
},
|
|
34
|
+
// For File size limits
|
|
35
|
+
getRejectedResponseFromDescriptor: () => {
|
|
36
|
+
throw new Error('500 - MockedMediaApi.getRejectedResponseFromDescriptor: method not implemented');
|
|
37
|
+
},
|
|
38
|
+
// --------------------------------------------------------
|
|
39
|
+
// METADATA ENDPOINTS
|
|
40
|
+
// --------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
getFile: async fileId => {
|
|
43
|
+
const fileItem = getFileItem(fileId);
|
|
44
|
+
if (!fileItem) {
|
|
45
|
+
throw new Error('404 - MockedMediaApi.getFile: file not found');
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
data: getMediaFile(fileItem)
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
getItems: async ids => {
|
|
52
|
+
const items = ids.map(id => getFileItem(id)).filter(fileState => !!fileState);
|
|
53
|
+
return {
|
|
54
|
+
data: {
|
|
55
|
+
items
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
// TODO
|
|
60
|
+
getImageMetadata: async () => {
|
|
61
|
+
throw new Error('500 - MockedMediaApi.getImageMetadata: method not implemented');
|
|
62
|
+
},
|
|
63
|
+
// --------------------------------------------------------
|
|
64
|
+
// URL ENDPOINTS
|
|
65
|
+
// --------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
// TODO
|
|
68
|
+
getFileImageURL: async () => {
|
|
69
|
+
throw new Error('500 - MockedMediaApi.getFileImageURL: method not implemented');
|
|
70
|
+
},
|
|
71
|
+
// TODO
|
|
72
|
+
getFileImageURLSync: () => {
|
|
73
|
+
throw new Error('500 - MockedMediaApi.getFileImageURLSync: method not implemented');
|
|
74
|
+
},
|
|
75
|
+
getFileBinaryURL: async id => {
|
|
76
|
+
const fileItem = getFileItem(id);
|
|
77
|
+
if (!fileItem) {
|
|
78
|
+
throw new Error('404 - MockedMediaApi.getFileBinaryURL: file not found');
|
|
79
|
+
}
|
|
80
|
+
if (fileItem.details.size === 0) {
|
|
81
|
+
// TODO veryify if this is the correct answer for an uploading file
|
|
82
|
+
throw new Error('404 - MockedMediaApi.getFileBinaryURL: file is empty');
|
|
83
|
+
}
|
|
84
|
+
return `/file/${id}/binary`;
|
|
85
|
+
},
|
|
86
|
+
getArtifactURL: async (artifacts, artifactName) => {
|
|
87
|
+
var _artifacts$artifactNa;
|
|
88
|
+
const artifactUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.url;
|
|
89
|
+
if (!artifactUrl) {
|
|
90
|
+
throw new Error(`404 - MockedMediaApi.getArtifactURL: artifact ${artifactName} not found`);
|
|
91
|
+
}
|
|
92
|
+
return artifactUrl;
|
|
93
|
+
},
|
|
94
|
+
// --------------------------------------------------------
|
|
95
|
+
// BINARY ENDPOINTS
|
|
96
|
+
// --------------------------------------------------------
|
|
97
|
+
getImage: async fileId => {
|
|
98
|
+
const fileItem = getFileItem(fileId);
|
|
99
|
+
if (!fileItem) {
|
|
100
|
+
throw new Error('404 - MockedMediaApi.getImage: file not found');
|
|
101
|
+
}
|
|
102
|
+
if (!fileItem.details.representations.image) {
|
|
103
|
+
throw new Error('404 - MockedMediaApi.getImage: image not found');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Empty Blob. Might have to change for a real one if TLR loads the image
|
|
107
|
+
return new Blob();
|
|
108
|
+
},
|
|
109
|
+
// --------------------------------------------------------
|
|
110
|
+
// OTHER ENDPOINTS
|
|
111
|
+
// --------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
// TODO
|
|
114
|
+
copyFileWithToken: async body => {
|
|
115
|
+
const fileId = body.sourceFile.id;
|
|
116
|
+
const fileItem = getFileItem(fileId);
|
|
117
|
+
if (!fileItem) {
|
|
118
|
+
throw new Error('404 - MockedMediaApi.copyFileWithToken: file not found');
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
data: getMediaFile(fileItem)
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
// TODO
|
|
125
|
+
removeCollectionFile: async () => {},
|
|
126
|
+
// --------------------------------------------------------
|
|
127
|
+
// OTHER ENDPOINTS
|
|
128
|
+
// --------------------------------------------------------
|
|
129
|
+
request: async () => new Response(),
|
|
130
|
+
resolveAuth: async () => ({
|
|
131
|
+
asapIssuer: '',
|
|
132
|
+
token: '',
|
|
133
|
+
baseUrl: ''
|
|
134
|
+
}),
|
|
135
|
+
resolveInitialAuth: () => ({
|
|
136
|
+
asapIssuer: '',
|
|
137
|
+
token: '',
|
|
138
|
+
baseUrl: ''
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Mocked Media API
|
|
144
|
+
*/
|
|
145
|
+
export const createMockedMediaApi = initialFileItems => {
|
|
146
|
+
const storedFileItems = new Map();
|
|
147
|
+
const getFileItem = fileId => storedFileItems.get(fileId);
|
|
148
|
+
const setFileItems = fileItems => {
|
|
149
|
+
const normalised = normaliseInput(fileItems);
|
|
150
|
+
normalised.forEach(fileItem => storedFileItems.set(fileItem.id, fileItem));
|
|
151
|
+
};
|
|
152
|
+
if (initialFileItems) {
|
|
153
|
+
setFileItems(initialFileItems);
|
|
154
|
+
}
|
|
155
|
+
const mediaApi = getMediaApi({
|
|
156
|
+
setFileItems,
|
|
157
|
+
getFileItem
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
setFileItems,
|
|
161
|
+
getFileItem,
|
|
162
|
+
mediaApi
|
|
163
|
+
};
|
|
164
|
+
};
|
|
@@ -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
|
+
});
|
|
@@ -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';
|