@c1m-public/dash-site-kit 3.0.0 → 4.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/README.md CHANGED
@@ -281,7 +281,7 @@ before relying on it.
281
281
 
282
282
  ## Peer dependencies
283
283
 
284
- `@c1m-public/channel-client` ^3.0.0, `@c1m-public/platform-auth` ^1.0.0, `next` 16, `react` 19.
284
+ `@c1m-public/channel-client` ^4.0.0, `@c1m-public/platform-auth` ^1.0.0, `next` 16, `react` 19.
285
285
 
286
286
  The moving quote form, validation, server data layer and customer lead portal
287
287
  are shared across Dash sites. A site supplies its own channel client and
@@ -11,14 +11,25 @@ export interface DirectoryEntry {
11
11
  tagline?: string;
12
12
  category?: string;
13
13
  logoUrl?: string;
14
+ /** The owner's card image for directory lists; fall back to the logo when absent. */
15
+ cardUrl?: string;
14
16
  reviewCount: number;
15
17
  averageRating: number;
16
18
  verified: boolean;
17
19
  regionCode?: string;
18
20
  regionLabel?: string;
19
21
  }
22
+ export interface DirectoryGalleryItem {
23
+ url: string;
24
+ kind: string;
25
+ altText?: string;
26
+ caption?: string;
27
+ }
20
28
  export interface DirectoryProfile extends DirectoryEntry {
21
29
  description?: string;
30
+ /** The wide banner across the top of the listing page. */
31
+ heroUrl?: string;
32
+ gallery: DirectoryGalleryItem[];
22
33
  createdAt?: string;
23
34
  }
24
35
  /**
@@ -35,3 +46,13 @@ export interface DirectoryFilter {
35
46
  region?: string;
36
47
  category?: string;
37
48
  }
49
+ export interface DirectoryBrowseOptions extends DirectoryFilter {
50
+ cursor?: string;
51
+ }
52
+ export type DirectoryBrowseResult = {
53
+ state: "resolved";
54
+ items: DirectoryEntry[];
55
+ nextCursor?: string;
56
+ } | {
57
+ state: "invalid_cursor";
58
+ };
@@ -1,6 +1,8 @@
1
1
  import { safeImageSource } from "../url-policy.js";
2
2
  export function resolveC1MAsset(client, value) {
3
- if (!value)
3
+ const source = value?.trim();
4
+ // Old gallery rows can still reference an unserved seed namespace.
5
+ if (!source || source.startsWith("/tenant-media/"))
4
6
  return undefined;
5
- return safeImageSource(client.assetUrl(value));
7
+ return safeImageSource(client.assetUrl(source));
6
8
  }
@@ -8,16 +8,18 @@ export declare function requireDashScope(scope: string): void;
8
8
  /**
9
9
  * The shared, cacheable client for reads whose answer is the same for every
10
10
  * visitor — the profile, the directory, regions. Anything whose answer depends
11
- * on who is asking must use getVisitorScopedChannelClient() below instead.
11
+ * on who is asking must use getUncachedChannelClient() below instead.
12
12
  */
13
13
  export declare function getChannelClient(): ChannelClient;
14
14
  /** Verify the deployment scope once per request before any dash read. */
15
15
  export declare const getDashChannelClient: () => Promise<ChannelClient>;
16
+ /** Directory visibility and eligibility are checked on every server request. */
17
+ export declare const getDirectoryChannelClient: () => Promise<ChannelClient>;
16
18
  /**
17
19
  * Preserve the original Vercel visitor across the server-to-server channel
18
20
  * hop. The npm client signs these edge-provided values with the channel token;
19
21
  * callers must never accept equivalent values from form fields or query input.
20
- * Built on the no-store client (see getVisitorScopedChannelClient); the
22
+ * Built on the no-store client (see getUncachedChannelClient); the
21
23
  * request-scoped scope verification is shared with getDashChannelClient.
22
24
  */
23
25
  export declare function getVisitorDashChannelClient(): Promise<ChannelClient>;
