@cloudsignal/pwa-sdk 1.2.4 → 2.0.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.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isValidUUID } from './chunk-IMM7VF4N.js';
2
- export { generateAuthHeaders, generateHMACSignature, isValidUUID, makeAuthenticatedRequest } from './chunk-IMM7VF4N.js';
1
+ import { isValidUUID } from './chunk-IQHSODT4.js';
2
+ export { generateAuthHeaders, generateHMACSignature, isValidUUID, makeAuthenticatedRequest } from './chunk-IQHSODT4.js';
3
3
 
4
4
  /**
5
5
  * CloudSignal PWA SDK v1.0.0
@@ -934,13 +934,13 @@ function createAuthContext(config) {
934
934
  onTokenExpired: config.onTokenExpired
935
935
  };
936
936
  }
937
- if (!config.organizationSecret) {
938
- throw new Error("Either userToken or organizationSecret is required");
937
+ if (!config.organizationPublishableKey) {
938
+ throw new Error("Either userToken or organizationPublishableKey is required");
939
939
  }
940
940
  return {
941
941
  mode: "hmac",
942
942
  organizationId: config.organizationId,
943
- organizationSecret: config.organizationSecret
943
+ organizationPublishableKey: config.organizationPublishableKey
944
944
  };
945
945
  }
946
946
  async function makeAuthenticatedRequestWithContext(authContext, method, url, body, onTokenExpired) {
@@ -960,13 +960,13 @@ async function makeAuthenticatedRequestWithContext(authContext, method, url, bod
960
960
  body
961
961
  );
962
962
  }
963
- const { makeAuthenticatedRequest: makeAuthenticatedRequest4 } = await import('./hmac-LWLR6F7Z.js');
964
- if (!authContext.organizationSecret) {
965
- throw new Error("organizationSecret required for HMAC auth mode");
963
+ const { makeAuthenticatedRequest: makeAuthenticatedRequest4 } = await import('./hmac-WITZIX2O.js');
964
+ if (!authContext.organizationPublishableKey) {
965
+ throw new Error("organizationPublishableKey required for HMAC auth mode");
966
966
  }
967
967
  return makeAuthenticatedRequest4(
968
968
  authContext.organizationId,
969
- authContext.organizationSecret,
969
+ authContext.organizationPublishableKey,
970
970
  method,
971
971
  url,
972
972
  body
@@ -1029,15 +1029,6 @@ function removeRegistrationId(organizationId, serviceId) {
1029
1029
  const key = `registration_${organizationId}_${serviceId}`;
1030
1030
  return removeStorageItem(key);
1031
1031
  }
1032
- function isInstallationRegistered(organizationId, serviceId) {
1033
- const key = `install_registered_${organizationId}_${serviceId}`;
1034
- return getStorageItem(key) === true;
1035
- }
1036
- function markInstallationRegistered(organizationId, serviceId, registrationId) {
1037
- const key = `install_registered_${organizationId}_${serviceId}`;
1038
- setStorageItem(`install_id_${organizationId}_${serviceId}`, registrationId);
1039
- return setStorageItem(key, true);
1040
- }
1041
1032
  var IndexedDBStorage = class {
1042
1033
  constructor(dbName = "CloudSignalPWA", dbVersion = 1) {
1043
1034
  this.db = null;
@@ -1244,7 +1235,7 @@ var PushNotificationManager = class {
1244
1235
  this.deviceDetector = new DeviceDetector();
1245
1236
  this.authContext = createAuthContext({
1246
1237
  organizationId: options.organizationId,
1247
- organizationSecret: options.organizationSecret,
1238
+ organizationPublishableKey: options.organizationPublishableKey,
1248
1239
  userToken: options.userToken
1249
1240
  });
1250
1241
  this.onRegistered = options.onRegistered;
@@ -1483,72 +1474,6 @@ var PushNotificationManager = class {
1483
1474
  return null;
1484
1475
  }
1485
1476
  }
1486
- /**
1487
- * Register PWA installation without push subscription.
1488
- * This tracks users who installed the PWA but haven't subscribed to notifications.
1489
- * Called automatically when installation is detected.
1490
- *
1491
- * @returns Installation registration result or null if already registered/failed
1492
- */
1493
- async registerInstallation() {
1494
- try {
1495
- if (isInstallationRegistered(this.organizationId, this.serviceId)) {
1496
- this.log("Installation already registered, skipping");
1497
- return null;
1498
- }
1499
- const fingerprint = await generateBrowserFingerprint();
1500
- const deviceInfo = this.deviceDetector.getDeviceInfo();
1501
- const platformInfo = this.deviceDetector.getPlatformInfo();
1502
- const installationData = {
1503
- service_id: this.serviceId,
1504
- browser_fingerprint: fingerprint || void 0,
1505
- device_type: deviceInfo.deviceType,
1506
- device_model: deviceInfo.deviceModel,
1507
- browser_name: platformInfo.browser,
1508
- browser_version: platformInfo.browserVersion,
1509
- os_name: platformInfo.os,
1510
- os_version: platformInfo.osVersion,
1511
- user_agent: platformInfo.userAgent,
1512
- display_mode: "standalone",
1513
- is_installed: true,
1514
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
1515
- language: navigator.language || "en-US"
1516
- };
1517
- const url = `${this.serviceUrl}/api/v1/registration/install-only`;
1518
- const response = await makeAuthenticatedRequestWithContext(
1519
- this.authContext,
1520
- "POST",
1521
- url,
1522
- installationData,
1523
- this.onTokenExpired
1524
- );
1525
- if (!response.ok) {
1526
- const errorText = await response.text();
1527
- throw new Error(`Installation registration failed: ${response.status} - ${errorText}`);
1528
- }
1529
- const result = await response.json();
1530
- markInstallationRegistered(this.organizationId, this.serviceId, result.registration_id);
1531
- this.log(`Installation registered successfully: ${result.registration_id}`);
1532
- return { registrationId: result.registration_id };
1533
- } catch (error) {
1534
- const err = error instanceof Error ? error : new Error(String(error));
1535
- this.log(`Installation registration failed: ${err.message}`, "error");
1536
- this.onError?.(err);
1537
- return null;
1538
- }
1539
- }
1540
- /**
1541
- * Check if installation is already registered
1542
- */
1543
- isInstallationRegistered() {
1544
- return isInstallationRegistered(this.organizationId, this.serviceId);
1545
- }
1546
- /**
1547
- * Get stored installation registration ID
1548
- */
1549
- getInstallationId() {
1550
- return getStorageItem(`install_id_${this.organizationId}_${this.serviceId}`);
1551
- }
1552
1477
  /**
1553
1478
  * Request notification permission
1554
1479
  */
