Skip to content

Commit 32eecb7

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

27 files changed

+74
-71
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 @browserbasehq/sdk
58+
$ yarn link browserbase
5959

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

6666
## Running tests

README.md

Lines changed: 11 additions & 8 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/@browserbasehq/sdk.svg)](https://npmjs.org/package/@browserbasehq/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@browserbasehq/sdk)
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)
44

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

@@ -11,16 +11,19 @@ It is generated with [Stainless](https://www.stainlessapi.com/).
1111
## Installation
1212

1313
```sh
14-
npm install @browserbasehq/sdk
14+
npm install git+ssh://[email protected]:browserbase/sdk-node.git
1515
```
1616

17+
> [!NOTE]
18+
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install browserbase`
19+
1720
## Usage
1821

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

2124
<!-- prettier-ignore -->
2225
```js
23-
import Browserbase from '@browserbasehq/sdk';
26+
import Browserbase from 'browserbase';
2427

2528
const client = new Browserbase({
2629
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
@@ -41,7 +44,7 @@ This library includes TypeScript definitions for all request params and response
4144

4245
<!-- prettier-ignore -->
4346
```ts
44-
import Browserbase from '@browserbasehq/sdk';
47+
import Browserbase from 'browserbase';
4548

4649
const client = new Browserbase({
4750
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
@@ -215,11 +218,11 @@ add the following import before your first import `from "Browserbase"`:
215218
```ts
216219
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
217220
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
218-
import '@browserbasehq/sdk/shims/web';
219-
import Browserbase from '@browserbasehq/sdk';
221+
import 'browserbase/shims/web';
222+
import Browserbase from 'browserbase';
220223
```
221224

222-
To do the inverse, add `import "@browserbasehq/sdk/shims/node"` (which does import polyfills).
225+
To do the inverse, add `import "browserbase/shims/node"` (which does import polyfills).
223226
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)).
224227

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

230233
```ts
231234
import { fetch } from 'undici'; // as one example
232-
import Browserbase from '@browserbasehq/sdk';
235+
import Browserbase from 'browserbase';
233236

234237
const client = new Browserbase({
235238
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {

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-
'^@browserbasehq/sdk$': '<rootDir>/src/index.ts',
11-
'^@browserbasehq/sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12-
'^@browserbasehq/sdk/(.*)$': '<rootDir>/src/$1',
10+
'^browserbase$': '<rootDir>/src/index.ts',
11+
'^browserbase/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12+
'^browserbase/(.*)$': '<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-
"@browserbasehq/sdk": ".",
70-
"@browserbasehq/sdk/*": "./src/*"
69+
"browserbase": ".",
70+
"browserbase/*": "./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 `"@browserbasehq/sdk/resources/foo"` works
11+
# This way importing from `"browserbase/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("@browserbasehq/sdk")')
51-
(cd dist && node -e 'import("@browserbasehq/sdk")' --input-type=module)
50+
(cd dist && node -e 'require("browserbase")')
51+
(cd dist && node -e 'import("browserbase")' --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'] ?? '@browserbasehq/sdk/';
5+
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'browserbase/';
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 '@browserbasehq/sdk/_shims/index'`,
145+
// if we have `import { type Readable } from 'browserbase/_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-
`@browserbasehq/sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
3+
`browserbase` 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, `@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.
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.
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 '@browserbasehq/sdk/shims/node'`
19-
- `import '@browserbasehq/sdk/shims/web'`
18+
- `import 'browserbase/shims/node'`
19+
- `import 'browserbase/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 `@browserbasehq/sdk/_shims/registry`.
25+
Runtime shims get installed by calling `setShims` exported by `browserbase/_shims/registry`.
2626

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

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

3131
- checks if shims have been set manually
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`.
32+
- if not, calls `setShims` with the shims from `browserbase/_shims/auto/runtime`
33+
- re-exports the installed shims from `browserbase/_shims/registry`.
3434

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`.
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`.
3737

3838
### How it works - Type time
3939

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`.
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`.
4141

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`.
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`.
4444

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"`.
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"`.

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 '@browserbasehq/sdk/_shims/auto/types';
5+
import * as auto from 'browserbase/_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('@browserbasehq/sdk/_shims/auto/runtime');
5+
const auto = require('browserbase/_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 '@browserbasehq/sdk/_shims/auto/runtime';
5+
import * as auto from 'browserbase/_shims/auto/runtime';
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
export * from './registry.mjs';

0 commit comments

Comments
 (0)