import {z} from 'zod' export type UserSimple = {'avatar-thumb-url'?: unknown | undefined, 'created-at'?: unknown | undefined, email: unknown, 'employee-number'?: unknown | undefined, firstname: unknown, fullname?: unknown | undefined, id?: number | undefined, lastname: unknown, login: unknown, 'salesforce-id': unknown, 'updated-at'?: unknown | undefined}; export type Currency = {code: unknown, decimals?: number | undefined, enabled?: boolean | undefined, id?: number | undefined, name: unknown, symbol?: unknown | undefined}; export type BusinessGroup = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, description?: unknown | undefined, id?: number | undefined, name: unknown, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type Country = {code: unknown, 'created-at'?: string | undefined, id?: number | undefined, name?: unknown | undefined, 'updated-at'?: string | undefined}; export type Purpose = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, id?: number | undefined, kind: unknown, name: unknown, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type Address = {active?: boolean | undefined, attention?: unknown | undefined, 'business-group-name'?: unknown | undefined, city: unknown, 'content-groups'?: Array | undefined, country: Country, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, id?: number | undefined, 'local-tax-number': unknown, 'location-code'?: unknown | undefined, name?: unknown | undefined, 'postal-code': unknown, purposes?: Array | undefined, state?: unknown | undefined, 'state-iso-code'?: unknown | undefined, street1: unknown, street2?: unknown | undefined, street3?: unknown | undefined, street4?: unknown | undefined, 'tax-registrations'?: Array
| undefined, type?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined, 'vat-country'?: Country | undefined, 'vat-number'?: unknown | undefined}; export type PhoneNumber = {'area-code'?: unknown | undefined, 'country-code'?: unknown | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, extension?: unknown | undefined, id?: number | undefined, number?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type Contact = {active?: boolean | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, email?: unknown | undefined, id?: number | undefined, 'name-additional'?: unknown | undefined, 'name-family'?: unknown | undefined, 'name-fullname'?: unknown | undefined, 'name-given'?: unknown | undefined, 'name-prefix'?: unknown | undefined, 'name-suffix'?: unknown | undefined, notes?: unknown | undefined, 'phone-fax'?: PhoneNumber | undefined, 'phone-mobile'?: PhoneNumber | undefined, 'phone-work'?: PhoneNumber | undefined, photo?: unknown | undefined, purposes?: Array | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type AccountType = {active?: boolean | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, currency: Currency, 'dynamic-flag'?: boolean | undefined, id?: number | undefined, 'legal-entity-name'?: unknown | undefined, name: unknown, 'primary-address'?: Address | undefined, 'primary-contact'?: Contact | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type Period = {'account-type'?: AccountType | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'end-date': unknown, id?: number | undefined, 'is-open'?: boolean | undefined, name: unknown, 'segment-1'?: boolean | undefined, 'segment-10'?: boolean | undefined, 'segment-11'?: boolean | undefined, 'segment-12'?: boolean | undefined, 'segment-13'?: boolean | undefined, 'segment-14'?: boolean | undefined, 'segment-15'?: boolean | undefined, 'segment-16'?: boolean | undefined, 'segment-17'?: boolean | undefined, 'segment-18'?: boolean | undefined, 'segment-19'?: boolean | undefined, 'segment-2'?: boolean | undefined, 'segment-20'?: boolean | undefined, 'segment-3'?: boolean | undefined, 'segment-4'?: boolean | undefined, 'segment-5'?: boolean | undefined, 'segment-6'?: boolean | undefined, 'segment-7'?: boolean | undefined, 'segment-8'?: boolean | undefined, 'segment-9'?: boolean | undefined, 'start-date': unknown, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type BudgetLine = {amount?: number | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, currency?: Currency | undefined, description?: unknown | undefined, 'error-on-overrun'?: boolean | undefined, id?: number | undefined, notes?: unknown | undefined, 'overrun-calculation'?: number | undefined, owner?: UserSimple | undefined, 'owner-is-approver'?: number | undefined, 'pending-requisitions-amount'?: number | undefined, period: Period, remaining?: number | undefined, 'remaining-budget'?: number | undefined, 'segment-1'?: unknown | undefined, 'segment-10'?: unknown | undefined, 'segment-11'?: unknown | undefined, 'segment-12'?: unknown | undefined, 'segment-13'?: unknown | undefined, 'segment-14'?: unknown | undefined, 'segment-15'?: unknown | undefined, 'segment-16'?: unknown | undefined, 'segment-17'?: unknown | undefined, 'segment-18'?: unknown | undefined, 'segment-19'?: unknown | undefined, 'segment-2'?: unknown | undefined, 'segment-20'?: unknown | undefined, 'segment-3'?: unknown | undefined, 'segment-4'?: unknown | undefined, 'segment-5'?: unknown | undefined, 'segment-6'?: unknown | undefined, 'segment-7'?: unknown | undefined, 'segment-8'?: unknown | undefined, 'segment-9'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type PatchApiBudgetLinesIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: BudgetLine}; export type PatchApiBudgetLinesIdOptions = {baseUrl?: string | undefined, OAuth2AccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const userSimple = z.object({"avatar-thumb-url": z.string().optional(), "created-at": z.string().optional(), email: z.string(), "employee-number": z.string().optional(), firstname: z.string(), fullname: z.string().optional(), id: z.number().int().optional(), lastname: z.string(), login: z.string(), "salesforce-id": z.string(), "updated-at": z.string().optional()}); export const currency = z.object({code: z.string(), decimals: z.number().int().optional(), enabled: z.boolean().optional(), id: z.number().int().optional(), name: z.string(), symbol: z.string().optional()}); export const businessGroup = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), description: z.string().optional(), id: z.number().int().optional(), name: z.string(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const country = z.object({code: z.string(), "created-at": z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), "updated-at": z.string().optional()}); export const purpose = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), id: z.number().int().optional(), kind: z.string(), name: z.string(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const address: z.ZodType
= z.object({active: z.boolean().optional(), attention: z.string().optional(), "business-group-name": z.string().optional(), city: z.string(), "content-groups": z.array(businessGroup).optional(), country: country, "created-at": z.string().optional(), "created-by": userSimple.optional(), id: z.number().int().optional(), "local-tax-number": z.string(), "location-code": z.string().optional(), name: z.string().optional(), "postal-code": z.string(), purposes: z.array(purpose).optional(), state: z.string().optional(), "state-iso-code": z.string().optional(), street1: z.string(), street2: z.string().optional(), street3: z.string().optional(), street4: z.string().optional(), "tax-registrations": z.array(z.lazy(() => address)).optional(), type: z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional(), "vat-country": country.optional(), "vat-number": z.string().optional()}); export const phoneNumber = z.object({"area-code": z.string().optional(), "country-code": z.string().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), extension: z.string().optional(), id: z.number().int().optional(), number: z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const contact = z.object({active: z.boolean().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), email: z.string().optional(), id: z.number().int().optional(), "name-additional": z.string().optional(), "name-family": z.string().optional(), "name-fullname": z.string().optional(), "name-given": z.string().optional(), "name-prefix": z.string().optional(), "name-suffix": z.string().optional(), notes: z.string().optional(), "phone-fax": phoneNumber.optional(), "phone-mobile": phoneNumber.optional(), "phone-work": phoneNumber.optional(), photo: z.string().optional(), purposes: z.array(purpose).optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const accountType = z.object({active: z.boolean().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), currency: currency, "dynamic-flag": z.boolean().optional(), id: z.number().int().optional(), "legal-entity-name": z.string().optional(), name: z.string(), "primary-address": address.optional(), "primary-contact": contact.optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const period = z.object({"account-type": accountType.optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), "end-date": z.string(), id: z.number().int().optional(), "is-open": z.boolean().optional(), name: z.string(), "segment-1": z.boolean().optional(), "segment-10": z.boolean().optional(), "segment-11": z.boolean().optional(), "segment-12": z.boolean().optional(), "segment-13": z.boolean().optional(), "segment-14": z.boolean().optional(), "segment-15": z.boolean().optional(), "segment-16": z.boolean().optional(), "segment-17": z.boolean().optional(), "segment-18": z.boolean().optional(), "segment-19": z.boolean().optional(), "segment-2": z.boolean().optional(), "segment-20": z.boolean().optional(), "segment-3": z.boolean().optional(), "segment-4": z.boolean().optional(), "segment-5": z.boolean().optional(), "segment-6": z.boolean().optional(), "segment-7": z.boolean().optional(), "segment-8": z.boolean().optional(), "segment-9": z.boolean().optional(), "start-date": z.string(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const budgetLine = z.object({amount: z.number().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), currency: currency.optional(), description: z.string().optional(), "error-on-overrun": z.boolean().optional(), id: z.number().int().optional(), notes: z.string().optional(), "overrun-calculation": z.number().int().optional(), owner: userSimple.optional(), "owner-is-approver": z.number().int().optional(), "pending-requisitions-amount": z.number().optional(), period: period, remaining: z.number().optional(), "remaining-budget": z.number().optional(), "segment-1": z.string().optional(), "segment-10": z.string().optional(), "segment-11": z.string().optional(), "segment-12": z.string().optional(), "segment-13": z.string().optional(), "segment-14": z.string().optional(), "segment-15": z.string().optional(), "segment-16": z.string().optional(), "segment-17": z.string().optional(), "segment-18": z.string().optional(), "segment-19": z.string().optional(), "segment-2": z.string().optional(), "segment-20": z.string().optional(), "segment-3": z.string().optional(), "segment-4": z.string().optional(), "segment-5": z.string().optional(), "segment-6": z.string().optional(), "segment-7": z.string().optional(), "segment-8": z.string().optional(), "segment-9": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const patchApiBudgetLinesIdResponse = z.array(budgetLine); 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 budget line * * PATCH /budget_lines/{id} * * Also accepts auth: OAuth2ClientCredential */ export const patchApiBudgetLinesId = async (args: PatchApiBudgetLinesIdArgs, options?: PatchApiBudgetLinesIdOptions) => { const {baseUrl = "https://r38.coupadev.com/api", fetch: fetchFn = fetch, OAuth2AccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.return_object != null) query.append("return_object", String(args.return_object)) if (args.filter != null) query.append("filter", String(args.filter)) if (OAuth2AccessCode !== undefined) headers.set('authorization', `Bearer ${OAuth2AccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/budget_lines/${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(patchApiBudgetLinesIdResponse, await res.json()) };