@pi-r/aws-v3 0.2.2 → 0.3.0

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 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");
@@ -70,22 +72,15 @@ function createStorageClient(credential, service = 'aws-v3', sdk = '@aws-sdk/cli
70
72
  }
71
73
  exports.createStorageClient = createStorageClient;
72
74
  function createDatabaseClient(credential) {
73
- try {
74
- const AWS = require('@aws-sdk/lib-dynamodb');
75
- const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
76
- return [AWS.DynamoDBDocumentClient.from(new DynamoDBClient(credential), credential.translateConfig), AWS];
77
- }
78
- catch (err) {
79
- this.checkPackage(err, '@aws-sdk', { passThrough: true });
80
- throw err;
81
- }
75
+ return [Lib.DynamoDBDocumentClient.from(new Client.DynamoDBClient(credential), credential.translateConfig), Lib];
82
76
  }
83
77
  exports.createDatabaseClient = createDatabaseClient;
84
78
  function validateStorage(credential) {
85
79
  const credentials = sanitizeCredentials(credential);
86
- if (credential.profile || !credentials && process.env.AWS_SDK_LOAD_CONFIG === '1') {
80
+ const profile = credential.profile;
81
+ if (profile || !credentials && process.env.AWS_SDK_LOAD_CONFIG === '1') {
87
82
  const { fromIni } = require('@aws-sdk/credential-provider-ini');
88
- credential.credentials = fromIni({ profile: credential.profile });
83
+ credential.credentials = fromIni({ profile });
89
84
  return true;
90
85
  }
91
86
  return !!credentials && (typeof credentials === 'function' || (0, aws_1.isAccessDefined)(credentials) || (0, aws_1.isEnvDefined)());
@@ -112,8 +107,8 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
112
107
  .catch(() => {
113
108
  const input = { ...options, Bucket };
114
109
  const region = credential.region;
115
- if (!input.CreateBucketConfiguration && typeof region === 'string' && region !== 'us-east-1') {
116
- input.CreateBucketConfiguration = { LocationConstraint: region };
110
+ if (typeof region === 'string' && region !== 'us-east-1') {
111
+ input.CreateBucketConfiguration || (input.CreateBucketConfiguration = { LocationConstraint: region });
117
112
  }
118
113
  return client.send(new AWS.CreateBucketCommand(input))
119
114
  .then(async () => {
@@ -141,11 +136,12 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
141
136
  exports.createBucketV2 = createBucketV2;
142
137
  function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
143
138
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
144
- const policy = 'Policy' in options && !('ACL' in options);
139
+ const block = 'PublicAccessBlockConfiguration' in options;
140
+ const policy = !block && 'Policy' in options && !('ACL' in options);
145
141
  options.Bucket = Bucket;
146
- return (policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
142
+ return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
147
143
  .then(() => {
148
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [policy ? "Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */ : "Bucket ACL configured" /* VAL_CLOUD.ACL_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
144
+ this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [block ? "Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ : policy ? "Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */ : "Bucket ACL configured" /* VAL_CLOUD.ACL_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
149
145
  return true;
150
146
  })
151
147
  .catch(err => {
@@ -159,11 +155,12 @@ exports.setBucketPolicy = setBucketPolicy;
159
155
  function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
160
156
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
161
157
  const WebsiteConfiguration = {};
162
- if ((0, types_1.isString)(options.indexPage)) {
163
- WebsiteConfiguration.IndexDocument = { Suffix: options.indexPage };
158
+ const { indexPage: Suffix, errorPage: Key } = options;
159
+ if ((0, types_1.isString)(Suffix)) {
160
+ WebsiteConfiguration.IndexDocument = { Suffix };
164
161
  }
165
- if ((0, types_1.isString)(options.errorPage)) {
166
- WebsiteConfiguration.ErrorDocument = { Key: options.errorPage };
162
+ if ((0, types_1.isString)(Key)) {
163
+ WebsiteConfiguration.ErrorDocument = { Key };
167
164
  }
168
165
  return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
169
166
  .then(() => {
@@ -193,8 +190,9 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
193
190
  }
194
191
  return client.send(new AWS.DeleteObjectsCommand({ Bucket, Delete: { Objects } }))
195
192
  .then(data => {
196
- if ((0, types_1.isArray)(data.Deleted)) {
197
- const files = data.Deleted.length + ' files';
193
+ const Deleted = data.Deleted;
194
+ if ((0, types_1.isArray)(Deleted)) {
195
+ const files = Deleted.length + ' files';
198
196
  this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
199
197
  }
200
198
  })
@@ -253,9 +251,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
253
251
  if (update) {
254
252
  await db.send(new AWS.UpdateCommand({ ...command, ...update }));
255
253
  }
256
- const output = await db.send(new AWS.GetCommand(command));
257
- if (output.Item) {
258
- rows = [output.Item];
254
+ const Item = (await db.send(new AWS.GetCommand(command))).Item;
255
+ if (Item) {
256
+ rows = [Item];
259
257
  }
260
258
  }
261
259
  else if ((0, types_1.isPlainObject)(query)) {
package/download/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../client");
4
3
  const util_1 = require("@e-mc/cloud/util");
5
4
  const types_1 = require("@e-mc/types");
6
5
  const Module = require("@e-mc/module");
7
6
  const Cloud = require("@e-mc/cloud");
7
+ const client_1 = require("../client");
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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "AWS V3 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -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.5.3",
24
- "@e-mc/module": "^0.5.3",
25
- "@e-mc/types": "^0.5.3",
26
- "@pi-r/aws": "^0.2.2",
27
- "@aws-sdk/client-dynamodb": "^3.335.0",
28
- "@aws-sdk/client-s3": "^3.335.0",
29
- "@aws-sdk/lib-dynamodb": "^3.335.0"
23
+ "@e-mc/cloud": "^0.6.0",
24
+ "@e-mc/module": "^0.6.0",
25
+ "@e-mc/types": "^0.6.0",
26
+ "@pi-r/aws": "^0.3.0",
27
+ "@aws-sdk/client-dynamodb": "^3.385.0",
28
+ "@aws-sdk/client-s3": "^3.385.0",
29
+ "@aws-sdk/lib-dynamodb": "^3.385.0"
30
30
  }
31
31
  }
package/upload/index.js CHANGED
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const stream = require("stream");
6
- const client_1 = require("../client");
7
6
  const util_1 = require("@e-mc/cloud/util");
8
7
  const aws_1 = require("@pi-r/aws");
9
8
  const types_1 = require("@e-mc/types");
10
9
  const Module = require("@e-mc/module");
11
10
  const Cloud = require("@e-mc/cloud");
11
+ const client_1 = require("../client");
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') {