@stapel/alerts-react 0.1.1

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 (166) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/LICENSE +21 -0
  3. package/MODULE.md +140 -0
  4. package/README.md +147 -0
  5. package/dist/analytics/events.d.ts +29 -0
  6. package/dist/analytics/events.d.ts.map +1 -0
  7. package/dist/analytics/events.js +28 -0
  8. package/dist/analytics/events.js.map +1 -0
  9. package/dist/api/alertsApi.d.ts +84 -0
  10. package/dist/api/alertsApi.d.ts.map +1 -0
  11. package/dist/api/alertsApi.js +127 -0
  12. package/dist/api/alertsApi.js.map +1 -0
  13. package/dist/api/generated/schema.d.ts +453 -0
  14. package/dist/api/generated/schema.d.ts.map +1 -0
  15. package/dist/api/generated/schema.js +2 -0
  16. package/dist/api/generated/schema.js.map +1 -0
  17. package/dist/api/types.d.ts +78 -0
  18. package/dist/api/types.d.ts.map +1 -0
  19. package/dist/api/types.js +44 -0
  20. package/dist/api/types.js.map +1 -0
  21. package/dist/default/FixIssueDialog.d.ts +15 -0
  22. package/dist/default/FixIssueDialog.d.ts.map +1 -0
  23. package/dist/default/FixIssueDialog.js +67 -0
  24. package/dist/default/FixIssueDialog.js.map +1 -0
  25. package/dist/default/IssueDetail.d.ts +10 -0
  26. package/dist/default/IssueDetail.d.ts.map +1 -0
  27. package/dist/default/IssueDetail.js +83 -0
  28. package/dist/default/IssueDetail.js.map +1 -0
  29. package/dist/default/IssueFilterBar.d.ts +21 -0
  30. package/dist/default/IssueFilterBar.d.ts.map +1 -0
  31. package/dist/default/IssueFilterBar.js +86 -0
  32. package/dist/default/IssueFilterBar.js.map +1 -0
  33. package/dist/default/IssuesFeed.d.ts +10 -0
  34. package/dist/default/IssuesFeed.d.ts.map +1 -0
  35. package/dist/default/IssuesFeed.js +137 -0
  36. package/dist/default/IssuesFeed.js.map +1 -0
  37. package/dist/default/MuteIssueDialog.d.ts +19 -0
  38. package/dist/default/MuteIssueDialog.d.ts.map +1 -0
  39. package/dist/default/MuteIssueDialog.js +72 -0
  40. package/dist/default/MuteIssueDialog.js.map +1 -0
  41. package/dist/default/index.d.ts +32 -0
  42. package/dist/default/index.d.ts.map +1 -0
  43. package/dist/default/index.js +26 -0
  44. package/dist/default/index.js.map +1 -0
  45. package/dist/default/labels.d.ts +40 -0
  46. package/dist/default/labels.d.ts.map +1 -0
  47. package/dist/default/labels.js +94 -0
  48. package/dist/default/labels.js.map +1 -0
  49. package/dist/default/layout.d.ts +32 -0
  50. package/dist/default/layout.d.ts.map +1 -0
  51. package/dist/default/layout.js +44 -0
  52. package/dist/default/layout.js.map +1 -0
  53. package/dist/default/types.d.ts +27 -0
  54. package/dist/default/types.d.ts.map +1 -0
  55. package/dist/default/types.js +2 -0
  56. package/dist/default/types.js.map +1 -0
  57. package/dist/flows/errors.d.ts +12 -0
  58. package/dist/flows/errors.d.ts.map +1 -0
  59. package/dist/flows/errors.js +13 -0
  60. package/dist/flows/errors.js.map +1 -0
  61. package/dist/flows/registry.d.ts +22 -0
  62. package/dist/flows/registry.d.ts.map +1 -0
  63. package/dist/flows/registry.js +20 -0
  64. package/dist/flows/registry.js.map +1 -0
  65. package/dist/headless/AlertsProvider.d.ts +19 -0
  66. package/dist/headless/AlertsProvider.d.ts.map +1 -0
  67. package/dist/headless/AlertsProvider.js +15 -0
  68. package/dist/headless/AlertsProvider.js.map +1 -0
  69. package/dist/i18n/errorsMap.d.ts +10 -0
  70. package/dist/i18n/errorsMap.d.ts.map +1 -0
  71. package/dist/i18n/errorsMap.js +20 -0
  72. package/dist/i18n/errorsMap.js.map +1 -0
  73. package/dist/i18n/es.d.ts +20 -0
  74. package/dist/i18n/es.d.ts.map +1 -0
  75. package/dist/i18n/es.js +152 -0
  76. package/dist/i18n/es.js.map +1 -0
  77. package/dist/i18n/generated/errors.es.gen.d.ts +9 -0
  78. package/dist/i18n/generated/errors.es.gen.d.ts.map +1 -0
  79. package/dist/i18n/generated/errors.es.gen.js +57 -0
  80. package/dist/i18n/generated/errors.es.gen.js.map +1 -0
  81. package/dist/i18n/generated/errors.gen.d.ts +323 -0
  82. package/dist/i18n/generated/errors.gen.d.ts.map +1 -0
  83. package/dist/i18n/generated/errors.gen.js +165 -0
  84. package/dist/i18n/generated/errors.gen.js.map +1 -0
  85. package/dist/i18n/generated/errors.ru.gen.d.ts +9 -0
  86. package/dist/i18n/generated/errors.ru.gen.d.ts.map +1 -0
  87. package/dist/i18n/generated/errors.ru.gen.js +57 -0
  88. package/dist/i18n/generated/errors.ru.gen.js.map +1 -0
  89. package/dist/i18n/keys.d.ts +164 -0
  90. package/dist/i18n/keys.d.ts.map +1 -0
  91. package/dist/i18n/keys.js +300 -0
  92. package/dist/i18n/keys.js.map +1 -0
  93. package/dist/i18n/ru.d.ts +27 -0
  94. package/dist/i18n/ru.d.ts.map +1 -0
  95. package/dist/i18n/ru.js +159 -0
  96. package/dist/i18n/ru.js.map +1 -0
  97. package/dist/index.d.ts +42 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +45 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/model/context.d.ts +11 -0
  102. package/dist/model/context.d.ts.map +1 -0
  103. package/dist/model/context.js +16 -0
  104. package/dist/model/context.js.map +1 -0
  105. package/dist/model/issues.d.ts +103 -0
  106. package/dist/model/issues.d.ts.map +1 -0
  107. package/dist/model/issues.js +230 -0
  108. package/dist/model/issues.js.map +1 -0
  109. package/dist/model/queryKeys.d.ts +11 -0
  110. package/dist/model/queryKeys.d.ts.map +1 -0
  111. package/dist/model/queryKeys.js +32 -0
  112. package/dist/model/queryKeys.js.map +1 -0
  113. package/dist/model/refusals.d.ts +25 -0
  114. package/dist/model/refusals.d.ts.map +1 -0
  115. package/dist/model/refusals.js +73 -0
  116. package/dist/model/refusals.js.map +1 -0
  117. package/dist/model/runtime.d.ts +51 -0
  118. package/dist/model/runtime.d.ts.map +1 -0
  119. package/dist/model/runtime.js +29 -0
  120. package/dist/model/runtime.js.map +1 -0
  121. package/dist/model/status.d.ts +60 -0
  122. package/dist/model/status.d.ts.map +1 -0
  123. package/dist/model/status.js +116 -0
  124. package/dist/model/status.js.map +1 -0
  125. package/dist/nav/manifest.d.ts +43 -0
  126. package/dist/nav/manifest.d.ts.map +1 -0
  127. package/dist/nav/manifest.js +36 -0
  128. package/dist/nav/manifest.js.map +1 -0
  129. package/llms.txt +84 -0
  130. package/manifest.json +694 -0
  131. package/nav-manifest.json +46 -0
  132. package/package.json +119 -0
  133. package/src/analytics/events.ts +29 -0
  134. package/src/analytics/generated/events.json +7 -0
  135. package/src/api/alertsApi.ts +259 -0
  136. package/src/api/generated/schema.ts +455 -0
  137. package/src/api/types.ts +113 -0
  138. package/src/default/FixIssueDialog.tsx +158 -0
  139. package/src/default/IssueDetail.tsx +431 -0
  140. package/src/default/IssueFilterBar.tsx +197 -0
  141. package/src/default/IssuesFeed.tsx +343 -0
  142. package/src/default/MuteIssueDialog.tsx +186 -0
  143. package/src/default/index.ts +37 -0
  144. package/src/default/labels.ts +113 -0
  145. package/src/default/layout.ts +52 -0
  146. package/src/default/types.ts +27 -0
  147. package/src/flows/errors.ts +16 -0
  148. package/src/flows/registry.ts +32 -0
  149. package/src/headless/AlertsProvider.tsx +20 -0
  150. package/src/i18n/errorsMap.ts +31 -0
  151. package/src/i18n/es.ts +181 -0
  152. package/src/i18n/generated/errors.es.gen.ts +63 -0
  153. package/src/i18n/generated/errors.gen.ts +196 -0
  154. package/src/i18n/generated/errors.json +370 -0
  155. package/src/i18n/generated/errors.ru.gen.ts +63 -0
  156. package/src/i18n/keys.ts +341 -0
  157. package/src/i18n/ru.ts +188 -0
  158. package/src/index.ts +152 -0
  159. package/src/model/context.tsx +28 -0
  160. package/src/model/issues.ts +311 -0
  161. package/src/model/queryKeys.ts +41 -0
  162. package/src/model/refusals.ts +82 -0
  163. package/src/model/runtime.ts +80 -0
  164. package/src/model/status.ts +179 -0
  165. package/src/nav/manifest.ts +76 -0
  166. package/tsconfig.json +26 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,109 @@
