diff --git a/package.json b/package.json index 9e8c02b..bd17bbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrapybara", - "version": "2.5.2", + "version": "2.6.0-beta.5", "private": false, "repository": "https://github.com/scrapybara/scrapybara-ts", "main": "./index.js", diff --git a/reference.md b/reference.md index 2ad5ea0..3774f1a 100644 --- a/reference.md +++ b/reference.md @@ -1,6 +1,6 @@ # Reference -
client.getAuthStates() -> Scrapybara.AuthStateResponse[] +
client.deleteAuthState({ ...params }) -> Scrapybara.DeleteBrowserAuthResponse
@@ -13,7 +13,9 @@
```typescript -await client.getAuthStates(); +await client.deleteAuthState({ + authStateId: "auth_state_id", +}); ```
@@ -29,6 +31,14 @@ await client.getAuthStates();
+**request:** `Scrapybara.DeleteAuthStateRequest` + +
+
+ +
+
+ **requestOptions:** `ScrapybaraClient.RequestOptions`
@@ -605,9 +615,199 @@ await client.instance.resume("instance_id");
+
client.instance.rescheduleTermination(instanceId, { ...params }) -> Scrapybara.StopInstanceResponse +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.instance.rescheduleTermination("instance_id"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instanceId:** `string` + +
+
+ +
+
+ +**request:** `Scrapybara.InstanceRescheduleTerminationRequest` + +
client.instance.exposePort(instanceId, { ...params }) -> Scrapybara.ExposePortResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Expose a port on the instance with a public-facing URL. + +This endpoint creates a temporary public URL that routes traffic to the specified port on the instance. + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.instance.exposePort("instance_id", { + port: 1, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instanceId:** `string` + +
+
+ +
+
+ +**request:** `Scrapybara.ExposePortRequest` + +
+
+ +
+
+ +**requestOptions:** `Instance.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.instance.deployToNetlify(instanceId, { ...params }) -> Scrapybara.NetlifyDeployResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Deploy a directory from the instance to Netlify. + +Args: +directory_path: Path to the directory on the instance to deploy + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.instance.deployToNetlify("instance_id", { + directoryPath: "directory_path", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instanceId:** `string` + +
+
+ +
+
+ +**request:** `Scrapybara.NetlifyDeployRequest` + +
+
+ +
+
+ +**requestOptions:** `Instance.RequestOptions` + +
+
+
+
+ +
+
+
+ ## Browser -
client.browser.start(instanceId) -> Scrapybara.StartBrowserResponse +
client.browser.start(instanceId, { ...params }) -> Scrapybara.StartBrowserResponse
@@ -644,6 +844,14 @@ await client.browser.start("instance_id");
+**request:** `Scrapybara.BrowserStartRequest` + +
+
+ +
+
+ **requestOptions:** `Browser.RequestOptions`
@@ -703,6 +911,54 @@ await client.browser.getCdpUrl("instance_id");
+
client.browser.getStreamUrl(instanceId) -> Scrapybara.BrowserGetStreamUrlResponse +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.browser.getStreamUrl("instance_id"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instanceId:** `string` + +
+
+ +
+
+ +**requestOptions:** `Browser.RequestOptions` + +
+
+
+
+ +
+
+
+
client.browser.getCurrentUrl(instanceId) -> Scrapybara.BrowserGetCurrentUrlResponse
@@ -1621,3 +1877,194 @@ await client.env.delete("instance_id", {
+ +## BetaVmManagement + +
client.betaVmManagement.takeSnapshot(instanceId) -> Scrapybara.SnapshotResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Take a snapshot of an instance + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.betaVmManagement.takeSnapshot("instance_id"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instanceId:** `string` + +
+
+ +
+
+ +**requestOptions:** `BetaVmManagement.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.betaVmManagement.warmupSnapshot(snapshotId) -> Scrapybara.SuccessResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Warmup a snapshot + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.betaVmManagement.warmupSnapshot("snapshot_id"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**snapshotId:** `string` + +
+
+ +
+
+ +**requestOptions:** `BetaVmManagement.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.betaVmManagement.deleteSnapshot(snapshotId) -> Scrapybara.SuccessResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete a snapshot + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.betaVmManagement.deleteSnapshot("snapshot_id"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**snapshotId:** `string` + +
+
+ +
+
+ +**requestOptions:** `BetaVmManagement.RequestOptions` + +
+
+
+
+ +
+
+
diff --git a/src/Client.ts b/src/Client.ts index f199fb3..1396c9a 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -13,6 +13,7 @@ import { Browser } from "./api/resources/browser/client/Client"; import { Code } from "./api/resources/code/client/Client"; import { Notebook } from "./api/resources/notebook/client/Client"; import { Env } from "./api/resources/env/client/Client"; +import { BetaVmManagement } from "./api/resources/betaVmManagement/client/Client"; export declare namespace ScrapybaraClient { export interface Options { @@ -38,6 +39,7 @@ export class ScrapybaraClient { protected _code: Code | undefined; protected _notebook: Notebook | undefined; protected _env: Env | undefined; + protected _betaVmManagement: BetaVmManagement | undefined; constructor(protected readonly _options: ScrapybaraClient.Options = {}) {} @@ -61,6 +63,10 @@ export class ScrapybaraClient { return (this._env ??= new Env(this._options)); } + public get betaVmManagement(): BetaVmManagement { + return (this._betaVmManagement ??= new BetaVmManagement(this._options)); + } + /** * @param {Scrapybara.DeploymentConfig} request * @param {ScrapybaraClient.RequestOptions} requestOptions - Request-specific configuration. @@ -83,8 +89,8 @@ export class ScrapybaraClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -162,8 +168,8 @@ export class ScrapybaraClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -238,8 +244,8 @@ export class ScrapybaraClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -300,8 +306,8 @@ export class ScrapybaraClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -344,6 +350,90 @@ export class ScrapybaraClient { } } + /** + * @param {Scrapybara.DeleteAuthStateRequest} request + * @param {ScrapybaraClient.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.deleteAuthState({ + * authStateId: "auth_state_id" + * }) + */ + public async deleteAuthState( + request: Scrapybara.DeleteAuthStateRequest, + requestOptions?: ScrapybaraClient.RequestOptions, + ): Promise { + const { authStateId } = request; + const _queryParams: Record = {}; + _queryParams["auth_state_id"] = authStateId; + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + "v1/delete_auth_state", + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + queryParameters: _queryParams, + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.DeleteBrowserAuthResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError("Timeout exceeded when calling POST /v1/delete_auth_state."); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + protected async _getCustomAuthorizationHeaders() { const apiKeyValue = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["SCRAPYBARA_API_KEY"]; return { "x-api-key": apiKeyValue }; diff --git a/src/ScrapybaraClient.ts b/src/ScrapybaraClient.ts index 287ffb5..5c65050 100644 --- a/src/ScrapybaraClient.ts +++ b/src/ScrapybaraClient.ts @@ -53,13 +53,45 @@ export declare namespace ScrapybaraClient { type RequestOptions = FernClient.RequestOptions; } +export class Beta { + constructor( + private readonly fern: FernClient, + ) {} + + public async takeSnapshot( + instanceId: string, + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.betaVmManagement.takeSnapshot(instanceId, requestOptions); + } + + public async warmupSnapshot( + snapshotId: string, + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.betaVmManagement.warmupSnapshot(snapshotId, requestOptions); + } + + public async deleteSnapshot( + snapshotId: string, + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.betaVmManagement.deleteSnapshot(snapshotId, requestOptions); + } +} + export class ScrapybaraClient { private _fern: FernClient; + private _beta: Beta | undefined; constructor(readonly _options?: ScrapybaraClient.Options) { this._fern = new FernClient(_options); } + public get beta(): Beta { + return (this._beta ??= new Beta(this._fern)); + } + public async startUbuntu( request: Omit = {}, requestOptions?: ScrapybaraClient.RequestOptions, @@ -593,6 +625,16 @@ export class BaseInstance { return await this.fern.instance.resume(this.id, request, requestOptions); } + /** + * Reschedule the termination time for the instance. + */ + public async rescheduleTermination( + request: Scrapybara.InstanceRescheduleTerminationRequest = {}, + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.instance.rescheduleTermination(this.id, request, requestOptions); + } + /** * Upload a file to the instance */ @@ -603,6 +645,26 @@ export class BaseInstance { ): Promise { return await this.fern.instance.upload(file, this.id, request, requestOptions); } + + /** + * Expose a port on the instance with a public-facing URL. + */ + public async exposePort( + request: Scrapybara.ExposePortRequest, + requestOptions?: FernClient.RequestOptions + ): Promise { + return await this.fern.instance.exposePort(this.id, request, requestOptions); + } + + /** + * Deploy a directory from the instance to Netlify. + */ + public async deployToNetlify( + request: Scrapybara.NetlifyDeployRequest, + requestOptions?: FernClient.RequestOptions + ): Promise { + return await this.fern.instance.deployToNetlify(this.id, request, requestOptions); + } } export class UbuntuInstance extends BaseInstance { @@ -676,6 +738,12 @@ export class BrowserInstance extends BaseInstance { ): Promise { return await this.fern.browser.authenticate(this.id, request, requestOptions); } + + public async getStreamUrl( + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.browser.getStreamUrl(this.id, requestOptions); + } } export class WindowsInstance extends BaseInstance { @@ -690,8 +758,8 @@ export class Browser { private readonly fern: FernClient, ) {} - public async start(requestOptions?: FernClient.RequestOptions): Promise { - return await this.fern.browser.start(this.instanceId, requestOptions); + public async start(request: Scrapybara.BrowserStartRequest = {}, requestOptions?: FernClient.RequestOptions): Promise { + return await this.fern.browser.start(this.instanceId, request, requestOptions); } public async getCdpUrl(requestOptions?: FernClient.RequestOptions): Promise { @@ -725,6 +793,12 @@ export class Browser { return await this.fern.browser.authenticate(this.instanceId, request, requestOptions); } + public async getStreamUrl( + requestOptions?: FernClient.RequestOptions, + ): Promise { + return await this.fern.browser.getStreamUrl(this.instanceId, requestOptions); + } + public async stop(requestOptions?: FernClient.RequestOptions): Promise { return await this.fern.browser.stop(this.instanceId, requestOptions); } diff --git a/src/api/client/requests/DeleteAuthStateRequest.ts b/src/api/client/requests/DeleteAuthStateRequest.ts new file mode 100644 index 0000000..ac8b1b4 --- /dev/null +++ b/src/api/client/requests/DeleteAuthStateRequest.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * { + * authStateId: "auth_state_id" + * } + */ +export interface DeleteAuthStateRequest { + authStateId: string; +} diff --git a/src/api/client/requests/DeploymentConfig.ts b/src/api/client/requests/DeploymentConfig.ts index a62aa00..fbb472f 100644 --- a/src/api/client/requests/DeploymentConfig.ts +++ b/src/api/client/requests/DeploymentConfig.ts @@ -13,4 +13,6 @@ export interface DeploymentConfig { timeoutHours?: number; blockedDomains?: string[]; resolution?: number[]; + backend?: string; + snapshotId?: string; } diff --git a/src/api/client/requests/index.ts b/src/api/client/requests/index.ts index 85daf8a..fad0faa 100644 --- a/src/api/client/requests/index.ts +++ b/src/api/client/requests/index.ts @@ -1 +1,2 @@ export { type DeploymentConfig } from "./DeploymentConfig"; +export { type DeleteAuthStateRequest } from "./DeleteAuthStateRequest"; diff --git a/src/api/resources/betaVmManagement/client/Client.ts b/src/api/resources/betaVmManagement/client/Client.ts new file mode 100644 index 0000000..825449b --- /dev/null +++ b/src/api/resources/betaVmManagement/client/Client.ts @@ -0,0 +1,283 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as Scrapybara from "../../../index"; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization/index"; +import * as errors from "../../../../errors/index"; + +export declare namespace BetaVmManagement { + export interface Options { + environment?: core.Supplier; + apiKey?: core.Supplier; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Additional headers to include in the request. */ + headers?: Record; + } +} + +export class BetaVmManagement { + constructor(protected readonly _options: BetaVmManagement.Options = {}) {} + + /** + * Take a snapshot of an instance + * + * @param {string} instanceId + * @param {BetaVmManagement.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.betaVmManagement.takeSnapshot("instance_id") + */ + public async takeSnapshot( + instanceId: string, + requestOptions?: BetaVmManagement.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/beta/instances/${encodeURIComponent(instanceId)}/snapshot`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.SnapshotResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/beta/instances/{instance_id}/snapshot.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Warmup a snapshot + * + * @param {string} snapshotId + * @param {BetaVmManagement.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.betaVmManagement.warmupSnapshot("snapshot_id") + */ + public async warmupSnapshot( + snapshotId: string, + requestOptions?: BetaVmManagement.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/beta/snapshots/${encodeURIComponent(snapshotId)}/warmup`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.SuccessResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/beta/snapshots/{snapshot_id}/warmup.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Delete a snapshot + * + * @param {string} snapshotId + * @param {BetaVmManagement.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.betaVmManagement.deleteSnapshot("snapshot_id") + */ + public async deleteSnapshot( + snapshotId: string, + requestOptions?: BetaVmManagement.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/beta/snapshots/${encodeURIComponent(snapshotId)}/delete`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.SuccessResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/beta/snapshots/{snapshot_id}/delete.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getCustomAuthorizationHeaders() { + const apiKeyValue = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["SCRAPYBARA_API_KEY"]; + return { "x-api-key": apiKeyValue }; + } +} diff --git a/src/api/resources/betaVmManagement/client/index.ts b/src/api/resources/betaVmManagement/client/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/api/resources/betaVmManagement/client/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/api/resources/betaVmManagement/index.ts b/src/api/resources/betaVmManagement/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/betaVmManagement/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/browser/client/Client.ts b/src/api/resources/browser/client/Client.ts index d674373..3fe8786 100644 --- a/src/api/resources/browser/client/Client.ts +++ b/src/api/resources/browser/client/Client.ts @@ -32,6 +32,7 @@ export class Browser { /** * @param {string} instanceId + * @param {Scrapybara.BrowserStartRequest} request * @param {Browser.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Scrapybara.UnprocessableEntityError} @@ -41,8 +42,15 @@ export class Browser { */ public async start( instanceId: string, + request: Scrapybara.BrowserStartRequest = {}, requestOptions?: Browser.RequestOptions, ): Promise { + const { separateStream } = request; + const _queryParams: Record = {}; + if (separateStream != null) { + _queryParams["separate_stream"] = separateStream.toString(); + } + const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, @@ -52,14 +60,15 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), ...requestOptions?.headers, }, contentType: "application/json", + queryParameters: _queryParams, requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, maxRetries: requestOptions?.maxRetries, @@ -132,8 +141,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -190,6 +199,86 @@ export class Browser { } } + /** + * @param {string} instanceId + * @param {Browser.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.browser.getStreamUrl("instance_id") + */ + public async getStreamUrl( + instanceId: string, + requestOptions?: Browser.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/instance/${encodeURIComponent(instanceId)}/browser/stream_url`, + ), + method: "GET", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.BrowserGetStreamUrlResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling GET /v1/instance/{instance_id}/browser/stream_url.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + /** * @param {string} instanceId * @param {Browser.RequestOptions} requestOptions - Request-specific configuration. @@ -212,8 +301,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -300,8 +389,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -392,8 +481,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -480,8 +569,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -561,8 +650,8 @@ export class Browser { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), diff --git a/src/api/resources/browser/client/requests/BrowserStartRequest.ts b/src/api/resources/browser/client/requests/BrowserStartRequest.ts new file mode 100644 index 0000000..2b4bcb7 --- /dev/null +++ b/src/api/resources/browser/client/requests/BrowserStartRequest.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * {} + */ +export interface BrowserStartRequest { + separateStream?: boolean; +} diff --git a/src/api/resources/browser/client/requests/index.ts b/src/api/resources/browser/client/requests/index.ts index 612773b..252755c 100644 --- a/src/api/resources/browser/client/requests/index.ts +++ b/src/api/resources/browser/client/requests/index.ts @@ -1,3 +1,4 @@ +export { type BrowserStartRequest } from "./BrowserStartRequest"; export { type BrowserSaveAuthRequest } from "./BrowserSaveAuthRequest"; export { type BrowserModifyAuthRequest } from "./BrowserModifyAuthRequest"; export { type BrowserAuthenticateRequest } from "./BrowserAuthenticateRequest"; diff --git a/src/api/resources/code/client/Client.ts b/src/api/resources/code/client/Client.ts index e2ab1a4..64591ce 100644 --- a/src/api/resources/code/client/Client.ts +++ b/src/api/resources/code/client/Client.ts @@ -56,8 +56,8 @@ export class Code { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), diff --git a/src/api/resources/env/client/Client.ts b/src/api/resources/env/client/Client.ts index d44910a..a1ceba9 100644 --- a/src/api/resources/env/client/Client.ts +++ b/src/api/resources/env/client/Client.ts @@ -49,8 +49,8 @@ export class Env { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -135,8 +135,8 @@ export class Env { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -220,8 +220,8 @@ export class Env { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 2b556c5..adabd70 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -4,6 +4,7 @@ export * as browser from "./browser"; export * as code from "./code"; export * as notebook from "./notebook"; export * as env from "./env"; +export * as betaVmManagement from "./betaVmManagement"; export * from "./instance/client/requests"; export * from "./browser/client/requests"; export * from "./code/client/requests"; diff --git a/src/api/resources/instance/client/Client.ts b/src/api/resources/instance/client/Client.ts index d38653b..f600e64 100644 --- a/src/api/resources/instance/client/Client.ts +++ b/src/api/resources/instance/client/Client.ts @@ -54,8 +54,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -134,8 +134,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -219,8 +219,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -302,8 +302,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -388,8 +388,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -473,8 +473,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -566,8 +566,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -648,8 +648,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -728,8 +728,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -816,8 +816,8 @@ export class Instance { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -875,6 +875,274 @@ export class Instance { } } + /** + * @param {string} instanceId + * @param {Scrapybara.InstanceRescheduleTerminationRequest} request + * @param {Instance.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.instance.rescheduleTermination("instance_id") + */ + public async rescheduleTermination( + instanceId: string, + request: Scrapybara.InstanceRescheduleTerminationRequest = {}, + requestOptions?: Instance.RequestOptions, + ): Promise { + const { newTimeoutHours } = request; + const _queryParams: Record = {}; + if (newTimeoutHours != null) { + _queryParams["new_timeout_hours"] = newTimeoutHours.toString(); + } + + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/instance/${encodeURIComponent(instanceId)}/reschedule_termination`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + queryParameters: _queryParams, + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.StopInstanceResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/instance/{instance_id}/reschedule_termination.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Expose a port on the instance with a public-facing URL. + * + * This endpoint creates a temporary public URL that routes traffic to the specified port on the instance. + * + * @param {string} instanceId + * @param {Scrapybara.ExposePortRequest} request + * @param {Instance.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.instance.exposePort("instance_id", { + * port: 1 + * }) + */ + public async exposePort( + instanceId: string, + request: Scrapybara.ExposePortRequest, + requestOptions?: Instance.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/instance/${encodeURIComponent(instanceId)}/expose_port`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: serializers.ExposePortRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.ExposePortResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/instance/{instance_id}/expose_port.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Deploy a directory from the instance to Netlify. + * + * Args: + * directory_path: Path to the directory on the instance to deploy + * + * @param {string} instanceId + * @param {Scrapybara.NetlifyDeployRequest} request + * @param {Instance.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Scrapybara.UnprocessableEntityError} + * + * @example + * await client.instance.deployToNetlify("instance_id", { + * directoryPath: "directory_path" + * }) + */ + public async deployToNetlify( + instanceId: string, + request: Scrapybara.NetlifyDeployRequest, + requestOptions?: Instance.RequestOptions, + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.ScrapybaraEnvironment.Production, + `v1/instance/${encodeURIComponent(instanceId)}/deploy_to_netlify`, + ), + method: "POST", + headers: { + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "scrapybara", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...(await this._getCustomAuthorizationHeaders()), + ...requestOptions?.headers, + }, + contentType: "application/json", + requestType: "json", + body: serializers.NetlifyDeployRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 600000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.NetlifyDeployResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Scrapybara.UnprocessableEntityError( + serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + ); + default: + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.ScrapybaraError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.ScrapybaraTimeoutError( + "Timeout exceeded when calling POST /v1/instance/{instance_id}/deploy_to_netlify.", + ); + case "unknown": + throw new errors.ScrapybaraError({ + message: _response.error.errorMessage, + }); + } + } + protected async _getCustomAuthorizationHeaders() { const apiKeyValue = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["SCRAPYBARA_API_KEY"]; return { "x-api-key": apiKeyValue }; diff --git a/src/api/resources/instance/client/requests/ExposePortRequest.ts b/src/api/resources/instance/client/requests/ExposePortRequest.ts new file mode 100644 index 0000000..3c1f955 --- /dev/null +++ b/src/api/resources/instance/client/requests/ExposePortRequest.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * { + * port: 1 + * } + */ +export interface ExposePortRequest { + port: number; +} diff --git a/src/api/resources/instance/client/requests/InstanceRescheduleTerminationRequest.ts b/src/api/resources/instance/client/requests/InstanceRescheduleTerminationRequest.ts new file mode 100644 index 0000000..c542c05 --- /dev/null +++ b/src/api/resources/instance/client/requests/InstanceRescheduleTerminationRequest.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * {} + */ +export interface InstanceRescheduleTerminationRequest { + newTimeoutHours?: number; +} diff --git a/src/api/resources/instance/client/requests/NetlifyDeployRequest.ts b/src/api/resources/instance/client/requests/NetlifyDeployRequest.ts new file mode 100644 index 0000000..aeba43f --- /dev/null +++ b/src/api/resources/instance/client/requests/NetlifyDeployRequest.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * { + * directoryPath: "directory_path" + * } + */ +export interface NetlifyDeployRequest { + directoryPath: string; +} diff --git a/src/api/resources/instance/client/requests/index.ts b/src/api/resources/instance/client/requests/index.ts index e7ad8d7..ad9d048 100644 --- a/src/api/resources/instance/client/requests/index.ts +++ b/src/api/resources/instance/client/requests/index.ts @@ -3,3 +3,6 @@ export { type EditRequest } from "./EditRequest"; export { type FileRequest } from "./FileRequest"; export { type BodyUploadV1InstanceInstanceIdUploadPost } from "./BodyUploadV1InstanceInstanceIdUploadPost"; export { type InstanceResumeRequest } from "./InstanceResumeRequest"; +export { type ExposePortRequest } from "./ExposePortRequest"; +export { type NetlifyDeployRequest } from "./NetlifyDeployRequest"; +export { type InstanceRescheduleTerminationRequest } from "./InstanceRescheduleTerminationRequest"; \ No newline at end of file diff --git a/src/api/resources/notebook/client/Client.ts b/src/api/resources/notebook/client/Client.ts index c0c681c..11cda75 100644 --- a/src/api/resources/notebook/client/Client.ts +++ b/src/api/resources/notebook/client/Client.ts @@ -52,8 +52,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -136,8 +136,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -219,8 +219,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -301,8 +301,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -388,8 +388,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -475,8 +475,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -560,8 +560,8 @@ export class Notebook { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scrapybara", - "X-Fern-SDK-Version": "2.5.2", - "User-Agent": "scrapybara/2.5.2", + "X-Fern-SDK-Version": "2.6.0-beta.5", + "User-Agent": "scrapybara/2.6.0-beta.5", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), diff --git a/src/api/types/BrowserGetStreamUrlResponse.ts b/src/api/types/BrowserGetStreamUrlResponse.ts new file mode 100644 index 0000000..6b328a1 --- /dev/null +++ b/src/api/types/BrowserGetStreamUrlResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface BrowserGetStreamUrlResponse { + streamUrl: string; +} diff --git a/src/api/types/DeleteBrowserAuthResponse.ts b/src/api/types/DeleteBrowserAuthResponse.ts new file mode 100644 index 0000000..5af5bde --- /dev/null +++ b/src/api/types/DeleteBrowserAuthResponse.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface DeleteBrowserAuthResponse { + status: string; + authStateId: string; +} diff --git a/src/api/types/ExposePortResponse.ts b/src/api/types/ExposePortResponse.ts new file mode 100644 index 0000000..3134cd8 --- /dev/null +++ b/src/api/types/ExposePortResponse.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ExposePortResponse { + status: string; + publicUrl: string; +} diff --git a/src/api/types/NetlifyDeployResponse.ts b/src/api/types/NetlifyDeployResponse.ts new file mode 100644 index 0000000..b8bb8c4 --- /dev/null +++ b/src/api/types/NetlifyDeployResponse.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Response model for netlify deployment. + */ +export interface NetlifyDeployResponse { + output?: string; + error?: string; + siteUrl?: string; +} diff --git a/src/api/types/SnapshotResponse.ts b/src/api/types/SnapshotResponse.ts new file mode 100644 index 0000000..8a119e8 --- /dev/null +++ b/src/api/types/SnapshotResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface SnapshotResponse { + snapshotId: string; +} diff --git a/src/api/types/StartBrowserResponse.ts b/src/api/types/StartBrowserResponse.ts index 5cc6d12..c94b414 100644 --- a/src/api/types/StartBrowserResponse.ts +++ b/src/api/types/StartBrowserResponse.ts @@ -4,4 +4,5 @@ export interface StartBrowserResponse { cdpUrl: string; + streamUrl?: string; } diff --git a/src/api/types/SuccessResponse.ts b/src/api/types/SuccessResponse.ts new file mode 100644 index 0000000..e489bd0 --- /dev/null +++ b/src/api/types/SuccessResponse.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface SuccessResponse { + success: boolean; + message: string; +} diff --git a/src/api/types/index.ts b/src/api/types/index.ts index 0625fda..4851755 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -41,3 +41,9 @@ export * from "./TypeTextAction"; export * from "./ValidationErrorLocItem"; export * from "./ValidationError"; export * from "./WaitAction"; +export * from "./SnapshotResponse"; +export * from "./SuccessResponse"; +export * from "./BrowserGetStreamUrlResponse"; +export * from "./ExposePortResponse"; +export * from "./NetlifyDeployResponse"; +export * from "./DeleteBrowserAuthResponse"; diff --git a/src/serialization/client/requests/DeploymentConfig.ts b/src/serialization/client/requests/DeploymentConfig.ts index eabcdfc..9c9eb02 100644 --- a/src/serialization/client/requests/DeploymentConfig.ts +++ b/src/serialization/client/requests/DeploymentConfig.ts @@ -18,6 +18,8 @@ export const DeploymentConfig: core.serialization.Schema< core.serialization.list(core.serialization.string()).optional(), ), resolution: core.serialization.list(core.serialization.number()).optional(), + backend: core.serialization.string().optional(), + snapshotId: core.serialization.property("snapshot_id", core.serialization.string().optional()), }); export declare namespace DeploymentConfig { @@ -26,5 +28,7 @@ export declare namespace DeploymentConfig { timeout_hours?: number | null; blocked_domains?: string[] | null; resolution?: number[] | null; + backend?: string | null; + snapshot_id?: string | null; } } diff --git a/src/serialization/resources/instance/client/requests/ExposePortRequest.ts b/src/serialization/resources/instance/client/requests/ExposePortRequest.ts new file mode 100644 index 0000000..6218f74 --- /dev/null +++ b/src/serialization/resources/instance/client/requests/ExposePortRequest.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../../index"; +import * as Scrapybara from "../../../../../api/index"; +import * as core from "../../../../../core"; + +export const ExposePortRequest: core.serialization.Schema< + serializers.ExposePortRequest.Raw, + Scrapybara.ExposePortRequest +> = core.serialization.object({ + port: core.serialization.number(), +}); + +export declare namespace ExposePortRequest { + export interface Raw { + port: number; + } +} diff --git a/src/serialization/resources/instance/client/requests/NetlifyDeployRequest.ts b/src/serialization/resources/instance/client/requests/NetlifyDeployRequest.ts new file mode 100644 index 0000000..6529eb1 --- /dev/null +++ b/src/serialization/resources/instance/client/requests/NetlifyDeployRequest.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../../index"; +import * as Scrapybara from "../../../../../api/index"; +import * as core from "../../../../../core"; + +export const NetlifyDeployRequest: core.serialization.Schema< + serializers.NetlifyDeployRequest.Raw, + Scrapybara.NetlifyDeployRequest +> = core.serialization.object({ + directoryPath: core.serialization.property("directory_path", core.serialization.string()), +}); + +export declare namespace NetlifyDeployRequest { + export interface Raw { + directory_path: string; + } +} diff --git a/src/serialization/resources/instance/client/requests/index.ts b/src/serialization/resources/instance/client/requests/index.ts index 761c04a..76c1b5a 100644 --- a/src/serialization/resources/instance/client/requests/index.ts +++ b/src/serialization/resources/instance/client/requests/index.ts @@ -1,3 +1,5 @@ export { BashRequest } from "./BashRequest"; export { EditRequest } from "./EditRequest"; export { FileRequest } from "./FileRequest"; +export { ExposePortRequest } from "./ExposePortRequest"; +export { NetlifyDeployRequest } from "./NetlifyDeployRequest"; diff --git a/src/serialization/types/BrowserGetStreamUrlResponse.ts b/src/serialization/types/BrowserGetStreamUrlResponse.ts new file mode 100644 index 0000000..2ae7f58 --- /dev/null +++ b/src/serialization/types/BrowserGetStreamUrlResponse.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const BrowserGetStreamUrlResponse: core.serialization.ObjectSchema< + serializers.BrowserGetStreamUrlResponse.Raw, + Scrapybara.BrowserGetStreamUrlResponse +> = core.serialization.object({ + streamUrl: core.serialization.property("stream_url", core.serialization.string()), +}); + +export declare namespace BrowserGetStreamUrlResponse { + export interface Raw { + stream_url: string; + } +} diff --git a/src/serialization/types/DeleteBrowserAuthResponse.ts b/src/serialization/types/DeleteBrowserAuthResponse.ts new file mode 100644 index 0000000..aad6a49 --- /dev/null +++ b/src/serialization/types/DeleteBrowserAuthResponse.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const DeleteBrowserAuthResponse: core.serialization.ObjectSchema< + serializers.DeleteBrowserAuthResponse.Raw, + Scrapybara.DeleteBrowserAuthResponse +> = core.serialization.object({ + status: core.serialization.string(), + authStateId: core.serialization.property("auth_state_id", core.serialization.string()), +}); + +export declare namespace DeleteBrowserAuthResponse { + export interface Raw { + status: string; + auth_state_id: string; + } +} diff --git a/src/serialization/types/ExposePortResponse.ts b/src/serialization/types/ExposePortResponse.ts new file mode 100644 index 0000000..4afe7d6 --- /dev/null +++ b/src/serialization/types/ExposePortResponse.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const ExposePortResponse: core.serialization.ObjectSchema< + serializers.ExposePortResponse.Raw, + Scrapybara.ExposePortResponse +> = core.serialization.object({ + status: core.serialization.string(), + publicUrl: core.serialization.property("public_url", core.serialization.string()), +}); + +export declare namespace ExposePortResponse { + export interface Raw { + status: string; + public_url: string; + } +} diff --git a/src/serialization/types/NetlifyDeployResponse.ts b/src/serialization/types/NetlifyDeployResponse.ts new file mode 100644 index 0000000..d69725e --- /dev/null +++ b/src/serialization/types/NetlifyDeployResponse.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const NetlifyDeployResponse: core.serialization.ObjectSchema< + serializers.NetlifyDeployResponse.Raw, + Scrapybara.NetlifyDeployResponse +> = core.serialization.object({ + output: core.serialization.string().optional(), + error: core.serialization.string().optional(), + siteUrl: core.serialization.property("site_url", core.serialization.string().optional()), +}); + +export declare namespace NetlifyDeployResponse { + export interface Raw { + output?: string | null; + error?: string | null; + site_url?: string | null; + } +} diff --git a/src/serialization/types/SnapshotResponse.ts b/src/serialization/types/SnapshotResponse.ts new file mode 100644 index 0000000..a9c2149 --- /dev/null +++ b/src/serialization/types/SnapshotResponse.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const SnapshotResponse: core.serialization.ObjectSchema< + serializers.SnapshotResponse.Raw, + Scrapybara.SnapshotResponse +> = core.serialization.object({ + snapshotId: core.serialization.property("snapshot_id", core.serialization.string()), +}); + +export declare namespace SnapshotResponse { + export interface Raw { + snapshot_id: string; + } +} diff --git a/src/serialization/types/StartBrowserResponse.ts b/src/serialization/types/StartBrowserResponse.ts index e25a1c0..0a857ff 100644 --- a/src/serialization/types/StartBrowserResponse.ts +++ b/src/serialization/types/StartBrowserResponse.ts @@ -11,10 +11,12 @@ export const StartBrowserResponse: core.serialization.ObjectSchema< Scrapybara.StartBrowserResponse > = core.serialization.object({ cdpUrl: core.serialization.property("cdp_url", core.serialization.string()), + streamUrl: core.serialization.property("stream_url", core.serialization.string().optional()), }); export declare namespace StartBrowserResponse { export interface Raw { cdp_url: string; + stream_url?: string | null; } } diff --git a/src/serialization/types/SuccessResponse.ts b/src/serialization/types/SuccessResponse.ts new file mode 100644 index 0000000..1cf46fa --- /dev/null +++ b/src/serialization/types/SuccessResponse.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../index"; +import * as Scrapybara from "../../api/index"; +import * as core from "../../core"; + +export const SuccessResponse: core.serialization.ObjectSchema< + serializers.SuccessResponse.Raw, + Scrapybara.SuccessResponse +> = core.serialization.object({ + success: core.serialization.boolean(), + message: core.serialization.string(), +}); + +export declare namespace SuccessResponse { + export interface Raw { + success: boolean; + message: string; + } +} diff --git a/src/serialization/types/index.ts b/src/serialization/types/index.ts index 706c909..10ddfd5 100644 --- a/src/serialization/types/index.ts +++ b/src/serialization/types/index.ts @@ -4,16 +4,19 @@ export * from "./BashResponse"; export * from "./BrowserAuthenticateResponse"; export * from "./BrowserGetCdpUrlResponse"; export * from "./BrowserGetCurrentUrlResponse"; +export * from "./BrowserGetStreamUrlResponse"; export * from "./CellType"; export * from "./Button"; export * from "./ClickMouseActionClickType"; export * from "./ClickMouseAction"; export * from "./ComputerResponse"; +export * from "./DeleteBrowserAuthResponse"; export * from "./DragMouseAction"; export * from "./EditResponse"; export * from "./EnvGetResponse"; export * from "./EnvResponse"; export * from "./ExecuteCellRequest"; +export * from "./ExposePortResponse"; export * from "./FileResponse"; export * from "./GetCursorPositionAction"; export * from "./GetInstanceResponseInstanceType"; @@ -25,14 +28,17 @@ export * from "./InstanceScreenshotResponse"; export * from "./KernelInfo"; export * from "./ModifyBrowserAuthResponse"; export * from "./MoveMouseAction"; +export * from "./NetlifyDeployResponse"; export * from "./Notebook"; export * from "./NotebookCell"; export * from "./PressKeyAction"; export * from "./SaveBrowserAuthResponse"; export * from "./ScrollAction"; +export * from "./SnapshotResponse"; export * from "./StartBrowserResponse"; export * from "./StopBrowserResponse"; export * from "./StopInstanceResponse"; +export * from "./SuccessResponse"; export * from "./TakeScreenshotAction"; export * from "./TypeTextAction"; export * from "./UploadResponse"; diff --git a/src/version.ts b/src/version.ts index 7ad3ea6..1ef686a 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const SDK_VERSION = "2.5.2"; +export const SDK_VERSION = "2.6.0-beta.5"; diff --git a/tests/custom.test.ts b/tests/custom.test.ts index f51c459..e307ffe 100644 --- a/tests/custom.test.ts +++ b/tests/custom.test.ts @@ -1,4 +1,4 @@ -import { ScrapybaraClient } from "../src"; +import { ScrapybaraClient, UbuntuInstance } from "../src"; import { anthropic, UBUNTU_SYSTEM_PROMPT as ANTHROPIC_UBUNTU_SYSTEM_PROMPT, @@ -31,7 +31,7 @@ describe("test", () => { } }); - it("ubuntu test", async () => { + it.skip("ubuntu test", async () => { const ubuntuInstance = await client.startUbuntu(); console.log((await ubuntuInstance.getStreamUrl()).streamUrl); assert(ubuntuInstance.id !== undefined); @@ -42,7 +42,7 @@ describe("test", () => { const screenshotResponse = await ubuntuInstance.screenshot(); assert(screenshotResponse.base64Image !== undefined); - await ubuntuInstance.browser.start(); + await ubuntuInstance.browser.start({ separateStream: true }); const cdpUrl = await ubuntuInstance.browser.getCdpUrl(); assert(cdpUrl.cdpUrl !== undefined); @@ -75,7 +75,7 @@ describe("test", () => { const screenshotResponse = await ubuntuInstance.screenshot(); assert(screenshotResponse.base64Image !== undefined); - await ubuntuInstance.browser.start(); + await ubuntuInstance.browser.start({ separateStream: true }); const cdpUrl = await ubuntuInstance.browser.getCdpUrl(); assert(cdpUrl.cdpUrl !== undefined); @@ -97,7 +97,7 @@ describe("test", () => { await ubuntuInstance.stop(); }, 600000); - it("browser test", async () => { + it.skip("browser test", async () => { const browserInstance = await client.startBrowser(); console.log((await browserInstance.getStreamUrl()).streamUrl); assert(browserInstance.id !== undefined); @@ -187,7 +187,7 @@ describe("test", () => { await windowsInstance.stop(); }, 600000); - it("ubuntu test with openai", async () => { + it.skip("ubuntu test with openai", async () => { const ubuntuInstance = await client.startUbuntu(); console.log((await ubuntuInstance.getStreamUrl()).streamUrl); assert(ubuntuInstance.id !== undefined); @@ -198,7 +198,7 @@ describe("test", () => { const screenshotResponse = await ubuntuInstance.screenshot(); assert(screenshotResponse.base64Image !== undefined); - await ubuntuInstance.browser.start(); + await ubuntuInstance.browser.start({ separateStream: true }); const cdpUrl = await ubuntuInstance.browser.getCdpUrl(); assert(cdpUrl.cdpUrl !== undefined); @@ -220,7 +220,7 @@ describe("test", () => { await ubuntuInstance.stop(); }, 600000); - it("browser test with openai", async () => { + it.skip("browser test with openai", async () => { const browserInstance = await client.startBrowser(); console.log((await browserInstance.getStreamUrl()).streamUrl); assert(browserInstance.id !== undefined); @@ -279,7 +279,7 @@ describe("test", () => { await windowsInstance.stop(); }, 600000); - it("test file upload and download", async () => { + it.skip("test file upload and download", async () => { // Start an Ubuntu instance const instance = await client.startUbuntu(); @@ -305,4 +305,96 @@ describe("test", () => { fs.unlinkSync(testFilePath); await instance.stop(); }, 60000); + + it.skip("test beta vm management", async () => { + // Start a rodent instance + const instance = await client.startUbuntu({ backend: "rodent" }); + assert(instance.id !== undefined); + + try { + // Take a snapshot + const snapshotResponse = await client.beta.takeSnapshot(instance.id); + assert(snapshotResponse !== undefined); + assert(snapshotResponse.snapshotId !== undefined); + const snapshotId = snapshotResponse.snapshotId; + console.log(`Created snapshot with ID: ${snapshotId}`); + + // Warmup the snapshot + const warmupResponse = await client.beta.warmupSnapshot(snapshotId); + assert(warmupResponse !== undefined); + assert(warmupResponse.success === true); + + // Delete the snapshot + const deleteResponse = await client.beta.deleteSnapshot(snapshotId); + assert(deleteResponse !== undefined); + assert(deleteResponse.success === true); + } finally { + await instance.stop(); + } + }, 120000); + + it.skip("test restore from snapshot", async () => { + // Start original instance + const originalInstance = await client.startUbuntu({ backend: "rodent" }); + assert(originalInstance.id !== undefined); + console.log(`Started original instance: ${originalInstance.id}`); + + let snapshotId: string | null = null; + let restoredInstance: UbuntuInstance | null = null; + + try { + // Create a file to verify restoration later + const testMarker = `test-marker-${Date.now()}`; + await originalInstance.bash({ command: `echo '${testMarker}' > /tmp/snapshot-test-file` }); + + // Take a snapshot + const snapshotResponse = await client.beta.takeSnapshot(originalInstance.id); + assert(snapshotResponse !== undefined); + assert(snapshotResponse.snapshotId !== undefined); + + snapshotId = snapshotResponse.snapshotId; + console.log(`Created snapshot with ID: ${snapshotId}`); + + // Warmup the snapshot (optional but recommended) + await client.beta.warmupSnapshot(snapshotId); + + // Stop the original instance + await originalInstance.stop(); + + // Start a new instance from the snapshot + restoredInstance = await client.startUbuntu({ snapshotId: snapshotId, backend: "rodent" }); + assert(restoredInstance.id !== undefined); + console.log(`Started restored instance: ${restoredInstance.id}`); + + // Verify the test file exists with our marker + const fileContent = await restoredInstance.bash({ command: "cat /tmp/snapshot-test-file" }); + assert(fileContent.output?.includes(testMarker)); + console.log("Successfully verified snapshot restoration!"); + } finally { + // Clean up resources + if (originalInstance) { + try { + await originalInstance.stop(); + } catch (error) { + console.error("Error stopping original instance:", error); + } + } + + if (restoredInstance) { + try { + await restoredInstance.stop(); + } catch (error) { + console.error("Error stopping restored instance:", error); + } + } + + if (snapshotId) { + try { + await client.beta.deleteSnapshot(snapshotId); + } catch (error) { + console.error("Error deleting snapshot:", error); + } + } + } + }, 240000); }); diff --git a/yarn.lock b/yarn.lock index 7bc29ac..d03968a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -656,9 +656,12 @@ form-data "^4.0.0" "@types/node@*": - version "22.15.23" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.15.23.tgz#a0b7c03f951f1ffe381a6a345c68d80e48043dd0" - integrity sha512-7Ec1zaFPF4RJ0eXu1YT/xgiebqwqoJz8rYPDi/O2BcZ++Wpt0Kq9cl0eg6NN6bYbPnR67ZLo7St5Q3UK0SnARw== + version "22.14.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.14.1.tgz#53b54585cec81c21eee3697521e31312d6ca1e6f" + integrity sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw== + version "22.14.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.14.1.tgz#53b54585cec81c21eee3697521e31312d6ca1e6f" + integrity sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw== dependencies: undici-types "~6.21.0" @@ -1112,10 +1115,10 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== -caniuse-lite@^1.0.30001716: - version "1.0.30001718" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001718.tgz#dae13a9c80d517c30c6197515a96131c194d8f82" - integrity sha512-AflseV1ahcSunK53NfEs9gFWgOEmzr0f+kaMFA4xiLZlr9Hzt7HxcSpIFcnNCUkz6R6dWKa54rUz3HUmI3nVcw== +caniuse-lite@^1.0.30001688: + version "1.0.30001715" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001715.tgz#bd325a37ad366e3fe90827d74062807a34fbaeb2" + integrity sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw== chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0: version "4.1.2" @@ -1306,10 +1309,10 @@ ejs@^3.1.10: dependencies: jake "^10.8.5" -electron-to-chromium@^1.5.149: - version "1.5.159" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.159.tgz#b909c4a5dbd00674f18419199f71c945a199effe" - integrity sha512-CEvHptWAMV5p6GJ0Lq8aheyvVbfzVrv5mmidu1D3pidoVNkB3tTBsTMVtPJ+rzRK5oV229mCLz9Zj/hNvU8GBA== +electron-to-chromium@^1.5.73: + version "1.5.140" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.140.tgz#91d9279fe72963f22c5784cc7f3461b5fed34786" + integrity sha512-o82Rj+ONp4Ip7Cl1r7lrqx/pXhbp/lh9DpKcMNscFJdh8ebyRofnc7Sh01B4jx403RI0oqTBvlZ7OBIZLMr2+Q== emittery@^0.13.1: version "0.13.1" @@ -1329,6 +1332,10 @@ enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.1: graceful-fs "^4.2.4" tapable "^2.2.0" +entities@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/entities/-/entities-6.0.0.tgz#09c9e29cb79b0a6459a9b9db9efb418ac5bb8e51" + integrity sha512-aKstq2TDOndCn4diEyp9Uq/Flu2i1GlLkc6XIDQSDMuaFE3OPW5OphLCyQ5SpSJZTb4reN+kTcYru5yIfXoRPw== entities@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/entities/-/entities-6.0.0.tgz#09c9e29cb79b0a6459a9b9db9efb418ac5bb8e51" @@ -1355,6 +1362,9 @@ es-module-lexer@^1.2.1: version "1.7.0" resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.7.0.tgz#9159601561880a85f2734560a9099b2c31e5372a" integrity sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA== + version "1.7.0" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.7.0.tgz#9159601561880a85f2734560a9099b2c31e5372a" + integrity sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA== es-object-atoms@^1.0.0, es-object-atoms@^1.1.1: version "1.1.1" @@ -2484,11 +2494,15 @@ parse-json@^5.2.0: lines-and-columns "^1.1.6" parse5@^7.0.0, parse5@^7.1.1: + version "7.3.0" + resolved "https://registry.yarnpkg.com/parse5/-/parse5-7.3.0.tgz#d7e224fa72399c7a175099f45fc2ad024b05ec05" + integrity sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw== version "7.3.0" resolved "https://registry.yarnpkg.com/parse5/-/parse5-7.3.0.tgz#d7e224fa72399c7a175099f45fc2ad024b05ec05" integrity sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw== dependencies: entities "^6.0.0" + entities "^6.0.0" path-exists@^4.0.0: version "4.0.0" @@ -2669,7 +2683,7 @@ saxes@^6.0.0: dependencies: xmlchars "^2.2.0" -schema-utils@^4.3.0, schema-utils@^4.3.2: +schema-utils@^4.3.0: version "4.3.2" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.3.2.tgz#0c10878bf4a73fd2b1dfd14b9462b26788c806ae" integrity sha512-Gn/JaSk/Mt9gYubxTtSn/QCV4em9mpAPiR1rqy/Ocu19u/G9J5WWdNoUT4SiV6mFC3y6cxyFcFwdzPM3FgxGAQ== @@ -3065,9 +3079,9 @@ webpack-sources@^3.2.3: integrity sha512-77R0RDmJfj9dyv5p3bM5pOHa+X8/ZkO9c7kpDstigkC4nIDobadsfSGCwB4bKhMVxqAok8tajaoR8rirM7+VFQ== webpack@^5.97.1: - version "5.99.9" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.99.9.tgz#d7de799ec17d0cce3c83b70744b4aedb537d8247" - integrity sha512-brOPwM3JnmOa+7kd3NsmOUOwbDAj8FT9xDsG3IW0MgbN9yZV7Oi/s/+MNQ/EcSMqw7qfoRyXPoeEWT8zLVdVGg== + version "5.99.5" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.99.5.tgz#86e3b3a5a03377ea5da271c929934003f5ac5dd8" + integrity sha512-q+vHBa6H9qwBLUlHL4Y7L0L1/LlyBKZtS9FHNCQmtayxjI5RKC9yD8gpvLeqGv5lCQp1Re04yi0MF40pf30Pvg== dependencies: "@types/eslint-scope" "^3.7.7" "@types/estree" "^1.0.6"