@digipair/skill-s3 0.81.2 → 0.82.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/index.cjs.js CHANGED
@@ -2,23 +2,71 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index.cjs2.js');
6
- require('buffer');
7
- require('stream');
8
- require('node:stream');
9
- require('http');
10
- require('https');
11
- require('http2');
12
- require('zlib');
13
- require('os');
14
- require('path');
15
- require('crypto');
16
- require('fs');
17
- require('process');
5
+ var clientS3 = require('@aws-sdk/client-s3');
18
6
 
7
+ let S3Service = class S3Service {
8
+ getClient(config) {
9
+ return new clientS3.S3Client(config);
10
+ }
11
+ async upload(params, _pinsSettingsList, context) {
12
+ const { bucket, key, content, config = context.privates.S3_CONFIG } = params;
13
+ const client = this.getClient(config);
14
+ const match = content.match(/^data:(.*?);base64,/);
15
+ const contentType = match[1];
16
+ const command = new clientS3.PutObjectCommand({
17
+ Bucket: bucket,
18
+ Key: key,
19
+ Body: Buffer.from(content.replace(/^data:.*;base64,/, ''), 'base64'),
20
+ ContentType: contentType
21
+ });
22
+ return await client.send(command);
23
+ }
24
+ async download(params, _pinsSettingsList, context) {
25
+ const { bucket, key, range, config = context.privates.S3_CONFIG } = params;
26
+ const client = this.getClient(config);
27
+ const command = new clientS3.GetObjectCommand({
28
+ Bucket: bucket,
29
+ Key: key,
30
+ Range: range
31
+ });
32
+ const response = await client.send(command);
33
+ const stream = response.Body;
34
+ const chunks = [];
35
+ for await (const chunk of stream){
36
+ chunks.push(chunk);
37
+ }
38
+ const buffer = Buffer.concat(chunks);
39
+ const base64 = buffer.toString('base64');
40
+ return `data:${response.ContentType};base64,${base64}`;
41
+ }
42
+ async delete(params, _pinsSettingsList, context) {
43
+ const { bucket, key, config = context.privates.S3_CONFIG } = params;
44
+ const client = this.getClient(config);
45
+ const command = new clientS3.DeleteObjectCommand({
46
+ Bucket: bucket,
47
+ Key: key
48
+ });
49
+ await client.send(command);
50
+ return client.send(command);
51
+ }
52
+ async list(params, _pinsSettingsList, context) {
53
+ const { bucket, prefix = '', config = context.privates.S3_CONFIG } = params;
54
+ const client = this.getClient(config);
55
+ const command = new clientS3.ListObjectsV2Command({
56
+ Bucket: bucket,
57
+ Prefix: prefix
58
+ });
59
+ return await client.send(command);
60
+ }
61
+ };
62
+ // Export helpers
63
+ const service = new S3Service();
64
+ const upload = (params, pinsSettingsList, context)=>service.upload(params, pinsSettingsList, context);
65
+ const download = (params, pinsSettingsList, context)=>service.download(params, pinsSettingsList, context);
66
+ const remove = (params, pinsSettingsList, context)=>service.delete(params, pinsSettingsList, context);
67
+ const list = (params, pinsSettingsList, context)=>service.list(params, pinsSettingsList, context);
19
68
 
20
-
21
- exports.download = index.download;
22
- exports.list = index.list;
23
- exports.remove = index.remove;
24
- exports.upload = index.upload;
69
+ exports.download = download;
70
+ exports.list = list;
71
+ exports.remove = remove;
72
+ exports.upload = upload;
package/index.esm.js CHANGED
@@ -1,13 +1,65 @@
1
- export { aI as download, aK as list, aJ as remove, aH as upload } from './index.esm2.js';
2
- import 'buffer';
3
- import 'stream';
4
- import 'node:stream';
5
- import 'http';
6
- import 'https';
7
- import 'http2';
8
- import 'zlib';
9
- import 'os';
10
- import 'path';
11
- import 'crypto';
12
- import 'fs';
13
- import 'process';
1
+ import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
2
+
3
+ let S3Service = class S3Service {
4
+ getClient(config) {
5
+ return new S3Client(config);
6
+ }
7
+ async upload(params, _pinsSettingsList, context) {
8
+ const { bucket, key, content, config = context.privates.S3_CONFIG } = params;
9
+ const client = this.getClient(config);
10
+ const match = content.match(/^data:(.*?);base64,/);
11
+ const contentType = match[1];
12
+ const command = new PutObjectCommand({
13
+ Bucket: bucket,
14
+ Key: key,
15
+ Body: Buffer.from(content.replace(/^data:.*;base64,/, ''), 'base64'),
16
+ ContentType: contentType
17
+ });
18
+ return await client.send(command);
19
+ }
20
+ async download(params, _pinsSettingsList, context) {
21
+ const { bucket, key, range, config = context.privates.S3_CONFIG } = params;
22
+ const client = this.getClient(config);
23
+ const command = new GetObjectCommand({
24
+ Bucket: bucket,
25
+ Key: key,
26
+ Range: range
27
+ });
28
+ const response = await client.send(command);
29
+ const stream = response.Body;
30
+ const chunks = [];
31
+ for await (const chunk of stream){
32
+ chunks.push(chunk);
33
+ }
34
+ const buffer = Buffer.concat(chunks);
35
+ const base64 = buffer.toString('base64');
36
+ return `data:${response.ContentType};base64,${base64}`;
37
+ }
38
+ async delete(params, _pinsSettingsList, context) {
39
+ const { bucket, key, config = context.privates.S3_CONFIG } = params;
40
+ const client = this.getClient(config);
41
+ const command = new DeleteObjectCommand({
42
+ Bucket: bucket,
43
+ Key: key
44
+ });
45
+ await client.send(command);
46
+ return client.send(command);
47
+ }
48
+ async list(params, _pinsSettingsList, context) {
49
+ const { bucket, prefix = '', config = context.privates.S3_CONFIG } = params;
50
+ const client = this.getClient(config);
51
+ const command = new ListObjectsV2Command({
52
+ Bucket: bucket,
53
+ Prefix: prefix
54
+ });
55
+ return await client.send(command);
56
+ }
57
+ };
58
+ // Export helpers
59
+ const service = new S3Service();
60
+ const upload = (params, pinsSettingsList, context)=>service.upload(params, pinsSettingsList, context);
61
+ const download = (params, pinsSettingsList, context)=>service.download(params, pinsSettingsList, context);
62
+ const remove = (params, pinsSettingsList, context)=>service.delete(params, pinsSettingsList, context);
63
+ const list = (params, pinsSettingsList, context)=>service.list(params, pinsSettingsList, context);
64
+
65
+ export { download, list, remove, upload };
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@digipair/skill-s3",
3
- "version": "0.81.2",
3
+ "version": "0.82.0",
4
4
  "keywords": [
5
5
  "digipair",
6
6
  "service",
7
7
  "tool"
8
8
  ],
9
- "dependencies": {},
9
+ "dependencies": {
10
+ "@aws-sdk/client-s3": "^3.787.0"
11
+ },
10
12
  "main": "./index.cjs.js",
11
13
  "module": "./index.esm.js"
12
14
  }