import {z} from 'zod' export type ReductionAddition = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, lastModifiedDate?: number | undefined, name?: string | undefined, type: 'ADDITIONAL_ABS' | 'ADDITION_PERCENT' | 'REDUCTION_ABS' | 'REDUCTION_PERCENT', value: unknown}; export type PurchasePrice = {id?: string | undefined, version?: string | undefined, createdDate?: number | undefined, currencyId: string, customerId?: string | undefined, description?: string | undefined, endDate?: number | undefined, lastModifiedByUserId?: string | undefined, lastModifiedDate?: number | undefined, price: unknown, priceScaleType: 'SCALE_FROM' | 'SCALE_TO', priceScaleValue: unknown, reductionAdditions?: Array | undefined, startDate?: number | undefined}; export type EntityReference = {entityId?: string | undefined, entityName?: string | undefined}; export type OnlyId = {id?: string | undefined}; export type CustomAttribute = {attributeDefinitionId?: string | undefined, booleanValue?: boolean | undefined, dateValue?: number | undefined, entityId?: string | undefined, entityReferences?: Array | undefined, numberValue?: unknown | undefined, selectedValueId?: string | undefined, selectedValues?: Array | undefined, stringValue?: string | undefined}; export type ArticleSupplySource = {id?: string | undefined, version?: string | undefined, articleNumber?: string | undefined, articlePrices?: Array | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, description?: string | undefined, dropshippingPossible?: boolean | undefined, ean?: string | undefined, fixedPurchaseQuantity?: unknown | undefined, ignoreInDropshippingAutomation?: boolean | undefined, internalNote?: string | undefined, lastModifiedDate?: number | undefined, manufacturerPartNumber?: string | undefined, matchCode?: string | undefined, minimumPurchaseQuantity?: unknown | undefined, name: string, procurementLeadDays?: number | undefined, shortDescription1?: string | undefined, shortDescription2?: string | undefined, supplierId?: string | undefined, supplierStockQuantity?: unknown | undefined, taxRateType?: ('REDUCED' | 'SLIGHTLY_REDUCED' | 'STANDARD' | 'SUPER_REDUCED' | 'ZERO') | undefined, unitId?: string | undefined}; export type UpdateApiArticleSupplySourceIdIdArgs = {id: string, dryRun?: boolean | undefined, body: ArticleSupplySource}; export type UpdateApiArticleSupplySourceIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const reductionAddition = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), lastModifiedDate: z.number().int().optional(), name: z.string().optional(), type: z.enum(["ADDITIONAL_ABS", "ADDITION_PERCENT", "REDUCTION_ABS", "REDUCTION_PERCENT"]), value: z.string()}); export const purchasePrice = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), currencyId: z.string(), customerId: z.string().optional(), description: z.string().optional(), endDate: z.number().int().optional(), lastModifiedByUserId: z.string().optional(), lastModifiedDate: z.number().int().optional(), price: z.string(), priceScaleType: z.enum(["SCALE_FROM", "SCALE_TO"]), priceScaleValue: z.string(), reductionAdditions: z.array(reductionAddition).optional(), startDate: z.number().int().optional()}); export const entityReference = z.object({entityId: z.string().optional(), entityName: z.string().optional()}); export const onlyId = z.object({id: z.string().optional()}); export const customAttribute = z.object({attributeDefinitionId: z.string().optional(), booleanValue: z.boolean().optional(), dateValue: z.number().int().optional(), entityId: z.string().optional(), entityReferences: z.array(entityReference).optional(), numberValue: z.string().optional(), selectedValueId: z.string().optional(), selectedValues: z.array(onlyId).optional(), stringValue: z.string().optional()}); export const articleSupplySource = z.object({id: z.string().optional(), version: z.string().optional(), articleNumber: z.string().optional(), articlePrices: z.array(purchasePrice).optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), description: z.string().optional(), dropshippingPossible: z.boolean().optional(), ean: z.string().optional(), fixedPurchaseQuantity: z.string().optional(), ignoreInDropshippingAutomation: z.boolean().optional(), internalNote: z.string().optional(), lastModifiedDate: z.number().int().optional(), manufacturerPartNumber: z.string().optional(), matchCode: z.string().optional(), minimumPurchaseQuantity: z.string().optional(), name: z.string(), procurementLeadDays: z.number().int().optional(), shortDescription1: z.string().optional(), shortDescription2: z.string().optional(), supplierId: z.string().optional(), supplierStockQuantity: z.string().optional(), taxRateType: z.enum(["REDUCED", "SLIGHTLY_REDUCED", "STANDARD", "SUPER_REDUCED", "ZERO"]).optional(), unitId: z.string().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 }; /** * update articleSupplySource * * PUT /articleSupplySource/id/{id} */ export const updateApiArticleSupplySourceIdId = async (args: UpdateApiArticleSupplySourceIdIdArgs, options: UpdateApiArticleSupplySourceIdIdOptions) => { 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(/\/+$/, '')}/articleSupplySource/id/${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(articleSupplySource, await res.json()) };