triangle-utils 1.4.29 → 1.4.31

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.
@@ -11,7 +11,7 @@ export declare class UtilsMisc {
11
11
  send_email(recipient: string, subject: string, text: string): Promise<boolean>;
12
12
  admin_alert(text: string): Promise<boolean>;
13
13
  safe_run(f: () => Promise<any>): Promise<void>;
14
- iterate<T>(inputs: T[], f: (input: T, iterator_id: number) => Promise<any>, num_iterators?: number, print_indices?: boolean): Promise<void>;
14
+ iterate<T>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<any>, num_iterators?: number, print_option?: number | boolean): Promise<void>;
15
15
  static wait(duration: number): Promise<unknown>;
16
16
  static get_current_time(): string;
17
17
  static get_current_milliseconds(): number;
@@ -58,17 +58,18 @@ export class UtilsMisc {
58
58
  }
59
59
  }
60
60
  }
61
- async iterate(inputs, f, num_iterators = 1, print_indices = false) {
61
+ async iterate(inputs, f, num_iterators = 1, print_option) {
62
+ const print_freq = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option;
62
63
  let index = 0;
63
64
  let iterators = [];
64
- for (let i = 0; i < num_iterators; i++) {
65
+ for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
65
66
  iterators.push((async () => {
66
67
  while (index < inputs.length) {
67
68
  index += 1;
68
- if (print_indices) {
69
- console.log(i + ":" + (index - 1) + "/" + inputs.length);
69
+ if (print_freq !== undefined && (index % print_freq === 0)) {
70
+ console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length);
70
71
  }
71
- await this.safe_run(() => f(inputs[index - 1], i));
72
+ await this.safe_run(() => f(inputs[index - 1], iterator_id, index));
72
73
  }
73
74
  })());
74
75
  }
@@ -0,0 +1,5 @@
1
+ export declare class UtilsSES {
2
+ private readonly ses;
3
+ constructor(region: string);
4
+ send_email(recipient: string, subject: string, text: string): Promise<void>;
5
+ }
@@ -0,0 +1,30 @@
1
+ import { SES } from "@aws-sdk/client-ses";
2
+ export class UtilsSES {
3
+ ses;
4
+ constructor(region) {
5
+ this.ses = new SES({ region: region });
6
+ }
7
+ async send_email(recipient, subject, text) {
8
+ const sender = "no-reply@triangleanalytics.com";
9
+ await this.ses.sendEmail({
10
+ Source: sender,
11
+ Destination: {
12
+ ToAddresses: [
13
+ recipient
14
+ ]
15
+ },
16
+ Message: {
17
+ Subject: {
18
+ Charset: "UTF-8",
19
+ Data: subject
20
+ },
21
+ Body: {
22
+ Text: {
23
+ Charset: "UTF-8",
24
+ Data: text
25
+ }
26
+ }
27
+ }
28
+ });
29
+ }
30
+ }
@@ -5,6 +5,7 @@ import { UtilsBedrock } from "./UtilsBedrock.js";
5
5
  import { UtilsBee } from "./UtilsBee.js";
6
6
  import { UtilsS3Vectors } from "./UtilsS3Vectors.js";
7
7
  import { UtilsCognito } from "./UtilsCognito.js";
8
+ import { UtilsSES } from "./UtilsSES.js";
8
9
  import { UtilsMisc } from "./UtilsMisc.js";
9
10
  import { UtilsYoutube } from "./UtilsYoutube.js";
10
11
  import { UtilsXAI } from "./UtilsXAI.js";
@@ -15,6 +16,7 @@ export declare class TriangleUtils extends UtilsMisc {
15
16
  readonly s3vectors: UtilsS3Vectors;
16
17
  readonly bedrock: UtilsBedrock;
17
18
  readonly cognito: UtilsCognito;
19
+ readonly ses: UtilsSES;
18
20
  readonly bee: UtilsBee;
19
21
  readonly youtube: UtilsYoutube;
20
22
  readonly xai: UtilsXAI;
@@ -29,6 +31,7 @@ export * from "./UtilsBedrock.js";
29
31
  export * from "./UtilsBee.js";
30
32
  export * from "./UtilsCognito.js";
31
33
  export * from "./UtilsS3Vectors.js";
34
+ export * from "./UtilsSES.js";
32
35
  export * from "./UtilsNitter.js";
33
36
  export * from "./UtilsXAI.js";
34
37
  export * from "./UtilsYoutube.js";
package/dist/src/index.js CHANGED
@@ -4,6 +4,7 @@ import { UtilsBedrock } from "./UtilsBedrock.js";
4
4
  import { UtilsBee } from "./UtilsBee.js";
5
5
  import { UtilsS3Vectors } from "./UtilsS3Vectors.js";
6
6
  import { UtilsCognito } from "./UtilsCognito.js";
7
+ import { UtilsSES } from "./UtilsSES.js";
7
8
  import { UtilsMisc } from "./UtilsMisc.js";
8
9
  import { UtilsYoutube } from "./UtilsYoutube.js";
9
10
  import { UtilsXAI } from "./UtilsXAI.js";
@@ -14,6 +15,7 @@ export class TriangleUtils extends UtilsMisc {
14
15
  s3vectors;
15
16
  bedrock;
16
17
  cognito;
18
+ ses;
17
19
  bee;
18
20
  youtube;
19
21
  xai;
@@ -25,6 +27,7 @@ export class TriangleUtils extends UtilsMisc {
25
27
  this.s3vectors = new UtilsS3Vectors(config.region);
26
28
  this.bedrock = new UtilsBedrock(config.region);
27
29
  this.cognito = new UtilsCognito(config.region);
30
+ this.ses = new UtilsSES(config.region);
28
31
  this.bee = new UtilsBee(config.scraping_bee_api_key);
29
32
  this.youtube = new UtilsYoutube(config.youtube_api_key);
30
33
  this.xai = new UtilsXAI(config.xai_api_key);
@@ -39,6 +42,7 @@ export * from "./UtilsBedrock.js";
39
42
  export * from "./UtilsBee.js";
40
43
  export * from "./UtilsCognito.js";
41
44
  export * from "./UtilsS3Vectors.js";
45
+ export * from "./UtilsSES.js";
42
46
  export * from "./UtilsNitter.js";
43
47
  export * from "./UtilsXAI.js";
44
48
  export * from "./UtilsYoutube.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.29",
3
+ "version": "1.4.31",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -21,6 +21,7 @@
21
21
  "@aws-sdk/client-s3": "^3.953.0",
22
22
  "@aws-sdk/client-s3vectors": "^3.953.0",
23
23
  "@aws-sdk/client-secrets-manager": "^3.965.0",
24
+ "@aws-sdk/client-ses": "^3.1032.0",
24
25
  "@aws-sdk/s3-request-presigner": "^3.953.0",
25
26
  "@types/jsdom": "^28.0.1",
26
27
  "@types/node": "^25.2.3",
package/src/UtilsMisc.ts CHANGED
@@ -69,17 +69,18 @@ export class UtilsMisc {
69
69
  }
70
70
  }
71
71
 
72
- async iterate<T>(inputs : T[], f : (input : T, iterator_id : number) => Promise<any>, num_iterators : number = 1, print_indices : boolean = false) {
72
+ async iterate<T>(inputs : T[], f : (input : T, iterator_id : number, index : number) => Promise<any>, num_iterators : number = 1, print_option? : number | boolean) {
73
+ const print_freq : number | undefined = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option
73
74
  let index = 0
74
75
  let iterators = []
75
- for (let i = 0; i < num_iterators; i++) {
76
+ for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
76
77
  iterators.push((async () => {
77
78
  while (index < inputs.length) {
78
79
  index += 1
79
- if (print_indices) {
80
- console.log(i + ":" + (index - 1) + "/" + inputs.length)
80
+ if (print_freq !== undefined && (index % print_freq === 0)) {
81
+ console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length)
81
82
  }
82
- await this.safe_run(() => f(inputs[index - 1], i))
83
+ await this.safe_run(() => f(inputs[index - 1], iterator_id, index))
83
84
  }
84
85
  })())
85
86
  }
@@ -0,0 +1,35 @@
1
+ import { SES } from "@aws-sdk/client-ses"
2
+
3
+ export class UtilsSES {
4
+
5
+ private readonly ses : SES
6
+
7
+ constructor(region : string) {
8
+ this.ses = new SES({ region : region })
9
+ }
10
+
11
+ async send_email(recipient : string, subject : string, text : string) {
12
+ const sender : string = "no-reply@triangleanalytics.com"
13
+ await this.ses.sendEmail({
14
+ Source : sender,
15
+ Destination : {
16
+ ToAddresses : [
17
+ recipient
18
+ ]
19
+ },
20
+ Message : {
21
+ Subject : {
22
+ Charset : "UTF-8",
23
+ Data : subject
24
+ },
25
+ Body : {
26
+ Text : {
27
+ Charset : "UTF-8",
28
+ Data : text
29
+ }
30
+ }
31
+ }
32
+ })
33
+ }
34
+
35
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { UtilsBedrock } from "./UtilsBedrock"
5
5
  import { UtilsBee } from "./UtilsBee"
6
6
  import { UtilsS3Vectors } from "./UtilsS3Vectors"
7
7
  import { UtilsCognito } from "./UtilsCognito"
8
+ import { UtilsSES } from "./UtilsSES"
8
9
  import { UtilsMisc } from "./UtilsMisc"
9
10
  import { UtilsYoutube } from "./UtilsYoutube"
10
11
  import { UtilsXAI } from "./UtilsXAI"
@@ -19,6 +20,7 @@ export class TriangleUtils extends UtilsMisc {
19
20
  readonly s3vectors : UtilsS3Vectors
20
21
  readonly bedrock : UtilsBedrock
21
22
  readonly cognito : UtilsCognito
23
+ readonly ses : UtilsSES
22
24
  readonly bee : UtilsBee
23
25
  readonly youtube : UtilsYoutube
24
26
  readonly xai : UtilsXAI
@@ -31,6 +33,7 @@ export class TriangleUtils extends UtilsMisc {
31
33
  this.s3vectors = new UtilsS3Vectors(config.region)
32
34
  this.bedrock = new UtilsBedrock(config.region)
33
35
  this.cognito = new UtilsCognito(config.region)
36
+ this.ses = new UtilsSES(config.region)
34
37
  this.bee = new UtilsBee(config.scraping_bee_api_key)
35
38
  this.youtube = new UtilsYoutube(config.youtube_api_key)
36
39
  this.xai = new UtilsXAI(config.xai_api_key)
@@ -46,6 +49,7 @@ export * from "./UtilsBedrock"
46
49
  export * from "./UtilsBee"
47
50
  export * from "./UtilsCognito"
48
51
  export * from "./UtilsS3Vectors"
52
+ export * from "./UtilsSES"
49
53
  export * from "./UtilsNitter"
50
54
  export * from "./UtilsXAI"
51
55
  export * from "./UtilsYoutube"