@pi-r/aws-v3 0.3.2 → 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 Studio Trigger
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,6 +1,6 @@
1
1
  # @pi-r/aws-v3
2
2
 
3
- PEP 402 - Forever Aina
3
+ PEP 402 - Forever Vivy
4
4
 
5
5
  ## LICENSE
6
6
 
package/download/index.js CHANGED
@@ -16,8 +16,7 @@ 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
- client
20
- .send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
19
+ client.send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
21
20
  .then(result => {
22
21
  (0, util_1.readableAsBuffer)(result.Body).then(buffer => callback(null, buffer)).catch(err => callback(err));
23
22
  const deleteObject = target.deleteObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws-v3",
3
- "version": "0.3.2",
3
+ "version": "0.5.2",
4
4
  "description": "AWS V3 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.6.1",
24
- "@e-mc/module": "^0.6.1",
25
- "@e-mc/types": "^0.6.1",
26
- "@pi-r/aws": "^0.3.2",
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
27
  "@aws-sdk/client-dynamodb": "^3.525.0",
28
28
  "@aws-sdk/client-s3": "^3.525.0",
29
29
  "@aws-sdk/lib-dynamodb": "^3.525.0"
package/upload/index.js CHANGED
@@ -16,7 +16,7 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
16
16
  return async (data, callback) => {
17
17
  var _a;
18
18
  const { bucket: Bucket, localUri } = data;
19
- const { pathname = '', fileGroup, contentType, metadata, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
19
+ const { pathname = '', fileGroup, contentType, metadata, tags, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
20
20
  let filename = data.upload.filename || path.basename(localUri), bucketKey;
21
21
  const cleanup = () => {
22
22
  BUCKET_SESSION.delete(service + Bucket);
@@ -29,15 +29,25 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
29
29
  callback(err);
30
30
  return false;
31
31
  };
32
+ const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + Bucket);
33
+ const configBucket = admin.configBucket;
32
34
  if (!BUCKET_SESSION.has(service + Bucket)) {
33
35
  const bucketAcl = admin.publicRead ? 'public-read' : admin.acl;
34
- 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, admin.configBucket?.create, service, sdk));
36
+ 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
37
  if (!await response) {
36
38
  errorResponse(null);
37
39
  return;
38
40
  }
39
41
  BUCKET_SESSION.add(service + Bucket);
40
42
  }
43
+ const DefaultRetention = configBucket?.retentionPolicy;
44
+ if ((0, types_1.isPlainObject)(DefaultRetention)) {
45
+ client.send(new AWS.PutObjectLockConfigurationCommand({ Bucket, ObjectLockConfiguration: { ObjectLockEnabled: 'Enabled', Rule: { DefaultRetention } }, ExpectedBucketOwner: options?.ExpectedBucketOwner, RequestPayer: options?.RequestPayer }))
46
+ .then(() => {
47
+ aws_1.writeMessageDefaultRetention.call(this, Bucket, DefaultRetention, service);
48
+ })
49
+ .catch(err => addLog(err));
50
+ }
41
51
  if (!overwrite) {
42
52
  const current = filename;
43
53
  const next = (0, util_1.generateFilename)(filename);
@@ -69,7 +79,6 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
69
79
  const Key = [filename];
70
80
  const Body = [data.buffer];
71
81
  const ContentType = [contentType];
72
- const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + Bucket);
73
82
  if (fileGroup) {
74
83
  for (const [content, ext, localFile] of fileGroup) {
75
84
  try {
@@ -132,6 +141,30 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
132
141
  .then(() => {
133
142
  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);
134
143
  if (first) {
144
+ if ((0, types_1.isPlainObject)(tags)) {
145
+ const TagSet = [];
146
+ for (const name in tags) {
147
+ TagSet.push({ Key: name, Value: tags[name] });
148
+ }
149
+ client.send(new AWS.PutObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner, Tagging: { TagSet }, RequestPayer: params.RequestPayer }), error => {
150
+ if (!error) {
151
+ this.formatMessage(64, service, ["Tags created", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
152
+ }
153
+ else {
154
+ addLog(error);
155
+ }
156
+ });
157
+ }
158
+ else if (tags === false) {
159
+ client.send(new AWS.DeleteObjectTaggingCommand({ Bucket, Key: params.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }), error => {
160
+ if (!error) {
161
+ this.formatMessage(64, service, ["Tags deleted", Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
162
+ }
163
+ else {
164
+ addLog(error);
165
+ }
166
+ });
167
+ }
135
168
  cleanup();
136
169
  callback(null, url);
137
170
  }