1
+ # @stapel/alerts-react
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 493df78: pin stapel-alerts 0.2.1: IssuePage from the schema, limit parameter
8
+
9
+ The contract caught up with the wire, so the pair stops correcting it.
10
+
11
+ **`IssuePage` is generated.** `docs/schema.json` now declares `GET /issues`
12
+ as the `{count, offset, limit, results}` envelope the view always returned;
13
+ the hand-declared type goes and `api/types.ts` re-exports the schema's.
14
+ `test/pair.test.ts` still proves the envelope on the wire — a generated type
15
+ is a statement about the contract, and the rows a screen draws come from the
16
+ body.
17
+
18
+ **`useIssues(filters)` takes `limit`.** `?limit=` is a parameter (1..200,
19
+ server default 50 when omitted). The server clamps rather than refuses and
20
+ echoes the size it applied, and the hook pages by that echo, never by the
21
+ number it asked for — a request for 500 rows cut to 200 does not skip 300.
22
+ `limit` rides in the filter key like the offset does, because a different
23
+ page size is a different server answer. It is a view setting, not a filter:
24
+ the feed's empty state does not count it, and "Clear" keeps it.
25
+
26
+ **`mute` sends the deadline alone.** `muted_until` on its own is a mute —
27
+ the store infers `status: "muted"` from it — so the patch no longer carries
28
+ a status. The key itself is still always sent (`null` for "forever"): a patch
29
+ without it is a note, not a mute.
30
+
31
+ **A non-muted row never carries a deadline.** Every transition out of `muted`
32
+ now clears `muted_until`, so the detail's "draw the deadline only while
33
+ muted" is no longer a workaround for a stale field but the plain rule that a
34
+ deadline belongs to the muted status. The test that fed a fixed row a stale
35
+ deadline exercised a wire state the backend can no longer produce and is
36
+ gone.
37
+
38
+ ## 0.1.0
39
+
40
+ ### Minor Changes
41
+
42
+ - f47c5bf: The React pair for stapel-alerts 0.1.0 — first release.
43
+
44
+ An alert store answers "which bugs are open, which are fixed, and which came
45
+ back". This package is the screen a person reconciles a fix wave against: the
46
+ triage feed grouped by the service that reported, the issue with its last
47
+ occurrences and their redacted context, and the three judgements an operator
48
+ can record.
49
+
50
+ **It reads and manages the tracker; it does not report to it.** `POST /report`
51
+ is authenticated with a service key that lives in every container in the fleet,
52
+ and the blast radius of one leaking must not include a browser. There is no
53
+ code path here that can reach it, and `test/pair.test.ts` asserts that over the
54
+ source rather than over an export list — an operation nobody exported today is
55
+ one refactor away from being exported tomorrow.
56
+
57
+ **The reads are conditional, and the validator lives in the cache entry.** Both
58
+ `GET`s answer an `ETag` and honour `If-None-Match` with a 304 and no body — the
59
+ module's own stated requirement, because a board open on a wall re-asks every
60
+ minute. `@stapel/core`'s client can express neither side (it surfaces no
61
+ response headers, and a 304 is not `response.ok`, so it would be thrown), so
62
+ the two reads speak `fetch` directly with every non-2xx folded through core's
63
+ `parseErrorEnvelope` — one error dialect out of both transports. The cached
64
+ value is `{etag, page}`, and on a 304 the query function returns THE PREVIOUS
65
+ OBJECT: TanStack compares by reference, so a poll through a quiet night
66
+ notifies nobody and repaints nothing. The test asserts `toBe`, not `toEqual` —
67
+ a hook that rebuilt an equal object would pass the second and still repaint
68
+ every minute.
69
+
70
+ **Four gaps between the backend's schema and its views, worked around and
71
+ named.** A-1: `docs/schema.json` declares `GET /issues` → `Issue[]` while the
72
+ view returns `{count, offset, limit, results}` — a pair that trusted the schema
73
+ would have rendered every row as `undefined`, so `IssuePage` is declared by
74
+ hand and proved against the wire. A-2: the page size is a server constant and
75
+ not a parameter, so it is read out of the answer. A-3: `PATCH` ignores
76
+ `muted_until` unless the patch also carries `status`, which is answered 200 and
77
+ changes nothing — so `mute` always sends both. A-4: `set_status` never clears
78
+ `muted_until` when the status moves on, so the deadline is rendered only while
79
+ the issue IS muted.
80
+
81
+ **`regressed` is never offered.** The store asserts it from evidence — a fixed
82
+ issue received a new event — and a caller able to set it would be a caller able
83
+ to withhold it. Every status control is built from `SETTABLE_ISSUE_STATUSES`,
84
+ which has three members, so the refusal cannot be provoked from this UI at all;
85
+ `isStatusNotSettable` exists for the host that wires its own control.
86
+
87
+ **Staff-only, said out loud.** Every route is `IsStaffUser`, and the nav axis
88
+ (`public` | `member`) cannot say so. The door stays visible and the screen names
89
+ the 403 — a hidden door teaches nobody anything, and an empty triage table
90
+ teaches the wrong thing: "nothing is broken" is the one sentence an error
91
+ tracker must never say by accident. A 401 is a separate arm with separate copy,
92
+ because the raw conditional reads do not run core's bearer-refresh retry and an
93
+ expired token arrives here as exactly that.
94
+
95
+ **Pinned at stapel-alerts 0.2.0, for the locale catalogue alone.** The wire
96
+ this pair consumes is byte-identical across 0.1.0..0.2.0 — `docs/schema.json`,
97
+ `docs/errors.json` and `docs/flows.json` do not move — and 0.2.0 adds
98
+ `translations/errors.{ru,es}.json` for the six codes the module owns. Without
99
+ the bump the pair would have had to hand-author those six strings and a Russian
100
+ host would have read six English refusals on day one; with it, `gen:errors`
101
+ reads the module's own catalogue merged over stapel-core's, and nothing in this
102
+ package words a backend refusal.
103
+
104
+ `/default` ships the antd skin — `IssuesFeed`, `IssueDetail`, `IssueFilterBar`,
105
+ `FixIssueDialog`, `MuteIssueDialog` — on `@stapel/tokens-antd/skin`, tokens
106
+ only, with ru and es beside en. Two nav entries under the container-owned
107
+ `admin.root`; the detail is a route and not a menu item, because nobody
108
+ navigates to one bug from a menu — they arrive from a row, or from an
109
+ `alerts:<issue-id>` reference in a commit message.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stapel contributors
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/MODULE.md ADDED
@@ -0,0 +1,140 @@
1
+ # @stapel/alerts-react — module guide
2
+
3
+ The React pair for **stapel-alerts**. Human companion to the generated
4
+ `llms.txt` (agent context) and `manifest.json` (machine catalog); `README.md`
5
+ is the usage entry point.
6
+
7
+ ## What this pair is for
8
+
9
+ One sentence: **an alert store answers "which bugs are open, which are fixed,
10
+ and which came back", and this is the screen a person reconciles a fix wave
11
+ against.**
12
+
13
+ Everything below follows from two facts about the backend. First, the module
14
+ is machine-facing on purpose — stable uuid ids, ETags, JSON only — because the
15
+ caller it was designed for is an agent closing issues after a fix wave; a
16
+ browser is the second caller and gets the same contract. Second, the tracker
17
+ and the REPORTING path are authenticated differently on purpose, and this pair
18
+ lives entirely on the tracker side.
19
+
20
+ ## Layers
21
+
22
+ - **api/** — `createAlertsApi(client, raw?)`, plus type aliases over the
23
+ package-LOCAL generated `components["schemas"]` (`Issue`, `IssueDetail`,
24
+ `ErrorEvent`, the three enums), produced by `pnpm gen:api` from
25
+ stapel-alerts's own `docs/schema.json`. Four operations; the fifth
26
+ (`POST /report`) is deliberately absent. The two READS do not ride
27
+ `StapelClient` — see "The two transports" below.
28
+ - **model/** — `useIssues` / `useIssue` (the conditional reads and the ETag
29
+ machinery), `useIssueStatus` (the three writes plus a note), the query-key
30
+ factory, `groupIssuesByService`, and the named refusals.
31
+ - **flows/** — `toFlowError` + the zero-flow `ALERTS_FLOWS` shim. The module
32
+ annotates no `@flow_step` and its `docs/flows.json` is literally `[]`, so
33
+ `gen:flows` emits nothing and the shim keeps the pair's public surface at its
34
+ zero-flow shape.
35
+ - **headless/** — `<AlertsProvider>`, core's `createModuleContext` provider
36
+ bound to this pair's names. Renders nothing.
37
+ - **default/** — the antd skin behind the `./default` subpath: two screens
38
+ (`IssuesFeed`, `IssueDetail`), the filter bar and the two dialogs.
39
+ - **i18n/** — `keys.ts` (en, backend codes spread in first), `ru.ts`, `es.ts`.
40
+ - **nav/** — two `NavEntry` values under the container-owned `admin.root`.
41
+
42
+ ## The two transports, and the one dialect
43
+
44
+ `views._conditional` answers an `ETag` on both `GET`s and honours
45
+ `If-None-Match` with a **304 and no body**. `@stapel/core`'s `StapelClient`
46
+ cannot express either side: it parses a JSON body and surfaces no response
47
+ headers (so the validator is unreadable), and a 304 is not `response.ok` (so it
48
+ would be THROWN). The two reads therefore speak `fetch` directly — the
49
+ `@stapel/docs-react` precedent for the same class of problem — bound to the
50
+ runtime's base URL, credentials and default headers.
51
+
52
+ The rule that keeps this from becoming the two-dialect defect CONTRIBUTING.md
53
+ warns about: **the raw reader folds every non-2xx through core's own
54
+ `parseErrorEnvelope` at its single rethrow point**, so a caller catches a
55
+ `StapelApiError` with a `.code` and a `.status` no matter which transport
56
+ produced it. `test/pair.test.ts` proves it by driving a real 403 envelope
57
+ through the real raw reader and reading `.code` off what was caught.
58
+
59
+ What the raw path does NOT carry is core's bearer-refresh retry. A 401 on a
60
+ read is therefore also the shape an expired token takes here, which is exactly
61
+ the case where "sign in again" is the right copy — and why `isAlertsUnauthorized`
62
+ is a different arm from `isAlertsStaffOnly`.
63
+
64
+ ## Where the validator lives — and why not in a ref
65
+
66
+ The cached VALUE is `{etag, page}`. The obvious alternative, a `useRef` beside
67
+ the query, is wrong three ways: two panes on the same filters are two refs over
68
+ one cache entry; an unmount throws the validator away while the rows survive;
69
+ and a re-mount then asks unconditionally for a page it already has.
70
+
71
+ On a 304 the query function returns **the previous object itself**. The
72
+ identity is the message: TanStack compares by reference, so a poll through a
73
+ quiet night notifies nobody and repaints nothing. A hook that rebuilt an equal
74
+ object would pass a `toEqual` assertion and still repaint every minute, which
75
+ is why `test/issuesHook.test.tsx` asserts `toBe`.
76
+
77
+ ## Mechanisms that exist — do not rebuild them
78
+
79
+ - **`SETTABLE_ISSUE_STATUSES`.** Every status control is built from it, so
80
+ `regressed` cannot be offered by construction. It is the store's verdict on
81
+ evidence; a caller able to assert it could also decline to.
82
+ - **`POST /fix` is the close.** A `PATCH {status: "fixed"}` leaves the same
83
+ status and records no release and no zeroed `count_since_fix` — the counter
84
+ that answers "did it come back?".
85
+ - **`mute` always sends the `muted_until` key.** The deadline alone is the
86
+ mute — the store infers the status and clears the deadline on the way out —
87
+ and a patch without the key is a note. `null` is "forever".
88
+ - **One invalidation.** `alertsQueryKeys.issues` is a prefix of both the list
89
+ keys and the detail key, so a write invalidates everything this module caches
90
+ in one call, and each re-ask is conditional.
91
+ - **`groupIssuesByService` is pure and exported.** The feed's ordering rule
92
+ (worst level, then loudest, never alphabetical) is a product decision that
93
+ must be testable without a render.
94
+
95
+ ## What this pair deliberately does NOT do
96
+
97
+ - **It does not report.** No `POST /report`, no `X-Service-Key`, no way to
98
+ reach either. A reporter's key lives in every container in the fleet.
99
+ - **It does not invent a service directory.** The filter bar offers the
100
+ services present in the page it has. `Service` upstream is the reporters' key
101
+ store, not a directory an operator may filter by.
102
+ - **It does not hide the staff wall.** The nav entry stays visible and the
103
+ screen names the 403 — an empty board would say "nothing is broken".
104
+ - **It does not draw a deadline outside the muted status.** `null` while
105
+ muted means "no deadline"; every other status has none, because the store
106
+ clears it.
107
+ - **It does not stream.** The module pushes nothing; the pair polls
108
+ conditionally on `runtime.pollIntervalMs` (60 s by default, the interval the
109
+ module's own API doc names), and `0` switches it off.
110
+
111
+ ## Backend gaps
112
+
113
+ None at stapel-alerts 0.2.1. The contract declares the `IssuePage` envelope,
114
+ takes `?limit=`, mutes on `muted_until` alone and clears the deadline on the
115
+ way out of a mute — the pair leans on each of those and works around nothing.
116
+
117
+ ## Core seams used
118
+
119
+ | seam | why |
120
+ |---|---|
121
+ | `createModuleRuntime` / `createModuleContext` | the pair plumbing, one reviewed copy |
122
+ | `parseErrorEnvelope` | the raw reads' single rethrow point — one dialect |
123
+ | `loadStateFromQuery` / `mapLoad` / `matchList` / `LoadBoundary` | the four arms, so "empty" and "failed" cannot share a branch |
124
+ | `useActiveSessionReady` | no read fires before the session has an answer |
125
+ | `useFormat` | relative times and timestamps at the APP's locale |
126
+ | `toFlowError` / `isErrorCode` | the refusal helpers |
127
+ | `NavEntry` | the two admin entries |
128
+ | `@stapel/tokens-antd/skin` | `Page`, `DataTable`, `StatusTag`, `SkinDialog`, `SkinConfirm`, `ErrorAlert`, `EmptyState` |
129
+
130
+ ## Not yet here
131
+
132
+ - A note editor on the issue screen. `useIssueStatus().annotate` exists and no
133
+ skin draws it: an operator writing a sentence about a bug wants somewhere to
134
+ put it, and the right shape for that is a decision the first host to ask can
135
+ make.
136
+ - A "mine"/assignment axis. The backend has no field for it
137
+ (stapel-alerts MODULE.md lists per-issue assignment as a 0.2 candidate).
138
+ - A live channel. There is none upstream, and a socket for a tracker whose
139
+ events arrive when the system is already failing is a smoke detector wired to
140
+ the burning fuse box.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @stapel/alerts-react
2
+
3
+ **The fleet's error tracker, read and reconciled from a browser.**
4
+
5
+ [`stapel-alerts`](https://github.com/usestapel/stapel-alerts) collects what a
6
+ fleet without Sentry would otherwise leave in `docker logs`: one `Issue` per
7
+ bug, with a status a fix wave is reconciled against, and one `ErrorEvent` per
8
+ occurrence with the trace and the redacted context. This package is the pair
9
+ that reads it — the triage feed, the issue, and the three judgements an
10
+ operator can record.
11
+
12
+ **It does not report.** `POST /report` is authenticated with a service key that
13
+ lives in every container in the fleet, and the blast radius of one leaking must
14
+ not include a browser. There is no code path here that can reach it, and
15
+ `test/pair.test.ts` asserts as much over the source.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pnpm add @stapel/alerts-react @stapel/core @tanstack/react-query
21
+ # the default skin (opt-in):
22
+ pnpm add antd @stapel/tokens-antd
23
+ ```
24
+
25
+ ## Mount
26
+
27
+ ```tsx
28
+ import { createAlertsRuntime, AlertsProvider } from "@stapel/alerts-react";
29
+ import { IssuesFeed, IssueDetail } from "@stapel/alerts-react/default";
30
+
31
+ const runtime = createAlertsRuntime({
32
+ baseUrl: "/alerts/api/v1/",
33
+ credentials: "include", // the staff session the tracker requires
34
+ commitRefUrl: (sha) => `https://github.com/acme/api/commit/${sha}`,
35
+ });
36
+
37
+ // runtime.client goes into core's <StapelConfigProvider config={{ client }}>
38
+ <AlertsProvider runtime={runtime}>
39
+ <IssuesFeed issueHref={(id) => `/admin/alerts/${id}`} />
40
+ </AlertsProvider>
41
+ ```
42
+
43
+ ## The reads are conditional, and that is the point
44
+
45
+ Both `GET`s answer an `ETag` and honour `If-None-Match` with a **304 and no
46
+ body** — the module's own stated requirement, because a triage board open on a
47
+ wall re-asks every minute and should not be handed a page of JSON it already
48
+ has.
49
+
50
+ `useIssues` and `useIssue` implement the other half:
51
+
52
+ - the cached value is `{etag, page}` — the rows and the validator the server
53
+ issued *for those rows*, stored together because that is what they are;
54
+ - a 304 returns **the previous object itself**, so TanStack sees the same
55
+ reference, notifies nobody, and a board polling through a quiet night
56
+ repaints exactly zero times;
57
+ - the validator is offered only when there are rows it belongs to.
58
+
59
+ `@stapel/core`'s `StapelClient` cannot express either side of this — it parses a
60
+ JSON body and surfaces no headers, and a 304 is not `response.ok`, so it would
61
+ be thrown as an error. So the two reads speak `fetch` directly (the
62
+ `@stapel/docs-react` precedent), with every non-2xx folded through core's own
63
+ `parseErrorEnvelope`: **one error dialect out of both transports**, so a caller
64
+ always catches a `StapelApiError` with a `.code`.
65
+
66
+ ## Hooks
67
+
68
+ | hook | what it answers |
69
+ |---|---|
70
+ | `useIssues(filters)` | the triage page: rows, the same rows grouped by service worst-first, the total apart from the page, the cursor, and the validator; `filters.limit` is the page size (1..200, server default 50) |
71
+ | `useIssue(id)` | one issue with its last 20 occurrences, their traces and their context |
72
+ | `useIssueStatus()` | `fix` (POST `/fix` with the release), `mute`, `reopen`, `annotate` |
73
+
74
+ `groupIssuesByService` is exported and pure: "which service is on fire" is the
75
+ first question the feed answers and it must be answerable without a render.
76
+
77
+ ## What this pair will not let you do
78
+
79
+ - **Set `regressed`.** The store asserts it from evidence (a fixed issue
80
+ received a new event), and a caller able to set it would be a caller able to
81
+ withhold it. `SETTABLE_ISSUE_STATUSES` is the list every control is built
82
+ from, and it has three members.
83
+ - **Close an issue with `PATCH {status: "fixed"}`.** Only `POST /fix` records
84
+ the release AND zeroes `count_since_fix`, which is the entire answer to "did
85
+ it come back?".
86
+ - **Mute by omitting the deadline.** `muted_until` on its own IS the mute (the
87
+ store infers `status: "muted"` from it and clears it on the way out of a
88
+ mute), so `mute` always sends the key — `null` for a mute with no deadline.
89
+ A patch without it is a note.
90
+
91
+ ## What the contract states, and the pair leans on
92
+
93
+ - `GET /issues` answers `IssuePage` — `{count, offset, limit, results}` — and
94
+ the schema declares it, so the type is generated; `test/pair.test.ts` still
95
+ proves the envelope on the wire.
96
+ - `?limit=` is a parameter (1..200, default 50). It is clamped, not refused,
97
+ and the envelope echoes the size applied, so `useIssues` pages by the echo
98
+ and never by the number it asked for.
99
+ - `muted_until` belongs to the muted status: a patch of the deadline alone
100
+ mutes, and every transition out of `muted` clears it, so a non-muted row
101
+ never carries a deadline and the detail draws one only while muted.
102
+
103
+ ## Staff-only, and it says so
104
+
105
+ Every tracker route is `IsStaffUser`. The nav axis has two values
106
+ (`public` | `member`) and cannot say "staff", so the SCREEN says it: the door
107
+ stays visible and the pane names the refusal (`isAlertsStaffOnly`) instead of
108
+ drawing an empty triage table. A hidden door teaches nobody anything; an empty
109
+ board teaches the wrong thing — *nothing is broken* is the one sentence an
110
+ error tracker must never say by accident. A 401 is a different sentence again
111
+ ("sign in"), because the raw conditional reads do not run core's bearer-refresh
112
+ retry.
113
+
114
+ ## The default skin
115
+
116
+ `@stapel/alerts-react/default` ships `IssuesFeed`, `IssueDetail`,
117
+ `IssueFilterBar`, `FixIssueDialog` and `MuteIssueDialog` on antd through
118
+ `@stapel/tokens-antd/skin` — tokens only, no raw colours, every string an i18n
119
+ key. Import the subpath to opt in; the main entry pulls no antd at all.
120
+
121
+ ## i18n
122
+
123
+ ```tsx
124
+ import { registerAlertsI18n } from "@stapel/alerts-react";
125
+ import { registerAlertsI18nRu } from "@stapel/alerts-react/i18n/ru";
126
+ ```
127
+
128
+ `en` ships in the main entry (backend error codes included); `ru` and `es` are
129
+ opt-in subpaths, and every backend code is covered in all three: stapel-alerts
130
+ 0.2.0 ships `translations/errors.{ru,es}.json` for the six keys it owns, merged
131
+ over stapel-core's catalogue by `gen:errors` exactly as the backend loader
132
+ merges them at runtime. Nothing here hand-authors a backend refusal.
133
+
134
+ ## Navigation
135
+
136
+ Two entries under the container-owned `admin.root`: `admin.alerts` (the board)
137
+ and `admin.alerts-issue` (`:issueId`, a route and not a menu item — nobody
138
+ navigates to one bug from a menu; they arrive from a row or from an
139
+ `alerts:<issue-id>` reference in a commit message, which is why the id is
140
+ stable).
141
+
142
+ ---
143
+
144
+ - Module guide: [MODULE.md](./MODULE.md) · Agent context:
145
+ [llms.txt](./llms.txt) · Machine catalog:
146
+ [manifest.json](./manifest.json)
147
+ - [CHANGELOG.md](./CHANGELOG.md) · MIT
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The pair's analytics vocabulary.
3
+ *
4
+ * Three events, and every one of them is a JUDGEMENT an operator made about a
5
+ * live bug — this is fixed, by this release; this is known and I do not want
6
+ * to hear about it until Monday; this is back, reopen it. Reading the feed is
7
+ * not on the list: it happens whenever the tab is open and reports nothing
8
+ * about what anyone decided.
9
+ *
10
+ * The names are constants rather than `defineEvent` declarations because a
11
+ * pair carries no `@stapel/analytics` runtime by architecture (slim wave
12
+ * §21/S1): it emits through the `Analytics` SEAM the host injects.
13
+ *
14
+ * **Nothing here carries an issue id, a title, a trace or a service name.** A
15
+ * fingerprint plus a culprit is a map of where a system is weakest, and a
16
+ * product-analytics stream is not where that belongs. `level` is the whole
17
+ * payload — enough to answer "are operators closing fatals or debug noise",
18
+ * which is the only question this data is for.
19
+ */
20
+ export declare const ALERTS_EVENTS: {
21
+ /** An issue was closed with a release. Prop: `level`. */
22
+ readonly issueFixed: "alerts.issue.fixed";
23
+ /** An issue was muted. Props: `level`, `hasDeadline`. */
24
+ readonly issueMuted: "alerts.issue.muted";
25
+ /** An issue was put back on the board. Prop: `level`. */
26
+ readonly issueReopened: "alerts.issue.reopened";
27
+ };
28
+ export type AlertsEventName = (typeof ALERTS_EVENTS)[keyof typeof ALERTS_EVENTS];
29
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/analytics/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa;IACxB,yDAAyD;;IAEzD,yDAAyD;;IAEzD,yDAAyD;;CAEjD,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The pair's analytics vocabulary.
3
+ *
4
+ * Three events, and every one of them is a JUDGEMENT an operator made about a
5
+ * live bug — this is fixed, by this release; this is known and I do not want
6
+ * to hear about it until Monday; this is back, reopen it. Reading the feed is
7
+ * not on the list: it happens whenever the tab is open and reports nothing
8
+ * about what anyone decided.
9
+ *
10
+ * The names are constants rather than `defineEvent` declarations because a
11
+ * pair carries no `@stapel/analytics` runtime by architecture (slim wave
12
+ * §21/S1): it emits through the `Analytics` SEAM the host injects.
13
+ *
14
+ * **Nothing here carries an issue id, a title, a trace or a service name.** A
15
+ * fingerprint plus a culprit is a map of where a system is weakest, and a
16
+ * product-analytics stream is not where that belongs. `level` is the whole
17
+ * payload — enough to answer "are operators closing fatals or debug noise",
18
+ * which is the only question this data is for.
19
+ */
20
+ export const ALERTS_EVENTS = {
21
+ /** An issue was closed with a release. Prop: `level`. */
22
+ issueFixed: "alerts.issue.fixed",
23
+ /** An issue was muted. Props: `level`, `hasDeadline`. */
24
+ issueMuted: "alerts.issue.muted",
25
+ /** An issue was put back on the board. Prop: `level`. */
26
+ issueReopened: "alerts.issue.reopened",
27
+ };
28
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/analytics/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,yDAAyD;IACzD,UAAU,EAAE,oBAAoB;IAChC,yDAAyD;IACzD,UAAU,EAAE,oBAAoB;IAChC,yDAAyD;IACzD,aAAa,EAAE,uBAAuB;CAC9B,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { StapelClient } from "@stapel/core";
2
+ import type { Issue, IssueDetail, IssueFix, IssueLevel, IssuePage, IssuePatch, IssueStatus } from "./types.js";
3
+ /** Query for `GET /issues` — every parameter `IssueListView` reads. */
4
+ export interface IssueFilters {
5
+ readonly status?: IssueStatus;
6
+ readonly level?: IssueLevel;
7
+ /** The reporting service's name, exactly as the tracker stores it. */
8
+ readonly service?: string;
9
+ /** ISO-8601; `last_seen >= since`. */
10
+ readonly since?: string;
11
+ /** Only `new` + `regressed` — the module's own definition of open. */
12
+ readonly open?: boolean;
13
+ /** Row offset; default 0. */
14
+ readonly offset?: number;
15
+ /**
16
+ * Page size, 1..200; the server's default (50) when omitted. Out-of-range
17
+ * values are CLAMPED, not refused, and the envelope echoes the size that was
18
+ * applied — page by `IssuePage.limit`, never by this number.
19
+ */
20
+ readonly limit?: number;
21
+ }
22
+ /**
23
+ * The answer to a conditional read.
24
+ *
25
+ * `"unchanged"` is a RESULT, not an error and not an absence: the server
26
+ * confirmed the rows on screen are current. A caller that folded it into
27
+ * `undefined` would blank a triage table every time nothing had happened,
28
+ * which is most of the time.
29
+ */
30
+ export type ConditionalRead<T> = {
31
+ readonly outcome: "modified";
32
+ /** The validator to send next time. `null` if the server sent none. */
33
+ readonly etag: string | null;
34
+ readonly data: T;
35
+ } | {
36
+ readonly outcome: "unchanged";
37
+ readonly etag: string;
38
+ };
39
+ /** Per-read options: the validator to offer, and the abort signal. */
40
+ export interface ConditionalReadOptions {
41
+ /** The `ETag` from the previous read of this exact query, if any. */
42
+ readonly etag?: string | null | undefined;
43
+ readonly signal?: AbortSignal | undefined;
44
+ }
45
+ export interface AlertsApi {
46
+ readonly client: StapelClient;
47
+ /**
48
+ * The triage list, newest activity first.
49
+ *
50
+ * Answers a PAGE — `{count, offset, limit, results}`, the `IssuePage` the
51
+ * schema declares (`api/types.ts`).
52
+ */
53
+ issues(filters?: IssueFilters, options?: ConditionalReadOptions): Promise<ConditionalRead<IssuePage>>;
54
+ /** One issue with its last 20 events, their traces and their context. */
55
+ issue(issueId: string, options?: ConditionalReadOptions): Promise<ConditionalRead<IssueDetail>>;
56
+ /**
57
+ * Set a status a caller is allowed to assert, and/or leave a note.
58
+ *
59
+ * **`muted_until` on its own is a mute.** The field has no meaning in any
60
+ * other status, so a patch carrying only the deadline sets `status: "muted"`
61
+ * (`null` for a mute with no deadline), and any status other than `muted`
62
+ * ignores and CLEARS it — a deadline leaves with the mute. Omitting the key
63
+ * is not a mute at all, so `model/status.ts` always sends it.
64
+ */
65
+ patchIssue(issueId: string, patch: IssuePatch): Promise<Issue>;
66
+ /**
67
+ * Close an issue with the release that claims the fix.
68
+ *
69
+ * Idempotent by design: fixing a fixed issue overwrites the version, which
70
+ * is what re-deploying a better fix should do. Zeroes `count_since_fix`, so
71
+ * "has anything happened since?" stays a column rather than a query over
72
+ * events retention may already have swept.
73
+ */
74
+ fixIssue(issueId: string, fix: IssueFix): Promise<Issue>;
75
+ }
76
+ /** The raw-transport knobs `createAlertsRuntime` forwards (see the header). */
77
+ export interface AlertsRawOptions {
78
+ readonly fetch?: typeof globalThis.fetch;
79
+ readonly credentials?: RequestCredentials;
80
+ /** Merged into every raw read (a tenant id, a bearer header). */
81
+ readonly defaultHeaders?: Record<string, string>;
82
+ }
83
+ export declare function createAlertsApi(client: StapelClient, raw?: AlertsRawOptions): AlertsApi;
84
+ //# sourceMappingURL=alertsApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alertsApi.d.ts","sourceRoot":"","sources":["../../src/api/alertsApi.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IACzB;IACE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB,GACD;IACE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEN,sEAAsE;AACtE,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B;;;;;OAKG;IACH,MAAM,CACJ,OAAO,CAAC,EAAE,YAAY,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;IAEvC,yEAAyE;IACzE,KAAK,CACH,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC;IAEzC;;;;;;;;OAQG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAE/D;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;CAC1D;AAED,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAC1C,iEAAiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD;AA4ED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,YAAY,EACpB,GAAG,GAAE,gBAAqB,GACzB,SAAS,CAiCX"}