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 Commodity = {active?: boolean | undefined, category?: ('goods' | 'services') | undefined, 'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, deductibility?: ('fully_deductible' | 'partially_deductible' | 'not_deductible') | undefined, id?: number | undefined, 'imported-from-taxonomy'?: boolean | undefined, name: unknown, parent?: Commodity | undefined, preferred?: ('Yes' | 'No' | 'Automatic' | 'Always' | 'Never') | undefined, subcategory?: ('raw_materials' | 'investment_goods' | 'services_exceptions') | undefined, 'translated-name'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined}; export type CommodityTranslation = {commodity: Commodity, 'created-at'?: unknown | undefined, id?: number | undefined, locale: unknown, name: unknown, 'updated-at'?: unknown | undefined}; export type PatchApiCommodityTranslationsIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: CommodityTranslation}; export type PatchApiCommodityTranslationsIdOptions = {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 commodity: z.ZodType = z.object({active: z.boolean().optional(), category: z.enum(["goods", "services"]).optional(), "created-at": z.string().optional(), "created-by": userSimple.optional(), deductibility: z.enum(["fully_deductible", "partially_deductible", "not_deductible"]).optional(), id: z.number().int().optional(), "imported-from-taxonomy": z.boolean().optional(), name: z.string(), parent: z.lazy(() => commodity.optional()), preferred: z.enum(["Yes", "No", "Automatic", "Always", "Never"]).optional(), subcategory: z.enum(["raw_materials", "investment_goods", "services_exceptions"]).optional(), "translated-name": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional()}); export const commodityTranslation = z.object({commodity: commodity, "created-at": z.string().optional(), id: z.number().int().optional(), locale: z.string(), name: z.string(), "updated-at": z.string().optional()}); export const patchApiCommodityTranslationsIdResponse = z.array(commodityTranslation); 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 commodity translation * * PATCH /commodity_translations/{id} * * Also accepts auth: OAuth2ClientCredential */ export const patchApiCommodityTranslationsId = async (args: PatchApiCommodityTranslationsIdArgs, options?: PatchApiCommodityTranslationsIdOptions) => { 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(/\/+$/, '')}/commodity_translations/${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(patchApiCommodityTranslationsIdResponse, await res.json()) };