import {z} from 'zod' export type InvoiceTypeEnum1 = 'accounts_receivable' | 'accounts_payable'; export type ServiceLineEnum = 'on_demand' | 'routed'; export type TaskGroupTypeEnum1 = 'chrt_ground_provider' | 'cargo_on_flight' | 'cargo_on_vessel' | 'onboard_courier'; export type RateSheetDefaultClientCreate1 = {schema_version: 1, counterparty_org_id?: (string | null) | undefined, counterparty_off_chrt_org_data_id?: (string | null) | undefined, counterparty_driver_id?: (string | null) | undefined, invoice_type: InvoiceTypeEnum1, service_line: ServiceLineEnum, task_group_type: TaskGroupTypeEnum1, rate_sheet_id: string | null}; export type UpdateApiBillingNewRateSheetDefaultsSetV1Args = {body: RateSheetDefaultClientCreate1}; export type UpdateApiBillingNewRateSheetDefaultsSetV1Options = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceTypeEnum1 = z.enum(["accounts_receivable", "accounts_payable"]); export const serviceLineEnum = z.enum(["on_demand", "routed"]); export const taskGroupTypeEnum1 = z.enum(["chrt_ground_provider", "cargo_on_flight", "cargo_on_vessel", "onboard_courier"]); export const rateSheetDefault1 = z.object({schema_version: z.literal(1), counterparty_org_id: z.string().nullable().optional(), counterparty_off_chrt_org_data_id: z.string().nullable().optional(), counterparty_driver_id: z.string().nullable().optional(), invoice_type: invoiceTypeEnum1, service_line: serviceLineEnum, task_group_type: taskGroupTypeEnum1, rate_sheet_id: z.string().nullable(), _id: z.string(), owned_by_org_id: z.string(), created_by_user_id: z.string(), created_at_timestamp: z.string(), last_edited_by_user_id: z.string(), last_edited_at_timestamp: z.string()}); 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 }; /** * Set * * PUT /billing_new/rate_sheet_defaults/set/v1 */ export const updateApiBillingNewRateSheetDefaultsSetV1 = async (args: UpdateApiBillingNewRateSheetDefaultsSetV1Args, options?: UpdateApiBillingNewRateSheetDefaultsSetV1Options) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing_new/rate_sheet_defaults/set/v1${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(rateSheetDefault1, await res.json()) };