ump-plugin-notification
v0.0.1
Published
UMP Notification Plugin — Web Notifications API (notifications.spec.whatwg.org)
Readme
ump-plugin-notification
Web Notifications API (https://notifications.spec.whatwg.org) for UMP apps.
Install
npm install ump-plugin-notificationPeer dependencies (must already be installed in your app):
ump-coreump-native
Usage
Importing the module installs Notification on globalThis (only when
missing — a host implementation always wins) and also exposes it as a
named export. Off-the-shelf libs (web-push, OneSignal, FCM shims) that
reach for the bare global keep working.
import { Notification } from 'ump-plugin-notification';
// 1) Ask for permission.
const perm = await Notification.requestPermission();
if (perm !== 'granted') return;
// 2) Post a notification.
const n = new Notification('Hello', {
body: 'World',
icon: 'https://example.com/icon.png',
tag: 't1',
data: { foo: 'bar' },
});
// 3) Listen for lifecycle events.
n.addEventListener('show', () => console.log('shown'));
n.addEventListener('click', () => console.log('clicked'));
n.addEventListener('close', () => console.log('closed'));
n.addEventListener('error', () => console.log('error'));
// Or via on* property setters.
n.onclick = () => console.log('clicked (prop)');
// 4) Programmatic close.
n.close();API
Notification.permission
Read-only 'default' | 'granted' | 'denied'. Starts at 'default'
until requestPermission() resolves.
Notification.requestPermission(callback?)
Returns Promise<NotificationPermission>. Legacy callback form is
supported. If no host bridge is installed, resolves to 'denied' and
leaves permission at 'default' so a later install can ask again.
Notification.maxActions
Static 2 (matches spec minimum). Action buttons themselves are
forwarded to the host as options.actions with no JS-side
validation.
new Notification(title, options?)
Recognised options: body, icon, image, badge, tag, data,
silent, requireInteraction, lang, dir, vibrate, actions,
timestamp, renotify. Unknown keys pass through verbatim.
Instance fields mirror the spec: title, body, icon, image,
badge, tag, data, silent, requireInteraction, lang, dir,
vibrate, timestamp. onshow / onclick / onclose / onerror
property setters fire alongside addEventListener listeners.
notification.close()
Fire-and-forget dismiss. Idempotent — calling more than once is a no-op. Suppresses any subsequent late events from the host.
Spec deviations
getNotifications()is not provided (ServiceWorker scope).serviceWorkeraccessor on instances is not modelled.- Action buttons are forwarded verbatim — no JS-side validation; the platform decides whether to render them.
Migration from ump-native
In ump-native 0.1.x, Notification was bundled with the main package.
Starting 0.2.x, it ships as this separate plugin.
- import { Notification } from 'ump-native';
+ import { Notification } from 'ump-plugin-notification';No API changes. Type aliases NotificationOptions and
NotificationPermission are also re-exported.
