Skip to content

Commit 52cf741

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): update via SDK Studio (#17)
1 parent a96a86c commit 52cf741

File tree

5 files changed

+27
-65
lines changed

5 files changed

+27
-65
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ import Browserbase from 'browserbase';
2727

2828
const client = new Browserbase({
2929
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
30-
environment: 'development', // or 'production' | 'local'; defaults to 'production'
3130
});
3231

3332
async function main() {
34-
const context = await client.contexts.create({ projectId: 'projectId' });
33+
const session = await client.sessions.create({ projectId: 'your_project_id', proxies: true });
3534

36-
console.log(context.id);
35+
console.log(session.id);
3736
}
3837

3938
main();
@@ -49,12 +48,11 @@ import Browserbase from 'browserbase';
4948

5049
const client = new Browserbase({
5150
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
52-
environment: 'development', // or 'production' | 'local'; defaults to 'production'
5351
});
5452

5553
async function main() {
56-
const params: Browserbase.ContextCreateParams = { projectId: 'projectId' };
57-
const context: Browserbase.ContextCreateResponse = await client.contexts.create(params);
54+
const params: Browserbase.SessionCreateParams = { projectId: 'your_project_id', proxies: true };
55+
const session: Browserbase.SessionCreateResponse = await client.sessions.create(params);
5856
}
5957

6058
main();
@@ -71,15 +69,17 @@ a subclass of `APIError` will be thrown:
7169
<!-- prettier-ignore -->
7270
```ts
7371
async function main() {
74-
const context = await client.contexts.create({ projectId: 'projectId' }).catch(async (err) => {
75-
if (err instanceof Browserbase.APIError) {
76-
console.log(err.status); // 400
77-
console.log(err.name); // BadRequestError
78-
console.log(err.headers); // {server: 'nginx', ...}
79-
} else {
80-
throw err;
81-
}
82-
});
72+
const session = await client.sessions
73+
.create({ projectId: 'your_project_id', proxies: true })
74+
.catch(async (err) => {
75+
if (err instanceof Browserbase.APIError) {
76+
console.log(err.status); // 400
77+
console.log(err.name); // BadRequestError
78+
console.log(err.headers); // {server: 'nginx', ...}
79+
} else {
80+
throw err;
81+
}
82+
});
8383
}
8484

8585
main();
@@ -114,7 +114,7 @@ const client = new Browserbase({
114114
});
115115

116116
// Or, configure per-request:
117-
await client.contexts.create({ projectId: 'projectId' }, {
117+
await client.sessions.create({ projectId: 'your_project_id', proxies: true }, {
118118
maxRetries: 5,
119119
});
120120
```
@@ -131,7 +131,7 @@ const client = new Browserbase({
131131
});
132132

133133
// Override per-request:
134-
await client.contexts.create({ projectId: 'projectId' }, {
134+
await client.sessions.create({ projectId: 'your_project_id', proxies: true }, {
135135
timeout: 5 * 1000,
136136
});
137137
```
@@ -152,15 +152,15 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
152152
```ts
153153
const client = new Browserbase();
154154

155-
const response = await client.contexts.create({ projectId: 'projectId' }).asResponse();
155+
const response = await client.sessions.create({ projectId: 'your_project_id', proxies: true }).asResponse();
156156
console.log(response.headers.get('X-My-Header'));
157157
console.log(response.statusText); // access the underlying Response object
158158

159-
const { data: context, response: raw } = await client.contexts
160-
.create({ projectId: 'projectId' })
159+
const { data: session, response: raw } = await client.sessions
160+
.create({ projectId: 'your_project_id', proxies: true })
161161
.withResponse();
162162
console.log(raw.headers.get('X-My-Header'));
163-
console.log(context.id);
163+
console.log(session.id);
164164
```
165165

166166
### Making custom/undocumented requests
@@ -264,8 +264,8 @@ const client = new Browserbase({
264264
});
265265

266266
// Override per-request:
267-
await client.contexts.create(
268-
{ projectId: 'projectId' },
267+
await client.sessions.create(
268+
{ projectId: 'your_project_id', proxies: true },
269269
{
270270
httpAgent: new http.Agent({ keepAlive: false }),
271271
},

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ or products provided by Browserbase please follow the respective company's secur
2020

2121
### Browserbase Terms and Policies
2222

23-
Please contact dev-feedback@browserbase.com for any questions or concerns regarding security of our services.
23+
Please contact support@browserbase.com for any questions or concerns regarding security of our services.
2424

2525
---
2626

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "browserbase",
33
"version": "0.1.0-alpha.1",
44
"description": "The official TypeScript library for the Browserbase API",
5-
"author": "Browserbase <dev-feedback@browserbase.com>",
5+
"author": "Browserbase <support@browserbase.com>",
66
"types": "dist/index.d.ts",
77
"main": "dist/index.js",
88
"type": "commonjs",

src/index.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@ import { type Agent } from './_shims/index';
66
import * as Core from './core';
77
import * as API from './resources/index';
88

9-
const environments = {
10-
production: 'https://api.browserbase.com',
11-
development: 'https://api.dev.browserbase.com',
12-
local: 'http://api.localhost',
13-
};
14-
type Environment = keyof typeof environments;
15-
169
export interface ClientOptions {
1710
/**
1811
* Your [Browserbase API Key](https://www.browserbase.com/settings).
1912
*/
2013
apiKey?: string | undefined;
2114

22-
/**
23-
* Specifies the environment to use for the API.
24-
*
25-
* Each environment maps to a different base URL:
26-
* - `production` corresponds to `https://api.browserbase.com`
27-
* - `development` corresponds to `https://api.dev.browserbase.com`
28-
* - `local` corresponds to `http://api.localhost`
29-
*/
30-
environment?: Environment;
31-
3215
/**
3316
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
3417
*
@@ -98,7 +81,6 @@ export class Browserbase extends Core.APIClient {
9881
* API Client for interfacing with the Browserbase API.
9982
*
10083
* @param {string | undefined} [opts.apiKey=process.env['BROWSERBASE_API_KEY'] ?? undefined]
101-
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
10284
* @param {string} [opts.baseURL=process.env['BROWSERBASE_BASE_URL'] ?? https://api.browserbase.com] - Override the default base URL for the API.
10385
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
10486
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
@@ -121,18 +103,11 @@ export class Browserbase extends Core.APIClient {
121103
const options: ClientOptions = {
122104
apiKey,
123105
...opts,
124-
baseURL,
125-
environment: opts.environment ?? 'production',
106+
baseURL: baseURL || `https://api.browserbase.com`,
126107
};
127108

128-
if (baseURL && opts.environment) {
129-
throw new Errors.BrowserbaseError(
130-
'Ambiguous URL; The `baseURL` option (or BROWSERBASE_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
131-
);
132-
}
133-
134109
super({
135-
baseURL: options.baseURL || environments[options.environment || 'production'],
110+
baseURL: options.baseURL!,
136111
timeout: options.timeout ?? 60000 /* 1 minute */,
137112
httpAgent: options.httpAgent,
138113
maxRetries: options.maxRetries,

tests/index.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ describe('instantiate client', () => {
159159
const client = new Browserbase({ apiKey: 'My API Key' });
160160
expect(client.baseURL).toEqual('https://api.browserbase.com');
161161
});
162-
163-
test('env variable with environment', () => {
164-
process.env['BROWSERBASE_BASE_URL'] = 'https://example.com/from_env';
165-
166-
expect(
167-
() => new Browserbase({ apiKey: 'My API Key', environment: 'production' }),
168-
).toThrowErrorMatchingInlineSnapshot(
169-
`"Ambiguous URL; The \`baseURL\` option (or BROWSERBASE_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`,
170-
);
171-
172-
const client = new Browserbase({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
173-
expect(client.baseURL).toEqual('https://api.browserbase.com');
174-
});
175162
});
176163

177164
test('maxRetries option is correctly set', () => {

0 commit comments

Comments
 (0)