// @ts-check import { renameLabelFor } from "./evaluate.js"; /** * @typedef {import("../generated/api").CartInput} RunInput * @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult */ /** * Delivery Customization Function: relabels every presented delivery * option to the shopper's actual chosen method + date, so checkout never * shows a generic carrier label ("Standard", "Economy") that could be * mistaken for a shipping ETA on what's actually a pickup or local-delivery * order. Phase 4 doesn't yet have a per-option method mapping (that needs * Phase 5's zones/rates work), so every option in the cart gets the same * clarified label — reasonable since a single order only has one chosen * fulfillment method today. * @param {RunInput} input * @returns {FunctionRunResult} */ export function deliveryCustomizationRun(input) { const attributes = { dd_method: input.cart.ddMethod?.value, dd_date: input.cart.ddDate?.value, }; const decision = renameLabelFor(attributes); if (!decision.rename) { return { operations: [] }; } const operations = input.cart.deliveryGroups.flatMap((group) => group.deliveryOptions.map((option) => ({ rename: { deliveryOptionHandle: option.handle, title: decision.title, }, })), ); return { operations }; }