import {z} from 'zod' export type AccrualConfig = {frequency: 'SEMI_MONTHLY' | 'MONTHLY' | 'WEEKLY', monthlyDaysOfMonth?: Array | undefined, weeklyStartDate?: string | undefined, weeklyIncrement?: number | undefined, balanceCapInWholeDays?: number | undefined, accrualOffsetFromStartDate: number}; export type PolicyAction = {type: 'OPEN' | 'CLOSE' | 'MOD_ALLOCATION' | 'ADJUST' | 'TRANSFER' | 'SET' | 'PRORATED_MOD' | 'FULL_MOD', exprString?: string | undefined}; export type PolicyEvent = {dateExpr: string, action: PolicyAction, noteExpr?: string | undefined, groupId?: string | undefined, title?: string | undefined}; export type UpdateTimeOffPolicy = {name?: string | undefined, displayName?: string | undefined, description?: string | undefined, guidelines?: string | undefined, color?: string | undefined, emoji?: string | undefined, type?: ('PTO' | 'TOIL' | 'VACATION' | 'SICK' | 'MEDICAL' | 'JURY' | 'OFFSITE' | 'PARENTAL' | 'UNPAID' | 'DISABILITY_SHORT' | 'DISABILITY_LONG' | 'BEREAVEMENT' | 'MILITARY' | 'RELIGIOUS' | 'VOTING' | 'VOLUNTEER' | 'UNKNOWN') | undefined, status?: ('ACTIVE' | 'INACTIVE') | undefined, allocationType?: ('UPFRONT' | 'UNLIMITED' | 'ACCRUAL') | undefined, annualAllocation?: number | undefined, accrualConfig?: AccrualConfig | undefined, maxConsecutiveDaysPerRequest?: number | undefined, minBalance?: number | undefined, enableCarryOverBalance?: boolean | undefined, maxCarryOverBalance?: number | undefined, carryOverExpirationDate?: string | undefined, carryOverExpirationMonths?: number | undefined, enablePartialDayRequests?: boolean | undefined, partialDayGranularity?: number | undefined, enablePartialDayPeriod?: boolean | undefined, disableRequests?: boolean | undefined, noteRequired?: boolean | undefined, enableManagerRequests?: boolean | undefined, filter?: string | undefined, holidayCalendarId?: string | undefined, respectPersonCalendar?: boolean | undefined, disableProratedAllocation?: boolean | undefined, prorationRounding?: ('UP' | 'NEAREST' | 'HALF') | undefined, yearStartDate?: string | undefined, yearStartDateExpression?: string | undefined, policyFromDate?: string | undefined, policyUntilDate?: string | undefined, workDays?: (Array<'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY'>) | undefined, policyEvents?: Array | undefined}; export type CreateApiV1OrgOrgIdTimeoffPolicyPolicyIdEstimateAccrualsArgs = {orgId: string, policyId: string, body: UpdateTimeOffPolicy}; export type CreateApiV1OrgOrgIdTimeoffPolicyPolicyIdEstimateAccrualsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const estimatedAccrual = z.object({daysPerPeriod: z.number()}); 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 }; /** * Estimate accrual value for policy * * POST /v1/org/{orgId}/timeoff/policy/{policyId}/estimateAccruals */ export const createApiV1OrgOrgIdTimeoffPolicyPolicyIdEstimateAccruals = async (args: CreateApiV1OrgOrgIdTimeoffPolicyPolicyIdEstimateAccrualsArgs, options?: CreateApiV1OrgOrgIdTimeoffPolicyPolicyIdEstimateAccrualsOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/timeoff/policy/${encodeURIComponent(String(args.policyId))}/estimateAccruals${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(estimatedAccrual, await res.json()) };