import type TrackPurchaseParameters from '../models/TrackPurchaseParameters'; export default class TrackPurchaseParametersUtil { /** * Returns the names of the fields required for Shopping V2 purchase * tracking parity with Web that are missing from `parameters`. * * Required fields: orderId, value (order_value), currencyCode (currency), * subtotal, and a non-empty products list (line_items) where every product * has a non-empty sku or extProductId. */ static missingRequiredV2Fields( parameters?: TrackPurchaseParameters | null ): string[] { if (!parameters) { return ['parameters']; } const missing: string[] = []; if (!parameters.orderId) { missing.push('orderId'); } if (typeof parameters.value !== 'number') { missing.push('value'); } if (!parameters.currencyCode) { missing.push('currencyCode'); } if (typeof parameters.subtotal !== 'number') { missing.push('subtotal'); } const products = parameters.products; if (!products || products.length === 0) { missing.push('products'); } else { products.forEach((product, index) => { if (!product.sku && !product.extProductId) { missing.push(`products[${index}].sku`); } }); } return missing; } }