web-manager 4.1.35 → 4.1.37

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 CHANGED
@@ -14,6 +14,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
14
14
  - `Fixed` for any bug fixes.
15
15
  - `Security` in case of vulnerabilities.
16
16
 
17
+ ---
18
+ ## [4.1.37] - 2026-04-05
19
+ ### Added
20
+ - Added `_resolveUsage()` to auth module that merges account usage data with plan limits from config, exposed as a top-level `usage` binding context.
21
+ - Added `payment.processors` and `payment.plans` defaults to configuration.
22
+
23
+ ## [4.1.36] - 2026-04-02
24
+ ### Fixed
25
+ - Fixed mocha binary path preventing `npm test` from running.
26
+ - Fixed lodash ESM named import incompatibility with Node.js (`storage.js`).
27
+ - Fixed test suite calling nonexistent API methods (`init` → `initialize`, `storage('local')` → `storage()`).
28
+ - Fixed mocha hanging after tests due to `setInterval` in version checker (added `--exit` flag).
29
+
30
+ ### Changed
31
+ - Enhanced `escapeHTML` to recursively handle objects, arrays, and pass through non-string types.
32
+ - Rewrote `showNotification` to use safe DOM construction (`textContent`) instead of `innerHTML`.
33
+ - Split monolithic `test.js` into 8 modular test files under `test/tests/`.
34
+ - Expanded test coverage from ~10 broken tests to 70 passing tests.
35
+
36
+ ### Security
37
+ - Blocked `javascript:` protocol in `@attr` bindings for URL attributes (`href`, `src`, `action`, `formaction`).
38
+
39
+ ---
40
+ ## [4.1.35] - 2026-04-02
41
+ ### Changed
42
+ - Bumped `chatsy` from `^2.0.13` to `^2.0.14`.
43
+
17
44
  ---
18
45
  ## [4.1.34] - 2026-04-01
19
46
  ### Changed
package/dist/index.js CHANGED
@@ -296,6 +296,10 @@ class Manager {
296
296
  FIREBASE_EMULATOR_CONNECT: false,
297
297
  },
298
298
  validRedirectHosts: [],
299
+ payment: {
300
+ processors: {},
301
+ plans: [],
302
+ },
299
303
 
300
304
  // Non-configurable defaults
