@atlaskit/media-client 14.1.1 → 14.3.2

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 (96) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/cjs/client/collection-fetcher.js +1 -1
  3. package/dist/cjs/client/file-fetcher/error.js +1 -1
  4. package/dist/cjs/client/file-fetcher/index.js +6 -15
  5. package/dist/cjs/client/media-client.js +50 -1
  6. package/dist/cjs/client/media-store/error.js +1 -1
  7. package/dist/cjs/client/media-store/index.js +1 -1
  8. package/dist/cjs/client/mobile-upload.js +98 -0
  9. package/dist/cjs/constants.js +1 -1
  10. package/dist/cjs/identifier.js +1 -1
  11. package/dist/cjs/index.js +127 -113
  12. package/dist/cjs/models/errors/helpers.js +1 -1
  13. package/dist/cjs/models/errors/index.js +5 -5
  14. package/dist/cjs/models/file-state.js +1 -1
  15. package/dist/cjs/models/media.js +1 -1
  16. package/dist/cjs/models/mobile-upload.js +5 -0
  17. package/dist/cjs/utils/createFileDataLoader.js +2 -1
  18. package/dist/cjs/utils/detectEmptyFile.js +1 -1
  19. package/dist/cjs/utils/hashing/hasherCreator.js +1 -1
  20. package/dist/cjs/utils/imageResizeModeToFileImageMode.js +12 -0
  21. package/dist/cjs/utils/mobileUpload/error.js +67 -0
  22. package/dist/cjs/utils/mobileUpload/helpers.js +110 -0
  23. package/dist/cjs/utils/mobileUpload/index.js +49 -0
  24. package/dist/cjs/utils/mobileUpload/servicesCache.js +12 -0
  25. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +103 -0
  26. package/dist/cjs/utils/mobileUpload/stateMachine/states/error.js +10 -0
  27. package/dist/cjs/utils/mobileUpload/stateMachine/states/processed.js +10 -0
  28. package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +77 -0
  29. package/dist/cjs/utils/mobileUpload/stateMachine/states/processingFailed.js +10 -0
  30. package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +70 -0
  31. package/dist/cjs/utils/mobileUpload/stateMachine/types.js +5 -0
  32. package/dist/cjs/utils/polling/errors.js +1 -1
  33. package/dist/cjs/utils/polling/index.js +6 -7
  34. package/dist/cjs/utils/request/errors.js +1 -1
  35. package/dist/cjs/utils/request/helpers.js +13 -13
  36. package/dist/cjs/utils/request/index.js +5 -5
  37. package/dist/cjs/utils/setTimeoutPromise.js +1 -1
  38. package/dist/cjs/utils/url.js +1 -1
  39. package/dist/cjs/version.json +1 -1
  40. package/dist/es2019/client/file-fetcher/index.js +1 -11
  41. package/dist/es2019/client/media-client.js +15 -1
  42. package/dist/es2019/client/mobile-upload.js +80 -0
  43. package/dist/es2019/index.js +1 -0
  44. package/dist/es2019/models/mobile-upload.js +1 -0
  45. package/dist/es2019/utils/imageResizeModeToFileImageMode.js +1 -0
  46. package/dist/es2019/utils/mobileUpload/error.js +30 -0
  47. package/dist/es2019/utils/mobileUpload/helpers.js +55 -0
  48. package/dist/es2019/utils/mobileUpload/index.js +4 -0
  49. package/dist/es2019/utils/mobileUpload/servicesCache.js +4 -0
  50. package/dist/es2019/utils/mobileUpload/stateMachine/index.js +52 -0
  51. package/dist/es2019/utils/mobileUpload/stateMachine/states/error.js +3 -0
  52. package/dist/es2019/utils/mobileUpload/stateMachine/states/processed.js +3 -0
  53. package/dist/es2019/utils/mobileUpload/stateMachine/states/processing.js +60 -0
  54. package/dist/es2019/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
  55. package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +44 -0
  56. package/dist/es2019/utils/mobileUpload/stateMachine/types.js +1 -0
  57. package/dist/es2019/utils/polling/index.js +5 -5
  58. package/dist/es2019/version.json +1 -1
  59. package/dist/esm/client/file-fetcher/index.js +1 -9
  60. package/dist/esm/client/media-client.js +44 -1
  61. package/dist/esm/client/mobile-upload.js +83 -0
  62. package/dist/esm/index.js +1 -0
  63. package/dist/esm/models/mobile-upload.js +1 -0
  64. package/dist/esm/utils/imageResizeModeToFileImageMode.js +3 -0
  65. package/dist/esm/utils/mobileUpload/error.js +51 -0
  66. package/dist/esm/utils/mobileUpload/helpers.js +86 -0
  67. package/dist/esm/utils/mobileUpload/index.js +4 -0
  68. package/dist/esm/utils/mobileUpload/servicesCache.js +4 -0
  69. package/dist/esm/utils/mobileUpload/stateMachine/index.js +78 -0
  70. package/dist/esm/utils/mobileUpload/stateMachine/states/error.js +3 -0
  71. package/dist/esm/utils/mobileUpload/stateMachine/states/processed.js +3 -0
  72. package/dist/esm/utils/mobileUpload/stateMachine/states/processing.js +68 -0
  73. package/dist/esm/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
  74. package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +58 -0
  75. package/dist/esm/utils/mobileUpload/stateMachine/types.js +1 -0
  76. package/dist/esm/utils/polling/index.js +5 -5
  77. package/dist/esm/version.json +1 -1
  78. package/dist/types/client/media-client.d.ts +3 -0
  79. package/dist/types/client/mobile-upload.d.ts +11 -0
  80. package/dist/types/index.d.ts +4 -2
  81. package/dist/types/models/mobile-upload.d.ts +28 -0
  82. package/dist/types/utils/imageResizeModeToFileImageMode.d.ts +3 -0
  83. package/dist/types/utils/mobileUpload/error.d.ts +29 -0
  84. package/dist/types/utils/mobileUpload/helpers.d.ts +8 -0
  85. package/dist/types/utils/mobileUpload/index.d.ts +5 -0
  86. package/dist/types/utils/mobileUpload/servicesCache.d.ts +4 -0
  87. package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +7 -0
  88. package/dist/types/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
  89. package/dist/types/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
  90. package/dist/types/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
  91. package/dist/types/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
  92. package/dist/types/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
  93. package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +69 -0
  94. package/dist/types/utils/polling/errors.d.ts +1 -1
  95. package/dist/types/utils/polling/index.d.ts +8 -3
  96. package/package.json +7 -6
