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 BusinessEntityAccountOwner = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, email?: string | undefined, fullname?: string | undefined, id?: number | undefined, purposes?: Array | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined, 'user-id': number}; export type BusinessEntityAlternateName = {'business-entity-id'?: number | undefined, 'created-at'?: string | undefined, id?: number | undefined, name?: unknown | undefined, 'updated-at'?: string | undefined}; export type BusinessEntityExternalReference = {'business-entity-id'?: number | undefined, 'created-at'?: string | undefined, id?: number | undefined, name?: unknown | undefined, type?: unknown | undefined, 'updated-at'?: string | undefined, value?: unknown | undefined}; export type BusinessEntityRelationship = {'business-entity-id'?: number | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, id?: number | undefined, 'related-business-entity-id'?: number | undefined, 'relationship-type': 'parent_child', status?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type BusinessEntityAddress = {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 TaxRegistration = {active?: boolean | undefined, country: Country, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'fiscal-representative': unknown, id?: number | undefined, local?: boolean | undefined, number: unknown, 'owner-id'?: number | undefined, 'owner-type'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type BusinessEntity = {addresses?: Array
| undefined, 'business-entity-account-owners'?: Array | undefined, 'business-entity-alternate-names'?: Array | undefined, 'business-entity-external-references'?: Array | undefined, 'business-entity-relationships'?: Array | undefined, 'country-of-origin'?: Country | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'display-name'?: unknown | undefined, 'formation-type'?: ('Organization' | 'Person') | undefined, id?: number | undefined, name: unknown, 'primary-address'?: BusinessEntityAddress | undefined, 'primary-contact'?: Contact | undefined, status?: unknown | undefined, 'tax-registrations'?: Array | undefined, type?: ('LegalBusinessEntity' | 'OrganizationalBusinessEntity') | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type UpdateApiBusinessEntitiesIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: BusinessEntity}; export type UpdateApiBusinessEntitiesIdOptions = {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 businessEntityAccountOwner = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), email: z.string().optional(), fullname: z.string().optional(), id: z.number().int().optional(), purposes: z.array(purpose).optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional(), "user-id": z.number().int()}); export const businessEntityAlternateName = z.object({"business-entity-id": z.number().int().optional(), "created-at": z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), "updated-at": z.string().optional()}); export const businessEntityExternalReference = z.object({"business-entity-id": z.number().int().optional(), "created-at": z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), type: z.string().optional(), "updated-at": z.string().optional(), value: z.string().optional()}); export const businessEntityRelationship = z.object({"business-entity-id": z.number().int().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), id: z.number().int().optional(), "related-business-entity-id": z.number().int().optional(), "relationship-type": z.literal("parent_child"), status: z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const businessEntityAddress = 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 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 taxRegistration = z.object({active: z.boolean().optional(), country: country, "created-at": z.string().optional(), "created-by": userSimple.optional(), "fiscal-representative": z.unknown(), id: z.number().int().optional(), local: z.boolean().optional(), number: z.string(), "owner-id": z.number().int().optional(), "owner-type": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const businessEntity = z.object({addresses: z.array(address).optional(), "business-entity-account-owners": z.array(businessEntityAccountOwner).optional(), "business-entity-alternate-names": z.array(businessEntityAlternateName).optional(), "business-entity-external-references": z.array(businessEntityExternalReference).optional(), "business-entity-relationships": z.array(businessEntityRelationship).optional(), "country-of-origin": country.optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), "display-name": z.string().optional(), "formation-type": z.enum(["Organization", "Person"]).optional(), id: z.number().int().optional(), name: z.string(), "primary-address": businessEntityAddress.optional(), "primary-contact": contact.optional(), status: z.string().optional(), "tax-registrations": z.array(taxRegistration).optional(), type: z.enum(["LegalBusinessEntity", "OrganizationalBusinessEntity"]).optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const updateApiBusinessEntitiesIdResponse = z.array(businessEntity); 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 business entity * * PUT /business_entities/{id} * * Also accepts auth: OAuth2ClientCredential */ export const updateApiBusinessEntitiesId = async (args: UpdateApiBusinessEntitiesIdArgs, options?: UpdateApiBusinessEntitiesIdOptions) => { 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(/\/+$/, '')}/business_entities/${encodeURIComponent(String(args.id))}${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(updateApiBusinessEntitiesIdResponse, await res.json()) };