@nodii/onboarding 0.1.0 → 0.2.0

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 (56) hide show
  1. package/README.md +46 -0
  2. package/dist/{chunk-KQTS47FC.js → chunk-A3DE2IAH.js} +30 -5
  3. package/dist/chunk-A3DE2IAH.js.map +1 -0
  4. package/dist/{chunk-U6AXKGYQ.js → chunk-DWFZA5T6.js} +10 -8
  5. package/dist/chunk-DWFZA5T6.js.map +1 -0
  6. package/dist/{chunk-F75ZJERM.js → chunk-KFHVZGX6.js} +34 -14
  7. package/dist/chunk-KFHVZGX6.js.map +1 -0
  8. package/dist/{chunk-U56GQITG.js → chunk-NDSBIB3N.js} +25 -5
  9. package/dist/chunk-NDSBIB3N.js.map +1 -0
  10. package/dist/chunk-OLWR5COK.js +10 -0
  11. package/dist/chunk-OLWR5COK.js.map +1 -0
  12. package/dist/{chunk-IPAKPLIF.js → chunk-OVULPWNZ.js} +341 -80
  13. package/dist/chunk-OVULPWNZ.js.map +1 -0
  14. package/dist/{chunk-LVJM4CTG.js → chunk-T7EWURTF.js} +34 -19
  15. package/dist/chunk-T7EWURTF.js.map +1 -0
  16. package/dist/{chunk-BMQINH6O.js → chunk-UHOFGWI7.js} +5 -4
  17. package/dist/chunk-UHOFGWI7.js.map +1 -0
  18. package/dist/{chunk-SIMLMQPT.js → chunk-WKN4U7QF.js} +3 -5
  19. package/dist/chunk-WKN4U7QF.js.map +1 -0
  20. package/dist/{chunk-AZE3NPSY.js → chunk-ZR6X3GSM.js} +3 -3
  21. package/dist/{chunk-AZE3NPSY.js.map → chunk-ZR6X3GSM.js.map} +1 -1
  22. package/dist/{client-CqE2dF9A.d.ts → client-NvqPpfQP.d.ts} +1 -1
  23. package/dist/consent/index.d.ts +3 -3
  24. package/dist/consent/index.js +2 -2
  25. package/dist/{controller-BQb62D0N.d.ts → controller-BLH3wnxl.d.ts} +1 -1
  26. package/dist/dynamic/index.d.ts +13 -5
  27. package/dist/dynamic/index.js +4 -3
  28. package/dist/form/index.d.ts +12 -4
  29. package/dist/form/index.js +2 -2
  30. package/dist/{index-Dqfa890U.d.ts → index-BMSbQGWP.d.ts} +23 -3
  31. package/dist/index.d.ts +8 -8
  32. package/dist/index.js +9 -8
  33. package/dist/{model-mnjAEtKe.d.ts → model-BI_I-D_V.d.ts} +16 -2
  34. package/dist/{model-ESLSEbi0.d.ts → model-CEwvHlWA.d.ts} +14 -1
  35. package/dist/render-EWQXF73I.js +5 -0
  36. package/dist/{render-DC7P2BGQ.js.map → render-EWQXF73I.js.map} +1 -1
  37. package/dist/{schema-BrXb9gnh.d.ts → schema-BrtjpXfL.d.ts} +0 -10
  38. package/dist/{signup-client-BL5DfarJ.d.ts → signup-client-CS95nkVO.d.ts} +4 -4
  39. package/dist/spec/index.d.ts +3 -3
  40. package/dist/spec/index.js +2 -2
  41. package/dist/submit/index.d.ts +5 -5
  42. package/dist/submit/index.js +3 -2
  43. package/dist/viewer/index.d.ts +3 -3
  44. package/dist/viewer/index.js +1 -1
  45. package/dist/widget/index.d.ts +61 -22
  46. package/dist/widget/index.js +9 -8
  47. package/package.json +1 -1
  48. package/dist/chunk-BMQINH6O.js.map +0 -1
  49. package/dist/chunk-F75ZJERM.js.map +0 -1
  50. package/dist/chunk-IPAKPLIF.js.map +0 -1
  51. package/dist/chunk-KQTS47FC.js.map +0 -1
  52. package/dist/chunk-LVJM4CTG.js.map +0 -1
  53. package/dist/chunk-SIMLMQPT.js.map +0 -1
  54. package/dist/chunk-U56GQITG.js.map +0 -1
  55. package/dist/chunk-U6AXKGYQ.js.map +0 -1
  56. package/dist/render-DC7P2BGQ.js +0 -5
package/README.md CHANGED
@@ -18,6 +18,52 @@ Subpath exports:
18
18
  - `@nodii/onboarding/widget` — default themeable widgets (contact + signup +
19
19
  consent step)
20
20
 
21
+ ## Embedding the lead (contact) form
22
+
23
+ The contact widget renders the D1165 lead fields. Its choices, labels, the
24
+ privacy-notice link and the bot-challenge siteKey come from the onboarder's
25
+ spec, so fetch it first:
26
+
27
+ ```ts
28
+ import { fetchOnboardingSpec } from "@nodii/onboarding/spec";
29
+ import { mountContactForm } from "@nodii/onboarding/widget";
30
+
31
+ const baseUrl = "https://platform.nucleus-cloud.in"; // the onboarder's intake
32
+ const spec = await fetchOnboardingSpec({ baseUrl, onboarder: "nodii" });
33
+ mountContactForm(document.getElementById("contact")!, {
34
+ onboarder: "nodii",
35
+ baseUrl,
36
+ form: "contact",
37
+ spec,
38
+ intakeKind: "enquiry",
39
+ attribution: { button: "book-a-chat" },
40
+ });
41
+ ```
42
+
43
+ The spec's privacy-notice link is a presigned URL that expires, so an open
44
+ form re-reads the spec every 5 minutes and swaps in the fresh link
45
+ (`specRefreshMs`; 0 turns it off). A `privacyUrl` you pass is never re-read,
46
+ and must be an http(s) URL, absolute or relative: the form refuses to mount
47
+ with anything else.
48
+
49
+ The widget draws a fixed set of fields. Company, contact name and email are
50
+ always required; the spec's `required` flag is honoured for the interest
51
+ choice only; phone, team size and message are optional; the address fields are
52
+ not drawn. To require more, build the form on the headless
53
+ `@nodii/onboarding/form` and `@nodii/onboarding/submit` modules, as the Nodii
54
+ website does.
55
+
56
+ A `scroll_then_accept` PDF renders inline with PDF.js. Its worker loads from
57
+ next to the package when that URL really serves a script; in a bundled page
58
+ (Vite, webpack) it usually doesn't, and the worker comes from jsDelivr instead,
59
+ pinned to the PDF.js version in use. To self-host it, set
60
+ `GlobalWorkerOptions.workerSrc` on `pdfjs-dist` before the first render: the
61
+ viewer leaves a configured worker alone.
62
+
63
+ When the spec carries no `botChallenge` (D1444), no reCAPTCHA script loads and
64
+ no token is sent. The page's origin must be registered for the onboarder
65
+ (the tenant CORS writer) or the browser refuses the intake's responses.
66
+
21
67
  ## Tests
22
68
 
23
69
  ### Fast unit + happy-dom (default)
@@ -1,4 +1,5 @@
1
- import { createConsentController } from './chunk-AZE3NPSY.js';
1
+ import { createConsentController } from './chunk-ZR6X3GSM.js';
2
+ import { isSubdomainLabelShape, SUBDOMAIN_SHAPE_MESSAGE } from './chunk-OLWR5COK.js';
2
3
  import { z } from 'zod/v3';
3
4
 
