From 399e406094ffe18000c59608a67cf148d56570a3 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Mon, 28 Oct 2024 23:14:16 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- README.md | 46 ++++++++++++++++++++++----------------------- SECURITY.md | 2 +- package.json | 2 +- src/index.ts | 29 ++-------------------------- tests/index.test.ts | 13 ------------- 5 files changed, 27 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 9dfea97..b42332b 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,12 @@ 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() { - const context = await client.contexts.create({ projectId: 'projectId' }); + const session = await client.sessions.create({ projectId: 'your_project_id', proxies: true }); - console.log(context.id); + console.log(session.id); } main(); @@ -49,12 +48,11 @@ 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() { - const params: Browserbase.ContextCreateParams = { projectId: 'projectId' }; - const context: Browserbase.ContextCreateResponse = await client.contexts.create(params); + const params: Browserbase.SessionCreateParams = { projectId: 'your_project_id', proxies: true }; + const session: Browserbase.SessionCreateResponse = await client.sessions.create(params); } main(); @@ -71,15 +69,17 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const context = await client.contexts.create({ projectId: 'projectId' }).catch(async (err) => { - if (err instanceof Browserbase.APIError) { - console.log(err.status); // 400 - console.log(err.name); // BadRequestError - console.log(err.headers); // {server: 'nginx', ...} - } else { - throw err; - } - }); + const session = await client.sessions + .create({ projectId: 'your_project_id', proxies: true }) + .catch(async (err) => { + if (err instanceof Browserbase.APIError) { + console.log(err.status); // 400 + console.log(err.name); // BadRequestError + console.log(err.headers); // {server: 'nginx', ...} + } else { + throw err; + } + }); } main(); @@ -114,7 +114,7 @@ const client = new Browserbase({ }); // Or, configure per-request: -await client.contexts.create({ projectId: 'projectId' }, { +await client.sessions.create({ projectId: 'your_project_id', proxies: true }, { maxRetries: 5, }); ``` @@ -131,7 +131,7 @@ const client = new Browserbase({ }); // Override per-request: -await client.contexts.create({ projectId: 'projectId' }, { +await client.sessions.create({ projectId: 'your_project_id', proxies: true }, { timeout: 5 * 1000, }); ``` @@ -152,15 +152,15 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts const client = new Browserbase(); -const response = await client.contexts.create({ projectId: 'projectId' }).asResponse(); +const response = await client.sessions.create({ projectId: 'your_project_id', proxies: true }).asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object -const { data: context, response: raw } = await client.contexts - .create({ projectId: 'projectId' }) +const { data: session, response: raw } = await client.sessions + .create({ projectId: 'your_project_id', proxies: true }) .withResponse(); console.log(raw.headers.get('X-My-Header')); -console.log(context.id); +console.log(session.id); ``` ### Making custom/undocumented requests @@ -264,8 +264,8 @@ const client = new Browserbase({ }); // Override per-request: -await client.contexts.create( - { projectId: 'projectId' }, +await client.sessions.create( + { projectId: 'your_project_id', proxies: true }, { httpAgent: new http.Agent({ keepAlive: false }), }, diff --git a/SECURITY.md b/SECURITY.md index 06c5b6e..4fdede8 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -20,7 +20,7 @@ or products provided by Browserbase please follow the respective company's secur ### Browserbase Terms and Policies -Please contact dev-feedback@browserbase.com for any questions or concerns regarding security of our services. +Please contact support@browserbase.com for any questions or concerns regarding security of our services. --- diff --git a/package.json b/package.json index 0a7f825..cf7de78 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "browserbase", "version": "0.1.0-alpha.1", "description": "The official TypeScript library for the Browserbase API", - "author": "Browserbase ", + "author": "Browserbase ", "types": "dist/index.d.ts", "main": "dist/index.js", "type": "commonjs", diff --git a/src/index.ts b/src/index.ts index daf7904..3d2e3a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,29 +6,12 @@ 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/" * @@ -98,7 +81,6 @@ 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 {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. @@ -121,18 +103,11 @@ export class Browserbase extends Core.APIClient { const options: ClientOptions = { apiKey, ...opts, - baseURL, - environment: opts.environment ?? 'production', + baseURL: baseURL || `https://api.browserbase.com`, }; - 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 || environments[options.environment || 'production'], + baseURL: options.baseURL!, timeout: options.timeout ?? 60000 /* 1 minute */, httpAgent: options.httpAgent, maxRetries: options.maxRetries, diff --git a/tests/index.test.ts b/tests/index.test.ts index 367603a..2603353 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -159,19 +159,6 @@ describe('instantiate client', () => { const client = new Browserbase({ apiKey: 'My API Key' }); 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'); - }); }); test('maxRetries option is correctly set', () => {