@atlaskit/media-client 17.1.2 → 17.1.3
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 +7 -0
- package/constants/package.json +8 -1
- package/dist/cjs/client/media-store/resolveAuth.js +1 -1
- package/dist/cjs/utils/request/helpers.js +4 -4
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/media-store/resolveAuth.js +1 -1
- package/dist/es2019/utils/request/helpers.js +4 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/media-store/resolveAuth.js +1 -1
- package/dist/esm/utils/request/helpers.js +4 -4
- package/dist/esm/version.json +1 -1
- package/dist/types-ts4.0/client/__mocks__/collection-fetcher.d.ts +8 -0
- package/dist/types-ts4.0/client/__mocks__/file-fetcher.d.ts +10 -0
- package/dist/types-ts4.0/client/__mocks__/media-client.d.ts +13 -0
- package/dist/types-ts4.0/client/collection-fetcher.d.ts +35 -0
- package/dist/types-ts4.0/client/events.d.ts +14 -0
- package/dist/types-ts4.0/client/file-fetcher/error.d.ts +29 -0
- package/dist/types-ts4.0/client/file-fetcher/index.d.ts +56 -0
- package/dist/types-ts4.0/client/media-client.d.ts +28 -0
- package/dist/types-ts4.0/client/media-store/error.d.ts +16 -0
- package/dist/types-ts4.0/client/media-store/index.d.ts +167 -0
- package/dist/types-ts4.0/client/media-store/resolveAuth.d.ts +4 -0
- package/dist/types-ts4.0/client/mobile-upload.d.ts +11 -0
- package/dist/types-ts4.0/client/stargate-client.d.ts +15 -0
- package/dist/types-ts4.0/constants.d.ts +6 -0
- package/dist/types-ts4.0/file-streams-cache.d.ts +15 -0
- package/dist/types-ts4.0/globalMediaEventEmitter.d.ts +6 -0
- package/dist/types-ts4.0/identifier.d.ts +15 -0
- package/dist/types-ts4.0/index.d.ts +90 -0
- package/dist/types-ts4.0/models/artifacts.d.ts +12 -0
- package/dist/types-ts4.0/models/auth-headers.d.ts +11 -0
- package/dist/types-ts4.0/models/auth-query-parameters.d.ts +11 -0
- package/dist/types-ts4.0/models/errors/helpers.d.ts +6 -0
- package/dist/types-ts4.0/models/errors/index.d.ts +11 -0
- package/dist/types-ts4.0/models/errors/types.d.ts +15 -0
- package/dist/types-ts4.0/models/file-state.d.ts +91 -0
- package/dist/types-ts4.0/models/item.d.ts +25 -0
- package/dist/types-ts4.0/models/media-subscribable.d.ts +3 -0
- package/dist/types-ts4.0/models/media.d.ts +66 -0
- package/dist/types-ts4.0/models/mobile-upload.d.ts +28 -0
- package/dist/types-ts4.0/upload-controller.d.ts +7 -0
- package/dist/types-ts4.0/uploader/calculateChunkSize.d.ts +11 -0
- package/dist/types-ts4.0/uploader/error.d.ts +29 -0
- package/dist/types-ts4.0/uploader/index.d.ts +21 -0
- package/dist/types-ts4.0/utils/checkWebpSupport.d.ts +1 -0
- package/dist/types-ts4.0/utils/convertBase64ToBlob.d.ts +1 -0
- package/dist/types-ts4.0/utils/createFileDataLoader.d.ts +30 -0
- package/dist/types-ts4.0/utils/createMediaSubject.d.ts +3 -0
- package/dist/types-ts4.0/utils/detectEmptyFile.d.ts +16 -0
- package/dist/types-ts4.0/utils/getDimensionsFromBlob.d.ts +6 -0
- package/dist/types-ts4.0/utils/getImageDimensionsFromBlob.d.ts +5 -0
- package/dist/types-ts4.0/utils/getMediaTypeFromUploadableFile.d.ts +3 -0
- package/dist/types-ts4.0/utils/getVideoDimensionsFromBlob.d.ts +6 -0
- package/dist/types-ts4.0/utils/hashing/hasher.d.ts +3 -0
- package/dist/types-ts4.0/utils/hashing/hasherCreator.d.ts +3 -0
- package/dist/types-ts4.0/utils/hashing/simpleHasher.d.ts +4 -0
- package/dist/types-ts4.0/utils/hashing/workerHasher.d.ts +16 -0
- package/dist/types-ts4.0/utils/imageResizeModeToFileImageMode.d.ts +3 -0
- package/dist/types-ts4.0/utils/isImageRemote.d.ts +1 -0
- package/dist/types-ts4.0/utils/mediaSubscribable/fromObservable.d.ts +5 -0
- package/dist/types-ts4.0/utils/mediaSubscribable/index.d.ts +3 -0
- package/dist/types-ts4.0/utils/mediaSubscribable/toPromise.d.ts +10 -0
- package/dist/types-ts4.0/utils/mediaSubscribable/types.d.ts +16 -0
- package/dist/types-ts4.0/utils/mobileUpload/error.d.ts +29 -0
- package/dist/types-ts4.0/utils/mobileUpload/helpers.d.ts +8 -0
- package/dist/types-ts4.0/utils/mobileUpload/index.d.ts +5 -0
- package/dist/types-ts4.0/utils/mobileUpload/servicesCache.d.ts +4 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/index.d.ts +7 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
- package/dist/types-ts4.0/utils/mobileUpload/stateMachine/types.d.ts +69 -0
- package/dist/types-ts4.0/utils/overrideMediaTypeIfUnknown.d.ts +5 -0
- package/dist/types-ts4.0/utils/polling/errors.d.ts +12 -0
- package/dist/types-ts4.0/utils/polling/index.d.ts +33 -0
- package/dist/types-ts4.0/utils/polling/types.d.ts +7 -0
- package/dist/types-ts4.0/utils/request/errors.d.ts +20 -0
- package/dist/types-ts4.0/utils/request/helpers.d.ts +38 -0
- package/dist/types-ts4.0/utils/request/index.d.ts +5 -0
- package/dist/types-ts4.0/utils/request/types.d.ts +43 -0
- package/dist/types-ts4.0/utils/safeUnsubscribe.d.ts +2 -0
- package/dist/types-ts4.0/utils/setTimeoutPromise.d.ts +2 -0
- package/dist/types-ts4.0/utils/shouldFetchRemoteFileStates.d.ts +16 -0
- package/dist/types-ts4.0/utils/url.d.ts +17 -0
- package/dist/types-ts4.0/utils/with-media-client-hoc.d.ts +16 -0
- package/package.json +10 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type MediaSubscription = {
|
|
2
|
+
unsubscribe: () => void;
|
|
3
|
+
};
|
|
4
|
+
declare type PartialObserver<T> = {
|
|
5
|
+
next?: (value: T) => void;
|
|
6
|
+
error?: (err: any) => void;
|
|
7
|
+
complete?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare type NextObserver<T> = PartialObserver<T> & Required<Pick<PartialObserver<T>, 'next'>>;
|
|
10
|
+
export declare type ErrorObserver<T> = PartialObserver<T> & Required<Pick<PartialObserver<T>, 'error'>>;
|
|
11
|
+
export declare type CompletionObserver<T> = PartialObserver<T> & Required<Pick<PartialObserver<T>, 'complete'>>;
|
|
12
|
+
export declare type MediaObserver<T> = NextObserver<T> | ErrorObserver<T> | CompletionObserver<T> | ((value: T) => void);
|
|
13
|
+
export declare type MediaSubscribable<T> = {
|
|
14
|
+
subscribe(observer?: MediaObserver<T>): MediaSubscription;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseMediaClientError } from '../../models/errors';
|
|
2
|
+
import { PollingErrorReason, PollingErrorAttributes } from './types';
|
|
3
|
+
export declare class PollingError extends BaseMediaClientError<PollingErrorAttributes> {
|
|
4
|
+
readonly reason: PollingErrorReason;
|
|
5
|
+
readonly attempts: number;
|
|
6
|
+
constructor(reason: PollingErrorReason, attempts: number);
|
|
7
|
+
get attributes(): {
|
|
8
|
+
reason: "pollingMaxAttemptsExceeded";
|
|
9
|
+
attempts: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function isPollingError(err?: Error): err is PollingError;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Executor } from './types';
|
|
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;
|
|
9
|
+
/**
|
|
10
|
+
* This class encapsulates polling functionality with the following features:
|
|
11
|
+
*
|
|
12
|
+
* - async executor function provides each attempt
|
|
13
|
+
* - executor will only repeat defined max amount of times (options)
|
|
14
|
+
* - each attempt uses a timeout to the next attempt by an interval (ms)
|
|
15
|
+
* - each attempt increases the timeout interval by a "poll_backoffFactor"
|
|
16
|
+
* - if max attempts are exceeded or executor has exception then onError handler is called
|
|
17
|
+
*
|
|
18
|
+
* IMPORTANT! the executor function must explicitly call ".next()" for the next iteration to run
|
|
19
|
+
*/
|
|
20
|
+
export declare class PollingFunction {
|
|
21
|
+
options: PollingOptions;
|
|
22
|
+
poll_intervalMs: number;
|
|
23
|
+
attempt: number;
|
|
24
|
+
shouldIterate: boolean;
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
timeoutId: number;
|
|
27
|
+
constructor(options?: Partial<PollingOptions>);
|
|
28
|
+
execute(executor: Executor): Promise<void>;
|
|
29
|
+
private fail;
|
|
30
|
+
getIntervalMsForIteration(iteration: number): number;
|
|
31
|
+
next(): void;
|
|
32
|
+
cancel(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type Executor = () => Promise<void>;
|
|
2
|
+
export declare type PollingErrorReason = 'pollingMaxAttemptsExceeded';
|
|
3
|
+
export declare type PollingErrorAttributes = {
|
|
4
|
+
readonly reason: PollingErrorReason;
|
|
5
|
+
readonly attempts: number;
|
|
6
|
+
readonly innerError?: Error;
|
|
7
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseMediaClientError } from '../../models/errors';
|
|
2
|
+
import { RequestErrorReason, RequestErrorMetadata, RequestErrorAttributes } from './types';
|
|
3
|
+
export declare class RequestError extends BaseMediaClientError<RequestErrorAttributes> {
|
|
4
|
+
readonly reason: RequestErrorReason;
|
|
5
|
+
readonly metadata?: RequestErrorMetadata | undefined;
|
|
6
|
+
readonly innerError?: Error | undefined;
|
|
7
|
+
constructor(reason: RequestErrorReason, metadata?: RequestErrorMetadata | undefined, innerError?: Error | undefined);
|
|
8
|
+
get attributes(): {
|
|
9
|
+
reason: RequestErrorReason;
|
|
10
|
+
method: import("./types").RequestMethod | undefined;
|
|
11
|
+
endpoint: string | undefined;
|
|
12
|
+
mediaRegion: string | undefined;
|
|
13
|
+
mediaEnv: string | undefined;
|
|
14
|
+
attempts: number | undefined;
|
|
15
|
+
clientExhaustedRetries: boolean | undefined;
|
|
16
|
+
statusCode: number | undefined;
|
|
17
|
+
innerError: Error | undefined;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare function isRequestError(err: Error): err is RequestError;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Auth } from '@atlaskit/media-core';
|
|
2
|
+
import { RequestError } from './errors';
|
|
3
|
+
import { CreateUrlOptions, RequestErrorReason, RequestErrorMetadata, RequestHeaders, RequestMetadata, RetryOptions } from './types';
|
|
4
|
+
export declare function clientTimeoutPromise(timeout: number): Promise<Response>;
|
|
5
|
+
export declare function waitPromise(timeout: number): Promise<void>;
|
|
6
|
+
export declare function isAbortedRequestError(err: any): boolean;
|
|
7
|
+
export declare function isFetchNetworkError(err: any): err is TypeError;
|
|
8
|
+
export declare function isRateLimitedError(error: Error | undefined): boolean;
|
|
9
|
+
export declare function mapAuthToRequestHeaders(auth: Auth): RequestHeaders;
|
|
10
|
+
export declare function createUrl(url: string, { params, auth }: CreateUrlOptions): string;
|
|
11
|
+
export declare function withAuth(auth?: Auth): (headers?: RequestHeaders | undefined) => RequestHeaders | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
14
|
+
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
15
|
+
*/
|
|
16
|
+
export declare function mapResponseToJson(response: Response): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
19
|
+
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
20
|
+
*/
|
|
21
|
+
export declare function mapResponseToBlob(response: Response): Promise<Blob>;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
24
|
+
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
25
|
+
*/
|
|
26
|
+
export declare function mapResponseToVoid(): Promise<void>;
|
|
27
|
+
export declare function createMapResponseToJson(metadata: RequestMetadata): (response: Response) => Promise<any>;
|
|
28
|
+
export declare function createMapResponseToBlob(metadata: RequestMetadata): (response: Response) => Promise<Blob>;
|
|
29
|
+
export declare const DEFAULT_RETRY_OPTIONS: RetryOptions;
|
|
30
|
+
export declare function cloneRequestError(error: RequestError, extraMetadata: Partial<RequestErrorMetadata>): RequestError;
|
|
31
|
+
export declare function fetchRetry(functionToRetry: () => Promise<Response>, metadata: RequestMetadata, overwriteOptions?: Partial<RetryOptions>): Promise<Response>;
|
|
32
|
+
export declare function createRequestErrorReason(statusCode: number): RequestErrorReason;
|
|
33
|
+
export declare function createRequestErrorFromResponse(metadata: RequestErrorMetadata, response: Response): RequestError;
|
|
34
|
+
export declare function createProcessFetchResponse(metadata: RequestMetadata): (response: Response) => Response;
|
|
35
|
+
export declare function extractMediaHeaders(response: Response): {
|
|
36
|
+
mediaRegion: string;
|
|
37
|
+
mediaEnv: string;
|
|
38
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RequestOptions } from './types';
|
|
2
|
+
export type { RequestErrorReason, RequestErrorMetadata, RequestErrorAttributes, } from './types';
|
|
3
|
+
export { RequestError, isRequestError } from './errors';
|
|
4
|
+
export { isRateLimitedError } from './helpers';
|
|
5
|
+
export declare function request(url: string, options?: RequestOptions, controller?: AbortController): Promise<Response>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Auth } from '@atlaskit/media-core';
|
|
2
|
+
export declare type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
export declare type RequestParams = {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
export declare type RequestHeaders = {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type RetryOptions = {
|
|
10
|
+
readonly startTimeoutInMs: number;
|
|
11
|
+
readonly maxAttempts: number;
|
|
12
|
+
readonly factor: number;
|
|
13
|
+
};
|
|
14
|
+
export declare type ClientOptions = {
|
|
15
|
+
readonly retryOptions?: Partial<RetryOptions>;
|
|
16
|
+
readonly clientTimeout?: number;
|
|
17
|
+
};
|
|
18
|
+
export declare type RequestMetadata = {
|
|
19
|
+
readonly method?: RequestMethod;
|
|
20
|
+
readonly endpoint?: string;
|
|
21
|
+
readonly mediaRegion?: string;
|
|
22
|
+
readonly mediaEnv?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare type RequestOptions = RequestMetadata & {
|
|
25
|
+
readonly auth?: Auth;
|
|
26
|
+
readonly params?: RequestParams;
|
|
27
|
+
readonly headers?: RequestHeaders;
|
|
28
|
+
readonly body?: any;
|
|
29
|
+
readonly clientOptions?: ClientOptions;
|
|
30
|
+
};
|
|
31
|
+
export declare type CreateUrlOptions = {
|
|
32
|
+
readonly params?: RequestParams;
|
|
33
|
+
readonly auth?: Auth;
|
|
34
|
+
};
|
|
35
|
+
export declare type RequestErrorReason = 'clientOffline' | 'clientAbortedRequest' | 'clientTimeoutRequest' | 'serverInvalidBody' | 'serverBadRequest' | 'serverUnauthorized' | 'serverForbidden' | 'serverNotFound' | 'serverRateLimited' | 'serverInternalError' | 'serverBadGateway' | 'serverUnexpectedError';
|
|
36
|
+
export declare type RequestErrorMetadata = RequestMetadata & {
|
|
37
|
+
readonly attempts?: number;
|
|
38
|
+
readonly clientExhaustedRetries?: boolean;
|
|
39
|
+
readonly statusCode?: number;
|
|
40
|
+
};
|
|
41
|
+
export declare type RequestErrorAttributes = RequestErrorMetadata & {
|
|
42
|
+
readonly reason: RequestErrorReason;
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Observable } from 'rxjs/Observable';
|
|
2
|
+
import { FilePreview } from '../models/file-state';
|
|
3
|
+
import { MediaType } from '../models/media';
|
|
4
|
+
/**
|
|
5
|
+
* Async helper determining if we should fetch remote fileStates from the backend:
|
|
6
|
+
* - we poll the backend for all supported documents,
|
|
7
|
+
* - we poll the backend is mimeType isn't natively supported by the browser,
|
|
8
|
+
* - we poll the backend if we don't have a local preview available.
|
|
9
|
+
* - we poll the backend if we have a video with which we can't extract dimensions,
|
|
10
|
+
*
|
|
11
|
+
* Polling the backend periodically refreshes the cached fileState until the file is processed.
|
|
12
|
+
* Polling is needed for the use cases above to properly render the file in our components.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function shouldFetchRemoteFileStates(mediaType: MediaType, mimeType: string, preview?: FilePreview | Promise<FilePreview>): Promise<boolean>;
|
|
16
|
+
export declare function shouldFetchRemoteFileStatesObservable(mediaType: MediaType, mimeType: string, preview?: FilePreview | Promise<FilePreview>): Observable<boolean>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const isMediaBlobUrl: (url: string) => boolean;
|
|
2
|
+
export interface MediaBlobUrlAttrs {
|
|
3
|
+
id: string;
|
|
4
|
+
contextId: string;
|
|
5
|
+
collection?: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
name?: string;
|
|
8
|
+
mimeType?: string;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
alt?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const getAttrsFromUrl: (blobUrl: string) => MediaBlobUrlAttrs | undefined;
|
|
14
|
+
export declare const objectToQueryString: (json: {
|
|
15
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
16
|
+
}) => string;
|
|
17
|
+
export declare const addFileAttrsToUrl: (url: string, fileAttrs: MediaBlobUrlAttrs) => string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MediaClientConfig } from '@atlaskit/media-core';
|
|
3
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
4
|
+
import { MediaClient } from '../client/media-client';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
export interface WithMediaClientConfig {
|
|
7
|
+
mediaClientConfig: MediaClientConfig;
|
|
8
|
+
}
|
|
9
|
+
export interface WithMediaClient {
|
|
10
|
+
mediaClient: MediaClient;
|
|
11
|
+
identifier?: Identifier;
|
|
12
|
+
}
|
|
13
|
+
export declare const getMediaClient: (mediaClientConfig: MediaClientConfig, featureFlags?: MediaFeatureFlags | undefined) => MediaClient;
|
|
14
|
+
export declare type WithMediaClientConfigProps<P extends WithMediaClient> = Omit<P, 'mediaClient'> & WithMediaClientConfig;
|
|
15
|
+
export declare type WithMediaClientFunction = <P extends WithMediaClient>(Component: React.ComponentType<P>, featureFlags?: MediaFeatureFlags) => React.ComponentType<WithMediaClientConfigProps<P>>;
|
|
16
|
+
export declare const withMediaClient: WithMediaClientFunction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "17.1.
|
|
3
|
+
"version": "17.1.3",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"module:es2019": "dist/es2019/index.js",
|
|
14
14
|
"types": "dist/types/index.d.ts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
">=4.0 <4.5": {
|
|
17
|
+
"*": [
|
|
18
|
+
"dist/types-ts4.0/*"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
15
22
|
"sideEffects": false,
|
|
16
23
|
"atlaskit:src": "src/index.ts",
|
|
17
24
|
"af:exports": {
|
|
@@ -43,7 +50,7 @@
|
|
|
43
50
|
"xstate": "^4.20.0"
|
|
44
51
|
},
|
|
45
52
|
"peerDependencies": {
|
|
46
|
-
"@atlaskit/media-core": "^33.0.
|
|
53
|
+
"@atlaskit/media-core": "^33.0.3",
|
|
47
54
|
"@emotion/react": "^11.7.1",
|
|
48
55
|
"react": "^16.8.0"
|
|
49
56
|
},
|
|
@@ -62,7 +69,7 @@
|
|
|
62
69
|
"fetch-mock": "^8.0.0",
|
|
63
70
|
"react": "^16.8.0",
|
|
64
71
|
"react-dom": "^16.8.0",
|
|
65
|
-
"typescript": "4.
|
|
72
|
+
"typescript": "4.5.5"
|
|
66
73
|
},
|
|
67
74
|
"resolutions": {
|
|
68
75
|
"lru-fast": "0.2.2"
|