Skip to content

Commit e943253

Browse files
committed
[Components] browserbase #15425
Sources - New Session Actions - Create Session - Create Context - List Projects
1 parent 119777b commit e943253

File tree

12 files changed

+225
-380
lines changed

12 files changed

+225
-380
lines changed

components/browserbase/actions/create-context/create-context.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import browserbase from "../../browserbase.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "browserbase-create-context",
65
name: "Create Context",
76
description: "Creates a new context in Browserbase. [See the documentation](https://docs.browserbase.com/reference/api/create-a-context)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
browserbase,
@@ -18,7 +17,10 @@ export default {
1817
},
1918
async run({ $ }) {
2019
const response = await this.browserbase.createContext({
21-
projectId: this.projectId,
20+
$,
21+
data: {
22+
projectId: this.projectId,
23+
},
2224
});
2325

2426
$.export("$summary", `Successfully created context with ID: ${response.id}`);

components/browserbase/actions/create-session/create-session.mjs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import browserbase from "../../browserbase.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import { REGION_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
34

45
export default {
56
key: "browserbase-create-session",
67
name: "Create Session",
78
description: "Creates a new browser session with specified settings. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
browserbase,
@@ -16,65 +17,64 @@ export default {
1617
],
1718
},
1819
extensionId: {
19-
propDefinition: [
20-
browserbase,
21-
"extensionId",
22-
],
20+
type: "string",
21+
label: "Extension ID",
22+
description: "The uploaded Extension ID",
2323
optional: true,
2424
},
2525
browserSettings: {
26-
propDefinition: [
27-
browserbase,
28-
"browserSettings",
29-
],
26+
type: "object",
27+
label: "Browser Settings",
28+
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.",
3029
optional: true,
3130
},
3231
timeout: {
33-
propDefinition: [
34-
browserbase,
35-
"timeout",
36-
],
32+
type: "integer",
33+
label: "Timeout",
34+
description: "Duration in seconds after which the session will automatically end.",
35+
min: 60,
36+
max: 21600,
3737
optional: true,
3838
},
3939
keepAlive: {
40-
propDefinition: [
41-
browserbase,
42-
"keepAlive",
43-
],
40+
type: "boolean",
41+
label: "Keep Alive",
42+
description: "Set to true to keep the session alive even after disconnections.",
4443
optional: true,
4544
},
4645
proxies: {
47-
propDefinition: [
48-
browserbase,
49-
"proxies",
50-
],
46+
type: "string[]",
47+
label: "Proxies",
48+
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.",
5149
optional: true,
5250
},
5351
region: {
54-
propDefinition: [
55-
browserbase,
56-
"region",
57-
],
52+
type: "string",
53+
label: "Region",
54+
description: "The region where the session should run.",
55+
options: REGION_OPTIONS,
5856
optional: true,
5957
},
6058
userMetadata: {
61-
propDefinition: [
62-
browserbase,
63-
"userMetadata",
64-
],
59+
type: "object",
60+
label: "User Metadata",
61+
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).",
6562
optional: true,
6663
},
6764
},
6865
async run({ $ }) {
6966
const response = await this.browserbase.createSession({
70-
projectId: this.projectId,
71-
extensionId: this.extensionId,
72-
browserSettings: this.browserSettings,
73-
timeout: this.timeout,
74-
keepAlive: this.keepAlive,
75-
proxies: this.proxies && this.proxies.map(JSON.parse),
76-
region: this.region,
77-
userMetadata: this.userMetadata,
67+
$,
68+
data: {
69+
projectId: this.projectId,
70+
extensionId: this.extensionId,
71+
browserSettings: parseObject(this.browserSettings),
72+
timeout: this.timeout,
73+
keepAlive: this.keepAlive,
74+
proxies: parseObject(this.proxies),
75+
region: this.region,
76+
userMetadata: parseObject(this.userMetadata),
77+
},
7878
});
7979

8080
$.export("$summary", `Session created successfully with ID: ${response.id}`);
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import browserbase from "../../browserbase.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "browserbase-list-projects",
65
name: "List Projects",
76
description: "Lists all projects. [See the documentation](https://docs.browserbase.com/reference/api/list-projects)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
browserbase,
1211
},
1312
async run({ $ }) {
14-
const projects = await this.browserbase.listProjects();
15-
$.export("$summary", `Successfully listed ${projects.length} projects.`);
13+
const projects = await this.browserbase.listProjects({
14+
$,
15+
});
16+
$.export("$summary", `Successfully listed ${projects.length} project(s).`);
1617
return projects;
1718
},
1819
};

components/browserbase/browserbase.app.mjs

