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 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 CounterpartyAddress = {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 FinancialCounterparty = {abbreviation: unknown, active?: boolean | undefined, 'bank-code'?: unknown | undefined, 'branch-code'?: unknown | undefined, 'counterparty-address'?: CounterpartyAddress | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, description?: unknown | undefined, 'external-identification-lei'?: unknown | undefined, 'external-identification-name'?: unknown | undefined, id?: number | undefined, name: unknown, 'payment-usage'?: unknown | undefined, 'swift-code'?: unknown | undefined, 'treasury-usage'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type PatchApiFinancialCounterpartiesIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: FinancialCounterparty}; export type PatchApiFinancialCounterpartiesIdOptions = {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 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 counterpartyAddress = 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(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 financialCounterparty = z.object({abbreviation: z.string(), active: z.boolean().optional(), "bank-code": z.string().optional(), "branch-code": z.string().optional(), "counterparty-address": counterpartyAddress.optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), description: z.string().optional(), "external-identification-lei": z.string().optional(), "external-identification-name": z.string().optional(), id: z.number().int().optional(), name: z.string(), "payment-usage": z.string().optional(), "swift-code": z.string().optional(), "treasury-usage": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const patchApiFinancialCounterpartiesIdResponse = z.array(financialCounterparty); 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 }; /** * /financial_counterparties/{id} * * PATCH /financial_counterparties/{id} * * Also accepts auth: OAuth2ClientCredential */ export const patchApiFinancialCounterpartiesId = async (args: PatchApiFinancialCounterpartiesIdArgs, options?: PatchApiFinancialCounterpartiesIdOptions) => { 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(/\/+$/, '')}/financial_counterparties/${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(patchApiFinancialCounterpartiesIdResponse, await res.json()) };