@connextar/house 0.23.1 → 0.23.3

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.
Files changed (180) hide show
  1. package/README.md +22 -3
  2. package/dist/analytics/browser.d.ts +1 -0
  3. package/dist/analytics/browser.d.ts.map +1 -1
  4. package/dist/analytics/browser.js +20 -3
  5. package/dist/analytics/browser.js.map +1 -1
  6. package/dist/analytics/config.d.ts +5 -0
  7. package/dist/analytics/config.d.ts.map +1 -1
  8. package/dist/analytics/config.js +4 -1
  9. package/dist/analytics/config.js.map +1 -1
  10. package/dist/analytics/react.d.ts.map +1 -1
  11. package/dist/analytics/react.js +4 -2
  12. package/dist/analytics/react.js.map +1 -1
  13. package/dist/analytics/redact.d.ts.map +1 -1
  14. package/dist/analytics/redact.js +6 -1
  15. package/dist/analytics/redact.js.map +1 -1
  16. package/package.json +5 -2
  17. package/src/account/data-contract.ts +112 -0
  18. package/src/account/index.ts +11 -0
  19. package/src/admin/access.ts +267 -0
  20. package/src/admin/audit.ts +238 -0
  21. package/src/admin/bootstrap.ts +220 -0
  22. package/src/admin/client-index.ts +19 -0
  23. package/src/admin/client.tsx +187 -0
  24. package/src/admin/index.ts +91 -0
  25. package/src/admin/proof.ts +155 -0
  26. package/src/admin/second-factor-index.ts +16 -0
  27. package/src/admin/second-factor.ts +403 -0
  28. package/src/admin/testing-index.ts +13 -0
  29. package/src/admin/testing.ts +299 -0
  30. package/src/admin/view-as.ts +511 -0
  31. package/src/ai/config-index.ts +40 -0
  32. package/src/ai/config.ts +176 -0
  33. package/src/ai/images.ts +18 -0
  34. package/src/ai/index.ts +21 -0
  35. package/src/ai/pricing.ts +107 -0
  36. package/src/ai/provider.ts +403 -0
  37. package/src/analytics/browser.ts +400 -0
  38. package/src/analytics/client-index.ts +12 -0
  39. package/src/analytics/config.ts +89 -0
  40. package/src/analytics/index.ts +17 -0
  41. package/src/analytics/ingest.ts +81 -0
  42. package/src/analytics/react-index.ts +16 -0
  43. package/src/analytics/react.tsx +241 -0
  44. package/src/analytics/redact.ts +146 -0
  45. package/src/analytics/server-index.ts +17 -0
  46. package/src/analytics/server.ts +277 -0
  47. package/src/auth/index.ts +30 -0
  48. package/src/auth/second-factor-index.ts +16 -0
  49. package/src/auth/second-factor-next.ts +136 -0
  50. package/src/auth/second-factor-routes.ts +40 -0
  51. package/src/auth/second-factor.ts +226 -0
  52. package/src/auth/step-up-client-index.ts +13 -0
  53. package/src/auth/step-up-client.ts +23 -0
  54. package/src/auth/step-up-index.ts +19 -0
  55. package/src/auth/step-up-routes.ts +99 -0
  56. package/src/auth/step-up.ts +432 -0
  57. package/src/auth/two-factor-policy.ts +112 -0
  58. package/src/changelog/changelog.tsx +367 -0
  59. package/src/changelog/index.ts +12 -0
  60. package/src/editor/block-handle.tsx +312 -0
  61. package/src/editor/blocks.ts +169 -0
  62. package/src/editor/bubble-toolbar.tsx +208 -0
  63. package/src/editor/collapsible.ts +159 -0
  64. package/src/editor/content-index.ts +1 -0
  65. package/src/editor/content.tsx +343 -0
  66. package/src/editor/editor.tsx +333 -0
  67. package/src/editor/emoji-index.ts +1 -0
  68. package/src/editor/emoji-picker.tsx +114 -0
  69. package/src/editor/emoji.ts +436 -0
  70. package/src/editor/index.ts +6 -0
  71. package/src/editor/sections.ts +83 -0
  72. package/src/editor/suggestion-popup.tsx +136 -0
  73. package/src/editor/suggestions.ts +309 -0
  74. package/src/editor/ui.tsx +171 -0
  75. package/src/errors/error-shell.tsx +72 -0
  76. package/src/errors/global-error-shell.tsx +116 -0
  77. package/src/errors/index.ts +2 -0
  78. package/src/grid/columns.ts +48 -0
  79. package/src/grid/compare.ts +35 -0
  80. package/src/grid/hidden-columns.ts +95 -0
  81. package/src/grid/index.ts +27 -0
  82. package/src/grid/use-grid.ts +282 -0
  83. package/src/grid/views.ts +70 -0
  84. package/src/guides/guide-article.tsx +92 -0
  85. package/src/guides/guide-figure-zoom.tsx +533 -0
  86. package/src/guides/guide-figure.tsx +68 -0
  87. package/src/guides/guide-toc.tsx +133 -0
  88. package/src/guides/guides-landing.tsx +57 -0
  89. package/src/guides/guides-search.tsx +160 -0
  90. package/src/guides/guides-shell.tsx +60 -0
  91. package/src/guides/guides-sidebar.tsx +93 -0
  92. package/src/guides/index.ts +28 -0
  93. package/src/guides/library.ts +165 -0
  94. package/src/health/health.ts +115 -0
  95. package/src/health/index.ts +11 -0
  96. package/src/internal/cx.ts +4 -0
  97. package/src/internal/next-link.ts +23 -0
  98. package/src/jobs/counts.ts +151 -0
  99. package/src/jobs/cron-auth.ts +60 -0
  100. package/src/jobs/health.ts +315 -0
  101. package/src/jobs/idle.ts +86 -0
  102. package/src/jobs/index.ts +120 -0
  103. package/src/jobs/job-health-list.tsx +316 -0
  104. package/src/jobs/next-index.ts +4 -0
  105. package/src/jobs/next.ts +65 -0
  106. package/src/jobs/prisma-index.ts +12 -0
  107. package/src/jobs/prisma.ts +170 -0
  108. package/src/jobs/prune.ts +79 -0
  109. package/src/jobs/react-index.ts +35 -0
  110. package/src/jobs/registry.ts +189 -0
  111. package/src/jobs/scheduler.ts +437 -0
  112. package/src/jobs/store.ts +212 -0
  113. package/src/jobs/windows.ts +157 -0
  114. package/src/maintenance/core.ts +270 -0
  115. package/src/maintenance/gate.ts +171 -0
  116. package/src/maintenance/index.ts +40 -0
  117. package/src/maintenance/page.ts +76 -0
  118. package/src/maintenance/proxy.ts +88 -0
  119. package/src/maintenance/react-index.ts +7 -0
  120. package/src/maintenance/react.tsx +190 -0
  121. package/src/maintenance/route.ts +82 -0
  122. package/src/maintenance/unavailable.ts +61 -0
  123. package/src/markdown/figure.tsx +132 -0
  124. package/src/markdown/figures.ts +237 -0
  125. package/src/markdown/guide.tsx +536 -0
  126. package/src/markdown/index.ts +53 -0
  127. package/src/markdown/table-view.tsx +74 -0
  128. package/src/markdown/table.ts +90 -0
  129. package/src/password/common.ts +58 -0
  130. package/src/password/estimate-index.ts +18 -0
  131. package/src/password/estimate.ts +715 -0
  132. package/src/password/index.ts +40 -0
  133. package/src/password/password-input.tsx +116 -0
  134. package/src/password/password-strength.tsx +157 -0
  135. package/src/password/reveal.ts +151 -0
  136. package/src/rate-limit/better-auth.ts +94 -0
  137. package/src/rate-limit/index.ts +32 -0
  138. package/src/rate-limit/keys.ts +110 -0
  139. package/src/rate-limit/limiter.ts +276 -0
  140. package/src/rate-limit/prisma-index.ts +12 -0
  141. package/src/rate-limit/prisma.ts +157 -0
  142. package/src/rate-limit/store.ts +47 -0
  143. package/src/release/changelog.ts +364 -0
  144. package/src/release/index.ts +32 -0
  145. package/src/release/version.ts +64 -0
  146. package/src/setup-guide/bits.tsx +420 -0
  147. package/src/setup-guide/card.tsx +358 -0
  148. package/src/setup-guide/class-names.ts +144 -0
  149. package/src/setup-guide/context.tsx +239 -0
  150. package/src/setup-guide/guide.ts +271 -0
  151. package/src/setup-guide/index.ts +76 -0
  152. package/src/setup-guide/launcher.tsx +207 -0
  153. package/src/setup-guide/strip.tsx +127 -0
  154. package/src/styles/house.css +384 -0
  155. package/src/trail/index.ts +12 -0
  156. package/src/trail/rules.ts +84 -0
  157. package/src/trail/trail.tsx +367 -0
  158. package/src/ux/errors.ts +32 -0
  159. package/src/ux/feedback.tsx +41 -0
  160. package/src/ux/index.ts +44 -0
  161. package/src/ux/navigation-index.ts +16 -0
  162. package/src/ux/navigation-progress.tsx +270 -0
  163. package/src/ux/optimistic.ts +415 -0
  164. package/src/ux/use-action.ts +155 -0
  165. package/src/ux/use-optimistic-list.ts +227 -0
  166. package/src/ux/use-optimistic-value.ts +136 -0
  167. package/src/web-search/index.ts +13 -0
  168. package/src/web-search/providers.ts +177 -0
  169. package/src/web-search/types.ts +98 -0
  170. package/src/whats-new/body.tsx +190 -0
  171. package/src/whats-new/index.ts +43 -0
  172. package/src/whats-new/seen.ts +40 -0
  173. package/src/whats-new/select.ts +230 -0
  174. package/src/whats-new/use-whats-new.ts +109 -0
  175. package/src/wizard/index.ts +61 -0
  176. package/src/wizard/invalid.ts +152 -0
  177. package/src/wizard/react-hook-form-index.ts +11 -0
  178. package/src/wizard/rhf-adapter.ts +67 -0
  179. package/src/wizard/rules.ts +137 -0
  180. package/src/wizard/wizard.tsx +442 -0
