@aria-framework/notify 0.6.0 → 0.7.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # @aria-framework/notify
2
+
3
+ Older releases are recorded in the README's "Upgrading to …" sections; this file starts at 0.7.0.
4
+
5
+ ## 0.7.1 — 2026-11-16
6
+
7
+ **Fix: "Live updates paused. Refresh to see changes." no longer stays on screen after the stream reconnects.**
8
+ The strip carries Bootstrap's `d-flex` (`display:flex !important`), which beats the `hidden` attribute (reboot's
9
+ `[hidden]{display:none!important}` comes first at the same specificity). 0.7.0 hid it with `strip.hidden = true` only,
10
+ so after ANY momentary drop (the hub sign-in cutting streams at 30 minutes, a network blip) the strip stayed visible
11
+ for good while the regions were live again; the tests read the attribute, not what is displayed.
12
+
13
+ - `live.js` hides the strip (and the "N new" bar) with `hidden` AND Bootstrap's `d-none`, and shows it by removing both.
14
+ - `bell.css` adds `.live-strip[hidden], .live-newbar[hidden] { display:none !important }` — two selectors' worth of
15
+ specificity, so it wins over `.d-flex` in any order and without depending on the host's CSS framework.
16
+ - **New, additive:** the strip carries `data-live-reason` — `down` (the stream dropped) or the live-stop's reason
17
+ (`too_many`, `evicted`, `off`, …) — and drops it when hidden. The words are unchanged.
18
+ - Tests (`test/live-client.js`) now read the strip's COMPUTED display under Bootstrap 5.3.3's own rules: down → shown
19
+ (flex), reopen → not displayed and undimmed, live-stop → shown and stays; each mechanism alone. jsdom settles two
20
+ `!important` declarations by order, not specificity, so the bell.css rule's specificity is asserted structurally.
21
+
22
+ No app code changes: bump `@aria-framework/notify` to `^0.7.1` and refresh the lockfile.
23
+
24
+ ## 0.7.0 — 2026-11-04
25
+
26
+ Carries 0.6.0 (per-audience stream caps), which was merged but never published: **publish 0.7.0 only**.
27
+
28
+ **Every app's bell changes, with no code change on the app's side:**
29
+
30
+ - **The time is short and sits on the right of the title**: `now`, `3m`, `2h`, `1d` — no longer
31
+ `just now`, `3m ago`, `2h ago`, `1d ago` on a line of its own.
32
+ - **`body` now shows in the bell**: whitespace collapsed, one line, cut with an ellipsis, under the
33
+ title. Before 0.7.0 the bell never showed `body`. An app that stores something in `body` it does
34
+ not want in the dropdown should check what it writes there.
35
+ - **`context` shows when the app's `/recent` items carry it** (one line, cut with an ellipsis).
36
+ - **A click marks the row read at once** (class, badge −1, regroup), POSTs `/:id/read` with
37
+ `keepalive`, then re-syncs. A link to the page already open hides the dropdown and fires
38
+ `aria:notif-goto` `{ href }` on `document` — not for a ctrl / cmd / shift / alt or non-primary
39
+ click, which opens elsewhere (the row is still marked read).
40
+ - **Security: the row href guard is now an origin check.** "Starts with one slash" let `/\evil.com`,
41
+ `/<TAB>/evil.com` and `/<LF>/evil.com` through, and browsers resolve all three to `//evil.com`. A
42
+ link must now hold no control character, space or backslash and must resolve to the page's own
43
+ origin; anything else becomes the notifications page. (The weakness predates 0.7.0.)
44
+
45
+ **Store (additive):**
46
+
47
+ - `createMany` also returns `rows: [{ userId, id }]`, in `userIds` order.
48
+ - `extendUnread(id, userId, { appendTitle, sep = ', ', at })` grows an unread row's title and
49
+ moves its time (owner- and unread-guarded, one statement). `TITLE_MAX` = 500 characters: past it,
50
+ nothing changes and the answer is `false`. `at` (UTC text, `YYYY-MM-DD HH:MM:SS`) is for a test's
51
+ clock; the default is the database's.
52
+
53
+ **Pin `^0.7.0`.** An app that calls `extendUnread`, reads `rows`, listens for `aria:notif-goto` or
54
+ passes `context` needs 0.7.0; under a `^0.6.0` or older range it can resolve to a version without
55
+ them, and the bell then silently does none of it.
package/README.md CHANGED
@@ -50,6 +50,25 @@ the same answer as an id that does not exist, so it leaks nothing either. There
50
50
  permission check to forget, and **moving that scope to a caller-side `if` would be a silent
