@vercel/sdk
Version:
<p align="center"> <a href="https://vercel.com"> <img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> <h3 align="center">Vercel</h3> </a> <p align="center">Develop. Preview. Ship.</p> </p>
293 lines (273 loc) • 7.86 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
/**
* The status of the current sandbox.
*/
export const NamedSandboxStatus = {
Running: "running",
Stopped: "stopped",
Stopping: "stopping",
} as const;
/**
* The status of the current sandbox.
*/
export type NamedSandboxStatus = ClosedEnum<typeof NamedSandboxStatus>;
/**
* Keep-last snapshot configuration.
*/
export type KeepLastSnapshots = {
/**
* Number of most recent snapshots to keep.
*/
count: number;
/**
* Expiration time in milliseconds for kept snapshots.
*/
expiration?: number | undefined;
/**
* Whether to immediately delete evicted snapshots.
*/
deleteEvicted: boolean;
};
export const NamedSandboxNetworkPolicyMode = {
AllowAll: "allow-all",
Custom: "custom",
DefaultAllow: "default-allow",
DefaultDeny: "default-deny",
DenyAll: "deny-all",
} as const;
export type NamedSandboxNetworkPolicyMode = ClosedEnum<
typeof NamedSandboxNetworkPolicyMode
>;
/**
* Network policy configuration.
*/
export type NetworkPolicy = {
mode: NamedSandboxNetworkPolicyMode;
allowedDomains?: Array<string> | undefined;
allowedCIDRs?: Array<string> | undefined;
deniedCIDRs?: Array<string> | undefined;
};
export const NamedSandboxMode = {
ReadOnly: "read-only",
ReadWrite: "read-write",
} as const;
export type NamedSandboxMode = ClosedEnum<typeof NamedSandboxMode>;
/**
* Key-value pairs of mount path and drive.
*/
export type Mounts = {
drive: string;
mode?: NamedSandboxMode | undefined;
};
/**
* This object contains information related to a Vercel NamedSandbox.
*/
export type NamedSandbox = {
/**
* The unique identifier of the sandbox.
*/
name: string;
/**
* Current snapshot ID that the named sandbox is pointing to.
*/
currentSnapshotId?: string | undefined;
/**
* Current session ID the sandbox is pointing to.
*/
currentSessionId: string;
/**
* The status of the current sandbox.
*/
status: NamedSandboxStatus;
/**
* The time when the sandbox status was last updated, in milliseconds since the epoch.
*/
statusUpdatedAt: number;
/**
* Whether the sandbox persists its state across restarts via automatic snapshots.
*/
persistent: boolean;
/**
* The region the sandbox runs in.
*/
region?: string | undefined;
/**
* Number of virtual CPUs allocated.
*/
vcpus?: number | undefined;
/**
* Memory allocated in MB.
*/
memory?: number | undefined;
/**
* Runtime identifier.
*/
runtime?: string | undefined;
/**
* Timeout in milliseconds.
*/
timeout?: number | undefined;
/**
* Default snapshot expiration time in milliseconds. 0 means no expiration.
*/
snapshotExpiration?: number | undefined;
/**
* Keep-last snapshot configuration.
*/
keepLastSnapshots?: KeepLastSnapshots | undefined;
/**
* Network policy configuration.
*/
networkPolicy?: NetworkPolicy | undefined;
/**
* Cumulative egress bytes across all sandbox runs.
*/
totalEgressBytes?: number | undefined;
/**
* Cumulative ingress bytes across all sandbox runs.
*/
totalIngressBytes?: number | undefined;
/**
* Cumulative active CPU duration in milliseconds across all sandbox runs.
*/
totalActiveCpuDurationMs?: number | undefined;
/**
* Cumulative wall-clock duration in milliseconds across all sandbox runs.
*/
totalDurationMs?: number | undefined;
/**
* The working directory of the sandbox.
*/
cwd?: string | undefined;
/**
* Key-value tags attached to the named sandbox.
*/
tags?: { [k: string]: string } | undefined;
/**
* Key-value pairs of mount path and drive.
*/
mounts?: { [k: string]: Mounts } | undefined;
/**
* The time when the named sandbox was created, in milliseconds since the epoch.
*/
createdAt: number;
/**
* The time when the named sandbox was last updated, in milliseconds since the epoch.
*/
updatedAt: number;
};
/** @internal */
export const NamedSandboxStatus$inboundSchema: z.ZodNativeEnum<
typeof NamedSandboxStatus
> = z.nativeEnum(NamedSandboxStatus);
/** @internal */
export const KeepLastSnapshots$inboundSchema: z.ZodType<
KeepLastSnapshots,
z.ZodTypeDef,
unknown
> = z.object({
count: types.number(),
expiration: types.optional(types.number()),
deleteEvicted: types.boolean(),
});
export function keepLastSnapshotsFromJSON(
jsonString: string,
): SafeParseResult<KeepLastSnapshots, SDKValidationError> {
return safeParse(
jsonString,
(x) => KeepLastSnapshots$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'KeepLastSnapshots' from JSON`,
);
}
/** @internal */
export const NamedSandboxNetworkPolicyMode$inboundSchema: z.ZodNativeEnum<
typeof NamedSandboxNetworkPolicyMode
> = z.nativeEnum(NamedSandboxNetworkPolicyMode);
/** @internal */
export const NetworkPolicy$inboundSchema: z.ZodType<
NetworkPolicy,
z.ZodTypeDef,
unknown
> = z.object({
mode: NamedSandboxNetworkPolicyMode$inboundSchema,
allowedDomains: types.optional(z.array(types.string())),
allowedCIDRs: types.optional(z.array(types.string())),
deniedCIDRs: types.optional(z.array(types.string())),
});
export function networkPolicyFromJSON(
jsonString: string,
): SafeParseResult<NetworkPolicy, SDKValidationError> {
return safeParse(
jsonString,
(x) => NetworkPolicy$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'NetworkPolicy' from JSON`,
);
}
/** @internal */
export const NamedSandboxMode$inboundSchema: z.ZodNativeEnum<
typeof NamedSandboxMode
> = z.nativeEnum(NamedSandboxMode);
/** @internal */
export const Mounts$inboundSchema: z.ZodType<Mounts, z.ZodTypeDef, unknown> = z
.object({
drive: types.string(),
mode: types.optional(NamedSandboxMode$inboundSchema),
});
export function mountsFromJSON(
jsonString: string,
): SafeParseResult<Mounts, SDKValidationError> {
return safeParse(
jsonString,
(x) => Mounts$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Mounts' from JSON`,
);
}
/** @internal */
export const NamedSandbox$inboundSchema: z.ZodType<
NamedSandbox,
z.ZodTypeDef,
unknown
> = z.object({
name: types.string(),
currentSnapshotId: types.optional(types.string()),
currentSessionId: types.string(),
status: NamedSandboxStatus$inboundSchema,
statusUpdatedAt: types.number(),
persistent: types.boolean(),
region: types.optional(types.string()),
vcpus: types.optional(types.number()),
memory: types.optional(types.number()),
runtime: types.optional(types.string()),
timeout: types.optional(types.number()),
snapshotExpiration: types.optional(types.number()),
keepLastSnapshots: types.optional(
z.lazy(() => KeepLastSnapshots$inboundSchema),
),
networkPolicy: types.optional(z.lazy(() => NetworkPolicy$inboundSchema)),
totalEgressBytes: types.optional(types.number()),
totalIngressBytes: types.optional(types.number()),
totalActiveCpuDurationMs: types.optional(types.number()),
totalDurationMs: types.optional(types.number()),
cwd: types.optional(types.string()),
tags: types.optional(z.record(types.string())),
mounts: types.optional(z.record(z.lazy(() => Mounts$inboundSchema))),
createdAt: types.number(),
updatedAt: types.number(),
});
export function namedSandboxFromJSON(
jsonString: string,
): SafeParseResult<NamedSandbox, SDKValidationError> {
return safeParse(
jsonString,
(x) => NamedSandbox$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'NamedSandbox' from JSON`,
);
}