JJopgood PWAcore + adaptersv0.0.2GitHub

API Reference

Complete public surface of @jopgood/pwa-core. The PWAManager class and the reactive store it owns.

Everything exported from @jopgood/pwa-core. Anything not listed here is internal and may change.

new PWAManager(options)

Constructs a manager. Safe to call on the server; no browser APIs are touched until mount().

Options

OptionTypeDefaultDescription
serviceWorkerUrlstringURL of your service-worker file. Required.
vapidPublicKeystringURL-safe base64 VAPID public key for push subscriptions. Required.
onSubscriptionChange(subscription: PushSubscription | null) => voidFired after mount() syncs the existing subscription, after a successful subscribe(), and after unsubscribe() (with null).
onError(error: Error) => voidFired on service-worker registration errors and subscribe() failures.

Methods

MethodReturnsDescription
mount()voidRegisters the service worker, reads the current permission, and syncs any existing push subscription. Call once after hydration.
unmount()voidRemoves internal listeners. Does not unregister the SW or unsubscribe.
requestNotificationPermission()Promise<NotificationPermission | undefined>Prompts the user if permission === "default". Returns undefined in environments without the Notification API.
subscribe()Promise<void>Creates a PushSubscription against the configured VAPID key. Requires granted permission and an active SW. Fires onSubscriptionChange.
unsubscribe()Promise<void>Unsubscribes the current push subscription, if any. Fires onSubscriptionChange with null.
activateWaiting()voidSends SKIP_WAITING to a waiting service worker. The page reloads when the new worker takes control. No-op if nothing is waiting.

manager.store

A @tanstack/store instance holding the reactive state. Read via manager.store.state; subscribe via manager.store.subscribe(listener).

PWAState

FieldTypeDescription
permission"default" | "granted" | "denied"Current Notification permission.
isSupportedbooleantrue once navigator.serviceWorker is detected during mount().
isSubscribedbooleanWhether a PushSubscription exists.
subscriptionPushSubscription | nullThe active push subscription, if any.
swState"idle" | "installing" | "waiting" | "active" | "error"Lifecycle of the registered service worker.
swUpdateAvailablebooleantrue when a new SW has installed and is waiting to activate. Flips back to false after activateWaiting().
isLoadingbooleantrue while the initial registration is in flight.
errorError | nullLast error from registration or subscription.

Internal classes

SWRegistrar, PermissionManager, and SubscriptionManager are exported from the package barrel so adapters can compose them directly. They're not covered here. Read the source in packages/pwa-core/src ↗ if that level of access is needed.

Pre-1.0

Anything outside the table above (internal classes, createPWAStore) is not covered by semver yet. Pin exact versions.