@c1m-public/dash-site-kit 0.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/LICENSE +21 -0
- package/README.md +145 -0
- package/dist/format.d.ts +11 -0
- package/dist/format.js +16 -0
- package/dist/image-policy.d.ts +6 -0
- package/dist/image-policy.js +28 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +6 -0
- package/dist/models/bootstrap.d.ts +33 -0
- package/dist/models/bootstrap.js +1 -0
- package/dist/models/directory.d.ts +37 -0
- package/dist/models/directory.js +1 -0
- package/dist/models/lead-portal.d.ts +56 -0
- package/dist/models/lead-portal.js +6 -0
- package/dist/models/leads.d.ts +19 -0
- package/dist/models/leads.js +1 -0
- package/dist/models/plans.d.ts +31 -0
- package/dist/models/plans.js +1 -0
- package/dist/models/profile.d.ts +25 -0
- package/dist/models/profile.js +1 -0
- package/dist/next/assets.d.ts +4 -0
- package/dist/next/assets.js +6 -0
- package/dist/next/cache.d.ts +7 -0
- package/dist/next/cache.js +7 -0
- package/dist/next/client.d.ts +24 -0
- package/dist/next/client.js +84 -0
- package/dist/next/data-layer.d.ts +48 -0
- package/dist/next/data-layer.js +57 -0
- package/dist/next/delivery.d.ts +2 -0
- package/dist/next/delivery.js +7 -0
- package/dist/next/env.d.ts +12 -0
- package/dist/next/env.js +38 -0
- package/dist/next/normalize.d.ts +23 -0
- package/dist/next/normalize.js +142 -0
- package/dist/next/observability.d.ts +11 -0
- package/dist/next/observability.js +18 -0
- package/dist/next/providers/bootstrap.d.ts +7 -0
- package/dist/next/providers/bootstrap.js +23 -0
- package/dist/next/providers/directory.d.ts +7 -0
- package/dist/next/providers/directory.js +39 -0
- package/dist/next/providers/lead-portal.d.ts +7 -0
- package/dist/next/providers/lead-portal.js +65 -0
- package/dist/next/providers/leads.d.ts +13 -0
- package/dist/next/providers/leads.js +38 -0
- package/dist/next/providers/plans.d.ts +7 -0
- package/dist/next/providers/plans.js +17 -0
- package/dist/next/providers/profile.d.ts +15 -0
- package/dist/next/providers/profile.js +33 -0
- package/dist/next.d.ts +23 -0
- package/dist/next.js +21 -0
- package/dist/ports/bootstrap.d.ts +6 -0
- package/dist/ports/bootstrap.js +1 -0
- package/dist/ports/directory.d.ts +7 -0
- package/dist/ports/directory.js +1 -0
- package/dist/ports/lead-portal.d.ts +6 -0
- package/dist/ports/lead-portal.js +1 -0
- package/dist/ports/leads.d.ts +9 -0
- package/dist/ports/leads.js +1 -0
- package/dist/ports/plans.d.ts +5 -0
- package/dist/ports/plans.js +1 -0
- package/dist/ports/profile.d.ts +9 -0
- package/dist/ports/profile.js +1 -0
- package/dist/site-config.d.ts +70 -0
- package/dist/site-config.js +87 -0
- package/dist/ui/error-fallback.d.ts +6 -0
- package/dist/ui/error-fallback.js +12 -0
- package/dist/ui/primitives.d.ts +25 -0
- package/dist/ui/primitives.js +23 -0
- package/dist/ui/site-image.d.ts +7 -0
- package/dist/ui/site-image.js +9 -0
- package/dist/ui.d.ts +12 -0
- package/dist/ui.js +12 -0
- package/dist/url-policy.d.ts +3 -0
- package/dist/url-policy.js +46 -0
- package/dist/validation/directory.d.ts +2 -0
- package/dist/validation/directory.js +15 -0
- package/dist/validation/leads.d.ts +21 -0
- package/dist/validation/leads.js +59 -0
- package/package.json +67 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { resolveC1MAsset } from "../assets.js";
|
|
3
|
+
import { getChannelClient, getDashChannelClient } from "../client.js";
|
|
4
|
+
import { normalizeDashProfile } from "../normalize.js";
|
|
5
|
+
/**
|
|
6
|
+
* `resolveBootstrap` is required: the profile name falls back to the dash
|
|
7
|
+
* bootstrap, and in a site that layer may be wrapped (local preview), so the
|
|
8
|
+
* package must be handed the site's composed loader rather than reaching for
|
|
9
|
+
* one itself.
|
|
10
|
+
*/
|
|
11
|
+
export function createC1MProfileProvider(resolveBootstrap, resolveClient = getDashChannelClient) {
|
|
12
|
+
return {
|
|
13
|
+
async loadProfile() {
|
|
14
|
+
const client = await resolveClient();
|
|
15
|
+
// The shell already fetched dash.init (deduped per request); the page
|
|
16
|
+
// read is the only extra hop the profile page pays.
|
|
17
|
+
const [bootstrap, response] = await Promise.all([resolveBootstrap(), client.dash.profile()]);
|
|
18
|
+
const profile = normalizeDashProfile(bootstrap.name, response);
|
|
19
|
+
// The door returns platform-hosted media as RELATIVE paths
|
|
20
|
+
// (`/tenant-media/…`). Resolve them against the API origin here — in the
|
|
21
|
+
// browser a relative src would point at this site, not at C1M.
|
|
22
|
+
return {
|
|
23
|
+
...profile,
|
|
24
|
+
logoUrl: resolveC1MAsset(client, profile.logoUrl),
|
|
25
|
+
coverUrl: resolveC1MAsset(client, profile.coverUrl),
|
|
26
|
+
gallery: profile.gallery.flatMap((item) => {
|
|
27
|
+
const url = resolveC1MAsset(client, item.url);
|
|
28
|
+
return url ? [{ ...item, url }] : [];
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next entry: the ACCESS layer. Server-only and Next-coupled.
|
|
3
|
+
*
|
|
4
|
+
* A consuming site should forbid this subpath from `app/**` and
|
|
5
|
+
* `components/**` — if a page can call the door directly, swapping the backend
|
|
6
|
+
* means editing every page and the channel token starts leaking into things
|
|
7
|
+
* that render. Depend on the object returned by `createDashDataLayer` instead.
|
|
8
|
+
*/
|
|
9
|
+
export { createDashDataLayer } from "./next/data-layer.js";
|
|
10
|
+
export type { DashDataLayer, DashDataLayerOptions, DashPreview } from "./next/data-layer.js";
|
|
11
|
+
export { ChannelScopeMismatchError, getChannelClient, getDashChannelClient, getVisitorDashChannelClient, requireDashScope, } from "./next/client.js";
|
|
12
|
+
export { ChannelConfigurationError, resolveChannelEnvironment } from "./next/env.js";
|
|
13
|
+
export type { ChannelEnvironment } from "./next/env.js";
|
|
14
|
+
export { CHANNEL_SITE_CACHE_TAG } from "./next/cache.js";
|
|
15
|
+
export { getChannelAttestation } from "./next/delivery.js";
|
|
16
|
+
export { observeChannelRequest } from "./next/observability.js";
|
|
17
|
+
export { resolveC1MAsset } from "./next/assets.js";
|
|
18
|
+
export { createC1MBootstrapProvider } from "./next/providers/bootstrap.js";
|
|
19
|
+
export { createC1MDirectoryProvider } from "./next/providers/directory.js";
|
|
20
|
+
export { createC1MLeadPortalProvider } from "./next/providers/lead-portal.js";
|
|
21
|
+
export { createC1MLeadsProvider } from "./next/providers/leads.js";
|
|
22
|
+
export { createC1MPlansProvider } from "./next/providers/plans.js";
|
|
23
|
+
export { createC1MProfileProvider } from "./next/providers/profile.js";
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next entry: the ACCESS layer. Server-only and Next-coupled.
|
|
3
|
+
*
|
|
4
|
+
* A consuming site should forbid this subpath from `app/**` and
|
|
5
|
+
* `components/**` — if a page can call the door directly, swapping the backend
|
|
6
|
+
* means editing every page and the channel token starts leaking into things
|
|
7
|
+
* that render. Depend on the object returned by `createDashDataLayer` instead.
|
|
8
|
+
*/
|
|
9
|
+
export { createDashDataLayer } from "./next/data-layer.js";
|
|
10
|
+
export { ChannelScopeMismatchError, getChannelClient, getDashChannelClient, getVisitorDashChannelClient, requireDashScope, } from "./next/client.js";
|
|
11
|
+
export { ChannelConfigurationError, resolveChannelEnvironment } from "./next/env.js";
|
|
12
|
+
export { CHANNEL_SITE_CACHE_TAG } from "./next/cache.js";
|
|
13
|
+
export { getChannelAttestation } from "./next/delivery.js";
|
|
14
|
+
export { observeChannelRequest } from "./next/observability.js";
|
|
15
|
+
export { resolveC1MAsset } from "./next/assets.js";
|
|
16
|
+
export { createC1MBootstrapProvider } from "./next/providers/bootstrap.js";
|
|
17
|
+
export { createC1MDirectoryProvider } from "./next/providers/directory.js";
|
|
18
|
+
export { createC1MLeadPortalProvider } from "./next/providers/lead-portal.js";
|
|
19
|
+
export { createC1MLeadsProvider } from "./next/providers/leads.js";
|
|
20
|
+
export { createC1MPlansProvider } from "./next/providers/plans.js";
|
|
21
|
+
export { createC1MProfileProvider } from "./next/providers/profile.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { DirectoryEntry, DirectoryFilter, DirectoryProfileResult, DirectoryRegion } from "../models/directory.js";
|
|
3
|
+
export interface DirectoryProvider {
|
|
4
|
+
listRegions(): Promise<DirectoryRegion[]>;
|
|
5
|
+
list(filter?: DirectoryFilter): Promise<DirectoryEntry[]>;
|
|
6
|
+
get(idOrSlug: string): Promise<DirectoryProfileResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { LeadInput, LeadOutcome } from "../models/leads.js";
|
|
3
|
+
export interface LeadsProvider {
|
|
4
|
+
/**
|
|
5
|
+
* `attemptId` is the idempotency key for one logical submission: the form
|
|
6
|
+
* renders it once, so a double-clicked Send creates one lead, not two.
|
|
7
|
+
*/
|
|
8
|
+
create(input: LeadInput, attemptId: string): Promise<LeadOutcome>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { DashProfile } from "../models/profile.js";
|
|
3
|
+
/**
|
|
4
|
+
* The seam. `lib/profile` and `app/` depend on THIS, never on a provider
|
|
5
|
+
* package — so swapping or mocking the backend touches one adapter, not the site.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProfileProvider {
|
|
8
|
+
loadProfile(): Promise<DashProfile>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "server-only";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape a site's `site.defaults.json` must satisfy. Everything except
|
|
3
|
+
* `name` is optional so an uncommissioned base still builds.
|
|
4
|
+
*/
|
|
5
|
+
export interface SiteDefaults {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/** The real public origin, set at commissioning time. */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Recorded on every captured lead so a dash's CRM can tell its sites apart. */
|
|
11
|
+
leadSource?: string;
|
|
12
|
+
/** Display fallback only; the plan catalog's per-region currency always wins. */
|
|
13
|
+
defaultCurrency?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SiteMeta {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
baseUrl: string | null;
|
|
19
|
+
locale: string;
|
|
20
|
+
iconUrl?: string;
|
|
21
|
+
imageUrl?: string;
|
|
22
|
+
primaryColor?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The bootstrap fields site metadata reads. Structural, so the full DashBootstrap satisfies it. */
|
|
25
|
+
export interface SiteMetaBootstrap {
|
|
26
|
+
seo: {
|
|
27
|
+
title?: string | null;
|
|
28
|
+
description?: string | null;
|
|
29
|
+
};
|
|
30
|
+
site: {
|
|
31
|
+
url?: string | null;
|
|
32
|
+
};
|
|
33
|
+
locale: {
|
|
34
|
+
locale?: string | null;
|
|
35
|
+
};
|
|
36
|
+
branding: {
|
|
37
|
+
faviconUrl?: string | null;
|
|
38
|
+
logoSquareUrl?: string | null;
|
|
39
|
+
coverUrl?: string | null;
|
|
40
|
+
logoUrl?: string | null;
|
|
41
|
+
primaryColor?: string | null;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface SiteConfig {
|
|
45
|
+
siteName: string;
|
|
46
|
+
siteDescription: string;
|
|
47
|
+
leadSource: string;
|
|
48
|
+
defaultCurrency: string;
|
|
49
|
+
resolveSiteBaseUrl(): string | null;
|
|
50
|
+
canonicalUrl(baseUrl: string | null, pathname: string): string | undefined;
|
|
51
|
+
formatMoney(cents: number, currency: string): string;
|
|
52
|
+
resolveSiteMeta(): Promise<SiteMeta>;
|
|
53
|
+
}
|
|
54
|
+
export declare function canonicalUrl(baseUrl: string | null, pathname: string): string | undefined;
|
|
55
|
+
export declare function safeLocale(value: string | null | undefined): string;
|
|
56
|
+
export interface SiteConfigOptions {
|
|
57
|
+
/** Reads the composed bootstrap loader. Omit for a site with no channel access. */
|
|
58
|
+
loadBootstrap?: () => Promise<SiteMetaBootstrap>;
|
|
59
|
+
/** Injected for testability; defaults to `process.env`. */
|
|
60
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Binds one site's `site.defaults.json` into the helpers that need it.
|
|
64
|
+
*
|
|
65
|
+
* This exists because `leadSource`, `baseUrl` and `defaultCurrency` are the
|
|
66
|
+
* ONLY things that legitimately differ between two dash sites built on this
|
|
67
|
+
* package. Passing them in once, here, is what lets every other module in the
|
|
68
|
+
* package be identical across sites instead of copy-pasted and re-edited.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createSiteConfig(defaults: SiteDefaults, options?: SiteConfigOptions): SiteConfig;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { formatMoney } from "./format.js";
|
|
2
|
+
export function canonicalUrl(baseUrl, pathname) {
|
|
3
|
+
if (!baseUrl)
|
|
4
|
+
return undefined;
|
|
5
|
+
const path = pathname === "/" ? "" : `/${pathname.replace(/^\/+|\/+$/g, "")}`;
|
|
6
|
+
return `${baseUrl}${path}`;
|
|
7
|
+
}
|
|
8
|
+
export function safeLocale(value) {
|
|
9
|
+
const locale = value?.trim().replaceAll("_", "-");
|
|
10
|
+
return locale && /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i.test(locale) ? locale : "en";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Binds one site's `site.defaults.json` into the helpers that need it.
|
|
14
|
+
*
|
|
15
|
+
* This exists because `leadSource`, `baseUrl` and `defaultCurrency` are the
|
|
16
|
+
* ONLY things that legitimately differ between two dash sites built on this
|
|
17
|
+
* package. Passing them in once, here, is what lets every other module in the
|
|
18
|
+
* package be identical across sites instead of copy-pasted and re-edited.
|
|
19
|
+
*/
|
|
20
|
+
export function createSiteConfig(defaults, options = {}) {
|
|
21
|
+
const env = options.env ?? process.env;
|
|
22
|
+
const siteName = defaults.name;
|
|
23
|
+
const siteDescription = defaults.description ?? "";
|
|
24
|
+
const leadSource = (defaults.leadSource ?? "").trim() || siteName;
|
|
25
|
+
const defaultCurrency = (defaults.defaultCurrency ?? "").trim() || "GBP";
|
|
26
|
+
/**
|
|
27
|
+
* Resolution order:
|
|
28
|
+
* 1. `baseUrl` from site.defaults.json — the real domain.
|
|
29
|
+
* 2. Vercel's production domain when deployed but not yet commissioned.
|
|
30
|
+
* 3. null — metadata falls back to relative URLs and the sitemap is empty,
|
|
31
|
+
* which is correct for a base that must never be indexed as itself.
|
|
32
|
+
*/
|
|
33
|
+
function resolveSiteBaseUrl() {
|
|
34
|
+
const configured = defaults.baseUrl?.trim();
|
|
35
|
+
if (configured)
|
|
36
|
+
return configured.replace(/\/+$/, "");
|
|
37
|
+
const vercelHost = env.VERCEL_PROJECT_PRODUCTION_URL?.trim();
|
|
38
|
+
if (vercelHost)
|
|
39
|
+
return `https://${vercelHost}`;
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Platform first, site defaults as the fallback: name, description and
|
|
44
|
+
* public origin come from the dash bootstrap when the channel is reachable,
|
|
45
|
+
* so a commissioned site never hardcodes its own domain. An unreachable
|
|
46
|
+
* channel degrades to the defaults instead of failing the request.
|
|
47
|
+
*/
|
|
48
|
+
async function resolveSiteMeta() {
|
|
49
|
+
const fallback = {
|
|
50
|
+
name: siteName,
|
|
51
|
+
description: siteDescription,
|
|
52
|
+
baseUrl: resolveSiteBaseUrl(),
|
|
53
|
+
locale: "en",
|
|
54
|
+
};
|
|
55
|
+
if (!options.loadBootstrap)
|
|
56
|
+
return fallback;
|
|
57
|
+
try {
|
|
58
|
+
const bootstrap = await options.loadBootstrap();
|
|
59
|
+
return {
|
|
60
|
+
name: bootstrap.seo.title || siteName,
|
|
61
|
+
description: bootstrap.seo.description || siteDescription,
|
|
62
|
+
baseUrl: bootstrap.site.url ?? resolveSiteBaseUrl(),
|
|
63
|
+
locale: safeLocale(bootstrap.locale.locale),
|
|
64
|
+
...(bootstrap.branding.faviconUrl ?? bootstrap.branding.logoSquareUrl
|
|
65
|
+
? { iconUrl: (bootstrap.branding.faviconUrl ?? bootstrap.branding.logoSquareUrl) }
|
|
66
|
+
: {}),
|
|
67
|
+
...(bootstrap.branding.coverUrl ?? bootstrap.branding.logoUrl
|
|
68
|
+
? { imageUrl: (bootstrap.branding.coverUrl ?? bootstrap.branding.logoUrl) }
|
|
69
|
+
: {}),
|
|
70
|
+
...(bootstrap.branding.primaryColor ? { primaryColor: bootstrap.branding.primaryColor } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return fallback;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
siteName,
|
|
79
|
+
siteDescription,
|
|
80
|
+
leadSource,
|
|
81
|
+
defaultCurrency,
|
|
82
|
+
resolveSiteBaseUrl,
|
|
83
|
+
canonicalUrl,
|
|
84
|
+
formatMoney: (cents, currency) => formatMoney(cents, currency, defaultCurrency),
|
|
85
|
+
resolveSiteMeta,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
export function SiteErrorFallback({ error, reset, }) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
console.error({
|
|
7
|
+
event: "c1m.site.render_error",
|
|
8
|
+
digest: error.digest ?? "unavailable",
|
|
9
|
+
});
|
|
10
|
+
}, [error.digest]);
|
|
11
|
+
return (_jsx("main", { className: "grid min-h-screen place-items-center bg-subtle px-5 py-16", children: _jsxs("section", { className: "w-full max-w-xl rounded-[2rem] border border-border bg-white p-8 shadow-xl shadow-slate-900/5 sm:p-12", children: [_jsx("p", { className: "text-xs font-semibold uppercase tracking-[0.18em] text-red-700", children: "Site unavailable" }), _jsx("h1", { className: "mt-4 text-balance text-4xl font-semibold tracking-[-0.045em] text-ink", children: "We could not load this site." }), _jsx("p", { className: "mt-4 leading-7 text-muted", children: "Please try again. If the problem continues, contact the site owner." }), _jsx("button", { className: "mt-7 min-h-11 rounded-full bg-ink px-5 py-2.5 text-sm font-semibold text-white hover:bg-slate-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ink", onClick: reset, type: "button", children: "Try again" })] }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function Container({ children, className }: {
|
|
2
|
+
children: React.ReactNode;
|
|
3
|
+
className?: string;
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
export declare function Eyebrow({ children, className }: {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
9
|
+
export declare function ButtonLink({ children, href, variant, className, }: {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
href: string;
|
|
12
|
+
variant?: "primary" | "secondary" | "quiet";
|
|
13
|
+
className?: string;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
export declare function SectionHeading({ eyebrow, title, description, }: {
|
|
16
|
+
eyebrow?: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
}): import("react").JSX.Element;
|
|
20
|
+
export declare function StatusPanel({ title, children, className, }: {
|
|
21
|
+
title: string;
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
className?: string;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
25
|
+
export declare function VerifiedBadge(): import("react").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
function classes(...values) {
|
|
4
|
+
return values.filter(Boolean).join(" ");
|
|
5
|
+
}
|
|
6
|
+
export function Container({ children, className }) {
|
|
7
|
+
return _jsx("div", { className: classes("mx-auto w-full max-w-6xl px-5 sm:px-8", className), children: children });
|
|
8
|
+
}
|
|
9
|
+
export function Eyebrow({ children, className }) {
|
|
10
|
+
return (_jsx("p", { className: classes("text-xs font-semibold uppercase tracking-[0.18em] text-accent-text", className), children: children }));
|
|
11
|
+
}
|
|
12
|
+
export function ButtonLink({ children, href, variant = "primary", className, }) {
|
|
13
|
+
return (_jsx(Link, { className: classes("inline-flex min-h-11 items-center justify-center rounded-full px-5 py-2.5 text-sm font-semibold transition-colors", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent-text", variant === "primary" && "border border-accent-text bg-accent text-accent-foreground hover:bg-accent-strong", variant === "secondary" && "border border-border bg-white text-ink hover:border-ink/30 hover:bg-subtle", variant === "quiet" && "px-0 text-accent-text hover:text-accent-strong", className), href: href, children: children }));
|
|
14
|
+
}
|
|
15
|
+
export function SectionHeading({ eyebrow, title, description, }) {
|
|
16
|
+
return (_jsxs("div", { className: "max-w-2xl", children: [eyebrow ? _jsx(Eyebrow, { children: eyebrow }) : null, _jsx("h2", { className: "mt-3 text-balance text-3xl font-semibold tracking-[-0.035em] text-ink sm:text-4xl", children: title }), description ? _jsx("p", { className: "mt-4 text-pretty text-base leading-7 text-muted sm:text-lg", children: description }) : null] }));
|
|
17
|
+
}
|
|
18
|
+
export function StatusPanel({ title, children, className, }) {
|
|
19
|
+
return (_jsxs("section", { className: classes("rounded-3xl border border-border bg-subtle px-6 py-10 text-center", className), children: [_jsx("h2", { className: "text-lg font-semibold text-ink", children: title }), children ? _jsx("div", { className: "mt-2 text-sm leading-6 text-muted", children: children }) : null] }));
|
|
20
|
+
}
|
|
21
|
+
export function VerifiedBadge() {
|
|
22
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1 rounded-full bg-success-soft px-2.5 py-1 text-xs font-semibold text-success", children: [_jsx("span", { "aria-hidden": "true", children: "\u2713" }), " Verified"] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ImageProps } from "next/image";
|
|
2
|
+
type SiteImageProps = Omit<ImageProps, "src"> & {
|
|
3
|
+
src?: string;
|
|
4
|
+
};
|
|
5
|
+
/** Provider-normalized SaaSDash media rendered through one layout-safe image seam. */
|
|
6
|
+
export declare function SiteImage({ src, alt, unoptimized, ...props }: SiteImageProps): import("react").JSX.Element | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Image, {} from "next/image";
|
|
3
|
+
import { shouldOptimizeSaaSDashImage } from "../image-policy.js";
|
|
4
|
+
/** Provider-normalized SaaSDash media rendered through one layout-safe image seam. */
|
|
5
|
+
export function SiteImage({ src, alt, unoptimized, ...props }) {
|
|
6
|
+
if (!src)
|
|
7
|
+
return null;
|
|
8
|
+
return (_jsx(Image, { ...props, alt: alt, src: src, unoptimized: unoptimized ?? !shouldOptimizeSaaSDashImage(src) }));
|
|
9
|
+
}
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI entry: the DESIGN layer primitives.
|
|
3
|
+
*
|
|
4
|
+
* These are unstyled-by-intent structural primitives, not a design system.
|
|
5
|
+
* They render Tailwind utility classes that resolve against CSS custom
|
|
6
|
+
* properties the consuming site owns — `--ink`, `--muted`, `--subtle`,
|
|
7
|
+
* `--border`, `--accent`, `--accent-foreground`, `--accent-text`. A site
|
|
8
|
+
* rebrands by redefining those tokens, not by forking these components.
|
|
9
|
+
*/
|
|
10
|
+
export { ButtonLink, Container, Eyebrow, SectionHeading, StatusPanel, VerifiedBadge, } from "./ui/primitives.js";
|
|
11
|
+
export { SiteImage } from "./ui/site-image.js";
|
|
12
|
+
export { SiteErrorFallback } from "./ui/error-fallback.js";
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI entry: the DESIGN layer primitives.
|
|
3
|
+
*
|
|
4
|
+
* These are unstyled-by-intent structural primitives, not a design system.
|
|
5
|
+
* They render Tailwind utility classes that resolve against CSS custom
|
|
6
|
+
* properties the consuming site owns — `--ink`, `--muted`, `--subtle`,
|
|
7
|
+
* `--border`, `--accent`, `--accent-foreground`, `--accent-text`. A site
|
|
8
|
+
* rebrands by redefining those tokens, not by forking these components.
|
|
9
|
+
*/
|
|
10
|
+
export { ButtonLink, Container, Eyebrow, SectionHeading, StatusPanel, VerifiedBadge, } from "./ui/primitives.js";
|
|
11
|
+
export { SiteImage } from "./ui/site-image.js";
|
|
12
|
+
export { SiteErrorFallback } from "./ui/error-fallback.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const LOCAL_HTTP_HOSTS = new Set(["localhost", "127.0.0.1", "::1"]);
|
|
2
|
+
function candidate(value) {
|
|
3
|
+
return typeof value === "string" ? value.trim() : "";
|
|
4
|
+
}
|
|
5
|
+
function internal(value) {
|
|
6
|
+
return ((value.startsWith("/") && !value.startsWith("//")) ||
|
|
7
|
+
value.startsWith("#") ||
|
|
8
|
+
value.startsWith("?"));
|
|
9
|
+
}
|
|
10
|
+
export function safePublicHref(value) {
|
|
11
|
+
const href = candidate(value);
|
|
12
|
+
if (!href)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (internal(href))
|
|
15
|
+
return href;
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL(href);
|
|
18
|
+
if (["https:", "http:", "mailto:", "tel:"].includes(url.protocol))
|
|
19
|
+
return url.toString();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
export function safeImageSource(value) {
|
|
27
|
+
const source = candidate(value);
|
|
28
|
+
if (!source)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (source.startsWith("/") && !source.startsWith("//"))
|
|
31
|
+
return source;
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(source);
|
|
34
|
+
if (url.protocol === "https:")
|
|
35
|
+
return url.toString();
|
|
36
|
+
if (url.protocol === "http:" && LOCAL_HTTP_HOSTS.has(url.hostname))
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
export function isInternalHref(href) {
|
|
45
|
+
return internal(href);
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const directoryKeyPattern = /^[A-Za-z0-9_-]+$/;
|
|
2
|
+
const MAX_DIRECTORY_KEY_LENGTH = 128;
|
|
3
|
+
export function validateDirectoryKey(value) {
|
|
4
|
+
if (typeof value !== "string")
|
|
5
|
+
return null;
|
|
6
|
+
const normalized = value.trim();
|
|
7
|
+
return normalized.length > 0 &&
|
|
8
|
+
normalized.length <= MAX_DIRECTORY_KEY_LENGTH &&
|
|
9
|
+
directoryKeyPattern.test(normalized)
|
|
10
|
+
? normalized
|
|
11
|
+
: null;
|
|
12
|
+
}
|
|
13
|
+
export function validateRegionFilter(value) {
|
|
14
|
+
return validateDirectoryKey(value) ?? undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LeadInput } from "../models/leads.js";
|
|
2
|
+
export declare const LEAD_LIMITS: {
|
|
3
|
+
readonly name: 120;
|
|
4
|
+
readonly email: 254;
|
|
5
|
+
readonly phone: 40;
|
|
6
|
+
readonly message: 4000;
|
|
7
|
+
};
|
|
8
|
+
export interface ValidatedLead {
|
|
9
|
+
attemptId: string;
|
|
10
|
+
input: LeadInput;
|
|
11
|
+
}
|
|
12
|
+
export type LeadField = "name" | "email" | "phone" | "message";
|
|
13
|
+
export type LeadValidationResult = {
|
|
14
|
+
valid: true;
|
|
15
|
+
value: ValidatedLead;
|
|
16
|
+
} | {
|
|
17
|
+
valid: false;
|
|
18
|
+
fieldErrors: Partial<Record<LeadField, string>>;
|
|
19
|
+
formError?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function validateLeadForm(formData: FormData): LeadValidationResult;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const LEAD_LIMITS = {
|
|
2
|
+
name: 120,
|
|
3
|
+
email: 254,
|
|
4
|
+
phone: 40,
|
|
5
|
+
message: 4_000,
|
|
6
|
+
};
|
|
7
|
+
const attemptPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
8
|
+
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
9
|
+
function optional(value, max) {
|
|
10
|
+
if (typeof value !== "string")
|
|
11
|
+
return undefined;
|
|
12
|
+
const normalized = value.trim();
|
|
13
|
+
return normalized && normalized.length <= max ? normalized : undefined;
|
|
14
|
+
}
|
|
15
|
+
export function validateLeadForm(formData) {
|
|
16
|
+
const attemptId = optional(formData.get("lead_attempt_id"), 64);
|
|
17
|
+
const rawName = formData.get("name");
|
|
18
|
+
const rawEmail = formData.get("email");
|
|
19
|
+
const rawPhone = formData.get("phone");
|
|
20
|
+
const rawMessage = formData.get("message");
|
|
21
|
+
const name = optional(rawName, LEAD_LIMITS.name);
|
|
22
|
+
const email = optional(rawEmail, LEAD_LIMITS.email)?.toLowerCase();
|
|
23
|
+
const phone = optional(rawPhone, LEAD_LIMITS.phone);
|
|
24
|
+
const message = optional(rawMessage, LEAD_LIMITS.message);
|
|
25
|
+
const fieldErrors = {};
|
|
26
|
+
if (!email) {
|
|
27
|
+
fieldErrors.email = typeof rawEmail === "string" && rawEmail.trim().length > LEAD_LIMITS.email
|
|
28
|
+
? `Email must be ${LEAD_LIMITS.email} characters or fewer.`
|
|
29
|
+
: "Enter your email address.";
|
|
30
|
+
}
|
|
31
|
+
else if (!emailPattern.test(email)) {
|
|
32
|
+
fieldErrors.email = "Enter a valid email address.";
|
|
33
|
+
}
|
|
34
|
+
// A non-empty value over its limit is invalid, not silently discarded.
|
|
35
|
+
if (typeof rawName === "string" && rawName.trim() && !name)
|
|
36
|
+
fieldErrors.name = `Name must be ${LEAD_LIMITS.name} characters or fewer.`;
|
|
37
|
+
if (typeof rawPhone === "string" && rawPhone.trim() && !phone)
|
|
38
|
+
fieldErrors.phone = `Phone must be ${LEAD_LIMITS.phone} characters or fewer.`;
|
|
39
|
+
if (typeof rawMessage === "string" && rawMessage.trim() && !message)
|
|
40
|
+
fieldErrors.message = `Message must be ${LEAD_LIMITS.message} characters or fewer.`;
|
|
41
|
+
const formError = !attemptId || !attemptPattern.test(attemptId)
|
|
42
|
+
? "This form has expired. Refresh the page and try again."
|
|
43
|
+
: undefined;
|
|
44
|
+
if (formError || Object.keys(fieldErrors).length > 0) {
|
|
45
|
+
return { valid: false, fieldErrors, ...(formError ? { formError } : {}) };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
valid: true,
|
|
49
|
+
value: {
|
|
50
|
+
attemptId: attemptId,
|
|
51
|
+
input: {
|
|
52
|
+
email: email,
|
|
53
|
+
...(name ? { name } : {}),
|
|
54
|
+
...(phone ? { phone } : {}),
|
|
55
|
+
...(message ? { message } : {}),
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|