@eifi1/ui-kit 0.26.0 → 0.27.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.
Files changed (158) hide show
  1. package/README.md +15 -4
  2. package/dist/chart.d.ts +13 -9
  3. package/dist/components/account-chips.d.ts +1 -1
  4. package/dist/components/amount-input.d.ts +13 -9
  5. package/dist/components/button-group.d.ts +13 -9
  6. package/dist/components/calculator.d.ts +13 -9
  7. package/dist/components/confirm-dialog.d.ts +13 -9
  8. package/dist/components/copy-button.d.ts +10 -6
  9. package/dist/components/danger-confirm.d.ts +13 -9
  10. package/dist/components/data-table-cells.d.ts +1 -1
  11. package/dist/components/data-table-filter-popover.d.ts +1 -1
  12. package/dist/components/data-table-filters.d.ts +1 -1
  13. package/dist/components/data-table-labels.d.ts +1 -1
  14. package/dist/components/data-table-pagination.d.ts +1 -1
  15. package/dist/components/data-table.d.ts +1 -1
  16. package/dist/components/data-table.js.map +1 -1
  17. package/dist/components/facing-pair.d.ts +13 -9
  18. package/dist/components/file-button.d.ts +13 -9
  19. package/dist/components/file-dropzone.d.ts +13 -9
  20. package/dist/components/form-actions.d.ts +13 -9
  21. package/dist/components/iban-input.d.ts +13 -9
  22. package/dist/components/language-select.d.ts +13 -9
  23. package/dist/components/money-field.d.ts +13 -9
  24. package/dist/components/number-field.d.ts +13 -9
  25. package/dist/components/number-input.d.ts +13 -9
  26. package/dist/components/numpad-sheet.d.ts +13 -9
  27. package/dist/components/phone-input.d.ts +13 -9
  28. package/dist/components/series-chart.d.ts +13 -9
  29. package/dist/components/settings-fields.d.ts +13 -9
  30. package/dist/components/share-card.d.ts +13 -9
  31. package/dist/components/text-link.d.ts +13 -9
  32. package/dist/components/time-input.d.ts +13 -9
  33. package/dist/components/ui.d.ts +10 -6
  34. package/dist/components/use-table-state.d.ts +1 -1
  35. package/dist/{data-table-labels-Cdn1QS2k.d.ts → data-table-labels-DUELeXpa.d.ts} +5 -0
  36. package/dist/data-table.d.ts +1 -1
  37. package/dist/feedback/feedback-attachment.d.ts +13 -9
  38. package/dist/feedback/feedback-attachment.js +3 -3
  39. package/dist/feedback/feedback-attachment.js.map +1 -1
  40. package/dist/feedback/feedback-capture.d.ts +71 -0
  41. package/dist/feedback/feedback-capture.js +194 -0
  42. package/dist/feedback/feedback-capture.js.map +1 -0
  43. package/dist/feedback/feedback-context.d.ts +71 -0
  44. package/dist/feedback/feedback-context.js +96 -0
  45. package/dist/feedback/feedback-context.js.map +1 -0
  46. package/dist/feedback/feedback-crash.d.ts +276 -0
  47. package/dist/feedback/feedback-crash.js +225 -0
  48. package/dist/feedback/feedback-crash.js.map +1 -0
  49. package/dist/feedback/feedback-dialog.d.ts +13 -9
  50. package/dist/feedback/feedback-dialog.js +5 -3
  51. package/dist/feedback/feedback-dialog.js.map +1 -1
  52. package/dist/feedback/feedback-inbox.d.ts +13 -9
  53. package/dist/feedback/feedback-inbox.js +89 -49
  54. package/dist/feedback/feedback-inbox.js.map +1 -1
  55. package/dist/feedback/feedback-labels.d.ts +71 -0
  56. package/dist/feedback/feedback-labels.js +48 -0
  57. package/dist/feedback/feedback-labels.js.map +1 -0
  58. package/dist/feedback/feedback-menu.d.ts +71 -0
  59. package/dist/feedback/feedback-menu.js +61 -0
  60. package/dist/feedback/feedback-menu.js.map +1 -0
  61. package/dist/feedback/feedback-record.d.ts +71 -0
  62. package/dist/feedback/feedback-record.js +104 -0
  63. package/dist/feedback/feedback-record.js.map +1 -0
  64. package/dist/feedback/feedback-row-detail.d.ts +71 -0
  65. package/dist/feedback/feedback-row-detail.js +437 -0
  66. package/dist/feedback/feedback-row-detail.js.map +1 -0
  67. package/dist/feedback/feedback-status-undo.d.ts +71 -0
  68. package/dist/feedback/feedback-status-undo.js +40 -0
  69. package/dist/feedback/feedback-status-undo.js.map +1 -0
  70. package/dist/feedback/feedback-submit.d.ts +182 -0
  71. package/dist/feedback/feedback-submit.js +101 -0
  72. package/dist/feedback/feedback-submit.js.map +1 -0
  73. package/dist/feedback/feedback-swipe.d.ts +152 -0
  74. package/dist/feedback/feedback-swipe.js +73 -0
  75. package/dist/feedback/feedback-swipe.js.map +1 -0
  76. package/dist/feedback/feedback-table.d.ts +71 -0
  77. package/dist/feedback/feedback-table.js +357 -0
  78. package/dist/feedback/feedback-table.js.map +1 -0
  79. package/dist/feedback/feedback-thread.d.ts +13 -9
  80. package/dist/feedback.d.ts +17 -9
  81. package/dist/feedback.js +11 -0
  82. package/dist/feedback.js.map +1 -1
  83. package/dist/hooks/use-file-drop.d.ts +13 -9
  84. package/dist/i18n/defaults.d.ts +13 -9
  85. package/dist/i18n/defaults.js +16 -0
  86. package/dist/i18n/defaults.js.map +1 -1
  87. package/dist/i18n/german.d.ts +13 -9
  88. package/dist/i18n/german.js +91 -5
  89. package/dist/i18n/german.js.map +1 -1
  90. package/dist/i18n/kit-labels.d.ts +7 -3
  91. package/dist/i18n/kit-labels.js.map +1 -1
  92. package/dist/i18n/languages.d.ts +13 -9
  93. package/dist/i18n/locales/de-CH.d.ts +13 -9
  94. package/dist/i18n/locales/en.d.ts +13 -9
  95. package/dist/i18n/locales/en.js +10 -1
  96. package/dist/i18n/locales/en.js.map +1 -1
  97. package/dist/i18n/locales/es.d.ts +13 -9
  98. package/dist/i18n/locales/es.js +89 -5
  99. package/dist/i18n/locales/es.js.map +1 -1
  100. package/dist/i18n/locales/fr.d.ts +13 -9
  101. package/dist/i18n/locales/fr.js +89 -5
  102. package/dist/i18n/locales/fr.js.map +1 -1
  103. package/dist/i18n/locales/hu.d.ts +13 -9
  104. package/dist/i18n/locales/hu.js +90 -5
  105. package/dist/i18n/locales/hu.js.map +1 -1
  106. package/dist/i18n/locales/it.d.ts +13 -9
  107. package/dist/i18n/locales/it.js +89 -5
  108. package/dist/i18n/locales/it.js.map +1 -1
  109. package/dist/i18n/locales/zh.d.ts +13 -9
  110. package/dist/i18n/locales/zh.js +89 -5
  111. package/dist/i18n/locales/zh.js.map +1 -1
  112. package/dist/i18n/review.d.ts +16 -11
  113. package/dist/i18n/review.js +11 -0
  114. package/dist/i18n/review.js.map +1 -1
  115. package/dist/i18n/swiss.js +3 -1
  116. package/dist/i18n/swiss.js.map +1 -1
  117. package/dist/index.d.ts +6 -2
  118. package/dist/index.js +11 -0
  119. package/dist/index.js.map +1 -1
  120. package/dist/{feedback-BXKH-ToU.d.ts → kit-labels-DQg82eHB.d.ts} +1275 -25
  121. package/dist/rhf/fields.d.ts +13 -9
  122. package/dist/rhf/form.d.ts +13 -9
  123. package/dist/rhf.d.ts +13 -9
  124. package/dist/shell/app-shell.d.ts +13 -9
  125. package/dist/shell/top-bar-brand.d.ts +13 -9
  126. package/dist/shell.d.ts +11 -11
  127. package/dist/wizard/stepper-nav.d.ts +13 -9
  128. package/dist/wizard.d.ts +13 -9
  129. package/package.json +6 -1
  130. package/src/components/data-table.tsx +5 -0
  131. package/src/feedback/feedback-attachment.tsx +19 -3
  132. package/src/feedback/feedback-capture.ts +285 -0
  133. package/src/feedback/feedback-context.tsx +217 -0
  134. package/src/feedback/feedback-crash.ts +547 -0
  135. package/src/feedback/feedback-dialog.tsx +29 -6
  136. package/src/feedback/feedback-inbox.tsx +131 -27
  137. package/src/feedback/feedback-labels.ts +127 -0
  138. package/src/feedback/feedback-menu.tsx +132 -0
  139. package/src/feedback/feedback-record.ts +345 -0
  140. package/src/feedback/feedback-row-detail.tsx +825 -0
  141. package/src/feedback/feedback-status-undo.ts +111 -0
  142. package/src/feedback/feedback-submit.tsx +224 -0
  143. package/src/feedback/feedback-swipe.tsx +170 -0
  144. package/src/feedback/feedback-table.tsx +757 -0
  145. package/src/feedback.ts +13 -0
  146. package/src/i18n/defaults.ts +16 -0
  147. package/src/i18n/german.ts +98 -5
  148. package/src/i18n/kit-labels.tsx +20 -0
  149. package/src/i18n/locales/en.ts +15 -1
  150. package/src/i18n/locales/es.ts +96 -5
  151. package/src/i18n/locales/fr.ts +95 -5
  152. package/src/i18n/locales/hu.ts +94 -5
  153. package/src/i18n/locales/it.ts +97 -5
  154. package/src/i18n/locales/zh.ts +90 -5
  155. package/src/i18n/review.ts +14 -2
  156. package/src/i18n/swiss.ts +5 -1
  157. package/src/index.ts +13 -0
  158. package/tokens.css +4 -0
