import {z} from 'zod' export type GetApiTransactionsCustomFieldsCustomFieldIdOptionsArgs = {customFieldId: string, fromDate?: string | undefined, toDate?: string | undefined, byDateField?: ('createdAt' | 'updatedAt' | null) | undefined, limit?: number | undefined, page?: number | undefined, sortBy?: ('createdAt' | 'updatedAt') | undefined, sortDirection?: ('ASC' | 'DESC') | undefined}; export type GetApiTransactionsCustomFieldsCustomFieldIdOptionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiTransactionsCustomFieldsCustomFieldIdOptionsResponse = z.object({data: z.array(z.object({id: z.string().optional(), customFieldId: z.string().optional(), name: z.string().optional(), value: z.string().optional(), status: z.enum(["ACTIVE", "INACTIVE"]).optional(), isDefault: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).optional(), hasNextPage: z.boolean().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 }; /** * List Custom Field Options * * GET /transactions/custom-fields/{customFieldId}/options */ export const getApiTransactionsCustomFieldsCustomFieldIdOptions = async (args: GetApiTransactionsCustomFieldsCustomFieldIdOptionsArgs, options?: GetApiTransactionsCustomFieldsCustomFieldIdOptionsOptions) => { const {baseUrl = "https://partner-api.getpliant.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.byDateField != null) query.append("byDateField", String(args.byDateField)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/custom-fields/${encodeURIComponent(String(args.customFieldId))}/options${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(getApiTransactionsCustomFieldsCustomFieldIdOptionsResponse, await res.json()) };