import {z} from 'zod' export type StringI18nDetail = {value?: string | undefined, language?: ('DE' | 'EN' | 'ES' | 'PT' | 'FR' | 'IT' | 'ZH') | undefined}; export type WeightDetail = {value?: number | undefined, unit?: ('KG' | 'G' | 'LB' | 'OZ') | undefined}; export type LengthMeasurementDetail = {value?: number | undefined, unit?: ('M' | 'DM' | 'CM' | 'MM' | 'IN') | undefined}; export type MonetaryValueDetail = {currencyCode?: string | undefined, value?: number | undefined}; export type PackagingUnitDetail = {type?: ('PALLET' | 'CARTON') | undefined, barcode?: string | undefined, piecesPerPackagingUnit?: number | undefined, grossWeight?: WeightDetail | undefined, netWeight?: WeightDetail | undefined, length?: LengthMeasurementDetail | undefined, width?: LengthMeasurementDetail | undefined, height?: LengthMeasurementDetail | undefined}; export type ArticleMinimumQuantityDetail = {quantity?: number | undefined, warehouseId: number, calculationMode?: string | undefined}; export type MinimumExpirationDateDetail = {notifyDaysBeforeExpiration: number, warehouseId: number}; export type ArticleMinimumShelfLifeDetail = {minimumShelfLife: number, warehouseId: number}; export type ArticlePost = {sku: string, deletedAt?: string | undefined, alternativeSkus?: Array | undefined, name?: StringI18nDetail | undefined, articleType?: ('PRODUCT' | 'CARTON') | undefined, barcode?: string | undefined, supplierReferenceNumber?: string | undefined, alternativeBarcodes?: Array | undefined, grossWeight?: WeightDetail | undefined, netWeight?: WeightDetail | undefined, lotRequired?: boolean | undefined, expirationDateRequired?: boolean | undefined, serialNumberRequired?: boolean | undefined, canShipWithoutCarton?: boolean | undefined, length?: LengthMeasurementDetail | undefined, width?: LengthMeasurementDetail | undefined, height?: LengthMeasurementDetail | undefined, customsContentDescription?: string | undefined, countryOfOrigin?: ('AF' | 'AX' | 'AL' | 'DZ' | 'AS' | 'AD' | 'AO' | 'AI' | 'AQ' | 'AG' | 'AR' | 'AM' | 'AW' | 'AU' | 'AT' | 'AZ' | 'BS' | 'BH' | 'BD' | 'BB' | 'BY' | 'BE' | 'BZ' | 'BJ' | 'BM' | 'BT' | 'BO' | 'BA' | 'BW' | 'BV' | 'BR' | 'IO' | 'BN' | 'BG' | 'BF' | 'BI' | 'KH' | 'CM' | 'CA' | 'CV' | 'KY' | 'CF' | 'TD' | 'CL' | 'CN' | 'CX' | 'CC' | 'CO' | 'KM' | 'CG' | 'CD' | 'CK' | 'CR' | 'CI' | 'HR' | 'CU' | 'CY' | 'CZ' | 'DK' | 'DJ' | 'DM' | 'DO' | 'EC' | 'EG' | 'SV' | 'GQ' | 'ER' | 'EE' | 'ET' | 'FK' | 'FO' | 'FJ' | 'FI' | 'FR' | 'GF' | 'PF' | 'TF' | 'GA' | 'GM' | 'GE' | 'DE' | 'GH' | 'GI' | 'GR' | 'GL' | 'GD' | 'GP' | 'GU' | 'GT' | 'GG' | 'GN' | 'GW' | 'GY' | 'HT' | 'HM' | 'VA' | 'HN' | 'HK' | 'HU' | 'IS' | 'IN' | 'ID' | 'IR' | 'IQ' | 'IE' | 'IM' | 'IL' | 'IT' | 'JM' | 'JP' | 'JE' | 'JO' | 'KZ' | 'KE' | 'KI' | 'KP' | 'KR' | 'XK' | 'KW' | 'KG' | 'LA' | 'LV' | 'LB' | 'LS' | 'LR' | 'LY' | 'LI' | 'LT' | 'LU' | 'MO' | 'MK' | 'MG' | 'MW' | 'MY' | 'MV' | 'ML' | 'MT' | 'MH' | 'MQ' | 'MR' | 'MU' | 'YT' | 'MX' | 'FM' | 'MD' | 'MC' | 'MN' | 'ME' | 'MS' | 'MA' | 'MZ' | 'MM' | 'NA' | 'NR' | 'NP' | 'NL' | 'NC' | 'NZ' | 'NI' | 'NE' | 'NG' | 'NU' | 'NF' | 'MP' | 'NO' | 'OM' | 'PK' | 'PW' | 'PS' | 'PA' | 'PG' | 'PY' | 'PE' | 'PH' | 'PN' | 'PL' | 'PT' | 'PR' | 'QA' | 'RE' | 'RO' | 'RU' | 'RW' | 'BL' | 'SH' | 'KN' | 'LC' | 'MF' | 'PM' | 'VC' | 'WS' | 'SM' | 'ST' | 'SA' | 'SN' | 'RS' | 'SC' | 'SL' | 'SG' | 'SK' | 'SI' | 'SB' | 'SO' | 'ZA' | 'GS' | 'ES' | 'LK' | 'SD' | 'SR' | 'SJ' | 'CW' | 'BQ' | 'SX' | 'SZ' | 'SE' | 'CH' | 'SY' | 'TW' | 'TJ' | 'TZ' | 'TH' | 'TL' | 'TG' | 'TK' | 'TO' | 'TT' | 'TN' | 'TR' | 'TM' | 'TC' | 'TV' | 'UG' | 'UA' | 'AE' | 'GB' | 'US' | 'UM' | 'UY' | 'UZ' | 'VU' | 'VE' | 'VN' | 'VG' | 'VI' | 'WF' | 'EH' | 'YE' | 'ZM' | 'ZW') | undefined, salesPrice?: MonetaryValueDetail | undefined, insuranceValue?: MonetaryValueDetail | undefined, customsValue?: MonetaryValueDetail | undefined, unNumber?: string | undefined, customAttributes?: {[key: string]: string} | undefined, itemGroup?: string | undefined, lottableBatchRequired?: boolean | undefined, alternativeNames?: Array | undefined, tariffNumber?: string | undefined, alternativeSalesPrices?: Array | undefined, alternativeInsuranceValues?: Array | undefined, alternativeCustomsValues?: Array | undefined, packagingUnits?: Array | undefined, lotNumberPriorities?: {[key: string]: string} | undefined, minimumQuantities?: Array | undefined, minimumExpirationDates?: Array | undefined, minimumShelfLives?: Array | undefined, dummyExpirationDate?: string | undefined, dummyLotNumber?: string | undefined}; export type CreateApiArticlesSellerIdValidateArgs = {sellerId: number, body: ArticlePost}; export type CreateApiArticlesSellerIdValidateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const stringI18nDetail = z.object({value: z.string().max(255).optional(), language: z.enum(["DE", "EN", "ES", "PT", "FR", "IT", "ZH"]).optional()}); export const weightDetail = z.object({value: z.number().optional(), unit: z.enum(["KG", "G", "LB", "OZ"]).optional()}); export const lengthMeasurementDetail = z.object({value: z.number().optional(), unit: z.enum(["M", "DM", "CM", "MM", "IN"]).optional()}); export const monetaryValueDetail = z.object({currencyCode: z.string().optional(), value: z.number().optional()}); export const packagingUnitDetail = z.object({type: z.enum(["PALLET", "CARTON"]).optional(), barcode: z.string().optional(), piecesPerPackagingUnit: z.number().int().optional(), grossWeight: weightDetail.optional(), netWeight: weightDetail.optional(), length: lengthMeasurementDetail.optional(), width: lengthMeasurementDetail.optional(), height: lengthMeasurementDetail.optional()}); export const articleMinimumQuantityDetail = z.object({quantity: z.number().int().optional(), warehouseId: z.number().int(), calculationMode: z.string().optional()}); export const minimumExpirationDateDetail = z.object({notifyDaysBeforeExpiration: z.number().int().gte(1), warehouseId: z.number().int()}); export const articleMinimumShelfLifeDetail = z.object({minimumShelfLife: z.number().int().gte(1), warehouseId: z.number().int()}); export const messageDetail = z.object({code: z.string().optional(), description: z.string().optional()}); export const link = z.object({link: z.string().optional()}); export const articleImageGet = z.object({id: z.string().optional(), url: link.optional(), packagingUnit: packagingUnitDetail.optional(), source: z.string()}); export const articleGetDetail = z.object({sku: z.string().min(1).max(50), deletedAt: z.string().optional(), alternativeSkus: z.array(z.string()).optional(), name: stringI18nDetail.optional(), articleType: z.enum(["PRODUCT", "CARTON"]).optional(), barcode: z.string().max(50).optional(), supplierReferenceNumber: z.string().max(20).optional(), alternativeBarcodes: z.array(z.string()).optional(), grossWeight: weightDetail.optional(), netWeight: weightDetail.optional(), lotRequired: z.boolean().optional(), expirationDateRequired: z.boolean().optional(), serialNumberRequired: z.boolean().optional(), canShipWithoutCarton: z.boolean().optional(), length: lengthMeasurementDetail.optional(), width: lengthMeasurementDetail.optional(), height: lengthMeasurementDetail.optional(), customsContentDescription: z.string().optional(), countryOfOrigin: z.enum(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "XK", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "CW", "BQ", "SX", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]).optional(), salesPrice: monetaryValueDetail.optional(), insuranceValue: monetaryValueDetail.optional(), customsValue: monetaryValueDetail.optional(), unNumber: z.string().optional(), customAttributes: z.record(z.string(), z.string()).optional(), itemGroup: z.string().optional(), lottableBatchRequired: z.boolean().optional(), alternativeNames: z.array(stringI18nDetail).optional(), tariffNumber: z.string().max(20).optional(), alternativeSalesPrices: z.array(monetaryValueDetail).optional(), alternativeInsuranceValues: z.array(monetaryValueDetail).optional(), alternativeCustomsValues: z.array(monetaryValueDetail).optional(), packagingUnits: z.array(packagingUnitDetail).optional(), lotNumberPriorities: z.record(z.string(), z.string()).optional(), minimumQuantities: z.array(articleMinimumQuantityDetail).optional(), minimumExpirationDates: z.array(minimumExpirationDateDetail).optional(), minimumShelfLives: z.array(articleMinimumShelfLifeDetail).optional(), dummyExpirationDate: z.string().optional(), dummyLotNumber: z.string().optional(), id: z.number().int().optional(), created: z.string().optional(), lastModified: z.string().optional(), errors: z.array(messageDetail).optional(), warnings: z.array(messageDetail).optional(), sellerId: z.number().int().optional(), articleIdentifier: z.string().optional(), images: z.array(articleImageGet).optional(), lengthM: z.number().optional(), widthM: z.number().optional(), heightM: z.number().optional(), grossWeightKG: z.number().optional(), netWeightKG: z.number().optional(), tags: z.array(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 }; /** * Validate article PUT request * * POST /articles/{sellerId}/validate */ export const createApiArticlesSellerIdValidate = async (args: CreateApiArticlesSellerIdValidateArgs, options?: CreateApiArticlesSellerIdValidateOptions) => { const {baseUrl = "https://api.quivo.co", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/articles/${encodeURIComponent(String(args.sellerId))}/validate${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(articleGetDetail, await res.json()) };