import {z} from 'zod' export type PatchedRevenueTransaction = {id?: number | undefined, is_deleted?: boolean | undefined, deleted_at?: (string | null) | undefined, entity_name?: string | undefined, entity_currency?: string | undefined, client_name?: string | undefined, contract_name?: string | undefined, contract_status?: string | undefined, product_name?: string | undefined, product_bundle_name?: string | undefined, product_is_taxable?: boolean | undefined, contract_identifier?: string | undefined, client_identifier?: string | undefined, product_identifier?: string | undefined, gross_amount?: string | undefined, invoice_number?: string | undefined, invoice_date?: string | undefined, invoice_payment_status?: string | undefined, invoice_voided_date?: string | undefined, credit_memo_number?: string | undefined, credit_memo_date?: string | undefined, credit_memo_voided_date?: string | undefined, credit_memo_application_status?: string | undefined, revenue_type?: string | undefined, journal_entry_order?: string | undefined, contract_subscription_notes?: string | undefined, subscription_discount?: (number | null) | undefined, department_name?: string | undefined, parent_department_name?: string | undefined, parent_department?: number | undefined, tags?: string | undefined, usage_tier_name?: string | undefined, last_modified_at?: string | undefined, anrok_item_id?: string | undefined, sphere_item_id?: string | undefined, source?: (string | null) | undefined, description?: (string | null) | undefined, external_id?: (string | null) | undefined, client_external_id?: (string | null) | undefined, contract_external_id?: (string | null) | undefined, contract_subscription_external_id?: (string | null) | undefined, product_external_id?: (string | null) | undefined, accounting_period?: (string | null) | undefined, transaction_date?: (string | null) | undefined, transaction_end_date?: (string | null) | undefined, currency?: string | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, recognized?: (number | null) | undefined, amount?: (number | null) | undefined, quantity?: (number | null) | undefined, rate?: (number | null) | undefined, discount?: (number | null) | undefined, refunds?: (number | null) | undefined, processing_fees?: (number | null) | undefined, platform_fees?: (number | null) | undefined, transfers?: (number | null) | undefined, tax?: (number | null) | undefined, balance_adjustment?: (number | null) | undefined, mrr?: (number | null) | undefined, renewall?: boolean | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, is_migration_invoiced?: boolean | undefined, created_at?: (string | null) | undefined, customer?: number | undefined, entity?: (number | null) | undefined, client?: (number | null) | undefined, contract?: (number | null) | undefined, contract_subscription?: (number | null) | undefined, non_contract_subscription?: (number | null) | undefined, contract_usage?: (number | null) | undefined, contract_milestone?: (number | null) | undefined, non_contract_usage?: (number | null) | undefined, prepaid_commit?: (number | null) | undefined, product?: (number | null) | undefined, product_bundle?: (number | null) | undefined, contract_product_bundle?: (number | null) | undefined, contract_bundle?: (number | null) | undefined, journal_entry?: (number | null) | undefined, invoice?: (number | null) | undefined, credit_memo?: (number | null) | undefined, department?: (number | null) | undefined, usage_tier?: (number | null) | undefined}; export type PatchApiRrApiV1TransactionsIdArgs = {id: number, body: PatchedRevenueTransaction}; export type PatchApiRrApiV1TransactionsIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const revenueTransaction = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), entity_name: z.string(), entity_currency: z.string(), client_name: z.string(), contract_name: z.string(), contract_status: z.string(), product_name: z.string(), product_bundle_name: z.string(), product_is_taxable: z.boolean(), contract_identifier: z.string(), client_identifier: z.string(), product_identifier: z.string(), gross_amount: z.string(), invoice_number: z.string(), invoice_date: z.string(), invoice_payment_status: z.string(), invoice_voided_date: z.string(), credit_memo_number: z.string(), credit_memo_date: z.string(), credit_memo_voided_date: z.string(), credit_memo_application_status: z.string(), revenue_type: z.string(), journal_entry_order: z.string(), contract_subscription_notes: z.string(), subscription_discount: z.number().gt(-10000000000000).lt(10000000000000).nullable(), department_name: z.string(), parent_department_name: z.string(), parent_department: z.number().int(), tags: z.string().optional(), usage_tier_name: z.string(), last_modified_at: z.string(), anrok_item_id: z.string(), sphere_item_id: z.string(), source: z.string().max(250).nullable().optional(), description: z.string().nullable().optional(), external_id: z.string().max(250).nullable().optional(), client_external_id: z.string().max(250).nullable().optional(), contract_external_id: z.string().max(250).nullable().optional(), contract_subscription_external_id: z.string().max(250).nullable().optional(), product_external_id: z.string().max(250).nullable().optional(), accounting_period: z.string().nullable().optional(), transaction_date: z.string().nullable().optional(), transaction_end_date: 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(), recognized: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), quantity: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), rate: z.number().gt(-10000000000000).lt(10000000000000).nullable().optional(), discount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), refunds: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), processing_fees: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), platform_fees: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), transfers: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), tax: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), balance_adjustment: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), mrr: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), renewall: z.boolean().optional(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), is_migration_invoiced: z.boolean().optional(), created_at: z.string().nullable(), customer: z.number().int(), entity: z.number().int().nullable().optional(), client: z.number().int().nullable().optional(), contract: z.number().int().nullable().optional(), contract_subscription: z.number().int().nullable().optional(), non_contract_subscription: z.number().int().nullable().optional(), contract_usage: z.number().int().nullable().optional(), contract_milestone: z.number().int().nullable().optional(), non_contract_usage: z.number().int().nullable().optional(), prepaid_commit: z.number().int().nullable().optional(), product: z.number().int().nullable().optional(), product_bundle: z.number().int().nullable().optional(), contract_product_bundle: z.number().int().nullable().optional(), contract_bundle: z.number().int().nullable().optional(), journal_entry: z.number().int().nullable().optional(), invoice: z.number().int().nullable().optional(), credit_memo: z.number().int().nullable().optional(), department: z.number().int().nullable().optional(), usage_tier: z.number().int().nullable().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 }; /** * Partial Update Revenue Transaction * * PATCH /rr/api/v1/transactions/{id} */ export const patchApiRrApiV1TransactionsId = async (args: PatchApiRrApiV1TransactionsIdArgs, options?: PatchApiRrApiV1TransactionsIdOptions) => { 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/transactions/${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(revenueTransaction, await res.json()) };