@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
@@ -0,0 +1,51 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+
11
+ import { BaseMediaClientError } from '../../models/errors';
12
+ export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
13
+ _inherits(MobileUploadError, _BaseMediaClientError);
14
+
15
+ var _super = _createSuper(MobileUploadError);
16
+
17
+ function MobileUploadError(reason, id, metadata) {
18
+ var _this;
19
+
20
+ _classCallCheck(this, MobileUploadError);
21
+
22
+ _this = _super.call(this, reason);
23
+ _this.reason = reason;
24
+ _this.id = id;
25
+ _this.metadata = metadata;
26
+ return _this;
27
+ }
28
+
29
+ _createClass(MobileUploadError, [{
30
+ key: "attributes",
31
+ get: function get() {
32
+ var reason = this.reason,
33
+ id = this.id,
34
+ _this$metadata = this.metadata;
35
+ _this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
36
+ var collectionName = _this$metadata.collectionName,
37
+ occurrenceKey = _this$metadata.occurrenceKey;
38
+ return {
39
+ reason: reason,
40
+ id: id,
41
+ collectionName: collectionName,
42
+ occurrenceKey: occurrenceKey
43
+ };
44
+ }
45
+ }]);
46
+
47
+ return MobileUploadError;
48
+ }(BaseMediaClientError);
49
+ export function isMobileUploadError(err) {
50
+ return err instanceof MobileUploadError;
51
+ }
@@ -0,0 +1,86 @@
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import { ReplaySubject } from 'rxjs/ReplaySubject';
4
+ import { from } from 'rxjs/observable/from';
5
+ import { map } from 'rxjs/operators/map';
6
+ import { mapMediaItemToFileState } from '../../models/file-state';
7
+ import { createFileStateSubject } from '../createFileStateSubject';
8
+ import { isEmptyFile } from '../detectEmptyFile';
9
+ import { PollingFunction } from '../polling';
10
+ import { MobileUploadError } from './error';
11
+ export var createMobileFileStateSubject = function createMobileFileStateSubject(service) {
12
+ var subject = new ReplaySubject(1);
13
+ from(service.start()).pipe(map(function (state) {
14
+ return state.context.currentFileState;
15
+ })).subscribe(subject);
16
+ return subject;
17
+ };
18
+ export var createMobileDownloadFileStream = function createMobileDownloadFileStream(dataloader, id, collectionName, occurrenceKey) {
19
+ var subject = createFileStateSubject();
20
+ var poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
21
+
22
+ poll.onError = function (error) {
23
+ return subject.error(error);
24
+ };
25
+
26
+ poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
27
+ var response, fileState;
28
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
29
+ while (1) {
30
+ switch (_context.prev = _context.next) {
31
+ case 0:
32
+ _context.next = 2;
33
+ return dataloader.load({
34
+ id: id,
35
+ collectionName: collectionName
36
+ });
37
+
38
+ case 2:
39
+ response = _context.sent;
40
+
41
+ if (response) {
42
+ _context.next = 5;
43
+ break;
44
+ }
45
+
46
+ throw new MobileUploadError('emptyItems', id, {
47
+ collectionName: collectionName,
48
+ occurrenceKey: occurrenceKey
49
+ });
50
+
51
+ case 5:
52
+ if (!isEmptyFile(response)) {
53
+ _context.next = 7;
54
+ break;
55
+ }
56
+
57
+ throw new MobileUploadError('zeroVersionFile', id, {
58
+ collectionName: collectionName,
59
+ occurrenceKey: occurrenceKey
60
+ });
61
+
62
+ case 7:
63
+ fileState = mapMediaItemToFileState(id, response);
64
+ subject.next(fileState);
65
+ _context.t0 = fileState.status;
66
+ _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
67
+ break;
68
+
69
+ case 12:
70
+ // the only case for continuing polling, otherwise this function is run once only
71
+ poll.next();
72
+ return _context.abrupt("break", 16);
73
+
74
+ case 14:
75
+ subject.complete();
76
+ return _context.abrupt("break", 16);
77
+
78
+ case 16:
79
+ case "end":
80
+ return _context.stop();
81
+ }
82
+ }
83
+ }, _callee);
84
+ })));
85
+ return subject;
86
+ };
@@ -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,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,3 @@
1
+ export var machineErrorState = {
2
+ type: 'final'
3
+ };
@@ -0,0 +1,3 @@
1
+ export var machineProcessedState = {
2
+ type: 'final'
3
+ };
@@ -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,3 @@
1
+ export var machineProcessingFailedState = {
2
+ type: 'final'
3
+ };
@@ -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: getMediaFeatureFlag('poll_intervalMs'),
15
- poll_maxAttempts: getMediaFeatureFlag('poll_maxAttempts'),
16
- poll_backoffFactor: getMediaFeatureFlag('poll_backoffFactor'),
17
- poll_maxIntervalMs: getMediaFeatureFlag('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:
@@ -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
  }
@@ -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;
@@ -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
+ }
@@ -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 declare type ImageResizeMode = 'crop' | 'fit' | 'full-fit' | 'stretchy-fit';
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';
@@ -39,7 +41,7 @@ export { isFileIdentifier, isExternalImageIdentifier, isDifferentIdentifier, } f
39
41
  export type { Identifier, FileIdentifier, ExternalImageIdentifier, } from './identifier';
40
42
  export type { EventPayloadListener, UploadEventPayloadMap, MediaViewedEventPayload, } from './client/events';
41
43
  export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
42
- export type { WithMediaClientConfig, WithMediaClientConfigProps, } from './utils/with-media-client-hoc';
44
+ export type { WithMediaClientConfig, WithMediaClientConfigProps, WithMediaClientFunction, } from './utils/with-media-client-hoc';
43
45
  export { globalMediaEventEmitter } from './globalMediaEventEmitter';
44
46
  export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString, } from './utils/url';
45
47
  export type { MediaBlobUrlAttrs } from './utils/url';
@@ -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
+ }
@@ -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,3 @@
1
+ import { StateNodeConfig } from 'xstate';
2
+ import { StateMachineContext, StateMachineSchema, StateMachineEvent } from '../types';
3
+ export declare const machineErrorState: StateNodeConfig<StateMachineContext, StateMachineSchema, StateMachineEvent>;
@@ -0,0 +1,3 @@
1
+ import { StateNodeConfig } from 'xstate';
2
+ import { StateMachineContext, StateMachineSchema, StateMachineEvent } from '../types';
3
+ export declare const machineProcessedState: StateNodeConfig<StateMachineContext, StateMachineSchema, StateMachineEvent>;
@@ -0,0 +1,3 @@
1
+ import { StateNodeConfig } from 'xstate';
2
+ import { ProcessingStateMachineSchema, StateMachineContext, StateMachineEvent } from '../types';
3
+ export declare const machineProcessingState: StateNodeConfig<StateMachineContext, ProcessingStateMachineSchema, StateMachineEvent>;
@@ -0,0 +1,3 @@
1
+ import { StateNodeConfig } from 'xstate';
2
+ import { StateMachineContext, StateMachineSchema, StateMachineEvent } from '../types';
3
+ export declare const machineProcessingFailedState: StateNodeConfig<StateMachineContext, StateMachineSchema, StateMachineEvent>;
@@ -0,0 +1,3 @@
1
+ import { StateNodeConfig } from 'xstate';
2
+ import { StateMachineContext, StateMachineSchema, StateMachineEvent } from '../types';
3
+ export declare const machineUploadingState: StateNodeConfig<StateMachineContext, StateMachineSchema, StateMachineEvent>;