@wireai/activation 0.13.5 → 0.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1121,6 +1121,26 @@ var deriveAnswers = (messages) => {
1121
1121
  return out;
1122
1122
  };
1123
1123
 
1124
+ // src/utils/readPlan.ts
1125
+ var PLAN_PART_KIND = "onboarding_plan";
1126
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1127
+ var hasDataParts = (value) => isRecord(value) && Array.isArray(value.dataParts);
1128
+ var planFromPart = (part) => {
1129
+ if (!isRecord(part) || part.kind !== PLAN_PART_KIND) return void 0;
1130
+ return isRecord(part.plan) ? part.plan : void 0;
1131
+ };
1132
+ var readPlan = (messages) => {
1133
+ for (let i = messages.length - 1; i >= 0; i--) {
1134
+ const message = messages[i];
1135
+ if (!hasDataParts(message)) continue;
1136
+ for (const part of message.dataParts) {
1137
+ const plan = planFromPart(part);
1138
+ if (plan !== void 0) return plan;
1139
+ }
1140
+ }
1141
+ return void 0;
1142
+ };
1143
+
1124
1144
  // src/utils/readProgress.ts
1125
1145
  var readProgress = (response) => {
1126
1146
  var _a;
@@ -1135,7 +1155,10 @@ var readProgress = (response) => {
1135
1155
  key: typeof p.key === "string" ? p.key : void 0,
1136
1156
  // Whitelisted the same way as every other field: an old backend simply omits it.
1137
1157
  slot_id: typeof p.slot_id === "string" ? p.slot_id : void 0,
1138
- skippable: typeof p.skippable === "boolean" ? p.skippable : void 0
1158
+ skippable: typeof p.skippable === "boolean" ? p.skippable : void 0,
1159
+ // Whitelisted like the rest: a non-string (or absent) arm key reads as "no experiment", never
1160
+ // as an error. The kit does not interpret the value — see `OnboardingProgress.variant`.
1161
+ variant: typeof p.variant === "string" ? p.variant : void 0
1139
1162
  };
1140
1163
  };
1141
1164
 
@@ -1677,6 +1700,7 @@ var OnboardingFlow = ({
1677
1700
  const clientContextRef = useRef(clientContext);
1678
1701
  clientContextRef.current = clientContext;
1679
1702
  const lastScreenIndexRef = useRef(-1);
1703
+ const variantRef = useRef(void 0);
1680
1704
  const previewTimer = useRef(null);
1681
1705
  const [runId, setRunId] = useState(0);
1682
1706
  const startedRunRef = useRef(-1);
@@ -1726,14 +1750,17 @@ var OnboardingFlow = ({
1726
1750
  useEffect(() => {
1727
1751
  var _a2, _b2, _c2, _d2;
1728
1752
  setValidationError(void 0);
1753
+ if (variantRef.current === void 0 && progress.variant) variantRef.current = progress.variant;
1729
1754
  if (!(lastCard == null ? void 0 : lastCard.id)) return;
1730
1755
  const step2 = (_a2 = progress.step) != null ? _a2 : renderedCount;
1731
1756
  lastScreenIndexRef.current = Math.max(0, step2 - 1);
1732
- (_c2 = onEventRef.current) == null ? void 0 : _c2.call(onEventRef, {
1757
+ const turn = {
1733
1758
  type: "turn",
1734
1759
  step: step2,
1735
1760
  component: (_b2 = lastCard.response) == null ? void 0 : _b2.component
1736
- });
1761
+ };
1762
+ if (variantRef.current !== void 0) turn.variant = variantRef.current;
1763
+ (_c2 = onEventRef.current) == null ? void 0 : _c2.call(onEventRef, turn);
1737
1764
  if (((_d2 = lastCard.response) == null ? void 0 : _d2.component) === "InterstitialCard") {
1738
1765
  sendPreview(reportTargetRef.current, {
1739
1766
  sessionId: sessionIdRef.current,
@@ -1791,7 +1818,11 @@ var OnboardingFlow = ({
1791
1818
  const handleFinish = useCallback(() => {
1792
1819
  if (finished.current) return;
1793
1820
  finished.current = true;
1794
- onCompleteRef.current({ answers: deriveAnswers(messages), raw: messages });
1821
+ const result = { answers: deriveAnswers(messages), raw: messages };
1822
+ const plan = readPlan(messages);
1823
+ if (plan !== void 0) result.plan = plan;
1824
+ if (variantRef.current !== void 0) result.variant = variantRef.current;
1825
+ onCompleteRef.current(result);
1795
1826
  }, [messages]);
1796
1827
  const handleRetry = useCallback(() => {
1797
1828
  attempts.current = 0;