Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Oct 28, 2024
1 parent 02974f0 commit a96a86c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "[email protected]",
"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
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

0 comments on commit a96a86c

Please sign in to comment.