@atlaskit/media-client 23.1.3 → 24.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 (119) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/client/file-fetcher/index.js +112 -36
  3. package/dist/cjs/client/media-client.js +18 -6
  4. package/dist/cjs/client/media-store/index.js +3 -4
  5. package/dist/cjs/client/mobile-upload.js +38 -2
  6. package/dist/cjs/index.js +7 -0
  7. package/dist/cjs/models/file-state.js +2 -2
  8. package/dist/cjs/test-helpers/_numbers.js +9 -0
  9. package/dist/cjs/test-helpers/authProvider.js +71 -0
  10. package/dist/cjs/test-helpers/collectionNames.js +16 -0
  11. package/dist/cjs/test-helpers/exampleMediaItems.js +317 -0
  12. package/dist/cjs/test-helpers/fakeMediaClient.js +77 -0
  13. package/dist/cjs/test-helpers/index.js +374 -0
  14. package/dist/cjs/test-helpers/mediaClientProvider.js +60 -0
  15. package/dist/cjs/test-helpers/mediaPickerAuthProvider.js +95 -0
  16. package/dist/cjs/utils/createFileDataLoader.js +2 -2
  17. package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +2 -2
  18. package/dist/cjs/utils/polling/index.js +2 -2
  19. package/dist/cjs/utils/request/helpers.js +2 -2
  20. package/dist/cjs/utils/url.js +2 -2
  21. package/dist/cjs/utils/with-media-client-hoc.js +8 -16
  22. package/dist/es2019/client/file-fetcher/index.js +101 -28
  23. package/dist/es2019/client/media-client.js +15 -7
  24. package/dist/es2019/client/media-store/index.js +1 -2
  25. package/dist/es2019/client/mobile-upload.js +33 -2
  26. package/dist/es2019/index.js +1 -0
  27. package/dist/es2019/test-helpers/_numbers.js +3 -0
  28. package/dist/es2019/test-helpers/authProvider.js +34 -0
  29. package/dist/es2019/test-helpers/collectionNames.js +5 -0
  30. package/dist/es2019/test-helpers/exampleMediaItems.js +268 -0
  31. package/dist/es2019/test-helpers/fakeMediaClient.js +63 -0
  32. package/dist/es2019/test-helpers/index.js +7 -0
  33. package/dist/es2019/test-helpers/mediaClientProvider.js +42 -0
  34. package/dist/es2019/test-helpers/mediaPickerAuthProvider.js +56 -0
  35. package/dist/es2019/utils/with-media-client-hoc.js +8 -16
  36. package/dist/esm/client/file-fetcher/index.js +108 -32
  37. package/dist/esm/client/media-client.js +19 -7
  38. package/dist/esm/client/media-store/index.js +3 -4
  39. package/dist/esm/client/mobile-upload.js +38 -2
  40. package/dist/esm/index.js +1 -0
  41. package/dist/esm/models/file-state.js +2 -2
  42. package/dist/esm/test-helpers/_numbers.js +3 -0
  43. package/dist/esm/test-helpers/authProvider.js +63 -0
  44. package/dist/esm/test-helpers/collectionNames.js +5 -0
  45. package/dist/esm/test-helpers/exampleMediaItems.js +268 -0
  46. package/dist/esm/test-helpers/fakeMediaClient.js +69 -0
  47. package/dist/esm/test-helpers/index.js +7 -0
  48. package/dist/esm/test-helpers/mediaClientProvider.js +48 -0
  49. package/dist/esm/test-helpers/mediaPickerAuthProvider.js +85 -0
  50. package/dist/esm/utils/createFileDataLoader.js +2 -2
  51. package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +2 -2
  52. package/dist/esm/utils/polling/index.js +2 -2
  53. package/dist/esm/utils/request/helpers.js +2 -2
  54. package/dist/esm/utils/url.js +2 -2
  55. package/dist/esm/utils/with-media-client-hoc.js +8 -16
  56. package/dist/types/client/events.d.ts +1 -1
  57. package/dist/types/client/file-fetcher/index.d.ts +10 -6
  58. package/dist/types/client/media-client.d.ts +10 -5
  59. package/dist/types/client/media-store/index.d.ts +3 -4
  60. package/dist/types/client/mobile-upload.d.ts +6 -2
  61. package/dist/types/file-streams-cache.d.ts +1 -1
  62. package/dist/types/index.d.ts +4 -2
  63. package/dist/types/models/artifacts.d.ts +1 -11
  64. package/dist/types/models/file-state.d.ts +4 -73
  65. package/dist/types/models/media.d.ts +1 -1
  66. package/dist/types/models/mobile-upload.d.ts +1 -1
  67. package/dist/types/test-helpers/_numbers.d.ts +1 -0
  68. package/dist/types/test-helpers/authProvider.d.ts +6 -0
  69. package/dist/types/test-helpers/collectionNames.d.ts +5 -0
  70. package/dist/types/test-helpers/exampleMediaItems.d.ts +53 -0
  71. package/dist/types/test-helpers/fakeMediaClient.d.ts +4 -0
  72. package/dist/types/test-helpers/index.d.ts +7 -0
  73. package/dist/types/test-helpers/mediaClientProvider.d.ts +23 -0
  74. package/dist/types/test-helpers/mediaPickerAuthProvider.d.ts +5 -0
  75. package/dist/types/utils/createMediaSubject.d.ts +1 -1
  76. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +1 -1
  77. package/dist/types/utils/mediaSubscribable/toPromise.d.ts +1 -1
  78. package/dist/types/utils/mediaSubscribable/types.d.ts +1 -1
  79. package/dist/types/utils/mobileUpload/helpers.d.ts +1 -1
  80. package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +1 -1
  81. package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +1 -1
  82. package/dist/types/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
  83. package/dist/types/utils/shouldFetchRemoteFileStates.d.ts +1 -1
  84. package/dist/types/utils/with-media-client-hoc.d.ts +2 -3
  85. package/dist/types-ts4.5/client/events.d.ts +1 -1
  86. package/dist/types-ts4.5/client/file-fetcher/index.d.ts +10 -6
  87. package/dist/types-ts4.5/client/media-client.d.ts +10 -5
  88. package/dist/types-ts4.5/client/media-store/index.d.ts +3 -4
  89. package/dist/types-ts4.5/client/mobile-upload.d.ts +6 -2
  90. package/dist/types-ts4.5/file-streams-cache.d.ts +1 -1
  91. package/dist/types-ts4.5/index.d.ts +4 -2
  92. package/dist/types-ts4.5/models/artifacts.d.ts +1 -11
  93. package/dist/types-ts4.5/models/file-state.d.ts +4 -73
  94. package/dist/types-ts4.5/models/media.d.ts +1 -1
  95. package/dist/types-ts4.5/models/mobile-upload.d.ts +1 -1
  96. package/dist/types-ts4.5/test-helpers/_numbers.d.ts +1 -0
  97. package/dist/types-ts4.5/test-helpers/authProvider.d.ts +6 -0
  98. package/dist/types-ts4.5/test-helpers/collectionNames.d.ts +5 -0
  99. package/dist/types-ts4.5/test-helpers/exampleMediaItems.d.ts +53 -0
  100. package/dist/types-ts4.5/test-helpers/fakeMediaClient.d.ts +4 -0
  101. package/dist/types-ts4.5/test-helpers/index.d.ts +7 -0
  102. package/dist/types-ts4.5/test-helpers/mediaClientProvider.d.ts +23 -0
  103. package/dist/types-ts4.5/test-helpers/mediaPickerAuthProvider.d.ts +5 -0
  104. package/dist/types-ts4.5/utils/createMediaSubject.d.ts +1 -1
  105. package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +1 -1
  106. package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +1 -1
  107. package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +1 -1
  108. package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +1 -1
  109. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +1 -1
  110. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +1 -1
  111. package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
  112. package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +1 -1
  113. package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +2 -3
  114. package/package.json +13 -4
  115. package/report.api.md +52 -162
  116. package/tmp/api-report-tmp.d.ts +51 -154
  117. package/dist/cjs/version.json +0 -5
  118. package/dist/es2019/version.json +0 -5
  119. package/dist/esm/version.json +0 -5
