@pi-r/aws-v3 0.6.3 → 0.6.5
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 +6 -3
- package/client/index.js +17 -18
- package/download/index.js +3 -4
- package/package.json +9 -9
- package/upload/index.js +5 -6
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
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
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# @pi-r/aws-v3
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/cloud/aws-v3.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
6
9
|
|
|
7
10
|
MIT
|
package/client/index.js
CHANGED
|
@@ -27,16 +27,16 @@ async function setCannedAcl(S3, client, Bucket, ACL, service = 'aws-v3', recursi
|
|
|
27
27
|
}
|
|
28
28
|
return client.send(new S3.PutBucketPolicyCommand({ Bucket, Policy }))
|
|
29
29
|
.then(() => {
|
|
30
|
-
this.formatMessage(64
|
|
30
|
+
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
31
31
|
})
|
|
32
32
|
.catch((err) => {
|
|
33
33
|
if (!recursive && err instanceof Error) {
|
|
34
34
|
if (err.name === 'OperationAborted') {
|
|
35
|
-
setTimeout(async () => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000
|
|
36
|
-
this.formatMessage(64
|
|
35
|
+
setTimeout(async () => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000);
|
|
36
|
+
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
this.formatMessage(64
|
|
39
|
+
this.formatMessage(64, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
});
|
|
@@ -176,7 +176,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v
|
|
|
176
176
|
}
|
|
177
177
|
return client.send(new AWS.CreateBucketCommand(input))
|
|
178
178
|
.then(async () => {
|
|
179
|
-
this.formatMessage(64
|
|
179
|
+
this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
180
180
|
if (ACL) {
|
|
181
181
|
await setCannedAcl.call(this, AWS, client, Bucket, ACL, service);
|
|
182
182
|
}
|
|
@@ -191,7 +191,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v
|
|
|
191
191
|
}
|
|
192
192
|
return true;
|
|
193
193
|
default:
|
|
194
|
-
this.formatFail(64
|
|
194
|
+
this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
195
195
|
return false;
|
|
196
196
|
}
|
|
197
197
|
});
|
|
@@ -205,12 +205,12 @@ async function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk
|
|
|
205
205
|
options.Bucket = Bucket;
|
|
206
206
|
return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
|
|
207
207
|
.then(() => {
|
|
208
|
-
this.formatMessage(64
|
|
208
|
+
this.formatMessage(64, service, [block ? "Bucket configured" : policy ? "Bucket policy configured" : "Bucket ACL configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
209
209
|
return true;
|
|
210
210
|
})
|
|
211
211
|
.catch(err => {
|
|
212
212
|
if (!isNoSuchBucket(err)) {
|
|
213
|
-
this.formatFail(64
|
|
213
|
+
this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
214
214
|
}
|
|
215
215
|
return false;
|
|
216
216
|
});
|
|
@@ -228,12 +228,12 @@ async function setBucketWebsite(credential, Bucket, options, service = 'aws', sd
|
|
|
228
228
|
}
|
|
229
229
|
return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
|
|
230
230
|
.then(() => {
|
|
231
|
-
this.formatMessage(64
|
|
231
|
+
this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
232
232
|
return true;
|
|
233
233
|
})
|
|
234
234
|
.catch(err => {
|
|
235
235
|
if (!isNoSuchBucket(err)) {
|
|
236
|
-
this.formatFail(64
|
|
236
|
+
this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
237
237
|
}
|
|
238
238
|
return false;
|
|
239
239
|
});
|
|
@@ -257,17 +257,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
257
257
|
const Deleted = data.Deleted;
|
|
258
258
|
if ((0, types_1.isArray)(Deleted)) {
|
|
259
259
|
const files = Deleted.length + ' files';
|
|
260
|
-
this.formatMessage(64
|
|
260
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
261
261
|
}
|
|
262
262
|
})
|
|
263
263
|
.catch(err => {
|
|
264
|
-
this.formatFail(64
|
|
264
|
+
this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
267
|
})
|
|
268
268
|
.catch(err => {
|
|
269
269
|
if (!isNoSuchBucket(err)) {
|
|
270
|
-
this.formatFail(64
|
|
270
|
+
this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
271
271
|
}
|
|
272
272
|
});
|
|
273
273
|
}
|
|
@@ -301,7 +301,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
301
301
|
if (key && (id || (0, types_1.isPlainObject)(key))) {
|
|
302
302
|
if (!TableName) {
|
|
303
303
|
closeClient();
|
|
304
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
304
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
305
305
|
}
|
|
306
306
|
if (useCache) {
|
|
307
307
|
queryString = TableName + '_' + Module.asString(key, true) + (id !== undefined ? '_' + Module.asString(id, true) : '');
|
|
@@ -327,7 +327,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
327
327
|
}
|
|
328
328
|
if (!query.TableName) {
|
|
329
329
|
closeClient();
|
|
330
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
330
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
331
331
|
}
|
|
332
332
|
if (limit > 0) {
|
|
333
333
|
query.Limit = limit;
|
|
@@ -349,9 +349,8 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
349
349
|
}
|
|
350
350
|
TableName || (TableName = Object.keys(params.RequestItems)[0]);
|
|
351
351
|
if (!TableName) {
|
|
352
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
352
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
353
353
|
}
|
|
354
|
-
// @ts-ignore
|
|
355
354
|
const Item = (_a = params.RequestItems)[TableName] || (_a[TableName] = {});
|
|
356
355
|
Item.Keys = query;
|
|
357
356
|
params = { RequestItems: { [TableName]: Item } };
|
|
@@ -385,7 +384,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
385
384
|
}
|
|
386
385
|
else {
|
|
387
386
|
closeClient();
|
|
388
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
387
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
389
388
|
}
|
|
390
389
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
391
390
|
}
|
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.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "AWS V3 cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.8.
|
|
24
|
-
"@e-mc/module": "^0.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
26
|
-
"@pi-r/aws": "^0.6.
|
|
27
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/credential-providers": "^3.
|
|
30
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
23
|
+
"@e-mc/cloud": "^0.8.6",
|
|
24
|
+
"@e-mc/module": "^0.8.6",
|
|
25
|
+
"@e-mc/types": "^0.8.6",
|
|
26
|
+
"@pi-r/aws": "^0.6.5",
|
|
27
|
+
"@aws-sdk/client-dynamodb": "^3.525.0",
|
|
28
|
+
"@aws-sdk/client-s3": "^3.525.0",
|
|
29
|
+
"@aws-sdk/credential-providers": "^3.525.0",
|
|
30
|
+
"@aws-sdk/lib-dynamodb": "^3.525.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
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 stream = require("stream");
|
|
5
4
|
const util_1 = require("@e-mc/cloud/util");
|
|
@@ -7,7 +6,7 @@ const aws_1 = require("@pi-r/aws");
|
|
|
7
6
|
const types_1 = require("@e-mc/types");
|
|
8
7
|
const Module = require("@e-mc/module");
|
|
9
8
|
const Cloud = require("@e-mc/cloud");
|
|
10
|
-
const client_1 = require("
|
|
9
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
11
10
|
const BUCKET_SESSION = new Set();
|
|
12
11
|
const BUCKET_RESPONSE = {};
|
|
13
12
|
function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
@@ -69,7 +68,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
69
68
|
});
|
|
70
69
|
} while (exists && ++i);
|
|
71
70
|
if (i > 0) {
|
|
72
|
-
this.formatMessage(64
|
|
71
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
if (pathname) {
|
|
@@ -134,7 +133,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
134
133
|
client.send(new AWS.PutObjectCommand(params), { abortSignal: this.signal })
|
|
135
134
|
.then(() => {
|
|
136
135
|
const url = endpoint ? Module.joinPath(endpoint, objectKey) : Module.joinPath(`https://${Bucket}.s3.${!credential.region || credential.region === 'us-east-1' ? 'us-east-1.' : ''}amazonaws.com`, objectKey);
|
|
137
|
-
this.formatMessage(64
|
|
136
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
138
137
|
if (!first) {
|
|
139
138
|
return;
|
|
140
139
|
}
|
|
@@ -146,7 +145,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
146
145
|
}
|
|
147
146
|
client.send(new AWS.PutObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner, Tagging: { TagSet }, RequestPayer: params.RequestPayer }), error => {
|
|
148
147
|
if (!error) {
|
|
149
|
-
this.formatMessage(64
|
|
148
|
+
this.formatMessage(64, service, ["Tags created", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
150
149
|
}
|
|
151
150
|
else {
|
|
152
151
|
addLog(error);
|
|
@@ -156,7 +155,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
156
155
|
else if (tags === false || length === 0) {
|
|
157
156
|
client.send(new AWS.DeleteObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }), error => {
|
|
158
157
|
if (!error) {
|
|
159
|
-
this.formatMessage(64
|
|
158
|
+
this.formatMessage(64, service, ["Tags deleted", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
160
159
|
}
|
|
161
160
|
else {
|
|
162
161
|
addLog(error);
|