@uniweb/core 0.10.1 → 0.10.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "vitest": "^4.1.7"
41
41
  },
42
42
  "dependencies": {
43
- "@uniweb/semantic-parser": "^1.2.3",
44
- "@uniweb/theming": "^0.1.15"
43
+ "@uniweb/theming": "^0.1.15",
44
+ "@uniweb/semantic-parser": "^1.2.3"
45
45
  },
46
46
  "scripts": {
47
47
  "test": "vitest run"
package/src/page.js CHANGED
@@ -48,13 +48,24 @@ export default class Page {
48
48
  // Rewrite target (if set, this route is served by an external site)
49
49
  this.rewrite = pageData.rewrite || null
50
50
 
51
- // Opt this page into section-level instrumentation (`trackSections` in
52
- // page.yml). Off by default, and PAGE-LEVEL ONLY — there is deliberately no
53
- // site-wide or folder-level spelling, because one event per section on every
54
- // page of a site produces far more distinct values than an analytics
55
- // consumer can reasonably retain. The runtime reads it to decide whether to
56
- // arm an observer; it means nothing without a tracking destination.
57
- this.trackSections = pageData.trackSections || false
51
+ // This page's answer on section-level instrumentation (`trackSections` in
52
+ // page.yml) an OVERRIDE, not a switch.
53
+ //
54
+ // **Three states, and the third is the point.** `undefined` means the page
55
+ // said nothing and the site's own `tracking.emit` decides; `true` and
56
+ // `false` override it in either direction, so an owner can instrument one
57
+ // page of a quiet site or exempt a noisy page of a loud one.
58
+ //
59
+ // ⛔ **`|| false` was wrong here and collapsed the tri-state**, which made
60
+ // page-level the ONLY spelling and forced every owner to tick pages
61
+ // individually. The wire already carried all three — `content-collector`
62
+ // emits the key only when it is `!= null` — so nothing but this line had to
63
+ // change. ⇒ Read `?? undefined`, never a boolean coercion.
64
+ //
65
+ // The runtime passes it to `Tracker.arms('section_view', …)`, which is where
66
+ // the precedence against the host's own list is resolved. It means nothing
67
+ // without a tracking destination.
68
+ this.trackSections = pageData.trackSections ?? undefined
58
69
 
59
70
  // Two orthogonal visibility axes:
60
71
  // • `hidden` — REACHABILITY. When true the page is excluded from the published
package/src/tracker.js CHANGED
@@ -207,6 +207,17 @@ export default class Tracker {
207
207
  // reports three times.
208
208
  this.currentPath = null
209
209
 
210
+ // What the runtime may ARM, as two independent narrowings. Both are `null`
211
+ // when nothing narrows, which is the common case and the cheap one.
212
+ //
213
+ // ⛔ **Neither ever filters `track()`.** The registry is open by design, and
214
+ // a client-side allowlist over a foundation's own events would export one
215
+ // host's policy onto every host — including hosts that sent no list, whose
216
+ // sites would silently drop everything their foundation emits. These gate
217
+ // the runtime's OWN emissions and nothing else. See `arms()`.
218
+ this.hostEvents = options.hostEvents ? new Set(options.hostEvents) : null
219
+ this.siteEmit = options.siteEmit ? new Set(options.siteEmit) : null
220
+
210
221
  this.framed = detectFramed()
211
222
 
212
223
  // Called once when consent moves to granted, and never otherwise. The
@@ -259,6 +270,39 @@ export default class Tracker {
259
270
  return !!this.endpoint && this.isLiveDocument()
260
271
  }
261
272
 
273
+ /**
274
+ * Whether the runtime should ARM one of its own automatic emitters.
275
+ *
276
+ * ⭐ **Three questions, in the order that makes each one's absence safe:**
277
+ *
278
+ * 1. **Is there anywhere to send, in a live document?** — `isEnabled()`.
279
+ * 2. **Will the host consume this?** `hostEvents` is the host's cost switch:
280
+ * no point arming an observer for a row nobody stores. ⛔ **Absent means NO
281
+ * NARROWING, never an empty set** — a host that sends no list is an older
282
+ * or simpler one, and reading absence as "consume nothing" would take
283
+ * every site on that host dark with every gate reading yes.
284
+ * 3. **Did the site ask for it?** `siteEmit` is the operator's own selection.
285
+ * Absent means everything.
286
+ *
287
+ * `override` is the per-page answer where one exists (`page.trackSections`).
288
+ * It replaces the SITE's answer and cannot escape the host's: a page may
289
+ * widen what its own site configured, and may not conjure a row the host
290
+ * declined to store.
291
+ *
292
+ * ⛔ **Not consulted by `track()`.** A foundation's events are never gated —
293
+ * see the constructor.
294
+ *
295
+ * @param {string} event
296
+ * @param {boolean} [override] - the per-page decision, when the caller has one
297
+ * @returns {boolean}
298
+ */
299
+ arms(event, override) {
300
+ if (!this.isEnabled()) return false
301
+ if (this.hostEvents && !this.hostEvents.has(event)) return false
302
+ if (override != null) return !!override
303
+ return !this.siteEmit || this.siteEmit.has(event)
304
+ }
305
+
262
306
  /** @returns {'granted'|'denied'|'pending'} */
263
307
  consentStatus() {
264
308
  return this.consent
@@ -333,7 +377,7 @@ export default class Tracker {
333
377
  * @param {string} path
334
378
  */
335
379
  trackPageView(path) {
336
- if (!this.isEnabled() || !path) return
380
+ if (!this.arms('page_view') || !path) return
337
381
  if (path === this.currentPath) return
338
382
  this.currentPath = path
339
383
  // Promptly, rather than waiting out the batch window: a page view is the