@wealthreach/site-kit 1.0.0 → 1.0.2
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 +21 -0
- package/dist/a11y/shell-client.js +1 -1
- package/dist/blog/index.d.ts +60 -9
- package/dist/blog/index.js +85 -12
- package/dist/next/config.cjs +1 -1
- package/dist/next/config.js +1 -1
- package/dist/next/draft-route.js +1 -1
- package/dist/next/leads-route.d.ts +12 -3
- package/dist/next/leads-route.js +14 -3
- package/package.json +1 -1
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
|
-
|
|
38
|
+
!config.visitors?.enabled && analytics ? /* @__PURE__ */ jsx(ConsentGate, { children: analytics }) : null
|
|
39
39
|
]
|
|
40
40
|
}
|
|
41
41
|
);
|
package/dist/blog/index.d.ts
CHANGED
|
@@ -3,15 +3,27 @@ import { SiteConfig } from '../config/index.js';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import '../regulatory-schema-uDKNJ7q8.js';
|
|
5
5
|
|
|
6
|
+
/** True when a blog file begins with a properly closed YAML frontmatter block (`---` or `---yaml`). */
|
|
7
|
+
declare function hasFrontmatterBlock(raw: string): boolean;
|
|
8
|
+
/** True when a file without a valid frontmatter block looks like malformed or non-YAML frontmatter. */
|
|
9
|
+
declare function looksLikeMalformedFrontmatter(raw: string): boolean;
|
|
10
|
+
/** Safely parses YAML frontmatter with gray-matter's JS/eval engines disabled. */
|
|
11
|
+
declare function parseSafeFrontmatter(raw: string): {
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
|
6
15
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
16
|
+
* Contract 3.5 / 3.8 blog post frontmatter schema:
|
|
17
|
+
* - Accepts `date` or `publishedAt` (normalizing `date` from `publishedAt` when omitted).
|
|
18
|
+
* - Holds are marked `status: "waiting"` or `published: false` (bare or quoted `"true"`/`"false"`).
|
|
19
|
+
* - Unknown `status` values fail closed in `isPostLive`.
|
|
9
20
|
*/
|
|
10
|
-
declare const postFrontmatterSchema: z.ZodObject<{
|
|
21
|
+
declare const postFrontmatterSchema: z.ZodPipe<z.ZodObject<{
|
|
11
22
|
title: z.ZodString;
|
|
12
23
|
description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
24
|
excerpt: z.ZodOptional<z.ZodString>;
|
|
14
|
-
date: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date
|
|
25
|
+
date: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
|
|
26
|
+
publishedAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
|
|
15
27
|
updatedAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
|
|
16
28
|
author: z.ZodOptional<z.ZodString>;
|
|
17
29
|
category: z.ZodOptional<z.ZodString>;
|
|
@@ -19,8 +31,46 @@ declare const postFrontmatterSchema: z.ZodObject<{
|
|
|
19
31
|
image: z.ZodOptional<z.ZodString>;
|
|
20
32
|
videoUrl: z.ZodOptional<z.ZodString>;
|
|
21
33
|
transcript: z.ZodOptional<z.ZodString>;
|
|
22
|
-
status: z.ZodOptional<z.
|
|
23
|
-
|
|
34
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
waiting: "waiting";
|
|
36
|
+
live: "live";
|
|
37
|
+
}>>;
|
|
38
|
+
published: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<z.ZodEnum<{
|
|
39
|
+
true: "true";
|
|
40
|
+
false: "false";
|
|
41
|
+
}>, z.ZodTransform<boolean, "true" | "false">>]>>;
|
|
42
|
+
}, z.core.$loose>, z.ZodTransform<{
|
|
43
|
+
date: string;
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
tags: string[];
|
|
47
|
+
excerpt?: string | undefined;
|
|
48
|
+
publishedAt?: string | undefined;
|
|
49
|
+
updatedAt?: string | undefined;
|
|
50
|
+
author?: string | undefined;
|
|
51
|
+
category?: string | undefined;
|
|
52
|
+
image?: string | undefined;
|
|
53
|
+
videoUrl?: string | undefined;
|
|
54
|
+
transcript?: string | undefined;
|
|
55
|
+
status?: "waiting" | "live" | undefined;
|
|
56
|
+
published?: boolean | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
[x: string]: unknown;
|
|
59
|
+
title: string;
|
|
60
|
+
description: string;
|
|
61
|
+
tags: string[];
|
|
62
|
+
excerpt?: string | undefined;
|
|
63
|
+
date?: string | undefined;
|
|
64
|
+
publishedAt?: string | undefined;
|
|
65
|
+
updatedAt?: string | undefined;
|
|
66
|
+
author?: string | undefined;
|
|
67
|
+
category?: string | undefined;
|
|
68
|
+
image?: string | undefined;
|
|
69
|
+
videoUrl?: string | undefined;
|
|
70
|
+
transcript?: string | undefined;
|
|
71
|
+
status?: "waiting" | "live" | undefined;
|
|
72
|
+
published?: boolean | undefined;
|
|
73
|
+
}>>;
|
|
24
74
|
type PostFrontmatter = z.infer<typeof postFrontmatterSchema>;
|
|
25
75
|
interface BlogPost {
|
|
26
76
|
slug: string;
|
|
@@ -29,7 +79,7 @@ interface BlogPost {
|
|
|
29
79
|
content: string;
|
|
30
80
|
}
|
|
31
81
|
|
|
32
|
-
/** Exact Contract 3.5 rule:
|
|
82
|
+
/** Exact Contract 3.5 rule: `published: false`, `status: "waiting"`, or any unknown status is not live. */
|
|
33
83
|
declare function isPostLive(postOrFrontmatter: Pick<BlogPost, "frontmatter"> | PostFrontmatter): boolean;
|
|
34
84
|
/**
|
|
35
85
|
* Exact log format parsed by WealthReach / Eve `post_not_served` diagnostics
|
|
@@ -74,9 +124,10 @@ declare function getPostBySlug(slug: string, options?: {
|
|
|
74
124
|
|
|
75
125
|
declare function buildPostJsonLd(post: BlogPost, config: SiteConfig): Record<string, unknown>;
|
|
76
126
|
|
|
77
|
-
declare const DRAFT_AUDIENCE_COOKIE = "
|
|
127
|
+
declare const DRAFT_AUDIENCE_COOKIE = "wr_draft_audience";
|
|
78
128
|
declare function isOwnerAudienceCookie(cookieValue: string | undefined): boolean;
|
|
79
129
|
declare function isDraftViewEnabled(isDraftMode: boolean): boolean;
|
|
130
|
+
declare function isOwnerDraftAudience(cookieValue: string | undefined): boolean;
|
|
80
131
|
|
|
81
132
|
/**
|
|
82
133
|
* Owner-only draft preview banner for `status: "waiting"` posts.
|
|
@@ -88,5 +139,5 @@ declare function DraftOwnerBanner({ slug, className, }: {
|
|
|
88
139
|
className?: string;
|
|
89
140
|
}): React.JSX.Element;
|
|
90
141
|
|
|
91
|
-
export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, isDraftViewEnabled, isOwnerAudienceCookie, isPostLive, loadPosts, logHiddenPost, postFrontmatterSchema };
|
|
142
|
+
export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, hasFrontmatterBlock, isDraftViewEnabled, isOwnerAudienceCookie, isOwnerDraftAudience, isPostLive, loadPosts, logHiddenPost, looksLikeMalformedFrontmatter, parseSafeFrontmatter, postFrontmatterSchema };
|
|
92
143
|
export type { BlogPost, PostFrontmatter, PostSource };
|
package/dist/blog/index.js
CHANGED
|
@@ -1,24 +1,71 @@
|
|
|
1
1
|
// src/blog/frontmatter.ts
|
|
2
|
+
import matter from "gray-matter";
|
|
2
3
|
import { z } from "zod";
|
|
4
|
+
var dateField = z.union([z.string().trim().min(1), z.date()]).transform((v) => v instanceof Date ? v.toISOString().slice(0, 10) : v);
|
|
5
|
+
var publishedField = z.union([
|
|
6
|
+
z.boolean(),
|
|
7
|
+
z.enum(["true", "false"]).transform((v) => v === "true")
|
|
8
|
+
]);
|
|
9
|
+
var FRONTMATTER_BLOCK_RE = /^(?:\uFEFF)?---(?:[ \t]*(?:yaml|yml))?[ \t]*\r?\n([\s\S]*?)^---[ \t]*\r?(?:\n|$)/m;
|
|
10
|
+
var MALFORMED_FRONTMATTER_RE = /^(?:\uFEFF)?(?:---(?!-)|(?:status|published):)/;
|
|
11
|
+
var SAFE_MATTER_OPTIONS = {
|
|
12
|
+
engines: {
|
|
13
|
+
js: () => {
|
|
14
|
+
throw new Error("JavaScript frontmatter engine is disabled for security.");
|
|
15
|
+
},
|
|
16
|
+
javascript: () => {
|
|
17
|
+
throw new Error("JavaScript frontmatter engine is disabled for security.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function hasFrontmatterBlock(raw) {
|
|
22
|
+
const match = raw.match(FRONTMATTER_BLOCK_RE);
|
|
23
|
+
return Boolean(match && match.index === 0);
|
|
24
|
+
}
|
|
25
|
+
function looksLikeMalformedFrontmatter(raw) {
|
|
26
|
+
return !hasFrontmatterBlock(raw) && MALFORMED_FRONTMATTER_RE.test(raw.slice(0, 1024));
|
|
27
|
+
}
|
|
28
|
+
function parseSafeFrontmatter(raw) {
|
|
29
|
+
const parsed = matter(raw, SAFE_MATTER_OPTIONS);
|
|
30
|
+
return {
|
|
31
|
+
data: parsed.data ?? {},
|
|
32
|
+
content: parsed.content
|
|
33
|
+
};
|
|
34
|
+
}
|
|
3
35
|
var postFrontmatterSchema = z.object({
|
|
4
36
|
title: z.string().trim().min(1),
|
|
5
37
|
description: z.string().trim().optional().default(""),
|
|
6
38
|
excerpt: z.string().trim().optional(),
|
|
7
|
-
date:
|
|
8
|
-
|
|
39
|
+
date: dateField.optional(),
|
|
40
|
+
publishedAt: dateField.optional(),
|
|
41
|
+
updatedAt: dateField.optional(),
|
|
9
42
|
author: z.string().trim().optional(),
|
|
10
43
|
category: z.string().trim().optional(),
|
|
11
44
|
tags: z.array(z.string().trim().min(1)).optional().default([]),
|
|
12
45
|
image: z.string().trim().optional(),
|
|
13
46
|
videoUrl: z.string().trim().optional(),
|
|
14
47
|
transcript: z.string().optional(),
|
|
15
|
-
status: z.
|
|
16
|
-
|
|
48
|
+
status: z.enum(["waiting", "live"]).optional(),
|
|
49
|
+
published: publishedField.optional()
|
|
50
|
+
}).passthrough().superRefine((data, ctx) => {
|
|
51
|
+
if (!data.date && !data.publishedAt) {
|
|
52
|
+
ctx.addIssue({
|
|
53
|
+
code: z.ZodIssueCode.custom,
|
|
54
|
+
path: ["date"],
|
|
55
|
+
message: "Post frontmatter requires either `date` or `publishedAt`."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}).transform((data) => ({
|
|
59
|
+
...data,
|
|
60
|
+
date: data.date ?? data.publishedAt
|
|
61
|
+
}));
|
|
17
62
|
|
|
18
63
|
// src/blog/visibility.ts
|
|
19
64
|
function isPostLive(postOrFrontmatter) {
|
|
20
65
|
const fm = "frontmatter" in postOrFrontmatter && postOrFrontmatter.frontmatter !== null && typeof postOrFrontmatter.frontmatter === "object" ? postOrFrontmatter.frontmatter : postOrFrontmatter;
|
|
21
|
-
|
|
66
|
+
if (fm.published === false || fm.published === "false") return false;
|
|
67
|
+
if (fm.status !== void 0 && fm.status !== "live") return false;
|
|
68
|
+
return true;
|
|
22
69
|
}
|
|
23
70
|
function logHiddenPost(slug, reason) {
|
|
24
71
|
console.warn(`hiding "${slug}": ${reason}`);
|
|
@@ -37,13 +84,15 @@ function assertPostReadable(post, options) {
|
|
|
37
84
|
// src/blog/source.ts
|
|
38
85
|
import fs from "fs";
|
|
39
86
|
import path from "path";
|
|
40
|
-
import matter from "gray-matter";
|
|
41
87
|
var POST_EXT_RE = /\.(?:mdx|md)$/i;
|
|
42
88
|
function createFileSystemPostSource(options) {
|
|
43
89
|
const baseDir = path.resolve(
|
|
44
90
|
options?.cwd ?? process.cwd(),
|
|
45
91
|
options?.postsDir ?? "data/blog"
|
|
46
92
|
);
|
|
93
|
+
function slugToTitle(slug) {
|
|
94
|
+
return slug.replace(/[-_]+/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase());
|
|
95
|
+
}
|
|
47
96
|
function parseFile(filePath, slug) {
|
|
48
97
|
try {
|
|
49
98
|
const raw = fs.readFileSync(
|
|
@@ -51,7 +100,24 @@ function createFileSystemPostSource(options) {
|
|
|
51
100
|
filePath,
|
|
52
101
|
"utf8"
|
|
53
102
|
);
|
|
54
|
-
|
|
103
|
+
if (!hasFrontmatterBlock(raw)) {
|
|
104
|
+
if (looksLikeMalformedFrontmatter(raw)) {
|
|
105
|
+
logHiddenPost(slug, "malformed frontmatter block");
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
slug,
|
|
110
|
+
filePath,
|
|
111
|
+
frontmatter: {
|
|
112
|
+
title: slugToTitle(slug),
|
|
113
|
+
description: "",
|
|
114
|
+
date: "",
|
|
115
|
+
tags: []
|
|
116
|
+
},
|
|
117
|
+
content: raw
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const { data, content } = parseSafeFrontmatter(raw);
|
|
55
121
|
const parsed = postFrontmatterSchema.safeParse(data);
|
|
56
122
|
if (!parsed.success) {
|
|
57
123
|
logHiddenPost(
|
|
@@ -183,13 +249,16 @@ function buildPostJsonLd(post, config) {
|
|
|
183
249
|
}
|
|
184
250
|
|
|
185
251
|
// src/blog/draft-view.ts
|
|
186
|
-
var DRAFT_AUDIENCE_COOKIE = "
|
|
252
|
+
var DRAFT_AUDIENCE_COOKIE = "wr_draft_audience";
|
|
187
253
|
function isOwnerAudienceCookie(cookieValue) {
|
|
188
254
|
return cookieValue === "owner";
|
|
189
255
|
}
|
|
190
256
|
function isDraftViewEnabled(isDraftMode) {
|
|
191
257
|
return process.env.NODE_ENV === "development" || isDraftMode;
|
|
192
258
|
}
|
|
259
|
+
function isOwnerDraftAudience(cookieValue) {
|
|
260
|
+
return process.env.NODE_ENV === "development" || isOwnerAudienceCookie(cookieValue);
|
|
261
|
+
}
|
|
193
262
|
|
|
194
263
|
// src/blog/draft-banner.tsx
|
|
195
264
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -214,11 +283,11 @@ function DraftOwnerBanner({
|
|
|
214
283
|
fontWeight: 500
|
|
215
284
|
},
|
|
216
285
|
children: [
|
|
217
|
-
"Draft
|
|
286
|
+
/* @__PURE__ */ jsx("span", { children: "Draft \u2014 not on your live site." }),
|
|
287
|
+
" ",
|
|
288
|
+
"Visitors can't see this post yet",
|
|
218
289
|
slug ? ` (${slug})` : "",
|
|
219
|
-
"
|
|
220
|
-
/* @__PURE__ */ jsx("code", { children: 'status: "waiting"' }),
|
|
221
|
-
") and is not visible to public visitors until published in WealthReach."
|
|
290
|
+
"."
|
|
222
291
|
]
|
|
223
292
|
}
|
|
224
293
|
);
|
|
@@ -230,10 +299,14 @@ export {
|
|
|
230
299
|
buildPostJsonLd,
|
|
231
300
|
createFileSystemPostSource,
|
|
232
301
|
getPostBySlug,
|
|
302
|
+
hasFrontmatterBlock,
|
|
233
303
|
isDraftViewEnabled,
|
|
234
304
|
isOwnerAudienceCookie,
|
|
305
|
+
isOwnerDraftAudience,
|
|
235
306
|
isPostLive,
|
|
236
307
|
loadPosts,
|
|
237
308
|
logHiddenPost,
|
|
309
|
+
looksLikeMalformedFrontmatter,
|
|
310
|
+
parseSafeFrontmatter,
|
|
238
311
|
postFrontmatterSchema
|
|
239
312
|
};
|
package/dist/next/config.cjs
CHANGED
|
@@ -71,7 +71,7 @@ var SECURITY_HEADERS = buildSecurityHeaders({
|
|
|
71
71
|
includeFrameOptions: true
|
|
72
72
|
});
|
|
73
73
|
function isSandboxOrDev() {
|
|
74
|
-
return process.env.NODE_ENV
|
|
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 {
|
package/dist/next/config.js
CHANGED
|
@@ -43,7 +43,7 @@ var SECURITY_HEADERS = buildSecurityHeaders({
|
|
|
43
43
|
includeFrameOptions: true
|
|
44
44
|
});
|
|
45
45
|
function isSandboxOrDev() {
|
|
46
|
-
return process.env.NODE_ENV
|
|
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 {
|
package/dist/next/draft-route.js
CHANGED
|
@@ -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 = "
|
|
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
|
|
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 (
|
|
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 };
|
package/dist/next/leads-route.js
CHANGED
|
@@ -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:
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|