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,437 @@
1
+ // PRV-*: keine Drittanbieter-Requests vor der Einwilligung, lokale Schriften, kein eigenes Tracking,
2
+ // Pflichtseiten, Cookie-Hinweis.
3
+ import { routeOfPage, routeOfSource } from '../context.js';
4
+ import { outputRule, sourceRule } from '../rule.js';
5
+ import { COMPONENT, MARKER } from '../sdk.js';
6
+ import { excerpt, findAll } from '../util/code.js';
7
+ import { declaredExternal, tighteningSeverity } from '../util/csp.js';
8
+ import { getAttr } from '../util/svelte.js';
9
+ import { lineOf, parseHtml } from '../util/html.js';
10
+ /** Schrift- und Skript-CDNs (PRV-002). */
11
+ export const CDN_HOSTS = [
12
+ 'fonts.googleapis.com',
13
+ 'fonts.gstatic.com',
14
+ 'use.typekit.net',
15
+ 'p.typekit.net',
16
+ 'fonts.bunny.net',
17
+ 'use.fontawesome.com',
18
+ 'kit.fontawesome.com',
19
+ 'fast.fonts.net',
20
+ 'cdn.jsdelivr.net',
21
+ 'unpkg.com',
22
+ 'cdnjs.cloudflare.com',
23
+ 'ajax.googleapis.com',
24
+ 'code.jquery.com',
25
+ 'stackpath.bootstrapcdn.com',
26
+ 'maxcdn.bootstrapcdn.com',
27
+ 'cdn.tailwindcss.com',
28
+ 'esm.sh',
29
+ 'cdn.skypack.dev',
30
+ ];
31
+ const FONT_HOSTS = new Set([
32
+ 'fonts.googleapis.com',
33
+ 'fonts.gstatic.com',
34
+ 'use.typekit.net',
35
+ 'p.typekit.net',
36
+ 'fonts.bunny.net',
37
+ 'fast.fonts.net',
38
+ ]);
39
+ function hostOf(url) {
40
+ const u = url.trim();
41
+ if (!/^(https?:)?\/\//i.test(u))
42
+ return null;
43
+ try {
44
+ return new URL(u.startsWith('//') ? `https:${u}` : u).host.toLowerCase();
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ function isCdnHost(host) {
51
+ return CDN_HOSTS.some((h) => host === h || host.endsWith(`.${h}`));
52
+ }
53
+ /** Externe Adresse, die nicht zur Seite selbst gehört und nicht von PRV-002 gemeldet wird. */
54
+ function externalHost(url, siteHost) {
55
+ const host = hostOf(url);
56
+ if (!host || host === siteHost || isCdnHost(host))
57
+ return null;
58
+ return host;
59
+ }
60
+ const LOADING_LINK_RELS = new Set([
61
+ 'stylesheet',
62
+ 'preload',
63
+ 'modulepreload',
64
+ 'prefetch',
65
+ 'preconnect',
66
+ 'dns-prefetch',
67
+ 'icon',
68
+ 'shortcut',
69
+ 'apple-touch-icon',
70
+ 'manifest',
71
+ ]);
72
+ /** URLs, die ein Element beim Laden abruft. */
73
+ function loadedUrls(tag, attrs) {
74
+ const get = (name) => attrs[name] ?? null;
75
+ const urls = [];
76
+ const push = (v) => {
77
+ if (v)
78
+ urls.push(v);
79
+ };
80
+ const srcset = (v) => {
81
+ if (v)
82
+ for (const part of v.split(','))
83
+ push(part.trim().split(/\s+/)[0] ?? null);
84
+ };
85
+ switch (tag) {
86
+ case 'script':
87
+ case 'iframe':
88
+ case 'frame':
89
+ case 'embed':
90
+ case 'audio':
91
+ case 'track':
92
+ push(get('src'));
93
+ break;
94
+ case 'img':
95
+ case 'source':
96
+ push(get('src'));
97
+ srcset(get('srcset'));
98
+ break;
99
+ case 'video':
100
+ push(get('src'));
101
+ push(get('poster'));
102
+ break;
103
+ case 'input':
104
+ if ((get('type') ?? '').toLowerCase() === 'image')
105
+ push(get('src'));
106
+ break;
107
+ case 'object':
108
+ push(get('data'));
109
+ break;
110
+ case 'link': {
111
+ const rels = (get('rel') ?? '').toLowerCase().split(/\s+/);
112
+ if (rels.some((r) => LOADING_LINK_RELS.has(r)))
113
+ push(get('href'));
114
+ break;
115
+ }
116
+ }
117
+ return urls;
118
+ }
119
+ const CSS_URL = /(?:@import\s+(?:url\(\s*)?|url\(\s*)['"]?((?:https?:)?\/\/[^'")\s]+)/gi;
120
+ function cssExternal(text) {
121
+ return [...text.matchAll(CSS_URL)].map((m) => ({ url: m[1] ?? '', index: m.index }));
122
+ }
123
+ function prv001Message(url, where) {
124
+ return `\`${excerpt(url, 100)}\` wird vor der Einwilligung geladen (${where}).`;
125
+ }
126
+ function htmlDocExternal(doc, path, siteHost) {
127
+ const out = [];
128
+ for (const el of doc.elements) {
129
+ for (const url of loadedUrls(el.tag, el.attrs)) {
130
+ if (externalHost(url, siteHost))
131
+ out.push({ file: path, line: lineOf(doc, el), message: prv001Message(url, `<${el.tag}>`) });
132
+ }
133
+ if (el.tag === 'style') {
134
+ const css = el.children.map((c) => ('text' in c ? c.text : '')).join('');
135
+ for (const hit of cssExternal(css)) {
136
+ if (externalHost(hit.url, siteHost))
137
+ out.push({ file: path, line: lineOf(doc, el), message: prv001Message(hit.url, 'CSS') });
138
+ }
139
+ }
140
+ }
141
+ return out;
142
+ }
143
+ const prv001Source = sourceRule('PRV-001', (ctx) => {
144
+ const out = [];
145
+ for (const path of ctx.svelteFiles()) {
146
+ const ast = ctx.svelte(path);
147
+ if (!ast)
148
+ continue;
149
+ for (const el of ast.elements) {
150
+ if (el.kind !== 'element' || el.ancestors.includes(COMPONENT.consentGate))
151
+ continue;
152
+ const attrs = {};
153
+ for (const a of el.attributes)
154
+ if (a.kind === 'attribute')
155
+ attrs[a.name.toLowerCase()] = typeof a.value === 'string' ? a.value : null;
156
+ for (const url of loadedUrls(el.name, attrs)) {
157
+ if (externalHost(url, null))
158
+ out.push(ctx.at(path, el.start, prv001Message(url, `<${el.name}> in ${path}`)));
159
+ }
160
+ }
161
+ for (const style of ast.styles) {
162
+ for (const hit of cssExternal(style.content)) {
163
+ if (externalHost(hit.url, null))
164
+ out.push(ctx.at(path, style.start + hit.index, prv001Message(hit.url, 'CSS')));
165
+ }
166
+ }
167
+ }
168
+ for (const path of ctx.cssFiles()) {
169
+ for (const hit of cssExternal(ctx.code(path))) {
170
+ if (externalHost(hit.url, null))
171
+ out.push(ctx.at(path, hit.index, prv001Message(hit.url, 'CSS')));
172
+ }
173
+ }
174
+ for (const path of ctx.htmlFiles()) {
175
+ out.push(...htmlDocExternal(parseHtml(ctx.code(path)), path, null));
176
+ }
177
+ return out;
178
+ });
179
+ const prv001Output = outputRule('PRV-001', (ctx) => {
180
+ const out = [];
181
+ const siteHost = ctx.siteHost();
182
+ for (const path of ctx.pages())
183
+ out.push(...htmlDocExternal(ctx.html(path), path, siteHost));
184
+ for (const path of ctx.paths().filter((p) => p.endsWith('.css'))) {
185
+ const text = ctx.text(path) ?? '';
186
+ for (const hit of cssExternal(text)) {
187
+ if (externalHost(hit.url, siteHost))
188
+ out.push(ctx.at(path, hit.index, prv001Message(hit.url, 'CSS')));
189
+ }
190
+ }
191
+ return out;
192
+ });
193
+ // ------------------------------------------------------------------ PRV-002
194
+ const CDN_PATTERN = new RegExp(`(?:https?:)?//(?:[a-z0-9-]+\\.)*(?:${CDN_HOSTS.map((h) => h.replace(/\./g, '\\.')).join('|')})\\b[^\\s'"\`)<>]*`, 'gi');
195
+ function scanCdn(ctx, paths, text) {
196
+ const out = [];
197
+ for (const path of paths) {
198
+ for (const m of findAll(text(path), CDN_PATTERN, ctx.lines(path))) {
199
+ const host = hostOf(m.text) ?? '';
200
+ const font = FONT_HOSTS.has(host) || /font/i.test(m.text);
201
+ out.push({
202
+ file: path,
203
+ line: m.line,
204
+ column: m.column,
205
+ message: font
206
+ ? `\`${excerpt(m.text, 100)}\` lädt eine Schrift von einem fremden Server.`
207
+ : `\`${excerpt(m.text, 100)}\` lädt Code von einem CDN.`,
208
+ ...(font
209
+ ? {}
210
+ : {
211
+ fix: 'Installiere das Paket per npm (falls freigegeben) und importiere es, statt es vom CDN zu laden.',
212
+ }),
213
+ });
214
+ }
215
+ }
216
+ return out;
217
+ }
218
+ const prv002Source = sourceRule('PRV-002', (ctx) => scanCdn(ctx, ctx.textFiles((p) => p.startsWith('src/') || p.startsWith('static/')), (p) => ctx.code(p)));
219
+ const prv002Output = outputRule('PRV-002', (ctx) => scanCdn(ctx, ctx.textFiles((p) => /\.(html|css|js)$/.test(p)), (p) => ctx.text(p) ?? ''));
220
+ // ------------------------------------------------------------------ PRV-003
221
+ const TRACKING_PATTERNS = [
222
+ { pattern: /connect\.facebook\.net/g, name: 'Meta Pixel' },
223
+ { pattern: /\bfbq\s*\(/g, name: 'Meta Pixel' },
224
+ { pattern: /googletagmanager\.com/g, name: 'Google Tag Manager' },
225
+ { pattern: /google-analytics\.com/g, name: 'Google Analytics' },
226
+ { pattern: /\bgtag\s*\(/g, name: 'Google Tag' },
227
+ { pattern: /\bdataLayer\.push\s*\(/g, name: 'Google Tag Manager' },
228
+ { pattern: /static\.hotjar\.com/g, name: 'Hotjar' },
229
+ { pattern: /\bclarity\.ms\b/g, name: 'Microsoft Clarity' },
230
+ { pattern: /snap\.licdn\.com/g, name: 'LinkedIn Insight' },
231
+ { pattern: /analytics\.tiktok\.com/g, name: 'TikTok Pixel' },
232
+ { pattern: /\bttq\.(?:load|page|track)\s*\(/g, name: 'TikTok Pixel' },
233
+ { pattern: /\b_paq\.push\s*\(/g, name: 'Matomo' },
234
+ { pattern: /plausible\.io\/js/g, name: 'Plausible' },
235
+ ];
236
+ /** Pfade aus `static/`, die ein `<ExternalScript>` lädt, mit der Kategorie seines Dienstes. */
237
+ function externalScriptFiles(ctx) {
238
+ const declared = new Map(declaredExternal(ctx).map((e) => [e.id, e.category]));
239
+ const out = new Map();
240
+ for (const path of ctx.svelteFiles()) {
241
+ for (const el of ctx.svelte(path)?.elements ?? []) {
242
+ if (el.kind !== 'component' || el.name !== COMPONENT.externalScript)
243
+ continue;
244
+ const src = getAttr(el, 'src')?.value;
245
+ const id = getAttr(el, 'id')?.value;
246
+ if (typeof src !== 'string' || !src.startsWith('/') || src.startsWith('//'))
247
+ continue;
248
+ const file = `static${src.split(/[?#]/)[0]}`;
249
+ const category = typeof id === 'string' ? declared.get(id) : undefined;
250
+ out.set(file, [...(out.get(file) ?? []), category ?? 'unbekannt']);
251
+ }
252
+ }
253
+ return out;
254
+ }
255
+ const prv003 = sourceRule('PRV-003', (ctx) => {
256
+ const out = [];
257
+ const scan = (path, report) => {
258
+ for (const { pattern, name } of TRACKING_PATTERNS) {
259
+ for (const m of findAll(ctx.code(path), pattern, ctx.lines(path)))
260
+ report(m, name);
261
+ }
262
+ };
263
+ for (const path of [...ctx.codeFiles(), ...ctx.htmlFiles()]) {
264
+ scan(path, (m, name) => out.push({
265
+ file: path,
266
+ line: m.line,
267
+ column: m.column,
268
+ message: `\`${path}\` enthält ein eigenes Tracking-Snippet (${name}).`,
269
+ }));
270
+ }
271
+ // Regelsatz 3: Snippets der Anbieter liegen als Datei in `static/` und laden über `<ExternalScript>` nach der
272
+ // Einwilligung. Erlaubt nur, wenn genau das geschieht und der Dienst als Statistik oder Marketing deklariert ist.
273
+ const loaded = externalScriptFiles(ctx);
274
+ const severity = tighteningSeverity(ctx);
275
+ for (const path of ctx.paths().filter((p) => p.startsWith('static/') && /\.m?js$/.test(p))) {
276
+ const categories = loaded.get(path) ?? [];
277
+ const ok = categories.length > 0 && categories.every((c) => c === 'marketing' || c === 'statistics');
278
+ if (ok)
279
+ continue;
280
+ scan(path, (m, name) => out.push({
281
+ file: path,
282
+ line: m.line,
283
+ column: m.column,
284
+ severity,
285
+ message: categories.length === 0
286
+ ? `\`${path}\` enthält ein Tracking-Snippet (${name}), wird aber nicht über \`<ExternalScript>\` geladen.`
287
+ : `\`${path}\` enthält ein Tracking-Snippet (${name}), sein Dienst ist aber nicht als \`statistics\` oder \`marketing\` deklariert.`,
288
+ fix: 'Lade die Datei mit `<ExternalScript id="…" src="/…" />` und deklariere den Dienst unter `external` mit `category: \'marketing\'` (oder `statistics`). Google Tag und Meta Pixel gehen einfacher über `<Tracking />` mit der Kennung im CRM. Anleitung: extern.md.',
289
+ }));
290
+ }
291
+ return out;
292
+ });
293
+ // ------------------------------------------------------------------ PRV-008
294
+ const prv008 = sourceRule('PRV-008', (ctx) => {
295
+ const out = [];
296
+ for (const entry of declaredExternal(ctx)) {
297
+ if (entry.preset)
298
+ continue;
299
+ const missing = ['provider', 'purpose', 'privacyUrl'].filter((k) => entry[k] === null);
300
+ if (missing.length === 0)
301
+ continue;
302
+ out.push({
303
+ file: 'dealsystem.config.ts',
304
+ line: ctx.siteConfig().data ? findExternalLine(ctx, entry.id) : null,
305
+ message: `Der fremde Dienst \`${entry.id}\` nennt nicht ${missing.map((k) => `\`${k}\``).join(', ')}. Der Cookie-Hinweis kann dem Besucher dann nicht sagen, wer die Daten bekommt.`,
306
+ fix: `Ergänze unter \`external.${entry.id}\` z. B. \`provider: 'Anbieter GmbH, Deutschland'\`, \`purpose: 'Live-Chat'\`, \`privacyUrl: 'https://anbieter.de/datenschutz'\`. Frag den Kunden, wenn du den Anbieter nicht sicher kennst.`,
307
+ });
308
+ }
309
+ return out;
310
+ });
311
+ function findExternalLine(ctx, id) {
312
+ const text = ctx.text('dealsystem.config.ts') ?? '';
313
+ const idx = text.search(new RegExp(`['"]?${id.replace(/-/g, '\\-')}['"]?\\s*:\\s*\\{`));
314
+ return idx < 0 ? null : ctx.lines('dealsystem.config.ts').at(idx).line;
315
+ }
316
+ // ------------------------------------------------------------------ PRV-004
317
+ const LEGAL_PAGES = [
318
+ { route: '/impressum', component: COMPONENT.impressum, marker: MARKER.impressum },
319
+ { route: '/datenschutz', component: COMPONENT.datenschutz, marker: MARKER.datenschutz },
320
+ ];
321
+ function usesComponent(ctx, path, name) {
322
+ return ctx.svelte(path)?.elements.some((e) => e.kind === 'component' && e.name === name) ?? false;
323
+ }
324
+ const prv004Source = sourceRule('PRV-004', (ctx) => {
325
+ const out = [];
326
+ const pages = ctx.paths().filter((p) => p.startsWith('src/routes/') && p.endsWith('/+page.svelte'));
327
+ for (const legal of LEGAL_PAGES) {
328
+ const page = pages.find((p) => routeOfSource(p) === legal.route);
329
+ const fix = `Lege \`src/routes${legal.route}/+page.svelte\` mit \`<${legal.component} />\` an (Import aus \`@dealsystem/site\`).`;
330
+ if (!page)
331
+ out.push({
332
+ file: `src/routes${legal.route}/+page.svelte`,
333
+ message: `Die Seite \`${legal.route}\` fehlt.`,
334
+ fix,
335
+ });
336
+ else if (!usesComponent(ctx, page, legal.component)) {
337
+ out.push({
338
+ file: page,
339
+ message: `Die Seite \`${legal.route}\` nutzt nicht \`<${legal.component} />\`.`,
340
+ fix,
341
+ });
342
+ }
343
+ }
344
+ return out;
345
+ });
346
+ function hasMarker(doc, marker) {
347
+ return doc.elements.some((e) => marker in e.attrs);
348
+ }
349
+ const prv004Output = outputRule('PRV-004', (ctx) => {
350
+ const out = [];
351
+ for (const legal of LEGAL_PAGES) {
352
+ const page = ctx.pages().find((p) => routeOfPage(p) === legal.route);
353
+ const fix = `Lege \`src/routes${legal.route}/+page.svelte\` mit \`<${legal.component} />\` an.`;
354
+ if (!page)
355
+ out.push({ file: null, message: `Die gebaute Seite enthält keine Route \`${legal.route}\`.`, fix });
356
+ else if (!hasMarker(ctx.html(page), legal.marker)) {
357
+ out.push({ file: page, message: `\`${legal.route}\` enthält nicht \`<${legal.component} />\`.`, fix });
358
+ }
359
+ }
360
+ return out;
361
+ });
362
+ // ------------------------------------------------------------------ PRV-005
363
+ const prv005Source = sourceRule('PRV-005', (ctx) => {
364
+ const layout = 'src/routes/+layout.svelte';
365
+ if (!ctx.files.has(layout)) {
366
+ return [{ file: layout, message: '`src/routes/+layout.svelte` fehlt.' }];
367
+ }
368
+ const missing = [COMPONENT.siteFooterLegal, COMPONENT.cookieBanner].filter((c) => !usesComponent(ctx, layout, c));
369
+ return missing.map((c) => ({ file: layout, message: `\`<${c} />\` fehlt im Haupt-Layout.` }));
370
+ });
371
+ /** Löst einen Link relativ zur Seite auf; `null` für externe Ziele. */
372
+ export function resolveHref(href, pageRoute) {
373
+ const h = href.trim();
374
+ if (!h || h.startsWith('#') || /^[a-z][a-z0-9+.-]*:/i.test(h) || h.startsWith('//'))
375
+ return null;
376
+ try {
377
+ // Wie der Browser: relativ zur Adresse der Seite (SvelteKit: ohne Schrägstrich am Ende).
378
+ return decodeURIComponent(new URL(h, `https://site.invalid${pageRoute}`).pathname);
379
+ }
380
+ catch {
381
+ return null;
382
+ }
383
+ }
384
+ function normalizeRoute(path) {
385
+ return path.length > 1 ? path.replace(/\/+$/, '').replace(/\.html$/, '') : path;
386
+ }
387
+ const prv005Output = outputRule('PRV-005', (ctx) => {
388
+ const out = [];
389
+ for (const page of ctx.contentPages()) {
390
+ const doc = ctx.html(page);
391
+ const route = routeOfPage(page);
392
+ const targets = new Set(doc.elements
393
+ .filter((e) => e.tag === 'a' && e.attrs.href !== undefined)
394
+ .map((e) => resolveHref(e.attrs.href ?? '', route))
395
+ .filter((r) => r !== null)
396
+ .map(normalizeRoute));
397
+ for (const legal of ['/impressum', '/datenschutz']) {
398
+ if (route === legal || targets.has(legal))
399
+ continue;
400
+ out.push({ file: page, message: `Die Seite \`${route}\` verlinkt nicht auf \`${legal}\`.` });
401
+ }
402
+ if (!hasMarker(doc, MARKER.cookieBanner)) {
403
+ out.push({
404
+ file: page,
405
+ message: `Die Seite \`${route}\` enthält keinen Cookie-Hinweis (\`<CookieBanner />\`).`,
406
+ });
407
+ }
408
+ }
409
+ return out;
410
+ });
411
+ // ------------------------------------------------------------------ PRV-006
412
+ const STORAGE = /\b(?:document\.cookie|localStorage|sessionStorage)\b/g;
413
+ const prv006 = sourceRule('PRV-006', (ctx) => {
414
+ const out = [];
415
+ for (const path of ctx.codeFiles()) {
416
+ for (const m of findAll(ctx.code(path), STORAGE, ctx.lines(path))) {
417
+ out.push({
418
+ file: path,
419
+ line: m.line,
420
+ column: m.column,
421
+ message: `\`${path}\` speichert Daten im Browser (\`${m.text}\`).`,
422
+ });
423
+ }
424
+ }
425
+ return out;
426
+ });
427
+ export const privacySourceRules = [
428
+ prv001Source,
429
+ prv002Source,
430
+ prv003,
431
+ prv004Source,
432
+ prv005Source,
433
+ prv006,
434
+ prv008,
435
+ ];
436
+ export const privacyOutputRules = [prv001Output, prv002Output, prv004Output, prv005Output];
437
+ export { normalizeRoute };
@@ -0,0 +1,11 @@
1
+ import { type OutputRule, type SourceRule } from '../rule.js';
2
+ export declare const OUTPUT_LIMITS: {
3
+ readonly totalBytes: number;
4
+ readonly files: 10000;
5
+ readonly fileBytes: number;
6
+ readonly jsGzipBytesPerPage: number;
7
+ };
8
+ /** Ab dieser Länge sollte ein Text im CRM änderbar sein. */
9
+ export declare const CONTENT_SLOT_MIN_LENGTH = 120;
10
+ export declare const qualitySourceRules: SourceRule[];
11
+ export declare const qualityOutputRules: OutputRule[];