@cloudsignal/pwa-sdk 1.2.2 → 1.2.4
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/CHANGELOG.md +32 -0
- package/README.md +502 -38
- package/dist/index.cjs +87 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.global.js +4 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +87 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1029,6 +1029,15 @@ 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
|
+
}
|
|
1032
1041
|
var IndexedDBStorage = class {
|
|
1033
1042
|
constructor(dbName = "CloudSignalPWA", dbVersion = 1) {
|
|
1034
1043
|
this.db = null;
|
|
@@ -1474,6 +1483,72 @@ var PushNotificationManager = class {
|
|
|
1474
1483
|
return null;
|
|
1475
1484
|
}
|
|
1476
1485
|
}
|
|
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
|
+
}
|
|
1477
1552
|
/**
|
|
1478
1553
|
* Request notification permission
|
|
1479
1554
|
*/
|
|
@@ -3004,7 +3079,7 @@ var IOSInstallBanner = class {
|
|
|
3004
3079
|
|
|
3005
3080
|
// src/CloudSignalPWA.ts
|
|
3006
3081
|
var DEFAULT_SERVICE_URL = "https://pwa.cloudsignal.app";
|
|
3007
|
-
var SDK_VERSION = "1.2.
|
|
3082
|
+
var SDK_VERSION = "1.2.3";
|
|
3008
3083
|
var CloudSignalPWA = class {
|
|
3009
3084
|
constructor(config) {
|
|
3010
3085
|
this.initialized = false;
|
|
@@ -3145,11 +3220,20 @@ var CloudSignalPWA = class {
|
|
|
3145
3220
|
this.configureNotificationAnalytics(swReg);
|
|
3146
3221
|
}
|
|
3147
3222
|
if (this.iosInstallBanner && this.config.iosInstallBanner?.showOnFirstVisit !== false) {
|
|
3148
|
-
const
|
|
3149
|
-
if (!
|
|
3223
|
+
const installState2 = this.installationManager.getState();
|
|
3224
|
+
if (!installState2.isInstalled) {
|
|
3150
3225
|
this.iosInstallBanner.show();
|
|
3151
3226
|
}
|
|
3152
3227
|
}
|
|
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
|
+
}
|
|
3153
3237
|
this.initialized = true;
|
|
3154
3238
|
const result = {
|
|
3155
3239
|
success: true,
|