@8ms/helpers 2.4.10 → 2.4.12

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.
Files changed (78) hide show
  1. package/dist/_class/BaseClass.cjs +31 -21
  2. package/dist/_class/BaseClass.mjs +31 -21
  3. package/dist/_class/BaseNamespace.cjs +10 -9
  4. package/dist/_class/BaseNamespace.mjs +10 -9
  5. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  6. package/dist/_virtual/_rolldown/runtime.mjs +1 -1
  7. package/dist/api/ApiResponseClass.cjs +96 -96
  8. package/dist/api/ApiResponseClass.mjs +96 -96
  9. package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.cjs +70 -60
  10. package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.mjs +70 -60
  11. package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.cjs +30 -28
  12. package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.mjs +30 -28
  13. package/dist/aws/ec2/server/AwsEc2Namespace.cjs +29 -32
  14. package/dist/aws/ec2/server/AwsEc2Namespace.mjs +29 -32
  15. package/dist/aws/ecs/server/AwsEcsNamespace.cjs +92 -78
  16. package/dist/aws/ecs/server/AwsEcsNamespace.mjs +92 -78
  17. package/dist/aws/glue/server/AwsGlueNamespace.cjs +17 -17
  18. package/dist/aws/glue/server/AwsGlueNamespace.mjs +17 -17
  19. package/dist/aws/lambda/server/AwsLambdaNamespace.cjs +33 -31
  20. package/dist/aws/lambda/server/AwsLambdaNamespace.mjs +33 -31
  21. package/dist/aws/s3/server/AwsS3Namespace.cjs +280 -265
  22. package/dist/aws/s3/server/AwsS3Namespace.mjs +280 -265
  23. package/dist/aws/ses/server/AwsSesNamespace.cjs +27 -30
  24. package/dist/aws/ses/server/AwsSesNamespace.mjs +27 -30
  25. package/dist/aws/ses/server/SimpleEmail.cjs +202 -199
  26. package/dist/aws/ses/server/SimpleEmail.mjs +202 -199
  27. package/dist/aws/sqs/server/AwsSqsNamespace.cjs +35 -38
  28. package/dist/aws/sqs/server/AwsSqsNamespace.mjs +35 -38
  29. package/dist/aws/ssm/server/AwsSsmNamespace.cjs +24 -23
  30. package/dist/aws/ssm/server/AwsSsmNamespace.mjs +24 -23
  31. package/dist/date/index.cjs +1 -1
  32. package/dist/date/index.mjs +1 -1
  33. package/dist/drizzle/server/DrizzleNamespace.cjs +39 -42
  34. package/dist/drizzle/server/DrizzleNamespace.d.cts +1 -0
  35. package/dist/drizzle/server/DrizzleNamespace.mjs +39 -42
  36. package/dist/googleAds/server/GoogleAdsNamespace.cjs +21 -24
  37. package/dist/googleAds/server/GoogleAdsNamespace.mjs +21 -24
  38. package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.cjs +87 -70
  39. package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.mjs +87 -70
  40. package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.cjs +22 -25
  41. package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.mjs +22 -25
  42. package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.cjs +45 -38
  43. package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.mjs +45 -38
  44. package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.cjs +12 -15
  45. package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.mjs +12 -15
  46. package/dist/littleWarden/server/LittleWardenNamespace.cjs +12 -15
  47. package/dist/littleWarden/server/LittleWardenNamespace.mjs +12 -15
  48. package/dist/nextJs/client/index.cjs +2 -0
  49. package/dist/nextJs/client/index.d.cts +2 -1
  50. package/dist/nextJs/client/index.d.mts +2 -1
  51. package/dist/nextJs/client/index.mjs +2 -1
  52. package/dist/nextJs/client/useAsyncEffect.cjs +23 -0
  53. package/dist/nextJs/client/useAsyncEffect.d.cts +4 -0
  54. package/dist/nextJs/client/useAsyncEffect.d.mts +4 -0
  55. package/dist/nextJs/client/useAsyncEffect.mjs +21 -0
  56. package/dist/onePassword/server/OnePasswordNamespace.cjs +30 -33
  57. package/dist/onePassword/server/OnePasswordNamespace.mjs +30 -33
  58. package/dist/openAi/server/OpenAiNamespace.cjs +20 -20
  59. package/dist/openAi/server/OpenAiNamespace.mjs +20 -20
  60. package/dist/prisma/server/PrismaNamespace.cjs +35 -38
  61. package/dist/prisma/server/PrismaNamespace.mjs +35 -38
  62. package/dist/snapchat/server/SnapchatNamespace.cjs +12 -12
  63. package/dist/snapchat/server/SnapchatNamespace.mjs +12 -12
  64. package/dist/upTimeRobot/server/UpTimeRobotNamespace.cjs +19 -19
  65. package/dist/upTimeRobot/server/UpTimeRobotNamespace.mjs +19 -19
  66. package/package.json +4 -12
  67. package/dist/nextJs/index.cjs +0 -4
  68. package/dist/nextJs/index.d.cts +0 -2
  69. package/dist/nextJs/index.d.mts +0 -2
  70. package/dist/nextJs/index.mjs +0 -2
  71. package/dist/nextJs/nextJs.cjs +0 -13
  72. package/dist/nextJs/nextJs.d.cts +0 -19
  73. package/dist/nextJs/nextJs.d.mts +0 -19
  74. package/dist/nextJs/nextJs.mjs +0 -11
  75. package/dist/nextJs/tests/getIp.cjs +0 -9
  76. package/dist/nextJs/tests/getIp.d.cts +0 -1
  77. package/dist/nextJs/tests/getIp.d.mts +0 -1
  78. package/dist/nextJs/tests/getIp.mjs +0 -10