@@ -7,7 +7,7 @@ import uuid from 'uuid/v4';
7
7
  import 'setimmediate';
8
8
  import { authToOwner } from '@atlaskit/media-core';
9
9
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
10
- import { MediaStore } from '../media-store';
10
+ import { MediaStore as MediaApi } from '../media-store';
11
11
  import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
12
12
  import { FileFetcherError } from './error';
13
13
  import { uploadFile } from '../../uploader';
@@ -26,9 +26,29 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
26
26
  import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileStates';
27
27
  import { PollingFunction } from '../../utils/polling';
28
28
  import { isEmptyFile } from '../../utils/detectEmptyFile';
29
+ import { mediaStore } from '@atlaskit/media-state';
29
30
  export { isFileFetcherError, FileFetcherError } from './error';
30
31
  export class FileFetcherImpl {
31
- constructor(mediaStore) {
32
+ constructor(mediaApi, store = mediaStore) {
33
+ _defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
34
+ status: 'error',
35
+ id,
36
+ reason: error,
37
+ occurrenceKey,
38
+ message: error
39
+ } : {
40
+ status: 'error',
41
+ id,
42
+ reason: error === null || error === void 0 ? void 0 : error.reason,
43
+ details: error === null || error === void 0 ? void 0 : error.attributes,
44
+ occurrenceKey,
45
+ message: error === null || error === void 0 ? void 0 : error.message
46
+ });
47
+ _defineProperty(this, "setFileState", (id, fileState) => {
48
+ this.store.setState(state => {
49
+ state.files[id] = fileState;
50
+ });
51
+ });
32
52
  // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
33
53
  _defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
34
54
  const subject = createMediaSubject();
@@ -105,8 +125,9 @@ export class FileFetcherImpl {
105
125
  preview
106
126
  };
107
127
  });
