web-manager 4.1.2 → 4.1.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/CLAUDE.md CHANGED
@@ -181,7 +181,7 @@ document.body.addEventListener('click', (e) => {
181
181
  - **loadScript Options**: src, async, defer, crossorigin, integrity, timeout, retries
182
182
 
183
183
  ### Utilities (`utilities.js`)
184
- - **Exports**: `clipboardCopy()`, `escapeHTML()`, `showNotification()`, `getPlatform()`, `getBrowser()`, `getRuntime()`, `isMobile()`, `getDeviceType()`, `getContext()`
184
+ - **Exports**: `clipboardCopy()`, `escapeHTML()`, `showNotification()`, `getPlatform()`, `getBrowser()`, `getRuntime()`, `isMobile()`, `getDevice()`, `getContext()`
185
185
 
186
186
  ## Build System
187
187
 
package/README.md CHANGED
@@ -108,7 +108,7 @@ Web Manager is designed to work in multiple environments:
108
108
  - **Firebase v12 Integration**: Modern Firebase Auth, Firestore, and Cloud Messaging
109
109
  - **Data Binding System**: Reactive DOM updates with `data-wm-bind` attributes
110
110
  - **Storage API**: Enhanced localStorage/sessionStorage with path-based access and JSON serialization
111
- - **Utilities**: `clipboardCopy()`, `escapeHTML()`, `getContext()`, `showNotification()`, `getPlatform()`, `getBrowser()`, `getRuntime()`, `isMobile()`, `getDeviceType()`
111
+ - **Utilities**: `clipboardCopy()`, `escapeHTML()`, `getContext()`, `showNotification()`, `getPlatform()`, `getBrowser()`, `getRuntime()`, `isMobile()`, `getDevice()`
112
112
  - **DOM Utilities**: Dynamic script loading with retry/timeout support
113
113
  - **Service Worker Management**: Registration, messaging, and state tracking
114
114
  - **Push Notifications**: Firebase Cloud Messaging with auto-subscription
@@ -354,6 +354,35 @@ unsubscribe();
354
354
  Add these classes to elements for automatic auth functionality:
355
355
  - `.auth-signout-btn` - Sign out button (shows confirmation dialog)
356
356
 
357
+ **⚠️ Auth State Timing**:
358
+
359
+ On fresh page loads, Firebase Auth needs time to restore the user session from IndexedDB/localStorage. Methods like `auth.isAuthenticated()`, `auth.getUser()`, and `auth.getIdToken()` may return `null`/`false` if called before auth state is determined.
360
+
361
+ **Problem:**
362
+ ```javascript
363
+ // ❌ May fail on page load - auth state not yet determined
364
+ await Manager.dom().ready();
365
+ const token = await auth.getIdToken(); // Could throw if currentUser is null
366
+ ```
367
+
368
+ **Solution:** Use `auth.listen({ once: true })` to wait for auth state:
369
+ ```javascript
370
+ // ✅ Wait for auth state to be determined first
371
+ auth.listen({ once: true }, async (result) => {
372
+ if (result.user) {
373
+ const token = await auth.getIdToken(); // Safe - user is authenticated
374
+ }
375
+ });
376
+ ```
377
+
378
+ **When this matters:**
379
+ - Pages making authenticated API calls immediately on load
380
+ - OAuth callback pages
381
+ - Deep links requiring authentication
382
+
383
+ **When NOT needed:**
384
+ - User-triggered actions (button clicks) - auth state is always determined by then
385
+
357
386
  ### Data Binding System
358
387
 
359
388
  Reactive DOM updates with `data-wm-bind` attributes:
@@ -538,7 +567,7 @@ await notifications.syncSubscription();
538
567
 
539
568
  **Features**:
540
569
  - Stores subscription in localStorage and Firestore
541
- - Tracks device context (platform, runtime, deviceType)
570
+ - Tracks device context (platform, runtime, device)
542
571
  - Auto-requests after configurable delay post-click
543
572
  - Syncs with user authentication state
544
573
 
@@ -663,7 +692,7 @@ import {
663
692
  getBrowser,
664
693
  getRuntime,
665
694
  isMobile,
666
- getDeviceType,
695
+ getDevice,
667
696
  getContext
668
697
  } from 'web-manager/modules/utilities';
669
698
  // Or: const utils = Manager.utilities();
@@ -691,13 +720,13 @@ getBrowser(); // 'chrome', 'firefox', 'safari', 'edge', 'opera', 'brave', null
691
720
  getRuntime(); // 'web', 'browser-extension'
692
721
 
693
722
  // Device detection
694
- isMobile(); // true/false
695
- getDeviceType(); // 'mobile' (<768px), 'tablet' (768-1199px), 'desktop' (>=1200px)
723
+ isMobile(); // true/false
724
+ getDevice(); // 'mobile' (<768px), 'tablet' (768-1199px), 'desktop' (>=1200px)
696
725
 
697
726
  // Full context
698
727
  getContext();
699
728
  // {
700
- // client: { language, mobile, deviceType, platform, browser, vendor, runtime, userAgent, url },
729
+ // client: { language, mobile, device, platform, browser, vendor, runtime, userAgent, url },
701
730
  // geolocation: { ip, country, region, city, latitude, longitude }
702
731
  // }
703
732
  ```
package/dist/index.js CHANGED
@@ -367,8 +367,8 @@ class Manager {
367
367
  // Set runtime - web, browser-extension, electron, node
368
368
  $html.dataset.runtime = this._utilities.getRuntime();
369
369
 
370
- // Set device type - mobile, tablet, desktop
371
- $html.dataset.device = this._utilities.getDeviceType();
370
+ // Set device - mobile, tablet, desktop
371
+ $html.dataset.device = this._utilities.getDevice();
372
372
  }
373
373
 
374
374
  async _initializeFirebase() {
@@ -81,8 +81,8 @@ class Utilities {
81
81
  const timeout = options.timeout !== undefined ? options.timeout : 5000;
82
82
 
83
83
  const $notification = document.createElement('div');
84
- $notification.className = `alert alert-${type} alert-dismissible fade show position-fixed top-0 start-50 translate-middle-x mt-5`;
85
- $notification.style.zIndex = '9999';
84
+ $notification.className = `alert alert-${type} alert-dismissible fade show position-fixed`;
85
+ $notification.style.cssText = 'z-index: 9999; top: 1rem; left: 50%; transform: translateX(-50%);';
86
86
  $notification.innerHTML = `
87
87
  ${text}
88
88
  <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
@@ -137,22 +137,27 @@ class Utilities {
137
137
  if (/edg/i.test(ua)) {
138
138
  return 'edge';
139
139
  }
140
+
140
141
  // Opera before Chrome (Opera includes "Chrome" in UA)
141
142
  if (/opera|opr/i.test(ua)) {
142
143
  return 'opera';
143
144
  }
145
+
144
146
  // Brave before Chrome (Brave includes "Chrome" in UA)
145
147
  if (navigator.brave || /brave/i.test(ua)) {
146
148
  return 'brave';
147
149
  }
150
+
148
151
  // Chrome (including Chromium-based browsers)
149
152
  if (/chrome|chromium|crios/i.test(ua)) {
150
153
  return 'chrome';
151
154
  }
155
+
152
156
  // Firefox
153
157
  if (/firefox|fxios/i.test(ua)) {
154
158
  return 'firefox';
155
159
  }
160
+
156
161
  // Safari last (most browsers include "Safari" in UA)
157
162
  if (/safari/i.test(ua)) {
158
163
  return 'safari';
@@ -202,8 +207,8 @@ class Utilities {
202
207
  }
203
208
  }
204
209
 
205
- // Get device type based on screen width
206
- getDeviceType() {
210
+ // Get device based on screen width
211
+ getDevice() {
207
212
  const width = window.innerWidth;
208
213
 
209
214
  // Mobile: < 768px (Bootstrap's md breakpoint)
@@ -227,7 +232,7 @@ class Utilities {
227
232
  client: {
228
233
  language: navigator.language,
229
234
  mobile: this.isMobile(),
230
- deviceType: this.getDeviceType(),
235
+ device: this.getDevice(),
231
236
  platform: this.getPlatform(),
232
237
  browser: this.getBrowser(),
233
238
  vendor: navigator.vendor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",