import {z} from 'zod' export type GetApiBillingNewRateSheetDefaultsListV1Options = {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 getApiBillingNewRateSheetDefaultsListV1Response = z.array(rateSheetDefault1); 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 }; /** * List * * GET /billing_new/rate_sheet_defaults/list/v1 */ export const getApiBillingNewRateSheetDefaultsListV1 = async (options?: GetApiBillingNewRateSheetDefaultsListV1Options) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing_new/rate_sheet_defaults/list/v1${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(getApiBillingNewRateSheetDefaultsListV1Response, await res.json()) };