import {z} from 'zod' export type ManufacturingIntentSupersedeRequest = {idempotency_key: string, scope: 'project' | 'part' | 'feature' | 'drawing', intent_type: string, label: string, value?: {[key: string]: unknown} | undefined, part_id?: (string | null) | undefined, cad_file_version_id?: (string | null) | undefined, feature_id?: (string | null) | undefined, source?: ('user_confirmed' | 'user_direct' | 'ollie_confirmed' | 'admin_confirmed') | undefined, provenance?: {[key: string]: unknown} | undefined}; export type CreateApiApiV1ManufacturingIntentsEventIdSupersedeArgs = {event_id: string, body: ManufacturingIntentSupersedeRequest}; export type CreateApiApiV1ManufacturingIntentsEventIdSupersedeOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const manufacturingIntentRead = z.object({id: z.string(), project_id: z.string(), part_id: z.string().nullable(), cad_file_version_id: z.string().nullable(), feature_id: z.string().nullable(), scope: z.enum(["project", "part", "feature", "drawing"]), intent_type: z.string(), label: z.string(), value: z.record(z.string(), z.unknown()), state: z.enum(["active", "retracted", "superseded"]), source: z.enum(["user_confirmed", "user_direct", "ollie_confirmed", "admin_confirmed"]), source_certainty: z.literal("user_asserted"), provenance: z.record(z.string(), z.unknown()), idempotency_key: z.string(), supersedes_event_id: z.string().nullable(), retracted_at: z.string().nullable(), retracted_by_user_id: z.string().nullable(), retraction_reason: z.string().nullable(), created_at: z.string(), updated_at: z.string()}); 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 }; /** * Supersede Intent * * POST /api/v1/manufacturing-intents/{event_id}/supersede */ export const createApiApiV1ManufacturingIntentsEventIdSupersede = async (args: CreateApiApiV1ManufacturingIntentsEventIdSupersedeArgs, options: CreateApiApiV1ManufacturingIntentsEventIdSupersedeOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/manufacturing-intents/${encodeURIComponent(String(args.event_id))}/supersede${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(manufacturingIntentRead, await res.json()) };