@pi-r/aws-v3 0.2.9 → 0.2.11

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 2020-24 Code Geass
1
+ Copyright 2024 An Pham
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 Josee + Nunnally
3
+ PEP 402 - Forever
4
4
 
5
5
  ## LICENSE
6
6
 
package/client/index.js CHANGED
@@ -54,9 +54,10 @@ function sanitizeCredentials(credential) {
54
54
  }
55
55
  const isNoSuchBucket = (err) => err instanceof Error && err.name === 'NoSuchBucket';
56
56
  function createStorageClient(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
57
+ var _a;
57
58
  try {
58
59
  sanitizeCredentials(credential);
59
- const expiration = credential.credentials?.expiration;
60
+ const expiration = (_a = credential.credentials) === null || _a === void 0 ? void 0 : _a.expiration;
60
61
  if (expiration && !(expiration instanceof Date)) {
61
62
  delete credential.expiration;
62
63
  }
@@ -187,7 +188,7 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
187
188
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
188
189
  return client.send(new AWS.ListObjectsCommand({ Bucket }))
189
190
  .then(({ Contents }) => {
190
- if (Contents?.length) {
191
+ if (Contents === null || Contents === void 0 ? void 0 : Contents.length) {
191
192
  let Objects = Contents.map(data => ({ Key: data.Key }));
192
193
  if (!recursive) {
193
194
  Objects = Objects.filter(value => value.Key.indexOf('/') === -1);
@@ -222,7 +223,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
222
223
  const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
223
224
  let client;
224
225
  const createClient = () => client || (client = createDatabaseClient.call(this, length === 1 ? credential : { ...credential }));
225
- const closeClient = () => client?.[0].destroy();
226
+ const closeClient = () => client === null || client === void 0 ? void 0 : client[0].destroy();
226
227
  for (let i = 0; i < length; ++i) {
227
228
  const item = batch[i];
228
229
  const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
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.5",
24
- "@e-mc/module": "^0.5.5",
25
- "@e-mc/types": "^0.5.5",
26
- "@pi-r/aws": "^0.2.9",
23
+ "@e-mc/cloud": "^0.5.6",
24
+ "@e-mc/module": "^0.5.6",
25
+ "@e-mc/types": "^0.5.6",
26
+ "@pi-r/aws": "^0.2.11",
27
27
  "@aws-sdk/client-dynamodb": "^3.540.0",
28
28
  "@aws-sdk/client-s3": "^3.540.0",
29
29
  "@aws-sdk/lib-dynamodb": "^3.540.0"
@@ -0,0 +1,41 @@
1
+ import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
2
+
3
+ import type { AwsAuthInputConfig } from '@aws-sdk/middleware-signing';
4
+ import type { DynamoDBClientConfig, QueryCommandInput, ScanCommandInput } from '@aws-sdk/client-dynamodb';
5
+ import type { BatchGetCommandInput, TranslateConfig, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
6
+ import type { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
7
+ import type { S3ClientConfig } from '@aws-sdk/client-s3';
8
+
9
+ export interface AWSBaseCredential extends AwsAuthInputConfig {
10
+ provider?: {
11
+ http?: unknown;
12
+ ini?: unknown;
13
+ cognitoIdentity?: unknown;
14
+ cognitoIdentityPool?: unknown;
15
+ temporaryCredentials?: unknown;
16
+ webToken?: unknown;
17
+ containerMetadata?: unknown;
18
+ instanceMetadata?: unknown;
19
+ process?: unknown;
20
+ tokenFile?: unknown;
21
+ sso?: unknown;
22
+ env?: unknown;
23
+ nodeProviderChain?: unknown;
24
+ };
25
+ }
26
+
27
+ export type AWSStorage = CloudStorage<AWSStorageCredential, "aws-v3">;
28
+
29
+ export interface AWSStorageCredential extends S3ClientConfig, AWSBaseCredential {}
30
+
31
+ export interface AWSDatabaseQuery extends CloudDatabase<QueryCommandInput | ObjectMap<NativeAttributeValue>[], PlainObject, UpdateCommandInput, BatchGetCommandInput | ScanCommandInput> {
32
+ source: "cloud";
33
+ service: "aws-v3";
34
+ key?: string | AttributeKey;
35
+ }
36
+
37
+ export interface AWSDatabaseCredential extends Omit<DynamoDBClientConfig, "credentials">, AWSBaseCredential {
38
+ translateConfig?: TranslateConfig;
39
+ }
40
+
41
+ export type AttributeKey = Record<string, NativeAttributeValue>;
package/upload/index.js CHANGED
@@ -14,6 +14,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
14
14
  const [client, AWS] = client_1.createStorageClient.call(this, credential, service, sdk);
15
15
  return async (data, callback) => {
16
16
  var _a;
17
+ var _b;
17
18
  const { bucket: Bucket, localUri } = data;
18
19
  const { pathname = '', fileGroup, contentType, metadata, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
19
20
  let filename = data.upload.filename || path.basename(localUri), bucketKey;
@@ -30,7 +31,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
30
31
  };
31
32
  if (!BUCKET_SESSION.has(service + Bucket)) {
32
33
  const bucketAcl = admin.publicRead ? 'public-read' : admin.acl;
33
- const response = BUCKET_RESPONSE[_a = bucketKey = (0, aws_1.getBucketKey)(credential, Bucket, bucketAcl, service, sdk)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, Bucket, bucketAcl, admin.configBucket?.create, service, sdk));
34
+ const response = BUCKET_RESPONSE[_b = bucketKey = (0, aws_1.getBucketKey)(credential, Bucket, bucketAcl, service, sdk)] || (BUCKET_RESPONSE[_b] = client_1.createBucketV2.call(this, credential, Bucket, bucketAcl, (_a = admin.configBucket) === null || _a === void 0 ? void 0 : _a.create, service, sdk));
34
35
  if (!await response) {
35
36
  errorResponse(null);
36
37
  return;