triangle-utils 1.4.165 → 1.4.167

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.
@@ -0,0 +1,14 @@
1
+ export declare class UtilsBrave {
2
+ private readonly brave_api_key?;
3
+ constructor(brave_api_key: string | undefined);
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>;
14
+ }
@@ -0,0 +1,70 @@
1
+ export class UtilsBrave {
2
+ brave_api_key;
3
+ constructor(brave_api_key) {
4
+ this.brave_api_key = brave_api_key;
5
+ }
6
+ async web_search(q, options = {}) {
7
+ const verbosity = options.verbosity || 0;
8
+ if (this.brave_api_key === undefined) {
9
+ return undefined;
10
+ }
11
+ try {
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, {
18
+ headers: {
19
+ "X-Subscription-Token": this.brave_api_key
20
+ }
21
+ });
22
+ if (!response.ok) {
23
+ console.log("Failed to Brave:", response.status);
24
+ return;
25
+ }
26
+ const body = await response.json();
27
+ const results = body.web.results;
28
+ if (!Array.isArray(results)) {
29
+ return undefined;
30
+ }
31
+ return body.results;
32
+ }
33
+ catch (error) {
34
+ console.log("Failed to Brave:", error.stack);
35
+ }
36
+ return undefined;
37
+ }
38
+ async news_search(q, options = {}) {
39
+ const verbosity = options.verbosity || 0;
40
+ if (this.brave_api_key === undefined) {
41
+ return undefined;
42
+ }
43
+ try {
44
+ const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined;
45
+ const url = "https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "");
46
+ if (verbosity > 0) {
47
+ console.log(url);
48
+ }
49
+ const response = await fetch(url, {
50
+ headers: {
51
+ "X-Subscription-Token": this.brave_api_key
52
+ }
53
+ });
54
+ if (!response.ok) {
55
+ console.log("Failed to Brave:", response.status);
56
+ return;
57
+ }
58
+ const body = await response.json();
59
+ const results = body.results;
60
+ if (!Array.isArray(results)) {
61
+ return undefined;
62
+ }
63
+ return body.results;
64
+ }
65
+ catch (error) {
66
+ console.log("Failed to Brave:", error.stack);
67
+ }
68
+ return undefined;
69
+ }
70
+ }
package/dist/src/f.js CHANGED
@@ -83,3 +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.news_search("abdul el sayed", { min_date: "2026-09-03", max_date: "2026-09-05" })
87
+ .then(console.log);
@@ -14,6 +14,7 @@ import { GlobalConfig } from "./types/GlobalConfig.js";
14
14
  import { UtilsRDS } from "./UtilsRDS.js";
15
15
  import { ApplicationConfig } from "./types/ApplicationConfig.js";
16
16
  import { UtilsTextract } from "./UtilsTextract.js";
