1'use strict';23// Every outcome ensurePlanOrder can return, what each means for the journal, and the cutover items4// the plan-order pass hands to the completion report -- in one frozen place.5//6// The writer (rp-target-wix ensurePlanOrder) returns an outcome per source contract; the generated7// importer records each one here with recordPlanOrderOutcome, and canceled/expired source8// contracts (never written: Wix cannot hold them as orders) with recordPlanOrderHistoryOnly. The9// completion report joins reportRows(), so a subscription that did not land as a live order, or10// whose billing no longer runs on its own, is always a task for someone. Same rule as11// member-outcome-registry.js: a code this file does not know throws instead of being bucketed.1213const fs =
98 if (!['canceled', 'expired'].includes(sourceStatus)) throw new Error(`history-only plan orders are canceled or expired source contracts, got ${JSON.stringify(sourceStatus)}`);
102const IMPORT_OPERATOR_PROMPT_UNKNOWN = `For each source key in affectedIds, read its row in ${OUTCOMES_PATH} (memberId, planId, startDate). List Pricing Plans orders for that member and plan (GET /pricing-plans/v2/orders?buyerIds=<memberId>&planIds=<planId>). If one order has that start date, write its id to the plan-order crosswalk for the source key. If none, re-run the plan-order import for that record only. Never create a second order by hand: orders cannot be deleted.`;
103const IMPORT_OPERATOR_PROMPT_REVIEW = `For each source key in affectedIds, read its outcome in ${OUTCOMES_PATH}. Ambiguous: choose which listed order is the contract's and write its id to the crosswalk. Failed or read failed: fix the cause and re-run the plan-order import for those records. Read-back mismatch or failed: compare the order in Business Manager with the source contract and record the decision. Never create a second order for a key that has an orderId.`;
104const IMPORT_OPERATOR_PROMPT_SHARED = `Two or more source contracts in ${OUTCOMES_PATH} were matched to the same Wix order (same member, plan and start date). For each order id in affectedIds, decide whether the source holds a duplicate; if not, re-run the plan-order import for the extra contract with a distinguishing start date chosen with the owner.`;
115 action: `Cutover Operator: ${liveOrders.length} pricing-plan subscription(s) were imported as offline orders; Wix does not charge them automatically. Ask the owner how to collect from now on: mark each cycle paid offline in Business Manager > Pricing Plans, or ask subscribers to buy the plan again online. Record the choice.`,
116 deadlineReason: 'before go-live; the next billing date of each subscription is unpaid otherwise', affectedCount: liveOrders.length, affectedIds: liveOrders,
117 artifactRefs: [OUTCOMES_PATH], resolutionEvidence: "The owner's collection choice is recorded on this task.",
122 action: `Cutover Operator: ${history.length} canceled or expired source subscription(s) were kept as history only; Wix cannot hold them as plan orders. No action unless the owner wants a subscriber re-added (Business Manager > Pricing Plans > Sell a plan).`,
129 action: `Cutover Operator: ${notLive.length} subscription(s) match an order on the site that is already canceled or ended, so the subscriber has no live plan. In Business Manager > Pricing Plans, re-add each subscriber to the plan (Sell a plan) if the source subscription is still active.`,
136 action: `Cutover Operator: ${paused.length} subscription(s) paused on the source were imported but are not paused on Wix. In Business Manager > Pricing Plans, pause each listed order.`,
137 deadlineReason: 'before go-live; these subscribers have access they paused', affectedCount: paused.length, affectedIds: paused.map((row) => row.orderId),
138 artifactRefs: [OUTCOMES_PATH], resolutionEvidence: 'Each listed order reads back PAUSED.',
151 action: `Requires Import Operator: ${review.length} subscription(s) did not land cleanly (ambiguous match, failed write or read, or a read-back mismatch).`,
162 action: `Requires Import Operator: ${shared.length} Wix order(s) are claimed by more than one source subscription (same member, plan and start date).`,