@browserbasehq/sdk 2.5.0 → 2.7.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/LICENSE +1 -1
- package/README.md +8 -20
- package/_shims/node-runtime.js +17 -7
- package/_shims/node-runtime.js.map +1 -1
- package/core.d.ts +19 -5
- package/core.d.ts.map +1 -1
- package/core.js +30 -18
- package/core.js.map +1 -1
- package/core.mjs +30 -18
- package/core.mjs.map +1 -1
- package/index.d.mts +3 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -1
- package/index.js +23 -9
- package/index.js.map +1 -1
- package/index.mjs +6 -2
- package/index.mjs.map +1 -1
- package/package.json +4 -5
- package/resource.d.ts +1 -1
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/contexts.d.ts +11 -5
- package/resources/contexts.d.ts.map +1 -1
- package/resources/contexts.js +16 -6
- package/resources/contexts.js.map +1 -1
- package/resources/contexts.mjs +16 -6
- package/resources/contexts.mjs.map +1 -1
- package/resources/extensions.d.ts +2 -2
- package/resources/extensions.js +19 -9
- package/resources/extensions.js.map +1 -1
- package/resources/extensions.mjs +2 -2
- package/resources/projects.d.ts +3 -3
- package/resources/projects.js +3 -3
- package/resources/projects.mjs +3 -3
- package/resources/sessions/logs.d.ts +6 -2
- package/resources/sessions/logs.d.ts.map +1 -1
- package/resources/sessions/recording.d.ts +3 -1
- package/resources/sessions/recording.d.ts.map +1 -1
- package/resources/sessions/sessions.d.ts +59 -141
- package/resources/sessions/sessions.d.ts.map +1 -1
- package/resources/sessions/sessions.js +23 -13
- package/resources/sessions/sessions.js.map +1 -1
- package/resources/sessions/sessions.mjs +6 -6
- package/resources/sessions/sessions.mjs.map +1 -1
- package/resources/sessions/uploads.js +17 -7
- package/resources/sessions/uploads.js.map +1 -1
- package/src/core.ts +46 -17
- package/src/index.ts +11 -0
- package/src/resource.ts +1 -1
- package/src/resources/contexts.ts +25 -5
- package/src/resources/extensions.ts +2 -2
- package/src/resources/projects.ts +3 -3
- package/src/resources/sessions/logs.ts +2 -2
- package/src/resources/sessions/recording.ts +1 -1
- package/src/resources/sessions/sessions.ts +73 -186
- package/src/uploads.ts +2 -3
- package/src/version.ts +1 -1
- package/uploads.d.ts.map +1 -1
- package/uploads.js +2 -1
- package/uploads.js.map +1 -1
- package/uploads.mjs +2 -1
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
package/src/core.ts
CHANGED
|
@@ -33,6 +33,20 @@ export {
|
|
|
33
33
|
|
|
34
34
|
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* An alias to the builtin `Array` type so we can
|
|
38
|
+
* easily alias it in import statements if there are name clashes.
|
|
39
|
+
*/
|
|
40
|
+
type _Array<T> = Array<T>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An alias to the builtin `Record` type so we can
|
|
44
|
+
* easily alias it in import statements if there are name clashes.
|
|
45
|
+
*/
|
|
46
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
47
|
+
|
|
48
|
+
export type { _Array as Array, _Record as Record };
|
|
49
|
+
|
|
36
50
|
type PromiseOrValue<T> = T | Promise<T>;
|
|
37
51
|
|
|
38
52
|
type APIResponseProps = {
|
|
@@ -56,6 +70,12 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
|
|
|
56
70
|
const mediaType = contentType?.split(';')[0]?.trim();
|
|
57
71
|
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
58
72
|
if (isJSON) {
|
|
73
|
+
const contentLength = response.headers.get('content-length');
|
|
74
|
+
if (contentLength === '0') {
|
|
75
|
+
// if there is no content we can't do anything
|
|
76
|
+
return undefined as T;
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
const json = await response.json();
|
|
60
80
|
|
|
61
81
|
debug('response', response.status, response.url, response.headers, json);
|
|
@@ -156,6 +176,7 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
156
176
|
|
|
157
177
|
export abstract class APIClient {
|
|
158
178
|
baseURL: string;
|
|
179
|
+
#baseURLOverridden: boolean;
|
|
159
180
|
maxRetries: number;
|
|
160
181
|
timeout: number;
|
|
161
182
|
httpAgent: Agent | undefined;
|
|
@@ -165,18 +186,21 @@ export abstract class APIClient {
|
|
|
165
186
|
|
|
166
187
|
constructor({
|
|
167
188
|
baseURL,
|
|
189
|
+
baseURLOverridden,
|
|
168
190
|
maxRetries = 2,
|
|
169
191
|
timeout = 60000, // 1 minute
|
|
170
192
|
httpAgent,
|
|
171
193
|
fetch: overriddenFetch,
|
|
172
194
|
}: {
|
|
173
195
|
baseURL: string;
|
|
196
|
+
baseURLOverridden: boolean;
|
|
174
197
|
maxRetries?: number | undefined;
|
|
175
198
|
timeout: number | undefined;
|
|
176
199
|
httpAgent: Agent | undefined;
|
|
177
200
|
fetch: Fetch | undefined;
|
|
178
201
|
}) {
|
|
179
202
|
this.baseURL = baseURL;
|
|
203
|
+
this.#baseURLOverridden = baseURLOverridden;
|
|
180
204
|
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
|
|
181
205
|
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
182
206
|
this.httpAgent = httpAgent;
|
|
@@ -199,7 +223,7 @@ export abstract class APIClient {
|
|
|
199
223
|
protected defaultHeaders(opts: FinalRequestOptions): Headers {
|
|
200
224
|
return {
|
|
201
225
|
Accept: 'application/json',
|
|
202
|
-
'Content-Type': 'application/json',
|
|
226
|
+
...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
|
|
203
227
|
'User-Agent': this.getUserAgent(),
|
|
204
228
|
...getPlatformHeaders(),
|
|
205
229
|
...this.authHeaders(opts),
|
|
@@ -281,12 +305,12 @@ export abstract class APIClient {
|
|
|
281
305
|
return null;
|
|
282
306
|
}
|
|
283
307
|
|
|
284
|
-
buildRequest<Req>(
|
|
285
|
-
|
|
308
|
+
async buildRequest<Req>(
|
|
309
|
+
inputOptions: FinalRequestOptions<Req>,
|
|
286
310
|
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
287
|
-
): { req: RequestInit; url: string; timeout: number } {
|
|
288
|
-
options = { ...
|
|
289
|
-
const { method, path, query, headers: headers = {} } = options;
|
|
311
|
+
): Promise<{ req: RequestInit; url: string; timeout: number }> {
|
|
312
|
+
const options = { ...inputOptions };
|
|
313
|
+
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
|
|
290
314
|
|
|
291
315
|
const body =
|
|
292
316
|
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
|
|
@@ -296,7 +320,7 @@ export abstract class APIClient {
|
|
|
296
320
|
: null;
|
|
297
321
|
const contentLength = this.calculateContentLength(body);
|
|
298
322
|
|
|
299
|
-
const url = this.buildURL(path!, query);
|
|
323
|
+
const url = this.buildURL(path!, query, defaultBaseURL);
|
|
300
324
|
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
301
325
|
options.timeout = options.timeout ?? this.timeout;
|
|
302
326
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
|
|
@@ -313,8 +337,8 @@ export abstract class APIClient {
|
|
|
313
337
|
}
|
|
314
338
|
|
|
315
339
|
if (this.idempotencyHeader && method !== 'get') {
|
|
316
|
-
if (!
|
|
317
|
-
headers[this.idempotencyHeader] =
|
|
340
|
+
if (!inputOptions.idempotencyKey) inputOptions.idempotencyKey = this.defaultIdempotencyKey();
|
|
341
|
+
headers[this.idempotencyHeader] = inputOptions.idempotencyKey;
|
|
318
342
|
}
|
|
319
343
|
|
|
320
344
|
const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
|
|
@@ -371,7 +395,7 @@ export abstract class APIClient {
|
|
|
371
395
|
getHeader(headers, 'x-stainless-timeout') === undefined &&
|
|
372
396
|
options.timeout
|
|
373
397
|
) {
|
|
374
|
-
reqHeaders['x-stainless-timeout'] = String(options.timeout);
|
|
398
|
+
reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
|
|
375
399
|
}
|
|
376
400
|
|
|
377
401
|
this.validateHeaders(reqHeaders, headers);
|
|
@@ -432,7 +456,9 @@ export abstract class APIClient {
|
|
|
432
456
|
|
|
433
457
|
await this.prepareOptions(options);
|
|
434
458
|
|
|
435
|
-
const { req, url, timeout } = this.buildRequest(options, {
|
|
459
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
460
|
+
retryCount: maxRetries - retriesRemaining,
|
|
461
|
+
});
|
|
436
462
|
|
|
437
463
|
await this.prepareRequest(req, { url, options });
|
|
438
464
|
|
|
@@ -489,11 +515,12 @@ export abstract class APIClient {
|
|
|
489
515
|
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
490
516
|
}
|
|
491
517
|
|
|
492
|
-
buildURL<Req>(path: string, query: Req | null | undefined): string {
|
|
518
|
+
buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string {
|
|
519
|
+
const baseURL = (!this.#baseURLOverridden && defaultBaseURL) || this.baseURL;
|
|
493
520
|
const url =
|
|
494
521
|
isAbsoluteURL(path) ?
|
|
495
522
|
new URL(path)
|
|
496
|
-
: new URL(
|
|
523
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
497
524
|
|
|
498
525
|
const defaultQuery = this.defaultQuery();
|
|
499
526
|
if (!isEmptyObj(defaultQuery)) {
|
|
@@ -778,6 +805,7 @@ export type RequestOptions<
|
|
|
778
805
|
query?: Req | undefined;
|
|
779
806
|
body?: Req | null | undefined;
|
|
780
807
|
headers?: Headers | undefined;
|
|
808
|
+
defaultBaseURL?: string | undefined;
|
|
781
809
|
|
|
782
810
|
maxRetries?: number;
|
|
783
811
|
stream?: boolean | undefined;
|
|
@@ -799,6 +827,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
|
|
|
799
827
|
query: true,
|
|
800
828
|
body: true,
|
|
801
829
|
headers: true,
|
|
830
|
+
defaultBaseURL: true,
|
|
802
831
|
|
|
803
832
|
maxRetries: true,
|
|
804
833
|
stream: true,
|
|
@@ -857,7 +886,7 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
857
886
|
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
858
887
|
'X-Stainless-Runtime': 'deno',
|
|
859
888
|
'X-Stainless-Runtime-Version':
|
|
860
|
-
typeof Deno.version === 'string' ? Deno.version :
|
|
889
|
+
typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
|
861
890
|
};
|
|
862
891
|
}
|
|
863
892
|
if (typeof EdgeRuntime !== 'undefined') {
|
|
@@ -1065,21 +1094,21 @@ export const coerceBoolean = (value: unknown): boolean => {
|
|
|
1065
1094
|
};
|
|
1066
1095
|
|
|
1067
1096
|
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
1068
|
-
if (value
|
|
1097
|
+
if (value == null) {
|
|
1069
1098
|
return undefined;
|
|
1070
1099
|
}
|
|
1071
1100
|
return coerceInteger(value);
|
|
1072
1101
|
};
|
|
1073
1102
|
|
|
1074
1103
|
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
1075
|
-
if (value
|
|
1104
|
+
if (value == null) {
|
|
1076
1105
|
return undefined;
|
|
1077
1106
|
}
|
|
1078
1107
|
return coerceFloat(value);
|
|
1079
1108
|
};
|
|
1080
1109
|
|
|
1081
1110
|
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
1082
|
-
if (value
|
|
1111
|
+
if (value == null) {
|
|
1083
1112
|
return undefined;
|
|
1084
1113
|
}
|
|
1085
1114
|
return coerceBoolean(value);
|
package/src/index.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface ClientOptions {
|
|
|
45
45
|
*
|
|
46
46
|
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
47
47
|
* much longer than this timeout before the promise succeeds or fails.
|
|
48
|
+
*
|
|
49
|
+
* @unit milliseconds
|
|
48
50
|
*/
|
|
49
51
|
timeout?: number | undefined;
|
|
50
52
|
|
|
@@ -128,6 +130,7 @@ export class Browserbase extends Core.APIClient {
|
|
|
128
130
|
|
|
129
131
|
super({
|
|
130
132
|
baseURL: options.baseURL!,
|
|
133
|
+
baseURLOverridden: baseURL ? baseURL !== 'https://api.browserbase.com' : false,
|
|
131
134
|
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
132
135
|
httpAgent: options.httpAgent,
|
|
133
136
|
maxRetries: options.maxRetries,
|
|
@@ -144,6 +147,13 @@ export class Browserbase extends Core.APIClient {
|
|
|
144
147
|
projects: API.Projects = new API.Projects(this);
|
|
145
148
|
sessions: API.Sessions = new API.Sessions(this);
|
|
146
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Check whether the base URL is set to its default.
|
|
152
|
+
*/
|
|
153
|
+
#baseURLOverridden(): boolean {
|
|
154
|
+
return this.baseURL !== 'https://api.browserbase.com';
|
|
155
|
+
}
|
|
156
|
+
|
|
147
157
|
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
148
158
|
return this._options.defaultQuery;
|
|
149
159
|
}
|
|
@@ -184,6 +194,7 @@ Browserbase.Contexts = Contexts;
|
|
|
184
194
|
Browserbase.Extensions = Extensions;
|
|
185
195
|
Browserbase.Projects = Projects;
|
|
186
196
|
Browserbase.Sessions = Sessions;
|
|
197
|
+
|
|
187
198
|
export declare namespace Browserbase {
|
|
188
199
|
export type RequestOptions = Core.RequestOptions;
|
|
189
200
|
|
package/src/resource.ts
CHANGED
|
@@ -1,29 +1,48 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
|
+
import { isRequestOptions } from '../core';
|
|
4
5
|
import * as Core from '../core';
|
|
5
6
|
|
|
6
7
|
export class Contexts extends APIResource {
|
|
7
8
|
/**
|
|
8
9
|
* Create a Context
|
|
9
10
|
*/
|
|
10
|
-
create(body
|
|
11
|
+
create(body?: ContextCreateParams, options?: Core.RequestOptions): Core.APIPromise<ContextCreateResponse>;
|
|
12
|
+
create(options?: Core.RequestOptions): Core.APIPromise<ContextCreateResponse>;
|
|
13
|
+
create(
|
|
14
|
+
body: ContextCreateParams | Core.RequestOptions = {},
|
|
15
|
+
options?: Core.RequestOptions,
|
|
16
|
+
): Core.APIPromise<ContextCreateResponse> {
|
|
17
|
+
if (isRequestOptions(body)) {
|
|
18
|
+
return this.create({}, body);
|
|
19
|
+
}
|
|
11
20
|
return this._client.post('/v1/contexts', { body, ...options });
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
|
-
* Context
|
|
24
|
+
* Get a Context
|
|
16
25
|
*/
|
|
17
26
|
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<Context> {
|
|
18
27
|
return this._client.get(`/v1/contexts/${id}`, options);
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
/**
|
|
22
|
-
* Update Context
|
|
31
|
+
* Update a Context
|
|
23
32
|
*/
|
|
24
33
|
update(id: string, options?: Core.RequestOptions): Core.APIPromise<ContextUpdateResponse> {
|
|
25
34
|
return this._client.put(`/v1/contexts/${id}`, options);
|
|
26
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Delete a Context
|
|
39
|
+
*/
|
|
40
|
+
delete(id: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
41
|
+
return this._client.delete(`/v1/contexts/${id}`, {
|
|
42
|
+
...options,
|
|
43
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
27
46
|
}
|
|
28
47
|
|
|
29
48
|
export interface Context {
|
|
@@ -94,9 +113,10 @@ export interface ContextUpdateResponse {
|
|
|
94
113
|
export interface ContextCreateParams {
|
|
95
114
|
/**
|
|
96
115
|
* The Project ID. Can be found in
|
|
97
|
-
* [Settings](https://www.browserbase.com/settings).
|
|
116
|
+
* [Settings](https://www.browserbase.com/settings). Optional - if not provided,
|
|
117
|
+
* the project will be inferred from the API key.
|
|
98
118
|
*/
|
|
99
|
-
projectId
|
|
119
|
+
projectId?: string;
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
export declare namespace Contexts {
|
|
@@ -12,14 +12,14 @@ export class Extensions extends APIResource {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Extension
|
|
15
|
+
* Get an Extension
|
|
16
16
|
*/
|
|
17
17
|
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<Extension> {
|
|
18
18
|
return this._client.get(`/v1/extensions/${id}`, options);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Delete Extension
|
|
22
|
+
* Delete an Extension
|
|
23
23
|
*/
|
|
24
24
|
delete(id: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
25
25
|
return this._client.delete(`/v1/extensions/${id}`, {
|
|
@@ -5,21 +5,21 @@ import * as Core from '../core';
|
|
|
5
5
|
|
|
6
6
|
export class Projects extends APIResource {
|
|
7
7
|
/**
|
|
8
|
-
* Project
|
|
8
|
+
* Get a Project
|
|
9
9
|
*/
|
|
10
10
|
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<Project> {
|
|
11
11
|
return this._client.get(`/v1/projects/${id}`, options);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* List
|
|
15
|
+
* List Projects
|
|
16
16
|
*/
|
|
17
17
|
list(options?: Core.RequestOptions): Core.APIPromise<ProjectListResponse> {
|
|
18
18
|
return this._client.get('/v1/projects', options);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Project Usage
|
|
22
|
+
* Get Project Usage
|
|
23
23
|
*/
|
|
24
24
|
usage(id: string, options?: Core.RequestOptions): Core.APIPromise<ProjectUsage> {
|
|
25
25
|
return this._client.get(`/v1/projects/${id}/usage`, options);
|
|
@@ -35,7 +35,7 @@ export interface SessionLog {
|
|
|
35
35
|
|
|
36
36
|
export namespace SessionLog {
|
|
37
37
|
export interface Request {
|
|
38
|
-
params:
|
|
38
|
+
params: { [key: string]: unknown };
|
|
39
39
|
|
|
40
40
|
rawBody: string;
|
|
41
41
|
|
|
@@ -48,7 +48,7 @@ export namespace SessionLog {
|
|
|
48
48
|
export interface Response {
|
|
49
49
|
rawBody: string;
|
|
50
50
|
|
|
51
|
-
result:
|
|
51
|
+
result: { [key: string]: unknown };
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* milliseconds that have elapsed since the UNIX epoch
|