import {z} from 'zod' export type DeleteApiVaultsIdArgs = {id: string, 'X-Vault-Deletion-Mode': 'schedule', 'X-Confirm-Name-B64': string}; export type DeleteApiVaultsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const unreachedAdmin = z.object({user_id: z.string(), name: z.string().nullable(), email: z.string(), reason: z.string()}); export const responseMeta = z.object({api_version: z.string().optional(), request_id: z.string().optional(), response_ms: z.number().int().optional(), timestamp: z.number().int().optional(), pools: z.object({}).optional(), billing: z.object({past_due: z.boolean().optional()}).optional(), quota: z.object({limit: z.number().int().optional(), used: z.number().int().optional(), remaining: z.number().int().optional(), resets_at: z.number().int().optional()}).optional()}); export const deleteApiVaultsIdResponse = z.object({data: z.object({vault_id: z.string(), status: z.enum(["deletion_scheduled", "deleting"]), deletion_requested_at: z.number().int().optional(), deletion_scheduled_for: z.number().int().optional(), deletion_requested_by: z.string().optional(), deletion_schedule_id: z.string().optional(), deletion_notice_unreached: z.array(unreachedAdmin).nullable().optional(), started_at: z.number().int().optional()}), meta: responseMeta.optional()}); 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 }; /** * Schedule vault deletion * * DELETE /vaults/{id} */ export const deleteApiVaultsId = async (args: DeleteApiVaultsIdArgs, options?: DeleteApiVaultsIdOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Vault-Deletion-Mode'] != null) headers.set("X-Vault-Deletion-Mode", String(args['X-Vault-Deletion-Mode'])) if (args['X-Confirm-Name-B64'] != null) headers.set("X-Confirm-Name-B64", String(args['X-Confirm-Name-B64'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/vaults/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiVaultsIdResponse, await res.json()) };