import {z} from 'zod' export type GetApiV1FinanceQuotesQuoteIdLineItemsArgs = {'Customer-Id': number, quoteId: number, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiV1FinanceQuotesQuoteIdLineItemsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const readQuoteLineItemModel = z.object({id: z.number().int().optional(), quoteId: z.number().int().nullable().optional(), contactId: z.number().int().nullable().optional(), createdAt: z.string().optional(), quantity: z.number().optional(), description: z.string().optional(), taxId: z.number().int().nullable().optional(), taxPercentage: z.number().optional(), unitCost: z.number().nullable().optional(), unitSellingPrice: z.number().optional(), taxAmount: z.number().nullable().optional(), grossAmount: z.number().nullable().optional(), nominalCodeId: z.number().int().nullable().optional(), departmentCodeId: z.number().int().nullable().optional()}); export const pagedResponseReadQuoteLineItemModel = z.object({items: z.array(readQuoteLineItemModel).optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), pageItemCount: 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 }; /** * Gets a list of quote line items that belong to the specified quote * * GET /v1/finance/quotes/{quoteId}/lineItems */ export const getApiV1FinanceQuotesQuoteIdLineItems = async (args: GetApiV1FinanceQuotesQuoteIdLineItemsArgs, options?: GetApiV1FinanceQuotesQuoteIdLineItemsOptions) => { const {baseUrl = "https://api.bigchange.com", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Customer-Id'] != null) headers.set("Customer-Id", String(args['Customer-Id'])) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/finance/quotes/${encodeURIComponent(String(args.quoteId))}/lineItems${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(pagedResponseReadQuoteLineItemModel, await res.json()) };