@@ -19,7 +19,7 @@ export function requireDashScope(scope) {
19
19
  /**
20
20
  * The shared, cacheable client for reads whose answer is the same for every
21
21
  * visitor — the profile, the directory, regions. Anything whose answer depends
22
- * on who is asking must use getVisitorScopedChannelClient() below instead.
22
+ * on who is asking must use getUncachedChannelClient() below instead.
23
23
  */
24
24
  export function getChannelClient() {
25
25
  if (channelClient)
@@ -40,38 +40,43 @@ export const getDashChannelClient = cache(async () => {
40
40
  requireDashScope(identity.scope);
41
41
  return client;
42
42
  });
43
- let visitorChannelClient = null;
43
+ let uncachedChannelClient = null;
44
44
  /**
45
- * The `no-store` client for VISITOR-SCOPED calls. Anything whose answer
45
+ * The `no-store` client for fresh directory and visitor-scoped calls. Anything whose answer
46
46
  * depends on who is asking — geo detection (which picks the pricing region
47
47
  * and therefore the displayed currency), lead capture — is kept off the
48
48
  * shared 60s revalidation window above. The adapter also forces no-store for
49
49
  * visitor-signed reads; this client keeps the intent clear at the call site.
50
50
  */
51
- function getVisitorScopedChannelClient() {
52
- if (visitorChannelClient)
53
- return visitorChannelClient;
51
+ function getUncachedChannelClient() {
52
+ if (uncachedChannelClient)
53
+ return uncachedChannelClient;
54
54
  const environment = resolveChannelEnvironment();
55
- visitorChannelClient = createNextDashChannelClient({
55
+ uncachedChannelClient = createNextDashChannelClient({
56
56
  token: environment.token,
57
57
  ...(environment.apiUrl ? { baseUrl: environment.apiUrl } : {}),
58
58
  cache: "no-store",
59
59
  observe: observeChannelRequest,
60
60
  });
61
- return visitorChannelClient;
61
+ return uncachedChannelClient;
62
62
  }
63
+ /** Directory visibility and eligibility are checked on every server request. */
64
+ export const getDirectoryChannelClient = cache(async () => {
65
+ await getDashChannelClient();
66
+ return getUncachedChannelClient();
67
+ });
63
68
  /**
64
69
  * Preserve the original Vercel visitor across the server-to-server channel
65
70
  * hop. The npm client signs these edge-provided values with the channel token;
66
71
  * callers must never accept equivalent values from form fields or query input.
67
- * Built on the no-store client (see getVisitorScopedChannelClient); the
72
+ * Built on the no-store client (see getUncachedChannelClient); the
68
73
  * request-scoped scope verification is shared with getDashChannelClient.
69
74
  */
70
75
  export async function getVisitorDashChannelClient() {
71
76
  // Reuse the per-request scope check (memoised via React cache) so the
72
77
  // visitor path is just as scope-guarded as the cached path.
73
78
  const [, requestHeaders] = await Promise.all([getDashChannelClient(), headers()]);
74
- const client = getVisitorScopedChannelClient();
79
+ const client = getUncachedChannelClient();
75
80
  const forwarded = requestHeaders.get("x-vercel-forwarded-for") ?? requestHeaders.get("x-forwarded-for") ?? "";
76
81
  const ip = forwarded.split(",", 1)[0]?.trim() ?? "";
77
82
  return client.withVisitor({
@@ -1,6 +1,6 @@
1
1
  import "server-only";
2
2
  import type { DashBootstrap } from "../models/bootstrap.js";
3
- import type { DirectoryEntry, DirectoryFilter, DirectoryProfileResult, DirectoryRegion } from "../models/directory.js";
3
+ import type { DirectoryBrowseOptions, DirectoryBrowseResult, DirectoryEntry, DirectoryFilter, DirectoryProfileResult, DirectoryRegion } from "../models/directory.js";
4
4
  import type { LeadInput, LeadOutcome } from "../models/leads.js";
5
5
  import type { RequestLinkOutcome, ViewOutcome } from "../models/lead-portal.js";
6
6
  import type { MovingQuoteInput, MovingQuoteOutcome, MovingAddressList, MovingAddressResult, MovingDistanceResult } from "../models/moving-quotes.js";
@@ -29,6 +29,7 @@ export interface DashDataLayer {
29
29
  listDirectoryRegions(): Promise<DirectoryRegion[]>;
30
30
  getDirectoryRegion(code: string): Promise<DirectoryRegion | undefined>;
31
31
  listDirectory(filter?: DirectoryFilter): Promise<DirectoryEntry[]>;
32
+ browseDirectory(options?: DirectoryBrowseOptions): Promise<DirectoryBrowseResult>;
32
33
  getDirectoryProfile(idOrSlug: string): Promise<DirectoryProfileResult>;
33
34
  loadDashPlans(): Promise<PlanCatalog>;
34
35
  submitLead(input: LeadInput, attemptId: string): Promise<LeadOutcome>;
@@ -1,9 +1,9 @@
1
1
  import "server-only";
2
2
  import { cache } from "react";
3
3
  import { submitMovingQuote, lookupMovingAddresses, resolveMovingAddress, getMovingDistance } from "./providers/moving-quotes.js";
4
- import { selectDirectoryRegion, validateDirectoryKey } from "../validation/directory.js";
4
+ import { selectDirectoryRegion, validateDirectoryKey, validateRegionFilter } from "../validation/directory.js";
5
5
  import { createC1MBootstrapProvider } from "./providers/bootstrap.js";
6
- import { createC1MDirectoryProvider } from "./providers/directory.js";
6
+ import { createDirectoryProvider } from "./providers/directory.js";
7
7
  import { createC1MLeadPortalProvider } from "./providers/lead-portal.js";
8
8
  import { createC1MLeadsProvider } from "./providers/leads.js";
9
9
  import { createC1MPlansProvider } from "./providers/plans.js";
@@ -22,19 +22,25 @@ export function createDashDataLayer(options) {
22
22
  const bootstrapProvider = createC1MBootstrapProvider();
23
23
  const loadDashBootstrap = cache(() => inPreview() ? Promise.resolve(preview.bootstrap) : bootstrapProvider.loadBootstrap());
24
24
  const profileProvider = createC1MProfileProvider(loadDashBootstrap);
25
- const directoryProvider = createC1MDirectoryProvider();
25
+ const directoryProvider = createDirectoryProvider();
26
26
  const plansProvider = createC1MPlansProvider();
27
27
  const leadsProvider = createC1MLeadsProvider(options.leadSource);
28
28
  const leadPortalProvider = createC1MLeadPortalProvider();
29
29
  const waitlistProvider = createC1MWaitlistProvider();
30
30
  const loadDashProfile = cache(() => inPreview() ? Promise.resolve(preview.profile) : profileProvider.loadProfile());
31
31
  const listDirectoryRegions = cache(() => inPreview() ? Promise.resolve([]) : directoryProvider.listRegions());
32
- const listDirectory = cache((filter) => inPreview() ? Promise.resolve([]) : directoryProvider.list(filter));
32
+ const readDirectory = cache(async (region, category, cursor) => inPreview() ? { state: "resolved", items: [] } : directoryProvider.browse({ region, category, cursor }));
33
+ const browseDirectory = (options = {}) => readDirectory(validateRegionFilter(options.region)?.toLowerCase(), options.category?.trim() || undefined, options.cursor);
34
+ const readDirectoryProfile = cache((key) => inPreview() ? Promise.resolve({ state: "missing" }) : directoryProvider.get(key));
33
35
  return {
34
36
  loadDashBootstrap,
35
37
  loadDashProfile,
36
38
  listDirectoryRegions,
37
- listDirectory,
39
+ browseDirectory,
40
+ async listDirectory(filter = {}) {
41
+ const result = await browseDirectory(filter);
42
+ return result.state === "resolved" ? result.items : [];
43
+ },
38
44
  async getDirectoryRegion(code) {
39
45
  return selectDirectoryRegion(await listDirectoryRegions(), code);
40
46
  },
@@ -44,9 +50,7 @@ export function createDashDataLayer(options) {
44
50
  const key = validateDirectoryKey(idOrSlug);
45
51
  if (!key)
46
52
  return { state: "missing" };
47
- if (inPreview())
48
- return { state: "missing" };
49
- return directoryProvider.get(key);
53
+ return readDirectoryProfile(key);
50
54
  },
51
55
  loadDashPlans: cache(() => plansProvider.loadCatalog()),
52
56
  submitLead: (input, attemptId) => leadsProvider.create(input, attemptId),
@@ -94,6 +94,7 @@ export function normalizeDirectoryEntry(entry) {
94
94
  tagline: text(entry.tagline),
95
95
  category: text(entry.category),
96
96
  logoUrl: text(entry.logo_url) ?? text(entry.logo_square_url),
97
+ cardUrl: text(entry.card_media_url),
97
98
  reviewCount: entry.review_count,
98
99
  averageRating: entry.average_rating,
99
100
  verified: entry.verified === true,
@@ -107,6 +108,17 @@ export function normalizeDirectoryProfile(profile) {
107
108
  ...entry,
108
109
  name: text(profile.display_name) ?? entry.name,
109
110
  description: text(profile.description),
111
+ heroUrl: text(profile.hero_media_url),
112
+ gallery: (profile.gallery_items ?? []).map((item) => {
113
+ const altText = text(item.alt_text);
114
+ const caption = text(item.caption);
115
+ return {
116
+ url: item.url,
117
+ kind: item.kind,
118
+ ...(altText ? { altText } : {}),
119
+ ...(caption ? { caption } : {}),
120
+ };
121
+ }),
110
122
  createdAt: text(profile.created_at),
111
123
  };
112
124
  }
@@ -1,7 +1,14 @@
1
1
  import "server-only";
2
2
  import type { DirectoryProvider } from "../../ports/directory.js";
3
+ import type { DirectoryBrowseOptions, DirectoryBrowseResult, DirectoryEntry } from "../../models/directory.js";
3
4
  import { getChannelClient } from "../client.js";
4
5
  type ChannelClient = ReturnType<typeof getChannelClient>;
5
6
  type ChannelClientResolver = () => ChannelClient | Promise<ChannelClient>;
6
7
  export declare function createC1MDirectoryProvider(resolveClient?: ChannelClientResolver): DirectoryProvider;
8
+ export declare function createDirectoryProvider(resolveClient?: ChannelClientResolver): {
9
+ browse: (options?: DirectoryBrowseOptions) => Promise<DirectoryBrowseResult>;
10
+ listRegions(): Promise<import("../../index.js").DirectoryRegion[]>;
11
+ list(filter?: import("../../index.js").DirectoryFilter): Promise<DirectoryEntry[]>;
12
+ get(idOrSlug: string): Promise<import("../../index.js").DirectoryProfileResult>;
13
+ };
7
14
  export {};
@@ -1,30 +1,68 @@
1
1
  import "server-only";
2
2
  import { isChannelAPIError } from "@c1m-public/channel-client";
3
3
  import { resolveC1MAsset } from "../assets.js";
4
- import { getChannelClient, getDashChannelClient } from "../client.js";
4
+ import { getChannelClient, getDirectoryChannelClient } from "../client.js";
5
5
  import { normalizeDirectoryEntry, normalizeDirectoryProfile, normalizeDirectoryRegion } from "../normalize.js";
6
6
  function resolveEntryAsset(client, entry) {
7
- return { ...entry, logoUrl: resolveC1MAsset(client, entry.logoUrl) };
7
+ return {
8
+ ...entry,
9
+ logoUrl: resolveC1MAsset(client, entry.logoUrl),
10
+ cardUrl: resolveC1MAsset(client, entry.cardUrl),
11
+ };
8
12
  }
9
- export function createC1MDirectoryProvider(resolveClient = getDashChannelClient) {
13
+ function resolveProfileAssets(client, profile) {
14
+ const resolved = resolveEntryAsset(client, profile);
10
15
  return {
16
+ ...resolved,
17
+ heroUrl: resolveC1MAsset(client, profile.heroUrl),
18
+ gallery: profile.gallery.flatMap((item) => {
19
+ const url = resolveC1MAsset(client, item.url);
20
+ return url ? [{ ...item, url }] : [];
21
+ }),
22
+ };
23
+ }
24
+ export function createC1MDirectoryProvider(resolveClient) {
25
+ return createDirectoryProvider(resolveClient);
26
+ }
27
+ export function createDirectoryProvider(resolveClient = getDirectoryChannelClient) {
28
+ async function browse(options = {}) {
29
+ const { region, category, cursor } = options;
30
+ if (cursor !== undefined && (cursor.length === 0 || cursor.length > 512)) {
31
+ return { state: "invalid_cursor" };
32
+ }
33
+ const client = await resolveClient();
34
+ try {
35
+ const response = await client.dash.directory.list({
36
+ ...(region ? { region } : {}),
37
+ ...(category ? { category } : {}),
38
+ ...(cursor ? { cursor } : {}),
39
+ });
40
+ return {
41
+ state: "resolved",
42
+ items: (response.items ?? []).map(normalizeDirectoryEntry).map((entry) => resolveEntryAsset(client, entry)),
43
+ ...(response.next_cursor ? { nextCursor: response.next_cursor } : {}),
44
+ };
45
+ }
46
+ catch (error) {
47
+ if (cursor && isChannelAPIError(error) && error.code === "invalid_cursor")
48
+ return { state: "invalid_cursor" };
49
+ throw error;
50
+ }
51
+ }
52
+ const provider = {
11
53
  async listRegions() {
12
54
  const response = await (await resolveClient()).dash.directory.regions();
13
55
  return (response.items ?? []).map(normalizeDirectoryRegion);
14
56
  },
15
57
  async list(filter = {}) {
16
- const client = await resolveClient();
17
- const response = await client.dash.directory.list({
18
- ...(filter.region ? { region: filter.region } : {}),
19
- ...(filter.category ? { category: filter.category } : {}),
20
- });
21
- return (response.items ?? []).map(normalizeDirectoryEntry).map((entry) => resolveEntryAsset(client, entry));
58
+ const result = await browse(filter);
59
+ return result.state === "resolved" ? result.items : [];
22
60
  },
23
61
  async get(idOrSlug) {
24
62
  try {
25
63
  const client = await resolveClient();
26
64
  const response = await client.dash.directory.get(idOrSlug);
27
- const profile = resolveEntryAsset(client, normalizeDirectoryProfile(response.profile));
65
+ const profile = resolveProfileAssets(client, normalizeDirectoryProfile(response.profile));
28
66
  return { state: "resolved", profile };
29
67
  }
30
68
  catch (error) {
@@ -36,4 +74,5 @@ export function createC1MDirectoryProvider(resolveClient = getDashChannelClient)
36
74
  }
37
75
  },
38
76
  };
77
+ return { ...provider, browse };
39
78
  }
@@ -16,9 +16,7 @@ export function createC1MProfileProvider(resolveBootstrap, resolveClient = getDa
16
16
  // read is the only extra hop the profile page pays.
17
17
  const [bootstrap, response] = await Promise.all([resolveBootstrap(), client.dash.profile()]);
18
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.
19
+ // Resolve managed media against the API origin before rendering.
22
20
  return {
23
21
  ...profile,
24
22
  logoUrl: resolveC1MAsset(client, profile.logoUrl),
@@ -0,0 +1,8 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ import { SiteImage } from "./site-image.js";
3
+ type Props = Omit<ComponentProps<typeof SiteImage>, "onError"> & {
4
+ fallback?: ReactNode;
5
+ };
6
+ /** Render an optional public asset, replacing it when the browser can't load it. */
7
+ export declare function SiteImageWithFallback({ fallback, src, ...image }: Props): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { SiteImage } from "./site-image.js";
5
+ /** Render an optional public asset, replacing it when the browser can't load it. */
6
+ export function SiteImageWithFallback({ fallback, src, ...image }) {
7
+ const [failedUrl, setFailedUrl] = useState();
8
+ if (!src || src === failedUrl)
9
+ return _jsx(_Fragment, { children: fallback });
10
+ return _jsx(SiteImage, { ...image, src: src, onError: () => setFailedUrl(src) });
11
+ }
package/dist/ui.d.ts CHANGED
@@ -23,3 +23,4 @@ export { DashPlanCards } from "./ui/plan-cards.js";
23
23
  export { DashMovingQuoteForm, type MovingQuoteFormState } from "./ui/moving-quote-form.js";
24
24
  export { DashLeadPortalPage } from "./ui/lead-portal-page.js";
25
25
  export { DashPortalLinkForm, type PortalFormState } from "./ui/lead-portal-form.js";
26
+ export { SiteImageWithFallback } from "./ui/site-image-with-fallback.js";
package/dist/ui.js CHANGED
@@ -23,3 +23,4 @@ export { DashPlanCards } from "./ui/plan-cards.js";
23
23
  export { DashMovingQuoteForm } from "./ui/moving-quote-form.js";
24
24
  export { DashLeadPortalPage } from "./ui/lead-portal-page.js";
25
25
  export { DashPortalLinkForm } from "./ui/lead-portal-form.js";
26
+ export { SiteImageWithFallback } from "./ui/site-image-with-fallback.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/dash-site-kit",
3
- "version": "3.0.0",
3
+ "version": "4.1.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": "^3.0.0",
46
+ "@c1m-public/channel-client": "^4.3.0",
47
47
  "@c1m-public/platform-auth": "^1.0.0",
48
48
  "next": "^16",
49
49
  "react": "^19"
@@ -57,7 +57,7 @@
57
57
  "react-dom": "19.2.8",
58
58
  "typescript": "5.9.3",
59
59
  "vitest": "^4.1.4",
60
- "@c1m-public/channel-client": "3.0.0",
60
+ "@c1m-public/channel-client": "4.3.0",
61
61
  "@c1m-public/platform-auth": "1.0.0"
62
62
  },
63
63
  "peerDependenciesMeta": {