import {z} from 'zod' export type GetApiContactRenewalRemindersIdArgs = {id: string}; export type GetApiContactRenewalRemindersIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, accountToken?: string | undefined, fetch?: typeof fetch | undefined}; export const id = z.number().int().gte(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const frequency = z.enum(["day", "week", "month", "year", "days", "weeks", "months", "years"]).nullable(); export const contactRenewalReminder = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), active: z.boolean().nullable(), next_due_at: z.string(), last_sent_at: z.string().nullable(), due_soon_at: z.string().nullable(), due_soon_time_threshold_interval: z.number().int().nullable(), due_soon_time_threshold_frequency: frequency, overdue: z.boolean(), due_soon: z.boolean(), contact_id: id, contact_renewal_type_id: id, contact_renewal_type_name: z.string(), contact_archived_at: z.string().nullable()}).nullable(); 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 }; /** * Retrieve Contact Renewal Reminder * * GET /contact_renewal_reminders/{id} */ export const getApiContactRenewalRemindersId = async (args: GetApiContactRenewalRemindersIdArgs, options?: GetApiContactRenewalRemindersIdOptions) => { const {baseUrl = "https://secure.fleetio.com/api", fetch: fetchFn = fetch, apiKey, accountToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) if (accountToken !== undefined) headers.set("Account-Token", accountToken) const url = `${baseUrl.replace(/\/+$/, '')}/contact_renewal_reminders/${encodeURIComponent(String(args.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(contactRenewalReminder, await res.json()) };