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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.1-alpha.0"
".": "0.1.0-alpha.1"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 18
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-60444f8b1aa1aa8dbec1e9f11e929c2b7ac27470764ef5f1796134fc27f3381c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-9f93c744538f57747ea1385817e21b40c318b65ebc155dca8950268beb280bc9.yml
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Browserbase from 'browserbase';

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

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

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

async function main() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browserbase",
"version": "0.0.1-alpha.0",
"version": "0.1.0-alpha.1",
"description": "The official TypeScript library for the Browserbase API",
"author": "Browserbase <dev-feedback@browserbase.com>",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "yarn@1.22.22",
"files": [
"*"
"**/*"
],
"private": false,
"scripts": {
Expand Down
31 changes: 28 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ import { type Agent } from './_shims/index';
import * as Core from './core';
import * as API from './resources/index';

const environments = {
production: 'https://api.browserbase.com',
development: 'https://api.dev.browserbase.com',
local: 'http://api.localhost',
};
type Environment = keyof typeof environments;

export interface ClientOptions {
/**
* Your [Browserbase API Key](https://www.browserbase.com/settings).
*/
apiKey?: string | undefined;

/**
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://api.browserbase.com`
* - `development` corresponds to `https://api.dev.browserbase.com`
* - `local` corresponds to `http://api.localhost`
*/
environment?: Environment;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*
Expand Down Expand Up @@ -81,7 +98,8 @@ export class Browserbase extends Core.APIClient {
* API Client for interfacing with the Browserbase API.
*
* @param {string | undefined} [opts.apiKey=process.env['BROWSERBASE_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['BROWSERBASE_BASE_URL'] ?? https://api.dev.browserbase.com] - Override the default base URL for the API.
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['BROWSERBASE_BASE_URL'] ?? https://api.browserbase.com] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
Expand All @@ -103,11 +121,18 @@ export class Browserbase extends Core.APIClient {
const options: ClientOptions = {
apiKey,
...opts,
baseURL: baseURL || `https://api.dev.browserbase.com`,
baseURL,
environment: opts.environment ?? 'production',
};

if (baseURL && opts.environment) {
throw new Errors.BrowserbaseError(
'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',
);
}

super({
baseURL: options.baseURL!,
baseURL: options.baseURL || environments[options.environment || 'production'],
timeout: options.timeout ?? 60000 /* 1 minute */,
httpAgent: options.httpAgent,
maxRetries: options.maxRetries,
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.0.1-alpha.0'; // x-release-please-version
export const VERSION = '0.1.0-alpha.1'; // x-release-please-version
17 changes: 15 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,26 @@ describe('instantiate client', () => {
test('empty env variable', () => {
process.env['BROWSERBASE_BASE_URL'] = ''; // empty
const client = new Browserbase({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.dev.browserbase.com');
expect(client.baseURL).toEqual('https://api.browserbase.com');
});

test('blank env variable', () => {
process.env['BROWSERBASE_BASE_URL'] = ' '; // blank
const client = new Browserbase({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.dev.browserbase.com');
expect(client.baseURL).toEqual('https://api.browserbase.com');
});

test('env variable with environment', () => {
process.env['BROWSERBASE_BASE_URL'] = 'https://example.com/from_env';

expect(
() => new Browserbase({ apiKey: 'My API Key', environment: 'production' }),
).toThrowErrorMatchingInlineSnapshot(
`"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"`,
);

const client = new Browserbase({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
expect(client.baseURL).toEqual('https://api.browserbase.com');
});
});

Expand Down