@c1m-public/dash-site-kit 0.6.0 → 0.8.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/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/models/attribution.d.ts +22 -0
- package/dist/models/attribution.js +61 -0
- package/dist/models/bootstrap.d.ts +18 -0
- package/dist/models/bootstrap.js +26 -1
- package/dist/models/waitlist.d.ts +18 -0
- package/dist/models/waitlist.js +1 -0
- package/dist/next/data-layer.d.ts +5 -0
- package/dist/next/data-layer.js +6 -0
- package/dist/next/first-touch.d.ts +10 -0
- package/dist/next/first-touch.js +28 -0
- package/dist/next/normalize.js +7 -0
- package/dist/next/providers/waitlist.d.ts +8 -0
- package/dist/next/providers/waitlist.js +32 -0
- package/dist/next.d.ts +2 -0
- package/dist/next.js +2 -0
- package/dist/ports/waitlist.d.ts +9 -0
- package/dist/ports/waitlist.js +1 -0
- package/dist/ui/waitlist-form.d.ts +8 -0
- package/dist/ui/waitlist-form.js +41 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* reaching the transport, as a package boundary rather than a folder rule.
|
|
10
10
|
*/
|
|
11
11
|
export type * from "./models/bootstrap.js";
|
|
12
|
+
export type * from "./models/waitlist.js";
|
|
13
|
+
export { GATE_EXEMPT_PATHS, gateRedirect } from "./models/bootstrap.js";
|
|
14
|
+
export type * from "./models/attribution.js";
|
|
15
|
+
export { FIRST_TOUCH_COOKIE, FIRST_TOUCH_MAX_AGE_SECONDS, decodeFirstTouch, encodeFirstTouch, firstTouchFrom } from "./models/attribution.js";
|
|
12
16
|
export type * from "./models/directory.js";
|
|
13
17
|
export type * from "./models/leads.js";
|
|
14
18
|
export type * from "./models/lead-portal.js";
|
|
@@ -20,6 +24,7 @@ export type { LeadsProvider } from "./ports/leads.js";
|
|
|
20
24
|
export type { LeadPortalProvider } from "./ports/lead-portal.js";
|
|
21
25
|
export type { PlansProvider } from "./ports/plans.js";
|
|
22
26
|
export type { ProfileProvider } from "./ports/profile.js";
|
|
27
|
+
export type { WaitlistProvider } from "./ports/waitlist.js";
|
|
23
28
|
export { selectDirectoryRegion, validateDirectoryKey, validateRegionFilter, } from "./validation/directory.js";
|
|
24
29
|
export { LEAD_LIMITS, validateLeadForm } from "./validation/leads.js";
|
|
25
30
|
export type { LeadField, LeadValidationResult, ValidatedLead } from "./validation/leads.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { GATE_EXEMPT_PATHS, gateRedirect } from "./models/bootstrap.js";
|
|
2
|
+
export { FIRST_TOUCH_COOKIE, FIRST_TOUCH_MAX_AGE_SECONDS, decodeFirstTouch, encodeFirstTouch, firstTouchFrom } from "./models/attribution.js";
|
|
1
3
|
export { selectDirectoryRegion, validateDirectoryKey, validateRegionFilter, } from "./validation/directory.js";
|
|
2
4
|
export { LEAD_LIMITS, validateLeadForm } from "./validation/leads.js";
|
|
3
5
|
export { formatMoney } from "./format.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-touch attribution: where a visitor first came from, captured once and
|
|
3
|
+
* carried in a first-party cookie until they sign up. Framework-neutral.
|
|
4
|
+
*/
|
|
5
|
+
export declare const FIRST_TOUCH_COOKIE = "c1m_ft";
|
|
6
|
+
export declare const FIRST_TOUCH_MAX_AGE_SECONDS: number;
|
|
7
|
+
export interface FirstTouch {
|
|
8
|
+
utm_source?: string;
|
|
9
|
+
utm_medium?: string;
|
|
10
|
+
utm_campaign?: string;
|
|
11
|
+
utm_term?: string;
|
|
12
|
+
utm_content?: string;
|
|
13
|
+
referrer_host?: string;
|
|
14
|
+
landing_path?: string;
|
|
15
|
+
country?: string;
|
|
16
|
+
locale?: string;
|
|
17
|
+
}
|
|
18
|
+
/** The first touch for a landing request. The referrer counts only when external. */
|
|
19
|
+
export declare function firstTouchFrom(url: URL, referrer: string | null | undefined): FirstTouch;
|
|
20
|
+
export declare function encodeFirstTouch(touch: FirstTouch): string;
|
|
21
|
+
/** Parses a cookie value, keeping only known, bounded string fields. */
|
|
22
|
+
export declare function decodeFirstTouch(value: string | null | undefined): FirstTouch;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-touch attribution: where a visitor first came from, captured once and
|
|
3
|
+
* carried in a first-party cookie until they sign up. Framework-neutral.
|
|
4
|
+
*/
|
|
5
|
+
export const FIRST_TOUCH_COOKIE = "c1m_ft";
|
|
6
|
+
export const FIRST_TOUCH_MAX_AGE_SECONDS = 60 * 60 * 24 * 30;
|
|
7
|
+
const UTM_KEYS = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
8
|
+
function bounded(value, max) {
|
|
9
|
+
const trimmed = value?.trim();
|
|
10
|
+
return trimmed && trimmed.length <= max && !/[\u0000-\u001f\u007f]/.test(trimmed) ? trimmed : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The first touch for a landing request. The referrer counts only when external. */
|
|
13
|
+
export function firstTouchFrom(url, referrer) {
|
|
14
|
+
const touch = { landing_path: bounded(url.pathname + url.search, 512) };
|
|
15
|
+
for (const key of UTM_KEYS) {
|
|
16
|
+
const value = bounded(url.searchParams.get(key), 128);
|
|
17
|
+
if (value)
|
|
18
|
+
touch[key] = value;
|
|
19
|
+
}
|
|
20
|
+
if (referrer) {
|
|
21
|
+
try {
|
|
22
|
+
const host = new URL(referrer).hostname.toLowerCase();
|
|
23
|
+
if (host && host !== url.hostname.toLowerCase())
|
|
24
|
+
touch.referrer_host = bounded(host, 253);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// An unparsable referrer is simply not recorded.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return touch;
|
|
31
|
+
}
|
|
32
|
+
export function encodeFirstTouch(touch) {
|
|
33
|
+
return encodeURIComponent(JSON.stringify(touch));
|
|
34
|
+
}
|
|
35
|
+
/** Parses a cookie value, keeping only known, bounded string fields. */
|
|
36
|
+
export function decodeFirstTouch(value) {
|
|
37
|
+
if (!value || value.length > 4096)
|
|
38
|
+
return {};
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = JSON.parse(decodeURIComponent(value));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
if (!parsed || typeof parsed !== "object")
|
|
47
|
+
return {};
|
|
48
|
+
const source = parsed;
|
|
49
|
+
const out = {};
|
|
50
|
+
const limits = {
|
|
51
|
+
utm_source: 128, utm_medium: 128, utm_campaign: 128, utm_term: 128, utm_content: 128,
|
|
52
|
+
referrer_host: 253, landing_path: 512, country: 2, locale: 35,
|
|
53
|
+
};
|
|
54
|
+
for (const key of Object.keys(limits)) {
|
|
55
|
+
const raw = source[key];
|
|
56
|
+
const value = typeof raw === "string" ? bounded(raw, limits[key]) : undefined;
|
|
57
|
+
if (value)
|
|
58
|
+
out[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
@@ -30,4 +30,22 @@ export interface DashBootstrap {
|
|
|
30
30
|
title: string;
|
|
31
31
|
description?: string;
|
|
32
32
|
};
|
|
33
|
+
/** The server-decided public gate; null means the normal site. */
|
|
34
|
+
gate: DashGate | null;
|
|
33
35
|
}
|
|
36
|
+
export interface DashGate {
|
|
37
|
+
kind: "waitlist";
|
|
38
|
+
placement: "page" | "block";
|
|
39
|
+
path: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Paths a page gate never redirects: the gate itself, framework and API
|
|
43
|
+
* routes, crawler files and legal pages (consent must stay readable).
|
|
44
|
+
*/
|
|
45
|
+
export declare const GATE_EXEMPT_PATHS: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* Where a request must go instead, or null to serve it. Only page placement
|
|
48
|
+
* redirects; the server already decided whether the gate applies, so this
|
|
49
|
+
* never recomputes availability.
|
|
50
|
+
*/
|
|
51
|
+
export declare function gateRedirect(bootstrap: Pick<DashBootstrap, "gate">, pathname: string, exempt?: readonly string[]): string | null;
|
package/dist/models/bootstrap.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Paths a page gate never redirects: the gate itself, framework and API
|
|
3
|
+
* routes, crawler files and legal pages (consent must stay readable).
|
|
4
|
+
*/
|
|
5
|
+
export const GATE_EXEMPT_PATHS = [
|
|
6
|
+
"/api", "/_next", "/.well-known", "/robots.txt", "/sitemap.xml", "/favicon.ico",
|
|
7
|
+
"/privacy", "/terms", "/cookies", "/legal",
|
|
8
|
+
];
|
|
9
|
+
function underPath(pathname, prefix) {
|
|
10
|
+
return pathname === prefix || pathname.startsWith(prefix.endsWith("/") ? prefix : `${prefix}/`);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where a request must go instead, or null to serve it. Only page placement
|
|
14
|
+
* redirects; the server already decided whether the gate applies, so this
|
|
15
|
+
* never recomputes availability.
|
|
16
|
+
*/
|
|
17
|
+
export function gateRedirect(bootstrap, pathname, exempt = []) {
|
|
18
|
+
const gate = bootstrap.gate;
|
|
19
|
+
if (!gate || gate.placement !== "page")
|
|
20
|
+
return null;
|
|
21
|
+
for (const prefix of [gate.path, ...GATE_EXEMPT_PATHS, ...exempt]) {
|
|
22
|
+
if (underPath(pathname, prefix))
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return gate.path;
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FirstTouch } from "./attribution.js";
|
|
2
|
+
export interface DashWaitlistForm {
|
|
3
|
+
/** True while the server-decided gate is live. */
|
|
4
|
+
acceptingEntries: boolean;
|
|
5
|
+
collectMarketingConsent: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface DashWaitlistSubmission {
|
|
8
|
+
email: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
marketingOptIn?: boolean;
|
|
11
|
+
/** Which placement captured the signup. */
|
|
12
|
+
source?: "waitlist_page" | "waitlist_block";
|
|
13
|
+
/** First-touch context; the server bounds and may drop any field. */
|
|
14
|
+
attribution?: FirstTouch;
|
|
15
|
+
}
|
|
16
|
+
export interface DashWaitlistReceipt {
|
|
17
|
+
accepted: true;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,7 @@ import type { LeadInput, LeadOutcome } from "../models/leads.js";
|
|
|
5
5
|
import type { RequestLinkOutcome, ViewOutcome } from "../models/lead-portal.js";
|
|
6
6
|
import type { PlanCatalog } from "../models/plans.js";
|
|
7
7
|
import type { DashProfile } from "../models/profile.js";
|
|
8
|
+
import type { DashWaitlistForm, DashWaitlistReceipt, DashWaitlistSubmission } from "../models/waitlist.js";
|
|
8
9
|
/**
|
|
9
10
|
* A credential-free local preview. When `enabled()` is true the layer answers
|
|
10
11
|
* from these fixtures and never touches the channel, so `npm run dev` works
|
|
@@ -32,6 +33,10 @@ export interface DashDataLayer {
|
|
|
32
33
|
submitLead(input: LeadInput, attemptId: string): Promise<LeadOutcome>;
|
|
33
34
|
requestPortalLink(email: string): Promise<RequestLinkOutcome>;
|
|
34
35
|
viewPortal(token: string): Promise<ViewOutcome>;
|
|
36
|
+
loadDashWaitlistForm(): Promise<DashWaitlistForm>;
|
|
37
|
+
submitDashWaitlist(input: DashWaitlistSubmission, attemptId: string): Promise<DashWaitlistReceipt>;
|
|
38
|
+
verifyWaitlistEmail(token: string): Promise<boolean>;
|
|
39
|
+
leaveWaitlist(key: string): Promise<boolean>;
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* Builds the whole logic layer for a dash site in one call.
|
package/dist/next/data-layer.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createC1MLeadPortalProvider } from "./providers/lead-portal.js";
|
|
|
7
7
|
import { createC1MLeadsProvider } from "./providers/leads.js";
|
|
8
8
|
import { createC1MPlansProvider } from "./providers/plans.js";
|
|
9
9
|
import { createC1MProfileProvider } from "./providers/profile.js";
|
|
10
|
+
import { createC1MWaitlistProvider } from "./providers/waitlist.js";
|
|
10
11
|
/**
|
|
11
12
|
* Builds the whole logic layer for a dash site in one call.
|
|
12
13
|
*
|
|
@@ -24,6 +25,7 @@ export function createDashDataLayer(options) {
|
|
|
24
25
|
const plansProvider = createC1MPlansProvider();
|
|
25
26
|
const leadsProvider = createC1MLeadsProvider(options.leadSource);
|
|
26
27
|
const leadPortalProvider = createC1MLeadPortalProvider();
|
|
28
|
+
const waitlistProvider = createC1MWaitlistProvider();
|
|
27
29
|
const loadDashProfile = cache(() => inPreview() ? Promise.resolve(preview.profile) : profileProvider.loadProfile());
|
|
28
30
|
const listDirectoryRegions = cache(() => inPreview() ? Promise.resolve([]) : directoryProvider.listRegions());
|
|
29
31
|
const listDirectory = cache((filter) => inPreview() ? Promise.resolve([]) : directoryProvider.list(filter));
|
|
@@ -49,5 +51,9 @@ export function createDashDataLayer(options) {
|
|
|
49
51
|
submitLead: (input, attemptId) => leadsProvider.create(input, attemptId),
|
|
50
52
|
requestPortalLink: (email) => leadPortalProvider.requestLink(email),
|
|
51
53
|
viewPortal: (token) => leadPortalProvider.view(token),
|
|
54
|
+
loadDashWaitlistForm: cache(() => waitlistProvider.loadForm()),
|
|
55
|
+
submitDashWaitlist: (input, attemptId) => waitlistProvider.submit(input, attemptId),
|
|
56
|
+
verifyWaitlistEmail: (token) => waitlistProvider.verify(token),
|
|
57
|
+
leaveWaitlist: (key) => waitlistProvider.leave(key),
|
|
52
58
|
};
|
|
53
59
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { NextRequest, NextResponse } from "next/server";
|
|
3
|
+
import { type FirstTouch } from "../models/attribution.js";
|
|
4
|
+
/**
|
|
5
|
+
* Call from the site's proxy/middleware on page requests. It records the
|
|
6
|
+
* first touch once; later visits never overwrite it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function recordFirstTouch(request: NextRequest, response: NextResponse): NextResponse;
|
|
9
|
+
/** The visitor's first touch plus request-time country and locale hints. */
|
|
10
|
+
export declare function readFirstTouch(): Promise<FirstTouch>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { cookies, headers } from "next/headers";
|
|
3
|
+
import { FIRST_TOUCH_COOKIE, FIRST_TOUCH_MAX_AGE_SECONDS, decodeFirstTouch, encodeFirstTouch, firstTouchFrom, } from "../models/attribution.js";
|
|
4
|
+
/**
|
|
5
|
+
* Call from the site's proxy/middleware on page requests. It records the
|
|
6
|
+
* first touch once; later visits never overwrite it.
|
|
7
|
+
*/
|
|
8
|
+
export function recordFirstTouch(request, response) {
|
|
9
|
+
if (request.cookies.has(FIRST_TOUCH_COOKIE))
|
|
10
|
+
return response;
|
|
11
|
+
const touch = firstTouchFrom(request.nextUrl, request.headers.get("referer"));
|
|
12
|
+
response.cookies.set(FIRST_TOUCH_COOKIE, encodeFirstTouch(touch), {
|
|
13
|
+
httpOnly: true, sameSite: "lax", secure: request.nextUrl.protocol === "https:", path: "/", maxAge: FIRST_TOUCH_MAX_AGE_SECONDS,
|
|
14
|
+
});
|
|
15
|
+
return response;
|
|
16
|
+
}
|
|
17
|
+
/** The visitor's first touch plus request-time country and locale hints. */
|
|
18
|
+
export async function readFirstTouch() {
|
|
19
|
+
const [jar, requestHeaders] = await Promise.all([cookies(), headers()]);
|
|
20
|
+
const touch = decodeFirstTouch(jar.get(FIRST_TOUCH_COOKIE)?.value);
|
|
21
|
+
const country = requestHeaders.get("x-vercel-ip-country")?.toUpperCase();
|
|
22
|
+
if (country && /^[A-Z]{2}$/.test(country))
|
|
23
|
+
touch.country = country;
|
|
24
|
+
const locale = requestHeaders.get("accept-language")?.split(",")[0]?.split(";")[0]?.trim();
|
|
25
|
+
if (locale && /^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/.test(locale))
|
|
26
|
+
touch.locale = locale;
|
|
27
|
+
return touch;
|
|
28
|
+
}
|
package/dist/next/normalize.js
CHANGED
|
@@ -29,6 +29,7 @@ export function normalizeDashBootstrap(init) {
|
|
|
29
29
|
title: text(init.seo?.title) ?? name,
|
|
30
30
|
description: text(init.seo?.description) ?? text(init.public_profile.headline) ?? text(init.public_profile.short_description),
|
|
31
31
|
},
|
|
32
|
+
gate: normalizeGate(init.gate),
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
// --- profile --------------------------------------------------------------
|
|
@@ -140,3 +141,9 @@ export function normalizePlanCatalog(response) {
|
|
|
140
141
|
defaultRegion: response.default_region,
|
|
141
142
|
};
|
|
142
143
|
}
|
|
144
|
+
function normalizeGate(gate) {
|
|
145
|
+
if (gate?.kind !== "waitlist" || (gate.placement !== "page" && gate.placement !== "block"))
|
|
146
|
+
return null;
|
|
147
|
+
const path = typeof gate.path === "string" && gate.path.startsWith("/") && !gate.path.startsWith("//") ? gate.path : "/waitlist";
|
|
148
|
+
return { kind: "waitlist", placement: gate.placement, path };
|
|
149
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { WaitlistProvider } from "../../ports/waitlist.js";
|
|
3
|
+
import { getDashChannelClient } from "../client.js";
|
|
4
|
+
import { readFirstTouch } from "../first-touch.js";
|
|
5
|
+
type ChannelClient = Awaited<ReturnType<typeof getDashChannelClient>>;
|
|
6
|
+
type ChannelClientResolver = () => ChannelClient | Promise<ChannelClient>;
|
|
7
|
+
export declare function createC1MWaitlistProvider(resolveClient?: ChannelClientResolver, attribution?: typeof readFirstTouch): WaitlistProvider;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { getDashChannelClient } from "../client.js";
|
|
3
|
+
import { readFirstTouch } from "../first-touch.js";
|
|
4
|
+
export function createC1MWaitlistProvider(resolveClient = getDashChannelClient, attribution = readFirstTouch) {
|
|
5
|
+
return {
|
|
6
|
+
async loadForm() {
|
|
7
|
+
const response = await (await resolveClient()).dash.waitlist.form();
|
|
8
|
+
return {
|
|
9
|
+
acceptingEntries: response.gate !== undefined,
|
|
10
|
+
collectMarketingConsent: response.collect_marketing_consent === true,
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
async submit(input, attemptId) {
|
|
14
|
+
const response = await (await resolveClient()).dash.waitlist.submit({
|
|
15
|
+
email: input.email,
|
|
16
|
+
name: input.name,
|
|
17
|
+
marketing_opt_in: input.marketingOptIn === true,
|
|
18
|
+
source: input.source ?? "waitlist_page",
|
|
19
|
+
attribution: input.attribution ?? (await attribution()),
|
|
20
|
+
}, { idempotencyKey: attemptId });
|
|
21
|
+
if (response.accepted !== true)
|
|
22
|
+
throw new Error("waitlist submission was not accepted");
|
|
23
|
+
return { accepted: true };
|
|
24
|
+
},
|
|
25
|
+
async verify(token) {
|
|
26
|
+
return (await (await resolveClient()).audience.verify(token)).verified === true;
|
|
27
|
+
},
|
|
28
|
+
async leave(key) {
|
|
29
|
+
return (await (await resolveClient()).audience.unsubscribe(key)).unsubscribed === true;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
package/dist/next.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export { ChannelSiteSentryConfigurationError, createChannelSiteRequestErrorHandl
|
|
|
22
22
|
export type { ChannelSiteSentryEnvironment, ChannelSiteSentryOptions, } from "./next/sentry.js";
|
|
23
23
|
export { resolveC1MAsset } from "./next/assets.js";
|
|
24
24
|
export { createC1MBootstrapProvider } from "./next/providers/bootstrap.js";
|
|
25
|
+
export { createC1MWaitlistProvider } from "./next/providers/waitlist.js";
|
|
26
|
+
export { readFirstTouch, recordFirstTouch } from "./next/first-touch.js";
|
|
25
27
|
export { createC1MDirectoryProvider } from "./next/providers/directory.js";
|
|
26
28
|
export { createC1MLeadPortalProvider } from "./next/providers/lead-portal.js";
|
|
27
29
|
export { createC1MLeadsProvider } from "./next/providers/leads.js";
|
package/dist/next.js
CHANGED
|
@@ -17,6 +17,8 @@ export { observeChannelRequest } from "./next/observability.js";
|
|
|
17
17
|
export { ChannelSiteSentryConfigurationError, createChannelSiteRequestErrorHandler, initializeChannelSiteSentry, resolveChannelSiteSentryOptions, } from "./next/sentry.js";
|
|
18
18
|
export { resolveC1MAsset } from "./next/assets.js";
|
|
19
19
|
export { createC1MBootstrapProvider } from "./next/providers/bootstrap.js";
|
|
20
|
+
export { createC1MWaitlistProvider } from "./next/providers/waitlist.js";
|
|
21
|
+
export { readFirstTouch, recordFirstTouch } from "./next/first-touch.js";
|
|
20
22
|
export { createC1MDirectoryProvider } from "./next/providers/directory.js";
|
|
21
23
|
export { createC1MLeadPortalProvider } from "./next/providers/lead-portal.js";
|
|
22
24
|
export { createC1MLeadsProvider } from "./next/providers/leads.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DashWaitlistForm, DashWaitlistReceipt, DashWaitlistSubmission } from "../models/waitlist.js";
|
|
2
|
+
export interface WaitlistProvider {
|
|
3
|
+
loadForm(): Promise<DashWaitlistForm>;
|
|
4
|
+
submit(input: DashWaitlistSubmission, attemptId: string): Promise<DashWaitlistReceipt>;
|
|
5
|
+
/** Confirms an email from the confirmation link; false for unknown or used tokens. */
|
|
6
|
+
verify(token: string): Promise<boolean>;
|
|
7
|
+
/** Revokes consent and leaves every list from an email's unsubscribe link. */
|
|
8
|
+
leave(key: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DashWaitlistReceipt, DashWaitlistSubmission } from "../models/waitlist.js";
|
|
2
|
+
export declare function DashWaitlistForm({ acceptingEntries, collectMarketingConsent, placement, submit, }: {
|
|
3
|
+
acceptingEntries: boolean;
|
|
4
|
+
collectMarketingConsent: boolean;
|
|
5
|
+
/** Recorded as the signup's source. */
|
|
6
|
+
placement?: "page" | "block";
|
|
7
|
+
submit: (input: DashWaitlistSubmission) => Promise<DashWaitlistReceipt>;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useState } from "react";
|
|
4
|
+
export function DashWaitlistForm({ acceptingEntries, collectMarketingConsent, placement = "page", submit, }) {
|
|
5
|
+
const id = useId();
|
|
6
|
+
const [ready, setReady] = useState(false);
|
|
7
|
+
const [pending, setPending] = useState(false);
|
|
8
|
+
const [accepted, setAccepted] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
useEffect(() => setReady(true), []);
|
|
11
|
+
async function onSubmit(event) {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
if (!ready || pending || !acceptingEntries)
|
|
14
|
+
return;
|
|
15
|
+
const values = new FormData(event.currentTarget);
|
|
16
|
+
setPending(true);
|
|
17
|
+
setError(null);
|
|
18
|
+
try {
|
|
19
|
+
const receipt = await submit({
|
|
20
|
+
email: String(values.get("email") ?? "").trim(),
|
|
21
|
+
name: String(values.get("name") ?? "").trim(),
|
|
22
|
+
marketingOptIn: collectMarketingConsent && values.get("marketing_opt_in") === "on",
|
|
23
|
+
source: placement === "block" ? "waitlist_block" : "waitlist_page",
|
|
24
|
+
});
|
|
25
|
+
if (receipt.accepted !== true)
|
|
26
|
+
throw new Error("waitlist submission was not accepted");
|
|
27
|
+
setAccepted(true);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
setError("We could not add you right now. Please try again.");
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
setPending(false);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (accepted)
|
|
37
|
+
return _jsx("p", { role: "status", children: "Thanks. Check your inbox to confirm your place." });
|
|
38
|
+
if (!acceptingEntries)
|
|
39
|
+
return _jsx("p", { role: "status", children: "The waitlist is currently closed." });
|
|
40
|
+
return (_jsxs("form", { className: "space-y-4", onSubmit: onSubmit, children: [_jsxs("label", { className: "block space-y-1.5", htmlFor: `${id}-name`, children: [_jsx("span", { className: "text-sm font-medium text-ink", children: "Name (optional)" }), _jsx("input", { className: "min-h-11 w-full rounded-xl border border-border bg-white px-3 py-2 text-ink", disabled: !ready || pending, id: `${id}-name`, maxLength: 255, name: "name", autoComplete: "name" })] }), _jsxs("label", { className: "block space-y-1.5", htmlFor: `${id}-email`, children: [_jsx("span", { className: "text-sm font-medium text-ink", children: "Email" }), _jsx("input", { className: "min-h-11 w-full rounded-xl border border-border bg-white px-3 py-2 text-ink", disabled: !ready || pending, id: `${id}-email`, maxLength: 254, name: "email", type: "email", autoComplete: "email", required: true })] }), collectMarketingConsent ? (_jsxs("label", { className: "flex items-start gap-2 text-sm leading-6 text-muted", children: [_jsx("input", { className: "mt-1", disabled: !ready || pending, name: "marketing_opt_in", type: "checkbox" }), _jsx("span", { children: "I would also like to receive marketing emails. I can unsubscribe later." })] })) : null, error ? _jsx("p", { className: "text-sm text-red-700", role: "alert", children: error }) : null, _jsx("button", { className: "min-h-11 rounded-full bg-accent px-5 py-2.5 text-sm font-semibold text-accent-foreground disabled:opacity-60", disabled: !ready || pending, type: "submit", children: pending ? "Joining…" : "Join the waitlist" })] }));
|
|
41
|
+
}
|
package/dist/ui.d.ts
CHANGED
|
@@ -9,4 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { ButtonLink, Container, Eyebrow, SectionHeading, StatusPanel, VerifiedBadge, } from "./ui/primitives.js";
|
|
11
11
|
export { SiteImage } from "./ui/site-image.js";
|
|
12
|
+
export { DashWaitlistForm } from "./ui/waitlist-form.js";
|
|
12
13
|
export { SiteErrorFallback } from "./ui/error-fallback.js";
|
package/dist/ui.js
CHANGED
|
@@ -9,4 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { ButtonLink, Container, Eyebrow, SectionHeading, StatusPanel, VerifiedBadge, } from "./ui/primitives.js";
|
|
11
11
|
export { SiteImage } from "./ui/site-image.js";
|
|
12
|
+
export { DashWaitlistForm } from "./ui/waitlist-form.js";
|
|
12
13
|
export { SiteErrorFallback } from "./ui/error-fallback.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c1m-public/dash-site-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Shared transport, domain and UI layer for MML dash-scoped public sites",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"server-only": "0.0.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@c1m-public/channel-client": ">=0.
|
|
46
|
+
"@c1m-public/channel-client": ">=0.28.0 <1",
|
|
47
47
|
"next": "^16",
|
|
48
48
|
"react": "^19"
|
|
49
49
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"typescript": "5.9.3",
|
|
55
55
|
"vitest": "^4.1.4",
|
|
56
56
|
"@types/node": "^22",
|
|
57
|
-
"@c1m-public/channel-client": "0.
|
|
57
|
+
"@c1m-public/channel-client": "0.28.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"next": {
|