@parag.more.withsurface.com/forms-sdk 0.1.4

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.
Files changed (177) hide show
  1. package/README.md +63 -0
  2. package/dist/index.cjs +2737 -0
  3. package/dist/index.cjs.map +7 -0
  4. package/dist/index.mjs +2714 -0
  5. package/dist/index.mjs.map +7 -0
  6. package/dist/react/index.cjs +44 -0
  7. package/dist/react/index.cjs.map +7 -0
  8. package/dist/react/index.mjs +21 -0
  9. package/dist/react/index.mjs.map +7 -0
  10. package/dist/surface-forms-sdk.min.js +2 -0
  11. package/dist/surface-forms-sdk.min.js.map +7 -0
  12. package/dist/types/bind/bindForm.d.ts +43 -0
  13. package/dist/types/bind/bindForm.d.ts.map +1 -0
  14. package/dist/types/bind/bindForm.test.d.ts +2 -0
  15. package/dist/types/bind/bindForm.test.d.ts.map +1 -0
  16. package/dist/types/bind/bookingWidget.d.ts +35 -0
  17. package/dist/types/bind/bookingWidget.d.ts.map +1 -0
  18. package/dist/types/bind/bookingWidget.test.d.ts +2 -0
  19. package/dist/types/bind/bookingWidget.test.d.ts.map +1 -0
  20. package/dist/types/core/client/emailValidation.d.ts +23 -0
  21. package/dist/types/core/client/emailValidation.d.ts.map +1 -0
  22. package/dist/types/core/client/emailValidation.test.d.ts +2 -0
  23. package/dist/types/core/client/emailValidation.test.d.ts.map +1 -0
  24. package/dist/types/core/client/responses.d.ts +35 -0
  25. package/dist/types/core/client/responses.d.ts.map +1 -0
  26. package/dist/types/core/client/responses.test.d.ts +2 -0
  27. package/dist/types/core/client/responses.test.d.ts.map +1 -0
  28. package/dist/types/core/client/runtimeConfig.contract.test.d.ts +2 -0
  29. package/dist/types/core/client/runtimeConfig.contract.test.d.ts.map +1 -0
  30. package/dist/types/core/client/runtimeConfig.d.ts +72 -0
  31. package/dist/types/core/client/runtimeConfig.d.ts.map +1 -0
  32. package/dist/types/core/client/runtimeConfig.test.d.ts +2 -0
  33. package/dist/types/core/client/runtimeConfig.test.d.ts.map +1 -0
  34. package/dist/types/core/client/scheduler.contract.test.d.ts +2 -0
  35. package/dist/types/core/client/scheduler.contract.test.d.ts.map +1 -0
  36. package/dist/types/core/client/scheduler.d.ts +121 -0
  37. package/dist/types/core/client/scheduler.d.ts.map +1 -0
  38. package/dist/types/core/client/scheduler.test.d.ts +2 -0
  39. package/dist/types/core/client/scheduler.test.d.ts.map +1 -0
  40. package/dist/types/core/client/transport.d.ts +56 -0
  41. package/dist/types/core/client/transport.d.ts.map +1 -0
  42. package/dist/types/core/client/transport.test.d.ts +2 -0
  43. package/dist/types/core/client/transport.test.d.ts.map +1 -0
  44. package/dist/types/core/engine/answerAudit.d.ts +21 -0
  45. package/dist/types/core/engine/answerAudit.d.ts.map +1 -0
  46. package/dist/types/core/engine/answerAudit.test.d.ts +2 -0
  47. package/dist/types/core/engine/answerAudit.test.d.ts.map +1 -0
  48. package/dist/types/core/engine/answerStates.contract.test.d.ts +2 -0
  49. package/dist/types/core/engine/answerStates.contract.test.d.ts.map +1 -0
  50. package/dist/types/core/engine/answerStates.d.ts +92 -0
  51. package/dist/types/core/engine/answerStates.d.ts.map +1 -0
  52. package/dist/types/core/engine/formEngine.d.ts +145 -0
  53. package/dist/types/core/engine/formEngine.d.ts.map +1 -0
  54. package/dist/types/core/engine/formEngine.test.d.ts +2 -0
  55. package/dist/types/core/engine/formEngine.test.d.ts.map +1 -0
  56. package/dist/types/core/engine/redirect.d.ts +36 -0
  57. package/dist/types/core/engine/redirect.d.ts.map +1 -0
  58. package/dist/types/core/engine/redirect.test.d.ts +2 -0
  59. package/dist/types/core/engine/redirect.test.d.ts.map +1 -0
  60. package/dist/types/core/engine/responsePayload.contract.test.d.ts +2 -0
  61. package/dist/types/core/engine/responsePayload.contract.test.d.ts.map +1 -0
  62. package/dist/types/core/engine/responsePayload.d.ts +74 -0
  63. package/dist/types/core/engine/responsePayload.d.ts.map +1 -0
  64. package/dist/types/core/engine/responsePayload.test.d.ts +2 -0
  65. package/dist/types/core/engine/responsePayload.test.d.ts.map +1 -0
  66. package/dist/types/core/engine/urlData.contract.test.d.ts +2 -0
  67. package/dist/types/core/engine/urlData.contract.test.d.ts.map +1 -0
  68. package/dist/types/core/engine/urlData.d.ts +30 -0
  69. package/dist/types/core/engine/urlData.d.ts.map +1 -0
  70. package/dist/types/core/engine/urlData.test.d.ts +2 -0
  71. package/dist/types/core/engine/urlData.test.d.ts.map +1 -0
  72. package/dist/types/core/engine/urlPrefill.d.ts +21 -0
  73. package/dist/types/core/engine/urlPrefill.d.ts.map +1 -0
  74. package/dist/types/core/engine/urlPrefill.test.d.ts +2 -0
  75. package/dist/types/core/engine/urlPrefill.test.d.ts.map +1 -0
  76. package/dist/types/core/events/dropoffDetection.d.ts +21 -0
  77. package/dist/types/core/events/dropoffDetection.d.ts.map +1 -0
  78. package/dist/types/core/events/dropoffDetection.test.d.ts +2 -0
  79. package/dist/types/core/events/dropoffDetection.test.d.ts.map +1 -0
  80. package/dist/types/core/events/emitter.d.ts +23 -0
  81. package/dist/types/core/events/emitter.d.ts.map +1 -0
  82. package/dist/types/core/events/emitter.test.d.ts +2 -0
  83. package/dist/types/core/events/emitter.test.d.ts.map +1 -0
  84. package/dist/types/core/events/formJourneyTracker.contract.test.d.ts +2 -0
  85. package/dist/types/core/events/formJourneyTracker.contract.test.d.ts.map +1 -0
  86. package/dist/types/core/events/formJourneyTracker.d.ts +69 -0
  87. package/dist/types/core/events/formJourneyTracker.d.ts.map +1 -0
  88. package/dist/types/core/events/formJourneyTracker.test.d.ts +2 -0
  89. package/dist/types/core/events/formJourneyTracker.test.d.ts.map +1 -0
  90. package/dist/types/core/events/pushEvents.contract.test.d.ts +2 -0
  91. package/dist/types/core/events/pushEvents.contract.test.d.ts.map +1 -0
  92. package/dist/types/core/events/pushEvents.d.ts +62 -0
  93. package/dist/types/core/events/pushEvents.d.ts.map +1 -0
  94. package/dist/types/core/events/pushEvents.test.d.ts +2 -0
  95. package/dist/types/core/events/pushEvents.test.d.ts.map +1 -0
  96. package/dist/types/core/events/startedDetection.d.ts +11 -0
  97. package/dist/types/core/events/startedDetection.d.ts.map +1 -0
  98. package/dist/types/core/events/startedDetection.test.d.ts +2 -0
  99. package/dist/types/core/events/startedDetection.test.d.ts.map +1 -0
  100. package/dist/types/core/events/viewDetection.d.ts +15 -0
  101. package/dist/types/core/events/viewDetection.d.ts.map +1 -0
  102. package/dist/types/core/events/viewDetection.test.d.ts +2 -0
  103. package/dist/types/core/events/viewDetection.test.d.ts.map +1 -0
  104. package/dist/types/core/identity/browserFingerprint.d.ts +40 -0
  105. package/dist/types/core/identity/browserFingerprint.d.ts.map +1 -0
  106. package/dist/types/core/identity/browserFingerprint.test.d.ts +2 -0
  107. package/dist/types/core/identity/browserFingerprint.test.d.ts.map +1 -0
  108. package/dist/types/core/identity/ensureIdentified.d.ts +27 -0
  109. package/dist/types/core/identity/ensureIdentified.d.ts.map +1 -0
  110. package/dist/types/core/identity/ensureIdentified.test.d.ts +2 -0
  111. package/dist/types/core/identity/ensureIdentified.test.d.ts.map +1 -0
  112. package/dist/types/core/identity/identify.contract.test.d.ts +2 -0
  113. package/dist/types/core/identity/identify.contract.test.d.ts.map +1 -0
  114. package/dist/types/core/identity/identify.d.ts +48 -0
  115. package/dist/types/core/identity/identify.d.ts.map +1 -0
  116. package/dist/types/core/identity/identify.test.d.ts +2 -0
  117. package/dist/types/core/identity/identify.test.d.ts.map +1 -0
  118. package/dist/types/core/identity/journey.contract.test.d.ts +2 -0
  119. package/dist/types/core/identity/journey.contract.test.d.ts.map +1 -0
  120. package/dist/types/core/identity/journey.d.ts +28 -0
  121. package/dist/types/core/identity/journey.d.ts.map +1 -0
  122. package/dist/types/core/identity/journey.test.d.ts +2 -0
  123. package/dist/types/core/identity/journey.test.d.ts.map +1 -0
  124. package/dist/types/core/identity/journey.testStubs.d.ts +5 -0
  125. package/dist/types/core/identity/journey.testStubs.d.ts.map +1 -0
  126. package/dist/types/core/identity/leadDataCache.d.ts +27 -0
  127. package/dist/types/core/identity/leadDataCache.d.ts.map +1 -0
  128. package/dist/types/core/identity/leadDataCache.test.d.ts +2 -0
  129. package/dist/types/core/identity/leadDataCache.test.d.ts.map +1 -0
  130. package/dist/types/enrichment/attachEnrichment.d.ts +35 -0
  131. package/dist/types/enrichment/attachEnrichment.d.ts.map +1 -0
  132. package/dist/types/enrichment/attachEnrichment.test.d.ts +2 -0
  133. package/dist/types/enrichment/attachEnrichment.test.d.ts.map +1 -0
  134. package/dist/types/index.d.ts +28 -0
  135. package/dist/types/index.d.ts.map +1 -0
  136. package/dist/types/react/index.d.ts +2 -0
  137. package/dist/types/react/index.d.ts.map +1 -0
  138. package/dist/types/react/ssr.test.d.ts +2 -0
  139. package/dist/types/react/ssr.test.d.ts.map +1 -0
  140. package/dist/types/react/useSurfaceForm.d.ts +25 -0
  141. package/dist/types/react/useSurfaceForm.d.ts.map +1 -0
  142. package/dist/types/react/useSurfaceForm.test.d.ts +2 -0
  143. package/dist/types/react/useSurfaceForm.test.d.ts.map +1 -0
  144. package/dist/types/surfaceForms.d.ts +120 -0
  145. package/dist/types/surfaceForms.d.ts.map +1 -0
  146. package/dist/types/surfaceForms.test.d.ts +2 -0
  147. package/dist/types/surfaceForms.test.d.ts.map +1 -0
  148. package/dist/types/tracking/attachTracking.d.ts +35 -0
  149. package/dist/types/tracking/attachTracking.d.ts.map +1 -0
  150. package/dist/types/tracking/attachTracking.test.d.ts +2 -0
  151. package/dist/types/tracking/attachTracking.test.d.ts.map +1 -0
  152. package/dist/types/tracking/conversionRules.contract.test.d.ts +2 -0
  153. package/dist/types/tracking/conversionRules.contract.test.d.ts.map +1 -0
  154. package/dist/types/tracking/conversionRules.d.ts +87 -0
  155. package/dist/types/tracking/conversionRules.d.ts.map +1 -0
  156. package/dist/types/tracking/conversionRules.test.d.ts +2 -0
  157. package/dist/types/tracking/conversionRules.test.d.ts.map +1 -0
  158. package/dist/types/tracking/vendors.d.ts +46 -0
  159. package/dist/types/tracking/vendors.d.ts.map +1 -0
  160. package/dist/types/tracking/vendors.test.d.ts +2 -0
  161. package/dist/types/tracking/vendors.test.d.ts.map +1 -0
  162. package/dist/types/validation/attachEmailValidation.d.ts +8 -0
  163. package/dist/types/validation/attachEmailValidation.d.ts.map +1 -0
  164. package/dist/types/validation/attachEmailValidation.test.d.ts +2 -0
  165. package/dist/types/validation/attachEmailValidation.test.d.ts.map +1 -0
  166. package/docs/api.md +310 -0
  167. package/docs/reference/binding.md +116 -0
  168. package/docs/reference/clients.md +212 -0
  169. package/docs/reference/engine.md +193 -0
  170. package/docs/reference/events.md +93 -0
  171. package/docs/reference/identity.md +116 -0
  172. package/llms.txt +317 -0
  173. package/package.json +25 -0
  174. package/skills/surface-forms-sdk/SKILL.md +153 -0
  175. package/skills/surface-forms-sdk/debugging.md +64 -0
  176. package/skills/surface-forms-sdk/editing.md +67 -0
  177. package/skills/surface-forms-sdk/patterns.md +222 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answerStates.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/answerStates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAC/E,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;I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eAAe,EACf,aAAa,EACb,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,mBAAmB,CACX,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC;AAE3G,gHAAgH;AAChH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,gBAAgB,GAAG,kBAAkB,CAAC;IAC5C,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,eAAe,GACf,eAAe,GACf,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,cAAc,GACd,oBAAoB,GACpB,oBAAoB,GACpB,gCAAgC,GAChC,kBAAkB,GAClB,eAAe,CAAC"}
