import {z} from 'zod' export type FormSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, isEnabled?: boolean | undefined, shareKey?: boolean | undefined, targetType?: boolean | undefined, fields?: boolean | undefined, templates?: boolean | undefined, targetSettings?: boolean | undefined, successMessage?: boolean | undefined, ipWhitelist?: boolean | undefined, logoFileId?: boolean | undefined, logoAltText?: boolean | undefined, faviconFileId?: boolean | undefined, createdByUserId?: boolean | undefined}; export type CreateApiFormIdGetItemArgs = {id: string, body: {select?: FormSelectSchema | undefined}}; export type CreateApiFormIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const form = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), name: z.string(), description: z.string().optional(), isEnabled: z.boolean(), shareKey: z.string().optional(), targetType: z.enum(["Incident", "ScheduledMaintenance"]), fields: z.object({}).optional(), templates: z.object({}).optional(), targetSettings: z.object({}).optional(), successMessage: z.string().optional(), ipWhitelist: z.string().optional(), logoFileId: z.string().optional(), logoAltText: z.string().optional(), faviconFileId: z.string().optional(), createdByUserId: z.string().optional()}); export const createApiFormIdGetItemResponse = z.object({data: form.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 Form * * POST /form/{id}/get-item */ export const createApiFormIdGetItem = async (args: CreateApiFormIdGetItemArgs, options?: CreateApiFormIdGetItemOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/form/${encodeURIComponent(String(args.id))}/get-item${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiFormIdGetItemResponse, await res.json()) };