-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - browserbase #16714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - browserbase #16714
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
119777b
browserbase init
luancazarine e943253
[Components] browserbase #15425
luancazarine 5cd4b88
pnpm update
luancazarine 39f21f8
pnpm update
luancazarine cde79dd
Merge branch 'master' into issue-15425
luancazarine 26065e9
pnpm update
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
components/browserbase/actions/create-context/create-context.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import browserbase from "../../browserbase.app.mjs"; | ||
|
||
export default { | ||
key: "browserbase-create-context", | ||
name: "Create Context", | ||
description: "Creates a new context in Browserbase. [See the documentation](https://docs.browserbase.com/reference/api/create-a-context)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
browserbase, | ||
projectId: { | ||
propDefinition: [ | ||
browserbase, | ||
"projectId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.browserbase.createContext({ | ||
$, | ||
data: { | ||
projectId: this.projectId, | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Successfully created context with ID: ${response.id}`); | ||
|
||
return response; | ||
}, | ||
}; |
83 changes: 83 additions & 0 deletions
83
components/browserbase/actions/create-session/create-session.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import browserbase from "../../browserbase.app.mjs"; | ||
import { REGION_OPTIONS } from "../../common/constants.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "browserbase-create-session", | ||
name: "Create Session", | ||
description: "Creates a new browser session with specified settings. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
browserbase, | ||
projectId: { | ||
propDefinition: [ | ||
browserbase, | ||
"projectId", | ||
], | ||
}, | ||
extensionId: { | ||
type: "string", | ||
label: "Extension ID", | ||
description: "The uploaded Extension ID", | ||
optional: true, | ||
}, | ||
browserSettings: { | ||
type: "object", | ||
label: "Browser Settings", | ||
description: "An object with the settings for the session. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session#body-browser-settings) for more details.", | ||
optional: true, | ||
}, | ||
timeout: { | ||
type: "integer", | ||
label: "Timeout", | ||
description: "Duration in seconds after which the session will automatically end.", | ||
min: 60, | ||
max: 21600, | ||
optional: true, | ||
}, | ||
keepAlive: { | ||
type: "boolean", | ||
label: "Keep Alive", | ||
description: "Set to true to keep the session alive even after disconnections.", | ||
optional: true, | ||
}, | ||
proxies: { | ||
type: "string[]", | ||
label: "Proxies", | ||
description: "An array of objects with proxy configuration. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session#body-proxies) for more details.", | ||
optional: true, | ||
}, | ||
region: { | ||
type: "string", | ||
label: "Region", | ||
description: "The region where the session should run.", | ||
options: REGION_OPTIONS, | ||
optional: true, | ||
}, | ||
userMetadata: { | ||
type: "object", | ||
label: "User Metadata", | ||
description: "Arbitrary user metadata to attach to the session. To learn more about user metadata, see [User Metadata](https://docs.browserbase.com/features/sessions#user-metadata).", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.browserbase.createSession({ | ||
$, | ||
data: { | ||
projectId: this.projectId, | ||
extensionId: this.extensionId, | ||
browserSettings: parseObject(this.browserSettings), | ||
timeout: this.timeout, | ||
keepAlive: this.keepAlive, | ||
proxies: parseObject(this.proxies), | ||
region: this.region, | ||
userMetadata: parseObject(this.userMetadata), | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Session created successfully with ID: ${response.id}`); | ||
return response; | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
components/browserbase/actions/list-projects/list-projects.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import browserbase from "../../browserbase.app.mjs"; | ||
|
||
export default { | ||
key: "browserbase-list-projects", | ||
name: "List Projects", | ||
description: "Lists all projects. [See the documentation](https://docs.browserbase.com/reference/api/list-projects)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
browserbase, | ||
}, | ||
async run({ $ }) { | ||
const projects = await this.browserbase.listProjects({ | ||
$, | ||
}); | ||
$.export("$summary", `Successfully listed ${projects.length} project(s).`); | ||
return projects; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,66 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "browserbase", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
projectId: { | ||
type: "string", | ||
label: "Project ID", | ||
description: "The ID of the project", | ||
async options() { | ||
const projects = await this.listProjects(); | ||
return projects.map((project) => ({ | ||
value: project.id, | ||
label: project.name, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.browserbase.com/v1"; | ||
}, | ||
_headers() { | ||
return { | ||
"x-bb-api-key": `${this.$auth.api_key}`, | ||
"Content-Type": "application/json", | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
listProjects(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/projects", | ||
...opts, | ||
}); | ||
}, | ||
listSessions(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/sessions", | ||
...opts, | ||
}); | ||
}, | ||
createSession(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/sessions", | ||
...opts, | ||
}); | ||
}, | ||
createContext(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/contexts", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const REGION_OPTIONS = [ | ||
{ | ||
label: "US West 2", | ||
value: "us-west-2", | ||
}, | ||
{ | ||
label: "US East 1", | ||
value: "us-east-1", | ||
}, | ||
{ | ||
label: "EU Central 1", | ||
value: "eu-central-1", | ||
}, | ||
{ | ||
label: "AP Southeast 1", | ||
value: "ap-southeast-1", | ||
}, | ||
]; | ||
|
||
export const STATUS_OPTIONS = [ | ||
"RUNNING", | ||
"ERROR", | ||
"TIMED_OUT", | ||
"COMPLETED", | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const parseObject = (obj) => { | ||
if (!obj) return undefined; | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => { | ||
if (typeof item === "string") { | ||
try { | ||
return JSON.parse(item); | ||
} catch (e) { | ||
return item; | ||
} | ||
} | ||
return item; | ||
}); | ||
} | ||
if (typeof obj === "string") { | ||
try { | ||
return JSON.parse(obj); | ||
} catch (e) { | ||
return obj; | ||
} | ||
} | ||
return obj; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/browserbase", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Browserbase Components", | ||
"main": "browserbase.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
import browserbase from "../../browserbase.app.mjs"; | ||
|
||
export default { | ||
props: { | ||
browserbase, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastDate() { | ||
return this.db.get("lastDate") || 0; | ||
}, | ||
_setLastDate(lastDate) { | ||
this.db.set("lastDate", lastDate); | ||
}, | ||
getParams() { | ||
return {}; | ||
}, | ||
async emitEvent(maxResults = false) { | ||
const lastDate = this._getLastDate(); | ||
const fn = this.getFunction(); | ||
|
||
const response = await fn({ | ||
params: this.getParams(), | ||
}); | ||
|
||
let responseArray = response.filter((item) => { | ||
return Date.parse(item.createdAt) > lastDate; | ||
}); | ||
|
||
if (responseArray.length) { | ||
if (maxResults && (responseArray.length > maxResults)) { | ||
responseArray.length = maxResults; | ||
} | ||
this._setLastDate(Date.parse(responseArray[0].createdAt)); | ||
} | ||
|
||
for (const item of responseArray.reverse()) { | ||
this.$emit(item, { | ||
id: item.id, | ||
summary: this.getSummary(item), | ||
ts: Date.parse(item.createdAt), | ||
}); | ||
} | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
await this.emitEvent(25); | ||
}, | ||
}, | ||
async run() { | ||
await this.emitEvent(); | ||
}, | ||
}; |
45 changes: 45 additions & 0 deletions
45
components/browserbase/sources/new-session/new-session.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { STATUS_OPTIONS } from "../../common/constants.mjs"; | ||
import common from "../common/base.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "browserbase-new-session", | ||
name: "New Session Created", | ||
description: "Emit new event when a new session is created. [See the documentation](https://docs.browserbase.com/reference/api/list-sessions)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
...common.props, | ||
status: { | ||
type: "string", | ||
label: "Status", | ||
description: "The status of the session.", | ||
options: STATUS_OPTIONS, | ||
optional: true, | ||
}, | ||
q: { | ||
type: "string", | ||
label: "Query", | ||
description: "Query sessions by user metadata. See [Querying Sessions by User Metadata](https://docs.browserbase.com/features/sessions#querying-sessions-by-user-metadata) for the schema of this query.", | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
getFunction() { | ||
return this.browserbase.listSessions; | ||
}, | ||
getParams() { | ||
return { | ||
status: this.status, | ||
q: this.q || null, | ||
}; | ||
}, | ||
getSummary(item) { | ||
return `New session: ${item.id}`; | ||
}, | ||
}, | ||
sampleEmit, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.