@@ -1642,7 +1567,7 @@ var HeartbeatManager = class {
1642
1567
  this.onTokenExpired = options.onTokenExpired;
1643
1568
  this.authContext = createAuthContext({
1644
1569
  organizationId: options.organizationId,
1645
- organizationSecret: options.organizationSecret,
1570
+ organizationPublishableKey: options.organizationPublishableKey,
1646
1571
  userToken: options.userToken
1647
1572
  });
1648
1573
  this.config = {
@@ -3079,7 +3004,7 @@ var IOSInstallBanner = class {
3079
3004
 
3080
3005
  // src/CloudSignalPWA.ts
3081
3006
  var DEFAULT_SERVICE_URL = "https://pwa.cloudsignal.app";
3082
- var SDK_VERSION = "1.2.3";
3007
+ var SDK_VERSION = "1.2.0";
3083
3008
  var CloudSignalPWA = class {
3084
3009
  constructor(config) {
3085
3010
  this.initialized = false;
@@ -3093,12 +3018,12 @@ var CloudSignalPWA = class {
3093
3018
  this.config = config;
3094
3019
  this.serviceUrl = config.serviceUrl || DEFAULT_SERVICE_URL;
3095
3020
  this.debug = config.debug ?? false;
3096
- if (!config.organizationSecret && !config.userToken) {
3097
- throw new Error("Either organizationSecret or userToken must be provided");
3021
+ if (!config.organizationPublishableKey && !config.userToken) {
3022
+ throw new Error("Either organizationPublishableKey or userToken must be provided");
3098
3023
  }
3099
3024
  this.authContext = createAuthContext({
3100
3025
  organizationId: config.organizationId,
3101
- organizationSecret: config.organizationSecret,
3026
+ organizationPublishableKey: config.organizationPublishableKey,
3102
3027
  userToken: config.userToken
3103
3028
  });
3104
3029
  this.deviceDetector = new DeviceDetector();
@@ -3119,7 +3044,7 @@ var CloudSignalPWA = class {
3119
3044
  this.pushNotificationManager = new PushNotificationManager({
3120
3045
  serviceUrl: this.serviceUrl,
3121
3046
  organizationId: config.organizationId,
3122
- organizationSecret: config.organizationSecret,
3047
+ organizationPublishableKey: config.organizationPublishableKey,
3123
3048
  userToken: config.userToken,
3124
3049
  onTokenExpired: config.onTokenExpired,
3125
3050
  serviceId: config.serviceId,
@@ -3138,7 +3063,7 @@ var CloudSignalPWA = class {
3138
3063
  this.heartbeatManager = new HeartbeatManager({
3139
3064
  serviceUrl: this.serviceUrl,
3140
3065
  organizationId: config.organizationId,
3141
- organizationSecret: config.organizationSecret,
3066
+ organizationPublishableKey: config.organizationPublishableKey,
3142
3067
  userToken: config.userToken,
3143
3068
  onTokenExpired: config.onTokenExpired,
3144
3069
  config: config.heartbeat,
@@ -3220,20 +3145,11 @@ var CloudSignalPWA = class {
3220
3145
  this.configureNotificationAnalytics(swReg);
3221
3146
  }
3222
3147
  if (this.iosInstallBanner && this.config.iosInstallBanner?.showOnFirstVisit !== false) {
3223
- const installState2 = this.installationManager.getState();
3224
- if (!installState2.isInstalled) {
3148
+ const installState = this.installationManager.getState();
3149
+ if (!installState.isInstalled) {
3225
3150
  this.iosInstallBanner.show();
3226
3151
  }
3227
3152
  }
3228
- const installState = this.installationManager.getState();
3229
- if (installState.isInstalled) {
3230
- this.log("PWA installation detected, registering...");
3231
- const installResult = await this.pushNotificationManager.registerInstallation();
3232
- if (installResult) {
3233
- this.log(`Installation registered: ${installResult.registrationId}`);
3234
- this.emit("install:registered", { registrationId: installResult.registrationId });
3235
- }
3236
- }
3237
3153
  this.initialized = true;
3238
3154
  const result = {
3239
3155
  success: true,