@dealsystem/site 0.0.0-stage → 0.2.1

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.
Files changed (183) hide show
  1. package/README.md +145 -2
  2. package/agent-files/claude/skills/angebote-einbauen/SKILL.md +30 -0
  3. package/agent-files/claude/skills/bild-einbauen/SKILL.md +43 -0
  4. package/agent-files/claude/skills/domain-verbinden/SKILL.md +23 -0
  5. package/agent-files/claude/skills/erster-entwurf/SKILL.md +54 -0
  6. package/agent-files/claude/skills/extern-einbinden/SKILL.md +37 -0
  7. package/agent-files/claude/skills/formular-anbinden/SKILL.md +34 -0
  8. package/agent-files/claude/skills/funnel-mehrstufig/BewertungFunnel.svelte +220 -0
  9. package/agent-files/claude/skills/funnel-mehrstufig/SKILL.md +101 -0
  10. package/agent-files/claude/skills/neue-seite/SKILL.md +47 -0
  11. package/agent-files/claude/skills/prueffehler-beheben/SKILL.md +31 -0
  12. package/agent-files/claude/skills/termin-buchung/SKILL.md +51 -0
  13. package/agent-files/claude/skills/veroeffentlichen/SKILL.md +38 -0
  14. package/agent-files/cursor/rules/dealsystem.mdc +7 -0
  15. package/agent-files/manifest.json +101 -0
  16. package/contract/README.md +41 -0
  17. package/contract/ds-content.v1.json +2355 -0
  18. package/contract/external-presets.v1.json +65 -0
  19. package/contract/funnel-code-config.md +87 -0
  20. package/contract/site-api.v1.json +3916 -0
  21. package/dist/client/altcha-workers.d.ts +10 -0
  22. package/dist/client/attribution.d.ts +119 -0
  23. package/dist/client/attribution.js +341 -0
  24. package/dist/client/bookingClient.svelte.d.ts +166 -0
  25. package/dist/client/bookingClient.svelte.js +369 -0
  26. package/dist/client/bookingTime.d.ts +46 -0
  27. package/dist/client/bookingTime.js +109 -0
  28. package/dist/client/captcha.d.ts +26 -0
  29. package/dist/client/captcha.js +71 -0
  30. package/dist/client/captchaSession.d.ts +21 -0
  31. package/dist/client/captchaSession.js +105 -0
  32. package/dist/client/collections.d.ts +34 -0
  33. package/dist/client/collections.js +40 -0
  34. package/dist/client/externalScript.d.ts +20 -0
  35. package/dist/client/externalScript.js +36 -0
  36. package/dist/client/funnelState.svelte.d.ts +47 -0
  37. package/dist/client/funnelState.svelte.js +81 -0
  38. package/dist/client/leadClient.svelte.d.ts +131 -0
  39. package/dist/client/leadClient.svelte.js +250 -0
  40. package/dist/client/pageview.d.ts +7 -0
  41. package/dist/client/pageview.js +44 -0
  42. package/dist/client/siteApi.d.ts +211 -0
  43. package/dist/client/siteApi.js +320 -0
  44. package/dist/client/tracking.d.ts +18 -0
  45. package/dist/client/tracking.js +93 -0
  46. package/dist/client/validation.d.ts +10 -0
  47. package/dist/client/validation.js +66 -0
  48. package/dist/components/Booker.svelte +729 -0
  49. package/dist/components/Booker.svelte.d.ts +42 -0
  50. package/dist/components/CollectionList.svelte +122 -0
  51. package/dist/components/CollectionList.svelte.d.ts +65 -0
  52. package/dist/components/ConsentGate.svelte +68 -0
  53. package/dist/components/ConsentGate.svelte.d.ts +44 -0
  54. package/dist/components/CookieBanner.svelte +303 -0
  55. package/dist/components/CookieBanner.svelte.d.ts +29 -0
  56. package/dist/components/Datenschutz.svelte +84 -0
  57. package/dist/components/Datenschutz.svelte.d.ts +26 -0
  58. package/dist/components/Embed.svelte +263 -0
  59. package/dist/components/Embed.svelte.d.ts +41 -0
  60. package/dist/components/ExternalScript.svelte +94 -0
  61. package/dist/components/ExternalScript.svelte.d.ts +41 -0
  62. package/dist/components/Impressum.svelte +59 -0
  63. package/dist/components/Impressum.svelte.d.ts +25 -0
  64. package/dist/components/LeadForm.svelte +475 -0
  65. package/dist/components/LeadForm.svelte.d.ts +35 -0
  66. package/dist/components/LeadHoneypot.svelte +43 -0
  67. package/dist/components/LeadHoneypot.svelte.d.ts +18 -0
  68. package/dist/components/Link.svelte +48 -0
  69. package/dist/components/Link.svelte.d.ts +30 -0
  70. package/dist/components/MapEmbed.svelte +154 -0
  71. package/dist/components/MapEmbed.svelte.d.ts +28 -0
  72. package/dist/components/MediaImage.svelte +218 -0
  73. package/dist/components/MediaImage.svelte.d.ts +128 -0
  74. package/dist/components/MediaVideo.svelte +103 -0
  75. package/dist/components/MediaVideo.svelte.d.ts +20 -0
  76. package/dist/components/RichText.svelte +105 -0
  77. package/dist/components/RichText.svelte.d.ts +55 -0
  78. package/dist/components/Seo.svelte +89 -0
  79. package/dist/components/Seo.svelte.d.ts +45 -0
  80. package/dist/components/SiteFooterLegal.svelte +75 -0
  81. package/dist/components/SiteFooterLegal.svelte.d.ts +22 -0
  82. package/dist/components/SiteHead.svelte +79 -0
  83. package/dist/components/SiteHead.svelte.d.ts +32 -0
  84. package/dist/components/Text.svelte +100 -0
  85. package/dist/components/Text.svelte.d.ts +55 -0
  86. package/dist/components/Tracking.svelte +30 -0
  87. package/dist/components/Tracking.svelte.d.ts +14 -0
  88. package/dist/components/Zeitfenster.svelte +92 -0
  89. package/dist/components/Zeitfenster.svelte.d.ts +34 -0
  90. package/dist/components/legal.d.ts +12 -0
  91. package/dist/components/legal.js +27 -0
  92. package/dist/config/index.d.ts +121 -0
  93. package/dist/config/index.js +602 -0
  94. package/dist/config/static/index.d.ts +3 -0
  95. package/dist/config/static/index.js +5 -0
  96. package/dist/config/static/lines.d.ts +9 -0
  97. package/dist/config/static/lines.js +22 -0
  98. package/dist/config/static/literal.d.ts +45 -0
  99. package/dist/config/static/literal.js +175 -0
  100. package/dist/config/static/siteConfig.d.ts +39 -0
  101. package/dist/config/static/siteConfig.js +150 -0
  102. package/dist/consent/consent.svelte.d.ts +91 -0
  103. package/dist/consent/consent.svelte.js +221 -0
  104. package/dist/content/index.d.ts +123 -0
  105. package/dist/content/index.js +247 -0
  106. package/dist/contentBlock.d.ts +45 -0
  107. package/dist/contentBlock.js +78 -0
  108. package/dist/csp/index.d.ts +27 -0
  109. package/dist/csp/index.js +74 -0
  110. package/dist/external/csp.d.ts +25 -0
  111. package/dist/external/csp.js +104 -0
  112. package/dist/external/hosts.d.ts +30 -0
  113. package/dist/external/hosts.js +128 -0
  114. package/dist/external/presets.d.ts +54 -0
  115. package/dist/external/presets.js +212 -0
  116. package/dist/external/resolve.d.ts +39 -0
  117. package/dist/external/resolve.js +254 -0
  118. package/dist/index.d.ts +32 -0
  119. package/dist/index.js +32 -0
  120. package/dist/internal/consentNeed.d.ts +21 -0
  121. package/dist/internal/consentNeed.js +50 -0
  122. package/dist/internal/dealsystem-legal-imprint.d.ts +2 -0
  123. package/dist/internal/dealsystem-legal-imprint.js +5 -0
  124. package/dist/internal/dealsystem-legal-privacy.d.ts +2 -0
  125. package/dist/internal/dealsystem-legal-privacy.js +5 -0
  126. package/dist/internal/dealsystem-site-data.d.ts +3 -0
  127. package/dist/internal/dealsystem-site-data.js +2 -0
  128. package/dist/internal/imprint.d.ts +4 -0
  129. package/dist/internal/imprint.js +10 -0
  130. package/dist/internal/mediaImage.d.ts +15 -0
  131. package/dist/internal/mediaImage.js +22 -0
  132. package/dist/internal/privacy.d.ts +4 -0
  133. package/dist/internal/privacy.js +10 -0
  134. package/dist/internal/providers.d.ts +9 -0
  135. package/dist/internal/providers.js +44 -0
  136. package/dist/internal/reload.d.ts +2 -0
  137. package/dist/internal/reload.js +5 -0
  138. package/dist/internal/seo.d.ts +41 -0
  139. package/dist/internal/seo.js +79 -0
  140. package/dist/internal/siteData.d.ts +7 -0
  141. package/dist/internal/siteData.js +39 -0
  142. package/dist/internal/usage.d.ts +7 -0
  143. package/dist/internal/usage.js +13 -0
  144. package/dist/keys.d.ts +20 -0
  145. package/dist/keys.js +58 -0
  146. package/dist/leadmagnet.d.ts +16 -0
  147. package/dist/leadmagnet.js +28 -0
  148. package/dist/paths.d.ts +8 -0
  149. package/dist/paths.js +9 -0
  150. package/dist/richtext/escape.d.ts +4 -0
  151. package/dist/richtext/escape.js +18 -0
  152. package/dist/richtext/server.d.ts +16 -0
  153. package/dist/richtext/server.js +123 -0
  154. package/dist/schedule.d.ts +23 -0
  155. package/dist/schedule.js +67 -0
  156. package/dist/slots.d.ts +9 -0
  157. package/dist/slots.js +38 -0
  158. package/dist/snapshot.d.ts +14 -0
  159. package/dist/snapshot.js +214 -0
  160. package/dist/types.d.ts +550 -0
  161. package/dist/types.js +4 -0
  162. package/dist/version.d.ts +2 -0
  163. package/dist/version.js +2 -0
  164. package/dist/vite/index.d.ts +85 -0
  165. package/dist/vite/index.js +641 -0
  166. package/dist/vite/scan.d.ts +47 -0
  167. package/dist/vite/scan.js +355 -0
  168. package/dist/vite/zeitfenster.d.ts +18 -0
  169. package/dist/vite/zeitfenster.js +76 -0
  170. package/docs/ablauf.md +191 -0
  171. package/docs/agents-block.md +101 -0
  172. package/docs/befehle.md +103 -0
  173. package/docs/extern.md +143 -0
  174. package/docs/gestaltung.md +139 -0
  175. package/docs/inhalte.md +224 -0
  176. package/docs/komponenten.md +1273 -0
  177. package/docs/konfiguration.md +310 -0
  178. package/docs/llms.txt +19 -0
  179. package/docs/rechtstexte.md +84 -0
  180. package/docs/regeln.md +108 -0
  181. package/docs/seo.md +55 -0
  182. package/docs/termine.md +73 -0
  183. package/package.json +115 -5
