@flowerforce/flowerbase 1.6.0 → 1.6.1-beta.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.
- package/dist/services/aws/index.d.ts +15 -2
- package/dist/services/aws/index.d.ts.map +1 -1
- package/dist/services/aws/index.js +43 -5
- package/dist/services/index.d.ts +14 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +42 -3
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/services/aws/index.ts +75 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InvokeAsyncCommandInput, InvokeAsyncCommandOutput, InvokeCommandInput, InvokeCommandOutput, Lambda } from '@aws-sdk/client-lambda';
|
|
2
|
-
import {
|
|
2
|
+
import { GetObjectCommandInput, GetObjectCommandOutput, PutObjectCommandInput, PutObjectCommandOutput, S3Client } from '@aws-sdk/client-s3';
|
|
3
3
|
type LambdaInvokeResponse = Omit<InvokeCommandOutput, 'Payload'> & {
|
|
4
4
|
Payload: {
|
|
5
5
|
text: () => string | undefined;
|
|
@@ -10,7 +10,20 @@ declare const Aws: () => {
|
|
|
10
10
|
Invoke: (params: InvokeCommandInput) => Promise<LambdaInvokeResponse>;
|
|
11
11
|
InvokeAsync: (params: InvokeAsyncCommandInput) => Promise<InvokeAsyncCommandOutput>;
|
|
12
12
|
};
|
|
13
|
-
s3: (region: string) =>
|
|
13
|
+
s3: (region: string) => S3Client & {
|
|
14
|
+
PutObject: (params: PutObjectCommandInput) => Promise<PutObjectCommandOutput>;
|
|
15
|
+
GetObject: (params: GetObjectCommandInput) => Promise<GetObjectCommandOutput>;
|
|
16
|
+
getSignedUrl: (operation: "getObject" | "putObject", params: (GetObjectCommandInput | PutObjectCommandInput) & {
|
|
17
|
+
Expires?: number;
|
|
18
|
+
}, options?: {
|
|
19
|
+
expiresIn?: number;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
PresignURL: (params: (GetObjectCommandInput | PutObjectCommandInput) & {
|
|
22
|
+
Method?: string;
|
|
23
|
+
ExpirationMS?: number;
|
|
24
|
+
Expires?: number;
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
};
|
|
14
27
|
};
|
|
15
28
|
export default Aws;
|
|
16
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,wBAAwB,EAExB,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,EACP,MAAM,wBAAwB,CAAA;AAC/B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,wBAAwB,EAExB,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,EACP,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAEL,qBAAqB,EACrB,sBAAsB,EAEtB,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACT,MAAM,oBAAoB,CAAA;AAI3B,KAAK,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IACjE,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;KAC/B,CAAA;CACF,CAAA;AAUD,QAAA,MAAM,GAAG;qBAkBY,MAAM;gBAKX,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,oBAAoB,CAAC;qBACxD,CAAC,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,wBAAwB,CAAC;;iBAwB1E,MAAM;mBAMJ,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,sBAAsB,CAAC;mBAClE,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,sBAAsB,CAAC;sBAC/D,CACZ,SAAS,2BAAkB,EAC3B,MAAM;sBAhDqE,MAAM;SAgD5D,EACrB,OAAO,CAAC,EAAE;YAAE,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,KAC7B,OAAO,CAAC,MAAM,CAAC;oBACR,CAAC,MAAM;qBAjDd,MAAM;2BACA,MAAM;sBACX,MAAM;SA+CyB,KAAK,OAAO,CAAC,MAAM,CAAC;;CAgDhE,CAAA;AAED,eAAe,GAAG,CAAA"}
|
|
@@ -8,9 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
13
24
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
25
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
14
26
|
const constants_1 = require("../../constants");
|
|
15
27
|
const decodePayload = (payload) => {
|
|
16
28
|
if (!payload) {
|
|
@@ -44,11 +56,37 @@ const Aws = () => {
|
|
|
44
56
|
lambda.invokeAsync = invokeAsync;
|
|
45
57
|
return lambda;
|
|
46
58
|
},
|
|
47
|
-
s3: (region) =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
s3: (region) => {
|
|
60
|
+
const client = new client_s3_1.S3Client({
|
|
61
|
+
region,
|
|
62
|
+
credentials,
|
|
63
|
+
forcePathStyle: true
|
|
64
|
+
});
|
|
65
|
+
client.PutObject = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
return client.send(new client_s3_1.PutObjectCommand(params));
|
|
67
|
+
});
|
|
68
|
+
client.GetObject = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
return client.send(new client_s3_1.GetObjectCommand(params));
|
|
70
|
+
});
|
|
71
|
+
client.getSignedUrl = (operation, params, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
const { Expires } = params, rest = __rest(params, ["Expires"]);
|
|
74
|
+
const expiresIn = (_a = options === null || options === void 0 ? void 0 : options.expiresIn) !== null && _a !== void 0 ? _a : Expires;
|
|
75
|
+
if (operation === 'putObject') {
|
|
76
|
+
return (0, s3_request_presigner_1.getSignedUrl)(client, new client_s3_1.PutObjectCommand(rest), expiresIn ? { expiresIn } : undefined);
|
|
77
|
+
}
|
|
78
|
+
return (0, s3_request_presigner_1.getSignedUrl)(client, new client_s3_1.GetObjectCommand(rest), expiresIn ? { expiresIn } : undefined);
|
|
79
|
+
});
|
|
80
|
+
client.PresignURL = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const { Method, ExpirationMS, Expires } = params, rest = __rest(params, ["Method", "ExpirationMS", "Expires"]);
|
|
82
|
+
const normalizedMethod = Method === null || Method === void 0 ? void 0 : Method.toUpperCase();
|
|
83
|
+
const operation = normalizedMethod === 'PUT' ? 'putObject' : 'getObject';
|
|
84
|
+
const expiresIn = Expires !== null && Expires !== void 0 ? Expires : (typeof ExpirationMS === 'number' ? Math.ceil(ExpirationMS / 1000) : undefined);
|
|
85
|
+
const options = typeof expiresIn === 'number' ? { expiresIn } : undefined;
|
|
86
|
+
return client.getSignedUrl(operation, rest, options);
|
|
87
|
+
});
|
|
88
|
+
return client;
|
|
89
|
+
}
|
|
52
90
|
};
|
|
53
91
|
};
|
|
54
92
|
exports.default = Aws;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -122,7 +122,20 @@ export declare const services: {
|
|
|
122
122
|
}>;
|
|
123
123
|
InvokeAsync: (params: import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandInput) => Promise<import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandOutput>;
|
|
124
124
|
};
|
|
125
|
-
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").
|
|
125
|
+
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").S3Client & {
|
|
126
|
+
PutObject: (params: import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").PutObjectCommandOutput>;
|
|
127
|
+
GetObject: (params: import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").GetObjectCommandOutput>;
|
|
128
|
+
getSignedUrl: (operation: "getObject" | "putObject", params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
129
|
+
Expires?: number;
|
|
130
|
+
}, options?: {
|
|
131
|
+
expiresIn?: number;
|
|
132
|
+
}) => Promise<string>;
|
|
133
|
+
PresignURL: (params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
134
|
+
Method?: string;
|
|
135
|
+
ExpirationMS?: number;
|
|
136
|
+
Expires?: number;
|
|
137
|
+
}) => Promise<string>;
|
|
138
|
+
};
|
|
126
139
|
};
|
|
127
140
|
auth: import("./auth/model").AuthServiceType;
|
|
128
141
|
'mongodb-atlas': import("./mongodb-atlas/model").MongodbAtlasFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAMo5E,CAAC;yBAAa,CAAC;;;;;;;;;;;CADv7E,CAAA"}
|
|
@@ -163,7 +163,20 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
163
163
|
}>;
|
|
164
164
|
InvokeAsync: (params: import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandInput) => Promise<import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandOutput>;
|
|
165
165
|
};
|
|
166
|
-
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").
|
|
166
|
+
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").S3Client & {
|
|
167
|
+
PutObject: (params: import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").PutObjectCommandOutput>;
|
|
168
|
+
GetObject: (params: import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").GetObjectCommandOutput>;
|
|
169
|
+
getSignedUrl: (operation: "getObject" | "putObject", params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
170
|
+
Expires?: number;
|
|
171
|
+
}, options?: {
|
|
172
|
+
expiresIn?: number;
|
|
173
|
+
}) => Promise<string>;
|
|
174
|
+
PresignURL: (params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
175
|
+
Method?: string;
|
|
176
|
+
ExpirationMS?: number;
|
|
177
|
+
Expires?: number;
|
|
178
|
+
}) => Promise<string>;
|
|
179
|
+
};
|
|
167
180
|
} | {
|
|
168
181
|
emailPasswordAuth: {
|
|
169
182
|
registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
|
|
@@ -297,7 +310,20 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
297
310
|
}>;
|
|
298
311
|
InvokeAsync: (params: import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandInput) => Promise<import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandOutput>;
|
|
299
312
|
};
|
|
300
|
-
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").
|
|
313
|
+
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").S3Client & {
|
|
314
|
+
PutObject: (params: import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").PutObjectCommandOutput>;
|
|
315
|
+
GetObject: (params: import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").GetObjectCommandOutput>;
|
|
316
|
+
getSignedUrl: (operation: "getObject" | "putObject", params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
317
|
+
Expires?: number;
|
|
318
|
+
}, options?: {
|
|
319
|
+
expiresIn?: number;
|
|
320
|
+
}) => Promise<string>;
|
|
321
|
+
PresignURL: (params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
322
|
+
Method?: string;
|
|
323
|
+
ExpirationMS?: number;
|
|
324
|
+
Expires?: number;
|
|
325
|
+
}) => Promise<string>;
|
|
326
|
+
};
|
|
301
327
|
} | {
|
|
302
328
|
emailPasswordAuth: {
|
|
303
329
|
registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
|
|
@@ -430,7 +456,20 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
430
456
|
}>;
|
|
431
457
|
InvokeAsync: (params: import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandInput) => Promise<import("@aws-sdk/client-lambda/dist-types").InvokeAsyncCommandOutput>;
|
|
432
458
|
};
|
|
433
|
-
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").
|
|
459
|
+
s3: (region: string) => import("@aws-sdk/client-s3/dist-types").S3Client & {
|
|
460
|
+
PutObject: (params: import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").PutObjectCommandOutput>;
|
|
461
|
+
GetObject: (params: import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3/dist-types").GetObjectCommandOutput>;
|
|
462
|
+
getSignedUrl: (operation: "getObject" | "putObject", params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
463
|
+
Expires?: number;
|
|
464
|
+
}, options?: {
|
|
465
|
+
expiresIn?: number;
|
|
466
|
+
}) => Promise<string>;
|
|
467
|
+
PresignURL: (params: (import("@aws-sdk/client-s3/dist-types").GetObjectCommandInput | import("@aws-sdk/client-s3/dist-types").PutObjectCommandInput) & {
|
|
468
|
+
Method?: string;
|
|
469
|
+
ExpirationMS?: number;
|
|
470
|
+
Expires?: number;
|
|
471
|
+
}) => Promise<string>;
|
|
472
|
+
};
|
|
434
473
|
} | {
|
|
435
474
|
emailPasswordAuth: {
|
|
436
475
|
registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;uBAqBP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BArCU,MAAM,OAAO,QAAQ
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;uBAqBP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BArCU,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA6DqjB,CAAC;iCAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAf,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAf,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;4BAhBpmB,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAerE,CAAA"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,16 @@ import {
|
|
|
7
7
|
InvokeCommandOutput,
|
|
8
8
|
Lambda
|
|
9
9
|
} from '@aws-sdk/client-lambda'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
GetObjectCommand,
|
|
12
|
+
GetObjectCommandInput,
|
|
13
|
+
GetObjectCommandOutput,
|
|
14
|
+
PutObjectCommand,
|
|
15
|
+
PutObjectCommandInput,
|
|
16
|
+
PutObjectCommandOutput,
|
|
17
|
+
S3Client
|
|
18
|
+
} from '@aws-sdk/client-s3'
|
|
19
|
+
import { getSignedUrl as presignGetSignedUrl } from '@aws-sdk/s3-request-presigner'
|
|
11
20
|
import { S3_CONFIG } from '../../constants'
|
|
12
21
|
|
|
13
22
|
type LambdaInvokeResponse = Omit<InvokeCommandOutput, 'Payload'> & {
|
|
@@ -33,6 +42,14 @@ const Aws = () => {
|
|
|
33
42
|
}
|
|
34
43
|
: undefined
|
|
35
44
|
|
|
45
|
+
type PresignOperation = 'getObject' | 'putObject'
|
|
46
|
+
type PresignParams = (GetObjectCommandInput | PutObjectCommandInput) & { Expires?: number }
|
|
47
|
+
type PresignURLParams = (GetObjectCommandInput | PutObjectCommandInput) & {
|
|
48
|
+
Method?: string
|
|
49
|
+
ExpirationMS?: number
|
|
50
|
+
Expires?: number
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
return {
|
|
37
54
|
lambda: (region: string) => {
|
|
38
55
|
const lambda = new Lambda({
|
|
@@ -64,12 +81,66 @@ const Aws = () => {
|
|
|
64
81
|
|
|
65
82
|
return lambda
|
|
66
83
|
},
|
|
67
|
-
s3: (region: string) =>
|
|
68
|
-
new
|
|
84
|
+
s3: (region: string) => {
|
|
85
|
+
const client = new S3Client({
|
|
69
86
|
region,
|
|
70
87
|
credentials,
|
|
71
88
|
forcePathStyle: true
|
|
72
|
-
})
|
|
89
|
+
}) as S3Client & {
|
|
90
|
+
PutObject: (params: PutObjectCommandInput) => Promise<PutObjectCommandOutput>
|
|
91
|
+
GetObject: (params: GetObjectCommandInput) => Promise<GetObjectCommandOutput>
|
|
92
|
+
getSignedUrl: (
|
|
93
|
+
operation: PresignOperation,
|
|
94
|
+
params: PresignParams,
|
|
95
|
+
options?: { expiresIn?: number }
|
|
96
|
+
) => Promise<string>
|
|
97
|
+
PresignURL: (params: PresignURLParams) => Promise<string>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
client.PutObject = async (params: PutObjectCommandInput): Promise<PutObjectCommandOutput> => {
|
|
101
|
+
return client.send(new PutObjectCommand(params))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
client.GetObject = async (params: GetObjectCommandInput): Promise<GetObjectCommandOutput> => {
|
|
105
|
+
return client.send(new GetObjectCommand(params))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
client.getSignedUrl = async (
|
|
109
|
+
operation: PresignOperation,
|
|
110
|
+
params: PresignParams,
|
|
111
|
+
options?: { expiresIn?: number }
|
|
112
|
+
): Promise<string> => {
|
|
113
|
+
const { Expires, ...rest } = params
|
|
114
|
+
const expiresIn = options?.expiresIn ?? Expires
|
|
115
|
+
|
|
116
|
+
if (operation === 'putObject') {
|
|
117
|
+
return presignGetSignedUrl(
|
|
118
|
+
client,
|
|
119
|
+
new PutObjectCommand(rest as PutObjectCommandInput),
|
|
120
|
+
expiresIn ? { expiresIn } : undefined
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return presignGetSignedUrl(
|
|
125
|
+
client,
|
|
126
|
+
new GetObjectCommand(rest as GetObjectCommandInput),
|
|
127
|
+
expiresIn ? { expiresIn } : undefined
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
client.PresignURL = async (params: PresignURLParams): Promise<string> => {
|
|
132
|
+
const { Method, ExpirationMS, Expires, ...rest } = params
|
|
133
|
+
const normalizedMethod = Method?.toUpperCase()
|
|
134
|
+
const operation: PresignOperation = normalizedMethod === 'PUT' ? 'putObject' : 'getObject'
|
|
135
|
+
const expiresIn =
|
|
136
|
+
Expires ?? (typeof ExpirationMS === 'number' ? Math.ceil(ExpirationMS / 1000) : undefined)
|
|
137
|
+
const options = typeof expiresIn === 'number' ? { expiresIn } : undefined
|
|
138
|
+
|
|
139
|
+
return client.getSignedUrl(operation, rest as PresignParams, options)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return client
|
|
143
|
+
}
|
|
73
144
|
}
|
|
74
145
|
}
|
|
75
146
|
|