@wealthreach/site-kit 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # `@wealthreach/site-kit`
2
+
3
+ Shared runtime plumbing for WealthReach Next.js 16 advisor websites. **Standardizes plumbing, never presentation.**
4
+
5
+ ## Subpath Exports
6
+
7
+ - `@wealthreach/site-kit/config` — Contract v3.8+ `siteConfigSchema`, `defineSiteConfig()`, `normalizeSiteConfig()`, `buildMetadata()`, `buildOrganizationJsonLd()`
8
+ - `@wealthreach/site-kit/disclosures` — Signed ENG-1460 regulatory disclosure generator (all 9 registration kinds) + `disclosureRegionProps()` / `disclosureLinkProps()`
9
+ - `@wealthreach/site-kit/consent` — Unified geo-aware consent engine (`wr_consent`, `privacy_mode`, GPC, legacy cookie migration, `/api/privacy-mode` 304 fallback, `<ConsentProvider>`, `<ConsentGate>`, `<ConsentBanner />`, `<PrivacyChoicesButton />`)
10
+ - `@wealthreach/site-kit/analytics` — First-touch UTM/gclid/referrer capture, consent-gated first-party + GTM `dataLayer` tracking, `<BookingEmbed />` + `useBookingTracker()`
11
+ - `@wealthreach/site-kit/forms` — Universal `useWealthReachForm()`, `<WealthReachForm>`, `<WealthReachHiddenContext>` (for Server Actions), automatic field packing + sensitive PII key blocklist
12
+ - `@wealthreach/site-kit/a11y` & `/a11y/client` — Static-SSG-safe `<SiteShell>`, `:focus-visible` `<SkipLink>`, `useAccessibleDialog()`
13
+ - `@wealthreach/site-kit/blog` & `/mdx` — Exact Contract 3.5 `status: "waiting"` hold gate, `isPostLive()`, `assertPostReadable()`, `isDraftViewEnabled()`, `isOwnerDraftAudience()`, `<DraftOwnerBanner />`, `buildPostJsonLd()`, `safeUrl()`, `rehypeSafeUrls()`
14
+ - `@wealthreach/site-kit/next`, `/next/proxy`, `/next/privacy-mode`, `/next/leads`, `/next/draft` — `withWealthReach()` (sandbox-safe), Edge geo proxy, `/api/privacy-mode` 304 fallback route, `/api/leads` handler + `submitLeadToWealthReach()`, and timing-safe `/api/draft` door
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @wealthreach/site-kit
20
+ npm install -D @wealthreach/site-cli
21
+ ```
@@ -35,7 +35,7 @@ function SiteShellClient({
35
35
  footer,
36
36
  consentBanner !== void 0 ? consentBanner : /* @__PURE__ */ jsx(ConsentBanner, {}),
37
37
  /* @__PURE__ */ jsx(PageTracker, {}),
38
- analytics && /* @__PURE__ */ jsx(ConsentGate, { children: analytics })
38
+ !config.visitors?.enabled && analytics ? /* @__PURE__ */ jsx(ConsentGate, { children: analytics }) : null
39
39
  ]
40
40
  }
41
41
  );
@@ -4,14 +4,17 @@ import React from 'react';
4
4
  import '../regulatory-schema-uDKNJ7q8.js';
5
5
 
6
6
  /**
7
- * Exact Contract 3.5 waiting-post hold spelling:
8
- * A held post carries `status: "waiting"` — omitted means live.
7
+ * Contract 3.5 blog post frontmatter schema:
8
+ * - Accepts `date` or `publishedAt` (normalizing `date` from `publishedAt` when omitted).
9
+ * - Holds are marked `status: "waiting"` (or legacy `published: false`).
10
+ * - Unknown `status` values fail closed in `isPostLive`.
9
11
  */
10
- declare const postFrontmatterSchema: z.ZodObject<{
12
+ declare const postFrontmatterSchema: z.ZodPipe<z.ZodObject<{
11
13
  title: z.ZodString;
12
14
  description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
13
15
  excerpt: z.ZodOptional<z.ZodString>;
14
- date: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>;
16
+ date: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
17
+ publishedAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
15
18
  updatedAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
16
19
  author: z.ZodOptional<z.ZodString>;
17
20
  category: z.ZodOptional<z.ZodString>;
@@ -19,8 +22,43 @@ declare const postFrontmatterSchema: z.ZodObject<{
19
22
  image: z.ZodOptional<z.ZodString>;
20
23
  videoUrl: z.ZodOptional<z.ZodString>;
21
24
  transcript: z.ZodOptional<z.ZodString>;
22
- status: z.ZodOptional<z.ZodLiteral<"waiting">>;
23
- }, z.core.$loose>;
25
+ status: z.ZodOptional<z.ZodEnum<{
26
+ waiting: "waiting";
27
+ live: "live";
28
+ }>>;
29
+ published: z.ZodOptional<z.ZodBoolean>;
30
+ }, z.core.$loose>, z.ZodTransform<{
31
+ date: string;
32
+ title: string;
33
+ description: string;
34
+ tags: string[];
35
+ excerpt?: string | undefined;
36
+ publishedAt?: string | undefined;
37
+ updatedAt?: string | undefined;
38
+ author?: string | undefined;
39
+ category?: string | undefined;
40
+ image?: string | undefined;
41
+ videoUrl?: string | undefined;
42
+ transcript?: string | undefined;
43
+ status?: "waiting" | "live" | undefined;
44
+ published?: boolean | undefined;
45
+ }, {
46
+ [x: string]: unknown;
47
+ title: string;
48
+ description: string;
49
+ tags: string[];
50
+ excerpt?: string | undefined;
51
+ date?: string | undefined;
52
+ publishedAt?: string | undefined;
53
+ updatedAt?: string | undefined;
54
+ author?: string | undefined;
55
+ category?: string | undefined;
56
+ image?: string | undefined;
57
+ videoUrl?: string | undefined;
58
+ transcript?: string | undefined;
59
+ status?: "waiting" | "live" | undefined;
60
+ published?: boolean | undefined;
61
+ }>>;
24
62
  type PostFrontmatter = z.infer<typeof postFrontmatterSchema>;
25
63
  interface BlogPost {
26
64
  slug: string;
@@ -29,7 +67,7 @@ interface BlogPost {
29
67
  content: string;
30
68
  }
31
69
 
32
- /** Exact Contract 3.5 rule: a post is live iff `status` is not `"waiting"`. */
70
+ /** Exact Contract 3.5 rule: `published: false`, `status: "waiting"`, or any unknown status is not live. */
33
71
  declare function isPostLive(postOrFrontmatter: Pick<BlogPost, "frontmatter"> | PostFrontmatter): boolean;
34
72
  /**
35
73
  * Exact log format parsed by WealthReach / Eve `post_not_served` diagnostics
@@ -74,9 +112,10 @@ declare function getPostBySlug(slug: string, options?: {
74
112
 
75
113
  declare function buildPostJsonLd(post: BlogPost, config: SiteConfig): Record<string, unknown>;
76
114
 
77
- declare const DRAFT_AUDIENCE_COOKIE = "__wr_draft_audience";
115
+ declare const DRAFT_AUDIENCE_COOKIE = "wr_draft_audience";
78
116
  declare function isOwnerAudienceCookie(cookieValue: string | undefined): boolean;
79
117
  declare function isDraftViewEnabled(isDraftMode: boolean): boolean;
118
+ declare function isOwnerDraftAudience(cookieValue: string | undefined): boolean;
80
119
 
81
120
  /**
82
121
  * Owner-only draft preview banner for `status: "waiting"` posts.
@@ -88,5 +127,5 @@ declare function DraftOwnerBanner({ slug, className, }: {
88
127
  className?: string;
89
128
  }): React.JSX.Element;
90
129
 
91
- export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, isDraftViewEnabled, isOwnerAudienceCookie, isPostLive, loadPosts, logHiddenPost, postFrontmatterSchema };
130
+ export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, isDraftViewEnabled, isOwnerAudienceCookie, isOwnerDraftAudience, isPostLive, loadPosts, logHiddenPost, postFrontmatterSchema };
92
131
  export type { BlogPost, PostFrontmatter, PostSource };
@@ -1,24 +1,40 @@
1
1
  // src/blog/frontmatter.ts
2
2
  import { z } from "zod";
3
+ var dateField = z.union([z.string().trim().min(1), z.date()]).transform((v) => v instanceof Date ? v.toISOString().slice(0, 10) : v);
3
4
  var postFrontmatterSchema = z.object({
4
5
  title: z.string().trim().min(1),
5
6
  description: z.string().trim().optional().default(""),
6
7
  excerpt: z.string().trim().optional(),
7
- date: z.union([z.string().trim().min(1), z.date()]).transform((v) => v instanceof Date ? v.toISOString().slice(0, 10) : v),
8
- updatedAt: z.union([z.string().trim().min(1), z.date()]).transform((v) => v instanceof Date ? v.toISOString().slice(0, 10) : v).optional(),
8
+ date: dateField.optional(),
9
+ publishedAt: dateField.optional(),
10
+ updatedAt: dateField.optional(),
9
11
  author: z.string().trim().optional(),
10
12
  category: z.string().trim().optional(),
11
13
  tags: z.array(z.string().trim().min(1)).optional().default([]),
12
14
  image: z.string().trim().optional(),
13
15
  videoUrl: z.string().trim().optional(),
14
16
  transcript: z.string().optional(),
15
- status: z.literal("waiting").optional()
16
- }).passthrough();
17
+ status: z.enum(["waiting", "live"]).optional(),
18
+ published: z.boolean().optional()
19
+ }).passthrough().superRefine((data, ctx) => {
20
+ if (!data.date && !data.publishedAt) {
21
+ ctx.addIssue({
22
+ code: z.ZodIssueCode.custom,
23
+ path: ["date"],
24
+ message: "Post frontmatter requires either `date` or `publishedAt`."
25
+ });
26
+ }
27
+ }).transform((data) => ({
28
+ ...data,
29
+ date: data.date ?? data.publishedAt
30
+ }));
17
31
 
18
32
  // src/blog/visibility.ts
19
33
  function isPostLive(postOrFrontmatter) {
20
34
  const fm = "frontmatter" in postOrFrontmatter && postOrFrontmatter.frontmatter !== null && typeof postOrFrontmatter.frontmatter === "object" ? postOrFrontmatter.frontmatter : postOrFrontmatter;
21
- return fm.status !== "waiting";
35
+ if (fm.published === false) return false;
36
+ if (fm.status !== void 0 && fm.status !== "live") return false;
37
+ return true;
22
38
  }
23
39
  function logHiddenPost(slug, reason) {
24
40
  console.warn(`hiding "${slug}": ${reason}`);
@@ -183,13 +199,16 @@ function buildPostJsonLd(post, config) {
183
199
  }
184
200
 
185
201
  // src/blog/draft-view.ts
186
- var DRAFT_AUDIENCE_COOKIE = "__wr_draft_audience";
202
+ var DRAFT_AUDIENCE_COOKIE = "wr_draft_audience";
187
203
  function isOwnerAudienceCookie(cookieValue) {
188
204
  return cookieValue === "owner";
189
205
  }
190
206
  function isDraftViewEnabled(isDraftMode) {
191
207
  return process.env.NODE_ENV === "development" || isDraftMode;
192
208
  }
209
+ function isOwnerDraftAudience(cookieValue) {
210
+ return process.env.NODE_ENV === "development" || isOwnerAudienceCookie(cookieValue);
211
+ }
193
212
 
194
213
  // src/blog/draft-banner.tsx
195
214
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -214,11 +233,11 @@ function DraftOwnerBanner({
214
233
  fontWeight: 500
215
234
  },
216
235
  children: [
217
- "Draft preview",
236
+ /* @__PURE__ */ jsx("span", { children: "Draft \u2014 not on your live site." }),
237
+ " ",
238
+ "Visitors can't see this post yet",
218
239
  slug ? ` (${slug})` : "",
219
- ": this post is held (",
220
- /* @__PURE__ */ jsx("code", { children: 'status: "waiting"' }),
221
- ") and is not visible to public visitors until published in WealthReach."
240
+ "."
222
241
  ]
223
242
  }
224
243
  );
@@ -232,6 +251,7 @@ export {
232
251
  getPostBySlug,
233
252
  isDraftViewEnabled,
234
253
  isOwnerAudienceCookie,
254
+ isOwnerDraftAudience,
235
255
  isPostLive,
236
256
  loadPosts,
237
257
  logHiddenPost,
@@ -71,7 +71,7 @@ var SECURITY_HEADERS = buildSecurityHeaders({
71
71
  includeFrameOptions: true
72
72
  });
73
73
  function isSandboxOrDev() {
74
- return process.env.NODE_ENV !== "production" || process.env.WR_SANDBOX === "1" || process.env.WR_SANDBOX_PREVIEW === "1";
74
+ return process.env.NODE_ENV === "development" || process.env.WR_SANDBOX === "1" || process.env.WR_SANDBOX_PREVIEW === "1";
75
75
  }
76
76
  function withWealthReach(options = {}) {
77
77
  const {
@@ -43,7 +43,7 @@ var SECURITY_HEADERS = buildSecurityHeaders({
43
43
  includeFrameOptions: true
44
44
  });
45
45
  function isSandboxOrDev() {
46
- return process.env.NODE_ENV !== "production" || process.env.WR_SANDBOX === "1" || process.env.WR_SANDBOX_PREVIEW === "1";
46
+ return process.env.NODE_ENV === "development" || process.env.WR_SANDBOX === "1" || process.env.WR_SANDBOX_PREVIEW === "1";
47
47
  }
48
48
  function withWealthReach(options = {}) {
49
49
  const {
@@ -4,7 +4,7 @@ import { cookies, draftMode } from "next/headers";
4
4
  import { redirect } from "next/navigation";
5
5
 
6
6
  // src/blog/draft-view.ts
7
- var DRAFT_AUDIENCE_COOKIE = "__wr_draft_audience";
7
+ var DRAFT_AUDIENCE_COOKIE = "wr_draft_audience";
8
8
 
9
9
  // src/next/draft-route.ts
10
10
  function safeRelativePath(raw) {
@@ -61,12 +61,19 @@ interface SubmitLeadToWealthReachArgs {
61
61
  sourceUrl: string;
62
62
  attribution?: AttributionSnapshot;
63
63
  websiteVisit?: WebsiteVisitSnapshot;
64
- /** Default true so site-kit forms notify advisors via WealthReach unless a custom route handles emails locally. */
64
+ /** Default true when a server secret (`WR_DRAFT_SECRET` / `WR_SITE_LEADS_SECRET`) is available so WealthReach notifies advisors securely. */
65
65
  notifyAdvisor?: boolean;
66
+ /** Optional server-only secret override for signing `x-wr-site-signature` (defaults to `WR_SITE_LEADS_SECRET` or `WR_DRAFT_SECRET`). */
67
+ notifySecret?: string;
66
68
  /** Override synthetic check mode (auto-enabled when WR_SANDBOX=1 or WR_SYNTHETIC_LEADS=1). */
67
69
  syntheticCheck?: boolean;
68
70
  fetchImpl?: typeof fetch;
69
71
  }
72
+ declare function computeSiteLeadNotifySignature(input: {
73
+ siteId: string;
74
+ advisorId: string;
75
+ submissionId: string;
76
+ }, secret: string): string;
70
77
  type SubmitLeadResult = {
71
78
  ok: true;
72
79
  leadId: string;
@@ -109,8 +116,10 @@ declare function extractWealthReachContext(formData: FormData, fallback: {
109
116
  interface LeadRouteHandlerOptions {
110
117
  /** Verify Cloudflare Turnstile when TURNSTILE_SECRET_KEY is configured (default true). */
111
118
  verifyTurnstile?: boolean;
112
- /** Have WealthReach email the advisor (default true; set false if onAfterCapture sends a custom CC email). */
119
+ /** Have WealthReach email the advisor when a server secret (`WR_DRAFT_SECRET`) is configured (set false if onAfterCapture sends a custom CC email). */
113
120
  notifyAdvisor?: boolean;
121
+ /** Optional server-only secret override for `x-wr-site-signature`. */
122
+ notifySecret?: string;
114
123
  /** Optional downstream hook (e.g. Zapier/Slack, custom fit routing, team CC) run AFTER WealthReach confirms capture. */
115
124
  onAfterCapture?: (ctx: {
116
125
  leadId: string;
@@ -125,5 +134,5 @@ interface LeadRouteHandlerOptions {
125
134
  */
126
135
  declare function createLeadRouteHandler(getConfig: () => SiteConfig, options?: LeadRouteHandlerOptions): (request: Request) => Promise<Response>;
127
136
 
128
- export { createLeadRouteHandler, extractWealthReachContext, resolveSiteLeadsEndpoint, submitLeadToWealthReach };
137
+ export { computeSiteLeadNotifySignature, createLeadRouteHandler, extractWealthReachContext, resolveSiteLeadsEndpoint, submitLeadToWealthReach };
129
138
  export type { ExtractedWealthReachContext, LeadRouteHandlerOptions, SubmitLeadResult, SubmitLeadToWealthReachArgs };
@@ -1,5 +1,5 @@
1
1
  // src/next/leads-route.ts
2
- import { randomUUID } from "crypto";
2
+ import { createHmac, randomUUID } from "crypto";
3
3
  import { NextResponse } from "next/server";
4
4
 
5
5
  // src/config/schema.ts
@@ -513,6 +513,11 @@ async function verifyTurnstile(token, remoteIp) {
513
513
  return { ok: false, reason: "verify_error" };
514
514
  }
515
515
  }
516
+ function computeSiteLeadNotifySignature(input, secret) {
517
+ return createHmac("sha256", secret).update(
518
+ `site-leads-notify:${input.siteId.toLowerCase()}:${input.advisorId.toLowerCase()}:${input.submissionId}`
519
+ ).digest("hex");
520
+ }
516
521
  async function submitLeadToWealthReach(args) {
517
522
  const { config } = args;
518
523
  const siteId = config.siteId?.trim();
@@ -531,6 +536,9 @@ async function submitLeadToWealthReach(args) {
531
536
  };
532
537
  }
533
538
  const isSynthetic = args.syntheticCheck ?? (process.env.WR_SANDBOX === "1" || process.env.WR_SYNTHETIC_LEADS === "1");
539
+ const notifySecret = args.notifySecret?.trim() || process.env.WR_SITE_LEADS_SECRET?.trim() || process.env.WR_DRAFT_SECRET?.trim() || "";
540
+ const wantsNotify = args.notifyAdvisor ?? Boolean(notifySecret);
541
+ const siteSignature = wantsNotify && notifySecret ? computeSiteLeadNotifySignature({ siteId, advisorId, submissionId }, notifySecret) : "";
534
542
  const payload = {
535
543
  siteId,
536
544
  advisorId,
@@ -542,7 +550,7 @@ async function submitLeadToWealthReach(args) {
542
550
  ...args.phone ? { phone: args.phone } : {},
543
551
  ...args.message ? { message: args.message } : {},
544
552
  ...args.customFields && Object.keys(args.customFields).length > 0 ? { customFields: args.customFields } : {},
545
- notifyAdvisor: args.notifyAdvisor ?? true,
553
+ notifyAdvisor: wantsNotify,
546
554
  sourceUrl: args.sourceUrl,
547
555
  attribution: args.attribution ?? {},
548
556
  ...args.websiteVisit ? { websiteVisit: args.websiteVisit } : {}
@@ -554,6 +562,7 @@ async function submitLeadToWealthReach(args) {
554
562
  headers: {
555
563
  "Content-Type": "application/json",
556
564
  "x-api-key": apiKey,
565
+ ...siteSignature ? { "x-wr-site-signature": siteSignature } : {},
557
566
  ...isSynthetic ? { "x-wr-synthetic-check": "1" } : {}
558
567
  },
559
568
  body: JSON.stringify(payload)
@@ -725,7 +734,8 @@ function createLeadRouteHandler(getConfig, options) {
725
734
  const result = await submitLeadToWealthReach({
726
735
  config,
727
736
  ...submission,
728
- notifyAdvisor: options?.notifyAdvisor ?? true,
737
+ ...options?.notifyAdvisor !== void 0 ? { notifyAdvisor: options.notifyAdvisor } : {},
738
+ ...options?.notifySecret ? { notifySecret: options.notifySecret } : {},
729
739
  fetchImpl: options?.fetchImpl
730
740
  });
731
741
  if (!result.ok) {
@@ -753,6 +763,7 @@ function createLeadRouteHandler(getConfig, options) {
753
763
  };
754
764
  }
755
765
  export {
766
+ computeSiteLeadNotifySignature,
756
767
  createLeadRouteHandler,
757
768
  extractWealthReachContext,
758
769
  resolveSiteLeadsEndpoint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wealthreach/site-kit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Shared compliance, universal form tracking, BrandywineOak consent, WCAG 2.2 AA accessibility, blog/draft, and Next.js plumbing for bespoke WealthReach advisor sites.",
5
5
  "license": "MIT",
6
6
  "type": "module",