web-manager 4.3.4 → 4.3.6

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
@@ -99,8 +99,13 @@ class Manager {
99
99
  // convention). Reads flat `firebaseConfig` (BEM/BXM/EM canonical shape) and falls
100
100
  // back to nested `firebase.app.config` (UJM's current `_config.yml` shape).
101
101
  // Once UJM migrates to the flat shape this fallback can be dropped.
102
- if (this._resolveFirebaseConfig()) {
102
+ // Initialize Firebase only when the resolved config can actually boot the
103
+ // SDK — apiKey is mandatory (init without one crashes with auth/invalid-api-key).
104
+ // Configs carrying only projectId/authDomain still resolve for URL derivation.
105
+ if (this._resolveFirebaseConfig()?.apiKey) {
103
106
  await this._initializeFirebase();
107
+ } else {
108
+ console.log('[Firebase] Skipped: config has no apiKey (Firebase-less site or empty framework merge blob)');
104
109
  }
105
110
 
106
111
  // Initialize Sentry if enabled
@@ -394,14 +399,20 @@ class Manager {
394
399
 
395
400
  // Resolve the Firebase web SDK config blob. Flat `firebaseConfig` first (canonical
396
401
  // shape — BEM/BXM/EM), then nested `firebase.app.config` (UJM legacy yaml shape).
397
- // Returns the blob when it has at least one own key, otherwise null.
402
+ // A blob only counts when at least one value is non-empty — framework config merges
403
+ // (e.g. UJM's Jekyll chain) inject all-empty-string blobs into Firebase-less sites,
404
+ // and those must resolve to null (no init, no URL derivation).
398
405
  _resolveFirebaseConfig() {
406
+ const hasValues = (blob) => !!blob
407
+ && typeof blob === 'object'
408
+ && Object.values(blob).some((value) => value);
409
+
399
410
  const flat = this.config.firebaseConfig;
400
- if (flat && typeof flat === 'object' && Object.keys(flat).length > 0) {
411
+ if (hasValues(flat)) {
401
412
  return flat;
402
413
  }
403
414
  const nested = this.config.firebase?.app?.config;
404
- if (nested && typeof nested === 'object' && Object.keys(nested).length > 0) {
415
+ if (hasValues(nested)) {
405
416
  return nested;
406
417
  }
407
418
  return null;
@@ -50,3 +50,10 @@ Manager (index.js)
50
50
  ├── DOM utilities (standalone)
51
51
  └── Utilities (standalone)
52
52
  ```
53
+
54
+ ## Firebase Initialization
55
+
56
+ `initialize(config)` boots Firebase only when a usable web SDK config resolves:
57
+
58
+ - `_resolveFirebaseConfig()` checks the flat `firebaseConfig` blob first (canonical shape — BEM/BXM/EM), then the nested `firebase.app.config` (UJM yaml shape). A blob only counts when **at least one value is non-empty** — framework config merges (e.g. UJM's Jekyll chain) inject all-empty-string blobs into Firebase-less sites, and those resolve to `null` (no init, no URL derivation).
59
+ - Initialization additionally requires a **non-empty `apiKey`** — the SDK cannot boot without one (it crashes the page with `auth/invalid-api-key`). Configs carrying only `projectId`/`authDomain` still resolve so `getFunctionsUrl()`/`getApiUrl()` can derive URLs, but Firebase itself stays uninitialized and the console logs `[Firebase] Skipped: config has no apiKey ...` (same idiom as `[Analytics] Skipped:`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "4.3.4",
3
+ "version": "4.3.6",
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
  "files": [
package/src/index.js CHANGED
@@ -99,8 +99,13 @@ class Manager {
99
99
  // convention). Reads flat `firebaseConfig` (BEM/BXM/EM canonical shape) and falls
100
100
  // back to nested `firebase.app.config` (UJM's current `_config.yml` shape).
101
101
  // Once UJM migrates to the flat shape this fallback can be dropped.
102
- if (this._resolveFirebaseConfig()) {
102
+ // Initialize Firebase only when the resolved config can actually boot the
103
+ // SDK — apiKey is mandatory (init without one crashes with auth/invalid-api-key).
104
+ // Configs carrying only projectId/authDomain still resolve for URL derivation.
105
+ if (this._resolveFirebaseConfig()?.apiKey) {
103
106
  await this._initializeFirebase();
107
+ } else {
108
+ console.log('[Firebase] Skipped: config has no apiKey (Firebase-less site or empty framework merge blob)');
104
109
  }
105
110
 
106
111
  // Initialize Sentry if enabled
@@ -394,14 +399,20 @@ class Manager {
394
399
 
395
400
  // Resolve the Firebase web SDK config blob. Flat `firebaseConfig` first (canonical
396
401
  // shape — BEM/BXM/EM), then nested `firebase.app.config` (UJM legacy yaml shape).
397
- // Returns the blob when it has at least one own key, otherwise null.
402
+ // A blob only counts when at least one value is non-empty — framework config merges
403
+ // (e.g. UJM's Jekyll chain) inject all-empty-string blobs into Firebase-less sites,
404
+ // and those must resolve to null (no init, no URL derivation).
398
405
  _resolveFirebaseConfig() {
406
+ const hasValues = (blob) => !!blob
407
+ && typeof blob === 'object'
408
+ && Object.values(blob).some((value) => value);
409
+
399
410
  const flat = this.config.firebaseConfig;
400
- if (flat && typeof flat === 'object' && Object.keys(flat).length > 0) {
411
+ if (hasValues(flat)) {
401
412
  return flat;
402
413
  }
403
414
  const nested = this.config.firebase?.app?.config;
404
- if (nested && typeof nested === 'object' && Object.keys(nested).length > 0) {
415
+ if (hasValues(nested)) {
405
416
  return nested;
406
417
  }
407
418
  return null;