@pi-r/aws-v3 0.3.0 → 0.5.0

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/download/index.js CHANGED
@@ -16,9 +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
- // @ts-ignore
20
- client
21
- .send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
19
+ client.send(new AWS.GetObjectCommand(input), { abortSignal: this.signal })
22
20
  .then(result => {
23
21
  (0, util_1.readableAsBuffer)(result.Body).then(buffer => callback(null, buffer)).catch(err => callback(err));
24
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.0",
3
+ "version": "0.5.0",
4
4
  "description": "AWS V3 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -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.6.0",
24
- "@e-mc/module": "^0.6.0",
25
- "@e-mc/types": "^0.6.0",
26
- "@pi-r/aws": "^0.3.0",
27
- "@aws-sdk/client-dynamodb": "^3.385.0",
28
- "@aws-sdk/client-s3": "^3.385.0",
29
- "@aws-sdk/lib-dynamodb": "^3.385.0"
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"
30
30
  }
31
31
  }
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 {
@@ -128,11 +137,34 @@ function upload(credential, service = 'aws-v3', sdk = '@aws-sdk/client-s3') {
128
137
  }
129
138
  continue;
130
139
  }
131
- // @ts-ignore
132
140
  client.send(new AWS.PutObjectCommand(params), { abortSignal: this.signal })
133
141
  .then(() => {
134
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);
135
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 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, 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 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], params.Key, { ...Cloud.LOG_CLOUD_COMMAND });
162
+ }
163
+ else {
164
+ addLog(error);
165
+ }
166
+ });
167
+ }
136
168
  cleanup();
137
169
  callback(null, url);
138
170
  }