Lines changed: 17 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ export default {
44
type: "app",
55
app: "browserbase",
66
propDefinitions: {
7-
sessionId: {
8-
type: "string",
9-
label: "Session ID",
10-
description: "The ID of the session",
11-
async options() {
12-
const sessions = await this.listSessions();
13-
return sessions.map((session) => ({
14-
value: session.id,
15-
label: session.id,
16-
}));
17-
},
18-
},
197
projectId: {
208
type: "string",
219
label: "Project ID",
@@ -28,179 +16,51 @@ export default {
2816
}));
2917
},
3018
},
31-
extensionId: {
32-
type: "string",
33-
label: "Extension ID",
34-
description: "The uploaded Extension ID",
35-
optional: true,
36-
},
37-
browserSettings: {
38-
type: "object",
39-
label: "Browser Settings",
40-
description: "The settings for the browser",
41-
optional: true,
42-
},
43-
timeout: {
44-
type: "integer",
45-
label: "Timeout",
46-
description: "Duration in seconds after which the session will automatically end.",
47-
optional: true,
48-
min: 60,
49-
max: 21600,
50-
},
51-
keepAlive: {
52-
type: "boolean",
53-
label: "Keep Alive",
54-
description: "Set to true to keep the session alive even after disconnections.",
55-
optional: true,
56-
},
57-
proxies: {
58-
type: "string[]",
59-
label: "Proxies",
60-
description: "Proxy configuration. Can be true for default proxy, or an array of proxy configurations.",
61-
optional: true,
62-
},
63-
region: {
64-
type: "string",
65-
label: "Region",
66-
description: "The region where the session should run.",
67-
options: [
68-
{
69-
label: "US West 2",
70-
value: "us-west-2",
71-
},
72-
{
73-
label: "US East 1",
74-
value: "us-east-1",
75-
},
76-
{
77-
label: "EU Central 1",
78-
value: "eu-central-1",
79-
},
80-
{
81-
label: "AP Southeast 1",
82-
value: "ap-southeast-1",
83-
},
84-
],
85-
optional: true,
86-
},
87-
userMetadata: {
88-
type: "object",
89-
label: "User Metadata",
90-
description: "Arbitrary user metadata to attach to the session.",
91-
optional: true,
92-
},
9319
},
9420
methods: {
9521
_baseUrl() {
9622
return "https://api.browserbase.com/v1";
9723
},
98-
async _makeRequest(opts = {}) {
99-
const {
100-
$ = this, method = "GET", path = "/", headers, ...otherOpts
101-
} = opts;
24+
_headers() {
25+
return {
26+
"x-bb-api-key": `${this.$auth.api_key}`,
27+
"Content-Type": "application/json",
28+
};
29+
},
30+
_makeRequest({
31+
$ = this, path, ...opts
32+
}) {
10233
return axios($, {
103-
...otherOpts,
104-
method,
10534
url: this._baseUrl() + path,
106-
headers: {
107-
...headers,
108-
"X-BB-API-Key": this.$auth.api_key,
109-
},
35+
headers: this._headers(),
36+
...opts,
11037
});
11138
},
112-
async listProjects(opts = {}) {
39+
listProjects(opts = {}) {
11340
return this._makeRequest({
11441
path: "/projects",
11542
...opts,
11643
});
11744
},
118-
async listSessions(opts = {}) {
45+
listSessions(opts = {}) {
11946
return this._makeRequest({
12047
path: "/sessions",
12148
...opts,
12249
});
12350
},
124-
async createSession(opts = {}) {
125-
const {
126-
projectId, extensionId, browserSettings, timeout, keepAlive, proxies, region, userMetadata, ...otherOpts
127-
} = opts;
128-
const data = {
129-
projectId,
130-
extensionId,
131-
browserSettings,
132-
timeout,
133-
keepAlive,
134-
proxies,
135-
region,
136-
userMetadata,
137-
};
51+
createSession(opts = {}) {
13852
return this._makeRequest({
13953
method: "POST",
14054
path: "/sessions",
141-
data,
142-
...otherOpts,
55+
...opts,
14356
});
14457
},
145-
async createContext(opts = {}) {
146-
const {
147-
projectId, ...otherOpts
148-
} = opts;
58+
createContext(opts = {}) {
14959
return this._makeRequest({
15060
method: "POST",
15161
path: "/contexts",
152-
data: {
153-
projectId,
154-
},
155-
...otherOpts,
156-
});
157-
},
158-
async getSessionLogs(opts = {}) {
159-
const {
160-
sessionId, ...otherOpts
161-
} = opts;
162-
return this._makeRequest({
163-
path: `/sessions/${sessionId}/logs`,
164-
...otherOpts,
62+
...opts,
16563
});
16664
},
16765
},
168-
hooks: {
169-
async activate() {
170-
this._checkForNewProjects();
171-
this._checkForNewSessions();
172-
},
173-
},
174-
async _checkForNewProjects() {
175-
const projects = await this.listProjects();
176-
for (const project of projects) {
177-
this.$emit(project, {
178-
id: project.id,
179-
summary: project.name,
180-
ts: new Date().getTime(),
181-
});
182-
}
183-
},
184-
async _checkForNewSessions() {
185-
const sessions = await this.listSessions();
186-
for (const session of sessions) {
187-
this.$emit(session, {
188-
id: session.id,
189-
summary: `New session: ${session.id}`,
190-
ts: new Date().getTime(),
191-
});
192-
}
193-
},
194-
async _checkForNewLogs(sessionId) {
195-
const logs = await this.getSessionLogs({
196-
sessionId,
197-
});
198-
for (const log of logs) {
199-
this.$emit(log, {
200-
id: log.id,
201-
summary: `Log for session: ${sessionId}`,
202-
ts: new Date().getTime(),
203-
});
204-
}
205-
},
20666
};

0 commit comments

Comments
 (0)