diff --git a/components/brave_search_api/actions/web-search/web-search.mjs b/components/brave_search_api/actions/web-search/web-search.mjs new file mode 100644 index 0000000000000..fc9d39f102eb4 --- /dev/null +++ b/components/brave_search_api/actions/web-search/web-search.mjs @@ -0,0 +1,72 @@ +import app from "../../brave_search_api.app.mjs"; + +export default { + key: "brave_search_api-web-search", + name: "Web Search", + description: "Query Brave Search and get back search results from the web. [See the documentation](https://api-dashboard.search.brave.com/app/documentation/web-search/get-started)", + version: "0.0.1", + type: "action", + props: { + app, + q: { + propDefinition: [ + app, + "q", + ], + }, + country: { + propDefinition: [ + app, + "country", + ], + }, + searchLang: { + propDefinition: [ + app, + "searchLang", + ], + }, + uiLang: { + propDefinition: [ + app, + "uiLang", + ], + }, + safesearch: { + propDefinition: [ + app, + "safesearch", + ], + }, + }, + async run({ $ }) { + const allResults = []; + const count = 20; + for (let offset = 0; offset < 5; offset++) { + const response = await this.app.webSearch({ + $, + params: { + q: this.q, + country: this.country, + search_lang: this.searchLang, + ui_lang: this.uiLang, + safesearch: this.safesearch, + count, + offset, + }, + }); + + const results = response.web?.results; + allResults.push(...results); + + if (results.length < count) { + break; + } + } + + $.export("$summary", `Retrieved ${allResults.length} results`); + return { + allResults, + }; + }, +}; diff --git a/components/brave_search_api/brave_search_api.app.mjs b/components/brave_search_api/brave_search_api.app.mjs index fad13cd5853e9..c0888d9705d08 100644 --- a/components/brave_search_api/brave_search_api.app.mjs +++ b/components/brave_search_api/brave_search_api.app.mjs @@ -1,11 +1,72 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "brave_search_api", - propDefinitions: {}, + propDefinitions: { + q: { + type: "string", + label: "Query", + description: "Search query string", + }, + country: { + type: "string", + label: "Country", + description: "Country code to localize search results", + optional: true, + options: constants.COUNTRY_CODES, + }, + searchLang: { + type: "string", + label: "Search Language", + description: "Language to use for search results", + optional: true, + options: constants.LANGUAGE_CODES, + }, + uiLang: { + type: "string", + label: "UI Language", + description: "Language for the user interface", + optional: true, + options: constants.UI_CODES, + }, + safesearch: { + type: "string", + label: "SafeSearch", + description: "SafeSearch filter level", + optional: true, + options: constants.SEARCH_OPTIONS, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.search.brave.com/res/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "x-subscription-token": `${this.$auth.api_key}`, + "accept": "application/json", + "accept-encoding": "gzip", + ...headers, + }, + }); + }, + + async webSearch(args = {}) { + return this._makeRequest({ + path: "/web/search", + ...args, + }); }, }, }; diff --git a/components/brave_search_api/common/constants.mjs b/components/brave_search_api/common/constants.mjs new file mode 100644 index 0000000000000..13955f1e4b90d --- /dev/null +++ b/components/brave_search_api/common/constants.mjs @@ -0,0 +1,513 @@ +export default { + COUNTRY_CODES: [ + { + label: "All Regions", + value: "ALL", + }, + { + label: "Argentina", + value: "AR", + }, + { + label: "Australia", + value: "AU", + }, + { + label: "Austria", + value: "AT", + }, + { + label: "Belgium", + value: "BE", + }, + { + label: "Brazil", + value: "BR", + }, + { + label: "Canada", + value: "CA", + }, + { + label: "Chile", + value: "CL", + }, + { + label: "Denmark", + value: "DK", + }, + { + label: "Finland", + value: "FI", + }, + { + label: "France", + value: "FR", + }, + { + label: "Germany", + value: "DE", + }, + { + label: "Hong Kong", + value: "HK", + }, + { + label: "India", + value: "IN", + }, + { + label: "Indonesia", + value: "ID", + }, + { + label: "Italy", + value: "IT", + }, + { + label: "Japan", + value: "JP", + }, + { + label: "Korea", + value: "KR", + }, + { + label: "Malaysia", + value: "MY", + }, + { + label: "Mexico", + value: "MX", + }, + { + label: "Netherlands", + value: "NL", + }, + { + label: "New Zealand", + value: "NZ", + }, + { + label: "Norway", + value: "NO", + }, + { + label: "People's Republic of China", + value: "CN", + }, + { + label: "Poland", + value: "PL", + }, + { + label: "Portugal", + value: "PT", + }, + { + label: "Philippines", + value: "PH", + }, + { + label: "Russia", + value: "RU", + }, + { + label: "Saudi Arabia", + value: "SA", + }, + { + label: "South Africa", + value: "ZA", + }, + { + label: "Spain", + value: "ES", + }, + { + label: "Sweden", + value: "SV", + }, + { + label: "Switzerland", + value: "CH", + }, + { + label: "Taiwan", + value: "TW", + }, + { + label: "Turkey", + value: "TR", + }, + { + label: "United Kingdom", + value: "GB", + }, + { + label: "United States", + value: "US", + }, + ], + LANGUAGE_CODES: [ + { + label: "Arabic", + value: "ar", + }, + { + label: "Basque", + value: "eu", + }, + { + label: "Bengali", + value: "bn", + }, + { + label: "Bulgarian", + value: "bg", + }, + { + label: "Catalan", + value: "ca", + }, + { + label: "Chinese (Simplified)", + value: "zh-hans", + }, + { + label: "Chinese (Traditional)", + value: "zh-hant", + }, + { + label: "Croatian", + value: "hr", + }, + { + label: "Czech", + value: "cs", + }, + { + label: "Danish", + value: "da", + }, + { + label: "Dutch", + value: "nl", + }, + { + label: "English", + value: "en", + }, + { + label: "English (United Kingdom)", + value: "en-gb", + }, + { + label: "Estonian", + value: "et", + }, + { + label: "Finnish", + value: "fi", + }, + { + label: "French", + value: "fr", + }, + { + label: "Galician", + value: "gl", + }, + { + label: "German", + value: "de", + }, + { + label: "Gujarati", + value: "gu", + }, + { + label: "Hebrew", + value: "he", + }, + { + label: "Hindi", + value: "hi", + }, + { + label: "Hungarian", + value: "hu", + }, + { + label: "Icelandic", + value: "is", + }, + { + label: "Italian", + value: "it", + }, + { + label: "Japanese", + value: "jp", + }, + { + label: "Kannada", + value: "kn", + }, + { + label: "Korean", + value: "ko", + }, + { + label: "Latvian", + value: "lv", + }, + { + label: "Lithuanian", + value: "lt", + }, + { + label: "Malay", + value: "ms", + }, + { + label: "Malayalam", + value: "ml", + }, + { + label: "Marathi", + value: "mr", + }, + { + label: "Norwegian Bokmål", + value: "nb", + }, + { + label: "Polish", + value: "pl", + }, + { + label: "Portuguese (Brazil)", + value: "pt-br", + }, + { + label: "Portuguese (Portugal)", + value: "pt-pt", + }, + { + label: "Punjabi", + value: "pa", + }, + { + label: "Romanian", + value: "ro", + }, + { + label: "Russian", + value: "ru", + }, + { + label: "Serbian (Cyrillic)", + value: "sr", + }, + { + label: "Slovak", + value: "sk", + }, + { + label: "Slovenian", + value: "sl", + }, + { + label: "Spanish", + value: "es", + }, + { + label: "Swedish", + value: "sv", + }, + { + label: "Tamil", + value: "ta", + }, + { + label: "Telugu", + value: "te", + }, + { + label: "Thai", + value: "th", + }, + { + label: "Turkish", + value: "tr", + }, + { + label: "Ukrainian", + value: "uk", + }, + { + label: "Vietnamese", + value: "vi", + }, + ], + UI_CODES: [ + { + label: "Argentina (Spanish)", + value: "es-AR", + }, + { + label: "Australia (English)", + value: "en-AU", + }, + { + label: "Austria (German)", + value: "de-AT", + }, + { + label: "Belgium (Dutch)", + value: "nl-BE", + }, + { + label: "Belgium (French)", + value: "fr-BE", + }, + { + label: "Brazil (Portuguese)", + value: "pt-BR", + }, + { + label: "Canada (English)", + value: "en-CA", + }, + { + label: "Canada (French)", + value: "fr-CA", + }, + { + label: "Chile (Spanish)", + value: "es-CL", + }, + { + label: "Denmark (Danish)", + value: "da-DK", + }, + { + label: "Finland (Finnish)", + value: "fi-FI", + }, + { + label: "France (French)", + value: "fr-FR", + }, + { + label: "Germany (German)", + value: "de-DE", + }, + { + label: "Hong Kong SAR (Traditional Chinese)", + value: "zh-HK", + }, + { + label: "India (English)", + value: "en-IN", + }, + { + label: "Indonesia (English)", + value: "en-ID", + }, + { + label: "Italy (Italian)", + value: "it-IT", + }, + { + label: "Japan (Japanese)", + value: "ja-JP", + }, + { + label: "Korea (Korean)", + value: "ko-KR", + }, + { + label: "Malaysia (English)", + value: "en-MY", + }, + { + label: "Mexico (Spanish)", + value: "es-MX", + }, + { + label: "Netherlands (Dutch)", + value: "nl-NL", + }, + { + label: "New Zealand (English)", + value: "en-NZ", + }, + { + label: "Norway (Norwegian)", + value: "no-NO", + }, + { + label: "People's Republic of China (Chinese)", + value: "zh-CN", + }, + { + label: "Poland (Polish)", + value: "pl-PL", + }, + { + label: "Philippines (English)", + value: "en-PH", + }, + { + label: "Russia (Russian)", + value: "ru-RU", + }, + { + label: "South Africa (English)", + value: "en-ZA", + }, + { + label: "Spain (Spanish)", + value: "es-ES", + }, + { + label: "Sweden (Swedish)", + value: "sv-SE", + }, + { + label: "Switzerland (French)", + value: "fr-CH", + }, + { + label: "Switzerland (German)", + value: "de-CH", + }, + { + label: "Taiwan (Traditional Chinese)", + value: "zh-TW", + }, + { + label: "Turkey (Turkish)", + value: "tr-TR", + }, + { + label: "United Kingdom (English)", + value: "en-GB", + }, + { + label: "United States (English)", + value: "en-US", + }, + { + label: "United States (Spanish)", + value: "es-US", + }, + ], + SEARCH_OPTIONS: [ + "off", + "moderate", + "strict", + ], +}; diff --git a/components/brave_search_api/package.json b/components/brave_search_api/package.json index 0bfae660095db..da56ff5e61786 100644 --- a/components/brave_search_api/package.json +++ b/components/brave_search_api/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/brave_search_api", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Brave Search API Components", "main": "brave_search_api.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 418357c001edc..3c88992858acb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1843,7 +1843,11 @@ importers: components/brandmentions: {} - components/brave_search_api: {} + components/brave_search_api: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/braze: {} @@ -11271,8 +11275,7 @@ importers: specifier: ^6.11.0 version: 6.13.1 - components/redis_cloud_rest_api: - specifiers: {} + components/redis_cloud_rest_api: {} components/redmine: {}