@pi-r/aws-v3 0.3.0 → 0.3.2
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 +8 -5
- package/package.json +9 -9
- package/upload/index.js +8 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Studio Trigger
|
|
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
|
@@ -4,7 +4,7 @@ const util_1 = require("@e-mc/cloud/util");
|
|
|
4
4
|
const types_1 = require("@e-mc/types");
|
|
5
5
|
const Module = require("@e-mc/module");
|
|
6
6
|
const Cloud = require("@e-mc/cloud");
|
|
7
|
-
const client_1 = require("
|
|
7
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
8
8
|
function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
9
9
|
const [client, AWS] = client_1.createStorageClient.call(this, config, service, sdk);
|
|
10
10
|
return (data, callback) => {
|
|
@@ -16,7 +16,6 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
16
16
|
}
|
|
17
17
|
const location = Module.joinPath(Bucket, Key);
|
|
18
18
|
let input = { Bucket, Key, VersionId: target.versionId };
|
|
19
|
-
// @ts-ignore
|
|
20
19
|
client
|
|
21
20
|
.send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
|
|
22
21
|
.then(result => {
|
|
@@ -27,12 +26,16 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
27
26
|
input = Object.assign(deleteObject, input);
|
|
28
27
|
}
|
|
29
28
|
client.send(new AWS.DeleteObjectCommand(input))
|
|
30
|
-
.then(() => this.formatMessage(64
|
|
31
|
-
.catch(err => this.formatFail(64
|
|
29
|
+
.then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
|
|
30
|
+
.catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
|
|
32
31
|
}
|
|
33
32
|
})
|
|
34
33
|
.catch(err => callback(err));
|
|
35
34
|
};
|
|
36
35
|
}
|
|
36
|
+
exports.default = download;
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if (exports.default) {
|
|
39
|
+
module.exports = exports.default;
|
|
40
|
+
module.exports.default = exports.default;
|
|
41
|
+
}
|
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.2",
|
|
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.1",
|
|
24
|
+
"@e-mc/module": "^0.6.1",
|
|
25
|
+
"@e-mc/types": "^0.6.1",
|
|
26
|
+
"@pi-r/aws": "^0.3.2",
|
|
27
|
+
"@aws-sdk/client-dynamodb": "^3.525.0",
|
|
28
|
+
"@aws-sdk/client-s3": "^3.525.0",
|
|
29
|
+
"@aws-sdk/lib-dynamodb": "^3.525.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/upload/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const aws_1 = require("@pi-r/aws");
|
|
|
8
8
|
const types_1 = require("@e-mc/types");
|
|
9
9
|
const Module = require("@e-mc/module");
|
|
10
10
|
const Cloud = require("@e-mc/cloud");
|
|
11
|
-
const client_1 = require("
|
|
11
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
12
12
|
const BUCKET_SESSION = new Set();
|
|
13
13
|
const BUCKET_RESPONSE = {};
|
|
14
14
|
function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
@@ -60,7 +60,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
60
60
|
});
|
|
61
61
|
} while (exists && ++i);
|
|
62
62
|
if (i > 0) {
|
|
63
|
-
this.formatMessage(64
|
|
63
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
if (pathname) {
|
|
@@ -128,7 +128,6 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
128
128
|
}
|
|
129
129
|
continue;
|
|
130
130
|
}
|
|
131
|
-
// @ts-ignore
|
|
132
131
|
client.send(new AWS.PutObjectCommand(params), { abortSignal: this.signal })
|
|
133
132
|
.then(() => {
|
|
134
133
|
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 +135,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
136
135
|
cleanup();
|
|
137
136
|
callback(null, url);
|
|
138
137
|
}
|
|
139
|
-
this.formatMessage(64
|
|
138
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
140
139
|
})
|
|
141
140
|
.catch(err => {
|
|
142
141
|
if (first) {
|
|
@@ -149,5 +148,9 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
|
149
148
|
}
|
|
150
149
|
};
|
|
151
150
|
}
|
|
151
|
+
exports.default = upload;
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
if (exports.default) {
|
|
154
|
+
module.exports = exports.default;
|
|
155
|
+
module.exports.default = exports.default;
|
|
156
|
+
}
|