@aws-amplify/ui-react-storage 3.1.5 → 3.2.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.
@@ -23,7 +23,7 @@ const logger = getLogger('Storage');
23
23
  const MISSING_REQUIRED_PROPS_MESSAGE = '`StorageManager` requires a `maxFileCount` prop to be provided.';
24
24
  const ACCESS_LEVEL_WITH_PATH_CALLBACK_MESSAGE = '`StorageManager` does not allow usage of a `path` callback prop with an `accessLevel` prop.';
25
25
  const ACCESS_LEVEL_DEPRECATION_MESSAGE = '`accessLevel` has been deprecated and will be removed in a future major version. See migration notes at https://ui.docs.amplify.aws/react/connected-components/storage/storagemanager';
26
- const StorageManagerBase = React.forwardRef(function StorageManager({ acceptedFileTypes = [], accessLevel, autoUpload = true, components, defaultFiles, displayText: overrideDisplayText, isResumable = false, maxFileCount, maxFileSize, onFileRemove, onUploadError, onUploadStart, onUploadSuccess, path, processFile, showThumbnails = true, }, ref) {
26
+ const StorageManagerBase = React.forwardRef(function StorageManager({ acceptedFileTypes = [], accessLevel, autoUpload = true, components, defaultFiles, displayText: overrideDisplayText, isResumable = false, maxFileCount, maxFileSize, onFileRemove, onUploadError, onUploadStart, onUploadSuccess, path, processFile, showThumbnails = true, useAccelerateEndpoint, }, ref) {
27
27
  if (!maxFileCount) {
28
28
  // eslint-disable-next-line no-console
29
29
  console.warn(MISSING_REQUIRED_PROPS_MESSAGE);
@@ -90,6 +90,7 @@ const StorageManagerBase = React.forwardRef(function StorageManager({ acceptedFi
90
90
  setUploadSuccess,
91
91
  processFile,
92
92
  path,
93
+ useAccelerateEndpoint,
93
94
  });
94
95
  const onFilePickerChange = (event) => {
95
96
  const { files } = event.target;
@@ -4,7 +4,7 @@ import { getInput } from '../../utils/getInput.mjs';
4
4
  import { uploadFile } from '../../utils/uploadFile.mjs';
5
5
  import { FileStatus } from '../../types.mjs';
6
6
 
7
- function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, }) {
7
+ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, useAccelerateEndpoint, }) {
8
8
  React.useEffect(() => {
9
9
  const filesReadyToUpload = files.filter((file) => file.status === FileStatus.QUEUED);
10
10
  if (filesReadyToUpload.length > maxFileCount) {
@@ -31,6 +31,7 @@ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProce
31
31
  onProgress,
32
32
  path,
33
33
  processFile,
34
+ useAccelerateEndpoint,
34
35
  });
35
36
  uploadFile({
36
37
  input,
@@ -71,6 +72,7 @@ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProce
71
72
  setUploadSuccess,
72
73
  processFile,
73
74
  path,
75
+ useAccelerateEndpoint,
74
76
  ]);
75
77
  }
76
78
 
@@ -2,29 +2,37 @@ import { fetchAuthSession } from 'aws-amplify/auth';
2
2
  import { isTypedFunction, isString } from '@aws-amplify/ui';
3
3
  import { resolveFile } from './resolveFile.mjs';
4
4
 
5
- const getInput = ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, }) => {
5
+ const getInput = ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, useAccelerateEndpoint, }) => {
6
6
  return async () => {
7
7
  const hasCallbackPath = isTypedFunction(path);
8
8
  const hasStringPath = isString(path);
9
9
  const hasKeyInput = !!accessLevel && !hasCallbackPath;
10
10
  const { file: data, key: processedKey, ...rest } = await resolveFile({ file, key, processFile });
11
- if (processFile) {
12
- // provide post-processing value of target `key`
13
- onProcessFileSuccess({ processedKey });
14
- }
15
11
  const contentType = file.type || 'binary/octet-stream';
16
12
  // IMPORTANT: always pass `...rest` here for backwards compatibility
17
- const options = { contentType, onProgress, ...rest };
13
+ const options = { contentType, onProgress, useAccelerateEndpoint, ...rest };
14
+ let inputResult;
18
15
  if (hasKeyInput) {
19
16
  // legacy handling of `path` is to prefix to `fileKey`
20
17
  const resolvedKey = hasStringPath
21
18
  ? `${path}${processedKey}`
22
19
  : processedKey;
23
- return { data, key: resolvedKey, options: { ...options, accessLevel } };
20
+ inputResult = {
21
+ data,
22
+ key: resolvedKey,
23
+ options: { ...options, accessLevel },
24
+ };
25
+ }
26
+ else {
27
+ const { identityId } = await fetchAuthSession();
28
+ const resolvedPath = `${hasCallbackPath ? path({ identityId }) : path}${processedKey}`;
29
+ inputResult = { data: file, path: resolvedPath, options };
30
+ }
31
+ if (processFile) {
32
+ // provide post-processing value of target `key`
33
+ onProcessFileSuccess({ processedKey });
24
34
  }
25
- const { identityId } = await fetchAuthSession();
26
- const resolvedPath = `${hasCallbackPath ? path({ identityId }) : path}${processedKey}`;
27
- return { data: file, path: resolvedPath, options };
35
+ return inputResult;
28
36
  };
29
37
  };
30
38
 
@@ -1,3 +1,3 @@
1
- const VERSION = '3.1.5';
1
+ const VERSION = '3.2.0';
2
2
 
3
3
  export { VERSION };
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ function _interopNamespace(e) {
33
33
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
34
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
35
35
 
36
- const VERSION = '3.1.5';
36
+ const VERSION = '3.2.0';
37
37
 
38
38
  const MISSING_REQUIRED_PROP_MESSAGE = '`StorageImage` requires either an `imgKey` or `path` prop.';
39
39
  const HAS_DEPRECATED_PROPS_MESSAGE = '`imgKey`, `accessLevel`, and `identityId` will be replaced with `path` in a future major version. See https://ui.docs.amplify.aws/react/connected-components/storage/storageimage#props';
@@ -404,29 +404,37 @@ const resolveFile = ({ processFile, ...input }) => {
404
404
  });
405
405
  };
406
406
 
407
- const getInput = ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, }) => {
407
+ const getInput = ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, useAccelerateEndpoint, }) => {
408
408
  return async () => {
409
409
  const hasCallbackPath = ui.isTypedFunction(path);
410
410
  const hasStringPath = ui.isString(path);
411
411
  const hasKeyInput = !!accessLevel && !hasCallbackPath;
412
412
  const { file: data, key: processedKey, ...rest } = await resolveFile({ file, key, processFile });
413
- if (processFile) {
414
- // provide post-processing value of target `key`
415
- onProcessFileSuccess({ processedKey });
416
- }
417
413
  const contentType = file.type || 'binary/octet-stream';
418
414
  // IMPORTANT: always pass `...rest` here for backwards compatibility
419
- const options = { contentType, onProgress, ...rest };
415
+ const options = { contentType, onProgress, useAccelerateEndpoint, ...rest };
416
+ let inputResult;
420
417
  if (hasKeyInput) {
421
418
  // legacy handling of `path` is to prefix to `fileKey`
422
419
  const resolvedKey = hasStringPath
423
420
  ? `${path}${processedKey}`
424
421
  : processedKey;
425
- return { data, key: resolvedKey, options: { ...options, accessLevel } };
422
+ inputResult = {
423
+ data,
424
+ key: resolvedKey,
425
+ options: { ...options, accessLevel },
426
+ };
427
+ }
428
+ else {
429
+ const { identityId } = await auth.fetchAuthSession();
430
+ const resolvedPath = `${hasCallbackPath ? path({ identityId }) : path}${processedKey}`;
431
+ inputResult = { data: file, path: resolvedPath, options };
432
+ }
433
+ if (processFile) {
434
+ // provide post-processing value of target `key`
435
+ onProcessFileSuccess({ processedKey });
426
436
  }
427
- const { identityId } = await auth.fetchAuthSession();
428
- const resolvedPath = `${hasCallbackPath ? path({ identityId }) : path}${processedKey}`;
429
- return { data: file, path: resolvedPath, options };
437
+ return inputResult;
430
438
  };
431
439
  };
