@pi-r/aws-v3 0.2.8 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Mile Square Park
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
@@ -1,6 +1,6 @@
1
1
  # @pi-r/aws-v3
2
2
 
3
- PEP 402 - Forever
3
+ PEP 402 - Forever Aina
4
4
 
5
5
  ## LICENSE
6
6
 
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 () => {
@@ -160,11 +155,12 @@ exports.setBucketPolicy = setBucketPolicy;
160
155
  function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
161
156
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
162
157
  const WebsiteConfiguration = {};
163
- if ((0, types_1.isString)(options.indexPage)) {
164
- WebsiteConfiguration.IndexDocument = { Suffix: options.indexPage };
158
+ const { indexPage: Suffix, errorPage: Key } = options;
159
+ if ((0, types_1.isString)(Suffix)) {
160
+ WebsiteConfiguration.IndexDocument = { Suffix };
165
161
  }
166
- if ((0, types_1.isString)(options.errorPage)) {
167
- WebsiteConfiguration.ErrorDocument = { Key: options.errorPage };
162
+ if ((0, types_1.isString)(Key)) {
163
+ WebsiteConfiguration.ErrorDocument = { Key };
168
164
  }
169
165
  return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
170
166
  .then(() => {
@@ -194,8 +190,9 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
194
190
  }
195
191
  return client.send(new AWS.DeleteObjectsCommand({ Bucket, Delete: { Objects } }))
196
192
  .then(data => {
197
- if ((0, types_1.isArray)(data.Deleted)) {
198
- const files = data.Deleted.length + ' files';
193
+ const Deleted = data.Deleted;
194
+ if ((0, types_1.isArray)(Deleted)) {
195
+ const files = Deleted.length + ' files';
199
196
  this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
200
197
  }
201
198
  })
@@ -254,9 +251,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
254
251
  if (update) {
255
252
  await db.send(new AWS.UpdateCommand({ ...command, ...update }));
256
253
  }
257
- const output = await db.send(new AWS.GetCommand(command));
258
- if (output.Item) {
259
- rows = [output.Item];
254
+ const Item = (await db.send(new AWS.GetCommand(command))).Item;
255
+ if (Item) {
256
+ rows = [Item];
260
257
  }
261
258
  }
262
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("@pi-r/aws-v3");
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("@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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.2.8",
3
+ "version": "0.3.2",
4
4
  "description": "AWS V3 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.5.4",
24
- "@e-mc/module": "^0.5.4",
25
- "@e-mc/types": "^0.5.4",
26
- "@pi-r/aws": "^0.2.8",
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
27
  "@aws-sdk/client-dynamodb": "^3.525.0",
28
28
  "@aws-sdk/client-s3": "^3.525.0",
29
29
  "@aws-sdk/lib-dynamodb": "^3.525.0"
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("@pi-r/aws-v3");
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("@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') {