@pi-r/aws-v3 0.5.0 → 0.5.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 An Pham
1
+ Copyright 2023 Wit Studio
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,5 +1,7 @@
1
- ### @pi-r/aws-v3
1
+ # @pi-r/aws-v3
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Vivy
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -23,16 +23,16 @@ function setCannedAcl(S3, client, Bucket, ACL, service = 'aws-v3', recursive) {
23
23
  }
24
24
  return client.send(new S3.PutBucketPolicyCommand({ Bucket, Policy }))
25
25
  .then(() => {
26
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
26
+ this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
27
27
  })
28
28
  .catch((err) => {
29
29
  if (!recursive && err instanceof Error) {
30
30
  if (err.name === 'OperationAborted') {
31
- setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000 /* TIME.m */);
32
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
31
+ setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000);
32
+ this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
33
33
  }
34
34
  else {
35
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
35
+ this.formatMessage(64, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
36
36
  }
37
37
  }
38
38
  });
@@ -112,7 +112,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
112
112
  }
113
113
  return client.send(new AWS.CreateBucketCommand(input))
114
114
  .then(async () => {
115
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* VAL_CLOUD.CREATE_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
115
+ this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
116
116
  if (ACL) {
117
117
  await setCannedAcl.call(this, AWS, client, Bucket, ACL, service);
118
118
  }
@@ -127,7 +127,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
127
127
  }
128
128
  return true;
129
129
  default:
130
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
130
+ this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
131
131
  return false;
132
132
  }
133
133
  });
@@ -141,12 +141,12 @@ function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aw
141
141
  options.Bucket = Bucket;
142
142
  return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
143
143
  .then(() => {
144
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [block ? "Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ : policy ? "Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */ : "Bucket ACL configured" /* VAL_CLOUD.ACL_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
144
+ this.formatMessage(64, service, [block ? "Bucket configured" : policy ? "Bucket policy configured" : "Bucket ACL configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
145
145
  return true;
146
146
  })
147
147
  .catch(err => {
148
148
  if (!isNoSuchBucket(err)) {
149
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
149
+ this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
150
150
  }
151
151
  return false;
152
152
  });
@@ -164,12 +164,12 @@ function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'a
164
164
  }
165
165
  return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
166
166
  .then(() => {
167
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
167
+ this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
168
168
  return true;
169
169
  })
170
170
  .catch(err => {
171
171
  if (!isNoSuchBucket(err)) {
172
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
172
+ this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
173
173
  }
174
174
  return false;
175
175
  });
@@ -193,17 +193,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
193
193
  const Deleted = data.Deleted;
194
194
  if ((0, types_1.isArray)(Deleted)) {
195
195
  const files = Deleted.length + ' files';
196
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
196
+ this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
197
197
  }
198
198
  })
199
199
  .catch(err => {
200
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
200
+ this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
201
201
  });
202
202
  }
203
203
  })
204
204
  .catch(err => {
205
205
  if (!isNoSuchBucket(err)) {
206
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
206
+ this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
207
207
  }
208
208
  });
209
209
  }
@@ -225,7 +225,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
225
225
  const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
226
226
  if (!table) {
227
227
  closeClient();
228
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
228
+ throw (0, util_1.formatError)(item, "Missing database table");
229
229
  }
230
230
  (0, aws_1.setDatabaseEndpoint)(credential);
231
231
  const renewCache = ignoreCache === 0;
@@ -273,7 +273,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
273
273
  }
274
274
  else {
275
275
  closeClient();
276
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
276
+ throw (0, util_1.formatError)(item, "Missing database query");
277
277
  }
278
278
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
279
279
  }
package/download/index.js CHANGED
@@ -4,7 +4,7 @@ const util_1 = require("@e-mc/cloud/util");
4
4
  const types_1 = require("@e-mc/types");
5
5
  const Module = require("@e-mc/module");
6
6
  const Cloud = require("@e-mc/cloud");
7
- const client_1 = require("../client");
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) => {
@@ -25,12 +25,16 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
25
25
  input = Object.assign(deleteObject, input);
26
26
  }
27
27
  client.send(new AWS.DeleteObjectCommand(input))
28
- .then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE }))
29
- .catch(err => this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
28
+ .then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
29
+ .catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
30
30
  }
31
31
  })
32
32
  .catch(err => callback(err));
33
33
  };
34
34
  }
35
+ exports.default = download;
35
36
 
36
- module.exports = download;
37
+ if (exports.default) {
38
+ module.exports = exports.default;
39
+ module.exports.default = exports.default;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "AWS V3 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/cloud/aws-v3"
13
13
  },
14
14
  "keywords": [
@@ -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.0",
24
- "@e-mc/module": "^0.7.0",
25
- "@e-mc/types": "^0.7.0",
26
- "@pi-r/aws": "^0.5.0",
27
- "@aws-sdk/client-dynamodb": "^3.468.0",
28
- "@aws-sdk/client-s3": "^3.468.0",
29
- "@aws-sdk/lib-dynamodb": "^3.468.0"
23
+ "@e-mc/cloud": "^0.7.2",
24
+ "@e-mc/module": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "@pi-r/aws": "^0.5.2",
27
+ "@aws-sdk/client-dynamodb": "^3.525.0",
28
+ "@aws-sdk/client-s3": "^3.525.0",
29
+ "@aws-sdk/lib-dynamodb": "^3.525.0"
30
30
  }
31
31
  }
package/upload/index.js CHANGED
@@ -8,7 +8,7 @@ const aws_1 = require("@pi-r/aws");
8
8
  const types_1 = require("@e-mc/types");
9
9
  const Module = require("@e-mc/module");
10
10
  const Cloud = require("@e-mc/cloud");
11
- const client_1 = require("../client");
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') {
@@ -70,7 +70,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
70
70
  });
71
71
  } while (exists && ++i);
72
72
  if (i > 0) {
73
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
73
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
74
74
  }
75
75
  }
76
76
  if (pathname) {
@@ -148,7 +148,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
148
148
  }
149
149
  client.send(new AWS.PutObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner, Tagging: { TagSet }, RequestPayer: params.RequestPayer }), error => {
150
150
  if (!error) {
151
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
151
+ this.formatMessage(64, service, ["Tags created", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
152
152
  }
153
153
  else {
154
154
  addLog(error);
@@ -158,7 +158,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
158
158
  else if (tags === false) {
159
159
  client.send(new AWS.DeleteObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }), error => {
160
160
  if (!error) {
161
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
161
+ this.formatMessage(64, service, ["Tags deleted", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
162
162
  }
163
163
  else {
164
164
  addLog(error);
@@ -168,7 +168,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
168
168
  cleanup();
169
169
  callback(null, url);
170
170
  }
171
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
171
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
172
172
  })
173
173
  .catch(err => {
174
174
  if (first) {
@@ -181,5 +181,9 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
181
181
  }
182
182
  };
183
183
  }
184
+ exports.default = upload;
184
185
 
185
- module.exports = upload;
186
+ if (exports.default) {
187
+ module.exports = exports.default;
188
+ module.exports.default = exports.default;
189
+ }