@@ -0,0 +1,547 @@
1
+ import { crashFingerprint } from "../components/error-boundary";
2
+ import type { CrashReport } from "../components/error-boundary";
3
+ import type { FeedbackEnvironment } from "./feedback-record";
4
+
5
+ /**
6
+ * Crash auto-filing, the client half — §4.6 of the feedback contract
7
+ * (docs/feedback-harmonization.md), lifted from keksdose's
8
+ * `frontend/src/shared/lib/crash-report.ts` (feedback #160).
9
+ *
10
+ * Until #160 keksdose had no telemetry at all: a render crash was one `console.error`
11
+ * that died with the tab, and live 0.4.26 crashed deterministically on /accounts for a
12
+ * real user without anybody finding out. kastlan and Kurvenschmiede still file nothing
13
+ * (contract §1). The kit's `ErrorBoundary` already owns the screen, the hostile-throw
14
+ * normalisation, the per-page-load dedupe and cap, and the chunk-load test; this module
15
+ * is the other half every app was going to write again — the POST, the buffer and the
16
+ * page redaction — so the three apps keep only what only they know: the endpoint, the
17
+ * token, the demo check and which query params may leave the device.
18
+ *
19
+ * Two rules outrank everything else, both keksdose's:
20
+ *
21
+ * 1. **It never throws.** It runs inside a boundary that has already caught a crash; a
22
+ * reporter that throws takes the fallback down with it and the user gets the white
23
+ * screen the boundary exists to prevent. Every function below ends in a `catch`.
24
+ * 2. **Structure, never content.** Nothing the user typed may go into a report — see
25
+ * {@link CrashReporter.redact}, which rebuilds the query string from an allow-list.
26
+ *
27
+ * One fix over keksdose: a report counts as filed **only when the server answered
28
+ * `stored: true`**. keksdose keys on `res.ok` + `reference` (kk `crash-report.ts:253-255`,
29
+ * `:325`), so its server's `202 { stored: false }` — the 20-an-hour limiter, a demo user
30
+ * — resolved `{}`, and the kit fallback said "This error has been reported
31
+ * automatically." for a report that was dropped (contract §4.6).
32
+ */
33
+
34
+ /** How many undeliverable reports wait in storage — the newest ones. A device stuck in a
35
+ * crash loop while offline would otherwise fill `localStorage` with copies of one stack
36
+ * (kk `crash-report.ts:37-39`, `MAX_PENDING = 3`). */
37
+ const MAX_PENDING = 3;
38
+
39
+ /** How long after a Vite hot update a crash is taken for its fallout (kk
40
+ * `crash-report.ts:76-79`): long enough for the re-render the update triggers, short
41
+ * enough that a crash the developer causes by clicking a minute later is still filed. */
42
+ const HOT_UPDATE_GRACE_MS = 10_000;
43
+
44
+ /**
45
+ * `POST /feedback/crash`'s body — `CrashReportCreate`, §3.6 (kk `schemas/feedback.py`),
46
+ * including the optional `origin` and `environment` the server copies into the row's
47
+ * `context`, so a dev crash no longer reads as prod and the admin list shows its env
48
+ * chip (§3.2).
49
+ *
50
+ * Every string is clamped to the server's column width before it is sent: one character
51
+ * over a `max_length` used to come back 422 and the report was lost (kk
52
+ * `crash-report.ts:104-106`) — the diagnostics are worth more truncated than not
53
+ * delivered. Empty strings are sent as `null`.
54
+ */
55
+ export interface CrashReportCreate {
56
+ /** The thrown value's `name`, ≤ 200. */
57
+ name: string | null;
58
+ /** 1–2000; `"(no message)"` when the error had none. */
59
+ message: string;
60
+ /** ≤ 8000 each. */
61
+ stack: string | null;
62
+ component_stack: string | null;
63
+ /** The boundary's `placement`: `"app"` stays `"app"`, anything else is `"page"`. */
64
+ boundary: "app" | "page";
65
+ /** `origin` + the redacted page, ≤ 2000. */
66
+ url: string | null;
67
+ /** The redacted page's pathname, ≤ 500. */
68
+ route: string | null;
69
+ /** ≤ 50 each. */
70
+ version: string | null;
71
+ viewport: string | null;
72
+ /** ≤ 500. */
73
+ ua: string | null;
74
+ online: boolean | null;
75
+ /** ISO 8601, UTC — when it crashed, not when a buffered copy was finally sent. */
76
+ occurred_at: string;
77
+ /** `location.origin` — which copy of the app (§3.2). ≤ 200. */
78
+ origin: string | null;
79
+ /** `"prod"` / `"dev"` / `"local"` (§3.2) — the app's `environment` option. ≤ 20. */
80
+ environment: string | null;
81
+ }
82
+
83
+ /** `POST /feedback/crash`'s answer — always a 202 (§3.6). Only `stored` decides. */
84
+ export interface CrashReportResponse {
85
+ /** `false` when the server dropped it on purpose: the limiter, a demo user. */
86
+ stored: boolean;
87
+ /** `true` when it was counted onto an open row with the same fingerprint. */
88
+ duplicate?: boolean;
89
+ feedback_id?: number | null;
90
+ /** The fingerprint's first 8 characters, for the user to quote. */
91
+ reference?: string | null;
92
+ }
93
+
94
+ /**
95
+ * What {@link CrashReporter.onReport} resolves with — the kit `ErrorBoundary`'s
96
+ * `CrashReportResult`, narrowed to the three answers the fallback tells apart:
97
+ *
98
+ * - **filed with a reference** — `{ reference: "3fae6774" }`: the server stored it
99
+ * (`stored === true`) and named it; the screen says "Reported as 3fae6774" and drops
100
+ * the copy button;
101
+ * - **filed** — `{}`: stored, but the server gave no reference; the screen says "This
102
+ * error has been reported automatically.";
103
+ * - **not filed** — `{ filed: false }`: suppressed by the app (`suppress`, a hot
104
+ * update, a chunk-load error), refused by the server (`stored: false`, a 4xx), or
105
+ * buffered for later (offline, signed out, 401, 5xx, no network). The screen claims
106
+ * nothing and keeps the copy button.
107
+ *
108
+ * Code that reads it outside a boundary: filed is `result.filed !== false`.
109
+ */
110
+ export type CrashFiling = { reference?: string } | { filed: false };
111
+
112
+ export interface CrashReporterOptions {
113
+ /** The app's crash route, e.g. `${API_BASE}/feedback/crash` (§3.3). */
114
+ endpoint: string;
115
+ /**
116
+ * The bearer token, read at the moment of filing — **never assumed to exist**. Nothing
117
+ * (`null`, `undefined`, `""`) means signed out, or not yet signed in again (kastlan
118
+ * keeps its access token in memory, so it is `null` at start-up until the refresh
119
+ * lands): the report is buffered and {@link CrashReporter.flushPending} sends it once
120
+ * a token appears.
121
+ *
122
+ * Must not touch React — no hooks, no context: it runs from a component that is
123
+ * mid-crash. Read storage or a store's `getState()` (kk `crash-report.ts:175-181`).
124
+ * A throw reads as "no token".
125
+ */
126
+ getToken: () => string | null | undefined;
127
+ /**
128
+ * The query params a report may keep — the app's ALLOW-list (§4.6). Everything else
129
+ * is dropped, so a param added later stays out until somebody decides otherwise.
130
+ * keksdose's: `p ps sort tab g granularity month preset from to tstate future
131
+ * archived uncleared` (kk `crash-report.ts:136-151`) — what locates a render crash
132
+ * (paging, sort, range, grouping), never `q` (free text), `f.*` (filters holding
133
+ * payee names) or ids (`row`, `action`). Copied when the reporter is made.
134
+ */
135
+ allowParams: Iterable<string>;
136
+ /** The `localStorage` key undeliverable reports wait under — one per app, e.g.
137
+ * keksdose's `"keksdose.pendingCrashReports"` (kk `crash-report.ts:35`). */
138
+ storageKey: string;
139
+ /**
140
+ * The app's own opt-out: `true` files nothing and buffers nothing — keksdose's demo
141
+ * sessions (kk `crash-report.ts:183-193`; its server answers `stored: false` for them
142
+ * anyway). Asked at filing time and again before a flush, which keeps the buffer
143
+ * while it says `true`. Must not touch React; a throw reads as `false`. Optional:
144
+ * kastlan has no demo users.
145
+ */
146
+ suppress?: () => boolean;
147
+ /** The deploy environment, copied into every report (§3.2; kk
148
+ * `app/deploy-environment.ts`). */
149
+ environment: FeedbackEnvironment | (string & {});
150
+ /** Which copy of the app — default `location.origin` at filing time. */
151
+ origin?: string;
152
+ /** The app build — default the boundary's `appVersion` prop, as the report carries it. */
153
+ version?: string;
154
+ /** The `fetch` to post with — default the global one, looked up at each call. For
155
+ * tests (no network) and for an app whose `fetch` is wrapped. */
156
+ fetchImpl?: typeof fetch;
157
+ }
158
+
159
+ /** What {@link createCrashReporter} returns. Every member is a free function (no
160
+ * `this`), safe to pass as a prop or a listener as it stands. */
161
+ export interface CrashReporter {
162
+ /**
163
+ * The boundary's `onReport`: file one crash and say how it went ({@link CrashFiling}).
164
+ * Never throws, never rejects.
165
+ *
166
+ * The report arrives already `redact`ed when this reporter's `redact` is the
167
+ * boundary's too; the page is reduced again here anyway, because the allow-list is
168
+ * the one thing this channel must never get wrong (kk `crash-report.ts:273-276`).
169
+ */
170
+ onReport: (report: CrashReport) => Promise<CrashFiling>;
171
+ /**
172
+ * The boundary's `redact`: the report with its page reduced to the pathname and the
173
+ * allowed query params (no hash). The screen's details and the copy button — whose
174
+ * text ends up pasted into a feedback message — then show the same reduced page as the
175
+ * POST (kk `crash-report.ts:114-135`). `extras` are the app's own and pass unchanged.
176
+ */
177
+ redact: (report: CrashReport) => CrashReport;
178
+ /**
179
+ * Send the buffered reports. Call it at start-up and whenever a token appears (kk
180
+ * `main.tsx:59-61`). One flush at a time — a second call while one runs joins it.
181
+ * Keeps the buffer while there is no token, the app suppresses, or the browser is
182
+ * offline; stops at the first 401/5xx/network failure and keeps the rest. Never
183
+ * rejects.
184
+ */
185
+ flushPending: () => Promise<void>;
186
+ /**
187
+ * Note that Vite has just applied a hot update: a crash within 10 s of one is HMR
188
+ * fallout (a module re-executed under a live React tree), not the app's bug, and is
189
+ * not filed (kk `crash-report.ts:56-102`; eight rows across five keksdose feedback
190
+ * runs were exactly this). Dev only by construction — a production build has no
191
+ * `import.meta.hot` to call it from. The kit cannot listen itself (a pre-bundled
192
+ * dependency sees no `import.meta.hot`), so the app wires both events:
193
+ *
194
+ * ```ts
195
+ * if (import.meta.hot) {
196
+ * import.meta.hot.on("vite:beforeUpdate", () => crashReporter.noteHotUpdate());
197
+ * import.meta.hot.on("vite:afterUpdate", () => crashReporter.noteHotUpdate());
198
+ * }
199
+ * ```
200
+ */
201
+ noteHotUpdate: (at?: number) => void;
202
+ }
203
+
204
+ const NOT_FILED: CrashFiling = Object.freeze({ filed: false as const });
205
+
206
+ /** Trimmed and cut to `max`; `null` for a non-string or an empty one. */
207
+ function clamp(value: unknown, max: number): string | null {
208
+ if (typeof value !== "string") return null;
209
+ const trimmed = value.trim();
210
+ if (!trimmed) return null;
211
+ return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
212
+ }
213
+
214
+ /** The page as `pathname?allowed=params` — never anything else. */
215
+ function reducePage(page: unknown, allow: ReadonlySet<string>): string {
216
+ const raw = typeof page === "string" ? page : "";
217
+ try {
218
+ // The base only lets a path parse; it never leaves this function.
219
+ const url = new URL(raw, "http://localhost");
220
+ const kept = new URLSearchParams();
221
+ for (const [key, value] of url.searchParams) {
222
+ if (allow.has(key)) kept.append(key, value);
223
+ }
224
+ const query = kept.toString();
225
+ return `${url.pathname}${query ? `?${query}` : ""}`;
226
+ } catch {
227
+ // A page that will not parse still has a pathname worth having (kk `:163-167`).
228
+ return raw.split(/[?#]/)[0];
229
+ }
230
+ }
231
+
232
+ /** The server's message normalisation (kk `feedback_service.py` `_normalise`): hex runs
233
+ * of 6 or more first, then digit runs, to `#`; whitespace collapsed. */
234
+ function normalise(text: string): string {
235
+ return text
236
+ .replace(/\b[0-9a-fA-F]{6,}\b/g, "#")
237
+ .replace(/\d+/g, "#")
238
+ .replace(/\s+/g, " ")
239
+ .trim();
240
+ }
241
+
242
+ /**
243
+ * "The same crash again" in the buffer: the kit boundary's {@link crashFingerprint}
244
+ * (name, message, top frames) over the server's normalised message and first three
245
+ * normalised stack lines, plus the version and route — the server's own identity
246
+ * (§3.6) without the user, who is whoever signs in to flush. Placement is left out, as
247
+ * the server leaves it out: two copies that differ only in it end up as one row anyway.
248
+ * Never coarser than the server's key, so the buffer never merges two crashes the server
249
+ * would have filed apart.
250
+ */
251
+ function bufferKey(p: CrashReportCreate): string {
252
+ const frames = (p.stack ?? "").split("\n").slice(0, 3).map(normalise).join("\n");
253
+ const crash = crashFingerprint({ name: p.name ?? "", message: normalise(p.message), stack: frames });
254
+ return `${p.version ?? ""}::${p.route ?? ""}::${crash}`;
255
+ }
256
+
257
+ /**
258
+ * The buffer, deduplicated and bounded: one entry per {@link bufferKey}, the FIRST
259
+ * occurrence kept (its `occurred_at` is when the bug first hit) but moved to the position
260
+ * of the latest, so a crash that keeps recurring is the last to be evicted; then the
261
+ * newest {@link MAX_PENDING}.
262
+ */
263
+ function compact(list: CrashReportCreate[]): CrashReportCreate[] {
264
+ const first = new Map<string, CrashReportCreate>();
265
+ const last = new Map<string, number>();
266
+ list.forEach((p, i) => {
267
+ const key = bufferKey(p);
268
+ if (!first.has(key)) first.set(key, p);
269
+ last.set(key, i);
270
+ });
271
+ return [...last.entries()]
272
+ .sort((a, b) => a[1] - b[1])
273
+ .map(([key]) => first.get(key) as CrashReportCreate)
274
+ .slice(-MAX_PENDING);
275
+ }
276
+
277
+ function isPayload(value: unknown): value is CrashReportCreate {
278
+ if (!value || typeof value !== "object") return false;
279
+ const p = value as Partial<CrashReportCreate>;
280
+ return typeof p.message === "string" && p.message !== "" && typeof p.occurred_at === "string";
281
+ }
282
+
283
+ function storage(): Storage | null {
284
+ try {
285
+ return globalThis.localStorage ?? null;
286
+ } catch {
287
+ return null; // private mode / storage disabled
288
+ }
289
+ }
290
+
291
+ function isOffline(): boolean {
292
+ try {
293
+ return typeof navigator !== "undefined" && navigator.onLine === false;
294
+ } catch {
295
+ return false;
296
+ }
297
+ }
298
+
299
+ function viewport(): string | null {
300
+ try {
301
+ return `${window.innerWidth}x${window.innerHeight}`;
302
+ } catch {
303
+ return null;
304
+ }
305
+ }
306
+
307
+ function currentOrigin(): string {
308
+ try {
309
+ const origin = globalThis.location?.origin;
310
+ return typeof origin === "string" && origin !== "null" ? origin : "";
311
+ } catch {
312
+ return "";
313
+ }
314
+ }
315
+
316
+ type PostResult = { filed: true; reference?: string } | { filed: false; retry: boolean };
317
+
318
+ /**
319
+ * Make the crash filer for one app — §4.6, the kit's half of keksdose's
320
+ * `shared/lib/crash-report.ts`. Hand the result to both boundaries (`placement="app"`
321
+ * at the root, `"page"` in the layout):
322
+ *
323
+ * ```tsx
324
+ * export const crashReporter = createCrashReporter({
325
+ * endpoint: `${API_BASE}/feedback/crash`,
326
+ * getToken: () => localStorage.getItem("auth_token"),
327
+ * allowParams: ["p", "ps", "sort", "tab"],
328
+ * storageKey: "myapp.pendingCrashReports",
329
+ * suppress: () => useAuth.getState().user?.is_demo === true,
330
+ * environment: deployEnvironment(),
331
+ * });
332
+ *
333
+ * <ErrorBoundary placement="page" appVersion={APP_VERSION}
334
+ * redact={crashReporter.redact} onReport={crashReporter.onReport}>
335
+ *
336
+ * // start-up, and whenever a token appears (kk main.tsx:59-61)
337
+ * void crashReporter.flushPending();
338
+ * useAuth.subscribe((s, prev) => { if (s.token && !prev.token) void crashReporter.flushPending(); });
339
+ * ```
340
+ *
341
+ * What it sends: §3.6's `CrashReportCreate` ({@link CrashReportCreate}) with `origin`
342
+ * and `environment`, clamped to the server's caps. How: a bare `fetch` with `keepalive`
343
+ * and the bearer token — **not the app's axios client**, whose 401 handler would log the
344
+ * user out of a page that has just crashed (kk `crash-report.ts:222-235`), and
345
+ * `keepalive` so the request survives the Reload the user is about to press.
346
+ *
347
+ * When it files nothing (resolving `{ filed: false }`):
348
+ * - a chunk-load error (the boundary already withholds those) — a deploy or a dropped
349
+ * connection, not a defect;
350
+ * - `suppress()` says so (demo sessions), or a hot update landed under 10 s ago;
351
+ * - the server answered `stored: false` (limiter, demo) or a 4xx other than 401 —
352
+ * dropped, never retried: the server will never take that payload.
353
+ *
354
+ * When it buffers (also `{ filed: false }` — not filed *yet*): offline, no token,
355
+ * 401, 5xx, or no network. Up to 3 reports wait under `storageKey`, the newest kept,
356
+ * identical crashes kept once (see `bufferKey`); {@link CrashReporter.flushPending}
357
+ * sends them. A signed-out visitor's crash waits for a sign-in — there is no
358
+ * unauthenticated crash endpoint (Kurvenschmiede's public pages; accepted, §4.6).
359
+ */
360
+ export function createCrashReporter(options: CrashReporterOptions): CrashReporter {
361
+ const { endpoint, getToken, storageKey, suppress, environment } = options;
362
+ const allow: ReadonlySet<string> = new Set(options.allowParams);
363
+ let lastHotUpdateAt = 0;
364
+ let flushing: Promise<void> | null = null;
365
+
366
+ function token(): string | null {
367
+ try {
368
+ const t = getToken();
369
+ return typeof t === "string" && t !== "" ? t : null;
370
+ } catch {
371
+ return null;
372
+ }
373
+ }
374
+
375
+ function suppressed(): boolean {
376
+ try {
377
+ return suppress?.() === true;
378
+ } catch {
379
+ // keksdose's rule (`isDemoSession`): an opt-out that cannot answer does not opt
380
+ // out — the server suppresses demo users itself.
381
+ return false;
382
+ }
383
+ }
384
+
385
+ function readPending(): CrashReportCreate[] {
386
+ try {
387
+ const raw = storage()?.getItem(storageKey);
388
+ if (!raw) return [];
389
+ const parsed: unknown = JSON.parse(raw);
390
+ return Array.isArray(parsed) ? parsed.filter(isPayload) : [];
391
+ } catch {
392
+ return [];
393
+ }
394
+ }
395
+
396
+ function writePending(list: CrashReportCreate[]): void {
397
+ try {
398
+ const store = storage();
399
+ if (!store) return;
400
+ const kept = compact(list);
401
+ if (kept.length === 0) store.removeItem(storageKey);
402
+ else store.setItem(storageKey, JSON.stringify(kept));
403
+ } catch {
404
+ /* best effort: a report that cannot be buffered is lost */
405
+ }
406
+ }
407
+
408
+ function buffer(payload: CrashReportCreate): void {
409
+ writePending([...readPending(), payload]);
410
+ }
411
+
412
+ async function post(payload: CrashReportCreate, bearer: string): Promise<PostResult> {
413
+ try {
414
+ // A local, so it is called without `this` — `options.fetchImpl(…)` would bind the
415
+ // options object and a browser's own `fetch` throws "Illegal invocation".
416
+ const send = options.fetchImpl ?? globalThis.fetch;
417
+ if (typeof send !== "function") return { filed: false, retry: true };
418
+ const res = await send(endpoint, {
419
+ method: "POST",
420
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${bearer}` },
421
+ body: JSON.stringify(payload),
422
+ keepalive: true,
423
+ });
424
+ if (!res.ok) {
425
+ // 401: the token expired — worth another go after the next sign-in. 5xx: the
426
+ // server's trouble. Any other 4xx refuses this payload for good, and retrying it
427
+ // would wedge the buffer behind it (kk `crash-report.ts:246-252`).
428
+ return { filed: false, retry: res.status === 401 || res.status >= 500 };
429
+ }
430
+ const body: unknown = await res.json().catch(() => null);
431
+ const answer = (body ?? {}) as Partial<Record<keyof CrashReportResponse, unknown>>;
432
+ // THE fix (§4.6): a 202 is not a filing. `stored: false` is the limiter or a
433
+ // demo user, and a body without `stored` is no proof either.
434
+ if (answer.stored !== true) return { filed: false, retry: false };
435
+ const reference = typeof answer.reference === "string" && answer.reference ? answer.reference : undefined;
436
+ return reference ? { filed: true, reference } : { filed: true };
437
+ } catch {
438
+ return { filed: false, retry: true }; // network down, blocked, a hostile fetch
439
+ }
440
+ }
441
+
442
+ function payloadOf(report: CrashReport): CrashReportCreate {
443
+ const page = reducePage(report.page, allow);
444
+ const origin = options.origin ?? currentOrigin();
445
+ return {
446
+ name: clamp(report.name, 200),
447
+ message: clamp(report.message, 2000) ?? "(no message)",
448
+ stack: clamp(report.stack, 8000),
449
+ component_stack: clamp(report.componentStack, 8000),
450
+ boundary: report.placement === "app" ? "app" : "page",
451
+ url: clamp(`${origin}${page}`, 2000),
452
+ route: clamp(page.split("?")[0], 500),
453
+ version: clamp(options.version ?? report.appVersion, 50),
454
+ viewport: clamp(viewport(), 50),
455
+ ua: clamp(report.userAgent, 500),
456
+ online: typeof report.online === "boolean" ? report.online : null,
457
+ occurred_at: typeof report.time === "string" && report.time ? report.time : new Date().toISOString(),
458
+ origin: clamp(origin, 200),
459
+ environment: clamp(environment, 20),
460
+ };
461
+ }
462
+
463
+ async function onReport(report: CrashReport): Promise<CrashFiling> {
464
+ try {
465
+ // The boundary never hands one over; said here too, so a direct caller cannot
466
+ // buffer a connectivity symptom as if it were a defect.
467
+ if (report.chunkLoad) return NOT_FILED;
468
+ if (suppressed()) return NOT_FILED;
469
+ if (lastHotUpdateAt > 0 && Date.now() - lastHotUpdateAt < HOT_UPDATE_GRACE_MS) {
470
+ // Said out loud: the developer is looking at this screen, and "nothing was
471
+ // filed" only reassures when you know why (kk `crash-report.ts:284-288`).
472
+ console.info("[ui-kit] crash not filed: a hot update landed moments ago", report.message);
473
+ return NOT_FILED;
474
+ }
475
+ // Built before any wait, so it carries the state at crash time (`online: false`
476
+ // included) whenever it is finally sent.
477
+ const payload = payloadOf(report);
478
+ const bearer = token();
479
+ // Offline: the crashes hardest to reproduce are the ones with no network (kk
480
+ // `crash-report.ts:308-315`). Signed out: nobody to file it under yet.
481
+ if (isOffline() || !bearer) {
482
+ buffer(payload);
483
+ return NOT_FILED;
484
+ }
485
+ const result = await post(payload, bearer);
486
+ if (result.filed) return result.reference ? { reference: result.reference } : {};
487
+ if (result.retry) buffer(payload);
488
+ return NOT_FILED;
489
+ } catch {
490
+ // Last line of defence: whatever went wrong in here, the fallback still renders.
491
+ return NOT_FILED;
492
+ }
493
+ }
494
+
495
+ async function drain(): Promise<void> {
496
+ try {
497
+ const pending = readPending();
498
+ if (pending.length === 0) return;
499
+ // Still unattributable, opted out or offline: keep them rather than burn them.
500
+ const bearer = token();
501
+ if (!bearer || suppressed() || isOffline()) return;
502
+ // Clear first and re-buffer only what failed for a reason worth retrying: should
503
+ // the tab die mid-flush, losing a report beats re-posting the same rows on every
504
+ // load forever (kk `crash-report.ts:353-356`).
505
+ writePending([]);
506
+ const keep: CrashReportCreate[] = [];
507
+ for (const [i, payload] of pending.entries()) {
508
+ const result = await post(payload, bearer);
509
+ if (!result.filed && result.retry) {
510
+ // The token or the server is the trouble, not this report — the rest would
511
+ // fail the same way. Keep it and everything after it for the next flush.
512
+ keep.push(...pending.slice(i));
513
+ break;
514
+ }
515
+ }
516
+ // Merged with what arrived meanwhile, never overwritten: a crash that buffered
517
+ // while the POSTs above were in flight (the start-up flush runs exactly when a
518
+ // boot-time crash fires) comes after them and is the newest (kk `:362-367`).
519
+ if (keep.length > 0) writePending([...keep, ...readPending()]);
520
+ } catch {
521
+ /* never throws: a failed flush must not break start-up */
522
+ }
523
+ }
524
+
525
+ function flushPending(): Promise<void> {
526
+ flushing ??= drain().finally(() => {
527
+ flushing = null;
528
+ });
529
+ return flushing;
530
+ }
531
+
532
+ function redact(report: CrashReport): CrashReport {
533
+ try {
534
+ return { ...report, page: reducePage(report.page, allow) };
535
+ } catch {
536
+ // Only a hostile object gets here (a getter that throws on the spread), so
537
+ // nothing of it is read again: fail closed with an empty report.
538
+ return { name: "Error", message: "", page: "", time: "", userAgent: "", chunkLoad: false, extras: {} };
539
+ }
540
+ }
541
+
542
+ function noteHotUpdate(at: number = Date.now()): void {
543
+ lastHotUpdateAt = at;
544
+ }
545
+
546
+ return { onReport, redact, flushPending, noteHotUpdate };
547
+ }
@@ -3,6 +3,7 @@ import type { ReactNode } from "react";
3
3
  import { Button, Input, PHONE_QUERY, Select, Textarea } from "../components/ui";
4
4
  import type { ButtonSize, ButtonVariant } from "../components/ui";
5
5
  import { Modal } from "../components/modal";
6
+ import { isApplePlatform } from "../hooks/use-hotkey";
6
7
  import { useMediaQuery } from "../hooks/use-media-query";
7
8
  import { useKitLabels } from "../i18n/kit-labels";
8
9
  import {
@@ -52,7 +53,8 @@ export interface FeedbackDialogLabels extends FeedbackAttachmentLabels {
52
53
  subject: string;
53
54
  body: string;
54
55
  attachment: string;
55
- submitHint: string;
56
+ /** See {@link FeedbackDialogTextLabels.submitHint}. */
57
+ submitHint: FeedbackSubmitHint;
56
58
  cancel: string;
57
59
  save: string;
58
60
  /** @deprecated since 0.16.0 — use `attachmentList`, the one key for the heading and
@@ -61,6 +63,9 @@ export interface FeedbackDialogLabels extends FeedbackAttachmentLabels {
61
63
  attachments?: string;
62
64
  }
63
65
 
66
+ /** The submit hint: a string, or the line for the platform (`apple`: Mac, iPhone, iPad). */
67
+ export type FeedbackSubmitHint = string | ((apple: boolean) => string);
68
+
64
69
  /**
65
70
  * The dialog's own strings — the `feedbackDialog` namespace of `<UiKitProvider
66
71
  * labels>` (0.12.0). The attachment keys are not repeated here: they are the
@@ -79,8 +84,13 @@ export interface FeedbackDialogTextLabels {
79
84
  bodyOptional?: string;
80
85
  /** The heading over the attachment buttons. */
81
86
  attachment: string;
82
- /** The line beside the buttons naming the shortcut. */
83
- submitHint: string;
87
+ /**
88
+ * The line beside the buttons naming the shortcut. Since 0.27.0 a function of the
89
+ * platform, like `form.submitShortcut`: `apple` is true on a Mac, iPhone or iPad, where
90
+ * the key is Cmd — "⌘ Enter to send" there, keksdose's "Ctrl+Enter to send" elsewhere
91
+ * (§7.12). A plain string is still taken and shown everywhere, as before 0.27.0.
92
+ */
93
+ submitHint: FeedbackSubmitHint;
84
94
  cancel: string;
85
95
  save: string;
86
96
  /** @deprecated since 0.16.0 — use `feedbackAttachment.attachmentList`. It and this
@@ -90,16 +100,27 @@ export interface FeedbackDialogTextLabels {
90
100
  attachments?: string;
91
101
  }
92
102
 
103
+ /**
104
+ * English. The feedback contract's wording (docs/feedback-harmonization.md §4.2, 0.27.0):
105
+ * "Send", not keksdose's "Save", and the body asks "What happened?" (Marcel's two calls);
106
+ * the rest is keksdose's. Since 0.27.0 `attachment`, the single-mode heading, is keksdose's
107
+ * `feedback.attachment` **"Attachment"** (it said "Screenshot" over a button that says "Add
108
+ * attachment" and a picker that may offer a PDF), and `submitHint` is keksdose's
109
+ * **"Ctrl+Enter to send"** — "⌘ Enter to send" on Apple platforms, where the old
110
+ * "Ctrl/⌘ + Enter" made every reader parse both. The `attachments="multiple"` heading is
111
+ * `feedbackAttachment.attachmentList` ("Attachments") and did not change.
112
+ */
93
113
  export const DEFAULT_FEEDBACK_DIALOG_LABELS: FeedbackDialogTextLabels = {
94
114
  title: "Send feedback",
95
115
  category: "Category",
96
116
  subject: "Subject",
97
117
  body: "What happened?",
98
118
  bodyOptional: "What happened? (optional)",
99
- attachment: "Screenshot",
119
+ attachment: "Attachment",
100
120
  // No `attachments`: the multiple-mode heading is `feedbackAttachment.attachmentList`,
101
121
  // and a default here would shadow a provider that translated only that one.
102
- submitHint: "Ctrl/⌘ + Enter to send",
122
+ // The modifier as `form.submitShortcut` writes it: "⌘ Enter" on Apple, "Ctrl+Enter" elsewhere.
123
+ submitHint: (apple) => (apple ? "⌘ Enter to send" : "Ctrl+Enter to send"),
103
124
  cancel: "Cancel",
104
125
  save: "Send",
105
126
  };
@@ -393,7 +414,9 @@ export function FeedbackDialog(props: FeedbackDialogProps) {
393
414
  </>
394
415
  )}
395
416
  <div className="flex items-center justify-between gap-2">
396
- <div className="text-xs text-[var(--text-placeholder)]">{labels.submitHint}</div>
417
+ <div className="text-xs text-[var(--text-placeholder)]">
418
+ {typeof labels.submitHint === "function" ? labels.submitHint(isApplePlatform()) : labels.submitHint}
419
+ </div>
397
420
  <div className="flex gap-2">
398
421
  <Button variant="ghost" onClick={onClose}>
399
422
  {labels.cancel}