triangle-utils 1.4.166 → 1.4.168
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/UtilsBrave.d.ts +10 -2
- package/dist/src/UtilsBrave.js +24 -6
- package/dist/src/f.js +2 -1
- package/package.json +3 -2
- package/src/UtilsBrave.ts +32 -6
- package/src/f.ts +2 -1
package/dist/src/UtilsBrave.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export declare class UtilsBrave {
|
|
2
2
|
private readonly brave_api_key?;
|
|
3
3
|
constructor(brave_api_key: string | undefined);
|
|
4
|
-
web_search(q: string
|
|
5
|
-
|
|
4
|
+
web_search(q: string, options?: {
|
|
5
|
+
min_date?: string;
|
|
6
|
+
max_date?: string;
|
|
7
|
+
verbosity?: number;
|
|
8
|
+
}): Promise<Record<string, any>[] | undefined>;
|
|
9
|
+
news_search(q: string, options?: {
|
|
10
|
+
min_date?: string;
|
|
11
|
+
max_date?: string;
|
|
12
|
+
verbosity?: number;
|
|
13
|
+
}): Promise<Record<string, any>[] | undefined>;
|
|
6
14
|
}
|
package/dist/src/UtilsBrave.js
CHANGED
|
@@ -3,12 +3,18 @@ export class UtilsBrave {
|
|
|
3
3
|
constructor(brave_api_key) {
|
|
4
4
|
this.brave_api_key = brave_api_key;
|
|
5
5
|
}
|
|
6
|
-
async web_search(q) {
|
|
6
|
+
async web_search(q, options = {}) {
|
|
7
|
+
const verbosity = options.verbosity || 0;
|
|
7
8
|
if (this.brave_api_key === undefined) {
|
|
8
9
|
return undefined;
|
|
9
10
|
}
|
|
10
11
|
try {
|
|
11
|
-
const
|
|
12
|
+
const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined;
|
|
13
|
+
const url = "https://api.search.brave.com/res/v1/web/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "");
|
|
14
|
+
if (verbosity > 0) {
|
|
15
|
+
console.log(url);
|
|
16
|
+
}
|
|
17
|
+
const response = await fetch(url, {
|
|
12
18
|
headers: {
|
|
13
19
|
"X-Subscription-Token": this.brave_api_key
|
|
14
20
|
}
|
|
@@ -18,7 +24,10 @@ export class UtilsBrave {
|
|
|
18
24
|
return;
|
|
19
25
|
}
|
|
20
26
|
const body = await response.json();
|
|
21
|
-
|
|
27
|
+
if (verbosity > 1) {
|
|
28
|
+
console.log(JSON.stringify(body, undefined, 4));
|
|
29
|
+
}
|
|
30
|
+
const results = body.web?.results;
|
|
22
31
|
if (!Array.isArray(results)) {
|
|
23
32
|
return undefined;
|
|
24
33
|
}
|
|
@@ -29,12 +38,18 @@ export class UtilsBrave {
|
|
|
29
38
|
}
|
|
30
39
|
return undefined;
|
|
31
40
|
}
|
|
32
|
-
async news_search(q) {
|
|
41
|
+
async news_search(q, options = {}) {
|
|
42
|
+
const verbosity = options.verbosity || 0;
|
|
33
43
|
if (this.brave_api_key === undefined) {
|
|
34
44
|
return undefined;
|
|
35
45
|
}
|
|
36
46
|
try {
|
|
37
|
-
const
|
|
47
|
+
const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined;
|
|
48
|
+
const url = "https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "");
|
|
49
|
+
if (verbosity > 0) {
|
|
50
|
+
console.log(url);
|
|
51
|
+
}
|
|
52
|
+
const response = await fetch(url, {
|
|
38
53
|
headers: {
|
|
39
54
|
"X-Subscription-Token": this.brave_api_key
|
|
40
55
|
}
|
|
@@ -44,7 +59,10 @@ export class UtilsBrave {
|
|
|
44
59
|
return;
|
|
45
60
|
}
|
|
46
61
|
const body = await response.json();
|
|
47
|
-
|
|
62
|
+
if (verbosity > 1) {
|
|
63
|
+
console.log(JSON.stringify(body, undefined, 4));
|
|
64
|
+
}
|
|
65
|
+
const results = body?.results;
|
|
48
66
|
if (!Array.isArray(results)) {
|
|
49
67
|
return undefined;
|
|
50
68
|
}
|
package/dist/src/f.js
CHANGED
|
@@ -83,4 +83,5 @@ const utils = new TriangleUtils(config);
|
|
|
83
83
|
// .then(response => console.log(response))
|
|
84
84
|
// await utils.s3.get_download_url("s3://triangle-675045717295-us-east-1-an/tenant_documents/a3a9627f-a94d-4d47-a110-307a6f5563af/a146d789-da40-4e3c-a132-8b7110f3f7df.pdf", { name : "hye.pdf" })
|
|
85
85
|
// .then(response => console.log(response))
|
|
86
|
-
await utils.brave.web_search("
|
|
86
|
+
await utils.brave.web_search("press releases site:https://cohen.house.gov/", { min_date: "2026-09-03", max_date: "2026-09-05" })
|
|
87
|
+
.then(console.log);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.168",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"googleapis": "^170.0.0",
|
|
39
39
|
"jsdom": "^29.0.1",
|
|
40
40
|
"pg": "^8.23.0",
|
|
41
|
-
"scrapingbee": "^1.8.2"
|
|
41
|
+
"scrapingbee": "^1.8.2",
|
|
42
|
+
"triangle-types": "^1.0.259"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@eslint/js": "^9.39.2",
|
package/src/UtilsBrave.ts
CHANGED
|
@@ -6,12 +6,22 @@ export class UtilsBrave {
|
|
|
6
6
|
this.brave_api_key = brave_api_key
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
async web_search(q : string
|
|
9
|
+
async web_search(q : string, options : {
|
|
10
|
+
min_date? : string,
|
|
11
|
+
max_date? : string,
|
|
12
|
+
verbosity? : number
|
|
13
|
+
} = {}) : Promise<Record<string, any>[] | undefined> {
|
|
14
|
+
const verbosity = options.verbosity || 0
|
|
10
15
|
if (this.brave_api_key === undefined) {
|
|
11
16
|
return undefined
|
|
12
17
|
}
|
|
13
18
|
try {
|
|
14
|
-
const
|
|
19
|
+
const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined
|
|
20
|
+
const url = "https://api.search.brave.com/res/v1/web/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "")
|
|
21
|
+
if (verbosity > 0) {
|
|
22
|
+
console.log(url)
|
|
23
|
+
}
|
|
24
|
+
const response = await fetch(url, {
|
|
15
25
|
headers : {
|
|
16
26
|
"X-Subscription-Token" : this.brave_api_key
|
|
17
27
|
}
|
|
@@ -21,7 +31,10 @@ export class UtilsBrave {
|
|
|
21
31
|
return
|
|
22
32
|
}
|
|
23
33
|
const body : any = await response.json()
|
|
24
|
-
|
|
34
|
+
if (verbosity > 1) {
|
|
35
|
+
console.log(JSON.stringify(body, undefined, 4))
|
|
36
|
+
}
|
|
37
|
+
const results = body.web?.results
|
|
25
38
|
if (!Array.isArray(results)) {
|
|
26
39
|
return undefined
|
|
27
40
|
}
|
|
@@ -32,12 +45,22 @@ export class UtilsBrave {
|
|
|
32
45
|
return undefined
|
|
33
46
|
}
|
|
34
47
|
|
|
35
|
-
async news_search(q : string
|
|
48
|
+
async news_search(q : string, options : {
|
|
49
|
+
min_date? : string,
|
|
50
|
+
max_date? : string,
|
|
51
|
+
verbosity? : number
|
|
52
|
+
} = {}) : Promise<Record<string, any>[] | undefined> {
|
|
53
|
+
const verbosity = options.verbosity || 0
|
|
36
54
|
if (this.brave_api_key === undefined) {
|
|
37
55
|
return undefined
|
|
38
56
|
}
|
|
39
57
|
try {
|
|
40
|
-
const
|
|
58
|
+
const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined
|
|
59
|
+
const url = "https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "")
|
|
60
|
+
if (verbosity > 0) {
|
|
61
|
+
console.log(url)
|
|
62
|
+
}
|
|
63
|
+
const response = await fetch(url, {
|
|
41
64
|
headers : {
|
|
42
65
|
"X-Subscription-Token" : this.brave_api_key
|
|
43
66
|
}
|
|
@@ -47,7 +70,10 @@ export class UtilsBrave {
|
|
|
47
70
|
return
|
|
48
71
|
}
|
|
49
72
|
const body : any = await response.json()
|
|
50
|
-
|
|
73
|
+
if (verbosity > 1) {
|
|
74
|
+
console.log(JSON.stringify(body, undefined, 4))
|
|
75
|
+
}
|
|
76
|
+
const results = body?.results
|
|
51
77
|
if (!Array.isArray(results)) {
|
|
52
78
|
return undefined
|
|
53
79
|
}
|
package/src/f.ts
CHANGED
|
@@ -107,4 +107,5 @@ const utils = new TriangleUtils(config)
|
|
|
107
107
|
// .then(response => console.log(response))
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
await utils.brave.web_search("
|
|
110
|
+
await utils.brave.web_search("press releases site:https://cohen.house.gov/", { min_date : "2026-09-03", max_date : "2026-09-05" })
|
|
111
|
+
.then(console.log)
|