Skip to content

Commit bee573a

Browse files
author
Stainless Bot
committed
feat(api): api update (#26)
1 parent 32eecb7 commit bee573a

27 files changed

+87
-89
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ $ cd sdk-node
5555
# With yarn
5656
$ yarn link
5757
$ cd ../my-package
58-
$ yarn link browserbase
58+
$ yarn link @browserbasehq/sdk
5959

6060
# With pnpm
6161
$ pnpm link --global
6262
$ cd ../my-package
63-
$ pnpm link -—global browserbase
63+
$ pnpm link -—global @browserbasehq/sdk
6464
```
6565

6666
## Running tests

README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Browserbase Node API Library
22

3-
[![NPM version](https://img.shields.io/npm/v/browserbase.svg)](https://npmjs.org/package/browserbase) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/browserbase)
3+
[![NPM version](https://img.shields.io/npm/v/@browserbasehq/sdk.svg)](https://npmjs.org/package/@browserbasehq/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@browserbasehq/sdk)
44

55
This library provides convenient access to the Browserbase REST API from server-side TypeScript or JavaScript.
66

@@ -15,22 +15,22 @@ npm install git+ssh://[email protected]:browserbase/sdk-node.git
1515
```
1616

1717
> [!NOTE]
18-
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install browserbase`
18+
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install @browserbasehq/sdk`
1919
2020
## Usage
2121

2222
The full API of this library can be found in [api.md](api.md).
2323

2424
<!-- prettier-ignore -->
2525
```js
26-
import Browserbase from 'browserbase';
26+
import Browserbase from '@browserbasehq/sdk';
2727

2828
const client = new Browserbase({
2929
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
3030
});
3131

3232
async function main() {
33-
const session = await client.sessions.create({ projectId: 'your_project_id', proxies: true });
33+
const session = await client.sessions.create({ projectId: 'your_project_id' });
3434

3535
console.log(session.id);
3636
}
@@ -44,14 +44,14 @@ This library includes TypeScript definitions for all request params and response
4444

4545
<!-- prettier-ignore -->
4646
```ts
47-
import Browserbase from 'browserbase';
47+
import Browserbase from '@browserbasehq/sdk';
4848

4949
const client = new Browserbase({
5050
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
5151
});
5252

5353
async function main() {
54-
const params: Browserbase.SessionCreateParams = { projectId: 'your_project_id', proxies: true };
54+
const params: Browserbase.SessionCreateParams = { projectId: 'your_project_id' };
5555
const session: Browserbase.SessionCreateResponse = await client.sessions.create(params);
5656
}
5757

@@ -69,17 +69,15 @@ a subclass of `APIError` will be thrown:
6969
<!-- prettier-ignore -->
7070
```ts
7171
async function main() {
72-
const session = await client.sessions
73-
.create({ projectId: 'your_project_id', proxies: true })
74-
.catch(async (err) => {
75-
if (err instanceof Browserbase.APIError) {
76-
console.log(err.status); // 400
77-
console.log(err.name); // BadRequestError
78-
console.log(err.headers); // {server: 'nginx', ...}
79-
} else {
80-
throw err;
81-
}
82-
});
72+
const session = await client.sessions.create({ projectId: 'your_project_id' }).catch(async (err) => {
73+
if (err instanceof Browserbase.APIError) {
74+
console.log(err.status); // 400
75+
console.log(err.name); // BadRequestError
76+
console.log(err.headers); // {server: 'nginx', ...}
77+
} else {
78+
throw err;
79+
}
80+
});
8381
}
8482

8583
main();
@@ -114,7 +112,7 @@ const client = new Browserbase({
114112
});
115113

116114
// Or, configure per-request:
117-
await client.sessions.create({ projectId: 'your_project_id', proxies: true }, {
115+
await client.sessions.create({ projectId: 'your_project_id' }, {
118116
maxRetries: 5,
119117
});
120118
```
@@ -131,7 +129,7 @@ const client = new Browserbase({
131129
});
132130

133131
// Override per-request:
134-
await client.sessions.create({ projectId: 'your_project_id', proxies: true }, {
132+
await client.sessions.create({ projectId: 'your_project_id' }, {
135133
timeout: 5 * 1000,
136134
});
137135
```
@@ -152,12 +150,12 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
152150
```ts
153151
const client = new Browserbase();
154152

155-
const response = await client.sessions.create({ projectId: 'your_project_id', proxies: true }).asResponse();
153+
const response = await client.sessions.create({ projectId: 'your_project_id' }).asResponse();
156154
console.log(response.headers.get('X-My-Header'));
157155
console.log(response.statusText); // access the underlying Response object
158156

159157
const { data: session, response: raw } = await client.sessions
160-
.create({ projectId: 'your_project_id', proxies: true })
158+
.create({ projectId: 'your_project_id' })
161159
.withResponse();
162160
console.log(raw.headers.get('X-My-Header'));
163161
console.log(session.id);
@@ -218,11 +216,11 @@ add the following import before your first import `from "Browserbase"`:
218216
```ts
219217
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
220218
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
221-
import 'browserbase/shims/web';
222-
import Browserbase from 'browserbase';
219+
import '@browserbasehq/sdk/shims/web';
220+
import Browserbase from '@browserbasehq/sdk';
223221
```
224222

225-
To do the inverse, add `import "browserbase/shims/node"` (which does import polyfills).
223+
To do the inverse, add `import "@browserbasehq/sdk/shims/node"` (which does import polyfills).
226224
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/browserbase/sdk-node/tree/main/src/_shims#readme)).
227225

228226
### Logging and middleware
@@ -232,7 +230,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e
232230

233231
```ts
234232
import { fetch } from 'undici'; // as one example
235-
import Browserbase from 'browserbase';
233+
import Browserbase from '@browserbasehq/sdk';
236234

237235
const client = new Browserbase({
238236
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
@@ -265,7 +263,7 @@ const client = new Browserbase({
265263

266264
// Override per-request:
267265
await client.sessions.create(
268-
{ projectId: 'your_project_id', proxies: true },
266+
{ projectId: 'your_project_id' },
269267
{
270268
httpAgent: new http.Agent({ keepAlive: false }),
271269
},

jest.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = {
77
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
88
},
99
moduleNameMapper: {
10-
'^browserbase$': '<rootDir>/src/index.ts',
11-
'^browserbase/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12-
'^browserbase/(.*)$': '<rootDir>/src/$1',
10+
'^@browserbasehq/sdk$': '<rootDir>/src/index.ts',
11+
'^@browserbasehq/sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12+
'^@browserbasehq/sdk/(.*)$': '<rootDir>/src/$1',
1313
},
1414
modulePathIgnorePatterns: [
1515
'<rootDir>/ecosystem-tests/',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"./shims/web.mjs"
6767
],
6868
"imports": {
69-
"browserbase": ".",
70-
"browserbase/*": "./src/*"
69+
"@browserbasehq/sdk": ".",
70+
"@browserbasehq/sdk/*": "./src/*"
7171
},
7272
"exports": {
7373
"./_shims/auto/*": {

scripts/build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs
88

99
# Build into dist and will publish the package from there,
1010
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
11-
# This way importing from `"browserbase/resources/foo"` works
11+
# This way importing from `"@browserbasehq/sdk/resources/foo"` works
1212
# even with `"moduleResolution": "node"`
1313

1414
rm -rf dist; mkdir dist
@@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs
4747

4848
# make sure that nothing crashes when we require the output CJS or
4949
# import the output ESM
50-
(cd dist && node -e 'require("browserbase")')
51-
(cd dist && node -e 'import("browserbase")' --input-type=module)
50+
(cd dist && node -e 'require("@browserbasehq/sdk")')
51+
(cd dist && node -e 'import("@browserbasehq/sdk")' --input-type=module)
5252

5353
if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
5454
then

scripts/utils/postprocess-files.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const { parse } = require('@typescript-eslint/parser');
44

5-
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'browserbase/';
5+
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@browserbasehq/sdk/';
66

77
const distDir =
88
process.env['DIST_PATH'] ?
@@ -142,7 +142,7 @@ async function postprocess() {
142142

143143
if (file.endsWith('.d.ts')) {
144144
// work around bad tsc behavior
145-
// if we have `import { type Readable } from 'browserbase/_shims/index'`,
145+
// if we have `import { type Readable } from '@browserbasehq/sdk/_shims/index'`,
146146
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
147147
// in the output .d.ts
148148
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');

src/_shims/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 👋 Wondering what everything in here does?
22

3-
`browserbase` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
3+
`@browserbasehq/sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
44
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
55

6-
To do this, `browserbase` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
6+
To do this, `@browserbasehq/sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
77

88
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
99
automatically select the correct shims for each environment. However, conditional exports are a fairly new
@@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example.
1515

1616
The user can work around these issues by manually importing one of:
1717

18-
- `import 'browserbase/shims/node'`
19-
- `import 'browserbase/shims/web'`
18+
- `import '@browserbasehq/sdk/shims/node'`
19+
- `import '@browserbasehq/sdk/shims/web'`
2020

2121
All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
2222

2323
### How it works - Runtime
2424

25-
Runtime shims get installed by calling `setShims` exported by `browserbase/_shims/registry`.
25+
Runtime shims get installed by calling `setShims` exported by `@browserbasehq/sdk/_shims/registry`.
2626

27-
Manually importing `browserbase/shims/node` or `browserbase/shims/web`, calls `setShims` with the respective runtime shims.
27+
Manually importing `@browserbasehq/sdk/shims/node` or `@browserbasehq/sdk/shims/web`, calls `setShims` with the respective runtime shims.
2828

29-
All client code imports shims from `browserbase/_shims/index`, which:
29+
All client code imports shims from `@browserbasehq/sdk/_shims/index`, which:
3030

3131
- checks if shims have been set manually
32-
- if not, calls `setShims` with the shims from `browserbase/_shims/auto/runtime`
33-
- re-exports the installed shims from `browserbase/_shims/registry`.
32+
- if not, calls `setShims` with the shims from `@browserbasehq/sdk/_shims/auto/runtime`
33+
- re-exports the installed shims from `@browserbasehq/sdk/_shims/registry`.
3434

35-
`browserbase/_shims/auto/runtime` exports web runtime shims.
36-
If the `node` export condition is set, the export map replaces it with `browserbase/_shims/auto/runtime-node`.
35+
`@browserbasehq/sdk/_shims/auto/runtime` exports web runtime shims.
36+
If the `node` export condition is set, the export map replaces it with `@browserbasehq/sdk/_shims/auto/runtime-node`.
3737

3838
### How it works - Type time
3939

40-
All client code imports shim types from `browserbase/_shims/index`, which selects the manual types from `browserbase/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `browserbase/_shims/auto/types`.
40+
All client code imports shim types from `@browserbasehq/sdk/_shims/index`, which selects the manual types from `@browserbasehq/sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@browserbasehq/sdk/_shims/auto/types`.
4141

42-
`browserbase/_shims/manual-types` exports an empty namespace.
43-
Manually importing `browserbase/shims/node` or `browserbase/shims/web` merges declarations into this empty namespace, so they get picked up by `browserbase/_shims/index`.
42+
`@browserbasehq/sdk/_shims/manual-types` exports an empty namespace.
43+
Manually importing `@browserbasehq/sdk/shims/node` or `@browserbasehq/sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@browserbasehq/sdk/_shims/index`.
4444

45-
`browserbase/_shims/auto/types` exports web type definitions.
46-
If the `node` export condition is set, the export map replaces it with `browserbase/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
45+
`@browserbasehq/sdk/_shims/auto/types` exports web type definitions.
46+
If the `node` export condition is set, the export map replaces it with `@browserbasehq/sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.

src/_shims/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
import { manual } from './manual-types';
5-
import * as auto from 'browserbase/_shims/auto/types';
5+
import * as auto from '@browserbasehq/sdk/_shims/auto/types';
66
import { type RequestOptions } from '../core';
77

88
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;

src/_shims/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
const shims = require('./registry');
5-
const auto = require('browserbase/_shims/auto/runtime');
5+
const auto = require('@browserbasehq/sdk/_shims/auto/runtime');
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
for (const property of Object.keys(shims)) {
88
Object.defineProperty(exports, property, {

src/_shims/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
import * as shims from './registry.mjs';
5-
import * as auto from 'browserbase/_shims/auto/runtime';
5+
import * as auto from '@browserbasehq/sdk/_shims/auto/runtime';
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
export * from './registry.mjs';

0 commit comments

Comments
 (0)