@8ms/helpers 2.0.16 → 2.0.18
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/.yarn/install-state.gz +0 -0
- package/aws/s3/AwsS3Namespace.d.ts +10 -5
- package/aws/s3/AwsS3Namespace.js +60 -44
- package/aws/ses/AwsSesNamespace.d.ts +2 -11
- package/aws/ses/AwsSesNamespace.js +1 -1
- package/aws/ses/SimpleEmail.d.ts +1 -1
- package/aws/ses/SimpleEmail.js +1 -1
- package/package.json +1 -1
- package/util/getGzipCompressed.d.ts +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -40,14 +40,19 @@ export declare class AwsS3Namespace extends BaseNamespace {
|
|
|
40
40
|
*/
|
|
41
41
|
listFolders: (bucket: string, folder: string) => Promise<string[]>;
|
|
42
42
|
move: (fromBucket: string, fromKey: string, toBucket: string, toKey: string) => Promise<void>;
|
|
43
|
-
readBrotli: (bucket: string, key: string,
|
|
43
|
+
readBrotli: (bucket: string, key: string, brotliOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
44
|
+
readJsonBrotli: (bucket: string, key: string, brotliOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
44
45
|
readBuffer: (bucket: string, key: string) => Promise<ReadBufferResponse>;
|
|
45
46
|
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
46
|
-
readFile: (bucket: string, key: string,
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
readFile: (bucket: string, key: string, options?: Options) => Promise<ReadFileResponse>;
|
|
48
|
+
readJson: (bucket: string, key: string) => Promise<ReadFileResponse>;
|
|
49
|
+
readJsonGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
50
|
+
readGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
51
|
+
writeBrotli: (bucket: string, key: string, data: any, brotliOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
49
52
|
writeFile: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
50
|
-
|
|
53
|
+
writeJson: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
54
|
+
writeJsonGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
55
|
+
writeGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
51
56
|
/**
|
|
52
57
|
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
53
58
|
*/
|
package/aws/s3/AwsS3Namespace.js
CHANGED
|
@@ -206,17 +206,23 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
206
206
|
Key: fromKey,
|
|
207
207
|
}));
|
|
208
208
|
};
|
|
209
|
-
this.readBrotli = async (bucket, key,
|
|
209
|
+
this.readBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
210
210
|
await this.ensureInit();
|
|
211
|
-
|
|
211
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
212
212
|
// Cache exists and is still within our caching timeframe
|
|
213
|
-
if (undefined !==
|
|
214
|
-
|
|
215
|
-
if (false !== isJson) {
|
|
216
|
-
response.body = JSON.parse(response.body);
|
|
217
|
-
}
|
|
213
|
+
if (undefined !== apiResponse.body) {
|
|
214
|
+
apiResponse.body = await (0, server_2.getBrotliDecompressed)(apiResponse.body, brotliOptions);
|
|
218
215
|
}
|
|
219
|
-
return
|
|
216
|
+
return apiResponse;
|
|
217
|
+
};
|
|
218
|
+
this.readJsonBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
219
|
+
await this.ensureInit();
|
|
220
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
221
|
+
if (undefined !== apiResponse.body) {
|
|
222
|
+
apiResponse.body = await (0, server_2.getBrotliDecompressed)(apiResponse.body, brotliOptions);
|
|
223
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
224
|
+
}
|
|
225
|
+
return apiResponse;
|
|
220
226
|
};
|
|
221
227
|
this.readBuffer = async (bucket, key) => {
|
|
222
228
|
await this.ensureInit();
|
|
@@ -264,7 +270,7 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
264
270
|
}
|
|
265
271
|
return response;
|
|
266
272
|
};
|
|
267
|
-
this.readFile = async (bucket, key,
|
|
273
|
+
this.readFile = async (bucket, key, options = {}) => {
|
|
268
274
|
await this.ensureInit();
|
|
269
275
|
let response = (0, cloneDeep_1.default)(server_3.readFileDefault);
|
|
270
276
|
const today = (0, date_1.getToday)();
|
|
@@ -276,6 +282,7 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
276
282
|
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
277
283
|
Bucket: bucket,
|
|
278
284
|
Key: key,
|
|
285
|
+
...options,
|
|
279
286
|
}));
|
|
280
287
|
//console.log('apiResponse', apiResponse);
|
|
281
288
|
if ((0, server_1.isResponse200)(apiResponse)) {
|
|
@@ -283,19 +290,15 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
283
290
|
// Convert the date to unix
|
|
284
291
|
response.modified.unix = modified.toUnixInteger();
|
|
285
292
|
// Compare now to unix
|
|
286
|
-
response.modified.vs_now.months = today.diff(modified,
|
|
287
|
-
response.modified.vs_now.days = today.diff(modified,
|
|
288
|
-
response.modified.vs_now.hours = today.diff(modified,
|
|
289
|
-
response.modified.vs_now.minutes = today.diff(modified,
|
|
293
|
+
response.modified.vs_now.months = today.diff(modified, "months").months;
|
|
294
|
+
response.modified.vs_now.days = today.diff(modified, "days").days;
|
|
295
|
+
response.modified.vs_now.hours = today.diff(modified, "hours").hours;
|
|
296
|
+
response.modified.vs_now.minutes = today.diff(modified, "minutes").minutes;
|
|
290
297
|
// Compare now to midnight
|
|
291
|
-
response.modified.vs_midnight.hours = today.diff(midnight,
|
|
292
|
-
response.modified.vs_midnight.minutes = today.diff(midnight,
|
|
298
|
+
response.modified.vs_midnight.hours = today.diff(midnight, "hours").hours;
|
|
299
|
+
response.modified.vs_midnight.minutes = today.diff(midnight, "minutes").hours;
|
|
293
300
|
// Convert stream into a string
|
|
294
301
|
response.body = await (0, string_1.getStringFromStream)(apiResponse.Body);
|
|
295
|
-
// If we need to return JSON, parse it. On error return undefined
|
|
296
|
-
if (false !== isJson) {
|
|
297
|
-
response.body = JSON.parse(response.body) || null;
|
|
298
|
-
}
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
304
|
catch (error) {
|
|
@@ -304,29 +307,34 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
304
307
|
}
|
|
305
308
|
return response;
|
|
306
309
|
};
|
|
307
|
-
this.
|
|
310
|
+
this.readJson = async (bucket, key) => {
|
|
308
311
|
await this.ensureInit();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
312
|
+
const apiResponse = await this.readFile(bucket, key);
|
|
313
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
314
|
+
return apiResponse;
|
|
315
|
+
};
|
|
316
|
+
this.readJsonGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
317
|
+
await this.ensureInit();
|
|
318
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
319
|
+
if (undefined !== apiResponse.body) {
|
|
320
|
+
apiResponse.body = await (0, server_2.getGzipDecompressed)(apiResponse.body, gzipOptions);
|
|
321
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
316
322
|
}
|
|
317
|
-
return
|
|
323
|
+
return apiResponse;
|
|
318
324
|
};
|
|
319
|
-
this.
|
|
325
|
+
this.readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
320
326
|
await this.ensureInit();
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
327
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
328
|
+
if (undefined !== apiResponse.body) {
|
|
329
|
+
apiResponse.body = await (0, server_2.getGzipDecompressed)(apiResponse.body, gzipOptions);
|
|
324
330
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
331
|
+
return apiResponse;
|
|
332
|
+
};
|
|
333
|
+
this.writeBrotli = async (bucket, key, data, brotliOptions = {}, awsS3Options = {}) => {
|
|
334
|
+
await this.ensureInit();
|
|
335
|
+
let finalData = data;
|
|
336
|
+
finalData = await (0, server_2.getBrotliCompressed)(finalData, brotliOptions);
|
|
337
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
330
338
|
return apiResponse;
|
|
331
339
|
};
|
|
332
340
|
this.writeFile = async (bucket, key, data, options = {}) => {
|
|
@@ -340,15 +348,23 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
340
348
|
}));
|
|
341
349
|
return apiResponse;
|
|
342
350
|
};
|
|
343
|
-
this.
|
|
351
|
+
this.writeJson = async (bucket, key, data, options = {}) => {
|
|
352
|
+
await this.ensureInit();
|
|
353
|
+
const apiResponse = await this.writeFile(bucket, key, JSON.stringify(data), options);
|
|
354
|
+
return apiResponse;
|
|
355
|
+
};
|
|
356
|
+
this.writeJsonGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
357
|
+
await this.ensureInit();
|
|
358
|
+
let finalData = JSON.stringify(data);
|
|
359
|
+
finalData = await (0, server_2.getGzipCompressed)(finalData, gzipOptions);
|
|
360
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
361
|
+
return apiResponse;
|
|
362
|
+
};
|
|
363
|
+
this.writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
344
364
|
await this.ensureInit();
|
|
345
365
|
let finalData = data;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
// Compress the data
|
|
350
|
-
const gzipData = await (0, server_2.getGzipCompressed)(finalData);
|
|
351
|
-
const apiResponse = await this.writeFile(bucket, key, gzipData, options);
|
|
366
|
+
finalData = await (0, server_2.getGzipCompressed)(finalData, gzipOptions);
|
|
367
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
352
368
|
return apiResponse;
|
|
353
369
|
};
|
|
354
370
|
/**
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { BaseNamespace } from "../../_class";
|
|
2
2
|
import { AwsConfig } from "../server";
|
|
3
|
-
import type { SESClient } from "@aws-sdk/client-ses";
|
|
4
|
-
type SendProps = {
|
|
5
|
-
bcc?: string[];
|
|
6
|
-
cc?: string[];
|
|
7
|
-
from?: string;
|
|
8
|
-
html?: string;
|
|
9
|
-
subject?: string;
|
|
10
|
-
to?: string | string[];
|
|
11
|
-
};
|
|
3
|
+
import type { SendEmailCommandInput, SESClient } from "@aws-sdk/client-ses";
|
|
12
4
|
export declare class AwsSesNamespace extends BaseNamespace {
|
|
13
5
|
client: SESClient | null;
|
|
14
6
|
config: AwsConfig | null;
|
|
15
7
|
ensureInit: () => Promise<void>;
|
|
16
|
-
send: (
|
|
8
|
+
send: (input: SendEmailCommandInput) => Promise<any>;
|
|
17
9
|
}
|
|
18
|
-
export {};
|
|
@@ -49,7 +49,7 @@ class AwsSesNamespace extends _class_1.BaseNamespace {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
this.send = async (
|
|
52
|
+
this.send = async (input) => {
|
|
53
53
|
await this.ensureInit();
|
|
54
54
|
const { SendEmailCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-ses")));
|
|
55
55
|
let response;
|
package/aws/ses/SimpleEmail.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class SimpleEmail extends BaseClass {
|
|
|
27
27
|
setBcc: (recipient: string | string[]) => this;
|
|
28
28
|
setCc: (recipient: string | string[]) => this;
|
|
29
29
|
setTo: (recipient: string | string[]) => this;
|
|
30
|
-
|
|
30
|
+
getSendParam: () => {
|
|
31
31
|
Destination: {
|
|
32
32
|
BccAddresses: string[];
|
|
33
33
|
CcAddresses: string[];
|
package/aws/ses/SimpleEmail.js
CHANGED
|
@@ -42,7 +42,7 @@ class SimpleEmail extends _class_1.BaseClass {
|
|
|
42
42
|
this.setTo = (recipient) => {
|
|
43
43
|
return this._setArray("to", recipient);
|
|
44
44
|
};
|
|
45
|
-
this.
|
|
45
|
+
this.getSendParam = () => {
|
|
46
46
|
// https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/ses-examples-sending-email.html
|
|
47
47
|
const params = {
|
|
48
48
|
Destination: {
|
package/package.json
CHANGED
|
@@ -2,4 +2,4 @@ import { type ZlibOptions } from "zlib";
|
|
|
2
2
|
/**
|
|
3
3
|
* Compress a given input using Gzip.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getGzipCompressed: (input: any, options?: ZlibOptions) => Promise<
|
|
5
|
+
export declare const getGzipCompressed: (input: any, options?: ZlibOptions) => Promise<string>;
|