@pi-r/aws-v3 0.3.4 → 0.3.6

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,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
-
1
+ Copyright 2023 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
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
@@ -1,7 +1,5 @@
1
- # @pi-r/aws-v3
2
-
3
- PEP 402 - Forever
4
-
5
- ## LICENSE
6
-
1
+ # @pi-r/aws-v3
2
+
3
+ ## LICENSE
4
+
7
5
  MIT
package/client/index.js CHANGED
@@ -1,8 +1,6 @@
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");
6
4
  const aws_1 = require("@pi-r/aws");
7
5
  const util_1 = require("@e-mc/cloud/util");
8
6
  const types_1 = require("@e-mc/types");
@@ -73,15 +71,22 @@ function createStorageClient(credential, service = 'aws-v3', sdk = '@aws-sdk/cli
73
71
  }
74
72
  exports.createStorageClient = createStorageClient;
75
73
  function createDatabaseClient(credential) {
76
- return [Lib.DynamoDBDocumentClient.from(new Client.DynamoDBClient(credential), credential.translateConfig), Lib];
74
+ try {
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
+ }
77
83
  }
78
84
  exports.createDatabaseClient = createDatabaseClient;
79
85
  function validateStorage(credential) {
80
86
  const credentials = sanitizeCredentials(credential);
81
- const profile = credential.profile;
82
- if (profile || !credentials && process.env.AWS_SDK_LOAD_CONFIG === '1') {
87
+ if (credential.profile || !credentials && process.env.AWS_SDK_LOAD_CONFIG === '1') {
83
88
  const { fromIni } = require('@aws-sdk/credential-provider-ini');
84
- credential.credentials = fromIni({ profile });
89
+ credential.credentials = fromIni({ profile: credential.profile });
85
90
  return true;
86
91
  }
87
92
  return !!credentials && (typeof credentials === 'function' || (0, aws_1.isAccessDefined)(credentials) || (0, aws_1.isEnvDefined)());
@@ -108,8 +113,8 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
108
113
  .catch(() => {
109
114
  const input = { ...options, Bucket };
110
115
  const region = credential.region;
111
- if (typeof region === 'string' && region !== 'us-east-1') {
112
- input.CreateBucketConfiguration || (input.CreateBucketConfiguration = { LocationConstraint: region });
116
+ if (!input.CreateBucketConfiguration && typeof region === 'string' && region !== 'us-east-1') {
117
+ input.CreateBucketConfiguration = { LocationConstraint: region };
113
118
  }
114
119
  return client.send(new AWS.CreateBucketCommand(input))
115
120
  .then(async () => {
@@ -156,12 +161,11 @@ exports.setBucketPolicy = setBucketPolicy;
156
161
  function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
157
162
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
158
163
  const WebsiteConfiguration = {};
159
- const { indexPage: Suffix, errorPage: Key } = options;
160
- if ((0, types_1.isString)(Suffix)) {
161
- WebsiteConfiguration.IndexDocument = { Suffix };
164
+ if ((0, types_1.isString)(options.indexPage)) {
165
+ WebsiteConfiguration.IndexDocument = { Suffix: options.indexPage };
162
166
  }
163
- if ((0, types_1.isString)(Key)) {
164
- WebsiteConfiguration.ErrorDocument = { Key };
167
+ if ((0, types_1.isString)(options.errorPage)) {
168
+ WebsiteConfiguration.ErrorDocument = { Key: options.errorPage };
165
169
  }
166
170
  return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
167
171
  .then(() => {
@@ -191,9 +195,8 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
191
195
  }
192
196
  return client.send(new AWS.DeleteObjectsCommand({ Bucket, Delete: { Objects } }))
193
197
  .then(data => {
194
- const Deleted = data.Deleted;
195
- if ((0, types_1.isArray)(Deleted)) {
196
- const files = Deleted.length + ' files';
198
+ if ((0, types_1.isArray)(data.Deleted)) {
199
+ const files = data.Deleted.length + ' files';
197
200
  this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
198
201
  }
199
202
  })
@@ -252,9 +255,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
252
255
  if (update) {
253
256
  await db.send(new AWS.UpdateCommand({ ...command, ...update }));
254
257
  }
255
- const Item = (await db.send(new AWS.GetCommand(command))).Item;
256
- if (Item) {
257
- rows = [Item];
258
+ const output = await db.send(new AWS.GetCommand(command));
259
+ if (output.Item) {
260
+ rows = [output.Item];
258
261
  }
259
262
  }
260
263
  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");
2
3
  const util_1 = require("@e-mc/cloud/util");
3
4
  const types_1 = require("@e-mc/types");
4
5
  const Module = require("@e-mc/module");
5
6
  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,31 +1,31 @@
1
- {
2
- "name": "@pi-r/aws-v3",
3
- "version": "0.3.4",
4
- "description": "AWS V3 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
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
23
- "@e-mc/cloud": "^0.6.3",
24
- "@e-mc/module": "^0.6.3",
25
- "@e-mc/types": "^0.6.3",
26
- "@pi-r/aws": "^0.3.4",
27
- "@aws-sdk/client-dynamodb": "^3.540.0",
28
- "@aws-sdk/client-s3": "^3.540.0",
29
- "@aws-sdk/lib-dynamodb": "^3.540.0"
30
- }
31
- }
1
+ {
2
+ "name": "@pi-r/aws-v3",
3
+ "version": "0.3.6",
4
+ "description": "AWS V3 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
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "^0.6.16",
24
+ "@e-mc/module": "^0.6.16",
25
+ "@e-mc/types": "^0.6.16",
26
+ "@pi-r/aws": "^0.3.6",
27
+ "@aws-sdk/client-dynamodb": "^3.614.0",
28
+ "@aws-sdk/client-s3": "^3.614.0",
29
+ "@aws-sdk/lib-dynamodb": "^3.614.0"
30
+ }
31
+ }
@@ -0,0 +1,42 @@
1
+ import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
2
+
3
+ import type { AwsSdkSigV4AuthInputConfig } from '@aws-sdk/core';
4
+ import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput, TransactGetItemsCommandInput } from '@aws-sdk/client-dynamodb';
5
+ import type { BatchGetCommandInput, NativeAttributeValue, TranslateConfig, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
6
+ import type { S3ClientConfig } from '@aws-sdk/client-s3';
7
+ import type { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
8
+
9
+ export interface AWSBaseCredential extends Omit<AwsSdkSigV4AuthInputConfig, "credentials"> {
10
+ credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider;
11
+ provider?: {
12
+ http?: unknown;
13
+ ini?: unknown;
14
+ cognitoIdentity?: unknown;
15
+ cognitoIdentityPool?: unknown;
16
+ temporaryCredentials?: unknown;
17
+ webToken?: unknown;
18
+ containerMetadata?: unknown;
19
+ instanceMetadata?: unknown;
20
+ process?: unknown;
21
+ tokenFile?: unknown;
22
+ sso?: unknown;
23
+ env?: unknown;
24
+ nodeProviderChain?: unknown;
25
+ };
26
+ }
27
+
28
+ export type AWSStorage = CloudStorage<AWSStorageCredential, "aws-v3">;
29
+
30
+ export interface AWSStorageCredential extends S3ClientConfig, AWSBaseCredential {}
31
+
32
+ export interface AWSDatabaseQuery extends CloudDatabase<QueryCommandInput | ObjectMap<NativeAttributeValue>[] | string, PlainObject, UpdateCommandInput | string, BatchGetCommandInput | ScanCommandInput | TransactGetItemsCommandInput | NativeAttributeValue[]> {
33
+ source: "cloud";
34
+ service: "aws-v3";
35
+ key?: string | AttributeKey;
36
+ }
37
+
38
+ export interface AWSDatabaseCredential extends Omit<DynamoDBClientConfig, "credentials">, AWSBaseCredential {
39
+ translateConfig?: TranslateConfig;
40
+ }
41
+
42
+ export type AttributeKey = Record<string, NativeAttributeValue>;
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");
5
6
  const util_1 = require("@e-mc/cloud/util");
6
7
  const aws_1 = require("@pi-r/aws");
7
8
  const types_1 = require("@e-mc/types");
8
9
  const Module = require("@e-mc/module");
9
10
  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') {