1'use strict';23const { isBlank } = require('./value-utils.js');45// rp-target-wix — spec 0042 Decision 5: balance-reconciliation REPORTING, not a write path.6//7// Wix's gift-cards API has no balance-increase/credit method (spec 0042's "no-credit-API8// finding": create, send-email, query/search, disable, find-by-email, redeem, void — nothing that9// raises a balance). The only correction for a card already created wrong is disable-and-replace,10// a code change that alters the customer-facing code and needs its own human sign-off (see11// gift-cards/gift-card.json's pitfalls) — never a silent balance patch. This module therefore only12
48 gap: { code: 'invalid-policy', summary: `policy must be "A", "B", or "C" (spec 0042 Decision 5) — got ${JSON.stringify(policy)}.` },
49 };
50 }
51
52 const source = normalizeMoney(sourceBalance);
53 if (source === null) {
54 return {
55 sourceNumber,
56 ok: false,
57 gap: { code: 'unavailable-source-balance', summary: `no verified current balance available for card ${sourceNumber} from the bridge plugin (spec 0040) — report this card as unreconciled rather than assuming it matches.` },
58 };
59 }
60 const wix = normalizeMoney(wixBalance);
61 if (wix === null) {
62 return {
63 sourceNumber,
64 ok: false,
65 gap: { code: 'unavailable-wix-balance', summary: `no Wix balance available for card ${sourceNumber} — read it back via Get Gift Card before reconciling.` },
84 summary: `card ${sourceNumber} shows ${wix} in Wix but ${source} at the source — the known, accepted overstatement of Policy A (face value at creation, no replay). Correcting it requires disabling and replacing the card (no balance-credit API exists), which changes the customer-facing code and needs its own human sign-off.`,
85 };
86 }
87
88 // Any other direction/policy combination is not a shape any policy's documented behavior
89 // produces on its own (e.g. Policy A showing a Wix balance BELOW the source, or any mismatch at
90 // all under Policy B/C) — a real anomaly, not something to explain away.
91 return {
92 sourceNumber,
93 ok: false,
94 policy,
95 sourceBalance: source,
96 wixBalance: wix,
97 drift,
98 verdict: 'unexpected-drift',
99 action: 'investigate',
100 summary: `card ${sourceNumber} shows ${wix} in Wix vs ${source} at the source (drift ${drift}) under Policy ${policy} — not a shape any policy's documented behavior explains; investigate before accepting or correcting it.`,