@@ -4,12 +4,14 @@ import { CollectionFetcher } from './collection-fetcher';
4
4
  import { FileFetcherImpl } from './file-fetcher';
5
5
  import { StargateClient } from './stargate-client';
6
6
  export class MediaClient {
7
+ // mobile upload is lazily loaded
7
8
  // Deprecated value introduced for backward compatibility with Context
8
9
  constructor(mediaClientConfig, featureFlags) {
9
10
  this.mediaClientConfig = mediaClientConfig;
10
11
  this.featureFlags = featureFlags;
11
12
  this.mediaStore = new MediaStore({
12
- authProvider: mediaClientConfig.authProvider
13
+ authProvider: mediaClientConfig.authProvider,
14
+ initialAuth: mediaClientConfig.initialAuth
13
15
  }, featureFlags);
14
16
  this.config = mediaClientConfig;
15
17
  this.collection = new CollectionFetcher(this.mediaStore);
@@ -34,6 +36,18 @@ export class MediaClient {
34
36
  return (await this.mediaStore.getImageMetadata(id, params)).metadata;
35
37
  }
36
38
 
39
+ async mobileUploadPromise() {
40
+ if (this.mobileUpload) {
41
+ return this.mobileUpload;
42
+ }
43
+
44
+ const module = await import(
45
+ /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */
46
+ './mobile-upload');
47
+ this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
48
+ return this.mobileUpload;
49
+ }
50
+
37
51
  on(event, listener) {
38
52
  this.eventEmitter.on(event, listener);
39
53
  }
@@ -0,0 +1,80 @@
1
+ import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
2
+ import { getFileStreamsCache } from '../file-streams-cache';
3
+ import { createFileDataloader } from '../utils/createFileDataLoader';
4
+ import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
5
+ export class MobileUploadImpl {
6
+ constructor(mediaStore) {
7
+ this.dataloader = createFileDataloader(mediaStore);
8
+ this.servicesCache = createServicesCache();
9
+ }
10
+
11
+ notifyUploadStart(event) {
12
+ const {
13
+ fileId,
14
+ collectionName,
15
+ occurrenceKey,
16
+ fileName,
17
+ fileSize,
18
+ fileMimetype,
19
+ preview,
20
+ createdAt
21
+ } = event;
22
+ const mediaType = getMediaTypeFromMimeType(fileMimetype);
23
+ const initialState = {
24
+ status: 'uploading',
25
+ id: fileId,
26
+ occurrenceKey,
27
+ name: fileName,
28
+ size: fileSize,
29
+ progress: 0,
30
+ mediaType,
31
+ mimeType: fileMimetype,
32
+ preview,
33
+ createdAt
34
+ };
35
+ const service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
36
+ const subject = createMobileFileStateSubject(service);
37
+ this.servicesCache.put(fileId, service);
38
+ getFileStreamsCache().set(fileId, subject);
39
+ }
40
+
41
+ notifyUploadProgress(event) {
42
+ const {
43
+ fileId,
44
+ progress
45
+ } = event;
46
+ const service = this.servicesCache.get(fileId);
47
+
48
+ if (service) {
49
+ service.send('UPLOAD_PROGRESS', {
50
+ progress
51
+ });
52
+ }
53
+ }
54
+
55
+ notifyUploadEnd(event) {
56
+ const {
57
+ fileId
58
+ } = event;
59
+ const service = this.servicesCache.get(fileId);
60
+
61
+ if (service) {
62
+ service.send('UPLOAD_END');
63
+ }
64
+ }
65
+
66
+ notifyUploadError(event) {
67
+ const {
68
+ fileId,
69
+ message
70
+ } = event;
71
+ const service = this.servicesCache.get(fileId);
72
+
73
+ if (service) {
74
+ service.send('UPLOAD_ERROR', {
75
+ message
76
+ });
77
+ }
78
+ }
79
+
80
+ }
@@ -10,6 +10,7 @@ export { request, RequestError, isRequestError, isRateLimitedError } from './uti
10
10
  export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl } from './utils/request/helpers';
11
11
  export { PollingFunction } from './utils/polling';
12
12
  export { isPollingError, PollingError } from './utils/polling/errors';
13
+ export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';
13
14
  export { FileFetcherImpl, FileFetcherError, isFileFetcherError } from './client/file-fetcher';
14
15
  export { CollectionFetcher } from './client/collection-fetcher';
15
16
  export { MediaClient } from './client/media-client';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export const imageResizeModeToFileImageMode = resizeMode => resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode;
@@ -0,0 +1,30 @@
1
+ import { BaseMediaClientError } from '../../models/errors';
2
+ export class MobileUploadError extends BaseMediaClientError {
3
+ constructor(reason, id, metadata) {
4
+ super(reason);
5
+ this.reason = reason;
6
+ this.id = id;
7
+ this.metadata = metadata;
8
+ }
9
+
10
+ get attributes() {
11
+ const {
12
+ reason,
13
+ id,
14
+ metadata: {
15
+ collectionName,
16
+ occurrenceKey
17
+ } = {}
18
+ } = this;
19
+ return {
20
+ reason,
21
+ id,
22
+ collectionName,
23
+ occurrenceKey
24
+ };
25
+ }
26
+
27
+ }
28
+ export function isMobileUploadError(err) {
29
+ return err instanceof MobileUploadError;
30
+ }
@@ -0,0 +1,55 @@
1
+ import { ReplaySubject } from 'rxjs/ReplaySubject';
2
+ import { from } from 'rxjs/observable/from';
3
+ import { map } from 'rxjs/operators/map';
4
+ import { mapMediaItemToFileState } from '../../models/file-state';
5
+ import { createFileStateSubject } from '../createFileStateSubject';
6
+ import { isEmptyFile } from '../detectEmptyFile';
7
+ import { PollingFunction } from '../polling';
8
+ import { MobileUploadError } from './error';
9
+ export const createMobileFileStateSubject = service => {
10
+ const subject = new ReplaySubject(1);
11
+ from(service.start()).pipe(map(state => state.context.currentFileState)).subscribe(subject);
12
+ return subject;
13
+ };
14
+ export const createMobileDownloadFileStream = (dataloader, id, collectionName, occurrenceKey) => {
15
+ const subject = createFileStateSubject();
16
+ const poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
17
+
18
+ poll.onError = error => subject.error(error);
19
+
20
+ poll.execute(async () => {
21
+ const response = await dataloader.load({
22
+ id,
23
+ collectionName
24
+ });
25
+
26
+ if (!response) {
27
+ throw new MobileUploadError('emptyItems', id, {
28
+ collectionName,
29
+ occurrenceKey
30
+ });
31
+ }
32
+
33
+ if (isEmptyFile(response)) {
34
+ throw new MobileUploadError('zeroVersionFile', id, {
35
+ collectionName,
36
+ occurrenceKey
37
+ });
38
+ }
39
+
40
+ const fileState = mapMediaItemToFileState(id, response);
41
+ subject.next(fileState);
42
+
43
+ switch (fileState.status) {
44
+ case 'processing':
45
+ // the only case for continuing polling, otherwise this function is run once only
46
+ poll.next();
47
+ break;
48
+
49
+ case 'processed':
50
+ subject.complete();
51
+ break;
52
+ }
53
+ });
54
+ return subject;
55
+ };
@@ -0,0 +1,4 @@
1
+ export { isMobileUploadError, MobileUploadError } from './error';
2
+ export { createServicesCache } from './servicesCache';
3
+ export { createMobileUploadService, createMobileUploadStateMachine } from './stateMachine';
4
+ export { createMobileFileStateSubject } from './helpers';
@@ -0,0 +1,4 @@
1
+ import { LRUCache } from 'lru-fast';
2
+ export function createServicesCache() {
3
+ return new LRUCache(100);
4
+ }
@@ -0,0 +1,52 @@
1
+ import { map } from 'rxjs/operators/map';
2
+ import { createMachine, interpret } from 'xstate';
3
+ import { isProcessingFileState } from '../../../models/file-state';
4
+ import { shouldFetchRemoteFileStates } from '../../shouldFetchRemoteFileStates';
5
+ import { createMobileDownloadFileStream } from '../helpers';
6
+ import { machineUploadingState } from './states/uploading';
7
+ import { machineProcessingState } from './states/processing';
8
+ import { machineProcessedState } from './states/processed';
9
+ import { machineProcessingFailedState } from './states/processingFailed';
10
+ import { machineErrorState } from './states/error';
11
+ export const createMobileUploadStateMachine = (dataloader, initialState, collectionName) => createMachine({
12
+ // Initial state
13
+ initial: initialState.status,
14
+ // Context
15
+ context: {
16
+ currentFileState: initialState
17
+ },
18
+ // State definitions
19
+ states: {
20
+ uploading: machineUploadingState,
21
+ processing: machineProcessingState,
22
+ processed: machineProcessedState,
23
+ processingFailed: machineProcessingFailedState,
24
+ error: machineErrorState
25
+ }
26
+ }, {
27
+ services: {
28
+ shouldFetchRemoteFileStates: async ctx => {
29
+ const {
30
+ currentFileState
31
+ } = ctx;
32
+
33
+ if (isProcessingFileState(currentFileState)) {
34
+ const {
35
+ mediaType,
36
+ mimeType,
37
+ preview
38
+ } = currentFileState;
39
+ return shouldFetchRemoteFileStates(mediaType, mimeType, preview);
40
+ }
41
+
42
+ return false;
43
+ },
44
+ fetchRemoteFileStates: ctx => createMobileDownloadFileStream(dataloader, ctx.currentFileState.id, collectionName, ctx.currentFileState.occurrenceKey).pipe(map(fileState => ({
45
+ type: 'REMOTE_FILESTATE_RESULT',
46
+ fileState
47
+ })))
48
+ }
49
+ });
50
+ export function createMobileUploadService(machine) {
51
+ return interpret(machine);
52
+ }
@@ -0,0 +1,3 @@
1
+ export const machineErrorState = {
2
+ type: 'final'
3
+ };
@@ -0,0 +1,3 @@
1
+ export const machineProcessedState = {
2
+ type: 'final'
3
+ };
@@ -0,0 +1,60 @@
1
+ import { assign, send } from 'xstate';
2
+ export const machineProcessingState = {
3
+ // Events
4
+ on: {
5
+ REMOTE_FILESTATE_PROCESSED: 'processed',
6
+ REMOTE_FILESTATE_PROCESSING_FAILED: 'processingFailed',
7
+ REMOTE_FILESTATE_ERROR: 'error'
8
+ },
9
+ // Initial sub state
10
+ initial: 'loading',
11
+ // Sub states definitions
12
+ states: {
13
+ loading: {
14
+ invoke: {
15
+ src: 'shouldFetchRemoteFileStates',
16
+ onDone: {
17
+ actions: send((_, event) => ({
18
+ // shouldFetchRemoteFileStates resolves a boolean
19
+ type: event.data ? 'REMOTE_FILESTATE_FETCH' : 'REMOTE_FILESTATE_BYPASS'
20
+ }))
21
+ },
22
+ onError: 'idle'
23
+ },
24
+ on: {
25
+ REMOTE_FILESTATE_FETCH: 'fetchingRemoteFileStates',
26
+ REMOTE_FILESTATE_BYPASS: 'idle'
27
+ }
28
+ },
29
+ fetchingRemoteFileStates: {
30
+ invoke: {
31
+ src: 'fetchRemoteFileStates',
32
+ onDone: {
33
+ actions: send(ctx => ({
34
+ type: ctx.currentFileState.status === 'processed' ? 'REMOTE_FILESTATE_PROCESSED' : 'REMOTE_FILESTATE_PROCESSING_FAILED'
35
+ }))
36
+ },
37
+ onError: {
38
+ actions: [assign({
39
+ currentFileState: (ctx, event) => ({
40
+ status: 'error',
41
+ id: ctx.currentFileState.id,
42
+ occurrenceKey: ctx.currentFileState.occurrenceKey,
43
+ message: event.data.message
44
+ })
45
+ }), send({
46
+ type: 'REMOTE_FILESTATE_ERROR'
47
+ })]
48
+ }
49
+ },
50
+ on: {
51
+ REMOTE_FILESTATE_RESULT: {
52
+ actions: assign({
53
+ currentFileState: (_, event) => event.fileState
54
+ })
55
+ }
56
+ }
57
+ },
58
+ idle: {}
59
+ }
60
+ };
@@ -0,0 +1,3 @@
1
+ export const machineProcessingFailedState = {
2
+ type: 'final'
3
+ };
@@ -0,0 +1,44 @@
1
+ import { assign } from 'xstate';
2
+ import { isUploadingFileState } from '../../../../models/file-state';
3
+ export const machineUploadingState = {
4
+ // Events
5
+ on: {
6
+ UPLOAD_PROGRESS: [{
7
+ target: 'uploading',
8
+ cond: (ctx, event) => isUploadingFileState(ctx.currentFileState) && event.progress > ctx.currentFileState.progress,
9
+ actions: assign({
10
+ currentFileState: (ctx, event) => ({ ...ctx.currentFileState,
11
+ progress: event.progress
12
+ })
13
+ })
14
+ }, {
15
+ target: 'error'
16
+ }],
17
+ UPLOAD_END: {
18
+ target: 'processing',
19
+ actions: assign({
20
+ currentFileState: ctx => isUploadingFileState(ctx.currentFileState) && {
21
+ status: 'processing',
22
+ id: ctx.currentFileState.id,
23
+ occurrenceKey: ctx.currentFileState.occurrenceKey,
24
+ name: ctx.currentFileState.name,
25
+ size: ctx.currentFileState.size,
26
+ mediaType: ctx.currentFileState.mediaType,
27
+ mimeType: ctx.currentFileState.mimeType,
28
+ preview: ctx.currentFileState.preview,
29
+ createdAt: ctx.currentFileState.createdAt
30
+ } || ctx.currentFileState
31
+ })
32
+ },
33
+ UPLOAD_ERROR: {
34
+ target: 'error',
35
+ actions: assign({
36
+ currentFileState: (ctx, event) => ({
37
+ status: 'error',
38
+ id: ctx.currentFileState.id,
39
+ message: event.message
40
+ })
41
+ })
42
+ }
43
+ }
44
+ };
@@ -1,11 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { getMediaFeatureFlag } from '@atlaskit/media-common/mediaFeatureFlags';
3
2
  import { PollingError } from './errors';
3
+ // default polling options without using feature flags
4
4
  export const defaultPollingOptions = {
5
- poll_intervalMs: getMediaFeatureFlag('poll_intervalMs'),
6
- poll_maxAttempts: getMediaFeatureFlag('poll_maxAttempts'),
7
- poll_backoffFactor: getMediaFeatureFlag('poll_backoffFactor'),
8
- poll_maxIntervalMs: getMediaFeatureFlag('poll_maxIntervalMs')
5
+ poll_intervalMs: 3000,
6
+ poll_maxAttempts: 30,
7
+ poll_backoffFactor: 1.25,
8
+ poll_maxIntervalMs: 200000
9
9
  };
10
10
  /**
11
11
  * This class encapsulates polling functionality with the following features:
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "14.1.1",
3
+ "version": "14.3.2",
4
4
  "sideEffects": false
5
5
  }
@@ -37,7 +37,6 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
37
37
  import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
38
38
  import { PollingFunction } from '../../utils/polling';
39
39
  import { isEmptyFile } from '../../utils/detectEmptyFile';
40
- import { getMediaFeatureFlag } from '@atlaskit/media-common/mediaFeatureFlags';
41
40
  export { isFileFetcherError, FileFetcherError } from './error';
42
41
  export var FileFetcherImpl = /*#__PURE__*/function () {
43
42
  function FileFetcherImpl(mediaStore) {
@@ -47,14 +46,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
47
46
 
48
47
  _defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
49
48
  var subject = createFileStateSubject();
50
- var featureFlags = _this.mediaStore.featureFlags;
51
- var pollingOptions = {
52
- poll_intervalMs: getMediaFeatureFlag('poll_intervalMs', featureFlags),
53
- poll_maxAttempts: getMediaFeatureFlag('poll_maxAttempts', featureFlags),
54
- poll_backoffFactor: getMediaFeatureFlag('poll_backoffFactor', featureFlags),
55
- poll_maxIntervalMs: getMediaFeatureFlag('poll_maxIntervalMs', featureFlags)
56
- };
57
- var poll = new PollingFunction(pollingOptions); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
49
+ var poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
58
50
 
59
51
  poll.onError = function (error) {
60
52
  return subject.error(error);
@@ -8,6 +8,7 @@ import { CollectionFetcher } from './collection-fetcher';
8
8
  import { FileFetcherImpl } from './file-fetcher';
9
9
  import { StargateClient } from './stargate-client';
10
10
  export var MediaClient = /*#__PURE__*/function () {
11
+ // mobile upload is lazily loaded
11
12
  // Deprecated value introduced for backward compatibility with Context
12
13
  function MediaClient(mediaClientConfig, featureFlags) {
13
14
  _classCallCheck(this, MediaClient);
@@ -15,7 +16,8 @@ export var MediaClient = /*#__PURE__*/function () {
15
16
  this.mediaClientConfig = mediaClientConfig;
16
17
  this.featureFlags = featureFlags;
17
18
  this.mediaStore = new MediaStore({
18
- authProvider: mediaClientConfig.authProvider
19
+ authProvider: mediaClientConfig.authProvider,
20
+ initialAuth: mediaClientConfig.initialAuth
19
21
  }, featureFlags);
20
22
  this.config = mediaClientConfig;
21
23
  this.collection = new CollectionFetcher(this.mediaStore);
@@ -67,6 +69,47 @@ export var MediaClient = /*#__PURE__*/function () {
67
69
 
68
70
  return getImageMetadata;
69
71
  }()
72
+ }, {
73
+ key: "mobileUploadPromise",
74
+ value: function () {
75
+ var _mobileUploadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
76
+ var module;
77
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
78
+ while (1) {
79
+ switch (_context2.prev = _context2.next) {
80
+ case 0:
81
+ if (!this.mobileUpload) {
82
+ _context2.next = 2;
83
+ break;
84
+ }
85
+
86
+ return _context2.abrupt("return", this.mobileUpload);
87
+
88
+ case 2:
89
+ _context2.next = 4;
90
+ return import(
91
+ /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */
92
+ './mobile-upload');
93
+
94
+ case 4:
95
+ module = _context2.sent;
96
+ this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
97
+ return _context2.abrupt("return", this.mobileUpload);
98
+
99
+ case 7:
100
+ case "end":
101
+ return _context2.stop();
102
+ }
103
+ }
104
+ }, _callee2, this);
105
+ }));
106
+
107
+ function mobileUploadPromise() {
108
+ return _mobileUploadPromise.apply(this, arguments);
109
+ }
110
+
111
+ return mobileUploadPromise;
112
+ }()
70
113
  }, {
71
114
  key: "on",
72
115
  value: function on(event, listener) {
@@ -0,0 +1,83 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
4
+ import { getFileStreamsCache } from '../file-streams-cache';
5
+ import { createFileDataloader } from '../utils/createFileDataLoader';
6
+ import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
7
+ export var MobileUploadImpl = /*#__PURE__*/function () {
8
+ function MobileUploadImpl(mediaStore) {
9
+ _classCallCheck(this, MobileUploadImpl);
10
+
11
+ this.dataloader = createFileDataloader(mediaStore);
12
+ this.servicesCache = createServicesCache();
13
+ }
14
+
15
+ _createClass(MobileUploadImpl, [{
16
+ key: "notifyUploadStart",
17
+ value: function notifyUploadStart(event) {
18
+ var fileId = event.fileId,
19
+ collectionName = event.collectionName,
20
+ occurrenceKey = event.occurrenceKey,
21
+ fileName = event.fileName,
22
+ fileSize = event.fileSize,
23
+ fileMimetype = event.fileMimetype,
24
+ preview = event.preview,
25
+ createdAt = event.createdAt;
26
+ var mediaType = getMediaTypeFromMimeType(fileMimetype);
27
+ var initialState = {
28
+ status: 'uploading',
29
+ id: fileId,
30
+ occurrenceKey: occurrenceKey,
31
+ name: fileName,
32
+ size: fileSize,
33
+ progress: 0,
34
+ mediaType: mediaType,
35
+ mimeType: fileMimetype,
36
+ preview: preview,
37
+ createdAt: createdAt
38
+ };
39
+ var service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
40
+ var subject = createMobileFileStateSubject(service);
41
+ this.servicesCache.put(fileId, service);
42
+ getFileStreamsCache().set(fileId, subject);
43
+ }
44
+ }, {
45
+ key: "notifyUploadProgress",
46
+ value: function notifyUploadProgress(event) {
47
+ var fileId = event.fileId,
48
+ progress = event.progress;
49
+ var service = this.servicesCache.get(fileId);
50
+
51
+ if (service) {
52
+ service.send('UPLOAD_PROGRESS', {
53
+ progress: progress
54
+ });
55
+ }
56
+ }
57
+ }, {
58
+ key: "notifyUploadEnd",
59
+ value: function notifyUploadEnd(event) {
60
+ var fileId = event.fileId;
61
+ var service = this.servicesCache.get(fileId);
62
+
63
+ if (service) {
64
+ service.send('UPLOAD_END');
65
+ }
66
+ }
67
+ }, {
68
+ key: "notifyUploadError",
69
+ value: function notifyUploadError(event) {
70
+ var fileId = event.fileId,
71
+ message = event.message;
72
+ var service = this.servicesCache.get(fileId);
73
+
74
+ if (service) {
75
+ service.send('UPLOAD_ERROR', {
76
+ message: message
77
+ });
78
+ }
79
+ }
80
+ }]);
81
+
82
+ return MobileUploadImpl;
83
+ }();
package/dist/esm/index.js CHANGED
@@ -10,6 +10,7 @@ export { request, RequestError, isRequestError, isRateLimitedError } from './uti
10
10
  export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl } from './utils/request/helpers';
11
11
  export { PollingFunction } from './utils/polling';
12
12
  export { isPollingError, PollingError } from './utils/polling/errors';
13
+ export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';
13
14
  export { FileFetcherImpl, FileFetcherError, isFileFetcherError } from './client/file-fetcher';
14
15
  export { CollectionFetcher } from './client/collection-fetcher';
15
16
  export { MediaClient } from './client/media-client';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export var imageResizeModeToFileImageMode = function imageResizeModeToFileImageMode(resizeMode) {
2
+ return resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode;
3
+ };