@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.
- 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/erster-entwurf/SKILL.md +54 -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 +38 -0
- package/agent-files/cursor/rules/dealsystem.mdc +7 -0
- package/agent-files/manifest.json +101 -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 +191 -0
- package/docs/agents-block.md +101 -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,320 @@
|
|
|
1
|
+
// Client für die öffentliche Site-API (`/api/site/v1/s/{publishableKey}/…`).
|
|
2
|
+
// Grundsatz: Fehler kommen als Daten zurück. Keine Funktion hier wirft, auch
|
|
3
|
+
// nicht bei Netzfehlern oder kaputten Antworten.
|
|
4
|
+
import { getSiteData } from '../internal/siteData.js';
|
|
5
|
+
import { normalizeEntry } from '../snapshot.js';
|
|
6
|
+
const LOCATION_TYPES = ['google_meet', 'in_person', 'phone', 'link'];
|
|
7
|
+
function str(value) {
|
|
8
|
+
return typeof value === 'string' ? value : null;
|
|
9
|
+
}
|
|
10
|
+
/** Liest die Terminart defensiv: Unbekanntes fällt weg, nie eine Ausnahme. */
|
|
11
|
+
function normalizeBookingInfo(raw) {
|
|
12
|
+
if (!isRecord(raw))
|
|
13
|
+
return null;
|
|
14
|
+
const key = str(raw.key);
|
|
15
|
+
const timezone = str(raw.timezone);
|
|
16
|
+
const duration = raw.durationMinutes;
|
|
17
|
+
if (!key || !timezone || typeof duration !== 'number' || !Number.isFinite(duration) || duration <= 0)
|
|
18
|
+
return null;
|
|
19
|
+
const locations = Array.isArray(raw.locations)
|
|
20
|
+
? raw.locations.flatMap((l) => isRecord(l) && LOCATION_TYPES.includes(l.type) && typeof l.label === 'string'
|
|
21
|
+
? [{ type: l.type, label: l.label }]
|
|
22
|
+
: [])
|
|
23
|
+
: [];
|
|
24
|
+
const questions = Array.isArray(raw.questions)
|
|
25
|
+
? raw.questions.flatMap((q) => {
|
|
26
|
+
if (!isRecord(q) || typeof q.key !== 'string' || typeof q.label !== 'string')
|
|
27
|
+
return [];
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
key: q.key,
|
|
31
|
+
label: q.label,
|
|
32
|
+
type: str(q.type) ?? 'text',
|
|
33
|
+
required: q.required === true,
|
|
34
|
+
options: Array.isArray(q.options)
|
|
35
|
+
? q.options.filter((o) => typeof o === 'string')
|
|
36
|
+
: null,
|
|
37
|
+
placeholder: str(q.placeholder),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
})
|
|
41
|
+
: [];
|
|
42
|
+
return {
|
|
43
|
+
key,
|
|
44
|
+
label: str(raw.label) ?? str(raw.title) ?? key,
|
|
45
|
+
title: str(raw.title) ?? key,
|
|
46
|
+
description: str(raw.description),
|
|
47
|
+
durationMinutes: duration,
|
|
48
|
+
timezone,
|
|
49
|
+
locations,
|
|
50
|
+
questions,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function isInstant(value) {
|
|
54
|
+
return typeof value === 'string' && !Number.isNaN(Date.parse(value));
|
|
55
|
+
}
|
|
56
|
+
const MESSAGES = {
|
|
57
|
+
network: 'Die Verbindung ist fehlgeschlagen. Bitte prüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.',
|
|
58
|
+
rate_limited: 'Im Moment gehen zu viele Anfragen ein. Bitte versuchen Sie es in ein paar Minuten erneut.',
|
|
59
|
+
validation: 'Bitte prüfen Sie Ihre Angaben.',
|
|
60
|
+
captcha_failed: 'Die Sicherheitsprüfung ist fehlgeschlagen. Bitte versuchen Sie es erneut.',
|
|
61
|
+
rejected: 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.',
|
|
62
|
+
not_found: 'Der angefragte Inhalt ist nicht verfügbar.',
|
|
63
|
+
conflict: 'Diese Zeit ist leider nicht mehr frei. Bitte wählen Sie eine andere.',
|
|
64
|
+
gone: 'Dieser Termin hat bereits begonnen oder ist vorbei.',
|
|
65
|
+
forbidden: 'Die Anfrage wurde abgelehnt.',
|
|
66
|
+
server: 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.',
|
|
67
|
+
invalid_response: 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.',
|
|
68
|
+
};
|
|
69
|
+
function isRecord(value) {
|
|
70
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
71
|
+
}
|
|
72
|
+
function fail(kind, status, extra = {}) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: {
|
|
76
|
+
kind,
|
|
77
|
+
status,
|
|
78
|
+
code: extra.code ?? null,
|
|
79
|
+
message: MESSAGES[kind],
|
|
80
|
+
retryAfterSeconds: extra.retryAfterSeconds ?? null,
|
|
81
|
+
invalidFields: extra.invalidFields ?? [],
|
|
82
|
+
formInvalid: extra.formInvalid ?? false,
|
|
83
|
+
invalidPaths: extra.invalidPaths ?? [],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function kindOf(status, code) {
|
|
88
|
+
if (code === 'captcha_failed')
|
|
89
|
+
return 'captcha_failed';
|
|
90
|
+
if (status === 429)
|
|
91
|
+
return 'rate_limited';
|
|
92
|
+
if (status === 404)
|
|
93
|
+
return 'not_found';
|
|
94
|
+
if (status === 409)
|
|
95
|
+
return 'conflict';
|
|
96
|
+
if (status === 410)
|
|
97
|
+
return 'gone';
|
|
98
|
+
if (status === 403)
|
|
99
|
+
return 'forbidden';
|
|
100
|
+
if (status === 422)
|
|
101
|
+
return 'validation';
|
|
102
|
+
if (status >= 500)
|
|
103
|
+
return 'server';
|
|
104
|
+
return 'rejected';
|
|
105
|
+
}
|
|
106
|
+
/** Liest `details: [{ path, message }]` eines `validation_error`. Texte des Servers werden nicht übernommen. */
|
|
107
|
+
function validationDetails(body) {
|
|
108
|
+
const invalidFields = [];
|
|
109
|
+
const invalidPaths = [];
|
|
110
|
+
let formInvalid = false;
|
|
111
|
+
if (Array.isArray(body.details)) {
|
|
112
|
+
for (const detail of body.details) {
|
|
113
|
+
const path = isRecord(detail) ? detail.path : null;
|
|
114
|
+
if (typeof path !== 'string')
|
|
115
|
+
continue;
|
|
116
|
+
if (!invalidPaths.includes(path) && invalidPaths.length < 100)
|
|
117
|
+
invalidPaths.push(path.slice(0, 200));
|
|
118
|
+
if (path === 'data')
|
|
119
|
+
formInvalid = true;
|
|
120
|
+
else if (path.startsWith('data.')) {
|
|
121
|
+
// `data.themen.0` gehört zum Feld `themen`.
|
|
122
|
+
const name = path.slice('data.'.length).split('.')[0];
|
|
123
|
+
if (name && !invalidFields.includes(name))
|
|
124
|
+
invalidFields.push(name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { invalidFields, formInvalid, invalidPaths };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Baut einen Client für die Site-API.
|
|
132
|
+
* @internal Seiten nutzen `<LeadForm>`, `loadCollection()` und `loadEntry()`.
|
|
133
|
+
*/
|
|
134
|
+
export function createSiteApi(options) {
|
|
135
|
+
const base = `${options.baseUrl.replace(/\/+$/, '')}/api/site/v1/s/${encodeURIComponent(options.siteKey)}`;
|
|
136
|
+
const timeoutMs = options.timeoutMs ?? 15_000;
|
|
137
|
+
async function request(path, init) {
|
|
138
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
139
|
+
const controller = new AbortController();
|
|
140
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
141
|
+
let response;
|
|
142
|
+
let body;
|
|
143
|
+
try {
|
|
144
|
+
response = await doFetch(base + path, {
|
|
145
|
+
...init,
|
|
146
|
+
credentials: 'omit',
|
|
147
|
+
signal: controller.signal,
|
|
148
|
+
});
|
|
149
|
+
const text = await response.text();
|
|
150
|
+
try {
|
|
151
|
+
body = text ? JSON.parse(text) : null;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
body = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return fail('network', null);
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
const record = isRecord(body) ? body : {};
|
|
165
|
+
const code = typeof record.code === 'string' ? record.code : null;
|
|
166
|
+
const retryAfter = Number.parseInt(response.headers.get('Retry-After') ?? '', 10);
|
|
167
|
+
return fail(kindOf(response.status, code), response.status, {
|
|
168
|
+
code,
|
|
169
|
+
retryAfterSeconds: Number.isFinite(retryAfter) && retryAfter >= 0 ? retryAfter : null,
|
|
170
|
+
...validationDetails(record),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (!isRecord(body))
|
|
174
|
+
return fail('invalid_response', response.status);
|
|
175
|
+
return { ok: true, data: body };
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
async submitLead(lead) {
|
|
179
|
+
const send = () => request('/leads', {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: { 'Content-Type': 'application/json' },
|
|
182
|
+
body: JSON.stringify(lead),
|
|
183
|
+
});
|
|
184
|
+
let result = await send();
|
|
185
|
+
// `internal_error` darf mit derselben submissionId wiederholt werden: einmal, automatisch.
|
|
186
|
+
if (!result.ok && result.error.status === 500 && result.error.code === 'internal_error') {
|
|
187
|
+
result = await send();
|
|
188
|
+
}
|
|
189
|
+
if (!result.ok)
|
|
190
|
+
return result;
|
|
191
|
+
const data = result.data.data;
|
|
192
|
+
// Nie ein Erfolg ohne ausdrückliches `accepted: true`.
|
|
193
|
+
if (!isRecord(data) || data.accepted !== true)
|
|
194
|
+
return fail('invalid_response', 200);
|
|
195
|
+
return { ok: true, data: { accepted: true, dryRun: data.dryRun === true } };
|
|
196
|
+
},
|
|
197
|
+
async track(pageview) {
|
|
198
|
+
const result = await request('/track', {
|
|
199
|
+
method: 'POST',
|
|
200
|
+
headers: { 'Content-Type': 'application/json' },
|
|
201
|
+
body: JSON.stringify(pageview),
|
|
202
|
+
// Auch beim Verlassen der Seite noch zustellen.
|
|
203
|
+
keepalive: true,
|
|
204
|
+
});
|
|
205
|
+
if (!result.ok)
|
|
206
|
+
return result;
|
|
207
|
+
const data = result.data.data;
|
|
208
|
+
if (!isRecord(data) || data.accepted !== true)
|
|
209
|
+
return fail('invalid_response', 200);
|
|
210
|
+
return { ok: true, data: { accepted: true, dryRun: data.dryRun === true } };
|
|
211
|
+
},
|
|
212
|
+
async getCollection(key, query = {}) {
|
|
213
|
+
const params = new URLSearchParams();
|
|
214
|
+
// Der Server liefert ohne Angabe 20 Einträge und höchstens 100 je Abruf.
|
|
215
|
+
if (query.limit !== undefined) {
|
|
216
|
+
params.set('limit', String(Math.min(100, Math.max(1, Math.floor(query.limit)))));
|
|
217
|
+
}
|
|
218
|
+
if (query.offset)
|
|
219
|
+
params.set('offset', String(Math.min(10_000, Math.max(0, Math.floor(query.offset)))));
|
|
220
|
+
if (query.sort)
|
|
221
|
+
params.set('sort', query.sort === 'oldest' ? 'publishedAt' : '-publishedAt');
|
|
222
|
+
const search = params.toString();
|
|
223
|
+
const result = await request(`/collections/${encodeURIComponent(key)}${search ? `?${search}` : ''}`, {
|
|
224
|
+
method: 'GET',
|
|
225
|
+
});
|
|
226
|
+
if (!result.ok)
|
|
227
|
+
return result;
|
|
228
|
+
if (!Array.isArray(result.data.data))
|
|
229
|
+
return fail('invalid_response', 200);
|
|
230
|
+
const meta = isRecord(result.data.meta) ? result.data.meta : {};
|
|
231
|
+
return {
|
|
232
|
+
ok: true,
|
|
233
|
+
data: {
|
|
234
|
+
entries: result.data.data.map(normalizeEntry).filter((e) => e !== null),
|
|
235
|
+
total: typeof meta.total === 'number' ? meta.total : null,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
async getBooking(bookingKey) {
|
|
240
|
+
const result = await request(`/booking/${encodeURIComponent(bookingKey)}`, { method: 'GET' });
|
|
241
|
+
if (!result.ok)
|
|
242
|
+
return result;
|
|
243
|
+
const info = normalizeBookingInfo(result.data.data);
|
|
244
|
+
return info ? { ok: true, data: info } : fail('invalid_response', 200);
|
|
245
|
+
},
|
|
246
|
+
async getBookingSlots(bookingKey, range) {
|
|
247
|
+
const params = new URLSearchParams({ from: range.from, to: range.to });
|
|
248
|
+
const result = await request(`/booking/${encodeURIComponent(bookingKey)}/slots?${params}`, {
|
|
249
|
+
method: 'GET',
|
|
250
|
+
});
|
|
251
|
+
if (!result.ok)
|
|
252
|
+
return result;
|
|
253
|
+
const data = result.data.data;
|
|
254
|
+
if (!isRecord(data) || typeof data.timezone !== 'string' || !Array.isArray(data.slots)) {
|
|
255
|
+
return fail('invalid_response', 200);
|
|
256
|
+
}
|
|
257
|
+
const slots = data.slots
|
|
258
|
+
.flatMap((slot) => isRecord(slot) && isInstant(slot.start) && isInstant(slot.end)
|
|
259
|
+
? [{ start: slot.start, end: slot.end }]
|
|
260
|
+
: [])
|
|
261
|
+
.sort((a, b) => Date.parse(a.start) - Date.parse(b.start));
|
|
262
|
+
return {
|
|
263
|
+
ok: true,
|
|
264
|
+
data: {
|
|
265
|
+
timezone: data.timezone,
|
|
266
|
+
from: str(data.from) ?? range.from,
|
|
267
|
+
to: str(data.to) ?? range.to,
|
|
268
|
+
slots,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
async createBooking(bookingKey, booking) {
|
|
273
|
+
const send = () => request(`/booking/${encodeURIComponent(bookingKey)}/bookings`, {
|
|
274
|
+
method: 'POST',
|
|
275
|
+
headers: { 'Content-Type': 'application/json' },
|
|
276
|
+
body: JSON.stringify(booking),
|
|
277
|
+
});
|
|
278
|
+
let result = await send();
|
|
279
|
+
// Wie bei Leads: `internal_error` einmal mit derselben submissionId wiederholen (gebucht wird nur einmal).
|
|
280
|
+
if (!result.ok && result.error.status === 500 && result.error.code === 'internal_error') {
|
|
281
|
+
result = await send();
|
|
282
|
+
}
|
|
283
|
+
if (!result.ok)
|
|
284
|
+
return result;
|
|
285
|
+
const data = result.data.data;
|
|
286
|
+
// Nie ein Erfolg ohne ausdrückliches `booked: true`.
|
|
287
|
+
if (!isRecord(data) || data.booked !== true)
|
|
288
|
+
return fail('invalid_response', 200);
|
|
289
|
+
return {
|
|
290
|
+
ok: true,
|
|
291
|
+
data: {
|
|
292
|
+
booked: true,
|
|
293
|
+
dryRun: data.dryRun === true,
|
|
294
|
+
duplicate: data.duplicate === true,
|
|
295
|
+
start: isInstant(data.start) ? data.start : null,
|
|
296
|
+
end: isInstant(data.end) ? data.end : null,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
async getEntry(key, slug) {
|
|
301
|
+
const result = await request(`/collections/${encodeURIComponent(key)}/${encodeURIComponent(slug)}`, {
|
|
302
|
+
method: 'GET',
|
|
303
|
+
});
|
|
304
|
+
if (!result.ok)
|
|
305
|
+
return result;
|
|
306
|
+
const entry = normalizeEntry(result.data.data);
|
|
307
|
+
return entry ? { ok: true, data: entry } : fail('invalid_response', 200);
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/** @internal Adresse, von der das Formular seine Captcha-Aufgabe holt. */
|
|
312
|
+
export function captchaChallengeUrl() {
|
|
313
|
+
const { api } = getSiteData();
|
|
314
|
+
return `${api.baseUrl.replace(/\/+$/, '')}/api/site/v1/s/${encodeURIComponent(api.siteKey)}/captcha`;
|
|
315
|
+
}
|
|
316
|
+
/** @internal Client mit den Zugangsdaten der Seite aus dem Build. */
|
|
317
|
+
export function siteApi() {
|
|
318
|
+
const { api } = getSiteData();
|
|
319
|
+
return createSiteApi({ baseUrl: api.baseUrl, siteKey: api.siteKey });
|
|
320
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TrackingConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bindet die im CRM eingetragenen Tracking-IDs ein. Je ID höchstens einmal.
|
|
4
|
+
* Gibt die geladenen Skript-Adressen zurück.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadTracking(config: TrackingConfig): string[];
|
|
8
|
+
/** Ereignis-ID einer Anfrage, gleich bei Pixel, gtag und der serverseitigen Conversion (Core: `lead-<submissionId>`). */
|
|
9
|
+
export declare function leadEventId(submissionId: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Meldet eine angenommene Anfrage an Meta Pixel (`Lead`) und Google Tag (`generate_lead`), mit derselben
|
|
12
|
+
* Ereignis-ID wie die serverseitige Conversion. So zählen Meta und Google sie einmal. Nur, wenn die Tags
|
|
13
|
+
* geladen sind, also nach der Einwilligung „Marketing“. Gibt zurück, wohin gemeldet wurde.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function reportLeadConversion(submissionId: string): string[];
|
|
17
|
+
/** @internal Nur für Tests. */
|
|
18
|
+
export declare function resetTrackingForTests(): void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const GOOGLE_TAG = /^(G|GT|AW)-[A-Z0-9-]{4,30}$/;
|
|
2
|
+
const META_PIXEL = /^\d{5,20}$/;
|
|
3
|
+
const loaded = new Set();
|
|
4
|
+
function addScript(src) {
|
|
5
|
+
const script = document.createElement('script');
|
|
6
|
+
script.async = true;
|
|
7
|
+
script.src = src;
|
|
8
|
+
document.head.append(script);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Bindet die im CRM eingetragenen Tracking-IDs ein. Je ID höchstens einmal.
|
|
12
|
+
* Gibt die geladenen Skript-Adressen zurück.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function loadTracking(config) {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return [];
|
|
18
|
+
const w = window;
|
|
19
|
+
const added = [];
|
|
20
|
+
const googleTagId = config.googleTagId?.trim().toUpperCase();
|
|
21
|
+
if (googleTagId && GOOGLE_TAG.test(googleTagId) && !loaded.has(googleTagId)) {
|
|
22
|
+
loaded.add(googleTagId);
|
|
23
|
+
const dataLayer = (w.dataLayer ??= []);
|
|
24
|
+
// gtag erwartet das `arguments`-Objekt, kein Array.
|
|
25
|
+
const gtag = function () {
|
|
26
|
+
// eslint-disable-next-line prefer-rest-params
|
|
27
|
+
dataLayer.push(arguments);
|
|
28
|
+
};
|
|
29
|
+
w.gtag ??= gtag;
|
|
30
|
+
gtag('js', new Date());
|
|
31
|
+
gtag('config', googleTagId);
|
|
32
|
+
const src = `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(googleTagId)}`;
|
|
33
|
+
addScript(src);
|
|
34
|
+
added.push(src);
|
|
35
|
+
}
|
|
36
|
+
const metaPixelId = config.metaPixelId?.trim();
|
|
37
|
+
if (metaPixelId && META_PIXEL.test(metaPixelId) && !loaded.has(metaPixelId)) {
|
|
38
|
+
loaded.add(metaPixelId);
|
|
39
|
+
if (!w.fbq) {
|
|
40
|
+
const fbq = function (...args) {
|
|
41
|
+
if (typeof fbq.callMethod === 'function') {
|
|
42
|
+
fbq.callMethod(...args);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
fbq.queue.push(args);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
fbq.push = fbq;
|
|
49
|
+
fbq.loaded = true;
|
|
50
|
+
fbq.version = '2.0';
|
|
51
|
+
fbq.queue = [];
|
|
52
|
+
w.fbq = fbq;
|
|
53
|
+
w._fbq ??= fbq;
|
|
54
|
+
const src = 'https://connect.facebook.net/en_US/fbevents.js';
|
|
55
|
+
addScript(src);
|
|
56
|
+
added.push(src);
|
|
57
|
+
}
|
|
58
|
+
const fbq = w.fbq;
|
|
59
|
+
fbq('init', metaPixelId);
|
|
60
|
+
fbq('track', 'PageView');
|
|
61
|
+
}
|
|
62
|
+
return added;
|
|
63
|
+
}
|
|
64
|
+
/** Ereignis-ID einer Anfrage, gleich bei Pixel, gtag und der serverseitigen Conversion (Core: `lead-<submissionId>`). */
|
|
65
|
+
export function leadEventId(submissionId) {
|
|
66
|
+
return `lead-${submissionId}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Meldet eine angenommene Anfrage an Meta Pixel (`Lead`) und Google Tag (`generate_lead`), mit derselben
|
|
70
|
+
* Ereignis-ID wie die serverseitige Conversion. So zählen Meta und Google sie einmal. Nur, wenn die Tags
|
|
71
|
+
* geladen sind, also nach der Einwilligung „Marketing“. Gibt zurück, wohin gemeldet wurde.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export function reportLeadConversion(submissionId) {
|
|
75
|
+
if (typeof window === 'undefined' || loaded.size === 0)
|
|
76
|
+
return [];
|
|
77
|
+
const w = window;
|
|
78
|
+
const eventID = leadEventId(submissionId);
|
|
79
|
+
const sent = [];
|
|
80
|
+
if (typeof w.fbq === 'function') {
|
|
81
|
+
w.fbq('track', 'Lead', {}, { eventID });
|
|
82
|
+
sent.push('meta');
|
|
83
|
+
}
|
|
84
|
+
if (typeof w.gtag === 'function') {
|
|
85
|
+
w.gtag('event', 'generate_lead', { transaction_id: eventID });
|
|
86
|
+
sent.push('google');
|
|
87
|
+
}
|
|
88
|
+
return sent;
|
|
89
|
+
}
|
|
90
|
+
/** @internal Nur für Tests. */
|
|
91
|
+
export function resetTrackingForTests() {
|
|
92
|
+
loaded.clear();
|
|
93
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FunnelFieldDef } from '../types.js';
|
|
2
|
+
export type FieldValue = string | boolean | string[];
|
|
3
|
+
/** Höchstlänge eines Feldes, wenn die Konfiguration keine nennt. */
|
|
4
|
+
export declare function maxLengthOf(field: FunnelFieldDef): number;
|
|
5
|
+
/** Sichtbare Beschriftung eines Feldes. */
|
|
6
|
+
export declare function labelOf(field: FunnelFieldDef): string;
|
|
7
|
+
/** Meldung zu einem Feld oder `null`, wenn der Wert passt. */
|
|
8
|
+
export declare function validateField(field: FunnelFieldDef, value: FieldValue | undefined): string | null;
|
|
9
|
+
/** Werte für den Versand: getrimmt, leere Felder ausgelassen. */
|
|
10
|
+
export declare function toLeadData(fields: readonly FunnelFieldDef[], values: Record<string, FieldValue | undefined>): Record<string, string | string[] | boolean>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
|
|
2
|
+
const PHONE = /^[+0-9][0-9 ()/.-]{4,29}$/;
|
|
3
|
+
/** Höchstlänge eines Feldes, wenn die Konfiguration keine nennt. */
|
|
4
|
+
export function maxLengthOf(field) {
|
|
5
|
+
// Die Site-API nimmt je Feld höchstens 10 000 Zeichen an.
|
|
6
|
+
return Math.min(field.maxLength ?? (field.type === 'textarea' ? 5000 : 255), 10_000);
|
|
7
|
+
}
|
|
8
|
+
/** Sichtbare Beschriftung eines Feldes. */
|
|
9
|
+
export function labelOf(field) {
|
|
10
|
+
return field.label ?? field.name.charAt(0).toUpperCase() + field.name.slice(1);
|
|
11
|
+
}
|
|
12
|
+
/** Meldung zu einem Feld oder `null`, wenn der Wert passt. */
|
|
13
|
+
export function validateField(field, value) {
|
|
14
|
+
const label = labelOf(field);
|
|
15
|
+
const empty = value === undefined ||
|
|
16
|
+
value === false ||
|
|
17
|
+
(typeof value === 'string' && value.trim() === '') ||
|
|
18
|
+
(Array.isArray(value) && value.length === 0);
|
|
19
|
+
if (empty) {
|
|
20
|
+
if (!field.required)
|
|
21
|
+
return null;
|
|
22
|
+
if (field.type === 'checkbox')
|
|
23
|
+
return `Bitte bestätigen Sie „${label}“.`;
|
|
24
|
+
if (field.type === 'select' || field.type === 'multiselect')
|
|
25
|
+
return `Bitte wählen Sie bei „${label}“ etwas aus.`;
|
|
26
|
+
return `Bitte füllen Sie das Feld „${label}“ aus.`;
|
|
27
|
+
}
|
|
28
|
+
if (typeof value !== 'string')
|
|
29
|
+
return null;
|
|
30
|
+
const text = value.trim();
|
|
31
|
+
if (text.length > maxLengthOf(field)) {
|
|
32
|
+
return `„${label}“ ist zu lang. Erlaubt sind höchstens ${maxLengthOf(field)} Zeichen.`;
|
|
33
|
+
}
|
|
34
|
+
if (field.type === 'email' && !EMAIL.test(text)) {
|
|
35
|
+
return 'Bitte geben Sie eine gültige E-Mail-Adresse ein, z. B. name@beispiel.de.';
|
|
36
|
+
}
|
|
37
|
+
if (field.type === 'tel' && !PHONE.test(text)) {
|
|
38
|
+
return 'Bitte geben Sie eine gültige Telefonnummer ein, z. B. 0341 1234567.';
|
|
39
|
+
}
|
|
40
|
+
if (field.type === 'date' && !/^\d{4}-\d{2}-\d{2}$/.test(text)) {
|
|
41
|
+
return `Bitte geben Sie bei „${label}“ ein Datum an.`;
|
|
42
|
+
}
|
|
43
|
+
if (field.type === 'select' && field.options && !field.options.includes(text)) {
|
|
44
|
+
return `Bitte wählen Sie bei „${label}“ etwas aus.`;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Werte für den Versand: getrimmt, leere Felder ausgelassen. */
|
|
49
|
+
export function toLeadData(fields, values) {
|
|
50
|
+
const data = {};
|
|
51
|
+
for (const field of fields) {
|
|
52
|
+
const value = values[field.name];
|
|
53
|
+
if (typeof value === 'string') {
|
|
54
|
+
if (value.trim() !== '')
|
|
55
|
+
data[field.name] = value.trim();
|
|
56
|
+
}
|
|
57
|
+
else if (Array.isArray(value)) {
|
|
58
|
+
if (value.length > 0)
|
|
59
|
+
data[field.name] = [...value];
|
|
60
|
+
}
|
|
61
|
+
else if (value === true) {
|
|
62
|
+
data[field.name] = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return data;
|
|
66
|
+
}
|