@pi-r/aws 0.5.0 → 0.5.3

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 Haruhi Suzumiya
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
1
+ # @pi-r/aws
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
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(() => 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(() => 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
  };
@@ -180,7 +180,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws', sdk =
180
180
  }
181
181
  return S3.createBucket(input).promise()
182
182
  .then(async () => {
183
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* VAL_CLOUD.CREATE_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
183
+ this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
184
184
  if (ACL) {
185
185
  await setCannedAcl.call(this, S3, Bucket, ACL, service);
186
186
  }
@@ -195,7 +195,7 @@ function createBucketV2(credential, Bucket, ACL, options, service = 'aws', sdk =
195
195
  }
196
196
  return true;
197
197
  default:
198
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
198
+ this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
199
199
  return false;
200
200
  }
201
201
  });
@@ -212,12 +212,12 @@ function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk = 'aw
212
212
  }
213
213
  return ('PublicAccessBlockConfiguration' in options ? S3.putPublicAccessBlock(options) : 'Policy' in options && (0, types_1.isString)(options.Policy) && !ibm ? S3.putBucketPolicy(options) : S3.putBucketAcl(options)).promise()
214
214
  .then(() => {
215
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket policy configured" /* VAL_CLOUD.POLICY_BUCKET */, Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
215
+ this.formatMessage(64, service, ["Bucket policy configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
216
216
  return true;
217
217
  })
218
218
  .catch(err => {
219
219
  if (!(0, exports.isNoSuchBucket)(err)) {
220
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
220
+ this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
221
221
  }
222
222
  return false;
223
223
  });
@@ -235,12 +235,12 @@ function setBucketWebsite(credential, Bucket, options, service = 'aws', sdk = 'a
235
235
  }
236
236
  return S3.putBucketWebsite({ Bucket, WebsiteConfiguration }).promise()
237
237
  .then(() => {
238
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
238
+ this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
239
239
  return true;
240
240
  })
241
241
  .catch(err => {
242
242
  if (!(0, exports.isNoSuchBucket)(err)) {
243
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
243
+ this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
244
244
  }
245
245
  return false;
246
246
  });
@@ -264,17 +264,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
264
264
  const Deleted = data.Deleted;
265
265
  if ((0, types_1.isArray)(Deleted)) {
266
266
  const files = Deleted.length + ' files';
267
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
267
+ this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
268
268
  }
269
269
  })
270
270
  .catch(err => {
271
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
271
+ this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
272
272
  });
273
273
  }
274
274
  })
275
275
  .catch(err => {
276
276
  if (!(0, exports.isNoSuchBucket)(err)) {
277
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
277
+ this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
278
278
  }
279
279
  });
280
280
  }
@@ -297,7 +297,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
297
297
  const item = batch[i];
298
298
  const { service, table, id = '', query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
299
299
  if (!table) {
300
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
300
+ throw (0, util_1.formatError)(item, "Missing database table");
301
301
  }
302
302
  const renewCache = ignoreCache === 0;
303
303
  const getCache = (value) => {
@@ -342,7 +342,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
342
342
  }
343
343
  }
344
344
  else {
345
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
345
+ throw (0, util_1.formatError)(item, "Missing database query");
346
346
  }
347
347
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
348
348
  }
@@ -382,7 +382,7 @@ function writeMessageDefaultRetention(bucket, retention, service = 'aws') {
382
382
  if (Mode) {
383
383
  status.push(status.length ? `(${Mode})` : Mode);
384
384
  }
385
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (retention policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
385
+ this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
386
386
  }
387
387
  exports.writeMessageDefaultRetention = writeMessageDefaultRetention;
388
388
  const getBucketKey = (credential, Bucket, acl, service, sdk) => Module.asString(credential, true) + Bucket + '_' + (acl || '') + service + sdk;
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.5.0",
3
+ "version": "0.5.3",
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.7.0",
25
- "@e-mc/module": "^0.7.0",
26
- "@e-mc/types": "^0.7.0",
27
- "aws-sdk": "^2.1514.0"
24
+ "@e-mc/cloud": "^0.7.3",
25
+ "@e-mc/module": "^0.7.3",
26
+ "@e-mc/types": "^0.7.3",
27
+ "aws-sdk": "^2.1591.0"
28
28
  }
29
29
  }
package/upload/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const fs = require("fs");
5
4
  const util_1 = require("@e-mc/cloud/util");
6
5
  const types_1 = require("@e-mc/types");
7
6
  const Module = require("@e-mc/module");
8
7
  const Cloud = require("@e-mc/cloud");
9
- const client_1 = require("../client");
8
+ const client_1 = require("@pi-r/aws");
10
9
  const BUCKET_SESSION = new Set();
11
10
  const BUCKET_RESPONSE = {};
12
11
  function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
@@ -71,7 +70,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
71
70
  });
72
71
  } while (exists && ++i);
73
72
  if (i > 0) {
74
- 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 });
75
74
  }
76
75
  }
77
76
  if (pathname) {
@@ -127,7 +126,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
127
126
  s3.upload(params, (err, result) => {
128
127
  if (!err) {
129
128
  const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
130
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
129
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
131
130
  if (first) {
132
131
  if (service !== 'oci') {
133
132
  if ((0, types_1.isPlainObject)(tags)) {
@@ -137,7 +136,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
137
136
  }
138
137
  s3.putObjectTagging({ Bucket, Key: result.Key, Tagging: { TagSet }, ExpectedBucketOwner: params.ExpectedBucketOwner, RequestPayer: params.RequestPayer }, error => {
139
138
  if (!error) {
140
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
139
+ this.formatMessage(64, service, ["Tags created", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
141
140
  }
142
141
  else {
143
142
  addLog(error);
@@ -147,7 +146,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
147
146
  else if (tags === false) {
148
147
  s3.deleteObjectTagging({ Bucket, Key: result.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }, error => {
149
148
  if (!error) {
150
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
149
+ this.formatMessage(64, service, ["Tags deleted", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
151
150
  }
152
151
  else {
153
152
  addLog(error);