@propknot/shared-ui 1.0.2 → 1.0.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/dist/index.js CHANGED
@@ -14457,6 +14457,7 @@ __export(index_exports, {
14457
14457
  SocketProvider: () => SocketProvider,
14458
14458
  TenantLayout: () => TenantLayout_default,
14459
14459
  TenantThemeProvider: () => TenantThemeProvider,
14460
+ api: () => api,
14460
14461
  auditNotifications: () => auditNotifications,
14461
14462
  createContrastEnhancedComponents: () => createContrastEnhancedComponents,
14462
14463
  createNotificationAwareAPI: () => createNotificationAwareAPI,
@@ -14496,7 +14497,9 @@ __export(index_exports, {
14496
14497
  setToastContext: () => setToastContext,
14497
14498
  showLocalNotification: () => showLocalNotification,
14498
14499
  showMessageNotification: () => showMessageNotification,
14500
+ subscribeToPushNotifications: () => subscribeToPushNotifications2,
14499
14501
  testNotificationCoverage: () => testNotificationCoverage,
14502
+ unsubscribeFromPushNotifications: () => unsubscribeFromPushNotifications,
14500
14503
  useAccessibleColors: () => useAccessibleColors,
14501
14504
  useAuth: () => useAuth,
14502
14505
  useContrastText: () => useContrastText,
@@ -19034,6 +19037,84 @@ var getNotificationPermission = () => {
19034
19037
  }
19035
19038
  return Notification.permission;
19036
19039
  };
19040
+ var urlBase64ToUint8Array = (base64String) => {
19041
+ const padding = "=".repeat((4 - base64String.length % 4) % 4);
19042
+ const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
19043
+ const rawData = window.atob(base64);
19044
+ const outputArray = new Uint8Array(rawData.length);
19045
+ for (let i = 0; i < rawData.length; ++i) {
19046
+ outputArray[i] = rawData.charCodeAt(i);
19047
+ }
19048
+ return outputArray;
19049
+ };
19050
+ var subscribeToPushNotifications2 = async () => {
19051
+ if (!isPushNotificationSupported()) {
19052
+ throw new Error("Push notifications are not supported");
19053
+ }
19054
+ if (Notification.permission !== "granted") {
19055
+ throw new Error("Notification permission not granted");
19056
+ }
19057
+ try {
19058
+ const existingRegistrations = await navigator.serviceWorker.getRegistrations();
19059
+ for (let registration2 of existingRegistrations) {
19060
+ await registration2.unregister();
19061
+ }
19062
+ const registration = await navigator.serviceWorker.register("/sw.js", {
19063
+ scope: "/",
19064
+ updateViaCache: "none"
19065
+ // Don't cache the service worker
19066
+ });
19067
+ await navigator.serviceWorker.ready;
19068
+ let subscription = await registration.pushManager.getSubscription();
19069
+ if (!subscription) {
19070
+ const vapidPublicKey = process.env.REACT_APP_VAPID_PUBLIC_KEY || "BJ2eTitSHPWl9WBAk0F1Drwmv6bQB48aDpM1ilutZcdygYfpbK7ODrlMSzvplaHWVwPtvQ1x-Y2SK2LadSQZ2mc";
19071
+ const subscriptionOptions = {
19072
+ userVisibleOnly: true,
19073
+ applicationServerKey: urlBase64ToUint8Array(vapidPublicKey)
19074
+ };
19075
+ subscription = await registration.pushManager.subscribe(subscriptionOptions);
19076
+ }
19077
+ await api_default.post("/notifications/subscribe", {
19078
+ subscription: subscription.toJSON()
19079
+ });
19080
+ return subscription;
19081
+ } catch (error) {
19082
+ console.error("Error subscribing to push notifications:", error);
19083
+ console.error("Error name:", error.name);
19084
+ console.error("Error message:", error.message);
19085
+ console.error("Error stack:", error.stack);
19086
+ if (error.name === "AbortError") {
19087
+ throw new Error("Push subscription was aborted. This might be due to invalid VAPID keys or browser restrictions.");
19088
+ } else if (error.name === "NotAllowedError") {
19089
+ throw new Error("Push notifications permission was denied by the user.");
19090
+ } else if (error.name === "NotSupportedError") {
19091
+ throw new Error("Push notifications are not supported in this browser.");
19092
+ }
19093
+ throw error;
19094
+ }
19095
+ };
19096
+ var unsubscribeFromPushNotifications = async () => {
19097
+ if (!isPushNotificationSupported()) {
19098
+ return;
19099
+ }
19100
+ try {
19101
+ const registration = await navigator.serviceWorker.getRegistration();
19102
+ if (!registration) {
19103
+ return;
19104
+ }
19105
+ const subscription = await registration.pushManager.getSubscription();
19106
+ if (!subscription) {
19107
+ return;
19108
+ }
19109
+ await subscription.unsubscribe();
19110
+ await api_default.post("/notifications/unsubscribe", {
19111
+ endpoint: subscription.endpoint
19112
+ });
19113
+ } catch (error) {
19114
+ console.error("Error unsubscribing from push notifications:", error);
19115
+ throw error;
19116
+ }
19117
+ };
19037
19118
  var isPushSubscribed = async () => {
19038
19119
  if (!isPushNotificationSupported()) {
19039
19120
  return false;
@@ -19110,6 +19191,7 @@ var isTenantAuthenticated = () => {
19110
19191
  SocketProvider,
19111
19192
  TenantLayout,
19112
19193
  TenantThemeProvider,
19194
+ api,
19113
19195
  auditNotifications,
19114
19196
  createContrastEnhancedComponents,
19115
19197
  createNotificationAwareAPI,
@@ -19149,7 +19231,9 @@ var isTenantAuthenticated = () => {
19149
19231
  setToastContext,
19150
19232
  showLocalNotification,
19151
19233
  showMessageNotification,
19234
+ subscribeToPushNotifications,
19152
19235
  testNotificationCoverage,
19236
+ unsubscribeFromPushNotifications,
19153
19237
  useAccessibleColors,
19154
19238
  useAuth,
19155
19239
  useContrastText,
package/dist/index.mjs CHANGED
@@ -19046,6 +19046,84 @@ var getNotificationPermission = () => {
19046
19046
  }
19047
19047
  return Notification.permission;
19048
19048
  };
19049
+ var urlBase64ToUint8Array = (base64String) => {
19050
+ const padding = "=".repeat((4 - base64String.length % 4) % 4);
19051
+ const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
19052
+ const rawData = window.atob(base64);
19053
+ const outputArray = new Uint8Array(rawData.length);
19054
+ for (let i = 0; i < rawData.length; ++i) {
19055
+ outputArray[i] = rawData.charCodeAt(i);
19056
+ }
19057
+ return outputArray;
19058
+ };
19059
+ var subscribeToPushNotifications2 = async () => {
19060
+ if (!isPushNotificationSupported()) {
19061
+ throw new Error("Push notifications are not supported");
19062
+ }
19063
+ if (Notification.permission !== "granted") {
19064
+ throw new Error("Notification permission not granted");
19065
+ }
19066
+ try {
19067
+ const existingRegistrations = await navigator.serviceWorker.getRegistrations();
19068
+ for (let registration2 of existingRegistrations) {
19069
+ await registration2.unregister();
19070
+ }
19071
+ const registration = await navigator.serviceWorker.register("/sw.js", {
19072
+ scope: "/",
19073
+ updateViaCache: "none"
19074
+ // Don't cache the service worker
19075
+ });
19076
+ await navigator.serviceWorker.ready;
19077
+ let subscription = await registration.pushManager.getSubscription();
19078
+ if (!subscription) {
19079
+ const vapidPublicKey = process.env.REACT_APP_VAPID_PUBLIC_KEY || "BJ2eTitSHPWl9WBAk0F1Drwmv6bQB48aDpM1ilutZcdygYfpbK7ODrlMSzvplaHWVwPtvQ1x-Y2SK2LadSQZ2mc";
19080
+ const subscriptionOptions = {
19081
+ userVisibleOnly: true,
19082
+ applicationServerKey: urlBase64ToUint8Array(vapidPublicKey)
19083
+ };
19084
+ subscription = await registration.pushManager.subscribe(subscriptionOptions);
19085
+ }
19086
+ await api_default.post("/notifications/subscribe", {
19087
+ subscription: subscription.toJSON()
19088
+ });
19089
+ return subscription;
19090
+ } catch (error) {
19091
+ console.error("Error subscribing to push notifications:", error);
19092
+ console.error("Error name:", error.name);
19093
+ console.error("Error message:", error.message);
19094
+ console.error("Error stack:", error.stack);
19095
+ if (error.name === "AbortError") {
19096
+ throw new Error("Push subscription was aborted. This might be due to invalid VAPID keys or browser restrictions.");
19097
+ } else if (error.name === "NotAllowedError") {
19098
+ throw new Error("Push notifications permission was denied by the user.");
19099
+ } else if (error.name === "NotSupportedError") {
19100
+ throw new Error("Push notifications are not supported in this browser.");
19101
+ }
19102
+ throw error;
19103
+ }
19104
+ };
19105
+ var unsubscribeFromPushNotifications = async () => {
19106
+ if (!isPushNotificationSupported()) {
19107
+ return;
19108
+ }
19109
+ try {
19110
+ const registration = await navigator.serviceWorker.getRegistration();
19111
+ if (!registration) {
19112
+ return;
19113
+ }
19114
+ const subscription = await registration.pushManager.getSubscription();
19115
+ if (!subscription) {
19116
+ return;
19117
+ }
19118
+ await subscription.unsubscribe();
19119
+ await api_default.post("/notifications/unsubscribe", {
19120
+ endpoint: subscription.endpoint
19121
+ });
19122
+ } catch (error) {
19123
+ console.error("Error unsubscribing from push notifications:", error);
19124
+ throw error;
19125
+ }
19126
+ };
19049
19127
  var isPushSubscribed = async () => {
19050
19128
  if (!isPushNotificationSupported()) {
19051
19129
  return false;
@@ -19121,6 +19199,7 @@ export {
19121
19199
  SocketProvider,
19122
19200
  TenantLayout_default as TenantLayout,
19123
19201
  TenantThemeProvider,
19202
+ api,
19124
19203
  auditNotifications,
19125
19204
  createContrastEnhancedComponents,
19126
19205
  createNotificationAwareAPI,
@@ -19160,7 +19239,9 @@ export {
19160
19239
  setToastContext,
19161
19240
  showLocalNotification,
19162
19241
  showMessageNotification,
19242
+ subscribeToPushNotifications2 as subscribeToPushNotifications,
19163
19243
  testNotificationCoverage,
19244
+ unsubscribeFromPushNotifications,
19164
19245
  useAccessibleColors,
19165
19246
  useAuth,
19166
19247
  useContrastText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propknot/shared-ui",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "files": [