import {z} from 'zod' export type PriceCalculationParameter = {id?: string | undefined, version?: string | undefined, articleCategoryId?: string | undefined, articleId?: string | undefined, createdDate?: number | undefined, fixSurcharge?: unknown | undefined, fromScale: unknown, lastModifiedDate?: number | undefined, lowerPurchasePriceBound: unknown, margin?: unknown | undefined, percentSurcharge?: unknown | undefined, profit?: unknown | undefined, salesChannel: string}; export type CreateApiPriceCalculationParameterArgs = {dryRun?: boolean | undefined, body: PriceCalculationParameter}; export type CreateApiPriceCalculationParameterOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const priceCalculationParameter = z.object({id: z.string().optional(), version: z.string().optional(), articleCategoryId: z.string().optional(), articleId: z.string().optional(), createdDate: z.number().int().optional(), fixSurcharge: z.string().optional(), fromScale: z.string(), lastModifiedDate: z.number().int().optional(), lowerPurchasePriceBound: z.string(), margin: z.string().optional(), percentSurcharge: z.string().optional(), profit: z.string().optional(), salesChannel: z.string()}); 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 }; /** * create a priceCalculationParameter * * POST /priceCalculationParameter */ export const createApiPriceCalculationParameter = async (args: CreateApiPriceCalculationParameterArgs, options: CreateApiPriceCalculationParameterOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/priceCalculationParameter${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(priceCalculationParameter, await res.json()) };