@uniweb/core 1.6.1 → 1.6.3

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": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,8 +53,8 @@
53
53
  "vitest": "^4.1.7"
54
54
  },
55
55
  "dependencies": {
56
- "@uniweb/semantic-parser": "~1.13.2",
57
- "@uniweb/theming": "~1.2.1"
56
+ "@uniweb/theming": "~1.2.1",
57
+ "@uniweb/semantic-parser": "~1.13.2"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest run"
@@ -21,7 +21,7 @@
21
21
  * @module @uniweb/core/resolve-route
22
22
  */
23
23
 
24
- import { decodeRouteValue, matchDynamicRoute, parentRouteOf } from './route-match.js'
24
+ import { decodeRouteValue, isDynamicRoute, matchDynamicRoute, parentRouteOf } from './route-match.js'
25
25
  import { resolveDefaultLocale } from './locale-config.js'
26
26
  import { siteAddress } from './site-address.js'
27
27
 
@@ -313,7 +313,7 @@ function findPage(index, path, { activeLocale, defaultLocale }) {
313
313
 
314
314
  for (const candidate of new Set([canonical, asGiven, shown])) {
315
315
  for (const page of index.pages) {
316
- if (!page.route.includes(':')) continue
316
+ if (!isDynamicRoute(page.route)) continue
317
317
  const hit = matchDynamicRoute(page.route, candidate)
318
318
  if (hit) return { page, route: candidate, params: hit.params, template: page.route }
319
319
  }
@@ -11,10 +11,9 @@
11
11
  * question, neither wrong on the routes anyone had tried.
12
12
  *
13
13
  * That is already bad inside one repo. It is worse across them, because the
14
- * matcher answers a question more than one lane asks: *which page does this
15
- * path name?* A consumer outside this repo routes with these patterns —
16
- * `hosting/framework-surface.json` declares `routePatternToRegex`,
17
- * `isDynamicRoute` and `normalizeRoute` read by its `src/routes.js`. Two copies
14
+ * matcher answers a question more than one program asks: *which page does this
15
+ * path name?* A host that serves a site asks it too, before it renders anything,
16
+ * which is why this leaf can be imported on its own. Two copies
18
17
  * that disagree by a single route give two answers to page identity, silently,
19
18
  * and only on the paths that have a pattern — which are exactly the interesting
20
19
  * ones. So this is a cross-boundary contract, not an implementation detail, and
@@ -33,7 +32,10 @@
33
32
  *
34
33
  * ## The syntax, in full
35
34
  *
36
- * `:param` captures exactly one non-empty path segment. `:param*` — the ONE
35
+ * `:param` captures exactly one non-empty path segment, and starts it: literal
36
+ * text may follow the name in its segment (`/files/:name.json`), while a `:`
37
+ * anywhere else in a segment is the character itself (`/Note:-a-thing` is a page,
38
+ * not a pattern). `:param*` — the ONE
37
39
  * multi-segment construct, admitted 2026-09-04 by ruling [Diego] for the
38
40
  * `[...path]` route folder — captures one or more segments, slashes intact, and
39
41
  * only as the FINAL segment of a pattern; anywhere else the `*` is the literal it
@@ -84,13 +86,27 @@ export function normalizeRoute(route) {
84
86
  }
85
87
 
86
88
  /**
87
- * Whether a route is a dynamic template rather than a concrete path.
89
+ * A parameter, wherever a pattern may hold one: `:name` at the START of a segment.
90
+ * Literal text may follow the name in that segment (`/files/:name.json`), and a `:`
91
+ * anywhere else in a segment is the character itself. `lead` is what precedes the
92
+ * `:`, a `/` or the start of the pattern, kept by whoever replaces the parameter.
93
+ */
94
+ const PARAM_SOURCE = `(^|/):(${PARAM_NAME})`
95
+
96
+ /**
97
+ * Whether a route is a dynamic template rather than a concrete path: whether one
98
+ * of its segments starts with a parameter (`/blog/:slug`, `/files/:name.json`,
99
+ * `/docs/:path*`).
100
+ *
101
+ * A route is plain text, so a `:` an author typed into a slug is text too:
102
+ * `/Note:-a-thing` is a page. Until 2026-11-02 this asked whether a route held a
103
+ * `:` at all, so that page left every menu and `/Noteabc` resolved to it.
88
104
  *
89
105
  * @param {string} route
90
106
  * @returns {boolean}
91
107
  */
92
108
  export function isDynamicRoute(route) {
93
- return typeof route === 'string' && route.includes(':')
109
+ return typeof route === 'string' && new RegExp(PARAM_SOURCE).test(route)
94
110
  }
95
111
 
96
112
  /** The catch-all token, only as a pattern's final segment: `/:path*`. */
@@ -123,10 +139,10 @@ export function routePatternToRegex(pattern) {
123
139
  let source = head
124
140
  // Escape first: a `.` in a route is a literal `.`, not "any character".
125
141
  .replace(REGEX_SPECIALS, '\\$&')
126
- // Then each `:name` becomes one non-empty segment capture.
127
- .replace(new RegExp(`:(${PARAM_NAME})`, 'g'), (_, name) => {
142
+ // Then each `:name` that starts a segment becomes one non-empty segment capture.
143
+ .replace(new RegExp(PARAM_SOURCE, 'g'), (_, lead, name) => {
128
144
  paramNames.push(name)
129
- return '([^/]+)'
145
+ return `${lead}([^/]+)`
130
146
  })
131
147
  if (catchAll) {
132
148
  paramNames.push(catchAll)
@@ -557,7 +573,7 @@ export function parentRouteOf(route, { declared = null, has } = {}) {
557
573
  * when its route ENDS in a parameter. ⛔ A page nested inside a parametric one —
558
574
  * `/members/:slug/cv` — does not, and returns null: composing a record onto it would
559
575
  * produce `/members/:slug/alice`, a URL that ranks in an index and 404s on click
560
- * (the failure hosting measured in their own fixture, 2026-09-12). A static page
576
+ * (the failure a host measured in its own fixture, 2026-09-12). A static page
561
577
  * returns null too, so a page that merely fetches to render itself contributes
562
578
  * nothing to a record index.
563
579
  *
@@ -623,16 +639,16 @@ export function fillRoutePattern(pattern, values, { field = null } = {}) {
623
639
  tailHref = '/' + encodeURIComponent(String(handle))
624
640
  head = pattern.slice(0, tail.index)
625
641
  }
626
- const href = head.replace(new RegExp(`:(${PARAM_NAME})`, 'g'), (_, name) => {
642
+ const href = head.replace(new RegExp(PARAM_SOURCE, 'g'), (_, lead, name) => {
627
643
  // ⭐ THE FIRST MEMBER of a `multi` field — a record has ONE canonical href, and
628
644
  // every member routes to it (`routeParamValues`). Baked whole, a `['a','b']`
629
645
  // field produced `/tags/a%2Cb`, a URL no lane matches.
630
646
  const [value] = routeParamValues(values, name, name === 'slug' ? field : null)
631
647
  if (value === undefined) {
632
648
  missing = true
633
- return ''
649
+ return lead
634
650
  }
635
- return encodeURIComponent(value)
651
+ return lead + encodeURIComponent(value)
636
652
  })
637
653
  return missing ? null : href + tailHref
638
654
  }
package/src/tracker.js CHANGED
@@ -162,6 +162,36 @@ function captureAcquisition() {
162
162
  return Object.keys(context).length > 0 ? context : null
163
163
  }
164
164
 
165
+ /**
166
+ * The landing address's values for the query keys a conversion carries, read once at construction.
167
+ *
168
+ * ⭐ **The keys are named by whoever collects, never by this file** — `tracking.landing`, a host's
169
+ * or a site's own. Which campaign keys and which ad-platform click IDs matter is a collector's
170
+ * business, and the list grows with the platforms it sends to; a list held here would name vendors
171
+ * in a public package and need a release for each [framework, answering hosting, 2026-11-03].
172
+ *
173
+ * ⛔ Only the keys named, only from the address the visitor arrived at, held for this document and
174
+ * sent only on `conversion` — the event whose attribution otherwise depends on a collector joining
175
+ * it to the arrival. A query can carry a search term or a token, so nothing unnamed is read.
176
+ *
177
+ * Called only for an enabled tracker in a browser, so it checks neither. Every site loads this
178
+ * file, so it is as small as it can be read: no keys, or none on the address, is `null`.
179
+ *
180
+ * @param {string[]} [keys]
181
+ * @returns {Object<string, string>|null}
182
+ */
183
+ function captureLanding(keys) {
184
+ let landing = null
185
+ if (Array.isArray(keys)) {
186
+ const params = new URLSearchParams(window.location.search)
187
+ for (const key of keys) {
188
+ const value = typeof key === 'string' && params.get(key)
189
+ if (value) (landing ||= {})[key] = value
190
+ }
191
+ }
192
+ return landing
193
+ }
194
+
165
195
  /**
166
196
  * An opaque key for one document lifetime. Never stored, never persisted.
167
197
  *
@@ -199,6 +229,8 @@ export default class Tracker {
199
229
  * @param {number} [options.flushIntervalMs=5000] - batch window, MILLISECONDS
200
230
  * @param {number} [options.maxQueueSize=10]
201
231
  * @param {boolean} [options.debug=false]
232
+ * @param {string[]} [options.landing] - query keys of the landing address each `conversion`
233
+ * carries, as `landing: { key: value }`; see `captureLanding`
202
234
  */
203
235
  constructor(options = {}) {
204
236
  this.endpoint = options.endpoint || null
@@ -232,6 +264,8 @@ export default class Tracker {
232
264
 
233
265
  this.queue = []
234
266
  this.acquisition = null
267
+ // What a conversion carries of the landing address, when a collector named keys.
268
+ this.landing = null
235
269
 
236
270
  // One key per document, minted only when there is somewhere to send it.
237
271
  // Rides the ENVELOPE beside `event` rather than inside a payload, because
@@ -295,6 +329,7 @@ export default class Tracker {
295
329
 
296
330
  if (isBrowser && this.isEnabled()) {
297
331
  this.acquisition = captureAcquisition()
332
+ this.landing = captureLanding(options.landing)
298
333
  // Minted even when consent is pending: events buffered before the visitor
299
334
  // answers must carry the SAME key as those after it, or granting consent
300
335
  // would split one visit in two. It never leaves the device until the
@@ -424,6 +459,11 @@ export default class Tracker {
424
459
  /**
425
460
  * Report an event.
426
461
  *
462
+ * A `conversion` also carries `landing`, the landing address's values for the keys a
463
+ * collector named (`captureLanding`), so its attribution survives navigation without the
464
+ * collector joining it to the arrival. Set after the caller's fields: it is this page
465
+ * load's fact, not a caller's.
466
+ *
427
467
  * @param {string} event - event name, e.g. 'video_milestone'. Open registry.
428
468
  * @param {Object} [data] - the caller's own fields; `path` overrides the
429
469
  * current route, which is what block-scoped callers supply.
@@ -431,7 +471,8 @@ export default class Tracker {
431
471
  track(event, data = {}) {
432
472
  if (!this.isEnabled() || !event) return
433
473
  const { path, ...rest } = data
434
- this.enqueue({ event, path: path || this.currentPath || undefined, ...rest })
474
+ const landing = event === 'conversion' && this.landing ? { landing: this.landing } : null
475
+ this.enqueue({ event, path: path || this.currentPath || undefined, ...rest, ...landing })
435
476
  }
436
477
 
437
478
  /**
package/src/website.js CHANGED
@@ -12,7 +12,7 @@ import ObservableState from './observable-state.js'
12
12
  import { normalizeSeo } from './seo.js'
13
13
  import { siteAddress, pageUrl } from './site-address.js'
14
14
  import { resolveDefaultLocale, localeLabel } from './locale-config.js'
15
- import { matchDynamicRoute, recordTitle, recordImage, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
15
+ import { isDynamicRoute, matchDynamicRoute, recordTitle, recordImage, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
16
16
  import { resolveFetchConfigs, pageRouteQuery, recordPages } from './fetch-config.js'
17
17
  import { declaredKeys } from './data-keys.js'
18
18
  import { pageRecordConfig, planFor, runPlanSync } from './page-data.js'
@@ -179,7 +179,7 @@ export default class Website {
179
179
  // materialize concrete pages on demand (/blog/:slug → /blog/my-post).
180
180
  this._dynamicPageData = new Map()
181
181
  for (const pageData of regularPages) {
182
- if (pageData.isDynamic || pageData.route?.includes(':')) {
182
+ if (pageData.isDynamic || isDynamicRoute(pageData.route)) {
183
183
  this._dynamicPageData.set(pageData.route, pageData)
184
184
  }
185
185
  }
@@ -1399,7 +1399,7 @@ export default class Website {
1399
1399
  const isPageVisible = (page) => {
1400
1400
  // Always exclude dynamic route template pages (e.g., /blog/:slug)
1401
1401
  // These are templates for generating pages, not actual navigable pages
1402
- if (page.route.includes(':')) return false
1402
+ if (isDynamicRoute(page.route)) return false
1403
1403
 
1404
1404
  // ⭐ And the pages made from one — a record's own page (/blog/my-post). The SPA keeps
1405
1405
  // those out of `this.pages` (`_dynamicPageCache`), but a static build expands them into