@pi-r/aws-v3 0.5.0 → 0.5.3
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/LICENSE +1 -1
- package/README.md +4 -2
- package/client/index.js +15 -15
- package/download/index.js +3 -4
- package/package.json +9 -9
- package/types/index.d.ts +41 -0
- package/upload/index.js +5 -6
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Haruhi Suzumiya
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -23,16 +23,16 @@ function setCannedAcl(S3, client, Bucket, ACL, service = 'aws-v3', recursive) {
|
|
|
23
23
|
}
|
|
24
24
|
return client.send(new S3.PutBucketPolicyCommand({ Bucket, Policy }))
|
|
25
25
|
.then(() => {
|
|
26
|
-
this.formatMessage(64
|
|
26
|
+
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
27
27
|
})
|
|
28
28
|
.catch((err) => {
|
|
29
29
|
if (!recursive && err instanceof Error) {
|
|
30
30
|
if (err.name === 'OperationAborted') {
|
|
31
|
-
setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000
|
|
32
|
-
this.formatMessage(64
|
|
31
|
+
setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000);
|
|
32
|
+
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
this.formatMessage(64
|
|
35
|
+
this.formatMessage(64, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -112,7 +112,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
|
|
|
112
112
|
}
|
|
113
113
|
return client.send(new AWS.CreateBucketCommand(input))
|
|
114
114
|
.then(async () => {
|
|
115
|
-
this.formatMessage(64
|
|
115
|
+
this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
116
116
|
if (ACL) {
|
|
117
117
|
await setCannedAcl.call(this, AWS, client, Bucket, ACL, service);
|
|
118
118
|
}
|
|
@@ -127,7 +127,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
|
|
|
127
127
|
}
|
|
128
128
|
return true;
|
|
129
129
|
default:
|
|
130
|
-
this.formatFail(64
|
|
130
|
+
this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
131
131
|
return false;
|
|
132
132
|
}
|
|
133
133
|
});
|
|
@@ -141,12 +141,12 @@ function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aw
|
|
|
141
141
|
options.Bucket = Bucket;
|
|
142
142
|
return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
|
|
143
143
|
.then(() => {
|
|
144
|
-
this.formatMessage(64
|
|
144
|
+
this.formatMessage(64, service, [block ? "Bucket configured" : policy ? "Bucket policy configured" : "Bucket ACL configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
145
145
|
return true;
|
|
146
146
|
})
|
|
147
147
|
.catch(err => {
|
|
148
148
|
if (!isNoSuchBucket(err)) {
|
|
149
|
-
this.formatFail(64
|
|
149
|
+
this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
150
150
|
}
|
|
151
151
|
return false;
|
|
152
152
|
});
|
|
@@ -164,12 +164,12 @@ function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'a
|
|
|
164
164
|
}
|
|
165
165
|
return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
|
|
166
166
|
.then(() => {
|
|
167
|
-
this.formatMessage(64
|
|
167
|
+
this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
168
168
|
return true;
|
|
169
169
|
})
|
|
170
170
|
.catch(err => {
|
|
171
171
|
if (!isNoSuchBucket(err)) {
|
|
172
|
-
this.formatFail(64
|
|
172
|
+
this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
173
173
|
}
|
|
174
174
|
return false;
|
|
175
175
|
});
|
|
@@ -193,17 +193,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
193
193
|
const Deleted = data.Deleted;
|
|
194
194
|
if ((0, types_1.isArray)(Deleted)) {
|
|
195
195
|
const files = Deleted.length + ' files';
|
|
196
|
-
this.formatMessage(64
|
|
196
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
197
197
|
}
|
|
198
198
|
})
|
|
199
199
|
.catch(err => {
|
|
200
|
-
this.formatFail(64
|
|
200
|
+
this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
})
|
|
204
204
|
.catch(err => {
|
|
205
205
|
if (!isNoSuchBucket(err)) {
|
|
206
|
-
this.formatFail(64
|
|
206
|
+
this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
209
|
}
|
|
@@ -225,7 +225,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
225
225
|
const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
|
|
226
226
|
if (!table) {
|
|
227
227
|
closeClient();
|
|
228
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
228
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
229
229
|
}
|
|
230
230
|
(0, aws_1.setDatabaseEndpoint)(credential);
|
|
231
231
|
const renewCache = ignoreCache === 0;
|
|
@@ -273,7 +273,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
273
273
|
}
|
|
274
274
|
else {
|
|
275
275
|
closeClient();
|
|
276
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
276
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
277
277
|
}
|
|
278
278
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
279
279
|
}
|
package/download/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const util_1 = require("@e-mc/cloud/util");
|
|
4
3
|
const types_1 = require("@e-mc/types");
|
|
5
4
|
const Module = require("@e-mc/module");
|
|
6
5
|
const Cloud = require("@e-mc/cloud");
|
|
7
|
-
const client_1 = require("
|
|
6
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
8
7
|
function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
9
8
|
const [client, AWS] = client_1.createStorageClient.call(this, config, service, sdk);
|
|
10
9
|
return (data, callback) => {
|
|
@@ -25,8 +24,8 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
25
24
|
input = Object.assign(deleteObject, input);
|
|
26
25
|
}
|
|
27
26
|
client.send(new AWS.DeleteObjectCommand(input))
|
|
28
|
-
.then(() => this.formatMessage(64
|
|
29
|
-
.catch(err => this.formatFail(64
|
|
27
|
+
.then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
|
|
28
|
+
.catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
|
|
30
29
|
}
|
|
31
30
|
})
|
|
32
31
|
.catch(err => callback(err));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws-v3",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "AWS V3 cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
12
|
"directory": "src/cloud/aws-v3"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.7.
|
|
24
|
-
"@e-mc/module": "^0.7.
|
|
25
|
-
"@e-mc/types": "^0.7.
|
|
26
|
-
"@pi-r/aws": "^0.5.
|
|
27
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
23
|
+
"@e-mc/cloud": "^0.7.3",
|
|
24
|
+
"@e-mc/module": "^0.7.3",
|
|
25
|
+
"@e-mc/types": "^0.7.3",
|
|
26
|
+
"@pi-r/aws": "^0.5.3",
|
|
27
|
+
"@aws-sdk/client-dynamodb": "^3.540.0",
|
|
28
|
+
"@aws-sdk/client-s3": "^3.540.0",
|
|
29
|
+
"@aws-sdk/lib-dynamodb": "^3.540.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
+
|
|
3
|
+
import type { AwsAuthInputConfig } from '@aws-sdk/middleware-signing';
|
|
4
|
+
import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput } from '@aws-sdk/client-dynamodb';
|
|
5
|
+
import type { BatchGetCommandInput, TranslateConfig, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
6
|
+
import type { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
7
|
+
import type { S3ClientConfig } from '@aws-sdk/client-s3';
|
|
8
|
+
|
|
9
|
+
export interface AWSBaseCredential extends AwsAuthInputConfig {
|
|
10
|
+
provider?: {
|
|
11
|
+
http?: unknown;
|
|
12
|
+
ini?: unknown;
|
|
13
|
+
cognitoIdentity?: unknown;
|
|
14
|
+
cognitoIdentityPool?: unknown;
|
|
15
|
+
temporaryCredentials?: unknown;
|
|
16
|
+
webToken?: unknown;
|
|
17
|
+
containerMetadata?: unknown;
|
|
18
|
+
instanceMetadata?: unknown;
|
|
19
|
+
process?: unknown;
|
|
20
|
+
tokenFile?: unknown;
|
|
21
|
+
sso?: unknown;
|
|
22
|
+
env?: unknown;
|
|
23
|
+
nodeProviderChain?: unknown;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type AWSStorage = CloudStorage<AWSStorageCredential, "aws-v3">;
|
|
28
|
+
|
|
29
|
+
export interface AWSStorageCredential extends S3ClientConfig, AWSBaseCredential {}
|
|
30
|
+
|
|
31
|
+
export interface AWSDatabaseQuery extends CloudDatabase<QueryCommandInput | ObjectMap<NativeAttributeValue>[], PlainObject, UpdateCommandInput, BatchGetCommandInput | ScanCommandInput> {
|
|
32
|
+
source: "cloud";
|
|
33
|
+
service: "aws-v3";
|
|
34
|
+
key?: string | AttributeKey;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AWSDatabaseCredential extends Omit<DynamoDBClientConfig, "credentials">, AWSBaseCredential {
|
|
38
|
+
translateConfig?: TranslateConfig;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type AttributeKey = Record<string, NativeAttributeValue>;
|
package/upload/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const stream = require("stream");
|
|
@@ -8,7 +7,7 @@ const aws_1 = require("@pi-r/aws");
|
|
|
8
7
|
const types_1 = require("@e-mc/types");
|
|
9
8
|
const Module = require("@e-mc/module");
|
|
10
9
|
const Cloud = require("@e-mc/cloud");
|
|
11
|
-
const client_1 = require("
|
|
10
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
12
11
|
const BUCKET_SESSION = new Set();
|
|
13
12
|
const BUCKET_RESPONSE = {};
|
|
14
13
|
function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
@@ -70,7 +69,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
70
69
|
});
|
|
71
70
|
} while (exists && ++i);
|
|
72
71
|
if (i > 0) {
|
|
73
|
-
this.formatMessage(64
|
|
72
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
if (pathname) {
|
|
@@ -148,7 +147,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
148
147
|
}
|
|
149
148
|
client.send(new AWS.PutObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner, Tagging: { TagSet }, RequestPayer: params.RequestPayer }), error => {
|
|
150
149
|
if (!error) {
|
|
151
|
-
this.formatMessage(64
|
|
150
|
+
this.formatMessage(64, service, ["Tags created", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
152
151
|
}
|
|
153
152
|
else {
|
|
154
153
|
addLog(error);
|
|
@@ -158,7 +157,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
158
157
|
else if (tags === false) {
|
|
159
158
|
client.send(new AWS.DeleteObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }), error => {
|
|
160
159
|
if (!error) {
|
|
161
|
-
this.formatMessage(64
|
|
160
|
+
this.formatMessage(64, service, ["Tags deleted", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
162
161
|
}
|
|
163
162
|
else {
|
|
164
163
|
addLog(error);
|
|
@@ -168,7 +167,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
168
167
|
cleanup();
|
|
169
168
|
callback(null, url);
|
|
170
169
|
}
|
|
171
|
-
this.formatMessage(64
|
|
170
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
172
171
|
})
|
|
173
172
|
.catch(err => {
|
|
174
173
|
if (first) {
|