@aws-amplify/storage 4.5.14 → 4.5.15-unstable.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 (75) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/lib/.tsbuildinfo +3 -0
  3. package/lib/Storage.d.ts +104 -0
  4. package/lib/Storage.js +54 -69
  5. package/lib/Storage.js.map +1 -1
  6. package/lib/common/S3ClientUtils.d.ts +33 -0
  7. package/lib/common/S3ClientUtils.js +9 -55
  8. package/lib/common/S3ClientUtils.js.map +1 -1
  9. package/lib/common/StorageConstants.d.ts +4 -0
  10. package/lib/common/StorageErrorStrings.d.ts +16 -0
  11. package/lib/common/StorageUtils.d.ts +4 -0
  12. package/lib/index.d.ts +4 -0
  13. package/lib/index.js +5 -58
  14. package/lib/index.js.map +1 -1
  15. package/lib/providers/AWSS3Provider.d.ts +83 -0
  16. package/lib/providers/AWSS3Provider.js +70 -149
  17. package/lib/providers/AWSS3Provider.js.map +1 -1
  18. package/lib/providers/AWSS3ProviderManagedUpload.d.ts +41 -0
  19. package/lib/providers/AWSS3ProviderManagedUpload.js +19 -82
  20. package/lib/providers/AWSS3ProviderManagedUpload.js.map +1 -1
  21. package/lib/providers/AWSS3UploadTask.d.ts +107 -0
  22. package/lib/providers/AWSS3UploadTask.js +29 -87
  23. package/lib/providers/AWSS3UploadTask.js.map +1 -1
  24. package/lib/providers/axios-http-handler.d.ts +40 -0
  25. package/lib/providers/axios-http-handler.js +6 -45
  26. package/lib/providers/axios-http-handler.js.map +1 -1
  27. package/lib/providers/index.d.ts +1 -0
  28. package/lib/types/AWSS3Provider.d.ts +121 -0
  29. package/lib/types/Provider.d.ts +22 -0
  30. package/lib/types/Storage.d.ts +79 -0
  31. package/lib/types/Storage.js +2 -12
  32. package/lib/types/Storage.js.map +1 -1
  33. package/lib/types/index.d.ts +3 -0
  34. package/lib/types/index.js +2 -12
  35. package/lib/types/index.js.map +1 -1
  36. package/lib-esm/.tsbuildinfo +3 -0
  37. package/lib-esm/Storage.d.ts +1 -4
  38. package/lib-esm/Storage.js +49 -61
  39. package/lib-esm/Storage.js.map +1 -1
  40. package/lib-esm/common/S3ClientUtils.js +1 -47
  41. package/lib-esm/common/S3ClientUtils.js.map +1 -1
  42. package/lib-esm/index.d.ts +3 -8
  43. package/lib-esm/index.js +5 -57
  44. package/lib-esm/index.js.map +1 -1
  45. package/lib-esm/providers/AWSS3Provider.d.ts +3 -7
  46. package/lib-esm/providers/AWSS3Provider.js +54 -126
  47. package/lib-esm/providers/AWSS3Provider.js.map +1 -1
  48. package/lib-esm/providers/AWSS3ProviderManagedUpload.js +3 -59
  49. package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +1 -1
  50. package/lib-esm/providers/AWSS3UploadTask.js +1 -56
  51. package/lib-esm/providers/AWSS3UploadTask.js.map +1 -1
  52. package/lib-esm/providers/axios-http-handler.js +3 -39
  53. package/lib-esm/providers/axios-http-handler.js.map +1 -1
  54. package/lib-esm/types/AWSS3Provider.d.ts +6 -5
  55. package/lib-esm/types/Storage.js +2 -12
  56. package/lib-esm/types/Storage.js.map +1 -1
  57. package/lib-esm/types/index.js +2 -12
  58. package/lib-esm/types/index.js.map +1 -1
  59. package/package.json +14 -10
  60. package/src/Storage.ts +59 -33
  61. package/src/index.ts +5 -57
  62. package/src/providers/AWSS3Provider.ts +41 -50
  63. package/src/providers/AWSS3ProviderManagedUpload.ts +2 -12
  64. package/src/providers/axios-http-handler.ts +2 -12
  65. package/src/types/AWSS3Provider.ts +6 -6
  66. package/src/types/Provider.ts +2 -12
  67. package/src/types/Storage.ts +2 -12
  68. package/src/types/index.ts +2 -12
  69. package/build.js +0 -5
  70. package/dist/aws-amplify-storage.js +0 -51312
  71. package/dist/aws-amplify-storage.js.map +0 -1
  72. package/dist/aws-amplify-storage.min.js +0 -26
  73. package/dist/aws-amplify-storage.min.js.map +0 -1
  74. package/index.js +0 -7
  75. package/webpack.config.dev.js +0 -6
