@cloudsignal/pwa-sdk 1.1.1 → 1.2.0

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/dist/index.d.mts CHANGED
@@ -187,6 +187,10 @@ interface BeforeInstallPromptEvent extends Event {
187
187
  /**
188
188
  * CloudSignal PWA SDK Configuration Types
189
189
  */
190
+ /**
191
+ * Authentication mode for SDK requests
192
+ */
193
+ type AuthMode$1 = 'hmac' | 'jwt';
190
194
  /**
191
195
  * Main SDK configuration options
192
196
  */
@@ -195,8 +199,22 @@ interface PWAConfig {
195
199
  serviceUrl?: string;
196
200
  /** Organization ID (UUID) */
197
201
  organizationId: string;
198
- /** Organization secret key for HMAC authentication */
199
- organizationSecret: string;
202
+ /**
203
+ * Organization secret key for HMAC authentication (anonymous mode)
204
+ * Required if userToken is not provided
205
+ */
206
+ organizationSecret?: string;
207
+ /**
208
+ * JWT token from identity provider for authenticated user mode
209
+ * Supports: Supabase, Firebase, Auth0, Clerk, custom OIDC
210
+ * When provided, takes precedence over organizationSecret
211
+ */
212
+ userToken?: string;
213
+ /**
214
+ * Callback to refresh JWT token when expired (401 response)
215
+ * Should return a new valid JWT token
216
+ */
217
+ onTokenExpired?: () => Promise<string>;
200
218
  /** PWA service ID (UUID) */
201
219
  serviceId: string;
202
220
  /** Enable debug logging */
@@ -503,7 +521,7 @@ interface NotificationAction {
503
521
  /**
504
522
  * Event types emitted by the SDK
505
523
  */
506
- type PWAEvent = 'install:available' | 'install:accepted' | 'install:dismissed' | 'install:completed' | 'install:error' | 'push:registered' | 'push:unregistered' | 'push:updated' | 'push:error' | 'push:received' | 'push:clicked' | 'permission:granted' | 'permission:denied' | 'permission:prompt' | 'sw:registered' | 'sw:updated' | 'sw:error' | 'sw:activated' | 'config:loaded' | 'config:error' | 'heartbeat:started' | 'heartbeat:stopped' | 'heartbeat:sent' | 'heartbeat:error' | 'heartbeat:intervalChanged' | 'heartbeat:pausedForBattery' | 'heartbeat:resumedFromBattery' | 'network:online' | 'network:offline' | 'state:changed' | 'wakeLock:acquired' | 'wakeLock:released' | 'wakeLock:error' | 'offlineQueue:queued' | 'offlineQueue:processed' | 'offlineQueue:flushed' | 'iosBanner:shown' | 'iosBanner:dismissed' | 'iosBanner:installClicked';
524
+ type PWAEvent = 'install:available' | 'install:accepted' | 'install:dismissed' | 'install:completed' | 'install:error' | 'push:registered' | 'push:unregistered' | 'push:updated' | 'push:error' | 'push:received' | 'push:clicked' | 'permission:granted' | 'permission:denied' | 'permission:prompt' | 'sw:registered' | 'sw:updated' | 'sw:error' | 'sw:activated' | 'config:loaded' | 'config:error' | 'heartbeat:started' | 'heartbeat:stopped' | 'heartbeat:sent' | 'heartbeat:error' | 'heartbeat:intervalChanged' | 'heartbeat:pausedForBattery' | 'heartbeat:resumedFromBattery' | 'network:online' | 'network:offline' | 'state:changed' | 'wakeLock:acquired' | 'wakeLock:released' | 'wakeLock:error' | 'offlineQueue:queued' | 'offlineQueue:processed' | 'offlineQueue:flushed' | 'iosBanner:shown' | 'iosBanner:dismissed' | 'iosBanner:installClicked' | 'auth:tokenUpdated';
507
525
  /**
508
526
  * Event handler function
509
527
  */
@@ -848,6 +866,7 @@ declare class CloudSignalPWA {
848
866
  private debug;
849
867
  private initialized;
850
868
  private serviceConfig;
869
+ private authContext;
851
870
  private deviceDetector;
852
871
  private serviceWorkerManager;
853
872
  private installationManager;
@@ -915,6 +934,16 @@ declare class CloudSignalPWA {
915
934
  * Request notification permission
916
935
  */
917
936
  requestPermission(): Promise<NotificationPermission>;
937
+ /**
938
+ * Get current authentication mode
939
+ */
940
+ getAuthMode(): AuthMode$1;
941
+ /**
942
+ * Set JWT user token (for upgrading anonymous to authenticated, or token refresh)
943
+ * After calling this, you should call registerForPush() again to re-register with user context
944
+ * @param token - JWT token from identity provider
945
+ */
946
+ setUserToken(token: string): void;
918
947
  /**
919
948
  * Get comprehensive device information
920
949
  */
@@ -1274,7 +1303,12 @@ declare class InstallationManager {
1274
1303
  interface PushNotificationManagerOptions {
1275
1304
  serviceUrl: string;
1276
1305
  organizationId: string;
1277
- organizationSecret: string;
1306
+ /** Organization secret for HMAC auth (optional if userToken provided) */
1307
+ organizationSecret?: string;
1308
+ /** JWT token for authenticated user mode (optional if organizationSecret provided) */
1309
+ userToken?: string;
1310
+ /** Callback to refresh JWT when expired */
1311
+ onTokenExpired?: () => Promise<string>;
1278
1312
  serviceId: string;
1279
1313
  debug?: boolean;
1280
1314
  onRegistered?: (registration: Registration) => void;
@@ -1288,7 +1322,6 @@ interface PushNotificationManagerOptions {
1288
1322
  declare class PushNotificationManager {
1289
1323
  private serviceUrl;
1290
1324
  private organizationId;
1291
- private organizationSecret;
1292
1325
  private serviceId;
1293
1326
  private debug;
1294
1327
  private deviceDetector;
@@ -1296,10 +1329,12 @@ declare class PushNotificationManager {
1296
1329
  private pushSubscription;
1297
1330
  private registrationId;
1298
1331
  private vapidPublicKey;
1332
+ private authContext;
1299
1333
  private onRegistered?;
1300
1334
  private onUnregistered?;
1301
1335
  private onError?;
1302
1336
  private onPermissionDenied?;
1337
+ private onTokenExpired?;
1303
1338
  constructor(options: PushNotificationManagerOptions);
1304
1339
  /**
1305
1340
  * Set service worker registration
@@ -1317,6 +1352,14 @@ declare class PushNotificationManager {
1317
1352
  * Check if registered for push notifications
1318
1353
  */
1319
1354
  isRegistered(): boolean;
1355
+ /**
1356
+ * Get current authentication mode
1357
+ */
1358
+ getAuthMode(): AuthMode$1;
1359
+ /**
1360
+ * Update JWT token (for token refresh or upgrading from HMAC to JWT)
1361
+ */
1362
+ updateToken(token: string): void;
1320
1363
  /**
1321
1364
  * Register for push notifications
1322
1365
  */
@@ -1359,7 +1402,12 @@ declare class PushNotificationManager {
1359
1402
  interface HeartbeatManagerOptions {
1360
1403
  serviceUrl: string;
1361
1404
  organizationId: string;
1362
- organizationSecret: string;
1405
+ /** Organization secret for HMAC auth (optional if userToken provided) */
1406
+ organizationSecret?: string;
1407
+ /** JWT token for authenticated user mode (optional if organizationSecret provided) */
1408
+ userToken?: string;
1409
+ /** Callback to refresh JWT when expired */
1410
+ onTokenExpired?: () => Promise<string>;
1363
1411
  config?: HeartbeatConfig;
1364
1412
  adaptiveConfig?: AdaptiveHeartbeatConfig;
1365
1413
  debug?: boolean;
@@ -1376,7 +1424,6 @@ interface HeartbeatManagerOptions {
1376
1424
  declare class HeartbeatManager {
1377
1425
  private serviceUrl;
1378
1426
  private organizationId;
1379
- private organizationSecret;
1380
1427
  private config;
1381
1428
  private adaptiveConfig;
1382
1429
  private debug;
@@ -1388,11 +1435,13 @@ declare class HeartbeatManager {
1388
1435
  private visibilityHandler;
1389
1436
  private connectionChangeHandler;
1390
1437
  private batteryManager;
1438
+ private authContext;
1391
1439
  private onHeartbeatSent?;
1392
1440
  private onHeartbeatError?;
1393
1441
  private onIntervalChanged?;
1394
1442
  private onPausedForBattery?;
1395
1443
  private onResumedFromBattery?;
1444
+ private onTokenExpired?;
1396
1445
  constructor(options: HeartbeatManagerOptions);
1397
1446
  /**
1398
1447
  * Set the registration ID for heartbeat requests
@@ -1410,6 +1459,14 @@ declare class HeartbeatManager {
1410
1459
  * Check if heartbeat is running
1411
1460
  */
1412
1461
  isHeartbeatRunning(): boolean;
1462
+ /**
1463
+ * Get current authentication mode
1464
+ */
1465
+ getAuthMode(): AuthMode$1;
1466
+ /**
1467
+ * Update JWT token (for token refresh or upgrading from HMAC to JWT)
1468
+ */
1469
+ updateToken(token: string): void;
1413
1470
  /**
1414
1471
  * Send a single heartbeat
1415
1472
  */
@@ -1923,6 +1980,89 @@ declare function makeAuthenticatedRequest(organizationId: string, organizationSe
1923
1980
  */
1924
1981
  declare function isValidUUID(value: string | null | undefined): boolean;
1925
1982
 
1983
+ /**
1984
+ * JWT Authentication Utilities
1985
+ * Implements CloudSignal's JWT-based authentication for user-linked registrations
1986
+ */
1987
+ /**
1988
+ * Auth mode type
1989
+ */
1990
+ type AuthMode = 'hmac' | 'jwt';
1991
+ /**
1992
+ * JWT auth configuration
1993
+ */
1994
+ interface JWTAuthConfig {
1995
+ /** JWT token from identity provider (Supabase, Firebase, Auth0, etc.) */
1996
+ token: string;
1997
+ /** Organization ID (still needed for provider config lookup) */
1998
+ organizationId: string;
1999
+ /** Callback to refresh token when expired */
2000
+ onTokenExpired?: () => Promise<string>;
2001
+ }
2002
+ /**
2003
+ * Generate authentication headers for JWT-based requests
2004
+ *
2005
+ * @param token - JWT token from identity provider
2006
+ * @param organizationId - Organization UUID
2007
+ * @returns Headers object with Bearer token and org ID
2008
+ */
2009
+ declare function generateJWTHeaders(token: string, organizationId: string): Record<string, string>;
2010
+ /**
2011
+ * Make an authenticated request using JWT
2012
+ * Handles token refresh on 401 errors
2013
+ *
2014
+ * @param config - JWT auth configuration
2015
+ * @param method - HTTP method
2016
+ * @param url - Request URL
2017
+ * @param body - Request body (optional)
2018
+ * @returns Fetch Response
2019
+ */
2020
+ declare function makeJWTAuthenticatedRequest(config: JWTAuthConfig, method: string, url: string, body?: Record<string, any>): Promise<Response>;
2021
+ /**
2022
+ * Auth context that can be passed to managers
2023
+ */
2024
+ interface AuthContext {
2025
+ mode: AuthMode;
2026
+ organizationId: string;
2027
+ organizationSecret?: string;
2028
+ userToken?: string;
2029
+ onTokenExpired?: () => Promise<string>;
2030
+ }
2031
+ /**
2032
+ * Create auth context from config
2033
+ * Determines auth mode based on provided credentials
2034
+ *
2035
+ * @param config - Configuration object
2036
+ * @returns Auth context with detected mode
2037
+ */
2038
+ declare function createAuthContext(config: {
2039
+ organizationId: string;
2040
+ organizationSecret?: string;
2041
+ userToken?: string;
2042
+ onTokenExpired?: () => Promise<string>;
2043
+ }): AuthContext;
2044
+ /**
2045
+ * Make authenticated request using auth context
2046
+ * Automatically selects HMAC or JWT based on context mode
2047
+ *
2048
+ * @param authContext - Auth context
2049
+ * @param method - HTTP method
2050
+ * @param url - Request URL
2051
+ * @param body - Request body (optional)
2052
+ * @param onTokenExpired - Token refresh callback (overrides context for this call)
2053
+ * @returns Fetch Response
2054
+ */
2055
+ declare function makeAuthenticatedRequestWithContext(authContext: AuthContext, method: string, url: string, body?: Record<string, any>, onTokenExpired?: () => Promise<string>): Promise<Response>;
2056
+ /**
2057
+ * Update token in auth context (for JWT mode)
2058
+ * Returns a new context with updated token
2059
+ *
2060
+ * @param authContext - Current auth context
2061
+ * @param newToken - New JWT token
2062
+ * @returns Updated auth context
2063
+ */
2064
+ declare function updateAuthToken(authContext: AuthContext, newToken: string): AuthContext;
2065
+
1926
2066
  /**
1927
2067
  * Browser Fingerprinting Utilities
1928
2068
  * Generate unique device identifiers for registration deduplication
@@ -2040,10 +2180,11 @@ declare class IndexedDBStorage {
2040
2180
  * Progressive Web App features with push notifications, installation management, and device tracking
2041
2181
  *
2042
2182
  * v1.1.0: Added WakeLock, OfflineQueue, iOS Install Banner, Network-aware Heartbeat, Notification Analytics
2183
+ * v1.2.0: Added JWT auth support for user-linked registrations
2043
2184
  *
2044
2185
  * @packageDocumentation
2045
2186
  */
2046
2187
 
2047
- declare const VERSION = "1.1.0";
2188
+ declare const VERSION = "1.2.0";
2048
2189
 
2049
- export { type AdaptiveHeartbeatConfig, type BatteryInfo, type BeforeInstallPromptEvent, CloudSignalPWA, type ConfigLoadedEvent, DeviceDetector, type DeviceInfo, type DisplayMode, type EventHandler, type HeartbeatConfig, type HeartbeatEvent, HeartbeatManager, type IOSBannerLanguage, type IOSBannerStrings, IOSInstallBanner, type IOSInstallBannerConfig$1 as IOSInstallBannerConfig, type IOSInstallBannerOptions$1 as IOSInstallBannerOptions, IOS_BANNER_TRANSLATIONS, IndexedDBStorage, type InitializeResult, type InstallAvailableEvent, type InstallResult, type InstallResultEvent, InstallationManager, type InstallationState, type LoggerFunction, NOTIFICATION_PROMPT_TRANSLATIONS, type NetworkConnectionInfo, type NetworkEvent, type NetworkInfo, type NotificationAction, type NotificationAnalyticsConfig, type NotificationAnalyticsEvent, type NotificationPayload, NotificationPermissionPrompt, type NotificationPermissionState, type NotificationPreferences, type IOSBannerLanguage as NotificationPromptLanguage, type NotificationPromptStrings, type OfflineQueueConfig$1 as OfflineQueueConfig, OfflineQueueManager, type OfflineQueueStats, type PWACapabilities, type PWAConfig, type PWAEvent, type PWAServiceConfig, type PWASupportLevel, type PermissionEvent, type PlatformInfo, type PushClickedEvent, PushNotificationManager, type PushReceivedEvent, type PushRegisteredEvent, type PushSubscriptionData, type QueueProcessResult, type QueuedRequest, type RegisterOptions, type Registration, type RegistrationStatus, type RegistrationStatusResponse, type ScreenInfo, type ServiceWorkerConfig, type ServiceWorkerEvent, ServiceWorkerManager, VERSION, type WakeLockConfig$1 as WakeLockConfig, WakeLockManager, type WakeLockState, CloudSignalPWA as default, detectBrowserLanguage, deviceDetector, generateAuthHeaders, generateBrowserFingerprint, generateHMACSignature, generateTrackingId, getRegistrationId, getStorageItem, isValidUUID, makeAuthenticatedRequest, removeRegistrationId, removeStorageItem, setRegistrationId, setStorageItem };
2190
+ export { type AdaptiveHeartbeatConfig, type AuthContext, type AuthMode$1 as AuthMode, type BatteryInfo, type BeforeInstallPromptEvent, CloudSignalPWA, type ConfigLoadedEvent, DeviceDetector, type DeviceInfo, type DisplayMode, type EventHandler, type HeartbeatConfig, type HeartbeatEvent, HeartbeatManager, type IOSBannerLanguage, type IOSBannerStrings, IOSInstallBanner, type IOSInstallBannerConfig$1 as IOSInstallBannerConfig, type IOSInstallBannerOptions$1 as IOSInstallBannerOptions, IOS_BANNER_TRANSLATIONS, IndexedDBStorage, type InitializeResult, type InstallAvailableEvent, type InstallResult, type InstallResultEvent, InstallationManager, type InstallationState, type LoggerFunction, NOTIFICATION_PROMPT_TRANSLATIONS, type NetworkConnectionInfo, type NetworkEvent, type NetworkInfo, type NotificationAction, type NotificationAnalyticsConfig, type NotificationAnalyticsEvent, type NotificationPayload, NotificationPermissionPrompt, type NotificationPermissionState, type NotificationPreferences, type IOSBannerLanguage as NotificationPromptLanguage, type NotificationPromptStrings, type OfflineQueueConfig$1 as OfflineQueueConfig, OfflineQueueManager, type OfflineQueueStats, type PWACapabilities, type PWAConfig, type PWAEvent, type PWAServiceConfig, type PWASupportLevel, type PermissionEvent, type PlatformInfo, type PushClickedEvent, PushNotificationManager, type PushReceivedEvent, type PushRegisteredEvent, type PushSubscriptionData, type QueueProcessResult, type QueuedRequest, type RegisterOptions, type Registration, type RegistrationStatus, type RegistrationStatusResponse, type ScreenInfo, type ServiceWorkerConfig, type ServiceWorkerEvent, ServiceWorkerManager, VERSION, type WakeLockConfig$1 as WakeLockConfig, WakeLockManager, type WakeLockState, createAuthContext, CloudSignalPWA as default, detectBrowserLanguage, deviceDetector, generateAuthHeaders, generateBrowserFingerprint, generateHMACSignature, generateJWTHeaders, generateTrackingId, getRegistrationId, getStorageItem, isValidUUID, makeAuthenticatedRequest, makeAuthenticatedRequestWithContext, makeJWTAuthenticatedRequest, removeRegistrationId, removeStorageItem, setRegistrationId, setStorageItem, updateAuthToken };
package/dist/index.d.ts CHANGED
@@ -187,6 +187,10 @@ interface BeforeInstallPromptEvent extends Event {
187
187
  /**
188
188
  * CloudSignal PWA SDK Configuration Types
189
189
  */
190
+ /**
191
+ * Authentication mode for SDK requests
192
+ */
193
+ type AuthMode$1 = 'hmac' | 'jwt';
190
194
  /**
191
195
  * Main SDK configuration options
192
196
  */
@@ -195,8 +199,22 @@ interface PWAConfig {
195
199
  serviceUrl?: string;
196
200
  /** Organization ID (UUID) */
197
201
  organizationId: string;
198
- /** Organization secret key for HMAC authentication */
199
- organizationSecret: string;
202
+ /**
203
+ * Organization secret key for HMAC authentication (anonymous mode)
204
+ * Required if userToken is not provided
205
+ */
206
+ organizationSecret?: string;
207
+ /**
208
+ * JWT token from identity provider for authenticated user mode
209
+ * Supports: Supabase, Firebase, Auth0, Clerk, custom OIDC
210
+ * When provided, takes precedence over organizationSecret
211
+ */
212
+ userToken?: string;
213
+ /**
214
+ * Callback to refresh JWT token when expired (401 response)
215
+ * Should return a new valid JWT token
216
+ */
217
+ onTokenExpired?: () => Promise<string>;
200
218
  /** PWA service ID (UUID) */
201
219
  serviceId: string;
202
220
  /** Enable debug logging */
@@ -503,7 +521,7 @@ interface NotificationAction {
503
521
  /**
504
522
  * Event types emitted by the SDK
505
523
  */
506
- type PWAEvent = 'install:available' | 'install:accepted' | 'install:dismissed' | 'install:completed' | 'install:error' | 'push:registered' | 'push:unregistered' | 'push:updated' | 'push:error' | 'push:received' | 'push:clicked' | 'permission:granted' | 'permission:denied' | 'permission:prompt' | 'sw:registered' | 'sw:updated' | 'sw:error' | 'sw:activated' | 'config:loaded' | 'config:error' | 'heartbeat:started' | 'heartbeat:stopped' | 'heartbeat:sent' | 'heartbeat:error' | 'heartbeat:intervalChanged' | 'heartbeat:pausedForBattery' | 'heartbeat:resumedFromBattery' | 'network:online' | 'network:offline' | 'state:changed' | 'wakeLock:acquired' | 'wakeLock:released' | 'wakeLock:error' | 'offlineQueue:queued' | 'offlineQueue:processed' | 'offlineQueue:flushed' | 'iosBanner:shown' | 'iosBanner:dismissed' | 'iosBanner:installClicked';
524
+ type PWAEvent = 'install:available' | 'install:accepted' | 'install:dismissed' | 'install:completed' | 'install:error' | 'push:registered' | 'push:unregistered' | 'push:updated' | 'push:error' | 'push:received' | 'push:clicked' | 'permission:granted' | 'permission:denied' | 'permission:prompt' | 'sw:registered' | 'sw:updated' | 'sw:error' | 'sw:activated' | 'config:loaded' | 'config:error' | 'heartbeat:started' | 'heartbeat:stopped' | 'heartbeat:sent' | 'heartbeat:error' | 'heartbeat:intervalChanged' | 'heartbeat:pausedForBattery' | 'heartbeat:resumedFromBattery' | 'network:online' | 'network:offline' | 'state:changed' | 'wakeLock:acquired' | 'wakeLock:released' | 'wakeLock:error' | 'offlineQueue:queued' | 'offlineQueue:processed' | 'offlineQueue:flushed' | 'iosBanner:shown' | 'iosBanner:dismissed' | 'iosBanner:installClicked' | 'auth:tokenUpdated';
507
525
  /**
508
526
  * Event handler function
509
527
  */
@@ -848,6 +866,7 @@ declare class CloudSignalPWA {
848
866
  private debug;
849
867
  private initialized;
850
868
  private serviceConfig;
869
+ private authContext;
851
870
  private deviceDetector;
852
871
  private serviceWorkerManager;
853
872
  private installationManager;
@@ -915,6 +934,16 @@ declare class CloudSignalPWA {
915
934
  * Request notification permission
916
935
  */
917
936
  requestPermission(): Promise<NotificationPermission>;
937
+ /**
938
+ * Get current authentication mode
939
+ */
940
+ getAuthMode(): AuthMode$1;
941
+ /**
942
+ * Set JWT user token (for upgrading anonymous to authenticated, or token refresh)
943
+ * After calling this, you should call registerForPush() again to re-register with user context
944
+ * @param token - JWT token from identity provider
945
+ */
946
+ setUserToken(token: string): void;
918
947
  /**
919
948
  * Get comprehensive device information
920
949
  */
@@ -1274,7 +1303,12 @@ declare class InstallationManager {
1274
1303
  interface PushNotificationManagerOptions {
1275
1304
  serviceUrl: string;
1276
1305
  organizationId: string;
1277
- organizationSecret: string;
1306
+ /** Organization secret for HMAC auth (optional if userToken provided) */
1307
+ organizationSecret?: string;
1308
+ /** JWT token for authenticated user mode (optional if organizationSecret provided) */
1309
+ userToken?: string;
1310
+ /** Callback to refresh JWT when expired */
1311
+ onTokenExpired?: () => Promise<string>;
1278
1312
  serviceId: string;
1279
1313
  debug?: boolean;
1280
1314
  onRegistered?: (registration: Registration) => void;
@@ -1288,7 +1322,6 @@ interface PushNotificationManagerOptions {
1288
1322
  declare class PushNotificationManager {
1289
1323
  private serviceUrl;
1290
1324
  private organizationId;
1291
- private organizationSecret;
1292
1325
  private serviceId;
1293
1326
  private debug;
1294
1327
  private deviceDetector;
@@ -1296,10 +1329,12 @@ declare class PushNotificationManager {
1296
1329
  private pushSubscription;
1297
1330
  private registrationId;
1298
1331
  private vapidPublicKey;
1332
+ private authContext;
1299
1333
  private onRegistered?;
1300
1334
  private onUnregistered?;
1301
1335
  private onError?;
1302
1336
  private onPermissionDenied?;
1337
+ private onTokenExpired?;
1303
1338
  constructor(options: PushNotificationManagerOptions);
1304
1339
  /**
1305
1340
  * Set service worker registration
@@ -1317,6 +1352,14 @@ declare class PushNotificationManager {
1317
1352
  * Check if registered for push notifications
1318
1353
  */
1319
1354
  isRegistered(): boolean;
1355
+ /**
1356
+ * Get current authentication mode
1357
+ */
1358
+ getAuthMode(): AuthMode$1;
1359
+ /**
1360
+ * Update JWT token (for token refresh or upgrading from HMAC to JWT)
1361
+ */
1362
+ updateToken(token: string): void;
1320
1363
  /**
1321
1364
  * Register for push notifications
1322
1365
  */
@@ -1359,7 +1402,12 @@ declare class PushNotificationManager {
1359
1402
  interface HeartbeatManagerOptions {
1360
1403
  serviceUrl: string;
1361
1404
  organizationId: string;
1362
- organizationSecret: string;
1405
+ /** Organization secret for HMAC auth (optional if userToken provided) */
1406
+ organizationSecret?: string;
1407
+ /** JWT token for authenticated user mode (optional if organizationSecret provided) */
1408
+ userToken?: string;
1409
+ /** Callback to refresh JWT when expired */
1410
+ onTokenExpired?: () => Promise<string>;
1363
1411
  config?: HeartbeatConfig;
1364
1412
  adaptiveConfig?: AdaptiveHeartbeatConfig;
1365
1413
  debug?: boolean;
@@ -1376,7 +1424,6 @@ interface HeartbeatManagerOptions {
1376
1424
  declare class HeartbeatManager {
1377
1425
  private serviceUrl;
1378
1426
  private organizationId;
1379
- private organizationSecret;
1380
1427
  private config;
1381
1428
  private adaptiveConfig;
1382
1429
  private debug;
@@ -1388,11 +1435,13 @@ declare class HeartbeatManager {
1388
1435
  private visibilityHandler;
1389
1436
  private connectionChangeHandler;
1390
1437
  private batteryManager;
1438
+ private authContext;
1391
1439
  private onHeartbeatSent?;
1392
1440
  private onHeartbeatError?;
1393
1441
  private onIntervalChanged?;
1394
1442
  private onPausedForBattery?;
1395
1443
  private onResumedFromBattery?;
1444
+ private onTokenExpired?;
1396
1445
  constructor(options: HeartbeatManagerOptions);
1397
1446
  /**
1398
1447
  * Set the registration ID for heartbeat requests
@@ -1410,6 +1459,14 @@ declare class HeartbeatManager {
1410
1459
  * Check if heartbeat is running
1411
1460
  */
1412
1461
  isHeartbeatRunning(): boolean;
1462
+ /**
1463
+ * Get current authentication mode
1464
+ */
1465
+ getAuthMode(): AuthMode$1;
1466
+ /**
1467
+ * Update JWT token (for token refresh or upgrading from HMAC to JWT)
1468
+ */
1469
+ updateToken(token: string): void;
1413
1470
  /**
1414
1471
  * Send a single heartbeat
1415
1472
  */
@@ -1923,6 +1980,89 @@ declare function makeAuthenticatedRequest(organizationId: string, organizationSe
1923
1980
  */
1924
1981
  declare function isValidUUID(value: string | null | undefined): boolean;
1925
1982
 
1983
+ /**
1984
+ * JWT Authentication Utilities
1985
+ * Implements CloudSignal's JWT-based authentication for user-linked registrations
1986
+ */
1987
+ /**
1988
+ * Auth mode type
1989
+ */
1990
+ type AuthMode = 'hmac' | 'jwt';
1991
+ /**
1992
+ * JWT auth configuration
1993
+ */
1994
+ interface JWTAuthConfig {
1995
+ /** JWT token from identity provider (Supabase, Firebase, Auth0, etc.) */
1996
+ token: string;
1997
+ /** Organization ID (still needed for provider config lookup) */
1998
+ organizationId: string;
1999
+ /** Callback to refresh token when expired */
2000
+ onTokenExpired?: () => Promise<string>;
2001
+ }
2002
+ /**
2003
+ * Generate authentication headers for JWT-based requests
2004
+ *
2005
+ * @param token - JWT token from identity provider
2006
+ * @param organizationId - Organization UUID
2007
+ * @returns Headers object with Bearer token and org ID
2008
+ */
2009
+ declare function generateJWTHeaders(token: string, organizationId: string): Record<string, string>;
2010
+ /**
2011
+ * Make an authenticated request using JWT
2012
+ * Handles token refresh on 401 errors
2013
+ *
2014
+ * @param config - JWT auth configuration
2015
+ * @param method - HTTP method
2016
+ * @param url - Request URL
2017
+ * @param body - Request body (optional)
2018
+ * @returns Fetch Response
2019
+ */
2020
+ declare function makeJWTAuthenticatedRequest(config: JWTAuthConfig, method: string, url: string, body?: Record<string, any>): Promise<Response>;
2021
+ /**
2022
+ * Auth context that can be passed to managers
2023
+ */
2024
+ interface AuthContext {
2025
+ mode: AuthMode;
2026
+ organizationId: string;
2027
+ organizationSecret?: string;
2028
+ userToken?: string;
2029
+ onTokenExpired?: () => Promise<string>;
2030
+ }
2031
+ /**
2032
+ * Create auth context from config
2033
+ * Determines auth mode based on provided credentials
2034
+ *
2035
+ * @param config - Configuration object
2036
+ * @returns Auth context with detected mode
2037
+ */
2038
+ declare function createAuthContext(config: {
2039
+ organizationId: string;
2040
+ organizationSecret?: string;
2041
+ userToken?: string;
2042
+ onTokenExpired?: () => Promise<string>;
2043
+ }): AuthContext;
2044
+ /**
2045
+ * Make authenticated request using auth context
2046
+ * Automatically selects HMAC or JWT based on context mode
2047
+ *
2048
+ * @param authContext - Auth context
2049
+ * @param method - HTTP method
2050
+ * @param url - Request URL
2051
+ * @param body - Request body (optional)
2052
+ * @param onTokenExpired - Token refresh callback (overrides context for this call)
2053
+ * @returns Fetch Response
2054
+ */
2055
+ declare function makeAuthenticatedRequestWithContext(authContext: AuthContext, method: string, url: string, body?: Record<string, any>, onTokenExpired?: () => Promise<string>): Promise<Response>;
2056
+ /**
2057
+ * Update token in auth context (for JWT mode)
2058
+ * Returns a new context with updated token
2059
+ *
2060
+ * @param authContext - Current auth context
2061
+ * @param newToken - New JWT token
2062
+ * @returns Updated auth context
2063
+ */
2064
+ declare function updateAuthToken(authContext: AuthContext, newToken: string): AuthContext;
2065
+
1926
2066
  /**
1927
2067
  * Browser Fingerprinting Utilities
1928
2068
  * Generate unique device identifiers for registration deduplication
@@ -2040,10 +2180,11 @@ declare class IndexedDBStorage {
2040
2180
  * Progressive Web App features with push notifications, installation management, and device tracking
2041
2181
  *
2042
2182
  * v1.1.0: Added WakeLock, OfflineQueue, iOS Install Banner, Network-aware Heartbeat, Notification Analytics
2183
+ * v1.2.0: Added JWT auth support for user-linked registrations
2043
2184
  *
2044
2185
  * @packageDocumentation
2045
2186
  */
2046
2187
 
2047
- declare const VERSION = "1.1.0";
2188
+ declare const VERSION = "1.2.0";
2048
2189
 
2049
- export { type AdaptiveHeartbeatConfig, type BatteryInfo, type BeforeInstallPromptEvent, CloudSignalPWA, type ConfigLoadedEvent, DeviceDetector, type DeviceInfo, type DisplayMode, type EventHandler, type HeartbeatConfig, type HeartbeatEvent, HeartbeatManager, type IOSBannerLanguage, type IOSBannerStrings, IOSInstallBanner, type IOSInstallBannerConfig$1 as IOSInstallBannerConfig, type IOSInstallBannerOptions$1 as IOSInstallBannerOptions, IOS_BANNER_TRANSLATIONS, IndexedDBStorage, type InitializeResult, type InstallAvailableEvent, type InstallResult, type InstallResultEvent, InstallationManager, type InstallationState, type LoggerFunction, NOTIFICATION_PROMPT_TRANSLATIONS, type NetworkConnectionInfo, type NetworkEvent, type NetworkInfo, type NotificationAction, type NotificationAnalyticsConfig, type NotificationAnalyticsEvent, type NotificationPayload, NotificationPermissionPrompt, type NotificationPermissionState, type NotificationPreferences, type IOSBannerLanguage as NotificationPromptLanguage, type NotificationPromptStrings, type OfflineQueueConfig$1 as OfflineQueueConfig, OfflineQueueManager, type OfflineQueueStats, type PWACapabilities, type PWAConfig, type PWAEvent, type PWAServiceConfig, type PWASupportLevel, type PermissionEvent, type PlatformInfo, type PushClickedEvent, PushNotificationManager, type PushReceivedEvent, type PushRegisteredEvent, type PushSubscriptionData, type QueueProcessResult, type QueuedRequest, type RegisterOptions, type Registration, type RegistrationStatus, type RegistrationStatusResponse, type ScreenInfo, type ServiceWorkerConfig, type ServiceWorkerEvent, ServiceWorkerManager, VERSION, type WakeLockConfig$1 as WakeLockConfig, WakeLockManager, type WakeLockState, CloudSignalPWA as default, detectBrowserLanguage, deviceDetector, generateAuthHeaders, generateBrowserFingerprint, generateHMACSignature, generateTrackingId, getRegistrationId, getStorageItem, isValidUUID, makeAuthenticatedRequest, removeRegistrationId, removeStorageItem, setRegistrationId, setStorageItem };
2190
+ export { type AdaptiveHeartbeatConfig, type AuthContext, type AuthMode$1 as AuthMode, type BatteryInfo, type BeforeInstallPromptEvent, CloudSignalPWA, type ConfigLoadedEvent, DeviceDetector, type DeviceInfo, type DisplayMode, type EventHandler, type HeartbeatConfig, type HeartbeatEvent, HeartbeatManager, type IOSBannerLanguage, type IOSBannerStrings, IOSInstallBanner, type IOSInstallBannerConfig$1 as IOSInstallBannerConfig, type IOSInstallBannerOptions$1 as IOSInstallBannerOptions, IOS_BANNER_TRANSLATIONS, IndexedDBStorage, type InitializeResult, type InstallAvailableEvent, type InstallResult, type InstallResultEvent, InstallationManager, type InstallationState, type LoggerFunction, NOTIFICATION_PROMPT_TRANSLATIONS, type NetworkConnectionInfo, type NetworkEvent, type NetworkInfo, type NotificationAction, type NotificationAnalyticsConfig, type NotificationAnalyticsEvent, type NotificationPayload, NotificationPermissionPrompt, type NotificationPermissionState, type NotificationPreferences, type IOSBannerLanguage as NotificationPromptLanguage, type NotificationPromptStrings, type OfflineQueueConfig$1 as OfflineQueueConfig, OfflineQueueManager, type OfflineQueueStats, type PWACapabilities, type PWAConfig, type PWAEvent, type PWAServiceConfig, type PWASupportLevel, type PermissionEvent, type PlatformInfo, type PushClickedEvent, PushNotificationManager, type PushReceivedEvent, type PushRegisteredEvent, type PushSubscriptionData, type QueueProcessResult, type QueuedRequest, type RegisterOptions, type Registration, type RegistrationStatus, type RegistrationStatusResponse, type ScreenInfo, type ServiceWorkerConfig, type ServiceWorkerEvent, ServiceWorkerManager, VERSION, type WakeLockConfig$1 as WakeLockConfig, WakeLockManager, type WakeLockState, createAuthContext, CloudSignalPWA as default, detectBrowserLanguage, deviceDetector, generateAuthHeaders, generateBrowserFingerprint, generateHMACSignature, generateJWTHeaders, generateTrackingId, getRegistrationId, getStorageItem, isValidUUID, makeAuthenticatedRequest, makeAuthenticatedRequestWithContext, makeJWTAuthenticatedRequest, removeRegistrationId, removeStorageItem, setRegistrationId, setStorageItem, updateAuthToken };