import {z} from 'zod' export type CompanyId = string; export type EmployeeId = string; export type AgencyAddress = string; export type AgencyName = string; export type CaseId = string; export type CustomName = string; export type DeductionType = '401k' | '403b' | 'dependent_care_benefit' | 'employer_sponsored_health_coverage' | 'garnishment' | 'hsa' | 'miscellaneous' | 'roth_401k' | 'roth_ira' | 'section_125' | 'simple_ira'; export type EffectiveEndDate = string; export type EffectiveStartDate = string; export type EmployeeContributionAmount = number; export type EmployeeContributionPercentage = number; export type EmployerContributionAmount = number; export type EmployerContributionPercentage = number; export type ExternalId = string; export type HsaType = 'family' | 'individual'; export type OrderNumber = string; export type CreateApiEmployeeDeductionTemplatesArgs = {body: {companyID: CompanyId, employeeID: EmployeeId, agency_address?: AgencyAddress | undefined, agency_name?: AgencyName | undefined, case_id?: CaseId | undefined, custom_name: CustomName, deduction_type: DeductionType, effective_end_date?: EffectiveEndDate | undefined, effective_start_date: EffectiveStartDate, employee_contribution_amount?: EmployeeContributionAmount | undefined, employee_contribution_percentage?: EmployeeContributionPercentage | undefined, employer_contribution_amount?: EmployerContributionAmount | undefined, employer_contribution_percentage?: EmployerContributionPercentage | undefined, external_id?: ExternalId | undefined, hsa_type?: HsaType | undefined, order_number?: OrderNumber | undefined}}; export type CreateApiEmployeeDeductionTemplatesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const employeeDeductionTemplateId = z.string(); export const companyId = z.string(); export const employeeId = z.string(); export const customName = z.string(); export const deductionType = z.enum(["401k", "403b", "dependent_care_benefit", "employer_sponsored_health_coverage", "garnishment", "hsa", "miscellaneous", "roth_401k", "roth_ira", "section_125", "simple_ira"]); export const effectiveStartDate = z.string(); export const employeeContributionAmount = z.number().gte(0); export const employeeContributionPercentage = z.number().gte(0).lte(100); export const externalId = z.string().min(1); export const exampleTemplate = z.object({deductionTemplateID: employeeDeductionTemplateId, companyID: companyId, employeeID: employeeId, custom_name: customName, deduction_type: deductionType, effective_start_date: effectiveStartDate, employee_contribution_amount: employeeContributionAmount.optional(), employer_contribution_percentage: employeeContributionPercentage.optional(), external_id: externalId.optional()}); export const createApiEmployeeDeductionTemplatesResponse = z.object({success: z.literal(true).optional(), data: exampleTemplate.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 Employee Deduction Template * * POST /employee-deduction-templates */ export const createApiEmployeeDeductionTemplates = async (args: CreateApiEmployeeDeductionTemplatesArgs, options?: CreateApiEmployeeDeductionTemplatesOptions) => { const {baseUrl = "https://api.zeal.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/employee-deduction-templates${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(createApiEmployeeDeductionTemplatesResponse, await res.json()) };