@pi-r/aws-v3 0.3.0 → 0.3.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 -5
- package/package.json +9 -9
- package/upload/index.js +3 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Lisa Mishima
|
|
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) => {
|
|
@@ -16,7 +15,6 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
16
15
|
}
|
|
17
16
|
const location = Module.joinPath(Bucket, Key);
|
|
18
17
|
let input = { Bucket, Key, VersionId: target.versionId };
|
|
19
|
-
// @ts-ignore
|
|
20
18
|
client
|
|
21
19
|
.send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
|
|
22
20
|
.then(result => {
|
|
@@ -27,8 +25,8 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
27
25
|
input = Object.assign(deleteObject, input);
|
|
28
26
|
}
|
|
29
27
|
client.send(new AWS.DeleteObjectCommand(input))
|
|
30
|
-
.then(() => this.formatMessage(64
|
|
31
|
-
.catch(err => this.formatFail(64
|
|
28
|
+
.then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
|
|
29
|
+
.catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
|
|
32
30
|
}
|
|
33
31
|
})
|
|
34
32
|
.catch(err => callback(err));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws-v3",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.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.6.
|
|
24
|
-
"@e-mc/module": "^0.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"@pi-r/aws": "^0.3.
|
|
27
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
23
|
+
"@e-mc/cloud": "^0.6.2",
|
|
24
|
+
"@e-mc/module": "^0.6.2",
|
|
25
|
+
"@e-mc/types": "^0.6.2",
|
|
26
|
+
"@pi-r/aws": "^0.3.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/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') {
|
|
@@ -60,7 +59,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
60
59
|
});
|
|
61
60
|
} while (exists && ++i);
|
|
62
61
|
if (i > 0) {
|
|
63
|
-
this.formatMessage(64
|
|
62
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
if (pathname) {
|
|
@@ -128,7 +127,6 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
128
127
|
}
|
|
129
128
|
continue;
|
|
130
129
|
}
|
|
131
|
-
// @ts-ignore
|
|
132
130
|
client.send(new AWS.PutObjectCommand(params), { abortSignal: this.signal })
|
|
133
131
|
.then(() => {
|
|
134
132
|
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);
|
|
@@ -136,7 +134,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
136
134
|
cleanup();
|
|
137
135
|
callback(null, url);
|
|
138
136
|
}
|
|
139
|
-
this.formatMessage(64
|
|
137
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
140
138
|
})
|
|
141
139
|
.catch(err => {
|
|
142
140
|
if (first) {
|