import {z} from 'zod' export type GetApiRrApiV1ContractsContractIdBundlesIdArgs = {contract_id: number, id: number}; export type GetApiRrApiV1ContractsContractIdBundlesIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const contractBundleLine = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), contract_bundle: z.number().int().optional(), product_name: z.string(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), product: z.number().int().nullable().optional()}); export const prorationMethodEnum = z.enum(["standard", "thirty_day", "daily"]); export const contractBundle = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), end_date: z.string().nullable().optional(), rebalance_journal_entries_indefinitely: z.boolean().optional(), lines: z.array(contractBundleLine), bundle_name: z.string().max(250), bundle_description: z.string().max(250).nullable().optional(), start_date: z.string(), use_daily_accounting: z.boolean().optional(), proration_method: prorationMethodEnum.optional(), use_catchup: z.boolean().optional(), catchup_date: z.string().nullable().optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), contract: z.number().int()}); 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 }; /** * Retrieve Contract Bundle * * GET /rr/api/v1/contracts/{contract_id}/bundles/{id} */ export const getApiRrApiV1ContractsContractIdBundlesId = async (args: GetApiRrApiV1ContractsContractIdBundlesIdArgs, options?: GetApiRrApiV1ContractsContractIdBundlesIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/rr/api/v1/contracts/${encodeURIComponent(String(args.contract_id))}/bundles/${encodeURIComponent(String(args.id))}${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(contractBundle, await res.json()) };