export type TinyPushEndpoints = { /** * - `POST` route that persists a subscription. */ subscribe?: string; /** * - `DELETE` route that removes a subscription. */ unsubscribe?: string; }; export type TinyPushManagerOptions = { /** * - The active registration. */ registration: ServiceWorkerRegistration; /** * - Base64 URL-safe VAPID public key. */ vapidPublicKey: string; /** * - Backend routes. */ endpoints?: TinyPushEndpoints; /** * - Fetch implementation, injectable for tests. */ fetch?: typeof fetch; /** * - State observer. */ onChange?: (state: TinyPushState) => void; }; export type TinyPushState = { /** * - Current status. */ status: 'unsupported' | 'unsubscribed' | 'subscribed' | 'denied' | 'pending'; /** * - The active subscription, when any. */ subscription: PushSubscription | null; /** * - The last error message, when any. */ error: string | null; }; /** * @file Owns the lifecycle of a `PushSubscription` in the page context. * * The manager never talks to the push service directly: it delegates to * `PushManager` and to two HTTP endpoints that your backend exposes. */ /** * Describes the optional backend routes used to persist or remove a * `PushSubscription`. * * @typedef {Object} TinyPushEndpoints * @property {string} [subscribe] - `POST` route that persists a subscription. * @property {string} [unsubscribe] - `DELETE` route that removes a subscription. */ /** * Describes every option accepted by the `TinyPushManager` constructor. * * @typedef {Object} TinyPushManagerOptions * @property {ServiceWorkerRegistration} registration - The active registration. * @property {string} vapidPublicKey - Base64 URL-safe VAPID public key. * @property {TinyPushEndpoints} [endpoints] - Backend routes. * @property {typeof fetch} [fetch] - Fetch implementation, injectable for tests. * @property {(state: TinyPushState) => void} [onChange] - State observer. */ /** * Represents an immutable snapshot of the manager state exposed to observers. * * @typedef {Object} TinyPushState * @property {'unsupported'|'unsubscribed'|'subscribed'|'denied'|'pending'} status - Current status. * @property {PushSubscription|null} subscription - The active subscription, when any. * @property {string|null} error - The last error message, when any. */ /** * Manages the full lifecycle of a browser `PushSubscription` in the page context. * * The manager is a thin, framework-agnostic wrapper around `PushManager`. It never * talks to a push service directly: it delegates subscription creation to the * `PushManager` API and persistence to two optional backend routes (`subscribe` * and `unsubscribe`). Every state transition is broadcast to the optional * `onChange` observer, which makes it easy to bind the manager to any UI layer. * * @example * const manager = new TinyPushManager({ * registration: await navigator.serviceWorker.ready, * vapidPublicKey: 'YOUR_PUBLIC_KEY', * endpoints: { subscribe: '/api/push', unsubscribe: '/api/push' }, * onChange: (state) => console.log(state.status), * }); * * await manager.subscribe(); * * @beta */ declare class TinyPushManager { #private; static get PUSH_TYPE(): Readonly<{ NOTIFICATION: "notification"; DATA: "data"; SYNC: "sync"; COMMAND: "command"; UNKNOWN: "unknown"; }>; /** * Reports whether the browser exposes the Push API. * @returns {boolean} `true` when the Push API is available. */ static isSupported(): boolean; /** @returns {NotificationPermission} The current permission. */ static get permission(): NotificationPermission; /** * Asks the user for the notification permission. * * @returns {Promise} The resulting permission. * @throws {Error} If the Push API is not supported. */ static requestPermission(): Promise; /** * Decodes a base64 URL-safe VAPID key. The result is memoized per key. * * @param {string} base64 - The VAPID public key. * @returns {BufferSource} The decoded key. * @throws {TypeError} If `base64` is not a non-empty string. */ static decodeVapidKey(base64: string): BufferSource; /** * Creates a manager bound to a service worker registration. * * @param {TinyPushManagerOptions} options - The manager options. * @throws {TypeError} If `options` is invalid. */ constructor(options: TinyPushManagerOptions); /** @returns {TinyPushState} A frozen snapshot of the current state. */ get state(): TinyPushState; /** * Returns the current subscription, if any. * * @returns {Promise} The subscription or `null`. */ getSubscription(): Promise; /** * Subscribes the user and uploads the subscription to the backend. * * @param {PushSubscriptionOptionsInit} [options] - Extra options merged into `subscribe`. * @returns {Promise} The active subscription. * @throws {Error} If the permission is denied or the browser rejects the subscription. */ subscribe(options?: PushSubscriptionOptionsInit): Promise; /** * Removes the subscription locally and on the backend. * * @returns {Promise} `true` when a subscription was removed. */ unsubscribe(): Promise; /** * Re-uploads the current subscription. Call it after a `pushsubscriptionchange`. * * @returns {Promise} The refreshed subscription. */ syncWithServer(): Promise; } export default TinyPushManager; //# sourceMappingURL=TinyPushManager.d.mts.map