@pi-r/aws-v3 0.9.4 → 0.10.1
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/client/index.js +30 -17
- package/package.json +9 -9
- package/types/index.d.ts +2 -2
package/client/index.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.deleteObjectsV2 = deleteObjectsV2;
|
|
|
14
14
|
exports.deleteObjectsV3 = deleteObjectsV3;
|
|
15
15
|
exports.executeQuery = executeQuery;
|
|
16
16
|
exports.executeBatchQuery = executeBatchQuery;
|
|
17
|
+
const S3 = require("@aws-sdk/client-s3");
|
|
17
18
|
const Lib = require("@aws-sdk/lib-dynamodb");
|
|
18
19
|
const Client = require("@aws-sdk/client-dynamodb");
|
|
19
20
|
const Providers = require("@aws-sdk/credential-providers");
|
|
@@ -21,7 +22,7 @@ const Cloud = require("@e-mc/cloud");
|
|
|
21
22
|
const types_1 = require("@e-mc/types");
|
|
22
23
|
const util_1 = require("@e-mc/cloud/util");
|
|
23
24
|
const aws_lib_1 = require("@pi-r/aws-lib");
|
|
24
|
-
async function setCannedAcl(
|
|
25
|
+
async function setCannedAcl(instance, client, Bucket, ACL, service = "aws-v3", recursive) {
|
|
25
26
|
let Policy;
|
|
26
27
|
switch (ACL) {
|
|
27
28
|
case 1:
|
|
@@ -37,14 +38,14 @@ async function setCannedAcl(S3, client, Bucket, ACL, service = "aws-v3", recursi
|
|
|
37
38
|
Policy = (0, aws_lib_1.getPrivatePolicy)(Bucket);
|
|
38
39
|
break;
|
|
39
40
|
}
|
|
40
|
-
return client.send(new
|
|
41
|
+
return client.send(new instance.PutBucketPolicyCommand({ Bucket, Policy }))
|
|
41
42
|
.then(() => {
|
|
42
43
|
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
43
44
|
})
|
|
44
45
|
.catch((err) => {
|
|
45
46
|
if (!recursive && err instanceof Error) {
|
|
46
47
|
if (err.name === 'OperationAborted') {
|
|
47
|
-
setTimeout(async () => setCannedAcl.call(this,
|
|
48
|
+
setTimeout(async () => setCannedAcl.call(this, instance, client, Bucket, ACL, service, true), 60000);
|
|
48
49
|
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
@@ -121,7 +122,7 @@ function fromProvider(credential) {
|
|
|
121
122
|
const isNoSuchBucket = (err) => err instanceof Error && err.name === 'NoSuchBucket';
|
|
122
123
|
function createStorageClient(credential, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
123
124
|
try {
|
|
124
|
-
const AWS = require(sdk);
|
|
125
|
+
const AWS = sdk === "@aws-sdk/client-s3" ? S3 : require(sdk);
|
|
125
126
|
return [new AWS.S3Client(fromProvider(credential)), AWS];
|
|
126
127
|
}
|
|
127
128
|
catch (err) {
|
|
@@ -147,7 +148,9 @@ async function createBucket(credential, Bucket, publicRead, service = "aws-v3",
|
|
|
147
148
|
return createBucketV2.call(this, credential, Bucket, publicRead ? "public-read" : undefined, undefined, service, sdk);
|
|
148
149
|
}
|
|
149
150
|
async function createBucketV2(credential, Bucket, ACL, options, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
150
|
-
|
|
151
|
+
if (ACL !== 1) {
|
|
152
|
+
ACL = (0, aws_lib_1.checkBucketCannedACL)(ACL);
|
|
153
|
+
}
|
|
151
154
|
const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
|
|
152
155
|
return client.send(new AWS.HeadBucketCommand({ Bucket }))
|
|
153
156
|
.then(async () => {
|
|
@@ -160,7 +163,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = "aws-v
|
|
|
160
163
|
const input = { ...options, Bucket };
|
|
161
164
|
const config = input.CreateBucketConfiguration ||= {};
|
|
162
165
|
if (!config.Location) {
|
|
163
|
-
const match = /^.+--([\w
|
|
166
|
+
const match = /^.+--([\w-]+)--x-s3$/.exec(Bucket);
|
|
164
167
|
if (match) {
|
|
165
168
|
config.Location = { Type: 'AvailabilityZone', Name: match[1] };
|
|
166
169
|
config.Bucket = { Type: 'Directory', DataRedundancy: 'SingleAvailabilityZone' };
|
|
@@ -398,7 +401,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
398
401
|
else {
|
|
399
402
|
update = '';
|
|
400
403
|
}
|
|
401
|
-
if (useCache && !update && (rows = this.getCacheResult(service, credential, queryString = Statement + '_' + Cloud.asString(Parameters, true) +
|
|
404
|
+
if (useCache && !update && (rows = this.getCacheResult(service, credential, queryString = Statement + '_' + Cloud.asString(Parameters, true) + '_' + (Limit ? Limit.toString() : '0'), cacheValue, ignoreCache))) {
|
|
402
405
|
result[i] = rows;
|
|
403
406
|
continue;
|
|
404
407
|
}
|
|
@@ -413,22 +416,32 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
413
416
|
queryString = '';
|
|
414
417
|
}
|
|
415
418
|
}
|
|
416
|
-
else if (TableName) {
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
else if (TableName || item.params) {
|
|
420
|
+
const params = (item.params || {});
|
|
421
|
+
if (!params.TransactItems) {
|
|
422
|
+
if (TableName) {
|
|
423
|
+
params.TableName = TableName;
|
|
424
|
+
}
|
|
425
|
+
else if (params.TableName) {
|
|
426
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
427
|
+
}
|
|
423
428
|
}
|
|
424
429
|
if (useCache && (rows = this.getCacheResult(service, credential, queryString = Cloud.asString(params, true), cacheValue, ignoreCache))) {
|
|
425
430
|
result[i] = rows;
|
|
426
431
|
continue;
|
|
427
432
|
}
|
|
428
433
|
const [db, AWS] = createClient();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
434
|
+
if (params.TransactItems) {
|
|
435
|
+
const { Responses } = await db.send(new AWS.TransactGetCommand(params));
|
|
436
|
+
if (Responses) {
|
|
437
|
+
rows = Responses.map(value => value.Item || {});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
const { Count, Items } = await db.send(new AWS.ScanCommand(params));
|
|
442
|
+
if (Count && Items) {
|
|
443
|
+
rows = Items;
|
|
444
|
+
}
|
|
432
445
|
}
|
|
433
446
|
}
|
|
434
447
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws-v3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "AWS cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/cloud": "^0.
|
|
23
|
-
"@e-mc/module": "^0.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
25
|
-
"@pi-r/aws-lib": "^0.
|
|
26
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
27
|
-
"@aws-sdk/client-s3": "^3.
|
|
22
|
+
"@e-mc/cloud": "^0.12.3",
|
|
23
|
+
"@e-mc/module": "^0.12.3",
|
|
24
|
+
"@e-mc/types": "^0.12.3",
|
|
25
|
+
"@pi-r/aws-lib": "^0.10.1",
|
|
26
|
+
"@aws-sdk/client-dynamodb": "^3.808.0",
|
|
27
|
+
"@aws-sdk/client-s3": "^3.808.0",
|
|
28
28
|
"@aws-sdk/credential-providers": "*",
|
|
29
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
30
|
-
"@aws-sdk/lib-storage": "^3.
|
|
29
|
+
"@aws-sdk/lib-dynamodb": "^3.808.0",
|
|
30
|
+
"@aws-sdk/lib-storage": "^3.808.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
2
|
|
|
3
3
|
import type { AwsSdkSigV4AuthInputConfig } from '@aws-sdk/core';
|
|
4
|
-
import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput } from '@aws-sdk/client-dynamodb';
|
|
4
|
+
import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput, TransactGetItemsCommandInput } from '@aws-sdk/client-dynamodb';
|
|
5
5
|
import type { BatchGetCommandInput, NativeAttributeValue, TranslateConfig, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
6
6
|
import type { S3ClientConfig } from '@aws-sdk/client-s3';
|
|
7
7
|
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
@@ -29,7 +29,7 @@ export type AWSStorage = CloudStorage<AWSStorageCredential, "aws-v3">;
|
|
|
29
29
|
|
|
30
30
|
export interface AWSStorageCredential extends S3ClientConfig, AWSBaseCredential {}
|
|
31
31
|
|
|
32
|
-
export interface AWSDatabaseQuery extends CloudDatabase<QueryCommandInput | ObjectMap<NativeAttributeValue>[] | string, PlainObject, UpdateCommandInput | string, BatchGetCommandInput | ScanCommandInput | NativeAttributeValue[]> {
|
|
32
|
+
export interface AWSDatabaseQuery extends CloudDatabase<QueryCommandInput | ObjectMap<NativeAttributeValue>[] | string, PlainObject, UpdateCommandInput | string, BatchGetCommandInput | ScanCommandInput | TransactGetItemsCommandInput | NativeAttributeValue[]> {
|
|
33
33
|
source: "cloud";
|
|
34
34
|
service: "aws-v3";
|
|
35
35
|
key?: string | AttributeKey;
|