@expofp/config 0.0.0-experimental.cf063fc
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/README.md +40 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/lib/apply-intents.d.ts +10 -0
- package/dist/lib/apply-intents.js +24 -0
- package/dist/lib/config-store.d.ts +8 -0
- package/dist/lib/config-store.js +16 -0
- package/dist/lib/debug-settings.d.ts +16 -0
- package/dist/lib/debug-settings.js +44 -0
- package/dist/lib/deprecated-url-params.d.ts +33 -0
- package/dist/lib/deprecated-url-params.js +72 -0
- package/dist/lib/json-schema.d.ts +67 -0
- package/dist/lib/json-schema.js +136 -0
- package/dist/lib/legacy-url.d.ts +162 -0
- package/dist/lib/legacy-url.js +416 -0
- package/dist/lib/load-config.d.ts +27 -0
- package/dist/lib/load-config.js +373 -0
- package/dist/lib/local-storage-codec.d.ts +44 -0
- package/dist/lib/local-storage-codec.js +76 -0
- package/dist/lib/normalize-fp-svg.d.ts +26 -0
- package/dist/lib/normalize-fp-svg.js +36 -0
- package/dist/lib/normalize-legacy-data.d.ts +13 -0
- package/dist/lib/normalize-legacy-data.js +90 -0
- package/dist/lib/rebooking.d.ts +19 -0
- package/dist/lib/rebooking.js +48 -0
- package/dist/lib/resource-urls.d.ts +52 -0
- package/dist/lib/resource-urls.js +203 -0
- package/dist/lib/serialize-config-resources.d.ts +46 -0
- package/dist/lib/serialize-config-resources.js +50 -0
- package/dist/lib/store-ref.d.ts +40 -0
- package/dist/lib/store-ref.js +56 -0
- package/dist/lib/strip-defaults.d.ts +27 -0
- package/dist/lib/strip-defaults.js +55 -0
- package/dist/lib/url-codec.d.ts +46 -0
- package/dist/lib/url-codec.js +165 -0
- package/dist/lib/url-intents.d.ts +40 -0
- package/dist/lib/url-intents.js +71 -0
- package/dist/lib/validate-flag.d.ts +10 -0
- package/dist/lib/validate-flag.js +36 -0
- package/dist/lib/validate-timing.d.ts +3 -0
- package/dist/lib/validate-timing.js +52 -0
- package/dist/lib/visit-resources.d.ts +99 -0
- package/dist/lib/visit-resources.js +209 -0
- package/package.json +36 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { resolve } from '@expofp/resolve';
|
|
3
|
+
import { ConfigDefaults, DataJsSchema, FpSvgJsSchema, FpSvgLayerJsSchema, LocalStorageConfigSchema, ManifestSchema, OptionsSchema, UrlConfigSchema, WfDataJsSchema, } from '@expofp/schema';
|
|
4
|
+
import { deepClone, deepFreeze } from '@expofp/utils';
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
import { parseDeprecatedUrlParams } from './deprecated-url-params.js';
|
|
7
|
+
import { parseFromStorage } from './local-storage-codec.js';
|
|
8
|
+
import { normalizeFpSvgLayerAliases } from './normalize-fp-svg.js';
|
|
9
|
+
import { normalizeLegacyData } from './normalize-legacy-data.js';
|
|
10
|
+
import { applyRebookingData } from './rebooking.js';
|
|
11
|
+
import { resolveUrl } from './store-ref.js';
|
|
12
|
+
import { parseFromUrlTolerant } from './url-codec.js';
|
|
13
|
+
import { parseIntentsFromUrl } from './url-intents.js';
|
|
14
|
+
import { readValidateFlag } from './validate-flag.js';
|
|
15
|
+
import { documentRef, isRefShaped, setValidateManifest, validateOrClone, visitResources, } from './visit-resources.js';
|
|
16
|
+
const log = debug('efp:config');
|
|
17
|
+
/**
|
|
18
|
+
* Assemble the effective config — the runtime's single, complete copy of the
|
|
19
|
+
* expo data — by layering, lowest to highest precedence:
|
|
20
|
+
* manifest (+ its legacy data.js) → options → localStorage → URL.
|
|
21
|
+
*
|
|
22
|
+
* With a `legacyDataUrlBase` (live events), the manifest's `legacyDataVersion`
|
|
23
|
+
* pin — or, absent one, the version probe — settles the `?v=` cache-buster,
|
|
24
|
+
* refs to the sibling drawing / wayfinding files are
|
|
25
|
+
* derived from it (`data.js` never carries them), and all three legacy files —
|
|
26
|
+
* `data.js` evaluated to its `__data` document like every legacy `.js` file,
|
|
27
|
+
* asset-resolved and merged in — are fetched in parallel. A manifest can
|
|
28
|
+
* instead carry the merged data itself plus explicit refs (offline copies) —
|
|
29
|
+
* then nothing is derived. The config holds only the REFS; the payloads live
|
|
30
|
+
* in `@expofp/resolve`'s memo: `loadConfig` resolves `fpSvgJsRef` and
|
|
31
|
+
* `wfDataJsRef` before returning, so consumers read them synchronously with
|
|
32
|
+
* `getResolved` from then on. Legacy normalization and the rebooking merge
|
|
33
|
+
* run last, and the result is deep-frozen.
|
|
34
|
+
*
|
|
35
|
+
* `url` / `storage` are browser inputs (page query, `localStorage`); Node
|
|
36
|
+
* callers (the offline CLI) omit them, which also skips those layers and the
|
|
37
|
+
* rebooking token lookup.
|
|
38
|
+
*/
|
|
39
|
+
export async function loadConfig(manifest, options, url, storage) {
|
|
40
|
+
const config = { ...ConfigDefaults };
|
|
41
|
+
// Schema validation is an opt-in diagnostic, read up front from the page
|
|
42
|
+
// inputs (URL query / localStorage): the parses it gates run before those
|
|
43
|
+
// layers merge, so it can't come off the effective config. See readValidateFlag.
|
|
44
|
+
const validateSchema = readValidateFlag(url, storage);
|
|
45
|
+
setValidateManifest(validateSchema); // gates the referenced-document parses (visit-resources)
|
|
46
|
+
// A normalized expo folder's mutable `manifest.json` is a tiny pointer
|
|
47
|
+
// (`{"$ref": "$/<expo>/<hash>/manifest.json"}`) — follow the chain down to
|
|
48
|
+
// the snapshot first. Then take an OWN copy of the settled manifest
|
|
49
|
+
// (validated when the flag is on — see validateOrClone): `resolve`
|
|
50
|
+
// deep-freezes what it settles, an offline or normalized manifest carries
|
|
51
|
+
// the full event data (booths, exhibitors, …), and `normalizeLegacyData`
|
|
52
|
+
// below mutates those nested objects in place. Store refs (`$/…`) expand
|
|
53
|
+
// into their canonical immutable URLs right here — the effective config
|
|
54
|
+
// only ever carries full URLs, so no consumer sees the notation.
|
|
55
|
+
manifest = validateOrClone(ManifestSchema, await resolveManifestChain(manifest));
|
|
56
|
+
await expandManifestStoreRefs(manifest);
|
|
57
|
+
// The legacy event-data directory and the data-revision pin are INPUTS,
|
|
58
|
+
// consumed right here — the effective config carries only the refs derived
|
|
59
|
+
// from them, so neither is merged.
|
|
60
|
+
const { legacyDataUrlBase, legacyDataVersion: manifestPin, ...manifestFields } = manifest;
|
|
61
|
+
applyConsentAlias(manifestFields);
|
|
62
|
+
assignDefined(config, manifestFields);
|
|
63
|
+
// don't trust, parse
|
|
64
|
+
options = OptionsSchema.parse(options);
|
|
65
|
+
applyConsentAlias(options);
|
|
66
|
+
// every legacy file URL is ?v= cache-busted; a timestamp busts when neither
|
|
67
|
+
// the manifest nor version.json pins a revision (TODO: drop once the legacy
|
|
68
|
+
// data directory is gone)
|
|
69
|
+
let legacyDataVersion = String(Date.now());
|
|
70
|
+
// live legacy directory: settle the version (manifest pin, else the
|
|
71
|
+
// version.json probe), then the sibling file refs — data.js never carries
|
|
72
|
+
// the payload refs, so both are known before it lands
|
|
73
|
+
if (legacyDataUrlBase) {
|
|
74
|
+
if (isFromDesignerReferrer()) {
|
|
75
|
+
// The designer previews in-progress edits — the directory's files change
|
|
76
|
+
// without a version bump, so a published version (the manifest pin and
|
|
77
|
+
// version.json alike) must not pin `?v=`; the unique timestamp stands
|
|
78
|
+
// and every load fetches fresh files.
|
|
79
|
+
log('loadConfig', 'designer referrer — cache-busting with a timestamp');
|
|
80
|
+
}
|
|
81
|
+
else if (typeof manifestPin === 'string' && manifestPin) {
|
|
82
|
+
// The manifest pins the data revision (get-manifest already probed
|
|
83
|
+
// version.json server-side) — honor it, no client probe: manifest and
|
|
84
|
+
// data stay consistent by construction.
|
|
85
|
+
legacyDataVersion = manifestPin;
|
|
86
|
+
}
|
|
87
|
+
else if (manifestPin === null) {
|
|
88
|
+
// The generator probed and there IS no version.json for this expo — the
|
|
89
|
+
// per-load timestamp stands, and the client must not re-probe (on the
|
|
90
|
+
// cross-origin contour that probe could only fail). Only an ABSENT pin
|
|
91
|
+
// (legacy manifests; the retired `$ref` pointer counts as absent) falls
|
|
92
|
+
// through to the probe below.
|
|
93
|
+
log('loadConfig', 'manifest pins "no version" — cache-busting with a timestamp');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
try {
|
|
97
|
+
legacyDataVersion = (await resolve({ $ref: `${legacyDataUrlBase}version.json` })).version;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
log('loadConfig', 'no version.json found at', legacyDataUrlBase);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Manifest-supplied refs win (offline copies point them at resolved .json
|
|
104
|
+
// documents); otherwise derive the conventional <base><file>.js URLs.
|
|
105
|
+
config.fpSvgJsRef ??= legacyFileRef(legacyDataUrlBase, 'fp.svg.js', legacyDataVersion);
|
|
106
|
+
config.wfDataJsRef ??= legacyFileRef(legacyDataUrlBase, 'wf.data.js', legacyDataVersion);
|
|
107
|
+
}
|
|
108
|
+
// Every ref the config carries is decorated with its document-processing
|
|
109
|
+
// hook (validate + absolutize resource URLs against the ref's directory) —
|
|
110
|
+
// after the manifest parse, which keeps refs as plain data, and covering
|
|
111
|
+
// manifest-supplied and derived refs alike. From here on, ANY
|
|
112
|
+
// `resolve(ref)` settles a good document.
|
|
113
|
+
if (config.fpSvgJsRef)
|
|
114
|
+
config.fpSvgJsRef = documentRef(config.fpSvgJsRef, FpSvgJsSchema);
|
|
115
|
+
if (config.wfDataJsRef)
|
|
116
|
+
config.wfDataJsRef = documentRef(config.wfDataJsRef, WfDataJsSchema);
|
|
117
|
+
const layerRefs = {};
|
|
118
|
+
for (const [name, ref] of Object.entries(config.fpSvgLayerJsRefs)) {
|
|
119
|
+
layerRefs[name] = fpSvgLayerDocumentRef(ref, name);
|
|
120
|
+
}
|
|
121
|
+
config.fpSvgLayerJsRefs = layerRefs;
|
|
122
|
+
// Resolve the expo data document, the drawing and the wayfinding graph
|
|
123
|
+
// eagerly, in parallel — one network round-trip instead of three. Works with
|
|
124
|
+
// or without a legacy directory (an offline manifest carries the merged
|
|
125
|
+
// data plus refs, and no directory). The payloads stay in the resolver's
|
|
126
|
+
// memo; consumers read them synchronously with `getResolved`.
|
|
127
|
+
const [data, fpSvg] = await Promise.all([
|
|
128
|
+
legacyDataUrlBase ? loadLegacyDataJs(legacyDataUrlBase, legacyDataVersion) : null,
|
|
129
|
+
config.fpSvgJsRef ? loadLegacyFpSvgJs(config.fpSvgJsRef, legacyDataUrlBase) : null,
|
|
130
|
+
prefetchWfData(config.wfDataJsRef),
|
|
131
|
+
]);
|
|
132
|
+
if (data) {
|
|
133
|
+
// the directory fields and the payload refs are inputs consumed above —
|
|
134
|
+
// data.js never carries them, and a stray copy must not clobber the
|
|
135
|
+
// decorated, already-resolved refs
|
|
136
|
+
const { flags, legacyDataUrlBase: _dataDir, legacyDataVersion: _dataVersion, fpSvgJsRef: _fpRef, wfDataJsRef: _wfRef, fpSvgLayerJsRefs: _layerRefs, ...dataFields } = data;
|
|
137
|
+
if (flags) {
|
|
138
|
+
// legacy data.js may nest the deprecated alias under `flags`; fold it too
|
|
139
|
+
applyConsentAlias(flags);
|
|
140
|
+
assignDefined(config, flags); // deprecated nesting — root-level fields win
|
|
141
|
+
}
|
|
142
|
+
applyConsentAlias(dataFields);
|
|
143
|
+
assignDefined(config, dataFields);
|
|
144
|
+
}
|
|
145
|
+
if (fpSvg) {
|
|
146
|
+
// a pending-poll may have landed on a fresh ?v= URL — the config must
|
|
147
|
+
// point at the ref that actually resolved
|
|
148
|
+
config.fpSvgJsRef = fpSvg.ref;
|
|
149
|
+
// The venue document is plan-derived, so the drawing — not the expo
|
|
150
|
+
// database's data.js projection — is its home: it rides beside the
|
|
151
|
+
// `__fpLayers` its layer names join to, written by the same converter run.
|
|
152
|
+
// A converter that emits the key is authoritative, including when it says
|
|
153
|
+
// the plan has no venues (`assignDefined` skips only `undefined`, so an
|
|
154
|
+
// empty array does overwrite a data.js that has not caught up). An absent
|
|
155
|
+
// key means the drawing predates the change and the data.js value stands.
|
|
156
|
+
// The payload is unvalidated in production (see `validateOrClone`), so a
|
|
157
|
+
// non-object value is dropped rather than spread character-by-character.
|
|
158
|
+
const drawingVenues = fpSvg.payload.__fpVenues;
|
|
159
|
+
if (drawingVenues && typeof drawingVenues === 'object')
|
|
160
|
+
assignDefined(config, drawingVenues);
|
|
161
|
+
if (!Object.keys(config.fpSvgLayerJsRefs).length && legacyDataUrlBase) {
|
|
162
|
+
config.fpSvgLayerJsRefs = buildFpSvgLayerJsRefs(fpSvg.payload, legacyDataUrlBase, legacyDataVersion);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
assignDefined(config, options);
|
|
166
|
+
if (storage) {
|
|
167
|
+
// The sticky per-browser preferences (viewerMode / previewMode / uiScale)
|
|
168
|
+
// are schema-typed storage settings but must NOT merge into the effective
|
|
169
|
+
// config: the floor plan reads their keys lazily, so the legacy one-shot
|
|
170
|
+
// URL seeds (`?viewermode=0`, `?resetuiscale`, …) stay revocable within
|
|
171
|
+
// the same load — a frozen config value would keep a cleared mode on.
|
|
172
|
+
const { viewerMode: _viewerMode, previewMode: _previewMode, uiScale: _uiScale, ...storageConfig } = parseFromStorage(LocalStorageConfigSchema, storage);
|
|
173
|
+
assignDefined(config, storageConfig);
|
|
174
|
+
}
|
|
175
|
+
// Embeds set `ignoreQuery` (manifest / data.js / options) to isolate the
|
|
176
|
+
// floor plan from the page URL. The effective value is settled here — every
|
|
177
|
+
// lower layer has merged, and the URL cannot re-enable itself because
|
|
178
|
+
// `ignoreQuery` is not a UrlConfigSchema field.
|
|
179
|
+
if (url !== undefined && !config.ignoreQuery) {
|
|
180
|
+
// tolerant: the query is visitor-editable, a bad value must not break boot
|
|
181
|
+
const { value: urlConfig, invalidKeys } = parseFromUrlTolerant(UrlConfigSchema, url);
|
|
182
|
+
// shortcut intents (`?selectBooth=A-12`) append after the bracketed
|
|
183
|
+
// `intents[…]` entries — both play, canonical form first
|
|
184
|
+
const shortcuts = parseIntentsFromUrl(url);
|
|
185
|
+
const canonicalIntents = [...(urlConfig.intents ?? []), ...shortcuts.intents];
|
|
186
|
+
// TEMPORARY: the deprecated shim, handed the canonical readings parsed
|
|
187
|
+
// above so it does not re-parse the query. Its fields merge first so the
|
|
188
|
+
// canonical keys below win; its `?agenda` intent appends, since assigning
|
|
189
|
+
// the slice would drop what the canonical keys put there. Delete with the
|
|
190
|
+
// module.
|
|
191
|
+
const { intents: aliasIntents = [], ...deprecatedFields } = parseDeprecatedUrlParams(url, {
|
|
192
|
+
visibility: urlConfig.visibility,
|
|
193
|
+
consent: urlConfig.consent,
|
|
194
|
+
intents: canonicalIntents,
|
|
195
|
+
});
|
|
196
|
+
const intents = [...canonicalIntents, ...aliasIntents];
|
|
197
|
+
if (intents.length)
|
|
198
|
+
urlConfig.intents = intents;
|
|
199
|
+
invalidKeys.push(...shortcuts.invalidKeys);
|
|
200
|
+
if (invalidKeys.length)
|
|
201
|
+
log('loadConfig', 'ignoring invalid URL config params:', invalidKeys);
|
|
202
|
+
assignDefined(config, deprecatedFields);
|
|
203
|
+
assignDefined(config, urlConfig);
|
|
204
|
+
}
|
|
205
|
+
normalizeLegacyData(config, legacyDataUrlBase);
|
|
206
|
+
// `ignoreQuery` means "isolate from the page URL": don't read the rebooking
|
|
207
|
+
// token (`?rt=`) from it either — pass no URL so a retained session token is
|
|
208
|
+
// still honored but the query is not.
|
|
209
|
+
await applyRebookingData(config, config.ignoreQuery ? undefined : url);
|
|
210
|
+
// validateSchema is a load-time input (read up front by readValidateFlag), not
|
|
211
|
+
// a config field — strip it so the effective config never carries it, like the
|
|
212
|
+
// deprecated allowConsent alias.
|
|
213
|
+
delete config.validateSchema;
|
|
214
|
+
deepFreeze(config);
|
|
215
|
+
return config;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Hops a manifest pointer chain may take before it must have settled. The
|
|
219
|
+
* normalized form needs exactly one (mutable pointer → immutable snapshot);
|
|
220
|
+
* the ceiling only guards against a cyclic or runaway chain.
|
|
221
|
+
*/
|
|
222
|
+
const MANIFEST_POINTER_HOPS_MAX = 3;
|
|
223
|
+
/**
|
|
224
|
+
* Follow the «pointer → snapshot» chain: a settled manifest that is itself
|
|
225
|
+
* ref-shaped is a pointer — resolve what it points at, until a document
|
|
226
|
+
* settles. A store ref (`$/…`) expands by the fixed convention before its
|
|
227
|
+
* fetch, the input ref included; a rooted local pointer resolves against
|
|
228
|
+
* the page like any rooted URL. Chain-walking lives here, not in
|
|
229
|
+
* `@expofp/resolve` — the resolver stays one-layered and domain-free.
|
|
230
|
+
*/
|
|
231
|
+
async function resolveManifestChain(input) {
|
|
232
|
+
let current = input;
|
|
233
|
+
for (let hops = 0;; hops++) {
|
|
234
|
+
if (isRefShaped(current))
|
|
235
|
+
current = { ...current, $ref: resolveUrl(current.$ref) };
|
|
236
|
+
const settled = await resolve(current);
|
|
237
|
+
if (!isRefShaped(settled))
|
|
238
|
+
return settled;
|
|
239
|
+
if (hops >= MANIFEST_POINTER_HOPS_MAX) {
|
|
240
|
+
throw new Error(`loadConfig: manifest pointer chain deeper than ${MANIFEST_POINTER_HOPS_MAX} at ${settled.$ref}`);
|
|
241
|
+
}
|
|
242
|
+
log('loadConfig', 'manifest is a pointer, following it to', settled.$ref);
|
|
243
|
+
current = { $ref: settled.$ref };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Expand every store ref (`$/…`) of a normalized manifest — asset URLs and
|
|
248
|
+
* document `$ref`s alike — into its canonical URL, via the one schema-guided
|
|
249
|
+
* walk. Passthrough for other values, so compat and offline manifests come
|
|
250
|
+
* out untouched.
|
|
251
|
+
*/
|
|
252
|
+
async function expandManifestStoreRefs(manifest) {
|
|
253
|
+
const expand = (url) => resolveUrl(url);
|
|
254
|
+
await visitResources(ManifestSchema, manifest, { asset: expand, ref: expand });
|
|
255
|
+
}
|
|
256
|
+
async function loadLegacyDataJs(baseUrl, version) {
|
|
257
|
+
// data.js is a window-assigning script like fp.svg.js — resolve() evaluates
|
|
258
|
+
// it to its globals and the expo data document rides on `__data`. The
|
|
259
|
+
// decorated ref validates the payload (gated) and makes every schema-tagged
|
|
260
|
+
// asset path absolute against its directory (= baseUrl).
|
|
261
|
+
const payload = await resolve(documentRef(legacyFileRef(baseUrl, 'data.js', version), DataJsSchema));
|
|
262
|
+
if (!payload.__data)
|
|
263
|
+
log('loadLegacyDataJs', 'no __data global in data.js at', baseUrl);
|
|
264
|
+
// the resolver's memoized payload is frozen — the merge and normalization
|
|
265
|
+
// write into an own copy (a clone, so nothing here depends on parse)
|
|
266
|
+
return deepClone(payload.__data ?? {});
|
|
267
|
+
}
|
|
268
|
+
/** Retry cadence while the platform is still generating the plan (`__fpPending`). */
|
|
269
|
+
const FP_SVG_PENDING_RETRY_MS = 2000;
|
|
270
|
+
/**
|
|
271
|
+
* Resolve `fp.svg.js` eagerly (a script evaluated to its globals live, a
|
|
272
|
+
* resolved `fp.svg.json` document offline). A still-generating plan serves a
|
|
273
|
+
* `{ __fpPending: true }` stub instead of the drawing; poll — with a fresh
|
|
274
|
+
* `?v=` per attempt to step around CDN caching — until the real payload lands.
|
|
275
|
+
* Returns the payload (for layer-ref derivation) and the ref that finally
|
|
276
|
+
* resolved, which is what the config must carry for `getResolved`.
|
|
277
|
+
*/
|
|
278
|
+
async function loadLegacyFpSvgJs(ref, baseUrl) {
|
|
279
|
+
let finalRef = ref; // already decorated by loadConfig
|
|
280
|
+
let fpSvgJs = await resolve(finalRef);
|
|
281
|
+
for (let attempt = 1; fpSvgJs.__fpPending && !fpSvgJs.__fp; attempt++) {
|
|
282
|
+
log('loadLegacyFpSvgJs', 'plan is still generating, retry', attempt);
|
|
283
|
+
await sleep(FP_SVG_PENDING_RETRY_MS);
|
|
284
|
+
// a fresh ?v= per attempt steps around CDN caching; an explicit ref (a
|
|
285
|
+
// resolved offline .json is never pending-stubbed) re-resolves as-is
|
|
286
|
+
finalRef = baseUrl
|
|
287
|
+
? documentRef(legacyFileRef(baseUrl, 'fp.svg.js', String(attempt)), FpSvgJsSchema)
|
|
288
|
+
: ref;
|
|
289
|
+
fpSvgJs = await resolve(finalRef, { forceFetch: true });
|
|
290
|
+
}
|
|
291
|
+
return { payload: fpSvgJs, ref: finalRef };
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Warm the wayfinding graph ref (`wf.data.js` live, `wf.data.json` offline).
|
|
295
|
+
* A plan without a graph used to load as a silent no-op script, so a failure
|
|
296
|
+
* only logs; the ref stays unsettled and consumers probing with `isResolved`
|
|
297
|
+
* keep wayfinding off.
|
|
298
|
+
*/
|
|
299
|
+
async function prefetchWfData(ref) {
|
|
300
|
+
if (!ref)
|
|
301
|
+
return;
|
|
302
|
+
try {
|
|
303
|
+
await resolve(ref); // decorated by loadConfig
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
log('prefetchWfData', 'wf.data.js not loaded, wayfinding stays off', err);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Decorate one layer's drawing ref: the standard document processing, plus
|
|
311
|
+
* the fold of the layer-suffixed drawing globals onto the canonical keys —
|
|
312
|
+
* newer converters emit only the suffixed globals in layer files (see
|
|
313
|
+
* `normalizeFpSvgLayerAliases`).
|
|
314
|
+
*/
|
|
315
|
+
function fpSvgLayerDocumentRef(ref, layerName) {
|
|
316
|
+
return documentRef(ref, FpSvgLayerJsSchema, (document) => normalizeFpSvgLayerAliases(document, layerName));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* One `$ref` per non-default layer, pointing at its `fp.svg.<layerName>.js`
|
|
320
|
+
* (the default layer's drawing is `fp.svg.js` itself, already resolved).
|
|
321
|
+
* Layer data is not fetched here — a consumer resolves a layer's ref on
|
|
322
|
+
* demand and reads it back with `getResolved`.
|
|
323
|
+
*/
|
|
324
|
+
function buildFpSvgLayerJsRefs(fpSvgJs, baseUrl, version) {
|
|
325
|
+
const refs = {};
|
|
326
|
+
for (const layer of fpSvgJs.__fpLayers ?? []) {
|
|
327
|
+
if (layer.name === fpSvgJs.__fpDefaultLayer)
|
|
328
|
+
continue;
|
|
329
|
+
refs[layer.name] = fpSvgLayerDocumentRef(legacyFileRef(baseUrl, `fp.svg.${layer.name}.js`, version), layer.name);
|
|
330
|
+
}
|
|
331
|
+
return refs;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* True when the page is embedded by the ExpoFP designer, which previews
|
|
335
|
+
* in-progress edits: the legacy directory's files then change without a
|
|
336
|
+
* `version.json` bump, so the published version must not pin the `?v=`
|
|
337
|
+
* cache-buster. A browser-only signal — in Node (the offline CLI) there is no
|
|
338
|
+
* document and no designer. Mirrors the floorplan's `utils/is-from-designer`.
|
|
339
|
+
*/
|
|
340
|
+
function isFromDesignerReferrer() {
|
|
341
|
+
if (typeof document === 'undefined' || !document.referrer)
|
|
342
|
+
return false;
|
|
343
|
+
return (document.referrer.includes('app.expofp.com') ||
|
|
344
|
+
document.referrer.includes('app-show.expofp.com'));
|
|
345
|
+
}
|
|
346
|
+
/** `$ref` to a file in the legacy data directory, `?v=` cache-busted like all legacy loads. */
|
|
347
|
+
function legacyFileRef(baseUrl, fileName, version) {
|
|
348
|
+
const url = `${baseUrl}${fileName}`;
|
|
349
|
+
return { $ref: version ? `${url}?v=${version}` : url };
|
|
350
|
+
}
|
|
351
|
+
function sleep(ms) {
|
|
352
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Fold one input layer's deprecated `allowConsent` boolean into `consent`
|
|
356
|
+
* (`true` → `'granted'`, `false` → `'denied'`) before that layer merges, so
|
|
357
|
+
* cross-layer precedence stays exact: a layer's own `consent` beats its own
|
|
358
|
+
* alias, and a higher layer's alias still beats a lower layer's `consent`.
|
|
359
|
+
*/
|
|
360
|
+
function applyConsentAlias(layer) {
|
|
361
|
+
if (layer.allowConsent !== undefined) {
|
|
362
|
+
layer.consent ??= layer.allowConsent ? 'granted' : 'denied';
|
|
363
|
+
delete layer.allowConsent;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/** `Object.assign`, except a key explicitly set to `undefined` never erases a lower layer. */
|
|
367
|
+
function assignDefined(target, source) {
|
|
368
|
+
for (const [key, value] of Object.entries(source)) {
|
|
369
|
+
if (value !== undefined) {
|
|
370
|
+
target[key] = value;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* localStorage codec — value ⇄ key/value store (`localStorage`), with coercion
|
|
3
|
+
* driven by an ordinary Zod schema (no `z.coerce` anywhere):
|
|
4
|
+
*
|
|
5
|
+
* parseFromStorage(schema, storage) store → validated value
|
|
6
|
+
* writeToStorage(value, storage) value → store
|
|
7
|
+
* clearStorage(schema, storage) remove the schema's keys
|
|
8
|
+
*
|
|
9
|
+
* Key layout — one `efp-`-prefixed key per top-level field, devtools-readable
|
|
10
|
+
* and consistent with the app's existing keys (`efp-locale`, `efp-telemetry`):
|
|
11
|
+
* • SCALAR fields (boolean/number/string/enum) → plain string value:
|
|
12
|
+
* efp-enableExperimentalMaplibre = "true"
|
|
13
|
+
* efp-debugPattern = "map:*"
|
|
14
|
+
* • OBJECT / ARRAY fields → JSON under one key:
|
|
15
|
+
* efp-bookmarks = ["a","b"]
|
|
16
|
+
*
|
|
17
|
+
* On decode, each scalar is coerced to its declared type by introspecting the
|
|
18
|
+
* schema (`z.toJSONSchema`); objects/arrays are JSON-parsed. Only prefixed keys
|
|
19
|
+
* are ever read or written — the rest of the store is never touched. The
|
|
20
|
+
* top-level schema must be an object.
|
|
21
|
+
*/
|
|
22
|
+
import type * as z from 'zod';
|
|
23
|
+
/** The subset of the DOM `Storage` API used here — `window.localStorage` satisfies it. */
|
|
24
|
+
export interface StorageLike {
|
|
25
|
+
getItem(key: string): string | null;
|
|
26
|
+
setItem(key: string, value: string): void;
|
|
27
|
+
removeItem(key: string): void;
|
|
28
|
+
}
|
|
29
|
+
export interface StorageCodecOptions {
|
|
30
|
+
/** Key prefix. Default `'efp-'`. */
|
|
31
|
+
prefix?: string;
|
|
32
|
+
}
|
|
33
|
+
/** The SDK's localStorage key prefix (`efp-locale`, `efp-telemetry`, …). */
|
|
34
|
+
export declare const DEFAULT_STORAGE_PREFIX = "efp-";
|
|
35
|
+
export declare function parseFromStorage<S extends z.ZodType>(schema: S, storage: StorageLike, options?: StorageCodecOptions): z.infer<S>;
|
|
36
|
+
export declare function safeParseFromStorage<S extends z.ZodType>(schema: S, storage: StorageLike, options?: StorageCodecOptions): z.ZodSafeParseResult<z.TypeOf<S>>;
|
|
37
|
+
export declare function writeToStorage(value: object, storage: StorageLike, options?: StorageCodecOptions): void;
|
|
38
|
+
/** Remove every key this schema owns (its prefixed keys) from the store. */
|
|
39
|
+
export declare function clearStorage(schema: z.ZodType, storage: StorageLike, options?: StorageCodecOptions): void;
|
|
40
|
+
/** A tiny in-memory `StorageLike` for tests, SSR, or when there is no `localStorage`. */
|
|
41
|
+
export declare function createMemoryStorage(initial?: Record<string, string>): StorageLike & {
|
|
42
|
+
dump(): Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=local-storage-codec.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { coerceScalar, toJsonSchema } from './json-schema.js';
|
|
2
|
+
/** The SDK's localStorage key prefix (`efp-locale`, `efp-telemetry`, …). */
|
|
3
|
+
export const DEFAULT_STORAGE_PREFIX = 'efp-';
|
|
4
|
+
/* ── Decode: store → value ─────────────────────────────────────────────────── */
|
|
5
|
+
export function parseFromStorage(schema, storage, options = {}) {
|
|
6
|
+
return schema.parse(readRecord(schema, storage, options.prefix ?? DEFAULT_STORAGE_PREFIX));
|
|
7
|
+
}
|
|
8
|
+
export function safeParseFromStorage(schema, storage, options = {}) {
|
|
9
|
+
return schema.safeParse(readRecord(schema, storage, options.prefix ?? DEFAULT_STORAGE_PREFIX));
|
|
10
|
+
}
|
|
11
|
+
function readRecord(schema, storage, prefix) {
|
|
12
|
+
const record = {};
|
|
13
|
+
for (const [field, node] of Object.entries(toJsonSchema(schema).properties ?? {})) {
|
|
14
|
+
const raw = storage.getItem(prefix + field);
|
|
15
|
+
if (raw === null) {
|
|
16
|
+
continue; // absent → let the schema apply its default / optionality
|
|
17
|
+
}
|
|
18
|
+
record[field] = readValue(node, raw);
|
|
19
|
+
}
|
|
20
|
+
return record;
|
|
21
|
+
}
|
|
22
|
+
function readValue(node, raw) {
|
|
23
|
+
if (node.type === 'object' || node.type === 'array' || node.anyOf || node.oneOf) {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(raw);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return raw; // malformed JSON → hand the string to schema.parse for a clear error
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return coerceScalar(raw, node.type);
|
|
32
|
+
}
|
|
33
|
+
/* ── Encode: value → store (schema-agnostic) ───────────────────────────────── */
|
|
34
|
+
export function writeToStorage(value, storage, options = {}) {
|
|
35
|
+
const prefix = options.prefix ?? DEFAULT_STORAGE_PREFIX;
|
|
36
|
+
for (const [field, item] of Object.entries(value)) {
|
|
37
|
+
const key = prefix + field;
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
storage.removeItem(key);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof item === 'object') {
|
|
42
|
+
storage.setItem(key, JSON.stringify(item)); // objects & arrays → JSON
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
storage.setItem(key, String(item)); // scalars → plain string
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Remove every key this schema owns (its prefixed keys) from the store. */
|
|
50
|
+
export function clearStorage(schema, storage, options = {}) {
|
|
51
|
+
const prefix = options.prefix ?? DEFAULT_STORAGE_PREFIX;
|
|
52
|
+
for (const field of Object.keys(toJsonSchema(schema).properties ?? {})) {
|
|
53
|
+
storage.removeItem(prefix + field);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/* ── Helpers ───────────────────────────────────────────────────────────────── */
|
|
57
|
+
/** A tiny in-memory `StorageLike` for tests, SSR, or when there is no `localStorage`. */
|
|
58
|
+
export function createMemoryStorage(initial = {}) {
|
|
59
|
+
const map = new Map(Object.entries(initial));
|
|
60
|
+
return {
|
|
61
|
+
getItem: (key) => (map.has(key) ? (map.get(key)) : null),
|
|
62
|
+
setItem: (key, value) => {
|
|
63
|
+
map.set(key, value);
|
|
64
|
+
},
|
|
65
|
+
removeItem: (key) => {
|
|
66
|
+
map.delete(key);
|
|
67
|
+
},
|
|
68
|
+
dump: () => {
|
|
69
|
+
const out = {};
|
|
70
|
+
map.forEach((value, key) => {
|
|
71
|
+
out[key] = value;
|
|
72
|
+
});
|
|
73
|
+
return out;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FpSvgLayerJs } from '@expofp/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Fold the layer-suffixed drawing globals onto the canonical keys, in place.
|
|
4
|
+
*
|
|
5
|
+
* `fp.svg.<layerName>.js` files come in two converter generations: older ones
|
|
6
|
+
* chain-assign every drawing global under both names (`window['__fpHall'] =
|
|
7
|
+
* window['__fp'] = …`), newer ones emit ONLY the suffixed globals
|
|
8
|
+
* (`window['__fpBooth'] = …` — the chain had every layer script clobber the
|
|
9
|
+
* shared `window.__fp`). The schemas and the floorplan know only the plain
|
|
10
|
+
* `__fp`/`__fpPaths` keys, so the loader folds the alias onto them on the
|
|
11
|
+
* payload's own copy, before the resource walk — the `svgAsset` URL rewrite
|
|
12
|
+
* then covers a folded drawing like a plain one. The folded values skip the
|
|
13
|
+
* (opt-in) schema validation, which ran before the fold — the same trust the
|
|
14
|
+
* untouched alias keys always had.
|
|
15
|
+
*
|
|
16
|
+
* The eager `fp.svg.js` needs no fold: every runtime generation reads its
|
|
17
|
+
* plain `__fp`, so converters keep emitting it there. A resolved offline
|
|
18
|
+
* `fp.svg.<layerName>.json` may still carry only alias keys (serialization
|
|
19
|
+
* re-mints cold refs without the fold), and folds here at load like a live
|
|
20
|
+
* script.
|
|
21
|
+
*
|
|
22
|
+
* Legacy-format shim: retires with the window-assigning `.js` payloads once
|
|
23
|
+
* the platform serves resolved JSON documents.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeFpSvgLayerAliases(payload: FpSvgLayerJs, layerName: string): void;
|
|
26
|
+
//# sourceMappingURL=normalize-fp-svg.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fold the layer-suffixed drawing globals onto the canonical keys, in place.
|
|
3
|
+
*
|
|
4
|
+
* `fp.svg.<layerName>.js` files come in two converter generations: older ones
|
|
5
|
+
* chain-assign every drawing global under both names (`window['__fpHall'] =
|
|
6
|
+
* window['__fp'] = …`), newer ones emit ONLY the suffixed globals
|
|
7
|
+
* (`window['__fpBooth'] = …` — the chain had every layer script clobber the
|
|
8
|
+
* shared `window.__fp`). The schemas and the floorplan know only the plain
|
|
9
|
+
* `__fp`/`__fpPaths` keys, so the loader folds the alias onto them on the
|
|
10
|
+
* payload's own copy, before the resource walk — the `svgAsset` URL rewrite
|
|
11
|
+
* then covers a folded drawing like a plain one. The folded values skip the
|
|
12
|
+
* (opt-in) schema validation, which ran before the fold — the same trust the
|
|
13
|
+
* untouched alias keys always had.
|
|
14
|
+
*
|
|
15
|
+
* The eager `fp.svg.js` needs no fold: every runtime generation reads its
|
|
16
|
+
* plain `__fp`, so converters keep emitting it there. A resolved offline
|
|
17
|
+
* `fp.svg.<layerName>.json` may still carry only alias keys (serialization
|
|
18
|
+
* re-mints cold refs without the fold), and folds here at load like a live
|
|
19
|
+
* script.
|
|
20
|
+
*
|
|
21
|
+
* Legacy-format shim: retires with the window-assigning `.js` payloads once
|
|
22
|
+
* the platform serves resolved JSON documents.
|
|
23
|
+
*/
|
|
24
|
+
export function normalizeFpSvgLayerAliases(payload, layerName) {
|
|
25
|
+
if (payload.__fp === undefined) {
|
|
26
|
+
const alias = payload[`__fp${layerName}`];
|
|
27
|
+
if (typeof alias === 'string')
|
|
28
|
+
payload.__fp = alias;
|
|
29
|
+
}
|
|
30
|
+
if (payload.__fpPaths === undefined) {
|
|
31
|
+
const alias = payload[`__fpPaths${layerName}`];
|
|
32
|
+
// the alias carries the same converter output as __fpPaths, just unvalidated
|
|
33
|
+
if (Array.isArray(alias))
|
|
34
|
+
payload.__fpPaths = alias;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-merge normalization of the legacy event data.
|
|
3
|
+
*
|
|
4
|
+
* Ports the floorplan's historical `data/validate-data.ts`, which mutated
|
|
5
|
+
* `window.__data` at module load. The config is now the single — and frozen —
|
|
6
|
+
* copy of that data, so the same fixes run here, inside `loadConfig`, after
|
|
7
|
+
* every layer is merged and before `deepFreeze`. The rules are kept verbatim
|
|
8
|
+
* (including the expo-specific ones marked for removal); only the opt-in
|
|
9
|
+
* console diagnostics were dropped — the schema parse validates instead.
|
|
10
|
+
*/
|
|
11
|
+
import { type Config } from '@expofp/schema';
|
|
12
|
+
export declare function normalizeLegacyData(config: Config, legacyDataUrlBase?: string): void;
|
|
13
|
+
//# sourceMappingURL=normalize-legacy-data.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { withVariantUrl } from './resource-urls.js';
|
|
2
|
+
/** One-off promo for the `expo` event — exhibitor ids forced to advertise. */
|
|
3
|
+
const EXPO_EXPO_ADS = [2567, 2704, 2681, 2592, 2740, 2709, 2482, 2609, 2734, 2696, 2840, 2566, 2736];
|
|
4
|
+
export function normalizeLegacyData(config, legacyDataUrlBase) {
|
|
5
|
+
const expo = config.expo;
|
|
6
|
+
const booths = (config.booths ?? []);
|
|
7
|
+
const exhibitors = (config.exhibitors ?? []);
|
|
8
|
+
// data.js may carry explicit nulls (the layer merge skips only `undefined`),
|
|
9
|
+
// and the effective config's arrays are non-nullable — the fallbacks must
|
|
10
|
+
// land back on the config, not just in the locals above.
|
|
11
|
+
config.booths = booths;
|
|
12
|
+
config.exhibitors = exhibitors;
|
|
13
|
+
config.categories ??= [];
|
|
14
|
+
// free plans force the ad and disable featured placement
|
|
15
|
+
if (config.free) {
|
|
16
|
+
config.noFeatured = true;
|
|
17
|
+
config.expoFpAd = true;
|
|
18
|
+
}
|
|
19
|
+
// an unexpired trial marks the event as a trial
|
|
20
|
+
if (config.trialExpiresAt) {
|
|
21
|
+
const expires = new Date(config.trialExpiresAt).getTime();
|
|
22
|
+
if (Date.now() < expires) {
|
|
23
|
+
config.isTrial = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// temporary workaround for invalid data.js
|
|
27
|
+
if (exhibitors.length > 0) {
|
|
28
|
+
for (const booth of booths) {
|
|
29
|
+
delete booth.reserved;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// exhibitor logos: always the object form on the effective config — the
|
|
33
|
+
// legacy string form (already absolutized) converts here, the platform's
|
|
34
|
+
// pre-scaled __small/__tiny siblings becoming explicit variant URLs
|
|
35
|
+
for (const exhibitor of exhibitors) {
|
|
36
|
+
if (typeof exhibitor.logo === 'string') {
|
|
37
|
+
exhibitor.logo = exhibitor.logo
|
|
38
|
+
? {
|
|
39
|
+
url: exhibitor.logo,
|
|
40
|
+
smallUrl: withVariantUrl(exhibitor.logo, '__small'),
|
|
41
|
+
tinyUrl: withVariantUrl(exhibitor.logo, '__tiny'),
|
|
42
|
+
}
|
|
43
|
+
: { url: exhibitor.logo };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// some data fixes (expo-specific will be removed)
|
|
47
|
+
if (!config.logo && expo === 'expo')
|
|
48
|
+
config.logo = legacyAssetUrl('../logo.svg', legacyDataUrlBase);
|
|
49
|
+
if (!config.logo)
|
|
50
|
+
config.logo = legacyAssetUrl(`../${expo}-logo.png`, legacyDataUrlBase);
|
|
51
|
+
if (!config.homeUrl && expo === 'jtrade19')
|
|
52
|
+
config.homeUrl = 'https://www.jtrade.co.uk/';
|
|
53
|
+
// this is permanent
|
|
54
|
+
if (!config.boothTerm)
|
|
55
|
+
config.boothTerm = 'Booth';
|
|
56
|
+
if (!config.exhibitorTermPlural)
|
|
57
|
+
config.exhibitorTermPlural = 'Exhibitors';
|
|
58
|
+
if (expo === 'expo') {
|
|
59
|
+
exhibitors
|
|
60
|
+
.filter((x) => x.logo?.url && EXPO_EXPO_ADS.includes(x.id))
|
|
61
|
+
.forEach((x) => (x.advertise = true));
|
|
62
|
+
}
|
|
63
|
+
// convert obsolete fields
|
|
64
|
+
for (const booth of booths) {
|
|
65
|
+
if (!booth.special) {
|
|
66
|
+
if (typeof booth.onHold === 'undefined')
|
|
67
|
+
booth.onHold = booth.isOnHold;
|
|
68
|
+
if (typeof booth.availColor === 'undefined')
|
|
69
|
+
booth.availColor = booth.availableColor;
|
|
70
|
+
if (typeof booth.type === 'undefined')
|
|
71
|
+
booth.type = booth.boothTypeName;
|
|
72
|
+
}
|
|
73
|
+
booth.exhibitors = booth.exhibitors ?? [];
|
|
74
|
+
}
|
|
75
|
+
for (const exhibitor of exhibitors) {
|
|
76
|
+
if (typeof exhibitor.featured === 'undefined')
|
|
77
|
+
exhibitor.featured = exhibitor.isFeatured;
|
|
78
|
+
if (typeof exhibitor.email === 'undefined')
|
|
79
|
+
exhibitor.email = exhibitor.publicEmail;
|
|
80
|
+
exhibitor.categories = exhibitor.categories ?? [];
|
|
81
|
+
}
|
|
82
|
+
// disable featured placement for free plans
|
|
83
|
+
if (config.noFeatured) {
|
|
84
|
+
exhibitors.forEach((e) => (e.featured = false));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The historical logo fallbacks are data-dir-relative paths — rebase them onto the data directory. */
|
|
88
|
+
function legacyAssetUrl(path, base) {
|
|
89
|
+
return base ? `${base.replace(/\/+$/, '')}/${path}` : path;
|
|
90
|
+
}
|