import {z} from 'zod' export type CreateApiApiPreviewCapsulesIdEntriesEntryIdRestoreArgs = {id: string, entryId: string}; export type CreateApiApiPreviewCapsulesIdEntriesEntryIdRestoreOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewCapsulesIdEntriesEntryIdRestoreResponse = z.object({entry: z.object({anchor: z.string().max(32), author: z.object({kind: z.enum(["person", "agent", "unknown"]), name: z.string().max(200).nullable(), user_id: z.string().max(128).nullable()}).and(z.record(z.string(), z.unknown())), author_client: z.enum(["web", "mcp", "mobile", "api"]), author_user_id: z.string().max(128).nullable(), content_md: z.string().max(10000).nullable(), created_at: z.string().max(40), edited_by: z.object({name: z.string().max(200).nullable(), user_id: z.string().max(128)}).and(z.record(z.string(), z.unknown())).nullable().optional(), entry_at: z.string().max(40), entry_number: z.number().int().gte(-9007199254740991).lte(9007199254740991), field_values: z.record(z.string(), z.unknown()), id: z.string().max(128), source_capsule_id: z.string().max(128).nullable().optional(), source_title: z.string().max(500).nullable().optional(), updated_at: z.string().max(40).nullable()}).and(z.record(z.string(), z.unknown())), fileRefs: z.record(z.string(), z.record(z.string(), z.unknown())).optional(), imageRefs: z.record(z.string(), z.record(z.string(), z.unknown())).optional(), impact: z.object({changed_fields: z.array(z.string().max(200)), dependents: z.object({items: z.array(z.object({id: z.string().max(128), ref: z.string().max(200), title: z.string().max(500), type_slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))), next_cursor: z.string().max(128).nullable(), total: z.number().int().gte(-9007199254740991).lte(9007199254740991)}).and(z.record(z.string(), z.unknown())), diff: z.object({text: z.string().max(8000), truncated: z.boolean()}).and(z.record(z.string(), z.unknown())).nullable()}).and(z.record(z.string(), z.unknown())).optional()}).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 }; /** * Restore a log entry deleted within the last 30 days, with its own number and content. Needs the update and delete scopes, like the entry delete. * * POST /api/preview/capsules/{id}/entries/{entryId}/restore * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewCapsulesIdEntriesEntryIdRestore = async (args: CreateApiApiPreviewCapsulesIdEntriesEntryIdRestoreArgs, options: CreateApiApiPreviewCapsulesIdEntriesEntryIdRestoreOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/capsules/${encodeURIComponent(String(args.id))}/entries/${encodeURIComponent(String(args.entryId))}/restore${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiPreviewCapsulesIdEntriesEntryIdRestoreResponse, await res.json()) };