triangle-utils 1.4.165 → 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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.165",
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)