@micha.bigler/ui-core-micha 4.42.0 → 4.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +4 -0
- package/dist/notifications/serviceWorker/sw.js +100 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.43.0 - UCM-NOTIF-18
|
|
4
|
+
|
|
5
|
+
The canonical copyable push service worker now supports DCM-provided localized
|
|
6
|
+
`open` and `done` notification actions. `open` retains same-origin navigation;
|
|
7
|
+
`done` obtains a per-click masked CSRF token and posts the opaque completion
|
|
8
|
+
token without opening an app window. Existing base-only push payloads retain
|
|
9
|
+
their display and tap-to-open behaviour. Gustav can pin this additive release.
|
|
10
|
+
|
|
3
11
|
## 4.42.0 - UCM-CHAT-21
|
|
4
12
|
|
|
5
13
|
In managed mode the chat model picker lists the offered families grouped by
|
package/README.md
CHANGED
|
@@ -239,6 +239,10 @@ extra peers are optional: `@micha.bigler/ui-core-micha/charts` (`@mui/x-charts`)
|
|
|
239
239
|
(`react-markdown`, `remark-gfm`). Install those peers only in apps that import the sub-path. The 4.0.0 entry in
|
|
240
240
|
`CHANGELOG.md` has the migration table.
|
|
241
241
|
|
|
242
|
+
## Shared chat: group permissions
|
|
243
|
+
|
|
244
|
+
An app that registers a DCM group catalogue gets the shared chat permission control without extra `ChatWorkspace` props. For the selected private, unarchived chat, UCM reads `chats/<id>/group-grants/` under `apiBase`; unsupported apps and older servers retain their existing chat UI. The server supplies localized group and member labels, availability, write confirmation metadata and opaque revisions. UCM sends only selected group IDs and both revisions on save. A stale response requires a reload; failed saves retain the draft. Existing `api` overrides can provide `getGroupGrants(id)` and `saveGroupGrants(id, payload)` using the same response contract. Authorization and enforcement remain server responsibilities.
|
|
245
|
+
|
|
242
246
|
## Shared chat: compact composer (opt-in)
|
|
243
247
|
|
|
244
248
|
`<ChatWorkspace composerLayout="compact" renderComposerContext={({ chat }) => ...}>` lays the composer out in two
|
|
@@ -3,15 +3,90 @@
|
|
|
3
3
|
* Canonical service-worker source. Copy this file verbatim to each consuming
|
|
4
4
|
* application's public/sw.js so it is served from that application's origin root.
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
6
|
+
const PUSH_CSRF_URL = '/api/notifications/push/csrf/';
|
|
7
|
+
const PUSH_DONE_URL = '/api/notifications/push/done/';
|
|
8
|
+
const KNOWN_ACTIONS = new Set(['open', 'done']);
|
|
9
|
+
const doneActionsInFlight = new WeakSet();
|
|
10
|
+
const appUrl = (value) => {
|
|
7
11
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
if (typeof value !== 'string' || !value)
|
|
13
|
+
return undefined;
|
|
14
|
+
const resolvedUrl = new URL(value, self.location.origin);
|
|
15
|
+
if (resolvedUrl.origin !== self.location.origin || !['http:', 'https:'].includes(resolvedUrl.protocol) || resolvedUrl.username || resolvedUrl.password)
|
|
16
|
+
return undefined;
|
|
17
|
+
return resolvedUrl.href;
|
|
12
18
|
}
|
|
13
19
|
catch (_a) {
|
|
14
|
-
return
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const safeAppUrl = (value) => appUrl(value) || new URL('/', self.location.origin).href;
|
|
24
|
+
const notificationAction = (actions, name) => (Array.isArray(actions)
|
|
25
|
+
? actions.find((action) => action && action.action === name && typeof action.title === 'string' && action.title)
|
|
26
|
+
: undefined);
|
|
27
|
+
const displayOptions = (payload) => {
|
|
28
|
+
const openAction = notificationAction(payload.actions, 'open');
|
|
29
|
+
const doneAction = notificationAction(payload.actions, 'done');
|
|
30
|
+
const hasDoneToken = typeof payload.done_token === 'string' && payload.done_token;
|
|
31
|
+
const actions = [];
|
|
32
|
+
if (openAction)
|
|
33
|
+
actions.push({ action: 'open', title: openAction.title });
|
|
34
|
+
if (doneAction && hasDoneToken)
|
|
35
|
+
actions.push({ action: 'done', title: doneAction.title });
|
|
36
|
+
const base = {
|
|
37
|
+
body: typeof payload.body === 'string' ? payload.body : '',
|
|
38
|
+
data: { url: safeAppUrl(payload.url), openUrl: appUrl(openAction === null || openAction === void 0 ? void 0 : openAction.url) || safeAppUrl(payload.url), doneToken: hasDoneToken ? payload.done_token : undefined },
|
|
39
|
+
};
|
|
40
|
+
const optional = {};
|
|
41
|
+
if (typeof payload.icon === 'string' && payload.icon)
|
|
42
|
+
optional.icon = payload.icon;
|
|
43
|
+
if (typeof payload.badge === 'string' && payload.badge)
|
|
44
|
+
optional.badge = payload.badge;
|
|
45
|
+
if (typeof payload.tag === 'string' && payload.tag)
|
|
46
|
+
optional.tag = payload.tag;
|
|
47
|
+
if (optional.tag && typeof payload.renotify === 'boolean')
|
|
48
|
+
optional.renotify = payload.renotify;
|
|
49
|
+
if (actions.length)
|
|
50
|
+
optional.actions = actions;
|
|
51
|
+
return { base, optional };
|
|
52
|
+
};
|
|
53
|
+
const showPushNotification = async (payload) => {
|
|
54
|
+
const { base, optional } = displayOptions(payload);
|
|
55
|
+
const title = typeof payload.title === 'string' && payload.title ? payload.title : 'Notification';
|
|
56
|
+
try {
|
|
57
|
+
await self.registration.showNotification(title, Object.assign(Object.assign({}, base), optional));
|
|
58
|
+
}
|
|
59
|
+
catch (_a) {
|
|
60
|
+
await self.registration.showNotification(title, base);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const openAppWindow = async (url) => {
|
|
64
|
+
const target = safeAppUrl(url);
|
|
65
|
+
const clientList = await clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
66
|
+
for (const client of clientList) {
|
|
67
|
+
if (appUrl(client.url) && 'focus' in client) {
|
|
68
|
+
await client.navigate(target);
|
|
69
|
+
return client.focus();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return clients.openWindow ? clients.openWindow(target) : undefined;
|
|
73
|
+
};
|
|
74
|
+
const completeNotification = async (token) => {
|
|
75
|
+
try {
|
|
76
|
+
const csrfResponse = await fetch(PUSH_CSRF_URL, { method: 'GET', mode: 'same-origin', credentials: 'same-origin', redirect: 'error', cache: 'no-store' });
|
|
77
|
+
if (csrfResponse.status !== 200 || csrfResponse.redirected)
|
|
78
|
+
return false;
|
|
79
|
+
const csrfPayload = await csrfResponse.json();
|
|
80
|
+
if (!csrfPayload || typeof csrfPayload.csrf_token !== 'string' || !csrfPayload.csrf_token)
|
|
81
|
+
return false;
|
|
82
|
+
const doneResponse = await fetch(PUSH_DONE_URL, {
|
|
83
|
+
method: 'POST', mode: 'same-origin', credentials: 'same-origin', redirect: 'error', cache: 'no-store', referrerPolicy: 'same-origin',
|
|
84
|
+
headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfPayload.csrf_token }, body: JSON.stringify({ token }),
|
|
85
|
+
});
|
|
86
|
+
return doneResponse.status === 204 && !doneResponse.redirected;
|
|
87
|
+
}
|
|
88
|
+
catch (_a) {
|
|
89
|
+
return false;
|
|
15
90
|
}
|
|
16
91
|
};
|
|
17
92
|
self.addEventListener('push', (event) => {
|
|
@@ -24,26 +99,25 @@ self.addEventListener('push', (event) => {
|
|
|
24
99
|
catch (_a) {
|
|
25
100
|
payload = { body: event.data.text() };
|
|
26
101
|
}
|
|
27
|
-
|
|
28
|
-
body: payload.body || '',
|
|
29
|
-
data: { url: resolveSameOriginUrl(payload.url) },
|
|
30
|
-
};
|
|
31
|
-
if (payload.icon)
|
|
32
|
-
options.icon = payload.icon;
|
|
33
|
-
if (payload.badge)
|
|
34
|
-
options.badge = payload.badge;
|
|
35
|
-
event.waitUntil(self.registration.showNotification(payload.title || 'Notification', options));
|
|
102
|
+
event.waitUntil(showPushNotification(payload && typeof payload === 'object' ? payload : {}));
|
|
36
103
|
});
|
|
37
104
|
self.addEventListener('notificationclick', (event) => {
|
|
38
|
-
var _a;
|
|
39
|
-
event
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
}
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
const { notification } = event;
|
|
107
|
+
if (event.action === 'done') {
|
|
108
|
+
const token = (_a = notification.data) === null || _a === void 0 ? void 0 : _a.doneToken;
|
|
109
|
+
if (!token || doneActionsInFlight.has(notification))
|
|
110
|
+
return;
|
|
111
|
+
doneActionsInFlight.add(notification);
|
|
112
|
+
event.waitUntil(completeNotification(token).then((completed) => { if (completed)
|
|
113
|
+
notification.close(); }).finally(() => doneActionsInFlight.delete(notification)));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (event.action && !KNOWN_ACTIONS.has(event.action))
|
|
117
|
+
return;
|
|
118
|
+
notification.close();
|
|
119
|
+
const target = event.action === 'open'
|
|
120
|
+
? appUrl((_b = notification.data) === null || _b === void 0 ? void 0 : _b.openUrl) || safeAppUrl((_c = notification.data) === null || _c === void 0 ? void 0 : _c.url)
|
|
121
|
+
: (_d = notification.data) === null || _d === void 0 ? void 0 : _d.url;
|
|
122
|
+
event.waitUntil(openAppWindow(target));
|
|
49
123
|
});
|