@atlaskit/media-client 24.0.1 → 24.0.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/utils/with-media-client-hoc.js +24 -0
  3. package/dist/es2019/utils/with-media-client-hoc.js +25 -0
  4. package/dist/esm/utils/with-media-client-hoc.js +25 -0
  5. package/dist/types/utils/with-media-client-hoc.d.ts +18 -0
  6. package/dist/types-ts4.5/client/__mocks__/collection-fetcher.d.ts +8 -0
  7. package/dist/types-ts4.5/client/__mocks__/file-fetcher.d.ts +10 -0
  8. package/dist/types-ts4.5/client/__mocks__/media-client.d.ts +11 -0
  9. package/dist/types-ts4.5/client/events.d.ts +14 -0
  10. package/dist/types-ts4.5/client/file-fetcher/error.d.ts +29 -0
  11. package/dist/types-ts4.5/client/file-fetcher/index.d.ts +62 -0
  12. package/dist/types-ts4.5/client/media-client.d.ts +32 -0
  13. package/dist/types-ts4.5/client/media-store/error.d.ts +16 -0
  14. package/dist/types-ts4.5/client/media-store/index.d.ts +168 -0
  15. package/dist/types-ts4.5/client/media-store/resolveAuth.d.ts +4 -0
  16. package/dist/types-ts4.5/client/mobile-upload.d.ts +15 -0
  17. package/dist/types-ts4.5/client/stargate-client.d.ts +15 -0
  18. package/dist/types-ts4.5/constants.d.ts +6 -0
  19. package/dist/types-ts4.5/file-streams-cache.d.ts +15 -0
  20. package/dist/types-ts4.5/globalMediaEventEmitter.d.ts +6 -0
  21. package/dist/types-ts4.5/identifier.d.ts +15 -0
  22. package/dist/types-ts4.5/index.d.ts +89 -0
  23. package/dist/types-ts4.5/models/artifacts.d.ts +2 -0
  24. package/dist/types-ts4.5/models/auth-headers.d.ts +11 -0
  25. package/dist/types-ts4.5/models/auth-query-parameters.d.ts +11 -0
  26. package/dist/types-ts4.5/models/errors/helpers.d.ts +6 -0
  27. package/dist/types-ts4.5/models/errors/index.d.ts +11 -0
  28. package/dist/types-ts4.5/models/errors/types.d.ts +15 -0
  29. package/dist/types-ts4.5/models/file-state.d.ts +25 -0
  30. package/dist/types-ts4.5/models/item.d.ts +25 -0
  31. package/dist/types-ts4.5/models/media.d.ts +48 -0
  32. package/dist/types-ts4.5/models/mobile-upload.d.ts +28 -0
  33. package/dist/types-ts4.5/test-helpers/_numbers.d.ts +1 -0
  34. package/dist/types-ts4.5/test-helpers/authProvider.d.ts +6 -0
  35. package/dist/types-ts4.5/test-helpers/collectionNames.d.ts +5 -0
  36. package/dist/types-ts4.5/test-helpers/exampleMediaItems.d.ts +53 -0
  37. package/dist/types-ts4.5/test-helpers/fakeMediaClient.d.ts +4 -0
  38. package/dist/types-ts4.5/test-helpers/index.d.ts +7 -0
  39. package/dist/types-ts4.5/test-helpers/mediaClientProvider.d.ts +23 -0
  40. package/dist/types-ts4.5/test-helpers/mediaPickerAuthProvider.d.ts +5 -0
  41. package/dist/types-ts4.5/upload-controller.d.ts +7 -0
  42. package/dist/types-ts4.5/uploader/calculateChunkSize.d.ts +11 -0
  43. package/dist/types-ts4.5/uploader/error.d.ts +29 -0
  44. package/dist/types-ts4.5/uploader/index.d.ts +23 -0
  45. package/dist/types-ts4.5/utils/checkWebpSupport.d.ts +1 -0
  46. package/dist/types-ts4.5/utils/convertBase64ToBlob.d.ts +1 -0
  47. package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +30 -0
  48. package/dist/types-ts4.5/utils/createMediaSubject.d.ts +3 -0
  49. package/dist/types-ts4.5/utils/detectEmptyFile.d.ts +16 -0
  50. package/dist/types-ts4.5/utils/getDimensionsFromBlob.d.ts +6 -0
  51. package/dist/types-ts4.5/utils/getImageDimensionsFromBlob.d.ts +5 -0
  52. package/dist/types-ts4.5/utils/getMediaTypeFromUploadableFile.d.ts +3 -0
  53. package/dist/types-ts4.5/utils/getVideoDimensionsFromBlob.d.ts +5 -0
  54. package/dist/types-ts4.5/utils/hashing/hasher.d.ts +3 -0
  55. package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +3 -0
  56. package/dist/types-ts4.5/utils/hashing/simpleHasher.d.ts +4 -0
  57. package/dist/types-ts4.5/utils/hashing/workerHasher.d.ts +16 -0
  58. package/dist/types-ts4.5/utils/imageResizeModeToFileImageMode.d.ts +3 -0
  59. package/dist/types-ts4.5/utils/isImageRemote.d.ts +1 -0
  60. package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +5 -0
  61. package/dist/types-ts4.5/utils/mediaSubscribable/index.d.ts +3 -0
  62. package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +10 -0
  63. package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +17 -0
  64. package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +29 -0
  65. package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +8 -0
  66. package/dist/types-ts4.5/utils/mobileUpload/index.d.ts +5 -0
  67. package/dist/types-ts4.5/utils/mobileUpload/servicesCache.d.ts +4 -0
  68. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +7 -0
  69. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
  70. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
  71. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
  72. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
  73. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
  74. package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +69 -0
  75. package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +5 -0
  76. package/dist/types-ts4.5/utils/polling/errors.d.ts +12 -0
  77. package/dist/types-ts4.5/utils/polling/index.d.ts +33 -0
  78. package/dist/types-ts4.5/utils/polling/types.d.ts +7 -0
  79. package/dist/types-ts4.5/utils/request/errors.d.ts +20 -0
  80. package/dist/types-ts4.5/utils/request/helpers.d.ts +46 -0
  81. package/dist/types-ts4.5/utils/request/index.d.ts +5 -0
  82. package/dist/types-ts4.5/utils/request/types.d.ts +46 -0
  83. package/dist/types-ts4.5/utils/safeUnsubscribe.d.ts +2 -0
  84. package/dist/types-ts4.5/utils/setTimeoutPromise.d.ts +2 -0
  85. package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +14 -0
  86. package/dist/types-ts4.5/utils/url.d.ts +17 -0
  87. package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +33 -0
  88. package/package.json +2 -2
  89. package/report.api.md +6 -6
  90. package/tmp/api-report-tmp.d.ts +1225 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 24.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41932](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41932) [`756dd90f1a3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/756dd90f1a3) - 1. Deprecate withMediaClient HOC in media-client and migrated it to media-client-react 2. clean up deprecated imports from media-client
8
+
9
+ ## 24.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#41501](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41501) [`b3cb749dc67`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b3cb749dc67) - Fix TS errors in AFM
14
+
3
15
  ## 24.0.1
4
16
 
5
17
  ### Patch Changes
@@ -17,7 +17,19 @@ var _mediaClient = require("../client/media-client");
17
17
  var _excluded = ["mediaClientConfig"];
18
18
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
19
19
  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; } }
20
+ /**
21
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
22
+ */
23
+
24
+ /**
25
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
26
+ */
27
+
20
28
  var mediaClientsMap = new Map();
29
+
30
+ /**
31
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
32
+ */
21
33
  var getMediaClient = exports.getMediaClient = function getMediaClient(mediaClientConfig) {
22
34
  var mediaClient = mediaClientsMap.get(mediaClientConfig);
23
35
  if (!mediaClient) {
@@ -38,6 +50,18 @@ var createEmptyMediaClient = function createEmptyMediaClient() {
38
50
  };
39
51
  return new _mediaClient.MediaClient(emptyConfig);
40
52
  };
53
+
54
+ /**
55
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
56
+ */
57
+
58
+ /**
59
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
60
+ */
61
+
62
+ /**
63
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
64
+ */
41
65
  var withMediaClient = exports.withMediaClient = function withMediaClient(Component) {
42
66
  return /*#__PURE__*/function (_React$Component) {
43
67
  (0, _inherits2.default)(_class, _React$Component);
@@ -1,7 +1,20 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import { MediaClient } from '../client/media-client';
4
+
5
+ /**
6
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
7
+ */
8
+
9
+ /**
10
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
11
+ */
12
+
4
13
  const mediaClientsMap = new Map();
14
+
15
+ /**
16
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
17
+ */
5
18
  export const getMediaClient = mediaClientConfig => {
6
19
  let mediaClient = mediaClientsMap.get(mediaClientConfig);
7
20
  if (!mediaClient) {
@@ -20,6 +33,18 @@ const createEmptyMediaClient = () => {
20
33
  };
21
34
  return new MediaClient(emptyConfig);
22
35
  };
36
+
37
+ /**
38
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
39
+ */
40
+
41
+ /**
42
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
43
+ */
44
+
45
+ /**
46
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
47
+ */
23
48
  export const withMediaClient = Component => {
24
49
  return class extends React.Component {
25
50
  render() {
@@ -10,7 +10,20 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
10
10
  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; } }
11
11
  import React from 'react';
12
12
  import { MediaClient } from '../client/media-client';
13
+
14
+ /**
15
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
16
+ */
17
+
18
+ /**
19
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
20
+ */
21
+
13
22
  var mediaClientsMap = new Map();
23
+
24
+ /**
25
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
26
+ */
14
27
  export var getMediaClient = function getMediaClient(mediaClientConfig) {
15
28
  var mediaClient = mediaClientsMap.get(mediaClientConfig);
16
29
  if (!mediaClient) {
@@ -31,6 +44,18 @@ var createEmptyMediaClient = function createEmptyMediaClient() {
31
44
  };
32
45
  return new MediaClient(emptyConfig);
33
46
  };
47
+
48
+ /**
49
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
50
+ */
51
+
52
+ /**
53
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
54
+ */
55
+
56
+ /**
57
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
58
+ */
34
59
  export var withMediaClient = function withMediaClient(Component) {
35
60
  return /*#__PURE__*/function (_React$Component) {
36
61
  _inherits(_class, _React$Component);
@@ -2,14 +2,32 @@ import React from 'react';
2
2
  import { MediaClientConfig } from '@atlaskit/media-core';
3
3
  import { MediaClient } from '../client/media-client';
4
4
  import { Identifier } from '../identifier';
5
+ /**
6
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
7
+ */
5
8
  export interface WithMediaClientConfig {
6
9
  mediaClientConfig: MediaClientConfig;
7
10
  }
11
+ /**
12
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
13
+ */
8
14
  export interface WithMediaClient {
9
15
  mediaClient: MediaClient;
10
16
  identifier?: Identifier;
11
17
  }
18
+ /**
19
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
20
+ */
12
21
  export declare const getMediaClient: (mediaClientConfig: MediaClientConfig) => MediaClient;
22
+ /**
23
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
24
+ */
13
25
  export type WithMediaClientConfigProps<P extends WithMediaClient> = Omit<P, 'mediaClient'> & WithMediaClientConfig;
26
+ /**
27
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
28
+ */
14
29
  export type WithMediaClientFunction = <P extends WithMediaClient>(Component: React.ComponentType<P>) => React.ComponentType<WithMediaClientConfigProps<P>>;
30
+ /**
31
+ * @deprecated This export will be removed. Please use one from `@atlaskit/media-client-react`
32
+ */
15
33
  export declare const withMediaClient: WithMediaClientFunction;
@@ -0,0 +1,8 @@
1
+ /// <reference types="jest" />
2
+ export declare const collectionCache: {};
3
+ export declare class CollectionFetcher {
4
+ constructor();
5
+ getItems: jest.Mock<any, any>;
6
+ removeFile: jest.Mock<any, any>;
7
+ loadNextPage: jest.Mock<any, any>;
8
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="jest" />
2
+ export declare class FileFetcher {
3
+ constructor();
4
+ getFileState: jest.Mock<any, any>;
5
+ getCurrentState: jest.Mock<any, any>;
6
+ getArtifactURL: jest.Mock<any, any>;
7
+ touchFiles: jest.Mock<any, any>;
8
+ upload: jest.Mock<any, any>;
9
+ downloadBinary: jest.Mock<any, any>;
10
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="jest" />
2
+ import { MediaClientConfig } from '@atlaskit/media-core';
3
+ import { FileFetcher } from '../file-fetcher';
4
+ export declare class MediaClient {
5
+ readonly config: MediaClientConfig;
6
+ readonly file: FileFetcher;
7
+ constructor(config: MediaClientConfig);
8
+ getImage: jest.Mock<any, any>;
9
+ getImageUrl: jest.Mock<any, any>;
10
+ getImageMetadata: jest.Mock<any, any>;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { FileState } from '@atlaskit/media-state';
2
+ export type EventPayloadMap<P> = {
3
+ readonly [event: string]: P;
4
+ };
5
+ export type EventPayloadListener<M extends EventPayloadMap<P>, E extends keyof M, P = any> = (payload: M[E]) => void;
6
+ export interface MediaViewedEventPayload {
7
+ fileId: string;
8
+ viewingLevel: 'minimal' | 'full' | 'download';
9
+ isUserCollection?: boolean;
10
+ }
11
+ export type UploadEventPayloadMap = {
12
+ 'file-added': FileState;
13
+ 'media-viewed': MediaViewedEventPayload;
14
+ };
@@ -0,0 +1,29 @@
1
+ import { BaseMediaClientError } from '../../models/errors';
2
+ export type FileFetcherErrorReason = 'invalidFileId' | 'emptyItems' | 'zeroVersionFile' | 'emptyFileName';
3
+ export type FileFetcherErrorAttributes = {
4
+ readonly reason: FileFetcherErrorReason;
5
+ readonly id: string;
6
+ readonly metadata?: {
7
+ readonly collectionName?: string;
8
+ readonly occurrenceKey?: string;
9
+ };
10
+ };
11
+ export declare class FileFetcherError extends BaseMediaClientError<FileFetcherErrorAttributes> {
12
+ readonly reason: FileFetcherErrorReason;
13
+ readonly id: string;
14
+ readonly metadata?: {
15
+ readonly collectionName?: string | undefined;
16
+ readonly occurrenceKey?: string | undefined;
17
+ } | undefined;
18
+ constructor(reason: FileFetcherErrorReason, id: string, metadata?: {
19
+ readonly collectionName?: string | undefined;
20
+ readonly occurrenceKey?: string | undefined;
21
+ } | undefined);
22
+ get attributes(): {
23
+ reason: FileFetcherErrorReason;
24
+ id: string;
25
+ collectionName: string | undefined;
26
+ occurrenceKey: string | undefined;
27
+ };
28
+ }
29
+ export declare function isFileFetcherError(err: Error): err is FileFetcherError;
@@ -0,0 +1,62 @@
1
+ import 'setimmediate';
2
+ import { AuthProvider } from '@atlaskit/media-core';
3
+ import { MediaFileArtifacts } from '@atlaskit/media-state';
4
+ import { MediaStore as MediaApi, MediaStoreCopyFileWithTokenParams, TouchedFiles, TouchFileDescriptor } from '../media-store';
5
+ import { GetFileOptions } from '../../models/file-state';
6
+ import { MediaFile } from '../../models/media';
7
+ import { UploadableFile, UploadableFileUpfrontIds } from '../../uploader';
8
+ import { UploadController } from '../../upload-controller';
9
+ import { MediaSubscribable } from '../../utils/mediaSubscribable';
10
+ import { Dimensions } from '../../utils/getDimensionsFromBlob';
11
+ import { MediaTraceContext } from '@atlaskit/media-common';
12
+ import { FilePreview, FileState, MediaStore } from '@atlaskit/media-state';
13
+ export type { FileFetcherErrorAttributes, FileFetcherErrorReason, } from './error';
14
+ export { isFileFetcherError, FileFetcherError } from './error';
15
+ export interface CopySourceFile {
16
+ id: string;
17
+ collection?: string;
18
+ authProvider: AuthProvider;
19
+ }
20
+ export interface CopyDestination extends MediaStoreCopyFileWithTokenParams {
21
+ authProvider: AuthProvider;
22
+ mediaStore?: MediaApi;
23
+ }
24
+ export interface CopyFileOptions {
25
+ preview?: FilePreview | Promise<FilePreview>;
26
+ mimeType?: string;
27
+ }
28
+ export type ExternalUploadPayload = {
29
+ uploadableFileUpfrontIds: UploadableFileUpfrontIds;
30
+ dimensions: Dimensions;
31
+ };
32
+ export interface FileFetcher {
33
+ getFileState(id: string, options?: GetFileOptions): MediaSubscribable;
34
+ getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
35
+ touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
36
+ upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
37
+ uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
38
+ downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
39
+ getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
40
+ copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
41
+ getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
42
+ }
43
+ export declare class FileFetcherImpl implements FileFetcher {
44
+ private readonly mediaApi;
45
+ private readonly store;
46
+ private readonly dataloader;
47
+ constructor(mediaApi: MediaApi, store?: MediaStore);
48
+ private getErrorFileState;
49
+ private setFileState;
50
+ getFileState(id: string, options?: GetFileOptions): MediaSubscribable;
51
+ getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
52
+ getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
53
+ getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
54
+ private createDownloadFileStream;
55
+ touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
56
+ private generateUploadableFileUpfrontIds;
57
+ uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
58
+ private getUploadingFileStateBase;
59
+ upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable;
60
+ downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
61
+ copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
62
+ }
@@ -0,0 +1,32 @@
1
+ import { MediaClientConfig } from '@atlaskit/media-core';
2
+ import { MediaTraceContext } from '@atlaskit/media-common';
3
+ import { MediaStore as MediaApi, MediaStoreGetFileImageParams, ImageMetadata } from './media-store';
4
+ import { FileFetcher } from './file-fetcher';
5
+ import { UploadEventPayloadMap, EventPayloadListener } from './events';
6
+ import { StargateClient } from './stargate-client';
7
+ import { MobileUpload } from '../models/mobile-upload';
8
+ import { MediaStore } from '@atlaskit/media-state';
9
+ export declare class MediaClient {
10
+ readonly mediaClientConfig: MediaClientConfig;
11
+ private readonly store;
12
+ readonly mediaStore: MediaApi;
13
+ readonly file: FileFetcher;
14
+ readonly stargate: StargateClient;
15
+ private readonly eventEmitter;
16
+ private mobileUpload?;
17
+ readonly config: MediaClientConfig;
18
+ constructor(mediaClientConfig: MediaClientConfig, store?: MediaStore, mediaApi?: MediaApi);
19
+ /**
20
+ * @internal
21
+ */
22
+ __DO_NOT_USE__getMediaStore(): MediaStore;
23
+ getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
24
+ getImageUrl(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
25
+ getImageUrlSync(id: string, params?: MediaStoreGetFileImageParams): string;
26
+ getImageMetadata(id: string, params?: MediaStoreGetFileImageParams): Promise<ImageMetadata>;
27
+ mobileUploadPromise(): Promise<MobileUpload>;
28
+ removeFileFromCollection(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
29
+ on<E extends keyof UploadEventPayloadMap>(event: E, listener: EventPayloadListener<UploadEventPayloadMap, E>): void;
30
+ off<E extends keyof UploadEventPayloadMap>(event: E, listener: EventPayloadListener<UploadEventPayloadMap, E>): void;
31
+ emit<E extends keyof UploadEventPayloadMap>(event: E, payload: UploadEventPayloadMap[E]): boolean;
32
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseMediaClientError } from '../../models/errors';
2
+ export type MediaStoreErrorReason = 'failedAuthProvider' | 'tokenExpired' | 'missingInitialAuth' | 'emptyAuth' | 'authProviderTimedOut';
3
+ export type MediaStoreErrorAttributes = {
4
+ readonly reason: MediaStoreErrorReason;
5
+ readonly innerError?: Error;
6
+ };
7
+ export declare class MediaStoreError extends BaseMediaClientError<MediaStoreErrorAttributes> {
8
+ readonly reason: MediaStoreErrorReason;
9
+ readonly innerError?: Error | undefined;
10
+ constructor(reason: MediaStoreErrorReason, innerError?: Error | undefined);
11
+ get attributes(): {
12
+ reason: MediaStoreErrorReason;
13
+ innerError: Error | undefined;
14
+ };
15
+ }
16
+ export declare function isMediaStoreError(err: Error): err is MediaStoreError;
@@ -0,0 +1,168 @@
1
+ import { AsapBasedAuth, AuthContext, ClientAltBasedAuth, MediaApiConfig, Auth } from '@atlaskit/media-core';
2
+ import { MediaTraceContext } from '@atlaskit/media-common';
3
+ import { MediaFileArtifacts } from '@atlaskit/media-state';
4
+ import { MediaChunksProbe, MediaItemDetails, MediaFile, MediaUpload } from '../../models/media';
5
+ import { ClientOptions, RequestHeaders, RequestMethod, RequestParams, RequestMetadata } from '../../utils/request/types';
6
+ export type { MediaStoreErrorReason, MediaStoreErrorAttributes } from './error';
7
+ export { MediaStoreError, isMediaStoreError } from './error';
8
+ export declare class MediaStore {
9
+ private readonly config;
10
+ constructor(config: MediaApiConfig);
11
+ removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
12
+ createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
13
+ uploadChunk(etag: string, blob: Blob, uploadId: string, partNumber: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
14
+ probeChunks(chunks: string[], uploadId: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaChunksProbe>>;
15
+ createFileFromUpload(body: MediaStoreCreateFileFromUploadBody, params?: MediaStoreCreateFileFromUploadParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
16
+ getRejectedResponseFromDescriptor(descriptor: TouchFileDescriptor, limit: number): RejectedTouchFile;
17
+ touchFiles(body: MediaStoreTouchFileBody, params?: MediaStoreTouchFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<TouchedFiles>>;
18
+ getFile(fileId: string, params?: MediaStoreGetFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
19
+ getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
20
+ getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
21
+ private createFileImageURL;
22
+ getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
23
+ getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
24
+ getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
25
+ getItems(ids: string[], collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<ItemsPayload>>;
26
+ getImageMetadata(id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext): Promise<{
27
+ metadata: ImageMetadata;
28
+ }>;
29
+ appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
30
+ copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
31
+ request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
32
+ resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
33
+ resolveInitialAuth: () => Auth;
34
+ }
35
+ export declare const getMediaEnvironment: () => string | undefined;
36
+ export declare const getMediaRegion: () => string | undefined;
37
+ export interface ResponseFileItem {
38
+ id: string;
39
+ type: 'file';
40
+ details: MediaItemDetails;
41
+ collection?: string;
42
+ metadataTraceContext?: MediaTraceContext;
43
+ }
44
+ export interface ItemsPayload {
45
+ items: ResponseFileItem[];
46
+ }
47
+ export type ImageMetadataArtifact = {
48
+ url?: string;
49
+ width?: number;
50
+ height?: number;
51
+ size?: number;
52
+ };
53
+ export interface ImageMetadata {
54
+ pending: boolean;
55
+ preview?: ImageMetadataArtifact;
56
+ original?: ImageMetadataArtifact;
57
+ }
58
+ export interface MediaStoreResponse<Data> {
59
+ readonly data: Data;
60
+ }
61
+ export type MediaStoreRequestOptions = RequestMetadata & {
62
+ readonly method?: RequestMethod;
63
+ readonly authContext?: AuthContext;
64
+ readonly params?: RequestParams;
65
+ readonly headers?: RequestHeaders;
66
+ readonly body?: any;
67
+ readonly clientOptions?: ClientOptions;
68
+ readonly traceContext?: MediaTraceContext;
69
+ };
70
+ export type MediaStoreCreateFileFromUploadParams = {
71
+ readonly collection?: string;
72
+ readonly occurrenceKey?: string;
73
+ readonly expireAfter?: number;
74
+ readonly replaceFileId?: string;
75
+ readonly skipConversions?: boolean;
76
+ };
77
+ export type MediaStoreCreateFileParams = {
78
+ readonly occurrenceKey?: string;
79
+ readonly collection?: string;
80
+ };
81
+ export interface MediaStoreTouchFileParams {
82
+ readonly collection?: string;
83
+ }
84
+ export interface TouchFileDescriptor {
85
+ fileId: string;
86
+ collection?: string;
87
+ occurrenceKey?: string;
88
+ expireAfter?: number;
89
+ deletable?: boolean;
90
+ size?: number;
91
+ }
92
+ export interface MediaStoreTouchFileBody {
93
+ descriptors: TouchFileDescriptor[];
94
+ }
95
+ export type MediaStoreCreateFileFromBinaryParams = {
96
+ readonly replaceFileId?: string;
97
+ readonly collection?: string;
98
+ readonly occurrenceKey?: string;
99
+ readonly expireAfter?: number;
100
+ readonly skipConversions?: boolean;
101
+ readonly name?: string;
102
+ };
103
+ export type MediaStoreCreateFileFromUploadConditions = {
104
+ readonly hash?: string;
105
+ readonly size?: number;
106
+ };
107
+ export type MediaStoreCreateFileFromUploadBody = {
108
+ readonly uploadId: string;
109
+ readonly name?: string;
110
+ readonly mimeType?: string;
111
+ readonly conditions?: MediaStoreCreateFileFromUploadConditions;
112
+ };
113
+ export type MediaStoreGetFileParams = {
114
+ readonly version?: number;
115
+ readonly collection?: string;
116
+ };
117
+ export type MediaStoreGetFileImageParams = {
118
+ readonly allowAnimated?: boolean;
119
+ readonly version?: number;
120
+ readonly collection?: string;
121
+ readonly width?: number;
122
+ readonly height?: number;
123
+ readonly mode?: 'fit' | 'full-fit' | 'crop';
124
+ readonly upscale?: boolean;
125
+ readonly 'max-age'?: number;
126
+ };
127
+ export interface SourceFile {
128
+ id: string;
129
+ owner: ClientAltBasedAuth | AsapBasedAuth;
130
+ collection?: string;
131
+ version?: number;
132
+ }
133
+ export type MediaStoreCopyFileWithTokenBody = {
134
+ sourceFile: SourceFile;
135
+ };
136
+ export type MediaStoreCopyFileWithTokenParams = {
137
+ readonly collection?: string;
138
+ readonly replaceFileId?: string;
139
+ readonly occurrenceKey?: string;
140
+ };
141
+ export type AppendChunksToUploadRequestBody = {
142
+ readonly chunks: string[];
143
+ readonly hash?: string;
144
+ readonly offset?: number;
145
+ };
146
+ export interface CreatedTouchedFile {
147
+ fileId: string;
148
+ uploadId: string;
149
+ }
150
+ export interface RejectedTouchFile {
151
+ fileId: string;
152
+ error: RejectionError;
153
+ }
154
+ export type RejectionError = {
155
+ code: 'ExceedMaxFileSizeLimit';
156
+ title: string;
157
+ href: string;
158
+ limit: number;
159
+ size: number;
160
+ };
161
+ export type TouchedFiles = {
162
+ created: CreatedTouchedFile[];
163
+ rejected?: RejectedTouchFile[];
164
+ };
165
+ export interface EmptyFile {
166
+ readonly id: string;
167
+ readonly createdAt: number;
168
+ }
@@ -0,0 +1,4 @@
1
+ import { Auth, AuthContext, AuthProvider } from '@atlaskit/media-core';
2
+ export declare const DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
3
+ export declare const resolveAuth: (authProvider: AuthProvider, authContext?: AuthContext, authProviderTimeout?: number) => Promise<Auth>;
4
+ export declare const resolveInitialAuth: (auth?: Auth) => Auth;
@@ -0,0 +1,15 @@
1
+ import { MediaStore } from '@atlaskit/media-state';
2
+ import { MobileUpload, MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent } from '../models/mobile-upload';
3
+ import { MediaStore as MediaApi } from './media-store';
4
+ export declare class MobileUploadImpl implements MobileUpload {
5
+ private readonly store;
6
+ private readonly dataloader;
7
+ private readonly servicesCache;
8
+ constructor(mediaApi: MediaApi, store?: MediaStore);
9
+ notifyUploadStart(event: MobileUploadStartEvent): void;
10
+ notifyUploadProgress(event: MobileUploadProgressEvent): void;
11
+ notifyUploadEnd(event: MobileUploadEndEvent): void;
12
+ notifyUploadError(event: MobileUploadErrorEvent): void;
13
+ private getErrorFileState;
14
+ private setFileState;
15
+ }
@@ -0,0 +1,15 @@
1
+ export interface EdgeData {
2
+ data: {
3
+ clientId: string;
4
+ token: string;
5
+ baseUrl: string;
6
+ expiresIn: number;
7
+ iat: number;
8
+ };
9
+ }
10
+ export declare class StargateClient {
11
+ private baseUrl;
12
+ constructor(baseUrl: string | undefined);
13
+ fetchToken(clientId: string): Promise<EdgeData>;
14
+ isTokenExpired(token: EdgeData): boolean;
15
+ }
@@ -0,0 +1,6 @@
1
+ export declare const RECENTS_COLLECTION = "recents";
2
+ export declare const FILE_CACHE_MAX_AGE: number;
3
+ export declare const MAX_RESOLUTION = 4096;
4
+ export declare const CHUNK_SIZE: number;
5
+ export declare const PROCESSING_BATCH_SIZE = 1000;
6
+ export declare const MAX_UPLOAD_FILE_SIZE: number;
@@ -0,0 +1,15 @@
1
+ import { LRUMap } from 'lru_map';
2
+ import { ReplaySubject } from 'rxjs/ReplaySubject';
3
+ import { FileState } from '@atlaskit/media-state';
4
+ export declare class StreamsCache<T> {
5
+ private readonly streams;
6
+ constructor(streams: LRUMap<string, ReplaySubject<T>>);
7
+ has(id: string): boolean;
8
+ set(id: string, stream: ReplaySubject<T>): void;
9
+ get(id: string): ReplaySubject<T> | undefined;
10
+ getOrInsert(id: string, callback: () => ReplaySubject<T>): ReplaySubject<T>;
11
+ removeAll(): void;
12
+ remove(id: string): void;
13
+ get size(): number;
14
+ }
15
+ export declare const getFileStreamsCache: () => StreamsCache<FileState>;
@@ -0,0 +1,6 @@
1
+ import { UploadEventPayloadMap, EventPayloadListener } from './client/events';
2
+ export declare const globalMediaEventEmitter: {
3
+ on<E extends keyof UploadEventPayloadMap>(event: E, listener: EventPayloadListener<UploadEventPayloadMap, E, any>): void;
4
+ off<E_1 extends keyof UploadEventPayloadMap>(event: E_1, listener: EventPayloadListener<UploadEventPayloadMap, E_1, any>): void;
5
+ emit<E_2 extends keyof UploadEventPayloadMap>(event: E_2, payload: UploadEventPayloadMap[E_2]): boolean | undefined;
6
+ };
@@ -0,0 +1,15 @@
1
+ export type Identifier = FileIdentifier | ExternalImageIdentifier;
2
+ export interface FileIdentifier {
3
+ readonly mediaItemType: 'file';
4
+ readonly id: string;
5
+ readonly occurrenceKey?: string;
6
+ readonly collectionName?: string;
7
+ }
8
+ export interface ExternalImageIdentifier {
9
+ readonly mediaItemType: 'external-image';
10
+ readonly dataURI: string;
11
+ readonly name?: string;
12
+ }
13
+ export declare const isFileIdentifier: (identifier: Identifier) => identifier is FileIdentifier;
14
+ export declare const isExternalImageIdentifier: (identifier: Identifier) => identifier is ExternalImageIdentifier;
15
+ export declare const isDifferentIdentifier: (a: Identifier, b: Identifier) => boolean;