51
51
  privilege escalation rather than a visible break.** Read it as a constraint on future edits.
52
52
 
53
+ ### Growing an unread row (0.7.0)
54
+
55
+ `createMany` returns `{ userIds, rows: [{ userId, id }] }` — each recipient's new row id, so a
56
+ caller can find its row again without reading it back (`userIds` is unchanged).
57
+
58
+ `extendUnread(id, userId, { appendTitle, sep = ', ', at })` appends to that row's title and moves its
59
+ `created_at` to now — "changed status to open" becomes "changed status to open, changed priority
60
+ from medium to high". It is one `UPDATE … WHERE id = ? AND user_id = ? AND is_read = 0`: scoped
61
+ like everything else, and a row its reader has already seen is never rewritten. It returns `true`
62
+ when the row changed and `false` otherwise (not yours, read, gone, nothing to append, or too long).
63
+ `at` (optional, UTC text `YYYY-MM-DD HH:MM:SS`) sets the new time for a test's clock; without it
64
+ the database's clock is used. A malformed `at` throws.
65
+
66
+ **The title is capped at `TITLE_MAX` = 500 characters** (exported). When the grown title would be
67
+ longer, nothing changes and the answer is `false` — the same as for a read row, so a caller's one
68
+ fallback ("write a new row for the follow-up") covers both. It never cuts a title. Which rows to
69
+ grow, and when to stop, is the app's rule (the desk's: field changes by one person on one ticket
70
+ inside its 2-minute email hold).
71
+
53
72
  ## Two channels
54
73
 
55
74
  - **users** — "tell these RECIPIENTS something happened". The bell.
@@ -129,8 +148,46 @@ has:
129
148
  <a class="list-group-item notif-row is-read" href="…">…</a>
130
149
  ```
131
150
 
132
- Colours come from @aria-framework/theme's tokens (`--brand-rgb`, `--text`, `--text-faint`), with
133
- Bootstrap's variables as the fallback.
151
+ Colours come from @aria-framework/theme's tokens (`--brand-rgb`, `--text`, `--text-soft`,
152
+ `--text-faint`, `--font-mono`), with Bootstrap's variables as the fallback.
153
+
154
+ ### A row's lines (0.7.0)
155
+
156
+ | line | from | shape |
157
+ |---|---|---|
158
+ | `.notif-head` | `.notif-line` (`.notif-who` = `actor_name`, `.notif-what` = `title`) and `.notif-time` | the title at most two lines; the time on the right, short: `now`, `3m`, `2h`, `1d` |
159
+ | `.notif-context` | `item.context`, when present | one line, cut with … |
160
+ | `.notif-body` | `item.body`, whitespace collapsed | one line, cut with …; no line when empty |
161
+
162
+ `context` is not a stored column: an app adds it to the items its `/recent` route returns (the
163
+ desk: `"<tracking id> · <subject>"` for a ticket row, read at render so a renamed subject shows
164
+ its new name). Everything is set with `textContent`, so neither line can carry markup.
165
+ `.notif-who` / `.notif-what` keep their names because an app's decorator may read them. An app
166
+ that wraps a row's children in its own flex box (the desk's avatars) must give that wrapper
167
+ `min-width: 0`, or the ellipsis never engages. A wider bell is the include's `notifWidth`
168
+ (default still `340px`; the desk passes `420px`).
169
+
170
+ ### Clicking a row (0.7.0)
171
+
172
+ An unread row turns read **at once**: `is-unread` → `is-read`, the badge drops by one, and the
173
+ list regroups (New → Earlier). Then `POST /:id/read`, then a re-sync for the server's word.
174
+
175
+ When the row links to the page already open (same path and query; only the hash may differ —
176
+ `/tickets/7#msg-3` on `/tickets/7`), the dropdown is hidden (Bootstrap's instance on the toggle,
177
+ when there is one) and the document receives the event below. A ctrl / cmd / shift / alt or
178
+ non-primary click opens elsewhere, so it does neither (the row is still marked read). The read
179
+ POST is sent with `keepalive`, so a click that navigates away does not cancel it.
180
+
181
+ ```js
182
+ document.addEventListener('aria:notif-goto', (e) => scrollToMessage(e.detail.href));
183
+ ```
184
+
185
+ That event is the page's only signal for a click on the hash it already has, which fires no
186
+ `hashchange`. Read the target from `detail.href`, not `location.hash`. A page that also listens
187
+ for `hashchange` may see both for a new hash; scrolling twice to one target is harmless.
188
+
189
+ Before 0.7.0 the click only POSTed. On a hash jump nothing reloaded, the server sends no frame
190
+ on read, and `data-bs-auto-close="outside"` kept the menu open — the row stayed under New.
134
191
 
