import {z} from 'zod' export type GetApiLandscapingProposalsTemplatesArgs = {proposal_type?: (string | null) | undefined, status?: string | undefined}; export type GetApiLandscapingProposalsTemplatesOptions = {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 landscapingProposalTemplateList = z.object({templates: z.array(landscapingProposalTemplate)}); 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 Landscaping Proposal Templates * * GET /landscaping-proposals/templates */ export const getApiLandscapingProposalsTemplates = async (args: GetApiLandscapingProposalsTemplatesArgs, options: GetApiLandscapingProposalsTemplatesOptions) => { 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.status != null) query.append("status", String(args.status)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/landscaping-proposals/templates${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(landscapingProposalTemplateList, await res.json()) };