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 BillToAddress = {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 Currency = {code: unknown, decimals?: number | undefined, enabled?: boolean | undefined, id?: number | undefined, name: unknown, symbol?: unknown | undefined}; export type LegalEntityAddress = {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 LegalEntity = {abbreviation: unknown, 'accounting-method'?: ('ifrs' | 'ifrs_9' | 'us_gaap') | undefined, active?: boolean | undefined, 'bill-to-address'?: BillToAddress | undefined, 'bill-to-addresses'?: Array | undefined, 'corporate-sector'?: unknown | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, currency: Currency, description?: unknown | undefined, 'external-identification-company-code'?: unknown | undefined, 'external-identification-creditor-id'?: unknown | undefined, 'external-identification-lei'?: unknown | undefined, 'external-identification-name-matching'?: unknown | undefined, 'external-identification-name-trading'?: unknown | undefined, 'external-identification-swift'?: unknown | undefined, id?: number | undefined, 'legal-entity-address'?: LegalEntityAddress | undefined, 'legal-entity-addresses'?: Array | undefined, name: unknown, parent?: LegalEntity | undefined, 'swift-code'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined, 'use-fx-rates-reciprocal'?: boolean | undefined}; export type UpdateApiLegalEntitiesIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: LegalEntity}; export type UpdateApiLegalEntitiesIdOptions = {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 billToAddress = 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 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 legalEntityAddress = 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 legalEntity: z.ZodType = z.object({abbreviation: z.string(), "accounting-method": z.enum(["ifrs", "ifrs_9", "us_gaap"]).optional(), active: z.boolean().optional(), "bill-to-address": billToAddress.optional(), "bill-to-addresses": z.array(billToAddress).optional(), "corporate-sector": z.string().optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), currency: currency, description: z.string().optional(), "external-identification-company-code": z.string().optional(), "external-identification-creditor-id": z.string().optional(), "external-identification-lei": z.string().optional(), "external-identification-name-matching": z.string().optional(), "external-identification-name-trading": z.string().optional(), "external-identification-swift": z.string().optional(), id: z.number().int().optional(), "legal-entity-address": legalEntityAddress.optional(), "legal-entity-addresses": z.array(legalEntityAddress).optional(), name: z.string(), parent: z.lazy(() => legalEntity.optional()), "swift-code": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional(), "use-fx-rates-reciprocal": z.boolean().optional()}); export const updateApiLegalEntitiesIdResponse = z.array(legalEntity); 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 }; /** * /legal_entities/{id} * * PUT /legal_entities/{id} * * Also accepts auth: OAuth2ClientCredential */ export const updateApiLegalEntitiesId = async (args: UpdateApiLegalEntitiesIdArgs, options?: UpdateApiLegalEntitiesIdOptions) => { 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(/\/+$/, '')}/legal_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(updateApiLegalEntitiesIdResponse, await res.json()) };