@pi-r/aws 0.6.2 → 0.6.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 An Pham
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,7 +1,10 @@
1
- ### @pi-r/aws
1
+ # @pi-r/aws
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/cloud/aws.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/cloud/aws.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import type { ConfigurationOptions } from 'aws-sdk/lib/core';
8
8
  import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
9
9
  import type { AttributeValue, DocumentClient } from 'aws-sdk/clients/dynamodb';
10
10
  import type { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
11
- import type { CreateBucketRequest } from 'aws-sdk/clients/s3';
11
+ import type { CreateBucketRequest, DefaultRetention } from 'aws-sdk/clients/s3';
12
12
 
13
13
  declare namespace AWS {
14
14
  function isAccessDefined(credential: Pick<ConfigurationOptions, "accessKeyId" | "secretAccessKey" | "sessionToken">): boolean;
@@ -33,7 +33,7 @@ declare namespace AWS {
33
33
  function executeBatchQuery(this: ICloud, credential: AWSDatabaseCredential, batch: AWSDatabaseQuery[], sessionKey?: string): Promise<BatchQueryResult>;
34
34
  function setDatabaseEndpoint(config: ServiceConfigurationOptions | DynamoDBClientConfig): void;
35
35
  function checkBucketCannedACL(value: unknown): BucketCannedACL | undefined;
36
- function writeMessageDefaultRetention(this: IModule, bucket: string, retention: s3.DefaultRetention, service?: string): void;
36
+ function writeMessageDefaultRetention(this: IModule, bucket: string, retention: DefaultRetention, service?: string): void;
37
37
  function parseAttributeValue(value: unknown): AttributeValue;
38
38
  function getBucketKey(credential: unknown, Bucket: string, acl: string | undefined, service: string, sdk: string): string;
39
39
  function isNoSuchBucket(err: unknown): boolean;
package/client/index.js CHANGED
@@ -18,15 +18,15 @@ async function setCannedAcl(S3, Bucket, ACL, service = 'aws', recursive) {
18
18
  }
19
19
  const callback = (err) => {
20
20
  if (!err) {
21
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
21
+ this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
22
22
  }
23
23
  else if (!recursive) {
24
24
  if (err instanceof Error && err.code === 'OperationAborted') {
25
- setTimeout(async () => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000 /* TIME.m */);
26
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Grant ${ACL} (delayed)`, Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
25
+ setTimeout(async () => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000);
26
+ this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
27
27
  }
28
28
  else {
29
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Unable to grant ' + ACL, Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
29
+ this.formatMessage(64, service, ['Unable to grant ' + ACL, Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
30
30
  }
31
31
  }
32
32
  };
@@ -188,7 +188,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws',
188
188
  }
189
189
  return S3.createBucket(input).promise()
190
190
  .then(async () => {
191
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* VAL_CLOUD.CREATE_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
191
+ this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
192
192
  if (ACL) {
193
193
  await setCannedAcl.call(this, S3, Bucket, ACL, service);
194
194
  }
@@ -203,7 +203,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws',
203
203
  }
204
204
  return true;
205
205
  default:
206
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
206
+ this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
207
207
  return false;
208
208
  }
209
209
  });
@@ -220,12 +220,12 @@ async function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk
220
220
  }
221
221
  return ('PublicAccessBlockConfiguration' in options ? S3.putPublicAccessBlock(options) : 'Policy' in options && (0, types_1.isString)(options.Policy) && !ibm ? S3.putBucketPolicy(options) : S3.putBucketAcl(options)).promise()
222
222
  .then(() => {
223
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
223
+ this.formatMessage(64, service, ["Bucket policy configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
224
224
  return true;
225
225
  })
226
226
  .catch(err => {
227
227
  if (!(0, exports.isNoSuchBucket)(err)) {
228
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
228
+ this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
229
229
  }
230
230
  return false;
231
231
  });
@@ -243,12 +243,12 @@ async function setBucketWebsite(credential, Bucket, options, service = 'aws', sd
243
243
  }
244
244
  return S3.putBucketWebsite({ Bucket, WebsiteConfiguration }).promise()
245
245
  .then(() => {
246
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
246
+ this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
247
247
  return true;
248
248
  })
249
249
  .catch(err => {
250
250
  if (!(0, exports.isNoSuchBucket)(err)) {
251
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
251
+ this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
252
252
  }
253
253
  return false;
254
254
  });
@@ -272,17 +272,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
272
272
  const Deleted = data.Deleted;
273
273
  if ((0, types_1.isArray)(Deleted)) {
274
274
  const files = Deleted.length + ' files';
275
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
275
+ this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
276
276
  }
277
277
  })
278
278
  .catch(err => {
279
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
279
+ this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
280
280
  });
281
281
  }
282
282
  })
283
283
  .catch(err => {
284
284
  if (!(0, exports.isNoSuchBucket)(err)) {
285
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
285
+ this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
286
286
  }
287
287
  });
288
288
  }
@@ -314,7 +314,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
314
314
  let rows, queryString = '';
315
315
  if (key && (id || (0, types_1.isPlainObject)(key))) {
316
316
  if (!TableName) {
317
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
317
+ throw (0, util_1.formatError)(item, "Missing database table");
318
318
  }
319
319
  if (useCache) {
320
320
  queryString = TableName + '_' + Module.asString(key, true) + (id !== undefined ? '_' + Module.asString(id, true) : '');
@@ -323,7 +323,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
323
323
  continue;
324
324
  }
325
325
  }
326
- const Key = (0, types_1.isPlainObject)(key) ? key : { [key]: parseAttributeValue(id) };
326
+ const Key = (0, types_1.isPlainObject)(key) ? key : { [key]: id };
327
327
  const command = { TableName, Key };
328
328
  client = createClient();
329
329
  if (update) {
@@ -339,7 +339,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
339
339
  query.TableName = TableName;
340
340
  }
341
341
  if (!TableName) {
342
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
342
+ throw (0, util_1.formatError)(item, "Missing database table");
343
343
  }
344
344
  if (limit > 0) {
345
345
  query.Limit = limit;
@@ -360,9 +360,8 @@ async function executeBatchQuery(credential, batch, sessionKey) {
360
360
  }
361
361
  TableName || (TableName = Object.keys(params.RequestItems)[0]);
362
362
  if (!TableName) {
363
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
363
+ throw (0, util_1.formatError)(item, "Missing database table");
364
364
  }
365
- // @ts-ignore
366
365
  const Item = (_a = params.RequestItems)[TableName] || (_a[TableName] = {});
367
366
  Item.Keys = query;
368
367
  params = { RequestItems: { [TableName]: Item } };
@@ -393,7 +392,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
393
392
  }
394
393
  }
395
394
  else {
396
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
395
+ throw (0, util_1.formatError)(item, "Missing database query");
397
396
  }
398
397
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
399
398
  }
@@ -433,7 +432,7 @@ function writeMessageDefaultRetention(bucket, retention, service = 'aws') {
433
432
  if (Mode) {
434
433
  status.push(status.length ? `(${Mode})` : Mode);
435
434
  }
436
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (Retention Policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
435
+ this.formatMessage(64, service, ["Bucket configured" + ' (Retention Policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
437
436
  }
438
437
  exports.writeMessageDefaultRetention = writeMessageDefaultRetention;
439
438
  function parseAttributeValue(value) {
package/download/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const types_1 = require("@e-mc/types");
4
3
  const Module = require("@e-mc/module");
5
4
  const Cloud = require("@e-mc/cloud");
6
- const client_1 = require("../client");
5
+ const client_1 = require("@pi-r/aws");
7
6
  function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
8
7
  const s3 = client_1.createStorageClient.call(this, credential, service, sdk);
9
8
  return (data, callback) => {
@@ -22,10 +21,10 @@ function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
22
21
  if (deleteObject) {
23
22
  s3.deleteObject((0, types_1.isPlainObject)(deleteObject) ? Object.assign(deleteObject, params) : params, error => {
24
23
  if (!error) {
25
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE });
24
+ this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
26
25
  }
27
26
  else {
28
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], error, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
27
+ this.formatFail(64, service, ["Delete failed", location], error, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
29
28
  }
30
29
  });
31
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "AWS V2 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
13
  "directory": "src/cloud/aws"
14
14
  },
15
15
  "keywords": [
@@ -21,9 +21,9 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/cloud": "^0.8.2",
25
- "@e-mc/module": "^0.8.2",
26
- "@e-mc/types": "^0.8.2",
27
- "aws-sdk": "^2.1545.0"
24
+ "@e-mc/cloud": "^0.8.6",
25
+ "@e-mc/module": "^0.8.6",
26
+ "@e-mc/types": "^0.8.6",
27
+ "aws-sdk": "^2.1570.0"
28
28
  }
29
29
  }
package/types/index.d.ts CHANGED
@@ -3,12 +3,18 @@ import type { CloudDatabase } from '@e-mc/types/lib/cloud';
3
3
 
4
4
  import type { ConfigurationOptions } from 'aws-sdk/lib/core';
5
5
  import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
6
- import type { BatchGetItemInput, Key, QueryInput, ScanInput, UpdateItemInput } from 'aws-sdk/clients/dynamodb';
6
+ import type { DocumentClient } from 'aws-sdk/clients/dynamodb';
7
7
  import type { PutBucketAclRequest, PutBucketPolicyRequest, PutPublicAccessBlockRequest } from 'aws-sdk/clients/s3';
8
8
 
9
9
  export type BucketCannedACL = "authenticated-read" | "private" | "public-read" | "public-read-write";
10
10
  export type ObjectCannedACL = BucketCannedACL | "aws-exec-read" | "bucket-owner-full-control" | "bucket-owner-read";
11
11
  export type ConfigureBucketOptions = PutBucketAclRequest | PutBucketPolicyRequest | PutPublicAccessBlockRequest;
12
+ export type Key = DocumentClient.Key;
13
+ export type GetItemInput = DocumentClient.GetItemInput;
14
+ export type QueryInput = DocumentClient.QueryInput;
15
+ export type UpdateItemInput = DocumentClient.UpdateItemInput;
16
+ export type ScanInput = DocumentClient.ScanInput;
17
+ export type BatchGetItemInput = DocumentClient.BatchGetItemInput;
12
18
 
13
19
  export interface AWSStorageCredential extends ConfigurationOptions {
14
20
  profile?: string;
package/upload/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
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");
8
- const client_1 = require("../client");
7
+ const client_1 = require("@pi-r/aws");
9
8
  const BUCKET_SESSION = new Set();
10
9
  const BUCKET_RESPONSE = {};
11
10
  function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
@@ -70,7 +69,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
70
69
  });
71
70
  } while (exists && ++i);
72
71
  if (i > 0) {
73
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
72
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
74
73
  }
75
74
  }
76
75
  if (pathname) {
@@ -129,7 +128,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
129
128
  return;
130
129
  }
131
130
  const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
132
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
131
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
133
132
  if (!first) {
134
133
  return;
135
134
  }
@@ -142,7 +141,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
142
141
  }
143
142
  s3.putObjectTagging({ Bucket, Key: result.Key, Tagging: { TagSet }, ExpectedBucketOwner: params.ExpectedBucketOwner, RequestPayer: params.RequestPayer }, error => {
144
143
  if (!error) {
145
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
144
+ this.formatMessage(64, service, ["Tags created", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
146
145
  }
147
146
  else {
148
147
  addLog(error);
@@ -152,7 +151,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
152
151
  else if (tags === false || length === 0) {
153
152
  s3.deleteObjectTagging({ Bucket, Key: result.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }, error => {
154
153
  if (!error) {
155
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
154
+ this.formatMessage(64, service, ["Tags deleted", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
156
155
  }
157
156
  else {
158
157
  addLog(error);