@wealthreach/site-kit 0.0.0-stage → 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 +20 -2
- package/dist/a11y/client.d.ts +23 -0
- package/dist/a11y/client.js +72 -0
- package/dist/a11y/index.d.ts +43 -0
- package/dist/a11y/index.js +194 -0
- package/dist/a11y/shell-client.d.ts +19 -0
- package/dist/a11y/shell-client.js +45 -0
- package/dist/analytics/index.d.ts +47 -0
- package/dist/analytics/index.js +122 -0
- package/dist/attribution-DQaAWtA5.d.ts +41 -0
- package/dist/blog/index.d.ts +131 -0
- package/dist/blog/index.js +259 -0
- package/dist/chunk-4YRCSRZZ.js +32 -0
- package/dist/chunk-7GDXQ6UB.js +772 -0
- package/dist/chunk-QQP7VG2C.js +231 -0
- package/dist/chunk-Y77ARZE4.js +214 -0
- package/dist/config/index.d.ts +20 -0
- package/dist/config/index.js +445 -0
- package/dist/consent/index.d.ts +103 -0
- package/dist/consent/index.js +61 -0
- package/dist/disclosures/index.d.ts +57 -0
- package/dist/disclosures/index.js +361 -0
- package/dist/forms/index.d.ts +128 -0
- package/dist/forms/index.js +449 -0
- package/dist/mdx/index.d.ts +15 -0
- package/dist/mdx/index.js +45 -0
- package/dist/next/config.cjs +140 -0
- package/dist/next/config.d.cts +36 -0
- package/dist/next/config.d.ts +36 -0
- package/dist/next/config.js +111 -0
- package/dist/next/draft-route.d.ts +10 -0
- package/dist/next/draft-route.js +49 -0
- package/dist/next/leads-route.d.ts +138 -0
- package/dist/next/leads-route.js +771 -0
- package/dist/next/privacy-mode.d.ts +14 -0
- package/dist/next/privacy-mode.js +86 -0
- package/dist/next/proxy.d.ts +19 -0
- package/dist/next/proxy.js +93 -0
- package/dist/regulatory-schema-uDKNJ7q8.d.ts +1301 -0
- package/dist/schema-C1ixytx2.d.ts +2911 -0
- package/dist/schema-DD0nDOD0.d.ts +1744 -0
- package/package.json +85 -3
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
// src/next/leads-route.ts
|
|
2
|
+
import { createHmac, randomUUID } from "crypto";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
|
|
5
|
+
// src/config/schema.ts
|
|
6
|
+
import { z as z2 } from "zod";
|
|
7
|
+
|
|
8
|
+
// src/disclosures/regulatory-schema.ts
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
var text = z.string().trim().min(1);
|
|
11
|
+
var httpsUrl = z.string().trim().url().refine((value) => value.startsWith("https://"), {
|
|
12
|
+
message: "must be an https:// URL"
|
|
13
|
+
});
|
|
14
|
+
var urlOrPath = z.string().trim().min(1).refine(
|
|
15
|
+
(value) => value.startsWith("https://") || value.startsWith("/") && !value.startsWith("//"),
|
|
16
|
+
{ message: "must be an https:// URL or site-relative /path" }
|
|
17
|
+
);
|
|
18
|
+
var US_STATES = {
|
|
19
|
+
AL: "Alabama",
|
|
20
|
+
AK: "Alaska",
|
|
21
|
+
AZ: "Arizona",
|
|
22
|
+
AR: "Arkansas",
|
|
23
|
+
CA: "California",
|
|
24
|
+
CO: "Colorado",
|
|
25
|
+
CT: "Connecticut",
|
|
26
|
+
DE: "Delaware",
|
|
27
|
+
DC: "District of Columbia",
|
|
28
|
+
FL: "Florida",
|
|
29
|
+
GA: "Georgia",
|
|
30
|
+
HI: "Hawaii",
|
|
31
|
+
ID: "Idaho",
|
|
32
|
+
IL: "Illinois",
|
|
33
|
+
IN: "Indiana",
|
|
34
|
+
IA: "Iowa",
|
|
35
|
+
KS: "Kansas",
|
|
36
|
+
KY: "Kentucky",
|
|
37
|
+
LA: "Louisiana",
|
|
38
|
+
ME: "Maine",
|
|
39
|
+
MD: "Maryland",
|
|
40
|
+
MA: "Massachusetts",
|
|
41
|
+
MI: "Michigan",
|
|
42
|
+
MN: "Minnesota",
|
|
43
|
+
MS: "Mississippi",
|
|
44
|
+
MO: "Missouri",
|
|
45
|
+
MT: "Montana",
|
|
46
|
+
NE: "Nebraska",
|
|
47
|
+
NV: "Nevada",
|
|
48
|
+
NH: "New Hampshire",
|
|
49
|
+
NJ: "New Jersey",
|
|
50
|
+
NM: "New Mexico",
|
|
51
|
+
NY: "New York",
|
|
52
|
+
NC: "North Carolina",
|
|
53
|
+
ND: "North Dakota",
|
|
54
|
+
OH: "Ohio",
|
|
55
|
+
OK: "Oklahoma",
|
|
56
|
+
OR: "Oregon",
|
|
57
|
+
PA: "Pennsylvania",
|
|
58
|
+
RI: "Rhode Island",
|
|
59
|
+
SC: "South Carolina",
|
|
60
|
+
SD: "South Dakota",
|
|
61
|
+
TN: "Tennessee",
|
|
62
|
+
TX: "Texas",
|
|
63
|
+
UT: "Utah",
|
|
64
|
+
VT: "Vermont",
|
|
65
|
+
VA: "Virginia",
|
|
66
|
+
WA: "Washington",
|
|
67
|
+
WV: "West Virginia",
|
|
68
|
+
WI: "Wisconsin",
|
|
69
|
+
WY: "Wyoming"
|
|
70
|
+
};
|
|
71
|
+
var PROVINCES = {
|
|
72
|
+
AB: "Alberta",
|
|
73
|
+
BC: "British Columbia",
|
|
74
|
+
MB: "Manitoba",
|
|
75
|
+
NB: "New Brunswick",
|
|
76
|
+
NL: "Newfoundland and Labrador",
|
|
77
|
+
NS: "Nova Scotia",
|
|
78
|
+
NT: "Northwest Territories",
|
|
79
|
+
NU: "Nunavut",
|
|
80
|
+
ON: "Ontario",
|
|
81
|
+
PE: "Prince Edward Island",
|
|
82
|
+
QC: "Quebec",
|
|
83
|
+
SK: "Saskatchewan",
|
|
84
|
+
YT: "Yukon"
|
|
85
|
+
};
|
|
86
|
+
var keys = (o) => Object.keys(o);
|
|
87
|
+
var usStateSchema = z.enum(keys(US_STATES));
|
|
88
|
+
var provinceSchema = z.enum(keys(PROVINCES));
|
|
89
|
+
var crdSchema = z.string().regex(/^[0-9]{1,10}$/, "must be a CRD number, digits only");
|
|
90
|
+
var statesSchema = z.array(usStateSchema).min(1, "must name at least one state");
|
|
91
|
+
var regulatorSchema = z.union([
|
|
92
|
+
z.strictObject({ sec: z.literal(true) }),
|
|
93
|
+
z.strictObject({
|
|
94
|
+
states: statesSchema,
|
|
95
|
+
exemptElsewhere: z.boolean().default(false)
|
|
96
|
+
})
|
|
97
|
+
]);
|
|
98
|
+
var membershipSchema = z.enum(["FINRA", "SIPC", "MSRB"]);
|
|
99
|
+
var adviserEntitySchema = z.strictObject({
|
|
100
|
+
legalName: text,
|
|
101
|
+
regulator: regulatorSchema,
|
|
102
|
+
crd: crdSchema.optional(),
|
|
103
|
+
formAdvUrl: urlOrPath.optional(),
|
|
104
|
+
formCrsUrl: urlOrPath.optional()
|
|
105
|
+
});
|
|
106
|
+
var brokerDealerEntitySchema = z.strictObject({
|
|
107
|
+
legalName: text,
|
|
108
|
+
memberships: z.array(membershipSchema).min(1),
|
|
109
|
+
crd: crdSchema.optional()
|
|
110
|
+
});
|
|
111
|
+
var dualFirmSchema = brokerDealerEntitySchema.extend({
|
|
112
|
+
regulator: regulatorSchema,
|
|
113
|
+
formAdvUrl: urlOrPath.optional(),
|
|
114
|
+
formCrsUrl: urlOrPath.optional()
|
|
115
|
+
});
|
|
116
|
+
var transactsSchema = z.union([statesSchema, z.literal("registered-states")]);
|
|
117
|
+
var addOns = {
|
|
118
|
+
affiliates: z.array(
|
|
119
|
+
z.strictObject({
|
|
120
|
+
role: z.enum(["insurance", "tax", "law", "planning"]),
|
|
121
|
+
legalName: text,
|
|
122
|
+
relation: z.enum(["affiliated", "unaffiliated"]),
|
|
123
|
+
licensedStates: statesSchema.optional()
|
|
124
|
+
})
|
|
125
|
+
).optional(),
|
|
126
|
+
custodian: text.optional()
|
|
127
|
+
};
|
|
128
|
+
var houseText = z.boolean().optional();
|
|
129
|
+
var regulatorySchema = z.discriminatedUnion("kind", [
|
|
130
|
+
z.strictObject({
|
|
131
|
+
kind: z.literal("adviser"),
|
|
132
|
+
regulator: regulatorSchema,
|
|
133
|
+
crd: crdSchema.optional(),
|
|
134
|
+
formAdvUrl: urlOrPath.optional(),
|
|
135
|
+
formCrsUrl: urlOrPath.optional(),
|
|
136
|
+
secFileNumber: z.string().regex(/^[0-9]{3}-[0-9]{1,6}$/, "must be an SEC file number such as 801-12345").optional(),
|
|
137
|
+
...addOns
|
|
138
|
+
}),
|
|
139
|
+
z.strictObject({
|
|
140
|
+
kind: z.literal("adviser-representative"),
|
|
141
|
+
adviser: adviserEntitySchema,
|
|
142
|
+
relation: z.enum(["dba", "affiliated", "unaffiliated"]),
|
|
143
|
+
...addOns
|
|
144
|
+
}),
|
|
145
|
+
z.strictObject({
|
|
146
|
+
kind: z.literal("broker-dealer-and-adviser"),
|
|
147
|
+
brokerDealer: brokerDealerEntitySchema,
|
|
148
|
+
adviser: adviserEntitySchema,
|
|
149
|
+
relation: z.literal("unaffiliated"),
|
|
150
|
+
transacts: transactsSchema,
|
|
151
|
+
clearingFirm: text.optional(),
|
|
152
|
+
brokerCheck: httpsUrl.optional(),
|
|
153
|
+
houseText,
|
|
154
|
+
...addOns
|
|
155
|
+
}),
|
|
156
|
+
z.strictObject({
|
|
157
|
+
kind: z.literal("dual-registrant"),
|
|
158
|
+
firm: dualFirmSchema,
|
|
159
|
+
capacities: z.array(z.enum(["registered-representative", "investment-adviser-representative"])).min(1),
|
|
160
|
+
transacts: transactsSchema,
|
|
161
|
+
brokerCheck: httpsUrl.optional(),
|
|
162
|
+
houseText,
|
|
163
|
+
...addOns
|
|
164
|
+
}),
|
|
165
|
+
z.strictObject({
|
|
166
|
+
kind: z.literal("broker-dealer-representative"),
|
|
167
|
+
brokerDealer: brokerDealerEntitySchema,
|
|
168
|
+
transacts: transactsSchema,
|
|
169
|
+
clearingFirm: text.optional(),
|
|
170
|
+
brokerCheck: httpsUrl.optional(),
|
|
171
|
+
houseText,
|
|
172
|
+
...addOns
|
|
173
|
+
}),
|
|
174
|
+
z.strictObject({
|
|
175
|
+
kind: z.literal("insurance-only"),
|
|
176
|
+
licensedStates: statesSchema,
|
|
177
|
+
...addOns
|
|
178
|
+
}),
|
|
179
|
+
z.strictObject({
|
|
180
|
+
kind: z.literal("canadian-dealer-representative"),
|
|
181
|
+
dealer: z.strictObject({
|
|
182
|
+
legalName: text,
|
|
183
|
+
sro: z.literal("CIRO"),
|
|
184
|
+
protectionFund: z.literal("CIPF")
|
|
185
|
+
}),
|
|
186
|
+
provinces: z.array(provinceSchema).min(1, "must name at least one province"),
|
|
187
|
+
tradeName: z.boolean(),
|
|
188
|
+
productScope: text.optional(),
|
|
189
|
+
...addOns
|
|
190
|
+
}),
|
|
191
|
+
z.strictObject({ kind: z.literal("not-regulated"), ...addOns }),
|
|
192
|
+
z.strictObject({
|
|
193
|
+
kind: z.literal("unclassified"),
|
|
194
|
+
crd: crdSchema.optional(),
|
|
195
|
+
formAdvUrl: urlOrPath.optional()
|
|
196
|
+
})
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
// src/config/schema.ts
|
|
200
|
+
var DEFAULT_LEADS_API_URL = "https://attract.wealthreach.ai/api/attract/site-leads";
|
|
201
|
+
var DEFAULT_ANALYTICS_ENDPOINT = "https://attract.wealthreach.ai/api/analytics/events";
|
|
202
|
+
var navItemSchema = z2.object({
|
|
203
|
+
label: z2.string().trim().min(1),
|
|
204
|
+
href: z2.string().trim().min(1)
|
|
205
|
+
});
|
|
206
|
+
var ctaLinkSchema = z2.object({
|
|
207
|
+
label: z2.string().trim().min(1),
|
|
208
|
+
href: z2.string().trim().min(1)
|
|
209
|
+
});
|
|
210
|
+
var socialLinkSchema = z2.object({
|
|
211
|
+
platform: z2.string().trim().min(1),
|
|
212
|
+
url: z2.string().trim().min(1)
|
|
213
|
+
});
|
|
214
|
+
var footerGroupSchema = z2.object({
|
|
215
|
+
heading: z2.string().trim().min(1),
|
|
216
|
+
links: z2.array(navItemSchema)
|
|
217
|
+
});
|
|
218
|
+
var bookingConfigSchema = z2.object({
|
|
219
|
+
provider: z2.enum(["calendly", "calcom", "none"]).default("none"),
|
|
220
|
+
url: z2.string().trim().optional().default(""),
|
|
221
|
+
mode: z2.enum(["embed", "link"]).default("link")
|
|
222
|
+
});
|
|
223
|
+
var consentConfigSchema = z2.object({
|
|
224
|
+
enabled: z2.boolean().default(true),
|
|
225
|
+
message: z2.string().trim().optional().default(""),
|
|
226
|
+
policyUrl: z2.string().trim().optional().default("/privacy-policy"),
|
|
227
|
+
/** Legacy cookie names to migrate silently for returning visitors (e.g. Brandywine Oak). */
|
|
228
|
+
legacyConsentCookies: z2.array(z2.string().trim().min(1)).optional().default([]),
|
|
229
|
+
/** Additional US states requiring opt-in beyond California (CA is always opt-in). */
|
|
230
|
+
extraOptInUsRegions: z2.array(z2.string().trim().length(2)).optional().default([]),
|
|
231
|
+
/** Set true if the site renders its own footer PrivacyChoicesButton instead of the floating one. */
|
|
232
|
+
hideFloatingPrivacyButton: z2.boolean().optional().default(false)
|
|
233
|
+
});
|
|
234
|
+
var visitorsConfigSchema = z2.object({
|
|
235
|
+
enabled: z2.boolean().default(false),
|
|
236
|
+
siteScriptUrl: z2.string().trim().optional().default("")
|
|
237
|
+
});
|
|
238
|
+
var blogConfigSchema = z2.object({
|
|
239
|
+
enabled: z2.boolean().optional().default(true),
|
|
240
|
+
routeSegment: z2.string().trim().min(1).optional().default("blog"),
|
|
241
|
+
postsDir: z2.string().trim().min(1).optional().default("data/blog"),
|
|
242
|
+
model: z2.enum(["data-module", "content-collection"]).optional().default("content-collection")
|
|
243
|
+
});
|
|
244
|
+
var complianceConfigSchema = z2.object({
|
|
245
|
+
disclosures: z2.array(z2.string()).default([]),
|
|
246
|
+
regulatory: regulatorySchema.optional(),
|
|
247
|
+
formAdvUrl: z2.string().trim().optional(),
|
|
248
|
+
formCrsUrl: z2.string().trim().optional(),
|
|
249
|
+
crd: z2.string().trim().optional(),
|
|
250
|
+
brokerCheckUrl: z2.string().trim().optional()
|
|
251
|
+
});
|
|
252
|
+
var integrationsConfigSchema = z2.object({
|
|
253
|
+
gtmId: z2.string().trim().optional(),
|
|
254
|
+
ga4MeasurementId: z2.string().trim().optional(),
|
|
255
|
+
vercelAnalytics: z2.boolean().optional().default(false)
|
|
256
|
+
});
|
|
257
|
+
var siteConfigSchema = z2.object({
|
|
258
|
+
version: z2.number().int().min(3).default(3),
|
|
259
|
+
siteId: z2.string().trim().optional().default(""),
|
|
260
|
+
advisorId: z2.string().trim().optional().default(""),
|
|
261
|
+
leadsApiUrl: z2.string().trim().optional().default(DEFAULT_LEADS_API_URL),
|
|
262
|
+
analyticsEndpoint: z2.string().trim().optional().default(DEFAULT_ANALYTICS_ENDPOINT),
|
|
263
|
+
analyticsApiKey: z2.string().trim().optional().default(""),
|
|
264
|
+
brand: z2.object({
|
|
265
|
+
legalName: z2.string().trim().min(1),
|
|
266
|
+
displayName: z2.string().trim().optional().default(""),
|
|
267
|
+
tagline: z2.string().trim().optional().default(""),
|
|
268
|
+
logoUrl: z2.string().trim().optional(),
|
|
269
|
+
ogImageUrl: z2.string().trim().optional()
|
|
270
|
+
}),
|
|
271
|
+
contact: z2.object({
|
|
272
|
+
email: z2.string().trim().optional().default(""),
|
|
273
|
+
phone: z2.string().trim().optional().default(""),
|
|
274
|
+
address: z2.string().trim().optional().default(""),
|
|
275
|
+
calendarUrl: z2.string().trim().optional().default("")
|
|
276
|
+
}).optional().default({ email: "", phone: "", address: "", calendarUrl: "" }),
|
|
277
|
+
booking: bookingConfigSchema.optional().default({
|
|
278
|
+
provider: "none",
|
|
279
|
+
url: "",
|
|
280
|
+
mode: "link"
|
|
281
|
+
}),
|
|
282
|
+
consent: consentConfigSchema.optional().default({
|
|
283
|
+
enabled: true,
|
|
284
|
+
message: "",
|
|
285
|
+
policyUrl: "/privacy-policy",
|
|
286
|
+
legacyConsentCookies: [],
|
|
287
|
+
extraOptInUsRegions: [],
|
|
288
|
+
hideFloatingPrivacyButton: false
|
|
289
|
+
}),
|
|
290
|
+
visitors: visitorsConfigSchema.optional(),
|
|
291
|
+
integrations: integrationsConfigSchema.optional().default({
|
|
292
|
+
vercelAnalytics: false
|
|
293
|
+
}),
|
|
294
|
+
forms: z2.object({
|
|
295
|
+
allowCustomEmailDispatch: z2.boolean().optional().default(false),
|
|
296
|
+
exemptFormIds: z2.array(z2.string()).optional().default([]),
|
|
297
|
+
lead: z2.union([
|
|
298
|
+
z2.literal(false),
|
|
299
|
+
z2.object({
|
|
300
|
+
enabled: z2.boolean().optional().default(true),
|
|
301
|
+
heading: z2.string().optional(),
|
|
302
|
+
buttonText: z2.string().optional(),
|
|
303
|
+
showPhone: z2.boolean().optional(),
|
|
304
|
+
showMessage: z2.boolean().optional()
|
|
305
|
+
}).passthrough()
|
|
306
|
+
]).optional()
|
|
307
|
+
}).passthrough().optional().default({ allowCustomEmailDispatch: false, exemptFormIds: [] }),
|
|
308
|
+
blog: blogConfigSchema.optional().default({
|
|
309
|
+
enabled: true,
|
|
310
|
+
routeSegment: "blog",
|
|
311
|
+
postsDir: "data/blog",
|
|
312
|
+
model: "content-collection"
|
|
313
|
+
}),
|
|
314
|
+
header: z2.object({
|
|
315
|
+
nav: z2.array(navItemSchema).optional().default([]),
|
|
316
|
+
cta: ctaLinkSchema.optional()
|
|
317
|
+
}).optional().default({ nav: [] }),
|
|
318
|
+
footer: z2.object({
|
|
319
|
+
groups: z2.array(footerGroupSchema).optional().default([]),
|
|
320
|
+
social: z2.array(socialLinkSchema).optional().default([])
|
|
321
|
+
}).optional().default({ groups: [], social: [] }),
|
|
322
|
+
seo: z2.object({
|
|
323
|
+
siteUrl: z2.string().trim().optional().default(""),
|
|
324
|
+
lang: z2.string().trim().optional().default("en"),
|
|
325
|
+
defaultTitle: z2.string().trim().optional().default(""),
|
|
326
|
+
titleTemplate: z2.string().trim().optional().default(""),
|
|
327
|
+
defaultDescription: z2.string().trim().optional().default(""),
|
|
328
|
+
ogImageUrl: z2.string().trim().optional(),
|
|
329
|
+
twitterHandle: z2.string().trim().optional()
|
|
330
|
+
}).optional().default({
|
|
331
|
+
siteUrl: "",
|
|
332
|
+
lang: "en",
|
|
333
|
+
defaultTitle: "",
|
|
334
|
+
titleTemplate: "",
|
|
335
|
+
defaultDescription: ""
|
|
336
|
+
}),
|
|
337
|
+
jsonLd: z2.object({
|
|
338
|
+
organization: z2.object({
|
|
339
|
+
type: z2.string().optional().default("FinancialService"),
|
|
340
|
+
sameAs: z2.array(z2.string()).optional(),
|
|
341
|
+
areaServed: z2.union([z2.string(), z2.array(z2.string())]).optional()
|
|
342
|
+
}).optional()
|
|
343
|
+
}).optional(),
|
|
344
|
+
compliance: complianceConfigSchema.optional().default({ disclosures: [] }),
|
|
345
|
+
theme: z2.record(z2.string(), z2.unknown()).optional()
|
|
346
|
+
}).passthrough().transform((parsed) => ({
|
|
347
|
+
...parsed,
|
|
348
|
+
brand: {
|
|
349
|
+
...parsed.brand,
|
|
350
|
+
displayName: parsed.brand.displayName || displayNameFromLegal(parsed.brand.legalName)
|
|
351
|
+
}
|
|
352
|
+
}));
|
|
353
|
+
var LEGAL_SUFFIX_RE = /,?\s+\b(?:LLC|L\.L\.C\.|LLP|L\.L\.P\.|Inc\.?|Corp\.?|Corporation|Ltd\.?|Limited|Co\.?|LP|L\.P\.|PC|P\.C\.|PLLC)\.?$/i;
|
|
354
|
+
function displayNameFromLegal(legalName) {
|
|
355
|
+
return legalName.trim().replace(LEGAL_SUFFIX_RE, "").trim() || legalName.trim();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/forms/packing.ts
|
|
359
|
+
var SENSITIVE_FIELD_RE = /(?:^|[_.-])(?:ssn|social[_-]?security|account[_-]?number|routing[_-]?number|password|passwd|secret|credit[_-]?card|card[_-]?number|cvv|cvc|tax[_-]?id|ein|tin)(?:$|[_.-])/i;
|
|
360
|
+
var HONEYPOT_KEYS = /* @__PURE__ */ new Set([
|
|
361
|
+
"website",
|
|
362
|
+
"company_website",
|
|
363
|
+
"wr_hp",
|
|
364
|
+
"_hp"
|
|
365
|
+
]);
|
|
366
|
+
var INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
367
|
+
"cf-turnstile-response",
|
|
368
|
+
"turnstileToken",
|
|
369
|
+
"__wr_context"
|
|
370
|
+
]);
|
|
371
|
+
function normalizeKey(raw) {
|
|
372
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64);
|
|
373
|
+
}
|
|
374
|
+
function isSensitiveFieldKey(key) {
|
|
375
|
+
return SENSITIVE_FIELD_RE.test(key);
|
|
376
|
+
}
|
|
377
|
+
function packFormEntries(entries) {
|
|
378
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
379
|
+
let honeypot = "";
|
|
380
|
+
let turnstileToken;
|
|
381
|
+
const blockedSensitiveKeys = [];
|
|
382
|
+
for (const [rawKey, rawValue] of entries) {
|
|
383
|
+
if (typeof File !== "undefined" && rawValue instanceof File) continue;
|
|
384
|
+
const key = rawKey.trim();
|
|
385
|
+
if (!key) continue;
|
|
386
|
+
if (HONEYPOT_KEYS.has(key.toLowerCase())) {
|
|
387
|
+
const val = String(rawValue ?? "").trim();
|
|
388
|
+
if (val) honeypot = val;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (key === "cf-turnstile-response" || key === "turnstileToken") {
|
|
392
|
+
const val = String(rawValue ?? "").trim();
|
|
393
|
+
if (val) turnstileToken = val;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (INTERNAL_KEYS.has(key)) continue;
|
|
397
|
+
if (isSensitiveFieldKey(key)) {
|
|
398
|
+
blockedSensitiveKeys.push(key);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const list = buckets.get(key) ?? [];
|
|
402
|
+
if (Array.isArray(rawValue)) {
|
|
403
|
+
for (const item of rawValue) {
|
|
404
|
+
const s = String(item).trim();
|
|
405
|
+
if (s) list.push(s);
|
|
406
|
+
}
|
|
407
|
+
} else if (typeof rawValue === "boolean") {
|
|
408
|
+
list.push(rawValue);
|
|
409
|
+
} else {
|
|
410
|
+
const s = String(rawValue ?? "").trim();
|
|
411
|
+
if (s.length > 0) list.push(s);
|
|
412
|
+
}
|
|
413
|
+
buckets.set(key, list);
|
|
414
|
+
}
|
|
415
|
+
let name;
|
|
416
|
+
let firstName;
|
|
417
|
+
let lastName;
|
|
418
|
+
let email = "";
|
|
419
|
+
let phone;
|
|
420
|
+
let message;
|
|
421
|
+
const customFields = {};
|
|
422
|
+
for (const [rawKey, values] of buckets.entries()) {
|
|
423
|
+
if (values.length === 0) continue;
|
|
424
|
+
const normalized = normalizeKey(rawKey);
|
|
425
|
+
const firstString = String(values[0] ?? "").trim();
|
|
426
|
+
if (normalized === "name" || normalized === "full_name" || normalized === "your_name") {
|
|
427
|
+
name = firstString;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (normalized === "first_name" || normalized === "firstname") {
|
|
431
|
+
firstName = firstString;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (normalized === "last_name" || normalized === "lastname") {
|
|
435
|
+
lastName = firstString;
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (normalized === "email" || normalized === "email_address" || normalized === "e_mail" || normalized === "e_mail_address") {
|
|
439
|
+
email = firstString.toLowerCase();
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (normalized === "phone" || normalized === "phone_number" || normalized === "telephone" || normalized === "tel") {
|
|
443
|
+
phone = firstString;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (normalized === "message" || normalized === "comments" || normalized === "notes" || normalized === "how_can_we_help") {
|
|
447
|
+
message = firstString;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!normalized) continue;
|
|
451
|
+
if (values.length === 1) {
|
|
452
|
+
const v = values[0];
|
|
453
|
+
if (typeof v === "boolean") {
|
|
454
|
+
customFields[normalized] = v;
|
|
455
|
+
} else if (v === "on") {
|
|
456
|
+
customFields[normalized] = true;
|
|
457
|
+
} else {
|
|
458
|
+
customFields[normalized] = v.slice(0, 2e3);
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
customFields[normalized] = values.map((v) => String(v).slice(0, 200)).slice(0, 25);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!name && (firstName || lastName)) {
|
|
465
|
+
name = [firstName, lastName].filter(Boolean).join(" ").trim();
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
...name ? { name } : {},
|
|
469
|
+
email,
|
|
470
|
+
...phone ? { phone } : {},
|
|
471
|
+
...message ? { message } : {},
|
|
472
|
+
honeypot,
|
|
473
|
+
...turnstileToken ? { turnstileToken } : {},
|
|
474
|
+
customFields,
|
|
475
|
+
blockedSensitiveKeys
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/next/leads-route.ts
|
|
480
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
481
|
+
var FORM_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
482
|
+
var ipBuckets = /* @__PURE__ */ new Map();
|
|
483
|
+
function checkLocalRateLimit(key, maxRequests = 15, windowMs = 10 * 60 * 1e3) {
|
|
484
|
+
const now = Date.now();
|
|
485
|
+
const current = ipBuckets.get(key);
|
|
486
|
+
if (!current || current.resetAt <= now) {
|
|
487
|
+
if (ipBuckets.size > 5e3) ipBuckets.clear();
|
|
488
|
+
ipBuckets.set(key, { count: 1, resetAt: now + windowMs });
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
if (current.count >= maxRequests) return false;
|
|
492
|
+
current.count += 1;
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
async function verifyTurnstile(token, remoteIp) {
|
|
496
|
+
const secret = process.env.TURNSTILE_SECRET_KEY?.trim();
|
|
497
|
+
if (!secret) return { ok: true };
|
|
498
|
+
if (!token) return { ok: false, reason: "missing_token" };
|
|
499
|
+
try {
|
|
500
|
+
const body = new URLSearchParams({ secret, response: token });
|
|
501
|
+
if (remoteIp) body.set("remoteip", remoteIp);
|
|
502
|
+
const res = await fetch(
|
|
503
|
+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
504
|
+
{
|
|
505
|
+
method: "POST",
|
|
506
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
507
|
+
body
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
const data = await res.json();
|
|
511
|
+
return data.success ? { ok: true } : { ok: false, reason: "rejected" };
|
|
512
|
+
} catch {
|
|
513
|
+
return { ok: false, reason: "verify_error" };
|
|
514
|
+
}
|
|
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
|
+
}
|
|
521
|
+
async function submitLeadToWealthReach(args) {
|
|
522
|
+
const { config } = args;
|
|
523
|
+
const siteId = config.siteId?.trim();
|
|
524
|
+
const advisorId = (args.advisorId ?? config.advisorId)?.trim();
|
|
525
|
+
const apiKey = config.analyticsApiKey?.trim();
|
|
526
|
+
const endpoint = resolveSiteLeadsEndpoint(config.leadsApiUrl);
|
|
527
|
+
const submissionId = args.submissionId?.trim() || randomUUID();
|
|
528
|
+
if (!siteId || !advisorId || !apiKey) {
|
|
529
|
+
if (process.env.WR_PRE_PROVISION_MOCK === "1") {
|
|
530
|
+
return { ok: true, leadId: submissionId, synthetic: true };
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
ok: false,
|
|
534
|
+
status: 503,
|
|
535
|
+
error: "Site lead tracking is not configured yet (missing siteId, advisorId, or analyticsApiKey)."
|
|
536
|
+
};
|
|
537
|
+
}
|
|
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) : "";
|
|
542
|
+
const payload = {
|
|
543
|
+
siteId,
|
|
544
|
+
advisorId,
|
|
545
|
+
submissionId,
|
|
546
|
+
formId: args.formId,
|
|
547
|
+
formKind: args.formKind ?? "lead",
|
|
548
|
+
...args.name ? { name: args.name } : {},
|
|
549
|
+
email: args.email.trim().toLowerCase(),
|
|
550
|
+
...args.phone ? { phone: args.phone } : {},
|
|
551
|
+
...args.message ? { message: args.message } : {},
|
|
552
|
+
...args.customFields && Object.keys(args.customFields).length > 0 ? { customFields: args.customFields } : {},
|
|
553
|
+
notifyAdvisor: wantsNotify,
|
|
554
|
+
sourceUrl: args.sourceUrl,
|
|
555
|
+
attribution: args.attribution ?? {},
|
|
556
|
+
...args.websiteVisit ? { websiteVisit: args.websiteVisit } : {}
|
|
557
|
+
};
|
|
558
|
+
const doFetch = args.fetchImpl ?? fetch;
|
|
559
|
+
try {
|
|
560
|
+
const res = await doFetch(endpoint, {
|
|
561
|
+
method: "POST",
|
|
562
|
+
headers: {
|
|
563
|
+
"Content-Type": "application/json",
|
|
564
|
+
"x-api-key": apiKey,
|
|
565
|
+
...siteSignature ? { "x-wr-site-signature": siteSignature } : {},
|
|
566
|
+
...isSynthetic ? { "x-wr-synthetic-check": "1" } : {}
|
|
567
|
+
},
|
|
568
|
+
body: JSON.stringify(payload)
|
|
569
|
+
});
|
|
570
|
+
const data = await res.json().catch(() => ({}));
|
|
571
|
+
if (!res.ok) {
|
|
572
|
+
return {
|
|
573
|
+
ok: false,
|
|
574
|
+
status: res.status,
|
|
575
|
+
error: data.error || `Lead handoff failed (${res.status})`
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
ok: true,
|
|
580
|
+
leadId: data.lead?.id ?? submissionId,
|
|
581
|
+
...data.synthetic ? { synthetic: true } : {}
|
|
582
|
+
};
|
|
583
|
+
} catch {
|
|
584
|
+
return {
|
|
585
|
+
ok: false,
|
|
586
|
+
status: 502,
|
|
587
|
+
error: "Could not reach WealthReach lead service. Please try again."
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
var ALLOWED_LEADS_HOST_RE = /(?:^|\.)wealthreach\.(?:ai|com)$/i;
|
|
592
|
+
function resolveSiteLeadsEndpoint(configuredUrl) {
|
|
593
|
+
const raw = configuredUrl?.trim();
|
|
594
|
+
if (!raw) return DEFAULT_LEADS_API_URL;
|
|
595
|
+
const candidate = raw.endsWith("/api/attract/leads") ? raw.replace(/\/api\/attract\/leads$/, "/api/attract/site-leads") : raw;
|
|
596
|
+
try {
|
|
597
|
+
const parsed = new URL(candidate);
|
|
598
|
+
const isLocalDev = process.env.NODE_ENV !== "production" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
599
|
+
if (parsed.protocol === "https:" && ALLOWED_LEADS_HOST_RE.test(parsed.hostname) || isLocalDev) {
|
|
600
|
+
return parsed.toString();
|
|
601
|
+
}
|
|
602
|
+
} catch {
|
|
603
|
+
}
|
|
604
|
+
return DEFAULT_LEADS_API_URL;
|
|
605
|
+
}
|
|
606
|
+
function extractWealthReachContext(formData, fallback) {
|
|
607
|
+
const raw = formData.get("__wr_context");
|
|
608
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
609
|
+
try {
|
|
610
|
+
const parsed = JSON.parse(raw);
|
|
611
|
+
return {
|
|
612
|
+
formId: parsed.formId || fallback.formId,
|
|
613
|
+
formKind: parsed.formKind || fallback.formKind || "lead",
|
|
614
|
+
submissionId: parsed.submissionId || randomUUID(),
|
|
615
|
+
sourceUrl: parsed.sourceUrl || fallback.sourceUrl,
|
|
616
|
+
attribution: parsed.attribution ?? {},
|
|
617
|
+
...parsed.websiteVisit ? { websiteVisit: parsed.websiteVisit } : {}
|
|
618
|
+
};
|
|
619
|
+
} catch {
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
formId: fallback.formId,
|
|
624
|
+
formKind: fallback.formKind || "lead",
|
|
625
|
+
submissionId: randomUUID(),
|
|
626
|
+
sourceUrl: fallback.sourceUrl,
|
|
627
|
+
attribution: {}
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function createLeadRouteHandler(getConfig, options) {
|
|
631
|
+
return async function POST(request) {
|
|
632
|
+
const clientIp = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || request.headers.get("x-real-ip") || "unknown";
|
|
633
|
+
if (!checkLocalRateLimit(`ip:${clientIp}`)) {
|
|
634
|
+
return NextResponse.json(
|
|
635
|
+
{ ok: false, error: "Too many submissions. Please try again shortly." },
|
|
636
|
+
{ status: 429 }
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const MAX_BODY_BYTES = 65536;
|
|
640
|
+
let rawBody;
|
|
641
|
+
try {
|
|
642
|
+
const rawText = await request.text();
|
|
643
|
+
if (rawText.length > MAX_BODY_BYTES) {
|
|
644
|
+
return NextResponse.json(
|
|
645
|
+
{ ok: false, error: "Submission payload too large." },
|
|
646
|
+
{ status: 413 }
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
const parsed = JSON.parse(rawText);
|
|
650
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
651
|
+
return NextResponse.json(
|
|
652
|
+
{ ok: false, error: "Invalid request payload." },
|
|
653
|
+
{ status: 400 }
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
rawBody = parsed;
|
|
657
|
+
} catch {
|
|
658
|
+
return NextResponse.json(
|
|
659
|
+
{ ok: false, error: "Invalid JSON payload." },
|
|
660
|
+
{ status: 400 }
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const honeypot = String(rawBody.honeypot ?? rawBody.website ?? "").trim();
|
|
664
|
+
if (honeypot.length > 0) {
|
|
665
|
+
return NextResponse.json({ ok: true, leadId: randomUUID() });
|
|
666
|
+
}
|
|
667
|
+
if (options?.verifyTurnstile !== false) {
|
|
668
|
+
const turnstile = await verifyTurnstile(
|
|
669
|
+
typeof rawBody.turnstileToken === "string" ? rawBody.turnstileToken : void 0,
|
|
670
|
+
clientIp === "unknown" ? null : clientIp
|
|
671
|
+
);
|
|
672
|
+
if (!turnstile.ok) {
|
|
673
|
+
return NextResponse.json(
|
|
674
|
+
{ ok: false, error: "Verification failed. Please try again." },
|
|
675
|
+
{ status: 400 }
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const formId = typeof rawBody.formId === "string" ? rawBody.formId.trim() : "contact";
|
|
680
|
+
if (!FORM_ID_RE.test(formId)) {
|
|
681
|
+
return NextResponse.json(
|
|
682
|
+
{ ok: false, error: "Invalid form identifier." },
|
|
683
|
+
{ status: 400 }
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
const formKind = typeof rawBody.formKind === "string" && ["lead", "newsletter", "resource", "calculator", "consultation", "event"].includes(
|
|
687
|
+
rawBody.formKind
|
|
688
|
+
) ? rawBody.formKind : "lead";
|
|
689
|
+
const packed = packFormEntries([
|
|
690
|
+
...typeof rawBody.name === "string" ? [["name", rawBody.name]] : [],
|
|
691
|
+
...typeof rawBody.email === "string" ? [["email", rawBody.email]] : [],
|
|
692
|
+
...typeof rawBody.phone === "string" ? [["phone", rawBody.phone]] : [],
|
|
693
|
+
...typeof rawBody.message === "string" ? [["message", rawBody.message]] : [],
|
|
694
|
+
...rawBody.customFields && typeof rawBody.customFields === "object" && !Array.isArray(rawBody.customFields) ? Object.entries(
|
|
695
|
+
rawBody.customFields
|
|
696
|
+
) : []
|
|
697
|
+
]);
|
|
698
|
+
if (packed.blockedSensitiveKeys.length > 0) {
|
|
699
|
+
return NextResponse.json(
|
|
700
|
+
{ ok: false, error: "Sensitive credential fields are not accepted." },
|
|
701
|
+
{ status: 400 }
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
if (!packed.email || !EMAIL_RE.test(packed.email)) {
|
|
705
|
+
return NextResponse.json(
|
|
706
|
+
{ ok: false, error: "Please enter a valid email address." },
|
|
707
|
+
{ status: 400 }
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
const allowsEmailOnly = formKind === "newsletter" || formKind === "resource";
|
|
711
|
+
if (!allowsEmailOnly && !packed.name) {
|
|
712
|
+
return NextResponse.json(
|
|
713
|
+
{ ok: false, error: "Please enter your name." },
|
|
714
|
+
{ status: 400 }
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
const config = getConfig();
|
|
718
|
+
const submissionId = typeof rawBody.submissionId === "string" && rawBody.submissionId.trim() ? rawBody.submissionId.trim() : randomUUID();
|
|
719
|
+
const sourceUrl = typeof rawBody.sourceUrl === "string" && rawBody.sourceUrl.startsWith("http") ? rawBody.sourceUrl : config.seo?.siteUrl || "https://example.invalid/";
|
|
720
|
+
const submission = {
|
|
721
|
+
formId,
|
|
722
|
+
formKind,
|
|
723
|
+
submissionId,
|
|
724
|
+
...typeof rawBody.advisorId === "string" ? { advisorId: rawBody.advisorId } : {},
|
|
725
|
+
...packed.name ? { name: packed.name } : {},
|
|
726
|
+
email: packed.email,
|
|
727
|
+
...packed.phone ? { phone: packed.phone } : {},
|
|
728
|
+
...packed.message ? { message: packed.message } : {},
|
|
729
|
+
...Object.keys(packed.customFields).length > 0 ? { customFields: packed.customFields } : {},
|
|
730
|
+
sourceUrl,
|
|
731
|
+
attribution: rawBody.attribution && typeof rawBody.attribution === "object" ? rawBody.attribution : {},
|
|
732
|
+
...rawBody.websiteVisit && typeof rawBody.websiteVisit === "object" ? { websiteVisit: rawBody.websiteVisit } : {}
|
|
733
|
+
};
|
|
734
|
+
const result = await submitLeadToWealthReach({
|
|
735
|
+
config,
|
|
736
|
+
...submission,
|
|
737
|
+
...options?.notifyAdvisor !== void 0 ? { notifyAdvisor: options.notifyAdvisor } : {},
|
|
738
|
+
...options?.notifySecret ? { notifySecret: options.notifySecret } : {},
|
|
739
|
+
fetchImpl: options?.fetchImpl
|
|
740
|
+
});
|
|
741
|
+
if (!result.ok) {
|
|
742
|
+
return NextResponse.json(
|
|
743
|
+
{ ok: false, error: result.error },
|
|
744
|
+
{ status: result.status >= 400 && result.status < 600 ? result.status : 502 }
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
let customData = void 0;
|
|
748
|
+
if (options?.onAfterCapture && !result.synthetic) {
|
|
749
|
+
customData = await options.onAfterCapture({
|
|
750
|
+
leadId: result.leadId,
|
|
751
|
+
submission
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
return NextResponse.json(
|
|
755
|
+
{
|
|
756
|
+
ok: true,
|
|
757
|
+
leadId: result.leadId,
|
|
758
|
+
...result.synthetic ? { synthetic: true } : {},
|
|
759
|
+
...customData ? { data: customData } : {}
|
|
760
|
+
},
|
|
761
|
+
{ headers: { "Cache-Control": "no-store" } }
|
|
762
|
+
);
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
export {
|
|
766
|
+
computeSiteLeadNotifySignature,
|
|
767
|
+
createLeadRouteHandler,
|
|
768
|
+
extractWealthReachContext,
|
|
769
|
+
resolveSiteLeadsEndpoint,
|
|
770
|
+
submitLeadToWealthReach
|
|
771
|
+
};
|