From a96a86c2e7c5025cacd7edd89f88b914de3596e3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:21:27 +0000 Subject: [PATCH 1/3] feat(api): update via SDK Studio (#16) --- .stats.yml | 2 +- README.md | 2 ++ package.json | 2 +- src/index.ts | 31 ++++++++++++++++++++++++++++--- tests/index.test.ts | 17 +++++++++++++++-- 5 files changed, 47 insertions(+), 7 deletions(-) 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 593ead0..f56ff7d 100644 --- a/package.json +++ b/package.json @@ -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/tests/index.test.ts b/tests/index.test.ts index 55a9e2e..c1f07a2 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'); }); }); From 52cf741bc4c5712f2fe15ee6eaa48e4c3643ec58 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:14:22 +0000 Subject: [PATCH 2/3] feat(api): update via SDK Studio (#17) --- 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 f56ff7d..fdc13a5 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 c1f07a2..7c42594 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', () => { From 639e9590b1f19ef1c927202331b891b417486c73 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:14:38 +0000 Subject: [PATCH 3/3] release: 0.1.0-alpha.2 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/version.ts | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d7a8735..c5e8a3e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.1" + ".": "0.1.0-alpha.2" } diff --git a/CHANGELOG.md b/CHANGELOG.md index eb71cba..c263641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.1.0-alpha.2 (2024-10-28) + +Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/browserbase/sdk-node/compare/v0.1.0-alpha.1...v0.1.0-alpha.2) + +### Features + +* **api:** update via SDK Studio ([#16](https://github.com/browserbase/sdk-node/issues/16)) ([a96a86c](https://github.com/browserbase/sdk-node/commit/a96a86c2e7c5025cacd7edd89f88b914de3596e3)) +* **api:** update via SDK Studio ([#17](https://github.com/browserbase/sdk-node/issues/17)) ([52cf741](https://github.com/browserbase/sdk-node/commit/52cf741bc4c5712f2fe15ee6eaa48e4c3643ec58)) + ## 0.1.0-alpha.1 (2024-10-28) Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/browserbase/sdk-node/compare/v0.0.1-alpha.0...v0.1.0-alpha.1) diff --git a/package-lock.json b/package-lock.json index 6bc8da7..f9ece45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "browserbase", - "version": "0.1.0-alpha.1", + "version": "0.1.0-alpha.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "browserbase", - "version": "0.1.0-alpha.1", + "version": "0.1.0-alpha.2", "license": "Apache-2.0", "dependencies": { "@types/node": "^18.11.18", diff --git a/package.json b/package.json index fdc13a5..47bd3a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "browserbase", - "version": "0.1.0-alpha.1", + "version": "0.1.0-alpha.2", "description": "The official TypeScript library for the Browserbase API", "author": "Browserbase ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index b0bfd9e..a528f63 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.1'; // x-release-please-version +export const VERSION = '0.1.0-alpha.2'; // x-release-please-version