@rivium/push-web 0.1.4 → 0.1.6

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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Internal helpers kept free of SDK state so they can be unit-tested.
3
+ * Not part of the public API.
4
+ */
5
+ export interface DeviceInfo {
6
+ /** OS name + version, e.g. "Windows 10.0", "Android 14", "macOS 14.5" */
7
+ osVersion?: string;
8
+ /** Browser name + major version, e.g. "Chrome 128", "Safari 17" */
9
+ deviceModel?: string;
10
+ }
11
+ /**
12
+ * Best-effort, synchronous OS / browser detection. Prefers User-Agent Client
13
+ * Hints (`navigator.userAgentData`) and falls back to minimal UA parsing.
14
+ * Never throws; unknown values are left undefined.
15
+ */
16
+ export declare function detectDeviceInfo(nav?: any): DeviceInfo;
17
+ /** Re-register at least this often, even if nothing changed. */
18
+ export declare const REFRESH_INTERVAL_MS: number;
19
+ /** What the server last saw from this browser. Persisted in localStorage. */
20
+ export interface RegistrationFingerprint {
21
+ /** Time of the last successful registration (ms since epoch) */
22
+ registeredAt: number;
23
+ /** Web Push endpoint, or null when registered MQTT-only */
24
+ endpoint: string | null;
25
+ appVersion: string | null;
26
+ sdkVersion: string;
27
+ userId: string | null;
28
+ }
29
+ export type RefreshReason = 'no_fingerprint' | 'interval' | 'endpoint_changed' | 'app_version_changed' | 'sdk_version_changed' | 'user_changed';
30
+ /**
31
+ * Decide whether a previously registered browser should silently re-register.
32
+ * Returns the reason, or null when the server is already up to date.
33
+ */
34
+ export declare function getRefreshReason(previous: RegistrationFingerprint | null, current: Omit<RegistrationFingerprint, 'registeredAt'>, now: number, intervalMs?: number): RefreshReason | null;
35
+ export declare function parseFingerprint(raw: string | null): RegistrationFingerprint | null;
36
+ /** Insertion-ordered set that forgets its oldest entries past `limit`. */
37
+ export declare class BoundedSet {
38
+ private readonly limit;
39
+ private readonly items;
40
+ constructor(limit: number);
41
+ has(value: string): boolean;
42
+ /** Adds the value. Returns false if it was already present. */
43
+ add(value: string): boolean;
44
+ delete(value: string): void;
45
+ get size(): number;
46
+ }
@@ -0,0 +1,2 @@
1
+ export declare const SDK_NAME = "web";
2
+ export declare const SDK_VERSION = "0.1.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivium/push-web",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Web Push SDK for browsers - Firebase alternative that works everywhere",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,15 +8,18 @@
8
8
  "types": "dist/index.d.ts",
9
9
  "files": [
10
10
  "dist",
11
+ "!dist/test",
11
12
  "service-worker.js"
12
13
  ],
13
14
  "scripts": {
15
+ "prebuild": "node scripts/gen-version.mjs",
14
16
  "build": "rollup -c",
15
17
  "dev": "rollup -c -w",
16
18
  "test": "NODE_OPTIONS='--experimental-vm-modules' jest --passWithNoTests",
17
19
  "test:watch": "NODE_OPTIONS='--experimental-vm-modules' jest --watch",
18
20
  "test:coverage": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage",
19
- "prepublishOnly": "npm run build"
21
+ "prepublishOnly": "npm run build",
22
+ "pretest": "node scripts/gen-version.mjs"
20
23
  },
21
24
  "keywords": [
22
25
  "push-notifications",
package/service-worker.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  // Cache name for offline support
9
- const CACHE_NAME = 'rivium-push-v0.1.4';
9
+ const CACHE_NAME = 'rivium-push-v0.1.5';
10
10
 
11
11
  /**
12
12
  * Config passed by the SDK on the registration URL.
@@ -23,9 +23,11 @@ const RIVIUM_CONFIG = (() => {
23
23
  apiKey: params.get('riviumApiKey') || null,
24
24
  serverUrl: params.get('riviumServerUrl') || 'https://push-api.rivium.co',
25
25
  deviceId: params.get('riviumDeviceId') || null,
26
+ // Added in 0.1.5. SDKs older than 0.1.5 don't pass it.
27
+ sdkVersion: params.get('riviumSdkVersion') || null,
26
28
  };
27
29
  } catch (e) {
28
- return { apiKey: null, serverUrl: 'https://push-api.rivium.co', deviceId: null };
30
+ return { apiKey: null, serverUrl: 'https://push-api.rivium.co', deviceId: null, sdkVersion: null };
29
31
  }
30
32
  })();
31
33
 
@@ -257,6 +259,9 @@ self.addEventListener('pushsubscriptionchange', (event) => {
257
259
  platform: 'web',
258
260
  appIdentifier: self.location.origin,
259
261
  webPushSubscription: subscription.toJSON(),
262
+ // 0.1.5: SDK identity (body, not header, to avoid a CORS preflight).
263
+ sdkName: 'web',
264
+ ...(RIVIUM_CONFIG.sdkVersion ? { sdkVersion: RIVIUM_CONFIG.sdkVersion } : {}),
260
265
  }),
261
266
  }),
262
267
  )
@@ -1,54 +0,0 @@
1
- /**
2
- * Mock for @rivium/pn-protocol
3
- */
4
- export declare enum PNState {
5
- CONNECTING = "connecting",
6
- CONNECTED = "connected",
7
- DISCONNECTED = "disconnected",
8
- ERROR = "error"
9
- }
10
- export declare enum PNDeliveryMode {
11
- AT_MOST_ONCE = 0,
12
- AT_LEAST_ONCE = 1,
13
- EXACTLY_ONCE = 2
14
- }
15
- export declare class PNMessage {
16
- topic: string;
17
- payload: any;
18
- }
19
- export declare class PNError extends Error {
20
- constructor(message?: string);
21
- }
22
- export interface PNConnectionListener {
23
- onStateChange?: (state: PNState) => void;
24
- onMessage?: (message: PNMessage) => void;
25
- onError?: (error: PNError) => void;
26
- }
27
- export declare class PNAuthFactory {
28
- static token(t: string): {
29
- type: string;
30
- value: string;
31
- };
32
- }
33
- export declare class PNConfigBuilder {
34
- private config;
35
- gateway(g: string): this;
36
- port(p: number): this;
37
- secure(s: boolean): this;
38
- clientId(c: string): this;
39
- auth(a: any): this;
40
- keepAlive(k: number): this;
41
- autoReconnect(a: boolean): this;
42
- maxReconnectDelay(m: number): this;
43
- build(): any;
44
- }
45
- export declare class PNSocket {
46
- private listener;
47
- constructor(_config: any);
48
- setListener(listener: PNConnectionListener): void;
49
- connect(): void;
50
- disconnect(): void;
51
- subscribe(_topic: string, _qos: PNDeliveryMode): void;
52
- unsubscribe(_topic: string, _qos: PNDeliveryMode): void;
53
- publish(_topic: string, _payload: any, _qos: PNDeliveryMode): void;
54
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * RiviumPush Web SDK Unit Tests
3
- */
4
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Jest test setup file
3
- * Sets up browser API mocks for testing
4
- */
5
- export {};