import {z} from 'zod' export type CreateApiFetchCOHTArgs = {body: {endRow?: number | undefined, operationType?: string | undefined, startRow?: number | undefined, textMatchStyle?: string | undefined, data?: ({_constructor?: string | undefined, operator?: string | undefined, criteria?: (Array<{fieldName?: string | undefined, operator?: string | undefined, value?: string | undefined}>) | undefined}) | undefined}}; export type CreateApiFetchCOHTOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const compensationHeaderType = z.object({configuration: z.object({additionalProperties: z.object({}).optional()}).nullable().optional(), createDate: z.string().optional(), createdBy: z.number().int().optional(), headerFormulaName: z.string().max(255).optional(), label: z.string().max(255).nullable().optional(), lastUpdateBy: z.number().int().optional(), lastUpdateDate: z.string().optional(), scRecordWorkflowFormulaName: z.string().max(255).optional(), scTypeFilterFormulaName: z.string().max(255).nullable().optional(), typedId: z.string().optional(), uniqueName: z.string().max(255).optional(), userGroupEdit: z.string().max(255).nullable().optional(), userGroupViewDetails: z.string().max(255).nullable().optional(), version: z.number().int().optional(), workflowFormulaName: z.string().max(255).nullable().optional(), attribute1: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute2: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute3: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute4: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute5: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute6: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute7: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute8: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute9: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute10: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute11: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute12: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute13: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute14: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute15: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute16: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute17: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute18: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute19: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute20: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute21: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute22: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute23: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute24: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute25: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute26: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute27: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute28: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute29: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional(), attribute30: z.union([z.number().int().nullable(), z.string().max(255).nullable(), z.number().nullable(), z.string().max(255).nullable(), z.string().max(255).nullable(), z.string().max(255).nullable()]).optional()}); export const createApiFetchCOHTResponse = z.object({response: z.object({node: z.string().optional(), startRow: z.number().int().optional(), data: z.array(compensationHeaderType).optional(), endRow: z.number().int().optional(), totalRows: z.number().int().optional(), status: z.number().int().optional()}).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 Compensation Types * * POST /fetch/COHT * * Also accepts auth: X-PriceFx-jwt */ export const createApiFetchCOHT = async (args: CreateApiFetchCOHTArgs, options?: CreateApiFetchCOHTOptions) => { const {baseUrl = "https://companynode.pricefx.com/pricefx/companypartition", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/fetch/COHT${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(createApiFetchCOHTResponse, await res.json()) };