@pi-r/aws 0.2.2 → 0.2.8
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 +18 -17
- package/download/index.js +8 -4
- package/package.json +6 -6
- package/types/index.d.ts +2 -2
- package/upload/index.js +8 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Mile Square Park
|
|
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
|
@@ -17,15 +17,15 @@ async function setCannedAcl(S3, Bucket, ACL, service = 'aws', recursive) {
|
|
|
17
17
|
}
|
|
18
18
|
const callback = (err) => {
|
|
19
19
|
if (!err) {
|
|
20
|
-
this.formatMessage(64
|
|
20
|
+
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
21
21
|
}
|
|
22
22
|
else if (!recursive) {
|
|
23
23
|
if (err instanceof Error && err.code === 'OperationAborted') {
|
|
24
|
-
setTimeout(() => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000
|
|
25
|
-
this.formatMessage(64
|
|
24
|
+
setTimeout(() => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000);
|
|
25
|
+
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
this.formatMessage(64
|
|
28
|
+
this.formatMessage(64, service, ['Unable to grant ' + ACL, Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -189,7 +189,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws', sdk =
|
|
|
189
189
|
}
|
|
190
190
|
return S3.createBucket(input).promise()
|
|
191
191
|
.then(async () => {
|
|
192
|
-
this.formatMessage(64
|
|
192
|
+
this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
193
193
|
if (ACL) {
|
|
194
194
|
await setCannedAcl.call(this, S3, Bucket, ACL, service);
|
|
195
195
|
}
|
|
@@ -204,7 +204,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws', sdk =
|
|
|
204
204
|
}
|
|
205
205
|
return true;
|
|
206
206
|
default:
|
|
207
|
-
this.formatFail(64
|
|
207
|
+
this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
208
208
|
return false;
|
|
209
209
|
}
|
|
210
210
|
});
|
|
@@ -212,20 +212,21 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws', sdk =
|
|
|
212
212
|
}
|
|
213
213
|
exports.createBucketV2 = createBucketV2;
|
|
214
214
|
function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
215
|
+
const ibm = service === 'ibm';
|
|
215
216
|
const S3 = createStorageClient.call(this, credential, service, sdk);
|
|
216
217
|
options.Bucket = Bucket;
|
|
217
|
-
if (
|
|
218
|
+
if (ibm && 'ACL' in options && options.ACL === 'authenticated-read') {
|
|
218
219
|
options.AccessControlPolicy = ACP_AUTHENTICATEDREAD;
|
|
219
220
|
delete options.ACL;
|
|
220
221
|
}
|
|
221
|
-
return ('Policy' in options && (0, types_1.isString)(options.Policy) &&
|
|
222
|
+
return ('PublicAccessBlockConfiguration' in options ? S3.putPublicAccessBlock(options) : 'Policy' in options && (0, types_1.isString)(options.Policy) && !ibm ? S3.putBucketPolicy(options) : S3.putBucketAcl(options)).promise()
|
|
222
223
|
.then(() => {
|
|
223
|
-
this.formatMessage(64
|
|
224
|
+
this.formatMessage(64, service, ["Bucket policy configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
224
225
|
return true;
|
|
225
226
|
})
|
|
226
227
|
.catch(err => {
|
|
227
228
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
228
|
-
this.formatFail(64
|
|
229
|
+
this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
229
230
|
}
|
|
230
231
|
return false;
|
|
231
232
|
});
|
|
@@ -242,12 +243,12 @@ function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'a
|
|
|
242
243
|
}
|
|
243
244
|
return S3.putBucketWebsite({ Bucket, WebsiteConfiguration }).promise()
|
|
244
245
|
.then(() => {
|
|
245
|
-
this.formatMessage(64
|
|
246
|
+
this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
246
247
|
return true;
|
|
247
248
|
})
|
|
248
249
|
.catch(err => {
|
|
249
250
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
250
|
-
this.formatFail(64
|
|
251
|
+
this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
251
252
|
}
|
|
252
253
|
return false;
|
|
253
254
|
});
|
|
@@ -270,17 +271,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
270
271
|
.then(data => {
|
|
271
272
|
if ((0, types_1.isArray)(data.Deleted)) {
|
|
272
273
|
const files = data.Deleted.length + ' files';
|
|
273
|
-
this.formatMessage(64
|
|
274
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
274
275
|
}
|
|
275
276
|
})
|
|
276
277
|
.catch(err => {
|
|
277
|
-
this.formatFail(64
|
|
278
|
+
this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
278
279
|
});
|
|
279
280
|
}
|
|
280
281
|
})
|
|
281
282
|
.catch(err => {
|
|
282
283
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
283
|
-
this.formatFail(64
|
|
284
|
+
this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
284
285
|
}
|
|
285
286
|
});
|
|
286
287
|
}
|
|
@@ -303,7 +304,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
303
304
|
const item = batch[i];
|
|
304
305
|
const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
|
|
305
306
|
if (!table) {
|
|
306
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
307
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
307
308
|
}
|
|
308
309
|
const renewCache = ignoreCache === 0;
|
|
309
310
|
const getCache = (value) => {
|
|
@@ -348,7 +349,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
351
|
else {
|
|
351
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
352
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
352
353
|
}
|
|
353
354
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
354
355
|
}
|
package/download/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_1 = require("
|
|
3
|
+
const client_1 = require("@pi-r/aws");
|
|
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");
|
|
@@ -22,10 +22,10 @@ function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
22
22
|
if (deleteObject) {
|
|
23
23
|
s3.deleteObject((0, types_1.isPlainObject)(deleteObject) ? Object.assign(deleteObject, params) : params, error => {
|
|
24
24
|
if (!error) {
|
|
25
|
-
this.formatMessage(64
|
|
25
|
+
this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
this.formatFail(64
|
|
28
|
+
this.formatFail(64, service, ["Delete failed", location], error, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -36,5 +36,9 @@ function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
exports.default = download;
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
if (exports.default) {
|
|
42
|
+
module.exports = exports.default;
|
|
43
|
+
module.exports.default = exports.default;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "AWS V2 cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/cloud/aws"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/cloud": "^0.5.
|
|
25
|
-
"@e-mc/module": "^0.5.
|
|
26
|
-
"@e-mc/types": "^0.5.
|
|
27
|
-
"aws-sdk": "^2.
|
|
24
|
+
"@e-mc/cloud": "^0.5.4",
|
|
25
|
+
"@e-mc/module": "^0.5.4",
|
|
26
|
+
"@e-mc/types": "^0.5.4",
|
|
27
|
+
"aws-sdk": "^2.1570.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import type { CloudDatabase } from '@e-mc/types/lib/cloud';
|
|
|
4
4
|
import type { ConfigurationOptions } from 'aws-sdk/lib/core';
|
|
5
5
|
import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
|
|
6
6
|
import type { Key, QueryInput, UpdateItemInput } from 'aws-sdk/clients/dynamodb';
|
|
7
|
-
import type { PutBucketAclRequest, PutBucketPolicyRequest } from 'aws-sdk/clients/s3';
|
|
7
|
+
import type { PutBucketAclRequest, PutBucketPolicyRequest, PutPublicAccessBlockRequest } from 'aws-sdk/clients/s3';
|
|
8
8
|
|
|
9
9
|
export type BucketCannedACL = "authenticated-read" | "private" | "public-read" | "public-read-write";
|
|
10
10
|
export type ObjectCannedACL = BucketCannedACL | "aws-exec-read" | "bucket-owner-full-control" | "bucket-owner-read";
|
|
11
|
-
export type ConfigureBucketOptions = PutBucketAclRequest | PutBucketPolicyRequest;
|
|
11
|
+
export type ConfigureBucketOptions = PutBucketAclRequest | PutBucketPolicyRequest | PutPublicAccessBlockRequest;
|
|
12
12
|
|
|
13
13
|
export interface AWSStorageCredential extends ConfigurationOptions {
|
|
14
14
|
profile?: string;
|
package/upload/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const client_1 = require("
|
|
5
|
+
const client_1 = require("@pi-r/aws");
|
|
6
6
|
const util_1 = require("@e-mc/cloud/util");
|
|
7
7
|
const types_1 = require("@e-mc/types");
|
|
8
8
|
const Module = require("@e-mc/module");
|
|
@@ -56,7 +56,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
56
56
|
});
|
|
57
57
|
} while (exists && ++i);
|
|
58
58
|
if (i > 0) {
|
|
59
|
-
this.formatMessage(64
|
|
59
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
if (pathname) {
|
|
@@ -113,7 +113,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
113
113
|
s3.upload(params, (err, result) => {
|
|
114
114
|
if (!err) {
|
|
115
115
|
const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
|
|
116
|
-
this.formatMessage(64
|
|
116
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
117
117
|
if (first) {
|
|
118
118
|
cleanup();
|
|
119
119
|
callback(null, url);
|
|
@@ -129,5 +129,9 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
exports.default = upload;
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
if (exports.default) {
|
|
135
|
+
module.exports = exports.default;
|
|
136
|
+
module.exports.default = exports.default;
|
|
137
|
+
}
|