From 186b59d32209a06f1b3f578719401431948e84f3 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Mon, 28 Oct 2024 21:21:22 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- .release-please-manifest.json | 2 +- .stats.yml | 2 +- README.md | 2 ++ package.json | 4 ++-- src/index.ts | 31 ++++++++++++++++++++++++++++--- src/version.ts | 2 +- tests/index.test.ts | 17 +++++++++++++++-- 7 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 67dcd73..d7a8735 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.0.1-alpha.0" + ".": "0.1.0-alpha.1" } diff --git a/.stats.yml b/.stats.yml index 70bddde..e5f4ae3 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 diff --git a/README.md b/README.md index 0380e8f..9dfea97 100644 --- a/README.md +++ b/README.md @@ -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() { @@ -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() { diff --git a/package.json b/package.json index b4fc8fb..0a7f825 100644 --- a/package.json +++ b/package.json @@ -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 ", "types": "dist/index.d.ts", @@ -10,7 +10,7 @@ "license": "Apache-2.0", "packageManager": "yarn@1.22.22", "files": [ - "*" + "**/*" ], "private": false, "scripts": { diff --git a/src/index.ts b/src/index.ts index 03c44c2..daf7904 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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/" * @@ -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. @@ -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, diff --git a/src/version.ts b/src/version.ts index db692bc..b0bfd9e 100644 --- a/src/version.ts +++ b/src/version.ts @@ -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 diff --git a/tests/index.test.ts b/tests/index.test.ts index 5507454..367603a 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -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'); }); });