dealsystem 0.0.1 → 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.
Files changed (104) hide show
  1. package/README.md +64 -2
  2. package/dist/api/errors.d.ts +25 -0
  3. package/dist/api/errors.js +38 -0
  4. package/dist/api/http.d.ts +56 -0
  5. package/dist/api/http.js +406 -0
  6. package/dist/api/legal.d.ts +9 -0
  7. package/dist/api/legal.js +20 -0
  8. package/dist/api/oauth.d.ts +35 -0
  9. package/dist/api/oauth.js +113 -0
  10. package/dist/api/types.d.ts +142 -0
  11. package/dist/api/types.js +9 -0
  12. package/dist/auth/credentials.d.ts +28 -0
  13. package/dist/auth/credentials.js +96 -0
  14. package/dist/auth/session.d.ts +10 -0
  15. package/dist/auth/session.js +46 -0
  16. package/dist/bin.d.ts +2 -0
  17. package/dist/bin.js +4 -0
  18. package/dist/check/allowlist.d.ts +9 -0
  19. package/dist/check/allowlist.js +74 -0
  20. package/dist/check/catalog.d.ts +6 -0
  21. package/dist/check/catalog.js +410 -0
  22. package/dist/check/context.d.ts +79 -0
  23. package/dist/check/context.js +230 -0
  24. package/dist/check/fileset.d.ts +19 -0
  25. package/dist/check/fileset.js +91 -0
  26. package/dist/check/format.d.ts +25 -0
  27. package/dist/check/format.js +79 -0
  28. package/dist/check/index.d.ts +8 -0
  29. package/dist/check/index.js +9 -0
  30. package/dist/check/rule.d.ts +15 -0
  31. package/dist/check/rule.js +6 -0
  32. package/dist/check/rules/a11y.d.ts +3 -0
  33. package/dist/check/rules/a11y.js +433 -0
  34. package/dist/check/rules/privacy.d.ts +9 -0
  35. package/dist/check/rules/privacy.js +437 -0
  36. package/dist/check/rules/quality.d.ts +11 -0
  37. package/dist/check/rules/quality.js +451 -0
  38. package/dist/check/rules/schedule.d.ts +2 -0
  39. package/dist/check/rules/schedule.js +30 -0
  40. package/dist/check/rules/security.d.ts +18 -0
  41. package/dist/check/rules/security.js +744 -0
  42. package/dist/check/rules/structure.d.ts +2 -0
  43. package/dist/check/rules/structure.js +399 -0
  44. package/dist/check/run.d.ts +15 -0
  45. package/dist/check/run.js +147 -0
  46. package/dist/check/sdk.d.ts +56 -0
  47. package/dist/check/sdk.js +58 -0
  48. package/dist/check/types.d.ts +116 -0
  49. package/dist/check/types.js +2 -0
  50. package/dist/check/util/code.d.ts +19 -0
  51. package/dist/check/util/code.js +113 -0
  52. package/dist/check/util/color.d.ts +10 -0
  53. package/dist/check/util/color.js +53 -0
  54. package/dist/check/util/csp.d.ts +71 -0
  55. package/dist/check/util/csp.js +229 -0
  56. package/dist/check/util/html.d.ts +31 -0
  57. package/dist/check/util/html.js +65 -0
  58. package/dist/check/util/lines.d.ts +1 -0
  59. package/dist/check/util/lines.js +2 -0
  60. package/dist/check/util/literal.d.ts +1 -0
  61. package/dist/check/util/literal.js +3 -0
  62. package/dist/check/util/svelte.d.ts +42 -0
  63. package/dist/check/util/svelte.js +109 -0
  64. package/dist/cli/context.d.ts +40 -0
  65. package/dist/cli/context.js +107 -0
  66. package/dist/cli/io.d.ts +26 -0
  67. package/dist/cli/io.js +68 -0
  68. package/dist/cli/main.d.ts +24 -0
  69. package/dist/cli/main.js +269 -0
  70. package/dist/commands/check.d.ts +4 -0
  71. package/dist/commands/check.js +54 -0
  72. package/dist/commands/deploy.d.ts +20 -0
  73. package/dist/commands/deploy.js +315 -0
  74. package/dist/commands/dev.d.ts +29 -0
  75. package/dist/commands/dev.js +149 -0
  76. package/dist/commands/image.d.ts +12 -0
  77. package/dist/commands/image.js +291 -0
  78. package/dist/commands/login.d.ts +3 -0
  79. package/dist/commands/login.js +116 -0
  80. package/dist/commands/pull.d.ts +12 -0
  81. package/dist/commands/pull.js +178 -0
  82. package/dist/commands/site.d.ts +9 -0
  83. package/dist/commands/site.js +84 -0
  84. package/dist/commands/sync.d.ts +2 -0
  85. package/dist/commands/sync.js +126 -0
  86. package/dist/index.d.ts +10 -0
  87. package/dist/index.js +10 -0
  88. package/dist/project/agentFiles.d.ts +17 -0
  89. package/dist/project/agentFiles.js +156 -0
  90. package/dist/project/agentsBlock.d.ts +2 -0
  91. package/dist/project/agentsBlock.js +14 -0
  92. package/dist/project/siteConfig.d.ts +5 -0
  93. package/dist/project/siteConfig.js +35 -0
  94. package/dist/project/snapshot.d.ts +21 -0
  95. package/dist/project/snapshot.js +125 -0
  96. package/dist/project/svelteConfig.d.ts +4 -0
  97. package/dist/project/svelteConfig.js +74 -0
  98. package/dist/project/tar.d.ts +8 -0
  99. package/dist/project/tar.js +89 -0
  100. package/dist/project/untar.d.ts +27 -0
  101. package/dist/project/untar.js +232 -0
  102. package/dist/project/uploadFiles.d.ts +17 -0
  103. package/dist/project/uploadFiles.js +55 -0
  104. package/package.json +63 -7
