@dealsystem/site 0.0.0-stage → 0.2.0
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 +145 -2
- package/agent-files/claude/skills/angebote-einbauen/SKILL.md +30 -0
- package/agent-files/claude/skills/bild-einbauen/SKILL.md +43 -0
- package/agent-files/claude/skills/domain-verbinden/SKILL.md +23 -0
- package/agent-files/claude/skills/extern-einbinden/SKILL.md +37 -0
- package/agent-files/claude/skills/formular-anbinden/SKILL.md +34 -0
- package/agent-files/claude/skills/funnel-mehrstufig/BewertungFunnel.svelte +220 -0
- package/agent-files/claude/skills/funnel-mehrstufig/SKILL.md +101 -0
- package/agent-files/claude/skills/neue-seite/SKILL.md +47 -0
- package/agent-files/claude/skills/prueffehler-beheben/SKILL.md +31 -0
- package/agent-files/claude/skills/termin-buchung/SKILL.md +51 -0
- package/agent-files/claude/skills/veroeffentlichen/SKILL.md +32 -0
- package/agent-files/cursor/rules/dealsystem.mdc +7 -0
- package/agent-files/manifest.json +93 -0
- package/contract/README.md +41 -0
- package/contract/ds-content.v1.json +2355 -0
- package/contract/external-presets.v1.json +65 -0
- package/contract/funnel-code-config.md +87 -0
- package/contract/site-api.v1.json +3916 -0
- package/dist/client/altcha-workers.d.ts +10 -0
- package/dist/client/attribution.d.ts +119 -0
- package/dist/client/attribution.js +341 -0
- package/dist/client/bookingClient.svelte.d.ts +166 -0
- package/dist/client/bookingClient.svelte.js +369 -0
- package/dist/client/bookingTime.d.ts +46 -0
- package/dist/client/bookingTime.js +109 -0
- package/dist/client/captcha.d.ts +26 -0
- package/dist/client/captcha.js +71 -0
- package/dist/client/captchaSession.d.ts +21 -0
- package/dist/client/captchaSession.js +105 -0
- package/dist/client/collections.d.ts +34 -0
- package/dist/client/collections.js +40 -0
- package/dist/client/externalScript.d.ts +20 -0
- package/dist/client/externalScript.js +36 -0
- package/dist/client/funnelState.svelte.d.ts +47 -0
- package/dist/client/funnelState.svelte.js +81 -0
- package/dist/client/leadClient.svelte.d.ts +131 -0
- package/dist/client/leadClient.svelte.js +250 -0
- package/dist/client/pageview.d.ts +7 -0
- package/dist/client/pageview.js +44 -0
- package/dist/client/siteApi.d.ts +211 -0
- package/dist/client/siteApi.js +320 -0
- package/dist/client/tracking.d.ts +18 -0
- package/dist/client/tracking.js +93 -0
- package/dist/client/validation.d.ts +10 -0
- package/dist/client/validation.js +66 -0
- package/dist/components/Booker.svelte +729 -0
- package/dist/components/Booker.svelte.d.ts +42 -0
- package/dist/components/CollectionList.svelte +122 -0
- package/dist/components/CollectionList.svelte.d.ts +65 -0
- package/dist/components/ConsentGate.svelte +68 -0
- package/dist/components/ConsentGate.svelte.d.ts +44 -0
- package/dist/components/CookieBanner.svelte +303 -0
- package/dist/components/CookieBanner.svelte.d.ts +29 -0
- package/dist/components/Datenschutz.svelte +84 -0
- package/dist/components/Datenschutz.svelte.d.ts +26 -0
- package/dist/components/Embed.svelte +263 -0
- package/dist/components/Embed.svelte.d.ts +41 -0
- package/dist/components/ExternalScript.svelte +94 -0
- package/dist/components/ExternalScript.svelte.d.ts +41 -0
- package/dist/components/Impressum.svelte +59 -0
- package/dist/components/Impressum.svelte.d.ts +25 -0
- package/dist/components/LeadForm.svelte +475 -0
- package/dist/components/LeadForm.svelte.d.ts +35 -0
- package/dist/components/LeadHoneypot.svelte +43 -0
- package/dist/components/LeadHoneypot.svelte.d.ts +18 -0
- package/dist/components/Link.svelte +48 -0
- package/dist/components/Link.svelte.d.ts +30 -0
- package/dist/components/MapEmbed.svelte +154 -0
- package/dist/components/MapEmbed.svelte.d.ts +28 -0
- package/dist/components/MediaImage.svelte +218 -0
- package/dist/components/MediaImage.svelte.d.ts +128 -0
- package/dist/components/MediaVideo.svelte +103 -0
- package/dist/components/MediaVideo.svelte.d.ts +20 -0
- package/dist/components/RichText.svelte +105 -0
- package/dist/components/RichText.svelte.d.ts +55 -0
- package/dist/components/Seo.svelte +89 -0
- package/dist/components/Seo.svelte.d.ts +45 -0
- package/dist/components/SiteFooterLegal.svelte +75 -0
- package/dist/components/SiteFooterLegal.svelte.d.ts +22 -0
- package/dist/components/SiteHead.svelte +79 -0
- package/dist/components/SiteHead.svelte.d.ts +32 -0
- package/dist/components/Text.svelte +100 -0
- package/dist/components/Text.svelte.d.ts +55 -0
- package/dist/components/Tracking.svelte +30 -0
- package/dist/components/Tracking.svelte.d.ts +14 -0
- package/dist/components/Zeitfenster.svelte +92 -0
- package/dist/components/Zeitfenster.svelte.d.ts +34 -0
- package/dist/components/legal.d.ts +12 -0
- package/dist/components/legal.js +27 -0
- package/dist/config/index.d.ts +121 -0
- package/dist/config/index.js +602 -0
- package/dist/config/static/index.d.ts +3 -0
- package/dist/config/static/index.js +5 -0
- package/dist/config/static/lines.d.ts +9 -0
- package/dist/config/static/lines.js +22 -0
- package/dist/config/static/literal.d.ts +45 -0
- package/dist/config/static/literal.js +175 -0
- package/dist/config/static/siteConfig.d.ts +39 -0
- package/dist/config/static/siteConfig.js +150 -0
- package/dist/consent/consent.svelte.d.ts +91 -0
- package/dist/consent/consent.svelte.js +221 -0
- package/dist/content/index.d.ts +123 -0
- package/dist/content/index.js +247 -0
- package/dist/contentBlock.d.ts +45 -0
- package/dist/contentBlock.js +78 -0
- package/dist/csp/index.d.ts +27 -0
- package/dist/csp/index.js +74 -0
- package/dist/external/csp.d.ts +25 -0
- package/dist/external/csp.js +104 -0
- package/dist/external/hosts.d.ts +30 -0
- package/dist/external/hosts.js +128 -0
- package/dist/external/presets.d.ts +54 -0
- package/dist/external/presets.js +212 -0
- package/dist/external/resolve.d.ts +39 -0
- package/dist/external/resolve.js +254 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/internal/consentNeed.d.ts +21 -0
- package/dist/internal/consentNeed.js +50 -0
- package/dist/internal/dealsystem-legal-imprint.d.ts +2 -0
- package/dist/internal/dealsystem-legal-imprint.js +5 -0
- package/dist/internal/dealsystem-legal-privacy.d.ts +2 -0
- package/dist/internal/dealsystem-legal-privacy.js +5 -0
- package/dist/internal/dealsystem-site-data.d.ts +3 -0
- package/dist/internal/dealsystem-site-data.js +2 -0
- package/dist/internal/imprint.d.ts +4 -0
- package/dist/internal/imprint.js +10 -0
- package/dist/internal/mediaImage.d.ts +15 -0
- package/dist/internal/mediaImage.js +22 -0
- package/dist/internal/privacy.d.ts +4 -0
- package/dist/internal/privacy.js +10 -0
- package/dist/internal/providers.d.ts +9 -0
- package/dist/internal/providers.js +44 -0
- package/dist/internal/reload.d.ts +2 -0
- package/dist/internal/reload.js +5 -0
- package/dist/internal/seo.d.ts +41 -0
- package/dist/internal/seo.js +79 -0
- package/dist/internal/siteData.d.ts +7 -0
- package/dist/internal/siteData.js +39 -0
- package/dist/internal/usage.d.ts +7 -0
- package/dist/internal/usage.js +13 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.js +58 -0
- package/dist/leadmagnet.d.ts +16 -0
- package/dist/leadmagnet.js +28 -0
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +9 -0
- package/dist/richtext/escape.d.ts +4 -0
- package/dist/richtext/escape.js +18 -0
- package/dist/richtext/server.d.ts +16 -0
- package/dist/richtext/server.js +123 -0
- package/dist/schedule.d.ts +23 -0
- package/dist/schedule.js +67 -0
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +38 -0
- package/dist/snapshot.d.ts +14 -0
- package/dist/snapshot.js +214 -0
- package/dist/types.d.ts +550 -0
- package/dist/types.js +4 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/dist/vite/index.d.ts +85 -0
- package/dist/vite/index.js +641 -0
- package/dist/vite/scan.d.ts +47 -0
- package/dist/vite/scan.js +355 -0
- package/dist/vite/zeitfenster.d.ts +18 -0
- package/dist/vite/zeitfenster.js +76 -0
- package/docs/ablauf.md +167 -0
- package/docs/agents-block.md +100 -0
- package/docs/befehle.md +103 -0
- package/docs/extern.md +143 -0
- package/docs/gestaltung.md +139 -0
- package/docs/inhalte.md +224 -0
- package/docs/komponenten.md +1273 -0
- package/docs/konfiguration.md +310 -0
- package/docs/llms.txt +19 -0
- package/docs/rechtstexte.md +84 -0
- package/docs/regeln.md +108 -0
- package/docs/seo.md +55 -0
- package/docs/termine.md +73 -0
- package/package.json +115 -5
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Einsendung eines Formulars ohne eigenes `fetch`: für eigene Oberflächen (mehrstufige Funnels, Rechner, Quiz)
|
|
2
|
+
// und intern für `<LeadForm>`. Eine Implementierung für beides: Prüfung, Captcha (ALTCHA, gelöst im Web Worker,
|
|
3
|
+
// ohne sichtbares Widget), versteckte Felder, Attribution, Honeypot, `submissionId`, Ereignis-ID für Pixel und
|
|
4
|
+
// gtag. Fehler kommen als Werte mit deutschem Text für Besucher zurück, nie als Ausnahme.
|
|
5
|
+
import { buildLeadAttribution, getCampaignParam, getCampaignUtm } from './attribution.js';
|
|
6
|
+
import { createCaptchaSession } from './captchaSession.js';
|
|
7
|
+
import { siteApi } from './siteApi.js';
|
|
8
|
+
import { reportLeadConversion } from './tracking.js';
|
|
9
|
+
import { labelOf, toLeadData, validateField } from './validation.js';
|
|
10
|
+
import { consent } from '../consent/consent.svelte.js';
|
|
11
|
+
import { getSiteData } from '../internal/siteData.js';
|
|
12
|
+
import { usageError } from '../internal/usage.js';
|
|
13
|
+
import { leadmagnetSuccessMessage, normalizeLeadmagnet } from '../leadmagnet.js';
|
|
14
|
+
/** Standard-Erfolgstext ohne Leadmagnet (auch in `<LeadForm>`). */
|
|
15
|
+
export const DEFAULT_SUCCESS_MESSAGE = 'Vielen Dank. Ihre Anfrage ist bei uns angekommen.';
|
|
16
|
+
const HIDDEN_MAX = 500;
|
|
17
|
+
const MESSAGES = {
|
|
18
|
+
validation: 'Bitte prüfen Sie Ihre Angaben.',
|
|
19
|
+
reachable: 'Bitte geben Sie eine E-Mail-Adresse oder eine Telefonnummer an.',
|
|
20
|
+
captcha: 'Die Sicherheitsprüfung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut.',
|
|
21
|
+
unavailable: 'Dieses Formular ist zurzeit nicht verfügbar.',
|
|
22
|
+
};
|
|
23
|
+
function captchaError() {
|
|
24
|
+
return {
|
|
25
|
+
kind: 'captcha_failed',
|
|
26
|
+
status: null,
|
|
27
|
+
code: null,
|
|
28
|
+
message: MESSAGES.captcha,
|
|
29
|
+
retryAfterSeconds: null,
|
|
30
|
+
invalidFields: [],
|
|
31
|
+
invalidPaths: [],
|
|
32
|
+
formInvalid: false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function reasonOf(error) {
|
|
36
|
+
if (error.kind === 'captcha_failed')
|
|
37
|
+
return 'captcha';
|
|
38
|
+
if (error.kind === 'rate_limited')
|
|
39
|
+
return 'rate_limited';
|
|
40
|
+
if (error.kind === 'network')
|
|
41
|
+
return 'network';
|
|
42
|
+
return 'unavailable';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Formular ohne `<LeadForm>`: für eigene Oberflächen wie mehrstufige Funnels. Nimmt den Schlüssel aus
|
|
46
|
+
* `dealsystem.config.ts`. Kein eigenes `fetch` an DealSystem, das ist verboten (`SEC-004`).
|
|
47
|
+
*
|
|
48
|
+
* Zeig bei jedem Fehler außer `validation` den Ausweichkontakt `res.fallback` (`QUA-008`) und
|
|
49
|
+
* setz `<LeadHoneypot client={lead} />` in die Oberfläche (Bot-Falle). Nach Erfolg passt `lead.successMessage`;
|
|
50
|
+
* verspricht das Formular eine Datei (`leadmagnet`), kündigt dieser Text sie an.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* <script lang="ts">
|
|
54
|
+
* import { createLeadClient, LeadHoneypot } from '@dealsystem/site';
|
|
55
|
+
* import { onMount } from 'svelte';
|
|
56
|
+
*
|
|
57
|
+
* const lead = createLeadClient('bewertung');
|
|
58
|
+
* onMount(() => () => lead.destroy());
|
|
59
|
+
* let email = $state('');
|
|
60
|
+
* let result = $state<Awaited<ReturnType<typeof lead.submit>> | null>(null);
|
|
61
|
+
*
|
|
62
|
+
* // Eigenes <form>: Enter sendet, der Browser prüft `required`. Ohne `action`, Absenden nur hier (SEC-007).
|
|
63
|
+
* async function senden(event: SubmitEvent) {
|
|
64
|
+
* event.preventDefault();
|
|
65
|
+
* result = await lead.submit({ email });
|
|
66
|
+
* }
|
|
67
|
+
* </script>
|
|
68
|
+
*
|
|
69
|
+
* <form onsubmit={senden}>
|
|
70
|
+
* <label for="email">E-Mail</label>
|
|
71
|
+
* <input id="email" type="email" autocomplete="email" required bind:value={email} onfocus={() => lead.prepare()} />
|
|
72
|
+
* <LeadHoneypot client={lead} />
|
|
73
|
+
* <button type="submit">Senden</button>
|
|
74
|
+
* </form>
|
|
75
|
+
* {#if result && !result.ok}
|
|
76
|
+
* <p role="alert">{result.message}</p>
|
|
77
|
+
* {#if result.fallback?.phone}<a href="tel:{result.fallback.phone}">{result.fallback.phone}</a>{/if}
|
|
78
|
+
* {/if}
|
|
79
|
+
*/
|
|
80
|
+
export function createLeadClient(funnel, options = {}) {
|
|
81
|
+
const site = getSiteData();
|
|
82
|
+
const definition = site.funnels[funnel];
|
|
83
|
+
if (!definition) {
|
|
84
|
+
const known = Object.keys(site.funnels);
|
|
85
|
+
usageError(`${options.caller ?? `createLeadClient("${funnel}")`}: Dieses Formular steht nicht in dealsystem.config.ts. ` +
|
|
86
|
+
(known.length > 0 ? `Vorhanden: ${known.join(', ')}.` : 'Dort ist noch kein Formular eingetragen.'));
|
|
87
|
+
}
|
|
88
|
+
const allFields = definition?.fields ?? [];
|
|
89
|
+
const visible = allFields.filter((f) => f.type !== 'hidden');
|
|
90
|
+
const hidden = allFields.filter((f) => f.type === 'hidden');
|
|
91
|
+
const fallback = { phone: site.legal.phone || null, email: site.legal.email || null };
|
|
92
|
+
const leadmagnet = normalizeLeadmagnet(definition?.leadmagnet);
|
|
93
|
+
let status = $state('idle');
|
|
94
|
+
let honeypot = '';
|
|
95
|
+
/** Bleibt über neue Versuche gleich, damit der Server Doppel erkennt; nach Erfolg neu. */
|
|
96
|
+
let submissionId = '';
|
|
97
|
+
let inFlight = null;
|
|
98
|
+
const captcha = createCaptchaSession({ name: String(funnel), element: options.captchaElement });
|
|
99
|
+
// --- Werte --------------------------------------------------------------------------------------------
|
|
100
|
+
function hiddenValues() {
|
|
101
|
+
const out = {};
|
|
102
|
+
for (const field of hidden) {
|
|
103
|
+
const from = field.from;
|
|
104
|
+
let value = null;
|
|
105
|
+
if (from && 'query' in from)
|
|
106
|
+
value = getCampaignParam(from.query);
|
|
107
|
+
else if (from && 'utm' in from)
|
|
108
|
+
value = getCampaignUtm(from.utm);
|
|
109
|
+
else if (from && 'value' in from)
|
|
110
|
+
value = from.value;
|
|
111
|
+
const text = value?.trim().slice(0, HIDDEN_MAX);
|
|
112
|
+
if (text)
|
|
113
|
+
out[field.name] = text;
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
function validate(values, only) {
|
|
118
|
+
const found = {};
|
|
119
|
+
const record = values;
|
|
120
|
+
for (const field of visible) {
|
|
121
|
+
if (only && !only.includes(field.name))
|
|
122
|
+
continue;
|
|
123
|
+
const value = record[field.name];
|
|
124
|
+
const message = validateField(field, Array.isArray(value) ? [...value] : value);
|
|
125
|
+
if (message)
|
|
126
|
+
found[field.name] = message;
|
|
127
|
+
}
|
|
128
|
+
return found;
|
|
129
|
+
}
|
|
130
|
+
async function send(values) {
|
|
131
|
+
const found = validate(values);
|
|
132
|
+
if (Object.keys(found).length > 0) {
|
|
133
|
+
return {
|
|
134
|
+
ok: false,
|
|
135
|
+
reason: 'validation',
|
|
136
|
+
message: MESSAGES.validation,
|
|
137
|
+
fields: found,
|
|
138
|
+
fallback: null,
|
|
139
|
+
error: null,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (!definition || definition.active === false) {
|
|
143
|
+
const error = { ...captchaError(), kind: 'not_found', message: MESSAGES.unavailable };
|
|
144
|
+
return {
|
|
145
|
+
ok: false,
|
|
146
|
+
reason: 'unavailable',
|
|
147
|
+
message: error.message,
|
|
148
|
+
fields: {},
|
|
149
|
+
fallback,
|
|
150
|
+
retryAfterSeconds: null,
|
|
151
|
+
error,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
status = 'captcha';
|
|
155
|
+
const payload = await captcha.solution();
|
|
156
|
+
if (!payload) {
|
|
157
|
+
const error = captchaError();
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
reason: 'captcha',
|
|
161
|
+
message: error.message,
|
|
162
|
+
fields: {},
|
|
163
|
+
fallback,
|
|
164
|
+
retryAfterSeconds: null,
|
|
165
|
+
error,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
status = 'sending';
|
|
169
|
+
submissionId ||= crypto.randomUUID();
|
|
170
|
+
const record = values;
|
|
171
|
+
const plain = Object.fromEntries(Object.entries(record).map(([k, v]) => [k, Array.isArray(v) ? [...v] : v]));
|
|
172
|
+
const result = await siteApi().submitLead({
|
|
173
|
+
funnelKey: funnel,
|
|
174
|
+
submissionId,
|
|
175
|
+
data: { ...toLeadData(visible, plain), ...hiddenValues() },
|
|
176
|
+
attribution: buildLeadAttribution(consent.granted(), consent.decidedAt),
|
|
177
|
+
captcha: payload,
|
|
178
|
+
website: honeypot.slice(0, 500),
|
|
179
|
+
});
|
|
180
|
+
if (result.ok) {
|
|
181
|
+
const id = submissionId;
|
|
182
|
+
submissionId = '';
|
|
183
|
+
captcha.clear();
|
|
184
|
+
// Gleiche Ereignis-ID wie die serverseitige Conversion. Die Vorschau zählt nicht.
|
|
185
|
+
if (!result.data.dryRun && consent.has('marketing'))
|
|
186
|
+
reportLeadConversion(id);
|
|
187
|
+
return { ok: true, dryRun: result.data.dryRun, submissionId: id };
|
|
188
|
+
}
|
|
189
|
+
captcha.consume();
|
|
190
|
+
const error = result.error;
|
|
191
|
+
if (error.kind === 'validation') {
|
|
192
|
+
const fields = {};
|
|
193
|
+
for (const field of visible) {
|
|
194
|
+
// Text vom Server wird nie angezeigt: eigene Meldung je Feld.
|
|
195
|
+
if (error.invalidFields.includes(field.name))
|
|
196
|
+
fields[field.name] = `Bitte prüfen Sie Ihre Angabe bei „${labelOf(field)}“.`;
|
|
197
|
+
}
|
|
198
|
+
const message = Object.keys(fields).length === 0 && error.formInvalid ? MESSAGES.reachable : MESSAGES.validation;
|
|
199
|
+
return {
|
|
200
|
+
ok: false,
|
|
201
|
+
reason: 'validation',
|
|
202
|
+
message,
|
|
203
|
+
fields,
|
|
204
|
+
fallback: null,
|
|
205
|
+
error: { ...error, message },
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
ok: false,
|
|
210
|
+
reason: reasonOf(error),
|
|
211
|
+
message: error.message,
|
|
212
|
+
fields: {},
|
|
213
|
+
fallback,
|
|
214
|
+
retryAfterSeconds: error.retryAfterSeconds,
|
|
215
|
+
error,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
funnel,
|
|
220
|
+
label: definition?.label ?? String(funnel),
|
|
221
|
+
available: Boolean(definition) && definition?.active !== false,
|
|
222
|
+
fields: visible,
|
|
223
|
+
fallback,
|
|
224
|
+
leadmagnet,
|
|
225
|
+
successMessage: leadmagnet ? leadmagnetSuccessMessage(leadmagnet.label) : DEFAULT_SUCCESS_MESSAGE,
|
|
226
|
+
get status() {
|
|
227
|
+
return status;
|
|
228
|
+
},
|
|
229
|
+
field: (name) => visible.find((f) => f.name === name),
|
|
230
|
+
prepare() {
|
|
231
|
+
captcha.start();
|
|
232
|
+
},
|
|
233
|
+
validate,
|
|
234
|
+
setHoneypot(value) {
|
|
235
|
+
honeypot = value;
|
|
236
|
+
},
|
|
237
|
+
submit(values) {
|
|
238
|
+
if (inFlight)
|
|
239
|
+
return inFlight;
|
|
240
|
+
inFlight = send(values).finally(() => {
|
|
241
|
+
inFlight = null;
|
|
242
|
+
status = 'idle';
|
|
243
|
+
});
|
|
244
|
+
return inFlight;
|
|
245
|
+
},
|
|
246
|
+
destroy() {
|
|
247
|
+
captcha.destroy();
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meldet einen Seitenaufruf, je Pfad nur einmal hintereinander. `<SiteHead>` ruft das bei jedem Seitenwechsel auf.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function trackPageview(path: string): void;
|
|
6
|
+
/** @internal Nur für Tests. */
|
|
7
|
+
export declare function resetPageviewsForTests(): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Seitenaufrufe für die Statistik der Website (`POST …/track`). Ohne Einwilligung nur Pfad, Einstieg, Kampagne und
|
|
2
|
+
// fremder Referrer; der Core zählt dann anonym über einen Tages-Hash (kein Zugriff auf das Endgerät). Die Besuchs-ID
|
|
3
|
+
// geht nur mit Einwilligung mit (`ATTRIBUTION_CONSENT.visitorId`).
|
|
4
|
+
import { consent } from '../consent/consent.svelte.js';
|
|
5
|
+
import { getEntry, getVisitorId } from './attribution.js';
|
|
6
|
+
import { siteApi } from './siteApi.js';
|
|
7
|
+
let landed = false;
|
|
8
|
+
let lastPath = null;
|
|
9
|
+
/**
|
|
10
|
+
* Meldet einen Seitenaufruf, je Pfad nur einmal hintereinander. `<SiteHead>` ruft das bei jedem Seitenwechsel auf.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function trackPageview(path) {
|
|
14
|
+
if (typeof window === 'undefined' || path === lastPath)
|
|
15
|
+
return;
|
|
16
|
+
lastPath = path;
|
|
17
|
+
const landing = !landed;
|
|
18
|
+
landed = true;
|
|
19
|
+
const granted = consent.granted();
|
|
20
|
+
const body = {
|
|
21
|
+
path: path.slice(0, 2000),
|
|
22
|
+
landing,
|
|
23
|
+
consent: { statistics: granted.statistics, marketing: granted.marketing, at: consent.decidedAt },
|
|
24
|
+
};
|
|
25
|
+
if (landing) {
|
|
26
|
+
const entry = getEntry();
|
|
27
|
+
if (entry.utm)
|
|
28
|
+
body.utm = entry.utm;
|
|
29
|
+
if (entry.referrerHost)
|
|
30
|
+
body.referrerHost = entry.referrerHost;
|
|
31
|
+
}
|
|
32
|
+
const visitorId = getVisitorId(granted);
|
|
33
|
+
if (visitorId)
|
|
34
|
+
body.visitorId = visitorId;
|
|
35
|
+
// Kein await, kein Fehler für den Besucher: Statistik ist nie wichtiger als die Seite.
|
|
36
|
+
void siteApi()
|
|
37
|
+
.track(body)
|
|
38
|
+
.catch(() => undefined);
|
|
39
|
+
}
|
|
40
|
+
/** @internal Nur für Tests. */
|
|
41
|
+
export function resetPageviewsForTests() {
|
|
42
|
+
landed = false;
|
|
43
|
+
lastPath = null;
|
|
44
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { LeadAttributionV2, Touch } from './attribution.js';
|
|
2
|
+
import type { RawCollectionEntry } from '../types.js';
|
|
3
|
+
/** Art eines Fehlers der Site-API, zum Verzweigen in der Oberfläche. */
|
|
4
|
+
export type SiteApiErrorKind =
|
|
5
|
+
/** Keine Verbindung, Abbruch oder Zeitüberschreitung. */
|
|
6
|
+
'network'
|
|
7
|
+
/** 429: zu viele Anfragen. */
|
|
8
|
+
| 'rate_limited'
|
|
9
|
+
/** 422 `validation_error`: Eingaben abgelehnt, siehe `invalidFields` und `formInvalid`. */
|
|
10
|
+
| 'validation'
|
|
11
|
+
/** 400 `captcha_failed`. */
|
|
12
|
+
| 'captcha_failed'
|
|
13
|
+
/** 400, 405, 413, 415: der Server nimmt die Anfrage so nicht an (z. B. `payload_too_large`). */
|
|
14
|
+
| 'rejected'
|
|
15
|
+
/** 404: Formular, Sammlung, Eintrag oder Buchung gibt es nicht (oder sie ist ausgeschaltet). */
|
|
16
|
+
| 'not_found'
|
|
17
|
+
/** 409 `slot_taken`: Die Zeit ist inzwischen vergeben. Freie Zeiten neu laden. */
|
|
18
|
+
| 'conflict'
|
|
19
|
+
/** 410 `appointment_closed`: Der Termin hat begonnen oder ist vorbei. */
|
|
20
|
+
| 'gone'
|
|
21
|
+
/** 403: die Seite darf von dieser Adresse aus nicht anfragen. */
|
|
22
|
+
| 'forbidden'
|
|
23
|
+
/** 5xx, auch `captcha_unavailable` (503). */
|
|
24
|
+
| 'server'
|
|
25
|
+
/** Antwort hat nicht die vereinbarte Form. */
|
|
26
|
+
| 'invalid_response';
|
|
27
|
+
/** Ein Fehler der Site-API als Wert. */
|
|
28
|
+
export interface SiteApiError {
|
|
29
|
+
kind: SiteApiErrorKind;
|
|
30
|
+
/** HTTP-Status, `null` bei Netzfehlern. */
|
|
31
|
+
status: number | null;
|
|
32
|
+
/** Fehlercode des Servers, z. B. `funnel_not_found`. */
|
|
33
|
+
code: string | null;
|
|
34
|
+
/** Text für Besucher, auf Deutsch. Nie Text vom Server. */
|
|
35
|
+
message: string;
|
|
36
|
+
/** Bei `rate_limited`: frühester neuer Versuch in Sekunden. */
|
|
37
|
+
retryAfterSeconds: number | null;
|
|
38
|
+
/** Bei `validation`: Namen der abgelehnten Felder (`details[].path` ohne `data.`). */
|
|
39
|
+
invalidFields: string[];
|
|
40
|
+
/** Bei `validation`: das Formular als Ganzes ist abgelehnt (`path: "data"`), z. B. weil E-Mail und Telefon fehlen. */
|
|
41
|
+
formInvalid: boolean;
|
|
42
|
+
/** Bei `validation`: alle abgelehnten Pfade wie gemeldet, z. B. `attendee.email` oder `answers.anliegen`. */
|
|
43
|
+
invalidPaths: string[];
|
|
44
|
+
}
|
|
45
|
+
/** Ergebnis jedes Aufrufs: entweder Daten oder ein Fehler, nie eine Ausnahme. */
|
|
46
|
+
export type SiteApiResult<T> = {
|
|
47
|
+
ok: true;
|
|
48
|
+
data: T;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
error: SiteApiError;
|
|
52
|
+
};
|
|
53
|
+
/** Fassung 1 der Zuordnung (flach, ältere SDKs). Der Core nimmt sie weiter an. */
|
|
54
|
+
export interface LeadAttributionV1 {
|
|
55
|
+
utmSource?: string;
|
|
56
|
+
utmMedium?: string;
|
|
57
|
+
utmCampaign?: string;
|
|
58
|
+
utmTerm?: string;
|
|
59
|
+
utmContent?: string;
|
|
60
|
+
referrerHost?: string;
|
|
61
|
+
capturedAt?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Body von `POST …/leads`. */
|
|
64
|
+
export interface LeadRequest {
|
|
65
|
+
funnelKey: string;
|
|
66
|
+
/** UUID je Einsendung. Derselbe Wert bei einem neuen Versuch verhindert Doppel. */
|
|
67
|
+
submissionId: string;
|
|
68
|
+
data: Record<string, string | string[] | boolean>;
|
|
69
|
+
/** Herkunft (Fassung 2). Ohne Einwilligung nur der aktuelle Besuch. */
|
|
70
|
+
attribution?: LeadAttributionV2 | LeadAttributionV1;
|
|
71
|
+
/** Gelöste Captcha-Aufgabe (ALTCHA v3): base64 von `{ challenge, solution }`, höchstens 4 000 Zeichen. */
|
|
72
|
+
captcha: string;
|
|
73
|
+
/** Honeypot. Echte Besucher lassen das Feld leer. */
|
|
74
|
+
website?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface LeadAccepted {
|
|
77
|
+
accepted: true;
|
|
78
|
+
/** `true` in der Vorschau: geprüft, aber nicht gespeichert. */
|
|
79
|
+
dryRun: boolean;
|
|
80
|
+
}
|
|
81
|
+
/** Body von `POST …/track` (Seitenaufruf). */
|
|
82
|
+
export interface PageviewRequest {
|
|
83
|
+
/** `location.pathname`. */
|
|
84
|
+
path: string;
|
|
85
|
+
/** Erster Seitenaufruf der geöffneten Seite: nur dann zählen `utm` und `referrerHost`. */
|
|
86
|
+
landing?: boolean;
|
|
87
|
+
referrerHost?: string | null;
|
|
88
|
+
utm?: Pick<Touch, 'source' | 'medium' | 'campaign' | 'term' | 'content'> | null;
|
|
89
|
+
/** Nur mit Einwilligung (siehe `ATTRIBUTION_CONSENT.visitorId`). */
|
|
90
|
+
visitorId?: string | null;
|
|
91
|
+
consent?: {
|
|
92
|
+
statistics: boolean;
|
|
93
|
+
marketing: boolean;
|
|
94
|
+
at: string | null;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Ort-Art eines Termins. Adresse, Telefonnummer oder Link nennt erst die Bestätigung. */
|
|
98
|
+
export type BookingLocationType = 'google_meet' | 'in_person' | 'phone' | 'link';
|
|
99
|
+
/** Eine Buchungsfrage der Terminart. Antworten gehen unter `answers[key]` mit. */
|
|
100
|
+
export interface BookingQuestion {
|
|
101
|
+
key: string;
|
|
102
|
+
label: string;
|
|
103
|
+
/** `text`, `textarea`, `number`, `boolean`, `select`, `multiselect`, `date`, `email`, `phone`; Unbekanntes wie `text`. */
|
|
104
|
+
type: string;
|
|
105
|
+
required: boolean;
|
|
106
|
+
options: string[] | null;
|
|
107
|
+
placeholder: string | null;
|
|
108
|
+
}
|
|
109
|
+
/** Antwort von `GET …/booking/{bookingKey}`. */
|
|
110
|
+
export interface BookingInfo {
|
|
111
|
+
key: string;
|
|
112
|
+
/** Bezeichnung aus dem Code, sonst der Name der Terminart. */
|
|
113
|
+
label: string;
|
|
114
|
+
/** Name der Terminart im CRM. */
|
|
115
|
+
title: string;
|
|
116
|
+
description: string | null;
|
|
117
|
+
durationMinutes: number;
|
|
118
|
+
/** IANA-Zeitzone des Kalenders, z. B. `Europe/Berlin`. */
|
|
119
|
+
timezone: string;
|
|
120
|
+
locations: {
|
|
121
|
+
type: BookingLocationType;
|
|
122
|
+
label: string;
|
|
123
|
+
}[];
|
|
124
|
+
questions: BookingQuestion[];
|
|
125
|
+
}
|
|
126
|
+
/** Ein freier Termin, Zeiten in UTC (`…Z`). */
|
|
127
|
+
export interface BookingSlot {
|
|
128
|
+
start: string;
|
|
129
|
+
end: string;
|
|
130
|
+
}
|
|
131
|
+
/** Antwort von `GET …/booking/{bookingKey}/slots`. */
|
|
132
|
+
export interface BookingSlots {
|
|
133
|
+
/** IANA-Zeitzone des Kalenders. */
|
|
134
|
+
timezone: string;
|
|
135
|
+
from: string;
|
|
136
|
+
to: string;
|
|
137
|
+
slots: BookingSlot[];
|
|
138
|
+
}
|
|
139
|
+
/** Body von `POST …/booking/{bookingKey}/bookings`. */
|
|
140
|
+
export interface BookingRequest {
|
|
141
|
+
/** UUID je Buchungsvorgang. Dieselbe ID wird innerhalb von 24 h nur einmal gebucht. */
|
|
142
|
+
submissionId: string;
|
|
143
|
+
/** Beginn, genau `start` aus `…/slots`. */
|
|
144
|
+
start: string;
|
|
145
|
+
/** IANA-Zeitzone des Besuchers, für die Zeiten in der Bestätigung. */
|
|
146
|
+
tz: string;
|
|
147
|
+
attendee: {
|
|
148
|
+
firstName: string;
|
|
149
|
+
lastName?: string;
|
|
150
|
+
email: string;
|
|
151
|
+
phone?: string;
|
|
152
|
+
};
|
|
153
|
+
answers?: Record<string, string | number | boolean | string[]>;
|
|
154
|
+
locationType?: BookingLocationType;
|
|
155
|
+
attribution?: LeadAttributionV2 | LeadAttributionV1;
|
|
156
|
+
captcha: string;
|
|
157
|
+
website?: string;
|
|
158
|
+
}
|
|
159
|
+
/** Antwort von `POST …/booking/{bookingKey}/bookings`. */
|
|
160
|
+
export interface BookingConfirmed {
|
|
161
|
+
booked: true;
|
|
162
|
+
/** Vorschau: geprüft, nichts gebucht, keine Mail. */
|
|
163
|
+
dryRun: boolean;
|
|
164
|
+
/** Dieselbe `submissionId` war schon gebucht (z. B. doppelt abgeschickt). */
|
|
165
|
+
duplicate: boolean;
|
|
166
|
+
start: string | null;
|
|
167
|
+
end: string | null;
|
|
168
|
+
}
|
|
169
|
+
export interface CollectionPage {
|
|
170
|
+
entries: RawCollectionEntry[];
|
|
171
|
+
/** Gesamtzahl laut Server, `null` wenn nicht genannt. */
|
|
172
|
+
total: number | null;
|
|
173
|
+
}
|
|
174
|
+
export interface SiteApiOptions {
|
|
175
|
+
/** Basis-URL des Core, z. B. `https://app.dealsystem.io`. Leer = gleiche Adresse (Entwicklung). */
|
|
176
|
+
baseUrl: string;
|
|
177
|
+
siteKey: string;
|
|
178
|
+
fetch?: typeof fetch;
|
|
179
|
+
timeoutMs?: number;
|
|
180
|
+
}
|
|
181
|
+
/** @internal */
|
|
182
|
+
export interface SiteApi {
|
|
183
|
+
submitLead(request: LeadRequest): Promise<SiteApiResult<LeadAccepted>>;
|
|
184
|
+
/** Seitenaufruf melden. Fehler sind egal: Gezählt wird, was ankommt. */
|
|
185
|
+
track(request: PageviewRequest): Promise<SiteApiResult<{
|
|
186
|
+
accepted: true;
|
|
187
|
+
dryRun: boolean;
|
|
188
|
+
}>>;
|
|
189
|
+
getCollection(key: string, query?: {
|
|
190
|
+
limit?: number;
|
|
191
|
+
offset?: number;
|
|
192
|
+
sort?: 'newest' | 'oldest';
|
|
193
|
+
}): Promise<SiteApiResult<CollectionPage>>;
|
|
194
|
+
getEntry(key: string, slug: string): Promise<SiteApiResult<RawCollectionEntry>>;
|
|
195
|
+
getBooking(bookingKey: string): Promise<SiteApiResult<BookingInfo>>;
|
|
196
|
+
/** Freie Zeiten zwischen `from` und `to` (ISO, höchstens 31 Tage). */
|
|
197
|
+
getBookingSlots(bookingKey: string, range: {
|
|
198
|
+
from: string;
|
|
199
|
+
to: string;
|
|
200
|
+
}): Promise<SiteApiResult<BookingSlots>>;
|
|
201
|
+
createBooking(bookingKey: string, request: BookingRequest): Promise<SiteApiResult<BookingConfirmed>>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Baut einen Client für die Site-API.
|
|
205
|
+
* @internal Seiten nutzen `<LeadForm>`, `loadCollection()` und `loadEntry()`.
|
|
206
|
+
*/
|
|
207
|
+
export declare function createSiteApi(options: SiteApiOptions): SiteApi;
|
|
208
|
+
/** @internal Adresse, von der das Formular seine Captcha-Aufgabe holt. */
|
|
209
|
+
export declare function captchaChallengeUrl(): string;
|
|
210
|
+
/** @internal Client mit den Zugangsdaten der Seite aus dem Build. */
|
|
211
|
+
export declare function siteApi(): SiteApi;
|