@pi-r/aws-v3 0.5.3 → 0.5.5

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 Haruhi Suzumiya
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/client/index.js CHANGED
@@ -56,9 +56,10 @@ function sanitizeCredentials(credential) {
56
56
  }
57
57
  const isNoSuchBucket = (err) => err instanceof Error && err.name === 'NoSuchBucket';
58
58
  function createStorageClient(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
59
+ var _a;
59
60
  try {
60
61
  sanitizeCredentials(credential);
61
- const expiration = credential.credentials?.expiration;
62
+ const expiration = (_a = credential.credentials) === null || _a === void 0 ? void 0 : _a.expiration;
62
63
  if (expiration && !(expiration instanceof Date)) {
63
64
  delete credential.expiration;
64
65
  }
@@ -183,7 +184,7 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
183
184
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
184
185
  return client.send(new AWS.ListObjectsCommand({ Bucket }))
185
186
  .then(({ Contents }) => {
186
- if (Contents?.length) {
187
+ if (Contents === null || Contents === void 0 ? void 0 : Contents.length) {
187
188
  let Objects = Contents.map(data => ({ Key: data.Key }));
188
189
  if (!recursive) {
189
190
  Objects = Objects.filter(value => value.Key.indexOf('/') === -1);
@@ -219,7 +220,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
219
220
  const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
220
221
  let client;
221
222
  const createClient = () => client || (client = createDatabaseClient.call(this, length === 1 ? credential : { ...credential }));
222
- const closeClient = () => client?.[0].destroy();
223
+ const closeClient = () => client === null || client === void 0 ? void 0 : client[0].destroy();
223
224
  for (let i = 0; i < length; ++i) {
224
225
  const item = batch[i];
225
226
  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.5.3",
3
+ "version": "0.5.5",
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.7.3",
24
- "@e-mc/module": "^0.7.3",
25
- "@e-mc/types": "^0.7.3",
26
- "@pi-r/aws": "^0.5.3",
27
- "@aws-sdk/client-dynamodb": "^3.540.0",
28
- "@aws-sdk/client-s3": "^3.540.0",
29
- "@aws-sdk/lib-dynamodb": "^3.540.0"
23
+ "@e-mc/cloud": "^0.7.10",
24
+ "@e-mc/module": "^0.7.10",
25
+ "@e-mc/types": "^0.7.10",
26
+ "@pi-r/aws": "^0.5.5",
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
30
  }
31
31
  }
package/upload/index.js CHANGED
@@ -32,16 +32,16 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
32
32
  const configBucket = admin.configBucket;
33
33
  if (!BUCKET_SESSION.has(service + Bucket)) {
34
34
  const bucketAcl = admin.publicRead ? 'public-read' : admin.acl;
35
- 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, configBucket?.create, service, sdk));
35
+ 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, configBucket === null || configBucket === void 0 ? void 0 : configBucket.create, service, sdk));
36
36
  if (!await response) {
37
37
  errorResponse(null);
38
38
  return;
39
39
  }
40
40
  BUCKET_SESSION.add(service + Bucket);
41
41
  }
42
- const DefaultRetention = configBucket?.retentionPolicy;
42
+ const DefaultRetention = configBucket === null || configBucket === void 0 ? void 0 : configBucket.retentionPolicy;
43
43
  if ((0, types_1.isPlainObject)(DefaultRetention)) {
44
- client.send(new AWS.PutObjectLockConfigurationCommand({ Bucket, ObjectLockConfiguration: { ObjectLockEnabled: 'Enabled', Rule: { DefaultRetention } }, ExpectedBucketOwner: options?.ExpectedBucketOwner, RequestPayer: options?.RequestPayer }))
44
+ client.send(new AWS.PutObjectLockConfigurationCommand({ Bucket, ObjectLockConfiguration: { ObjectLockEnabled: 'Enabled', Rule: { DefaultRetention } }, ExpectedBucketOwner: options === null || options === void 0 ? void 0 : options.ExpectedBucketOwner, RequestPayer: options === null || options === void 0 ? void 0 : options.RequestPayer }))
45
45
  .then(() => {
46
46
  aws_1.writeMessageDefaultRetention.call(this, Bucket, DefaultRetention, service);
47
47
  })
package/types/index.d.ts DELETED
@@ -1,41 +0,0 @@
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>;