@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,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rebooking layer of `loadConfig`.
|
|
3
|
+
*
|
|
4
|
+
* When a rebooking token is present (page query `?rt=…`, retained in
|
|
5
|
+
* `sessionStorage` across in-session navigations), fetch the per-exhibitor
|
|
6
|
+
* rebooking state from the platform and merge it into the not-yet-frozen
|
|
7
|
+
* config: `exhibitors[].rebookingState` / `rebookingNote` plus the
|
|
8
|
+
* `isRebooking` flag. Ported from the floorplan loader's init-time merge so
|
|
9
|
+
* the frozen config stays the single, complete copy of the event data. The
|
|
10
|
+
* floorplan keeps its own `tools/rebookingUrl.ts` helpers for UI *actions*
|
|
11
|
+
* against the same API (e.g. `set-rebooking-state`).
|
|
12
|
+
*
|
|
13
|
+
* Without a token — every ordinary visitor, and Node callers that pass no
|
|
14
|
+
* `url` — this is a synchronous no-op apart from `isRebooking = false`.
|
|
15
|
+
*/
|
|
16
|
+
import { type Config } from '@expofp/schema';
|
|
17
|
+
/** Merge rebooking state into `config` when a token is present. Never throws. */
|
|
18
|
+
export declare function applyRebookingData(config: Config, url: string | undefined): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=rebooking.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const TOKEN_KEY = 'rt';
|
|
2
|
+
const REBOOKING_API_ORIGIN = 'https://app.expofp.com/';
|
|
3
|
+
/** Merge rebooking state into `config` when a token is present. Never throws. */
|
|
4
|
+
export async function applyRebookingData(config, url) {
|
|
5
|
+
try {
|
|
6
|
+
const token = getRebookingToken(url);
|
|
7
|
+
if (!token) {
|
|
8
|
+
config.isRebooking = false;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
retainRebookingToken(token);
|
|
12
|
+
const apiUrl = new URL('api/rebooking-data', REBOOKING_API_ORIGIN);
|
|
13
|
+
apiUrl.searchParams.set(TOKEN_KEY, token);
|
|
14
|
+
apiUrl.searchParams.set('expoKey', config.expo);
|
|
15
|
+
const resp = await fetch(apiUrl.href);
|
|
16
|
+
if (resp.ok) {
|
|
17
|
+
const rebooking = (await resp.json());
|
|
18
|
+
mergeRebookingState(config, rebooking.exhibitors ?? []);
|
|
19
|
+
}
|
|
20
|
+
config.isRebooking = resp.ok;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
// parity with the old loader merge: report and continue without rebooking
|
|
24
|
+
console.error(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Token from the page query (same decode the floorplan helpers use), else the retained one. */
|
|
28
|
+
function getRebookingToken(url) {
|
|
29
|
+
const fromQuery = url ? new URLSearchParams(decodeURIComponent(url)).get(TOKEN_KEY) : null;
|
|
30
|
+
if (fromQuery)
|
|
31
|
+
return fromQuery;
|
|
32
|
+
return typeof sessionStorage !== 'undefined' ? sessionStorage.getItem(TOKEN_KEY) : null;
|
|
33
|
+
}
|
|
34
|
+
function retainRebookingToken(token) {
|
|
35
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
36
|
+
sessionStorage.setItem(TOKEN_KEY, token);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function mergeRebookingState(config, incoming) {
|
|
40
|
+
const exhibitors = config.exhibitors ?? [];
|
|
41
|
+
for (const rebooking of incoming) {
|
|
42
|
+
const exhibitor = exhibitors.find((x) => x.id === rebooking.id);
|
|
43
|
+
if (exhibitor) {
|
|
44
|
+
exhibitor.rebookingState = rebooking.rebookingState;
|
|
45
|
+
exhibitor.rebookingNote = rebooking.rebookingNote;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal URL/text helpers for the schema-tagged resource kinds. Nothing here
|
|
3
|
+
* is public API — consumers only ever see the effects: `resolve(ref, {
|
|
4
|
+
* schema })` settles documents with absolute resource URLs, and
|
|
5
|
+
* `visitResources` enumerates/rewrites them.
|
|
6
|
+
*/
|
|
7
|
+
/** Prepend `baseUrl` to a relative path so it becomes a full URL; absolute paths pass through. */
|
|
8
|
+
export declare function toAbsoluteUrl(path: string, baseUrl: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Scheme-qualified (`https:`, `data:`, `blob:`…), protocol-relative
|
|
11
|
+
* (`//host/…`), or rooted (`/…` — already resolved, just host-less). Note a
|
|
12
|
+
* page-relative offline path (`host-slug/data/…`, no leading slash) is NOT
|
|
13
|
+
* absolute: it is resolved against the page at runtime, so document loads must
|
|
14
|
+
* not rebase it (see `documentRef`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAbsoluteUrl(path: string): boolean;
|
|
17
|
+
/** The ref's own directory — the base its document's relative paths resolve against. */
|
|
18
|
+
export declare function refDirectory(ref: string): string;
|
|
19
|
+
/** Every distinct `<image>` asset URL in one SVG document string. */
|
|
20
|
+
export declare function collectSvgImageAssets(svg: string): string[];
|
|
21
|
+
/** Rewrite every `<image>` asset URL in one SVG document string. */
|
|
22
|
+
export declare function rewriteSvgImageAssets(svg: string, rewrite: (url: string) => string): string;
|
|
23
|
+
/** Every distinct non-`data:` `url(…)` in one CSS text. */
|
|
24
|
+
export declare function collectCssUrls(css: string): string[];
|
|
25
|
+
/** Rewrite every non-`data:` `url(…)` in one CSS text. */
|
|
26
|
+
export declare function rewriteCssUrls(css: string, rewrite: (url: string) => string): string;
|
|
27
|
+
export interface InlinedCss {
|
|
28
|
+
css: string;
|
|
29
|
+
/** Import URLs left in place (conditional/unresolvable) — keep them verbatim, don't localize. */
|
|
30
|
+
external: Set<string>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Replace every unconditional `@import` with the imported stylesheet's text.
|
|
34
|
+
*
|
|
35
|
+
* An offline copy cannot keep stylesheets as fetched files: a URL like
|
|
36
|
+
* `https://fonts.googleapis.com/css2?family=…` saves to an extension-less
|
|
37
|
+
* path that static servers refuse to serve as `text/css` (stylesheet loads
|
|
38
|
+
* enforce MIME), and the file's inner `url(…)`s would stay remote. Splicing
|
|
39
|
+
* the text into the importing CSS instead lets the ordinary `url(…)`
|
|
40
|
+
* localization pass handle every asset the import pulled in.
|
|
41
|
+
*
|
|
42
|
+
* Inner URLs of an imported sheet resolve against the *sheet's* URL, so they
|
|
43
|
+
* are rebased to absolute before splicing; nested imports recurse the same
|
|
44
|
+
* way. A conditional import (layer/supports/media) has no faithful inline
|
|
45
|
+
* form — it is kept verbatim (still network-dependent) with a warning, as is
|
|
46
|
+
* a relative href with no base to resolve against. An import cycle fails the
|
|
47
|
+
* build loudly.
|
|
48
|
+
*/
|
|
49
|
+
export declare function inlineCssImports(css: string, fetchText: (url: string) => string | Promise<string>, base?: string, stack?: readonly string[]): Promise<InlinedCss>;
|
|
50
|
+
/** `…/name.ext?q` → `…/name<suffix>.ext?q` (query untouched). */
|
|
51
|
+
export declare function withVariantUrl(url: string, suffix: string): string;
|
|
52
|
+
//# sourceMappingURL=resource-urls.d.ts.map
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal URL/text helpers for the schema-tagged resource kinds. Nothing here
|
|
3
|
+
* is public API — consumers only ever see the effects: `resolve(ref, {
|
|
4
|
+
* schema })` settles documents with absolute resource URLs, and
|
|
5
|
+
* `visitResources` enumerates/rewrites them.
|
|
6
|
+
*/
|
|
7
|
+
/** Prepend `baseUrl` to a relative path so it becomes a full URL; absolute paths pass through. */
|
|
8
|
+
export function toAbsoluteUrl(path, baseUrl) {
|
|
9
|
+
if (path === '' || isAbsoluteUrl(path)) {
|
|
10
|
+
return path;
|
|
11
|
+
}
|
|
12
|
+
return `${baseUrl.replace(/\/+$/, '')}/${path}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Scheme-qualified (`https:`, `data:`, `blob:`…), protocol-relative
|
|
16
|
+
* (`//host/…`), or rooted (`/…` — already resolved, just host-less). Note a
|
|
17
|
+
* page-relative offline path (`host-slug/data/…`, no leading slash) is NOT
|
|
18
|
+
* absolute: it is resolved against the page at runtime, so document loads must
|
|
19
|
+
* not rebase it (see `documentRef`).
|
|
20
|
+
*/
|
|
21
|
+
export function isAbsoluteUrl(path) {
|
|
22
|
+
return path.startsWith('/') || /^[a-z][a-z0-9+.-]*:/i.test(path);
|
|
23
|
+
}
|
|
24
|
+
/** The ref's own directory — the base its document's relative paths resolve against. */
|
|
25
|
+
export function refDirectory(ref) {
|
|
26
|
+
const path = ref.split(/[?#]/, 1)[0];
|
|
27
|
+
return path.slice(0, path.lastIndexOf('/') + 1);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `[...text.matchAll(regex)]` without `String.prototype.matchAll` — the
|
|
31
|
+
* collect functions run on the boot path and the SDK still targets Chrome
|
|
32
|
+
* 66–72 WebViews (matchAll is Chrome 73+). Resets `lastIndex` up front so the
|
|
33
|
+
* shared module-const `/g` regexes cannot carry scan state between calls.
|
|
34
|
+
*/
|
|
35
|
+
function execAll(regex, text) {
|
|
36
|
+
const matches = [];
|
|
37
|
+
regex.lastIndex = 0;
|
|
38
|
+
for (let match = regex.exec(text); match; match = regex.exec(text)) {
|
|
39
|
+
matches.push(match);
|
|
40
|
+
if (match[0] === '')
|
|
41
|
+
regex.lastIndex++; // zero-length match must not stall the scan
|
|
42
|
+
}
|
|
43
|
+
return matches;
|
|
44
|
+
}
|
|
45
|
+
/* ── SVG documents (`svgAsset`) — an `<image>`'s URLs are asset paths ─────── */
|
|
46
|
+
const IMAGE_TAG = /<image\b[^>]*>/g;
|
|
47
|
+
/**
|
|
48
|
+
* The asset-bearing attributes of an `<image>`: the href it draws, and
|
|
49
|
+
* `data-model-3d` — the URL of the 3D model the floor plan renders *instead* of
|
|
50
|
+
* the image, whose href then never loads (floorplan's `layer-models.ts`). Both are
|
|
51
|
+
* authored relative to the drawing, so both need the same rebase; a model URL
|
|
52
|
+
* left behind resolves against the page and 404s.
|
|
53
|
+
*/
|
|
54
|
+
const ASSET_ATTR = /(\b(?:(?:xlink:)?href|data-model-3d)\s*=\s*)(?:"([^"]*)"|'([^']*)')/g;
|
|
55
|
+
/** In-document (`#id`) and empty references are not asset URLs. */
|
|
56
|
+
function isAssetUrl(url) {
|
|
57
|
+
return !!url && !url.startsWith('#');
|
|
58
|
+
}
|
|
59
|
+
/** Every distinct `<image>` asset URL in one SVG document string. */
|
|
60
|
+
export function collectSvgImageAssets(svg) {
|
|
61
|
+
const urls = new Set();
|
|
62
|
+
if (!svg.includes('<image'))
|
|
63
|
+
return [];
|
|
64
|
+
for (const tag of svg.match(IMAGE_TAG) ?? []) {
|
|
65
|
+
for (const match of execAll(ASSET_ATTR, tag)) {
|
|
66
|
+
const url = match[2] ?? match[3];
|
|
67
|
+
if (isAssetUrl(url))
|
|
68
|
+
urls.add(url);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [...urls];
|
|
72
|
+
}
|
|
73
|
+
/** Rewrite every `<image>` asset URL in one SVG document string. */
|
|
74
|
+
export function rewriteSvgImageAssets(svg, rewrite) {
|
|
75
|
+
if (!svg.includes('<image'))
|
|
76
|
+
return svg;
|
|
77
|
+
return svg.replace(IMAGE_TAG, (tag) => tag.replace(ASSET_ATTR, (match, attr, doubleQuoted, singleQuoted) => {
|
|
78
|
+
const url = doubleQuoted ?? singleQuoted ?? '';
|
|
79
|
+
if (!isAssetUrl(url))
|
|
80
|
+
return match;
|
|
81
|
+
const quote = doubleQuoted !== undefined ? '"' : "'";
|
|
82
|
+
return `${attr}${quote}${rewrite(url)}${quote}`;
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/* ── CSS text (`cssAsset`) — `url(…)`s are asset paths ────────────────────── */
|
|
86
|
+
const CSS_URL = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
|
|
87
|
+
/** Every distinct non-`data:` `url(…)` in one CSS text. */
|
|
88
|
+
export function collectCssUrls(css) {
|
|
89
|
+
const urls = new Set();
|
|
90
|
+
for (const match of execAll(CSS_URL, css)) {
|
|
91
|
+
const url = match[2];
|
|
92
|
+
if (url && !url.startsWith('data:'))
|
|
93
|
+
urls.add(url);
|
|
94
|
+
}
|
|
95
|
+
return [...urls];
|
|
96
|
+
}
|
|
97
|
+
/** Rewrite every non-`data:` `url(…)` in one CSS text. */
|
|
98
|
+
export function rewriteCssUrls(css, rewrite) {
|
|
99
|
+
return css.replace(CSS_URL, (match, quote, url) => {
|
|
100
|
+
if (!url || url.startsWith('data:'))
|
|
101
|
+
return match;
|
|
102
|
+
return `url(${quote}${rewrite(url)}${quote})`;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/* ── CSS `@import` inlining (offline serialization) ───────────────────────── */
|
|
106
|
+
// One `@import` rule: `url(…)` or bare-string href, then everything up to the
|
|
107
|
+
// terminating `;` (an optional layer/supports/media condition).
|
|
108
|
+
const CSS_IMPORT = /@import\s+(?:url\(\s*(['"]?)(.*?)\1\s*\)|(["'])(.*?)\3)\s*([^;]*);/gi;
|
|
109
|
+
/**
|
|
110
|
+
* Replace every unconditional `@import` with the imported stylesheet's text.
|
|
111
|
+
*
|
|
112
|
+
* An offline copy cannot keep stylesheets as fetched files: a URL like
|
|
113
|
+
* `https://fonts.googleapis.com/css2?family=…` saves to an extension-less
|
|
114
|
+
* path that static servers refuse to serve as `text/css` (stylesheet loads
|
|
115
|
+
* enforce MIME), and the file's inner `url(…)`s would stay remote. Splicing
|
|
116
|
+
* the text into the importing CSS instead lets the ordinary `url(…)`
|
|
117
|
+
* localization pass handle every asset the import pulled in.
|
|
118
|
+
*
|
|
119
|
+
* Inner URLs of an imported sheet resolve against the *sheet's* URL, so they
|
|
120
|
+
* are rebased to absolute before splicing; nested imports recurse the same
|
|
121
|
+
* way. A conditional import (layer/supports/media) has no faithful inline
|
|
122
|
+
* form — it is kept verbatim (still network-dependent) with a warning, as is
|
|
123
|
+
* a relative href with no base to resolve against. An import cycle fails the
|
|
124
|
+
* build loudly.
|
|
125
|
+
*/
|
|
126
|
+
export async function inlineCssImports(css, fetchText, base, stack = []) {
|
|
127
|
+
const external = new Set();
|
|
128
|
+
const imports = [...css.matchAll(CSS_IMPORT)];
|
|
129
|
+
const replacements = await Promise.all(imports.map(async (match) => {
|
|
130
|
+
const href = match[2] ?? match[4] ?? '';
|
|
131
|
+
const condition = match[5].trim();
|
|
132
|
+
const url = resolveImportHref(href, base);
|
|
133
|
+
if (!url || condition) {
|
|
134
|
+
if (condition) {
|
|
135
|
+
console.warn(`Keeping conditional CSS import remote: @import ${href} ${condition}`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.warn(`Keeping unresolvable relative CSS import: @import ${href}`);
|
|
139
|
+
}
|
|
140
|
+
external.add(href);
|
|
141
|
+
return match[0];
|
|
142
|
+
}
|
|
143
|
+
if (stack.includes(url)) {
|
|
144
|
+
throw new Error(`CSS @import cycle: ${[...stack, url].join(' -> ')}`);
|
|
145
|
+
}
|
|
146
|
+
const imported = await fetchText(url);
|
|
147
|
+
// A common authoring slip is `@import url(font.ttf)` sitting beside a real
|
|
148
|
+
// `@font-face` — the browser fetches the font, fails to parse it as CSS,
|
|
149
|
+
// and the import contributes nothing (a no-op). Splicing its bytes in here
|
|
150
|
+
// would instead inject binary garbage that corrupts the whole stylesheet.
|
|
151
|
+
// Replicate the browser: drop the import. The font still loads offline via
|
|
152
|
+
// the sibling `@font-face`'s own `url(…)`, which the asset pass localizes.
|
|
153
|
+
if (!isStylesheetText(imported)) {
|
|
154
|
+
console.warn(`Dropping non-stylesheet CSS @import (not parseable as CSS): @import ${href}`);
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
// nested imports and relative url(…)s resolve against the imported sheet
|
|
158
|
+
const nested = await inlineCssImports(imported, fetchText, url, [...stack, url]);
|
|
159
|
+
for (const kept of nested.external) {
|
|
160
|
+
// the rebase below turns a kept rule's relative href absolute — track both forms
|
|
161
|
+
external.add(kept);
|
|
162
|
+
external.add(resolveImportHref(kept, url) ?? kept);
|
|
163
|
+
}
|
|
164
|
+
return rewriteCssUrls(nested.css, (inner) => resolveImportHref(inner, url) ?? inner);
|
|
165
|
+
}));
|
|
166
|
+
let index = 0;
|
|
167
|
+
return { css: css.replace(CSS_IMPORT, () => replacements[index++]), external };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Whether fetched `@import` content is a stylesheet rather than a binary asset
|
|
171
|
+
* (font/image) mistakenly targeted by `@import`. A NUL byte — abundant in every
|
|
172
|
+
* font format (TTF/OTF/WOFF/WOFF2/EOT) once decoded as text — never appears in a
|
|
173
|
+
* CSS stylesheet, so it is a precise, false-positive-free signal for binary.
|
|
174
|
+
*/
|
|
175
|
+
function isStylesheetText(text) {
|
|
176
|
+
return !text.includes('\u0000');
|
|
177
|
+
}
|
|
178
|
+
/** The href's absolute URL, or undefined when it is relative with no base to resolve against. */
|
|
179
|
+
function resolveImportHref(href, base) {
|
|
180
|
+
if (!href)
|
|
181
|
+
return undefined;
|
|
182
|
+
try {
|
|
183
|
+
return base ? new URL(href, base).href : new URL(href).href;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/* ── Logo variants — pre-scaled sibling files by filename suffix ──────────── */
|
|
190
|
+
/** `…/name.ext?q` → `…/name<suffix>.ext?q` (query untouched). */
|
|
191
|
+
export function withVariantUrl(url, suffix) {
|
|
192
|
+
const [path, query] = splitOnce(url, /[?#]/);
|
|
193
|
+
const lastSlash = path.lastIndexOf('/');
|
|
194
|
+
const dir = path.slice(0, lastSlash + 1);
|
|
195
|
+
const filename = path.slice(lastSlash + 1);
|
|
196
|
+
const dot = filename.lastIndexOf('.');
|
|
197
|
+
const suffixed = dot > 0 ? `${filename.slice(0, dot)}${suffix}${filename.slice(dot)}` : `${filename}${suffix}`;
|
|
198
|
+
return `${dir}${suffixed}${query}`;
|
|
199
|
+
}
|
|
200
|
+
function splitOnce(value, at) {
|
|
201
|
+
const index = value.search(at);
|
|
202
|
+
return index === -1 ? [value, ''] : [value.slice(0, index), value.slice(index)];
|
|
203
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Config, type Manifest } from '@expofp/schema';
|
|
2
|
+
import { type ResourceHandler } from './visit-resources.js';
|
|
3
|
+
/**
|
|
4
|
+
* Where serialized resources go: the caller decides storage (paths, prefixes,
|
|
5
|
+
* downloads); the config decides *what* the resources are.
|
|
6
|
+
*/
|
|
7
|
+
export type ConfigResourceStore = ResourceHandler;
|
|
8
|
+
/**
|
|
9
|
+
* Serialize a loaded config into a portable manifest: every schema-tagged
|
|
10
|
+
* asset (plain URLs, `<image>` hrefs inside the drawings, CSS `url(…)`s,
|
|
11
|
+
* pre-scaled exhibitor image variants) and every referenced payload document
|
|
12
|
+
* (drawing, layers, wayfinding graph — resolved on the fly) is handed to
|
|
13
|
+
* `store`, and the returned copy points at whatever URLs the store assigned.
|
|
14
|
+
*
|
|
15
|
+
* The legacy data directory fields are dropped — a serialized config IS the
|
|
16
|
+
* complete event data document, so a runtime consuming it derives and fetches
|
|
17
|
+
* nothing beyond the refs the store wrote.
|
|
18
|
+
*/
|
|
19
|
+
export declare function serializeConfigResources(config: Config, store: ConfigResourceStore, options?: {
|
|
20
|
+
signal?: AbortSignal | null;
|
|
21
|
+
}): Promise<Manifest>;
|
|
22
|
+
/**
|
|
23
|
+
* Version of the serialization POLICY — what {@link serializeConfigResources}
|
|
24
|
+
* does to a config beyond what the schema says: the walk's rewrite rules
|
|
25
|
+
* (`visit-resources`), the CSS `@import` splicing, the legacy normalization.
|
|
26
|
+
* Bump it by hand when that behavior changes without a schema change; it is
|
|
27
|
+
* one half of {@link serializationFormat}.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SERIALIZER_VERSION = 1;
|
|
30
|
+
/**
|
|
31
|
+
* The identity of the form a serialized manifest takes — the text a generator
|
|
32
|
+
* hashes into its format stamp. Two halves: the JSON Schema of `ConfigSchema`
|
|
33
|
+
* (the shape every snapshot follows; the referenced document schemas ride
|
|
34
|
+
* inside it, so a drawing- or wayfinding-schema change counts too — a schema
|
|
35
|
+
* change is a format change by construction, no hand bump needed) and
|
|
36
|
+
* {@link SERIALIZER_VERSION}. Deterministic across processes and platforms
|
|
37
|
+
* for one build of the packages.
|
|
38
|
+
*
|
|
39
|
+
* A snapshot built under one stamp must not be served under a runtime that
|
|
40
|
+
* expects another: the cloud generator (plan G § 2, wave G2) keys its
|
|
41
|
+
* level-0 "nothing changed" skip on this stamp next to the data revision, so
|
|
42
|
+
* a deploy that changes the format rebuilds every snapshot and a deploy that
|
|
43
|
+
* does not leaves them alone.
|
|
44
|
+
*/
|
|
45
|
+
export declare function serializationFormat(): string;
|
|
46
|
+
//# sourceMappingURL=serialize-config-resources.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ConfigSchema } from '@expofp/schema';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { visitResources } from './visit-resources.js';
|
|
4
|
+
/**
|
|
5
|
+
* Serialize a loaded config into a portable manifest: every schema-tagged
|
|
6
|
+
* asset (plain URLs, `<image>` hrefs inside the drawings, CSS `url(…)`s,
|
|
7
|
+
* pre-scaled exhibitor image variants) and every referenced payload document
|
|
8
|
+
* (drawing, layers, wayfinding graph — resolved on the fly) is handed to
|
|
9
|
+
* `store`, and the returned copy points at whatever URLs the store assigned.
|
|
10
|
+
*
|
|
11
|
+
* The legacy data directory fields are dropped — a serialized config IS the
|
|
12
|
+
* complete event data document, so a runtime consuming it derives and fetches
|
|
13
|
+
* nothing beyond the refs the store wrote.
|
|
14
|
+
*/
|
|
15
|
+
export async function serializeConfigResources(config, store, options) {
|
|
16
|
+
// a JSON round-trip IS the serialization: it thaws the frozen config and
|
|
17
|
+
// sheds the refs' in-code `process` decorations in one move
|
|
18
|
+
const manifest = JSON.parse(JSON.stringify(config));
|
|
19
|
+
await visitResources(ConfigSchema, manifest, store, { signal: options?.signal });
|
|
20
|
+
return manifest;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Version of the serialization POLICY — what {@link serializeConfigResources}
|
|
24
|
+
* does to a config beyond what the schema says: the walk's rewrite rules
|
|
25
|
+
* (`visit-resources`), the CSS `@import` splicing, the legacy normalization.
|
|
26
|
+
* Bump it by hand when that behavior changes without a schema change; it is
|
|
27
|
+
* one half of {@link serializationFormat}.
|
|
28
|
+
*/
|
|
29
|
+
export const SERIALIZER_VERSION = 1;
|
|
30
|
+
/**
|
|
31
|
+
* The identity of the form a serialized manifest takes — the text a generator
|
|
32
|
+
* hashes into its format stamp. Two halves: the JSON Schema of `ConfigSchema`
|
|
33
|
+
* (the shape every snapshot follows; the referenced document schemas ride
|
|
34
|
+
* inside it, so a drawing- or wayfinding-schema change counts too — a schema
|
|
35
|
+
* change is a format change by construction, no hand bump needed) and
|
|
36
|
+
* {@link SERIALIZER_VERSION}. Deterministic across processes and platforms
|
|
37
|
+
* for one build of the packages.
|
|
38
|
+
*
|
|
39
|
+
* A snapshot built under one stamp must not be served under a runtime that
|
|
40
|
+
* expects another: the cloud generator (plan G § 2, wave G2) keys its
|
|
41
|
+
* level-0 "nothing changed" skip on this stamp next to the data revision, so
|
|
42
|
+
* a deploy that changes the format rebuilds every snapshot and a deploy that
|
|
43
|
+
* does not leaves them alone.
|
|
44
|
+
*/
|
|
45
|
+
export function serializationFormat() {
|
|
46
|
+
return JSON.stringify({
|
|
47
|
+
serializer: SERIALIZER_VERSION,
|
|
48
|
+
schema: z.toJSONSchema(ConfigSchema, { io: 'input' }),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `$/` notation of the normalized expo form (plan G § 3) — the codec
|
|
3
|
+
* between a store ref and the canonical URL it aliases.
|
|
4
|
+
*
|
|
5
|
+
* Every object of an expo's content-addressed store lives at one URL fixed
|
|
6
|
+
* forever — `https://<expo>.expofp.com/immutable/<hash>/<name>`, the expo's
|
|
7
|
+
* production host whichever contour generated or serves the folder — and
|
|
8
|
+
* the store ref `$/<expo>/<hash>/<name>` is that URL's alias by pure prefix
|
|
9
|
+
* substitution. No document, page or base URL takes part, so a snapshot
|
|
10
|
+
* reads identically from a contour page, an integrator's host, a local
|
|
11
|
+
* `floorplan.js`, an inline copy or a Node tool. The two forms are
|
|
12
|
+
* equivalent and a creator compacts at will: shorter bytes, an explicit
|
|
13
|
+
* "store content" marker, and an alias that survives a domain move.
|
|
14
|
+
*
|
|
15
|
+
* The marker is unambiguous by generation invariant, not by URL illegality:
|
|
16
|
+
* a store only ever returns canonical URLs, and no passthrough value ever
|
|
17
|
+
* starts with `$/`. A ref left unexpanded by mistake breaks loudly — an
|
|
18
|
+
* honest 404 on `<base>/$/…` — where a `#/…` fragment would fail silently.
|
|
19
|
+
*
|
|
20
|
+
* The schema `.meta` walker (`visit-resources`) calls the codec at every
|
|
21
|
+
* URL-carrying place — manifest fields, document `$ref`s, CSS `url(…)`
|
|
22
|
+
* tokens, `<image>` hrefs of a drawing — so prose like `US$/day` is never
|
|
23
|
+
* touched, and the effective config only ever carries full URLs.
|
|
24
|
+
*/
|
|
25
|
+
/** Whether a URL-carrying value is a store ref (`$/…`). */
|
|
26
|
+
export declare function isStoreRef(value: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Expand a store ref into the canonical URL it aliases:
|
|
29
|
+
* `$/demo/ZL-InrvJgYpz1-k2/logo.png` →
|
|
30
|
+
* `https://demo.expofp.com/immutable/ZL-InrvJgYpz1-k2/logo.png`. Any other
|
|
31
|
+
* value — a full URL, a rooted or relative path, a `data:` URI — passes
|
|
32
|
+
* through untouched. A malformed `$/…` is a generation bug and throws.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveUrl(ref: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Compact a canonical store URL into its `$/` alias — the inverse of
|
|
37
|
+
* {@link resolveUrl}; any other URL passes through untouched.
|
|
38
|
+
*/
|
|
39
|
+
export declare function compactUrl(url: string): string;
|
|
40
|
+
//# sourceMappingURL=store-ref.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `$/` notation of the normalized expo form (plan G § 3) — the codec
|
|
3
|
+
* between a store ref and the canonical URL it aliases.
|
|
4
|
+
*
|
|
5
|
+
* Every object of an expo's content-addressed store lives at one URL fixed
|
|
6
|
+
* forever — `https://<expo>.expofp.com/immutable/<hash>/<name>`, the expo's
|
|
7
|
+
* production host whichever contour generated or serves the folder — and
|
|
8
|
+
* the store ref `$/<expo>/<hash>/<name>` is that URL's alias by pure prefix
|
|
9
|
+
* substitution. No document, page or base URL takes part, so a snapshot
|
|
10
|
+
* reads identically from a contour page, an integrator's host, a local
|
|
11
|
+
* `floorplan.js`, an inline copy or a Node tool. The two forms are
|
|
12
|
+
* equivalent and a creator compacts at will: shorter bytes, an explicit
|
|
13
|
+
* "store content" marker, and an alias that survives a domain move.
|
|
14
|
+
*
|
|
15
|
+
* The marker is unambiguous by generation invariant, not by URL illegality:
|
|
16
|
+
* a store only ever returns canonical URLs, and no passthrough value ever
|
|
17
|
+
* starts with `$/`. A ref left unexpanded by mistake breaks loudly — an
|
|
18
|
+
* honest 404 on `<base>/$/…` — where a `#/…` fragment would fail silently.
|
|
19
|
+
*
|
|
20
|
+
* The schema `.meta` walker (`visit-resources`) calls the codec at every
|
|
21
|
+
* URL-carrying place — manifest fields, document `$ref`s, CSS `url(…)`
|
|
22
|
+
* tokens, `<image>` hrefs of a drawing — so prose like `US$/day` is never
|
|
23
|
+
* touched, and the effective config only ever carries full URLs.
|
|
24
|
+
*/
|
|
25
|
+
const STORE_REF_PREFIX = '$/';
|
|
26
|
+
/** `$/<expo>/<key>` — the expo is one lowercase DNS label, the key is the rest verbatim. */
|
|
27
|
+
const STORE_REF = /^\$\/([a-z0-9-]+)\/(.+)$/;
|
|
28
|
+
/** The canonical store URL: the expo's production host, `/immutable/<key>`. */
|
|
29
|
+
const CANONICAL_URL = /^https:\/\/([a-z0-9-]+)\.expofp\.com\/immutable\/(.+)$/;
|
|
30
|
+
/** Whether a URL-carrying value is a store ref (`$/…`). */
|
|
31
|
+
export function isStoreRef(value) {
|
|
32
|
+
return value.startsWith(STORE_REF_PREFIX);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Expand a store ref into the canonical URL it aliases:
|
|
36
|
+
* `$/demo/ZL-InrvJgYpz1-k2/logo.png` →
|
|
37
|
+
* `https://demo.expofp.com/immutable/ZL-InrvJgYpz1-k2/logo.png`. Any other
|
|
38
|
+
* value — a full URL, a rooted or relative path, a `data:` URI — passes
|
|
39
|
+
* through untouched. A malformed `$/…` is a generation bug and throws.
|
|
40
|
+
*/
|
|
41
|
+
export function resolveUrl(ref) {
|
|
42
|
+
if (!isStoreRef(ref))
|
|
43
|
+
return ref;
|
|
44
|
+
const match = STORE_REF.exec(ref);
|
|
45
|
+
if (!match)
|
|
46
|
+
throw new Error(`resolveUrl: malformed store ref ${JSON.stringify(ref)}`);
|
|
47
|
+
return `https://${match[1]}.expofp.com/immutable/${match[2]}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compact a canonical store URL into its `$/` alias — the inverse of
|
|
51
|
+
* {@link resolveUrl}; any other URL passes through untouched.
|
|
52
|
+
*/
|
|
53
|
+
export function compactUrl(url) {
|
|
54
|
+
const match = CANONICAL_URL.exec(url);
|
|
55
|
+
return match ? `${STORE_REF_PREFIX}${match[1]}/${match[2]}` : url;
|
|
56
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Return a clone of `schema` with every `.default()` and `.prefault()` removed,
|
|
4
|
+
* recursively.
|
|
5
|
+
*
|
|
6
|
+
* Layered config parses each source (manifest, options, localStorage, URL)
|
|
7
|
+
* against an all-optional schema and merges the results. A default left in
|
|
8
|
+
* those schemas would materialize on *every* layer's parse — and in Zod 4
|
|
9
|
+
* `.partial()` does NOT suppress it — so a higher, empty layer would stomp a
|
|
10
|
+
* lower layer's explicit value. Strip defaults for the per-layer parse and
|
|
11
|
+
* apply them once, afterwards (see `ConfigDefaults`).
|
|
12
|
+
*
|
|
13
|
+
* A stripped field becomes `.optional()`: a default exists precisely because
|
|
14
|
+
* the input may omit the key, so the stripped schema parses a partial layer
|
|
15
|
+
* (missing key → absent) instead of erroring on the now-defaultless field.
|
|
16
|
+
*
|
|
17
|
+
* Recurses through objects, arrays, and the optional/nullable/readonly wrapper
|
|
18
|
+
* chain, carrying each node's `.meta()` across (the `asset`/`cssAsset` tags
|
|
19
|
+
* `DataSchema` relies on). Nodes it does not recognize — unions, records,
|
|
20
|
+
* tuples, lazy, pipes — are returned untouched, so a default nested inside one
|
|
21
|
+
* of those is left in place, and object-level modes/refinements (`.strict()`,
|
|
22
|
+
* `.refine()`, `.min()`, …) on rebuilt containers are not carried over. The
|
|
23
|
+
* config schemas keep defaults at the object top level and use none of those,
|
|
24
|
+
* so the boundary does not bite; widen the checks below if that changes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function stripDefaults(schema: z.core.$ZodType): z.ZodType;
|
|
27
|
+
//# sourceMappingURL=strip-defaults.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Return a clone of `schema` with every `.default()` and `.prefault()` removed,
|
|
4
|
+
* recursively.
|
|
5
|
+
*
|
|
6
|
+
* Layered config parses each source (manifest, options, localStorage, URL)
|
|
7
|
+
* against an all-optional schema and merges the results. A default left in
|
|
8
|
+
* those schemas would materialize on *every* layer's parse — and in Zod 4
|
|
9
|
+
* `.partial()` does NOT suppress it — so a higher, empty layer would stomp a
|
|
10
|
+
* lower layer's explicit value. Strip defaults for the per-layer parse and
|
|
11
|
+
* apply them once, afterwards (see `ConfigDefaults`).
|
|
12
|
+
*
|
|
13
|
+
* A stripped field becomes `.optional()`: a default exists precisely because
|
|
14
|
+
* the input may omit the key, so the stripped schema parses a partial layer
|
|
15
|
+
* (missing key → absent) instead of erroring on the now-defaultless field.
|
|
16
|
+
*
|
|
17
|
+
* Recurses through objects, arrays, and the optional/nullable/readonly wrapper
|
|
18
|
+
* chain, carrying each node's `.meta()` across (the `asset`/`cssAsset` tags
|
|
19
|
+
* `DataSchema` relies on). Nodes it does not recognize — unions, records,
|
|
20
|
+
* tuples, lazy, pipes — are returned untouched, so a default nested inside one
|
|
21
|
+
* of those is left in place, and object-level modes/refinements (`.strict()`,
|
|
22
|
+
* `.refine()`, `.min()`, …) on rebuilt containers are not carried over. The
|
|
23
|
+
* config schemas keep defaults at the object top level and use none of those,
|
|
24
|
+
* so the boundary does not bite; widen the checks below if that changes.
|
|
25
|
+
*/
|
|
26
|
+
export function stripDefaults(schema) {
|
|
27
|
+
if (schema instanceof z.ZodDefault || schema instanceof z.ZodPrefault) {
|
|
28
|
+
return keepMeta(schema, stripDefaults(schema.unwrap()).optional());
|
|
29
|
+
}
|
|
30
|
+
if (schema instanceof z.ZodOptional) {
|
|
31
|
+
return keepMeta(schema, stripDefaults(schema.unwrap()).optional());
|
|
32
|
+
}
|
|
33
|
+
if (schema instanceof z.ZodNullable) {
|
|
34
|
+
return keepMeta(schema, stripDefaults(schema.unwrap()).nullable());
|
|
35
|
+
}
|
|
36
|
+
if (schema instanceof z.ZodReadonly) {
|
|
37
|
+
return keepMeta(schema, stripDefaults(schema.unwrap()).readonly());
|
|
38
|
+
}
|
|
39
|
+
if (schema instanceof z.ZodArray) {
|
|
40
|
+
return keepMeta(schema, z.array(stripDefaults(schema.element)));
|
|
41
|
+
}
|
|
42
|
+
if (schema instanceof z.ZodObject) {
|
|
43
|
+
const shape = {};
|
|
44
|
+
for (const [key, field] of Object.entries(schema.shape)) {
|
|
45
|
+
shape[key] = stripDefaults(field);
|
|
46
|
+
}
|
|
47
|
+
return keepMeta(schema, z.object(shape));
|
|
48
|
+
}
|
|
49
|
+
return schema;
|
|
50
|
+
}
|
|
51
|
+
/** Copy `source`'s registered `.meta()` onto `target`, if it has any. */
|
|
52
|
+
function keepMeta(source, target) {
|
|
53
|
+
const meta = source.meta();
|
|
54
|
+
return meta ? target.meta(meta) : target;
|
|
55
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL query codec — value ⇄ `qs`-style bracketed query string, with coercion
|
|
3
|
+
* driven by an ordinary Zod schema (no `z.coerce`, nothing URL-specific in it):
|
|
4
|
+
*
|
|
5
|
+
* parseFromUrl(schema, input) URL or query string → validated value
|
|
6
|
+
* toQueryString(value) value → query string
|
|
7
|
+
*
|
|
8
|
+
* Decoding is two steps:
|
|
9
|
+
* 1. deflatten the bracketed query into a nested structure of strings:
|
|
10
|
+
* view[center][lat]=10 → { view: { center: { lat: '10' } } }
|
|
11
|
+
* tags[0]=a&tags[1]=b → { tags: ['a', 'b'] }
|
|
12
|
+
* exhibitors[0][id]=1 → { exhibitors: [ { id: '1' } ] }
|
|
13
|
+
* Numeric indices are honored up to `qs`'s default `arrayLimit` (20);
|
|
14
|
+
* above that the segment stays an object key, so a crafted
|
|
15
|
+
* `?intents[999999999]=x` cannot inflate a billion-slot sparse array.
|
|
16
|
+
* 2. walk the schema (`z.toJSONSchema`) alongside that structure, coerce each
|
|
17
|
+
* leaf to its declared type (string→number/boolean/…), then `schema.parse`.
|
|
18
|
+
*
|
|
19
|
+
* Encoding inverts step 1: nested value → bracketed keys (arrays use numeric
|
|
20
|
+
* indices). Round-trips for scalars, nested objects, scalar arrays and arrays of
|
|
21
|
+
* objects, provided you decode with the SAME schema. A discriminated union
|
|
22
|
+
* coerces by the arm its discriminator names (so `intents[…]` args get their
|
|
23
|
+
* types); other unions are left as-is for `schema.parse` to handle.
|
|
24
|
+
*
|
|
25
|
+
* The bracket syntax matches the widely-used `qs` library, so these query
|
|
26
|
+
* strings interop with `qs.parse` / `qs.stringify` and anything built on them.
|
|
27
|
+
*/
|
|
28
|
+
import type * as z from 'zod';
|
|
29
|
+
export declare function parseFromUrl<S extends z.ZodType>(schema: S, input: string | URL): z.infer<S>;
|
|
30
|
+
export declare function safeParseFromUrl<S extends z.ZodType>(schema: S, input: string | URL): z.ZodSafeParseResult<z.TypeOf<S>>;
|
|
31
|
+
/**
|
|
32
|
+
* Like `parseFromUrl`, but drops the query keys that fail validation instead
|
|
33
|
+
* of throwing — a visitor-edited URL must never break the caller. Expects an
|
|
34
|
+
* all-optional object schema (which every per-source config slice is), so the
|
|
35
|
+
* parse is guaranteed to succeed once the offending keys are gone; anything
|
|
36
|
+
* not attributable to a top-level key still throws (a programming error, not
|
|
37
|
+
* URL noise).
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseFromUrlTolerant<S extends z.ZodType>(schema: S, input: string | URL): {
|
|
40
|
+
value: z.infer<S>;
|
|
41
|
+
invalidKeys: string[];
|
|
42
|
+
};
|
|
43
|
+
/** URL or query string → the deflattened structure, keys in first-occurrence order. */
|
|
44
|
+
export declare function deflattenQuery(input: string | URL): Record<string, unknown>;
|
|
45
|
+
export declare function toQueryString(value: unknown): string;
|
|
46
|
+
//# sourceMappingURL=url-codec.d.ts.map
|