import {z} from 'zod' export type EmployeeDeductionTemplateId = string; export type GetApiEmployeeDeductionTemplatesDeductionTemplateIDArgs = {deductionTemplateID: EmployeeDeductionTemplateId}; export type GetApiEmployeeDeductionTemplatesDeductionTemplateIDOptions = {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 getApiEmployeeDeductionTemplatesDeductionTemplateIDResponse = 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 }; /** * Get Employee Deduction Template * * GET /employee-deduction-templates/{deductionTemplateID} */ export const getApiEmployeeDeductionTemplatesDeductionTemplateID = async (args: GetApiEmployeeDeductionTemplatesDeductionTemplateIDArgs, options?: GetApiEmployeeDeductionTemplatesDeductionTemplateIDOptions) => { const {baseUrl = "https://api.zeal.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/employee-deduction-templates/${encodeURIComponent(String(args.deductionTemplateID))}${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(getApiEmployeeDeductionTemplatesDeductionTemplateIDResponse, await res.json()) };