@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,10 @@
1
+ // Worker-Importe von Vite (`?worker`): Vite legt den Worker als eigene Datei ab.
2
+ declare module 'altcha/workers/pbkdf2?worker' {
3
+ const WorkerConstructor: new () => Worker;
4
+ export default WorkerConstructor;
5
+ }
6
+
7
+ declare module 'altcha/workers/sha?worker' {
8
+ const WorkerConstructor: new () => Worker;
9
+ export default WorkerConstructor;
10
+ }
@@ -0,0 +1,119 @@
1
+ import type { ConsentCategory } from '../consent/consent.svelte.js';
2
+ /**
3
+ * Welche Einwilligung was erlaubt. EINE Stelle für die Entscheidungen des Inhabers; jede Angabe gilt, sobald
4
+ * einer der genannten Zwecke erlaubt ist.
5
+ * - `history`: erster und letzter Besuch über Besuche hinweg, eigene Parameter gespeichert
6
+ * - `visitorId`: Besuchsreise (muss zu `SELF_SITE_CONSENT_RULES.visitorId` im Core passen)
7
+ * - `clickIds`: Klick-IDs der Werbenetze, `_fbp` (E-1, Empfehlung a: nur mit Marketing)
8
+ */
9
+ export declare const ATTRIBUTION_CONSENT: {
10
+ readonly history: readonly ["statistics", "marketing"];
11
+ readonly visitorId: readonly ["marketing"];
12
+ readonly clickIds: readonly ["marketing"];
13
+ };
14
+ /** Grenzen des Vertrags (`SELF_SITE_ATTRIBUTION_LIMITS` im Core). */
15
+ export declare const ATTRIBUTION_LIMITS: {
16
+ readonly text: 200;
17
+ readonly host: 255;
18
+ readonly path: 500;
19
+ readonly at: 64;
20
+ readonly clickId: 500;
21
+ readonly paramKey: 64;
22
+ readonly paramValue: 500;
23
+ readonly params: 20;
24
+ readonly touches: 1000;
25
+ };
26
+ /** So lange gelten gespeicherte Besuche und Klick-IDs (Tage); die Besuchs-ID 13 Monate. */
27
+ export declare const ATTRIBUTION_RETENTION_DAYS: {
28
+ readonly history: 90;
29
+ readonly clickIds: 90;
30
+ readonly visitorId: 395;
31
+ };
32
+ export type Granted = Record<ConsentCategory, boolean>;
33
+ /** Ein Besuch, wie im Vertrag. Nur gefüllte Felder sind gesetzt. */
34
+ export interface Touch {
35
+ source?: string;
36
+ medium?: string;
37
+ campaign?: string;
38
+ term?: string;
39
+ content?: string;
40
+ referrerHost?: string;
41
+ landingPath?: string;
42
+ at?: string;
43
+ }
44
+ export declare const CLICK_ID_KEYS: readonly ["gclid", "gbraid", "wbraid", "fbc", "fbp", "msclkid"];
45
+ export type ClickIdKey = (typeof CLICK_ID_KEYS)[number];
46
+ export type ClickIds = Partial<Record<ClickIdKey, string>>;
47
+ /** `attribution` im Lead, Fassung 2. */
48
+ export interface LeadAttributionV2 {
49
+ v: 2;
50
+ first: Touch | null;
51
+ last: Touch | null;
52
+ touches: number;
53
+ clickIds: ClickIds | null;
54
+ visitorId: string | null;
55
+ params: Record<string, string> | null;
56
+ consent: {
57
+ statistics: boolean;
58
+ marketing: boolean;
59
+ at: string | null;
60
+ };
61
+ }
62
+ declare const UTM_KEYS: readonly ["source", "medium", "campaign", "term", "content"];
63
+ /** Der aktuelle Besuch, nur im Arbeitsspeicher. */
64
+ interface Visit {
65
+ touch: Touch;
66
+ /** Suchteil der Einstiegsadresse: Klick-IDs werden erst mit Einwilligung daraus gelesen. */
67
+ search: string;
68
+ params: Record<string, string>;
69
+ at: number;
70
+ /** Für Seitenaufrufe: UTM und Referrer nur beim Einstieg. */
71
+ utm: Pick<Touch, (typeof UTM_KEYS)[number]> | null;
72
+ }
73
+ /** Eigene URL-Parameter: ohne UTM und Klick-IDs, ohne heikle Namen, höchstens 20, Werte gekürzt. */
74
+ export declare function readParams(search: string): Record<string, string>;
75
+ /**
76
+ * Hält den aktuellen Besuch fest und gleicht den Speicher mit der Einwilligung ab: legt an, was erlaubt ist, und
77
+ * löscht, was nicht (mehr) erlaubt ist. Mehrfach aufrufbar (Start der Seite, jede Änderung der Einwilligung).
78
+ * @internal
79
+ */
80
+ export declare function syncAttribution(granted: Granted): void;
81
+ /** Besuchs-ID, wenn erlaubt und angelegt. @internal */
82
+ export declare function getVisitorId(granted: Granted): string | null;
83
+ /** UTM und Referrer des aktuellen Besuchs, für den Seitenaufruf beim Einstieg. @internal */
84
+ export declare function getEntry(): {
85
+ utm: Visit['utm'];
86
+ referrerHost: string | null;
87
+ };
88
+ /**
89
+ * Wert eines eigenen URL-Parameters, z. B. `partner` aus `?partner=…`: aus dem aktuellen Besuch, sonst (nur mit
90
+ * Einwilligung) aus dem zuletzt gespeicherten. `null`, wenn es ihn nicht gibt. Nur im Browser.
91
+ *
92
+ * Nicht gelesen werden UTM-Parameter, Klick-IDs und Namen, die nach Zugangs- oder Personendaten aussehen
93
+ * (`email`, `token`, `session` …); höchstens 20 Parameter, Werte bis 500 Zeichen. Mit der Anfrage gehen die
94
+ * Parameter ohnehin an das CRM (`<LeadForm>`), dafür ist nichts zu tun.
95
+ *
96
+ * @example
97
+ * <script lang="ts">
98
+ * import { getCampaignParam } from '@dealsystem/site';
99
+ * import { onMount } from 'svelte';
100
+ * let partner = $state<string | null>(null);
101
+ * onMount(() => (partner = getCampaignParam('partner')));
102
+ * </script>
103
+ */
104
+ export declare function getCampaignParam(name: string): string | null;
105
+ /**
106
+ * UTM-Angabe für ein verstecktes Feld (`from: { utm: 'campaign' }`): aus dem aktuellen Besuch, sonst (nur mit
107
+ * Einwilligung) aus dem letzten gespeicherten Besuch.
108
+ * @internal
109
+ */
110
+ export declare function getCampaignUtm(key: (typeof UTM_KEYS)[number]): string | null;
111
+ /**
112
+ * `attribution` für den Lead (Fassung 2). Ohne Einwilligung nur der aktuelle Besuch, ohne Klick-IDs und
113
+ * Besuchs-ID.
114
+ * @internal
115
+ */
116
+ export declare function buildLeadAttribution(granted: Granted, consentAt: string | null): LeadAttributionV2 | undefined;
117
+ /** @internal Nur für Tests. */
118
+ export declare function resetAttributionForTests(): void;
119
+ export {};
@@ -0,0 +1,341 @@
1
+ /**
2
+ * Welche Einwilligung was erlaubt. EINE Stelle für die Entscheidungen des Inhabers; jede Angabe gilt, sobald
3
+ * einer der genannten Zwecke erlaubt ist.
4
+ * - `history`: erster und letzter Besuch über Besuche hinweg, eigene Parameter gespeichert
5
+ * - `visitorId`: Besuchsreise (muss zu `SELF_SITE_CONSENT_RULES.visitorId` im Core passen)
6
+ * - `clickIds`: Klick-IDs der Werbenetze, `_fbp` (E-1, Empfehlung a: nur mit Marketing)
7
+ */
8
+ export const ATTRIBUTION_CONSENT = {
9
+ history: ['statistics', 'marketing'],
10
+ visitorId: ['marketing'],
11
+ clickIds: ['marketing'],
12
+ };
13
+ /** Grenzen des Vertrags (`SELF_SITE_ATTRIBUTION_LIMITS` im Core). */
14
+ export const ATTRIBUTION_LIMITS = {
15
+ text: 200,
16
+ host: 255,
17
+ path: 500,
18
+ at: 64,
19
+ clickId: 500,
20
+ paramKey: 64,
21
+ paramValue: 500,
22
+ params: 20,
23
+ touches: 1000,
24
+ };
25
+ /** So lange gelten gespeicherte Besuche und Klick-IDs (Tage); die Besuchs-ID 13 Monate. */
26
+ export const ATTRIBUTION_RETENTION_DAYS = { history: 90, clickIds: 90, visitorId: 395 };
27
+ /** Nach so langer Pause zählt ein Aufruf als neuer Besuch, auch ohne neue Kampagne. */
28
+ const VISIT_GAP_MS = 30 * 60 * 1000;
29
+ const DAY_MS = 86_400_000;
30
+ const STORAGE_KEY = 'ds-attr';
31
+ /** Fassung 1 lag in `sessionStorage`; wird nicht mehr geschrieben und beim Start entfernt. */
32
+ const LEGACY_KEY = 'ds-first-touch';
33
+ export const CLICK_ID_KEYS = ['gclid', 'gbraid', 'wbraid', 'fbc', 'fbp', 'msclkid'];
34
+ const UTM_KEYS = ['source', 'medium', 'campaign', 'term', 'content'];
35
+ /** URL-Parameter für Klick-IDs. `fbclid` wird zu `fbc` im Meta-Format. */
36
+ const CLICK_PARAMS = {
37
+ gclid: 'gclid',
38
+ gbraid: 'gbraid',
39
+ wbraid: 'wbraid',
40
+ fbclid: 'fbc',
41
+ msclkid: 'msclkid',
42
+ };
43
+ const PARAM_KEY = /^[A-Za-z0-9_.-]{1,64}$/;
44
+ /** Eigene Parameter mit diesen Namen gehen nie mit: Sie tragen oft Zugangsdaten oder Personendaten. */
45
+ const SENSITIVE_PARAM = /(pass|token|secret|session|auth|key|email|mail|phone|tel|name|code|sig)/i;
46
+ const CLICK_ID_VALUE = /^[\x21-\x7e]+$/;
47
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
48
+ // eslint-disable-next-line no-control-regex -- Steuerzeichen gehören in keinen Wert
49
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g;
50
+ let visit = null;
51
+ let stored = null;
52
+ const allows = (granted, what) => ATTRIBUTION_CONSENT[what].some((c) => granted[c]);
53
+ function clean(value, max) {
54
+ const text = value?.replace(CONTROL, '').trim();
55
+ return text ? text.slice(0, max) : undefined;
56
+ }
57
+ function referrerHost() {
58
+ try {
59
+ if (!document.referrer)
60
+ return undefined;
61
+ const host = new URL(document.referrer).host.toLowerCase();
62
+ const own = window.location.host.toLowerCase();
63
+ if (!host || host === own || host === `www.${own}` || `www.${host}` === own)
64
+ return undefined;
65
+ return host.slice(0, ATTRIBUTION_LIMITS.host);
66
+ }
67
+ catch {
68
+ return undefined;
69
+ }
70
+ }
71
+ /** Eigene URL-Parameter: ohne UTM und Klick-IDs, ohne heikle Namen, höchstens 20, Werte gekürzt. */
72
+ export function readParams(search) {
73
+ const out = {};
74
+ for (const [key, raw] of new URLSearchParams(search)) {
75
+ if (Object.keys(out).length >= ATTRIBUTION_LIMITS.params)
76
+ break;
77
+ if (!PARAM_KEY.test(key) || key.startsWith('utm_') || key in CLICK_PARAMS || key === '_fbp')
78
+ continue;
79
+ if (SENSITIVE_PARAM.test(key) || key in out)
80
+ continue;
81
+ const value = clean(raw, ATTRIBUTION_LIMITS.paramValue);
82
+ if (value)
83
+ out[key] = value;
84
+ }
85
+ return out;
86
+ }
87
+ /** Klick-IDs aus der Einstiegsadresse. Nur aufrufen, wenn die Einwilligung vorliegt. */
88
+ function readClickIds(search, at) {
89
+ const params = new URLSearchParams(search);
90
+ const out = {};
91
+ for (const [param, key] of Object.entries(CLICK_PARAMS)) {
92
+ const raw = params.get(param)?.trim();
93
+ if (!raw || !CLICK_ID_VALUE.test(raw))
94
+ continue;
95
+ // Meta: `fb.1.<Zeitpunkt in ms>.<fbclid>`, die fbclid unverändert (Groß- und Kleinschreibung zählt).
96
+ const value = key === 'fbc' ? `fb.1.${at}.${raw}` : raw;
97
+ if (value.length <= ATTRIBUTION_LIMITS.clickId)
98
+ out[key] = value;
99
+ }
100
+ return out;
101
+ }
102
+ /** `_fbp` aus dem Cookie des Meta Pixels. Nur mit Einwilligung lesen. */
103
+ function readFbp() {
104
+ try {
105
+ const match = /(?:^|;\s*)_fbp=([^;]+)/.exec(document.cookie);
106
+ const value = match?.[1] ? decodeURIComponent(match[1]) : '';
107
+ return value && value.length <= ATTRIBUTION_LIMITS.clickId && CLICK_ID_VALUE.test(value)
108
+ ? value
109
+ : undefined;
110
+ }
111
+ catch {
112
+ return undefined;
113
+ }
114
+ }
115
+ function readStored() {
116
+ try {
117
+ const raw = localStorage.getItem(STORAGE_KEY);
118
+ const parsed = raw ? JSON.parse(raw) : null;
119
+ return typeof parsed === 'object' && parsed !== null && parsed.v === 2
120
+ ? parsed
121
+ : null;
122
+ }
123
+ catch {
124
+ return null;
125
+ }
126
+ }
127
+ function writeStored(value) {
128
+ try {
129
+ if (value && Object.keys(value).length > 1)
130
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(value));
131
+ else
132
+ localStorage.removeItem(STORAGE_KEY);
133
+ }
134
+ catch {
135
+ // Speicher voll oder gesperrt: es bleibt beim aktuellen Besuch.
136
+ }
137
+ }
138
+ function forgetLegacy() {
139
+ try {
140
+ sessionStorage.removeItem(LEGACY_KEY);
141
+ }
142
+ catch {
143
+ // nichts zu tun
144
+ }
145
+ }
146
+ /** Liest den aktuellen Besuch einmal je geöffneter Seite. Ohne Zugriff auf den Browser-Speicher. */
147
+ function currentVisit() {
148
+ if (visit)
149
+ return visit;
150
+ const url = new URL(window.location.href);
151
+ const at = Date.now();
152
+ const touch = {};
153
+ const utm = {};
154
+ for (const key of UTM_KEYS) {
155
+ const value = clean(url.searchParams.get(`utm_${key}`), ATTRIBUTION_LIMITS.text);
156
+ if (value)
157
+ touch[key] = utm[key] = value;
158
+ }
159
+ const host = referrerHost();
160
+ if (host)
161
+ touch.referrerHost = host;
162
+ touch.landingPath = url.pathname.slice(0, ATTRIBUTION_LIMITS.path);
163
+ touch.at = new Date(at).toISOString();
164
+ visit = {
165
+ touch,
166
+ search: url.search,
167
+ params: readParams(url.search),
168
+ at,
169
+ utm: Object.keys(utm).length > 0 ? utm : null,
170
+ };
171
+ return visit;
172
+ }
173
+ /** Bringt Kampagne oder Klick-ID mit? Dann zählt der Aufruf immer als neuer Besuch. */
174
+ function isCampaign(v) {
175
+ return Boolean(v.utm || v.touch.referrerHost || Object.keys(readClickIds(v.search, v.at)).length > 0);
176
+ }
177
+ /**
178
+ * Hält den aktuellen Besuch fest und gleicht den Speicher mit der Einwilligung ab: legt an, was erlaubt ist, und
179
+ * löscht, was nicht (mehr) erlaubt ist. Mehrfach aufrufbar (Start der Seite, jede Änderung der Einwilligung).
180
+ * @internal
181
+ */
182
+ export function syncAttribution(granted) {
183
+ if (typeof window === 'undefined')
184
+ return;
185
+ forgetLegacy();
186
+ const v = currentVisit();
187
+ if (!allows(granted, 'history') && !allows(granted, 'visitorId') && !allows(granted, 'clickIds')) {
188
+ stored = null;
189
+ writeStored(null);
190
+ return;
191
+ }
192
+ const now = Date.now();
193
+ const next = { v: 2, ...(stored ?? readStored() ?? {}) };
194
+ if (allows(granted, 'history')) {
195
+ const lastAt = next.last?.at ? Date.parse(next.last.at) : NaN;
196
+ if (Number.isFinite(lastAt) && now - lastAt > ATTRIBUTION_RETENTION_DAYS.history * DAY_MS) {
197
+ delete next.first;
198
+ delete next.last;
199
+ delete next.touches;
200
+ delete next.params;
201
+ }
202
+ // Gezählt wird der Besuch einmal: beim ersten Abgleich dieser geöffneten Seite.
203
+ const counted = stored !== null;
204
+ if (!counted) {
205
+ const fresh = !next.seen || now - next.seen > VISIT_GAP_MS || isCampaign(v);
206
+ if (fresh) {
207
+ next.first ??= v.touch;
208
+ next.last = v.touch;
209
+ next.touches = Math.min(ATTRIBUTION_LIMITS.touches, (next.touches ?? 0) + 1);
210
+ }
211
+ else {
212
+ next.first ??= v.touch;
213
+ next.last ??= v.touch;
214
+ next.touches ??= 1;
215
+ }
216
+ if (Object.keys(v.params).length > 0)
217
+ next.params = v.params;
218
+ }
219
+ next.seen = now;
220
+ }
221
+ else {
222
+ delete next.first;
223
+ delete next.last;
224
+ delete next.touches;
225
+ delete next.seen;
226
+ delete next.params;
227
+ }
228
+ if (allows(granted, 'clickIds')) {
229
+ const ids = {};
230
+ for (const [key, entry] of Object.entries(next.clickIds ?? {})) {
231
+ if (entry && now - entry.at <= ATTRIBUTION_RETENTION_DAYS.clickIds * DAY_MS)
232
+ ids[key] = entry;
233
+ }
234
+ // Die neueste Klick-ID je Netz gewinnt.
235
+ for (const [key, value] of Object.entries(readClickIds(v.search, v.at))) {
236
+ if (ids[key]?.value !== value)
237
+ ids[key] = { value, at: v.at };
238
+ }
239
+ const fbp = readFbp();
240
+ if (fbp)
241
+ ids.fbp = { value: fbp, at: now };
242
+ if (Object.keys(ids).length > 0)
243
+ next.clickIds = ids;
244
+ else
245
+ delete next.clickIds;
246
+ }
247
+ else {
248
+ delete next.clickIds;
249
+ }
250
+ if (allows(granted, 'visitorId')) {
251
+ const valid = next.visitorId &&
252
+ UUID.test(next.visitorId.id) &&
253
+ now - next.visitorId.at <= ATTRIBUTION_RETENTION_DAYS.visitorId * DAY_MS;
254
+ if (!valid)
255
+ next.visitorId = { id: crypto.randomUUID(), at: now };
256
+ }
257
+ else {
258
+ delete next.visitorId;
259
+ }
260
+ stored = next;
261
+ writeStored(next);
262
+ }
263
+ /** Besuchs-ID, wenn erlaubt und angelegt. @internal */
264
+ export function getVisitorId(granted) {
265
+ return allows(granted, 'visitorId') ? (stored?.visitorId?.id ?? null) : null;
266
+ }
267
+ /** UTM und Referrer des aktuellen Besuchs, für den Seitenaufruf beim Einstieg. @internal */
268
+ export function getEntry() {
269
+ if (typeof window === 'undefined')
270
+ return { utm: null, referrerHost: null };
271
+ const v = currentVisit();
272
+ return { utm: v.utm, referrerHost: v.touch.referrerHost ?? null };
273
+ }
274
+ /**
275
+ * Wert eines eigenen URL-Parameters, z. B. `partner` aus `?partner=…`: aus dem aktuellen Besuch, sonst (nur mit
276
+ * Einwilligung) aus dem zuletzt gespeicherten. `null`, wenn es ihn nicht gibt. Nur im Browser.
277
+ *
278
+ * Nicht gelesen werden UTM-Parameter, Klick-IDs und Namen, die nach Zugangs- oder Personendaten aussehen
279
+ * (`email`, `token`, `session` …); höchstens 20 Parameter, Werte bis 500 Zeichen. Mit der Anfrage gehen die
280
+ * Parameter ohnehin an das CRM (`<LeadForm>`), dafür ist nichts zu tun.
281
+ *
282
+ * @example
283
+ * <script lang="ts">
284
+ * import { getCampaignParam } from '@dealsystem/site';
285
+ * import { onMount } from 'svelte';
286
+ * let partner = $state<string | null>(null);
287
+ * onMount(() => (partner = getCampaignParam('partner')));
288
+ * </script>
289
+ */
290
+ export function getCampaignParam(name) {
291
+ if (typeof window === 'undefined')
292
+ return null;
293
+ return currentVisit().params[name] ?? stored?.params?.[name] ?? null;
294
+ }
295
+ /**
296
+ * UTM-Angabe für ein verstecktes Feld (`from: { utm: 'campaign' }`): aus dem aktuellen Besuch, sonst (nur mit
297
+ * Einwilligung) aus dem letzten gespeicherten Besuch.
298
+ * @internal
299
+ */
300
+ export function getCampaignUtm(key) {
301
+ if (typeof window === 'undefined')
302
+ return null;
303
+ return currentVisit().utm?.[key] ?? stored?.last?.[key] ?? null;
304
+ }
305
+ /**
306
+ * `attribution` für den Lead (Fassung 2). Ohne Einwilligung nur der aktuelle Besuch, ohne Klick-IDs und
307
+ * Besuchs-ID.
308
+ * @internal
309
+ */
310
+ export function buildLeadAttribution(granted, consentAt) {
311
+ if (typeof window === 'undefined')
312
+ return undefined;
313
+ const v = currentVisit();
314
+ const history = allows(granted, 'history') && stored;
315
+ const clickIds = {};
316
+ if (allows(granted, 'clickIds')) {
317
+ for (const [key, entry] of Object.entries(stored?.clickIds ?? {})) {
318
+ clickIds[key] = entry.value;
319
+ }
320
+ // Falls der Speicher gesperrt ist: wenigstens die Klick-IDs dieses Besuchs.
321
+ for (const [key, value] of Object.entries(readClickIds(v.search, v.at))) {
322
+ clickIds[key] ??= value;
323
+ }
324
+ }
325
+ const params = { ...(history ? stored.params : undefined), ...v.params };
326
+ return {
327
+ v: 2,
328
+ first: (history && stored.first) || v.touch,
329
+ last: (history && stored.last) || v.touch,
330
+ touches: (history && stored.touches) || 1,
331
+ clickIds: Object.keys(clickIds).length > 0 ? clickIds : null,
332
+ visitorId: getVisitorId(granted),
333
+ params: Object.keys(params).length > 0 ? params : null,
334
+ consent: { statistics: granted.statistics, marketing: granted.marketing, at: consentAt },
335
+ };
336
+ }
337
+ /** @internal Nur für Tests. */
338
+ export function resetAttributionForTests() {
339
+ visit = null;
340
+ stored = null;
341
+ }
@@ -0,0 +1,166 @@
1
+ import { type BookingInfo, type BookingLocationType, type BookingQuestion, type BookingSlot, type SiteApiError } from './siteApi.js';
2
+ import type { BookingKey } from '../types.js';
3
+ import type { LeadFallback } from './leadClient.svelte.js';
4
+ /** Warum etwas nicht geklappt hat. */
5
+ export type BookingFailureReason =
6
+ /** Angaben fehlen oder passen nicht: `fields` nennt je Feld den Text. */
7
+ 'validation'
8
+ /** Die Zeit ist inzwischen vergeben: freie Zeiten neu laden und eine andere wählen lassen. */
9
+ | 'slot_taken'
10
+ /** Die Angaben passen nicht zu dieser Terminart (Regel im CRM). Ausweichkontakt zeigen. */
11
+ | 'not_qualified'
12
+ /** Die Sicherheitsprüfung (Captcha) ließ sich nicht durchführen. */
13
+ | 'captcha'
14
+ /** Zu viele Anfragen; `retryAfterSeconds` sagt, wann es wieder geht. */
15
+ | 'rate_limited'
16
+ /** Keine Verbindung. */
17
+ | 'network'
18
+ /** Buchung ausgeschaltet, ohne Terminart, Kalender gestört oder Antwort unbrauchbar. */
19
+ | 'unavailable';
20
+ /** Fehlschlag mit Text für Besucher und Ausweichkontakt aus dem CRM. */
21
+ export interface BookingFailure {
22
+ ok: false;
23
+ reason: Exclude<BookingFailureReason, 'validation'>;
24
+ /** Text für Besucher, auf Deutsch. */
25
+ message: string;
26
+ fields: Record<string, never>;
27
+ /** Telefon und E-Mail aus dem CRM. Zeig sie, damit der Besucher trotzdem einen Termin bekommt. */
28
+ fallback: LeadFallback;
29
+ retryAfterSeconds: number | null;
30
+ /** @internal */
31
+ error: SiteApiError;
32
+ }
33
+ /** Ergebnis von `info()`. */
34
+ export type BookingInfoResult = {
35
+ ok: true;
36
+ info: BookingInfo;
37
+ } | BookingFailure;
38
+ /** Ergebnis von `slots()`. Zeiten in UTC; zum Anzeigen `groupSlotsByDay(result.slots, visitorTimeZone())`. */
39
+ export type BookingSlotsResult = {
40
+ ok: true;
41
+ /** Zeitzone des Kalenders (Hinweis für Besucher). */
42
+ timezone: string;
43
+ slots: BookingSlot[];
44
+ } | BookingFailure;
45
+ /** Was gebucht werden soll. */
46
+ export interface BookingInput {
47
+ /** Beginn genau wie `start` aus `slots()` (UTC). */
48
+ start: string;
49
+ firstName: string;
50
+ lastName?: string;
51
+ email: string;
52
+ phone?: string;
53
+ /** Antworten auf die Buchungsfragen (`info.questions[].key`). */
54
+ answers?: Record<string, string | number | boolean | readonly string[] | undefined>;
55
+ /** Gewählte Ort-Art aus `info.locations`; ohne Angabe die erste. */
56
+ locationType?: BookingLocationType;
57
+ }
58
+ /** Ergebnis von `book()`. */
59
+ export type BookingResult = {
60
+ ok: true;
61
+ /** `true` in der Vorschau: geprüft, nichts gebucht, keine Mail. Zeig dann einen Hinweis. */
62
+ dryRun: boolean;
63
+ /** `true`, wenn derselbe Vorgang schon gebucht war (doppelt abgeschickt). Für Besucher: gebucht. */
64
+ duplicate: boolean;
65
+ /** Beginn und Ende in UTC. */
66
+ start: string;
67
+ end: string | null;
68
+ submissionId: string;
69
+ } | {
70
+ ok: false;
71
+ reason: 'validation';
72
+ message: string;
73
+ /** Je abgelehntem Feld ein Text: `firstName`, `lastName`, `email`, `phone` oder `answers.<key>`. */
74
+ fields: Record<string, string>;
75
+ fallback: null;
76
+ /** @internal */
77
+ error: SiteApiError | null;
78
+ } | BookingFailure;
79
+ /** Was der Client gerade tut, reaktiv. */
80
+ export type BookingClientStatus = 'idle' | 'loading' | 'captcha' | 'sending';
81
+ export interface BookingClientOptions {
82
+ /** Element für das unsichtbare Captcha. @internal */
83
+ captchaElement?: () => HTMLElement | null;
84
+ /** Wie der Aufruf in Fehlermeldungen heißt. @internal */
85
+ caller?: string;
86
+ }
87
+ /** Ein Client für eine Terminbuchung aus `dealsystem.config.ts`. */
88
+ export interface BookingClient<K extends string = string> {
89
+ readonly booking: K;
90
+ /** `label` aus `dealsystem.config.ts`, sonst der Schlüssel. Nach `info()` gilt `info.label`. */
91
+ readonly label: string;
92
+ readonly fallback: LeadFallback;
93
+ /** Was der Client gerade tut (reaktiv). */
94
+ readonly status: BookingClientStatus;
95
+ /** Terminart: Titel, Dauer, Ort-Arten, Fragen, Zeitzone des Kalenders. Einmal geladen, danach aus dem Speicher. */
96
+ info(): Promise<BookingInfoResult>;
97
+ /** Freie Zeiten ab `from` (Standard: jetzt) bis `to` (Standard: 7 Tage später, höchstens 31 Tage). */
98
+ slots(from?: Date | string, to?: Date | string): Promise<BookingSlotsResult>;
99
+ /** Prüft die Angaben wie der Server. Leeres Objekt = in Ordnung. */
100
+ validate(input: Omit<BookingInput, 'start'>, questions?: readonly BookingQuestion[]): Record<string, string>;
101
+ /** Startet die Sicherheitsprüfung im Hintergrund, z. B. sobald eine Zeit gewählt ist. */
102
+ prepare(): void;
103
+ /** Wert der Bot-Falle (`<LeadHoneypot client={booking} />`). Echte Besucher lassen sie leer. */
104
+ setHoneypot(value: string): void;
105
+ /**
106
+ * Bucht. Wartet auf die Sicherheitsprüfung, hängt Zeitzone, Herkunft und Einwilligung an. Derselbe Beginn bei
107
+ * einem neuen Versuch behält die `submissionId`: doppelt abgeschickt wird nur einmal gebucht. Läuft schon eine
108
+ * Buchung, gibt es deren Ergebnis zurück.
109
+ */
110
+ book(input: BookingInput): Promise<BookingResult>;
111
+ /** Räumt das Captcha ab. In `onMount` als Rückgabe verwenden. */
112
+ destroy(): void;
113
+ }
114
+ /**
115
+ * Terminbuchung ohne `<Booker>`: für eine eigene Oberfläche. Nimmt den Schlüssel aus `booking` in
116
+ * `dealsystem.config.ts`. Die Terminart (Dauer, Arbeitszeiten, Fragen) richtet der Kunde im CRM ein; erfinde
117
+ * keine. Kein eigenes `fetch` an DealSystem (`SEC-004`).
118
+ *
119
+ * Zeiten kommen und gehen in UTC. Zeig sie in der Zeitzone des Besuchers (`groupSlotsByDay`, `visitorTimeZone`)
120
+ * und nenne die des Kalenders (`timezone`) als Hinweis. Zeig bei jedem Fehler außer `validation` den
121
+ * Ausweichkontakt `fallback`; bei `slot_taken` die Zeiten neu laden. Setz `<LeadHoneypot client={termin} />` in
122
+ * die Oberfläche.
123
+ *
124
+ * @example
125
+ * <script lang="ts">
126
+ * import { createBookingClient, groupSlotsByDay, visitorTimeZone, LeadHoneypot } from '@dealsystem/site';
127
+ * import { onMount } from 'svelte';
128
+ *
129
+ * const termin = createBookingClient('erstgespraech');
130
+ * const zone = visitorTimeZone();
131
+ * let tage = $state<ReturnType<typeof groupSlotsByDay>>([]);
132
+ * let start = $state('');
133
+ * let vorname = $state('');
134
+ * let email = $state('');
135
+ * let ergebnis = $state<Awaited<ReturnType<typeof termin.book>> | null>(null);
136
+ *
137
+ * onMount(() => {
138
+ * termin.slots().then((r) => (tage = r.ok ? groupSlotsByDay(r.slots, zone) : []));
139
+ * return () => termin.destroy();
140
+ * });
141
+ *
142
+ * async function buchen(event: SubmitEvent) {
143
+ * event.preventDefault();
144
+ * ergebnis = await termin.book({ start, firstName: vorname, email });
145
+ * }
146
+ * </script>
147
+ *
148
+ * {#each tage as tag (tag.date)}
149
+ * <h3>{tag.long}</h3>
150
+ * {#each tag.slots as zeit (zeit.start)}
151
+ * <button type="button" aria-pressed={start === zeit.start} onclick={() => ((start = zeit.start), termin.prepare())}>
152
+ * {zeit.time}
153
+ * </button>
154
+ * {/each}
155
+ * {/each}
156
+ * <form onsubmit={buchen}>
157
+ * <label for="vorname">Vorname</label>
158
+ * <input id="vorname" required bind:value={vorname} />
159
+ * <label for="email">E-Mail</label>
160
+ * <input id="email" type="email" required bind:value={email} />
161
+ * <LeadHoneypot client={termin} />
162
+ * <button type="submit" disabled={!start}>Termin buchen</button>
163
+ * </form>
164
+ * {#if ergebnis && !ergebnis.ok}<p role="alert">{ergebnis.message}</p>{/if}
165
+ */
166
+ export declare function createBookingClient<K extends BookingKey>(booking: K, options?: BookingClientOptions): BookingClient<K>;