@@ -1,22 +1,12 @@
1
- /*
2
- * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
  import {
14
4
  ConsoleLogger as Logger,
15
5
  Credentials,
16
- Parser,
17
6
  ICredentials,
18
7
  StorageHelper,
19
8
  Hub,
9
+ parseAWSExports,
20
10
  } from '@aws-amplify/core';
21
11
  import {
22
12
  S3Client,
@@ -45,7 +35,6 @@ import {
45
35
  S3ProviderGetOuput,
46
36
  S3ProviderPutConfig,
47
37
  S3ProviderRemoveConfig,
48
- S3ProviderListOutput,
49
38
  S3ProviderListConfig,
50
39
  S3ProviderCopyConfig,
51
40
  S3ProviderCopyOutput,
@@ -58,6 +47,7 @@ import {
58
47
  ResumableUploadConfig,
59
48
  UploadTask,
60
49
  S3ClientOptions,
50
+ S3ProviderListOutput,
61
51
  } from '../types';
62
52
  import { StorageErrorStrings } from '../common/StorageErrorStrings';
63
53
  import { dispatchStorageEvent } from '../common/StorageUtils';
@@ -69,7 +59,6 @@ import {
69
59
  autoAdjustClockskewMiddlewareOptions,
70
60
  createS3Client,
71
61
  } from '../common/S3ClientUtils';
72
- import { S3ProviderListOutputWithToken } from '.././types/AWSS3Provider';
73
62
  import { AWSS3ProviderManagedUpload } from './AWSS3ProviderManagedUpload';
74
63
  import { AWSS3UploadTask, TaskEvents } from './AWSS3UploadTask';
75
64
  import { UPLOADS_STORAGE_KEY } from '../common/StorageConstants';
@@ -138,7 +127,7 @@ export class AWSS3Provider implements StorageProvider {
138
127
  public configure(config?): object {
139
128
  logger.debug('configure Storage', config);
140
129
  if (!config) return this._config;
141
- const amplifyConfig = Parser.parseMobilehubConfig(config);
130
+ const amplifyConfig = parseAWSExports(config);
142
131
  this._config = Object.assign({}, this._config, amplifyConfig.Storage);
143
132
  if (!this._config.bucket) {
144
133
  logger.debug('Do not have bucket yet');
@@ -685,16 +674,16 @@ export class AWSS3Provider implements StorageProvider {
685
674
  params: ListObjectsV2Request,
686
675
  opt: S3ClientOptions,
687
676
  prefix: string
688
- ): Promise<S3ProviderListOutputWithToken> {
689
- const result: S3ProviderListOutputWithToken = {
690
- contents: [],
691
- nextToken: '',
677
+ ): Promise<S3ProviderListOutput> {
678
+ const list: S3ProviderListOutput = {
679
+ results: [],
680
+ hasNextToken: false,
692
681
  };
693
682
  const s3 = this._createNewS3Client(opt);
694
683
  const listObjectsV2Command = new ListObjectsV2Command({ ...params });
695
684
  const response = await s3.send(listObjectsV2Command);
696
685
  if (response && response.Contents) {
697
- result.contents = response.Contents.map(item => {
686
+ list.results = response.Contents.map(item => {
698
687
  return {
699
688
  key: item.Key.substr(prefix.length),
700
689
  eTag: item.ETag,
@@ -702,17 +691,18 @@ export class AWSS3Provider implements StorageProvider {
702
691
  size: item.Size,
703
692
  };
704
693
  });
705
- result.nextToken = response.NextContinuationToken;
694
+ list.nextToken = response.NextContinuationToken;
695
+ list.hasNextToken = response.IsTruncated;
706
696
  }
707
- return result;
697
+ return list;
708
698
  }
709
699
 
710
700
  /**
711
701
  * List bucket objects relative to the level and prefix specified
712
702
  * @param {string} path - the path that contains objects
713
703
  * @param {S3ProviderListConfig} [config] - Optional configuration for the underlying S3 command
714
- * @return {Promise<S3ProviderListOutput>} - Promise resolves to list of keys, eTags, lastModified and file size for
715
- * all objects in path
704
+ * @return {Promise<S3ProviderListOutput>} - Promise resolves to list of keys, eTags, lastModified
705
+ * and file size for all objects in path
716
706
  */
