@atlaskit/media-client 20.2.1 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/cjs/client/file-fetcher/error.js +4 -4
  3. package/dist/cjs/client/file-fetcher/index.js +275 -287
  4. package/dist/cjs/client/media-client.js +48 -34
  5. package/dist/cjs/client/media-store/index.js +367 -314
  6. package/dist/cjs/client/media-store/resolveAuth.js +30 -32
  7. package/dist/cjs/client/stargate-client.js +14 -16
  8. package/dist/cjs/index.js +6 -13
  9. package/dist/cjs/models/media.js +8 -9
  10. package/dist/cjs/uploader/error.js +4 -4
  11. package/dist/cjs/uploader/index.js +88 -96
  12. package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
  13. package/dist/cjs/utils/createFileDataLoader.js +67 -70
  14. package/dist/cjs/utils/getDimensionsFromBlob.js +23 -25
  15. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +24 -26
  16. package/dist/cjs/utils/hashing/hasherCreator.js +32 -34
  17. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -2
  18. package/dist/cjs/utils/mobileUpload/error.js +4 -4
  19. package/dist/cjs/utils/mobileUpload/helpers.js +41 -43
  20. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +14 -16
  21. package/dist/cjs/utils/parseJwt.js +52 -0
  22. package/dist/cjs/utils/polling/index.js +40 -42
  23. package/dist/cjs/utils/request/errors.js +9 -9
  24. package/dist/cjs/utils/request/helpers.js +143 -155
  25. package/dist/cjs/utils/request/index.js +24 -26
  26. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +39 -41
  27. package/dist/cjs/version.json +1 -1
  28. package/dist/es2019/client/file-fetcher/index.js +1 -3
  29. package/dist/es2019/client/media-client.js +3 -2
  30. package/dist/es2019/client/media-store/index.js +58 -15
  31. package/dist/es2019/index.js +2 -3
  32. package/dist/es2019/models/media.js +6 -4
  33. package/dist/es2019/uploader/index.js +3 -0
  34. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -2
  35. package/dist/es2019/utils/mediaSubscribable/toPromise.js +10 -12
  36. package/dist/es2019/utils/parseJwt.js +46 -0
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/client/file-fetcher/error.js +4 -4
  39. package/dist/esm/client/file-fetcher/index.js +273 -286
  40. package/dist/esm/client/media-client.js +46 -32
  41. package/dist/esm/client/media-store/index.js +367 -314
  42. package/dist/esm/client/media-store/resolveAuth.js +30 -32
  43. package/dist/esm/client/stargate-client.js +14 -16
  44. package/dist/esm/index.js +2 -3
  45. package/dist/esm/models/media.js +6 -6
  46. package/dist/esm/uploader/error.js +4 -4
  47. package/dist/esm/uploader/index.js +89 -96
  48. package/dist/esm/utils/convertBase64ToBlob.js +2 -2
  49. package/dist/esm/utils/createFileDataLoader.js +65 -69
  50. package/dist/esm/utils/getDimensionsFromBlob.js +23 -25
  51. package/dist/esm/utils/getVideoDimensionsFromBlob.js +24 -26
  52. package/dist/esm/utils/hashing/hasherCreator.js +28 -30
  53. package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -2
  54. package/dist/esm/utils/mobileUpload/error.js +4 -4
  55. package/dist/esm/utils/mobileUpload/helpers.js +41 -43
  56. package/dist/esm/utils/mobileUpload/stateMachine/index.js +14 -16
  57. package/dist/esm/utils/parseJwt.js +46 -0
  58. package/dist/esm/utils/polling/index.js +40 -42
  59. package/dist/esm/utils/request/errors.js +9 -9
  60. package/dist/esm/utils/request/helpers.js +143 -155
  61. package/dist/esm/utils/request/index.js +24 -26
  62. package/dist/esm/utils/shouldFetchRemoteFileStates.js +39 -41
  63. package/dist/esm/version.json +1 -1
  64. package/dist/types/client/__mocks__/media-client.d.ts +0 -2
  65. package/dist/types/client/file-fetcher/index.d.ts +4 -4
  66. package/dist/types/client/media-client.d.ts +1 -2
  67. package/dist/types/client/media-store/index.d.ts +17 -13
  68. package/dist/types/index.d.ts +4 -6
  69. package/dist/types/models/file-state.d.ts +2 -2
  70. package/dist/types/models/media.d.ts +1 -21
  71. package/dist/types/utils/createFileDataLoader.d.ts +2 -2
  72. package/dist/types/utils/createMediaSubject.d.ts +2 -2
  73. package/dist/types/utils/detectEmptyFile.d.ts +2 -2
  74. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +3 -3
  75. package/dist/types/utils/mediaSubscribable/toPromise.d.ts +2 -2
  76. package/dist/types/utils/mediaSubscribable/types.d.ts +9 -8
  77. package/dist/types/utils/parseJwt.d.ts +1 -0
  78. package/package.json +2 -2
  79. package/report.api.md +77 -126
  80. package/dist/cjs/client/collection-fetcher.js +0 -98
  81. package/dist/cjs/models/media-subscribable.js +0 -5
  82. package/dist/cjs/utils/deprecatedEndpointError.js +0 -43
  83. package/dist/es2019/client/collection-fetcher.js +0 -38
  84. package/dist/es2019/models/media-subscribable.js +0 -1
  85. package/dist/es2019/utils/deprecatedEndpointError.js +0 -20
  86. package/dist/esm/client/collection-fetcher.js +0 -89
  87. package/dist/esm/models/media-subscribable.js +0 -1
  88. package/dist/esm/utils/deprecatedEndpointError.js +0 -34
  89. package/dist/types/client/collection-fetcher.d.ts +0 -42
  90. package/dist/types/models/media-subscribable.d.ts +0 -3
  91. package/dist/types/utils/deprecatedEndpointError.d.ts +0 -16
