import {z} from 'zod' export type ContractPrepaidCommitStatusEnum = 'ACTIVE' | 'EXHAUSTED' | 'EXPIRED'; export type OverageInvoiceCadenceEnum = 'monthly' | 'quarterly' | 'biannual' | 'annual' | 'one_time' | 'custom'; export type PatchedContractPrepaidCommit = {id?: number | undefined, contract?: number | undefined, entity?: (number | null) | undefined, entity_name?: (string | null) | undefined, product?: (number | null) | undefined, product_name?: (string | null) | undefined, name?: string | undefined, description?: (string | null) | undefined, currency?: string | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, total_value?: number | undefined, remaining_value?: number | undefined, discount_percentage?: number | undefined, rate?: (number | null) | undefined, start_date?: string | undefined, expiration_date?: (string | null) | undefined, status?: ContractPrepaidCommitStatusEnum | undefined, priority?: number | undefined, is_invoiced?: boolean | undefined, invoice?: (number | null) | undefined, subledger?: (number | null) | undefined, overage_invoice_cadence?: OverageInvoiceCadenceEnum | undefined, auto_send_overage_invoices?: boolean | undefined, overage_invoice_start_month?: (string | null) | undefined, department?: (number | null) | undefined, department_name?: (string | null) | undefined, tags?: (string | null) | undefined, created_at?: (string | null) | undefined, last_modified_at?: (string | null) | undefined}; export type PatchApiRrApiV1ContractsContractIdPrepaidCommitsIdArgs = {contract_id: number, id: number, body: PatchedContractPrepaidCommit}; export type PatchApiRrApiV1ContractsContractIdPrepaidCommitsIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const contractPrepaidCommitStatusEnum = z.enum(["ACTIVE", "EXHAUSTED", "EXPIRED"]); export const overageInvoiceCadenceEnum = z.enum(["monthly", "quarterly", "biannual", "annual", "one_time", "custom"]); export const contractPrepaidCommit = z.object({id: z.number().int(), contract: z.number().int(), entity: z.number().int().nullable().optional(), entity_name: z.string().nullable(), product: z.number().int().nullable().optional(), product_name: z.string().nullable(), name: z.string().max(250), description: z.string().nullable().optional(), currency: z.string().max(3).optional(), exchange_rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), exchange_rate_book: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), total_value: z.number().gt(-1000000000000000000).lt(1000000000000000000), remaining_value: z.number().gt(-1000000000000000000).lt(1000000000000000000), discount_percentage: z.number().gte(0).lte(100).optional(), rate: z.number().gte(0).lt(100000000000000).nullable().optional(), start_date: z.string(), expiration_date: z.string().nullable().optional(), status: contractPrepaidCommitStatusEnum, priority: z.number().int().gte(-2147483648).lte(2147483647).optional(), is_invoiced: z.boolean(), invoice: z.number().int().nullable(), subledger: z.number().int().nullable().optional(), overage_invoice_cadence: overageInvoiceCadenceEnum.optional(), auto_send_overage_invoices: z.boolean().optional(), overage_invoice_start_month: z.string().nullable().optional(), department: z.number().int().nullable().optional(), department_name: z.string().nullable(), tags: z.string().nullable().optional(), created_at: z.string().nullable(), last_modified_at: z.string().nullable()}); 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 }; /** * Partial Update Prepaid Commit * * PATCH /rr/api/v1/contracts/{contract_id}/prepaid-commits/{id} */ export const patchApiRrApiV1ContractsContractIdPrepaidCommitsId = async (args: PatchApiRrApiV1ContractsContractIdPrepaidCommitsIdArgs, options?: PatchApiRrApiV1ContractsContractIdPrepaidCommitsIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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))}/prepaid-commits/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(contractPrepaidCommit, await res.json()) };