Skip to content

Commit

Permalink
Add filtering support to sandbox API list method in JS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Jan 10, 2025
1 parent 9a1cb59 commit 6d972dc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/js-sdk/src/sandbox/sandboxApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export interface SandboxApiOpts
Pick<ConnectionOpts, 'apiKey' | 'debug' | 'domain' | 'requestTimeoutMs'>
> {}

export interface SandboxListOpts extends SandboxApiOpts {
/**
* Filter the list of sandboxes by metadata, e.g. `{"key": "value"}`
*/
filters?: Record<string, string>
}

/**
* Information about a sandbox.
*/
Expand Down Expand Up @@ -87,11 +94,21 @@ export class SandboxApi {
*
* @returns list of running sandboxes.
*/
static async list(opts?: SandboxApiOpts): Promise<SandboxInfo[]> {
static async list(
opts?: SandboxListOpts): Promise<SandboxInfo[]> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)

const filters = opts?.filters ?? {}
const filterStrings = Object.entries(filters)
.map(([key, value]) => `${key}:${value}`)

const res = await client.api.GET('/sandboxes', {
params: {
query: {
filter: filterStrings,
}
},
signal: config.getSignal(opts?.requestTimeoutMs),
})

Expand Down

0 comments on commit 6d972dc

Please sign in to comment.