@atlaskit/media-client 22.0.0 → 22.0.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 (113) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/constants/package.json +2 -2
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/version.json +1 -1
  5. package/dist/esm/version.json +1 -1
  6. package/dist/types/client/events.d.ts +3 -3
  7. package/dist/types/client/file-fetcher/error.d.ts +2 -2
  8. package/dist/types/client/file-fetcher/index.d.ts +1 -1
  9. package/dist/types/client/media-store/error.d.ts +2 -2
  10. package/dist/types/client/media-store/index.d.ts +15 -15
  11. package/dist/types/client/media-store/resolveAuth.d.ts +2 -2
  12. package/dist/types/identifier.d.ts +1 -1
  13. package/dist/types/models/artifacts.d.ts +1 -1
  14. package/dist/types/models/auth-headers.d.ts +1 -1
  15. package/dist/types/models/auth-query-parameters.d.ts +1 -1
  16. package/dist/types/models/errors/types.d.ts +1 -1
  17. package/dist/types/models/file-state.d.ts +4 -4
  18. package/dist/types/models/item.d.ts +3 -3
  19. package/dist/types/models/media.d.ts +7 -7
  20. package/dist/types/models/mobile-upload.d.ts +4 -4
  21. package/dist/types/upload-controller.d.ts +1 -1
  22. package/dist/types/uploader/error.d.ts +2 -2
  23. package/dist/types/uploader/index.d.ts +4 -4
  24. package/dist/types/utils/createFileDataLoader.d.ts +4 -4
  25. package/dist/types/utils/getDimensionsFromBlob.d.ts +1 -1
  26. package/dist/types/utils/getImageDimensionsFromBlob.d.ts +1 -1
  27. package/dist/types/utils/imageResizeModeToFileImageMode.d.ts +2 -2
  28. package/dist/types/utils/mediaSubscribable/types.d.ts +7 -7
  29. package/dist/types/utils/mobileUpload/error.d.ts +2 -2
  30. package/dist/types/utils/mobileUpload/helpers.d.ts +1 -1
  31. package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +1 -1
  32. package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +5 -5
  33. package/dist/types/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
  34. package/dist/types/utils/polling/types.d.ts +3 -3
  35. package/dist/types/utils/request/types.d.ts +11 -11
  36. package/dist/types/utils/with-media-client-hoc.d.ts +3 -3
  37. package/dist/types-ts4.5/client/__mocks__/collection-fetcher.d.ts +8 -0
  38. package/dist/types-ts4.5/client/__mocks__/file-fetcher.d.ts +10 -0
  39. package/dist/types-ts4.5/client/__mocks__/media-client.d.ts +11 -0
  40. package/dist/types-ts4.5/client/events.d.ts +14 -0
  41. package/dist/types-ts4.5/client/file-fetcher/error.d.ts +29 -0
  42. package/dist/types-ts4.5/client/file-fetcher/index.d.ts +61 -0
  43. package/dist/types-ts4.5/client/media-client.d.ts +27 -0
  44. package/dist/types-ts4.5/client/media-store/error.d.ts +16 -0
  45. package/dist/types-ts4.5/client/media-store/index.d.ts +170 -0
  46. package/dist/types-ts4.5/client/media-store/resolveAuth.d.ts +4 -0
  47. package/dist/types-ts4.5/client/mobile-upload.d.ts +11 -0
  48. package/dist/types-ts4.5/client/stargate-client.d.ts +15 -0
  49. package/dist/types-ts4.5/constants.d.ts +6 -0
  50. package/dist/types-ts4.5/file-streams-cache.d.ts +15 -0
  51. package/dist/types-ts4.5/globalMediaEventEmitter.d.ts +6 -0
  52. package/dist/types-ts4.5/identifier.d.ts +15 -0
  53. package/dist/types-ts4.5/index.d.ts +87 -0
  54. package/dist/types-ts4.5/models/artifacts.d.ts +12 -0
  55. package/dist/types-ts4.5/models/auth-headers.d.ts +11 -0
  56. package/dist/types-ts4.5/models/auth-query-parameters.d.ts +11 -0
  57. package/dist/types-ts4.5/models/errors/helpers.d.ts +6 -0
  58. package/dist/types-ts4.5/models/errors/index.d.ts +11 -0
  59. package/dist/types-ts4.5/models/errors/types.d.ts +15 -0
  60. package/dist/types-ts4.5/models/file-state.d.ts +94 -0
  61. package/dist/types-ts4.5/models/item.d.ts +25 -0
  62. package/dist/types-ts4.5/models/media.d.ts +48 -0
  63. package/dist/types-ts4.5/models/mobile-upload.d.ts +28 -0
  64. package/dist/types-ts4.5/upload-controller.d.ts +7 -0
  65. package/dist/types-ts4.5/uploader/calculateChunkSize.d.ts +11 -0
  66. package/dist/types-ts4.5/uploader/error.d.ts +29 -0
  67. package/dist/types-ts4.5/uploader/index.d.ts +22 -0
  68. package/dist/types-ts4.5/utils/checkWebpSupport.d.ts +1 -0
  69. package/dist/types-ts4.5/utils/convertBase64ToBlob.d.ts +1 -0
  70. package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +30 -0
  71. package/dist/types-ts4.5/utils/createMediaSubject.d.ts +3 -0
  72. package/dist/types-ts4.5/utils/detectEmptyFile.d.ts +16 -0
  73. package/dist/types-ts4.5/utils/getDimensionsFromBlob.d.ts +6 -0
  74. package/dist/types-ts4.5/utils/getImageDimensionsFromBlob.d.ts +5 -0
  75. package/dist/types-ts4.5/utils/getMediaTypeFromUploadableFile.d.ts +3 -0
  76. package/dist/types-ts4.5/utils/getVideoDimensionsFromBlob.d.ts +5 -0
  77. package/dist/types-ts4.5/utils/hashing/hasher.d.ts +3 -0
  78. package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +3 -0
  79. package/dist/types-ts4.5/utils/hashing/simpleHasher.d.ts +4 -0
  80. package/dist/types-ts4.5/utils/hashing/workerHasher.d.ts +16 -0
  81. package/dist/types-ts4.5/utils/imageResizeModeToFileImageMode.d.ts +3 -0
  82. package/dist/types-ts4.5/utils/isImageRemote.d.ts +1 -0
  83. package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +5 -0
  84. package/dist/types-ts4.5/utils/mediaSubscribable/index.d.ts +3 -0
  85. package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +10 -0
  86. package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +17 -0
  87. package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +29 -0
  88. package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +8 -0
  89. package/dist/types-ts4.5/utils/mobileUpload/index.d.ts +5 -0
  90. package/dist/types-ts4.5/utils/mobileUpload/servicesCache.d.ts +4 -0
  91. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +7 -0
  92. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
  93. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
  94. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
  95. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
  96. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
  97. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +69 -0
  98. package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +5 -0
  99. package/dist/types-ts4.5/utils/parseJwt.d.ts +1 -0
  100. package/dist/types-ts4.5/utils/polling/errors.d.ts +12 -0
  101. package/dist/types-ts4.5/utils/polling/index.d.ts +33 -0
  102. package/dist/types-ts4.5/utils/polling/types.d.ts +7 -0
  103. package/dist/types-ts4.5/utils/request/errors.d.ts +20 -0
  104. package/dist/types-ts4.5/utils/request/helpers.d.ts +46 -0
  105. package/dist/types-ts4.5/utils/request/index.d.ts +5 -0
  106. package/dist/types-ts4.5/utils/request/types.d.ts +46 -0
  107. package/dist/types-ts4.5/utils/safeUnsubscribe.d.ts +2 -0
  108. package/dist/types-ts4.5/utils/setTimeoutPromise.d.ts +2 -0
  109. package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +16 -0
  110. package/dist/types-ts4.5/utils/url.d.ts +17 -0
  111. package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +16 -0
  112. package/package.json +13 -5
  113. package/report.api.md +7 -7
