@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.js CHANGED
@@ -1127,6 +1127,26 @@ var deriveAnswers = (messages) => {
1127
1127
  return out;
1128
1128
  };
1129
1129
 
1130
+ // src/utils/readPlan.ts
1131
+ var PLAN_PART_KIND = "onboarding_plan";
1132
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1133
+ var hasDataParts = (value) => isRecord(value) && Array.isArray(value.dataParts);
1134
+ var planFromPart = (part) => {
1135
+ if (!isRecord(part) || part.kind !== PLAN_PART_KIND) return void 0;
1136
+ return isRecord(part.plan) ? part.plan : void 0;
1137
+ };
1138
+ var readPlan = (messages) => {
1139
+ for (let i = messages.length - 1; i >= 0; i--) {
1140
+ const message = messages[i];
1141
+ if (!hasDataParts(message)) continue;
1142
+ for (const part of message.dataParts) {
1143
+ const plan = planFromPart(part);
1144
+ if (plan !== void 0) return plan;
1145
+ }
1146
+ }
1147
+ return void 0;
1148
+ };
1149
+
1130
1150
  // src/utils/readProgress.ts
1131
1151
  var readProgress = (response) => {
1132
1152
  var _a;
@@ -1141,7 +1161,10 @@ var readProgress = (response) => {
1141
1161
  key: typeof p.key === "string" ? p.key : void 0,
1142
1162
  // Whitelisted the same way as every other field: an old backend simply omits it.
1143
1163
  slot_id: typeof p.slot_id === "string" ? p.slot_id : void 0,
1144
- skippable: typeof p.skippable === "boolean" ? p.skippable : void 0
1164
+ skippable: typeof p.skippable === "boolean" ? p.skippable : void 0,
1165
+ // Whitelisted like the rest: a non-string (or absent) arm key reads as "no experiment", never
1166
+ // as an error. The kit does not interpret the value — see `OnboardingProgress.variant`.
1167
+ variant: typeof p.variant === "string" ? p.variant : void 0
1145
1168
  };
1146
1169
  };
1147
1170
 
@@ -1683,6 +1706,7 @@ var OnboardingFlow = ({
1683
1706
  const clientContextRef = React19.useRef(clientContext);
1684
1707
  clientContextRef.current = clientContext;
1685
1708
  const lastScreenIndexRef = React19.useRef(-1);
1709
+ const variantRef = React19.useRef(void 0);
1686
1710
  const previewTimer = React19.useRef(null);
1687
1711
  const [runId, setRunId] = React19.useState(0);
1688
1712
  const startedRunRef = React19.useRef(-1);
@@ -1732,14 +1756,17 @@ var OnboardingFlow = ({
1732
1756
  React19.useEffect(() => {
1733
1757
  var _a2, _b2, _c2, _d2;
1734
1758
  setValidationError(void 0);
1759
+ if (variantRef.current === void 0 && progress.variant) variantRef.current = progress.variant;
1735
1760
  if (!(lastCard == null ? void 0 : lastCard.id)) return;
1736
1761
  const step2 = (_a2 = progress.step) != null ? _a2 : renderedCount;
1737
1762
  lastScreenIndexRef.current = Math.max(0, step2 - 1);
1738
- (_c2 = onEventRef.current) == null ? void 0 : _c2.call(onEventRef, {
1763
+ const turn = {
1739
1764
  type: "turn",
1740
1765
  step: step2,
1741
1766
  component: (_b2 = lastCard.response) == null ? void 0 : _b2.component
1742
- });
1767
+ };
1768
+ if (variantRef.current !== void 0) turn.variant = variantRef.current;
1769
+ (_c2 = onEventRef.current) == null ? void 0 : _c2.call(onEventRef, turn);
1743
1770
  if (((_d2 = lastCard.response) == null ? void 0 : _d2.component) === "InterstitialCard") {
1744
1771
  sendPreview(reportTargetRef.current, {
1745
1772
  sessionId: sessionIdRef.current,
@@ -1797,7 +1824,11 @@ var OnboardingFlow = ({
1797
1824
  const handleFinish = React19.useCallback(() => {
1798
1825
  if (finished.current) return;
1799
1826
  finished.current = true;
1800
- onCompleteRef.current({ answers: deriveAnswers(messages), raw: messages });
1827
+ const result = { answers: deriveAnswers(messages), raw: messages };
1828
+ const plan = readPlan(messages);
1829
+ if (plan !== void 0) result.plan = plan;
1830
+ if (variantRef.current !== void 0) result.variant = variantRef.current;
1831
+ onCompleteRef.current(result);
1801
1832
  }, [messages]);
1802
1833
  const handleRetry = React19.useCallback(() => {
1803
1834
  attempts.current = 0;