#4352
feat(puter-js): puter.notifications
puter.notifications in puter.js. Part of PUT-2170. Stacks on #4351. Replaces #4322.
What
| Method | Does |
|---|---|
notify(notification) | creates an app.message for the current user; resolves to its uid |
onNotification(handler, { catchUp?, since?, onError? }) | the app's own notifications: missed ones first (oldest first), then live ones, each delivered once; catches up again after a reconnect |
on('click', handler) / off | the user tapped a push or a notification in the panel: { uid, target, data } |
requestPermission() / hasPermission() | asks for or checks notifications:push |
registerDevice / listDevices / removeDevice | for Puter's own shells only (/push/devices) |
- There's no
onPush, and apps never choose between live delivery and push; the server decides. - Clicks come only from the desktop's
notificationClickbroadcast. A click that arrived before the first handler goes to that handler once, afteron()returns. onNotificationneeds an app context (app_requiredotherwise) and live notifications on the server (events_disabledotherwise).- Typings in
index.d.ts, a docs page per method with sidebar entries, and a playground example.
Deployments without a push service. The /push/devices routes come from an extension and are absent on a plain self-hosted install. The device methods turn that 404 into push_unavailable ("Push notifications aren't available on this deployment"). A missing device is device_not_found, so the two can't be confused. Documented on each method.
Tests
- Unit (mocked fetch): 58 passed, including
push_unavailablefor each device method, a non-JSON 404, anddevice_not_foundpassing through. - API suite on node against a core server with no push service: the notifications and perms cases pass. The device cases that needed a push service were removed from this suite, along with its
pushcapability. check:puterjs:typesis clean. Typecheck: no new errors.
Not verified
Clicks from a real desktop are covered by unit tests only.
Activity
6dfa6f4e60dfff3upload file with puter.js can run this file html.
Coverage Report for puter.js SDK
⬆️ +0.10 pp
⬆️ +0.02 pp
⬇️ -0.21 pp
⬇️ -0.35 pp
File Coverage
⬆️ +0.05 pp
🟰 ±0 pp
🟰 ±0 pp
⬆️ +0.05 pp
🟰 ±0 pp
🟰 ±0 pp
🟰 ±0 pp
🟰 ±0 pp