Skip to content

Commit a96a86c

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

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 18
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-60444f8b1aa1aa8dbec1e9f11e929c2b7ac27470764ef5f1796134fc27f3381c.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-9f93c744538f57747ea1385817e21b40c318b65ebc155dca8950268beb280bc9.yml

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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'
3031
});
3132

3233
async function main() {
@@ -48,6 +49,7 @@ import Browserbase from 'browserbase';
4849

4950
const client = new Browserbase({
5051
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
52+
environment: 'development', // or 'production' | 'local'; defaults to 'production'
5153
});
5254

5355
async function main() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"packageManager": "yarn@1.22.22",
1212
"files": [
13-
"*"
13+
"**/*"
1414
],
1515
"private": false,
1616
"scripts": {

src/index.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,29 @@ 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+
916
export interface ClientOptions {
1017
/**
1118
* Your [Browserbase API Key](https://www.browserbase.com/settings).
1219
*/
1320
apiKey?: string | undefined;
1421

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+
1532
/**
1633
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
1734
*
@@ -81,7 +98,8 @@ export class Browserbase extends Core.APIClient {
8198
* API Client for interfacing with the Browserbase API.
8299
*
83100
* @param {string | undefined} [opts.apiKey=process.env['BROWSERBASE_API_KEY'] ?? undefined]
84-
* @param {string} [opts.baseURL=process.env['BROWSERBASE_BASE_URL'] ?? https://api.dev.browserbase.com] - Override the default base URL for the API.
101+
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
102+
* @param {string} [opts.baseURL=process.env['BROWSERBASE_BASE_URL'] ?? https://api.browserbase.com] - Override the default base URL for the API.
85103
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
86104
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
87105
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -103,11 +121,18 @@ export class Browserbase extends Core.APIClient {
103121
const options: ClientOptions = {
104122
apiKey,
105123
...opts,
106-
baseURL: baseURL || `https://api.dev.browserbase.com`,
124+
baseURL,
125+
environment: opts.environment ?? 'production',
107126
};
108127

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+
109134
super({
110-
baseURL: options.baseURL!,
135+
baseURL: options.baseURL || environments[options.environment || 'production'],
111136
timeout: options.timeout ?? 60000 /* 1 minute */,
112137
httpAgent: options.httpAgent,
113138
maxRetries: options.maxRetries,

tests/index.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,26 @@ describe('instantiate client', () => {
151151
test('empty env variable', () => {
152152
process.env['BROWSERBASE_BASE_URL'] = ''; // empty
153153
const client = new Browserbase({ apiKey: 'My API Key' });
154-
expect(client.baseURL).toEqual('https://api.dev.browserbase.com');
154+
expect(client.baseURL).toEqual('https://api.browserbase.com');
155155
});
156156

157157
test('blank env variable', () => {
158158
process.env['BROWSERBASE_BASE_URL'] = ' '; // blank
159159
const client = new Browserbase({ apiKey: 'My API Key' });
160-
expect(client.baseURL).toEqual('https://api.dev.browserbase.com');
160+
expect(client.baseURL).toEqual('https://api.browserbase.com');
161+
});
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');
161174
});
162175
});
163176

0 commit comments

Comments
 (0)