301
305
  refreshNewVersion: {
@@ -164,8 +164,12 @@ class Auth {
164
164
 
165
165
  // Update bindings and storage once per auth state change
166
166
  if (!this._hasProcessedStateChange) {
167
- this.manager.bindings().update({ auth: state });
167
+ this.manager.bindings().update({
168
+ auth: state,
169
+ usage: this._resolveUsage(state),
170
+ });
168
171
  this.manager.storage().set('auth', state);
172
+
169
173
  this._hasProcessedStateChange = true;
170
174
  }
171
175
 
@@ -252,6 +256,29 @@ class Auth {
252
256
  };
253
257
  }
254
258
 
259
+ // Resolve usage bindings from account data + plan limits from config.
260
+ // Returns: { credits: { monthly: 5, limit: 100 }, ... }
261
+ _resolveUsage(state) {
262
+ const accountUsage = state.account?.usage || {};
263
+ const plan = state.resolved?.plan || 'basic';
264
+ const plans = this.manager.config.payment?.plans || [];
265
+ const planConfig = plans.find(p => p.id === plan) || {};
266
+ const limits = planConfig.limits || {};
267
+
268
+ // Merge current usage with limits for each feature
269
+ const usage = {};
270
+ const keys = new Set([...Object.keys(accountUsage), ...Object.keys(limits)]);
271
+
272
+ for (const key of keys) {
273
+ usage[key] = {
274
+ ...(accountUsage[key] || {}),
275
+ limit: limits[key] || 0,
276
+ };
277
+ }
278
+
279
+ return usage;
280
+ }
281
+
255
282
  // Get ID token for the current user
256
283
  async getIdToken(forceRefresh = false) {
257
284
  try {
@@ -150,6 +150,14 @@ class Bindings {
150
150
  const attrValue = this._resolvePath(context, attrExpression) || '';
151
151
 
152
152
  if (attrValue) {
153
+ // Block javascript: protocol on URL attributes to prevent XSS
154
+ const URL_ATTRS = ['href', 'src', 'action', 'formaction'];
155
+ if (URL_ATTRS.includes(attrName.toLowerCase())
156
+ && /^\s*javascript\s*:/i.test(String(attrValue))) {
157
+ console.warn(`[Bindings] Blocked javascript: URL in @attr ${attrName}`);
158
+ return true;
159
+ }
160
+
153
161
  element.setAttribute(attrName, attrValue);
154
162
  } else {
155
163
  element.removeAttribute(attrName);
@@ -1,4 +1,5 @@
1
- import { get as _get, set as _set } from 'lodash';
1
+ import lodash from 'lodash';
2
+ const { get: _get, set: _set } = lodash;
2
3
 
3
4
  class Storage {
4
5
  constructor() {
@@ -37,26 +37,48 @@ class Utilities {
37
37
  }
38
38
 
39
39
  // Escape HTML to prevent XSS
40
- escapeHTML(str) {
41
- if (typeof str !== 'string') {
42
- return '';
40
+ // Accepts a string, object, or array — walks recursively, escaping all string values
41
+ escapeHTML(input) {
42
+ // Strings — escape and return
43
+ if (typeof input === 'string') {
44
+ this._shadowElement = this._shadowElement || document.createElement('p');
45
+ this._shadowElement.innerHTML = '';
46
+
47
+ // This automatically escapes HTML entities like <, >, &, etc.
48
+ this._shadowElement.appendChild(document.createTextNode(input));
49
+
50
+ // This is needed to escape quotes to prevent attribute injection
51
+ return this._shadowElement.innerHTML.replace(/["']/g, (m) => {
52
+ switch (m) {
53
+ case '"':
54
+ return '&quot;';
55
+ default:
56
+ return '&#039;';
57
+ }
58
+ });
43
59
  }
44
60
 
45
- this._shadowElement = this._shadowElement || document.createElement('p');
46
- this._shadowElement.innerHTML = '';
61
+ // Null/undefined pass through
62
+ if (input == null) {
63
+ return input;
64
+ }
47
65
 
48
- // This automatically escapes HTML entities like <, >, &, etc.
49
- this._shadowElement.appendChild(document.createTextNode(str));
66
+ // Arrays recurse each item
67
+ if (Array.isArray(input)) {
68
+ return input.map(item => this.escapeHTML(item));
69
+ }
50
70
 
51
- // This is needed to escape quotes to prevent attribute injection
52
- return this._shadowElement.innerHTML.replace(/["']/g, (m) => {
53
- switch (m) {
54
- case '"':
55
- return '&quot;';
56
- default:
57
- return '&#039;';
71
+ // Objects shallow clone, recurse each value
72
+ if (typeof input === 'object') {
73
+ const result = {};
74
+ for (const [key, value] of Object.entries(input)) {
75
+ result[key] = this.escapeHTML(value);
58
76
  }
59
- });
77
+ return result;
78
+ }
79
+
80
+ // Numbers, booleans, etc. — pass through unchanged
81
+ return input;
60
82
  }
61
83
 
62
84
  // Show notification
@@ -83,10 +105,17 @@ class Utilities {
83
105
  const $notification = document.createElement('div');
84
106
  $notification.className = `alert alert-${type} alert-dismissible fade show position-fixed`;
85
107
  $notification.style.cssText = 'z-index: 9999; top: 1rem; left: 50%; transform: translateX(-50%);';
86
- $notification.innerHTML = `
87
- ${text}
88
- <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
89
- `;
108
+
109
+ const $text = document.createElement('span');
110
+ $text.textContent = text;
111
+
112
+ const $closeBtn = document.createElement('button');
113
+ $closeBtn.type = 'button';
114
+ $closeBtn.className = 'btn-close';
115
+ $closeBtn.setAttribute('data-bs-dismiss', 'alert');
116
+
117
+ $notification.appendChild($text);
118
+ $notification.appendChild($closeBtn);
90
119
 
91
120
  document.body.appendChild($notification);
92
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "4.1.35",
3
+ "version": "4.1.37",
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",
@@ -11,8 +11,7 @@
11
11
  },
12
12
  "scripts": {
13
13
  "start": "npm run prepare:watch",
14
- "test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
15
- "test_": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
14
+ "test": "npm run prepare && mocha --require ./test/setup.js --require ./test/helpers.js 'test/tests/**/*.test.js' --timeout=10000 --exit",
16
15
  "prepare_": "node -e 'require(`prepare-package`)()'",
17
16
  "prepare": "node -e \"require('prepare-package')()\"",
18
17
  "prepare:watch": "node -e \"require('prepare-package/watch')()\""