@@ -0,0 +1,177 @@
1
+ import {
2
+ WebSearchError,
3
+ type FetchLike,
4
+ type OrganicResult,
5
+ type ProviderOptions,
6
+ type WebSearchCallOptions,
7
+ type WebSearchProvider,
8
+ type WebSearchProviderName,
9
+ type WebSearchRequest,
10
+ type WebSearchResponse,
11
+ } from "./types.js";
12
+
13
+ const DEFAULT_TIMEOUT_MS = 12_000;
14
+
15
+ function signalFor(options: WebSearchCallOptions | undefined): AbortSignal {
16
+ const timeout = AbortSignal.timeout(options?.timeoutMs ?? DEFAULT_TIMEOUT_MS);
17
+ return options?.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
18
+ }
19
+
20
+ /** The status, as a code — and nothing of the response body, which can echo the request. */
21
+ function codeFor(status: number): WebSearchError["code"] {
22
+ if (status === 401 || status === 403) return "unauthorised";
23
+ if (status === 402 || status === 429) return "rate_limited";
24
+ return "bad_response";
25
+ }
26
+
27
+ async function call(
28
+ provider: WebSearchProviderName,
29
+ doFetch: FetchLike,
30
+ url: URL,
31
+ init: RequestInit,
32
+ ): Promise<unknown> {
33
+ let response: Response;
34
+ try {
35
+ response = await doFetch(url, init);
36
+ } catch (error) {
37
+ // Never the error itself: a fetch failure can quote the address.
38
+ const aborted = error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
39
+ throw new WebSearchError(provider, aborted ? "timeout" : "unreachable");
40
+ }
41
+ if (!response.ok) throw new WebSearchError(provider, codeFor(response.status), response.status);
42
+ try {
43
+ return await response.json();
44
+ } catch {
45
+ throw new WebSearchError(provider, "bad_response", response.status);
46
+ }
47
+ }
48
+
49
+ const text = (value: unknown): string | null => (typeof value === "string" && value.trim() ? value.trim() : null);
50
+
51
+ /** Rows with a title and an address, numbered as the engine ranked them. */
52
+ function organic(rows: unknown): OrganicResult[] {
53
+ if (!Array.isArray(rows)) return [];
54
+ const out: OrganicResult[] = [];
55
+ for (const [index, row] of rows.entries()) {
56
+ if (!row || typeof row !== "object") continue;
57
+ const r = row as Record<string, unknown>;
58
+ const title = text(r.title);
59
+ const url = text(r.link);
60
+ if (!title || !url) continue;
61
+ out.push({
62
+ position: typeof r.position === "number" ? r.position : index + 1,
63
+ title,
64
+ url,
65
+ snippet: text(r.snippet),
66
+ });
67
+ }
68
+ return out;
69
+ }
70
+
71
+ /**
72
+ * Serper (serper.dev). The key goes in a header, never the address. One credit
73
+ * buys up to ten results; eleven to a hundred cost two.
74
+ */
75
+ export function serper(options: ProviderOptions): WebSearchProvider {
76
+ const doFetch = options.fetch ?? fetch;
77
+ const endpoint = new URL("search", `${(options.baseUrl ?? "https://google.serper.dev").replace(/\/+$/, "")}/`);
78
+ return {
79
+ name: "serper",
80
+ label: "Serper",
81
+ async search(request: WebSearchRequest, callOptions?: WebSearchCallOptions): Promise<WebSearchResponse> {
82
+ const body: Record<string, unknown> = { q: request.q };
83
+ if (request.country) body.gl = request.country.toLowerCase();
84
+ if (request.language) body.hl = request.language.toLowerCase();
85
+ if (request.num) body.num = request.num;
86
+ const data = await call("serper", doFetch, endpoint, {
87
+ method: "POST",
88
+ headers: { "X-API-KEY": options.apiKey, "Content-Type": "application/json", Accept: "application/json" },
89
+ body: JSON.stringify(body),
90
+ signal: signalFor(callOptions),
91
+ });
92
+ const answer = data as { organic?: unknown } | null;
93
+ if (!answer || !Array.isArray(answer.organic)) throw new WebSearchError("serper", "bad_response");
94
+ return { provider: "serper", results: organic(answer.organic) };
95
+ },
96
+ };
97
+ }
98
+
99
+ /** The Google domain for a country, so ValueSERP searches the same Google a person there would. */
100
+ function googleDomain(country: string | undefined): string | undefined {
101
+ if (!country) return undefined;
102
+ const code = country.toLowerCase();
103
+ if (code === "gb" || code === "uk") return "google.co.uk";
104
+ if (code === "us") return "google.com";
105
+ return undefined;
106
+ }
107
+
108
+ /**
109
+ * VALUE SERP (Traject Data). **The key goes in the query string** — that is
110
+ * their API, not a choice — so this module never lets the address reach an
111
+ * error message.
112
+ */
113
+ export function valueSerp(options: ProviderOptions): WebSearchProvider {
114
+ const doFetch = options.fetch ?? fetch;
115
+ const base = options.baseUrl ?? "https://api.valueserp.com/search";
116
+ return {
117
+ name: "valueserp",
118
+ label: "VALUE SERP",
119
+ async search(request: WebSearchRequest, callOptions?: WebSearchCallOptions): Promise<WebSearchResponse> {
120
+ const url = new URL(base);
121
+ url.searchParams.set("api_key", options.apiKey);
122
+ url.searchParams.set("q", request.q);
123
+ if (request.country) url.searchParams.set("gl", request.country.toLowerCase());
124
+ if (request.language) url.searchParams.set("hl", request.language.toLowerCase());
125
+ const domain = googleDomain(request.country);
126
+ if (domain) url.searchParams.set("google_domain", domain);
127
+ if (request.num) url.searchParams.set("num", String(request.num));
128
+ url.searchParams.set("output", "json");
129
+ const data = await call("valueserp", doFetch, url, {
130
+ headers: { Accept: "application/json" },
131
+ signal: signalFor(callOptions),
132
+ });
133
+ const answer = data as { organic_results?: unknown; request_info?: { success?: unknown } } | null;
134
+ if (!answer || answer.request_info?.success === false) throw new WebSearchError("valueserp", "bad_response");
135
+ // A search with no results has no `organic_results` at all.
136
+ return { provider: "valueserp", results: organic(answer.organic_results ?? []) };
137
+ },
138
+ };
139
+ }
140
+
141
+ /** What a deployment's environment says about search. */
142
+ export interface WebSearchEnv {
143
+ /** `serper` or `valueserp`, to choose when both keys are set. */
144
+ WEB_SEARCH_PROVIDER?: string;
145
+ SERPER_API_KEY?: string;
146
+ SERPER_URL?: string;
147
+ VALUESERP_API_KEY?: string;
148
+ VALUESERP_URL?: string;
149
+ }
150
+
151
+ /**
152
+ * The provider a deployment is set up for, or null when it has no key.
153
+ *
154
+ * `WEB_SEARCH_PROVIDER` decides when it names a provider that has a key;
155
+ * otherwise Serper is used if its key is set, then VALUE SERP. A named provider
156
+ * without a key falls back rather than failing, so a half-finished change to
157
+ * the environment degrades to the other provider instead of to no search.
158
+ */
159
+ export function webSearchProviderFromEnv(
160
+ env: WebSearchEnv = process.env as WebSearchEnv,
161
+ options: { fetch?: FetchLike } = {},
162
+ ): WebSearchProvider | null {
163
+ const keys: Record<WebSearchProviderName, string | undefined> = {
164
+ serper: env.SERPER_API_KEY?.trim() || undefined,
165
+ valueserp: env.VALUESERP_API_KEY?.trim() || undefined,
166
+ };
167
+ const wanted = env.WEB_SEARCH_PROVIDER?.trim().toLowerCase();
168
+ const order: WebSearchProviderName[] = wanted === "valueserp" ? ["valueserp", "serper"] : ["serper", "valueserp"];
169
+ for (const name of order) {
170
+ const apiKey = keys[name];
171
+ if (!apiKey) continue;
172
+ return name === "serper"
173
+ ? serper({ apiKey, baseUrl: env.SERPER_URL?.trim() || undefined, fetch: options.fetch })
174
+ : valueSerp({ apiKey, baseUrl: env.VALUESERP_URL?.trim() || undefined, fetch: options.fetch });
175
+ }
176
+ return null;
177
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * One search engine, whichever company answers it.
3
+ *
4
+ * An app that looks further than its own database — AltEd's tutors from the
5
+ * wider web was the first — wants the same thing from a search API: Google's
6
+ * organic results for a query, in a country and a language, quickly, and an
7
+ * error that says what went wrong without repeating the key it was sent with. Providers differ in everything else —
8
+ * where the key goes, what the fields are called, what a result costs — and
9
+ * that is exactly what this module hides.
10
+ */
11
+
12
+ /** The providers this module speaks to. */
13
+ export type WebSearchProviderName = "serper" | "valueserp";
14
+
15
+ /** What to search for. Everything but the words is optional. */
16
+ export interface WebSearchRequest {
17
+ /** The words, as they would be typed into the engine. */
18
+ q: string;
19
+ /** Two-letter country the results are for — `gl`: "gb", "us". */
20
+ country?: string;
21
+ /** Two-letter interface language — `hl`: "en". */
22
+ language?: string;
23
+ /** How many results to ask for. Providers bill differently above ten; see each provider. */
24
+ num?: number;
25
+ }
26
+
27
+ /** One organic result, the same shape from every provider. */
28
+ export interface OrganicResult {
29
+ /** 1-based, as the engine ranked it. */
30
+ position: number;
31
+ title: string;
32
+ /** The page's address, exactly as the engine gave it. */
33
+ url: string;
34
+ /** The engine's extract of the page, if it gave one. */
35
+ snippet: string | null;
36
+ }
37
+
38
+ export interface WebSearchResponse {
39
+ provider: WebSearchProviderName;
40
+ results: OrganicResult[];
41
+ }
42
+
43
+ export interface WebSearchCallOptions {
44
+ /** Abandon the request after this long. Default 12 seconds. */
45
+ timeoutMs?: number;
46
+ /** The caller's own cancellation, combined with the timeout. */
47
+ signal?: AbortSignal;
48
+ }
49
+
50
+ export interface WebSearchProvider {
51
+ readonly name: WebSearchProviderName;
52
+ /** A person-facing name, for a privacy policy's list of processors. */
53
+ readonly label: string;
54
+ search(request: WebSearchRequest, options?: WebSearchCallOptions): Promise<WebSearchResponse>;
55
+ }
56
+
57
+ /** Why a search failed, as a code an app can branch on. */
58
+ export type WebSearchErrorCode =
59
+ /** The key was refused. */
60
+ | "unauthorised"
61
+ /** The provider's rate limit or the account's credit ran out. */
62
+ | "rate_limited"
63
+ /** The request never got an answer in time. */
64
+ | "timeout"
65
+ /** The provider could not be reached at all. */
66
+ | "unreachable"
67
+ /** It answered, but not with results. */
68
+ | "bad_response";
69
+
70
+ /**
71
+ * A failed search. **Its message never contains the request's address or
72
+ * headers**: one provider takes the key in the query string, and an error that
73
+ * quoted the address would put a live key into whatever log caught it.
74
+ */
75
+ export class WebSearchError extends Error {
76
+ readonly provider: WebSearchProviderName;
77
+ readonly code: WebSearchErrorCode;
78
+ /** The HTTP status, when there was one. */
79
+ readonly status: number | undefined;
80
+
81
+ constructor(provider: WebSearchProviderName, code: WebSearchErrorCode, status?: number) {
82
+ super(`The ${provider} search failed (${code}${status ? `, HTTP ${status}` : ""}).`);
83
+ this.name = "WebSearchError";
84
+ this.provider = provider;
85
+ this.code = code;
86
+ this.status = status;
87
+ }
88
+ }
89
+
90
+ /** Injected for tests and for runtimes with their own `fetch`. */
91
+ export type FetchLike = (input: string | URL, init?: RequestInit) => Promise<Response>;
92
+
93
+ export interface ProviderOptions {
94
+ apiKey: string;
95
+ /** Point at a stand-in for local checks. */
96
+ baseUrl?: string;
97
+ fetch?: FetchLike;
98
+ }
@@ -0,0 +1,190 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+
3
+ import { DEFAULT_TAG_CLASS_NAMES, renderReleaseText, TAG_LABELS } from "../changelog/changelog.js";
4
+ import { cx } from "../internal/cx.js";
5
+ import type { ChangeType } from "../release/changelog.js";
6
+ import type { WhatsNewData } from "./select.js";
7
+
8
+ /**
9
+ * What goes inside the "what's new" dialog — not the dialog.
10
+ *
11
+ * Every app already has one, with its own idea of how a thing appears, what
12
+ * closes it and where focus goes: a Radix `DialogContent`, a hand-rolled
13
+ * overlay, MUI. So this ships the three parts that go in it — a title, the
14
+ * body and the button — and the app puts them in its own:
15
+ *
16
+ * ```tsx
17
+ * <Dialog open={news.open} onOpenChange={news.setOpen}>
18
+ * <DialogContent>
19
+ * <DialogTitle asChild><WhatsNewTitle /></DialogTitle>
20
+ * <WhatsNewBody data={news.data} changelogHref="/changelog" title={false}
21
+ * onChangelogClick={news.onChangelogClick} />
22
+ * <WhatsNewActions onDismiss={news.dismiss} />
23
+ * </DialogContent>
24
+ * </Dialog>
25
+ * ```
26
+ *
27
+ * Theme tokens only, the changelog's own tags, and no hooks: it renders
28
+ * wherever the app's dialog does.
29
+ */
30
+
31
+ export interface WhatsNewLabels {
32
+ title: string;
33
+ /** The line under the title. */
34
+ count: (releases: number) => string;
35
+ /** Under the highlights, when there were more than fit. */
36
+ more: (count: number) => string;
37
+ seeAll: string;
38
+ dismiss: string;
39
+ }
40
+
41
+ export const WHATS_NEW_LABELS: WhatsNewLabels = {
42
+ title: "What's new",
43
+ count: (n) => (n === 1 ? "1 update since you last looked" : `${n} updates since you last looked`),
44
+ more: (n) => (n === 1 ? "And 1 more." : `And ${n} more.`),
45
+ seeAll: "See everything in the changelog",
46
+ dismiss: "Got it",
47
+ };
48
+
49
+ export interface WhatsNewLinkProps {
50
+ href: string;
51
+ children: ReactNode;
52
+ className?: string;
53
+ onClick?: () => void;
54
+ }
55
+
56
+ /** How the changelog link is drawn. Defaults to a plain `<a>`; an app with a router passes its own. */
57
+ export type WhatsNewLinkComponent = (props: WhatsNewLinkProps) => ReactNode;
58
+
59
+ const PlainLink: WhatsNewLinkComponent = ({ children, ...rest }) => <a {...rest}>{children}</a>;
60
+
61
+ export interface WhatsNewTitleProps extends HTMLAttributes<HTMLHeadingElement> {
62
+ label?: string;
63
+ }
64
+
65
+ /**
66
+ * The dialog's heading — an `<h2>` that passes every prop through, so a Radix
67
+ * `<DialogTitle asChild>` can lend it its id and the dialog is named by it.
68
+ */
69
+ export function WhatsNewTitle({ label = WHATS_NEW_LABELS.title, className, children, ...rest }: WhatsNewTitleProps) {
70
+ return (
71
+ <h2 className={cx("text-lg leading-tight font-semibold tracking-tight text-foreground", className)} {...rest}>
72
+ {children ?? label}
73
+ </h2>
74
+ );
75
+ }
76
+
77
+ export interface WhatsNewBodyProps {
78
+ data: WhatsNewData;
79
+ /** The changelog page; the link goes to `${changelogHref}#${data.anchor}`, the newest release they haven't seen. */
80
+ changelogHref: string;
81
+ /** Tag classes per change type; merged over the changelog's defaults. */
82
+ tagClassNames?: Partial<Record<ChangeType, string>>;
83
+ labels?: Partial<WhatsNewLabels>;
84
+ link?: WhatsNewLinkComponent;
85
+ /** From `useWhatsNew`: following the link counts as having seen it. */
86
+ onChangelogClick?: () => void;
87
+ /** Draw the title here. `false` when the dialog draws `<WhatsNewTitle>` itself, as Radix and MUI want. */
88
+ title?: boolean;
89
+ /** The title's id, for a hand-rolled dialog's `aria-labelledby`. */
90
+ titleId?: string;
91
+ renderText?: (text: string) => ReactNode;
92
+ className?: string;
93
+ }
94
+
95
+ export function WhatsNewBody({
96
+ data,
97
+ changelogHref,
98
+ tagClassNames,
99
+ labels,
100
+ link: Link = PlainLink,
101
+ onChangelogClick,
102
+ title = true,
103
+ titleId,
104
+ renderText = renderReleaseText,
105
+ className,
106
+ }: WhatsNewBodyProps) {
107
+ const words = { ...WHATS_NEW_LABELS, ...labels };
108
+ const tags = { ...DEFAULT_TAG_CLASS_NAMES, ...tagClassNames };
109
+ const href = data.anchor ? `${changelogHref}#${data.anchor}` : changelogHref;
110
+
111
+ return (
112
+ <div className={cx("min-w-0", className)}>
113
+ {title ? <WhatsNewTitle id={titleId} label={words.title} /> : null}
114
+ <p className={cx("text-sm text-muted-foreground", title && "mt-1")}>{words.count(data.releaseCount)}</p>
115
+
116
+ {data.highlights.length > 0 ? (
117
+ <ul className="mt-4 divide-y divide-border overflow-hidden rounded-xl border border-border bg-card">
118
+ {data.highlights.map((item) => (
119
+ <li
120
+ key={`${item.version}:${item.heading}:${item.title}`}
121
+ className="grid gap-2 p-4 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-4"
122
+ >
123
+ <span
124
+ className={cx(
125
+ "inline-flex h-fit w-fit items-center rounded-full border px-2 py-0.5 text-[11px] font-semibold",
126
+ tags[item.type],
127
+ )}
128
+ >
129
+ {TAG_LABELS[item.type]}
130
+ </span>
131
+ <div className="min-w-0">
132
+ <p className="leading-snug font-semibold text-card-foreground">{item.title}</p>
133
+ <p className="mt-1 text-sm leading-relaxed text-muted-foreground">{renderText(item.text)}</p>
134
+ <p className="mt-1.5 text-xs text-muted-foreground">
135
+ {item.heading} · <span className="font-mono">v{item.version}</span>
136
+ </p>
137
+ </div>
138
+ </li>
139
+ ))}
140
+ </ul>
141
+ ) : null}
142
+
143
+ <p className="mt-4 flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm">
144
+ {data.moreCount > 0 ? <span className="text-muted-foreground">{words.more(data.moreCount)}</span> : null}
145
+ <Link
146
+ href={href}
147
+ onClick={onChangelogClick}
148
+ className="font-medium text-primary underline-offset-4 hover:underline focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
149
+ >
150
+ {words.seeAll}
151
+ </Link>
152
+ </p>
153
+ </div>
154
+ );
155
+ }
156
+
157
+ export interface WhatsNewActionsProps {
158
+ /** From `useWhatsNew`: closes the dialog and stores the newest version. */
159
+ onDismiss: () => void;
160
+ label?: string;
161
+ /** Anything else the app wants beside the button. */
162
+ children?: ReactNode;
163
+ className?: string;
164
+ buttonClassName?: string;
165
+ }
166
+
167
+ /** The dialog's footer: one button that closes it. An app with its own `Button` can draw that instead. */
168
+ export function WhatsNewActions({
169
+ onDismiss,
170
+ label = WHATS_NEW_LABELS.dismiss,
171
+ children,
172
+ className,
173
+ buttonClassName = "bg-primary text-primary-foreground hover:bg-primary/90",
174
+ }: WhatsNewActionsProps) {
175
+ return (
176
+ <div className={cx("mt-6 flex flex-wrap items-center justify-end gap-2", className)}>
177
+ {children}
178
+ <button
179
+ type="button"
180
+ onClick={onDismiss}
181
+ className={cx(
182
+ "inline-flex items-center rounded-md px-4 py-2 text-sm font-medium transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none",
183
+ buttonClassName,
184
+ )}
185
+ >
186
+ {label}
187
+ </button>
188
+ </div>
189
+ );
190
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * `@connextar/house/whats-new` — the dialog that tells a signed-in person what
3
+ * changed since they last looked, from the changelog the app already keeps.
4
+ *
5
+ * Four pieces, each with one job:
6
+ *
7
+ * - `whatsNew(CHANGELOG, user.lastSeenReleaseVersion, options)` — pure, run in
8
+ * the signed-in layout on the server. It picks the highlights in the public's
9
+ * words, so nothing internal ever reaches a browser.
10
+ * - `acceptSeenVersion(body, CHANGELOG, current)` — the check in the app's
11
+ * `POST /api/whats-new/seen` before it stores anything.
12
+ * - `useWhatsNew({ initial, markSeen, readOnly })` — opens once, stores on
13
+ * close, says so when that fails, never opens while viewing as someone.
14
+ * - `WhatsNewTitle`, `WhatsNewBody`, `WhatsNewActions` — what goes inside the
15
+ * app's own dialog. The dialog is the app's; this ships none.
16
+ *
17
+ * The data is each app's own: one nullable column and one route. This package
18
+ * makes no requests and knows no routes.
19
+ */
20
+ export {
21
+ DEFAULT_HIGHLIGHT_TYPES,
22
+ DEFAULT_SHOW_FOR,
23
+ DEFAULT_SKIP_HEADINGS,
24
+ WHATS_NEW_MAX_ITEMS,
25
+ whatsNew,
26
+ type WhatsNewData,
27
+ type WhatsNewHighlight,
28
+ type WhatsNewOptions,
29
+ } from "./select.js";
30
+ export { acceptSeenVersion, type SeenVersionResult } from "./seen.js";
31
+ export {
32
+ WHATS_NEW_LABELS,
33
+ WhatsNewActions,
34
+ WhatsNewBody,
35
+ WhatsNewTitle,
36
+ type WhatsNewActionsProps,
37
+ type WhatsNewBodyProps,
38
+ type WhatsNewLabels,
39
+ type WhatsNewLinkComponent,
40
+ type WhatsNewLinkProps,
41
+ type WhatsNewTitleProps,
42
+ } from "./body.js";
43
+ export { useWhatsNew, type UseWhatsNewOptions, type WhatsNew } from "./use-whats-new.js";
@@ -0,0 +1,40 @@
1
+ import type { ChangelogRelease } from "../release/changelog.js";
2
+ import { compareVersions, isReleaseVersion } from "../release/version.js";
3
+
4
+ /** What `acceptSeenVersion` decided: the version to store, or why the request is a 400. */
5
+ export type SeenVersionResult = { ok: true; version: string } | { ok: false; reason: string };
6
+
7
+ /**
8
+ * The body of `POST /api/whats-new/seen`, checked before anything is stored.
9
+ *
10
+ * The version must be a release version and no newer than the changelog's
11
+ * newest — anything else is a client that is wrong or lying, and storing it
12
+ * would hide releases that haven't happened yet. It needn't be one the
13
+ * changelog holds: an old tab may still be on a release since trimmed.
14
+ *
15
+ * Pass what is stored now as `current` and the answer never goes backwards: an
16
+ * old tab dismissing after a newer one stores the newer version again, rather
17
+ * than bringing back a dialog the person already closed.
18
+ */
19
+ export function acceptSeenVersion(
20
+ body: unknown,
21
+ changelog: readonly ChangelogRelease[],
22
+ current?: string | null,
23
+ ): SeenVersionResult {
24
+ const version =
25
+ body && typeof body === "object" && "version" in body ? (body as { version: unknown }).version : undefined;
26
+ if (typeof version !== "string") return { ok: false, reason: "Send the version you have seen, as { version }." };
27
+ if (!isReleaseVersion(version)) return { ok: false, reason: `"${version}" is not a release version.` };
28
+
29
+ const newest = changelog
30
+ .map((release) => release.version)
31
+ .filter(isReleaseVersion)
32
+ .reduce<string | null>((max, v) => (max === null || compareVersions(v, max) > 0 ? v : max), null);
33
+ if (newest === null) return { ok: false, reason: "There are no releases to have seen." };
34
+ if (compareVersions(version, newest) > 0) return { ok: false, reason: `${version} hasn't been released.` };
35
+
36
+ if (current && isReleaseVersion(current) && compareVersions(current, version) > 0) {
37
+ return { ok: true, version: current };
38
+ }
39
+ return { ok: true, version };
40
+ }