import {z} from 'zod' export type GetApiV1DrivesNameOrIdArgs = {nameOrId: string, projectId?: string | undefined, teamId?: string | undefined, slug?: string | undefined}; export type GetApiV1DrivesNameOrIdOptions = {baseUrl?: string | undefined, bearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const drive = z.object({createdAt: z.number(), currentSandboxName: z.string().optional(), currentSessionId: z.string().optional(), id: z.string(), maxSizeBytes: z.number(), name: z.string(), parentDriveId: z.string().optional(), projectId: z.string(), region: z.string(), rootDriveId: z.string().optional(), updatedAt: z.number(), workloadType: z.enum(["sandbox", "v0"]).optional()}); export const getApiV1DrivesNameOrIdResponse = z.object({drive: drive}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get a drive * * GET /v1/drives/{nameOrId} */ export const getApiV1DrivesNameOrId = async (args: GetApiV1DrivesNameOrIdArgs, options?: GetApiV1DrivesNameOrIdOptions) => { const {baseUrl = "https://api.vercel.com", fetch: fetchFn = fetch, bearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.slug != null) query.append("slug", String(args.slug)) if (bearerToken !== undefined) headers.set('authorization', `Bearer ${bearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/drives/${encodeURIComponent(String(args.nameOrId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1DrivesNameOrIdResponse, await res.json()) };