@atlaskit/media-client 14.0.0 → 14.3.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 +40 -0
- package/dist/cjs/client/file-fetcher/index.js +3 -10
- package/dist/cjs/client/media-client.js +48 -0
- package/dist/cjs/client/media-store/resolveAuth.js +36 -15
- package/dist/cjs/client/mobile-upload.js +98 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/models/mobile-upload.js +5 -0
- package/dist/cjs/utils/createFileDataLoader.js +4 -0
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +12 -0
- package/dist/cjs/utils/mobileUpload/error.js +67 -0
- package/dist/cjs/utils/mobileUpload/helpers.js +110 -0
- package/dist/cjs/utils/mobileUpload/index.js +49 -0
- package/dist/cjs/utils/mobileUpload/servicesCache.js +12 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +103 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/error.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processed.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +77 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processingFailed.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +70 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/types.js +5 -0
- package/dist/cjs/utils/polling/index.js +5 -6
- package/dist/cjs/utils/setTimeoutPromise.js +22 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +5 -12
- package/dist/es2019/client/media-client.js +13 -0
- package/dist/es2019/client/media-store/resolveAuth.js +12 -4
- package/dist/es2019/client/mobile-upload.js +80 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/models/mobile-upload.js +1 -0
- package/dist/es2019/utils/createFileDataLoader.js +3 -0
- package/dist/es2019/utils/imageResizeModeToFileImageMode.js +1 -0
- package/dist/es2019/utils/mobileUpload/error.js +30 -0
- package/dist/es2019/utils/mobileUpload/helpers.js +55 -0
- package/dist/es2019/utils/mobileUpload/index.js +4 -0
- package/dist/es2019/utils/mobileUpload/servicesCache.js +4 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/index.js +52 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/error.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processed.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processing.js +60 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +44 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/types.js +1 -0
- package/dist/es2019/utils/polling/index.js +5 -5
- package/dist/es2019/utils/setTimeoutPromise.js +6 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/index.js +5 -10
- package/dist/esm/client/media-client.js +42 -0
- package/dist/esm/client/media-store/resolveAuth.js +34 -14
- package/dist/esm/client/mobile-upload.js +83 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/models/mobile-upload.js +1 -0
- package/dist/esm/utils/createFileDataLoader.js +3 -0
- package/dist/esm/utils/imageResizeModeToFileImageMode.js +3 -0
- package/dist/esm/utils/mobileUpload/error.js +51 -0
- package/dist/esm/utils/mobileUpload/helpers.js +86 -0
- package/dist/esm/utils/mobileUpload/index.js +4 -0
- package/dist/esm/utils/mobileUpload/servicesCache.js +4 -0
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +78 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/error.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processed.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processing.js +68 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +58 -0
- package/dist/esm/utils/mobileUpload/stateMachine/types.js +1 -0
- package/dist/esm/utils/polling/index.js +5 -5
- package/dist/esm/utils/setTimeoutPromise.js +10 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +1 -0
- package/dist/types/client/media-client.d.ts +3 -0
- package/dist/types/client/media-store/error.d.ts +1 -1
- package/dist/types/client/media-store/resolveAuth.d.ts +2 -2
- package/dist/types/client/mobile-upload.d.ts +11 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/models/errors/types.d.ts +1 -1
- package/dist/types/models/mobile-upload.d.ts +28 -0
- package/dist/types/utils/createFileDataLoader.d.ts +4 -3
- package/dist/types/utils/imageResizeModeToFileImageMode.d.ts +3 -0
- package/dist/types/utils/mobileUpload/error.d.ts +29 -0
- package/dist/types/utils/mobileUpload/helpers.d.ts +8 -0
- package/dist/types/utils/mobileUpload/index.d.ts +5 -0
- package/dist/types/utils/mobileUpload/servicesCache.d.ts +4 -0
- package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +7 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +69 -0
- package/dist/types/utils/polling/index.d.ts +8 -3
- package/dist/types/utils/setTimeoutPromise.d.ts +2 -0
- package/package.json +9 -7
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { map } from 'rxjs/operators/map';
|
|
4
|
+
import { createMachine, interpret } from 'xstate';
|
|
5
|
+
import { isProcessingFileState } from '../../../models/file-state';
|
|
6
|
+
import { shouldFetchRemoteFileStates as _shouldFetchRemoteFileStates } from '../../shouldFetchRemoteFileStates';
|
|
7
|
+
import { createMobileDownloadFileStream } from '../helpers';
|
|
8
|
+
import { machineUploadingState } from './states/uploading';
|
|
9
|
+
import { machineProcessingState } from './states/processing';
|
|
10
|
+
import { machineProcessedState } from './states/processed';
|
|
11
|
+
import { machineProcessingFailedState } from './states/processingFailed';
|
|
12
|
+
import { machineErrorState } from './states/error';
|
|
13
|
+
export var createMobileUploadStateMachine = function createMobileUploadStateMachine(dataloader, initialState, collectionName) {
|
|
14
|
+
return createMachine({
|
|
15
|
+
// Initial state
|
|
16
|
+
initial: initialState.status,
|
|
17
|
+
// Context
|
|
18
|
+
context: {
|
|
19
|
+
currentFileState: initialState
|
|
20
|
+
},
|
|
21
|
+
// State definitions
|
|
22
|
+
states: {
|
|
23
|
+
uploading: machineUploadingState,
|
|
24
|
+
processing: machineProcessingState,
|
|
25
|
+
processed: machineProcessedState,
|
|
26
|
+
processingFailed: machineProcessingFailedState,
|
|
27
|
+
error: machineErrorState
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
services: {
|
|
31
|
+
shouldFetchRemoteFileStates: function () {
|
|
32
|
+
var _shouldFetchRemoteFileStates2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ctx) {
|
|
33
|
+
var currentFileState, mediaType, mimeType, preview;
|
|
34
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
|
+
while (1) {
|
|
36
|
+
switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
currentFileState = ctx.currentFileState;
|
|
39
|
+
|
|
40
|
+
if (!isProcessingFileState(currentFileState)) {
|
|
41
|
+
_context.next = 4;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
mediaType = currentFileState.mediaType, mimeType = currentFileState.mimeType, preview = currentFileState.preview;
|
|
46
|
+
return _context.abrupt("return", _shouldFetchRemoteFileStates(mediaType, mimeType, preview));
|
|
47
|
+
|
|
48
|
+
case 4:
|
|
49
|
+
return _context.abrupt("return", false);
|
|
50
|
+
|
|
51
|
+
case 5:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
function shouldFetchRemoteFileStates(_x) {
|
|
60
|
+
return _shouldFetchRemoteFileStates2.apply(this, arguments);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return shouldFetchRemoteFileStates;
|
|
64
|
+
}(),
|
|
65
|
+
fetchRemoteFileStates: function fetchRemoteFileStates(ctx) {
|
|
66
|
+
return createMobileDownloadFileStream(dataloader, ctx.currentFileState.id, collectionName, ctx.currentFileState.occurrenceKey).pipe(map(function (fileState) {
|
|
67
|
+
return {
|
|
68
|
+
type: 'REMOTE_FILESTATE_RESULT',
|
|
69
|
+
fileState: fileState
|
|
70
|
+
};
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
export function createMobileUploadService(machine) {
|
|
77
|
+
return interpret(machine);
|
|
78
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assign, send } from 'xstate';
|
|
2
|
+
export var 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(function (_, event) {
|
|
18
|
+
return {
|
|
19
|
+
// shouldFetchRemoteFileStates resolves a boolean
|
|
20
|
+
type: event.data ? 'REMOTE_FILESTATE_FETCH' : 'REMOTE_FILESTATE_BYPASS'
|
|
21
|
+
};
|
|
22
|
+
})
|
|
23
|
+
},
|
|
24
|
+
onError: 'idle'
|
|
25
|
+
},
|
|
26
|
+
on: {
|
|
27
|
+
REMOTE_FILESTATE_FETCH: 'fetchingRemoteFileStates',
|
|
28
|
+
REMOTE_FILESTATE_BYPASS: 'idle'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
fetchingRemoteFileStates: {
|
|
32
|
+
invoke: {
|
|
33
|
+
src: 'fetchRemoteFileStates',
|
|
34
|
+
onDone: {
|
|
35
|
+
actions: send(function (ctx) {
|
|
36
|
+
return {
|
|
37
|
+
type: ctx.currentFileState.status === 'processed' ? 'REMOTE_FILESTATE_PROCESSED' : 'REMOTE_FILESTATE_PROCESSING_FAILED'
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
onError: {
|
|
42
|
+
actions: [assign({
|
|
43
|
+
currentFileState: function currentFileState(ctx, event) {
|
|
44
|
+
return {
|
|
45
|
+
status: 'error',
|
|
46
|
+
id: ctx.currentFileState.id,
|
|
47
|
+
occurrenceKey: ctx.currentFileState.occurrenceKey,
|
|
48
|
+
message: event.data.message
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}), send({
|
|
52
|
+
type: 'REMOTE_FILESTATE_ERROR'
|
|
53
|
+
})]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
on: {
|
|
57
|
+
REMOTE_FILESTATE_RESULT: {
|
|
58
|
+
actions: assign({
|
|
59
|
+
currentFileState: function currentFileState(_, event) {
|
|
60
|
+
return event.fileState;
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
idle: {}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
+
|
|
7
|
+
import { assign } from 'xstate';
|
|
8
|
+
import { isUploadingFileState } from '../../../../models/file-state';
|
|
9
|
+
export var machineUploadingState = {
|
|
10
|
+
// Events
|
|
11
|
+
on: {
|
|
12
|
+
UPLOAD_PROGRESS: [{
|
|
13
|
+
target: 'uploading',
|
|
14
|
+
cond: function cond(ctx, event) {
|
|
15
|
+
return isUploadingFileState(ctx.currentFileState) && event.progress > ctx.currentFileState.progress;
|
|
16
|
+
},
|
|
17
|
+
actions: assign({
|
|
18
|
+
currentFileState: function currentFileState(ctx, event) {
|
|
19
|
+
return _objectSpread(_objectSpread({}, ctx.currentFileState), {}, {
|
|
20
|
+
progress: event.progress
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}, {
|
|
25
|
+
target: 'error'
|
|
26
|
+
}],
|
|
27
|
+
UPLOAD_END: {
|
|
28
|
+
target: 'processing',
|
|
29
|
+
actions: assign({
|
|
30
|
+
currentFileState: function currentFileState(ctx) {
|
|
31
|
+
return isUploadingFileState(ctx.currentFileState) && {
|
|
32
|
+
status: 'processing',
|
|
33
|
+
id: ctx.currentFileState.id,
|
|
34
|
+
occurrenceKey: ctx.currentFileState.occurrenceKey,
|
|
35
|
+
name: ctx.currentFileState.name,
|
|
36
|
+
size: ctx.currentFileState.size,
|
|
37
|
+
mediaType: ctx.currentFileState.mediaType,
|
|
38
|
+
mimeType: ctx.currentFileState.mimeType,
|
|
39
|
+
preview: ctx.currentFileState.preview,
|
|
40
|
+
createdAt: ctx.currentFileState.createdAt
|
|
41
|
+
} || ctx.currentFileState;
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
UPLOAD_ERROR: {
|
|
46
|
+
target: 'error',
|
|
47
|
+
actions: assign({
|
|
48
|
+
currentFileState: function currentFileState(ctx, event) {
|
|
49
|
+
return {
|
|
50
|
+
status: 'error',
|
|
51
|
+
id: ctx.currentFileState.id,
|
|
52
|
+
message: event.message
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,13 +8,13 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
8
8
|
|
|
9
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
10
|
|
|
11
|
-
import { getMediaFeatureFlag } from '@atlaskit/media-common/mediaFeatureFlags';
|
|
12
11
|
import { PollingError } from './errors';
|
|
12
|
+
// default polling options without using feature flags
|
|
13
13
|
export var defaultPollingOptions = {
|
|
14
|
-
poll_intervalMs:
|
|
15
|
-
poll_maxAttempts:
|
|
16
|
-
poll_backoffFactor:
|
|
17
|
-
poll_maxIntervalMs:
|
|
14
|
+
poll_intervalMs: 3000,
|
|
15
|
+
poll_maxAttempts: 30,
|
|
16
|
+
poll_backoffFactor: 1.25,
|
|
17
|
+
poll_maxIntervalMs: 200000
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* This class encapsulates polling functionality with the following features:
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var resolveTimeout = function resolveTimeout(timeout, resolveWith) {
|
|
2
|
+
return new Promise(function (resolve, _reject) {
|
|
3
|
+
setTimeout(resolve, timeout, resolveWith);
|
|
4
|
+
});
|
|
5
|
+
};
|
|
6
|
+
export var rejectTimeout = function rejectTimeout(timeout, rejectWith) {
|
|
7
|
+
return new Promise(function (_resolve, reject) {
|
|
8
|
+
setTimeout(reject, timeout, rejectWith);
|
|
9
|
+
});
|
|
10
|
+
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
2
|
+
import 'setimmediate';
|
|
2
3
|
import { AuthProvider } from '@atlaskit/media-core';
|
|
3
4
|
import { MediaStore, MediaStoreCopyFileWithTokenParams, TouchedFiles, TouchFileDescriptor } from '../media-store';
|
|
4
5
|
import { FilePreview, FileState, GetFileOptions } from '../../models/file-state';
|
|
@@ -5,6 +5,7 @@ import { CollectionFetcher } from './collection-fetcher';
|
|
|
5
5
|
import { FileFetcher } from './file-fetcher';
|
|
6
6
|
import { UploadEventPayloadMap, EventPayloadListener } from './events';
|
|
7
7
|
import { StargateClient } from './stargate-client';
|
|
8
|
+
import { MobileUpload } from '../models/mobile-upload';
|
|
8
9
|
export declare class MediaClient {
|
|
9
10
|
readonly mediaClientConfig: MediaClientConfig;
|
|
10
11
|
readonly featureFlags?: MediaFeatureFlags | undefined;
|
|
@@ -13,12 +14,14 @@ export declare class MediaClient {
|
|
|
13
14
|
readonly file: FileFetcher;
|
|
14
15
|
readonly stargate: StargateClient;
|
|
15
16
|
private readonly eventEmitter;
|
|
17
|
+
private mobileUpload?;
|
|
16
18
|
readonly config: MediaClientConfig;
|
|
17
19
|
constructor(mediaClientConfig: MediaClientConfig, featureFlags?: MediaFeatureFlags | undefined);
|
|
18
20
|
getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean): Promise<Blob>;
|
|
19
21
|
getImageUrl(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
|
|
20
22
|
getImageUrlSync(id: string, params?: MediaStoreGetFileImageParams): string;
|
|
21
23
|
getImageMetadata(id: string, params?: MediaStoreGetFileImageParams): Promise<ImageMetadata>;
|
|
24
|
+
mobileUploadPromise(): Promise<MobileUpload>;
|
|
22
25
|
on<E extends keyof UploadEventPayloadMap>(event: E, listener: EventPayloadListener<UploadEventPayloadMap, E>): void;
|
|
23
26
|
off<E extends keyof UploadEventPayloadMap>(event: E, listener: EventPayloadListener<UploadEventPayloadMap, E>): void;
|
|
24
27
|
emit<E extends keyof UploadEventPayloadMap>(event: E, payload: UploadEventPayloadMap[E]): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
|
-
export declare type MediaStoreErrorReason = 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth';
|
|
2
|
+
export declare type MediaStoreErrorReason = 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut';
|
|
3
3
|
export declare type MediaStoreErrorAttributes = {
|
|
4
4
|
readonly reason: MediaStoreErrorReason;
|
|
5
5
|
readonly innerError?: Error;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Auth, AuthContext, AuthProvider } from '@atlaskit/media-core';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const resolveAuth: (authProvider: AuthProvider, authContext?: AuthContext | undefined) => Promise<Auth>;
|
|
2
|
+
export declare const DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
|
|
3
|
+
export declare const resolveAuth: (authProvider: AuthProvider, authContext?: AuthContext | undefined, authProviderTimeout?: number) => Promise<Auth>;
|
|
4
4
|
export declare const resolveInitialAuth: (auth?: import("@atlaskit/media-core").ClientBasedAuth | import("@atlaskit/media-core").AsapBasedAuth | undefined) => Auth;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MobileUpload, MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent } from '../models/mobile-upload';
|
|
2
|
+
import { MediaStore } from './media-store';
|
|
3
|
+
export declare class MobileUploadImpl implements MobileUpload {
|
|
4
|
+
private readonly dataloader;
|
|
5
|
+
private readonly servicesCache;
|
|
6
|
+
constructor(mediaStore: MediaStore);
|
|
7
|
+
notifyUploadStart(event: MobileUploadStartEvent): void;
|
|
8
|
+
notifyUploadProgress(event: MobileUploadProgressEvent): void;
|
|
9
|
+
notifyUploadEnd(event: MobileUploadEndEvent): void;
|
|
10
|
+
notifyUploadError(event: MobileUploadErrorEvent): void;
|
|
11
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
|
|
|
11
11
|
export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './models/errors';
|
|
12
12
|
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
|
|
13
13
|
export type { FileStatus, FilePreview, PreviewOptions, GetFileOptions, UploadingFileState, ProcessingFileState, ProcessedFileState, ProcessingFailedState, ErrorFileState, NonErrorFileState, PreviewableFileState, FileState, } from './models/file-state';
|
|
14
|
+
export type { MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent, } from './models/mobile-upload';
|
|
14
15
|
export { getFileStreamsCache, StreamsCache } from './file-streams-cache';
|
|
15
16
|
export { uploadFile } from './uploader';
|
|
16
17
|
export type { UploadableFile, UploadableFileUpfrontIds, UploadFileCallbacks, UploadFileResult, } from './uploader';
|
|
@@ -21,7 +22,8 @@ export { PollingFunction } from './utils/polling';
|
|
|
21
22
|
export { isPollingError, PollingError } from './utils/polling/errors';
|
|
22
23
|
export type { Executor, PollingErrorAttributes, PollingErrorReason, } from './utils/polling/types';
|
|
23
24
|
export type { RequestMethod, RequestParams, RequestHeaders, RetryOptions, ClientOptions, RequestMetadata, RequestOptions, CreateUrlOptions, } from './utils/request/types';
|
|
24
|
-
export
|
|
25
|
+
export type { ImageResizeMode } from './utils/imageResizeModeToFileImageMode';
|
|
26
|
+
export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';
|
|
25
27
|
export { FileFetcherImpl, FileFetcherError, isFileFetcherError, } from './client/file-fetcher';
|
|
26
28
|
export type { CopySourceFile, CopyDestination, CopyFileOptions, FileFetcher, FileFetcherErrorAttributes, FileFetcherErrorReason, } from './client/file-fetcher';
|
|
27
29
|
export { CollectionFetcher } from './client/collection-fetcher';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type MediaClientErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError' | 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'pollingMaxAttemptsExceeded';
|
|
1
|
+
export declare type MediaClientErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError' | 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut' | 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'pollingMaxAttemptsExceeded';
|
|
2
2
|
export interface MediaClientErrorAttributes {
|
|
3
3
|
reason: MediaClientErrorReason;
|
|
4
4
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FilePreview } from './file-state';
|
|
2
|
+
export declare type MobileUploadStartEvent = {
|
|
3
|
+
fileId: string;
|
|
4
|
+
collectionName?: string;
|
|
5
|
+
occurrenceKey?: string;
|
|
6
|
+
fileName: string;
|
|
7
|
+
fileSize: number;
|
|
8
|
+
fileMimetype: string;
|
|
9
|
+
preview?: FilePreview;
|
|
10
|
+
createdAt?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare type MobileUploadProgressEvent = {
|
|
13
|
+
fileId: string;
|
|
14
|
+
progress: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type MobileUploadEndEvent = {
|
|
17
|
+
fileId: string;
|
|
18
|
+
};
|
|
19
|
+
export declare type MobileUploadErrorEvent = {
|
|
20
|
+
fileId: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
export interface MobileUpload {
|
|
24
|
+
notifyUploadStart(event: MobileUploadStartEvent): void;
|
|
25
|
+
notifyUploadProgress(event: MobileUploadProgressEvent): void;
|
|
26
|
+
notifyUploadEnd(event: MobileUploadEndEvent): void;
|
|
27
|
+
notifyUploadError(event: MobileUploadErrorEvent): void;
|
|
28
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'setimmediate';
|
|
1
2
|
import Dataloader from 'dataloader';
|
|
2
3
|
import { MediaStore, ResponseFileItem } from '../client/media-store';
|
|
3
4
|
import { MediaCollectionItemFullDetails } from '../models/media';
|
|
@@ -12,7 +13,7 @@ export declare type BatchLoadingErrorResult = {
|
|
|
12
13
|
readonly collection?: string;
|
|
13
14
|
readonly error: Error;
|
|
14
15
|
};
|
|
15
|
-
export declare const getItemsFromKeys: (dataloaderKeys: DataloaderKey
|
|
16
|
+
export declare const getItemsFromKeys: (dataloaderKeys: ReadonlyArray<DataloaderKey>, fileItems: Array<ResponseFileItem | BatchLoadingErrorResult>) => Array<DataloaderResult | Error>;
|
|
16
17
|
export declare type FileIdsByCollection = {
|
|
17
18
|
[collectionName: string]: string[];
|
|
18
19
|
};
|
|
@@ -25,5 +26,5 @@ export declare type FileIdsByCollection = {
|
|
|
25
26
|
*
|
|
26
27
|
* @param mediaStore instance of MediaStore
|
|
27
28
|
*/
|
|
28
|
-
export declare function createBatchLoadingFunc(mediaStore: MediaStore): (keys: DataloaderKey
|
|
29
|
-
export declare function createFileDataloader(mediaStore: MediaStore): Dataloader<DataloaderKey, DataloaderResult>;
|
|
29
|
+
export declare function createBatchLoadingFunc(mediaStore: MediaStore): (keys: ReadonlyArray<DataloaderKey>) => Promise<Array<DataloaderResult | Error>>;
|
|
30
|
+
export declare function createFileDataloader(mediaStore: MediaStore): Dataloader<DataloaderKey, DataloaderResult, DataloaderKey>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MediaStoreGetFileImageParams } from '../client/media-store';
|
|
2
|
+
export declare type ImageResizeMode = 'crop' | 'fit' | 'full-fit' | 'stretchy-fit';
|
|
3
|
+
export declare const imageResizeModeToFileImageMode: (resizeMode?: "crop" | "fit" | "full-fit" | "stretchy-fit" | undefined) => MediaStoreGetFileImageParams['mode'];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseMediaClientError } from '../../models/errors';
|
|
2
|
+
export declare type MobileUploadErrorReason = 'emptyItems' | 'zeroVersionFile';
|
|
3
|
+
export declare type MobileUploadErrorAttributes = {
|
|
4
|
+
readonly reason: MobileUploadErrorReason;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly metadata?: {
|
|
7
|
+
readonly collectionName?: string;
|
|
8
|
+
readonly occurrenceKey?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare class MobileUploadError extends BaseMediaClientError<MobileUploadErrorAttributes> {
|
|
12
|
+
readonly reason: MobileUploadErrorReason;
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly metadata?: {
|
|
15
|
+
readonly collectionName?: string | undefined;
|
|
16
|
+
readonly occurrenceKey?: string | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
constructor(reason: MobileUploadErrorReason, id: string, metadata?: {
|
|
19
|
+
readonly collectionName?: string | undefined;
|
|
20
|
+
readonly occurrenceKey?: string | undefined;
|
|
21
|
+
} | undefined);
|
|
22
|
+
get attributes(): {
|
|
23
|
+
reason: MobileUploadErrorReason;
|
|
24
|
+
id: string;
|
|
25
|
+
collectionName: string | undefined;
|
|
26
|
+
occurrenceKey: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare function isMobileUploadError(err: Error): err is MobileUploadError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Dataloader from 'dataloader';
|
|
2
|
+
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
3
|
+
import { Interpreter } from 'xstate';
|
|
4
|
+
import { FileState } from '../../models/file-state';
|
|
5
|
+
import { DataloaderKey, DataloaderResult } from '../createFileDataLoader';
|
|
6
|
+
import { StateMachineContext, StateMachineEvent, StateMachineTypestate } from './stateMachine/types';
|
|
7
|
+
export declare const createMobileFileStateSubject: (service: Interpreter<StateMachineContext, any, StateMachineEvent, StateMachineTypestate>) => ReplaySubject<FileState>;
|
|
8
|
+
export declare const createMobileDownloadFileStream: (dataloader: Dataloader<DataloaderKey, DataloaderResult>, id: string, collectionName?: string | undefined, occurrenceKey?: string | undefined) => ReplaySubject<FileState>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { isMobileUploadError, MobileUploadError } from './error';
|
|
2
|
+
export { createServicesCache } from './servicesCache';
|
|
3
|
+
export { createMobileUploadService, createMobileUploadStateMachine, } from './stateMachine';
|
|
4
|
+
export { createMobileFileStateSubject } from './helpers';
|
|
5
|
+
export type { StateMachineContext, StateMachineSchema, StateMachineEvent, StateMachineTypestate, } from './stateMachine/types';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LRUCache } from 'lru-fast';
|
|
2
|
+
import { Interpreter } from 'xstate';
|
|
3
|
+
import { StateMachineContext, StateMachineEvent, StateMachineTypestate } from './stateMachine/types';
|
|
4
|
+
export declare function createServicesCache(): LRUCache<string, Interpreter<StateMachineContext, any, StateMachineEvent, StateMachineTypestate>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
import { Interpreter, StateMachine } from 'xstate';
|
|
3
|
+
import { UploadingFileState } from '../../../models/file-state';
|
|
4
|
+
import { DataloaderKey, DataloaderResult } from '../../createFileDataLoader';
|
|
5
|
+
import { StateMachineContext, StateMachineEvent, StateMachineSchema, StateMachineTypestate } from './types';
|
|
6
|
+
export declare const createMobileUploadStateMachine: (dataloader: DataLoader<DataloaderKey, DataloaderResult>, initialState: UploadingFileState, collectionName?: string | undefined) => StateMachine<StateMachineContext, any, StateMachineEvent, StateMachineTypestate>;
|
|
7
|
+
export declare function createMobileUploadService(machine: StateMachine<StateMachineContext, StateMachineSchema, StateMachineEvent, StateMachineTypestate>): Interpreter<StateMachineContext, StateMachineSchema, StateMachineEvent, StateMachineTypestate>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { StateSchema } from 'xstate';
|
|
2
|
+
import { FileState, UploadingFileState, ProcessingFileState, ProcessedFileState, ErrorFileState, ProcessingFailedState } from '../../../models/file-state';
|
|
3
|
+
export declare type StateMachineContext = {
|
|
4
|
+
currentFileState: FileState;
|
|
5
|
+
};
|
|
6
|
+
export declare type StateMachineEvent = {
|
|
7
|
+
type: 'UPLOAD_PROGRESS';
|
|
8
|
+
progress: number;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'UPLOAD_END';
|
|
11
|
+
} | {
|
|
12
|
+
type: 'UPLOAD_ERROR';
|
|
13
|
+
message: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'REMOTE_FILESTATE_FETCH';
|
|
16
|
+
} | {
|
|
17
|
+
type: 'REMOTE_FILESTATE_BYPASS';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'REMOTE_FILESTATE_RESULT';
|
|
20
|
+
fileState: FileState;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'REMOTE_FILESTATE_PROCESSED';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'REMOTE_FILESTATE_PROCESSING_FAILED';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'REMOTE_FILESTATE_ERROR';
|
|
27
|
+
};
|
|
28
|
+
export declare type ProcessingStateMachineSchema = StateSchema<StateMachineContext> & {
|
|
29
|
+
states: {
|
|
30
|
+
loading: StateSchema<StateMachineContext>;
|
|
31
|
+
fetchingRemoteFileStates: StateSchema<StateMachineContext>;
|
|
32
|
+
idle: StateSchema<StateMachineContext>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare type StateMachineSchema = StateSchema<StateMachineContext> & {
|
|
36
|
+
states: {
|
|
37
|
+
uploading: StateSchema<StateMachineContext>;
|
|
38
|
+
processing: ProcessingStateMachineSchema;
|
|
39
|
+
processed: StateSchema<StateMachineContext>;
|
|
40
|
+
processingFailed: StateSchema<StateMachineContext>;
|
|
41
|
+
error: StateSchema<StateMachineContext>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare type StateMachineTypestate = {
|
|
45
|
+
value: 'uploading';
|
|
46
|
+
context: {
|
|
47
|
+
currentFileState: UploadingFileState;
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
value: 'processing';
|
|
51
|
+
context: {
|
|
52
|
+
currentFileState: ProcessingFileState;
|
|
53
|
+
};
|
|
54
|
+
} | {
|
|
55
|
+
value: 'processed';
|
|
56
|
+
context: {
|
|
57
|
+
currentFileState: ProcessedFileState;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
value: 'processingFailed';
|
|
61
|
+
context: {
|
|
62
|
+
currentFileState: ProcessingFailedState;
|
|
63
|
+
};
|
|
64
|
+
} | {
|
|
65
|
+
value: 'error';
|
|
66
|
+
context: {
|
|
67
|
+
currentFileState: ErrorFileState;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { PollingOptions } from '@atlaskit/media-common/mediaFeatureFlags';
|
|
2
1
|
import { Executor } from './types';
|
|
3
|
-
export
|
|
2
|
+
export interface PollingOptions {
|
|
3
|
+
poll_intervalMs: number;
|
|
4
|
+
poll_maxAttempts: number;
|
|
5
|
+
poll_backoffFactor: number;
|
|
6
|
+
poll_maxIntervalMs: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultPollingOptions: PollingOptions;
|
|
4
9
|
/**
|
|
5
10
|
* This class encapsulates polling functionality with the following features:
|
|
6
11
|
*
|
|
@@ -13,7 +18,7 @@ export declare const defaultPollingOptions: Required<PollingOptions>;
|
|
|
13
18
|
* IMPORTANT! the executor function must explicitly call ".next()" for the next iteration to run
|
|
14
19
|
*/
|
|
15
20
|
export declare class PollingFunction {
|
|
16
|
-
options:
|
|
21
|
+
options: PollingOptions;
|
|
17
22
|
poll_intervalMs: number;
|
|
18
23
|
attempt: number;
|
|
19
24
|
shouldIterate: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.3.0",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,17 +28,19 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/chunkinator": "^3.0.0",
|
|
31
|
-
"@atlaskit/media-common": "^2.
|
|
31
|
+
"@atlaskit/media-common": "^2.9.0",
|
|
32
32
|
"@babel/runtime": "^7.0.0",
|
|
33
|
-
"dataloader": "^
|
|
33
|
+
"dataloader": "^2.0.0",
|
|
34
34
|
"deep-equal": "^1.0.1",
|
|
35
35
|
"eventemitter2": "^4.1.0",
|
|
36
36
|
"lru-fast": "^0.2.2",
|
|
37
37
|
"query-string": "^5.1.0",
|
|
38
38
|
"rusha": "^0.8.13",
|
|
39
|
+
"setimmediate": "^1.0.5",
|
|
39
40
|
"uuid": "^3.1.0",
|
|
40
41
|
"uuid-validate": "^0.0.3",
|
|
41
|
-
"video-snapshot": "^1.0.11"
|
|
42
|
+
"video-snapshot": "^1.0.11",
|
|
43
|
+
"xstate": "^4.20.0"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"@atlaskit/media-core": "^32.2.0",
|
|
@@ -47,11 +49,11 @@
|
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@atlaskit/build-utils": "*",
|
|
50
|
-
"@atlaskit/button": "^16.
|
|
52
|
+
"@atlaskit/button": "^16.1.0",
|
|
51
53
|
"@atlaskit/docs": "*",
|
|
52
|
-
"@atlaskit/media-card": "^
|
|
54
|
+
"@atlaskit/media-card": "^72.0.0",
|
|
53
55
|
"@atlaskit/media-core": "^32.2.0",
|
|
54
|
-
"@atlaskit/media-test-helpers": "^28.
|
|
56
|
+
"@atlaskit/media-test-helpers": "^28.8.0",
|
|
55
57
|
"@atlaskit/ssr": "*",
|
|
56
58
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
57
59
|
"@types/deep-equal": "^1.0.1",
|