import {z} from 'zod' export type CommonEnumLineItemUomEnum = 'notApplicable' | 'piece' | 'linearFeet' | 'hour' | 'yard'; export type CommonExternalReferenceDto = {type?: (string | null) | undefined, externalId: string, displayId?: (string | null) | undefined, status?: (string | null) | undefined, url?: (string | null) | undefined, modifiedUtc?: (string | null) | undefined, lastSyncedUtc?: (string | null) | undefined}; export type QuoteFeeLineItemUpdateDto = {name?: (string | null) | undefined, description?: (string | null) | undefined, quantity?: (number | null) | undefined, price: number, accountingCodeId?: (string | null) | undefined, unitOfMeasure?: CommonEnumLineItemUomEnum | undefined, isTaxable?: (boolean | null) | undefined, taxCodeId?: (string | null) | undefined, taxRate?: (number | null) | undefined, overrideTaxRate?: (boolean | null) | undefined, externalReferences?: ({[key: string]: CommonExternalReferenceDto} | null) | undefined}; export type UpdateApiApiQuotesQuoteIdFeeLineItemsLineItemIdArgs = {quoteId: string, lineItemId: string, body: QuoteFeeLineItemUpdateDto}; export type UpdateApiApiQuotesQuoteIdFeeLineItemsLineItemIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const commonEnumLineItemUomEnum = z.enum(["notApplicable", "piece", "linearFeet", "hour", "yard"]); export const commonAccountingDetailsDto = z.object({classId: z.string().min(24).max(24).nullable().optional(), incomeAccountId: z.string().min(24).max(24).nullable().optional(), assetAccountId: z.string().min(24).max(24).nullable().optional(), expenseAccountId: z.string().min(24).max(24).nullable().optional(), cogsAccountId: z.string().min(24).max(24).nullable().optional()}); export const quoteFeeLineItemDto = z.object({id: z.string().min(36).max(36), name: z.string().min(1).max(200).nullable().optional(), description: z.string().max(2000).nullable().optional(), quantity: z.number().gte(0).nullable().optional(), price: z.number().gte(0), unitOfMeasure: commonEnumLineItemUomEnum.optional(), isTaxable: z.boolean().nullable().optional(), overrideTaxRate: z.boolean().nullable().optional(), taxCodeId: z.string().min(24).max(24).nullable().optional(), taxRate: z.number().nullable().optional(), number: z.number().int().optional(), accountingDetails: commonAccountingDetailsDto, accountingCodeId: z.string().min(24).max(24).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 }; /** * Update a specific fee line item for a Quote * * PUT /api/quotes/{quoteId}/fee-line-items/{lineItemId} */ export const updateApiApiQuotesQuoteIdFeeLineItemsLineItemId = async (args: UpdateApiApiQuotesQuoteIdFeeLineItemsLineItemIdArgs, options?: UpdateApiApiQuotesQuoteIdFeeLineItemsLineItemIdOptions) => { const {baseUrl = "https://api.fulcrumpro.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/quotes/${encodeURIComponent(String(args.quoteId))}/fee-line-items/${encodeURIComponent(String(args.lineItemId))}${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(quoteFeeLineItemDto, await res.json()) };