import {z} from 'zod' export type File = {id: number, customer: number, created_at: string, created_by: number | null, created_by_name: string, created_by_email: string, last_modified_at: string, name: string, url: string, s3_content_type?: (string | null) | undefined, s3_content_length?: (number | null) | undefined, s3_path: string, object_id?: (number | null) | undefined, app: string, model: string, is_deleted: boolean, deleted_at: string | null}; export type OverageInvoiceCadenceEnum = 'monthly' | 'quarterly' | 'biannual' | 'annual' | 'one_time' | 'custom'; export type NestedContractPrepaidCommit = {entity?: (number | null) | undefined, product?: (number | null) | undefined, name: string, description?: string | undefined, currency?: (string | null) | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, total_value: number, discount_percentage?: number | undefined, rate?: (number | null) | undefined, start_date: string, expiration_date?: (string | null) | undefined, priority?: number | 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, tags?: Array | undefined}; export type BillingFrequencyEnum = 'monthly' | 'quarterly' | 'biannual' | 'annual' | 'one_time' | 'custom'; export type ContractStatusEnum = 'ACTIVE' | 'PENDING' | 'COMPLETED' | 'DELETED'; export type SourceFc1Enum = 'SALESFORCE' | 'HUBSPOT' | 'STRIPE' | 'MANUAL'; export type PatchedContract = {id?: number | undefined, entity_name?: string | undefined, client_name?: string | undefined, client_terms?: string | undefined, department_name?: string | undefined, parent_department_name?: string | undefined, parent_department?: number | undefined, tags?: string | undefined, total_revenue?: number | undefined, total_mrr?: number | undefined, total_deferred_revenue?: number | undefined, currency?: string | undefined, entity_currency?: string | undefined, attachments?: Array | undefined, prepaid_commits?: Array | undefined, contract_end_date?: (string | null) | undefined, is_evergreen?: boolean | undefined, auto_send_invoices?: boolean | undefined, skip_evergreen_invoice_generation?: boolean | undefined, auto_apply_customer_stripe_config_to_invoices?: boolean | undefined, last_modified_at?: string | undefined, is_deleted?: string | undefined, deleted_at?: string | undefined, usage_tiers?: string | undefined, has_invoices?: boolean | undefined, has_journal_entries?: boolean | undefined, has_credit_memos?: boolean | undefined, effective_end_date?: string | undefined, working_end_date?: string | undefined, evergreen_locked_date?: (string | null) | undefined, search_vector?: (string | null) | undefined, search_text?: (string | null) | undefined, billing_frequency?: BillingFrequencyEnum | undefined, deal_name?: (string | null) | undefined, deal_id?: (string | null) | undefined, consultant?: (string | null) | undefined, closed_date?: (string | null) | undefined, total_contract_value?: (number | null) | undefined, contract_start_date?: (string | null) | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, crm_link?: (string | null) | undefined, contract_link?: (string | null) | undefined, status?: ContractStatusEnum | undefined, source?: SourceFc1Enum | undefined, source_deal_data: unknown, created_at?: string | undefined, auto_renew?: boolean | undefined, auto_renew_duration?: (number | null) | undefined, auto_renew_invoice?: boolean | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, minimum_monthly_commitment_amount?: (number | null) | undefined, minimum_monthly_commitment_quantity?: (number | null) | undefined, purchase_order_number?: (string | null) | undefined, customer?: number | undefined, entity?: (number | null) | undefined, client?: (number | null) | undefined, department?: (number | null) | undefined, journal_entries?: Array | undefined}; export type PatchApiRrApiV1ContractsIdArgs = {id: number, body: PatchedContract}; export type PatchApiRrApiV1ContractsIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const file = z.object({id: z.number().int(), customer: z.number().int(), created_at: z.string(), created_by: z.number().int().nullable(), created_by_name: z.string(), created_by_email: z.string(), last_modified_at: z.string(), name: z.string(), url: z.string(), s3_content_type: z.string().nullable().optional(), s3_content_length: z.number().int().gte(0).lte(2147483647).nullable().optional(), s3_path: z.string(), object_id: z.number().int().gte(0).lte(2147483647).nullable().optional(), app: z.string(), model: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable()}); export const overageInvoiceCadenceEnum = z.enum(["monthly", "quarterly", "biannual", "annual", "one_time", "custom"]); export const nestedContractPrepaidCommit = z.object({entity: z.number().int().nullable().optional(), product: z.number().int().nullable().optional(), name: z.string().max(250), description: z.string().optional(), currency: z.string().nullable().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), discount_percentage: z.number().gt(-1000).lt(1000).optional(), rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), start_date: z.string(), expiration_date: z.string().nullable().optional(), priority: z.number().int().optional(), 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(), tags: z.array(z.number().int()).optional()}); export const billingFrequencyEnum = z.enum(["monthly", "quarterly", "biannual", "annual", "one_time", "custom"]); export const contractStatusEnum = z.enum(["ACTIVE", "PENDING", "COMPLETED", "DELETED"]); export const sourceFc1Enum = z.enum(["SALESFORCE", "HUBSPOT", "STRIPE", "MANUAL"]); export const contract = z.object({id: z.number().int(), entity_name: z.string(), client_name: z.string(), client_terms: z.string(), department_name: z.string(), parent_department_name: z.string(), parent_department: z.number().int(), tags: z.string().optional(), total_revenue: z.number().gt(-10000000000000).lt(10000000000000), total_mrr: z.number().gt(-10000000000000).lt(10000000000000), total_deferred_revenue: z.number().gt(-10000000000000).lt(10000000000000), currency: z.string().optional(), entity_currency: z.string().optional(), attachments: z.array(file), prepaid_commits: z.array(nestedContractPrepaidCommit).optional(), contract_end_date: z.string().nullable().optional(), is_evergreen: z.boolean().optional(), auto_send_invoices: z.boolean().optional(), skip_evergreen_invoice_generation: z.boolean().optional(), auto_apply_customer_stripe_config_to_invoices: z.boolean().optional(), last_modified_at: z.string(), is_deleted: z.string(), deleted_at: z.string(), usage_tiers: z.string().optional(), has_invoices: z.boolean(), has_journal_entries: z.boolean(), has_credit_memos: z.boolean(), effective_end_date: z.string(), working_end_date: z.string(), evergreen_locked_date: z.string().nullable(), search_vector: z.string().nullable(), search_text: z.string().nullable(), billing_frequency: billingFrequencyEnum.optional(), deal_name: z.string().max(250).nullable().optional(), deal_id: z.string().max(250).nullable().optional(), consultant: z.string().max(250).nullable().optional(), closed_date: z.string().nullable().optional(), total_contract_value: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), contract_start_date: z.string().nullable().optional(), exchange_rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), exchange_rate_book: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), crm_link: z.string().max(500).nullable().optional(), contract_link: z.string().max(500).nullable().optional(), status: contractStatusEnum.optional(), source: sourceFc1Enum.optional(), source_deal_data: z.unknown(), created_at: z.string(), auto_renew: z.boolean().optional(), auto_renew_duration: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), auto_renew_invoice: 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(), minimum_monthly_commitment_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), minimum_monthly_commitment_quantity: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), purchase_order_number: z.string().max(120).nullable().optional(), customer: z.number().int(), entity: z.number().int().nullable().optional(), client: z.number().int().nullable().optional(), department: z.number().int().nullable().optional(), journal_entries: z.array(z.number().int()).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 Contract * * PATCH /rr/api/v1/contracts/{id} */ export const patchApiRrApiV1ContractsId = async (args: PatchApiRrApiV1ContractsIdArgs, options?: PatchApiRrApiV1ContractsIdOptions) => { 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.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(contract, await res.json()) };