432
440
 
@@ -452,7 +460,7 @@ async function uploadFile({ input, onError, onStart, onComplete, }) {
452
460
  return uploadTask;
453
461
  }
454
462
 
455
- function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, }) {
463
+ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, useAccelerateEndpoint, }) {
456
464
  React__namespace.useEffect(() => {
457
465
  const filesReadyToUpload = files.filter((file) => file.status === FileStatus.QUEUED);
458
466
  if (filesReadyToUpload.length > maxFileCount) {
@@ -479,6 +487,7 @@ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProce
479
487
  onProgress,
480
488
  path,
481
489
  processFile,
490
+ useAccelerateEndpoint,
482
491
  });
483
492
  uploadFile({
484
493
  input,
@@ -519,6 +528,7 @@ function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProce
519
528
  setUploadSuccess,
520
529
  processFile,
521
530
  path,
531
+ useAccelerateEndpoint,
522
532
  ]);
523
533
  }
524
534
 
@@ -652,7 +662,7 @@ const logger = ui.getLogger('Storage');
652
662
  const MISSING_REQUIRED_PROPS_MESSAGE = '`StorageManager` requires a `maxFileCount` prop to be provided.';
653
663
  const ACCESS_LEVEL_WITH_PATH_CALLBACK_MESSAGE = '`StorageManager` does not allow usage of a `path` callback prop with an `accessLevel` prop.';
654
664
  const ACCESS_LEVEL_DEPRECATION_MESSAGE = '`accessLevel` has been deprecated and will be removed in a future major version. See migration notes at https://ui.docs.amplify.aws/react/connected-components/storage/storagemanager';
655
- const StorageManagerBase = React__namespace.forwardRef(function StorageManager({ acceptedFileTypes = [], accessLevel, autoUpload = true, components, defaultFiles, displayText: overrideDisplayText, isResumable = false, maxFileCount, maxFileSize, onFileRemove, onUploadError, onUploadStart, onUploadSuccess, path, processFile, showThumbnails = true, }, ref) {
665
+ const StorageManagerBase = React__namespace.forwardRef(function StorageManager({ acceptedFileTypes = [], accessLevel, autoUpload = true, components, defaultFiles, displayText: overrideDisplayText, isResumable = false, maxFileCount, maxFileSize, onFileRemove, onUploadError, onUploadStart, onUploadSuccess, path, processFile, showThumbnails = true, useAccelerateEndpoint, }, ref) {
656
666
  if (!maxFileCount) {
657
667
  // eslint-disable-next-line no-console
658
668
  console.warn(MISSING_REQUIRED_PROPS_MESSAGE);
@@ -719,6 +729,7 @@ const StorageManagerBase = React__namespace.forwardRef(function StorageManager({
719
729
  setUploadSuccess,
720
730
  processFile,
721
731
  path,
732
+ useAccelerateEndpoint,
722
733
  });
723
734
  const onFilePickerChange = (event) => {
724
735
  const { files } = event.target;
@@ -1,7 +1,7 @@
1
1
  import { PathCallback } from '../../utils';
2
2
  import { StorageManagerProps } from '../../types';
3
3
  import { UseStorageManager } from '../useStorageManager';
4
- export interface UseUploadFilesProps extends Pick<StorageManagerProps, 'isResumable' | 'onUploadSuccess' | 'onUploadError' | 'onUploadStart' | 'maxFileCount' | 'processFile'>, Pick<UseStorageManager, 'setUploadingFile' | 'setUploadProgress' | 'setUploadSuccess' | 'files'> {
4
+ export interface UseUploadFilesProps extends Pick<StorageManagerProps, 'isResumable' | 'onUploadSuccess' | 'onUploadError' | 'onUploadStart' | 'maxFileCount' | 'processFile' | 'useAccelerateEndpoint'>, Pick<UseStorageManager, 'setUploadingFile' | 'setUploadProgress' | 'setUploadSuccess' | 'files'> {
5
5
  accessLevel?: StorageManagerProps['accessLevel'];
6
6
  onProcessFileSuccess: (input: {
7
7
  id: string;
@@ -9,4 +9,4 @@ export interface UseUploadFilesProps extends Pick<StorageManagerProps, 'isResuma
9
9
  }) => void;
10
10
  path?: string | PathCallback;
11
11
  }
12
- export declare function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, }: UseUploadFilesProps): void;
12
+ export declare function useUploadFiles({ accessLevel, files, isResumable, maxFileCount, onProcessFileSuccess, onUploadError, onUploadStart, onUploadSuccess, path, processFile, setUploadingFile, setUploadProgress, setUploadSuccess, useAccelerateEndpoint, }: UseUploadFilesProps): void;
@@ -26,6 +26,7 @@ export type DefaultFile = Pick<StorageFile, 'key'>;
26
26
  export interface ProcessFileParams extends Record<string, any> {
27
27
  file: File;
28
28
  key: string;
29
+ useAccelerateEndpoint?: boolean;
29
30
  }
30
31
  export type ProcessFile = (params: ProcessFileParams) => Promise<ProcessFileParams> | ProcessFileParams;
31
32
  export interface StorageManagerHandle {
@@ -113,6 +114,7 @@ export interface StorageManagerProps {
113
114
  * Provided value is prefixed to the file `key` for each file
114
115
  */
115
116
  path?: string;
117
+ useAccelerateEndpoint?: boolean;
116
118
  }
117
119
  export interface StorageManagerPathProps extends Omit<StorageManagerProps, 'accessLevel' | 'path'> {
118
120
  /**
@@ -123,4 +125,5 @@ export interface StorageManagerPathProps extends Omit<StorageManagerProps, 'acce
123
125
  */
124
126
  path: string | PathCallback;
125
127
  accessLevel?: never;
128
+ useAccelerateEndpoint?: boolean;
126
129
  }
@@ -12,5 +12,6 @@ export interface GetInputParams {
12
12
  onProgress: NonNullable<UploadDataWithPathInput['options']>['onProgress'];
13
13
  path: string | PathCallback | undefined;
14
14
  processFile: ProcessFile | undefined;
15
+ useAccelerateEndpoint?: boolean;
15
16
  }
16
- export declare const getInput: ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, }: GetInputParams) => () => Promise<PathInput | UploadDataInput>;
17
+ export declare const getInput: ({ accessLevel, file, key, onProcessFileSuccess, onProgress, path, processFile, useAccelerateEndpoint, }: GetInputParams) => () => Promise<PathInput | UploadDataInput>;
@@ -1 +1 @@
1
- export declare const VERSION = "3.1.5";
1
+ export declare const VERSION = "3.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-storage",
3
- "version": "3.1.5",
3
+ "version": "3.2.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -39,9 +39,9 @@
39
39
  "typecheck": "tsc --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@aws-amplify/ui": "6.0.17",
43
- "@aws-amplify/ui-react": "6.1.14",
44
- "@aws-amplify/ui-react-core": "3.0.17",
42
+ "@aws-amplify/ui": "6.1.0",
43
+ "@aws-amplify/ui-react": "6.2.0",
44
+ "@aws-amplify/ui-react-core": "3.0.18",
45
45
  "lodash": "4.17.21",
46
46
  "tslib": "^2.5.2"
47
47
  },