import {z} from 'zod' export type CreateApiApiV1ProjectsProjectIdExportExcelPreviewArgs = {project_id: string, template_id: string, sheets?: (Array | null) | undefined, include_hidden_layers?: boolean | undefined}; export type CreateApiApiV1ProjectsProjectIdExportExcelPreviewOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const matchedPlacement = z.object({key_type: z.enum(["code", "name"]), key: z.string(), uom: z.enum(["EA", "LF", "IN", "FT", "SF", "SY", "CF", "CY"]), value: z.number(), sheet: z.string(), cell: z.string(), result_type: z.enum(["count", "total_height", "perimeter", "surface_area_top_or_bottom", "surface_area_top_and_bottom", "surface_area_all_sides", "surface_area_full", "volume", "length", "segment_count", "surface_area_single_side", "surface_area_both_sides", "surface_area_single_end", "surface_area_both_ends", "surface_area_all_side_duct", "area", "grid_length_visible", "grid_length_x_visible", "grid_length_y_visible", "grid_intersection_count", "tile_count_average", "tile_count_visible", "area_counts"]).nullable().optional()}); export const unmatchedQuantity = z.object({condition_name: z.string(), code: z.string().nullable().optional(), uom: z.enum(["EA", "LF", "IN", "FT", "SF", "SY", "CF", "CY"]), value: z.number(), result_type: z.enum(["count", "total_height", "perimeter", "surface_area_top_or_bottom", "surface_area_top_and_bottom", "surface_area_all_sides", "surface_area_full", "volume", "length", "segment_count", "surface_area_single_side", "surface_area_both_sides", "surface_area_single_end", "surface_area_both_ends", "surface_area_all_side_duct", "area", "grid_length_visible", "grid_length_x_visible", "grid_length_y_visible", "grid_intersection_count", "tile_count_average", "tile_count_visible", "area_counts"]).nullable().optional()}); export const emptyTarget = z.object({sheet: z.string(), cell: z.string(), expected_key: z.string(), uom: z.enum(["EA", "LF", "IN", "FT", "SF", "SY", "CF", "CY"])}); export const uomConflict = z.object({key_type: z.enum(["code", "name"]), key: z.string(), requested_uom: z.enum(["EA", "LF", "IN", "FT", "SF", "SY", "CF", "CY"]), result_type: z.enum(["count", "total_height", "perimeter", "surface_area_top_or_bottom", "surface_area_top_and_bottom", "surface_area_all_sides", "surface_area_full", "volume", "length", "segment_count", "surface_area_single_side", "surface_area_both_sides", "surface_area_single_end", "surface_area_both_ends", "surface_area_all_side_duct", "area", "grid_length_visible", "grid_length_x_visible", "grid_length_y_visible", "grid_intersection_count", "tile_count_average", "tile_count_visible", "area_counts"]).nullable().optional()}); export const formulaOverwrite = z.object({sheet: z.string(), cell: z.string(), previous_formula: z.string()}); export const reconciliationReport = z.object({matched: z.array(matchedPlacement).optional(), unmatched_quantities: z.array(unmatchedQuantity).optional(), empty_targets: z.array(emptyTarget).optional(), uom_conflicts: z.array(uomConflict).optional(), fidelity_warnings: z.array(z.string()).optional(), formula_overwrites: z.array(formulaOverwrite).optional(), matched_count: z.number().int().optional(), total_quantities: z.number().int().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 }; /** * Preview Export * * POST /api/v1/projects/{project_id}/export/excel/preview */ export const createApiApiV1ProjectsProjectIdExportExcelPreview = async (args: CreateApiApiV1ProjectsProjectIdExportExcelPreviewArgs, options: CreateApiApiV1ProjectsProjectIdExportExcelPreviewOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.template_id != null) query.append("template_id", String(args.template_id)) for (const item of args.sheets ?? []) query.append("sheets", String(item)) if (args.include_hidden_layers != null) query.append("include_hidden_layers", String(args.include_hidden_layers)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.project_id))}/export/excel/preview${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(reconciliationReport, await res.json()) };