@rivium/push-web 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -89,9 +89,30 @@ const riviumPush = new RiviumPush({
89
89
  mqttQos: 1, // Optional - MQTT QoS level (default: 1)
90
90
  maxReconnectAttempts: 10, // Optional - max reconnect attempts (default: 10)
91
91
  logLevel: RiviumPushLogLevel.ERROR, // Optional - log level
92
+ appVersion: '2.0.0', // Optional - your app version (segment filter)
93
+ autoRefresh: true, // Optional - background re-registration (default: true)
92
94
  });
93
95
  ```
94
96
 
97
+ ### Automatic refresh
98
+
99
+ With `autoRefresh` on (the default), a browser that has registered before is
100
+ silently re-registered on page load when its registration is likely stale: 24
101
+ hours have passed, the push subscription endpoint changed, or `appVersion`, the
102
+ SDK version or the user ID changed. It never shows a permission prompt (it only
103
+ runs when permission is already granted) and never throws. Calling `register()`
104
+ yourself still always registers.
105
+
106
+ ### SDK version
107
+
108
+ ```typescript
109
+ import { SDK_VERSION } from '@rivium/push-web';
110
+ console.log(SDK_VERSION); // "0.1.5"
111
+ ```
112
+
113
+ The SDK reports `sdkName` / `sdkVersion`, the OS and the browser (as
114
+ `osVersion` / `deviceModel`) when registering, so they show up in the dashboard.
115
+
95
116
  ## Callbacks
96
117
 
97
118
  All event handlers return an unsubscribe function.
@@ -246,6 +267,12 @@ await riviumPush.unregister();
246
267
  </html>
247
268
  ```
248
269
 
270
+ ## Delivery Tracking
271
+
272
+ Notifications are confirmed as `delivered` automatically: Web Push arrivals by
273
+ the service worker, and messages received over the real-time connection on an
274
+ open page by the SDK. No code needed.
275
+
249
276
  ## Browser Support
250
277
 
251
278
  - Chrome 50+ (Desktop & Android)
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@
14
14
  *
15
15
  * @packageDocumentation
16
16
  */
17
+ import { SDK_NAME, SDK_VERSION } from './version';
18
+ export { SDK_NAME, SDK_VERSION };
17
19
  /**
18
20
  * Standardized error codes for RiviumPush SDK.
19
21
  * These codes help developers identify and handle specific error scenarios.
@@ -198,6 +200,15 @@ export interface RiviumPushConfig {
198
200
  * this at init time from your build config.
199
201
  */
200
202
  appVersion?: string;
203
+ /**
204
+ * Keep the server-side registration fresh without calling register() on
205
+ * every page load (default: true). On startup, a browser that registered
206
+ * before is silently re-registered in the background when 24h have passed,
207
+ * the push subscription endpoint changed, or `appVersion`, the SDK version
208
+ * or the userId changed. Never prompts: it only runs when notification
209
+ * permission is already granted. Errors are logged, never thrown.
210
+ */
211
+ autoRefresh?: boolean;
201
212
  }
202
213
  /**
203
214
  * Notification action button
@@ -368,6 +379,9 @@ declare class RiviumPush {
368
379
  private onReconnectingCallback;
369
380
  private onNetworkStateCallback;
370
381
  private onAppStateCallback;
382
+ private registerRequested;
383
+ private ackedMessageIds;
384
+ private receivedMessageIds;
371
385
  constructor(config: RiviumPushConfig);
372
386
  /**
373
387
  * Fetch MQTT and VAPID configuration from server
@@ -451,8 +465,12 @@ declare class RiviumPush {
451
465
  setUserId(userId: string): Promise<void>;
452
466
  /**
453
467
  * Clear user ID. Call this on logout.
468
+ *
469
+ * Also detaches the user on the server. Registration treats a missing
470
+ * userId as "keep the existing one", so clearing only local state would
471
+ * leave this browser receiving the logged-out user's notifications.
454
472
  */
455
- clearUserId(): void;
473
+ clearUserId(): Promise<void>;
456
474
  /**
457
475
  * Get the currently-stored userId, if any. Survives page reloads.
458
476
  */
@@ -543,6 +561,15 @@ declare class RiviumPush {
543
561
  private checkInitialMessage;
544
562
  private registerServiceWorker;
545
563
  private requestNotificationPermission;
564
+ /**
565
+ * Whether an existing subscription was created with the given VAPID key.
566
+ *
567
+ * `applicationServerKey` comes back as an ArrayBuffer, so compare it against
568
+ * the decoded form of the current key. If the browser doesn't expose the
569
+ * option (older implementations), assume a match rather than churn a working
570
+ * subscription.
571
+ */
572
+ private subscriptionMatchesVapidKey;
546
573
  private subscribeToPush;
547
574
  /**
548
575
  * Read platform-native device attributes. Sent on every register() so
@@ -560,9 +587,26 @@ declare class RiviumPush {
560
587
  private disconnectFromGateway;
561
588
  private scheduleReconnect;
562
589
  private handleMqttMessage;
590
+ /**
591
+ * POST /receipts/delivered for a message received on this page. Deduped per
592
+ * messageId (the server is idempotent too) and retried a bounded number of
593
+ * times on network errors, 429 and 5xx. Never throws.
594
+ */
595
+ private reportDelivered;
596
+ private saveRegistrationState;
597
+ /**
598
+ * Silently re-register a browser that registered before, when the server's
599
+ * copy is likely stale. Never prompts for permission and never throws.
600
+ */
601
+ private maybeAutoRefresh;
563
602
  private normalizeMessage;
564
603
  private getLocalizedContent;
565
604
  private handleBadge;
605
+ /**
606
+ * Records a messageId as handed to the app. Returns false if it already was.
607
+ * Messages without an id can't be deduped and always pass.
608
+ */
609
+ private markReceived;
566
610
  private handleServiceWorkerMessage;
567
611
  private showRichNotification;
568
612
  private updateFaviconBadge;