import {z} from 'zod' export type GetApiLegalEntitiesIdArgs = {id: number, limit?: number | undefined, offset?: number | undefined, order_by?: string | undefined, dir?: ('asc' | 'desc') | undefined, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined}; export type GetApiLegalEntitiesIdOptions = {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 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} * * GET /legal_entities/{id} * * Also accepts auth: OAuth2ClientCredential */ export const getApiLegalEntitiesId = async (args: GetApiLegalEntitiesIdArgs, options?: GetApiLegalEntitiesIdOptions) => { const {baseUrl = "https://r38.coupadev.com/api", fetch: fetchFn = fetch, OAuth2AccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.dir != null) query.append("dir", String(args.dir)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(legalEntity, await res.json()) };