108
- this.mediaStore = mediaStore;
109
- this.dataloader = createFileDataloader(mediaStore);
128
+ this.mediaApi = mediaApi;
129
+ this.store = store;
130
+ this.dataloader = createFileDataloader(mediaApi);
110
131
  }
111
132
  getFileState(id, options = {}) {
112
133
  const {
@@ -115,25 +136,47 @@ export class FileFetcherImpl {
115
136
  } = options;
116
137
  if (!isValidId(id)) {
117
138
  const subject = createMediaSubject();
118
- subject.error(new FileFetcherError('invalidFileId', id, {
139
+ const err = new FileFetcherError('invalidFileId', id, {
119
140
  collectionName,
120
141
  occurrenceKey
121
- }));
142
+ });
143
+ const errorFileState = {
144
+ status: 'error',
145
+ id,
146
+ reason: err === null || err === void 0 ? void 0 : err.reason,
147
+ message: err === null || err === void 0 ? void 0 : err.message,
148
+ occurrenceKey,
149
+ details: err === null || err === void 0 ? void 0 : err.attributes
150
+ };
151
+ subject.error(err);
152
+ this.setFileState(id, errorFileState);
122
153
  return fromObservable(subject);
123
154
  }
124
- return fromObservable(getFileStreamsCache().getOrInsert(id, () => this.createDownloadFileStream(id, collectionName)));
155
+ return fromObservable(getFileStreamsCache().getOrInsert(id, () => {
156
+ const subject = this.createDownloadFileStream(id, collectionName);
157
+ subject.subscribe({
158
+ next: fileState => {
159
+ this.setFileState(id, fileState);
160
+ },
161
+ error: err => {
162
+ const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
163
+ this.setFileState(id, errorFileState);
164
+ }
165
+ });
166
+ return subject;
167
+ }));
125
168
  }
126
169
  getCurrentState(id, options) {
127
170
  return toPromise(this.getFileState(id, options));
128
171
  }
129
172
  getArtifactURL(artifacts, artifactName, collectionName) {
130
- return this.mediaStore.getArtifactURL(artifacts, artifactName, collectionName);
173
+ return this.mediaApi.getArtifactURL(artifacts, artifactName, collectionName);
131
174
  }
132
175
  getFileBinaryURL(id, collectionName) {
133
- return this.mediaStore.getFileBinaryURL(id, collectionName);
176
+ return this.mediaApi.getFileBinaryURL(id, collectionName);
134
177
  }
135
178
  touchFiles(descriptors, collection, traceContext) {
136
- return this.mediaStore.touchFiles({
179
+ return this.mediaApi.touchFiles({
137
180
  descriptors
138
181
  }, {
139
182
  collection
@@ -189,6 +232,7 @@ export class FileFetcherImpl {
189
232
  subject.next(fileState);
190
233
  // we save it into the cache as soon as possible, in case someone subscribes
191
234
  getFileStreamsCache().set(id, subject);
235
+ this.setFileState(id, fileState);
192
236
  return new Promise(async (resolve, reject) => {
193
237
  const blob = await deferredBlob;
194
238
  if (!blob) {
@@ -240,15 +284,19 @@ export class FileFetcherImpl {
240
284
  const subject = createMediaSubject();
241
285
  getFileStreamsCache().set(id, subject);
242
286
  const onProgress = progress => {
243
- subject.next({
287
+ const fileState = {
244
288
  status: 'uploading',
245
289
  ...stateBase,
246
290
  progress
247
- });
291
+ };
292
+ subject.next(fileState);
293
+ this.setFileState(id, fileState);
248
294
  };
249
295
  let processingSubscription = new Subscription();
250
296
  const onUploadFinish = error => {
251
297
  if (error) {
298
+ const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
299
+ this.setFileState(id, errorFileState);
252
300
  return subject.error(error);
253
301
  }
254
302
  processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
@@ -256,11 +304,22 @@ export class FileFetcherImpl {
256
304
  ...stateBase,
257
305
  ...remoteFileState,
258
306
  ...overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType)
259
- }))).subscribe(subject);
307
+ }))).subscribe({
308
+ next: fileState => {
309
+ subject.next(fileState);
310
+ this.setFileState(id, fileState);
311
+ },
312
+ error: err => {
313
+ const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
314
+ subject.error(err);
315
+ this.setFileState(id, errorFileState);
316
+ },
317
+ complete: subject.complete
318
+ });
260
319
  };
261
320
  const {
262
321
  cancel
263
- } = uploadFile(file, this.mediaStore, upfrontId, {
322
+ } = uploadFile(file, this.mediaApi, upfrontId, {
264
323
  onUploadFinish,
265
324
  onProgress
266
325
  }, traceContext);
@@ -276,10 +335,8 @@ export class FileFetcherImpl {
276
335
  setTimeout(onProgress, 0, 0);
277
336
  return fromObservable(subject);
278
337
  }
279
-
280
- // TODO: ----- ADD TICKET
281
338
  async downloadBinary(id, name = 'download', collectionName) {
282
- const url = await this.mediaStore.getFileBinaryURL(id, collectionName);
339
+ const url = await this.mediaApi.getFileBinaryURL(id, collectionName);
283
340
  downloadUrl(url, {
284
341
  name
285
342
  });
@@ -305,7 +362,7 @@ export class FileFetcherImpl {
305
362
  preview,
306
363
  mimeType
307
364
  } = options;
308
- const mediaStore = destination.mediaStore || new MediaStore({
365
+ const mediaStore = destination.mediaStore || new MediaApi({
309
366
  authProvider: destinationAuthProvider
310
367
  });
311
368
  const owner = authToOwner(await authProvider({
@@ -359,25 +416,37 @@ export class FileFetcherImpl {
359
416
  // mimeType should always be returned by "copyFileWithToken"
360
417
  // but in case it's not, we don't want to penalize "copyFile"
361
418
  copiedMimeType && (await shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview))) {
362
- subject.next({
419
+ const fileState = {
363
420
  ...copiedFileState,
364
421
  ...overrideMediaTypeIfUnknown(copiedFileState, mediaType),
365
422
  ...previewOverride
366
- });
423
+ };
424
+ subject.next(fileState);
425
+ this.setFileState(copiedId, fileState);
367
426
  processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
368
- next: remoteFileState => subject.next({
369
- ...remoteFileState,
370
- ...overrideMediaTypeIfUnknown(remoteFileState, mediaType),
371
- ...(!isErrorFileState(remoteFileState) && previewOverride)
372
- }),
373
- error: err => subject.error(err),
427
+ next: remoteFileState => {
428
+ const fileState = {
429
+ ...remoteFileState,
430
+ ...overrideMediaTypeIfUnknown(remoteFileState, mediaType),
431
+ ...(!isErrorFileState(remoteFileState) && previewOverride)
432
+ };
433
+ this.setFileState(copiedId, fileState);
434
+ return subject.next(fileState);
435
+ },
436
+ error: err => {
437
+ const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
438
+ this.setFileState(copiedId, errorFileState);
439
+ return subject.error(err);
440
+ },
374
441
  complete: () => subject.complete()
375
442
  });
376
443
  } else if (!isProcessingFileState(copiedFileState)) {
377
- subject.next({
444
+ const fileState = {
378
445
  ...copiedFileState,
379
446
  ...(!isErrorFileState(copiedFileState) && previewOverride)
380
- });
447
+ };
448
+ subject.next(fileState);
449
+ this.setFileState(copiedId, fileState);
381
450
  }
382
451
  if (!cache.has(copiedId)) {
383
452
  getFileStreamsCache().set(copiedId, subject);
@@ -389,12 +458,16 @@ export class FileFetcherImpl {
389
458
  }
390
459
  if (replaceFileId) {
391
460
  const fileCache = cache.get(replaceFileId);
461
+ const replaceFileState = this.store.getState().files[replaceFileId];
392
462
  if (fileCache) {
393
463
  fileCache.error(error);
394
464
  } else {
395
465
  // Create a new subject with the error state for new subscriptions
396
466
  cache.set(id, createMediaSubject(error));
397
467
  }
468
+ const key = replaceFileState ? replaceFileId : id;
469
+ const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
470
+ this.setFileState(key, errorFileState);
398
471
  }
399
472
  throw error;
400
473
  }
@@ -1,24 +1,32 @@
1
1
  import { EventEmitter2 } from 'eventemitter2';
2
- import { MediaStore } from './media-store';
2
+ import { MediaStore as MediaApi } from './media-store';
3
3
  import { FileFetcherImpl } from './file-fetcher';
4
4
  import { StargateClient } from './stargate-client';
5
+ import { mediaStore } from '@atlaskit/media-state';
5
6
  export class MediaClient {
6
7
  // mobile upload is lazily loaded
7
8
 
8
9
  // Deprecated value introduced for backward compatibility with Context
9
10
 
10
- constructor(mediaClientConfig, featureFlags) {
11
+ constructor(mediaClientConfig, store = mediaStore, mediaApi) {
11
12
  this.mediaClientConfig = mediaClientConfig;
12
- this.featureFlags = featureFlags;
13
- this.mediaStore = new MediaStore({
13
+ this.store = store;
14
+ this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
14
15
  authProvider: mediaClientConfig.authProvider,
15
16
  initialAuth: mediaClientConfig.initialAuth
16
- }, featureFlags);
17
+ });
17
18
  this.config = mediaClientConfig;
18
- this.file = new FileFetcherImpl(this.mediaStore);
19
+ this.file = new FileFetcherImpl(this.mediaStore, this.store);
19
20
  this.eventEmitter = new EventEmitter2();
20
21
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
21
22
  }
23
+
24
+ /**
25
+ * @internal
26
+ */
27
+ __DO_NOT_USE__getMediaStore() {
28
+ return this.store;
29
+ }
22
30
  getImage(id, params, controller, fetchMaxRes, traceContext) {
23
31
  return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
24
32
  }
@@ -36,7 +44,7 @@ export class MediaClient {
36
44
  return this.mobileUpload;
37
45
  }
38
46
  const module = await import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
39
- this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
47
+ this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
40
48
  return this.mobileUpload;
41
49
  }
42
50
  async removeFileFromCollection(id, collectionName, occurrenceKey, traceContext) {
@@ -28,11 +28,10 @@ const jsonHeaders = {
28
28
  'Content-Type': 'application/json'
29
29
  };
30
30
  export class MediaStore {
31
- constructor(config, featureFlags) {
31
+ constructor(config) {
32
32
  _defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
33
33
  _defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
34
34
  this.config = config;
35
- this.featureFlags = featureFlags;
36
35
  }
37
36
  async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
38
37
  const metadata = {
@@ -1,10 +1,32 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
3
+ import { mediaStore } from '@atlaskit/media-state';
2
4
  import { getFileStreamsCache } from '../file-streams-cache';
3
5
  import { createFileDataloader } from '../utils/createFileDataLoader';
4
6
  import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
5
7
  export class MobileUploadImpl {
6
- constructor(mediaStore) {
7
- this.dataloader = createFileDataloader(mediaStore);
8
+ constructor(mediaApi, store = mediaStore) {
9
+ _defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
10
+ status: 'error',
11
+ id,
12
+ reason: error,
13
+ occurrenceKey,
14
+ message: error
15
+ } : {
16
+ status: 'error',
17
+ id,
18
+ reason: error === null || error === void 0 ? void 0 : error.reason,
19
+ details: error === null || error === void 0 ? void 0 : error.attributes,
20
+ occurrenceKey,
21
+ message: error === null || error === void 0 ? void 0 : error.message
22
+ });
23
+ _defineProperty(this, "setFileState", (id, fileState) => {
24
+ this.store.setState(state => {
25
+ state.files[id] = fileState;
26
+ });
27
+ });
28
+ this.store = store;
29
+ this.dataloader = createFileDataloader(mediaApi);
8
30
  this.servicesCache = createServicesCache();
9
31
  }
10
32
  notifyUploadStart(event) {
@@ -33,6 +55,15 @@ export class MobileUploadImpl {
33
55
  };
34
56
  const service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
35
57
  const subject = createMobileFileStateSubject(service);
58
+ subject.subscribe({
59
+ next: fileState => {
60
+ this.setFileState(fileId, fileState);
61
+ },
62
+ error: err => {
63
+ const errorFileState = this.getErrorFileState(err, fileId, occurrenceKey);
64
+ this.setFileState(fileId, errorFileState);
65
+ }
66
+ });
36
67
  this.servicesCache.set(fileId, service);
37
68
  getFileStreamsCache().set(fileId, subject);
38
69
  }
@@ -24,6 +24,7 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
24
24
  export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
25
25
  export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
26
26
  export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
27
+ export { getFileStreamsCache } from './file-streams-cache';
27
28
 
28
29
  // TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
29
30
 
@@ -0,0 +1,3 @@
1
+ export function numbers(count) {
2
+ return Array.from(Array(count).keys());
3
+ }
@@ -0,0 +1,34 @@
1
+ import { defaultCollectionName } from './collectionNames';
2
+ const cachedAuths = {};
3
+ const authProviderBaseURL = 'https://media-playground.dev.atl-paas.net/';
4
+ export class StoryBookAuthProvider {
5
+ static create(isAsapEnvironment, access) {
6
+ const loadTenatAuth = async collectionName => {
7
+ const environment = isAsapEnvironment ? 'asap' : '';
8
+ const headers = new Headers();
9
+ headers.append('Content-Type', 'application/json; charset=utf-8');
10
+ headers.append('Accept', 'text/plain, */*; q=0.01');
11
+ const config = {
12
+ method: 'POST',
13
+ headers,
14
+ body: access ? JSON.stringify({
15
+ access
16
+ }) : undefined
17
+ };
18
+ const url = `${authProviderBaseURL}/token/tenant?collection=${collectionName}&environment=${environment}`;
19
+ const response = fetch(url, config);
20
+
21
+ // We leverage the fact, that our internal /toke/tenant API returns data in the same format as Auth
22
+ return await (await response).json();
23
+ };
24
+ return authContext => {
25
+ const collectionName = authContext && authContext.collectionName || defaultCollectionName;
26
+ const accessStr = access ? JSON.stringify(access) : '';
27
+ const cacheKey = `${collectionName}-${accessStr}-${isAsapEnvironment}`;
28
+ if (!cachedAuths[cacheKey]) {
29
+ cachedAuths[cacheKey] = loadTenatAuth(collectionName);
30
+ }
31
+ return cachedAuths[cacheKey];
32
+ };
33
+ }
34
+ }
@@ -0,0 +1,5 @@
1
+ export const defaultCollectionName = 'MediaServicesSample';
2
+ export const onlyAnimatedGifsCollectionName = 'only-animated-gifs';
3
+ export const fileCollectionName = `${defaultCollectionName}Files`;
4
+ export const defaultMediaPickerCollectionName = 'mediapicker-test';
5
+ export const collectionNames = [defaultCollectionName, 'MediaServicesSampleAtlaskit', 'MediaServicesSampleHulk', 'MediaServicesSampleFabric', fileCollectionName, onlyAnimatedGifsCollectionName, defaultMediaPickerCollectionName];
@@ -0,0 +1,268 @@
1
+ import { videoURI, videoPreviewURI } from '@atlaskit/media-common/test-helpers';
2
+ import { defaultCollectionName as collectionName, onlyAnimatedGifsCollectionName } from './collectionNames';
3
+ const fileType = 'file';
4
+
5
+ // === FILE ===
6
+
7
+ export const genericFileId = {
8
+ id: '2dfcc12d-04d7-46e7-9fdf-3715ff00ba40',
9
+ mediaItemType: fileType,
10
+ collectionName: collectionName
11
+ };
12
+ export const audioFileId = {
13
+ id: 'a965c8df-1d64-4db8-9de5-16dfa8fd2e12',
14
+ // mp3 audio
15
+ mediaItemType: fileType,
16
+ collectionName: collectionName
17
+ };
18
+ export const audioNoCoverFileId = {
19
+ id: '7a5698bb-919c-4200-8699-6041e7913b11',
20
+ // mp3 audio
21
+ mediaItemType: fileType,
22
+ collectionName: collectionName
23
+ };
24
+ export const videoFileId = {
25
+ id: '1b01a476-83b4-4f44-8192-f83b2d00913a',
26
+ // mp4 video
27
+ mediaItemType: fileType,
28
+ collectionName: collectionName
29
+ };
30
+ export const videoHorizontalFileId = {
31
+ id: '2afaf845-4385-431f-9a15-3e21520cf896',
32
+ // .mov video
33
+ mediaItemType: fileType,
34
+ collectionName: collectionName
35
+ };
36
+ export const videoLargeFileId = {
37
+ id: '3291050e-6b66-4296-94c6-12088ef6fbad',
38
+ mediaItemType: fileType,
39
+ collectionName: collectionName
40
+ };
41
+ export const videoSquareFileId = {
42
+ id: 'cdff20d6-2c0a-4d0d-b2a9-22cc728a0368',
43
+ mediaItemType: fileType,
44
+ collectionName: collectionName
45
+ };
46
+ export const videoProcessingFailedId = {
47
+ id: 'e558199f-f982-4d23-93eb-313be5998d1b',
48
+ mediaItemType: fileType,
49
+ collectionName: collectionName
50
+ };
51
+ export const imageFileId = {
52
+ id: '5556346b-b081-482b-bc4a-4faca8ecd2de',
53
+ // jpg image
54
+ mediaItemType: fileType,
55
+ collectionName: collectionName
56
+ };
57
+ export const emptyImageFileId = {
58
+ id: 'aa7f7a63-2b1a-4405-b585-62e375a3b40a',
59
+ // jpg image
60
+ mediaItemType: fileType,
61
+ collectionName: collectionName
62
+ };
63
+ export const smallImageFileId = {
64
+ id: 'f251bd05-4b2d-485d-a088-57d112ca7945',
65
+ mediaItemType: fileType,
66
+ collectionName: collectionName
67
+ };
68
+ export const wideImageFileId = {
69
+ id: '3b6621a2-5b72-400e-ad95-447610dbb770',
70
+ mediaItemType: fileType,
71
+ collectionName: collectionName
72
+ };
73
+ export const largeImageFileId = {
74
+ id: '0607a6a8-b2ec-49a7-b6d3-d767cb49e844',
75
+ mediaItemType: fileType,
76
+ collectionName: collectionName
77
+ };
78
+ export const verticalImageFileId = {
79
+ id: 'f9235f5a-d582-4740-8611-ebf3feaf28b6',
80
+ mediaItemType: fileType,
81
+ collectionName: collectionName
82
+ };
83
+ export const docFileId = {
84
+ id: '71cd7e7d-4e86-4b89-a0b4-7f6ffe013c94',
85
+ mediaItemType: fileType,
86
+ collectionName: collectionName
87
+ };
88
+ export const bigDocFileId = {
89
+ id: 'd22f7a80-a661-4518-8b0e-eba02b6dfaca',
90
+ mediaItemType: fileType,
91
+ collectionName: collectionName
92
+ };
93
+ export const largePdfFileId = {
94
+ id: '0a510b7f-4168-44d8-b4d7-f5639ecefa2c',
95
+ mediaItemType: fileType,
96
+ collectionName: collectionName
97
+ };
98
+ export const passwordProtectedPdfFileId = {
99
+ id: 'c0e5bfa5-013d-4cbc-9b87-17d7f63bcc30',
100
+ mediaItemType: fileType,
101
+ collectionName: collectionName
102
+ };
103
+ export const codeFileId = {
104
+ id: '4bc95dd5-a7a2-4cbd-ac46-f9b9f0e0941a',
105
+ mediaItemType: fileType,
106
+ collectionName: collectionName
107
+ };
108
+ export const emailFileId = {
109
+ id: '79bb7327-fa6c-4e6f-8a7a-4ebd3607f481',
110
+ mediaItemType: fileType,
111
+ collectionName: collectionName
112
+ };
113
+ export const emailUnsupportedFileId = {
114
+ id: '3a2ae022-212a-4dca-a7d3-86eb016a0ed2',
115
+ mediaItemType: fileType,
116
+ collectionName: collectionName
117
+ };
118
+ export const archiveFileId = {
119
+ id: '1abbae6b-f507-4b4f-b181-21016bf3b7cc',
120
+ mediaItemType: fileType,
121
+ collectionName: collectionName
122
+ };
123
+ export const zipJiraArchiveFileId = {
124
+ id: 'aa99969c-6f0e-4cdc-8a57-9d38c43b2af8',
125
+ mediaItemType: fileType,
126
+ collectionName: collectionName
127
+ };
128
+ export const zipFileWithNestedFolderId = {
129
+ id: 'd1730520-316c-482a-a8c8-2b34acbea00b',
130
+ mediaItemType: fileType,
131
+ collectionName: collectionName
132
+ };
133
+ export const zipFileId = {
134
+ id: '3822aff2-9297-4ad9-93fd-ab1709f400ad',
135
+ mediaItemType: fileType,
136
+ collectionName: collectionName
137
+ };
138
+ export const zipItemMultipleFoldersAtRootId = {
139
+ id: 'b2c4623b-bd84-4d90-a2ed-61d50b0bd5f4',
140
+ mediaItemType: fileType,
141
+ collectionName: collectionName
142
+ };
143
+ export const zipItemLargeInnerFileId = {
144
+ id: '36b7957c-2d73-4cd5-8541-103daa2619ce',
145
+ mediaItemType: fileType,
146
+ collectionName: collectionName
147
+ };
148
+ export const zipEncryptedFileId = {
149
+ id: 'd1569d0f-936d-46f3-b974-a285696016c0',
150
+ mediaItemType: fileType,
151
+ collectionName: collectionName
152
+ };
153
+ export const unknownFileId = {
154
+ id: 'e0652e68-c596-4800-8a91-1920e6b8a585',
155
+ mediaItemType: fileType,
156
+ collectionName: collectionName
157
+ };
158
+ export const errorFileId = {
159
+ id: 'error-file-id',
160
+ mediaItemType: fileType,
161
+ collectionName: collectionName
162
+ };
163
+ export const gifFileId = {
164
+ id: '26adc5af-3af4-42a8-9c24-62b6ce0f9369',
165
+ mediaItemType: fileType,
166
+ collectionName: collectionName
167
+ };
168
+ export const noMetadataFileId = {
169
+ id: '1adaf6f9-37f6-4171-ab6b-455ec3115381',
170
+ mediaItemType: fileType,
171
+ collectionName: collectionName
172
+ };
173
+ export const animatedFileId = {
174
+ id: 'af637c7a-75c3-4254-b074-d16e6ae2e04b',
175
+ mediaItemType: fileType,
176
+ collectionName: onlyAnimatedGifsCollectionName
177
+ };
178
+ // === EXTERNAL IMAGE ===
179
+
180
+ export const atlassianLogoUrl = 'https://wac-cdn.atlassian.com/assets/img/favicons/atlassian/apple-touch-icon-152x152.png';
181
+ export const externalImageIdentifier = {
182
+ mediaItemType: 'external-image',
183
+ dataURI: atlassianLogoUrl
184
+ };
185
+ export const externalSmallImageIdentifier = {
186
+ mediaItemType: 'external-image',
187
+ dataURI: 'https://aui-cdn.atlassian.com/media/files-icon.png'
188
+ };
189
+ export const externaBrokenlIdentifier = {
190
+ mediaItemType: 'external-image',
191
+ dataURI: 'https://some-uri'
192
+ };
193
+ export const genericFileDetails = {
194
+ id: 'fd4c4672-323a-4b6c-8326-223169e2a13e',
195
+ mediaType: 'image',
196
+ mimeType: 'image/gif',
197
+ name: 'picker-thread-leaking.gif',
198
+ size: 2958464,
199
+ processingStatus: 'succeeded',
200
+ artifacts: {
201
+ 'thumb_320.jpg': {
202
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/thumb_320.jpg/binary',
203
+ processingStatus: 'succeeded'
204
+ },
205
+ 'thumb_large.jpg': {
206
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/thumb_320.jpg/binary',
207
+ processingStatus: 'succeeded'
208
+ },
209
+ 'thumb_120.jpg': {
210
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/thumb_120.jpg/binary',
211
+ processingStatus: 'succeeded'
212
+ },
213
+ 'thumb.jpg': {
214
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/thumb_120.jpg/binary',
215
+ processingStatus: 'succeeded'
216
+ },
217
+ 'meta.json': {
218
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/meta.json/binary',
219
+ processingStatus: 'succeeded'
220
+ },
221
+ 'image.jpg': {
222
+ url: '/file/fd4c4672-323a-4b6c-8326-223169e2a13e/artifact/image.jpg/binary',
223
+ processingStatus: 'succeeded'
224
+ }
225
+ }
226
+ };
227
+ export const imageFileDetails = {
228
+ id: 'some-id',
229
+ mediaType: 'image',
230
+ name: 'image_file.jpg',
231
+ size: 2958464
232
+ };
233
+ export const videoFileDetails = {
234
+ id: 'some-id',
235
+ mediaType: 'video',
236
+ name: 'video_file.mp4',
237
+ size: 29584640
238
+ };
239
+ export const audioFileDetails = {
240
+ id: 'some-id',
241
+ mediaType: 'audio',
242
+ name: 'audio_file.mp3',
243
+ size: 2958464
244
+ };
245
+ export const docFileDetails = {
246
+ id: 'some-id',
247
+ mediaType: 'doc',
248
+ name: 'doc_file.pdf',
249
+ size: 2958464
250
+ };
251
+ export const unknownFileDetails = {
252
+ id: 'some-id',
253
+ mediaType: 'unknown',
254
+ name: 'doc_file.pdf',
255
+ size: 2958464
256
+ };
257
+ export const genericDataURI = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAZABkAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABkAAAAAQAAAGQAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAAKgAwAEAAAAAQAAAAIAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIAAIAAgMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQICAQECAQEBAgICAgICAgICAQICAgICAgICAgL/2wBDAQEBAQEBAQEBAQECAQEBAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgL/3QAEAAH/2gAMAwEAAhEDEQA/AP0U8M2NmPDfh8C0tgBomkgAW8OAPsFvwK/lh7s+5u+/4n//2Q==';
258
+
259
+ // === VR test ids ===
260
+
261
+ export const vrVideoDetails = {
262
+ id: '0c3c64b9-65ad-4592-89d0-f838beebd81e',
263
+ name: 'video.mp4',
264
+ dataUri: videoURI,
265
+ previewDataUri: videoPreviewURI,
266
+ mediaType: 'video',
267
+ mimeType: 'video/mp4'
268
+ };