@pi-r/aws-v3 0.3.6 → 0.3.7
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/client/index.js +19 -22
- package/download/index.js +1 -1
- package/package.json +2 -2
- package/upload/index.js +1 -1
package/client/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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
|
+
const Lib = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const Client = require("@aws-sdk/client-dynamodb");
|
|
4
6
|
const aws_1 = require("@pi-r/aws");
|
|
5
7
|
const util_1 = require("@e-mc/cloud/util");
|
|
6
8
|
const types_1 = require("@e-mc/types");
|
|
@@ -71,22 +73,15 @@ function createStorageClient(credential, service = 'aws-v3', sdk = '@aws-sdk/cli
|
|
|
71
73
|
}
|
|
72
74
|
exports.createStorageClient = createStorageClient;
|
|
73
75
|
function createDatabaseClient(credential) {
|
|
74
|
-
|
|
75
|
-
const AWS = require('@aws-sdk/lib-dynamodb');
|
|
76
|
-
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
|
|
77
|
-
return [AWS.DynamoDBDocumentClient.from(new DynamoDBClient(credential), credential.translateConfig), AWS];
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
this.checkPackage(err, '@aws-sdk', { passThrough: true });
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
76
|
+
return [Lib.DynamoDBDocumentClient.from(new Client.DynamoDBClient(credential), credential.translateConfig), Lib];
|
|
83
77
|
}
|
|
84
78
|
exports.createDatabaseClient = createDatabaseClient;
|
|
85
79
|
function validateStorage(credential) {
|
|
86
80
|
const credentials = sanitizeCredentials(credential);
|
|
87
|
-
|
|
81
|
+
const profile = credential.profile;
|
|
82
|
+
if (profile || !credentials && process.env.AWS_SDK_LOAD_CONFIG === '1') {
|
|
88
83
|
const { fromIni } = require('@aws-sdk/credential-provider-ini');
|
|
89
|
-
credential.credentials = fromIni({ profile
|
|
84
|
+
credential.credentials = fromIni({ profile });
|
|
90
85
|
return true;
|
|
91
86
|
}
|
|
92
87
|
return !!credentials && (typeof credentials === 'function' || (0, aws_1.isAccessDefined)(credentials) || (0, aws_1.isEnvDefined)());
|
|
@@ -113,8 +108,8 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
|
|
|
113
108
|
.catch(() => {
|
|
114
109
|
const input = { ...options, Bucket };
|
|
115
110
|
const region = credential.region;
|
|
116
|
-
if (
|
|
117
|
-
input.CreateBucketConfiguration = { LocationConstraint: region };
|
|
111
|
+
if (typeof region === 'string' && region !== 'us-east-1') {
|
|
112
|
+
input.CreateBucketConfiguration || (input.CreateBucketConfiguration = { LocationConstraint: region });
|
|
118
113
|
}
|
|
119
114
|
return client.send(new AWS.CreateBucketCommand(input))
|
|
120
115
|
.then(async () => {
|
|
@@ -161,11 +156,12 @@ exports.setBucketPolicy = setBucketPolicy;
|
|
|
161
156
|
function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
162
157
|
const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
|
|
163
158
|
const WebsiteConfiguration = {};
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
const { indexPage: Suffix, errorPage: Key } = options;
|
|
160
|
+
if ((0, types_1.isString)(Suffix)) {
|
|
161
|
+
WebsiteConfiguration.IndexDocument = { Suffix };
|
|
166
162
|
}
|
|
167
|
-
if ((0, types_1.isString)(
|
|
168
|
-
WebsiteConfiguration.ErrorDocument = { Key
|
|
163
|
+
if ((0, types_1.isString)(Key)) {
|
|
164
|
+
WebsiteConfiguration.ErrorDocument = { Key };
|
|
169
165
|
}
|
|
170
166
|
return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
|
|
171
167
|
.then(() => {
|
|
@@ -195,8 +191,9 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
195
191
|
}
|
|
196
192
|
return client.send(new AWS.DeleteObjectsCommand({ Bucket, Delete: { Objects } }))
|
|
197
193
|
.then(data => {
|
|
198
|
-
|
|
199
|
-
|
|
194
|
+
const Deleted = data.Deleted;
|
|
195
|
+
if ((0, types_1.isArray)(Deleted)) {
|
|
196
|
+
const files = Deleted.length + ' files';
|
|
200
197
|
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
201
198
|
}
|
|
202
199
|
})
|
|
@@ -255,9 +252,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
255
252
|
if (update) {
|
|
256
253
|
await db.send(new AWS.UpdateCommand({ ...command, ...update }));
|
|
257
254
|
}
|
|
258
|
-
const
|
|
259
|
-
if (
|
|
260
|
-
rows = [
|
|
255
|
+
const Item = (await db.send(new AWS.GetCommand(command))).Item;
|
|
256
|
+
if (Item) {
|
|
257
|
+
rows = [Item];
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
260
|
else if ((0, types_1.isPlainObject)(query)) {
|
package/download/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const client_1 = require("@pi-r/aws-v3");
|
|
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");
|
|
6
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
7
7
|
function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|
|
8
8
|
const [client, AWS] = client_1.createStorageClient.call(this, config, service, sdk);
|
|
9
9
|
return (data, callback) => {
|
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.7",
|
|
4
4
|
"description": "AWS V3 cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@e-mc/cloud": "^0.6.16",
|
|
24
24
|
"@e-mc/module": "^0.6.16",
|
|
25
25
|
"@e-mc/types": "^0.6.16",
|
|
26
|
-
"@pi-r/aws": "^0.3.
|
|
26
|
+
"@pi-r/aws": "^0.3.7",
|
|
27
27
|
"@aws-sdk/client-dynamodb": "^3.614.0",
|
|
28
28
|
"@aws-sdk/client-s3": "^3.614.0",
|
|
29
29
|
"@aws-sdk/lib-dynamodb": "^3.614.0"
|
package/upload/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const stream = require("stream");
|
|
5
|
-
const client_1 = require("@pi-r/aws-v3");
|
|
6
5
|
const util_1 = require("@e-mc/cloud/util");
|
|
7
6
|
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");
|
|
10
|
+
const client_1 = require("@pi-r/aws-v3");
|
|
11
11
|
const BUCKET_SESSION = new Set();
|
|
12
12
|
const BUCKET_RESPONSE = {};
|
|
13
13
|
function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
|