@wealthreach/site-kit 1.0.3 → 1.1.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.
- package/dist/a11y/index.d.ts +32 -3
- package/dist/a11y/index.js +67 -2
- package/dist/next/config.cjs +13 -1
- package/dist/next/config.d.cts +2 -0
- package/dist/next/config.d.ts +2 -0
- package/dist/next/config.js +13 -1
- package/dist/next/leads-route.d.ts +21 -1
- package/dist/next/leads-route.js +73 -12
- package/package.json +2 -1
package/dist/a11y/index.d.ts
CHANGED
|
@@ -14,6 +14,20 @@ interface SkipLinkProps {
|
|
|
14
14
|
*/
|
|
15
15
|
declare function SkipLink({ targetId, label, className, }: SkipLinkProps): React.JSX.Element;
|
|
16
16
|
|
|
17
|
+
interface BotIdProtectedRoute {
|
|
18
|
+
path: string;
|
|
19
|
+
method: string;
|
|
20
|
+
advancedOptions?: {
|
|
21
|
+
checkLevel?: "basic" | "deepAnalysis";
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
declare const DEFAULT_BOTID_PROTECTED_ROUTES: BotIdProtectedRoute[];
|
|
25
|
+
interface SiteShellBotIdConfig {
|
|
26
|
+
/** Override protected mutating routes (defaults to `[{ path: "/api/leads", method: "POST" }]`). Never protect `GET` pages so AI crawlers & AEO stay untouched. */
|
|
27
|
+
protect?: BotIdProtectedRoute[];
|
|
28
|
+
/** Render BotIdClient even outside Vercel (primarily for tests). */
|
|
29
|
+
force?: boolean;
|
|
30
|
+
}
|
|
17
31
|
interface SiteShellProps {
|
|
18
32
|
config: SiteConfig;
|
|
19
33
|
header?: React.ReactNode;
|
|
@@ -24,6 +38,8 @@ interface SiteShellProps {
|
|
|
24
38
|
analytics?: React.ReactNode;
|
|
25
39
|
/** Extra elements to render inside `<head>` (fonts, custom preconnects, etc.). */
|
|
26
40
|
head?: React.ReactNode;
|
|
41
|
+
/** Invisible Vercel BotID protection scoped strictly to mutating form routes (`POST /api/leads` by default). Active automatically on Vercel deployments; dormant on `GET` pages and local/sandbox builds. Set `false` to disable. */
|
|
42
|
+
botId?: boolean | SiteShellBotIdConfig;
|
|
27
43
|
htmlClassName?: string;
|
|
28
44
|
bodyClassName?: string;
|
|
29
45
|
mainClassName?: string;
|
|
@@ -31,13 +47,26 @@ interface SiteShellProps {
|
|
|
31
47
|
privacyModeEndpoint?: string;
|
|
32
48
|
children: React.ReactNode;
|
|
33
49
|
}
|
|
50
|
+
declare function resolveBotIdRoutes(botId: SiteShellProps["botId"]): BotIdProtectedRoute[];
|
|
51
|
+
/**
|
|
52
|
+
* Captures the native `window.fetch` before `<BotIdClient>` wraps it so
|
|
53
|
+
* `buildBotIdPostScript` can detect when BotID's challenge succeeded vs failed
|
|
54
|
+
* or timed out — without ever double-posting or bypassing a real `403` verdict.
|
|
55
|
+
*/
|
|
56
|
+
declare function buildBotIdPreScript(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Bounds BotID challenge loading (4s) and resets stuck failed `<script>` tags
|
|
59
|
+
* on challenge load errors so a blocked/unavailable challenge script never
|
|
60
|
+
* hangs same-page retries and always lets the server policy decide.
|
|
61
|
+
*/
|
|
62
|
+
declare function buildBotIdPostScript(routes: BotIdProtectedRoute[], challengeTimeoutMs?: number): string;
|
|
34
63
|
/**
|
|
35
64
|
* Invisible compliance, consent, accessibility, and SEO root shell.
|
|
36
65
|
*
|
|
37
66
|
* HARD STATIC-SSG INVARIANT: SiteShell NEVER calls `cookies()` or `headers()`
|
|
38
67
|
* from `next/headers`, keeping every page 100% statically cacheable on Vercel CDN.
|
|
39
68
|
*/
|
|
40
|
-
declare function SiteShell({ config, header, footer, consentBanner, analytics, head, htmlClassName, bodyClassName, mainClassName, privacyModeEndpoint, children, }: SiteShellProps): React.JSX.Element;
|
|
69
|
+
declare function SiteShell({ config, header, footer, consentBanner, analytics, head, botId, htmlClassName, bodyClassName, mainClassName, privacyModeEndpoint, children, }: SiteShellProps): React.JSX.Element;
|
|
41
70
|
|
|
42
|
-
export { SiteShell, SkipLink };
|
|
43
|
-
export type { SiteShellProps, SkipLinkProps };
|
|
71
|
+
export { DEFAULT_BOTID_PROTECTED_ROUTES, SiteShell, SkipLink, buildBotIdPostScript, buildBotIdPreScript, resolveBotIdRoutes };
|
|
72
|
+
export type { BotIdProtectedRoute, SiteShellBotIdConfig, SiteShellProps, SkipLinkProps };
|
package/dist/a11y/index.js
CHANGED
|
@@ -53,6 +53,9 @@ function SkipLink({
|
|
|
53
53
|
] });
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// src/a11y/site-shell.tsx
|
|
57
|
+
import { BotIdClient } from "botid/client";
|
|
58
|
+
|
|
56
59
|
// src/config/metadata.ts
|
|
57
60
|
function buildOrganizationJsonLd(config) {
|
|
58
61
|
const org = config.jsonLd?.organization;
|
|
@@ -141,7 +144,45 @@ function buildConsentBootstrapScript(options) {
|
|
|
141
144
|
|
|
142
145
|
// src/a11y/site-shell.tsx
|
|
143
146
|
import { SiteShellClient } from "./shell-client.js";
|
|
144
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
147
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
148
|
+
var DEFAULT_BOTID_PROTECTED_ROUTES = [
|
|
149
|
+
{ path: "/api/leads", method: "POST" }
|
|
150
|
+
];
|
|
151
|
+
function shouldMountBotId(botId) {
|
|
152
|
+
if (botId === false) return false;
|
|
153
|
+
if (typeof botId === "object" && botId.force) return true;
|
|
154
|
+
if (process.env.WR_SANDBOX === "1" || process.env.WR_SYNTHETIC_LEADS === "1") {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return process.env.VERCEL === "1" || process.env.WR_ENABLE_BOTID === "1";
|
|
158
|
+
}
|
|
159
|
+
function safeInlineJson(value) {
|
|
160
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
161
|
+
}
|
|
162
|
+
function resolveBotIdRoutes(botId) {
|
|
163
|
+
const configured = typeof botId === "object" && botId.protect && botId.protect.length > 0 ? botId.protect.filter(
|
|
164
|
+
(route) => typeof route.path === "string" && route.path.startsWith("/") && !/[<>]/.test(route.path) && typeof route.method === "string" && /^(?:POST|PUT|PATCH|DELETE)$/i.test(route.method)
|
|
165
|
+
) : DEFAULT_BOTID_PROTECTED_ROUTES;
|
|
166
|
+
const routes = configured.length > 0 ? configured : DEFAULT_BOTID_PROTECTED_ROUTES;
|
|
167
|
+
const envLevel = process.env.WR_BOTID_CHECK_LEVEL?.trim();
|
|
168
|
+
if (envLevel === "basic" || envLevel === "deepAnalysis") {
|
|
169
|
+
return routes.map((route) => ({
|
|
170
|
+
...route,
|
|
171
|
+
advancedOptions: {
|
|
172
|
+
checkLevel: envLevel,
|
|
173
|
+
...route.advancedOptions
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
return routes;
|
|
178
|
+
}
|
|
179
|
+
function buildBotIdPreScript() {
|
|
180
|
+
return `(function(){if(window.__wrBotId)return;var raw=window.fetch.bind(window);var active=new Map();window.__wrBotId={raw:raw,active:active,seq:0,wrapped:false};window.fetch=function(input,init){var id=null;if(init&&init.headers&&typeof init.headers.get==='function'){id=init.headers.get('x-wr-botid-req');if(id)init.headers.delete('x-wr-botid-req');}if(id&&active.has(id)){var st=active.get(id);active.delete(id);clearTimeout(st.timer);if(st.timedOut)return st.fallbackPromise;st.dispatched=true;}return raw(input,init);};})();`;
|
|
181
|
+
}
|
|
182
|
+
function buildBotIdPostScript(routes, challengeTimeoutMs = 4e3) {
|
|
183
|
+
const timeout = Math.max(100, Math.round(challengeTimeoutMs));
|
|
184
|
+
return `(function(){var rt=window.__wrBotId;if(!rt||rt.wrapped)return;rt.wrapped=true;var botFetch=window.fetch;var routes=${safeInlineJson(routes)};function match(url,method){if(url.origin!==location.origin)return false;for(var k=0;k<routes.length;k++){var r=routes[k];if(r.method.toLowerCase()!==method.toLowerCase())continue;var re=new RegExp('^'+r.path.replace(/[.?+^$[\\]\\\\(){}|-]/g,'\\\\$&').split('*').join('.*')+'$');if(re.test(url.pathname))return true;}return false;}function resetBotId(){try{document.querySelectorAll('script[src*="149e9513-01fa-4fb0-aad4-566afd725d1b"]').forEach(function(el){el.remove();});window.dispatchEvent(new Event('online'));}catch(e){}}window.fetch=function(input,init){var url,method;try{url=new URL(input instanceof Request?input.url:input,location.href);method=(init&&init.method)||(input instanceof Request?input.method:'GET');}catch(e){return botFetch(input,init);}if(!match(url,method))return botFetch(input,init);var hdrs=new Headers((init&&init.headers)||(input instanceof Request?input.headers:undefined));if(hdrs.has('x-wr-botid-req'))return botFetch(input,init);var id=String(++rt.seq);hdrs.set('x-wr-botid-req',id);var taggedInit=Object.assign({},init,{headers:hdrs});return new Promise(function(resolve,reject){var st={timedOut:false,dispatched:false,timer:0,fallbackPromise:null};function fallback(){if(st.dispatched||st.timedOut)return;st.timedOut=true;clearTimeout(st.timer);resetBotId();st.fallbackPromise=rt.raw(input,init);st.fallbackPromise.then(resolve,reject);}st.timer=setTimeout(fallback,${timeout});rt.active.set(id,st);Promise.resolve().then(function(){return botFetch(input,taggedInit);}).then(function(res){clearTimeout(st.timer);rt.active.delete(id);if(!st.timedOut)resolve(res);},function(err){clearTimeout(st.timer);rt.active.delete(id);if(st.dispatched){if(!st.timedOut)reject(err);}else{fallback();}});});};})();`;
|
|
185
|
+
}
|
|
145
186
|
function SiteShell({
|
|
146
187
|
config,
|
|
147
188
|
header,
|
|
@@ -149,6 +190,7 @@ function SiteShell({
|
|
|
149
190
|
consentBanner,
|
|
150
191
|
analytics,
|
|
151
192
|
head,
|
|
193
|
+
botId = true,
|
|
152
194
|
htmlClassName,
|
|
153
195
|
bodyClassName = "antialiased",
|
|
154
196
|
mainClassName,
|
|
@@ -163,9 +205,28 @@ function SiteShell({
|
|
|
163
205
|
legacyConsentCookies: config.consent?.legacyConsentCookies
|
|
164
206
|
});
|
|
165
207
|
const orgJsonLd = buildOrganizationJsonLd(config);
|
|
208
|
+
const mountBotId = shouldMountBotId(botId);
|
|
209
|
+
const botIdRoutes = mountBotId ? resolveBotIdRoutes(botId) : [];
|
|
166
210
|
return /* @__PURE__ */ jsxs2("html", { lang: config.seo?.lang || "en", className: htmlClassName, children: [
|
|
167
211
|
/* @__PURE__ */ jsxs2("head", { children: [
|
|
168
212
|
bootstrapScript && /* @__PURE__ */ jsx2("script", { dangerouslySetInnerHTML: { __html: bootstrapScript } }),
|
|
213
|
+
mountBotId && /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
214
|
+
/* @__PURE__ */ jsx2(
|
|
215
|
+
"script",
|
|
216
|
+
{
|
|
217
|
+
dangerouslySetInnerHTML: { __html: buildBotIdPreScript() }
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
/* @__PURE__ */ jsx2(BotIdClient, { protect: botIdRoutes }),
|
|
221
|
+
/* @__PURE__ */ jsx2(
|
|
222
|
+
"script",
|
|
223
|
+
{
|
|
224
|
+
dangerouslySetInnerHTML: {
|
|
225
|
+
__html: buildBotIdPostScript(botIdRoutes)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
] }),
|
|
169
230
|
head
|
|
170
231
|
] }),
|
|
171
232
|
/* @__PURE__ */ jsxs2("body", { className: bodyClassName, children: [
|
|
@@ -194,6 +255,10 @@ function SiteShell({
|
|
|
194
255
|
] });
|
|
195
256
|
}
|
|
196
257
|
export {
|
|
258
|
+
DEFAULT_BOTID_PROTECTED_ROUTES,
|
|
197
259
|
SiteShell,
|
|
198
|
-
SkipLink
|
|
260
|
+
SkipLink,
|
|
261
|
+
buildBotIdPostScript,
|
|
262
|
+
buildBotIdPreScript,
|
|
263
|
+
resolveBotIdRoutes
|
|
199
264
|
};
|
package/dist/next/config.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(config_exports, {
|
|
|
27
27
|
withWealthReach: () => withWealthReach
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(config_exports);
|
|
30
|
+
var import_config = require("botid/next/config");
|
|
30
31
|
var SANDBOX_DEV_ORIGINS = [
|
|
31
32
|
"*.vercel.run",
|
|
32
33
|
"*.vercel.app",
|
|
@@ -78,6 +79,7 @@ function withWealthReach(options = {}) {
|
|
|
78
79
|
rootDir,
|
|
79
80
|
blogPostsDir = "data/blog",
|
|
80
81
|
extraFrameAncestors,
|
|
82
|
+
botId = true,
|
|
81
83
|
headers: userHeaders,
|
|
82
84
|
images: userImages,
|
|
83
85
|
allowedDevOrigins: userDevOrigins,
|
|
@@ -106,7 +108,7 @@ function withWealthReach(options = {}) {
|
|
|
106
108
|
/* @__PURE__ */ new Set([defaultTracingGlob, ...userTracing?.["/**"] ?? []])
|
|
107
109
|
)
|
|
108
110
|
};
|
|
109
|
-
|
|
111
|
+
const baseConfig = {
|
|
110
112
|
devIndicators: false,
|
|
111
113
|
poweredByHeader: false,
|
|
112
114
|
productionBrowserSourceMaps: false,
|
|
@@ -129,6 +131,16 @@ function withWealthReach(options = {}) {
|
|
|
129
131
|
return [{ source: "/(.*)", headers: baseHeaders }, ...extra];
|
|
130
132
|
}
|
|
131
133
|
};
|
|
134
|
+
if (!botId) return baseConfig;
|
|
135
|
+
const userRewrites = baseConfig.rewrites;
|
|
136
|
+
if (!userRewrites) return (0, import_config.withBotId)(baseConfig);
|
|
137
|
+
return (0, import_config.withBotId)({
|
|
138
|
+
...baseConfig,
|
|
139
|
+
async rewrites() {
|
|
140
|
+
const rewrites = await userRewrites();
|
|
141
|
+
return Array.isArray(rewrites) ? rewrites : { ...rewrites, beforeFiles: rewrites.beforeFiles ?? [] };
|
|
142
|
+
}
|
|
143
|
+
});
|
|
132
144
|
}
|
|
133
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
134
146
|
0 && (module.exports = {
|
package/dist/next/config.d.cts
CHANGED
|
@@ -23,6 +23,8 @@ interface WithWealthReachOptions extends NextConfig {
|
|
|
23
23
|
blogPostsDir?: string;
|
|
24
24
|
/** Additional CSP frame-ancestors origins beyond `'self'` and `https://*.wealthreach.ai`. */
|
|
25
25
|
extraFrameAncestors?: string[];
|
|
26
|
+
/** Enable Vercel BotID challenge proxy rewrites for protected mutating routes like `POST /api/leads` (default `true`). Does not affect `GET` routes or AI crawlers. */
|
|
27
|
+
botId?: boolean;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Wraps any client Next.js 16 config with WealthReach security headers, Eve
|
package/dist/next/config.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ interface WithWealthReachOptions extends NextConfig {
|
|
|
23
23
|
blogPostsDir?: string;
|
|
24
24
|
/** Additional CSP frame-ancestors origins beyond `'self'` and `https://*.wealthreach.ai`. */
|
|
25
25
|
extraFrameAncestors?: string[];
|
|
26
|
+
/** Enable Vercel BotID challenge proxy rewrites for protected mutating routes like `POST /api/leads` (default `true`). Does not affect `GET` routes or AI crawlers. */
|
|
27
|
+
botId?: boolean;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Wraps any client Next.js 16 config with WealthReach security headers, Eve
|
package/dist/next/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/next/config.ts
|
|
2
|
+
import { withBotId } from "botid/next/config";
|
|
2
3
|
var SANDBOX_DEV_ORIGINS = [
|
|
3
4
|
"*.vercel.run",
|
|
4
5
|
"*.vercel.app",
|
|
@@ -50,6 +51,7 @@ function withWealthReach(options = {}) {
|
|
|
50
51
|
rootDir,
|
|
51
52
|
blogPostsDir = "data/blog",
|
|
52
53
|
extraFrameAncestors,
|
|
54
|
+
botId = true,
|
|
53
55
|
headers: userHeaders,
|
|
54
56
|
images: userImages,
|
|
55
57
|
allowedDevOrigins: userDevOrigins,
|
|
@@ -78,7 +80,7 @@ function withWealthReach(options = {}) {
|
|
|
78
80
|
/* @__PURE__ */ new Set([defaultTracingGlob, ...userTracing?.["/**"] ?? []])
|
|
79
81
|
)
|
|
80
82
|
};
|
|
81
|
-
|
|
83
|
+
const baseConfig = {
|
|
82
84
|
devIndicators: false,
|
|
83
85
|
poweredByHeader: false,
|
|
84
86
|
productionBrowserSourceMaps: false,
|
|
@@ -101,6 +103,16 @@ function withWealthReach(options = {}) {
|
|
|
101
103
|
return [{ source: "/(.*)", headers: baseHeaders }, ...extra];
|
|
102
104
|
}
|
|
103
105
|
};
|
|
106
|
+
if (!botId) return baseConfig;
|
|
107
|
+
const userRewrites = baseConfig.rewrites;
|
|
108
|
+
if (!userRewrites) return withBotId(baseConfig);
|
|
109
|
+
return withBotId({
|
|
110
|
+
...baseConfig,
|
|
111
|
+
async rewrites() {
|
|
112
|
+
const rewrites = await userRewrites();
|
|
113
|
+
return Array.isArray(rewrites) ? rewrites : { ...rewrites, beforeFiles: rewrites.beforeFiles ?? [] };
|
|
114
|
+
}
|
|
115
|
+
});
|
|
104
116
|
}
|
|
105
117
|
export {
|
|
106
118
|
SANDBOX_DEV_ORIGINS,
|
|
@@ -50,6 +50,22 @@ interface NormalizedLeadSubmission {
|
|
|
50
50
|
turnstileToken?: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
interface BotIdVerificationOptions {
|
|
54
|
+
/** Override Vercel BotID check level (`"basic"` is free; `"deepAnalysis"` uses Kasada). Omit to inherit the Vercel project setting. */
|
|
55
|
+
checkLevel?: "basic" | "deepAnalysis";
|
|
56
|
+
/** Reject submissions with 503 if Vercel BotID encounters a transient upstream error (default `false` so legitimate advisor leads are never dropped during a BotID outage). */
|
|
57
|
+
failClosed?: boolean;
|
|
58
|
+
}
|
|
59
|
+
type BotIdCheckFn = (options?: {
|
|
60
|
+
advancedOptions?: {
|
|
61
|
+
checkLevel?: "basic" | "deepAnalysis";
|
|
62
|
+
};
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
isBot: boolean;
|
|
65
|
+
isHuman: boolean;
|
|
66
|
+
isVerifiedBot?: boolean;
|
|
67
|
+
bypassed?: boolean;
|
|
68
|
+
}>;
|
|
53
69
|
interface SubmitLeadToWealthReachArgs {
|
|
54
70
|
config: SiteConfig;
|
|
55
71
|
formId: string;
|
|
@@ -117,6 +133,8 @@ declare function extractWealthReachContext(formData: FormData, fallback: {
|
|
|
117
133
|
sourceUrl: string;
|
|
118
134
|
}): ExtractedWealthReachContext;
|
|
119
135
|
interface LeadRouteHandlerOptions {
|
|
136
|
+
/** Verify Vercel BotID on Vercel deployments (default `true`; skipped locally, in sandbox, or when Vercel OIDC is not enabled on the project). */
|
|
137
|
+
verifyBotId?: boolean | BotIdVerificationOptions;
|
|
120
138
|
/** Verify Cloudflare Turnstile when TURNSTILE_SECRET_KEY is configured (default true). */
|
|
121
139
|
verifyTurnstile?: boolean;
|
|
122
140
|
/** Have WealthReach email the advisor when a server secret (`WR_DRAFT_SECRET`) is configured (set false if onAfterCapture sends a custom CC email). */
|
|
@@ -129,6 +147,8 @@ interface LeadRouteHandlerOptions {
|
|
|
129
147
|
submission: NormalizedLeadSubmission;
|
|
130
148
|
}) => Promise<Record<string, unknown> | void>;
|
|
131
149
|
fetchImpl?: typeof fetch;
|
|
150
|
+
/** Optional test override for `checkBotId()` from `botid/server`. */
|
|
151
|
+
checkBotIdImpl?: BotIdCheckFn;
|
|
132
152
|
}
|
|
133
153
|
/**
|
|
134
154
|
* Creates a same-origin Next.js App Router `POST /api/leads` handler that
|
|
@@ -138,4 +158,4 @@ interface LeadRouteHandlerOptions {
|
|
|
138
158
|
declare function createLeadRouteHandler(getConfig: () => SiteConfig, options?: LeadRouteHandlerOptions): (request: Request) => Promise<Response>;
|
|
139
159
|
|
|
140
160
|
export { computeSiteLeadNotifySignature, createLeadRouteHandler, extractWealthReachContext, resolveSiteLeadsEndpoint, submitLeadToWealthReach };
|
|
141
|
-
export type { ExtractedWealthReachContext, LeadRouteHandlerOptions, SubmitLeadResult, SubmitLeadToWealthReachArgs };
|
|
161
|
+
export type { BotIdCheckFn, BotIdVerificationOptions, ExtractedWealthReachContext, LeadRouteHandlerOptions, SubmitLeadResult, SubmitLeadToWealthReachArgs };
|
package/dist/next/leads-route.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/next/leads-route.ts
|
|
2
2
|
import { createHmac, randomUUID } from "crypto";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
|
+
import { checkBotId } from "botid/server";
|
|
4
5
|
|
|
5
6
|
// src/config/schema.ts
|
|
6
7
|
import { z as z2 } from "zod";
|
|
@@ -500,6 +501,56 @@ function checkLocalRateLimit(key, maxRequests = 15, windowMs = 10 * 60 * 1e3) {
|
|
|
500
501
|
current.count += 1;
|
|
501
502
|
return true;
|
|
502
503
|
}
|
|
504
|
+
var VERCEL_REQUEST_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("@vercel/request-context");
|
|
505
|
+
function hasVercelBotIdRuntimeContext() {
|
|
506
|
+
const ctx = globalThis[VERCEL_REQUEST_CONTEXT_SYMBOL]?.get?.();
|
|
507
|
+
if (!ctx || typeof ctx.mutateResponseHeadersBeforeFlush !== "function") {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const oidcToken = ctx.headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
511
|
+
return Boolean(oidcToken);
|
|
512
|
+
}
|
|
513
|
+
async function verifyVercelBotId(option, checkBotIdImpl) {
|
|
514
|
+
if (option === false) return { ok: true };
|
|
515
|
+
if (process.env.WR_SANDBOX === "1" || process.env.WR_SYNTHETIC_LEADS === "1") {
|
|
516
|
+
return { ok: true };
|
|
517
|
+
}
|
|
518
|
+
if (!checkBotIdImpl) {
|
|
519
|
+
if (process.env.VERCEL !== "1" || !hasVercelBotIdRuntimeContext()) {
|
|
520
|
+
return { ok: true };
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const envLevel = process.env.WR_BOTID_CHECK_LEVEL?.trim();
|
|
524
|
+
const checkLevel = typeof option === "object" && option.checkLevel ? option.checkLevel : envLevel === "basic" || envLevel === "deepAnalysis" ? envLevel : void 0;
|
|
525
|
+
const failClosed = typeof option === "object" && option.failClosed === true;
|
|
526
|
+
try {
|
|
527
|
+
const checker = checkBotIdImpl ?? checkBotId;
|
|
528
|
+
const verdict = await checker(
|
|
529
|
+
checkLevel ? { advancedOptions: { checkLevel } } : void 0
|
|
530
|
+
);
|
|
531
|
+
if (verdict.isBot) {
|
|
532
|
+
return {
|
|
533
|
+
ok: false,
|
|
534
|
+
status: 403,
|
|
535
|
+
error: "Verification failed. Please try again."
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
return { ok: true };
|
|
539
|
+
} catch (err) {
|
|
540
|
+
console.warn(
|
|
541
|
+
"[site-kit/leads] Vercel BotID check failed",
|
|
542
|
+
err instanceof Error ? err.message : "unknown"
|
|
543
|
+
);
|
|
544
|
+
if (failClosed) {
|
|
545
|
+
return {
|
|
546
|
+
ok: false,
|
|
547
|
+
status: 503,
|
|
548
|
+
error: "Verification temporarily unavailable. Please try again."
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return { ok: true };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
503
554
|
async function verifyTurnstile(token, remoteIp) {
|
|
504
555
|
const secret = process.env.TURNSTILE_SECRET_KEY?.trim();
|
|
505
556
|
if (!secret) return { ok: true };
|
|
@@ -672,18 +723,6 @@ function createLeadRouteHandler(getConfig, options) {
|
|
|
672
723
|
if (honeypot.length > 0) {
|
|
673
724
|
return NextResponse.json({ ok: true, leadId: randomUUID() });
|
|
674
725
|
}
|
|
675
|
-
if (options?.verifyTurnstile !== false) {
|
|
676
|
-
const turnstile = await verifyTurnstile(
|
|
677
|
-
typeof rawBody.turnstileToken === "string" ? rawBody.turnstileToken : void 0,
|
|
678
|
-
clientIp === "unknown" ? null : clientIp
|
|
679
|
-
);
|
|
680
|
-
if (!turnstile.ok) {
|
|
681
|
-
return NextResponse.json(
|
|
682
|
-
{ ok: false, error: "Verification failed. Please try again." },
|
|
683
|
-
{ status: 400 }
|
|
684
|
-
);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
726
|
const formId = typeof rawBody.formId === "string" ? rawBody.formId.trim() : "contact";
|
|
688
727
|
if (!FORM_ID_RE.test(formId)) {
|
|
689
728
|
return NextResponse.json(
|
|
@@ -726,6 +765,28 @@ function createLeadRouteHandler(getConfig, options) {
|
|
|
726
765
|
{ status: 400 }
|
|
727
766
|
);
|
|
728
767
|
}
|
|
768
|
+
const botIdCheck = await verifyVercelBotId(
|
|
769
|
+
options?.verifyBotId,
|
|
770
|
+
options?.checkBotIdImpl
|
|
771
|
+
);
|
|
772
|
+
if (!botIdCheck.ok) {
|
|
773
|
+
return NextResponse.json(
|
|
774
|
+
{ ok: false, error: botIdCheck.error ?? "Verification failed." },
|
|
775
|
+
{ status: botIdCheck.status ?? 403 }
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
if (options?.verifyTurnstile !== false) {
|
|
779
|
+
const turnstile = await verifyTurnstile(
|
|
780
|
+
typeof rawBody.turnstileToken === "string" ? rawBody.turnstileToken : void 0,
|
|
781
|
+
clientIp === "unknown" ? null : clientIp
|
|
782
|
+
);
|
|
783
|
+
if (!turnstile.ok) {
|
|
784
|
+
return NextResponse.json(
|
|
785
|
+
{ ok: false, error: "Verification failed. Please try again." },
|
|
786
|
+
{ status: 400 }
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
729
790
|
const config = getConfig();
|
|
730
791
|
const submissionId = typeof rawBody.submissionId === "string" && rawBody.submissionId.trim() ? rawBody.submissionId.trim() : randomUUID();
|
|
731
792
|
const sourceUrl = typeof rawBody.sourceUrl === "string" && rawBody.sourceUrl.startsWith("http") ? rawBody.sourceUrl : config.seo?.siteUrl || "https://example.invalid/";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wealthreach/site-kit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
+
"botid": "^1.5.13",
|
|
74
75
|
"gray-matter": "^4.0.3",
|
|
75
76
|
"zod": "^4.6.7"
|
|
76
77
|
},
|