717
707
  public async list(
718
708
  path: string,
@@ -723,49 +713,55 @@ export class AWSS3Provider implements StorageProvider {
723
713
  throw new Error(StorageErrorStrings.NO_CREDENTIALS);
724
714
  }
725
715
  const opt: S3ClientOptions = Object.assign({}, this._config, config);
726
- const { bucket, track, maxKeys } = opt;
716
+ const { bucket, track, pageSize, nextToken } = opt;
727
717
  const prefix = this._prefix(opt);
728
718
  const final_path = prefix + path;
729
719
  logger.debug('list ' + path + ' from ' + final_path);
730
720
  try {
731
- const list: S3ProviderListOutput = [];
732
- let token: string;
733
- let listResult: S3ProviderListOutputWithToken;
721
+ const list: S3ProviderListOutput = {
722
+ results: [],
723
+ hasNextToken: false,
724
+ };
725
+ const MAX_PAGE_SIZE = 1000;
726
+ let listResult: S3ProviderListOutput;
734
727
  const params: ListObjectsV2Request = {
735
728
  Bucket: bucket,
736
729
  Prefix: final_path,
737
- MaxKeys: 1000,
730
+ MaxKeys: MAX_PAGE_SIZE,
731
+ ContinuationToken: nextToken,
738
732
  };
739
- if (maxKeys === 'ALL') {
733
+ params.ContinuationToken = nextToken;
734
+ if (pageSize === 'ALL') {
740
735
  do {
741
- params.ContinuationToken = token;
742
- params.MaxKeys = 1000;
743
736
  listResult = await this._list(params, opt, prefix);
744
- list.push(...listResult.contents);
745
- if (listResult.nextToken) token = listResult.nextToken;
737
+ list.results.push(...listResult.results);
738
+ if (listResult.nextToken)
739
+ params.ContinuationToken = listResult.nextToken;
746
740
  } while (listResult.nextToken);
747
741
  } else {
748
- maxKeys < 1000 || typeof maxKeys === 'string'
749
- ? (params.MaxKeys = maxKeys)
750
- : (params.MaxKeys = 1000);
742
+ if (
743
+ pageSize &&
744
+ pageSize <= MAX_PAGE_SIZE &&
745
+ typeof pageSize === 'number'
746
+ )
747
+ params.MaxKeys = pageSize;
748
+ else logger.warn(`pageSize should be from 0 - ${MAX_PAGE_SIZE}.`);
751
749
  listResult = await this._list(params, opt, prefix);
752
- list.push(...listResult.contents);
753
- if (maxKeys > 1000)
754
- logger.warn(
755
- "maxkeys can be from 0 - 1000 or 'ALL'. To list all files you can set maxKeys to 'ALL'."
756
- );
750
+ list.results.push(...listResult.results);
751
+ list.hasNextToken = listResult.hasNextToken;
752
+ list.nextToken = null ?? listResult.nextToken;
757
753
  }
758
754
  dispatchStorageEvent(
759
755
  track,
760
756
  'list',
761
757
  { method: 'list', result: 'success' },
762
758
  null,
763
- `${list.length} items returned from list operation`
759
+ `${list.results.length} items returned from list operation`
764
760
  );
765
761
  logger.debug('list', list);
766
762
  return list;
767
763
  } catch (error) {
768
- logger.warn('list error', error);
764
+ logger.error('list InvalidArgument', error);
769
765
  dispatchStorageEvent(
770
766
  track,
771
767
  'list',
@@ -851,8 +847,3 @@ export class AWSS3Provider implements StorageProvider {
851
847
  return s3client;
852
848
  }
853
849
  }
854
-
855
- /**
856
- * @deprecated use named import
857
- */
858
- export default AWSS3Provider;
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
 
14
4
  import { ConsoleLogger as Logger } from '@aws-amplify/core';
15
5
  import {
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
 
14
4
  import { HttpHandlerOptions } from '@aws-sdk/types';
15
5
  import { HttpHandler, HttpRequest, HttpResponse } from '@aws-sdk/protocol-http';
@@ -95,18 +95,20 @@ export type S3ProviderRemoveConfig = CommonStorageOptions & {
95
95
  provider?: 'AWSS3';
96
96
  };
97
97
 
98
- export type S3ProviderListOutputWithToken = {
99
- contents: S3ProviderListOutputItem[];
100
- nextToken: string;
98
+ export type S3ProviderListOutput = {
99
+ results: S3ProviderListOutputItem[];
100
+ nextToken?: string;
101
+ hasNextToken: boolean;
101
102
  };
102
103
 
103
104
  export type S3ProviderRemoveOutput = DeleteObjectCommandOutput;
104
105
 
105
106
  export type S3ProviderListConfig = CommonStorageOptions & {
106
107
  bucket?: string;
107
- maxKeys?: number | 'ALL';
108
+ pageSize?: number | 'ALL';
108
109
  provider?: 'AWSS3';
109
110
  identityId?: string;
111
+ nextToken?: string;
110
112
  };
111
113
 
112
114
  export type S3ClientOptions = StorageOptions & {
@@ -120,8 +122,6 @@ export interface S3ProviderListOutputItem {
120
122
  size: ListObjectsCommandOutputContent['Size'];
121
123
  }
122
124
 
123
- export type S3ProviderListOutput = S3ProviderListOutputItem[];
124
-
125
125
  export interface S3CopyTarget {
126
126
  key: string;
127
127
  level?: StorageAccessLevel;
@@ -1,16 +1,6 @@
1
1
  import { StorageCopySource, StorageCopyDestination } from './Storage';
2
- /*
3
- * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
6
- * the License. A copy of the License is located at
7
- *
8
- * http://aws.amazon.com/apache2.0/
9
- *
10
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
12
- * and limitations under the License.
13
- */
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
14
4
  export interface StorageProvider {
15
5
  // you need to implement those methods
16
6
 
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
  /**
14
4
  * Storage instance options
15
5
  */
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
 
14
4
  export * from './Storage';
15
5
  export * from './Provider';
package/build.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const build = require('../../scripts/build');
4
-
5
- build(process.argv[2], process.argv[3]);