@@ -0,0 +1,123 @@
1
+ // Markdown → geprüftes HTML, nur beim Build und nur für Standardtexte, die im
2
+ // Quelltext der Seite stehen (`<RichText key=… default="…">`). Richtext aus dem
3
+ // CRM rendert und bereinigt der DealSystem-Server; er kommt hier als fertiges
4
+ // HTML an und wird nie erneut geparst.
5
+ //
6
+ // Positiv-Liste wie im Core (`richtextHtml.ts`), aber ohne `img`: ein Bild aus
7
+ // Richtext käme von einer fremden Adresse und würde vor der Einwilligung laden.
8
+ import { Marked } from 'marked';
9
+ import sanitizeHtml from 'sanitize-html';
10
+ import { plainParagraphs } from './escape.js';
11
+ /**
12
+ * Obergrenze wie im Core. `marked` braucht auf präparierten Eingaben
13
+ * quadratische Zeit; längere Texte werden nur maskiert.
14
+ */
15
+ export const RICHTEXT_MAX_LENGTH = 20_000;
16
+ const ALLOWED_TAGS = [
17
+ 'h1',
18
+ 'h2',
19
+ 'h3',
20
+ 'h4',
21
+ 'h5',
22
+ 'h6',
23
+ 'p',
24
+ 'br',
25
+ 'hr',
26
+ 'strong',
27
+ 'b',
28
+ 'em',
29
+ 'i',
30
+ 'u',
31
+ 's',
32
+ 'del',
33
+ 'sub',
34
+ 'sup',
35
+ 'mark',
36
+ 'small',
37
+ 'code',
38
+ 'pre',
39
+ 'blockquote',
40
+ 'ul',
41
+ 'ol',
42
+ 'li',
43
+ 'a',
44
+ 'table',
45
+ 'thead',
46
+ 'tbody',
47
+ 'tfoot',
48
+ 'tr',
49
+ 'th',
50
+ 'td',
51
+ 'caption',
52
+ ];
53
+ const DROP_WITH_CONTENT = [
54
+ 'script',
55
+ 'style',
56
+ 'textarea',
57
+ 'option',
58
+ 'noscript',
59
+ 'iframe',
60
+ 'frame',
61
+ 'frameset',
62
+ 'object',
63
+ 'embed',
64
+ 'svg',
65
+ 'math',
66
+ 'template',
67
+ 'title',
68
+ 'xmp',
69
+ 'noembed',
70
+ 'noframes',
71
+ 'select',
72
+ ];
73
+ const OPTIONS = {
74
+ allowedTags: ALLOWED_TAGS,
75
+ allowedAttributes: {
76
+ a: ['href', 'title', 'target', 'rel'],
77
+ th: ['colspan', 'rowspan'],
78
+ td: ['colspan', 'rowspan'],
79
+ },
80
+ allowedSchemes: ['http', 'https', 'mailto', 'tel'],
81
+ allowedSchemesAppliedToAttributes: ['href'],
82
+ allowProtocolRelative: false,
83
+ disallowedTagsMode: 'discard',
84
+ nonTextTags: DROP_WITH_CONTENT,
85
+ transformTags: {
86
+ // `target` nur `_blank`, und dann immer mit `rel`: sonst bekäme die
87
+ // Zielseite über `window.opener` Zugriff auf den Tab.
88
+ a: (tagName, attribs) => {
89
+ const { target, rel: _rel, ...rest } = attribs;
90
+ return target === '_blank'
91
+ ? { tagName, attribs: { ...rest, target, rel: 'noopener noreferrer' } }
92
+ : { tagName, attribs: rest };
93
+ },
94
+ },
95
+ };
96
+ const markdown = new Marked({ gfm: true, breaks: false });
97
+ /**
98
+ * Prüft fertiges HTML gegen die Positiv-Liste. Bereinigtes HTML kommt
99
+ * unverändert heraus, nichts wird doppelt maskiert.
100
+ * @internal Benutzt nur das Vite-Plugin.
101
+ */
102
+ export function sanitizeRichtextHtml(html) {
103
+ return html ? sanitizeHtml(html, OPTIONS) : '';
104
+ }
105
+ /**
106
+ * Wandelt den Standardtext eines Richtext-Slots in geprüftes HTML um.
107
+ * @internal Benutzt nur das Vite-Plugin.
108
+ */
109
+ export function defaultRichtextToHtml(source) {
110
+ if (!source)
111
+ return '';
112
+ if (source.length > RICHTEXT_MAX_LENGTH)
113
+ return plainParagraphs(source);
114
+ let html;
115
+ try {
116
+ html = markdown.parse(source, { async: false });
117
+ }
118
+ catch {
119
+ // Stack Overflow bei tief verschachtelten Zitaten oder Listen.
120
+ return plainParagraphs(source);
121
+ }
122
+ return sanitizeHtml(html, OPTIONS);
123
+ }
@@ -0,0 +1,23 @@
1
+ /** Höchstens so viele künftige Grenzen meldet das Manifest (die frühesten). */
2
+ export declare const SCHEDULE_MAX = 50;
3
+ export type ZeitpunktFehler = 'format' | 'offset' | 'ungueltig';
4
+ /**
5
+ * Liest einen Zeitpunkt. Liefert Millisekunden seit 1970 (UTC) oder den Grund, warum es nicht geht:
6
+ * `offset` = Zeitzone fehlt, `format` = kein ISO-Zeitpunkt, `ungueltig` = z. B. 31. Februar.
7
+ */
8
+ export declare function parseZeitpunkt(value: string): {
9
+ ms: number;
10
+ } | {
11
+ fehler: ZeitpunktFehler;
12
+ };
13
+ /** Meldung zu einem Fehler beim Lesen, für Baustein und Prüfung. */
14
+ export declare function zeitpunktFehlerText(name: string, value: string, fehler: ZeitpunktFehler): string;
15
+ /** Ist der Inhalt zum Zeitpunkt `now` sichtbar? `ab` gehört dazu, `bis` nicht mehr: [ab, bis). */
16
+ export declare function imZeitfenster(now: number, ab: number | null, bis: number | null): boolean;
17
+ /** Nächste Grenze nach `now`, oder `null`. */
18
+ export declare function naechsteGrenze(now: number, grenzen: readonly (number | null)[]): number | null;
19
+ /**
20
+ * Die Grenzen für das Manifest: nur künftige (nach `now`), ohne doppelte, aufsteigend, höchstens
21
+ * `SCHEDULE_MAX`, als UTC-Zeitpunkt (`2026-12-01T17:00:00.000Z`).
22
+ */
23
+ export declare function scheduleFrom(grenzen: Iterable<number>, now: number): string[];
@@ -0,0 +1,67 @@
1
+ // Zeitpunkte für `<Zeitfenster>`: Lesen, Prüfen, Fenster auswerten. Ohne Abhängigkeiten, damit Baustein,
2
+ // Vite-Plugin (Manifest `schedule`) und `dealsystem check` (QUA-009) dieselbe Regel benutzen.
3
+ /**
4
+ * Zeitpunkt nach ISO 8601 **mit** Zeitzone: `2026-12-01T18:00:00+01:00` oder `…Z`. Ohne Angabe der Zeitzone
5
+ * hinge die Bedeutung von der Uhr des Rechners ab (Build-Host in UTC, Besucher in Berlin), deshalb nicht erlaubt.
6
+ */
7
+ const ZEITPUNKT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-](\d{2}):(\d{2}))$/;
8
+ /** Höchstens so viele künftige Grenzen meldet das Manifest (die frühesten). */
9
+ export const SCHEDULE_MAX = 50;
10
+ /**
11
+ * Liest einen Zeitpunkt. Liefert Millisekunden seit 1970 (UTC) oder den Grund, warum es nicht geht:
12
+ * `offset` = Zeitzone fehlt, `format` = kein ISO-Zeitpunkt, `ungueltig` = z. B. 31. Februar.
13
+ */
14
+ export function parseZeitpunkt(value) {
15
+ const text = value.trim();
16
+ const match = ZEITPUNKT.exec(text);
17
+ if (!match) {
18
+ const ohneZone = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(text);
19
+ return { fehler: ohneZone ? 'offset' : 'format' };
20
+ }
21
+ const [, y, mo, d, h, mi, s = '0', , zone, oh = '0', om = '0'] = match;
22
+ const month = Number(mo);
23
+ const day = Number(d);
24
+ const hour = Number(h);
25
+ const minute = Number(mi);
26
+ const second = Number(s);
27
+ if (month < 1 || month > 12 || day < 1 || hour > 23 || minute > 59 || second > 59)
28
+ return { fehler: 'ungueltig' };
29
+ if (zone !== 'Z' && (Number(oh) > 14 || Number(om) > 59))
30
+ return { fehler: 'ungueltig' };
31
+ // Tag im Monat prüfen: Date.UTC rollt den 31. Februar sonst still in den März.
32
+ if (new Date(Date.UTC(Number(y), month - 1, day)).getUTCDate() !== day)
33
+ return { fehler: 'ungueltig' };
34
+ const ms = Date.parse(text);
35
+ return Number.isFinite(ms) ? { ms } : { fehler: 'ungueltig' };
36
+ }
37
+ /** Meldung zu einem Fehler beim Lesen, für Baustein und Prüfung. */
38
+ export function zeitpunktFehlerText(name, value, fehler) {
39
+ const beispiel = 'z. B. "2026-12-01T18:00:00+01:00" (Winterzeit) oder "2026-07-01T18:00:00+02:00" (Sommerzeit)';
40
+ if (fehler === 'offset')
41
+ return `${name}="${value}" hat keine Zeitzone. Hänge sie an, ${beispiel}; sonst hinge die Zeit vom Rechner ab.`;
42
+ if (fehler === 'ungueltig')
43
+ return `${name}="${value}" ist kein gültiger Zeitpunkt (Datum oder Uhrzeit gibt es nicht).`;
44
+ return `${name}="${value}" ist kein Zeitpunkt. Schreibe Datum und Uhrzeit mit Zeitzone, ${beispiel}.`;
45
+ }
46
+ /** Ist der Inhalt zum Zeitpunkt `now` sichtbar? `ab` gehört dazu, `bis` nicht mehr: [ab, bis). */
47
+ export function imZeitfenster(now, ab, bis) {
48
+ return (ab === null || now >= ab) && (bis === null || now < bis);
49
+ }
50
+ /** Nächste Grenze nach `now`, oder `null`. */
51
+ export function naechsteGrenze(now, grenzen) {
52
+ let next = null;
53
+ for (const g of grenzen)
54
+ if (g !== null && g > now && (next === null || g < next))
55
+ next = g;
56
+ return next;
57
+ }
58
+ /**
59
+ * Die Grenzen für das Manifest: nur künftige (nach `now`), ohne doppelte, aufsteigend, höchstens
60
+ * `SCHEDULE_MAX`, als UTC-Zeitpunkt (`2026-12-01T17:00:00.000Z`).
61
+ */
62
+ export function scheduleFrom(grenzen, now) {
63
+ return [...new Set([...grenzen].filter((ms) => ms > now))]
64
+ .sort((a, b) => a - b)
65
+ .slice(0, SCHEDULE_MAX)
66
+ .map((ms) => new Date(ms).toISOString());
67
+ }
@@ -0,0 +1,9 @@
1
+ import type { ContentSlotLinkValue, MediaRef, SlotOverride } from './types.js';
2
+ type Overrides = Record<string, SlotOverride>;
3
+ /** Text eines `text`-, `textarea`- oder `richtext`-Slots, sonst `null`. */
4
+ export declare function resolveTextSlot(overrides: Overrides, key: string, aliases?: readonly string[]): string | null;
5
+ /** Wert eines `link`-Slots, sonst `null`. */
6
+ export declare function resolveLinkSlot(overrides: Overrides, key: string, aliases?: readonly string[]): ContentSlotLinkValue | null;
7
+ /** Bild eines `image`-Slots, sonst `null`. */
8
+ export declare function resolveImageSlot(overrides: Overrides, key: string, aliases?: readonly string[]): MediaRef | null;
9
+ export {};
package/dist/slots.js ADDED
@@ -0,0 +1,38 @@
1
+ // Die eine Stelle, an der „Überschreibung, sonst Standard“ entschieden wird.
2
+ // Passt eine Überschreibung nicht zum Typ des Slots, gilt der Standard: ein
3
+ // Kunde kann seine Seite über das CRM nicht kaputt schreiben.
4
+ import { normalizeMediaRef } from './snapshot.js';
5
+ function find(overrides, key, aliases) {
6
+ for (const candidate of [key, ...(aliases ?? [])]) {
7
+ if (Object.prototype.hasOwnProperty.call(overrides, candidate))
8
+ return overrides[candidate] ?? null;
9
+ }
10
+ return null;
11
+ }
12
+ /** Text eines `text`-, `textarea`- oder `richtext`-Slots, sonst `null`. */
13
+ export function resolveTextSlot(overrides, key, aliases) {
14
+ const hit = find(overrides, key, aliases);
15
+ if (!hit || hit.type === 'link' || hit.type === 'image')
16
+ return null;
17
+ return typeof hit.value === 'string' ? hit.value : null;
18
+ }
19
+ /** Wert eines `link`-Slots, sonst `null`. */
20
+ export function resolveLinkSlot(overrides, key, aliases) {
21
+ const hit = find(overrides, key, aliases);
22
+ if (!hit || hit.type !== 'link')
23
+ return null;
24
+ const value = hit.value;
25
+ if (!value || typeof value.href !== 'string' || typeof value.label !== 'string')
26
+ return null;
27
+ if (!/^(\/(?!\/)|https?:\/\/|mailto:|tel:|#)/i.test(value.href))
28
+ return null;
29
+ return { href: value.href, label: value.label, newTab: value.newTab === true };
30
+ }
31
+ /** Bild eines `image`-Slots, sonst `null`. */
32
+ export function resolveImageSlot(overrides, key, aliases) {
33
+ const hit = find(overrides, key, aliases);
34
+ if (!hit || hit.type !== 'image')
35
+ return null;
36
+ const ref = normalizeMediaRef(hit.value);
37
+ return ref && ref.kind === 'image' && ref.variants.length > 0 ? ref : null;
38
+ }
@@ -0,0 +1,14 @@
1
+ import type { ContentSnapshot, MediaRef, RawCollectionEntry, SeoConfig } from './types.js';
2
+ /** Prüft und bereinigt einen `MediaRef`. Unbrauchbares ergibt `null`. */
3
+ export declare function normalizeMediaRef(raw: unknown): MediaRef | null;
4
+ /** Prüft einen Eintrag aus Schnappschuss oder Site-API. */
5
+ export declare function normalizeEntry(raw: unknown): RawCollectionEntry | null;
6
+ /** Liest `seo` nachsichtig. Fehlt der Block (älterer Core), ist alles leer. */
7
+ export declare function normalizeSeo(raw: unknown): SeoConfig;
8
+ /** Ein leerer Schnappschuss: die Seite zeigt überall ihre Standardwerte. */
9
+ export declare function emptySnapshot(): ContentSnapshot;
10
+ /**
11
+ * Liest einen Schnappschuss nachsichtig ein. Iteriert über die bekannten
12
+ * Felder, nicht über die Eingabe.
13
+ */
14
+ export declare function normalizeSnapshot(raw: unknown): ContentSnapshot;
@@ -0,0 +1,214 @@
1
+ const SLOT_TYPES = ['text', 'textarea', 'richtext', 'link', 'image'];
2
+ function isRecord(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
5
+ function str(value) {
6
+ return typeof value === 'string' ? value : '';
7
+ }
8
+ function strOrNull(value) {
9
+ return typeof value === 'string' && value !== '' ? value : null;
10
+ }
11
+ function numOrNull(value) {
12
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
13
+ }
14
+ /** Nur Pfade der eigenen Seite und https-Adressen. Alles andere fällt weg. */
15
+ function safeUrl(value) {
16
+ if (typeof value !== 'string')
17
+ return null;
18
+ if (/^\/(?!\/)/.test(value) || /^https:\/\//i.test(value))
19
+ return value;
20
+ return null;
21
+ }
22
+ function normalizeVariant(raw) {
23
+ if (!isRecord(raw))
24
+ return null;
25
+ const url = safeUrl(raw.url);
26
+ const width = numOrNull(raw.width);
27
+ const format = raw.format;
28
+ if (!url || !width || width <= 0)
29
+ return null;
30
+ if (format !== 'jpeg' && format !== 'webp' && format !== 'avif')
31
+ return null;
32
+ return { url, width, format };
33
+ }
34
+ /** Prüft und bereinigt einen `MediaRef`. Unbrauchbares ergibt `null`. */
35
+ export function normalizeMediaRef(raw) {
36
+ if (!isRecord(raw))
37
+ return null;
38
+ const { kind } = raw;
39
+ if (typeof raw.id !== 'string' || (kind !== 'image' && kind !== 'video' && kind !== 'file'))
40
+ return null;
41
+ const ref = {
42
+ id: raw.id,
43
+ kind,
44
+ alt: str(raw.alt),
45
+ width: numOrNull(raw.width),
46
+ height: numOrNull(raw.height),
47
+ variants: Array.isArray(raw.variants)
48
+ ? raw.variants.map(normalizeVariant).filter((v) => v !== null)
49
+ : [],
50
+ };
51
+ if (isRecord(raw.video) && raw.video.provider === 'bunny') {
52
+ const playbackUrl = safeUrl(raw.video.playbackUrl);
53
+ const posterUrl = safeUrl(raw.video.posterUrl);
54
+ if (playbackUrl)
55
+ ref.video = { provider: 'bunny', playbackUrl, posterUrl: posterUrl ?? '' };
56
+ }
57
+ const url = safeUrl(raw.url);
58
+ if (url)
59
+ ref.url = url;
60
+ return ref;
61
+ }
62
+ /** Prüft einen Eintrag aus Schnappschuss oder Site-API. */
63
+ export function normalizeEntry(raw) {
64
+ if (!isRecord(raw) || typeof raw.slug !== 'string' || raw.slug === '')
65
+ return null;
66
+ const media = {};
67
+ if (isRecord(raw.media)) {
68
+ for (const [field, refs] of Object.entries(raw.media)) {
69
+ media[field] = Array.isArray(refs)
70
+ ? refs.map(normalizeMediaRef).filter((r) => r !== null)
71
+ : [];
72
+ }
73
+ }
74
+ return {
75
+ slug: raw.slug,
76
+ publishedAt: str(raw.publishedAt),
77
+ data: isRecord(raw.data) ? raw.data : {},
78
+ media,
79
+ };
80
+ }
81
+ function normalizeLegal(raw) {
82
+ const r = isRecord(raw) ? raw : {};
83
+ return {
84
+ company: str(r.company),
85
+ address: str(r.address),
86
+ email: str(r.email),
87
+ phone: str(r.phone),
88
+ imprintHtml: str(r.imprintHtml),
89
+ privacyHtml: str(r.privacyHtml),
90
+ };
91
+ }
92
+ // eslint-disable-next-line no-control-regex -- Steuerzeichen gehören nicht in Titel und Beschreibung
93
+ const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g;
94
+ /** Klartext für Titel und Beschreibung: Steuerzeichen raus, Leerraum zusammengefasst, leer = `null`. */
95
+ function plainText(value, max) {
96
+ if (typeof value !== 'string')
97
+ return null;
98
+ const text = value.replace(CONTROL, '').replace(/\s+/g, ' ').trim().slice(0, max);
99
+ return text === '' ? null : text;
100
+ }
101
+ function normalizeSeoMeta(raw) {
102
+ const r = isRecord(raw) ? raw : {};
103
+ const image = normalizeMediaRef(r.image);
104
+ return {
105
+ title: plainText(r.title, 300),
106
+ description: plainText(r.description, 1000),
107
+ image: image && image.kind === 'image' && image.variants.length > 0 ? image : null,
108
+ };
109
+ }
110
+ /** Statische Route in SvelteKit-Schreibweise, wie im Manifest: `/`, `/kontakt`, `/ueber-uns/team`. */
111
+ const STATIC_ROUTE = /^\/(?:[a-z0-9._~-]+(?:\/[a-z0-9._~-]+)*)?$/i;
112
+ function normalizeFavicon(raw) {
113
+ if (!isRecord(raw) || typeof raw.id !== 'string' || !Array.isArray(raw.icons))
114
+ return null;
115
+ const icons = [];
116
+ for (const icon of raw.icons) {
117
+ if (!isRecord(icon) || icon.type !== 'image/png')
118
+ continue;
119
+ // Nur Pfade der eigenen Seite: fremde Adressen würde die CSP ohnehin blockieren.
120
+ const url = typeof icon.url === 'string' && /^\/(?!\/)/.test(icon.url) ? icon.url : null;
121
+ const size = icon.size;
122
+ if (!url || typeof size !== 'number' || !Number.isInteger(size) || size <= 0)
123
+ continue;
124
+ icons.push({ url, size, type: 'image/png' });
125
+ }
126
+ icons.sort((a, b) => a.size - b.size);
127
+ return icons.length > 0 ? { id: raw.id, icons } : null;
128
+ }
129
+ /** Liest `seo` nachsichtig. Fehlt der Block (älterer Core), ist alles leer. */
130
+ export function normalizeSeo(raw) {
131
+ const r = isRecord(raw) ? raw : {};
132
+ const pages = {};
133
+ if (isRecord(r.pages)) {
134
+ for (const [route, meta] of Object.entries(r.pages)) {
135
+ if (!STATIC_ROUTE.test(route))
136
+ continue;
137
+ const normalized = normalizeSeoMeta(meta);
138
+ if (normalized.title || normalized.description || normalized.image)
139
+ pages[route] = normalized;
140
+ }
141
+ }
142
+ return {
143
+ noindex: r.noindex === true,
144
+ defaults: normalizeSeoMeta(r.defaults),
145
+ pages,
146
+ favicon: normalizeFavicon(r.favicon),
147
+ };
148
+ }
149
+ /** Ein leerer Schnappschuss: die Seite zeigt überall ihre Standardwerte. */
150
+ export function emptySnapshot() {
151
+ return normalizeSnapshot({});
152
+ }
153
+ /**
154
+ * Liest einen Schnappschuss nachsichtig ein. Iteriert über die bekannten
155
+ * Felder, nicht über die Eingabe.
156
+ */
157
+ export function normalizeSnapshot(raw) {
158
+ const r = isRecord(raw) ? raw : {};
159
+ const site = isRecord(r.site) ? r.site : {};
160
+ const tracking = isRecord(r.tracking) ? r.tracking : {};
161
+ const slots = {};
162
+ if (isRecord(r.slots)) {
163
+ for (const [key, slot] of Object.entries(r.slots)) {
164
+ if (!isRecord(slot))
165
+ continue;
166
+ const type = slot.type;
167
+ if (!SLOT_TYPES.includes(type))
168
+ continue;
169
+ // Nur eine echte Überschreibung zählt. `source: "default"` (Wert `null`)
170
+ // heißt: es gilt der Standard aus dem aktuellen Code.
171
+ if (slot.source === 'default' || slot.value === null || slot.value === undefined)
172
+ continue;
173
+ slots[key] = { type, value: slot.value };
174
+ }
175
+ }
176
+ const collections = {};
177
+ if (isRecord(r.collections)) {
178
+ for (const [key, collection] of Object.entries(r.collections)) {
179
+ if (!isRecord(collection))
180
+ continue;
181
+ collections[key] = {
182
+ source: str(collection.source) || 'cms',
183
+ schemaHash: str(collection.schemaHash),
184
+ entries: Array.isArray(collection.entries)
185
+ ? collection.entries.map(normalizeEntry).filter((e) => e !== null)
186
+ : [],
187
+ };
188
+ }
189
+ }
190
+ return {
191
+ snapshotVersion: 1,
192
+ site: {
193
+ id: str(site.id),
194
+ slug: str(site.slug),
195
+ name: str(site.name),
196
+ primaryHost: str(site.primaryHost),
197
+ locale: str(site.locale) || 'de',
198
+ },
199
+ legal: normalizeLegal(r.legal),
200
+ tracking: {
201
+ metaPixelId: strOrNull(tracking.metaPixelId),
202
+ googleTagId: strOrNull(tracking.googleTagId),
203
+ },
204
+ funnels: Array.isArray(r.funnels)
205
+ ? r.funnels
206
+ .filter(isRecord)
207
+ .filter((f) => typeof f.key === 'string')
208
+ .map((f) => ({ key: f.key, active: f.active !== false }))
209
+ : [],
210
+ slots,
211
+ collections,
212
+ seo: normalizeSeo(r.seo),
213
+ };
214
+ }