17
+ import { UtilsBrave } from "./UtilsBrave.js";
17
18
  export declare class TriangleUtils extends UtilsMisc {
18
19
  readonly dynamodb: UtilsDynamoDB;
19
20
  readonly rds: UtilsRDS;
@@ -24,6 +25,7 @@ export declare class TriangleUtils extends UtilsMisc {
24
25
  readonly cognito: UtilsCognito;
25
26
  readonly ses: UtilsSES;
26
27
  readonly bee: UtilsBee;
28
+ readonly brave: UtilsBrave;
27
29
  readonly youtube: UtilsYoutube;
28
30
  readonly anthropic: UtilsAnthropic;
29
31
  readonly xai: UtilsXAI;
package/dist/src/index.js CHANGED
@@ -12,6 +12,7 @@ import { UtilsAnthropic } from "./UtilsAnthropic.js";
12
12
  import { UtilsTwitter } from "./UtilsTwitter.js";
13
13
  import { UtilsRDS } from "./UtilsRDS.js";
14
14
  import { UtilsTextract } from "./UtilsTextract.js";
15
+ import { UtilsBrave } from "./UtilsBrave.js";
15
16
  export class TriangleUtils extends UtilsMisc {
16
17
  dynamodb;
17
18
  rds;
@@ -22,6 +23,7 @@ export class TriangleUtils extends UtilsMisc {
22
23
  cognito;
23
24
  ses;
24
25
  bee;
26
+ brave;
25
27
  youtube;
26
28
  anthropic;
27
29
  xai;
@@ -37,6 +39,7 @@ export class TriangleUtils extends UtilsMisc {
37
39
  this.cognito = new UtilsCognito(config.region);
38
40
  this.ses = new UtilsSES(config.region);
39
41
  this.bee = new UtilsBee(config.scraping_bee_api_key);
42
+ this.brave = new UtilsBrave(config.brave_api_key);
40
43
  this.youtube = new UtilsYoutube(config.youtube_api_key);
41
44
  this.anthropic = new UtilsAnthropic(config.anthropic_api_key);
42
45
  this.xai = new UtilsXAI(config.xai_api_key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.165",
3
+ "version": "1.4.167",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -0,0 +1,80 @@
1
+ export class UtilsBrave {
2
+
3
+ private readonly brave_api_key? : string
4
+
5
+ constructor(brave_api_key : string | undefined) {
6
+ this.brave_api_key = brave_api_key
7
+ }
8
+
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
15
+ if (this.brave_api_key === undefined) {
16
+ return undefined
17
+ }
18
+ try {
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, {
25
+ headers : {
26
+ "X-Subscription-Token" : this.brave_api_key
27
+ }
28
+ })
29
+ if (!response.ok) {
30
+ console.log("Failed to Brave:", response.status)
31
+ return
32
+ }
33
+ const body : any = await response.json()
34
+ const results = body.web.results
35
+ if (!Array.isArray(results)) {
36
+ return undefined
37
+ }
38
+ return body.results
39
+ } catch (error : any) {
40
+ console.log("Failed to Brave:", error.stack)
41
+ }
42
+ return undefined
43
+ }
44
+
45
+ async news_search(q : string, options : {
46
+ min_date? : string,
47
+ max_date? : string,
48
+ verbosity? : number
49
+ } = {}) : Promise<Record<string, any>[] | undefined> {
50
+ const verbosity = options.verbosity || 0
51
+ if (this.brave_api_key === undefined) {
52
+ return undefined
53
+ }
54
+ try {
55
+ const freshness = options.min_date !== undefined && options.max_date !== undefined ? (options.min_date + "to" + options.max_date) : undefined
56
+ const url = "https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q) + (freshness !== undefined ? ("&freshness=" + freshness) : "")
57
+ if (verbosity > 0) {
58
+ console.log(url)
59
+ }
60
+ const response = await fetch(url, {
61
+ headers : {
62
+ "X-Subscription-Token" : this.brave_api_key
63
+ }
64
+ })
65
+ if (!response.ok) {
66
+ console.log("Failed to Brave:", response.status)
67
+ return
68
+ }
69
+ const body : any = await response.json()
70
+ const results = body.results
71
+ if (!Array.isArray(results)) {
72
+ return undefined
73
+ }
74
+ return body.results
75
+ } catch (error : any) {
76
+ console.log("Failed to Brave:", error.stack)
77
+ }
78
+ return undefined
79
+ }
80
+ }
package/src/f.ts CHANGED
@@ -105,3 +105,7 @@ const utils = new TriangleUtils(config)
105
105
 
106
106
  // 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" })
107
107
  // .then(response => console.log(response))
108
+
109
+
110
+ await utils.brave.news_search("abdul el sayed", { min_date : "2026-09-03", max_date : "2026-09-05" })
111
+ .then(console.log)
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import { GlobalConfig } from "./types/GlobalConfig"
14
14
  import { UtilsRDS } from "./UtilsRDS"
15
15
  import { ApplicationConfig } from "./types/ApplicationConfig"
16
16
  import { UtilsTextract } from "./UtilsTextract"
17
+ import { UtilsBrave } from "./UtilsBrave"
17
18
 
18
19
 
19
20
 
@@ -28,6 +29,7 @@ export class TriangleUtils extends UtilsMisc {
28
29
  readonly cognito : UtilsCognito
29
30
  readonly ses : UtilsSES
30
31
  readonly bee : UtilsBee
32
+ readonly brave : UtilsBrave
31
33
  readonly youtube : UtilsYoutube
32
34
  readonly anthropic : UtilsAnthropic
33
35
  readonly xai : UtilsXAI
@@ -44,6 +46,7 @@ export class TriangleUtils extends UtilsMisc {
44
46
  this.cognito = new UtilsCognito(config.region)
45
47
  this.ses = new UtilsSES(config.region)
46
48
  this.bee = new UtilsBee(config.scraping_bee_api_key)
49
+ this.brave = new UtilsBrave(config.brave_api_key)
47
50
  this.youtube = new UtilsYoutube(config.youtube_api_key)
48
51
  this.anthropic = new UtilsAnthropic(config.anthropic_api_key)
49
52
  this.xai = new UtilsXAI(config.xai_api_key)