import {z} from 'zod' export type DeleteApiApiPreviewCapsulesIdArgs = {id: string, confirmOwnedLog?: ('true' | 'false') | undefined, confirm_citations?: ('true' | 'false') | undefined, permanent?: ('true' | 'false') | undefined}; export type DeleteApiApiPreviewCapsulesIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiApiPreviewCapsulesIdResponse = z.object({ownedLog: z.object({action: z.enum(["deleted", "detached"]), entry_count: z.number().int().gte(0).lte(9007199254740991), id: z.string().max(36), ref: z.string().max(200)}).and(z.record(z.string(), z.unknown())).optional(), recoverableUntil: z.string().max(64).nullable().optional(), softDeleted: z.boolean(), success: z.boolean()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Delete a capsule. It moves to Recently deleted and can be recovered for 30 days; ?permanent=true deletes it for good now (also for a capsule already in Recently deleted). A capsule that owns a log answers 409 `owned_log_present` naming the log and its entry count until `confirmOwnedLog=true` is sent; the log is then deleted with it, or detached and kept when you may not delete it. A log you may not read is never named: it is detached and kept, with no 409. A capsule other capsules cite needs ?confirm_citations=true; sending confirm_citations=true or confirm_citations=false opts in to that gate before its breaking-change effective date. * * DELETE /api/preview/capsules/{id} * * Also accepts auth: cookieAuth, oauth2 */ export const deleteApiApiPreviewCapsulesId = async (args: DeleteApiApiPreviewCapsulesIdArgs, options: DeleteApiApiPreviewCapsulesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.confirmOwnedLog != null) query.append("confirmOwnedLog", String(args.confirmOwnedLog)) if (args.confirm_citations != null) query.append("confirm_citations", String(args.confirm_citations)) if (args.permanent != null) query.append("permanent", String(args.permanent)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/capsules/${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(deleteApiApiPreviewCapsulesIdResponse, await res.json()) };