@@ -0,0 +1,451 @@
1
+ // QUA-*, CNT-*: Größe, Links, Pflichtdateien, Formular- und Slot-Schlüssel, Agenten-Anleitung, Content-Slots.
2
+ import { gzipSync } from 'node:zlib';
3
+ import { FUNNEL_MANIFEST_MAX_FIELDS } from '@dealsystem/site/config';
4
+ import { findPathLine, SITE_CONFIG_FILE } from '../../project/siteConfig.js';
5
+ import { mergeSlots, scanSlots, SlotScanError } from '@dealsystem/site/vite';
6
+ import { routeOfPage, routeOfSource } from '../context.js';
7
+ import { outputRule, sourceRule } from '../rule.js';
8
+ import { AGENTS_BLOCK_BEGIN, COMPONENT } from '../sdk.js';
9
+ import { excerpt, findAll } from '../util/code.js';
10
+ import { lineOf } from '../util/html.js';
11
+ import { getAttr } from '../util/svelte.js';
12
+ import { resolveHref } from './privacy.js';
13
+ export const OUTPUT_LIMITS = {
14
+ totalBytes: 200 * 1024 * 1024,
15
+ files: 10_000,
16
+ fileBytes: 25 * 1024 * 1024,
17
+ jsGzipBytesPerPage: 300 * 1024,
18
+ };
19
+ const MB = 1024 * 1024;
20
+ const mb = (n) => (n / MB).toFixed(1).replace('.', ',');
21
+ // ------------------------------------------------------------------ QUA-001
22
+ const qua001 = outputRule('QUA-001', (ctx) => {
23
+ const files = ctx.files.list();
24
+ const total = files.reduce((n, f) => n + f.size, 0);
25
+ const largest = [...files].sort((a, b) => b.size - a.size).slice(0, 5);
26
+ const top = largest.map((f) => `${f.path} (${mb(f.size)} MB)`).join(', ');
27
+ const out = [];
28
+ if (total > OUTPUT_LIMITS.totalBytes) {
29
+ out.push({
30
+ file: null,
31
+ message: `Die Seite ist zu groß (${mb(total)} MB, erlaubt 200 MB). Größte Dateien: ${top}.`,
32
+ });
33
+ }
34
+ if (files.length > OUTPUT_LIMITS.files) {
35
+ out.push({
36
+ file: null,
37
+ message: `Die Seite hat zu viele Dateien (${files.length}, erlaubt 10 000).`,
38
+ fix: 'Fasse Dateien zusammen oder entferne ungenutzte Dateien aus `static/`.',
39
+ });
40
+ }
41
+ for (const f of files.filter((x) => x.size > OUTPUT_LIMITS.fileBytes)) {
42
+ out.push({
43
+ file: f.path,
44
+ message: `\`${f.path}\` ist zu groß (${mb(f.size)} MB, erlaubt 25 MB je Datei).`,
45
+ });
46
+ }
47
+ return out;
48
+ });
49
+ // ------------------------------------------------------------------ QUA-002
50
+ function resolveAsset(ctx, ref, pageRoute) {
51
+ const path = resolveHref(ref, pageRoute);
52
+ if (!path)
53
+ return null;
54
+ const rel = path.replace(/^\/+/, '');
55
+ return ctx.files.has(rel) ? rel : null;
56
+ }
57
+ const IMPORT_CALL = /import\(\s*["']([^"']+\.js)["']\s*\)/g;
58
+ const qua002 = outputRule('QUA-002', (ctx) => {
59
+ const sizes = new Map();
60
+ const gz = (path) => {
61
+ let n = sizes.get(path);
62
+ if (n === undefined) {
63
+ const bytes = ctx.files.readBytes(path);
64
+ n = bytes ? gzipSync(bytes).byteLength : 0;
65
+ sizes.set(path, n);
66
+ }
67
+ return n;
68
+ };
69
+ const out = [];
70
+ for (const page of ctx.contentPages()) {
71
+ const doc = ctx.html(page);
72
+ const route = routeOfPage(page);
73
+ const scripts = new Set();
74
+ for (const el of doc.elements) {
75
+ const ref = el.tag === 'script'
76
+ ? el.attrs.src
77
+ : el.tag === 'link' && (el.attrs.rel ?? '').includes('modulepreload')
78
+ ? el.attrs.href
79
+ : undefined;
80
+ if (ref) {
81
+ const p = resolveAsset(ctx, ref, route);
82
+ if (p)
83
+ scripts.add(p);
84
+ }
85
+ if (el.tag === 'script' && !el.attrs.src) {
86
+ const inline = el.children.map((c) => ('text' in c ? c.text : '')).join('');
87
+ for (const m of inline.matchAll(IMPORT_CALL)) {
88
+ const p = resolveAsset(ctx, m[1] ?? '', route);
89
+ if (p)
90
+ scripts.add(p);
91
+ }
92
+ }
93
+ }
94
+ const total = [...scripts].reduce((n, p) => n + gz(p), 0);
95
+ if (total > OUTPUT_LIMITS.jsGzipBytesPerPage) {
96
+ out.push({
97
+ file: page,
98
+ message: `Die Seite \`${route}\` lädt ${Math.round(total / 1024)} KB JavaScript (gzip, empfohlen höchstens 300 KB).`,
99
+ });
100
+ }
101
+ }
102
+ return out;
103
+ });
104
+ // ------------------------------------------------------------------ QUA-003
105
+ /** Pfade, die der Edge selbst ausliefert (Medien aus dem CRM). */
106
+ const EDGE_PREFIXES = ['/_ds/'];
107
+ function targetExists(ctx, path) {
108
+ const rel = path.replace(/^\/+/, '').replace(/\/+$/, '');
109
+ if (rel === '')
110
+ return ctx.files.has('index.html');
111
+ return ctx.files.has(rel) || ctx.files.has(`${rel}.html`) || ctx.files.has(`${rel}/index.html`);
112
+ }
113
+ const qua003 = outputRule('QUA-003', (ctx) => {
114
+ const out = [];
115
+ if (!ctx.files.has('404.html')) {
116
+ out.push({
117
+ file: null,
118
+ message: '`404.html` fehlt in der gebauten Seite.',
119
+ fix: "Setze in svelte.config.js `adapter: adapter({ fallback: '404.html' })` wie im Starter.",
120
+ });
121
+ }
122
+ const siteHost = ctx.siteHost();
123
+ for (const page of ctx.pages()) {
124
+ const doc = ctx.html(page);
125
+ const route = routeOfPage(page);
126
+ const seen = new Set();
127
+ for (const el of doc.elements) {
128
+ if (el.tag !== 'a' || el.attrs.href === undefined)
129
+ continue;
130
+ let href = el.attrs.href.trim();
131
+ if (siteHost) {
132
+ const m = /^https?:\/\/([^/]+)(\/.*)?$/i.exec(href);
133
+ if (m && m[1]?.toLowerCase() === siteHost)
134
+ href = m[2] ?? '/';
135
+ }
136
+ const path = resolveHref(href.replace(/[?#].*$/, ''), route);
137
+ if (path === null || href.startsWith('#') || EDGE_PREFIXES.some((p) => path.startsWith(p)))
138
+ continue;
139
+ if (targetExists(ctx, path) || seen.has(path))
140
+ continue;
141
+ seen.add(path);
142
+ out.push({
143
+ file: page,
144
+ line: lineOf(doc, el),
145
+ message: `Der Link \`${excerpt(href, 100)}\` auf \`${route}\` führt ins Leere.`,
146
+ });
147
+ }
148
+ }
149
+ return out;
150
+ });
151
+ // ------------------------------------------------------------------ QUA-004
152
+ const qua004 = outputRule('QUA-004', (ctx) => ['sitemap.xml', 'robots.txt']
153
+ .filter((f) => !ctx.files.has(f))
154
+ .map((f) => ({ file: null, message: `\`${f}\` fehlt in der gebauten Seite.` })));
155
+ // ------------------------------------------------------------------ QUA-005
156
+ const configFindings = (ctx, kind) => ctx
157
+ .siteConfig()
158
+ .problems.filter((p) => p.kind === kind)
159
+ .map((p) => ({
160
+ file: 'dealsystem.config.ts',
161
+ line: p.line,
162
+ message: p.message,
163
+ ...(p.fix ? { fix: p.fix } : {}),
164
+ }));
165
+ const qua005 = sourceRule('QUA-005', (ctx) => configFindings(ctx, 'reachability'));
166
+ // ------------------------------------------------------------------ QUA-006
167
+ const COLLECTION_CALL = /\b(getCollection|getEntry|collectionEntries)\s*\(\s*(['"`])([^'"`]*)\2/g;
168
+ /** `[dealsystem] datei:12 Text` → `Text` */
169
+ function slotErrorText(error) {
170
+ return error.message.replace(/^\[dealsystem\]\s+\S+:\d+\s+/, '');
171
+ }
172
+ const qua006 = sourceRule('QUA-006', (ctx) => {
173
+ const config = ctx.siteConfig();
174
+ const out = configFindings(ctx, 'key');
175
+ const funnelKeys = config.data ? new Set(config.data.funnels.map((f) => f.key)) : null;
176
+ const collectionKeys = config.data ? new Set(config.data.collections.map((c) => c.key)) : null;
177
+ const known = (set) => set && set.size > 0 ? [...set].map((k) => `\`${k}\``).join(', ') : 'keine';
178
+ // Slots: dieselbe Prüfung wie das Vite-Plugin beim Build (`scanSlots`, `mergeSlots` aus dem SDK).
179
+ const slots = [];
180
+ for (const path of ctx.svelteFiles()) {
181
+ try {
182
+ slots.push(...scanSlots(ctx.text(path) ?? '', path));
183
+ }
184
+ catch (error) {
185
+ if (!(error instanceof SlotScanError))
186
+ continue; // Parse-Fehler meldet der Build (BLD-001).
187
+ out.push({ file: path, line: error.line, message: slotErrorText(error) });
188
+ }
189
+ }
190
+ try {
191
+ mergeSlots(slots);
192
+ }
193
+ catch (error) {
194
+ if (error instanceof SlotScanError)
195
+ out.push({ file: error.file, line: error.line, message: slotErrorText(error) });
196
+ }
197
+ for (const path of ctx.svelteFiles()) {
198
+ for (const el of ctx.svelte(path)?.elements ?? []) {
199
+ if (el.kind !== 'component')
200
+ continue;
201
+ const ref = el.name === COMPONENT.leadForm
202
+ ? { attr: getAttr(el, 'funnel'), keys: funnelKeys, kind: 'Das Formular', section: 'funnels' }
203
+ : el.name === COMPONENT.collectionList
204
+ ? {
205
+ attr: getAttr(el, 'collection'),
206
+ keys: collectionKeys,
207
+ kind: 'Die Sammlung',
208
+ section: 'collections',
209
+ }
210
+ : null;
211
+ if (!ref?.attr || typeof ref.attr.value !== 'string' || !ref.keys || ref.keys.has(ref.attr.value))
212
+ continue;
213
+ out.push(ctx.at(path, ref.attr.start, `${ref.kind} \`${ref.attr.value}\` gibt es in dealsystem.config.ts nicht (vorhanden: ${known(ref.keys)}).`, `Nutze einen vorhandenen Schlüssel oder lege \`${ref.section}['${ref.attr.value}']\` in dealsystem.config.ts an.`));
214
+ }
215
+ }
216
+ if (collectionKeys) {
217
+ for (const path of ctx.codeFiles()) {
218
+ for (const m of ctx.code(path).matchAll(COLLECTION_CALL)) {
219
+ const key = m[3] ?? '';
220
+ if (collectionKeys.has(key))
221
+ continue;
222
+ out.push(ctx.at(path, m.index, `\`${m[1]}('${key}')\`: Die Sammlung \`${key}\` gibt es in dealsystem.config.ts nicht (vorhanden: ${known(collectionKeys)}).`, `Nutze einen vorhandenen Schlüssel oder lege \`collections['${key}']\` in dealsystem.config.ts an.`));
223
+ }
224
+ }
225
+ }
226
+ return out;
227
+ });
228
+ // ------------------------------------------------------------------ QUA-007
229
+ const AGENTS_BLOCK_BEGIN_G = new RegExp(AGENTS_BLOCK_BEGIN.source, 'g');
230
+ const qua007 = sourceRule('QUA-007', (ctx) => {
231
+ const sdk = ctx.sdkVersion();
232
+ const text = ctx.text('AGENTS.md');
233
+ if (text === null)
234
+ return [
235
+ { file: 'AGENTS.md', message: 'AGENTS.md fehlt; dein Agent kennt die Regeln dieser Seite nicht.' },
236
+ ];
237
+ const m = AGENTS_BLOCK_BEGIN.exec(text);
238
+ if (!m)
239
+ return [
240
+ {
241
+ file: 'AGENTS.md',
242
+ message: 'AGENTS.md enthält keinen DealSystem-Block (`<!-- dealsystem:begin … -->`).',
243
+ },
244
+ ];
245
+ if (sdk && m[1] !== sdk) {
246
+ return [
247
+ {
248
+ file: 'AGENTS.md',
249
+ line: findAll(text, AGENTS_BLOCK_BEGIN_G)[0]?.line ?? null,
250
+ message: `Die Agenten-Anleitung gehört zu SDK ${m[1]}, installiert ist ${sdk}.`,
251
+ },
252
+ ];
253
+ }
254
+ return [];
255
+ });
256
+ // ------------------------------------------------------------------ CNT-001
257
+ /** Ab dieser Länge sollte ein Text im CRM änderbar sein. */
258
+ export const CONTENT_SLOT_MIN_LENGTH = 120;
259
+ const NON_CONTENT_ANCESTORS = new Set([
260
+ 'script',
261
+ 'style',
262
+ 'svelte:head',
263
+ 'title',
264
+ 'code',
265
+ 'pre',
266
+ 'svg',
267
+ COMPONENT.text,
268
+ COMPONENT.richText,
269
+ COMPONENT.impressum,
270
+ COMPONENT.datenschutz,
271
+ ]);
272
+ const HEADINGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
273
+ const cnt001 = sourceRule('CNT-001', (ctx) => {
274
+ const out = [];
275
+ for (const path of ctx.svelteFiles()) {
276
+ if (path.startsWith('src/routes/') && ['/impressum', '/datenschutz'].includes(routeOfSource(path)))
277
+ continue;
278
+ for (const t of ctx.svelte(path)?.texts ?? []) {
279
+ const text = t.data.replace(/\s+/g, ' ').trim();
280
+ if (t.ancestors.some((a) => NON_CONTENT_ANCESTORS.has(a)))
281
+ continue;
282
+ const offset = t.start + (t.data.length - t.data.trimStart().length);
283
+ // Überschriften gliedern die Seite: Der Kunde will sie umbenennen können, auch wenn sie kurz sind.
284
+ const heading = t.ancestors.findLast((a) => HEADINGS.has(a));
285
+ if (heading && /\p{L}{2,}/u.test(text)) {
286
+ out.push(ctx.at(path, offset, `Feste Überschrift in \`${path}\`: „${excerpt(text, 60)}“ ist im CRM nicht änderbar.`, `Schreibe sie als Slot: \`<Text key="seite.bereich.titel" default="${excerpt(text, 40)}" as="${heading}" />\`.`));
287
+ continue;
288
+ }
289
+ if (text.length < CONTENT_SLOT_MIN_LENGTH)
290
+ continue;
291
+ out.push(ctx.at(path, offset, `Fester Text in \`${path}\`: „${excerpt(text, 60)}“ ist im CRM nicht änderbar.`));
292
+ }
293
+ }
294
+ return out;
295
+ });
296
+ // ------------------------------------------------------------------ CNT-002
297
+ /** Muster für Firmendaten, die aus dem CRM kommen sollen. Bewusst eng: lieber ein Fund zu wenig als Fehlalarme. */
298
+ const COMPANY_DATA = [
299
+ { label: 'E-Mail-Adresse', pattern: /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/ },
300
+ { label: 'Adresse', pattern: /\b[0-9]{5}\s+\p{Lu}\p{Ll}{2,}/u },
301
+ {
302
+ label: 'Telefonnummer',
303
+ pattern: /(?:\+49|0049|\(0|(?<![0-9.,:])0)[1-9][0-9]{1,4}\)?[\s/-]{0,3}[0-9]{2,}(?:[\s-]?[0-9]{2,})*/,
304
+ },
305
+ ];
306
+ const COMPANY_DATA_IGNORED = new Set(['script', 'style', 'svelte:head', 'title', 'code', 'pre', 'svg']);
307
+ const cnt002 = sourceRule('CNT-002', (ctx) => {
308
+ const out = [];
309
+ for (const path of ctx.svelteFiles()) {
310
+ if (path.startsWith('src/routes/') && ['/impressum', '/datenschutz'].includes(routeOfSource(path)))
311
+ continue;
312
+ const ast = ctx.svelte(path);
313
+ if (!ast)
314
+ continue;
315
+ for (const t of ast.texts) {
316
+ if (t.ancestors.some((a) => COMPANY_DATA_IGNORED.has(a)))
317
+ continue;
318
+ for (const { label, pattern } of COMPANY_DATA) {
319
+ const m = pattern.exec(t.data);
320
+ if (!m)
321
+ continue;
322
+ // Telefonnummern haben mindestens sieben Ziffern; Jahreszahlen und Preise nicht.
323
+ if (label === 'Telefonnummer' && m[0].replace(/\D/g, '').length < 7)
324
+ continue;
325
+ out.push(ctx.at(path, t.start + m.index, `Feste ${label} in \`${path}\`: „${excerpt(m[0].trim(), 60)}“. Ändert der Kunde sie im CRM, bleibt hier die alte stehen.`));
326
+ break;
327
+ }
328
+ }
329
+ for (const el of ast.elements) {
330
+ if (el.kind !== 'element' || el.name.toLowerCase() !== 'a')
331
+ continue;
332
+ const href = el.attributes.find((a) => a.kind === 'attribute' && a.name.toLowerCase() === 'href');
333
+ if (typeof href?.value !== 'string')
334
+ continue;
335
+ const m = /^(mailto|tel):(.+)/i.exec(href.value.trim());
336
+ if (!m)
337
+ continue;
338
+ out.push(ctx.at(path, el.start, `Feste ${m[1].toLowerCase() === 'tel' ? 'Telefonnummer' : 'E-Mail-Adresse'} im Link in \`${path}\`: „${excerpt(m[2], 60)}“. Ändert der Kunde sie im CRM, bleibt hier die alte stehen.`));
339
+ }
340
+ }
341
+ return out;
342
+ });
343
+ // ------------------------------------------------------------------ CNT-003
344
+ const cnt003 = sourceRule('CNT-003', (ctx) => {
345
+ const out = [];
346
+ for (const path of ctx.svelteFiles()) {
347
+ for (const el of ctx.svelte(path)?.elements ?? []) {
348
+ if (el.kind !== 'component' || (el.name !== COMPONENT.text && el.name !== COMPONENT.richText))
349
+ continue;
350
+ const attr = getAttr(el, 'default');
351
+ // Nur der feste Wert in Anführungszeichen. In `{…}` ist `\n` JavaScript und ein echter Zeilenumbruch.
352
+ if (attr?.kind !== 'attribute' || typeof attr.value !== 'string' || !attr.value.includes('\\n'))
353
+ continue;
354
+ out.push(ctx.at(path, attr.start, `Im \`default\` von \`<${el.name}>\` steht \`\\n\`. In \`default="…"\` ist das kein Zeilenumbruch; auf der Seite steht dann wörtlich „\\n“.`));
355
+ }
356
+ }
357
+ return out;
358
+ });
359
+ // ------------------------------------------------------------------ CNT-004
360
+ /** Tags, die `<Seo>` setzt. Stehen sie zusätzlich im Kopf der Seite, gibt es sie doppelt. */
361
+ function seoTag(name, attrs) {
362
+ if (name === 'title')
363
+ return '<title>';
364
+ if (name !== 'meta')
365
+ return null;
366
+ const meta = String(attrs.get('name') ?? attrs.get('property') ?? '').toLowerCase();
367
+ if (meta === 'description' || meta.startsWith('og:') || meta.startsWith('twitter:'))
368
+ return `<meta ${meta}>`;
369
+ return null;
370
+ }
371
+ const cnt004 = sourceRule('CNT-004', (ctx) => {
372
+ const out = [];
373
+ for (const path of ctx.svelteFiles()) {
374
+ if (!/^src\/routes\/(?:.*\/)?\+(?:page|layout|error)(?:@[^.]*)?\.svelte$/.test(path))
375
+ continue;
376
+ for (const el of ctx.svelte(path)?.elements ?? []) {
377
+ if (el.kind !== 'element' || !el.ancestors.includes('svelte:head'))
378
+ continue;
379
+ const attrs = new Map(el.attributes.filter((a) => a.kind === 'attribute').map((a) => [a.name.toLowerCase(), a.value]));
380
+ const tag = seoTag(el.name.toLowerCase(), attrs);
381
+ if (!tag)
382
+ continue;
383
+ out.push(ctx.at(path, el.start, `\`${tag}\` steht fest in \`<svelte:head>\` von \`${path}\`. Was der Kunde unter Eigene Website → Einstellungen → Google und Teilen einträgt, wirkt hier nicht, und mit \`<Seo>\` stünde der Tag doppelt da.`));
384
+ }
385
+ }
386
+ const layout = 'src/routes/+layout.svelte';
387
+ if (ctx.files.has(layout) &&
388
+ !ctx.svelte(layout)?.elements.some((e) => e.kind === 'component' && e.name === COMPONENT.siteHead)) {
389
+ out.push({
390
+ file: layout,
391
+ message: `\`<${COMPONENT.siteHead} />\` fehlt im Haupt-Layout: Favicon und „Nicht bei Google anzeigen“ aus dem CRM wirken nicht.`,
392
+ });
393
+ }
394
+ const appHtml = ctx.text('src/app.html');
395
+ const icon = appHtml ? /<link\b[^>]*\brel=["']?(?:shortcut )?icon\b/i.exec(appHtml) : null;
396
+ if (appHtml && icon) {
397
+ out.push({
398
+ file: 'src/app.html',
399
+ line: appHtml.slice(0, icon.index).split('\n').length,
400
+ message: 'Der Favicon-Link steht in `src/app.html`. Lädt der Kunde im CRM ein Favicon hoch, gäbe es zwei.',
401
+ fix: 'Entferne den Link aus `src/app.html` und gib das Favicon `<SiteHead favicon="/favicon.svg" />` mit.',
402
+ });
403
+ }
404
+ return out;
405
+ });
406
+ // ------------------------------------------------------------------ QUA-008
407
+ const LEAD_CLIENT_IMPORT = /import\s*\{[^}]*\bcreateLeadClient\b[^}]*\}\s*from\s*['"]@dealsystem\/site['"]/;
408
+ const qua008 = sourceRule('QUA-008', (ctx) => {
409
+ const out = [];
410
+ for (const path of ctx.codeFiles()) {
411
+ const code = ctx.code(path);
412
+ const imported = LEAD_CLIENT_IMPORT.exec(code);
413
+ if (!imported)
414
+ continue;
415
+ if (/\.submit\s*\(/.test(code) && !/\bfallback\b/.test(code)) {
416
+ out.push(ctx.at(path, imported.index, `\`${path}\` sendet mit \`createLeadClient\`, zeigt aber keinen Ausweichkontakt (\`fallback\`). Scheitert der Versand, kann der Besucher nicht anfragen.`));
417
+ }
418
+ if (path.endsWith('.svelte') && !/<LeadHoneypot\b/.test(code)) {
419
+ out.push(ctx.at(path, imported.index, `\`${path}\` nutzt \`createLeadClient\` ohne \`<LeadHoneypot>\`. Ohne Bot-Falle kommen mehr Spam-Anfragen an.`));
420
+ }
421
+ }
422
+ return out;
423
+ });
424
+ // ------------------------------------------------------------------ QUA-010
425
+ const qua010 = sourceRule('QUA-010', (ctx) => {
426
+ const config = ctx.siteConfig();
427
+ const mod = ctx.module(SITE_CONFIG_FILE);
428
+ const out = [];
429
+ for (const funnel of config.data?.funnels ?? []) {
430
+ if (funnel.fields.length <= FUNNEL_MANIFEST_MAX_FIELDS)
431
+ continue;
432
+ out.push({
433
+ file: SITE_CONFIG_FILE,
434
+ line: mod ? findPathLine(mod, `funnels.${funnel.key}.fields`) : null,
435
+ message: `Das Formular "${funnel.key}" hat ${funnel.fields.length} Felder. Das CRM übernimmt nur die ersten ${FUNNEL_MANIFEST_MAX_FIELDS}; die übrigen kommen nur als Notiz an, ohne Prüfung und ohne Zuordnung.`,
436
+ });
437
+ }
438
+ return out;
439
+ });
440
+ export const qualitySourceRules = [
441
+ qua010,
442
+ qua008,
443
+ qua005,
444
+ qua006,
445
+ qua007,
446
+ cnt001,
447
+ cnt002,
448
+ cnt003,
449
+ cnt004,
450
+ ];
451
+ export const qualityOutputRules = [qua001, qua002, qua003, qua004];
@@ -0,0 +1,2 @@
1
+ import { type SourceRule } from '../rule.js';
2
+ export declare const scheduleSourceRules: SourceRule[];
@@ -0,0 +1,30 @@
1
+ // QUA-009: Zeitpunkte in `<Zeitfenster>`. Nur mit fester Zeichenkette und Zeitzone kann DealSystem zur Grenze neu
2
+ // bauen, und nur mit Zeitzone ist klar, welche Uhrzeit gemeint ist.
3
+ import { scanZeitfenster, zeitpunktFehlerText } from '@dealsystem/site/vite';
4
+ import { sourceRule } from '../rule.js';
5
+ const qua009 = sourceRule('QUA-009', (ctx) => {
6
+ const out = [];
7
+ for (const path of ctx.svelteFiles()) {
8
+ for (const fenster of scanZeitfenster(ctx.text(path) ?? '')) {
9
+ if (fenster.grenzen.length === 0) {
10
+ out.push(ctx.at(path, fenster.start, '`<Zeitfenster>` ohne `ab` und `bis` zeigt seinen Inhalt immer.'));
11
+ continue;
12
+ }
13
+ for (const grenze of fenster.grenzen) {
14
+ if (grenze.value === null) {
15
+ out.push(ctx.at(path, grenze.start, `\`<Zeitfenster ${grenze.name}={…}>\` ist keine feste Zeichenkette. Im Browser schaltet es um, aber DealSystem kann zu dieser Grenze nicht neu bauen: Im HTML (Google, Vorschauen) bleibt der alte Stand bis zum nächsten Hochladen.`));
16
+ }
17
+ else if (grenze.fehler) {
18
+ out.push(ctx.at(path, grenze.start, `\`<Zeitfenster>\`: ${zeitpunktFehlerText(grenze.name, grenze.value, grenze.fehler)}`));
19
+ }
20
+ }
21
+ const ab = fenster.grenzen.find((g) => g.name === 'ab')?.ms ?? null;
22
+ const bis = fenster.grenzen.find((g) => g.name === 'bis')?.ms ?? null;
23
+ if (ab !== null && bis !== null && ab >= bis) {
24
+ out.push(ctx.at(path, fenster.start, '`<Zeitfenster>`: `ab` liegt nicht vor `bis`, der Inhalt erscheint nie.'));
25
+ }
26
+ }
27
+ }
28
+ return out;
29
+ });
30
+ export const scheduleSourceRules = [qua009];
@@ -0,0 +1,18 @@
1
+ import { type OutputRule, type SourceRule } from '../rule.js';
2
+ /** Erkennungsmuster für Zugangsschlüssel (Teilmenge dessen, was gitleaks auf dem Build-Host prüft). */
3
+ export declare const SECRET_PATTERNS: readonly {
4
+ name: string;
5
+ pattern: RegExp;
6
+ }[];
7
+ /**
8
+ * Fremde Hosts, die die feste CSP der Altform (Starter bis SDK 0.1) nennen darf: Google Tag und Meta Pixel (nur
9
+ * über `<Tracking>`), die Site-API und OpenStreetMap (`<MapEmbed>`). Ab Regelsatz 3 kommen weitere Hosts nur über
10
+ * `external` in dealsystem.config.ts und `dealsystemCsp()`.
11
+ */
12
+ export declare const CSP_ALLOWED_HOSTS: readonly string[];
13
+ /** Ob `action` auf dieselbe Seite zeigt: leer, `#…`, `.` oder der Pfad der Seite selbst. */
14
+ export declare function isSamePageAction(value: string, route: string | null): boolean;
15
+ /** Herkunft der Karte, die `<MapEmbed>` aus dem SDK einbettet. Muss zu packages/site passen. */
16
+ export declare const MAP_EMBED_ORIGIN = "https://www.openstreetmap.org";
17
+ export declare const securitySourceRules: SourceRule[];
18
+ export declare const securityOutputRules: OutputRule[];