@aws-amplify/storage 5.6.4-graphql-api-functional-options.1 → 5.6.4-unstable.28bc873.6
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/lib/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
- package/lib/AwsClients/S3/abortMultipartUpload.js +85 -0
- package/lib/AwsClients/S3/base.d.ts +54 -0
- package/lib/AwsClients/S3/base.js +75 -0
- package/lib/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
- package/lib/AwsClients/S3/completeMultipartUpload.js +162 -0
- package/lib/AwsClients/S3/copyObject.d.ts +24 -0
- package/lib/AwsClients/S3/copyObject.js +98 -0
- package/lib/AwsClients/S3/createMultipartUpload.d.ts +21 -0
- package/lib/AwsClients/S3/createMultipartUpload.js +95 -0
- package/lib/AwsClients/S3/deleteObject.d.ts +20 -0
- package/lib/AwsClients/S3/deleteObject.js +86 -0
- package/lib/AwsClients/S3/getObject.d.ts +27 -0
- package/lib/AwsClients/S3/getObject.js +216 -0
- package/lib/AwsClients/S3/headObject.d.ts +20 -0
- package/lib/AwsClients/S3/headObject.js +96 -0
- package/lib/AwsClients/S3/index.d.ts +13 -0
- package/lib/AwsClients/S3/index.js +30 -0
- package/lib/AwsClients/S3/index.native.d.ts +14 -0
- package/lib/AwsClients/S3/index.native.js +31 -0
- package/lib/AwsClients/S3/listObjectsV2.d.ts +20 -0
- package/lib/AwsClients/S3/listObjectsV2.js +146 -0
- package/lib/AwsClients/S3/listParts.d.ts +20 -0
- package/lib/AwsClients/S3/listParts.js +110 -0
- package/lib/AwsClients/S3/putObject.d.ts +23 -0
- package/lib/AwsClients/S3/putObject.js +93 -0
- package/lib/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
- package/lib/AwsClients/S3/runtime/base64/index.browser.js +20 -0
- package/lib/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
- package/lib/AwsClients/S3/runtime/base64/index.native.js +17 -0
- package/lib/AwsClients/S3/runtime/constants.d.ts +9 -0
- package/lib/AwsClients/S3/runtime/constants.js +14 -0
- package/lib/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
- package/lib/AwsClients/S3/runtime/contentSha256middleware.js +70 -0
- package/lib/AwsClients/S3/runtime/index.browser.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.browser.js +20 -0
- package/lib/AwsClients/S3/runtime/index.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.js +21 -0
- package/lib/AwsClients/S3/runtime/index.native.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.native.js +20 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.js +15 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.js +21 -0
- package/lib/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
- package/lib/AwsClients/S3/runtime/xhrTransferHandler.js +201 -0
- package/lib/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/xmlParser/dom.js +92 -0
- package/lib/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
- package/lib/AwsClients/S3/runtime/xmlParser/pureJs.js +57 -0
- package/lib/AwsClients/S3/types.d.ts +2857 -0
- package/lib/AwsClients/S3/types.js +4 -0
- package/lib/AwsClients/S3/uploadPart.d.ts +20 -0
- package/lib/AwsClients/S3/uploadPart.js +96 -0
- package/lib/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
- package/lib/AwsClients/S3/utils/deserializeHelpers.js +153 -0
- package/lib/AwsClients/S3/utils/index.d.ts +5 -0
- package/lib/AwsClients/S3/utils/index.js +30 -0
- package/lib/AwsClients/S3/utils/parsePayload.d.ts +3 -0
- package/lib/AwsClients/S3/utils/parsePayload.js +96 -0
- package/lib/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
- package/lib/AwsClients/S3/utils/serializeHelpers.js +183 -0
- package/lib/Storage.d.ts +5 -5
- package/lib/Storage.js +60 -31
- package/lib/common/S3ClientUtils.d.ts +24 -15
- package/lib/common/S3ClientUtils.js +83 -95
- package/lib/common/StorageConstants.d.ts +0 -1
- package/lib/common/StorageConstants.js +3 -2
- package/lib/common/StorageErrorStrings.js +3 -1
- package/lib/common/StorageUtils.js +12 -6
- package/lib/index.js +19 -4
- package/lib/providers/AWSS3Provider.d.ts +4 -8
- package/lib/providers/AWSS3Provider.js +210 -139
- package/lib/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
- package/lib/providers/AWSS3ProviderManagedUpload.js +184 -98
- package/lib/providers/AWSS3UploadTask.d.ts +8 -8
- package/lib/providers/AWSS3UploadTask.js +226 -129
- package/lib/providers/index.js +4 -2
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AWSS3Provider.d.ts +62 -62
- package/lib/types/AWSS3Provider.js +0 -1
- package/lib/types/Provider.d.ts +1 -1
- package/lib/types/Provider.js +2 -1
- package/lib/types/Storage.d.ts +23 -23
- package/lib/types/Storage.js +0 -1
- package/lib/types/index.js +17 -1
- package/lib-esm/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
- package/lib-esm/AwsClients/S3/abortMultipartUpload.js +82 -0
- package/lib-esm/AwsClients/S3/base.d.ts +54 -0
- package/lib-esm/AwsClients/S3/base.js +71 -0
- package/lib-esm/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
- package/lib-esm/AwsClients/S3/completeMultipartUpload.js +159 -0
- package/lib-esm/AwsClients/S3/copyObject.d.ts +24 -0
- package/lib-esm/AwsClients/S3/copyObject.js +95 -0
- package/lib-esm/AwsClients/S3/createMultipartUpload.d.ts +21 -0
- package/lib-esm/AwsClients/S3/createMultipartUpload.js +92 -0
- package/lib-esm/AwsClients/S3/deleteObject.d.ts +20 -0
- package/lib-esm/AwsClients/S3/deleteObject.js +83 -0
- package/lib-esm/AwsClients/S3/getObject.d.ts +27 -0
- package/lib-esm/AwsClients/S3/getObject.js +212 -0
- package/lib-esm/AwsClients/S3/headObject.d.ts +20 -0
- package/lib-esm/AwsClients/S3/headObject.js +93 -0
- package/lib-esm/AwsClients/S3/index.d.ts +13 -0
- package/lib-esm/AwsClients/S3/index.js +14 -0
- package/lib-esm/AwsClients/S3/index.native.d.ts +14 -0
- package/lib-esm/AwsClients/S3/index.native.js +15 -0
- package/lib-esm/AwsClients/S3/listObjectsV2.d.ts +20 -0
- package/lib-esm/AwsClients/S3/listObjectsV2.js +143 -0
- package/lib-esm/AwsClients/S3/listParts.d.ts +20 -0
- package/lib-esm/AwsClients/S3/listParts.js +107 -0
- package/lib-esm/AwsClients/S3/putObject.d.ts +23 -0
- package/lib-esm/AwsClients/S3/putObject.js +90 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.browser.js +15 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.native.js +12 -0
- package/lib-esm/AwsClients/S3/runtime/constants.d.ts +9 -0
- package/lib-esm/AwsClients/S3/runtime/constants.js +11 -0
- package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
- package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.js +66 -0
- package/lib-esm/AwsClients/S3/runtime/index.browser.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.browser.js +8 -0
- package/lib-esm/AwsClients/S3/runtime/index.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.js +9 -0
- package/lib-esm/AwsClients/S3/runtime/index.native.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.native.js +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.js +12 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.js +18 -0
- package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
- package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.js +196 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.js +89 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.js +54 -0
- package/lib-esm/AwsClients/S3/types.d.ts +2857 -0
- package/lib-esm/AwsClients/S3/types.js +3 -0
- package/lib-esm/AwsClients/S3/uploadPart.d.ts +20 -0
- package/lib-esm/AwsClients/S3/uploadPart.js +93 -0
- package/lib-esm/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
- package/lib-esm/AwsClients/S3/utils/deserializeHelpers.js +144 -0
- package/lib-esm/AwsClients/S3/utils/index.d.ts +5 -0
- package/lib-esm/AwsClients/S3/utils/index.js +7 -0
- package/lib-esm/AwsClients/S3/utils/parsePayload.d.ts +3 -0
- package/lib-esm/AwsClients/S3/utils/parsePayload.js +91 -0
- package/lib-esm/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
- package/lib-esm/AwsClients/S3/utils/serializeHelpers.js +176 -0
- package/lib-esm/Storage.d.ts +5 -5
- package/lib-esm/Storage.js +53 -25
- package/lib-esm/common/S3ClientUtils.d.ts +24 -15
- package/lib-esm/common/S3ClientUtils.js +76 -93
- package/lib-esm/common/StorageConstants.d.ts +0 -1
- package/lib-esm/common/StorageConstants.js +2 -2
- package/lib-esm/common/StorageErrorStrings.js +2 -1
- package/lib-esm/common/StorageUtils.js +2 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/providers/AWSS3Provider.d.ts +4 -8
- package/lib-esm/providers/AWSS3Provider.js +162 -115
- package/lib-esm/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js +172 -87
- package/lib-esm/providers/AWSS3UploadTask.d.ts +8 -8
- package/lib-esm/providers/AWSS3UploadTask.js +202 -106
- package/lib-esm/providers/index.js +2 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AWSS3Provider.d.ts +62 -62
- package/lib-esm/types/AWSS3Provider.js +1 -1
- package/lib-esm/types/Provider.d.ts +1 -1
- package/lib-esm/types/Provider.js +3 -1
- package/lib-esm/types/Storage.d.ts +23 -23
- package/lib-esm/types/Storage.js +1 -1
- package/lib-esm/types/index.js +3 -1
- package/package.json +21 -26
- package/src/AwsClients/S3/abortMultipartUpload.ts +62 -0
- package/src/AwsClients/S3/base.ts +109 -0
- package/src/AwsClients/S3/completeMultipartUpload.ts +154 -0
- package/src/AwsClients/S3/copyObject.ts +90 -0
- package/src/AwsClients/S3/createMultipartUpload.ts +75 -0
- package/src/AwsClients/S3/deleteObject.ts +69 -0
- package/src/AwsClients/S3/getObject.ts +173 -0
- package/src/AwsClients/S3/headObject.ts +91 -0
- package/src/AwsClients/S3/index.native.ts +42 -0
- package/src/AwsClients/S3/index.ts +41 -0
- package/src/AwsClients/S3/listObjectsV2.ts +130 -0
- package/src/AwsClients/S3/listParts.ts +97 -0
- package/src/AwsClients/S3/putObject.ts +94 -0
- package/src/AwsClients/S3/runtime/base64/index.browser.ts +21 -0
- package/src/AwsClients/S3/runtime/base64/index.native.ts +16 -0
- package/src/AwsClients/S3/runtime/constants.ts +16 -0
- package/src/AwsClients/S3/runtime/contentSha256middleware.ts +29 -0
- package/src/AwsClients/S3/runtime/index.browser.ts +14 -0
- package/src/AwsClients/S3/runtime/index.native.ts +14 -0
- package/src/AwsClients/S3/runtime/index.ts +15 -0
- package/src/AwsClients/S3/runtime/s3TransferHandler/fetch.ts +23 -0
- package/src/AwsClients/S3/runtime/s3TransferHandler/xhr.ts +35 -0
- package/src/AwsClients/S3/runtime/xhrTransferHandler.ts +254 -0
- package/src/AwsClients/S3/runtime/xmlParser/dom.ts +92 -0
- package/src/AwsClients/S3/runtime/xmlParser/pureJs.ts +55 -0
- package/src/AwsClients/S3/types.ts +2877 -0
- package/src/AwsClients/S3/uploadPart.ts +83 -0
- package/src/AwsClients/S3/utils/deserializeHelpers.ts +136 -0
- package/src/AwsClients/S3/utils/index.ts +27 -0
- package/src/AwsClients/S3/utils/parsePayload.ts +45 -0
- package/src/AwsClients/S3/utils/serializeHelpers.ts +112 -0
- package/src/Storage.ts +30 -27
- package/src/common/S3ClientUtils.ts +57 -113
- package/src/common/StorageConstants.ts +2 -2
- package/src/common/StorageErrorStrings.ts +2 -0
- package/src/common/StorageUtils.ts +2 -0
- package/src/providers/AWSS3Provider.ts +80 -100
- package/src/providers/AWSS3ProviderManagedUpload.ts +56 -63
- package/src/providers/AWSS3UploadTask.ts +86 -87
- package/src/providers/index.ts +2 -0
- package/src/types/AWSS3Provider.ts +55 -49
- package/src/types/Provider.ts +7 -2
- package/lib/.tsbuildinfo +0 -3
- package/lib/Storage.js.map +0 -1
- package/lib/common/S3ClientUtils.js.map +0 -1
- package/lib/common/StorageConstants.js.map +0 -1
- package/lib/common/StorageErrorStrings.js.map +0 -1
- package/lib/common/StorageUtils.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/providers/AWSS3Provider.js.map +0 -1
- package/lib/providers/AWSS3ProviderManagedUpload.js.map +0 -1
- package/lib/providers/AWSS3UploadTask.js.map +0 -1
- package/lib/providers/axios-http-handler.d.ts +0 -40
- package/lib/providers/axios-http-handler.js +0 -193
- package/lib/providers/axios-http-handler.js.map +0 -1
- package/lib/providers/index.js.map +0 -1
- package/lib/types/AWSS3Provider.js.map +0 -1
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/Storage.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Storage.js.map +0 -1
- package/lib-esm/common/S3ClientUtils.js.map +0 -1
- package/lib-esm/common/StorageConstants.js.map +0 -1
- package/lib-esm/common/StorageErrorStrings.js.map +0 -1
- package/lib-esm/common/StorageUtils.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/providers/AWSS3Provider.js.map +0 -1
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +0 -1
- package/lib-esm/providers/AWSS3UploadTask.js.map +0 -1
- package/lib-esm/providers/axios-http-handler.d.ts +0 -40
- package/lib-esm/providers/axios-http-handler.js +0 -191
- package/lib-esm/providers/axios-http-handler.js.map +0 -1
- package/lib-esm/providers/index.js.map +0 -1
- package/lib-esm/types/AWSS3Provider.js.map +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/Storage.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/providers/axios-http-handler.ts +0 -242
|
@@ -1,32 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
3
|
import {
|
|
2
4
|
Category,
|
|
3
5
|
Credentials,
|
|
4
|
-
CustomUserAgentDetails,
|
|
5
6
|
ICredentials,
|
|
6
7
|
Logger,
|
|
7
8
|
StorageAction,
|
|
8
|
-
|
|
9
|
+
getAmplifyUserAgent,
|
|
9
10
|
} from '@aws-amplify/core';
|
|
11
|
+
import type { Credentials as AwsCredentials } from '@aws-sdk/types';
|
|
12
|
+
import type { EventEmitter } from 'events';
|
|
13
|
+
|
|
10
14
|
import { StorageAccessLevel, CustomPrefix } from '../types';
|
|
11
|
-
import {
|
|
12
|
-
InitializeMiddleware,
|
|
13
|
-
InitializeHandlerOptions,
|
|
14
|
-
FinalizeRequestHandlerOptions,
|
|
15
|
-
FinalizeRequestMiddleware,
|
|
16
|
-
HandlerExecutionContext,
|
|
17
|
-
} from '@aws-sdk/types';
|
|
18
|
-
import { S3ClientConfig, S3Client } from '@aws-sdk/client-s3';
|
|
19
|
-
import { CancelTokenSource } from 'axios';
|
|
20
|
-
import * as events from 'events';
|
|
21
|
-
import { AxiosHttpHandler } from '../providers/axios-http-handler';
|
|
22
|
-
import {
|
|
23
|
-
localTestingStorageEndpoint,
|
|
24
|
-
SET_CONTENT_LENGTH_HEADER,
|
|
25
|
-
} from './StorageConstants';
|
|
15
|
+
import { localTestingStorageEndpoint } from './StorageConstants';
|
|
26
16
|
|
|
27
17
|
const logger = new Logger('S3ClientUtils');
|
|
28
18
|
// placeholder credentials in order to satisfy type requirement, always results in 403 when used
|
|
29
|
-
const INVALID_CRED = { accessKeyId: '', secretAccessKey: '' };
|
|
19
|
+
const INVALID_CRED = { accessKeyId: '', secretAccessKey: '' } as ICredentials;
|
|
30
20
|
|
|
31
21
|
export const getPrefix = (config: {
|
|
32
22
|
credentials: ICredentials;
|
|
@@ -65,57 +55,6 @@ export const getPrefix = (config: {
|
|
|
65
55
|
}
|
|
66
56
|
};
|
|
67
57
|
|
|
68
|
-
export const createPrefixMiddleware =
|
|
69
|
-
(opt: Record<string, any>, key: string): InitializeMiddleware<any, any> =>
|
|
70
|
-
(next, _context) =>
|
|
71
|
-
async args => {
|
|
72
|
-
const credentials = await Credentials.get();
|
|
73
|
-
const cred = Credentials.shear(credentials);
|
|
74
|
-
const prefix = getPrefix({ ...opt, credentials: cred });
|
|
75
|
-
const clonedInput = Object.assign({}, args.input);
|
|
76
|
-
if (Object.prototype.hasOwnProperty.call(args.input, 'Key')) {
|
|
77
|
-
clonedInput.Key = prefix + key;
|
|
78
|
-
args.input = clonedInput;
|
|
79
|
-
} else if (Object.prototype.hasOwnProperty.call(args.input, 'Prefix')) {
|
|
80
|
-
clonedInput.Prefix = prefix + key;
|
|
81
|
-
args.input = clonedInput;
|
|
82
|
-
}
|
|
83
|
-
const result = next(args);
|
|
84
|
-
return result;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const isTimeSkewedError = (err: any): boolean =>
|
|
88
|
-
err.ServerTime &&
|
|
89
|
-
typeof err.Code === 'string' &&
|
|
90
|
-
err.Code === 'RequestTimeTooSkewed';
|
|
91
|
-
|
|
92
|
-
// we want to take the S3Client config in parameter so we can modify it's systemClockOffset
|
|
93
|
-
export const autoAdjustClockskewMiddleware =
|
|
94
|
-
(config: S3ClientConfig): FinalizeRequestMiddleware<any, any> =>
|
|
95
|
-
(next, _context: HandlerExecutionContext) =>
|
|
96
|
-
async args => {
|
|
97
|
-
try {
|
|
98
|
-
return await next(args);
|
|
99
|
-
} catch (err) {
|
|
100
|
-
if (isTimeSkewedError(err)) {
|
|
101
|
-
const serverDate = new Date(err.ServerTime);
|
|
102
|
-
config.systemClockOffset = serverDate.getTime() - Date.now();
|
|
103
|
-
}
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const autoAdjustClockskewMiddlewareOptions: FinalizeRequestHandlerOptions =
|
|
109
|
-
{
|
|
110
|
-
step: 'finalizeRequest',
|
|
111
|
-
name: 'autoAdjustClockskewMiddleware',
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const prefixMiddlewareOptions: InitializeHandlerOptions = {
|
|
115
|
-
step: 'initialize',
|
|
116
|
-
name: 'addPrefixMiddleware',
|
|
117
|
-
};
|
|
118
|
-
|
|
119
58
|
export const credentialsProvider = async () => {
|
|
120
59
|
try {
|
|
121
60
|
const credentials = await Credentials.get();
|
|
@@ -129,56 +68,61 @@ export const credentialsProvider = async () => {
|
|
|
129
68
|
}
|
|
130
69
|
};
|
|
131
70
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
71
|
+
interface S3InputConfig {
|
|
72
|
+
credentials?: AwsCredentials;
|
|
73
|
+
region?: string;
|
|
74
|
+
useAccelerateEndpoint?: boolean;
|
|
75
|
+
abortSignal?: AbortSignal;
|
|
76
|
+
emitter?: EventEmitter;
|
|
77
|
+
storageAction: StorageAction;
|
|
78
|
+
dangerouslyConnectToHttpEndpointForTesting?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface S3ResolvedConfig
|
|
82
|
+
extends Omit<S3InputConfig, 'region' | 'credentials'> {
|
|
83
|
+
region: string;
|
|
84
|
+
userAgentValue?: string;
|
|
85
|
+
credentials: () => Promise<AwsCredentials>;
|
|
86
|
+
customEndpoint?: string;
|
|
87
|
+
forcePathStyle?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A function that persists the s3 configs, so we don't need to
|
|
92
|
+
* assign each config parameter for every s3 API call.
|
|
93
|
+
*
|
|
94
|
+
* @inernal
|
|
95
|
+
*/
|
|
96
|
+
export const loadS3Config = (config: S3InputConfig): S3ResolvedConfig => {
|
|
97
|
+
if (!config.region) {
|
|
98
|
+
// Same error thrown by aws-sdk
|
|
99
|
+
throw new Error('Region is missing.');
|
|
157
100
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
region,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
101
|
+
return {
|
|
102
|
+
...config,
|
|
103
|
+
region: config.region,
|
|
104
|
+
credentials: config.credentials
|
|
105
|
+
? () => Promise.resolve(config.credentials!)
|
|
106
|
+
: credentialsProvider,
|
|
107
|
+
userAgentValue: getAmplifyUserAgent({
|
|
165
108
|
category: Category.Storage,
|
|
166
|
-
action: storageAction,
|
|
109
|
+
action: config.storageAction,
|
|
167
110
|
}),
|
|
168
|
-
...
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
111
|
+
...(config.dangerouslyConnectToHttpEndpointForTesting
|
|
112
|
+
? {
|
|
113
|
+
customEndpoint: localTestingStorageEndpoint,
|
|
114
|
+
forcePathStyle: true,
|
|
115
|
+
}
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
174
118
|
};
|
|
175
119
|
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
120
|
+
const MiB = 1024 * 1024;
|
|
121
|
+
const GiB = 1024 * MiB;
|
|
122
|
+
const TiB = 1024 * GiB;
|
|
179
123
|
|
|
180
|
-
export const DEFAULT_PART_SIZE = 5 *
|
|
181
|
-
export const MAX_OBJECT_SIZE = 5 *
|
|
124
|
+
export const DEFAULT_PART_SIZE = 5 * MiB;
|
|
125
|
+
export const MAX_OBJECT_SIZE = 5 * TiB;
|
|
182
126
|
export const MAX_PARTS_COUNT = 10000;
|
|
183
127
|
export const DEFAULT_QUEUE_SIZE = 4;
|
|
184
128
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
3
|
export const AMPLIFY_SYMBOL = (
|
|
2
4
|
typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
3
5
|
? Symbol.for('amplify_default')
|
|
4
6
|
: '@@amplify_default'
|
|
5
7
|
) as Symbol;
|
|
6
8
|
|
|
7
|
-
export const SET_CONTENT_LENGTH_HEADER = 'contentLengthMiddleware';
|
|
8
|
-
|
|
9
9
|
export const localTestingStorageEndpoint = 'http://localhost:20005';
|
|
10
10
|
|
|
11
11
|
export const UPLOADS_STORAGE_KEY = '__uploadInProgress';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
3
|
export enum StorageErrorStrings {
|
|
2
4
|
NO_CREDENTIALS = 'No credentials',
|
|
3
5
|
NO_SRC_KEY = 'source param should be an object with the property "key" with value of type string',
|
|
@@ -10,27 +10,25 @@ import {
|
|
|
10
10
|
StorageAction,
|
|
11
11
|
} from '@aws-amplify/core';
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import { createRequest } from '@aws-sdk/util-create-request';
|
|
29
|
-
import { S3RequestPresigner } from '@aws-sdk/s3-request-presigner';
|
|
13
|
+
copyObject,
|
|
14
|
+
CopyObjectInput,
|
|
15
|
+
getObject,
|
|
16
|
+
GetObjectInput,
|
|
17
|
+
GetObjectOutput,
|
|
18
|
+
getPresignedGetObjectUrl,
|
|
19
|
+
PutObjectInput,
|
|
20
|
+
headObject,
|
|
21
|
+
DeleteObjectInput,
|
|
22
|
+
deleteObject,
|
|
23
|
+
ListObjectsV2Input,
|
|
24
|
+
listObjectsV2,
|
|
25
|
+
SERVICE_NAME as S3_SERVICE_NAME,
|
|
26
|
+
HeadObjectInput,
|
|
27
|
+
} from '../AwsClients/S3';
|
|
30
28
|
import {
|
|
31
29
|
SEND_DOWNLOAD_PROGRESS_EVENT,
|
|
32
30
|
SEND_UPLOAD_PROGRESS_EVENT,
|
|
33
|
-
} from '
|
|
31
|
+
} from '../AwsClients/S3/utils';
|
|
34
32
|
import {
|
|
35
33
|
StorageOptions,
|
|
36
34
|
StorageProvider,
|
|
@@ -51,24 +49,20 @@ import {
|
|
|
51
49
|
UploadTask,
|
|
52
50
|
S3ClientOptions,
|
|
53
51
|
S3ProviderListOutput,
|
|
54
|
-
S3ProviderGetPropertiesOutput,
|
|
55
52
|
S3ProviderGetPropertiesConfig,
|
|
53
|
+
S3ProviderGetPropertiesOutput,
|
|
56
54
|
} from '../types';
|
|
57
55
|
import { StorageErrorStrings } from '../common/StorageErrorStrings';
|
|
58
56
|
import { dispatchStorageEvent } from '../common/StorageUtils';
|
|
59
57
|
import {
|
|
60
|
-
createPrefixMiddleware,
|
|
61
|
-
prefixMiddlewareOptions,
|
|
62
58
|
getPrefix,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
createS3Client,
|
|
59
|
+
S3ResolvedConfig,
|
|
60
|
+
loadS3Config,
|
|
66
61
|
} from '../common/S3ClientUtils';
|
|
67
62
|
import { AWSS3ProviderManagedUpload } from './AWSS3ProviderManagedUpload';
|
|
68
63
|
import { AWSS3UploadTask, TaskEvents } from './AWSS3UploadTask';
|
|
69
64
|
import { UPLOADS_STORAGE_KEY } from '../common/StorageConstants';
|
|
70
65
|
import * as events from 'events';
|
|
71
|
-
import { CancelTokenSource } from 'axios';
|
|
72
66
|
|
|
73
67
|
const logger = new Logger('AWSS3Provider');
|
|
74
68
|
|
|
@@ -81,8 +75,8 @@ interface AddTaskInput {
|
|
|
81
75
|
bucket: string;
|
|
82
76
|
emitter: events.EventEmitter;
|
|
83
77
|
key: string;
|
|
84
|
-
|
|
85
|
-
params?:
|
|
78
|
+
s3Config: S3ResolvedConfig;
|
|
79
|
+
params?: PutObjectInput;
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
/**
|
|
@@ -144,7 +138,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
144
138
|
addTaskInput: AddTaskInput,
|
|
145
139
|
config: S3ProviderPutConfig & ResumableUploadConfig
|
|
146
140
|
): UploadTask {
|
|
147
|
-
const {
|
|
141
|
+
const { s3Config, emitter, key, file, params } = addTaskInput;
|
|
148
142
|
const {
|
|
149
143
|
progressCallback,
|
|
150
144
|
completeCallback,
|
|
@@ -200,16 +194,17 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
200
194
|
const cred = Credentials.shear(credentials);
|
|
201
195
|
return getPrefix({
|
|
202
196
|
...config,
|
|
197
|
+
level: addTaskInput.accessLevel,
|
|
203
198
|
credentials: cred,
|
|
204
199
|
});
|
|
205
200
|
}
|
|
206
201
|
);
|
|
207
202
|
|
|
208
203
|
const task = new AWSS3UploadTask({
|
|
209
|
-
|
|
204
|
+
s3Config,
|
|
210
205
|
file,
|
|
211
206
|
emitter,
|
|
212
|
-
level:
|
|
207
|
+
level: addTaskInput.accessLevel,
|
|
213
208
|
storage: this._storage,
|
|
214
209
|
params,
|
|
215
210
|
prefixPromise,
|
|
@@ -288,7 +283,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
288
283
|
const finalDestKey = `${destPrefix}${destKey}`;
|
|
289
284
|
logger.debug(`copying ${finalSrcKey} to ${finalDestKey}`);
|
|
290
285
|
|
|
291
|
-
const params:
|
|
286
|
+
const params: CopyObjectInput = {
|
|
292
287
|
Bucket: bucket,
|
|
293
288
|
CopySource: finalSrcKey,
|
|
294
289
|
Key: finalDestKey,
|
|
@@ -315,9 +310,14 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
315
310
|
}
|
|
316
311
|
if (acl) params.ACL = acl;
|
|
317
312
|
|
|
318
|
-
const s3 = this._createNewS3Client(opt, StorageAction.Copy);
|
|
319
313
|
try {
|
|
320
|
-
await
|
|
314
|
+
await copyObject(
|
|
315
|
+
loadS3Config({
|
|
316
|
+
...opt,
|
|
317
|
+
storageAction: StorageAction.Copy,
|
|
318
|
+
}),
|
|
319
|
+
params
|
|
320
|
+
);
|
|
321
321
|
dispatchStorageEvent(
|
|
322
322
|
track,
|
|
323
323
|
'copy',
|
|
@@ -351,7 +351,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
351
351
|
*
|
|
352
352
|
* @param {string} key - key of the object
|
|
353
353
|
* @param {S3ProviderGetConfig} [config] - Optional configuration for the underlying S3 command
|
|
354
|
-
* @return {Promise<string |
|
|
354
|
+
* @return {Promise<string | GetObjectOutput>} - A promise resolves to Amazon S3 presigned URL or the
|
|
355
355
|
* GetObjectCommandOutput if download is set to true on success
|
|
356
356
|
*/
|
|
357
357
|
public async get<T extends S3ProviderGetConfig & StorageOptions>(
|
|
@@ -361,7 +361,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
361
361
|
public async get(
|
|
362
362
|
key: string,
|
|
363
363
|
config?: S3ProviderGetConfig
|
|
364
|
-
): Promise<string |
|
|
364
|
+
): Promise<string | GetObjectOutput> {
|
|
365
365
|
const credentialsOK = await this._ensureCredentials();
|
|
366
366
|
if (!credentialsOK || !this._isWithCredentials(this._config)) {
|
|
367
367
|
throw new Error(StorageErrorStrings.NO_CREDENTIALS);
|
|
@@ -386,10 +386,14 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
386
386
|
const prefix = this._prefix(opt);
|
|
387
387
|
const final_key = prefix + key;
|
|
388
388
|
const emitter = new events.EventEmitter();
|
|
389
|
-
const
|
|
389
|
+
const s3Config = loadS3Config({
|
|
390
|
+
...opt,
|
|
391
|
+
emitter,
|
|
392
|
+
storageAction: StorageAction.Get,
|
|
393
|
+
});
|
|
390
394
|
logger.debug('get ' + key + ' from ' + final_key);
|
|
391
395
|
|
|
392
|
-
const params:
|
|
396
|
+
const params: GetObjectInput = {
|
|
393
397
|
Bucket: bucket,
|
|
394
398
|
Key: final_key,
|
|
395
399
|
};
|
|
@@ -411,7 +415,6 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
411
415
|
}
|
|
412
416
|
|
|
413
417
|
if (download === true) {
|
|
414
|
-
const getObjectCommand = new GetObjectCommand(params);
|
|
415
418
|
try {
|
|
416
419
|
if (progressCallback) {
|
|
417
420
|
if (typeof progressCallback === 'function') {
|
|
@@ -425,7 +428,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
425
428
|
);
|
|
426
429
|
}
|
|
427
430
|
}
|
|
428
|
-
const response = await
|
|
431
|
+
const response = await getObject(s3Config, params);
|
|
429
432
|
emitter.removeAllListeners(SEND_DOWNLOAD_PROGRESS_EVENT);
|
|
430
433
|
dispatchStorageEvent(
|
|
431
434
|
track,
|
|
@@ -452,10 +455,8 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
452
455
|
}
|
|
453
456
|
}
|
|
454
457
|
if (validateObjectExistence) {
|
|
455
|
-
const headObjectCommand = new HeadObjectCommand(params);
|
|
456
|
-
|
|
457
458
|
try {
|
|
458
|
-
await
|
|
459
|
+
await headObject(s3Config, params);
|
|
459
460
|
} catch (error) {
|
|
460
461
|
if (error.$metadata?.httpStatusCode === 404) {
|
|
461
462
|
dispatchStorageEvent(
|
|
@@ -473,13 +474,15 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
476
|
try {
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
477
|
+
const url = await getPresignedGetObjectUrl(
|
|
478
|
+
{
|
|
479
|
+
...s3Config,
|
|
480
|
+
expiration: expires || DEFAULT_PRESIGN_EXPIRATION,
|
|
481
|
+
credentials: await s3Config.credentials(),
|
|
482
|
+
signingRegion: s3Config.region,
|
|
483
|
+
signingService: S3_SERVICE_NAME,
|
|
484
|
+
},
|
|
485
|
+
params
|
|
483
486
|
);
|
|
484
487
|
dispatchStorageEvent(
|
|
485
488
|
track,
|
|
@@ -528,15 +531,13 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
528
531
|
} = opt;
|
|
529
532
|
const prefix = this._prefix(opt);
|
|
530
533
|
const final_key = prefix + key;
|
|
531
|
-
const emitter = new events.EventEmitter();
|
|
532
|
-
const s3 = this._createNewS3Client(
|
|
533
|
-
opt,
|
|
534
|
-
StorageAction.GetProperties,
|
|
535
|
-
emitter
|
|
536
|
-
);
|
|
537
534
|
logger.debug(`getProperties ${key} from ${final_key}`);
|
|
538
535
|
|
|
539
|
-
const
|
|
536
|
+
const s3Config = loadS3Config({
|
|
537
|
+
...opt,
|
|
538
|
+
storageAction: StorageAction.GetProperties,
|
|
539
|
+
});
|
|
540
|
+
const params: HeadObjectInput = {
|
|
540
541
|
Bucket: bucket,
|
|
541
542
|
Key: final_key,
|
|
542
543
|
};
|
|
@@ -550,11 +551,9 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
550
551
|
if (SSECustomerKeyMD5) {
|
|
551
552
|
params.SSECustomerKeyMD5 = SSECustomerKeyMD5;
|
|
552
553
|
}
|
|
553
|
-
// See: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/headobjectcommand.html
|
|
554
554
|
|
|
555
|
-
const headObjectCommand = new HeadObjectCommand(params);
|
|
556
555
|
try {
|
|
557
|
-
const response = await
|
|
556
|
+
const response = await headObject(s3Config, params);
|
|
558
557
|
const getPropertiesResponse: S3ProviderGetPropertiesOutput = {
|
|
559
558
|
contentLength: response.ContentLength,
|
|
560
559
|
contentType: response.ContentType,
|
|
@@ -597,7 +596,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
597
596
|
*/
|
|
598
597
|
public put<T extends S3ProviderPutConfig>(
|
|
599
598
|
key: string,
|
|
600
|
-
object:
|
|
599
|
+
object: PutObjectInput['Body'],
|
|
601
600
|
config?: T
|
|
602
601
|
): S3ProviderPutOutput<T> {
|
|
603
602
|
const opt = Object.assign({}, this._config, config);
|
|
@@ -621,7 +620,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
621
620
|
} = opt;
|
|
622
621
|
const type = contentType ? contentType : 'binary/octet-stream';
|
|
623
622
|
|
|
624
|
-
const params:
|
|
623
|
+
const params: PutObjectInput = {
|
|
625
624
|
Bucket: bucket,
|
|
626
625
|
Key: key,
|
|
627
626
|
Body: object,
|
|
@@ -669,17 +668,14 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
669
668
|
}
|
|
670
669
|
|
|
671
670
|
if (resumable === true) {
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
createPrefixMiddleware(opt, key),
|
|
677
|
-
prefixMiddlewareOptions
|
|
678
|
-
);
|
|
671
|
+
const s3Config = loadS3Config({
|
|
672
|
+
...opt,
|
|
673
|
+
storageAction: StorageAction.Put,
|
|
674
|
+
});
|
|
679
675
|
const addTaskInput: AddTaskInput = {
|
|
680
676
|
bucket,
|
|
681
677
|
key,
|
|
682
|
-
|
|
678
|
+
s3Config,
|
|
683
679
|
file: object as Blob,
|
|
684
680
|
emitter,
|
|
685
681
|
accessLevel: level,
|
|
@@ -749,18 +745,19 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
749
745
|
|
|
750
746
|
const prefix = this._prefix(opt);
|
|
751
747
|
const final_key = prefix + key;
|
|
752
|
-
const s3 = this._createNewS3Client(opt, StorageAction.Remove);
|
|
753
748
|
logger.debug('remove ' + key + ' from ' + final_key);
|
|
754
749
|
|
|
755
|
-
const params:
|
|
750
|
+
const params: DeleteObjectInput = {
|
|
756
751
|
Bucket: bucket,
|
|
757
752
|
Key: final_key,
|
|
758
753
|
};
|
|
759
754
|
|
|
760
|
-
const
|
|
761
|
-
|
|
755
|
+
const s3Config = loadS3Config({
|
|
756
|
+
...opt,
|
|
757
|
+
storageAction: StorageAction.Remove,
|
|
758
|
+
});
|
|
762
759
|
try {
|
|
763
|
-
const response = await
|
|
760
|
+
const response = await deleteObject(s3Config, params);
|
|
764
761
|
dispatchStorageEvent(
|
|
765
762
|
track,
|
|
766
763
|
'delete',
|
|
@@ -781,7 +778,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
781
778
|
}
|
|
782
779
|
}
|
|
783
780
|
private async _list(
|
|
784
|
-
params:
|
|
781
|
+
params: ListObjectsV2Input,
|
|
785
782
|
opt: S3ClientOptions,
|
|
786
783
|
prefix: string
|
|
787
784
|
): Promise<S3ProviderListOutput> {
|
|
@@ -789,9 +786,13 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
789
786
|
results: [],
|
|
790
787
|
hasNextToken: false,
|
|
791
788
|
};
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
789
|
+
const response = await listObjectsV2(
|
|
790
|
+
loadS3Config({
|
|
791
|
+
...opt,
|
|
792
|
+
storageAction: StorageAction.List,
|
|
793
|
+
}),
|
|
794
|
+
{ ...params }
|
|
795
|
+
);
|
|
795
796
|
if (response && response.Contents) {
|
|
796
797
|
list.results = response.Contents.map(item => {
|
|
797
798
|
return {
|
|
@@ -834,7 +835,7 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
834
835
|
};
|
|
835
836
|
const MAX_PAGE_SIZE = 1000;
|
|
836
837
|
let listResult: S3ProviderListOutput;
|
|
837
|
-
const params:
|
|
838
|
+
const params: ListObjectsV2Input = {
|
|
838
839
|
Bucket: bucket,
|
|
839
840
|
Prefix: final_path,
|
|
840
841
|
MaxKeys: MAX_PAGE_SIZE,
|
|
@@ -936,25 +937,4 @@ export class AWSS3Provider implements StorageProvider {
|
|
|
936
937
|
return publicPath;
|
|
937
938
|
}
|
|
938
939
|
}
|
|
939
|
-
|
|
940
|
-
/**
|
|
941
|
-
* Creates an S3 client with new V3 aws sdk
|
|
942
|
-
*/
|
|
943
|
-
private _createNewS3Client(
|
|
944
|
-
config: {
|
|
945
|
-
region?: string;
|
|
946
|
-
cancelTokenSource?: CancelTokenSource;
|
|
947
|
-
dangerouslyConnectToHttpEndpointForTesting?: boolean;
|
|
948
|
-
useAccelerateEndpoint?: boolean;
|
|
949
|
-
},
|
|
950
|
-
storageAction: StorageAction,
|
|
951
|
-
emitter?: events.EventEmitter
|
|
952
|
-
): S3Client {
|
|
953
|
-
const s3client = createS3Client(config, storageAction, emitter);
|
|
954
|
-
s3client.middlewareStack.add(
|
|
955
|
-
autoAdjustClockskewMiddleware(s3client.config),
|
|
956
|
-
autoAdjustClockskewMiddlewareOptions
|
|
957
|
-
);
|
|
958
|
-
return s3client;
|
|
959
|
-
}
|
|
960
940
|
}
|