@pi-r/aws-v3 0.8.3 → 0.9.1
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 +7 -7
- package/README.md +1 -1
- package/client/index.js +18 -7
- package/download/index.js +6 -8
- package/package.json +32 -33
- package/types/index.d.ts +3 -1
- package/upload/index.js +11 -19
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -11,14 +11,15 @@ exports.setBucketTagging = setBucketTagging;
|
|
|
11
11
|
exports.setBucketWebsite = setBucketWebsite;
|
|
12
12
|
exports.deleteObjects = deleteObjects;
|
|
13
13
|
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
14
|
+
exports.deleteObjectsV3 = deleteObjectsV3;
|
|
14
15
|
exports.executeQuery = executeQuery;
|
|
15
16
|
exports.executeBatchQuery = executeBatchQuery;
|
|
16
17
|
const Lib = require("@aws-sdk/lib-dynamodb");
|
|
17
18
|
const Client = require("@aws-sdk/client-dynamodb");
|
|
18
19
|
const Providers = require("@aws-sdk/credential-providers");
|
|
19
20
|
const Cloud = require("@e-mc/cloud");
|
|
20
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
21
21
|
const types_1 = require("@e-mc/types");
|
|
22
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
22
23
|
const aws_lib_1 = require("@pi-r/aws-lib");
|
|
23
24
|
async function setCannedAcl(S3, client, Bucket, ACL, service = "aws-v3", recursive) {
|
|
24
25
|
let Policy;
|
|
@@ -228,10 +229,10 @@ async function setBucketTagging(credential, Bucket, options, service = "aws-v3",
|
|
|
228
229
|
return false;
|
|
229
230
|
};
|
|
230
231
|
if (deleting) {
|
|
231
|
-
return client.send(new AWS.DeleteBucketTaggingCommand({ Bucket, ExpectedBucketOwner: options.ExpectedBucketOwner })).then(command).catch(
|
|
232
|
+
return client.send(new AWS.DeleteBucketTaggingCommand({ Bucket, ExpectedBucketOwner: options.ExpectedBucketOwner })).then(command).catch(error);
|
|
232
233
|
}
|
|
233
234
|
options.Bucket = Bucket;
|
|
234
|
-
return client.send(new AWS.PutBucketTaggingCommand(options)).then(command).catch(
|
|
235
|
+
return client.send(new AWS.PutBucketTaggingCommand(options)).then(command).catch(error);
|
|
235
236
|
}
|
|
236
237
|
async function setBucketWebsite(credential, Bucket, options, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
237
238
|
const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
|
|
@@ -255,12 +256,22 @@ async function setBucketWebsite(credential, Bucket, options, service = "aws-v3",
|
|
|
255
256
|
return false;
|
|
256
257
|
});
|
|
257
258
|
}
|
|
258
|
-
async function deleteObjects(credential, Bucket, service
|
|
259
|
-
return deleteObjectsV2.call(this, credential, Bucket,
|
|
259
|
+
async function deleteObjects(credential, Bucket, service, sdk, recursive = true) {
|
|
260
|
+
return deleteObjectsV2.call(this, credential, Bucket, recursive, service, sdk);
|
|
260
261
|
}
|
|
261
|
-
async function deleteObjectsV2(credential, Bucket, recursive = true, service
|
|
262
|
+
async function deleteObjectsV2(credential, Bucket, recursive = true, service, sdk) {
|
|
263
|
+
return deleteObjectsV3.call(this, credential, Bucket, { recursive, Bucket }, service, sdk);
|
|
264
|
+
}
|
|
265
|
+
async function deleteObjectsV3(credential, Bucket, options = {}, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
266
|
+
options = { ...options };
|
|
267
|
+
let recursive = true;
|
|
268
|
+
if ('recursive' in options) {
|
|
269
|
+
recursive = options.recursive;
|
|
270
|
+
delete options.recursive;
|
|
271
|
+
}
|
|
272
|
+
options.Bucket ||= Bucket;
|
|
262
273
|
const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
|
|
263
|
-
return client.send(new AWS.ListObjectsCommand(
|
|
274
|
+
return client.send(new AWS.ListObjectsCommand(options))
|
|
264
275
|
.then(async ({ Contents }) => {
|
|
265
276
|
if (Contents?.length) {
|
|
266
277
|
let Objects = Contents.map(data => ({ Key: data.Key }));
|
package/download/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const Cloud = require("@e-mc/cloud");
|
|
3
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
4
3
|
const types_1 = require("@e-mc/types");
|
|
4
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
5
5
|
const client_1 = require("@pi-r/aws-v3");
|
|
6
6
|
function download(config, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
7
7
|
const [client, AWS] = client_1.createStorageClient.call(this, config, service, sdk);
|
|
@@ -15,11 +15,11 @@ function download(config, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
15
15
|
const location = Cloud.joinPath(Bucket, Key);
|
|
16
16
|
client.send(new AWS.GetObjectCommand({ ...target.options, Bucket, Key, VersionId: target.versionId }), { abortSignal: this.signal })
|
|
17
17
|
.then(result => {
|
|
18
|
-
(0, util_1.readableAsBuffer)(result.Body)
|
|
18
|
+
(0, util_1.readableAsBuffer)(result.Body)
|
|
19
|
+
.then(buffer => {
|
|
19
20
|
callback(null, buffer);
|
|
20
|
-
})
|
|
21
|
-
callback
|
|
22
|
-
});
|
|
21
|
+
})
|
|
22
|
+
.catch(callback);
|
|
23
23
|
let deleteObject = target.deleteObject;
|
|
24
24
|
if (deleteObject) {
|
|
25
25
|
if (!(0, types_1.isPlainObject)(deleteObject)) {
|
|
@@ -34,9 +34,7 @@ function download(config, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
})
|
|
37
|
-
.catch(
|
|
38
|
-
callback(err);
|
|
39
|
-
});
|
|
37
|
+
.catch(callback);
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
40
|
module.exports = download;
|
package/package.json
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/aws-v3",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "AWS cloud functions for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/cloud/aws-v3"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"@e-mc/
|
|
24
|
-
"@e-mc/
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@aws-sdk/client-
|
|
28
|
-
"@aws-sdk/
|
|
29
|
-
"@aws-sdk/
|
|
30
|
-
"@aws-sdk/lib-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/aws-v3",
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "AWS cloud functions for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/cloud/aws-v3"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc"
|
|
17
|
+
],
|
|
18
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@e-mc/cloud": "^0.11.2",
|
|
23
|
+
"@e-mc/module": "^0.11.2",
|
|
24
|
+
"@e-mc/types": "^0.11.2",
|
|
25
|
+
"@pi-r/aws-lib": "^0.9.1",
|
|
26
|
+
"@aws-sdk/client-dynamodb": "^3.741.0",
|
|
27
|
+
"@aws-sdk/client-s3": "^3.741.0",
|
|
28
|
+
"@aws-sdk/credential-providers": "*",
|
|
29
|
+
"@aws-sdk/lib-dynamodb": "^3.741.0",
|
|
30
|
+
"@aws-sdk/lib-storage": "^3.741.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import type { AwsSdkSigV4AuthInputConfig } from '@aws-sdk/core';
|
|
|
4
4
|
import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput } from '@aws-sdk/client-dynamodb';
|
|
5
5
|
import type { BatchGetCommandInput, NativeAttributeValue, TranslateConfig, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
6
6
|
import type { S3ClientConfig } from '@aws-sdk/client-s3';
|
|
7
|
+
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
7
8
|
|
|
8
|
-
export interface AWSBaseCredential extends AwsSdkSigV4AuthInputConfig {
|
|
9
|
+
export interface AWSBaseCredential extends Omit<AwsSdkSigV4AuthInputConfig, "credentials"> {
|
|
10
|
+
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider;
|
|
9
11
|
provider?: {
|
|
10
12
|
http?: unknown;
|
|
11
13
|
ini?: unknown;
|
package/upload/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const stream = require("stream");
|
|
5
|
-
const
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const stream = require("node:stream");
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
7
7
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
9
8
|
const types_1 = require("@e-mc/types");
|
|
9
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
10
10
|
const aws_lib_1 = require("@pi-r/aws-lib");
|
|
11
11
|
const client_1 = require("@pi-r/aws-v3");
|
|
12
12
|
const BUCKET_SESSION = new Set();
|
|
@@ -54,9 +54,7 @@ function upload(credential, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
54
54
|
.then(() => {
|
|
55
55
|
this.formatMessage(64, service, ["Bucket configured" + ' (Retention Policy)', Bucket], (0, aws_lib_1.formatDefaultRetention)(DefaultRetention), { ...Cloud.LOG_CLOUD_COMMAND });
|
|
56
56
|
})
|
|
57
|
-
.catch(
|
|
58
|
-
addLog(err);
|
|
59
|
-
});
|
|
57
|
+
.catch(addLog);
|
|
60
58
|
}
|
|
61
59
|
if (CORSConfiguration && Array.isArray(CORSConfiguration.CORSRules)) {
|
|
62
60
|
if (CORSConfiguration.CORSRules.length === 0) {
|
|
@@ -64,18 +62,14 @@ function upload(credential, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
64
62
|
.then(() => {
|
|
65
63
|
commandMessage('CORS', 'delete');
|
|
66
64
|
})
|
|
67
|
-
.catch(
|
|
68
|
-
addLog(err);
|
|
69
|
-
});
|
|
65
|
+
.catch(addLog);
|
|
70
66
|
}
|
|
71
67
|
else {
|
|
72
68
|
client.send(new AWS.PutBucketCorsCommand({ Bucket, CORSConfiguration, ExpectedBucketOwner }))
|
|
73
69
|
.then(() => {
|
|
74
70
|
commandMessage('CORS');
|
|
75
71
|
})
|
|
76
|
-
.catch(
|
|
77
|
-
addLog(err);
|
|
78
|
-
});
|
|
72
|
+
.catch(addLog);
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
if (LifecycleConfiguration && Array.isArray(LifecycleConfiguration.Rules)) {
|
|
@@ -93,16 +87,14 @@ function upload(credential, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
93
87
|
.then(() => {
|
|
94
88
|
commandMessage('Lifecycle');
|
|
95
89
|
})
|
|
96
|
-
.catch(
|
|
97
|
-
addLog(err);
|
|
98
|
-
});
|
|
90
|
+
.catch(addLog);
|
|
99
91
|
}
|
|
100
92
|
}
|
|
101
93
|
}
|
|
102
94
|
if (!overwrite) {
|
|
103
95
|
const current = filename;
|
|
104
96
|
const next = (0, util_1.generateFilename)(filename);
|
|
105
|
-
let i = 0, exists;
|
|
97
|
+
let i = 0, exists = false;
|
|
106
98
|
do {
|
|
107
99
|
if (i > 0) {
|
|
108
100
|
[filename, exists] = next(i);
|
|
@@ -114,7 +106,7 @@ function upload(credential, service = "aws-v3", sdk = "@aws-sdk/client-s3") {
|
|
|
114
106
|
.then(() => true)
|
|
115
107
|
.catch((err) => {
|
|
116
108
|
if (err instanceof Error && err.name !== 'NotFound') {
|
|
117
|
-
filename = (0,
|
|
109
|
+
filename = (0, node_crypto_1.randomUUID)() + path.extname(current);
|
|
118
110
|
return true;
|
|
119
111
|
}
|
|
120
112
|
return false;
|