@@ -0,0 +1,145 @@
1
+ import type { Transport } from "../client/transport";
2
+ import { type Unsubscribe } from "../events/emitter";
3
+ import type { FormJourneyTracker, FormJourneyTransitionReason } from "../events/formJourneyTracker";
4
+ import { type PushEventClient } from "../events/pushEvents";
5
+ import { type AnswerStates, type ExternalStates } from "./responsePayload";
6
+ /**
7
+ * The headless step engine (forms-sdk-plan.md §2.2): answers, traversal,
8
+ * response writes, and lifecycle events over the modules this stack built.
9
+ * Native semantics preserved:
10
+ *
11
+ * - **Partial saves on forward step change only** (row 23): first forward
12
+ * move creates the response, later moves update it, and every write sends
13
+ * the id of the step being *left* — all gated by
14
+ * `settings.trackPartialResponses` except the finishing write, which always
15
+ * happens.
16
+ * - **Finished/invalid derivation** (row 27): a resolved next step of
17
+ * `"END"`/`"INVALID"`/`undefined` finishes the form; `"INVALID"`
18
+ * disqualifies.
19
+ * - **Step transition events** (row 31): the `form_step_submitted` +
20
+ * `form_step_viewed` batch with `stepCompletionTime` in seconds since the
21
+ * engine was created (native's `initialRenderTime`), skipped when the form
22
+ * finishes (native returns before emitting on `"END"`).
23
+ * - `markViewed` mirrors native's view actions: `form_viewed` + first-step
24
+ * `form_step_viewed`, once.
25
+ * - Backward navigation never writes (native only re-arms `stepIdToSubmit`).
26
+ *
27
+ * **The engine does not evaluate routing** (Decisions #6): the customer's own
28
+ * code owns navigation. `next()`/`back()` are linear conveniences,
29
+ * `goToStep()` is the explicit move — forward jumps carry full forward
30
+ * semantics (step events, journey transition, partial write), jumps to an
31
+ * already-visited step rewind like `back()` (no write). Disqualification is
32
+ * the explicit `disqualify()` verb — in native it was a routing outcome (the
33
+ * `INVALID` sentinel), so without routing it needs its own API. The pluggable
34
+ * `resolveNextStep` remains as the headless hook for callers who express
35
+ * their routing as a resolver instead of imperative `goToStep` calls.
36
+ */
37
+ export type ResolvedNextStep = {
38
+ stepId: string;
39
+ reason?: FormJourneyTransitionReason;
40
+ };
41
+ export type ResolveNextStep = (currentStepId: string, answers: AnswerStates) => ResolvedNextStep | "END" | "INVALID";
42
+ export type FormEngineEvents = {
43
+ viewed: {
44
+ formId: string;
45
+ };
46
+ started: {
47
+ formId: string;
48
+ };
49
+ stepChanged: {
50
+ fromStepId: string;
51
+ toStepId: string;
52
+ };
53
+ stepCompleted: {
54
+ stepId: string;
55
+ };
56
+ completed: {
57
+ formId: string;
58
+ };
59
+ disqualified: {
60
+ stepId: string;
61
+ };
62
+ saved: {
63
+ responseId: string;
64
+ finished: boolean;
65
+ resumeToken: string | null;
66
+ };
67
+ error: {
68
+ scope: "submit";
69
+ error: unknown;
70
+ };
71
+ };
72
+ export type FormEngineState = {
73
+ currentStepId: string;
74
+ answers: AnswerStates;
75
+ /** Pseudo-answer states riding every write (URL_DATA attribution, enrichment results, …). */
76
+ externalStates: ExternalStates;
77
+ responseId: string | null;
78
+ /** From the create reply; with the responseId it authorizes a later resume (persist both). */
79
+ resumeToken: string | null;
80
+ finished: boolean;
81
+ };
82
+ export type FormEngine = {
83
+ setAnswer: (questionId: string, state: Record<string, unknown>) => void;
84
+ /** Writes a pseudo-answer external state (enrichment results, custom attribution) that rides every subsequent save. */
85
+ setExternalState: (id: string, state: {
86
+ type: string;
87
+ } & Record<string, unknown>) => void;
88
+ /** Merges keys into the response `meta` object carried by every subsequent save (post-finish it amends the stored response). */
89
+ mergeMeta: (partial: Record<string, unknown>) => void;
90
+ next: () => Promise<void>;
91
+ back: () => void;
92
+ /** Customer-owned navigation (Decisions #6): forward jumps save like next(), visited-step jumps rewind like back(). */
93
+ goToStep: (stepId: string) => Promise<void>;
94
+ submit: () => Promise<void>;
95
+ /** Finishes the form as disqualified (`invalidResponse: true`) — the explicit replacement for native's INVALID routing outcome. */
96
+ disqualify: () => Promise<void>;
97
+ savePartial: () => Promise<void>;
98
+ /** Resolves when every write queued so far has settled — await it before tearing the page down (test harnesses, SPA unmounts). */
99
+ flush: () => Promise<void>;
100
+ markViewed: () => void;
101
+ on: <K extends keyof FormEngineEvents>(event: K, handler: (payload: FormEngineEvents[K]) => void) => Unsubscribe;
102
+ state: () => FormEngineState;
103
+ subscribe: (listener: () => void) => Unsubscribe;
104
+ };
105
+ export declare const createFormEngine: ({ formId, environmentId, steps, transport, resolveNextStep, trackPartialResponses, trackCookies, externalStates, meta, identity, pushEvents, formJourney, preview, resume, }: {
106
+ formId: string;
107
+ environmentId?: string;
108
+ /** Ordered logical steps of the form record (the data contract). */
109
+ steps: Array<{
110
+ id: string;
111
+ endStepKind?: "thank_you" | "disqualified";
112
+ }>;
113
+ transport: Transport;
114
+ resolveNextStep?: ResolveNextStep;
115
+ trackPartialResponses?: boolean;
116
+ trackCookies?: boolean;
117
+ externalStates?: ExternalStates;
118
+ meta?: Record<string, unknown>;
119
+ /**
120
+ * Read at every write/event, not captured at construction — a re-identify
121
+ * (SurfaceForm.identify after cache expiry) must attribute subsequent
122
+ * responses and events to the current visitor, not the boot-time one.
123
+ */
124
+ identity?: () => {
125
+ fingerprint?: string;
126
+ leadSessionId?: string;
127
+ leadId?: string;
128
+ };
129
+ pushEvents?: PushEventClient;
130
+ formJourney?: FormJourneyTracker;
131
+ /** Preview mode never writes (§2.2): traversal and events run, responses are never created. */
132
+ preview?: boolean;
133
+ /**
134
+ * Resume a stored response (row 28): the seeded responseId turns every write
135
+ * into an update (no duplicate row), and the seeded answers ride along in
136
+ * the full-answer-set resend. Answers are keyed by questionId and seeded
137
+ * under the first step — the wire flattens steps, and presentation (which
138
+ * step to show) is the caller's own navigation.
139
+ */
140
+ resume?: {
141
+ responseId: string;
142
+ answers?: Record<string, Record<string, unknown>>;
143
+ };
144
+ }) => FormEngine;
145
+ //# sourceMappingURL=formEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formEngine.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/formEngine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AACpG,OAAO,EAAiC,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE3F,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IA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,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,GAAG,cAAc,CAAA;KAAE,CAAC,CAAC;IACzE,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAE,CAAC;CACpF,KAAG,UAgYH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=formEngine.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formEngine.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/formEngine.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Redirect handling (forms-sdk-plan.md rows 17/48), mirroring form-render's
3
+ * `handleRedirect.ts`:
4
+ *
5
+ * - Identity handoff: `leadId` and `sessionId` are appended as query params so
6
+ * the destination page's tag/SDK resolves the same visitor (row 17).
7
+ * - Protocol default matches `addProtocolToUrl` verbatim, including its quirk:
8
+ * the check is `startsWith("https")`, so an explicit `http://` URL gets
9
+ * double-prefixed. Replicated, not fixed — it's on the plan's
10
+ * replicate-then-review list territory (Phase 0 item 5); the parity harness
11
+ * compares against native.
12
+ * - Unparseable URLs pass through unchanged, blank URLs redirect nowhere.
13
+ * - `CurrentWindow` navigates `window.location` — the SDK runs first-party,
14
+ * which is exactly what native's `window.parent.location` resolves to on a
15
+ * top-level page. `NewTab` opens `_blank`.
16
+ * - Preview never navigates (native gates on preview/editing screens).
17
+ *
18
+ * The step engine owns *when* to redirect (per-step + thank-you triggers and
19
+ * the `redirectTimeout ?? 400 ms` delay — the default is exported here);
20
+ * parent-param forwarding via `redirectUrlParams` templating lands with the
21
+ * external-state store work (row 56).
22
+ */
23
+ export type RedirectType = "NewTab" | "CurrentWindow";
24
+ export declare const DEFAULT_REDIRECT_TIMEOUT_MS = 400;
25
+ export declare const buildRedirectUrl: (url: string, { leadId, sessionId }?: {
26
+ leadId?: string;
27
+ sessionId?: string;
28
+ }) => string;
29
+ export declare const performRedirect: ({ url, redirectType, leadId, sessionId, preview, }: {
30
+ url: string;
31
+ redirectType?: RedirectType;
32
+ leadId?: string;
33
+ sessionId?: string;
34
+ preview?: boolean;
35
+ }) => void;
36
+ //# sourceMappingURL=redirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/redirect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEtD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAQ/C,eAAO,MAAM,gBAAgB,QACtB,MAAM,0BACY;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7D,MAUF,CAAC;AAEF,eAAO,MAAM,eAAe,uDAMzB;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,KAAG,IAaH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=redirect.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/redirect.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=responsePayload.contract.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responsePayload.contract.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/responsePayload.contract.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Response payload builders (forms-sdk-plan.md rows 24-26), mirroring
3
+ * form-render's `createResponseApiPayload` exactly — the semantics here are
4
+ * load-bearing server contracts:
5
+ *
6
+ * - **Full answer-set resend on every write** (row 26): all steps' answers
7
+ * plus every external-state entry as a pseudo-answer keyed by its stateId.
8
+ * Server-side UTM preservation depends on the URL_DATA entry riding every
9
+ * update.
10
+ * - `SCHEDULER_AVAILABILITY_DATA` entries are transient client-only data and
11
+ * are never persisted.
12
+ * - Surface-native booking detection: the first answer with
13
+ * `eventScheduled: true` and a non-Calendly/Cal.com `uri` stamps
14
+ * `meta.bookingId`.
15
+ * - `enrichedFields` precedence: person-attribute enrichment wins over the
16
+ * processed APOLLO_EMAIL_ENRICHMENT external state, `{}` as the floor.
17
+ * - `meta.cookies` is stripped when `trackCookies` is off.
18
+ * - Creates pin `responseShapeVersion: "2.0"`; updates carry `responseId`.
19
+ *
20
+ * Types are local structural mirrors of `ZFormResponseData` /
21
+ * `ZFormUpdateResponseData` (zero-runtime-deps); the contract test validates
22
+ * built payloads against the real schemas. Answer/external-state entry shapes
23
+ * are pass-through records — component state shapes belong to the engine.
24
+ */
25
+ export type SingleFormResponse = {
26
+ questionId: string;
27
+ response: Record<string, unknown>;
28
+ };
29
+ /** Answers grouped per step, keyed stepId → questionId → component state. */
30
+ export type AnswerStates = Record<string, Record<string, Record<string, unknown>>>;
31
+ /** External state entries keyed by stateId; `type` discriminates (URL_DATA, enrichment, …). */
32
+ export type ExternalStates = Record<string, {
33
+ type: string;
34
+ } & Record<string, unknown>>;
35
+ export type FormResponsePayload = {
36
+ formId: string;
37
+ responses: SingleFormResponse[];
38
+ enrichedFields: Record<string, unknown>;
39
+ finished: boolean;
40
+ invalidResponse: boolean;
41
+ stepId: string;
42
+ fingerprint?: string;
43
+ leadSessionId?: string;
44
+ meta: Record<string, unknown>;
45
+ responseShapeVersion: "2.0";
46
+ };
47
+ export type FormUpdateResponsePayload = Omit<FormResponsePayload, "responseShapeVersion"> & {
48
+ responseId: string;
49
+ };
50
+ export declare const buildResponsesArray: (answers: AnswerStates, externalStates: ExternalStates) => {
51
+ responses: SingleFormResponse[];
52
+ enrichedFields: Record<string, unknown>;
53
+ bookingId?: string;
54
+ };
55
+ type BuildPayloadOptions = {
56
+ formId: string;
57
+ answers: AnswerStates;
58
+ externalStates: ExternalStates;
59
+ submittingOnStepId: string;
60
+ finished: boolean;
61
+ invalidResponse: boolean;
62
+ trackCookies: boolean;
63
+ meta?: Record<string, unknown>;
64
+ /** Person-attribute enrichment; wins over external-state enrichment like native. */
65
+ personAttributeEnrichedFields?: Record<string, unknown>;
66
+ fingerprint?: string;
67
+ leadSessionId?: string;
68
+ };
69
+ export declare const createSubmitResponsePayload: (options: BuildPayloadOptions) => FormResponsePayload;
70
+ export declare const createUpdateResponsePayload: (options: BuildPayloadOptions & {
71
+ responseId: string;
72
+ }) => FormUpdateResponsePayload;
73
+ export {};
74
+ //# sourceMappingURL=responsePayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responsePayload.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/responsePayload.ts"],"names":[],"mappings":"AAA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G,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC;IACtB,cAAc,EAAE,cAAc,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,oFAAoF;IACpF,6BAA6B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAkCF,eAAO,MAAM,2BAA2B,YAAa,mBAAmB,KAAG,mBAGzE,CAAC;AAEH,eAAO,MAAM,2BAA2B,YAC7B,mBAAmB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,KACpD,yBAGD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=responsePayload.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responsePayload.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/responsePayload.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=urlData.contract.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlData.contract.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/urlData.contract.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Attribution capture (forms-sdk-plan.md row 56): the `URL_DATA`
3
+ * external-state entry that rides every response write and feeds UTM/source
4
+ * attribution. Mirrors the URL-config branch of form-render's
5
+ * `buildExternalStateStore` — same shape (`fullUrl`/`params`/`referrer`/
6
+ * `cookies`, wire-validated against `ZURLData` in the contract test), same
7
+ * `defaultUrl` precedence, same swallow-on-malformed behavior.
8
+ *
9
+ * One structural simplification the self-hosted model earns (plan §4.1): the
10
+ * SDK runs in the page it measures, so `fullUrl`/`referrer`/`cookies` are
11
+ * read directly from `location`/`document` — native needs them relayed
12
+ * through `?url=`/`?referrer=`/`?cookies=` query params by the tag, including
13
+ * cookies as a JSON blob. Cookie capture stays gated by the same
14
+ * `trackCookies` setting.
15
+ */
16
+ export type UrlData = {
17
+ type: "URL_DATA";
18
+ fullUrl?: string;
19
+ params?: Record<string, string>;
20
+ referrer?: string;
21
+ cookies?: Record<string, string>;
22
+ };
23
+ export declare const constructUrlParamsObject: (url: string) => Record<string, string>;
24
+ export declare const parseCookiesObject: (cookieString: string) => Record<string, string>;
25
+ export declare const buildUrlData: ({ defaultUrl, trackCookies, }?: {
26
+ /** Config-pinned URL that wins over the live page URL, like native. */
27
+ defaultUrl?: string;
28
+ trackCookies?: boolean;
29
+ }) => UrlData;
30
+ //# sourceMappingURL=urlData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlData.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/urlData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAS,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAQ3E,CAAC;AAEF,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAc9E,CAAC;AAEF,eAAO,MAAM,YAAY,mCAGtB;IACD,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,KAAQ,OAwBR,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=urlData.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlData.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/urlData.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * URL prefill parsing (forms-sdk-plan.md row 19), same syntax as the native
3
+ * runtime's `useFormUrlParameters`/`parseQuestionId`: any
4
+ * `?<questionId>_<fieldName>=value` query param prefills a field. The param
5
+ * name splits on the FIRST underscore (field names may contain more), both
6
+ * sides are trimmed, `url`/`referrer`/`cookies` are reserved for attribution,
7
+ * and params without an underscore are ignored (no field to target).
8
+ */
9
+ export type ParsedUrlQuestionId = {
10
+ originalId: string;
11
+ questionId: string;
12
+ fieldName: string;
13
+ value: string;
14
+ };
15
+ export declare const parseQuestionId: (input: string) => {
16
+ originalId: string;
17
+ questionId: string;
18
+ fieldName: string | null;
19
+ };
20
+ export declare const parsePrefillParams: (search: string | URLSearchParams) => Record<string, ParsedUrlQuestionId[]> | null;
21
+ //# sourceMappingURL=urlPrefill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlPrefill.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/urlPrefill.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,MAAM;IAGzC,UAAU;IACV,UAAU;IACV,SAAS;CAEZ,CAAC;AAIF,eAAO,MAAM,kBAAkB,WACrB,MAAM,GAAG,eAAe,KAC/B,MAAM,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,GAAG,IAqB1C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=urlPrefill.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlPrefill.test.d.ts","sourceRoot":"","sources":["../../../../src/core/engine/urlPrefill.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { PushEventClient } from "./pushEvents";
2
+ /**
3
+ * `form_step_dropoff` beacon (forms-sdk-plan.md row 32), form-render's
4
+ * `useBeforeUnload` semantics without React: on `pagehide` — the only
5
+ * teardown event that still delivers beacons reliably — emit the drop-off
6
+ * event for the step the visitor abandoned, but only after the form was
7
+ * started and never for bfcache suspensions (`event.persisted`), which are
8
+ * not abandonment.
9
+ *
10
+ * State is read through a getter at fire time because the current step and
11
+ * session change after the listener attaches (native reads refs for the same
12
+ * reason). Delivery rides the pushEvent client, whose transport is
13
+ * sendBeacon-first — the property that makes a pagehide send survivable.
14
+ */
15
+ export declare const observeDropoff: (pushEventClient: PushEventClient, getState: () => {
16
+ started: boolean;
17
+ formId: string;
18
+ stepId: string;
19
+ sessionId?: string;
20
+ }) => (() => void);
21
+ //# sourceMappingURL=dropoffDetection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropoffDetection.d.ts","sourceRoot":"","sources":["../../../../src/core/events/dropoffDetection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,oBACR,eAAe,YACtB,MAAM;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,KACA,CAAC,MAAM,IAAI,CAkBb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dropoffDetection.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropoffDetection.test.d.ts","sourceRoot":"","sources":["../../../../src/core/events/dropoffDetection.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Instance-scoped typed event emitter — the primitive behind the SDK's
3
+ * public `form.on(...)` lifecycle surface (forms-sdk-plan.md §2.2) and the
4
+ * store-subscription contract adapters build on (§2.9).
5
+ *
6
+ * Exists because the SDK cannot use Node's EventEmitter (zero runtime deps,
7
+ * browser bundle) and must not reproduce form-render's module-level
8
+ * singleton listeners, which break multi-form pages (§2.7). Handler
9
+ * exceptions are isolated per handler: a throwing host callback never breaks
10
+ * the engine or sibling handlers — the never-break-the-host-page guarantee
11
+ * applied to the callback boundary.
12
+ *
13
+ * The concrete SDK event map (viewed/started/stepChanged/…) is owned by the
14
+ * step engine, which defines the payload shapes it emits; this module is
15
+ * deliberately payload-agnostic.
16
+ */
17
+ export type Unsubscribe = () => void;
18
+ export type Emitter<TEventMap extends Record<string, unknown>> = {
19
+ on: <K extends keyof TEventMap>(event: K, handler: (payload: TEventMap[K]) => void) => Unsubscribe;
20
+ emit: <K extends keyof TEventMap>(event: K, payload: TEventMap[K]) => void;
21
+ };
22
+ export declare const createEmitter: <TEventMap extends Record<string, unknown>>() => Emitter<TEventMap>;
23
+ //# sourceMappingURL=emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../../../../src/core/events/emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,MAAM,OAAO,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC/D,EAAE,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,WAAW,CAAC;IACnG,IAAI,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC5E,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAK,OAAO,CAAC,SAAS,CAsB5F,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=emitter.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.test.d.ts","sourceRoot":"","sources":["../../../../src/core/events/emitter.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=formJourneyTracker.contract.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formJourneyTracker.contract.test.d.ts","sourceRoot":"","sources":["../../../../src/core/events/formJourneyTracker.contract.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,69 @@
1
+ import type { Transport } from "../client/transport";
2
+ /**
3
+ * Form-journey step telemetry (forms-sdk-plan.md row 30): visits, transitions,
4
+ * and outcomes beaconed to `POST /api/v1/form-journey/track`. A direct port of
5
+ * form-render's `createFormJourneyTracker` — same ordinal bookkeeping, same
6
+ * close-previous-visit timing, same 50-visit cap with `truncated`, same
7
+ * freeze-on-terminal-outcome, same microtask coalescing (a transition
8
+ * immediately followed by a terminal sends one beacon, so an in-progress
9
+ * write can't race the disqualified one), and the same synchronous flush for
10
+ * the `in_progress` terminal, which only fires from pagehide and cannot
11
+ * depend on a microtask racing page teardown.
12
+ *
13
+ * Wire types are local structural mirrors of the Zod schemas in
14
+ * `@surface/types/v1/formJourney` (zero-runtime-deps); the contract test
15
+ * validates them against the real `ZFormJourneyTrackPayload`. The
16
+ * `transitionMeta`/`matched` payloads are typed opaque here — they are
17
+ * constructed by routing evaluation, which lands with the routing extraction,
18
+ * and the tracker only passes them through.
19
+ */
20
+ export type FormJourneyOutcome = "in_progress" | "completed" | "partial" | "disqualified" | "dropped_off";
21
+ export type FormJourneyTransitionReason = "initial" | "linear" | "conditional_match" | "default_fallback" | "prefill_jump" | "back_nav" | "auto_skip";
22
+ export type FormJourneyVisit = {
23
+ ordinal: number;
24
+ stepId: string;
25
+ enteredAt: string;
26
+ exitedAt?: string | null;
27
+ durationMs?: number | null;
28
+ fromStepId?: string | null;
29
+ transitionReason: FormJourneyTransitionReason;
30
+ transitionMeta?: unknown;
31
+ };
32
+ export type FormJourneyTrackPayload = {
33
+ responseId: string;
34
+ formId: string;
35
+ outcome?: FormJourneyOutcome;
36
+ disqualification?: {
37
+ reason: "conditional_match" | "default_fallback";
38
+ matched?: unknown;
39
+ } | null;
40
+ disqualifiedAtStepId?: string | null;
41
+ disqualifiedTriggerStepId?: string | null;
42
+ events: FormJourneyVisit[];
43
+ };
44
+ export interface FormJourneyTracker {
45
+ recordEntry: (stepId: string) => void;
46
+ recordTransition: (args: {
47
+ fromStepId: string;
48
+ toStepId: string;
49
+ reason: FormJourneyTransitionReason;
50
+ transitionMeta?: unknown;
51
+ }) => void;
52
+ recordTerminal: (args: {
53
+ outcome: FormJourneyOutcome;
54
+ disqualification?: {
55
+ reason: "conditional_match" | "default_fallback";
56
+ atStepId: string;
57
+ triggerStepId?: string;
58
+ matched?: unknown;
59
+ };
60
+ }) => void;
61
+ setResponseId: (responseId: string) => void;
62
+ setFormId: (formId: string) => void;
63
+ hasRecordedTransition: () => boolean;
64
+ }
65
+ export declare const createFormJourneyTracker: ({ transport, preview, }: {
66
+ transport: Transport;
67
+ preview?: boolean;
68
+ }) => FormJourneyTracker;
69
+ //# sourceMappingURL=formJourneyTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formJourneyTracker.d.ts","sourceRoot":"","sources":["../../../../src/core/events/formJourneyTracker.ts"],"names":[],"mappings":"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QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,2BAA2B,CAAC;QACpC,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,KAAK,IAAI,CAAC;IACX,cAAc,EAAE,CAAC,IAAI,EAAE;QACrB,OAAO,EAAE,kBAAkB,CAAC;QAC5B,gBAAgB,CAAC,EAAE;YACjB,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,CAAC;YACjD,QAAQ,EAAE,MAAM,CAAC;YACjB,aAAa,CAAC,EAAE,MAAM,CAAC;YACvB,OAAO,CAAC,EAAE,OAAO,CAAC;SACnB,CAAC;KACH,KAAK,IAAI,CAAC;IACX,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC;AAkCD,eAAO,MAAM,wBAAwB,4BAGlC;IACD,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,KAAG,kBA2HH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=formJourneyTracker.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formJourneyTracker.test.d.ts","sourceRoot":"","sources":["../../../../src/core/events/formJourneyTracker.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pushEvents.contract.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pushEvents.contract.test.d.ts","sourceRoot":"","sources":["../../../../src/core/events/pushEvents.contract.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ import type { Transport } from "../client/transport";
2
+ /**
3
+ * Client for the internal event pipeline `POST /api/v1/pushEvent`
4
+ * (forms-sdk-plan.md row 33), mirroring form-render's `callPushEventApi`:
5
+ * same wire shapes, same client-side bot filter, same required-field guard
6
+ * (any invalid event drops the whole request), same beacon-first delivery.
7
+ * Two deliberate departures, both decided in the plan: no PostHog mirror
8
+ * (Surface-internal telemetry — §1D row 33) and a `preview` flag that blocks
9
+ * every send so agent preview loops never pollute data (§2.2).
10
+ *
11
+ * The wire types below are structural mirrors of the Zod schemas in
12
+ * `@surface/types/v1/surfaceEvent/model/types.ts` — local because the SDK
13
+ * ships with zero runtime dependencies; the contract test in this directory
14
+ * validates them against the real schemas.
15
+ */
16
+ export type SurfaceEventType = "form_viewed" | "form_started" | "form_completed" | "form_step_viewed" | "form_step_submitted" | "form_step_dropoff" | "form_question_submitted" | "response_submission_created" | "response_submission_error" | "script_initiated";
17
+ export type SurfaceEventEntityType = "form" | "form_step" | "response";
18
+ export type PushEventProperty = {
19
+ key: string;
20
+ value: unknown;
21
+ };
22
+ export type PushEventPayload = {
23
+ type: SurfaceEventType;
24
+ entityType: SurfaceEventEntityType;
25
+ entityId: string;
26
+ stepId?: string | null;
27
+ leadSessionId?: string | null;
28
+ properties?: PushEventProperty[];
29
+ leadId?: string;
30
+ environmentId?: string;
31
+ };
32
+ /** The server accepts exactly one batch shape: a step transition pair. */
33
+ export type PushEventBatch = {
34
+ events: [
35
+ PushEventPayload & {
36
+ type: "form_step_submitted";
37
+ entityType: "form_step";
38
+ stepId: string;
39
+ },
40
+ PushEventPayload & {
41
+ type: "form_step_viewed";
42
+ entityType: "form_step";
43
+ stepId: string;
44
+ }
45
+ ];
46
+ };
47
+ export type PushEventRequest = PushEventPayload | PushEventBatch;
48
+ export declare const buildStepTransitionEventBatch: ({ sessionId, formId, currentStepId, nextStepId, stepCompletionTime, }: {
49
+ sessionId: string | undefined;
50
+ formId: string;
51
+ currentStepId: string;
52
+ nextStepId: string;
53
+ stepCompletionTime: number;
54
+ }) => PushEventBatch;
55
+ export type PushEventClient = {
56
+ push: (request: PushEventRequest) => void;
57
+ };
58
+ export declare const createPushEventClient: ({ transport, preview, }: {
59
+ transport: Transport;
60
+ preview?: boolean;
61
+ }) => PushEventClient;
62
+ //# sourceMappingURL=pushEvents.d.ts.map