@uniweb/build 1.15.1 → 1.15.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 +8 -8
- package/src/dev/api-mount.js +4 -2
- package/src/site/content-collector.js +46 -0
- package/src/uwx/folder.js +28 -1
- package/src/uwx/index.js +2 -0
- package/src/uwx/records.js +54 -7
- package/src/uwx/services-request.js +68 -3
- package/src/uwx/site.js +5 -1
- package/src/uwx/sync-store.js +31 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.3",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
-
"@uniweb/content-reader": "~1.5.8",
|
|
60
|
-
"@uniweb/theming": "~1.2.1",
|
|
61
59
|
"@uniweb/projections": "~1.2.11",
|
|
62
|
-
"@uniweb/schemas": "~1.6.7",
|
|
63
60
|
"@uniweb/semantic-parser": "~1.13.2",
|
|
64
|
-
"@uniweb/content-writer": "~1.3.1"
|
|
61
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
62
|
+
"@uniweb/content-reader": "~1.5.8",
|
|
63
|
+
"@uniweb/theming": "~1.2.1",
|
|
64
|
+
"@uniweb/schemas": "~1.6.7"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.4.
|
|
67
|
+
"@uniweb/runtime": "~1.4.4"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@tailwindcss/vite": "^4.0.0",
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
|
-
"@uniweb/
|
|
77
|
-
"@uniweb/
|
|
76
|
+
"@uniweb/runtime": "~1.4.4",
|
|
77
|
+
"@uniweb/core": "~1.6.4"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
package/src/dev/api-mount.js
CHANGED
|
@@ -139,8 +139,10 @@ export function mountDevApi(server, { root }) {
|
|
|
139
139
|
const response = await handler(new Request(new URL(inner, origin), init))
|
|
140
140
|
res.statusCode = response.status
|
|
141
141
|
response.headers.forEach((value, key) => res.setHeader(key, value))
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
// Bytes, never text: a handler may answer an image or a file, and reading it as
|
|
143
|
+
// text decodes it as UTF-8, turning every byte above 127 into U+FFFD.
|
|
144
|
+
const bytes = Buffer.from(await response.arrayBuffer())
|
|
145
|
+
res.end(bytes.length ? bytes : undefined)
|
|
144
146
|
} catch (err) {
|
|
145
147
|
res.statusCode = 500
|
|
146
148
|
res.setHeader('content-type', 'application/json')
|
|
@@ -119,6 +119,48 @@ function extractRouteParam(folderName) {
|
|
|
119
119
|
return match ? match[1] : null
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/** `?` starts a URL's query, `#` its fragment and `%` an escape. */
|
|
123
|
+
const URL_CHARACTER = /[?#%]/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A route holds none of a URL's own characters [Diego, 2026-11-02]. Without them a route goes into
|
|
127
|
+
* a link as it is, whoever writes the link: kit, the runtime, or a foundation's own
|
|
128
|
+
* `href={page.route}`. With one, the page still answered and the links to it broke:
|
|
129
|
+
* `/What-is-this?` was linked as `/What-is-this`, and `/C#-guide` as `/C` and a fragment.
|
|
130
|
+
*
|
|
131
|
+
* Every place a route is made asks this, on a build and on a push: a folder's name
|
|
132
|
+
* (`assertRouteFolder`), a page file's name (`folderModePageFiles`), a page's `slug:`
|
|
133
|
+
* (`buildRouteTranslations`, and the push's `localizeRouteSlugs`) and `site.yml`'s
|
|
134
|
+
* `i18n.routeTranslations` (`collectSiteContent`, and the push's `localizeRouteSlugs`).
|
|
135
|
+
*
|
|
136
|
+
* @param {string} value - the name, slug or route
|
|
137
|
+
* @param {string} what - says where it is, with the value, e.g. "a folder named `faq?`"
|
|
138
|
+
*/
|
|
139
|
+
export function refuseUrlCharacters(value, what) {
|
|
140
|
+
const found = typeof value === 'string' ? value.match(URL_CHARACTER) : null
|
|
141
|
+
if (!found) return
|
|
142
|
+
throw new Error(
|
|
143
|
+
`[uniweb] pages: ${what} holds \`${found[0]}\`, and a route can't hold \`?\`, \`#\` or \`%\`: ` +
|
|
144
|
+
`a URL reads them as its own, so every link to the page would break. Rename it without them.`
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* `site.yml`'s `i18n.routeTranslations`, `{ <locale>: { <canonical route>: <its route there> } }`,
|
|
150
|
+
* refused when a route in it holds `?`, `#` or `%` (`refuseUrlCharacters`).
|
|
151
|
+
*
|
|
152
|
+
* @param {*} map
|
|
153
|
+
*/
|
|
154
|
+
export function refuseUrlCharactersInTranslations(map) {
|
|
155
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) return
|
|
156
|
+
for (const [locale, table] of Object.entries(map)) {
|
|
157
|
+
if (!table || typeof table !== 'object' || Array.isArray(table)) continue
|
|
158
|
+
for (const [canonical, shown] of Object.entries(table)) {
|
|
159
|
+
refuseUrlCharacters(shown, `\`site.yml\`'s \`i18n.routeTranslations.${locale}\` gives ${canonical} the route \`${shown}\`, which`)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
122
164
|
/**
|
|
123
165
|
* Folders the build refuses on a route, ruled 2026-09-11 [Diego]:
|
|
124
166
|
*
|
|
@@ -139,6 +181,7 @@ function extractRouteParam(folderName) {
|
|
|
139
181
|
* @param {string} parentRoute - the route of the folder it sits in
|
|
140
182
|
*/
|
|
141
183
|
function assertRouteFolder(name, parentRoute) {
|
|
184
|
+
refuseUrlCharacters(name, `a folder named \`${name}\``)
|
|
142
185
|
if (name === '[dir]' || name === '[path]') {
|
|
143
186
|
const hint = name === '[path]' ? ' Did you mean `[...path]`, which captures a path of any depth?' : ''
|
|
144
187
|
throw new Error(
|
|
@@ -743,6 +786,7 @@ export function layerMountedFolder(name, local, mounted, contentMode) {
|
|
|
743
786
|
export function folderModePageFiles(entries, orderConfig) {
|
|
744
787
|
const items = entries.filter(isMarkdownFile).sort(compareFilenames).map((file) => {
|
|
745
788
|
const { name } = parse(file)
|
|
789
|
+
refuseUrlCharacters(name, `a page file named \`${file}\``)
|
|
746
790
|
return { file, name: parseNumericPrefix(name).name || name }
|
|
747
791
|
})
|
|
748
792
|
const parsed = Array.isArray(orderConfig?.pages) ? parseWildcardArray(orderConfig.pages) : null
|
|
@@ -2812,6 +2856,7 @@ export async function collectSiteContent(sitePath, options = {}) {
|
|
|
2812
2856
|
// keeps the canonical (folder-based) route. Strip the build-time `slug` from
|
|
2813
2857
|
// pages afterward — the runtime hydrates the precomputed map, not per-page
|
|
2814
2858
|
// slugs (see "Minimize Runtime Payload").
|
|
2859
|
+
refuseUrlCharactersInTranslations(siteConfig?.i18n?.routeTranslations)
|
|
2815
2860
|
const defaultLocale = resolveDefaultLocale(siteConfig)
|
|
2816
2861
|
const langValidation = validateLanguageConfig(siteConfig)
|
|
2817
2862
|
for (const { message } of langValidation.warnings) {
|
|
@@ -3064,6 +3109,7 @@ function buildRouteTranslations(pages, { defaultLocale = 'en', languages = null
|
|
|
3064
3109
|
)
|
|
3065
3110
|
continue
|
|
3066
3111
|
}
|
|
3112
|
+
refuseUrlCharacters(segment, `\`slug.${locale}\` of the page at ${canonicalRoute}, \`${segment}\`,`)
|
|
3067
3113
|
if (!isValidSlugSegment(segment)) {
|
|
3068
3114
|
console.warn(
|
|
3069
3115
|
`[content-collector] invalid slug '${segment}' for '${canonicalRoute}' (${locale}) — must be a single URL-safe path segment`
|
package/src/uwx/folder.js
CHANGED
|
@@ -57,6 +57,12 @@ import { fileLeaf } from './file-records.js'
|
|
|
57
57
|
export const FOLDER_MODEL_NAME = '@uniweb/folder'
|
|
58
58
|
export const FOLDER_ENTITY_KEY = '@folder'
|
|
59
59
|
|
|
60
|
+
// ⭐ A MOVED RECORD'S ENTRY IS FOUND BY THE ENTITY IT HELD. A record moved to another data schema
|
|
61
|
+
// goes up as a new entity, so its leaf names it by `$ref` and carries no entity uuid to look the
|
|
62
|
+
// entry up by. The entity it held does: this key, on the leaf, carries it to the stamping below.
|
|
63
|
+
// A symbol, so it never reaches the wire (`JSON.stringify` skips it) or the folder's hash.
|
|
64
|
+
const MOVED_FROM = Symbol('movedFrom')
|
|
65
|
+
|
|
60
66
|
// Point one authored leaf at the record entity it names. The folder's `contents`
|
|
61
67
|
// field is polymorphic (it can reference any data schema), so the ref uses the
|
|
62
68
|
// entity_ref OPEN form `{ schema, entity }` — not a bare uuid (a bare uuid is only
|
|
@@ -129,6 +135,7 @@ function contentsFromNodes(nodes, byEntityId, missing, sourceLocale, byLinkId =
|
|
|
129
135
|
continue
|
|
130
136
|
}
|
|
131
137
|
const leaf = refLeaf(entity)
|
|
138
|
+
if (entity.movedFrom) leaf[MOVED_FROM] = entity.movedFrom
|
|
132
139
|
// ⭐ What the folder says about the record (`records/folder.yml`, ruled 2026-09-27
|
|
133
140
|
// [Diego]): its display text, localized as a branch's is, and its tags, in the order
|
|
134
141
|
// written. A records service answers them beside the record as `$label` and `$tags`.
|
|
@@ -146,7 +153,8 @@ function recordOf(item) {
|
|
|
146
153
|
if (item?.kind !== 'ref') return null
|
|
147
154
|
const e = item.entry
|
|
148
155
|
const uuid = e && typeof e === 'object' ? e.entity : e
|
|
149
|
-
|
|
156
|
+
if (typeof uuid === 'string' && uuid) return uuid
|
|
157
|
+
return typeof item[MOVED_FROM] === 'string' ? item[MOVED_FROM] : null
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
/**
|
|
@@ -198,6 +206,25 @@ export function collectFolderItemUuids(doc) {
|
|
|
198
206
|
return out
|
|
199
207
|
}
|
|
200
208
|
|
|
209
|
+
/**
|
|
210
|
+
* What a stored folder says each record is: its entity's uuid → the data schema its entry names
|
|
211
|
+
* (`entry: { schema, entity }`, the schema's scoped name). Banked beside the placements, so a push
|
|
212
|
+
* can tell a record whose file moved to another schema (`records.js`, `heldTypes`).
|
|
213
|
+
*
|
|
214
|
+
* @param {object} doc - a stored `@uniweb/folder` document
|
|
215
|
+
* @returns {Record<string,string>}
|
|
216
|
+
*/
|
|
217
|
+
export function collectFolderRecordTypes(doc) {
|
|
218
|
+
const out = {}
|
|
219
|
+
walkFolderItems(doc?.contents, (_at, item) => {
|
|
220
|
+
const e = item?.kind === 'ref' ? item.entry : null
|
|
221
|
+
if (e && typeof e === 'object' && typeof e.entity === 'string' && e.entity && typeof e.schema === 'string' && e.schema) {
|
|
222
|
+
out[e.entity] = e.schema
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
return out
|
|
226
|
+
}
|
|
227
|
+
|
|
201
228
|
/**
|
|
202
229
|
* Stamp known `$uuid`s onto a folder document about to be sent, so the backend
|
|
203
230
|
* matches its stored rows instead of reading every item as new.
|
package/src/uwx/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export {
|
|
|
60
60
|
export { editYamlText, setYamlKey, replaceInYamlList } from './yaml-edit.js'
|
|
61
61
|
export { buildFolderEntity,
|
|
62
62
|
collectFolderItemUuids,
|
|
63
|
+
collectFolderRecordTypes,
|
|
63
64
|
stampFolderItemUuids
|
|
64
65
|
} from './folder.js'
|
|
65
66
|
// The identity of a record's list items — banked per record from what a push sent and
|
|
@@ -118,6 +119,7 @@ export {
|
|
|
118
119
|
listSyncedBackends,
|
|
119
120
|
updateBackendState,
|
|
120
121
|
updateBackendMap,
|
|
122
|
+
setBackendMap,
|
|
121
123
|
carryServed,
|
|
122
124
|
clearBackend,
|
|
123
125
|
clearBackendSections,
|
package/src/uwx/records.js
CHANGED
|
@@ -554,7 +554,7 @@ function describeUnresolved({ path, model, value, invalid, ambiguous }) {
|
|
|
554
554
|
// `{ $ref: <$id> }` for a record of the same package. A uuid it did not mint is never
|
|
555
555
|
// sent (see `buildRecordEntities`).
|
|
556
556
|
const AMBIGUOUS = Symbol('ambiguous')
|
|
557
|
-
function refResolver(readSchemas, recordMap) {
|
|
557
|
+
function refResolver(readSchemas, recordMap, moved = new Map()) {
|
|
558
558
|
const byModel = new Map() // Model → handle → the record: its own id (null before its first push) and `$id`
|
|
559
559
|
const byOwnId = new Map() // the record's own id → the record
|
|
560
560
|
for (const { declaration, flat } of readSchemas) {
|
|
@@ -567,7 +567,8 @@ function refResolver(readSchemas, recordMap) {
|
|
|
567
567
|
if (own) byOwnId.set(own, record)
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
|
-
|
|
570
|
+
// A record moved to another data schema is new on the wire, so a reference names it by `$id`.
|
|
571
|
+
const sent = ({ own, id }) => (own && recordMap[own] && !moved.has(own) ? { uuid: recordMap[own] } : { ref: id })
|
|
571
572
|
return {
|
|
572
573
|
resolve(model, value) {
|
|
573
574
|
if (typeof value !== 'string' || value === '') return { invalid: true }
|
|
@@ -582,6 +583,22 @@ function refResolver(readSchemas, recordMap) {
|
|
|
582
583
|
}
|
|
583
584
|
}
|
|
584
585
|
|
|
586
|
+
// A data schema's scoped name, `@scope/name` — not the unqualified `@/name`.
|
|
587
|
+
const SCOPED = /^@[^/\s]+\/[^/\s]+$/
|
|
588
|
+
|
|
589
|
+
// The fields of a record file holding `#ref`, the marker a pull writes for a set secret. A moved
|
|
590
|
+
// record's entity is new, and a new entity holds no secret, so these arrive unset
|
|
591
|
+
// [backend, 2026-11-04]: the push names them, to be set again.
|
|
592
|
+
function setSecretFields(data, prefix = '') {
|
|
593
|
+
const out = []
|
|
594
|
+
for (const [key, value] of Object.entries(data && typeof data === 'object' ? data : {})) {
|
|
595
|
+
if (key.startsWith('$')) continue
|
|
596
|
+
if (value === '#ref') out.push(prefix + key)
|
|
597
|
+
else if (value && typeof value === 'object' && !Array.isArray(value)) out.push(...setSecretFields(value, `${prefix}${key}.`))
|
|
598
|
+
}
|
|
599
|
+
return out
|
|
600
|
+
}
|
|
601
|
+
|
|
585
602
|
// "a", "a and b", "a, b and c" — items are already formatted.
|
|
586
603
|
function listOf(items) {
|
|
587
604
|
if (items.length <= 1) return items.join('')
|
|
@@ -871,9 +888,11 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
871
888
|
// lists it and nothing leaves it out. `records/folder.yml` only sorts records into
|
|
872
889
|
// sub-folders. A file named with a leading `_` is not read, so it is not a record.
|
|
873
890
|
//
|
|
874
|
-
// ⛔ A
|
|
875
|
-
//
|
|
876
|
-
//
|
|
891
|
+
// ⛔ A RECORD IS NOT LIVE BECAUSE ITS FILE IS HERE. A push puts it in the site's folder on
|
|
892
|
+
// the backend, and the site's first publish opens that folder to the live site. From then on
|
|
893
|
+
// the live site reads its records from the folder as it stands, so a later push adds, changes
|
|
894
|
+
// or removes them there with no republish [backend, 2026-11-04 — `delivery-orientation.md`].
|
|
895
|
+
// Nothing here decides that for a record.
|
|
877
896
|
//
|
|
878
897
|
// ⛔ UNTIL 2026-09-21 THE SET WAS `records.yml`'s: an unlisted entity was not
|
|
879
898
|
// pushed, and a missing `records.yml` pushed nothing. The inert state moved with
|
|
@@ -1058,6 +1077,20 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1058
1077
|
// file and the map is identity — exactly what happened before this change, so a
|
|
1059
1078
|
// single-backend project behaves as it always did.
|
|
1060
1079
|
const recordMap = opts.backend ? readBackendState(siteRoot, opts.backend).records || {} : {}
|
|
1080
|
+
// ⭐ WHAT THIS BACKEND HOLDS EACH RECORD AS: its uuid → the data schema its folder entry names
|
|
1081
|
+
// (`sync.json::backends.<B>.types`, banked from every folder a push or pull hands back). An
|
|
1082
|
+
// entity keeps its data schema for life, so an entry never changes.
|
|
1083
|
+
//
|
|
1084
|
+
// A record whose file now sits under another schema has MOVED. It goes up as a new entity of
|
|
1085
|
+
// the new schema (no `$uuid`, its `$id` for references), and its folder entry keeps its own
|
|
1086
|
+
// `$uuid`, found by the record it held, so the entry stays the row it was whatever the file is
|
|
1087
|
+
// now called. One push moves it (backend `entity-sync-wire.md` §11.3). The old entity is kept,
|
|
1088
|
+
// in no folder. ⛔ Until 2026-11-04 the push sent it with its `$uuid` and was refused
|
|
1089
|
+
// (`type_changed`), and the author's way round was to delete the line, which lost the entry
|
|
1090
|
+
// too whenever the file was renamed in the same move.
|
|
1091
|
+
const heldTypes = opts.backend ? readBackendState(siteRoot, opts.backend).types || {} : {}
|
|
1092
|
+
// the record's own id → { uuid: the entity it was, from, to }
|
|
1093
|
+
const moved = new Map()
|
|
1061
1094
|
|
|
1062
1095
|
const entities = []
|
|
1063
1096
|
const index = []
|
|
@@ -1186,6 +1219,14 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1186
1219
|
} else if (ownId) {
|
|
1187
1220
|
fileByOwnId.set(ownId, pooled.relPath)
|
|
1188
1221
|
}
|
|
1222
|
+
const held = ownId ? recordMap[ownId] : undefined
|
|
1223
|
+
const heldAs = held ? heldTypes[held] : undefined
|
|
1224
|
+
// ⛔ Only two fully scoped names compare. An unqualified `@/x` (a foundation whose scope is not
|
|
1225
|
+
// known here) would differ from the backend's `@acme/x` without the record having moved, and
|
|
1226
|
+
// read as a move it would send the record as new on every push.
|
|
1227
|
+
if (heldAs && SCOPED.test(heldAs) && SCOPED.test(declaration.name) && heldAs !== declaration.name) {
|
|
1228
|
+
moved.set(ownId, { uuid: held, from: heldAs, to: declaration.name })
|
|
1229
|
+
}
|
|
1189
1230
|
flat.push(rec)
|
|
1190
1231
|
sourceBySlug.set(r.slug, r)
|
|
1191
1232
|
produced.push({ id: rec.$id, slug: r.slug })
|
|
@@ -1194,14 +1235,14 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1194
1235
|
}
|
|
1195
1236
|
readSchemas.push({ label, declaration, flat, sourceBySlug })
|
|
1196
1237
|
}
|
|
1197
|
-
const refs = refResolver(readSchemas, recordMap)
|
|
1238
|
+
const refs = refResolver(readSchemas, recordMap, moved)
|
|
1198
1239
|
|
|
1199
1240
|
for (const { label, declaration, flat, sourceBySlug } of readSchemas) {
|
|
1200
1241
|
const ownIds = new Map()
|
|
1201
1242
|
const onWire = flat.map((rec) => {
|
|
1202
1243
|
const own = typeof rec.$uuid === 'string' && rec.$uuid ? rec.$uuid : null
|
|
1203
1244
|
ownIds.set(rec.slug, own)
|
|
1204
|
-
const minted = own ? recordMap[own] : undefined
|
|
1245
|
+
const minted = own && !moved.has(own) ? recordMap[own] : undefined
|
|
1205
1246
|
const { $uuid: _own, ...rest } = rec
|
|
1206
1247
|
return minted ? { ...rest, $uuid: minted } : rest
|
|
1207
1248
|
})
|
|
@@ -1236,6 +1277,10 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1236
1277
|
)
|
|
1237
1278
|
}
|
|
1238
1279
|
seen.add(dupKey)
|
|
1280
|
+
// A moved record's folder entry is found by the entity it held (`folder.js`).
|
|
1281
|
+
const own = ownIds.get(e.slug) ?? null
|
|
1282
|
+
const move = own ? moved.get(own) : undefined
|
|
1283
|
+
if (move) e.movedFrom = move.uuid
|
|
1239
1284
|
// The verb back-fills the minted `$uuid` into this source file, matched
|
|
1240
1285
|
// back from the finalized response by ($schema, $id).
|
|
1241
1286
|
const src = sourceBySlug.get(e.slug)
|
|
@@ -1254,6 +1299,8 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1254
1299
|
multiRecord: src ? src.multiRecord : false,
|
|
1255
1300
|
// Sent disabled, so the back-fill can check that the backend kept it that way.
|
|
1256
1301
|
draft: e.document.$disabled === true,
|
|
1302
|
+
// Moved to another data schema: what it was held as, and what it is now.
|
|
1303
|
+
...(move ? { moved: { from: move.from, to: move.to, uuid: move.uuid, secrets: setSecretFields(src?.data) } } : {}),
|
|
1257
1304
|
})
|
|
1258
1305
|
}
|
|
1259
1306
|
entities.push(...mappedOut.entities)
|
|
@@ -62,7 +62,7 @@ export const RUNTIME_KEYS = Object.freeze({
|
|
|
62
62
|
search: Object.freeze(['enabled', 'provider', 'endpoint', 'include', 'exclude', 'fields', 'weight']),
|
|
63
63
|
submit: Object.freeze(['enabled', 'endpoint']),
|
|
64
64
|
assistant: Object.freeze(['enabled', 'endpoint']),
|
|
65
|
-
tracking: Object.freeze(['enabled', 'endpoint', 'emit', 'consent', 'scripts', 'flushIntervalMs', 'debug', 'conversions']),
|
|
65
|
+
tracking: Object.freeze(['enabled', 'endpoint', 'emit', 'consent', 'scripts', 'flushIntervalMs', 'debug', 'conversions', 'landing']),
|
|
66
66
|
backend: Object.freeze(['enabled', 'endpoint'])
|
|
67
67
|
})
|
|
68
68
|
|
|
@@ -94,9 +94,20 @@ const RENAMED_SITE_KEYS = Object.freeze({ $devApi: '$devBackend' })
|
|
|
94
94
|
*/
|
|
95
95
|
const HOST_ONLY = new Map([
|
|
96
96
|
['records', () => '`records: true`'],
|
|
97
|
-
['google', (value) => `\`google: { id: ${value} }\``]
|
|
97
|
+
['google', (value) => `\`google: { id: ${value} }\``],
|
|
98
|
+
['meta', (value) => `\`meta: { pixel: '${value}' }\``],
|
|
99
|
+
['x', (value) => `\`x: { pixel: '${value}' }\``]
|
|
98
100
|
])
|
|
99
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Ad platforms a host tells of a site's conversions, server-side: `pixel` is the platform's
|
|
104
|
+
* public ID for the site, `events` names each conversion the site reports
|
|
105
|
+
* (`services.tracking.conversions`, a foundation's `block.track('conversion', …)`) to the
|
|
106
|
+
* platform's own event. The platform's token is a secret, set where secrets are set and never
|
|
107
|
+
* in this file — `token` here is a credential key, which a push never sends.
|
|
108
|
+
*/
|
|
109
|
+
const AD_PLATFORMS = new Set(['meta', 'x'])
|
|
110
|
+
|
|
100
111
|
/**
|
|
101
112
|
* Credential-shaped keys, mirroring the set the delivery edge strips on the reading
|
|
102
113
|
* side — deliberately the SAME list, so the two guards are visibly twins. Never sent
|
|
@@ -171,7 +182,39 @@ function entryProblem(name, value) {
|
|
|
171
182
|
if (HOST_ONLY.has(name) && addressOf(value)) {
|
|
172
183
|
return `\`services.${name}\` has no address of its own — your host provides it. Remove \`endpoint\`.`
|
|
173
184
|
}
|
|
174
|
-
if (name === 'tracking') return conversionsProblem(value.conversions)
|
|
185
|
+
if (name === 'tracking') return conversionsProblem(value.conversions) || landingProblem(value.landing)
|
|
186
|
+
if (AD_PLATFORMS.has(name)) return adPlatformProblem(name, value)
|
|
187
|
+
return null
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* What is wrong with an ad platform's entry, or null.
|
|
192
|
+
*
|
|
193
|
+
* ⛔ A pixel written as a bare number is refused, and not echoed back. YAML reads a long ID as a
|
|
194
|
+
* number, and an ID past 2^53 — a 16-digit dataset ID can be — is already a different number by
|
|
195
|
+
* the time this sees it, so repeating it would hand the author the wrong digits. Neither mistake
|
|
196
|
+
* shows anywhere a visitor goes: the platform hears nothing, which looks like no conversions.
|
|
197
|
+
*
|
|
198
|
+
* @param {string} name
|
|
199
|
+
* @param {object} value
|
|
200
|
+
* @returns {string|null}
|
|
201
|
+
*/
|
|
202
|
+
function adPlatformProblem(name, { pixel, events }) {
|
|
203
|
+
if (pixel !== undefined && typeof pixel !== 'string') {
|
|
204
|
+
return typeof pixel === 'number'
|
|
205
|
+
? `\`services.${name}.pixel\` is a number, and YAML can change the last digits of a long one. Copy the ID from the platform again and write it in quotes: \`pixel: '…'\`.`
|
|
206
|
+
: `\`services.${name}.pixel\` is the platform's ID, in quotes — not ${described(pixel)}.`
|
|
207
|
+
}
|
|
208
|
+
if (typeof pixel === 'string' && !pixel.trim()) return `\`services.${name}.pixel\` is empty.`
|
|
209
|
+
if (events === undefined) return null
|
|
210
|
+
if (!isMap(events)) {
|
|
211
|
+
return `\`services.${name}.events\` names each conversion to the platform's event — \`events: { signup: <event> }\` — not ${described(events)}.`
|
|
212
|
+
}
|
|
213
|
+
for (const [conversion, event] of Object.entries(events)) {
|
|
214
|
+
if (typeof event !== 'string' || !event.trim()) {
|
|
215
|
+
return `\`services.${name}.events.${conversion}\` is the platform's event for \`${conversion}\` — not ${described(event)}.`
|
|
216
|
+
}
|
|
217
|
+
}
|
|
175
218
|
return null
|
|
176
219
|
}
|
|
177
220
|
|
|
@@ -213,6 +256,28 @@ function conversionsProblem(list) {
|
|
|
213
256
|
return null
|
|
214
257
|
}
|
|
215
258
|
|
|
259
|
+
/**
|
|
260
|
+
* What is wrong with `services.tracking.landing`, or null: the query keys of the address a
|
|
261
|
+
* visitor arrived at that each conversion carries. Stopped here for the same reason as a
|
|
262
|
+
* conversion: at a visitor's browser a misread list carries nothing, and nothing says so.
|
|
263
|
+
*
|
|
264
|
+
* @param {*} list
|
|
265
|
+
* @returns {string|null}
|
|
266
|
+
*/
|
|
267
|
+
function landingProblem(list) {
|
|
268
|
+
if (list === undefined) return null
|
|
269
|
+
const path = '`services.tracking.landing`'
|
|
270
|
+
if (!Array.isArray(list)) {
|
|
271
|
+
return `${path} is a list of the landing address's query keys a conversion carries: \`[utm_source, utm_campaign]\` — not ${described(list)}.`
|
|
272
|
+
}
|
|
273
|
+
for (const [i, key] of list.entries()) {
|
|
274
|
+
if (typeof key !== 'string' || !key.trim()) {
|
|
275
|
+
return `${path}[${i}] is a query key, like \`utm_campaign\` — not ${described(key)}.`
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return null
|
|
279
|
+
}
|
|
280
|
+
|
|
216
281
|
/**
|
|
217
282
|
* Every entry of `site.yml::services` that neither a build nor a push can read, each said
|
|
218
283
|
* with its fix — [] when there is none.
|
package/src/uwx/site.js
CHANGED
|
@@ -71,6 +71,8 @@ import {
|
|
|
71
71
|
rootOrderConfig,
|
|
72
72
|
composeLocalizedRoute,
|
|
73
73
|
isValidSlugSegment,
|
|
74
|
+
refuseUrlCharacters,
|
|
75
|
+
refuseUrlCharactersInTranslations,
|
|
74
76
|
authoredId,
|
|
75
77
|
} from '../site/content-collector.js'
|
|
76
78
|
import { carrySectionFile, rewriteFileLinks } from '../site/file-links.js'
|
|
@@ -145,8 +147,9 @@ function localizeRouteSlugs(pages, siteYml, sourceLocale) {
|
|
|
145
147
|
let ownForm = false
|
|
146
148
|
visit(pages, '/', (record) => { if (record[AUTHORED_SLUG]) ownForm = true })
|
|
147
149
|
if (ownForm) {
|
|
148
|
-
visit(pages, '/', (record) => {
|
|
150
|
+
visit(pages, '/', (record, route) => {
|
|
149
151
|
for (const [locale, segment] of Object.entries(record[AUTHORED_SLUG] || {})) {
|
|
152
|
+
refuseUrlCharacters(segment, `\`slug.${locale}\` of the page at ${route}, \`${segment}\`,`)
|
|
150
153
|
if (carried(locale, segment)) record.slug[locale] = segment
|
|
151
154
|
}
|
|
152
155
|
})
|
|
@@ -154,6 +157,7 @@ function localizeRouteSlugs(pages, siteYml, sourceLocale) {
|
|
|
154
157
|
}
|
|
155
158
|
const map = siteYml?.i18n?.routeTranslations
|
|
156
159
|
if (!isPlainRecord(map)) return
|
|
160
|
+
refuseUrlCharactersInTranslations(map)
|
|
157
161
|
const segments = new Map() // canonical route → { locale: segment }, as the build composes them
|
|
158
162
|
visit(pages, '/', (record, route, parentRoute) => {
|
|
159
163
|
if (record.is_dynamic || record.is_index) return
|
package/src/uwx/sync-store.js
CHANGED
|
@@ -43,9 +43,12 @@ const VERSION = 1
|
|
|
43
43
|
/**
|
|
44
44
|
* Map sections — merged entry by entry. Anything else in a patch replaces.
|
|
45
45
|
* `recordItems` is keyed by a record's uuid here, each entry that record's list items
|
|
46
|
-
* (`record-items.js`) — replaced whole, one record at a time.
|
|
46
|
+
* (`record-items.js`) — replaced whole, one record at a time. `types` is keyed by a record's
|
|
47
|
+
* uuid too, each entry the data schema the backend holds it as, written whole from each folder the
|
|
48
|
+
* backend hands back (`setBackendMap`), so it names what the folder places. `retired` is the same
|
|
49
|
+
* shape: the records a push took out of the folder, which the backend keeps until they are deleted.
|
|
47
50
|
*/
|
|
48
|
-
const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files'])
|
|
51
|
+
const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files', 'types', 'retired'])
|
|
49
52
|
|
|
50
53
|
const storePath = (siteDir) => join(siteDir, SYNC_STORE_FILE)
|
|
51
54
|
|
|
@@ -241,6 +244,32 @@ export function updateBackendMap(siteDir, origin, section, entries, merge) {
|
|
|
241
244
|
return { added, changed, written: writeStore(siteDir, backends) }
|
|
242
245
|
}
|
|
243
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Write one map section whole, replacing what it held — for a section that is a snapshot of what
|
|
249
|
+
* the backend says, such as `types`, rather than an accumulation. An empty map removes the section.
|
|
250
|
+
*
|
|
251
|
+
* @param {string} siteDir
|
|
252
|
+
* @param {string} origin
|
|
253
|
+
* @param {string} section - a map section
|
|
254
|
+
* @param {Record<string, *>} map
|
|
255
|
+
* @returns {{ prior: Record<string, *>, written: boolean }} the section as it was before
|
|
256
|
+
*/
|
|
257
|
+
export function setBackendMap(siteDir, origin, section, map) {
|
|
258
|
+
const key = normalizeOrigin(origin)
|
|
259
|
+
if (!key || !MAP_SECTIONS.has(section) || !map || typeof map !== 'object') return { prior: {}, written: false }
|
|
260
|
+
const { backends } = readSyncStore(siteDir)
|
|
261
|
+
const state = backends[key] || {}
|
|
262
|
+
const prior = state[section] || {}
|
|
263
|
+
const next = { ...state }
|
|
264
|
+
if (Object.keys(map).length) next[section] = { ...map }
|
|
265
|
+
else delete next[section]
|
|
266
|
+
if (JSON.stringify(sortedKeys(prior)) === JSON.stringify(sortedKeys(map))) return { prior, written: false }
|
|
267
|
+
backends[key] = next
|
|
268
|
+
return { prior, written: writeStore(siteDir, backends) }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const sortedKeys = (map) => Object.fromEntries(Object.keys(map).sort().map((k) => [k, map[k]]))
|
|
272
|
+
|
|
244
273
|
/**
|
|
245
274
|
* The merge rule for the `assets` section — pass it to `updateBackendMap`.
|
|
246
275
|
*
|