Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions components/brave_search_api/actions/web-search/web-search.mjs
Original file line number Diff line number Diff line change
@@ -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,
};
},
};
69 changes: 65 additions & 4 deletions components/brave_search_api/brave_search_api.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
Loading
Loading