@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cloud1Media Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @c1m-public/dash-site-kit
|
|
2
|
+
|
|
3
|
+
The shared transport, domain and presentation layer for MML **dash-scoped**
|
|
4
|
+
public sites — the marketing site a dash publishes at its own domain, backed by
|
|
5
|
+
a dash-scoped SaaSDash Channel token.
|
|
6
|
+
|
|
7
|
+
It exists because that layer was being copy-pasted. Across the maintained
|
|
8
|
+
`dash-site` base and its commissioned sites, roughly 49 of 69 shared-path source
|
|
9
|
+
files were byte-identical, and the copies had begun to drift: one site missed a
|
|
10
|
+
fix and served the first visitor's currency to everyone for 60 seconds. This
|
|
11
|
+
package is that identical set, published once.
|
|
12
|
+
|
|
13
|
+
> Not for workspace sites. A workspace site's surface (cart, catalog, giving,
|
|
14
|
+
> session, subscriptions) shares almost nothing with this one — measured at 3 of
|
|
15
|
+
> 16 files. Do not widen this package to cover it.
|
|
16
|
+
|
|
17
|
+
## Entry points
|
|
18
|
+
|
|
19
|
+
The three subpaths are the layer boundary, made structural:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
design (app/, components/) → logic → access
|
|
23
|
+
/ui . /next
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
| Import | Layer | Contents |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `@c1m-public/dash-site-kit` | logic | domain models, ports, validation, URL/image policy, `formatMoney`, `createSiteConfig` |
|
|
29
|
+
| `@c1m-public/dash-site-kit/next` | access | channel client, providers, `createDashDataLayer` |
|
|
30
|
+
| `@c1m-public/dash-site-kit/ui` | design | structural primitives |
|
|
31
|
+
|
|
32
|
+
The root is framework-neutral — no `server-only`, no Next, no React — so it is
|
|
33
|
+
safe to import from anywhere, including a client component. `/next` is
|
|
34
|
+
server-only.
|
|
35
|
+
|
|
36
|
+
**Forbid `/next` in your design layer.** A page that can call the door directly
|
|
37
|
+
makes the backend un-swappable and starts leaking the channel token into things
|
|
38
|
+
that render:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
// eslint.config.mjs
|
|
42
|
+
{
|
|
43
|
+
files: ["app/**/*.{ts,tsx}", "components/**/*.{ts,tsx}"],
|
|
44
|
+
rules: {
|
|
45
|
+
"no-restricted-imports": ["error", {
|
|
46
|
+
paths: [{
|
|
47
|
+
name: "@c1m-public/dash-site-kit/next",
|
|
48
|
+
message: "The design layer must not talk to the API. Use the data layer you composed in lib/.",
|
|
49
|
+
}],
|
|
50
|
+
}],
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Composing a site
|
|
56
|
+
|
|
57
|
+
Two calls, in one `lib/` module the rest of the site imports:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// lib/site.ts
|
|
61
|
+
import "server-only";
|
|
62
|
+
import { createSiteConfig } from "@c1m-public/dash-site-kit";
|
|
63
|
+
import { createDashDataLayer } from "@c1m-public/dash-site-kit/next";
|
|
64
|
+
import siteDefaults from "@/site.defaults.json";
|
|
65
|
+
import { isLocalPreviewMode, localPreviewBootstrap, localPreviewProfile } from "@/lib/preview";
|
|
66
|
+
|
|
67
|
+
export const data = createDashDataLayer({
|
|
68
|
+
leadSource: siteDefaults.leadSource ?? siteDefaults.name,
|
|
69
|
+
preview: {
|
|
70
|
+
enabled: isLocalPreviewMode,
|
|
71
|
+
bootstrap: localPreviewBootstrap,
|
|
72
|
+
profile: localPreviewProfile,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const site = createSiteConfig(siteDefaults, {
|
|
77
|
+
loadBootstrap: data.loadDashBootstrap,
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`data` exposes `loadDashBootstrap`, `loadDashProfile`, `listDirectoryRegions`,
|
|
82
|
+
`getDirectoryRegion`, `listDirectory`, `getDirectoryProfile`, `loadDashPlans`,
|
|
83
|
+
`submitLead`, `requestPortalLink` and `viewPortal`. Every read is wrapped in
|
|
84
|
+
React `cache`, so the shell and the page share one request-scoped fetch.
|
|
85
|
+
|
|
86
|
+
### Why these two arguments and no others
|
|
87
|
+
|
|
88
|
+
They are the only things that legitimately differ between two dash sites:
|
|
89
|
+
|
|
90
|
+
- **`leadSource`** is recorded on every capture so a dash's CRM can tell its
|
|
91
|
+
sites apart. It is required, not defaulted — a wrong source silently
|
|
92
|
+
mis-attributes real leads, which is worse than a startup error.
|
|
93
|
+
- **`preview`** is the credential-free local preview. This is the seam that used
|
|
94
|
+
to force every site to hand-write its own
|
|
95
|
+
`lib/{bootstrap,directory,profile}/index.ts`, and those files were the single
|
|
96
|
+
largest source of drift between sites that were otherwise identical.
|
|
97
|
+
|
|
98
|
+
Everything else — the transport, the normalisation, the validation, the cache
|
|
99
|
+
policy — is the same everywhere by definition, which is why it is in here.
|
|
100
|
+
|
|
101
|
+
## Configuration
|
|
102
|
+
|
|
103
|
+
The access layer reads the channel token from the environment. `SAASDASH_*` is
|
|
104
|
+
preferred; `C1M_*` is accepted for older sites:
|
|
105
|
+
|
|
106
|
+
| Variable | Required | Meaning |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `SAASDASH_CHANNEL_TOKEN` / `C1M_CHANNEL_TOKEN` | yes | dash-scoped channel key, `sk_chan_…` |
|
|
109
|
+
| `SAASDASH_API_URL` / `C1M_API_URL` | no | override only for local or self-hosted |
|
|
110
|
+
|
|
111
|
+
The token is **server-only**. A `NEXT_PUBLIC_*` form of either variable is
|
|
112
|
+
rejected at startup rather than ignored.
|
|
113
|
+
|
|
114
|
+
## Cache policy
|
|
115
|
+
|
|
116
|
+
Two clients, deliberately:
|
|
117
|
+
|
|
118
|
+
- A **shared, revalidating** client for reads that are identical for every
|
|
119
|
+
visitor — profile, directory, regions.
|
|
120
|
+
- A **`no-store`** client for anything whose answer depends on who is asking —
|
|
121
|
+
geo detection (which picks the pricing region and therefore the displayed
|
|
122
|
+
currency) and lead capture.
|
|
123
|
+
|
|
124
|
+
The npm channel client forces `no-store` only for mutations and
|
|
125
|
+
customer-session reads, so a signed-visitor GET on the shared client would be
|
|
126
|
+
answered from the first visitor's cache entry for everyone that follows. That is
|
|
127
|
+
a real bug this package exists to stop repeating, and it is covered by tests
|
|
128
|
+
that fail if the two clients are merged.
|
|
129
|
+
|
|
130
|
+
## Styling contract
|
|
131
|
+
|
|
132
|
+
`/ui` ships structural primitives, not a design system. They render Tailwind
|
|
133
|
+
utility classes that resolve against CSS custom properties the **site** owns:
|
|
134
|
+
|
|
135
|
+
`--ink`, `--muted`, `--subtle`, `--border`, `--accent`, `--accent-foreground`,
|
|
136
|
+
`--accent-text`
|
|
137
|
+
|
|
138
|
+
A site rebrands by redefining those tokens in its own `globals.css`, not by
|
|
139
|
+
forking the components. If a primitive needs a variant that cannot be expressed
|
|
140
|
+
through the tokens, add the variant here rather than copying the file back into
|
|
141
|
+
a site — that copy is how the drift started.
|
|
142
|
+
|
|
143
|
+
## Peer dependencies
|
|
144
|
+
|
|
145
|
+
`@c1m-public/channel-client` (>=0.19.0), `next` 16, `react` 19.
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money is rendered from minor units, never from a float. A price that has been
|
|
3
|
+
* through a `number` division is a price that can be wrong by a penny, and a
|
|
4
|
+
* penny is enough to make a pricing page disagree with an invoice.
|
|
5
|
+
*
|
|
6
|
+
* `fallbackCurrency` is used only when the catalog row carries no currency of
|
|
7
|
+
* its own; the plan catalog's per-region currency always wins. Sites normally
|
|
8
|
+
* reach this through `createSiteConfig().formatMoney`, which binds the
|
|
9
|
+
* fallback from `site.defaults.json` once.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatMoney(cents: number, currency: string, fallbackCurrency?: string): string;
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money is rendered from minor units, never from a float. A price that has been
|
|
3
|
+
* through a `number` division is a price that can be wrong by a penny, and a
|
|
4
|
+
* penny is enough to make a pricing page disagree with an invoice.
|
|
5
|
+
*
|
|
6
|
+
* `fallbackCurrency` is used only when the catalog row carries no currency of
|
|
7
|
+
* its own; the plan catalog's per-region currency always wins. Sites normally
|
|
8
|
+
* reach this through `createSiteConfig().formatMoney`, which binds the
|
|
9
|
+
* fallback from `site.defaults.json` once.
|
|
10
|
+
*/
|
|
11
|
+
export function formatMoney(cents, currency, fallbackCurrency = "GBP") {
|
|
12
|
+
return new Intl.NumberFormat(undefined, {
|
|
13
|
+
style: "currency",
|
|
14
|
+
currency: currency || fallbackCurrency,
|
|
15
|
+
}).format(cents / 100);
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only known SaaSDash origins use the Next image proxy. Absolute media URLs are a
|
|
3
|
+
* valid Channel API shape; unknown HTTPS hosts still render through next/image
|
|
4
|
+
* with optimization bypassed instead of becoming a runtime hostname error.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shouldOptimizeSaaSDashImage(src: string, configuredApiUrl?: string | undefined): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const MANAGED_API_ORIGIN = "https://api.saasdash.app";
|
|
2
|
+
function origin(value) {
|
|
3
|
+
if (!value)
|
|
4
|
+
return undefined;
|
|
5
|
+
try {
|
|
6
|
+
return new URL(value).origin;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Only known SaaSDash origins use the Next image proxy. Absolute media URLs are a
|
|
14
|
+
* valid Channel API shape; unknown HTTPS hosts still render through next/image
|
|
15
|
+
* with optimization bypassed instead of becoming a runtime hostname error.
|
|
16
|
+
*/
|
|
17
|
+
export function shouldOptimizeSaaSDashImage(src, configuredApiUrl = process.env.SAASDASH_API_URL ?? process.env.C1M_API_URL) {
|
|
18
|
+
if (src.startsWith("/") && !src.startsWith("//"))
|
|
19
|
+
return true;
|
|
20
|
+
try {
|
|
21
|
+
const source = new URL(src);
|
|
22
|
+
const knownOrigin = source.origin === MANAGED_API_ORIGIN || source.origin === origin(configuredApiUrl);
|
|
23
|
+
return knownOrigin && source.pathname.startsWith("/tenant-media/");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root entry: the LOGIC layer. Framework-neutral — no server-only, no Next,
|
|
3
|
+
* no React. Safe to import from anywhere in a consuming site, including the
|
|
4
|
+
* design layer.
|
|
5
|
+
*
|
|
6
|
+
* The access layer lives at `@c1m-public/dash-site-kit/next` and the
|
|
7
|
+
* presentational primitives at `@c1m-public/dash-site-kit/ui`. That split is
|
|
8
|
+
* what lets a site's ESLint config forbid `app/**` and `components/**` from
|
|
9
|
+
* reaching the transport, as a package boundary rather than a folder rule.
|
|
10
|
+
*/
|
|
11
|
+
export type { DashBootstrap } from "./models/bootstrap.js";
|
|
12
|
+
export type { DirectoryEntry, DirectoryFilter, DirectoryProfileResult, DirectoryRegion, } from "./models/directory.js";
|
|
13
|
+
export type { LeadInput, LeadOutcome } from "./models/leads.js";
|
|
14
|
+
export type { RequestLinkOutcome, ViewOutcome } from "./models/lead-portal.js";
|
|
15
|
+
export type { Plan, PlanCatalog, PlanPrice, PlanRegion } from "./models/plans.js";
|
|
16
|
+
export type { DashProfile } from "./models/profile.js";
|
|
17
|
+
export type { BootstrapProvider } from "./ports/bootstrap.js";
|
|
18
|
+
export type { DirectoryProvider } from "./ports/directory.js";
|
|
19
|
+
export type { LeadsProvider } from "./ports/leads.js";
|
|
20
|
+
export type { LeadPortalProvider } from "./ports/lead-portal.js";
|
|
21
|
+
export type { PlansProvider } from "./ports/plans.js";
|
|
22
|
+
export type { ProfileProvider } from "./ports/profile.js";
|
|
23
|
+
export { validateDirectoryKey, validateRegionFilter } from "./validation/directory.js";
|
|
24
|
+
export { LEAD_LIMITS, validateLeadForm } from "./validation/leads.js";
|
|
25
|
+
export type { LeadField, LeadValidationResult, ValidatedLead } from "./validation/leads.js";
|
|
26
|
+
export { formatMoney } from "./format.js";
|
|
27
|
+
export * from "./url-policy.js";
|
|
28
|
+
export * from "./image-policy.js";
|
|
29
|
+
export { canonicalUrl, createSiteConfig, safeLocale, } from "./site-config.js";
|
|
30
|
+
export type { SiteConfig, SiteConfigOptions, SiteDefaults, SiteMeta, SiteMetaBootstrap, } from "./site-config.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { validateDirectoryKey, validateRegionFilter } from "./validation/directory.js";
|
|
2
|
+
export { LEAD_LIMITS, validateLeadForm } from "./validation/leads.js";
|
|
3
|
+
export { formatMoney } from "./format.js";
|
|
4
|
+
export * from "./url-policy.js";
|
|
5
|
+
export * from "./image-policy.js";
|
|
6
|
+
export { canonicalUrl, createSiteConfig, safeLocale, } from "./site-config.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything the shell needs on every request, from ONE channel read
|
|
3
|
+
* (`dash.init`): who the dash is, how it looks, where it lives, what it
|
|
4
|
+
* defaults to. The public profile page (gallery, about, member count) is a
|
|
5
|
+
* separate, page-local read — see `lib/profile`.
|
|
6
|
+
*/
|
|
7
|
+
export interface DashBootstrap {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
branding: {
|
|
12
|
+
primaryColor?: string;
|
|
13
|
+
logoUrl?: string;
|
|
14
|
+
logoSquareUrl?: string;
|
|
15
|
+
faviconUrl?: string;
|
|
16
|
+
coverUrl?: string;
|
|
17
|
+
};
|
|
18
|
+
locale: {
|
|
19
|
+
region?: string;
|
|
20
|
+
currency?: string;
|
|
21
|
+
locale?: string;
|
|
22
|
+
timezone?: string;
|
|
23
|
+
};
|
|
24
|
+
/** The dash's public origin the platform knows, or null before commissioning. */
|
|
25
|
+
site: {
|
|
26
|
+
url: string | null;
|
|
27
|
+
source: "hostname" | "channel" | "hosted" | null;
|
|
28
|
+
};
|
|
29
|
+
seo: {
|
|
30
|
+
title: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface DirectoryRegion {
|
|
2
|
+
code: string;
|
|
3
|
+
label: string;
|
|
4
|
+
/** How many listed workspaces sit in this region — render filters from it. */
|
|
5
|
+
count: number;
|
|
6
|
+
}
|
|
7
|
+
export interface DirectoryEntry {
|
|
8
|
+
id: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
name: string;
|
|
11
|
+
tagline?: string;
|
|
12
|
+
category?: string;
|
|
13
|
+
logoUrl?: string;
|
|
14
|
+
reviewCount: number;
|
|
15
|
+
averageRating: number;
|
|
16
|
+
verified: boolean;
|
|
17
|
+
regionCode?: string;
|
|
18
|
+
regionLabel?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DirectoryProfile extends DirectoryEntry {
|
|
21
|
+
description?: string;
|
|
22
|
+
createdAt?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A missing listing is an expected state (unlisted, renamed, or a typo in the
|
|
26
|
+
* URL), not an exception — the page turns it into a 404.
|
|
27
|
+
*/
|
|
28
|
+
export type DirectoryProfileResult = {
|
|
29
|
+
state: "resolved";
|
|
30
|
+
profile: DirectoryProfile;
|
|
31
|
+
} | {
|
|
32
|
+
state: "missing";
|
|
33
|
+
};
|
|
34
|
+
export interface DirectoryFilter {
|
|
35
|
+
region?: string;
|
|
36
|
+
category?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Lead Match Portal: a requester asks for a signed link by email, then
|
|
3
|
+
* views their quote requests with the token that link carries. Domain models
|
|
4
|
+
* only — the wire shape lives in the provider.
|
|
5
|
+
*/
|
|
6
|
+
export type LeadPortalRequestStatus = "received" | "matching" | "matched" | "closed";
|
|
7
|
+
export interface LeadPortalMatch {
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
category?: string;
|
|
11
|
+
logoUrl?: string;
|
|
12
|
+
coverageArea?: string;
|
|
13
|
+
verified: boolean;
|
|
14
|
+
rating?: number;
|
|
15
|
+
reviewCount?: number;
|
|
16
|
+
responded: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface LeadPortalRequest {
|
|
19
|
+
reference: string;
|
|
20
|
+
submittedAt: string;
|
|
21
|
+
status: LeadPortalRequestStatus;
|
|
22
|
+
summary: {
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
moveDate?: string;
|
|
26
|
+
size?: string;
|
|
27
|
+
};
|
|
28
|
+
matches: LeadPortalMatch[];
|
|
29
|
+
}
|
|
30
|
+
export interface LeadPortalView {
|
|
31
|
+
email: string;
|
|
32
|
+
requests: LeadPortalRequest[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `requested` is deliberately the ONLY success state, whether or not the email
|
|
36
|
+
* exists: the door does not enumerate accounts, and neither do we.
|
|
37
|
+
*/
|
|
38
|
+
export type RequestLinkOutcome = {
|
|
39
|
+
state: "requested";
|
|
40
|
+
} | {
|
|
41
|
+
state: "invalid";
|
|
42
|
+
} | {
|
|
43
|
+
state: "error";
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* `invalid_link` is an expired, malformed or revoked token — the visitor
|
|
47
|
+
* should request a fresh one. `unavailable` is everything transient.
|
|
48
|
+
*/
|
|
49
|
+
export type ViewOutcome = {
|
|
50
|
+
state: "ok";
|
|
51
|
+
view: LeadPortalView;
|
|
52
|
+
} | {
|
|
53
|
+
state: "invalid_link";
|
|
54
|
+
} | {
|
|
55
|
+
state: "unavailable";
|
|
56
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface LeadInput {
|
|
2
|
+
name?: string;
|
|
3
|
+
email: string;
|
|
4
|
+
phone?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* `invalid` is the server rejecting the submission (bad email, missing field
|
|
9
|
+
* the door requires); `error` is everything transient. The form renders them
|
|
10
|
+
* differently — "fix your input" versus "try again".
|
|
11
|
+
*/
|
|
12
|
+
export type LeadOutcome = {
|
|
13
|
+
state: "created";
|
|
14
|
+
id: string;
|
|
15
|
+
} | {
|
|
16
|
+
state: "invalid";
|
|
17
|
+
} | {
|
|
18
|
+
state: "error";
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money stays in minor units until the moment it is rendered (`lib/format.ts`),
|
|
3
|
+
* never as a float — mirroring the platform convention.
|
|
4
|
+
*/
|
|
5
|
+
export interface PlanPrice {
|
|
6
|
+
currency: string;
|
|
7
|
+
monthlyCents: number;
|
|
8
|
+
yearlyCents: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Plan {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
level: number;
|
|
15
|
+
isFree: boolean;
|
|
16
|
+
trialDays?: number;
|
|
17
|
+
highlights: string[];
|
|
18
|
+
/** Keyed by region code. Look up with the catalog's `defaultRegion` first. */
|
|
19
|
+
pricing: Record<string, PlanPrice>;
|
|
20
|
+
}
|
|
21
|
+
export interface PlanRegion {
|
|
22
|
+
code: string;
|
|
23
|
+
name: string;
|
|
24
|
+
currency: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PlanCatalog {
|
|
27
|
+
/** Sorted by level, ascending — free first. */
|
|
28
|
+
plans: Plan[];
|
|
29
|
+
regions: PlanRegion[];
|
|
30
|
+
defaultRegion: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dash's public face, as the design layer consumes it. Deliberately not
|
|
3
|
+
* the wire shape: the adapter merges the tenant record and the public profile
|
|
4
|
+
* page into one flat object a component can render without null-walking.
|
|
5
|
+
*/
|
|
6
|
+
export interface DashGalleryItem {
|
|
7
|
+
url: string;
|
|
8
|
+
kind: string;
|
|
9
|
+
altText?: string;
|
|
10
|
+
caption?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface DashProfile {
|
|
13
|
+
name: string;
|
|
14
|
+
headline?: string;
|
|
15
|
+
shortDescription?: string;
|
|
16
|
+
about?: string;
|
|
17
|
+
category?: string;
|
|
18
|
+
pricingSummary?: string;
|
|
19
|
+
logoUrl?: string;
|
|
20
|
+
coverUrl?: string;
|
|
21
|
+
gallery: DashGalleryItem[];
|
|
22
|
+
ownerName?: string;
|
|
23
|
+
/** Members across the dash. Zero on a brand-new dash — render nothing, not "0". */
|
|
24
|
+
userCount: number;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exported from the kit rather than redefined. The dash surface has no
|
|
3
|
+
* webhook route in v1, so nothing revalidates this tag automatically — content
|
|
4
|
+
* refreshes on the client's `revalidate` window. Keeping the kit's canonical
|
|
5
|
+
* tag means a future on-demand revalidation hook needs no data migration.
|
|
6
|
+
*/
|
|
7
|
+
export { CHANNEL_SITE_CACHE_TAG } from "@c1m-public/channel-client/next";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exported from the kit rather than redefined. The dash surface has no
|
|
3
|
+
* webhook route in v1, so nothing revalidates this tag automatically — content
|
|
4
|
+
* refreshes on the client's `revalidate` window. Keeping the kit's canonical
|
|
5
|
+
* tag means a future on-demand revalidation hook needs no data migration.
|
|
6
|
+
*/
|
|
7
|
+
export { CHANNEL_SITE_CACHE_TAG } from "@c1m-public/channel-client/next";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { createNextChannelClient } from "@c1m-public/channel-client/next";
|
|
3
|
+
type ChannelClient = ReturnType<typeof createNextChannelClient>;
|
|
4
|
+
export declare class ChannelScopeMismatchError extends Error {
|
|
5
|
+
constructor(actualScope: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function requireDashScope(scope: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* The shared, cacheable client for reads whose answer is the same for every
|
|
10
|
+
* visitor — the profile, the directory, regions. Anything whose answer depends
|
|
11
|
+
* on who is asking must use getVisitorScopedChannelClient() below instead.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getChannelClient(): ChannelClient;
|
|
14
|
+
/** Verify the deployment scope once per request before any dash read. */
|
|
15
|
+
export declare const getDashChannelClient: () => Promise<ChannelClient>;
|
|
16
|
+
/**
|
|
17
|
+
* Preserve the original Vercel visitor across the server-to-server channel
|
|
18
|
+
* hop. The npm client signs these edge-provided values with the channel token;
|
|
19
|
+
* callers must never accept equivalent values from form fields or query input.
|
|
20
|
+
* Built on the no-store client (see getVisitorScopedChannelClient); the
|
|
21
|
+
* request-scoped scope verification is shared with getDashChannelClient.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getVisitorDashChannelClient(): Promise<ChannelClient>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { createNextChannelClient } from "@c1m-public/channel-client/next";
|
|
3
|
+
import { cache } from "react";
|
|
4
|
+
import { headers } from "next/headers";
|
|
5
|
+
import { observeChannelRequest } from "./observability.js";
|
|
6
|
+
import { CHANNEL_SITE_CACHE_TAG } from "./cache.js";
|
|
7
|
+
import { resolveChannelEnvironment } from "./env.js";
|
|
8
|
+
let channelClient;
|
|
9
|
+
export class ChannelScopeMismatchError extends Error {
|
|
10
|
+
constructor(actualScope) {
|
|
11
|
+
super(`This site requires a dash channel token; received ${actualScope || "unknown"} scope`);
|
|
12
|
+
this.name = "ChannelScopeMismatchError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function requireDashScope(scope) {
|
|
16
|
+
if (scope !== "dash")
|
|
17
|
+
throw new ChannelScopeMismatchError(scope);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The shared, cacheable client for reads whose answer is the same for every
|
|
21
|
+
* visitor — the profile, the directory, regions. Anything whose answer depends
|
|
22
|
+
* on who is asking must use getVisitorScopedChannelClient() below instead.
|
|
23
|
+
*/
|
|
24
|
+
export function getChannelClient() {
|
|
25
|
+
if (channelClient)
|
|
26
|
+
return channelClient;
|
|
27
|
+
const environment = resolveChannelEnvironment();
|
|
28
|
+
channelClient = createNextChannelClient({
|
|
29
|
+
token: environment.token,
|
|
30
|
+
...(environment.apiUrl ? { baseUrl: environment.apiUrl } : {}),
|
|
31
|
+
cache: { revalidate: 60, tags: [CHANNEL_SITE_CACHE_TAG] },
|
|
32
|
+
observe: observeChannelRequest,
|
|
33
|
+
});
|
|
34
|
+
return channelClient;
|
|
35
|
+
}
|
|
36
|
+
/** Verify the deployment scope once per request before any dash read. */
|
|
37
|
+
export const getDashChannelClient = cache(async () => {
|
|
38
|
+
const client = getChannelClient();
|
|
39
|
+
const identity = await client.ping();
|
|
40
|
+
requireDashScope(identity.scope);
|
|
41
|
+
return client;
|
|
42
|
+
});
|
|
43
|
+
let visitorChannelClient = null;
|
|
44
|
+
/**
|
|
45
|
+
* The `no-store` client for VISITOR-SCOPED calls. Anything whose answer
|
|
46
|
+
* depends on who is asking — geo detection (which picks the pricing region
|
|
47
|
+
* and therefore the displayed currency), lead capture — must never ride the
|
|
48
|
+
* shared 60s revalidation window above: the npm client forces no-store only
|
|
49
|
+
* for mutations and customer-session reads, so a signed-visitor GET on the
|
|
50
|
+
* cached singleton would be answered from the first visitor's cache entry
|
|
51
|
+
* for everyone that follows.
|
|
52
|
+
*/
|
|
53
|
+
function getVisitorScopedChannelClient() {
|
|
54
|
+
if (visitorChannelClient)
|
|
55
|
+
return visitorChannelClient;
|
|
56
|
+
const environment = resolveChannelEnvironment();
|
|
57
|
+
visitorChannelClient = createNextChannelClient({
|
|
58
|
+
token: environment.token,
|
|
59
|
+
...(environment.apiUrl ? { baseUrl: environment.apiUrl } : {}),
|
|
60
|
+
cache: "no-store",
|
|
61
|
+
observe: observeChannelRequest,
|
|
62
|
+
});
|
|
63
|
+
return visitorChannelClient;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Preserve the original Vercel visitor across the server-to-server channel
|
|
67
|
+
* hop. The npm client signs these edge-provided values with the channel token;
|
|
68
|
+
* callers must never accept equivalent values from form fields or query input.
|
|
69
|
+
* Built on the no-store client (see getVisitorScopedChannelClient); the
|
|
70
|
+
* request-scoped scope verification is shared with getDashChannelClient.
|
|
71
|
+
*/
|
|
72
|
+
export async function getVisitorDashChannelClient() {
|
|
73
|
+
// Reuse the per-request scope check (memoised via React cache) so the
|
|
74
|
+
// visitor path is just as scope-guarded as the cached path.
|
|
75
|
+
const [, requestHeaders] = await Promise.all([getDashChannelClient(), headers()]);
|
|
76
|
+
const client = getVisitorScopedChannelClient();
|
|
77
|
+
const forwarded = requestHeaders.get("x-vercel-forwarded-for") ?? requestHeaders.get("x-forwarded-for") ?? "";
|
|
78
|
+
const ip = forwarded.split(",", 1)[0]?.trim() ?? "";
|
|
79
|
+
return client.withVisitor({
|
|
80
|
+
ip,
|
|
81
|
+
country: requestHeaders.get("x-vercel-ip-country") ?? "",
|
|
82
|
+
userAgent: requestHeaders.get("user-agent") ?? "",
|
|
83
|
+
});
|
|
84
|
+
}
|