triangle-utils 1.4.32 → 1.4.34
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/src/UtilsBee.d.ts +2 -2
- package/dist/src/UtilsBee.js +6 -2
- package/dist/src/UtilsMisc.d.ts +0 -4
- package/dist/src/UtilsMisc.js +2 -40
- package/dist/src/UtilsNitter.js +5 -5
- package/dist/src/UtilsSES.js +1 -0
- package/package.json +1 -2
- package/src/UtilsBee.ts +6 -2
- package/src/UtilsMisc.ts +2 -41
- package/src/UtilsNitter.ts +5 -5
- package/src/UtilsSES.ts +1 -0
package/dist/src/UtilsBee.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export declare class UtilsBee {
|
|
|
2
2
|
private readonly bee;
|
|
3
3
|
private readonly text_decoder;
|
|
4
4
|
constructor(scraping_bee_api_key: string | undefined);
|
|
5
|
-
get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Buffer<any> | undefined>;
|
|
6
|
-
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | undefined>;
|
|
5
|
+
get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Error | Buffer<any> | undefined>;
|
|
6
|
+
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | Error | undefined>;
|
|
7
7
|
google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
|
|
8
8
|
youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
|
|
9
9
|
}
|
package/dist/src/UtilsBee.js
CHANGED
|
@@ -22,9 +22,10 @@ export class UtilsBee {
|
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
24
|
if (error instanceof Error) {
|
|
25
|
-
|
|
25
|
+
if ((error.stack || "").includes("Request failed with status code 404")) {
|
|
26
|
+
return new Error("404");
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
|
-
console.log("Failed to get from Scraping Bee.");
|
|
28
29
|
}
|
|
29
30
|
return undefined;
|
|
30
31
|
}
|
|
@@ -33,6 +34,9 @@ export class UtilsBee {
|
|
|
33
34
|
if (buffer === undefined) {
|
|
34
35
|
return undefined;
|
|
35
36
|
}
|
|
37
|
+
if (buffer instanceof Error) {
|
|
38
|
+
return buffer;
|
|
39
|
+
}
|
|
36
40
|
return this.text_decoder.decode(buffer);
|
|
37
41
|
}
|
|
38
42
|
async google_search(query, news = false) {
|
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as nodemailer from "nodemailer";
|
|
2
1
|
import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig.js";
|
|
3
2
|
interface Encryption {
|
|
4
3
|
iv: string;
|
|
@@ -6,10 +5,7 @@ interface Encryption {
|
|
|
6
5
|
}
|
|
7
6
|
export declare class UtilsMisc {
|
|
8
7
|
readonly config: TriangleUtilsConfig;
|
|
9
|
-
readonly transporter: nodemailer.Transporter<import("nodemailer/lib/smtp-transport").SentMessageInfo, import("nodemailer/lib/smtp-transport").Options> | undefined;
|
|
10
8
|
constructor(config: TriangleUtilsConfig);
|
|
11
|
-
send_email(recipient: string, subject: string, text: string): Promise<boolean>;
|
|
12
|
-
admin_alert(text: string): Promise<boolean>;
|
|
13
9
|
safe_run(f: () => Promise<any>): Promise<void>;
|
|
14
10
|
iterate<T>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<any>, num_iterators?: number, print_option?: number | boolean): Promise<void>;
|
|
15
11
|
static wait(duration: number): Promise<unknown>;
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
|
-
import * as nodemailer from "nodemailer";
|
|
2
1
|
import * as crypto from "crypto";
|
|
3
2
|
export class UtilsMisc {
|
|
4
3
|
config;
|
|
5
|
-
transporter;
|
|
6
4
|
constructor(config) {
|
|
7
5
|
this.config = config;
|
|
8
|
-
if (config.google_email !== undefined && config.google_app_password !== undefined) {
|
|
9
|
-
this.transporter = nodemailer.createTransport({
|
|
10
|
-
service: "Gmail",
|
|
11
|
-
host: "smtp.gmail.com",
|
|
12
|
-
port: 465,
|
|
13
|
-
secure: true,
|
|
14
|
-
auth: {
|
|
15
|
-
user: config.google_email,
|
|
16
|
-
pass: config.google_app_password,
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async send_email(recipient, subject, text) {
|
|
22
|
-
if (this.transporter === undefined) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
for (let i = 0; i < 3; i++) {
|
|
26
|
-
try {
|
|
27
|
-
await this.transporter.sendMail({
|
|
28
|
-
from: this.config.alerts_email,
|
|
29
|
-
to: recipient,
|
|
30
|
-
subject: subject,
|
|
31
|
-
text: text
|
|
32
|
-
});
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.log("EMAIL ERROR", error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
async admin_alert(text) {
|
|
42
|
-
console.log("ADMIN ALERT:", text);
|
|
43
|
-
return await this.send_email(this.config.google_email, "ADMIN ALERT", text);
|
|
44
6
|
}
|
|
45
7
|
async safe_run(f) {
|
|
46
8
|
try {
|
|
@@ -51,10 +13,10 @@ export class UtilsMisc {
|
|
|
51
13
|
return;
|
|
52
14
|
}
|
|
53
15
|
if (error.stack !== undefined) {
|
|
54
|
-
|
|
16
|
+
console.log(error.stack.toString());
|
|
55
17
|
}
|
|
56
18
|
else {
|
|
57
|
-
|
|
19
|
+
console.log(error.toString());
|
|
58
20
|
}
|
|
59
21
|
}
|
|
60
22
|
}
|
package/dist/src/UtilsNitter.js
CHANGED
|
@@ -109,13 +109,13 @@ export class UtilsNitter extends UtilsBee {
|
|
|
109
109
|
let nitter_html = undefined;
|
|
110
110
|
for (let i = 0; i < 10; i++) {
|
|
111
111
|
nitter_html = await this.get(nitter_url, { render_js: false });
|
|
112
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
112
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
console.log("Failed to query Nitter, trying again.");
|
|
116
116
|
await UtilsMisc.wait((2 + 2 * i) * 1000);
|
|
117
117
|
}
|
|
118
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
118
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
119
119
|
console.log("Nitter failed for url", nitter_url);
|
|
120
120
|
return [];
|
|
121
121
|
}
|
|
@@ -145,14 +145,14 @@ export class UtilsNitter extends UtilsBee {
|
|
|
145
145
|
let nitter_html = undefined;
|
|
146
146
|
for (let i = 0; i < 10; i++) {
|
|
147
147
|
nitter_html = await this.get(nitter_url, { render_js: false });
|
|
148
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
148
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
151
|
console.log("Failed to query Nitter, trying again.");
|
|
152
152
|
await UtilsMisc.wait((2 + 2 * i) * 1000);
|
|
153
153
|
}
|
|
154
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
155
|
-
console.log("Nitter failed for
|
|
154
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
155
|
+
console.log("Nitter failed for url", nitter_url);
|
|
156
156
|
return [];
|
|
157
157
|
}
|
|
158
158
|
const nitter_data = parse_nitter_html(nitter_html);
|
package/dist/src/UtilsSES.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.34",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"@types/nodemailer": "^7.0.9",
|
|
29
29
|
"googleapis": "^170.0.0",
|
|
30
30
|
"jsdom": "^29.0.1",
|
|
31
|
-
"nodemailer": "^7.0.11",
|
|
32
31
|
"scrapingbee": "^1.8.2"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
package/src/UtilsBee.ts
CHANGED
|
@@ -25,9 +25,10 @@ export class UtilsBee {
|
|
|
25
25
|
return undefined
|
|
26
26
|
} catch (error) {
|
|
27
27
|
if (error instanceof Error) {
|
|
28
|
-
|
|
28
|
+
if ((error.stack || "").includes("Request failed with status code 404")) {
|
|
29
|
+
return new Error("404")
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
|
-
console.log("Failed to get from Scraping Bee.")
|
|
31
32
|
}
|
|
32
33
|
return undefined
|
|
33
34
|
|
|
@@ -38,6 +39,9 @@ export class UtilsBee {
|
|
|
38
39
|
if (buffer === undefined) {
|
|
39
40
|
return undefined
|
|
40
41
|
}
|
|
42
|
+
if (buffer instanceof Error) {
|
|
43
|
+
return buffer
|
|
44
|
+
}
|
|
41
45
|
return this.text_decoder.decode(buffer)
|
|
42
46
|
}
|
|
43
47
|
|
package/src/UtilsMisc.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as nodemailer from "nodemailer"
|
|
2
1
|
import * as crypto from "crypto"
|
|
3
2
|
|
|
4
3
|
import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig"
|
|
@@ -11,47 +10,9 @@ interface Encryption {
|
|
|
11
10
|
export class UtilsMisc {
|
|
12
11
|
|
|
13
12
|
readonly config : TriangleUtilsConfig
|
|
14
|
-
readonly transporter
|
|
15
13
|
|
|
16
14
|
constructor(config : TriangleUtilsConfig) {
|
|
17
15
|
this.config = config
|
|
18
|
-
if (config.google_email !== undefined && config.google_app_password !== undefined) {
|
|
19
|
-
this.transporter = nodemailer.createTransport({
|
|
20
|
-
service: "Gmail",
|
|
21
|
-
host: "smtp.gmail.com",
|
|
22
|
-
port: 465,
|
|
23
|
-
secure: true,
|
|
24
|
-
auth: {
|
|
25
|
-
user: config.google_email,
|
|
26
|
-
pass: config.google_app_password,
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async send_email(recipient : string, subject : string, text : string) : Promise<boolean> {
|
|
33
|
-
if (this.transporter === undefined) {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
for (let i = 0; i < 3; i++) {
|
|
37
|
-
try {
|
|
38
|
-
await this.transporter.sendMail({
|
|
39
|
-
from: this.config.alerts_email,
|
|
40
|
-
to: recipient,
|
|
41
|
-
subject: subject,
|
|
42
|
-
text: text
|
|
43
|
-
})
|
|
44
|
-
return true
|
|
45
|
-
} catch (error) {
|
|
46
|
-
console.log("EMAIL ERROR", error)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async admin_alert(text : string) : Promise<boolean> {
|
|
53
|
-
console.log("ADMIN ALERT:", text)
|
|
54
|
-
return await this.send_email(this.config.google_email, "ADMIN ALERT", text)
|
|
55
16
|
}
|
|
56
17
|
|
|
57
18
|
async safe_run(f : () => Promise<any>) : Promise<void> {
|
|
@@ -62,9 +23,9 @@ export class UtilsMisc {
|
|
|
62
23
|
return
|
|
63
24
|
}
|
|
64
25
|
if (error.stack !== undefined) {
|
|
65
|
-
|
|
26
|
+
console.log(error.stack.toString())
|
|
66
27
|
} else {
|
|
67
|
-
|
|
28
|
+
console.log(error.toString())
|
|
68
29
|
}
|
|
69
30
|
}
|
|
70
31
|
}
|
package/src/UtilsNitter.ts
CHANGED
|
@@ -121,13 +121,13 @@ export class UtilsNitter extends UtilsBee {
|
|
|
121
121
|
let nitter_html = undefined
|
|
122
122
|
for (let i = 0; i < 10; i++) {
|
|
123
123
|
nitter_html = await this.get(nitter_url, { render_js : false })
|
|
124
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
124
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
125
125
|
break
|
|
126
126
|
}
|
|
127
127
|
console.log("Failed to query Nitter, trying again.")
|
|
128
128
|
await UtilsMisc.wait((2 + 2 * i) * 1000)
|
|
129
129
|
}
|
|
130
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
130
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
131
131
|
console.log("Nitter failed for url", nitter_url)
|
|
132
132
|
return []
|
|
133
133
|
}
|
|
@@ -159,14 +159,14 @@ export class UtilsNitter extends UtilsBee {
|
|
|
159
159
|
let nitter_html = undefined
|
|
160
160
|
for (let i = 0; i < 10; i++) {
|
|
161
161
|
nitter_html = await this.get(nitter_url, { render_js : false })
|
|
162
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
162
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
163
163
|
break
|
|
164
164
|
}
|
|
165
165
|
console.log("Failed to query Nitter, trying again.")
|
|
166
166
|
await UtilsMisc.wait((2 + 2 * i) * 1000)
|
|
167
167
|
}
|
|
168
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
169
|
-
console.log("Nitter failed for
|
|
168
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
169
|
+
console.log("Nitter failed for url", nitter_url)
|
|
170
170
|
return []
|
|
171
171
|
}
|
|
172
172
|
const nitter_data = parse_nitter_html(nitter_html)
|