import { SubjectCharacteristic, CardCharacteristicInput } from '../types/products.types'; /** * A single product variant within a merged card. * @since v3.9.2 */ export interface MergedCardVariant { /** Characteristics for this variant */ characteristics: CardCharacteristicInput[]; } /** * Result of merged card variant validation. * @since v3.9.2 */ export interface MergedCardValidationResult { /** Non-variable characteristics (isVariable: false) that have DIFFERENT values across variants — WB will reject these. */ divergentFixedChars: SubjectCharacteristic[]; /** Variable characteristics (isVariable: true) that have IDENTICAL values across all variants — possibly intentional, but flagged for review. */ identicalVariableChars: SubjectCharacteristic[]; /** True if two or more variants share the exact same combination of variable characteristic values (duplicate variants — WB rejects). */ duplicateVariants: boolean; } /** * Client-side validator for merged product card variants. * * Checks that: * 1. All variants share the same value for `isVariable: false` characteristics (fixed chars). * 2. No two variants have identical combinations of `isVariable: true` values (duplicate variants). * 3. Optionally flags variable characteristics that don't actually vary across variants. * * **v3.10.2 update**: added optional `namedFieldsPerVariant` parameter — an array (one map per * variant by index) — to correctly handle WB API characteristics with `existNamedField: true` * (e.g. `brand`, `height`, `length`, `name`, `width`, `weight`) which are submitted as top-level * card fields rather than inside the variant `characteristics[]` array. * * Without the `namedFieldsPerVariant` parameter the helper falls back to legacy behaviour and * emits a one-time `console.warn` whenever a required `existNamedField: true` characteristic is * encountered — this may cause false positives. * * This is a best-effort client-side hint. The Wildberries API is the final authority — * a validation pass here doesn't guarantee API acceptance. * * @param characteristics - All characteristics for the category (from `getObjectCharc()`) * @param variants - Variants planned for the merged card * @param namedFieldsPerVariant - Optional array of named-field maps, one per variant (by index). * Each map holds top-level field values (brand, height, etc.) keyed by characteristic name. * @returns Validation result with violations grouped by type * * @example New call pattern (v3.10.2+): * ```typescript * const charcs = await sdk.products.getObjectCharc(2314); * const result = validateMergedCardVariants( * charcs.data ?? [], * [ * { characteristics: [{ id: 14177449, value: 'Red' }] }, * { characteristics: [{ id: 14177449, value: 'Blue' }] }, * ], * [ * { brand: 'Acme', height: 10 }, * { brand: 'Acme', height: 10 }, * ] * ); * if (result.divergentFixedChars.length > 0) { * throw new Error(`Fixed chars differ: ${result.divergentFixedChars.map(c => c.name).join(', ')}`); * } * ``` * * @example Legacy call pattern (still supported, emits one-time warn if existNamedField found): * ```typescript * const result = validateMergedCardVariants(charcs.data ?? [], variants); * ``` * * @see CHANGELOG v3.10.2 for migration details * @since v3.9.2 */ export declare function validateMergedCardVariants(characteristics: SubjectCharacteristic[], variants: MergedCardVariant[], namedFieldsPerVariant?: Record[]): MergedCardValidationResult; //# sourceMappingURL=validateMergedCardVariants.d.ts.map