@pi-r/aws-v3 0.6.3 → 0.6.6
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 -19
- package/download/index.js +5 -8
- package/package.json +9 -9
- package/upload/index.js +7 -10
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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.executeBatchQuery = exports.executeQuery = exports.deleteObjectsV2 = exports.deleteObjects = exports.setBucketWebsite = exports.setBucketPolicy = exports.createBucketV2 = exports.createBucket = exports.validateDatabase = exports.validateStorage = exports.createDatabaseClient = exports.createStorageClient = void 0;
|
|
4
3
|
const Lib = require("@aws-sdk/lib-dynamodb");
|
|
5
4
|
const Client = require("@aws-sdk/client-dynamodb");
|
|
@@ -27,16 +26,16 @@ async function setCannedAcl(S3, client, Bucket, ACL, service = 'aws-v3', recursi
|
|
|
27
26
|
}
|
|
28
27
|
return client.send(new S3.PutBucketPolicyCommand({ Bucket, Policy }))
|
|
29
28
|
.then(() => {
|
|
30
|
-
this.formatMessage(64
|
|
29
|
+
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
31
30
|
})
|
|
32
31
|
.catch((err) => {
|
|
33
32
|
if (!recursive && err instanceof Error) {
|
|
34
33
|
if (err.name === 'OperationAborted') {
|
|
35
|
-
setTimeout(async () => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000
|
|
36
|
-
this.formatMessage(64
|
|
34
|
+
setTimeout(async () => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000);
|
|
35
|
+
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
37
36
|
}
|
|
38
37
|
else {
|
|
39
|
-
this.formatMessage(64
|
|
38
|
+
this.formatMessage(64, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
});
|
|
@@ -176,7 +175,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v
|
|
|
176
175
|
}
|
|
177
176
|
return client.send(new AWS.CreateBucketCommand(input))
|
|
178
177
|
.then(async () => {
|
|
179
|
-
this.formatMessage(64
|
|
178
|
+
this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
180
179
|
if (ACL) {
|
|
181
180
|
await setCannedAcl.call(this, AWS, client, Bucket, ACL, service);
|
|
182
181
|
}
|
|
@@ -191,7 +190,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v
|
|
|
191
190
|
}
|
|
192
191
|
return true;
|
|
193
192
|
default:
|
|
194
|
-
this.formatFail(64
|
|
193
|
+
this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
195
194
|
return false;
|
|
196
195
|
}
|
|
197
196
|
});
|
|
@@ -205,12 +204,12 @@ async function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk
|
|
|
205
204
|
options.Bucket = Bucket;
|
|
206
205
|
return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
|
|
207
206
|
.then(() => {
|
|
208
|
-
this.formatMessage(64
|
|
207
|
+
this.formatMessage(64, service, [block ? "Bucket configured" : policy ? "Bucket policy configured" : "Bucket ACL configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
209
208
|
return true;
|
|
210
209
|
})
|
|
211
210
|
.catch(err => {
|
|
212
211
|
if (!isNoSuchBucket(err)) {
|
|
213
|
-
this.formatFail(64
|
|
212
|
+
this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
214
213
|
}
|
|
215
214
|
return false;
|
|
216
215
|
});
|
|
@@ -228,12 +227,12 @@ async function setBucketWebsite(credential, Bucket, options, service = 'aws', sd
|
|
|
228
227
|
}
|
|
229
228
|
return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
|
|
230
229
|
.then(() => {
|
|
231
|
-
this.formatMessage(64
|
|
230
|
+
this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
232
231
|
return true;
|
|
233
232
|
})
|
|
234
233
|
.catch(err => {
|
|
235
234
|
if (!isNoSuchBucket(err)) {
|
|
236
|
-
this.formatFail(64
|
|
235
|
+
this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
237
236
|
}
|
|
238
237
|
return false;
|
|
239
238
|
});
|
|
@@ -257,17 +256,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
257
256
|
const Deleted = data.Deleted;
|
|
258
257
|
if ((0, types_1.isArray)(Deleted)) {
|
|
259
258
|
const files = Deleted.length + ' files';
|
|
260
|
-
this.formatMessage(64
|
|
259
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
261
260
|
}
|
|
262
261
|
})
|
|
263
262
|
.catch(err => {
|
|
264
|
-
this.formatFail(64
|
|
263
|
+
this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
265
264
|
});
|
|
266
265
|
}
|
|
267
266
|
})
|
|
268
267
|
.catch(err => {
|
|
269
268
|
if (!isNoSuchBucket(err)) {
|
|
270
|
-
this.formatFail(64
|
|
269
|
+
this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
271
270
|
}
|
|
272
271
|
});
|
|
273
272
|
}
|
|
@@ -301,7 +300,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
301
300
|
if (key && (id || (0, types_1.isPlainObject)(key))) {
|
|
302
301
|
if (!TableName) {
|
|
303
302
|
closeClient();
|
|
304
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
303
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
305
304
|
}
|
|
306
305
|
if (useCache) {
|
|
307
306
|
queryString = TableName + '_' + Module.asString(key, true) + (id !== undefined ? '_' + Module.asString(id, true) : '');
|
|
@@ -327,7 +326,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
327
326
|
}
|
|
328
327
|
if (!query.TableName) {
|
|
329
328
|
closeClient();
|
|
330
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
329
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
331
330
|
}
|
|
332
331
|
if (limit > 0) {
|
|
333
332
|
query.Limit = limit;
|
|
@@ -349,9 +348,8 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
349
348
|
}
|
|
350
349
|
TableName || (TableName = Object.keys(params.RequestItems)[0]);
|
|
351
350
|
if (!TableName) {
|
|
352
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
351
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
353
352
|
}
|
|
354
|
-
// @ts-ignore
|
|
355
353
|
const Item = (_a = params.RequestItems)[TableName] || (_a[TableName] = {});
|
|
356
354
|
Item.Keys = query;
|
|
357
355
|
params = { RequestItems: { [TableName]: Item } };
|
|
@@ -385,7 +383,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
385
383
|
}
|
|
386
384
|
else {
|
|
387
385
|
closeClient();
|
|
388
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
386
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
389
387
|
}
|
|
390
388
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
391
389
|
}
|
package/download/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
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("
|
|
8
|
-
function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
6
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
7
|
+
module.exports = 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) => {
|
|
11
10
|
const { bucket: Bucket, download: target } = data;
|
|
@@ -25,12 +24,10 @@ 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));
|
|
33
32
|
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = download;
|
|
33
|
+
};
|
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.6",
|
|
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.7",
|
|
24
|
+
"@e-mc/module": "^0.8.7",
|
|
25
|
+
"@e-mc/types": "^0.8.7",
|
|
26
|
+
"@pi-r/aws": "^0.6.6",
|
|
27
|
+
"@aws-sdk/client-dynamodb": "^3.540.0",
|
|
28
|
+
"@aws-sdk/client-s3": "^3.540.0",
|
|
29
|
+
"@aws-sdk/credential-providers": "^3.540.0",
|
|
30
|
+
"@aws-sdk/lib-dynamodb": "^3.540.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,10 +6,10 @@ 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
|
-
function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
12
|
+
module.exports = function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
14
13
|
const [client, AWS] = client_1.createStorageClient.call(this, credential, service, sdk);
|
|
15
14
|
return async (data, callback) => {
|
|
16
15
|
var _a;
|
|
@@ -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);
|
|
@@ -176,6 +175,4 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
176
175
|
});
|
|
177
176
|
}
|
|
178
177
|
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
module.exports = upload;
|
|
178
|
+
};
|