import {z} from 'zod' export type GetApiApiV1ManufacturingIntentsProjectsProjectIdArgs = {project_id: string, scope?: ('project' | 'part' | 'feature' | 'drawing' | null) | undefined, part_id?: (string | null) | undefined, feature_id?: (string | null) | undefined, intent_type?: (string | null) | undefined, state?: ('active' | 'retracted' | 'superseded' | null) | undefined, include_inactive?: boolean | undefined}; export type GetApiApiV1ManufacturingIntentsProjectsProjectIdOptions = {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 manufacturingIntentListResponse = z.object({project_id: z.string(), events: z.array(manufacturingIntentRead), active_count: z.number().int(), retracted_count: z.number().int(), superseded_count: z.number().int()}); 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 }; /** * List Project Intents * * GET /api/v1/manufacturing-intents/projects/{project_id} */ export const getApiApiV1ManufacturingIntentsProjectsProjectId = async (args: GetApiApiV1ManufacturingIntentsProjectsProjectIdArgs, options: GetApiApiV1ManufacturingIntentsProjectsProjectIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scope != null) query.append("scope", String(args.scope)) if (args.part_id != null) query.append("part_id", String(args.part_id)) if (args.feature_id != null) query.append("feature_id", String(args.feature_id)) if (args.intent_type != null) query.append("intent_type", String(args.intent_type)) if (args.state != null) query.append("state", String(args.state)) if (args.include_inactive != null) query.append("include_inactive", String(args.include_inactive)) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/manufacturing-intents/projects/${encodeURIComponent(String(args.project_id))}${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(manufacturingIntentListResponse, await res.json()) };