@@ -0,0 +1,6 @@
1
+ export type { MediaClientError, MediaClientErrorReason } from './types';
2
+ import { MediaClientError, MediaClientErrorReason } from './types';
3
+ export declare function isMediaClientError(error: any): error is MediaClientError<{
4
+ reason: MediaClientErrorReason;
5
+ }>;
6
+ export declare function getMediaClientErrorReason(err: Error): MediaClientErrorReason | 'unknown';
@@ -0,0 +1,11 @@
1
+ import { MediaClientError, MediaClientErrorAttributes } from './types';
2
+ export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './types';
3
+ export { isMediaClientError, getMediaClientErrorReason } from './helpers';
4
+ /**
5
+ * Base class for media errors
6
+ */
7
+ export declare abstract class BaseMediaClientError<Attributes extends MediaClientErrorAttributes> extends Error implements MediaClientError<Attributes> {
8
+ readonly message: string;
9
+ constructor(message: string);
10
+ abstract get attributes(): Attributes;
11
+ }
@@ -0,0 +1,15 @@
1
+ export type MediaClientErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError' | 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut' | 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'pollingMaxAttemptsExceeded' | 'fileSizeExceedsLimit' | 'deprecatedEndpoint';
2
+ export interface MediaClientErrorAttributes {
3
+ reason: MediaClientErrorReason;
4
+ }
5
+ /**
6
+ * MediaClientError is the main interface which all the errors
7
+ * in Media Client must implement.
8
+ * MediaClientErrorReason is a dictionary that restricts all the possible
9
+ * reasons that the erros can define. Its values are private to this file.
10
+ * Any new error has to define its own Error Reasons locally, and also declare them
11
+ * here to comply with the interface restrictions
12
+ */
13
+ export interface MediaClientError<Attributes extends MediaClientErrorAttributes> extends Error {
14
+ readonly attributes: Attributes;
15
+ }
@@ -0,0 +1,94 @@
1
+ import { FileStatus as CommonFileStatus, MediaTraceContext } from '@atlaskit/media-common';
2
+ import { MediaStoreResponse } from '../client/media-store';
3
+ import { MediaFileArtifacts } from './artifacts';
4
+ import { MediaItemDetails, MediaFile, MediaRepresentations, MediaType } from './media';
5
+ export type BaseFileState = {
6
+ metadataTraceContext?: MediaTraceContext;
7
+ };
8
+ export type FileStatus = CommonFileStatus;
9
+ export interface FilePreview {
10
+ value: Blob | string;
11
+ origin?: 'local' | 'remote';
12
+ originalDimensions?: {
13
+ width: number;
14
+ height: number;
15
+ };
16
+ }
17
+ export interface PreviewOptions {
18
+ }
19
+ export interface GetFileOptions {
20
+ preview?: PreviewOptions;
21
+ collectionName?: string;
22
+ occurrenceKey?: string;
23
+ }
24
+ export interface UploadingFileState extends BaseFileState {
25
+ status: 'uploading';
26
+ id: string;
27
+ occurrenceKey?: string;
28
+ name: string;
29
+ size: number;
30
+ progress: number;
31
+ mediaType: MediaType;
32
+ mimeType: string;
33
+ preview?: FilePreview | Promise<FilePreview>;
34
+ createdAt?: number;
35
+ }
36
+ export interface PreviewableFileState {
37
+ preview: FilePreview | Promise<FilePreview>;
38
+ }
39
+ export interface ProcessingFileState extends BaseFileState {
40
+ status: 'processing';
41
+ id: string;
42
+ occurrenceKey?: string;
43
+ name: string;
44
+ size: number;
45
+ artifacts?: MediaFileArtifacts;
46
+ mediaType: MediaType;
47
+ mimeType: string;
48
+ preview?: FilePreview | Promise<FilePreview>;
49
+ representations?: MediaRepresentations;
50
+ createdAt?: number;
51
+ }
52
+ export interface ProcessedFileState extends BaseFileState {
53
+ status: 'processed';
54
+ id: string;
55
+ occurrenceKey?: string;
56
+ name: string;
57
+ size: number;
58
+ artifacts: MediaFileArtifacts;
59
+ mediaType: MediaType;
60
+ mimeType: string;
61
+ preview?: FilePreview | Promise<FilePreview>;
62
+ representations?: MediaRepresentations;
63
+ createdAt?: number;
64
+ }
65
+ export interface ProcessingFailedState extends BaseFileState {
66
+ status: 'failed-processing';
67
+ id: string;
68
+ occurrenceKey?: string;
69
+ name: string;
70
+ size: number;
71
+ artifacts: Object;
72
+ mediaType: MediaType;
73
+ mimeType: string;
74
+ preview?: FilePreview | Promise<FilePreview>;
75
+ representations?: MediaRepresentations;
76
+ createdAt?: number;
77
+ }
78
+ export interface ErrorFileState extends BaseFileState {
79
+ status: 'error';
80
+ id: string;
81
+ occurrenceKey?: string;
82
+ message?: string;
83
+ }
84
+ export type FileState = UploadingFileState | ProcessingFileState | ProcessedFileState | ErrorFileState | ProcessingFailedState;
85
+ export type NonErrorFileState = Exclude<FileState, ErrorFileState>;
86
+ export declare const isUploadingFileState: (fileState: FileState) => fileState is UploadingFileState;
87
+ export declare const isProcessingFileState: (fileState: FileState) => fileState is ProcessingFileState;
88
+ export declare const isProcessedFileState: (fileState: FileState) => fileState is ProcessedFileState;
89
+ export declare const isErrorFileState: (fileState: FileState) => fileState is ErrorFileState;
90
+ export declare const isPreviewableFileState: (fileState: FileState) => fileState is (UploadingFileState | ProcessingFileState | ProcessedFileState | ProcessingFailedState) & PreviewableFileState;
91
+ export declare const isFinalFileState: (fileState: FileState) => fileState is ProcessedFileState | ProcessingFailedState | ErrorFileState;
92
+ export declare const isImageRepresentationReady: (fileState: FileState) => boolean;
93
+ export declare const mapMediaFileToFileState: (mediaFile: MediaStoreResponse<MediaFile>) => FileState;
94
+ export declare const mapMediaItemToFileState: (id: string, item: MediaItemDetails) => FileState;
@@ -0,0 +1,25 @@
1
+ import { MediaType } from './media';
2
+ export type MediaItemType = 'file' | 'external-image';
3
+ export interface FileItem {
4
+ type: 'file';
5
+ details: FileDetails;
6
+ }
7
+ export type FileProcessingStatus = 'pending' | 'running' | 'succeeded' | 'failed';
8
+ export interface MediaArtifact {
9
+ processingStatus?: FileProcessingStatus;
10
+ url?: string;
11
+ }
12
+ export type Artifacts = {
13
+ [name: string]: MediaArtifact;
14
+ };
15
+ export interface FileDetails {
16
+ id: string;
17
+ name?: string;
18
+ size?: number;
19
+ mimeType?: string;
20
+ mediaType?: MediaType;
21
+ creationDate?: number;
22
+ processingStatus?: FileProcessingStatus;
23
+ artifacts?: Artifacts;
24
+ createdAt?: number;
25
+ }
@@ -0,0 +1,48 @@
1
+ import { MediaFeatureFlags, MediaTraceContext, MediaType } from '@atlaskit/media-common';
2
+ import type { MediaFileArtifacts } from './artifacts';
3
+ export type MediaFileProcessingStatus = 'pending' | 'succeeded' | 'failed';
4
+ export type { MediaType } from '@atlaskit/media-common';
5
+ export declare const isPreviewableType: (type: MediaType, featureFlags?: MediaFeatureFlags) => boolean;
6
+ export type MediaFile = {
7
+ readonly id: string;
8
+ readonly mediaType: MediaType;
9
+ readonly mimeType: string;
10
+ readonly name: string;
11
+ readonly processingStatus?: MediaFileProcessingStatus;
12
+ readonly size: number;
13
+ readonly artifacts: MediaFileArtifacts;
14
+ readonly representations: MediaRepresentations;
15
+ readonly createdAt?: number;
16
+ readonly metadataTraceContext?: MediaTraceContext;
17
+ };
18
+ export type MediaItemDetails = {
19
+ readonly mediaType: MediaType;
20
+ readonly mimeType: string;
21
+ readonly name: string;
22
+ readonly processingStatus: MediaFileProcessingStatus;
23
+ readonly size: number;
24
+ readonly artifacts: MediaFileArtifacts;
25
+ readonly representations: MediaRepresentations;
26
+ readonly createdAt?: number;
27
+ readonly metadataTraceContext?: MediaTraceContext;
28
+ };
29
+ export type MediaRepresentations = {
30
+ image?: Object;
31
+ };
32
+ export type MediaUpload = {
33
+ readonly id: string;
34
+ readonly created: number;
35
+ readonly expires: number;
36
+ };
37
+ export type MediaChunksProbe = {
38
+ readonly results: {
39
+ readonly [etag: string]: {
40
+ readonly exists: boolean;
41
+ };
42
+ };
43
+ };
44
+ export declare enum DATA_UNIT {
45
+ MB = 1048576,
46
+ GB = 1073741824,
47
+ TB = 1099511627776
48
+ }
@@ -0,0 +1,28 @@
1
+ import { FilePreview } from './file-state';
2
+ export 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 type MobileUploadProgressEvent = {
13
+ fileId: string;
14
+ progress: number;
15
+ };
16
+ export type MobileUploadEndEvent = {
17
+ fileId: string;
18
+ };
19
+ export 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,7 @@
1
+ export type AbortFunction = () => void;
2
+ export declare class UploadController {
3
+ abortFunction?: AbortFunction;
4
+ constructor();
5
+ setAbort(abortFunction: AbortFunction): void;
6
+ abort(): void;
7
+ }
@@ -0,0 +1,11 @@
1
+ export declare const fileSizeError = "fileSizeExceedsLimit";
2
+ /**
3
+ * This is a helper to dynamically calculate the chunk size for a given file size.
4
+ *
5
+ * @param fileSize The size of a file to calculate the chunk size for.
6
+ * @returns A number of bytes per chunk or Throws an Error if the file size exceeds 2TB
7
+ *
8
+ * @see {@link https://product-fabric.atlassian.net/wiki/spaces/FIL/pages/3221881143/Rule+of+thumb+for+chunk+sizes#Given-the-following-conditions}
9
+ *
10
+ */
11
+ export declare const calculateChunkSize: (fileSize: number) => number;
@@ -0,0 +1,29 @@
1
+ import { BaseMediaClientError } from '../models/errors';
2
+ export type UploaderErrorReason = 'fileSizeExceedsLimit';
3
+ export type UploaderErrorAttributes = {
4
+ readonly reason: UploaderErrorReason;
5
+ readonly id: string;
6
+ readonly metadata?: {
7
+ readonly collectionName?: string;
8
+ readonly occurrenceKey?: string;
9
+ };
10
+ };
11
+ export declare class UploaderError extends BaseMediaClientError<UploaderErrorAttributes> {
12
+ readonly reason: UploaderErrorReason;
13
+ readonly id: string;
14
+ readonly metadata?: {
15
+ readonly collectionName?: string | undefined;
16
+ readonly occurrenceKey?: string | undefined;
17
+ } | undefined;
18
+ constructor(reason: UploaderErrorReason, id: string, metadata?: {
19
+ readonly collectionName?: string | undefined;
20
+ readonly occurrenceKey?: string | undefined;
21
+ } | undefined);
22
+ get attributes(): {
23
+ reason: "fileSizeExceedsLimit";
24
+ id: string;
25
+ collectionName: string | undefined;
26
+ occurrenceKey: string | undefined;
27
+ };
28
+ }
29
+ export declare function isUploaderError(err: Error): err is UploaderError;
@@ -0,0 +1,22 @@
1
+ import { ChunkinatorFile } from '@atlaskit/chunkinator';
2
+ import { MediaStore } from '../client/media-store';
3
+ import { MediaTraceContext } from '@atlaskit/media-common';
4
+ export type UploadableFile = {
5
+ content: ChunkinatorFile;
6
+ name?: string;
7
+ mimeType?: string;
8
+ collection?: string;
9
+ };
10
+ export type UploadableFileUpfrontIds = {
11
+ id: string;
12
+ deferredUploadId: Promise<string>;
13
+ occurrenceKey?: string;
14
+ };
15
+ export type UploadFileCallbacks = {
16
+ onProgress: (progress: number) => void;
17
+ onUploadFinish: (error?: any) => void;
18
+ };
19
+ export interface UploadFileResult {
20
+ cancel: () => void;
21
+ }
22
+ export declare const uploadFile: (file: UploadableFile, store: MediaStore, uploadableFileUpfrontIds: UploadableFileUpfrontIds, callbacks?: UploadFileCallbacks, traceContext?: MediaTraceContext) => UploadFileResult;
@@ -0,0 +1 @@
1
+ export declare const checkWebpSupport: () => Promise<boolean>;
@@ -0,0 +1 @@
1
+ export declare const convertBase64ToBlob: (base64: string) => Blob;
@@ -0,0 +1,30 @@
1
+ import 'setimmediate';
2
+ import Dataloader from 'dataloader';
3
+ import { MediaStore, ResponseFileItem } from '../client/media-store';
4
+ import { MediaItemDetails } from '../models/media';
5
+ export declare const MAX_BATCH_SIZE = 100;
6
+ export type DataloaderKey = {
7
+ readonly id: string;
8
+ readonly collectionName?: string;
9
+ };
10
+ export type DataloaderResult = MediaItemDetails | null;
11
+ export type BatchLoadingErrorResult = {
12
+ readonly id: string;
13
+ readonly collection?: string;
14
+ readonly error: Error;
15
+ };
16
+ export declare const getItemsFromKeys: (dataloaderKeys: ReadonlyArray<DataloaderKey>, fileItems: Array<ResponseFileItem | BatchLoadingErrorResult>) => Array<DataloaderResult | Error>;
17
+ export type FileIdsByCollection = {
18
+ [collectionName: string]: string[];
19
+ };
20
+ /**
21
+ * Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
22
+ * Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
23
+ *
24
+ * If an Error is resolved in the results, it must be at same position then their corresponding key:
25
+ * - Dataloader will re-throw that Error when accessing/loading that particular key
26
+ *
27
+ * @param mediaStore instance of MediaStore
28
+ */
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 { ReplaySubject } from 'rxjs/ReplaySubject';
2
+ import { FileState } from '../models/file-state';
3
+ export declare function createMediaSubject<T extends FileState>(initialState?: T | Error): ReplaySubject<T>;
@@ -0,0 +1,16 @@
1
+ import { MediaItemDetails } from '../models/media';
2
+ /**
3
+ * EMPTY_FILE_HOURS_ELAPSED_TOLERANCE - how many hours since this file was
4
+ * created until we give up on expecting metadata?
5
+ *
6
+ * Yes, this is not an exact science. Any value under this tolerance will
7
+ * go undetected, however this is still suitable to catch the majority of
8
+ * cases where empty (files which never finished upload) are being reloaded.
9
+ *
10
+ * Continuous bad renders of empty files will eat our card render SLIs, so until
11
+ * there is a better response from backend we use this technique.
12
+ *
13
+ * Being encapsulated in this function, we can always improve the detection transparently.
14
+ */
15
+ export declare const EMPTY_FILE_HOURS_ELAPSED_TOLERANCE_MS: number;
16
+ export declare function isEmptyFile(fileDetails: MediaItemDetails, now?: number): Boolean;
@@ -0,0 +1,6 @@
1
+ import { MediaType } from '@atlaskit/media-common';
2
+ export type Dimensions = {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare const getDimensionsFromBlob: (mediaType: MediaType, blob: Blob) => Promise<Dimensions>;
@@ -0,0 +1,5 @@
1
+ export type Dimensions = {
2
+ width: number;
3
+ height: number;
4
+ };
5
+ export declare const getImageDimensionsFromBlob: (url: string) => Promise<Dimensions>;
@@ -0,0 +1,3 @@
1
+ import { MediaType } from '../models/media';
2
+ import { UploadableFile } from '../uploader';
3
+ export declare const getMediaTypeFromUploadableFile: (file: UploadableFile) => MediaType;
@@ -0,0 +1,5 @@
1
+ export interface Dimensions {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ export declare const getVideoDimensionsFromBlob: (blob: Blob) => Promise<Dimensions>;
@@ -0,0 +1,3 @@
1
+ export interface Hasher {
2
+ hash(blob: Blob): Promise<string>;
3
+ }
@@ -0,0 +1,3 @@
1
+ import { Hasher } from './hasher';
2
+ export declare const destroyHasher: () => null;
3
+ export declare const createHasher: () => Promise<Hasher>;
@@ -0,0 +1,4 @@
1
+ import { Hasher } from './hasher';
2
+ export declare class SimpleHasher implements Hasher {
3
+ hash(blob: Blob): Promise<string>;
4
+ }
@@ -0,0 +1,16 @@
1
+ import { Hasher } from './hasher';
2
+ export interface Deferred {
3
+ resolve: (hash: string) => void;
4
+ reject: (error: any) => void;
5
+ }
6
+ export declare class WorkerHasher implements Hasher {
7
+ private workers;
8
+ private jobs;
9
+ constructor(numOfWorkers: number);
10
+ hash(chunk: Blob): Promise<string>;
11
+ private createWorker;
12
+ private handleWorkerMessage;
13
+ private calculateHashInWorker;
14
+ private dispatch;
15
+ private getMostRelaxedWorker;
16
+ }
@@ -0,0 +1,3 @@
1
+ import { MediaStoreGetFileImageParams } from '../client/media-store';
2
+ export type ImageResizeMode = 'crop' | 'fit' | 'full-fit' | 'stretchy-fit';
3
+ export declare const imageResizeModeToFileImageMode: (resizeMode?: ImageResizeMode) => MediaStoreGetFileImageParams['mode'];
@@ -0,0 +1 @@
1
+ export declare const isImageRemote: (imageUrl: string, windowOrigin?: string) => boolean;
@@ -0,0 +1,5 @@
1
+ import { ReplaySubject } from 'rxjs/ReplaySubject';
2
+ import { FileState } from '../../models/file-state';
3
+ import { MediaSubscribable } from './types';
4
+ export declare function fromObservable(observable: ReplaySubject<FileState>): MediaSubscribable;
5
+ export declare function createMediaSubscribable(item?: FileState | Error): MediaSubscribable;
@@ -0,0 +1,3 @@
1
+ export type { MediaSubscribable, MediaObserver, MediaSubscription, } from './types';
2
+ export { toPromise } from './toPromise';
3
+ export { createMediaSubscribable, fromObservable } from './fromObservable';
@@ -0,0 +1,10 @@
1
+ import { Subscription } from 'rxjs/Subscription';
2
+ import { MediaSubscribable } from './types';
3
+ import { FileState } from '../../models/file-state';
4
+ /**
5
+ * This is a helper to transform the first value emitted by an MediaSubscribable into a Promise.
6
+ *
7
+ * @param mediaSubscribable a given MediaSubscribable<MediaSubscribableItem>
8
+ * @param subscription a default Subscription (this parameter exists for testing purpose)
9
+ */
10
+ export declare const toPromise: (mediaSubscribable: MediaSubscribable, subscription?: Subscription) => Promise<FileState>;
@@ -0,0 +1,17 @@
1
+ import { FileState } from '../../models/file-state';
2
+ export type MediaSubscription = {
3
+ unsubscribe: () => void;
4
+ };
5
+ type PartialObserver = {
6
+ next?: (value: FileState) => void;
7
+ error?: (err: any) => void;
8
+ complete?: () => void;
9
+ };
10
+ export type NextObserver = PartialObserver & Required<Pick<PartialObserver, 'next'>>;
11
+ export type ErrorObserver = PartialObserver & Required<Pick<PartialObserver, 'error'>>;
12
+ export type CompletionObserver = PartialObserver & Required<Pick<PartialObserver, 'complete'>>;
13
+ export type MediaObserver = NextObserver | ErrorObserver | CompletionObserver | ((value: FileState) => void);
14
+ export type MediaSubscribable = {
15
+ subscribe(observer?: MediaObserver): MediaSubscription;
16
+ };
17
+ export {};
@@ -0,0 +1,29 @@
1
+ import { BaseMediaClientError } from '../../models/errors';
2
+ export type MobileUploadErrorReason = 'emptyItems' | 'zeroVersionFile';
3
+ export 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, occurrenceKey?: string) => 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 { LRUMap } from 'lru_map';
2
+ import { Interpreter } from 'xstate';
3
+ import { StateMachineContext, StateMachineEvent, StateMachineTypestate } from './stateMachine/types';
4
+ export declare function createServicesCache(): LRUMap<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) => 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>;
@@ -0,0 +1,69 @@
1
+ import { StateSchema } from 'xstate';
2
+ import { FileState, UploadingFileState, ProcessingFileState, ProcessedFileState, ErrorFileState, ProcessingFailedState } from '../../../models/file-state';
3
+ export type StateMachineContext = {
4
+ currentFileState: FileState;
5
+ };
6
+ export 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 type ProcessingStateMachineSchema = StateSchema<StateMachineContext> & {
29
+ states: {
30
+ loading: StateSchema<StateMachineContext>;
31
+ fetchingRemoteFileStates: StateSchema<StateMachineContext>;
32
+ idle: StateSchema<StateMachineContext>;
33
+ };
34
+ };
35
+ export 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 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
+ };