@8ms/helpers 2.4.9 → 2.4.11
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/dist/_class/BaseClass.cjs +31 -21
- package/dist/_class/BaseClass.mjs +31 -21
- package/dist/_class/BaseNamespace.cjs +10 -9
- package/dist/_class/BaseNamespace.mjs +10 -9
- package/dist/api/ApiResponseClass.cjs +96 -96
- package/dist/api/ApiResponseClass.mjs +96 -96
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.cjs +70 -60
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.mjs +70 -60
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.cjs +30 -28
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.mjs +30 -28
- package/dist/aws/ec2/server/AwsEc2Namespace.cjs +29 -32
- package/dist/aws/ec2/server/AwsEc2Namespace.mjs +29 -32
- package/dist/aws/ecs/server/AwsEcsNamespace.cjs +92 -78
- package/dist/aws/ecs/server/AwsEcsNamespace.mjs +92 -78
- package/dist/aws/glue/server/AwsGlueNamespace.cjs +17 -17
- package/dist/aws/glue/server/AwsGlueNamespace.mjs +17 -17
- package/dist/aws/lambda/server/AwsLambdaNamespace.cjs +33 -31
- package/dist/aws/lambda/server/AwsLambdaNamespace.mjs +33 -31
- package/dist/aws/s3/server/AwsS3Namespace.cjs +280 -265
- package/dist/aws/s3/server/AwsS3Namespace.mjs +280 -265
- package/dist/aws/ses/server/AwsSesNamespace.cjs +27 -30
- package/dist/aws/ses/server/AwsSesNamespace.mjs +27 -30
- package/dist/aws/ses/server/SimpleEmail.cjs +202 -199
- package/dist/aws/ses/server/SimpleEmail.mjs +202 -199
- package/dist/aws/sqs/server/AwsSqsNamespace.cjs +35 -38
- package/dist/aws/sqs/server/AwsSqsNamespace.mjs +35 -38
- package/dist/aws/ssm/server/AwsSsmNamespace.cjs +24 -23
- package/dist/aws/ssm/server/AwsSsmNamespace.mjs +24 -23
- package/dist/drizzle/server/DrizzleNamespace.cjs +39 -42
- package/dist/drizzle/server/DrizzleNamespace.mjs +39 -42
- package/dist/googleAds/server/GoogleAdsNamespace.cjs +21 -24
- package/dist/googleAds/server/GoogleAdsNamespace.mjs +21 -24
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.cjs +86 -70
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.mjs +86 -70
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.cjs +22 -25
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.mjs +22 -25
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.cjs +44 -38
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.mjs +44 -38
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.cjs +12 -15
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.mjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.cjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.mjs +12 -15
- package/dist/onePassword/server/OnePasswordNamespace.cjs +30 -33
- package/dist/onePassword/server/OnePasswordNamespace.mjs +30 -33
- package/dist/openAi/server/OpenAiNamespace.cjs +20 -20
- package/dist/openAi/server/OpenAiNamespace.mjs +20 -20
- package/dist/prisma/server/PrismaNamespace.cjs +35 -38
- package/dist/prisma/server/PrismaNamespace.mjs +35 -38
- package/dist/snapchat/server/SnapchatNamespace.cjs +12 -12
- package/dist/snapchat/server/SnapchatNamespace.mjs +12 -12
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.cjs +19 -19
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.mjs +19 -19
- package/package.json +1 -1
|
@@ -15,282 +15,297 @@ import { readFileDefault } from "./awsS3.mjs";
|
|
|
15
15
|
import "./index.mjs";
|
|
16
16
|
//#region src/aws/s3/server/AwsS3Namespace.ts
|
|
17
17
|
var AwsS3Namespace = class extends BaseNamespace {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
18
|
+
ensureInit = async () => {
|
|
19
|
+
if (!this.client) try {
|
|
20
|
+
const { S3Client } = await import("@aws-sdk/client-s3");
|
|
21
|
+
this.client = new S3Client(this.config);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new Error("AWS S3 Client not installed");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
copy = async (fromBucket, fromKey, toBucket, toKey) => {
|
|
27
|
+
await this.ensureInit();
|
|
28
|
+
const { CopyObjectCommand } = await import("@aws-sdk/client-s3");
|
|
29
|
+
await this.client.send(new CopyObjectCommand({
|
|
30
|
+
Bucket: toBucket,
|
|
31
|
+
CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
|
|
32
|
+
Key: toKey
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
deleteFile = async (bucket, key) => {
|
|
36
|
+
await this.ensureInit();
|
|
37
|
+
const { DeleteObjectCommand } = await import("@aws-sdk/client-s3");
|
|
38
|
+
await this.client.send(new DeleteObjectCommand({
|
|
39
|
+
Bucket: bucket,
|
|
40
|
+
Key: key
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
deleteFiles = async (bucket, keys) => {
|
|
44
|
+
await this.ensureInit();
|
|
45
|
+
const { DeleteObjectsCommand } = await import("@aws-sdk/client-s3");
|
|
46
|
+
await this.client.send(new DeleteObjectsCommand({
|
|
47
|
+
Bucket: bucket,
|
|
48
|
+
Delete: { Objects: keys.map((key) => ({ Key: key })) }
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
deleteFolder = async (bucket, folder) => {
|
|
52
|
+
await this.ensureInit();
|
|
53
|
+
const { ListObjectsV2Command, DeleteObjectsCommand } = await import("@aws-sdk/client-s3");
|
|
54
|
+
const cleanFolder = getFolder(folder);
|
|
55
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
56
|
+
Bucket: bucket,
|
|
57
|
+
Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
|
|
58
|
+
}));
|
|
59
|
+
if (!apiResponse.Contents?.length || 0 === apiResponse.Contents.length) return;
|
|
60
|
+
const keys = apiResponse.Contents.map((file) => ({ Key: file.Key }));
|
|
61
|
+
await this.client.send(new DeleteObjectsCommand({
|
|
62
|
+
Bucket: bucket,
|
|
63
|
+
Delete: { Objects: keys }
|
|
64
|
+
}));
|
|
65
|
+
if (apiResponse.IsTruncated) await this.deleteFolder(bucket, folder);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* List the files in the given bucket and option folder
|
|
69
|
+
*/
|
|
70
|
+
listFiles = async (bucket, folder = "") => {
|
|
71
|
+
await this.ensureInit();
|
|
72
|
+
const { ListObjectsV2Command } = await import("@aws-sdk/client-s3");
|
|
73
|
+
const cleanFolder = getFolder(folder);
|
|
74
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
75
|
+
Bucket: bucket,
|
|
76
|
+
Delimiter: "/",
|
|
77
|
+
Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
|
|
78
|
+
}));
|
|
79
|
+
if (!apiResponse?.["Contents"]) return [];
|
|
80
|
+
const valid = apiResponse["Contents"].filter((content) => {
|
|
81
|
+
if (!content?.["Key"]) return false;
|
|
82
|
+
const keyExploded = content["Key"].split("/");
|
|
83
|
+
return keyExploded[keyExploded.length - 1].indexOf(".") > -1;
|
|
84
|
+
});
|
|
85
|
+
if (0 === valid.length) return [];
|
|
86
|
+
return valid.map((entry) => entry?.["Key"] ?? "").filter((entryKey) => "" !== entryKey);
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Fetch all the files within a given directory recursively
|
|
90
|
+
*/
|
|
91
|
+
filesIteratively = async (bucket, folder) => {
|
|
92
|
+
await this.ensureInit();
|
|
93
|
+
return await this.iterateFolders(bucket, folder);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Sub function
|
|
97
|
+
*/
|
|
98
|
+
iterateFolders = async (bucket, folder) => {
|
|
99
|
+
let response = [];
|
|
100
|
+
const folders = await this.listFolders(bucket, folder);
|
|
101
|
+
for (let i = 0; i < folders.length; i++) {
|
|
102
|
+
const subFolderFiles = await this.listFolders(bucket, `${folder}/${folders[i]}`);
|
|
103
|
+
const files = await this.listFiles(bucket, `${folder}/${folders[i]}`);
|
|
104
|
+
response = [
|
|
105
|
+
...response,
|
|
106
|
+
...files,
|
|
107
|
+
...subFolderFiles
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
return response;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* List the files in the given bucket and option folder.
|
|
114
|
+
*/
|
|
115
|
+
listFolders = async (bucket, folder) => {
|
|
116
|
+
await this.ensureInit();
|
|
117
|
+
const { ListObjectsV2Command } = await import("@aws-sdk/client-s3");
|
|
118
|
+
const cleanFolder = getFolder(folder);
|
|
119
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
120
|
+
Bucket: bucket,
|
|
121
|
+
Delimiter: "/",
|
|
122
|
+
Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
|
|
123
|
+
}));
|
|
124
|
+
if (!apiResponse?.["CommonPrefixes"]) return [];
|
|
125
|
+
return apiResponse["CommonPrefixes"].map((prefix) => {
|
|
126
|
+
if (!prefix?.Prefix) return "";
|
|
127
|
+
const fileFolders = prefix.Prefix.slice(0, -1).split("/");
|
|
128
|
+
return fileFolders[fileFolders.length - 1];
|
|
129
|
+
}).filter((prefixFolder) => "" !== prefixFolder);
|
|
130
|
+
};
|
|
131
|
+
move = async (fromBucket, fromKey, toBucket, toKey) => {
|
|
132
|
+
await this.ensureInit();
|
|
133
|
+
const { CopyObjectCommand, DeleteObjectCommand } = await import("@aws-sdk/client-s3");
|
|
134
|
+
await this.client.send(new CopyObjectCommand({
|
|
135
|
+
Bucket: toBucket,
|
|
136
|
+
CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
|
|
137
|
+
Key: toKey
|
|
138
|
+
}));
|
|
139
|
+
await this.client.send(new DeleteObjectCommand({
|
|
140
|
+
Bucket: fromBucket,
|
|
141
|
+
Key: fromKey
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
readBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
145
|
+
await this.ensureInit();
|
|
146
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
147
|
+
if (void 0 !== apiResponse.body) apiResponse.body = await getBrotliDecompressed(apiResponse.body, brotliOptions);
|
|
148
|
+
return apiResponse;
|
|
149
|
+
};
|
|
150
|
+
readJsonBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
151
|
+
await this.ensureInit();
|
|
152
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
153
|
+
if (void 0 !== apiResponse.body) {
|
|
154
|
+
apiResponse.body = await getBrotliDecompressed(apiResponse.body, brotliOptions);
|
|
155
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
156
|
+
}
|
|
157
|
+
return apiResponse;
|
|
158
|
+
};
|
|
159
|
+
readBuffer = async (bucket, key) => {
|
|
160
|
+
await this.ensureInit();
|
|
161
|
+
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
|
162
|
+
let response = {
|
|
163
|
+
...readFileDefault,
|
|
164
|
+
buffer: void 0
|
|
68
165
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!content?.["Key"]) return false;
|
|
81
|
-
const keyExploded = content["Key"].split("/");
|
|
82
|
-
return keyExploded[keyExploded.length - 1].indexOf(".") > -1;
|
|
166
|
+
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
167
|
+
Bucket: bucket,
|
|
168
|
+
Key: key
|
|
169
|
+
}));
|
|
170
|
+
if (isResponse200(apiResponse)) {
|
|
171
|
+
const chunks = [];
|
|
172
|
+
response.buffer = await new Promise((resolve, reject) => {
|
|
173
|
+
const body = apiResponse.Body;
|
|
174
|
+
body.on("data", (chunk) => chunks.push(chunk));
|
|
175
|
+
body.on("error", (err) => reject(err));
|
|
176
|
+
body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
83
177
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const folders = await this.listFolders(bucket, folder);
|
|
94
|
-
for (let i = 0; i < folders.length; i++) {
|
|
95
|
-
const subFolderFiles = await this.listFolders(bucket, `${folder}/${folders[i]}`);
|
|
96
|
-
const files = await this.listFiles(bucket, `${folder}/${folders[i]}`);
|
|
97
|
-
response = [
|
|
98
|
-
...response,
|
|
99
|
-
...files,
|
|
100
|
-
...subFolderFiles
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
return response;
|
|
104
|
-
};
|
|
105
|
-
this.listFolders = async (bucket, folder) => {
|
|
106
|
-
await this.ensureInit();
|
|
107
|
-
const { ListObjectsV2Command } = await import("@aws-sdk/client-s3");
|
|
108
|
-
const cleanFolder = getFolder(folder);
|
|
109
|
-
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
178
|
+
} else throw new Error("Error reading file.");
|
|
179
|
+
return response;
|
|
180
|
+
};
|
|
181
|
+
fileExists = async (bucket, key) => {
|
|
182
|
+
await this.ensureInit();
|
|
183
|
+
let response = false;
|
|
184
|
+
try {
|
|
185
|
+
const { HeadObjectCommand } = await import("@aws-sdk/client-s3");
|
|
186
|
+
response = isResponse200(await this.client.send(new HeadObjectCommand({
|
|
110
187
|
Bucket: bucket,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
Bucket: toBucket,
|
|
126
|
-
CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
|
|
127
|
-
Key: toKey
|
|
128
|
-
}));
|
|
129
|
-
await this.client.send(new DeleteObjectCommand({
|
|
130
|
-
Bucket: fromBucket,
|
|
131
|
-
Key: fromKey
|
|
132
|
-
}));
|
|
133
|
-
};
|
|
134
|
-
this.readBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
135
|
-
await this.ensureInit();
|
|
136
|
-
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
137
|
-
if (void 0 !== apiResponse.body) apiResponse.body = await getBrotliDecompressed(apiResponse.body, brotliOptions);
|
|
138
|
-
return apiResponse;
|
|
139
|
-
};
|
|
140
|
-
this.readJsonBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
141
|
-
await this.ensureInit();
|
|
142
|
-
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
143
|
-
if (void 0 !== apiResponse.body) {
|
|
144
|
-
apiResponse.body = await getBrotliDecompressed(apiResponse.body, brotliOptions);
|
|
145
|
-
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
146
|
-
}
|
|
147
|
-
return apiResponse;
|
|
148
|
-
};
|
|
149
|
-
this.readBuffer = async (bucket, key) => {
|
|
150
|
-
await this.ensureInit();
|
|
188
|
+
Key: key
|
|
189
|
+
})));
|
|
190
|
+
} catch (exception) {
|
|
191
|
+
response = false;
|
|
192
|
+
}
|
|
193
|
+
return response;
|
|
194
|
+
};
|
|
195
|
+
readFile = async (bucket, key, options = {}) => {
|
|
196
|
+
await this.ensureInit();
|
|
197
|
+
let response = structuredClone(readFileDefault);
|
|
198
|
+
const today = getToday();
|
|
199
|
+
getToday(true);
|
|
200
|
+
try {
|
|
201
|
+
response.now = today.toUnixInteger();
|
|
151
202
|
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
|
152
|
-
let response = {
|
|
153
|
-
...readFileDefault,
|
|
154
|
-
buffer: void 0
|
|
155
|
-
};
|
|
156
203
|
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
157
204
|
Bucket: bucket,
|
|
158
|
-
Key: key
|
|
205
|
+
Key: key,
|
|
206
|
+
...options
|
|
159
207
|
}));
|
|
160
208
|
if (isResponse200(apiResponse)) {
|
|
161
|
-
|
|
162
|
-
response.
|
|
163
|
-
const body = apiResponse.Body;
|
|
164
|
-
body.on("data", (chunk) => chunks.push(chunk));
|
|
165
|
-
body.on("error", (err) => reject(err));
|
|
166
|
-
body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
167
|
-
});
|
|
168
|
-
} else throw new Error("Error reading file.");
|
|
169
|
-
return response;
|
|
170
|
-
};
|
|
171
|
-
this.fileExists = async (bucket, key) => {
|
|
172
|
-
await this.ensureInit();
|
|
173
|
-
let response = false;
|
|
174
|
-
try {
|
|
175
|
-
const { HeadObjectCommand } = await import("@aws-sdk/client-s3");
|
|
176
|
-
response = isResponse200(await this.client.send(new HeadObjectCommand({
|
|
177
|
-
Bucket: bucket,
|
|
178
|
-
Key: key
|
|
179
|
-
})));
|
|
180
|
-
} catch (exception) {
|
|
181
|
-
response = false;
|
|
209
|
+
response.modified = getYmdHisString(apiResponse.LastModified);
|
|
210
|
+
response.body = await getStringFromStream(apiResponse.Body);
|
|
182
211
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
response.body = await getStringFromStream(apiResponse.Body);
|
|
201
|
-
}
|
|
202
|
-
} catch (error) {
|
|
203
|
-
response.body = null;
|
|
204
|
-
response.error = error;
|
|
205
|
-
}
|
|
206
|
-
return response;
|
|
207
|
-
};
|
|
208
|
-
this.readJson = async (bucket, key) => {
|
|
209
|
-
await this.ensureInit();
|
|
210
|
-
const apiResponse = await this.readFile(bucket, key);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
response.body = null;
|
|
214
|
+
response.error = error;
|
|
215
|
+
}
|
|
216
|
+
return response;
|
|
217
|
+
};
|
|
218
|
+
readJson = async (bucket, key) => {
|
|
219
|
+
await this.ensureInit();
|
|
220
|
+
const apiResponse = await this.readFile(bucket, key);
|
|
221
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
222
|
+
return apiResponse;
|
|
223
|
+
};
|
|
224
|
+
readJsonGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
225
|
+
await this.ensureInit();
|
|
226
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
227
|
+
if (void 0 !== apiResponse.body) {
|
|
228
|
+
apiResponse.body = await getGzipDecompressed(apiResponse.body, gzipOptions);
|
|
211
229
|
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
this.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return new Promise(async (resolve, reject) => {
|
|
264
|
-
let response = null;
|
|
265
|
-
const formData = new FormData();
|
|
266
|
-
Object.entries(props.fields).forEach(([key, value]) => {
|
|
267
|
-
formData.append(key, value);
|
|
268
|
-
});
|
|
269
|
-
formData.append("file", props.file);
|
|
270
|
-
if ((await fetch(props.url, {
|
|
271
|
-
method: "POST",
|
|
272
|
-
body: formData
|
|
273
|
-
})).ok) {
|
|
274
|
-
response = `https://${props.bucket}.s3.${this.config.region}.amazonaws.com/${props.key}`;
|
|
275
|
-
resolve(response);
|
|
276
|
-
} else {
|
|
277
|
-
response = null;
|
|
278
|
-
reject(response);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
this.urlContents = async (bucket, key, url) => {
|
|
283
|
-
await this.ensureInit();
|
|
284
|
-
const { default: ky } = await import("ky");
|
|
285
|
-
const response = await ky.get(url);
|
|
286
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
287
|
-
const data = Buffer.from(arrayBuffer);
|
|
288
|
-
await this.writeFile(bucket, key, data, {
|
|
289
|
-
ContentType: response.headers.get("content-type"),
|
|
290
|
-
ContentLength: response.headers.get("content-length")
|
|
230
|
+
}
|
|
231
|
+
return apiResponse;
|
|
232
|
+
};
|
|
233
|
+
readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
234
|
+
await this.ensureInit();
|
|
235
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
236
|
+
if (void 0 !== apiResponse.body) apiResponse.body = await getGzipDecompressed(apiResponse.body, gzipOptions);
|
|
237
|
+
return apiResponse;
|
|
238
|
+
};
|
|
239
|
+
writeBrotli = async (bucket, key, data, brotliOptions = {}, awsS3Options = {}) => {
|
|
240
|
+
await this.ensureInit();
|
|
241
|
+
let finalData = data;
|
|
242
|
+
finalData = await getBrotliCompressed(finalData, brotliOptions);
|
|
243
|
+
return await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
244
|
+
};
|
|
245
|
+
writeFile = async (bucket, key, data, options = {}) => {
|
|
246
|
+
await this.ensureInit();
|
|
247
|
+
const { PutObjectCommand } = await import("@aws-sdk/client-s3");
|
|
248
|
+
return await this.client.send(new PutObjectCommand({
|
|
249
|
+
Bucket: bucket,
|
|
250
|
+
Body: data,
|
|
251
|
+
Key: key,
|
|
252
|
+
...options
|
|
253
|
+
}));
|
|
254
|
+
};
|
|
255
|
+
writeJson = async (bucket, key, data, options = {}) => {
|
|
256
|
+
await this.ensureInit();
|
|
257
|
+
return await this.writeFile(bucket, key, JSON.stringify(data), options);
|
|
258
|
+
};
|
|
259
|
+
writeJsonGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
260
|
+
await this.ensureInit();
|
|
261
|
+
let finalData = JSON.stringify(data);
|
|
262
|
+
finalData = await getGzipCompressed(finalData, gzipOptions);
|
|
263
|
+
return await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
264
|
+
};
|
|
265
|
+
writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
266
|
+
await this.ensureInit();
|
|
267
|
+
let finalData = data;
|
|
268
|
+
finalData = await getGzipCompressed(finalData, gzipOptions);
|
|
269
|
+
return await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
273
|
+
*/
|
|
274
|
+
presignedPost = async (props) => {
|
|
275
|
+
await this.ensureInit();
|
|
276
|
+
return new Promise(async (resolve, reject) => {
|
|
277
|
+
let response = null;
|
|
278
|
+
const formData = new FormData();
|
|
279
|
+
Object.entries(props.fields).forEach(([key, value]) => {
|
|
280
|
+
formData.append(key, value);
|
|
291
281
|
});
|
|
292
|
-
|
|
293
|
-
|
|
282
|
+
formData.append("file", props.file);
|
|
283
|
+
if ((await fetch(props.url, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: formData
|
|
286
|
+
})).ok) {
|
|
287
|
+
response = `https://${props.bucket}.s3.${this.config.region}.amazonaws.com/${props.key}`;
|
|
288
|
+
resolve(response);
|
|
289
|
+
} else {
|
|
290
|
+
response = null;
|
|
291
|
+
reject(response);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Download a file and write to S3.
|
|
297
|
+
*/
|
|
298
|
+
urlContents = async (bucket, key, url) => {
|
|
299
|
+
await this.ensureInit();
|
|
300
|
+
const { default: ky } = await import("ky");
|
|
301
|
+
const response = await ky.get(url);
|
|
302
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
303
|
+
const data = Buffer.from(arrayBuffer);
|
|
304
|
+
await this.writeFile(bucket, key, data, {
|
|
305
|
+
ContentType: response.headers.get("content-type"),
|
|
306
|
+
ContentLength: response.headers.get("content-length")
|
|
307
|
+
});
|
|
308
|
+
};
|
|
294
309
|
};
|
|
295
310
|
//#endregion
|
|
296
311
|
export { AwsS3Namespace };
|
|
@@ -2,36 +2,33 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require__class_BaseNamespace = require("../../../_class/BaseNamespace.cjs");
|
|
3
3
|
//#region src/aws/ses/server/AwsSesNamespace.ts
|
|
4
4
|
var AwsSesNamespace = class extends require__class_BaseNamespace.BaseNamespace {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return response;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
5
|
+
ensureInit = async () => {
|
|
6
|
+
if (!this.client) try {
|
|
7
|
+
const { SESClient } = await import("@aws-sdk/client-ses");
|
|
8
|
+
this.client = new SESClient(this.config);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw new Error("AWS SES Client not installed");
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
send = async (input) => {
|
|
14
|
+
await this.ensureInit();
|
|
15
|
+
let response;
|
|
16
|
+
if (input?.Message?.Body?.Html?.Data) try {
|
|
17
|
+
const { SendEmailCommand } = await import("@aws-sdk/client-ses");
|
|
18
|
+
const command = new SendEmailCommand(input);
|
|
19
|
+
response = await this.client.send(command);
|
|
20
|
+
} catch (exception) {
|
|
21
|
+
response = exception;
|
|
22
|
+
}
|
|
23
|
+
else try {
|
|
24
|
+
const { SendRawEmailCommand } = await import("@aws-sdk/client-ses");
|
|
25
|
+
const command = new SendRawEmailCommand(input);
|
|
26
|
+
response = await this.client.send(command);
|
|
27
|
+
} catch (exception) {
|
|
28
|
+
response = exception;
|
|
29
|
+
}
|
|
30
|
+
return response;
|
|
31
|
+
};
|
|
35
32
|
};
|
|
36
33
|
//#endregion
|
|
37
34
|
exports.AwsSesNamespace = AwsSesNamespace;
|