import {z} from 'zod' export type GetApiApiBalancesBalanceIdPeriodsArgs = {balanceId: number}; export type GetApiApiBalancesBalanceIdPeriodsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectBalanceDefinition = z.object({Id: z.number().int().optional(), CompanyId: z.number().int().nullable().optional(), CountryId: z.number().int().nullable().optional(), Name: z.string().optional(), SpecialIdentifier: z.string().optional(), IsConfigurable: z.boolean().optional(), AmountEnabled: z.boolean().optional(), TaxEnabled: z.boolean().optional(), SecondaryAmountEnabled: z.boolean().optional(), TertiaryAmountEnabled: z.boolean().optional(), DaysEnabled: z.boolean().optional(), SecondaryDaysEnabled: z.boolean().optional(), HoursEnabled: z.boolean().optional(), BaseAmountEnabled: z.boolean().optional(), HasPeriods: z.boolean().optional(), SuspendedDaysEnabled: z.boolean().optional(), IsActive: z.boolean().optional(), BaseCalculationMethodId: z.number().int().nullable().optional(), BalanceEarningIntervalId: z.number().int().nullable().optional(), UnitsEarnedPerInterval: z.number().nullable().optional(), EarningFixedAmount: z.number().nullable().optional(), EarningPercentage: z.number().nullable().optional(), TerminationMethodId: z.number().int().nullable().optional(), SpendingMethodId: z.number().int().nullable().optional(), BalancePeriods: z.array(z.lazy(() => intectBalancePeriod)).optional()}); export const intectBalancePeriod: z.ZodType = z.object({Id: z.number().int().optional(), BalanceId: z.number().int().optional(), EarningStartDate: z.string().optional(), EarningEndDate: z.string().optional(), SpendingStartDate: z.string().optional(), SpendingEndDate: z.string().optional(), SpecialIdentifier: z.string().optional(), BalanceDefinition: intectBalanceDefinition.optional(), Name: z.string().optional()}); export const getApiApiBalancesBalanceIdPeriodsResponse = z.array(intectBalancePeriod); 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 }; /** * Retrieves balance periods for specified balance. * * GET /api/balances/{balanceId}/periods * * Also accepts auth: ApiKey */ export const getApiApiBalancesBalanceIdPeriods = async (args: GetApiApiBalancesBalanceIdPeriodsArgs, options?: GetApiApiBalancesBalanceIdPeriodsOptions) => { const {baseUrl = "https://api.intect.app", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/balances/${encodeURIComponent(String(args.balanceId))}/periods${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(getApiApiBalancesBalanceIdPeriodsResponse, await res.json()) };