import {z} from 'zod' export type GetApiLandscapingProposalsTemplatesActiveArgs = {proposal_type?: (string | null) | undefined, version?: (number | null) | undefined, include_sources?: boolean | undefined}; export type GetApiLandscapingProposalsTemplatesActiveOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const landscapingProposalTemplate = z.object({id: z.string(), organization_id: z.string(), template_id: z.string(), display_name: z.string(), proposal_type: z.string(), version: z.number().int(), status: z.enum(["draft", "active", "archived"]), s3_bucket: z.string(), s3_prefix: z.string(), manifest_s3_object_key: z.string(), renderer_kind: z.string(), metadata: z.record(z.string(), z.unknown()).optional(), created_at: z.string(), updated_at: z.string()}); export const landscapingProposalTemplateBundle = z.object({template: landscapingProposalTemplate, manifest: z.record(z.string(), z.unknown()), source_keys: z.record(z.string(), z.string()).optional(), draft_schema: z.record(z.string(), z.unknown()).nullable().optional(), render_schema: z.record(z.string(), z.unknown()).nullable().optional(), org_prompt: z.string().nullable().optional(), template_html: z.string().nullable().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 }; /** * Get Active Landscaping Proposal Template Bundle * * GET /landscaping-proposals/templates/active */ export const getApiLandscapingProposalsTemplatesActive = async (args: GetApiLandscapingProposalsTemplatesActiveArgs, options: GetApiLandscapingProposalsTemplatesActiveOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.proposal_type != null) query.append("proposal_type", String(args.proposal_type)) if (args.version != null) query.append("version", String(args.version)) if (args.include_sources != null) query.append("include_sources", String(args.include_sources)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/landscaping-proposals/templates/active${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(landscapingProposalTemplateBundle, await res.json()) };