@aws-amplify/storage 4.4.3 → 4.4.4-in-app-messaging.35
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/CHANGELOG.md +28 -352
- package/dist/aws-amplify-storage.js +6523 -5062
- package/dist/aws-amplify-storage.js.map +1 -1
- package/dist/aws-amplify-storage.min.js +5 -5
- package/dist/aws-amplify-storage.min.js.map +1 -1
- package/lib/Storage.d.ts +3 -1
- package/lib/Storage.js +25 -21
- package/lib/Storage.js.map +1 -1
- package/lib/common/S3ClientUtils.d.ts +33 -0
- package/lib/common/S3ClientUtils.js +179 -0
- package/lib/common/S3ClientUtils.js.map +1 -0
- package/lib/common/StorageConstants.d.ts +4 -0
- package/lib/common/StorageConstants.js +10 -0
- package/lib/common/StorageConstants.js.map +1 -0
- package/lib/common/StorageErrorStrings.d.ts +5 -1
- package/lib/common/StorageErrorStrings.js +5 -0
- package/lib/common/StorageErrorStrings.js.map +1 -1
- package/lib/common/StorageUtils.d.ts +4 -0
- package/lib/common/StorageUtils.js +41 -0
- package/lib/common/StorageUtils.js.map +1 -0
- package/lib/providers/AWSS3Provider.d.ts +9 -6
- package/lib/providers/AWSS3Provider.js +197 -149
- package/lib/providers/AWSS3Provider.js.map +1 -1
- package/lib/providers/AWSS3ProviderManagedUpload.d.ts +3 -10
- package/lib/providers/AWSS3ProviderManagedUpload.js +41 -109
- package/lib/providers/AWSS3ProviderManagedUpload.js.map +1 -1
- package/lib/providers/AWSS3UploadTask.d.ts +107 -0
- package/lib/providers/AWSS3UploadTask.js +610 -0
- package/lib/providers/AWSS3UploadTask.js.map +1 -0
- package/lib/providers/axios-http-handler.d.ts +5 -1
- package/lib/providers/axios-http-handler.js +28 -5
- package/lib/providers/axios-http-handler.js.map +1 -1
- package/lib/types/AWSS3Provider.d.ts +24 -4
- package/lib/types/Provider.d.ts +7 -1
- package/lib/types/Storage.d.ts +8 -8
- package/lib-esm/Storage.d.ts +3 -1
- package/lib-esm/Storage.js +25 -21
- package/lib-esm/Storage.js.map +1 -1
- package/lib-esm/common/S3ClientUtils.d.ts +33 -0
- package/lib-esm/common/S3ClientUtils.js +177 -0
- package/lib-esm/common/S3ClientUtils.js.map +1 -0
- package/lib-esm/common/StorageConstants.d.ts +4 -0
- package/lib-esm/common/StorageConstants.js +8 -0
- package/lib-esm/common/StorageConstants.js.map +1 -0
- package/lib-esm/common/StorageErrorStrings.d.ts +5 -1
- package/lib-esm/common/StorageErrorStrings.js +5 -0
- package/lib-esm/common/StorageErrorStrings.js.map +1 -1
- package/lib-esm/common/StorageUtils.d.ts +4 -0
- package/lib-esm/common/StorageUtils.js +39 -0
- package/lib-esm/common/StorageUtils.js.map +1 -0
- package/lib-esm/providers/AWSS3Provider.d.ts +9 -6
- package/lib-esm/providers/AWSS3Provider.js +192 -144
- package/lib-esm/providers/AWSS3Provider.js.map +1 -1
- package/lib-esm/providers/AWSS3ProviderManagedUpload.d.ts +3 -10
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js +44 -112
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +1 -1
- package/lib-esm/providers/AWSS3UploadTask.d.ts +107 -0
- package/lib-esm/providers/AWSS3UploadTask.js +605 -0
- package/lib-esm/providers/AWSS3UploadTask.js.map +1 -0
- package/lib-esm/providers/axios-http-handler.d.ts +5 -1
- package/lib-esm/providers/axios-http-handler.js +28 -5
- package/lib-esm/providers/axios-http-handler.js.map +1 -1
- package/lib-esm/types/AWSS3Provider.d.ts +24 -4
- package/lib-esm/types/Provider.d.ts +7 -1
- package/lib-esm/types/Storage.d.ts +8 -8
- package/package.json +3 -3
- package/src/Storage.ts +85 -27
- package/src/common/S3ClientUtils.ts +168 -0
- package/src/common/StorageConstants.ts +10 -0
- package/src/common/StorageErrorStrings.ts +5 -0
- package/src/common/StorageUtils.ts +51 -0
- package/src/providers/AWSS3Provider.ts +251 -88
- package/src/providers/AWSS3ProviderManagedUpload.ts +346 -397
- package/src/providers/AWSS3UploadTask.ts +543 -0
- package/src/providers/axios-http-handler.ts +221 -186
- package/src/types/AWSS3Provider.ts +48 -7
- package/src/types/Provider.ts +18 -3
- package/src/types/Storage.ts +9 -9
|
@@ -41,6 +41,7 @@ import { HttpResponse } from '@aws-sdk/protocol-http';
|
|
|
41
41
|
import { buildQueryString } from '@aws-sdk/querystring-builder';
|
|
42
42
|
import axios from 'axios';
|
|
43
43
|
import { ConsoleLogger as Logger, Platform } from '@aws-amplify/core';
|
|
44
|
+
import { AWSS3ProviderUploadErrorStrings } from '../common/StorageErrorStrings';
|
|
44
45
|
var logger = new Logger('axios-http-handler');
|
|
45
46
|
export var SEND_UPLOAD_PROGRESS_EVENT = 'sendUploadProgress';
|
|
46
47
|
export var SEND_DOWNLOAD_PROGRESS_EVENT = 'sendDownloadProgress';
|
|
@@ -91,7 +92,9 @@ var AxiosHttpHandler = /** @class */ (function () {
|
|
|
91
92
|
};
|
|
92
93
|
AxiosHttpHandler.prototype.handle = function (request, options) {
|
|
93
94
|
var requestTimeoutInMs = this.httpOptions.requestTimeout;
|
|
94
|
-
|
|
95
|
+
// prioritize the call specific event emitter, this is useful for multipart upload as each individual parts has
|
|
96
|
+
// their own event emitter, without having to create s3client for every individual calls.
|
|
97
|
+
var emitter = options.emitter || this.emitter;
|
|
95
98
|
var path = request.path;
|
|
96
99
|
if (request.query) {
|
|
97
100
|
var queryString = buildQueryString(request.query);
|
|
@@ -125,7 +128,7 @@ var AxiosHttpHandler = /** @class */ (function () {
|
|
|
125
128
|
// This change is a workaround to set the data as null (instead of undefined) to prevent axios from
|
|
126
129
|
// removing the content-type header. Link for the source code
|
|
127
130
|
// https://github.com/axios/axios/blob/dc4bc49673943e35280e5df831f5c3d0347a9393/lib/adapters/xhr.js#L121-L123
|
|
128
|
-
if (axiosRequest.headers['
|
|
131
|
+
if (axiosRequest.headers[Object.keys(axiosRequest.headers).find(function (key) { return key.toLowerCase() === 'content-type'; })]) {
|
|
129
132
|
axiosRequest.data = null;
|
|
130
133
|
}
|
|
131
134
|
}
|
|
@@ -143,10 +146,13 @@ var AxiosHttpHandler = /** @class */ (function () {
|
|
|
143
146
|
if (this.cancelTokenSource) {
|
|
144
147
|
axiosRequest.cancelToken = this.cancelTokenSource.token;
|
|
145
148
|
}
|
|
149
|
+
if (options.cancelTokenSource) {
|
|
150
|
+
axiosRequest.cancelToken = options.cancelTokenSource.token;
|
|
151
|
+
}
|
|
146
152
|
// From gamma release, aws-sdk now expects all response type to be of blob or streams
|
|
147
153
|
axiosRequest.responseType = 'blob';
|
|
148
154
|
// In Axios, Blobs are identified by calling Object.prototype.toString on the object. However, on React Native,
|
|
149
|
-
// calling Object.prototype.toString on a Blob returns '[object Object]' instead of '[object Blob]', which causes
|
|
155
|
+
// calling Object.prototype.toString on a Blob returns '[object Object]' instead of '[object Blob]', which causes
|
|
150
156
|
// Axios to treat Blobs as generic Javascript objects. Therefore we need a to use a custom request transformer
|
|
151
157
|
// to correctly handle Blob in React Native.
|
|
152
158
|
if (Platform.isReactNative) {
|
|
@@ -165,9 +171,26 @@ var AxiosHttpHandler = /** @class */ (function () {
|
|
|
165
171
|
};
|
|
166
172
|
})
|
|
167
173
|
.catch(function (error) {
|
|
174
|
+
var _a, _b, _c;
|
|
168
175
|
// Error
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
if (error.message !==
|
|
177
|
+
AWSS3ProviderUploadErrorStrings.UPLOAD_PAUSED_MESSAGE) {
|
|
178
|
+
logger.error(error.message);
|
|
179
|
+
}
|
|
180
|
+
// for axios' cancel error, we should re-throw it back so it's not considered an s3client error
|
|
181
|
+
// if we return empty, or an abitrary error HttpResponse, it will be hard to debug down the line
|
|
182
|
+
if (axios.isCancel(error)) {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
// otherwise, we should re-construct an HttpResponse from the error, so that it can be passed down to other
|
|
186
|
+
// aws sdk middleware (e.g retry, clock skew correction, error message serializing)
|
|
187
|
+
return {
|
|
188
|
+
response: new HttpResponse({
|
|
189
|
+
statusCode: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
190
|
+
body: (_b = error.response) === null || _b === void 0 ? void 0 : _b.data,
|
|
191
|
+
headers: (_c = error.response) === null || _c === void 0 ? void 0 : _c.headers,
|
|
192
|
+
}),
|
|
193
|
+
};
|
|
171
194
|
}),
|
|
172
195
|
requestTimeout(requestTimeoutInMs),
|
|
173
196
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-http-handler.js","sourceRoot":"","sources":["../../src/providers/axios-http-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAA4B,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAKN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"axios-http-handler.js","sourceRoot":"","sources":["../../src/providers/axios-http-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAA4B,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAKN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAEhF,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAChD,MAAM,CAAC,IAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAC/D,MAAM,CAAC,IAAM,4BAA4B,GAAG,sBAAsB,CAAC;AAEnE,SAAS,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jectRequest, GetObjectCommandOutput, PutObjectRequest, CopyObjectRequest, _Object, DeleteObjectCommandOutput } from '@aws-sdk/client-s3';
|
|
2
2
|
import { StorageOptions, StorageAccessLevel } from './Storage';
|
|
3
|
+
import { UploadTaskCompleteEvent, UploadTaskProgressEvent } from '../providers/AWSS3UploadTask';
|
|
4
|
+
import { UploadTask } from './Provider';
|
|
3
5
|
declare type ListObjectsCommandOutputContent = _Object;
|
|
6
|
+
export interface FileMetadata {
|
|
7
|
+
bucket: string;
|
|
8
|
+
fileName: string;
|
|
9
|
+
key: string;
|
|
10
|
+
lastTouched: number;
|
|
11
|
+
uploadId: string;
|
|
12
|
+
}
|
|
4
13
|
export declare type CommonStorageOptions = Omit<StorageOptions, 'credentials' | 'region' | 'bucket' | 'dangerouslyConnectToHttpEndpointForTesting'>;
|
|
5
14
|
export declare type S3ProviderGetConfig = CommonStorageOptions & {
|
|
6
15
|
download?: boolean;
|
|
@@ -21,7 +30,7 @@ export declare type S3ProviderGetConfig = CommonStorageOptions & {
|
|
|
21
30
|
export declare type S3ProviderGetOuput<T> = T extends {
|
|
22
31
|
download: true;
|
|
23
32
|
} ? GetObjectCommandOutput : string;
|
|
24
|
-
|
|
33
|
+
declare type _S3ProviderPutConfig = {
|
|
25
34
|
progressCallback?: (progress: any) => any;
|
|
26
35
|
provider?: 'AWSS3';
|
|
27
36
|
track?: boolean;
|
|
@@ -40,10 +49,15 @@ export declare type S3ProviderPutConfig = CommonStorageOptions & {
|
|
|
40
49
|
metadata?: PutObjectRequest['Metadata'];
|
|
41
50
|
tagging?: PutObjectRequest['Tagging'];
|
|
42
51
|
useAccelerateEndpoint?: boolean;
|
|
52
|
+
resumable?: boolean;
|
|
43
53
|
};
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
export declare type ResumableUploadConfig = {
|
|
55
|
+
resumable: true;
|
|
56
|
+
progressCallback?: (progress: UploadTaskProgressEvent) => any;
|
|
57
|
+
completeCallback?: (event: UploadTaskCompleteEvent) => any;
|
|
58
|
+
errorCallback?: (err: any) => any;
|
|
59
|
+
};
|
|
60
|
+
export declare type S3ProviderPutConfig = CommonStorageOptions & (_S3ProviderPutConfig | (_S3ProviderPutConfig & ResumableUploadConfig));
|
|
47
61
|
export declare type S3ProviderRemoveConfig = CommonStorageOptions & {
|
|
48
62
|
bucket?: string;
|
|
49
63
|
provider?: 'AWSS3';
|
|
@@ -89,4 +103,10 @@ export declare type S3ProviderCopyConfig = Omit<CommonStorageOptions, 'level'> &
|
|
|
89
103
|
export declare type S3ProviderCopyOutput = {
|
|
90
104
|
key: string;
|
|
91
105
|
};
|
|
106
|
+
export declare type PutResult = {
|
|
107
|
+
key: string;
|
|
108
|
+
};
|
|
109
|
+
export declare type S3ProviderPutOutput<T> = T extends {
|
|
110
|
+
resumable: true;
|
|
111
|
+
} ? UploadTask : Promise<PutResult>;
|
|
92
112
|
export {};
|
|
@@ -4,12 +4,18 @@ export interface StorageProvider {
|
|
|
4
4
|
copy?(src: StorageCopySource, dest: StorageCopyDestination, config?: any): Promise<any>;
|
|
5
5
|
configure(config: object): object;
|
|
6
6
|
get(key: string, options?: any): Promise<string | Object>;
|
|
7
|
-
put(key: string, object: any, options?: any): Promise<Object
|
|
7
|
+
put(key: string, object: any, options?: any): Promise<Object> | UploadTask;
|
|
8
8
|
remove(key: string, options?: any): Promise<any>;
|
|
9
9
|
list(path: any, options?: any): Promise<any>;
|
|
10
10
|
getCategory(): string;
|
|
11
11
|
getProviderName(): string;
|
|
12
12
|
}
|
|
13
|
+
export interface UploadTask {
|
|
14
|
+
resume(): any;
|
|
15
|
+
pause(): any;
|
|
16
|
+
percent: number;
|
|
17
|
+
isInProgress: boolean;
|
|
18
|
+
}
|
|
13
19
|
export interface StorageProviderWithCopy extends StorageProvider {
|
|
14
20
|
copy(src: StorageCopySource, dest: StorageCopyDestination, config?: any): Promise<any>;
|
|
15
21
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Storage instance options
|
|
3
3
|
*/
|
|
4
4
|
import { ICredentials } from '@aws-amplify/core';
|
|
5
|
-
import { StorageProvider, StorageProviderApi, AWSS3Provider, StorageProviderWithCopy, S3ProviderGetOuput,
|
|
5
|
+
import { StorageProvider, StorageProviderApi, AWSS3Provider, StorageProviderWithCopy, S3ProviderGetOuput, S3ProviderRemoveOutput, S3ProviderListOutput, S3ProviderCopyOutput, S3ProviderPutOutput } from '../';
|
|
6
6
|
declare type Tail<T extends any[]> = ((...t: T) => void) extends (h: any, ...r: infer R) => void ? R : never;
|
|
7
7
|
declare type Last<T extends any[]> = T[Exclude<keyof T, keyof Tail<T>>];
|
|
8
8
|
declare type LastParameter<F extends (...args: any) => any> = Last<Parameters<F>>;
|
|
@@ -55,16 +55,16 @@ export declare type StorageCopyConfig<T> = T extends StorageProviderWithCopy ? S
|
|
|
55
55
|
* return type.
|
|
56
56
|
* If it's a Record, check if provider is 'AWSS3', use the default type else use any.
|
|
57
57
|
*/
|
|
58
|
-
declare type PickProviderOutput<DefaultOutput, T, api extends StorageProviderApi> = T extends StorageProvider ? T['getProviderName'] extends 'AWSS3' ?
|
|
58
|
+
declare type PickProviderOutput<DefaultOutput, T, api extends StorageProviderApi> = T extends StorageProvider ? T['getProviderName'] extends 'AWSS3' ? DefaultOutput : T extends StorageProviderWithCopy ? ReturnType<T[api]> : ReturnType<T[Exclude<api, 'copy'>]> : T extends {
|
|
59
59
|
provider: string;
|
|
60
60
|
} ? T extends {
|
|
61
61
|
provider: 'AWSS3';
|
|
62
|
-
} ?
|
|
63
|
-
export declare type StorageGetOutput<T extends StorageProvider | Record<string, any>> = PickProviderOutput<S3ProviderGetOuput<T
|
|
64
|
-
export declare type StoragePutOutput<T> = PickProviderOutput<S3ProviderPutOutput
|
|
65
|
-
export declare type StorageRemoveOutput<T> = PickProviderOutput<S3ProviderRemoveOutput
|
|
66
|
-
export declare type StorageListOutput<T> = PickProviderOutput<S3ProviderListOutput
|
|
67
|
-
export declare type StorageCopyOutput<T> = PickProviderOutput<S3ProviderCopyOutput
|
|
62
|
+
} ? DefaultOutput : Promise<any> : DefaultOutput;
|
|
63
|
+
export declare type StorageGetOutput<T extends StorageProvider | Record<string, any>> = PickProviderOutput<Promise<S3ProviderGetOuput<T>>, T, 'get'>;
|
|
64
|
+
export declare type StoragePutOutput<T> = PickProviderOutput<S3ProviderPutOutput<T>, T, 'put'>;
|
|
65
|
+
export declare type StorageRemoveOutput<T> = PickProviderOutput<Promise<S3ProviderRemoveOutput>, T, 'remove'>;
|
|
66
|
+
export declare type StorageListOutput<T> = PickProviderOutput<Promise<S3ProviderListOutput>, T, 'list'>;
|
|
67
|
+
export declare type StorageCopyOutput<T> = PickProviderOutput<Promise<S3ProviderCopyOutput>, T, 'copy'>;
|
|
68
68
|
/**
|
|
69
69
|
* Utility type to allow custom provider to use any config keys, if provider is set to AWSS3 then it should use
|
|
70
70
|
* AWSS3Provider's config.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/storage",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.4-in-app-messaging.35+dcee89ab8",
|
|
4
4
|
"description": "Storage category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://aws-amplify.github.io/",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@aws-amplify/core": "4.3.
|
|
44
|
+
"@aws-amplify/core": "4.3.3-in-app-messaging.35+dcee89ab8",
|
|
45
45
|
"@aws-sdk/client-s3": "3.6.1",
|
|
46
46
|
"@aws-sdk/s3-request-presigner": "3.6.1",
|
|
47
47
|
"@aws-sdk/util-create-request": "3.6.1",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@types/sinon": "^7.5.1"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "dcee89ab81dbd6e6e90777abae16194a05e614b0"
|
|
103
103
|
}
|
package/src/Storage.ts
CHANGED
|
@@ -28,9 +28,11 @@ import {
|
|
|
28
28
|
StorageRemoveOutput,
|
|
29
29
|
StorageListOutput,
|
|
30
30
|
StorageCopyOutput,
|
|
31
|
+
UploadTask,
|
|
31
32
|
} from './types';
|
|
32
33
|
import axios, { CancelTokenSource } from 'axios';
|
|
33
34
|
import { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
35
|
+
import { AWSS3UploadTask } from './providers/AWSS3UploadTask';
|
|
34
36
|
|
|
35
37
|
const logger = new Logger('StorageClass');
|
|
36
38
|
|
|
@@ -98,7 +100,9 @@ export class Storage {
|
|
|
98
100
|
* @param providerName - the name of the plugin
|
|
99
101
|
*/
|
|
100
102
|
public getPluggable(providerName: string) {
|
|
101
|
-
const pluggable = this._pluggables.find(
|
|
103
|
+
const pluggable = this._pluggables.find(
|
|
104
|
+
pluggable => pluggable.getProviderName() === providerName
|
|
105
|
+
);
|
|
102
106
|
if (pluggable === undefined) {
|
|
103
107
|
logger.debug('No plugin found with providerName', providerName);
|
|
104
108
|
return null;
|
|
@@ -110,7 +114,9 @@ export class Storage {
|
|
|
110
114
|
* @param providerName - the name of the plugin
|
|
111
115
|
*/
|
|
112
116
|
public removePluggable(providerName: string) {
|
|
113
|
-
this._pluggables = this._pluggables.filter(
|
|
117
|
+
this._pluggables = this._pluggables.filter(
|
|
118
|
+
pluggable => pluggable.getProviderName() !== providerName
|
|
119
|
+
);
|
|
114
120
|
return;
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -140,8 +146,10 @@ export class Storage {
|
|
|
140
146
|
'SSEKMSKeyId',
|
|
141
147
|
];
|
|
142
148
|
|
|
143
|
-
const isInStorageArrayKeys = (k: string) =>
|
|
144
|
-
|
|
149
|
+
const isInStorageArrayKeys = (k: string) =>
|
|
150
|
+
storageArrayKeys.some(x => x === k);
|
|
151
|
+
const checkConfigKeysFromArray = (k: string[]) =>
|
|
152
|
+
k.find(k => isInStorageArrayKeys(k));
|
|
145
153
|
|
|
146
154
|
if (
|
|
147
155
|
storageKeysFromConfig &&
|
|
@@ -183,18 +191,39 @@ export class Storage {
|
|
|
183
191
|
return axios.CancelToken.source();
|
|
184
192
|
}
|
|
185
193
|
|
|
186
|
-
private updateRequestToBeCancellable(
|
|
194
|
+
private updateRequestToBeCancellable(
|
|
195
|
+
request: Promise<any>,
|
|
196
|
+
cancelTokenSource: CancelTokenSource
|
|
197
|
+
) {
|
|
187
198
|
this._cancelTokenSourceMap.set(request, cancelTokenSource);
|
|
188
199
|
}
|
|
189
200
|
|
|
201
|
+
private isUploadTask(x: unknown): x is UploadTask {
|
|
202
|
+
return (
|
|
203
|
+
typeof x !== 'undefined' &&
|
|
204
|
+
typeof x['pause'] === 'function' &&
|
|
205
|
+
typeof x['resume'] === 'function'
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
190
209
|
/**
|
|
191
210
|
* Cancels an inflight request
|
|
192
211
|
*
|
|
193
212
|
* @param request - The request to cancel
|
|
194
213
|
* @param [message] - A message to include in the cancelation exception
|
|
195
214
|
*/
|
|
196
|
-
public cancel(request:
|
|
197
|
-
|
|
215
|
+
public cancel(request: UploadTask, message?: string): Promise<boolean>;
|
|
216
|
+
public cancel(request: Promise<any>, message?: string): void;
|
|
217
|
+
public cancel(
|
|
218
|
+
request: Promise<any> | UploadTask,
|
|
219
|
+
message?: string
|
|
220
|
+
): void | Promise<boolean> {
|
|
221
|
+
if (request instanceof AWSS3UploadTask) {
|
|
222
|
+
return request._cancel();
|
|
223
|
+
}
|
|
224
|
+
const cancelTokenSource = this._cancelTokenSourceMap.get(
|
|
225
|
+
request as Promise<any>
|
|
226
|
+
);
|
|
198
227
|
if (cancelTokenSource) {
|
|
199
228
|
cancelTokenSource.cancel(message);
|
|
200
229
|
} else {
|
|
@@ -221,14 +250,20 @@ export class Storage {
|
|
|
221
250
|
config?: StorageCopyConfig<T>
|
|
222
251
|
): StorageCopyOutput<T> {
|
|
223
252
|
const provider = config?.provider || DEFAULT_PROVIDER;
|
|
224
|
-
const prov = this._pluggables.find(
|
|
253
|
+
const prov = this._pluggables.find(
|
|
254
|
+
pluggable => pluggable.getProviderName() === provider
|
|
255
|
+
);
|
|
225
256
|
if (prov === undefined) {
|
|
226
257
|
logger.debug('No plugin found with providerName', provider);
|
|
227
|
-
return Promise.reject(
|
|
258
|
+
return Promise.reject(
|
|
259
|
+
'No plugin found in Storage for the provider'
|
|
260
|
+
) as StorageCopyOutput<T>;
|
|
228
261
|
}
|
|
229
262
|
const cancelTokenSource = this.getCancellableTokenSource();
|
|
230
263
|
if (typeof prov.copy !== 'function') {
|
|
231
|
-
return Promise.reject(
|
|
264
|
+
return Promise.reject(
|
|
265
|
+
`.copy is not implemented on provider ${prov.getProviderName()}`
|
|
266
|
+
) as StorageCopyOutput<T>;
|
|
232
267
|
}
|
|
233
268
|
const responsePromise = prov.copy(src, dest, {
|
|
234
269
|
...config,
|
|
@@ -250,15 +285,18 @@ export class Storage {
|
|
|
250
285
|
key: string,
|
|
251
286
|
config?: StorageGetConfig<T>
|
|
252
287
|
): StorageGetOutput<T>;
|
|
253
|
-
public get<
|
|
254
|
-
key: string
|
|
255
|
-
|
|
256
|
-
): StorageGetOutput<T> {
|
|
288
|
+
public get<
|
|
289
|
+
T extends StorageProvider | { [key: string]: any; download?: boolean }
|
|
290
|
+
>(key: string, config?: StorageGetConfig<T>): StorageGetOutput<T> {
|
|
257
291
|
const provider = config?.provider || DEFAULT_PROVIDER;
|
|
258
|
-
const prov = this._pluggables.find(
|
|
292
|
+
const prov = this._pluggables.find(
|
|
293
|
+
pluggable => pluggable.getProviderName() === provider
|
|
294
|
+
);
|
|
259
295
|
if (prov === undefined) {
|
|
260
296
|
logger.debug('No plugin found with providerName', provider);
|
|
261
|
-
return Promise.reject(
|
|
297
|
+
return Promise.reject(
|
|
298
|
+
'No plugin found in Storage for the provider'
|
|
299
|
+
) as StorageGetOutput<T>;
|
|
262
300
|
}
|
|
263
301
|
const cancelTokenSource = this.getCancellableTokenSource();
|
|
264
302
|
const responsePromise = prov.get(key, {
|
|
@@ -292,18 +330,24 @@ export class Storage {
|
|
|
292
330
|
config?: StoragePutConfig<T>
|
|
293
331
|
): StoragePutOutput<T> {
|
|
294
332
|
const provider = config?.provider || DEFAULT_PROVIDER;
|
|
295
|
-
const prov = this._pluggables.find(
|
|
333
|
+
const prov = this._pluggables.find(
|
|
334
|
+
pluggable => pluggable.getProviderName() === provider
|
|
335
|
+
);
|
|
296
336
|
if (prov === undefined) {
|
|
297
337
|
logger.debug('No plugin found with providerName', provider);
|
|
298
|
-
return Promise.reject(
|
|
338
|
+
return Promise.reject(
|
|
339
|
+
'No plugin found in Storage for the provider'
|
|
340
|
+
) as StoragePutOutput<T>;
|
|
299
341
|
}
|
|
300
342
|
const cancelTokenSource = this.getCancellableTokenSource();
|
|
301
|
-
const
|
|
343
|
+
const response = prov.put(key, object, {
|
|
302
344
|
...config,
|
|
303
345
|
cancelTokenSource,
|
|
304
346
|
});
|
|
305
|
-
this.
|
|
306
|
-
|
|
347
|
+
if (!this.isUploadTask(response)) {
|
|
348
|
+
this.updateRequestToBeCancellable(response, cancelTokenSource);
|
|
349
|
+
}
|
|
350
|
+
return response as StoragePutOutput<T>;
|
|
307
351
|
}
|
|
308
352
|
|
|
309
353
|
/**
|
|
@@ -312,16 +356,23 @@ export class Storage {
|
|
|
312
356
|
* @param [config] - { level : private|protected|public }
|
|
313
357
|
* @return - Promise resolves upon successful removal of the object
|
|
314
358
|
*/
|
|
315
|
-
public remove<T extends Record<string, any>>(
|
|
359
|
+
public remove<T extends Record<string, any>>(
|
|
360
|
+
key: string,
|
|
361
|
+
config?: StorageRemoveConfig<T>
|
|
362
|
+
): StorageRemoveOutput<T>;
|
|
316
363
|
public remove<T extends StorageProvider = AWSS3Provider>(
|
|
317
364
|
key: string,
|
|
318
365
|
config?: StorageRemoveConfig<T>
|
|
319
366
|
): StorageRemoveOutput<T> {
|
|
320
367
|
const provider = config?.provider || DEFAULT_PROVIDER;
|
|
321
|
-
const prov = this._pluggables.find(
|
|
368
|
+
const prov = this._pluggables.find(
|
|
369
|
+
pluggable => pluggable.getProviderName() === provider
|
|
370
|
+
);
|
|
322
371
|
if (prov === undefined) {
|
|
323
372
|
logger.debug('No plugin found with providerName', provider);
|
|
324
|
-
return Promise.reject(
|
|
373
|
+
return Promise.reject(
|
|
374
|
+
'No plugin found in Storage for the provider'
|
|
375
|
+
) as StorageRemoveOutput<T>;
|
|
325
376
|
}
|
|
326
377
|
return prov.remove(key, config) as StorageRemoveOutput<T>;
|
|
327
378
|
}
|
|
@@ -332,16 +383,23 @@ export class Storage {
|
|
|
332
383
|
* @param [config] - { level : private|protected|public, maxKeys: NUMBER }
|
|
333
384
|
* @return - Promise resolves to list of keys for all objects in path
|
|
334
385
|
*/
|
|
335
|
-
public list<T extends Record<string, any>>(
|
|
386
|
+
public list<T extends Record<string, any>>(
|
|
387
|
+
key: string,
|
|
388
|
+
config?: StorageListConfig<T>
|
|
389
|
+
): StorageListOutput<T>;
|
|
336
390
|
public list<T extends StorageProvider = AWSS3Provider>(
|
|
337
391
|
path: string,
|
|
338
392
|
config?: StorageListConfig<T>
|
|
339
393
|
): StorageListOutput<T> {
|
|
340
394
|
const provider = config?.provider || DEFAULT_PROVIDER;
|
|
341
|
-
const prov = this._pluggables.find(
|
|
395
|
+
const prov = this._pluggables.find(
|
|
396
|
+
pluggable => pluggable.getProviderName() === provider
|
|
397
|
+
);
|
|
342
398
|
if (prov === undefined) {
|
|
343
399
|
logger.debug('No plugin found with providerName', provider);
|
|
344
|
-
return Promise.reject(
|
|
400
|
+
return Promise.reject(
|
|
401
|
+
'No plugin found in Storage for the provider'
|
|
402
|
+
) as StorageListOutput<T>;
|
|
345
403
|
}
|
|
346
404
|
return prov.list(path, config) as StorageListOutput<T>;
|
|
347
405
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Credentials,
|
|
3
|
+
ICredentials,
|
|
4
|
+
Logger,
|
|
5
|
+
getAmplifyUserAgent,
|
|
6
|
+
} from '@aws-amplify/core';
|
|
7
|
+
import { StorageAccessLevel, CustomPrefix } from '../types';
|
|
8
|
+
import {
|
|
9
|
+
InitializeMiddleware,
|
|
10
|
+
InitializeHandlerOptions,
|
|
11
|
+
FinalizeRequestHandlerOptions,
|
|
12
|
+
FinalizeRequestMiddleware,
|
|
13
|
+
HandlerExecutionContext,
|
|
14
|
+
} from '@aws-sdk/types';
|
|
15
|
+
import { S3ClientConfig, S3Client } from '@aws-sdk/client-s3';
|
|
16
|
+
import { CancelTokenSource } from 'axios';
|
|
17
|
+
import * as events from 'events';
|
|
18
|
+
import { AxiosHttpHandler } from '../providers/axios-http-handler';
|
|
19
|
+
import {
|
|
20
|
+
localTestingStorageEndpoint,
|
|
21
|
+
SET_CONTENT_LENGTH_HEADER,
|
|
22
|
+
} from './StorageConstants';
|
|
23
|
+
|
|
24
|
+
const logger = new Logger('S3ClientUtils');
|
|
25
|
+
// placeholder credentials in order to satisfy type requirement, always results in 403 when used
|
|
26
|
+
const INVALID_CRED = { accessKeyId: '', secretAccessKey: '' };
|
|
27
|
+
|
|
28
|
+
export const getPrefix = (config: {
|
|
29
|
+
credentials: ICredentials;
|
|
30
|
+
level?: StorageAccessLevel;
|
|
31
|
+
customPrefix?: CustomPrefix;
|
|
32
|
+
identityId?: string;
|
|
33
|
+
}): string => {
|
|
34
|
+
const { credentials, level, customPrefix, identityId } = config;
|
|
35
|
+
|
|
36
|
+
const resolvedCustomPrefix = customPrefix || {};
|
|
37
|
+
const resolvedIdentityId = identityId || credentials.identityId;
|
|
38
|
+
const privatePath =
|
|
39
|
+
(resolvedCustomPrefix.private !== undefined
|
|
40
|
+
? resolvedCustomPrefix.private
|
|
41
|
+
: 'private/') +
|
|
42
|
+
resolvedIdentityId +
|
|
43
|
+
'/';
|
|
44
|
+
const protectedPath =
|
|
45
|
+
(resolvedCustomPrefix.protected !== undefined
|
|
46
|
+
? resolvedCustomPrefix.protected
|
|
47
|
+
: 'protected/') +
|
|
48
|
+
resolvedIdentityId +
|
|
49
|
+
'/';
|
|
50
|
+
const publicPath =
|
|
51
|
+
resolvedCustomPrefix.public !== undefined
|
|
52
|
+
? resolvedCustomPrefix.public
|
|
53
|
+
: 'public/';
|
|
54
|
+
|
|
55
|
+
switch (level) {
|
|
56
|
+
case 'private':
|
|
57
|
+
return privatePath;
|
|
58
|
+
case 'protected':
|
|
59
|
+
return protectedPath;
|
|
60
|
+
default:
|
|
61
|
+
return publicPath;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const createPrefixMiddleware = (
|
|
66
|
+
opt: Record<string, any>,
|
|
67
|
+
key: string
|
|
68
|
+
): InitializeMiddleware<any, any> => (next, _context) => async args => {
|
|
69
|
+
const credentials = await Credentials.get();
|
|
70
|
+
const cred = Credentials.shear(credentials);
|
|
71
|
+
const prefix = getPrefix({ ...opt, credentials: cred });
|
|
72
|
+
const clonedInput = Object.assign({}, args.input);
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(args.input, 'Key')) {
|
|
74
|
+
clonedInput.Key = prefix + key;
|
|
75
|
+
args.input = clonedInput;
|
|
76
|
+
} else if (Object.prototype.hasOwnProperty.call(args.input, 'Prefix')) {
|
|
77
|
+
clonedInput.Prefix = prefix + key;
|
|
78
|
+
args.input = clonedInput;
|
|
79
|
+
}
|
|
80
|
+
const result = next(args);
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const isTimeSkewedError = (err: any): boolean =>
|
|
85
|
+
err.ServerTime &&
|
|
86
|
+
typeof err.Code === 'string' &&
|
|
87
|
+
err.Code === 'RequestTimeTooSkewed';
|
|
88
|
+
|
|
89
|
+
// we want to take the S3Client config in parameter so we can modify it's systemClockOffset
|
|
90
|
+
export const autoAdjustClockskewMiddleware = (
|
|
91
|
+
config: S3ClientConfig
|
|
92
|
+
): FinalizeRequestMiddleware<any, any> => (
|
|
93
|
+
next,
|
|
94
|
+
_context: HandlerExecutionContext
|
|
95
|
+
) => async args => {
|
|
96
|
+
try {
|
|
97
|
+
return await next(args);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (isTimeSkewedError(err)) {
|
|
100
|
+
const serverDate = new Date(err.ServerTime);
|
|
101
|
+
config.systemClockOffset = serverDate.getTime() - Date.now();
|
|
102
|
+
}
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const autoAdjustClockskewMiddlewareOptions: FinalizeRequestHandlerOptions = {
|
|
108
|
+
step: 'finalizeRequest',
|
|
109
|
+
name: 'autoAdjustClockskewMiddleware',
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const prefixMiddlewareOptions: InitializeHandlerOptions = {
|
|
113
|
+
step: 'initialize',
|
|
114
|
+
name: 'addPrefixMiddleware',
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const credentialsProvider = async () => {
|
|
118
|
+
try {
|
|
119
|
+
const credentials = await Credentials.get();
|
|
120
|
+
if (!credentials) return INVALID_CRED;
|
|
121
|
+
const cred = Credentials.shear(credentials);
|
|
122
|
+
logger.debug('credentials provider get credentials', cred);
|
|
123
|
+
return cred;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.warn('credentials provider error', error);
|
|
126
|
+
return INVALID_CRED;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const createS3Client = (
|
|
131
|
+
config: {
|
|
132
|
+
region?: string;
|
|
133
|
+
cancelTokenSource?: CancelTokenSource;
|
|
134
|
+
dangerouslyConnectToHttpEndpointForTesting?: boolean;
|
|
135
|
+
useAccelerateEndpoint?: boolean;
|
|
136
|
+
},
|
|
137
|
+
emitter?: events.EventEmitter
|
|
138
|
+
): S3Client => {
|
|
139
|
+
const {
|
|
140
|
+
region,
|
|
141
|
+
cancelTokenSource,
|
|
142
|
+
dangerouslyConnectToHttpEndpointForTesting,
|
|
143
|
+
useAccelerateEndpoint,
|
|
144
|
+
} = config;
|
|
145
|
+
let localTestingConfig = {};
|
|
146
|
+
|
|
147
|
+
if (dangerouslyConnectToHttpEndpointForTesting) {
|
|
148
|
+
localTestingConfig = {
|
|
149
|
+
endpoint: localTestingStorageEndpoint,
|
|
150
|
+
tls: false,
|
|
151
|
+
bucketEndpoint: false,
|
|
152
|
+
forcePathStyle: true,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const s3client = new S3Client({
|
|
157
|
+
region,
|
|
158
|
+
// Using provider instead of a static credentials, so that if an upload task was in progress, but credentials gets
|
|
159
|
+
// changed or invalidated (e.g user signed out), the subsequent requests will fail.
|
|
160
|
+
credentials: credentialsProvider,
|
|
161
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
162
|
+
...localTestingConfig,
|
|
163
|
+
requestHandler: new AxiosHttpHandler({}, emitter, cancelTokenSource),
|
|
164
|
+
useAccelerateEndpoint,
|
|
165
|
+
});
|
|
166
|
+
s3client.middlewareStack.remove(SET_CONTENT_LENGTH_HEADER);
|
|
167
|
+
return s3client;
|
|
168
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' &&
|
|
2
|
+
typeof Symbol.for === 'function'
|
|
3
|
+
? Symbol.for('amplify_default')
|
|
4
|
+
: '@@amplify_default') as Symbol;
|
|
5
|
+
|
|
6
|
+
export const SET_CONTENT_LENGTH_HEADER = 'contentLengthMiddleware';
|
|
7
|
+
|
|
8
|
+
export const localTestingStorageEndpoint = 'http://localhost:20005';
|
|
9
|
+
|
|
10
|
+
export const UPLOADS_STORAGE_KEY = '__uploadInProgress';
|
|
@@ -2,6 +2,7 @@ export enum StorageErrorStrings {
|
|
|
2
2
|
NO_CREDENTIALS = 'No credentials',
|
|
3
3
|
NO_SRC_KEY = 'source param should be an object with the property "key" with value of type string',
|
|
4
4
|
NO_DEST_KEY = 'destination param should be an object with the property "key" with value of type string',
|
|
5
|
+
INVALID_BLOB = 'Object must be an instance of Blob',
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export enum AWSS3ProviderMultipartCopierErrors {
|
|
@@ -11,3 +12,7 @@ export enum AWSS3ProviderMultipartCopierErrors {
|
|
|
11
12
|
NO_COPYSOURCE = 'You must specify a copy source',
|
|
12
13
|
MAX_NUM_PARTS_EXCEEDED = 'Only a maximum of 10000 parts are allowed',
|
|
13
14
|
}
|
|
15
|
+
|
|
16
|
+
export enum AWSS3ProviderUploadErrorStrings {
|
|
17
|
+
UPLOAD_PAUSED_MESSAGE = 'paused',
|
|
18
|
+
}
|