@@ -1,6 +1,6 @@
1
1
  export { MediaStore, MediaStoreError, isMediaStoreError, getMediaEnvironment, getMediaRegion } from './client/media-store';
2
2
  export { UploadController } from './upload-controller';
3
- export { isPreviewableType, isMediaCollectionItemFullDetails } from './models/media';
3
+ export { isPreviewableType } from './models/media';
4
4
  export { getArtifactUrl } from './models/artifacts';
5
5
  export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
6
6
  export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
@@ -11,7 +11,6 @@ export { PollingFunction } from './utils/polling';
11
11
  export { isPollingError, PollingError } from './utils/polling/errors';
12
12
  export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';
13
13
  export { FileFetcherImpl, FileFetcherError, isFileFetcherError } from './client/file-fetcher';
14
- export { CollectionFetcher } from './client/collection-fetcher';
15
14
  export { MediaClient } from './client/media-client';
16
15
  export { StargateClient } from './client/stargate-client';
17
16
  export { isImageRemote } from './utils/isImageRemote';
@@ -23,7 +22,7 @@ export { isFileIdentifier, isExternalImageIdentifier, isDifferentIdentifier } fr
23
22
  export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
24
23
  export { globalMediaEventEmitter } from './globalMediaEventEmitter';
25
24
  export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
26
- export { createMediaSubscribable } from './utils/mediaSubscribable';
25
+ export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
27
26
  export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
28
27
 
29
28
  // TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
@@ -1,4 +1,7 @@
1
1
  import { getMediaFeatureFlag } from '@atlaskit/media-common';
2
+
3
+ // Warning! You can't add new media file processing status!
4
+ // See packages/media/media-core/src/__tests__/cache-backward-compatibility.spec.ts
2
5
  export const isPreviewableType = (type, featureFlags) => {
3
6
  // in classic experience, only audio/video/image are previewable
4
7
  const defaultPreviewableTypes = ['audio', 'video', 'image'];
@@ -9,10 +12,9 @@ export const isPreviewableType = (type, featureFlags) => {
9
12
  }
10
13
  return defaultPreviewableTypes.indexOf(type) > -1;
11
14
  };
12
- export const isMediaCollectionItemFullDetails = mediaCollectionItem => !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
13
- export let DATA_UNIT;
14
- (function (DATA_UNIT) {
15
+ export let DATA_UNIT = /*#__PURE__*/function (DATA_UNIT) {
15
16
  DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
16
17
  DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
17
18
  DATA_UNIT[DATA_UNIT["TB"] = 1099511627776] = "TB";
18
- })(DATA_UNIT || (DATA_UNIT = {}));
19
+ return DATA_UNIT;
20
+ }({});
@@ -5,6 +5,9 @@ import { createHasher } from '../utils/hashing/hasherCreator';
5
5
  import { UploaderError } from './error';