@@ -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
- constructor(..._args) {
19
- super(..._args);
20
- this.ensureInit = async () => {
21
- if (!this.client) try {
22
- const { S3Client } = await import("@aws-sdk/client-s3");
23
- this.client = new S3Client(this.config);
24
- } catch (e) {
25
- throw new Error("AWS S3 Client not installed");
26
- }
27
- };
28
- this.copy = async (fromBucket, fromKey, toBucket, toKey) => {
29
- await this.ensureInit();
30
- const { CopyObjectCommand } = await import("@aws-sdk/client-s3");
31
- await this.client.send(new CopyObjectCommand({
32
- Bucket: toBucket,
33
- CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
34
- Key: toKey
35
- }));
36
- };
37
- this.deleteFile = async (bucket, key) => {
38
- await this.ensureInit();
39
- const { DeleteObjectCommand } = await import("@aws-sdk/client-s3");
40
- await this.client.send(new DeleteObjectCommand({
41
- Bucket: bucket,
42
- Key: key
43
- }));
44
- };
45
- this.deleteFiles = async (bucket, keys) => {
46
- await this.ensureInit();
47
- const { DeleteObjectsCommand } = await import("@aws-sdk/client-s3");
48
- await this.client.send(new DeleteObjectsCommand({
49
- Bucket: bucket,
50
- Delete: { Objects: keys.map((key) => ({ Key: key })) }
51
- }));
52
- };
53
- this.deleteFolder = async (bucket, folder) => {
54
- await this.ensureInit();
55
- const { ListObjectsV2Command, DeleteObjectsCommand } = await import("@aws-sdk/client-s3");
56
- const cleanFolder = getFolder(folder);
57
- const apiResponse = await this.client.send(new ListObjectsV2Command({
58
- Bucket: bucket,
59
- Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
60
- }));
61
- if (!apiResponse.Contents?.length || 0 === apiResponse.Contents.length) return;
62
- const keys = apiResponse.Contents.map((file) => ({ Key: file.Key }));
63
- await this.client.send(new DeleteObjectsCommand({
64
- Bucket: bucket,
65
- Delete: { Objects: keys }
66
- }));
67
- if (apiResponse.IsTruncated) await this.deleteFolder(bucket, folder);
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
- this.listFiles = async (bucket, folder = "") => {
70
- await this.ensureInit();
71
- const { ListObjectsV2Command } = await import("@aws-sdk/client-s3");
72
- const cleanFolder = getFolder(folder);
73
- const apiResponse = await this.client.send(new ListObjectsV2Command({
74
- Bucket: bucket,
75
- Delimiter: "/",
76
- Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
77
- }));
78
- if (!apiResponse?.["Contents"]) return [];
79
- const valid = apiResponse["Contents"].filter((content) => {
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
- if (0 === valid.length) return [];
85
- return valid.map((entry) => entry?.["Key"] ?? "").filter((entryKey) => "" !== entryKey);
86
- };
87
- this.filesIteratively = async (bucket, folder) => {
88
- await this.ensureInit();
89
- return await this.iterateFolders(bucket, folder);
90
- };
91
- this.iterateFolders = async (bucket, folder) => {
92
- let response = [];
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
- Delimiter: "/",
112
- Prefix: "" === cleanFolder ? "" : cleanFolder + "/"
113
- }));
114
- if (!apiResponse?.["CommonPrefixes"]) return [];
115
- return apiResponse["CommonPrefixes"].map((prefix) => {
116
- if (!prefix?.Prefix) return "";
117
- const fileFolders = prefix.Prefix.slice(0, -1).split("/");
118
- return fileFolders[fileFolders.length - 1];
119
- }).filter((prefixFolder) => "" !== prefixFolder);
120
- };
121
- this.move = async (fromBucket, fromKey, toBucket, toKey) => {
122
- await this.ensureInit();
123
- const { CopyObjectCommand, DeleteObjectCommand } = await import("@aws-sdk/client-s3");
124
- await this.client.send(new CopyObjectCommand({
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
- const chunks = [];
162
- response.buffer = await new Promise((resolve, reject) => {
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
- return response;
184
- };
185
- this.readFile = async (bucket, key, options = {}) => {
186
- await this.ensureInit();
187
- let response = structuredClone(readFileDefault);
188
- const today = getToday();
189
- getToday(true);
190
- try {
191
- response.now = today.toUnixInteger();
192
- const { GetObjectCommand } = await import("@aws-sdk/client-s3");
193
- const apiResponse = await this.client.send(new GetObjectCommand({
194
- Bucket: bucket,
195
- Key: key,
196
- ...options
197
- }));
198
- if (isResponse200(apiResponse)) {
199
- response.modified = getYmdHisString(apiResponse.LastModified);
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
- return apiResponse;
213
- };
214
- this.readJsonGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
215
- await this.ensureInit();
216
- const apiResponse = await this.readFile(bucket, key, awsS3Options);
217
- if (void 0 !== apiResponse.body) {
218
- apiResponse.body = await getGzipDecompressed(apiResponse.body, gzipOptions);
219
- apiResponse.body = JSON.parse(apiResponse.body) || null;
220
- }
221
- return apiResponse;
222
- };
223
- this.readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
224
- await this.ensureInit();
225
- const apiResponse = await this.readFile(bucket, key, awsS3Options);
226
- if (void 0 !== apiResponse.body) apiResponse.body = await getGzipDecompressed(apiResponse.body, gzipOptions);
227
- return apiResponse;
228
- };
229
- this.writeBrotli = async (bucket, key, data, brotliOptions = {}, awsS3Options = {}) => {
230
- await this.ensureInit();
231
- let finalData = data;
232
- finalData = await getBrotliCompressed(finalData, brotliOptions);
233
- return await this.writeFile(bucket, key, finalData, awsS3Options);
234
- };
235
- this.writeFile = async (bucket, key, data, options = {}) => {
236
- await this.ensureInit();
237
- const { PutObjectCommand } = await import("@aws-sdk/client-s3");
238
- return await this.client.send(new PutObjectCommand({
239
- Bucket: bucket,
240
- Body: data,
241
- Key: key,
242
- ...options
243
- }));
244
- };
245
- this.writeJson = async (bucket, key, data, options = {}) => {
246
- await this.ensureInit();
247
- return await this.writeFile(bucket, key, JSON.stringify(data), options);
248
- };
249
- this.writeJsonGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
250
- await this.ensureInit();
251
- let finalData = JSON.stringify(data);
252
- finalData = await getGzipCompressed(finalData, gzipOptions);
253
- return await this.writeFile(bucket, key, finalData, awsS3Options);
254
- };
255
- this.writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
256
- await this.ensureInit();
257
- let finalData = data;
258
- finalData = await getGzipCompressed(finalData, gzipOptions);
259
- return await this.writeFile(bucket, key, finalData, awsS3Options);
260
- };
261
- this.presignedPost = async (props) => {
262
- await this.ensureInit();
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
- constructor(..._args) {
6
- super(..._args);
7
- this.ensureInit = async () => {
8
- if (!this.client) try {
9
- const { SESClient } = await import("@aws-sdk/client-ses");
10
- this.client = new SESClient(this.config);
11
- } catch (e) {
12
- throw new Error("AWS SES Client not installed");
13
- }
14
- };
15
- this.send = async (input) => {
16
- await this.ensureInit();
17
- let response;
18
- if (input?.Message?.Body?.Html?.Data) try {
19
- const { SendEmailCommand } = await import("@aws-sdk/client-ses");
20
- const command = new SendEmailCommand(input);
21
- response = await this.client.send(command);
22
- } catch (exception) {
23
- response = exception;
24
- }
25
- else try {
26
- const { SendRawEmailCommand } = await import("@aws-sdk/client-ses");
27
- const command = new SendRawEmailCommand(input);
28
- response = await this.client.send(command);
29
- } catch (exception) {
30
- response = exception;
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;