@pi-r/aws-v3 0.2.1 → 0.2.8

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 Mile Square Park
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
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -21,16 +21,16 @@ function setCannedAcl(S3, client, Bucket, ACL, service = 'aws-v3', recursive) {
21
21
  }
22
22
  return client.send(new S3.PutBucketPolicyCommand({ Bucket, Policy }))
23
23
  .then(() => {
24
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
24
+ this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
25
25
  })
26
26
  .catch((err) => {
27
27
  if (!recursive && err instanceof Error) {
28
28
  if (err.name === 'OperationAborted') {
29
- setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000 /* TIME.m */);
30
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
29
+ setTimeout(() => setCannedAcl.call(this, S3, client, Bucket, ACL, service, true), 60000);
30
+ this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
31
31
  }
32
32
  else {
33
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
33
+ this.formatMessage(64, service, ['Unable to grant ' + ACL, err.Endpoint || Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
34
34
  }
35
35
  }
36
36
  });
@@ -117,7 +117,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
117
117
  }
118
118
  return client.send(new AWS.CreateBucketCommand(input))
119
119
  .then(async () => {
120
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* VAL_CLOUD.CREATE_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
120
+ this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
121
121
  if (ACL) {
122
122
  await setCannedAcl.call(this, AWS, client, Bucket, ACL, service);
123
123
  }
@@ -132,7 +132,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
132
132
  }
133
133
  return true;
134
134
  default:
135
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
135
+ this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
136
136
  return false;
137
137
  }
138
138
  });
@@ -141,16 +141,17 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws-v3', sd
141
141
  exports.createBucketV2 = createBucketV2;
142
142
  function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aws-sdk/clients/s3') {
143
143
  const [client, AWS] = createStorageClient.call(this, credential, service, sdk);
144
- const policy = 'Policy' in options && !('ACL' in options);
144
+ const block = 'PublicAccessBlockConfiguration' in options;
145
+ const policy = !block && 'Policy' in options && !('ACL' in options);
145
146
  options.Bucket = Bucket;
146
- return (policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
147
+ return (block ? client.send(new AWS.PutPublicAccessBlockCommand(options)) : policy ? client.send(new AWS.PutBucketPolicyCommand(options)) : client.send(new AWS.PutBucketAclCommand(options)))
147
148
  .then(() => {
148
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [policy ? "Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */ : "Bucket ACL configured" /* VAL_CLOUD.ACL_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
149
+ this.formatMessage(64, service, [block ? "Bucket configured" : policy ? "Bucket policy configured" : "Bucket ACL configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
149
150
  return true;
150
151
  })
151
152
  .catch(err => {
152
153
  if (!isNoSuchBucket(err)) {
153
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
154
+ this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
154
155
  }
155
156
  return false;
156
157
  });
@@ -167,12 +168,12 @@ function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'a
167
168
  }
168
169
  return client.send(new AWS.PutBucketWebsiteCommand({ Bucket, WebsiteConfiguration }))
169
170
  .then(() => {
170
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
171
+ this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
171
172
  return true;
172
173
  })
173
174
  .catch(err => {
174
175
  if (!isNoSuchBucket(err)) {
175
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
176
+ this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
176
177
  }
177
178
  return false;
178
179
  });
@@ -195,17 +196,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
195
196
  .then(data => {
196
197
  if ((0, types_1.isArray)(data.Deleted)) {
197
198
  const files = data.Deleted.length + ' files';
198
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
199
+ this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
199
200
  }
200
201
  })
201
202
  .catch(err => {
202
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
203
+ this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
203
204
  });
204
205
  }
205
206
  })
206
207
  .catch(err => {
207
208
  if (!isNoSuchBucket(err)) {
208
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
209
+ this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
209
210
  }
210
211
  });
211
212
  }
@@ -227,7 +228,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
227
228
  const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
228
229
  if (!table) {
229
230
  closeClient();
230
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
231
+ throw (0, util_1.formatError)(item, "Missing database table");
231
232
  }
232
233
  (0, aws_1.setDatabaseEndpoint)(credential);
233
234
  const renewCache = ignoreCache === 0;
@@ -275,7 +276,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
275
276
  }
276
277
  else {
277
278
  closeClient();
278
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
279
+ throw (0, util_1.formatError)(item, "Missing database query");
279
280
  }
280
281
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
281
282
  }
package/download/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../client");
3
+ const client_1 = require("@pi-r/aws-v3");
4
4
  const util_1 = require("@e-mc/cloud/util");
5
5
  const types_1 = require("@e-mc/types");
6
6
  const Module = require("@e-mc/module");
@@ -16,7 +16,6 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
16
16
  }
17
17
  const location = Module.joinPath(Bucket, Key);
18
18
  let input = { Bucket, Key, VersionId: target.versionId };
19
- // @ts-ignore
20
19
  client
21
20
  .send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
22
21
  .then(result => {
@@ -27,12 +26,16 @@ function download(config, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
27
26
  input = Object.assign(deleteObject, input);
28
27
  }
29
28
  client.send(new AWS.DeleteObjectCommand(input))
30
- .then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE }))
31
- .catch(err => this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
29
+ .then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
30
+ .catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
32
31
  }
33
32
  })
34
33
  .catch(err => callback(err));
35
34
  };
36
35
  }
36
+ exports.default = download;
37
37
 
38
- module.exports = download;
38
+ if (exports.default) {
39
+ module.exports = exports.default;
40
+ module.exports.default = exports.default;
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.2.1",
3
+ "version": "0.2.8",
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.5.2",
24
- "@e-mc/module": "^0.5.2",
25
- "@e-mc/types": "^0.5.2",
26
- "@pi-r/aws": "^0.2.1",
27
- "@aws-sdk/client-dynamodb": "^3.321.1",
28
- "@aws-sdk/client-s3": "^3.321.1",
29
- "@aws-sdk/lib-dynamodb": "^3.321.1"
23
+ "@e-mc/cloud": "^0.5.4",
24
+ "@e-mc/module": "^0.5.4",
25
+ "@e-mc/types": "^0.5.4",
26
+ "@pi-r/aws": "^0.2.8",
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
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const stream = require("stream");
6
- const client_1 = require("../client");
6
+ const client_1 = require("@pi-r/aws-v3");
7
7
  const util_1 = require("@e-mc/cloud/util");
8
8
  const aws_1 = require("@pi-r/aws");
9
9
  const types_1 = require("@e-mc/types");
@@ -60,7 +60,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
60
60
  });
61
61
  } while (exists && ++i);
62
62
  if (i > 0) {
63
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
63
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
64
64
  }
65
65
  }
66
66
  if (pathname) {
@@ -128,7 +128,6 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
128
128
  }
129
129
  continue;
130
130
  }
131
- // @ts-ignore
132
131
  client.send(new AWS.PutObjectCommand(params), { abortSignal: this.signal })
133
132
  .then(() => {
134
133
  const url = endpoint ? Module.joinPath(endpoint, objectKey) : Module.joinPath(`https://${Bucket}.s3.${!credential.region || credential.region === 'us-east-1' ? 'us-east-1.' : ''}amazonaws.com`, objectKey);
@@ -136,7 +135,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
136
135
  cleanup();
137
136
  callback(null, url);
138
137
  }
139
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
138
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
140
139
  })
141
140
  .catch(err => {
142
141
  if (first) {
@@ -149,5 +148,9 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
149
148
  }
150
149
  };
151
150
  }
151
+ exports.default = upload;
152
152
 
153
- module.exports = upload;
153
+ if (exports.default) {
154
+ module.exports = exports.default;
155
+ module.exports.default = exports.default;
156
+ }