135
192
  ## Live pages (0.5.0)
136
193
 
@@ -190,7 +247,9 @@ sit on the row or its first cell): with `data-live-insert` (draw it on page 1, d
190
247
  ticked, new rows are put in and marked New; otherwise a bar says "N new. Show them". Every reconnect catches every
191
248
  region up once (there is no replay). When the stream drops or is stopped, a strip says "Live updates paused" with a
192
249
  Refresh button — or, when the app refused the topics with the reason `off` (0.5.1: its installation-wide switch),
193
- "Live updates are off". Frames that arrive after this page submitted a form are ignored (the mid-navigation trap above)
250
+ "Live updates are off". The strip carries `data-live-reason` (0.7.1: `down`, or the stop's reason) and clears on the
251
+ next open; it is hidden with `hidden` AND `d-none`, and bell.css (linked by the bell partial) keeps
252
+ `.live-strip[hidden]` undisplayed, because Bootstrap's `.d-flex` beats the bare attribute. Frames that arrive after this page submitted a form are ignored (the mid-navigation trap above)
194
253
  until the page navigates — or, for a submit that does not (a download, `target=_blank`), until it is visible again
195
254
  or 8 s pass; a submit a script prevented is not a navigation.
196
255
 
@@ -258,3 +317,22 @@ stream of it is refused `busy`, exactly as a derived 0 is.
258
317
  are all refused there; give it an explicit `perAudience` or a larger `perProcess` before passing `'contact'`.
259
318
  - **A hub that names its own audiences** must keep their caps (with the default contact one) below `perProcess`, or
260
319
  `createHub` throws at boot.
320
+
321
+ ### Upgrading to 0.7.0
322
+
323
+ - **0.7.0 carries 0.6.0**, which was merged but never published: publish 0.7.0 only. It stands as
324
+ its own minor rather than folding into 0.6.0 because it adds API (`extendUnread`, `TITLE_MAX`,
325
+ `createMany`'s `rows`) and changes the bell's look, while the repo's todo.md already names 0.6.0
326
+ for the audience caps alone; reusing the number would change what it means. The hub's pending
327
+ `audience: 'contact'` change needs 0.6.0's code, which 0.7.0 has.
328
+ - **Nothing is required of a caller.** `createMany`'s `userIds` is unchanged; `rows` is new.
329
+ - **Every app's bell looks different without a code change**: the time reads `now` / `3m` / `1d`
330
+ (not `just now` / `3m ago`), and a row's `body` now shows under the title. CHANGELOG.md has the
331
+ list, including the href guard's fix (`/\evil.com` and friends). **Pin `^0.7.0`** in an app that
332
+ uses any of the new API or `aria:notif-goto`.
333
+ - **The bell's row changed shape**: `.notif-what` now sits in `.notif-head > .notif-line` with
334
+ `.notif-time` beside it, where it used to be a plain `div.small` followed by a time `div`. An
335
+ app's CSS or script that reached into the old shape by position (not by `.notif-who` /
336
+ `.notif-what`) should be checked. The time reads `1d`, not `1d ago`.
337
+ - **An app that wants the ticket line** adds `context` to the items `/recent` returns; without it
338
+ the row is as before plus the body's first line.
package/assets/bell.css CHANGED
@@ -15,6 +15,11 @@
15
15
  * .notif-row.is-unread tint + edge + dot + strong text
16
16
  * .notif-row.is-read faded text
17
17
  * .notif-section the "New" / "Earlier" label; .notif-section-count is the pill on "New"
18
+ *
19
+ * The row's lines (0.7.0): .notif-head holds .notif-line (who + what, at most two lines) and
20
+ * .notif-time ("1d", on the right); then .notif-context and .notif-body, ONE line each, cut with
21
+ * an ellipsis. An app that wraps the row's children in a flex box (an avatar decorator) must give
22
+ * that wrapper min-width:0, or the ellipsis never engages — direct div children get it here.
18
23
  */
19
24
  .notif-row{
20
25
  position:relative;
@@ -68,7 +73,26 @@
68
73
  letter-spacing:0;
69
74
  }
70
75
 
76
+ /* ── The row's lines (0.7.0) ───────────────────────────────────────────────────────────────── */
77
+ .notif-row > div{min-width:0;}
78
+ .notif-head{display:flex;justify-content:space-between;align-items:baseline;gap:.5rem;}
79
+ .notif-line{min-width:0;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden;}
80
+ .notif-time{flex:0 0 auto;white-space:nowrap;font-size:.72rem;color:var(--text-faint, var(--bs-secondary-color));}
81
+ .notif-context,
82
+ .notif-body{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:.15rem;
83
+ color:var(--text-soft, var(--bs-secondary-color));}
84
+ .notif-context{font-family:var(--font-mono, var(--bs-font-monospace));font-size:.72rem;}
85
+ .notif-body{font-size:.8rem;}
86
+ .notif-row.is-read .notif-context,
87
+ .notif-row.is-read .notif-body{color:var(--text-faint, var(--bs-secondary-color));}
88
+
71
89
  /* ── Live page regions (assets/live.js, 0.5.0) ─────────────────────────────────────────────── */
90
+ /* 0.7.1: a hidden strip or bar is NOT displayed, whatever the host's CSS. Both carry Bootstrap's .d-flex
91
+ * (display:flex !important), which beats the [hidden] attribute (reboot's rule comes first at the same
92
+ * specificity), so 0.7.0's "Live updates paused" strip stayed on screen after every reconnect. Two classes'
93
+ * worth of specificity outranks .d-flex in any order; live.js also toggles .d-none. */
94
+ .live-strip[hidden],
95
+ .live-newbar[hidden]{display:none !important;}
72
96
  .live-paused{opacity:.6;transition:opacity .2s;}
73
97
  .live-new{background:rgba(var(--brand-rgb, var(--bs-primary-rgb)), .07);transition:background 2s;}
74
98
  .live-new-pill{display:inline-block;margin-right:.4em;padding:0 .45em;border-radius:1em;font-size:.72em;font-weight:600;
package/assets/bell.js CHANGED
@@ -20,6 +20,14 @@
20
20
  * refreshes belong on reconnect only (firstOpen === false), because the first
21
21
  * open lands right after the page rendered.
22
22
  *
23
+ * And one this file raises itself (0.7.0):
24
+ * 'aria:notif-goto' detail = { href } — a bell row was clicked whose link is THIS page (path and
25
+ * query equal; only the hash may differ). The dropdown is hidden and the row
26
+ * marked read in place; the page scrolls to / highlights the target. Read the
27
+ * target from detail.href, not location.hash: the event fires a task after the
28
+ * click, and whether the hash has moved by then is the browser's business. Needed
29
+ * because a click on the hash the page already has fires no 'hashchange'.
30
+ *
23
31
  * Frame types listed in data-notif-quiet (comma-separated, e.g. "ticket,draft") do NOT re-sync
24
32
  * the bell — a ticket reply cannot change the notification list, and draft frames fire while
25
33
  * somebody is typing. Extra stream query params come from any page element carrying
@@ -40,8 +48,11 @@
40
48
  * A dropped stream is announced as 'aria:sse-down' (assets/live.js shows "Live updates paused").
41
49
  *
42
50
  * XSS-safe by construction: rows are createElement/textContent, and only a same-origin PATH may
43
- * become a row's href — a link that ever carried attacker-influenced text (javascript: or
44
- * //host) would execute or leave the site on click.
51
+ * become a row's href — a link that ever carried attacker-influenced text would otherwise execute
52
+ * (javascript:) or leave the site on click. "Starts with one slash" is NOT that test: browsers
53
+ * read a backslash as a slash and drop tab/CR/LF while parsing, so /\evil.com, /<TAB>/evil.com
54
+ * and /<LF>/evil.com are all //evil.com. 0.7.0: the raw link may hold no control character,
55
+ * space or backslash, and it must RESOLVE to this page's origin.
45
56
  */
46
57
  (function () {
47
58
  'use strict';
@@ -73,8 +84,11 @@
73
84
  var tokenMeta = document.querySelector('meta[name="csrf-token"]');
74
85
  var csrf = tokenMeta ? tokenMeta.getAttribute('content') : '';
75
86
 
76
- function post(url) {
77
- return fetch(url, { method: 'POST', headers: { 'x-csrf-token': csrf }, credentials: 'same-origin' });
87
+ /** keepalive (the read POST): a click that navigates away must not cancel the request. */
88
+ function post(url, keepalive) {
89
+ var o = { method: 'POST', headers: { 'x-csrf-token': csrf }, credentials: 'same-origin' };
90
+ if (keepalive) o.keepalive = true;
91
+ return fetch(url, o);
78
92
  }
79
93
 
80
94
  function setBadge(n) {
@@ -83,21 +97,58 @@
83
97
  }
84
98
 
85
99
  function safeHref(link) {
86
- return (typeof link === 'string' && /^\/(?!\/)/.test(link)) ? link : BASE;
100
+ if (typeof link !== 'string' || !/^\/(?!\/)/.test(link) || /[\x00-\x20\\]/.test(link)) return BASE;
101
+ try {
102
+ if (new URL(link, location.origin).origin !== location.origin) return BASE;
103
+ } catch (_) { return BASE; }
104
+ return link;
87
105
  }
88
106
 
89
- /** "3m ago" over SQLite's UTC datetime('now') strings — the trailing Z is load-bearing. */
107
+ /**
108
+ * "3m" over SQLite's UTC datetime('now') strings — the trailing Z is load-bearing. Short form
109
+ * since 0.7.0: it sits to the right of the title, so "now" / "3m" / "2h" / "1d".
110
+ */
90
111
  function relTime(iso) {
91
112
  if (!iso) return '';
92
113
  var t = Date.parse(String(iso).includes('T') ? iso : String(iso).replace(' ', 'T') + 'Z');
93
114
  if (!Number.isFinite(t)) return '';
94
115
  var s = Math.max(0, (Date.now() - t) / 1000);
95
- if (s < 60) return 'just now';
96
- if (s < 3600) return Math.floor(s / 60) + 'm ago';
97
- if (s < 86400) return Math.floor(s / 3600) + 'h ago';
98
- return Math.floor(s / 86400) + 'd ago';
116
+ if (s < 60) return 'now';
117
+ if (s < 3600) return Math.floor(s / 60) + 'm';
118
+ if (s < 86400) return Math.floor(s / 3600) + 'h';
119
+ return Math.floor(s / 86400) + 'd';
120
+ }
121
+
122
+ /** One line of text: whitespace (newlines included) collapsed, trimmed, bounded. '' when empty. */
123
+ function oneLine(v) {
124
+ if (v == null) return '';
125
+ return String(v).replace(/\s+/g, ' ').trim().slice(0, 300);
126
+ }
127
+
128
+ function line(cls, text) {
129
+ var el = document.createElement('div');
130
+ el.className = cls;
131
+ el.textContent = text;
132
+ return el;
99
133
  }
100
134
 
135
+ var current = null; // the last list rendered — a click marks its item read and re-renders
136
+
137
+ /** The dropdown, hidden — only when Bootstrap is there and owns an instance for the toggle. */
138
+ function hideMenu() {
139
+ var toggle = menu.querySelector('[data-bs-toggle="dropdown"]');
140
+ var bs = window.bootstrap;
141
+ var inst = toggle && bs && bs.Dropdown && bs.Dropdown.getInstance ? bs.Dropdown.getInstance(toggle) : null;
142
+ if (inst) inst.hide();
143
+ }
144
+
145
+ /**
146
+ * Row shape (0.7.0):
147
+ * .notif-head .notif-line (.notif-who actor, .notif-what title) | .notif-time "1d"
148
+ * .notif-context item.context — one line, cut with an ellipsis (an app's "TBL-4821 · subject")
149
+ * .notif-body item.body, whitespace collapsed — one line, cut; absent when there is none
150
+ * .notif-who / .notif-what keep their names: an app's decorator may read them.
151
+ */
101
152
  function row(item) {
102
153
  var a = document.createElement('a');
103
154
  a.href = safeHref(item.link);
@@ -105,8 +156,10 @@
105
156
  // that remaps .bg-light in dark mode made the tint the dropdown's own colour.
106
157
  a.className = 'dropdown-item py-2 border-bottom notif-row ' + (item.is_read ? 'is-read' : 'is-unread');
107
158
 
159
+ var head = document.createElement('div');
160
+ head.className = 'notif-head';
108
161
  var top = document.createElement('div');
109
- top.className = 'small';
162
+ top.className = 'small notif-line';
110
163
  if (item.actor_name) {
111
164
  var who = document.createElement('span');
112
165
  who.className = 'notif-who';
@@ -117,21 +170,52 @@
117
170
  what.className = 'notif-what';
118
171
  what.textContent = item.title || '';
119
172
  top.appendChild(what);
120
- a.appendChild(top);
173
+ head.appendChild(top);
174
+ var when = document.createElement('span');
175
+ when.className = 'notif-time';
176
+ when.textContent = relTime(item.created_at);
177
+ head.appendChild(when);
178
+ a.appendChild(head);
121
179
 
122
- var meta = document.createElement('div');
123
- meta.className = 'text-muted';
124
- meta.style.fontSize = '0.72rem';
125
- meta.textContent = relTime(item.created_at);
126
- a.appendChild(meta);
180
+ var context = oneLine(item.context);
181
+ if (context) a.appendChild(line('notif-context', context));
182
+ var body = oneLine(item.body);
183
+ if (body) a.appendChild(line('notif-body', body));
127
184
 
128
- a.addEventListener('click', function () {
129
- if (!item.is_read) { post(BASE + '/' + item.id + '/read'); } // navigation continues
185
+ a.addEventListener('click', function (ev) {
186
+ if (!item.is_read) {
187
+ // At once, in the list: the server sends no frame on read, and a link to the page already
188
+ // open (/tickets/7#msg-3) is a hash jump — no reload — so without this the row stays
189
+ // under New. Then the POST, then a sync for the server's own word.
190
+ item.is_read = 1;
191
+ a.classList.remove('is-unread');
192
+ a.classList.add('is-read');
193
+ if (current) {
194
+ current.unread = Math.max(0, (Number(current.unread) || 0) - 1);
195
+ setBadge(current.unread);
196
+ }
197
+ post(BASE + '/' + item.id + '/read', true).then(sync).catch(function () {});
198
+ }
199
+ // A modified or non-primary click opens a new tab or window (or downloads): this page stays
200
+ // where it is, so the menu stays open and the page is not told to jump. Read still applies.
201
+ var plain = !(ev && (ev.ctrlKey || ev.metaKey || ev.shiftKey || ev.altKey || ev.button));
202
+ var samePage = plain && a.pathname === location.pathname && a.search === location.search;
203
+ if (samePage) hideMenu();
204
+ // A task later (navigation continues; the clicked element must still be in the list while
205
+ // the browser follows it): regroup the list, and tell the page which link was followed.
206
+ // A same-hash click fires no hashchange, so 'aria:notif-goto' is the page's only signal.
207
+ setTimeout(function () {
208
+ if (current) render(current);
209
+ if (samePage) {
210
+ document.dispatchEvent(new CustomEvent('aria:notif-goto', { detail: { href: a.getAttribute('href') } }));
211
+ }
212
+ }, 0);
130
213
  });
131
214
  return a;
132
215
  }
133
216
 
134
217
  function render(data) {
218
+ current = data;
135
219
  setBadge(data.unread || 0);
136
220
  list.textContent = '';
137
221
  if (!data.items || !data.items.length) {
package/assets/live.js CHANGED
@@ -97,13 +97,27 @@
97
97
  : (reason === 'too_many' || reason === 'evicted')
98
98
  ? 'Live updates paused: too many open tabs. Close one and refresh, or refresh to see changes.'
99
99
  : 'Live updates paused. Refresh to see changes.';
100
- strip.hidden = false;
100
+ // data-live-reason (0.7.1): the reason word — 'down', or the live-stop's own (too_many, evicted, off, …) — for
101
+ // styling or a test; the words above are unchanged.
102
+ strip.setAttribute('data-live-reason', reason || 'down');
103
+ setShown(strip, true);
101
104
  REGIONS.forEach(function (r) { r.classList.add('live-paused'); });
102
105
  }
103
106
  function clearStrip() {
104
- if (strip) strip.hidden = true;
107
+ if (strip) { setShown(strip, false); strip.removeAttribute('data-live-reason'); }
105
108
  REGIONS.forEach(function (r) { r.classList.remove('live-paused'); });
106
109
  }
110
+ /**
111
+ * SHOW OR HIDE an element that carries a Bootstrap display utility (0.7.1). The `hidden` attribute alone does not
112
+ * hide it: Bootstrap 5.3's `.d-flex{display:flex!important}` comes after reboot's `[hidden]{display:none!important}`
113
+ * at the same specificity, so it wins, and 0.7.0's strip stayed on screen after every reconnect. So: `hidden` (what
114
+ * assistive tech reads) AND `d-none` (Bootstrap's own `display:none!important`, later than `.d-flex` in its sheet),
115
+ * with bell.css's `.live-strip[hidden]` rule as the guard that does not depend on Bootstrap's order.
116
+ */
117
+ function setShown(el, on) {
118
+ el.hidden = !on;
119
+ el.classList.toggle('d-none', !on);
120
+ }
107
121
 
108
122
  // ── Re-fetch and swap ─────────────────────────────────────────────────────────────────────
109
123
  /**
@@ -196,7 +210,7 @@
196
210
  if (bar.parentNode) bar.parentNode.removeChild(bar);
197
211
  };
198
212
  bar.__fresh = fresh;
199
- bar.hidden = false;
213
+ setShown(bar, true);
200
214
  }
201
215
 
202
216
  /** Replace `el` by `fresh`, marking rows `fresh` has that `el` had not. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aria-framework/notify",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Aria App Framework — notify module. In-app notifications: ownership-scoped rows, a per-process SSE hub for live delivery (with topics, caps per session, user, audience and process, and a per-event authorise hook for live pages), and a fire-and-forget emitter that needs no request and no actor, so a scheduler can raise one.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -14,7 +14,8 @@
14
14
  "hub.js",
15
15
  "emit.js",
16
16
  "assets/",
17
- "views/"
17
+ "views/",
18
+ "CHANGELOG.md"
18
19
  ],
19
20
  "peerDependencies": {
20
21
  "better-sqlite3": ">=11"
@@ -28,7 +29,7 @@
28
29
  "jsdom": "^30.0.1"
29
30
  },
30
31
  "scripts": {
31
- "test": "node test/store.js && node test/schema-parity.js && node test/hub.js && node test/live-hub.js && node test/emit.js && node test/bell.js && node test/live-client.js",
32
+ "test": "node test/store.js && node test/schema-parity.js && node test/hub.js && node test/live-hub.js && node test/emit.js && node test/bell.js && node test/bell-rows.js && node test/live-client.js",
32
33
  "prepublishOnly": "node ../../test/packaging.js notify"
33
34
  }
34
35
  }
package/store.js CHANGED
@@ -60,6 +60,9 @@ function schemaFor(dialect) {
60
60
  /** The SQLite schema, unchanged, for consumers that predate schemaFor(). */
61
61
  const SCHEMA = schemaFor(null);
62
62
 
63
+ /** The longest title extendUnread() will make (characters). Longer: it changes nothing. */
64
+ const TITLE_MAX = 500;
65
+
63
66
  /**
64
67
  * @param {Function} getDb returns the better-sqlite3 handle. A function, not a handle, because
65
68
  * the worker opens the database after modules are required.
@@ -108,6 +111,7 @@ function createStore(opts = {}) {
108
111
  return {
109
112
  SCHEMA,
110
113
  schemaFor,
114
+ TITLE_MAX,
111
115
  table: T,
112
116
 
113
117
  /**
@@ -116,25 +120,72 @@ function createStore(opts = {}) {
116
120
  * Returns the ids actually written so the caller can hand them to the hub. De-duplicated,
117
121
  * because "the assignee" and "a collaborator" are frequently the same person and two bells
118
122
  * for one event reads as a bug.
123
+ *
124
+ * 0.7.0: also `rows: [{ userId, id }]`, each recipient's NEW row id, in `userIds` order — so a
125
+ * caller that later wants to extendUnread() its row has the id without reading it back.
126
+ * Additive: `userIds` is unchanged.
119
127
  */
120
128
  async createMany(userIds, p = {}) {
121
129
  const ids = [...new Set((userIds || []).filter((v) => v != null).map(Number))]
122
130
  .filter((n) => Number.isInteger(n));
123
131
  // A notification with no type or no title has nothing to show; refusing quietly is right
124
132
  // because the caller is fire-and-forget and must not learn about this through a throw.
125
- if (!ids.length || !p.type || !p.title) return { userIds: [] };
133
+ if (!ids.length || !p.type || !p.title) return { userIds: [], rows: [] };
126
134
 
135
+ const rows = [];
127
136
  await driver.transaction(async (tx) => {
128
137
  for (const uid of ids) {
129
- await tx.run(
138
+ // returning('id') is empty on SQLite (the id arrives out of band) and RETURNING "id" on
139
+ // Postgres; either way the driver reports it as lastId.
140
+ const r = await tx.run(
130
141
  `INSERT INTO ${T} (user_id, type, title, body, link, actor_name, entity_type, entity_id)
131
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
142
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)${d().returning('id')}`,
132
143
  [uid, p.type, p.title, p.body || null, p.link || null,
133
144
  p.actor_name || null, p.entity_type || null, p.entity_id || null]
134
145
  );
146
+ rows.push({ userId: uid, id: Number(r.lastId) });
135
147
  }
136
148
  });
137
- return { userIds: ids };
149
+ return { userIds: ids, rows };
150
+ },
151
+
152
+ /**
153
+ * Grow an UNREAD row's title — "changed status to open" becomes "changed status to open,
154
+ * changed priority from medium to high" — and move its time up to now (0.7.0).
155
+ *
156
+ * ONE statement, guarded three ways: the row must be `id`, belong to `userId` (the
157
+ * ownership scope — see the top of this file) and still be unread. A row read a moment ago
158
+ * is never touched, so a caller cannot rewrite something its reader has already seen.
159
+ *
160
+ * THE TITLE IS CAPPED at TITLE_MAX (500) characters: when the grown title would be longer,
161
+ * nothing changes and this returns false — exactly as for a read row, so the caller's
162
+ * fallback (write a new row for the follow-up) covers both. A title is never cut mid-word.
163
+ *
164
+ * `opts.at` (optional, for a test's clock): the new created_at as UTC text,
165
+ * 'YYYY-MM-DD HH:MM:SS' — the format the column holds. Default: the database's clock
166
+ * (dialect now()). Anything else throws: a wrong-format time would sort wrongly, silently.
167
+ *
168
+ * Returns true when a row changed, false otherwise (not yours, read, gone, too long, or
169
+ * nothing to append). Both engines: `||`, CAST(? AS TEXT) and LENGTH() are common SQL; the
170
+ * casts are there because Postgres cannot type a bare parameter inside LENGTH().
171
+ */
172
+ async extendUnread(id, userId, opts = {}) {
173
+ opts = opts || {};
174
+ const more = opts.appendTitle == null ? '' : String(opts.appendTitle);
175
+ const sep = opts.sep == null ? ', ' : String(opts.sep);
176
+ if (!more.trim()) return false;
177
+ if (!Number.isInteger(Number(id)) || !Number.isInteger(Number(userId))) return false;
178
+ const at = opts.at == null ? null : String(opts.at);
179
+ if (at !== null && !/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(at)) {
180
+ throw new TypeError("notify: extendUnread opts.at must be UTC text 'YYYY-MM-DD HH:MM:SS'");
181
+ }
182
+ const r = await driver.run(
183
+ `UPDATE ${T} SET title = title || CAST(? AS TEXT) || CAST(? AS TEXT),
184
+ created_at = ${at === null ? d().now() : 'CAST(? AS TEXT)'}
185
+ WHERE id = ? AND user_id = ? AND is_read = 0
186
+ AND LENGTH(title) + LENGTH(CAST(? AS TEXT)) + LENGTH(CAST(? AS TEXT)) <= ${TITLE_MAX}`,
187
+ [sep, more, ...(at === null ? [] : [at]), Number(id), Number(userId), sep, more]);
188
+ return Number(r.changes) === 1;
138
189
  },
139
190
 
140
191
  unreadCount,
@@ -179,4 +230,4 @@ function createStore(opts = {}) {
179
230
  };
180
231
  }
181
232
 
182
- module.exports = { createStore, SCHEMA, schemaFor };
233
+ module.exports = { createStore, SCHEMA, schemaFor, TITLE_MAX };