triangle-utils 1.4.164 → 1.4.166

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,6 @@
1
+ export declare class UtilsBrave {
2
+ private readonly brave_api_key?;
3
+ constructor(brave_api_key: string | undefined);
4
+ web_search(q: string): Promise<Record<string, any>[] | undefined>;
5
+ news_search(q: string): Promise<Record<string, any>[] | undefined>;
6
+ }
@@ -0,0 +1,58 @@
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) {
7
+ if (this.brave_api_key === undefined) {
8
+ return undefined;
9
+ }
10
+ try {
11
+ const response = await fetch("https://api.search.brave.com/res/v1/web/search?q=" + encodeURIComponent(q), {
12
+ headers: {
13
+ "X-Subscription-Token": this.brave_api_key
14
+ }
15
+ });
16
+ if (!response.ok) {
17
+ console.log("Failed to Brave:", response.status);
18
+ return;
19
+ }
20
+ const body = await response.json();
21
+ const results = body.web.results;
22
+ if (!Array.isArray(results)) {
23
+ return undefined;
24
+ }
25
+ return body.results;
26
+ }
27
+ catch (error) {
28
+ console.log("Failed to Brave:", error.stack);
29
+ }
30
+ return undefined;
31
+ }
32
+ async news_search(q) {
33
+ if (this.brave_api_key === undefined) {
34
+ return undefined;
35
+ }
36
+ try {
37
+ const response = await fetch("https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q), {
38
+ headers: {
39
+ "X-Subscription-Token": this.brave_api_key
40
+ }
41
+ });
42
+ if (!response.ok) {
43
+ console.log("Failed to Brave:", response.status);
44
+ return;
45
+ }
46
+ const body = await response.json();
47
+ const results = body.results;
48
+ if (!Array.isArray(results)) {
49
+ return undefined;
50
+ }
51
+ return body.results;
52
+ }
53
+ catch (error) {
54
+ console.log("Failed to Brave:", error.stack);
55
+ }
56
+ return undefined;
57
+ }
58
+ }
package/dist/src/f.js CHANGED
@@ -83,3 +83,4 @@ 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("john cornyn");
@@ -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);
@@ -22,6 +22,7 @@ export declare class GlobalConfig {
22
22
  readonly youtube_api_key: string;
23
23
  readonly xai_api_key: string;
24
24
  readonly ballotpedia_api_key: string;
25
+ readonly brave_api_key: string;
25
26
  readonly [x: string]: any;
26
27
  constructor(global_config: GlobalConfig);
27
28
  static is(global_config: any): global_config is GlobalConfig;
@@ -22,6 +22,7 @@ export class GlobalConfig {
22
22
  youtube_api_key;
23
23
  xai_api_key;
24
24
  ballotpedia_api_key;
25
+ brave_api_key;
25
26
  constructor(global_config) {
26
27
  if (!GlobalConfig.is(global_config)) {
27
28
  throw Error("Invalid input.");
@@ -49,6 +50,7 @@ export class GlobalConfig {
49
50
  this.youtube_api_key = global_config.youtube_api_key;
50
51
  this.xai_api_key = global_config.xai_api_key;
51
52
  this.ballotpedia_api_key = global_config.ballotpedia_api_key;
53
+ this.brave_api_key = global_config.brave_api_key;
52
54
  }
53
55
  static is(global_config) {
54
56
  return (global_config !== undefined &&
@@ -74,6 +76,7 @@ export class GlobalConfig {
74
76
  typeof global_config.twitter_api_key === "string" &&
75
77
  typeof global_config.youtube_api_key === "string" &&
76
78
  typeof global_config.xai_api_key === "string" &&
77
- typeof global_config.ballotpedia_api_key === "string");
79
+ typeof global_config.ballotpedia_api_key === "string" &&
80
+ typeof global_config.brave_api_key === "string");
78
81
  }
79
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.164",
3
+ "version": "1.4.166",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -0,0 +1,60 @@
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) : Promise<Record<string, any>[] | undefined> {
10
+ if (this.brave_api_key === undefined) {
11
+ return undefined
12
+ }
13
+ try {
14
+ const response = await fetch("https://api.search.brave.com/res/v1/web/search?q=" + encodeURIComponent(q), {
15
+ headers : {
16
+ "X-Subscription-Token" : this.brave_api_key
17
+ }
18
+ })
19
+ if (!response.ok) {
20
+ console.log("Failed to Brave:", response.status)
21
+ return
22
+ }
23
+ const body : any = await response.json()
24
+ const results = body.web.results
25
+ if (!Array.isArray(results)) {
26
+ return undefined
27
+ }
28
+ return body.results
29
+ } catch (error : any) {
30
+ console.log("Failed to Brave:", error.stack)
31
+ }
32
+ return undefined
33
+ }
34
+
35
+ async news_search(q : string) : Promise<Record<string, any>[] | undefined> {
36
+ if (this.brave_api_key === undefined) {
37
+ return undefined
38
+ }
39
+ try {
40
+ const response = await fetch("https://api.search.brave.com/res/v1/news/search?q=" + encodeURIComponent(q), {
41
+ headers : {
42
+ "X-Subscription-Token" : this.brave_api_key
43
+ }
44
+ })
45
+ if (!response.ok) {
46
+ console.log("Failed to Brave:", response.status)
47
+ return
48
+ }
49
+ const body : any = await response.json()
50
+ const results = body.results
51
+ if (!Array.isArray(results)) {
52
+ return undefined
53
+ }
54
+ return body.results
55
+ } catch (error : any) {
56
+ console.log("Failed to Brave:", error.stack)
57
+ }
58
+ return undefined
59
+ }
60
+ }
package/src/f.ts CHANGED
@@ -105,3 +105,6 @@ 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.web_search("john cornyn")
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)
@@ -22,6 +22,7 @@ export class GlobalConfig {
22
22
  readonly youtube_api_key : string
23
23
  readonly xai_api_key : string
24
24
  readonly ballotpedia_api_key : string
25
+ readonly brave_api_key : string
25
26
  readonly [x : string] : any
26
27
 
27
28
  constructor(global_config : GlobalConfig) {
@@ -51,6 +52,7 @@ export class GlobalConfig {
51
52
  this.youtube_api_key = global_config.youtube_api_key
52
53
  this.xai_api_key = global_config.xai_api_key
53
54
  this.ballotpedia_api_key = global_config.ballotpedia_api_key
55
+ this.brave_api_key = global_config.brave_api_key
54
56
  }
55
57
 
56
58
  static is(global_config : any) : global_config is GlobalConfig {
@@ -78,7 +80,8 @@ export class GlobalConfig {
78
80
  typeof global_config.twitter_api_key === "string" &&
79
81
  typeof global_config.youtube_api_key === "string" &&
80
82
  typeof global_config.xai_api_key === "string" &&
81
- typeof global_config.ballotpedia_api_key === "string"
83
+ typeof global_config.ballotpedia_api_key === "string" &&
84
+ typeof global_config.brave_api_key === "string"
82
85
  )
83
86
  }
84
87
  }