import {z} from 'zod' export type HrisMetadata = {id?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, slug?: string | undefined}; export type PropertyHrisBenefitMetadata = Array; export type HrisBenefit = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, description?: string | undefined, company_id?: string | undefined, type?: ('RETIREMENT' | 'HEALTH' | 'DENTAL' | 'VISION' | 'LIFE' | 'HSA' | 'FSA' | 'SHORT_TERM_DISABILITY' | 'LONG_TERM_DISABILITY' | 'WORKERS_COMP' | 'HOUSING_STIPEND' | 'EMPLOYER_TAX_CONTRIBUTION' | 'GARNISHMENT' | 'LOAN_REPAYMENT' | 'CHARITABLE_CONTRIBUTION' | 'OTHER' | 'RETIREMENT_ROTH' | 'COMMUTER' | 'DEPENDENT_CARE' | 'PENSION') | undefined, tax?: ('PRE_TAX' | 'POST_TAX' | 'TAXABLE' | 'NON_TAXABLE' | 'TAX') | undefined, frequency?: ('ONE_TIME' | 'DAY' | 'QUARTER' | 'YEAR' | 'HOUR' | 'MONTH' | 'WEEK' | 'BIWEEKLY' | 'SEMIMONTHLY') | undefined, is_active?: boolean | undefined, employer_contribution_type?: ('PERCENTAGE' | 'FIXED') | undefined, employer_contribution_amount?: number | undefined, employer_contribution_max_amount?: number | undefined, coverage_level?: ('EMPLOYEE_ONLY' | 'EMPLOYEE_SPOUSE' | 'EMPLOYEE_CHILD' | 'EMPLOYEE_CHILDREN' | 'EMPLOYEE_FAMILY' | 'FAMILY' | 'OTHER') | undefined, currency?: string | undefined, metadata?: PropertyHrisBenefitMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type CreateApiHrisConnectionIdBenefitArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'name' | 'description' | 'company_id' | 'type' | 'tax' | 'frequency' | 'is_active' | 'employer_contribution_type' | 'employer_contribution_amount' | 'employer_contribution_max_amount' | 'coverage_level' | 'currency' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, body: HrisBenefit}; export type CreateApiHrisConnectionIdBenefitOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const hrisMetadata = z.object({id: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), slug: z.string().optional()}); export const propertyHrisBenefitMetadata = z.array(hrisMetadata); export const hrisBenefit = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), description: z.string().optional(), company_id: z.string().optional(), type: z.enum(["RETIREMENT", "HEALTH", "DENTAL", "VISION", "LIFE", "HSA", "FSA", "SHORT_TERM_DISABILITY", "LONG_TERM_DISABILITY", "WORKERS_COMP", "HOUSING_STIPEND", "EMPLOYER_TAX_CONTRIBUTION", "GARNISHMENT", "LOAN_REPAYMENT", "CHARITABLE_CONTRIBUTION", "OTHER", "RETIREMENT_ROTH", "COMMUTER", "DEPENDENT_CARE", "PENSION"]).optional(), tax: z.enum(["PRE_TAX", "POST_TAX", "TAXABLE", "NON_TAXABLE", "TAX"]).optional(), frequency: z.enum(["ONE_TIME", "DAY", "QUARTER", "YEAR", "HOUR", "MONTH", "WEEK", "BIWEEKLY", "SEMIMONTHLY"]).optional(), is_active: z.boolean().optional(), employer_contribution_type: z.enum(["PERCENTAGE", "FIXED"]).optional(), employer_contribution_amount: z.number().optional(), employer_contribution_max_amount: z.number().optional(), coverage_level: z.enum(["EMPLOYEE_ONLY", "EMPLOYEE_SPOUSE", "EMPLOYEE_CHILD", "EMPLOYEE_CHILDREN", "EMPLOYEE_FAMILY", "FAMILY", "OTHER"]).optional(), currency: z.string().optional(), metadata: propertyHrisBenefitMetadata.optional(), raw: z.record(z.string(), z.unknown()).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 }; /** * Create a benefit * * POST /hris/{connection_id}/benefit */ export const createApiHrisConnectionIdBenefit = async (args: CreateApiHrisConnectionIdBenefitArgs, options?: CreateApiHrisConnectionIdBenefitOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/hris/${encodeURIComponent(String(args.connection_id))}/benefit${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(hrisBenefit, await res.json()) };