Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/js-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type {
SandboxNetworkOpts,
SandboxLifecycle,
SandboxInfoLifecycle,
SnapshotCreateOpts,
SnapshotInfo,
SnapshotListOpts,
SnapshotPaginator,
Expand Down
11 changes: 6 additions & 5 deletions packages/js-sdk/src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
SandboxPaginator,
SandboxBetaCreateOpts,
SandboxApiOpts,
SnapshotCreateOpts,
SnapshotListOpts,
SnapshotInfo,
SnapshotPaginator,
Expand Down Expand Up @@ -621,11 +622,11 @@ export class Sandbox extends SandboxApi {
* const newSandbox = await Sandbox.create(snapshot.snapshotId)
* ```
*/
async createSnapshot(opts?: SandboxApiOpts): Promise<SnapshotInfo> {
return await SandboxApi.createSnapshot(
this.sandboxId,
this.resolveApiOpts(opts)
)
async createSnapshot(opts?: SnapshotCreateOpts): Promise<SnapshotInfo> {
return await SandboxApi.createSnapshot(this.sandboxId, {
...this.resolveApiOpts(opts),
...(opts?.name ? { name: opts.name } : {}),
})
}

/**
Expand Down
29 changes: 27 additions & 2 deletions packages/js-sdk/src/sandbox/sandboxApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,33 @@ export interface SnapshotListOpts extends SandboxApiOpts {
/**
* Information about a snapshot.
*/
/**
* Options for creating a snapshot.
*/
export interface SnapshotCreateOpts extends SandboxApiOpts {
/**
* Optional name for the snapshot template.
* If a snapshot template with this name already exists, a new build will
* be assigned to the existing template instead of creating a new one.
*
* When a name is provided, the returned `snapshotId` will use the
* namespaced format (e.g. `team-slug/my-snapshot:default`) which can be
* passed directly to `Sandbox.create()`.
*/
name?: string
}

export interface SnapshotInfo {
/**
* Snapshot identifier — template ID with tag, or namespaced name with tag (e.g. my-snapshot:latest).
* Can be used with Sandbox.create() to create a new sandbox from this snapshot.
*/
snapshotId: string
/**
* Full names of the snapshot template including team namespace and tag
* (e.g. `team-slug/my-snapshot:v2`).
*/
names: string[]
}

/**
Expand Down Expand Up @@ -687,7 +708,7 @@ export class SandboxApi {
*/
static async createSnapshot(
sandboxId: string,
opts?: SandboxApiOpts
opts?: SnapshotCreateOpts
): Promise<SnapshotInfo> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
Expand All @@ -698,7 +719,9 @@ export class SandboxApi {
sandboxID: sandboxId,
},
},
body: {},
body: {
...(opts?.name ? { name: opts.name } : {}),
},
signal: config.getSignal(opts?.requestTimeoutMs),
})

Expand All @@ -713,6 +736,7 @@ export class SandboxApi {

return {
snapshotId: res.data!.snapshotID,
names: res.data!.names,
}
}

Expand Down Expand Up @@ -1038,6 +1062,7 @@ export class SnapshotPaginator extends BasePaginator<SnapshotInfo> {
return (res.data ?? []).map(
(snapshot: components['schemas']['SnapshotInfo']) => ({
snapshotId: snapshot.snapshotID,
names: snapshot.names,
})
)
}
Expand Down