6
6
  import { CHUNK_SIZE, PROCESSING_BATCH_SIZE } from '../constants';
7
7
  import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
8
+
9
+ // TODO: Allow to pass multiple files
10
+
8
11
  const hashingFunction = async blob => {
9
12
  const hasher = await createHasher();
10
13
  return hasher.hash(blob);
@@ -14,6 +14,6 @@ export function fromObservable(observable) {
14
14
  }
15
15
  };
16
16
  }
17
- export function createMediaSubscribable(mediaSubscribableItem) {
18
- return fromObservable(createMediaSubject(mediaSubscribableItem));
17
+ export function createMediaSubscribable(item) {
18
+ return fromObservable(createMediaSubject(item));
19
19
  }
@@ -6,15 +6,13 @@ import { Subscription } from 'rxjs/Subscription';
6
6
  * @param subscription a default Subscription (this parameter exists for testing purpose)
7
7
  */
8
8
 
9
- export const toPromise = (mediaSubscribable, subscription = new Subscription()) => {
10
- return new Promise((resolve, reject) => subscription.add(mediaSubscribable.subscribe({
11
- next: state => {
12
- resolve(state);
13
- subscription.unsubscribe();
14
- },
15
- error: error => {
16
- reject(error);
17
- subscription.unsubscribe();
18
- }
19
- })));
20
- };
9
+ export const toPromise = (mediaSubscribable, subscription = new Subscription()) => new Promise((resolve, reject) => subscription.add(mediaSubscribable.subscribe({
10
+ next: state => {
11
+ resolve(state);
12
+ subscription.unsubscribe();
13
+ },
14
+ error: error => {
15
+ reject(error);
16
+ subscription.unsubscribe();
17
+ }
18
+ })));
@@ -0,0 +1,46 @@
1
+ // Implementation obtained from https://github.com/auth0/jwt-decode
2
+ // Copied from https://bitbucket.org/atlassian/%7Bc8e2f021-38d2-46d0-9b7a-b3f7b428f724%7D/pull-requests/13080
3
+
4
+ /* Decodes base64 string into unicode */
5
+ const b64DecodeUnicode = str => {
6
+ return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) {
7
+ let code = p.charCodeAt(0).toString(16).toUpperCase();
8
+ if (code.length < 2) {
9
+ code = '0' + code;
10
+ }
11
+ return '%' + code;
12
+ }));
13
+ };
14
+
15
+ /* Decodes base64url string into unicode */
16
+ const b64Decode = str => {
17
+ let output = str.replace(/-/g, '+').replace(/_/g, '/');
18
+ switch (output.length % 4) {
19
+ case 0:
20
+ break;
21
+ case 2:
22
+ output += '==';
23
+ break;
24
+ case 3:
25
+ output += '=';
26
+ break;
27
+ default:
28
+ throw new Error('Illegal base64url string!');
29
+ }
30
+ try {
31
+ return b64DecodeUnicode(output);
32
+ } catch (err) {
33
+ return atob(output);
34
+ }
35
+ };
36
+ export default function (token) {
37
+ try {
38
+ const body = token.split('.')[1];
39
+ return JSON.parse(b64Decode(body));
40
+ } catch (e) {
41
+ if (e instanceof Error) {
42
+ throw new Error('Invalid token specified: ' + e.message);
43
+ }
44
+ throw e;
45
+ }
46
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.2.1",
3
+ "version": "21.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -23,10 +23,10 @@ export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
23
23
  get: function get() {
24
24
  var reason = this.reason,
25
25
  id = this.id,
26
- _this$metadata = this.metadata;
27
- _this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
28
- var collectionName = _this$metadata.collectionName,
29
- occurrenceKey = _this$metadata.occurrenceKey;
26
+ _this$metadata = this.metadata,
27
+ _this$metadata2 = _this$metadata === void 0 ? {} : _this$metadata,
28
+ collectionName = _this$metadata2.collectionName,
29
+ occurrenceKey = _this$metadata2.occurrenceKey;
30
30
  return {
31
31
  reason: reason,
32
32
  id: id,