4
5
  function optionValue(option) {
@@ -146,7 +147,10 @@ var credentialsSchema = z.object({
146
147
  email: z.string().email("A valid account email is required"),
147
148
  displayName: z.string().trim().min(1, "Your name is required").max(200),
148
149
  organisationName: z.string().trim().min(1, "Organisation name is required").max(200),
149
- subdomain: z.string().trim().min(1, "Workspace subdomain is required").max(63)
150
+ subdomain: z.string().trim().min(1, "Workspace subdomain is required").max(63).refine(
151
+ (v) => v === "" || v.length > 63 || isSubdomainLabelShape(v),
152
+ SUBDOMAIN_SHAPE_MESSAGE
153
+ )
150
154
  });
151
155
  function zodIssuesToFieldErrors(issues) {
152
156
  return issues.map((issue) => ({
@@ -190,6 +194,7 @@ function createSignupStepper(spec) {
190
194
  consentErrors: []
191
195
  };
192
196
  let validatedSteps = /* @__PURE__ */ new Set();
197
+ const serverAccountErrorPaths = /* @__PURE__ */ new Set();
193
198
  let consentValidated = false;
194
199
  const listeners = /* @__PURE__ */ new Set();
195
200
  function emit() {
@@ -293,9 +298,14 @@ function createSignupStepper(spec) {
293
298
  emit();
294
299
  },
295
300
  setCredentials(credentials) {
301
+ const previous = state.credentials;
302
+ const cleared = Object.entries(credentials).filter(
303
+ ([k, v]) => v !== previous[k] && serverAccountErrorPaths.delete(k)
304
+ ).map(([k]) => k);
296
305
  state = {
297
306
  ...state,
298
- credentials: { ...state.credentials, ...credentials }
307
+ credentials: { ...state.credentials, ...credentials },
308
+ accountErrors: cleared.length === 0 ? state.accountErrors : state.accountErrors.filter((e) => !cleared.includes(e.path))
299
309
  };
300
310
  emit();
301
311
  },
@@ -348,6 +358,7 @@ function createSignupStepper(spec) {
348
358
  for (let i = 0; i < steps.length; i++) validatedSteps.add(i);
349
359
  const answersResult = deriveAnswersSchema(steps).safeParse(state.answers);
350
360
  const errors = answersResult.success ? [] : zodIssuesToFieldErrors(answersResult.error.issues);
361
+ serverAccountErrorPaths.clear();
351
362
  const accountErrors = [];
352
363
  const credResult = credentialsSchema.safeParse(state.credentials);
353
364
  if (!credResult.success) {
@@ -494,9 +505,23 @@ function createSignupStepper(spec) {
494
505
  state = { ...state, status: "error", serverError: message };
495
506
  emit();
496
507
  },
508
+ setAccountError(path, message) {
509
+ serverAccountErrorPaths.add(path);
510
+ state = {
511
+ ...state,
512
+ status: "editing",
513
+ serverError: null,
514
+ accountErrors: [
515
+ ...state.accountErrors.filter((e) => e.path !== path),
516
+ { path, message }
517
+ ]
518
+ };
519
+ emit();
520
+ },
497
521
  reset() {
498
522
  validatedSteps = /* @__PURE__ */ new Set();
499
523
  consentValidated = false;
524
+ serverAccountErrorPaths.clear();
500
525
  const currentDocs = consentController.getState().documents.map((d) => d.doc);
501
526
  unsubscribeConsent();
502
527
  consentController = createConsentController(
@@ -542,5 +567,5 @@ function createSignupStepper(spec) {
542
567
  }
543
568
 
544
569
  export { createSignupStepper, deriveAnswersSchema, deriveFieldSchema, deriveStepSchema, optionValue };
545
- //# sourceMappingURL=chunk-KQTS47FC.js.map
546
- //# sourceMappingURL=chunk-KQTS47FC.js.map
570
+ //# sourceMappingURL=chunk-A3DE2IAH.js.map
571
+ //# sourceMappingURL=chunk-A3DE2IAH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dynamic/derive.ts","../src/dynamic/stepper.ts"],"names":["z"],"mappings":";;;;AAiCO,SAAS,YAAY,MAAA,EAAyB;AACnD,EAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,QAAA,EAAU;AACjD,IAAA,MAAM,CAAA,GAAI,MAAA;AACV,IAAA,IAAI,WAAW,CAAA,EAAG,OAAO,MAAA,CAAO,CAAA,CAAE,OAAO,CAAC,CAAA;AAC1C,IAAA,IAAI,SAAS,CAAA,EAAG,OAAO,MAAA,CAAO,CAAA,CAAE,KAAK,CAAC,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,OAAO,MAAM,CAAA;AAC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,KAAA,GAAQ;AAAA,QACN,SAAA,EAAW,CAAA;AAAA,QACX,WAAW,KAAA,CAAM,MAAA;AAAA,QACjB,WAAA,EAAa,KAAA,CAAM,CAAC,CAAA,IAAK,IAAA;AAAA,QACzB,SAAS,EAAC;AAAA,QACV,kBAAkB,EAAC;AAAA,QACnB,QAAQ,EAAC;AAAA,QACT,eAAe,EAAC;AAAA,QAChB,OAAA,EAAS,EAAE,WAAA,EAAa,KAAA,EAAO,iBAAiB,KAAA,EAAM;AAAA,QACtD,WAAA,EAAa;AAAA,UACX,KAAA,EAAO,EAAA;AAAA,UACP,WAAA,EAAa,EAAA;AAAA,UACb,gBAAA,EAAkB,EAAA;AAAA,UAClB,SAAA,EAAW;AAAA,SACb;AAAA,QACA,MAAA,EAAQ,SAAA;AAAA,QACR,WAAA,EAAa,IAAA;AAAA,QACb,SAAA,EAAW,KAAA;AAAA,QACX,WAAA;AAAA,QACA,aAAA,EAAe,IAAA;AAAA,QACf,YAAA,EAAc,kBAAkB,QAAA,EAAS;AAAA,QACzC,YAAA,EAAc,KAAA;AAAA,QACd,kBAAkB,EAAC;AAAA,QACnB,eAAe;AAAC,OAClB;AACA,MAAA,IAAA,EAAK;AAAA,IACP,CAAA;AAAA,IAEA,UAAU,QAAA,EAAU;AAClB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AACX,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAC3B,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"chunk-A3DE2IAH.js","sourcesContent":["/**\n * Spec → Zod validator derivation (D540 §3).\n *\n * Turns arbitrary SpecField descriptors from the served spec into Zod\n * schemas for CLIENT-side UX validation. The server re-validates\n * authoritatively (D540 §2) — client validation is a convenience layer,\n * so the derivation is deliberately conservative:\n *\n * - Known `type`s map to typed schemas (see FIELD TYPE MAP below).\n * - An UNKNOWN type falls back to z.string() (never blocks a field the\n * server knows how to validate).\n * - Known `validation` keys are applied (minLength, maxLength, min, max,\n * pattern, format:\"email\"). Unknown validation keys are IGNORED\n * client-side — the server enforces them.\n * - `required:false` fields accept undefined AND \"\" (an empty input is\n * \"not provided\").\n * - select/radio values must be one of `options`; multiselect values\n * must be a subset.\n *\n * FIELD TYPE MAP:\n * text | textarea | tel | (unknown) → string\n * email → string().email()\n * number → coerce.number (DOM inputs are strings)\n * checkbox | boolean → boolean\n * select | radio → string ∈ options\n * multiselect → string[] ⊆ options\n * date → string, parseable as a date\n */\n\nimport { z } from \"zod/v3\";\nimport type { SpecField, SpecStep } from \"../spec/model.js\";\n\n/** Extract the comparable value of an option entry ({value}, {key}, or scalar). */\nexport function optionValue(option: unknown): string {\n if (option !== null && typeof option === \"object\") {\n const o = option as Record<string, unknown>;\n if (\"value\" in o) return String(o[\"value\"]);\n if (\"key\" in o) return String(o[\"key\"]);\n }\n return String(option);\n}\n\ninterface KnownValidation {\n minLength?: number;\n maxLength?: number;\n min?: number;\n max?: number;\n pattern?: string;\n format?: string;\n}\n\nfunction knownValidation(field: SpecField): KnownValidation {\n const v = field.validation ?? {};\n const out: KnownValidation = {};\n if (typeof v[\"minLength\"] === \"number\") out.minLength = v[\"minLength\"];\n if (typeof v[\"maxLength\"] === \"number\") out.maxLength = v[\"maxLength\"];\n if (typeof v[\"min\"] === \"number\") out.min = v[\"min\"];\n if (typeof v[\"max\"] === \"number\") out.max = v[\"max\"];\n if (typeof v[\"pattern\"] === \"string\") out.pattern = v[\"pattern\"];\n if (typeof v[\"format\"] === \"string\") out.format = v[\"format\"];\n return out;\n}\n\nfunction stringSchema(field: SpecField): z.ZodTypeAny {\n const v = knownValidation(field);\n let s = z.string();\n if (field.type === \"email\" || v.format === \"email\") {\n s = s.email(`${field.label} must be a valid email`);\n }\n if (v.minLength !== undefined) {\n s = s.min(\n v.minLength,\n `${field.label} must be at least ${v.minLength} characters`,\n );\n }\n if (v.maxLength !== undefined) {\n s = s.max(\n v.maxLength,\n `${field.label} must be at most ${v.maxLength} characters`,\n );\n }\n if (v.pattern !== undefined) {\n try {\n s = s.regex(\n new RegExp(v.pattern),\n `${field.label} has an invalid format`,\n );\n } catch {\n // Invalid regex in the spec — skip client-side; server enforces.\n }\n }\n return s;\n}\n\nfunction numberSchema(field: SpecField): z.ZodTypeAny {\n const v = knownValidation(field);\n let s = z.coerce.number({\n invalid_type_error: `${field.label} must be a number`,\n });\n if (v.min !== undefined) {\n s = s.min(v.min, `${field.label} must be at least ${v.min}`);\n }\n if (v.max !== undefined) {\n s = s.max(v.max, `${field.label} must be at most ${v.max}`);\n }\n return s;\n}\n\nfunction enumSchema(field: SpecField): z.ZodTypeAny {\n const allowed = (field.options ?? []).map(optionValue);\n if (allowed.length === 0) return z.string();\n return z.string().refine((val) => allowed.includes(val), {\n message: `${field.label} must be one of the offered options`,\n });\n}\n\nfunction multiEnumSchema(field: SpecField): z.ZodTypeAny {\n const allowed = (field.options ?? []).map(optionValue);\n const item =\n allowed.length === 0\n ? z.string()\n : z.string().refine((val) => allowed.includes(val), {\n message: `${field.label} contains a value outside the offered options`,\n });\n return z.array(item);\n}\n\nfunction dateSchema(field: SpecField): z.ZodTypeAny {\n return z.string().refine((val) => !Number.isNaN(Date.parse(val)), {\n message: `${field.label} must be a valid date`,\n });\n}\n\n/** Derive the value schema for one field, BEFORE the required/optional wrap. */\nfunction baseSchema(field: SpecField): z.ZodTypeAny {\n switch (field.type) {\n case \"email\":\n return stringSchema(field);\n case \"number\":\n return numberSchema(field);\n case \"checkbox\":\n case \"boolean\":\n return z.boolean();\n case \"select\":\n case \"radio\":\n return enumSchema(field);\n case \"multiselect\":\n return multiEnumSchema(field);\n case \"date\":\n return dateSchema(field);\n default:\n // text | textarea | tel | any unknown type → string with validation\n return stringSchema(field);\n }\n}\n\n/**\n * Derive the full Zod schema for one SpecField.\n * Optional fields accept undefined and \"\" (\"not provided\" in a form UI).\n * Required fields additionally reject \"\" for string-typed inputs.\n */\nexport function deriveFieldSchema(field: SpecField): z.ZodTypeAny {\n const base = baseSchema(field);\n if (field.required) {\n // Required string inputs must be non-empty.\n if (\n field.type !== \"checkbox\" &&\n field.type !== \"boolean\" &&\n field.type !== \"number\" &&\n field.type !== \"multiselect\"\n ) {\n return z\n .string({ required_error: `${field.label} is required` })\n .min(1, `${field.label} is required`)\n .pipe(base);\n }\n if (field.type === \"number\") {\n // A required number must be PRESENT. Without this guard,\n // z.coerce.number(\"\") coerces the empty DOM value to 0 and passes —\n // then buildSubmitPayload drops the \"\" answer, so the client declares\n // the form valid while the server 422s on a missing required field.\n // Reject empty/missing BEFORE coercion; a provided value flows to\n // the coercing number schema (min/max still apply).\n return z\n .any()\n .refine(\n (val) => val !== \"\" && val !== undefined && val !== null,\n `${field.label} is required`,\n )\n .pipe(base);\n }\n if (field.type === \"multiselect\") {\n return base.refine(\n (val) => Array.isArray(val) && val.length > 0,\n `${field.label} requires at least one selection`,\n );\n }\n return base;\n }\n // Optional: \"\" normalizes to undefined before validation.\n return z.preprocess(\n (val) =>\n val === \"\" || val === undefined || val === null ? undefined : val,\n base.optional(),\n );\n}\n\n/**\n * Derive a STRICT Zod object schema for one step's fields — unknown answer\n * keys within the step are rejected (mirrors the server's authoritative\n * re-validation posture; a stale client must not silently carry fields the\n * spec no longer defines).\n */\nexport function deriveStepSchema(step: SpecStep) {\n const shape: Record<string, z.ZodTypeAny> = {};\n for (const field of step.fields) {\n shape[field.key] = deriveFieldSchema(field);\n }\n return z.object(shape).strict();\n}\n\n/**\n * Derive the STRICT schema for the complete answers object across all\n * steps (used at submit time and by the 409-stale re-validation).\n */\nexport function deriveAnswersSchema(steps: SpecStep[]) {\n const shape: Record<string, z.ZodTypeAny> = {};\n for (const step of steps) {\n for (const field of step.fields) {\n shape[field.key] = deriveFieldSchema(field);\n }\n }\n return z.object(shape).strict();\n}\n","/**\n * Headless dynamic signup stepper (D540 §1/§3).\n *\n * The steps are GENERATED from the served spec: fields bucket by `stage`\n * server-side → the spec's forms.signup.steps array. More configured\n * fields ⇒ more steps. The final `activation` stage carries the\n * service-selection inputs feeding the existing terminal-stage guards.\n *\n * Framework-agnostic: same subscribe/mutate contract as the Phase-1\n * contact-form state. The default component layer renders it; framework\n * integrations can wrap it.\n *\n * 409 spec_stale flow (D540 reject-stale): the CALLER (widget/submit\n * orchestration) refetches the spec on OnboardingSpecStaleError and calls\n * `applyNewSpec(newSpec)`. The stepper re-validates every answer against\n * the NEW derived schema, DROPS answers whose fields no longer exist,\n * marks `specStale: true`, and repositions to the first step with errors —\n * the user re-confirms; the SDK NEVER silently auto-resubmits.\n */\n\nimport { z, type ZodIssue } from \"zod/v3\";\nimport type { OnboardingSpec, SpecStep, TerminalStage } from \"../spec/model.js\";\nimport { deriveAnswersSchema, deriveStepSchema } from \"./derive.js\";\nimport {\n createConsentController,\n type ConsentController,\n type ConsentState,\n type ConsentSubmitDocument,\n} from \"../consent/controller.js\";\nimport type { FieldError } from \"../form/state.js\";\nimport {\n isSubdomainLabelShape,\n SUBDOMAIN_SHAPE_MESSAGE,\n} from \"../submit/subdomain.js\";\n\nexport type StepperStatus = \"editing\" | \"submitting\" | \"success\" | \"error\";\n\nexport interface SignupConsent {\n tosAccepted: boolean;\n privacyAccepted: boolean;\n}\n\nexport interface SignupCredentials {\n email: string;\n displayName: string;\n organisationName: string;\n subdomain: string;\n}\n\nexport interface SignupStepperState {\n /** Zero-based index of the current step. */\n stepIndex: number;\n stepCount: number;\n currentStep: SpecStep | null;\n /** Answers keyed by field key (only keys defined by the active spec). */\n answers: Record<string, unknown>;\n /** Derived from serviceSelection-flagged answers (see buildSubmitPayload). */\n selectedServices: string[];\n /** Validation errors for the CURRENT step (or full-form at submit). */\n errors: FieldError[];\n /** Credential/consent errors (submit-time). */\n accountErrors: FieldError[];\n consent: SignupConsent;\n credentials: SignupCredentials;\n status: StepperStatus;\n serverError: string | null;\n /** True after a 409-stale spec swap until the user re-validates. */\n specStale: boolean;\n /** The specVersion currently driving the form (echoed on submit). */\n specVersion: string;\n /** Set on success from the submit response. */\n terminalStage: TerminalStage | null;\n /**\n * D543 ConsentPack state (per-document acceptance + gates). Empty\n * (documents:[]) when the spec serves no consentPack — the consent stage is\n * then skipped and does not gate the submit.\n */\n consentState: ConsentState;\n /**\n * True after a 409 consent_stale swap until the user re-accepts the changed\n * docs. Distinct from specStale — a doc-version bump does not necessarily\n * change the form fields, and the banner copy differs.\n */\n consentStale: boolean;\n /** Keys of the consent docs whose acceptance was reset by the last swap. */\n staleConsentKeys: string[];\n /** Consent-stage errors (submit-time; e.g. a required doc not accepted). */\n consentErrors: FieldError[];\n}\n\nexport type SignupStepperListener = (state: SignupStepperState) => void;\n\n/** The locked credential constraints (PublicOnboardingSubmitRequest). */\nconst credentialsSchema = z.object({\n email: z.string().email(\"A valid account email is required\"),\n displayName: z.string().trim().min(1, \"Your name is required\").max(200),\n organisationName: z\n .string()\n .trim()\n .min(1, \"Organisation name is required\")\n .max(200),\n subdomain: z\n .string()\n .trim()\n .min(1, \"Workspace subdomain is required\")\n .max(63)\n // Empty and over-long already have their own message above.\n .refine(\n (v) => v === \"\" || v.length > 63 || isSubdomainLabelShape(v),\n SUBDOMAIN_SHAPE_MESSAGE,\n ),\n});\n\nfunction zodIssuesToFieldErrors(issues: ZodIssue[]): FieldError[] {\n return issues.map((issue) => ({\n path: issue.path.join(\".\"),\n message: issue.message,\n }));\n}\n\n/** Flatten a serviceSelection field's answer into service ids. */\nfunction serviceIdsOf(key: string, value: unknown): string[] {\n if (typeof value === \"string\" && value !== \"\") return [value];\n if (Array.isArray(value)) return value.map((v) => String(v));\n if (value === true) return [key];\n return [];\n}\n\nexport interface SignupStepperControl {\n getState(): SignupStepperState;\n setAnswer(key: string, value: unknown): void;\n setConsent(consent: Partial<SignupConsent>): void;\n setCredentials(credentials: Partial<SignupCredentials>): void;\n /**\n * The headless ConsentPack controller (D543 §5). Exposed so the default\n * component layer AND fully custom tenant UIs drive the SAME state: mark\n * scroll/open evidence, set acceptance, read per-doc gate status. The\n * stepper subscribes to it internally so consent mutations re-emit stepper\n * state (consentState/consentStale) to the widget.\n */\n readonly consent: ConsentController;\n /** Validate ONLY the current step. Returns true when clean. */\n validateStep(): boolean;\n /** Validate current step; advance when clean. Returns true if advanced. */\n next(): boolean;\n back(): void;\n isFirstStep(): boolean;\n isLastStep(): boolean;\n /**\n * Full-form validation: every step's answers + credentials + consent.\n * Populates errors/accountErrors. Returns true when submittable.\n */\n validateAll(): boolean;\n /**\n * The submit payload body (minus botToken, which the transport attaches).\n * Call ONLY after validateAll() returns true.\n *\n * D543 §4: `consent.documents` is the per-doc consent array built from the\n * ACTUAL consent state (omitted when the spec serves no consentPack). The\n * booleans stay as the derived convenience. THROWS if any required consent\n * doc is not accepted at its gate (never fabricates acceptance).\n */\n buildSubmitPayload(): {\n specVersion: string;\n answers: Record<string, unknown>;\n selectedServices?: string[];\n consent: {\n tosAccepted: true;\n privacyAccepted: true;\n documents?: ConsentSubmitDocument[];\n };\n credentials: { email: string; displayName?: string };\n organisationName?: string;\n subdomain: string;\n };\n /**\n * Swap in a refetched spec after 409 spec_stale. Drops answers for\n * removed fields, re-validates the rest, marks specStale, repositions\n * to the first step with errors. ALSO swaps the consentPack (a spec bump\n * may carry new doc versions) — changed docs require re-acceptance. NEVER\n * auto-resubmits.\n */\n applyNewSpec(spec: OnboardingSpec): void;\n /** Clear the specStale flag once the user has re-confirmed. */\n acknowledgeSpecStale(): void;\n /**\n * Swap in the refetched spec's consentPack after 409 consent_stale (D543\n * §4). Resets acceptance for docs whose version/hash changed (re-acceptance\n * required — NEVER auto-accept a changed doc), marks consentStale, records\n * which keys were reset. NEVER auto-resubmits.\n */\n applyNewConsentPack(spec: OnboardingSpec): void;\n /** Clear the consentStale flag once the user has re-accepted. */\n acknowledgeConsentStale(): void;\n setSubmitting(): void;\n setSuccess(terminalStage: TerminalStage): void;\n setError(message: string): void;\n /**\n * Put a server's refusal on the one account field it is about (409\n * subdomain_taken → `subdomain`), so the user is told which input to change.\n * Returns the form to \"editing\" with no form-level error: the field carries\n * the message. Replaces any error already on that field. Editing the field\n * clears it; the next validateAll() recomputes account errors as usual.\n */\n setAccountError(path: keyof SignupCredentials, message: string): void;\n /**\n * Reset to the pristine initial state against the CURRENT spec: step 0,\n * status \"editing\", answers/credentials/consent/errors cleared. This is\n * the only transition back OUT of \"success\"/\"error\"; the widget's reset()\n * relies on it (otherwise a post-success keystroke would re-emit\n * status \"success\" and re-hide the form).\n */\n reset(): void;\n subscribe(listener: SignupStepperListener): () => void;\n}\n\n/**\n * Create a headless stepper for the spec's signup form.\n *\n * @example\n * ```ts\n * const spec = await fetchOnboardingSpec({ baseUrl, onboarder });\n * const stepper = createSignupStepper(spec);\n * stepper.subscribe(render);\n * stepper.setAnswer(\"company_name\", \"ACME\");\n * if (stepper.next()) { ... }\n * ```\n */\nexport function createSignupStepper(\n spec: OnboardingSpec,\n): SignupStepperControl {\n let steps: SpecStep[] = spec.forms.signup.steps;\n let specVersion = spec.specVersion;\n\n // D543 ConsentPack controller. The stepper OWNS it; the widget + custom\n // UIs drive it via the exposed `consent` control. It's the same instance\n // for the stepper's lifetime — applyNewConsentPack SWAPS its docs in place\n // (createConsentController is re-run on reset()).\n let consentController = createConsentController(spec.consentPack);\n\n let state: SignupStepperState = {\n stepIndex: 0,\n stepCount: steps.length,\n currentStep: steps[0] ?? null,\n answers: {},\n selectedServices: [],\n errors: [],\n accountErrors: [],\n consent: { tosAccepted: false, privacyAccepted: false },\n credentials: {\n email: \"\",\n displayName: \"\",\n organisationName: \"\",\n subdomain: \"\",\n },\n status: \"editing\",\n serverError: null,\n specStale: false,\n specVersion,\n terminalStage: null,\n consentState: consentController.getState(),\n consentStale: false,\n staleConsentKeys: [],\n consentErrors: [],\n };\n\n // Which step indices have been validated at least once. Once a step has\n // been validated, EVERY subsequent setAnswer revalidates it — so a\n // fix-then-rebreak on that step re-shows the error immediately (matching\n // the Phase-1 contact-form `hasValidated` fix). Before a step is validated,\n // typing does not spray errors. Cleared on reset()/applyNewSpec.\n let validatedSteps = new Set<number>();\n\n // Account fields whose current error came from the server (setAccountError)\n // rather than from the form's own validation. Only these clear on edit.\n const serverAccountErrorPaths = new Set<string>();\n\n // True once validateAll() has run — after that, EVERY consent mutation\n // recomputes consent errors (fix-then-rebreak parity with field errors), so\n // a per-doc error clears live as the user accepts and persists as long as a\n // required doc is unmet. Cleared on reset()/applyNewSpec/applyNewConsentPack.\n let consentValidated = false;\n\n const listeners = new Set<SignupStepperListener>();\n\n function emit(): void {\n for (const listener of listeners) {\n listener(structuredClone(state));\n }\n }\n\n /**\n * Mirror the consent controller's state into the stepper state and re-emit,\n * so a subscriber that only watches stepper state (the widget) sees consent\n * gate/acceptance changes. Once validateAll() has run, consent errors are\n * recomputed on every mutation so they clear live AND persist correctly\n * regardless of which emit (validateAll vs a consent mutation vs the async\n * viewer's scroll report) fires last.\n */\n function syncConsentState(): void {\n const consentState = consentController.getState();\n const consentErrors = consentValidated\n ? computeConsentErrors()\n : state.consentErrors;\n state = { ...state, consentState, consentErrors };\n emit();\n }\n\n // Wire consent mutations through the stepper so the widget re-renders. The\n // subscription lives for the controller's lifetime; on reset() a NEW\n // controller is created and re-subscribed.\n let unsubscribeConsent = consentController.subscribe(() =>\n syncConsentState(),\n );\n\n /** One error per required consent doc that is not accepted at its gate. */\n function computeConsentErrors(): FieldError[] {\n const errors: FieldError[] = [];\n for (const d of consentController.getState().documents) {\n if (d.doc.required && !(d.accepted && d.gateSatisfied)) {\n const need =\n d.doc.acceptanceLevel === \"scroll_then_accept\" && !d.gateSatisfied\n ? \"scroll to the end, then accept\"\n : d.doc.acceptanceLevel === \"open_then_accept\" && !d.gateSatisfied\n ? \"open the document, then accept\"\n : \"accept\";\n errors.push({\n path: d.key,\n message: `You must ${need} \"${d.doc.title}\".`,\n });\n }\n }\n return errors;\n }\n\n function knownFieldKeys(): Set<string> {\n const keys = new Set<string>();\n for (const step of steps) {\n for (const field of step.fields) keys.add(field.key);\n }\n return keys;\n }\n\n /** Answers restricted to the current step's fields. */\n function stepAnswers(step: SpecStep): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const field of step.fields) {\n if (field.key in state.answers) out[field.key] = state.answers[field.key];\n }\n return out;\n }\n\n function deriveSelectedServices(): string[] {\n const services: string[] = [];\n for (const step of steps) {\n for (const field of step.fields) {\n if (field.serviceSelection === true) {\n services.push(...serviceIdsOf(field.key, state.answers[field.key]));\n }\n }\n }\n return [...new Set(services)];\n }\n\n /**\n * The EFFECTIVE tos/privacy booleans (D543 §4 \"derived convenience\").\n *\n * When the spec serves a consentPack containing a `tos` / `privacy` doc,\n * the boolean is DERIVED from whether that doc is accepted (the array is\n * authoritative). Otherwise (pre-ConsentPack onboarder), the explicit\n * checkbox booleans from setConsent() apply. This keeps the legacy\n * booleans truthful without letting them contradict the consent array.\n */\n function effectiveConsentBooleans(): SignupConsent {\n if (consentController.isEmpty()) return { ...state.consent };\n const byType = new Map<string, boolean>();\n for (const d of consentController.getState().documents) {\n byType.set(d.doc.docType, d.accepted && d.gateSatisfied);\n }\n return {\n tosAccepted: byType.has(\"tos\")\n ? byType.get(\"tos\") === true\n : state.consent.tosAccepted,\n privacyAccepted: byType.has(\"privacy\")\n ? byType.get(\"privacy\") === true\n : state.consent.privacyAccepted,\n };\n }\n\n function runStepValidation(step: SpecStep): FieldError[] {\n const result = deriveStepSchema(step).safeParse(stepAnswers(step));\n return result.success ? [] : zodIssuesToFieldErrors(result.error.issues);\n }\n\n /**\n * Swap the consent controller's docs to the new spec's consentPack, RESET\n * acceptance for docs whose version/hash changed (re-acceptance required —\n * never auto-accept), and fold the result into stepper state. Shared by\n * applyNewSpec (a spec bump may also bump doc versions) and\n * applyNewConsentPack (a pure consent_stale swap). Returns the reset keys.\n *\n * `controllerAlreadyEmitted`: applyNewPack emits through the controller's\n * own subscription (syncConsentState), so the caller need not re-emit for\n * the consent slice — but callers that ALSO mutate other stepper state\n * fold it into their single state update to avoid a double render.\n */\n function swapConsentPack(newSpec: OnboardingSpec): string[] {\n const resetKeys = consentController.applyNewPack(newSpec.consentPack);\n return resetKeys;\n }\n\n function firstStepWithErrors(): number {\n for (let i = 0; i < steps.length; i++) {\n const step = steps[i];\n if (step && runStepValidation(step).length > 0) return i;\n }\n return 0;\n }\n\n return {\n get consent() {\n return consentController;\n },\n\n getState() {\n return structuredClone(state);\n },\n\n setAnswer(key, value) {\n state = {\n ...state,\n answers: { ...state.answers, [key]: value },\n };\n state.selectedServices = deriveSelectedServices();\n // Live-revalidate once THIS step has been validated at least once —\n // regardless of whether errors are currently showing. This is the\n // fix-then-rebreak fix: after fixing a field (errors → 0), breaking it\n // again must re-show the error without a fresh next()/validateStep().\n if (validatedSteps.has(state.stepIndex) && state.currentStep) {\n state = { ...state, errors: runStepValidation(state.currentStep) };\n }\n emit();\n },\n\n setConsent(consent) {\n state = { ...state, consent: { ...state.consent, ...consent } };\n emit();\n },\n\n setCredentials(credentials) {\n // A server's refusal of a field (setAccountError) answers the value\n // that was sent. Once the user changes that field it no longer applies;\n // an input event that re-sends the same value (autofill, IME) is no\n // change, and the refusal stands.\n const previous = state.credentials as unknown as Record<string, unknown>;\n const cleared = Object.entries(credentials)\n .filter(\n ([k, v]) => v !== previous[k] && serverAccountErrorPaths.delete(k),\n )\n .map(([k]) => k);\n state = {\n ...state,\n credentials: { ...state.credentials, ...credentials },\n accountErrors:\n cleared.length === 0\n ? state.accountErrors\n : state.accountErrors.filter((e) => !cleared.includes(e.path)),\n };\n emit();\n },\n\n validateStep() {\n if (!state.currentStep) return true;\n validatedSteps.add(state.stepIndex);\n const errors = runStepValidation(state.currentStep);\n state = { ...state, errors };\n emit();\n return errors.length === 0;\n },\n\n next() {\n if (!state.currentStep) return false;\n validatedSteps.add(state.stepIndex);\n const errors = runStepValidation(state.currentStep);\n if (errors.length > 0) {\n state = { ...state, errors };\n emit();\n return false;\n }\n if (state.stepIndex >= steps.length - 1) return false;\n const stepIndex = state.stepIndex + 1;\n state = {\n ...state,\n stepIndex,\n currentStep: steps[stepIndex] ?? null,\n errors: [],\n };\n emit();\n return true;\n },\n\n back() {\n if (state.stepIndex === 0) return;\n const stepIndex = state.stepIndex - 1;\n state = {\n ...state,\n stepIndex,\n currentStep: steps[stepIndex] ?? null,\n errors: [],\n };\n emit();\n },\n\n isFirstStep() {\n return state.stepIndex === 0;\n },\n\n isLastStep() {\n return state.stepIndex >= steps.length - 1;\n },\n\n validateAll() {\n // A full validation counts as validating every step.\n for (let i = 0; i < steps.length; i++) validatedSteps.add(i);\n // Answers across ALL steps (strict — unknown keys rejected).\n const answersResult = deriveAnswersSchema(steps).safeParse(state.answers);\n const errors = answersResult.success\n ? []\n : zodIssuesToFieldErrors(answersResult.error.issues);\n\n // Credentials + consent (locked submit contract). Recomputed from the\n // form alone, so a server refusal (setAccountError) is dropped here.\n serverAccountErrorPaths.clear();\n const accountErrors: FieldError[] = [];\n const credResult = credentialsSchema.safeParse(state.credentials);\n if (!credResult.success) {\n accountErrors.push(...zodIssuesToFieldErrors(credResult.error.issues));\n }\n // The tos/privacy booleans are the EFFECTIVE (derived-from-consentPack\n // when present) values. This keeps the legacy booleans in lockstep with\n // the ConsentPack — a user who accepted the tos DOC satisfies tosAccepted\n // without a separate checkbox, and one who did NOT is blocked here.\n const effective = effectiveConsentBooleans();\n if (effective.tosAccepted !== true) {\n accountErrors.push({\n path: \"tosAccepted\",\n message: \"You must accept the Terms of Service\",\n });\n }\n if (effective.privacyAccepted !== true) {\n accountErrors.push({\n path: \"privacyAccepted\",\n message: \"You must accept the Privacy Policy\",\n });\n }\n\n // D543 consent stage: every REQUIRED consent doc must be accepted at its\n // gate. Empty consentPack ⇒ vacuously complete (no consentErrors). Mark\n // consent validated so subsequent mutations recompute errors live.\n consentValidated = true;\n const consentErrors = consentController.isEmpty()\n ? []\n : computeConsentErrors();\n\n state = {\n ...state,\n errors,\n accountErrors,\n consentErrors,\n consentState: consentController.getState(),\n };\n emit();\n return (\n errors.length === 0 &&\n accountErrors.length === 0 &&\n consentErrors.length === 0\n );\n },\n\n buildSubmitPayload() {\n // COMPLIANCE-CRITICAL: never fabricate legal consent. Read the ACTUAL\n // consent state and refuse to build a payload unless the user genuinely\n // accepted both. A headless caller that skips validateAll() must not be\n // able to transmit consent:true for a user who never consented. The\n // booleans are the EFFECTIVE (consentPack-derived when present) values.\n const effective = effectiveConsentBooleans();\n if (\n effective.tosAccepted !== true ||\n effective.privacyAccepted !== true\n ) {\n throw new Error(\n \"buildSubmitPayload: cannot build a submit payload without genuine \" +\n \"user consent (tosAccepted && privacyAccepted must both be true). \" +\n \"Call validateAll() and surface the consent errors to the user first.\",\n );\n }\n\n // D543 §4: the consent-document array is authoritative. This THROWS if\n // any REQUIRED doc is not accepted at its gate (never fabricates\n // acceptance) — the same compliance discipline as the booleans above.\n // Omitted (undefined) when the spec serves no consentPack.\n const consentDocuments = consentController.isEmpty()\n ? undefined\n : consentController.buildConsentPayload();\n\n // Run answers through the derived schema so the wire carries COERCED\n // typed values (e.g. number fields as numbers, not raw DOM strings) —\n // this is the exact validation validateAll() applies, so a payload can\n // only be built from a state that would pass. A required field that is\n // empty/missing FAILS here (see deriveFieldSchema's required wrap),\n // so buildSubmitPayload throws rather than silently dropping it.\n const parsed = deriveAnswersSchema(steps).safeParse(state.answers);\n if (!parsed.success) {\n const detail = parsed.error.issues\n .map((i) => `${i.path.join(\".\") || \"(answers)\"}: ${i.message}`)\n .join(\"; \");\n throw new Error(\n `buildSubmitPayload: answers failed validation — call validateAll() first (${detail}).`,\n );\n }\n\n // Only keys the active spec defines, with empty optionals omitted.\n const known = knownFieldKeys();\n const answers: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(parsed.data)) {\n if (known.has(key) && value !== undefined && value !== \"\") {\n answers[key] = value;\n }\n }\n const selectedServices = deriveSelectedServices();\n return {\n specVersion,\n answers,\n ...(selectedServices.length > 0 ? { selectedServices } : {}),\n consent: {\n tosAccepted: effective.tosAccepted,\n privacyAccepted: effective.privacyAccepted,\n ...(consentDocuments !== undefined\n ? { documents: consentDocuments }\n : {}),\n } as {\n tosAccepted: true;\n privacyAccepted: true;\n documents?: ConsentSubmitDocument[];\n },\n credentials: {\n email: state.credentials.email,\n ...(state.credentials.displayName\n ? { displayName: state.credentials.displayName }\n : {}),\n },\n organisationName: state.credentials.organisationName,\n subdomain: state.credentials.subdomain,\n };\n },\n\n applyNewSpec(newSpec) {\n steps = newSpec.forms.signup.steps;\n specVersion = newSpec.specVersion;\n\n // Drop answers for fields the new spec no longer defines.\n const known = new Set<string>();\n for (const step of steps) {\n for (const field of step.fields) known.add(field.key);\n }\n const answers: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(state.answers)) {\n if (known.has(key)) answers[key] = value;\n }\n\n // A spec bump may ALSO carry new consent-doc versions — swap the pack so\n // changed docs require re-acceptance. Mark consentStale iff any accepted\n // doc was actually reset. (applyNewPack emits via the subscription; the\n // final state below overwrites consentState with the post-swap value.)\n const resetKeys = swapConsentPack(newSpec);\n\n state = {\n ...state,\n answers,\n stepCount: steps.length,\n specVersion,\n specStale: true,\n status: \"editing\",\n serverError: null,\n consentState: consentController.getState(),\n consentStale: state.consentStale || resetKeys.length > 0,\n staleConsentKeys: resetKeys,\n consentErrors: [],\n };\n state.selectedServices = deriveSelectedServices();\n\n // Reposition to the first step with errors under the NEW schema so\n // the user reviews exactly what changed; errors render immediately.\n const stepIndex = Math.min(firstStepWithErrors(), steps.length - 1);\n const currentStep = steps[Math.max(stepIndex, 0)] ?? null;\n // The repositioned step is being shown with errors → treat it as\n // validated so live-revalidation is active there immediately.\n validatedSteps = new Set<number>([Math.max(stepIndex, 0)]);\n state = {\n ...state,\n stepIndex: Math.max(stepIndex, 0),\n currentStep,\n errors: currentStep ? runStepValidation(currentStep) : [],\n };\n emit();\n },\n\n applyNewConsentPack(newSpec) {\n // Pure consent_stale swap (D543 §4): the form fields are unchanged; only\n // the consent docs may have bumped. Reset acceptance for changed docs\n // (re-acceptance required — NEVER auto-accept), mark consentStale.\n const resetKeys = swapConsentPack(newSpec);\n // Keep specVersion in lockstep — a consent_stale refetch carries the\n // current spec, whose specVersion the next submit must echo.\n specVersion = newSpec.specVersion;\n state = {\n ...state,\n specVersion,\n consentState: consentController.getState(),\n consentStale: true,\n staleConsentKeys: resetKeys,\n consentErrors: [],\n status: \"editing\",\n serverError: null,\n };\n emit();\n },\n\n acknowledgeConsentStale() {\n state = { ...state, consentStale: false, staleConsentKeys: [] };\n emit();\n },\n\n acknowledgeSpecStale() {\n state = { ...state, specStale: false };\n emit();\n },\n\n setSubmitting() {\n state = {\n ...state,\n status: \"submitting\",\n serverError: null,\n };\n emit();\n },\n\n setSuccess(terminalStage) {\n state = { ...state, status: \"success\", terminalStage, serverError: null };\n emit();\n },\n\n setError(message) {\n state = { ...state, status: \"error\", serverError: message };\n emit();\n },\n\n setAccountError(path, message) {\n serverAccountErrorPaths.add(path);\n // The refusal is the field's to show: the form is editable again, with\n // no form-level banner left to go stale once the field is fixed.\n state = {\n ...state,\n status: \"editing\",\n serverError: null,\n accountErrors: [\n ...state.accountErrors.filter((e) => e.path !== path),\n { path, message },\n ],\n };\n emit();\n },\n\n reset() {\n validatedSteps = new Set<number>();\n consentValidated = false;\n serverAccountErrorPaths.clear();\n // Rebuild the consent controller from the CURRENT (possibly swapped)\n // docs so reset() clears all acceptance/evidence back to pristine. Drop\n // the old subscription and re-subscribe the new instance.\n const currentDocs = consentController\n .getState()\n .documents.map((d) => d.doc);\n unsubscribeConsent();\n consentController = createConsentController(\n currentDocs.length > 0 ? { documents: currentDocs } : undefined,\n );\n unsubscribeConsent = consentController.subscribe(() =>\n syncConsentState(),\n );\n state = {\n stepIndex: 0,\n stepCount: steps.length,\n currentStep: steps[0] ?? null,\n answers: {},\n selectedServices: [],\n errors: [],\n accountErrors: [],\n consent: { tosAccepted: false, privacyAccepted: false },\n credentials: {\n email: \"\",\n displayName: \"\",\n organisationName: \"\",\n subdomain: \"\",\n },\n status: \"editing\",\n serverError: null,\n specStale: false,\n specVersion,\n terminalStage: null,\n consentState: consentController.getState(),\n consentStale: false,\n staleConsentKeys: [],\n consentErrors: [],\n };\n emit();\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { contactFormSchema } from './chunk-SIMLMQPT.js';
1
+ import { contactFormSchema } from './chunk-WKN4U7QF.js';
2
2
 
3
3
  // src/form/state.ts
4
4
  function zodIssuesToFieldErrors(issues) {
@@ -19,10 +19,9 @@ var INITIAL_VALUES = {
19
19
  attribution: void 0,
20
20
  privacyNoticeAcknowledged: false,
21
21
  marketingOptIn: false,
22
- intakeKind: "enquiry",
23
- website: void 0
22
+ intakeKind: "enquiry"
24
23
  };
25
- function createContactFormState() {
24
+ function createContactFormState(options = {}) {
26
25
  let state = {
27
26
  values: { ...INITIAL_VALUES },
28
27
  errors: [],
@@ -38,8 +37,11 @@ function createContactFormState() {
38
37
  }
39
38
  function runValidation() {
40
39
  const result = contactFormSchema.safeParse(state.values);
41
- if (result.success) return [];
42
- return zodIssuesToFieldErrors(result.error.issues);
40
+ const errors = result.success ? [] : zodIssuesToFieldErrors(result.error.issues);
41
+ if (options.requireInterest && state.values.interestModules.length === 0) {
42
+ errors.push({ path: "interestModules", message: "Choose at least one" });
43
+ }
44
+ return errors;
43
45
  }
44
46
  let hasValidated = false;
45
47
  return {
@@ -97,5 +99,5 @@ function createContactFormState() {
97
99
  }
98
100
 
99
101
  export { createContactFormState };
100
- //# sourceMappingURL=chunk-U6AXKGYQ.js.map
101
- //# sourceMappingURL=chunk-U6AXKGYQ.js.map
102
+ //# sourceMappingURL=chunk-DWFZA5T6.js.map
103
+ //# sourceMappingURL=chunk-DWFZA5T6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/form/state.ts"],"names":[],"mappings":";;;AAiEA,SAAS,uBAAuB,MAAA,EAAkC;AAChE,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC5B,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,IAAA,C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MAAA,EAAQ,SAAA,EAAW,aAAa,IAAA,EAAK;AACzD,MAAA,IAAA,EAAK;AAAA,IACP,CAAA;AAAA,IAEA,SAAS,OAAA,EAAS;AAChB,MAAA,KAAA,GAAQ,EAAE,GAAG,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAS,aAAa,OAAA,EAAQ;AAC1D,MAAA,IAAA,EAAK;AAAA,IACP,CAAA;AAAA,IAEA,KAAA,GAAQ;AACN,MAAA,YAAA,GAAe,KAAA;AACf,MAAA,KAAA,GAAQ;AAAA,QACN,MAAA,EAAQ,EAAE,GAAG,cAAA,EAAe;AAAA,QAC5B,QAAQ,EAAC;AAAA,QACT,WAAA,EAAa,IAAA;AAAA,QACb,MAAA,EAAQ,MAAA;AAAA,QACR,KAAA,EAAO;AAAA,OACT;AACA,MAAA,IAAA,EAAK;AAAA,IACP,CAAA;AAAA,IAEA,UAAU,QAAA,EAAU;AAClB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AACX,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAC3B,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"chunk-DWFZA5T6.js","sourcesContent":["/**\n * Headless form state manager for the contact form.\n *\n * Designed to be framework-agnostic — callers supply a change callback\n * and call the returned mutators. The widget layer uses this internally;\n * framework integrations (React, Vue, etc.) can wrap it in their own hooks.\n */\n\nimport type { ZodIssue } from \"zod/v3\";\nimport { contactFormSchema, type ContactFormValues } from \"./schema.js\";\n\nexport interface FieldError {\n path: string;\n message: string;\n}\n\nexport type FormStatus = \"idle\" | \"submitting\" | \"success\" | \"error\";\n\nexport interface ContactFormState {\n values: ContactFormValues;\n /** Per-field validation errors from the last validate() call. */\n errors: FieldError[];\n /** Cross-field / server error message. */\n serverError: string | null;\n status: FormStatus;\n /** True if values have been touched at least once. */\n dirty: boolean;\n}\n\nexport type ContactFormStateListener = (state: ContactFormState) => void;\n\nexport interface ContactFormStateOptions {\n /**\n * The onboarder publishes the interest question as required (its spec's\n * `forms.contact` field `interestModules`), so an empty choice is a field\n * error rather than a lead that says nothing about what was asked.\n */\n requireInterest?: boolean;\n}\n\nexport interface ContactFormControl {\n /** Current snapshot of form state. */\n getState(): ContactFormState;\n /** Update a single field value and re-validate if dirty. */\n setValue<K extends keyof ContactFormValues>(\n field: K,\n value: ContactFormValues[K],\n ): void;\n /**\n * Run full client-side validation. Returns true if valid.\n * Also marks the form dirty so future setValue calls auto-validate.\n */\n validate(): boolean;\n /** Mark the form as submitting. Called by the submit client. */\n setSubmitting(): void;\n /** Mark the form as successfully submitted. */\n setSuccess(): void;\n /** Set a server-side error (e.g. 429 rate limited). */\n setError(message: string): void;\n /** Reset to initial idle state. */\n reset(): void;\n /** Subscribe to state changes. Returns unsubscribe function. */\n subscribe(listener: ContactFormStateListener): () => void;\n}\n\nfunction zodIssuesToFieldErrors(issues: ZodIssue[]): FieldError[] {\n return issues.map((issue) => ({\n path: issue.path.join(\".\"),\n message: issue.message,\n }));\n}\n\nconst INITIAL_VALUES: ContactFormValues = {\n name: undefined,\n companyName: \"\",\n contactName: \"\",\n email: \"\",\n phone: undefined,\n message: undefined,\n interestModules: [],\n sizeBand: undefined,\n attribution: undefined,\n privacyNoticeAcknowledged: false,\n marketingOptIn: false,\n intakeKind: \"enquiry\",\n};\n\n/**\n * Create a new headless contact form state controller.\n *\n * @example\n * ```ts\n * const form = createContactFormState();\n * form.subscribe((state) => renderUI(state));\n * form.setValue(\"name\", \"Alice\");\n * const valid = form.validate();\n * if (valid) await submitContact(form.getState().values, botToken);\n * ```\n */\nexport function createContactFormState(\n options: ContactFormStateOptions = {},\n): ContactFormControl {\n let state: ContactFormState = {\n values: { ...INITIAL_VALUES },\n errors: [],\n serverError: null,\n status: \"idle\",\n dirty: false,\n };\n\n const listeners = new Set<ContactFormStateListener>();\n\n function emit(): void {\n for (const listener of listeners) {\n listener({ ...state, values: { ...state.values } });\n }\n }\n\n function runValidation(): FieldError[] {\n const result = contactFormSchema.safeParse(state.values);\n const errors = result.success\n ? []\n : zodIssuesToFieldErrors(result.error.issues);\n if (options.requireInterest && state.values.interestModules.length === 0) {\n errors.push({ path: \"interestModules\", message: \"Choose at least one\" });\n }\n return errors;\n }\n\n // Once validate() has run at least once, EVERY subsequent setValue\n // revalidates — errors both clear when a field is fixed AND reappear\n // when a fixed field is broken again. (Previously the revalidation was\n // gated on errors.length > 0, so fix-then-rebreak silently showed no\n // error until the next explicit validate().)\n let hasValidated = false;\n\n return {\n getState() {\n return { ...state, values: { ...state.values } };\n },\n\n setValue(field, value) {\n state = {\n ...state,\n values: { ...state.values, [field]: value },\n dirty: true,\n };\n if (hasValidated) {\n state = { ...state, errors: runValidation() };\n }\n emit();\n },\n\n validate() {\n hasValidated = true;\n const errors = runValidation();\n state = { ...state, errors, dirty: true };\n emit();\n return errors.length === 0;\n },\n\n setSubmitting() {\n state = { ...state, status: \"submitting\", serverError: null, errors: [] };\n emit();\n },\n\n setSuccess() {\n state = { ...state, status: \"success\", serverError: null };\n emit();\n },\n\n setError(message) {\n state = { ...state, status: \"error\", serverError: message };\n emit();\n },\n\n reset() {\n hasValidated = false;\n state = {\n values: { ...INITIAL_VALUES },\n errors: [],\n serverError: null,\n status: \"idle\",\n dirty: false,\n };\n emit();\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { consentPackSchema } from './chunk-U56GQITG.js';
1
+ import { consentPackSchema } from './chunk-NDSBIB3N.js';
2
2
  import { DEFAULT_REQUEST_TIMEOUT_MS, fetchWithTimeout, OnboardingNetworkError, OnboardingRateLimitError, OnboardingServerError, OnboardingSpecInvalidError, OnboardingValidationError } from './chunk-XJTJPBJB.js';
3
3
  import { z } from 'zod/v3';
4
4
 
@@ -175,25 +175,45 @@ async function fetchPinState(options) {
175
175
  "PIN must be a 6-digit Indian PIN code"
176
176
  );
177
177
  }
178
- const response = await fetchWithTimeout(
179
- `${options.baseUrl.replace(/\/$/, "")}/api/v1/public/onboarding/pin-state?pin=${encodeURIComponent(pin)}`,
180
- {
181
- method: "GET",
182
- fetchImpl: options.fetch ?? globalThis.fetch,
183
- timeoutMs: options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
184
- }
185
- );
178
+ let response;
179
+ try {
180
+ response = await fetchWithTimeout(
181
+ `${options.baseUrl.replace(/\/$/, "")}/api/v1/public/onboarding/pin-state?pin=${encodeURIComponent(pin)}`,
182
+ {
183
+ method: "GET",
184
+ fetchImpl: options.fetch ?? globalThis.fetch,
185
+ timeoutMs: options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
186
+ }
187
+ );
188
+ } catch (err) {
189
+ throw new OnboardingNetworkError(err);
190
+ }
186
191
  if (!response.ok) throw new OnboardingServerError(response.status);
187
- const value = await response.json();
188
- if (value.pin !== pin || value.state_iso !== null && typeof value.state_iso !== "string") {
192
+ let value;
193
+ try {
194
+ value = await response.json();
195
+ } catch {
196
+ throw new OnboardingServerError(
197
+ response.status,
198
+ "PIN-state response is not JSON"
199
+ );
200
+ }
201
+ if (typeof value !== "object" || value === null) {
202
+ throw new OnboardingServerError(
203
+ response.status,
204
+ "Invalid PIN-state response"
205
+ );
206
+ }
207
+ const answer = value;
208
+ if (answer.pin !== pin || answer.state_iso !== null && typeof answer.state_iso !== "string") {
189
209
  throw new OnboardingServerError(
190
210
  response.status,
191
211
  "Invalid PIN-state response"
192
212
  );
193
213
  }
194
- return { pin, stateIso: value.state_iso };
214
+ return { pin, stateIso: answer.state_iso };
195
215
  }
196
216
 
197
217
  export { FIELD_KEY_PATTERN, OnboardingSpecCache, defaultSpecCache, diffSpecFields, fetchOnboardingSpec, fetchPinState, onboardingSpecSchema, specFieldSchema, specStepSchema, validateOnboardingSpec };
198
- //# sourceMappingURL=chunk-F75ZJERM.js.map
199
- //# sourceMappingURL=chunk-F75ZJERM.js.map
218
+ //# sourceMappingURL=chunk-KFHVZGX6.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A,MAAM,IAAI,qBAAA;AAAA,MACR,QAAA,CAAS,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF;AAGA,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,EAAM;AAC/C,IAAA,MAAM,IAAI,qBAAA;AAAA,MACR,QAAA,CAAS,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,MAAA,GAAS,KAAA;AACf,EAAA,IACE,MAAA,CAAO,QAAQ,GAAA,IACd,MAAA,CAAO,cAAc,IAAA,IAAQ,OAAO,MAAA,CAAO,SAAA,KAAc,QAAA,EAC1D;AACA,IAAA,MAAM,IAAI,qBAAA;AAAA,MACR,QAAA,CAAS,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,GAAA,EAAK,QAAA,EAAU,MAAA,CAAO,SAAA,EAAU;AAC3C","file":"chunk-KFHVZGX6.js","sourcesContent":["/**\n * D540 §1 onboarding-spec model — mirrors the LOCKED hub REST contract:\n * GET /api/v1/public/onboarding/spec (PublicOnboardingSpecResponse)\n *\n * Response shape (hub JSON Schema, both tiers identical):\n * {\n * specVersion: string (monotonic; echo on submit; stale ⇒ 409),\n * onboarderTier: \"platform\" | \"tenant\",\n * botChallenge: { provider: \"recaptcha\", siteKey: string },\n * forms: {\n * contact: { fields: SpecField[] },\n * signup: { steps: [{ stage: \"lead\"|\"prospect\"|\"activation\",\n * fields: SpecField[] }] }\n * }\n * }\n *\n * SpecField (required: key, type, label, required):\n * { key, type, label, required, validation?, options?, serviceSelection?,\n * piiClass?: \"none\"|\"context\"|\"always\"|\"reference\" }\n *\n * The Zod schema below validates a fetched spec BEFORE the SDK renders\n * anything from it — a malformed spec throws OnboardingSpecInvalidError\n * (a half-parsed spec could silently drop required fields).\n */\n\nimport { z } from \"zod/v3\";\nimport { consentPackSchema } from \"../consent/model.js\";\n\nexport type OnboarderTier = \"platform\" | \"tenant\";\nexport type PiiClass = \"none\" | \"context\" | \"always\" | \"reference\";\nexport type SpecStage = \"lead\" | \"prospect\" | \"activation\";\nexport type TerminalStage = \"prospect\" | \"inactive\" | \"active\";\n\n/**\n * Field keys are interpolated into DOM element ids and (historically) CSS\n * selectors by the widget layer. Constrain them to a strict identifier\n * alphabet so a MALICIOUS or compromised onboarder spec cannot smuggle CSS\n * metacharacters or selector-breakout payloads (e.g. `evil], [onclick=…`)\n * through the fetched spec. A spec with an out-of-alphabet key is REJECTED\n * at parse time → OnboardingSpecInvalidError (fail-closed; never rendered).\n * This is layer 1; the widget also CSS.escapes ids as defense-in-depth.\n */\nexport const FIELD_KEY_PATTERN = /^[A-Za-z0-9_-]+$/;\n\nexport const specFieldSchema = z.object({\n key: z\n .string()\n .min(1)\n .regex(\n FIELD_KEY_PATTERN,\n \"field key must contain only letters, digits, underscore, or hyphen\",\n ),\n type: z.string().min(1),\n label: z.string(),\n required: z.boolean(),\n validation: z.record(z.unknown()).optional(),\n options: z.array(z.unknown()).optional(),\n serviceSelection: z.boolean().optional(),\n piiClass: z.enum([\"none\", \"context\", \"always\", \"reference\"]).optional(),\n});\n\nexport type SpecField = z.infer<typeof specFieldSchema>;\n\nexport const specStepSchema = z.object({\n stage: z.enum([\"lead\", \"prospect\", \"activation\"]),\n fields: z.array(specFieldSchema),\n});\n\nexport type SpecStep = z.infer<typeof specStepSchema>;\n\nexport const onboardingSpecSchema = z.object({\n specVersion: z.string().min(1),\n onboarderTier: z.enum([\"platform\", \"tenant\"]),\n // D1444: omitted when the onboarder has explicitly disabled bot checking.\n botChallenge: z\n .object({\n provider: z.literal(\"recaptcha\"),\n siteKey: z.string(),\n })\n .optional(),\n forms: z.object({\n // ADVISORY-ONLY (by design, plan §12.2 / D540): the Contact-Us form is\n // INTENTIONALLY a fixed barebones shape (name/email/phone/message) and is\n // NOT onboarder-configurable. `mountContactForm` renders that fixed set\n // directly and does NOT read forms.contact.fields — the field is modeled\n // (and validated) so the SDK can round-trip the full spec, but it drives\n // no rendering. Only forms.signup is spec-driven (the dynamic stepper).\n contact: z.object({ fields: z.array(specFieldSchema) }),\n signup: z.object({ steps: z.array(specStepSchema) }),\n }),\n // D543 §4 ConsentPack extension. OPTIONAL for backward-compat (D543\n // \"pre-ConsentPack submits still parse\"): an onboarder with no required\n // legal docs serves no block, and the consent stage is omitted from the\n // flow. When PRESENT it is validated fully (fail-closed) — a malformed\n // consentPack throws OnboardingSpecInvalidError, never rendered half-parsed.\n consentPack: consentPackSchema.optional(),\n});\n\nexport type OnboardingSpec = z.infer<typeof onboardingSpecSchema>;\n\n/**\n * Parse an unknown value as an OnboardingSpec.\n * Returns a SafeParseReturnType (inferred).\n */\nexport function validateOnboardingSpec(value: unknown) {\n return onboardingSpecSchema.safeParse(value);\n}\n","/**\n * Config-fetch client for GET /api/v1/public/onboarding/spec (D540 §1/§3).\n *\n * - The onboarder is derived SERVER-side from the request Host (D536) —\n * it is NOT sent by the client. The `onboarder` value here is purely the\n * CLIENT-side cache key (D540 §3: \"cache key (onboarder, specVersion)\").\n * - The spec response is validated against the LOCKED D540 shape before\n * it is returned; a malformed spec throws OnboardingSpecInvalidError.\n * - Cache semantics: every successful fetch is stored under\n * (onboarder, specVersion) and as the onboarder's \"latest\". The versioned\n * entries let the 409 spec_stale flow diff the previously-served version\n * against the refetched one (see `diffSpecFields` + the signup widget's\n * handleSpecStale, which reads the cached prior version before refetching).\n */\n\nimport {\n OnboardingNetworkError,\n OnboardingRateLimitError,\n OnboardingServerError,\n OnboardingSpecInvalidError,\n} from \"../submit/errors.js\";\nimport {\n DEFAULT_REQUEST_TIMEOUT_MS,\n fetchWithTimeout,\n} from \"../submit/http.js\";\nimport {\n validateOnboardingSpec,\n type OnboardingSpec,\n type SpecField,\n} from \"./model.js\";\n\nconst SPEC_PATH = \"/api/v1/public/onboarding/spec\";\n\n/**\n * In-memory spec cache keyed by (onboarder, specVersion), with a \"latest\"\n * pointer per onboarder. Purely client-side; no TTL — the reject-stale\n * policy (409 spec_stale on submit) is the authoritative staleness signal,\n * and a refetch overwrites \"latest\".\n */\nexport class OnboardingSpecCache {\n private readonly byVersion = new Map<string, OnboardingSpec>();\n private readonly latest = new Map<string, OnboardingSpec>();\n\n /**\n * Collision-proof composite key. Uses JSON.stringify of the tuple so an\n * onboarder or version containing the delimiter can never alias another\n * entry — and, critically, contains NO control characters (an earlier\n * NUL-separator made git treat this whole file as binary/undiffable).\n */\n private static versionKey(onboarder: string, specVersion: string): string {\n return JSON.stringify([onboarder, specVersion]);\n }\n\n get(onboarder: string, specVersion: string): OnboardingSpec | undefined {\n return this.byVersion.get(\n OnboardingSpecCache.versionKey(onboarder, specVersion),\n );\n }\n\n getLatest(onboarder: string): OnboardingSpec | undefined {\n return this.latest.get(onboarder);\n }\n\n set(onboarder: string, spec: OnboardingSpec): void {\n this.byVersion.set(\n OnboardingSpecCache.versionKey(onboarder, spec.specVersion),\n spec,\n );\n this.latest.set(onboarder, spec);\n }\n\n clear(): void {\n this.byVersion.clear();\n this.latest.clear();\n }\n}\n\n/** Module-level default cache (one per page). Injectable for tests/apps. */\nexport const defaultSpecCache = new OnboardingSpecCache();\n\n/**\n * Diff two spec versions' signup field sets — used by the 409 spec_stale\n * flow to tell the user WHAT changed. Compares by field key across all\n * signup steps.\n */\nexport interface SpecFieldDiff {\n added: string[];\n removed: string[];\n changed: string[];\n}\n\nfunction signupFieldMap(spec: OnboardingSpec): Map<string, SpecField> {\n const map = new Map<string, SpecField>();\n for (const step of spec.forms.signup.steps) {\n for (const field of step.fields) map.set(field.key, field);\n }\n return map;\n}\n\nexport function diffSpecFields(\n prev: OnboardingSpec,\n next: OnboardingSpec,\n): SpecFieldDiff {\n const prevMap = signupFieldMap(prev);\n const nextMap = signupFieldMap(next);\n const added: string[] = [];\n const removed: string[] = [];\n const changed: string[] = [];\n for (const key of nextMap.keys()) {\n if (!prevMap.has(key)) added.push(key);\n }\n for (const [key, prevField] of prevMap) {\n const nextField = nextMap.get(key);\n if (!nextField) {\n removed.push(key);\n continue;\n }\n if (JSON.stringify(prevField) !== JSON.stringify(nextField)) {\n changed.push(key);\n }\n }\n return {\n added: added.sort(),\n removed: removed.sort(),\n changed: changed.sort(),\n };\n}\n\nexport interface SpecFetchOptions {\n baseUrl: string;\n /**\n * Client-side cache key ONLY (never transmitted; trust is host-derived\n * per D536). Use the onboarder slug/id your embed is configured with.\n */\n onboarder: string;\n /** Custom fetch implementation (defaults to globalThis.fetch). */\n fetch?: typeof globalThis.fetch;\n /** Cache to read/write (defaults to the module-level cache). */\n cache?: OnboardingSpecCache;\n /**\n * Request timeout in ms (default 15s). A stalled intake aborts with\n * OnboardingNetworkError so the boot doesn't hang on \"Loading signup form…\".\n */\n timeoutMs?: number;\n /**\n * When true, return the cached \"latest\" for this onboarder if present\n * WITHOUT a network round-trip. Default false (spec fetches are cheap\n * and the server bumps specVersion on any change). The signup widget's\n * boot passes preferCached:true so a remount reuses the loaded spec.\n */\n preferCached?: boolean;\n}\n\nfunction buildUrl(baseUrl: string, path: string): string {\n const base = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n return `${base}${path}`;\n}\n\n/**\n * Fetch (and validate, and cache) the onboarding spec.\n *\n * @throws {OnboardingSpecInvalidError} response does not match D540 §1\n * @throws {OnboardingRateLimitError} on 429\n * @throws {OnboardingServerError} on any other non-2xx status\n * @throws {OnboardingNetworkError} on network failure OR timeout\n */\nexport async function fetchOnboardingSpec(\n options: SpecFetchOptions,\n): Promise<OnboardingSpec> {\n const cache = options.cache ?? defaultSpecCache;\n\n if (options.preferCached) {\n const cached = cache.getLatest(options.onboarder);\n if (cached) return cached;\n }\n\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const timeoutMs = options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const url = buildUrl(options.baseUrl, SPEC_PATH);\n\n let response: Response;\n try {\n response = await fetchWithTimeout(url, {\n method: \"GET\",\n timeoutMs,\n fetchImpl,\n });\n } catch (err) {\n throw new OnboardingNetworkError(err);\n }\n\n if (response.status === 429) {\n const retryAfterHeader = response.headers.get(\"retry-after\");\n const retryAfter = retryAfterHeader\n ? Number.parseInt(retryAfterHeader, 10)\n : Number.NaN;\n throw new OnboardingRateLimitError(\n Number.isNaN(retryAfter) ? null : retryAfter,\n );\n }\n if (response.status < 200 || response.status >= 300) {\n throw new OnboardingServerError(\n response.status,\n `Spec fetch failed with status ${response.status}`,\n );\n }\n\n let body: unknown;\n try {\n body = await response.json();\n } catch {\n throw new OnboardingSpecInvalidError(\"response body is not JSON\");\n }\n\n const parsed = validateOnboardingSpec(body);\n if (!parsed.success) {\n const detail = parsed.error.issues\n .slice(0, 5)\n .map((i) => `${i.path.join(\".\") || \"(root)\"}: ${i.message}`)\n .join(\"; \");\n throw new OnboardingSpecInvalidError(detail);\n }\n\n cache.set(options.onboarder, parsed.data);\n return parsed.data;\n}\n","import {\n OnboardingNetworkError,\n OnboardingServerError,\n OnboardingValidationError,\n} from \"../submit/errors.js\";\nimport {\n DEFAULT_REQUEST_TIMEOUT_MS,\n fetchWithTimeout,\n} from \"../submit/http.js\";\n\nexport interface PinStateResult {\n pin: string;\n stateIso: string | null;\n}\n\nexport async function fetchPinState(options: {\n baseUrl: string;\n pin: string;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}): Promise<PinStateResult> {\n const pin = options.pin.trim();\n if (!/^[1-9][0-9]{5}$/.test(pin)) {\n throw new OnboardingValidationError(\n \"PIN must be a 6-digit Indian PIN code\",\n );\n }\n // Every failure surfaces as a typed Onboarding error, as from the spec and\n // submit clients: a caller branches on the class, never on a raw TypeError\n // or a SyntaxError from a proxy's HTML error page.\n let response: Response;\n try {\n response = await fetchWithTimeout(\n `${options.baseUrl.replace(/\\/$/, \"\")}/api/v1/public/onboarding/pin-state?pin=${encodeURIComponent(pin)}`,\n {\n method: \"GET\",\n fetchImpl: options.fetch ?? globalThis.fetch,\n timeoutMs: options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,\n },\n );\n } catch (err) {\n throw new OnboardingNetworkError(err);\n }\n if (!response.ok) throw new OnboardingServerError(response.status);\n let value: unknown;\n try {\n value = await response.json();\n } catch {\n throw new OnboardingServerError(\n response.status,\n \"PIN-state response is not JSON\",\n );\n }\n // JSON that is not an object (`null`, a number, a string) is a bad answer\n // too, never a TypeError from reading its fields.\n if (typeof value !== \"object\" || value === null) {\n throw new OnboardingServerError(\n response.status,\n \"Invalid PIN-state response\",\n );\n }\n const answer = value as { pin?: unknown; state_iso?: unknown };\n if (\n answer.pin !== pin ||\n (answer.state_iso !== null && typeof answer.state_iso !== \"string\")\n ) {\n throw new OnboardingServerError(\n response.status,\n \"Invalid PIN-state response\",\n );\n }\n return { pin, stateIso: answer.state_iso };\n}\n"]}
@@ -1,5 +1,17 @@
1
1
  import { z } from 'zod/v3';
2
2
 
3
+ // src/consent/model.ts
4
+
5
+ // src/consent/url.ts
6
+ function isNavigableUrl(raw) {
7
+ try {
8
+ const { protocol } = new URL(raw, "https://relative.invalid/");
9
+ return protocol === "https:" || protocol === "http:";
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
3
15
  // src/consent/model.ts
4
16
  var CUSTOM_KEY_PATTERN = /^[A-Za-z0-9_-]+$/;
5
17
  var ACCEPTANCE_LEVELS = [
@@ -32,8 +44,16 @@ var consentDocumentSchema = z.object({
32
44
  // The SDK exposes contentHash so a consumer can display/verify integrity;
33
45
  // the server does NOT require it on the submit array.
34
46
  contentHash: z.string().min(1),
35
- // Short-TTL presigned GET for the artifact bytes (D543 §4 / 04-pii).
36
- downloadUrl: z.string().min(1),
47
+ // Short-TTL presigned GET for the artifact bytes (D543 §4 / 04-pii). It
48
+ // lands in an <a href> and the viewer's fetch, so only an http(s) URL or a
49
+ // relative one is accepted: a spec carrying `javascript:` fails closed.
50
+ downloadUrl: z.string().min(1).refine(isNavigableUrl, "downloadUrl must be an http(s) URL"),
51
+ // The artifact's stored MIME (e.g. "application/pdf"). The platform intake
52
+ // has served it since 2026-07-20 (tenant #334) so a renderer can pick a
53
+ // PDF viewer over a text body; D543 §4 does not list it, and a strict
54
+ // schema without it rejected every live spec (drift filed 2026-10-24).
55
+ // Optional: an onboarder that does not send it still parses.
56
+ contentType: z.string().min(1).optional(),
37
57
  acceptanceLevel: acceptanceLevelSchema,
38
58
  required: z.boolean()
39
59
  }).strict().superRefine((doc, ctx) => {
@@ -74,6 +94,6 @@ function consentDocKey(doc) {
74
94
  return doc.docType === "custom" ? `custom:${doc.customKey ?? ""}` : doc.docType;
75
95
  }
76
96
 
77
- export { ACCEPTANCE_LEVELS, DOC_TYPES, acceptanceLevelSchema, consentDocKey, consentDocumentSchema, consentPackSchema };
78
- //# sourceMappingURL=chunk-U56GQITG.js.map
79
- //# sourceMappingURL=chunk-U56GQITG.js.map
97
+ export { ACCEPTANCE_LEVELS, DOC_TYPES, acceptanceLevelSchema, consentDocKey, consentDocumentSchema, consentPackSchema, isNavigableUrl };
98
+ //# sourceMappingURL=chunk-NDSBIB3N.js.map
99
+ //# sourceMappingURL=chunk-NDSBIB3N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/consent/url.ts","../src/consent/model.ts"],"names":[],"mappings":";;;;;AAUO,SAAS,eAAe,GAAA,EAAsB;AACnD,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,QAAA,EAAS,GAAI,IAAI,GAAA,CAAI,KAAK,2BAA2B,CAAA;AAC7D,IAAA,OAAO,QAAA,KAAa,YAAY,QAAA,KAAa,OAAA;AAAA,EAC/C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;AC2CA,IAAM,kBAAA,GAAqB,kBAAA;AAGpB,IAAM,iBAAA,GAAoB;AAAA,EAC/B,UAAA;AAAA,EACA,oBAAA;AAAA,EACA;AACF;AAIO,IAAM,qBAAA,GAAwB,CAAA,CAAE,IAAA,CAAK,iBAAiB;AAGtD,IAAM,SAAA,GAAY,CAAC,KAAA,EAAO,SAAA,EAAW,OAAO,QAAQ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AA,CAAI,OAAA;AACV","file":"chunk-NDSBIB3N.js","sourcesContent":["/**\n * A document link the page may put in an `<a href>` or fetch: an http(s) URL,\n * absolute or relative. Any origin is fine: the intake's presigned links are\n * on the document store's own host. Anything else (`javascript:`, `data:`,\n * `vbscript:` …) is refused, so a tampered spec cannot run script in the host\n * page through a consent or privacy-notice link.\n *\n * The URL parser strips the whitespace and control characters a browser\n * ignores, so `\" javascript:…\"` and `\"java\\tscript:…\"` are refused too.\n */\nexport function isNavigableUrl(raw: string): boolean {\n try {\n const { protocol } = new URL(raw, \"https://relative.invalid/\");\n return protocol === \"https:\" || protocol === \"http:\";\n } catch {\n return false;\n }\n}\n","/**\n * D543 §4 ConsentPack spec model — the `consentPack` block that GET\n * /api/v1/public/onboarding/spec grows on top of the D540 shape:\n *\n * consentPack: {\n * documents: [\n * { doc_type, custom_key?, title, version_no, content_hash,\n * download_url, acceptance_level, required }\n * ]\n * }\n *\n * The intake projects ONLY `live` versions into this block (D543 §4);\n * `download_url` is a short-TTL presigned GET the SDK renders/opens.\n *\n * `acceptance_level` (D543 §2) is a per-document GATE:\n * - \"checkbox\" — a single accept checkbox (basic clickwrap).\n * - \"scroll_then_accept\" — accept disabled until the doc is scrolled to\n * the end (client asserts evidence.scrolled_to_end).\n * - \"open_then_accept\" — accept disabled until the doc is opened/viewed\n * (client asserts evidence.opened).\n * (E-signature is a deferred future level, D543 §2 — NOT modeled here.)\n *\n * FAIL-CLOSED (R1 + D543 §5 / D540 §1): a malformed consentPack throws\n * OnboardingSpecInvalidError at parse time — never rendered half-parsed\n * (a dropped `required` doc would let a user submit without consent, and a\n * missing `content_hash`/`version_no` would break the server's re-validation\n * match). The SDK refuses to render a consent step it cannot trust.\n *\n * DOM-ID HARDENING: a document's DOM-id token is derived from `doc_type`\n * (a fixed enum — safe) or, for custom docs, from `custom_key` (free-form\n * from the served spec). Custom keys are interpolated into element ids and\n * (historically) selectors by the widget layer, so they are constrained to\n * the SAME strict identifier alphabet as field keys (CUSTOM_KEY_PATTERN,\n * identical to the spec model's FIELD_KEY_PATTERN) and REJECTED at parse time\n * if they carry CSS/selector metacharacters. This is layer 1; the widget also\n * CSS.escapes every id token as defense-in-depth.\n *\n * SUBMIT PIN (P4): the submit array carries {legalDocumentId, versionNo,\n * accepted, evidence} — the server matches on legalDocumentId + versionNo\n * (contentHash is spec-side integrity metadata, NOT echoed on submit; a\n * content change publishes a new versionNo, so versionNo is a complete pin).\n *\n * DRIFT 5e3df7a3 (2026-07-14, consumer-visible) — RESOLVED by the canonical\n * shape: D543 §4 as literally written omitted `legal_document_id` from the\n * spec block, yet the submit array is KEYED on it (the server matches\n * legalDocumentId + versionNo against the live version). The\n * canonical alignment (both tiers, camelCase) INCLUDES `legalDocumentId` in\n * the spec `consentPack.documents[]`, exactly as the drift proposed. This\n * model REQUIRES it (fail-closed OnboardingSpecInvalidError if missing).\n */\n\nimport { z } from \"zod/v3\";\nimport { isNavigableUrl } from \"./url.js\";\n\n/**\n * DOM-id-safe custom-key alphabet. INTENTIONALLY identical to the spec\n * model's FIELD_KEY_PATTERN (`/^[A-Za-z0-9_-]+$/`), duplicated here rather\n * than imported to avoid a spec↔consent import cycle (spec/model.ts imports\n * consentPackSchema from this file). Any change to one must mirror the other.\n */\nconst CUSTOM_KEY_PATTERN = /^[A-Za-z0-9_-]+$/;\n\n/** D543 §2 acceptance-level enum. Extensible (adding a level is additive). */\nexport const ACCEPTANCE_LEVELS = [\n \"checkbox\",\n \"scroll_then_accept\",\n \"open_then_accept\",\n] as const;\n\nexport type AcceptanceLevel = (typeof ACCEPTANCE_LEVELS)[number];\n\nexport const acceptanceLevelSchema = z.enum(ACCEPTANCE_LEVELS);\n\n/** D543 §3 docType enum. */\nexport const DOC_TYPES = [\"tos\", \"privacy\", \"dpa\", \"custom\"] as const;\nexport type ConsentDocType = (typeof DOC_TYPES)[number];\n\n/**\n * One live legal document projected into the consent step. Mirrors the D543\n * §4 `consentPack.documents[]` element — CANONICAL camelCase wire shape (both\n * tenant + platform tiers aligned to this): { legalDocumentId, docType,\n * customKey (nullable), title, versionNo, contentHash, downloadUrl,\n * acceptanceLevel, required }. The `acceptanceLevel` enum VALUES stay snake\n * (checkbox | scroll_then_accept | open_then_accept).\n *\n * Cross-field invariant (D543 §3): `customKey` is a non-null identifier when\n * `docType === \"custom\"` and MUST be null otherwise (a canonical tos/privacy/\n * dpa doc is keyed by docType; only custom docs carry a key). The custom-key\n * alphabet is DOM-id safe.\n */\nexport const consentDocumentSchema = z\n .object({\n // Server-side opaque registry id (D543 §3 legal_documents.id). Echoed\n // verbatim on submit as consent.documents[].legalDocumentId (D543 §4);\n // the SDK never synthesizes it. See DRIFT 5e3df7a3 (module doc).\n legalDocumentId: z.string().min(1),\n docType: z.enum(DOC_TYPES),\n // Nullable (NOT omitted): non-custom docs send customKey:null.\n customKey: z\n .string()\n .min(1)\n .regex(\n CUSTOM_KEY_PATTERN,\n \"customKey must contain only letters, digits, underscore, or hyphen\",\n )\n .nullable(),\n title: z.string().min(1),\n // Monotonic version of the live document. This is the SUBMIT PIN: it is\n // echoed on submit (consent.documents[].versionNo) and the server matches\n // it against the current live version (mismatch ⇒ 409 consent_stale). Any\n // content change publishes a NEW version, so versionNo is a complete pin.\n versionNo: z.number().int().nonnegative(),\n // sha256 of the live artifact — spec-side integrity metadata (P4). NOT\n // echoed on submit: versionNo is the pin (a content change = new version),\n // so the submit array carries versionNo only, per the canonical wire shape.\n // The SDK exposes contentHash so a consumer can display/verify integrity;\n // the server does NOT require it on the submit array.\n contentHash: z.string().min(1),\n // Short-TTL presigned GET for the artifact bytes (D543 §4 / 04-pii). It\n // lands in an <a href> and the viewer's fetch, so only an http(s) URL or a\n // relative one is accepted: a spec carrying `javascript:` fails closed.\n downloadUrl: z\n .string()\n .min(1)\n .refine(isNavigableUrl, \"downloadUrl must be an http(s) URL\"),\n // The artifact's stored MIME (e.g. \"application/pdf\"). The platform intake\n // has served it since 2026-07-20 (tenant #334) so a renderer can pick a\n // PDF viewer over a text body; D543 §4 does not list it, and a strict\n // schema without it rejected every live spec (drift filed 2026-10-24).\n // Optional: an onboarder that does not send it still parses.\n contentType: z.string().min(1).optional(),\n acceptanceLevel: acceptanceLevelSchema,\n required: z.boolean(),\n })\n .strict()\n .superRefine((doc, ctx) => {\n if (doc.docType === \"custom\" && doc.customKey === null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: [\"customKey\"],\n message: \"customKey is required (non-null) when docType is 'custom'\",\n });\n }\n if (doc.docType !== \"custom\" && doc.customKey !== null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: [\"customKey\"],\n message: \"customKey must be null when docType is not 'custom'\",\n });\n }\n });\n\nexport type ConsentDocument = z.infer<typeof consentDocumentSchema>;\n\n/**\n * The `consentPack` block. `documents` may be empty (an onboarder with no\n * required legal docs) — the consent stage is then omitted from the flow.\n *\n * Uniqueness: no two documents may share the same STABLE key (docType, or\n * custom:<customKey> for custom docs). A duplicate would collide their DOM\n * ids AND their consent records — fail-closed at parse (the server keys the\n * registry on (scope, docType) / (scope, customKey) per D543 §3, so a\n * duplicate here is a projection bug, not a renderable spec).\n */\nexport const consentPackSchema = z\n .object({\n documents: z.array(consentDocumentSchema),\n })\n .strict()\n .superRefine((pack, ctx) => {\n const seen = new Set<string>();\n for (let i = 0; i < pack.documents.length; i++) {\n const doc = pack.documents[i];\n if (!doc) continue;\n const key = consentDocKey(doc);\n if (seen.has(key)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: [\"documents\", i],\n message: `duplicate consent document key \"${key}\"`,\n });\n }\n seen.add(key);\n }\n });\n\nexport type ConsentPack = z.infer<typeof consentPackSchema>;\n\n/**\n * Stable, collision-proof identity for a consent document, used as the map\n * key in the controller and the DOM-id token in the widget. `docType` is a\n * fixed enum; `custom:` is prefixed for custom docs so a customKey of\n * \"tos\" can never alias the canonical tos doc.\n *\n * Note: this is NOT the submit key — the submit array keys on the server's\n * opaque `legalDocumentId` (D543 §4), which the SDK does not synthesize.\n * This is a purely CLIENT-side identity for state + DOM.\n */\nexport function consentDocKey(doc: {\n docType: ConsentDocType;\n customKey?: string | null | undefined;\n}): string {\n return doc.docType === \"custom\"\n ? `custom:${doc.customKey ?? \"\"}`\n : doc.docType;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ // src/submit/subdomain.ts
2
+ var DNS_LABEL_RE = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
3
+ var SUBDOMAIN_SHAPE_MESSAGE = "Use letters, digits and hyphens only, with no hyphen at the start or end";
4
+ function isSubdomainLabelShape(raw) {
5
+ return DNS_LABEL_RE.test(raw.trim().toLowerCase());
6
+ }
7
+
8
+ export { SUBDOMAIN_SHAPE_MESSAGE, isSubdomainLabelShape };
9
+ //# sourceMappingURL=chunk-OLWR5COK.js.map
10
+ //# sourceMappingURL=chunk-OLWR5COK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/submit/subdomain.ts"],"names":[],"mappings":";AAUA,IAAM,YAAA,GAAe,sCAAA;AAEd,IAAM,uBAAA,GACX;AAEK,SAAS,sBAAsB,GAAA,EAAsB;AAC1D,EAAA,OAAO,aAAa,IAAA,CAAK,GAAA,CAAI,IAAA,EAAK,CAAE,aAAa,CAAA;AACnD","file":"chunk-OLWR5COK.js","sourcesContent":["/**\n * The workspace subdomain's shape (D836), checked before a submit so a\n * malformed label is a message on the field instead of a server refusal.\n *\n * Mirrors the intake's `normalizeSubdomainLabel` (nodii-tenant-service\n * src/services/tenancy/subdomain.ts): after trimming and lowercasing, a DNS\n * label of 1–63 characters from a-z, 0-9 and hyphens, with no hyphen at\n * either end. Upper case is fine; the intake lowercases it. Reservation and\n * availability stay the intake's call (`subdomain_taken`).\n */\nconst DNS_LABEL_RE = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;\n\nexport const SUBDOMAIN_SHAPE_MESSAGE =\n \"Use letters, digits and hyphens only, with no hyphen at the start or end\";\n\nexport function isSubdomainLabelShape(raw: string): boolean {\n return DNS_LABEL_RE.test(raw.trim().toLowerCase());\n}\n"]}