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,2 @@
1
+ import { type SourceRule } from '../rule.js';
2
+ export declare const structureRules: SourceRule[];
@@ -0,0 +1,399 @@
1
+ // STR-*, DEP-*: statischer Build, Projektaufbau, Abhängigkeiten.
2
+ import semver from 'semver';
3
+ import { DEFAULT_SDK_RANGE } from '../catalog.js';
4
+ import { ALTERNATIVES, isAllowedPackage } from '../allowlist.js';
5
+ import { sourceRule } from '../rule.js';
6
+ import { CONFIG_MODULE, CONTENT_MODULE, SDK_PACKAGE, VITE_MODULE } from '../sdk.js';
7
+ import { findAll, isSvelteFile } from '../util/code.js';
8
+ import { evaluate, isOpaque, isPlainObject } from '../util/literal.js';
9
+ const ROUTES = 'src/routes/';
10
+ const SERVER_ENDPOINT = /\/\+server\.(ts|js)$/;
11
+ const SERVER_LOAD = /\/\+(page|layout)\.server\.(ts|js)$/;
12
+ const CONTENT_IMPORT = /from\s+['"]@dealsystem\/site\/content['"]/g;
13
+ /** Die einzigen erlaubten Endpunkte: vorgerenderte Dateien aus dem Starter. */
14
+ const ALLOWED_ENDPOINTS = new Set([
15
+ 'src/routes/sitemap.xml/+server.ts',
16
+ 'src/routes/sitemap.xml/+server.js',
17
+ 'src/routes/robots.txt/+server.ts',
18
+ 'src/routes/robots.txt/+server.js',
19
+ ]);
20
+ function exportedValue(mod, name) {
21
+ if (!mod.namedExports.has(name))
22
+ return 'missing';
23
+ const init = mod.namedExports.get(name);
24
+ return init ? evaluate(mod, init) : undefined;
25
+ }
26
+ function exportsPrerenderTrue(ctx, path) {
27
+ const mod = ctx.module(path);
28
+ return mod !== null && exportedValue(mod, 'prerender') === true;
29
+ }
30
+ /** `prerender = true` in der Datei selbst oder in einem Layout darüber (SvelteKit vererbt die Option). */
31
+ function prerenderedViaLayout(ctx, path) {
32
+ if (exportsPrerenderTrue(ctx, path))
33
+ return true;
34
+ const dirs = path.split('/').slice(0, -1);
35
+ while (dirs.length >= 2) {
36
+ const dir = dirs.join('/');
37
+ for (const name of ['+layout.ts', '+layout.js', '+layout.server.ts', '+layout.server.js']) {
38
+ const p = `${dir}/${name}`;
39
+ if (p !== path && ctx.files.has(p) && exportsPrerenderTrue(ctx, p))
40
+ return true;
41
+ }
42
+ dirs.pop();
43
+ if (dirs.join('/') === 'src')
44
+ break;
45
+ }
46
+ return false;
47
+ }
48
+ function lineOfExport(ctx, path, name) {
49
+ const text = ctx.text(path) ?? '';
50
+ const idx = text.search(new RegExp(`export\\s+(const|let|var|function|async\\s+function)\\s+${name}\\b`));
51
+ return idx >= 0 ? ctx.lines(path).at(idx).line : null;
52
+ }
53
+ const str001 = sourceRule('STR-001', (ctx) => {
54
+ const path = ctx.svelteConfigPath();
55
+ if (!path) {
56
+ return [
57
+ {
58
+ file: 'svelte.config.js',
59
+ message: 'svelte.config.js fehlt.',
60
+ fix: 'Lege svelte.config.js wie im Starter an, mit `adapter: adapter()` aus `@sveltejs/adapter-static`.',
61
+ },
62
+ ];
63
+ }
64
+ const mod = ctx.module(path);
65
+ if (!mod)
66
+ return [];
67
+ const config = mod.defaultExport ? evaluate(mod, mod.defaultExport) : undefined;
68
+ const kit = isPlainObject(config) ? config.kit : undefined;
69
+ const adapter = isPlainObject(kit) ? kit.adapter : undefined;
70
+ const adapterModule = isOpaque(adapter) && adapter.call ? mod.imports.get(adapter.call) : undefined;
71
+ if (adapterModule === '@sveltejs/adapter-static')
72
+ return [];
73
+ const found = adapterModule ? ` Gefunden: \`${adapterModule}\`.` : '';
74
+ return [
75
+ {
76
+ file: path,
77
+ line: isOpaque(adapter) ? adapter.line : null,
78
+ message: `Diese Seite muss statisch gebaut werden.${found}`,
79
+ },
80
+ ];
81
+ });
82
+ const str002 = sourceRule('STR-002', (ctx) => {
83
+ const out = [];
84
+ for (const path of ctx.paths()) {
85
+ if (path.startsWith(ROUTES) && SERVER_ENDPOINT.test(path)) {
86
+ if (ALLOWED_ENDPOINTS.has(path) && exportsPrerenderTrue(ctx, path))
87
+ continue;
88
+ out.push(ALLOWED_ENDPOINTS.has(path)
89
+ ? {
90
+ file: path,
91
+ message: `\`${path}\` wird nicht vorgerendert.`,
92
+ fix: 'Ergänze `export const prerender = true` in der Datei.',
93
+ }
94
+ : { file: path, message: `\`${path}\` braucht einen Server.` });
95
+ }
96
+ else if (/^src\/hooks\.server\.(ts|js)$/.test(path)) {
97
+ out.push({ file: path, message: `\`${path}\` braucht einen Server.` });
98
+ }
99
+ else if (path.startsWith(ROUTES) && /\/\+page\.server\.(ts|js)$/.test(path)) {
100
+ const mod = ctx.module(path);
101
+ if (mod?.namedExports.has('actions')) {
102
+ out.push({
103
+ file: path,
104
+ line: lineOfExport(ctx, path, 'actions'),
105
+ message: `\`${path}\` enthält Form-Actions; die brauchen einen Server.`,
106
+ fix: 'Entferne `export const actions`. Formulare gehen über `<LeadForm>`.',
107
+ });
108
+ }
109
+ }
110
+ }
111
+ return out;
112
+ });
113
+ const str003 = sourceRule('STR-003', (ctx) => {
114
+ const out = ctx
115
+ .paths()
116
+ .filter((p) => p.startsWith(ROUTES) && SERVER_LOAD.test(p))
117
+ .filter((p) => !prerenderedViaLayout(ctx, p))
118
+ .map((p) => ({ file: p, message: `\`${p}\` läuft nur beim Build, wenn die Seite vorgerendert wird.` }));
119
+ // Die Lade-Helfer lesen beim Build eine Datei; im Browser gibt es sie nicht.
120
+ for (const path of ctx.codeFiles()) {
121
+ // Serverseitig beim Build: `+page.server.ts`, `+server.ts`, `*.server.ts` und `$lib/server/`.
122
+ if (SERVER_LOAD.test(path) ||
123
+ SERVER_ENDPOINT.test(path) ||
124
+ /\.server\.(ts|js)$/.test(path) ||
125
+ path.startsWith('src/lib/server/'))
126
+ continue;
127
+ const mod = isSvelteFile(path) ? null : ctx.module(path);
128
+ const imports = mod
129
+ ? mod.importList.filter((i) => i.module === CONTENT_MODULE)
130
+ : findAll(ctx.code(path), CONTENT_IMPORT, ctx.lines(path)).map((m) => ({
131
+ module: CONTENT_MODULE,
132
+ line: m.line,
133
+ }));
134
+ for (const imp of imports) {
135
+ const target = path.replace(/\/\+(page|layout)\.(ts|js)$/, '/+$1.server.$2');
136
+ out.push({
137
+ file: path,
138
+ line: imp.line,
139
+ message: `\`${path}\` importiert \`${CONTENT_MODULE}\`; die Lade-Helfer laufen nur beim Build auf dem Server.`,
140
+ fix: target !== path
141
+ ? `Benenne die Datei in \`${target}\` um (mit \`export const prerender = true\` dort oder im Layout).`
142
+ : `Lade die Daten in \`+page.server.ts\` (mit \`export const prerender = true\`) und gib sie über \`data\` an die Seite.`,
143
+ });
144
+ }
145
+ }
146
+ return out;
147
+ });
148
+ const str004 = sourceRule('STR-004', (ctx) => {
149
+ const out = [];
150
+ for (const page of ctx.paths().filter((p) => p.startsWith(ROUTES) && p.endsWith('/+page.svelte'))) {
151
+ const dir = page.slice(0, -'/+page.svelte'.length);
152
+ const segments = dir.split('/').slice(2);
153
+ if (!segments.some((s) => s.includes('[')))
154
+ continue;
155
+ const candidates = ['+page.ts', '+page.js', '+page.server.ts', '+page.server.js'].map((n) => `${dir}/${n}`);
156
+ const hasEntries = candidates.some((p) => ctx.files.has(p) && ctx.module(p)?.namedExports.has('entries'));
157
+ if (hasEntries)
158
+ continue;
159
+ const route = `/${segments.filter((s) => !(s.startsWith('(') && s.endsWith(')'))).join('/')}`;
160
+ out.push({
161
+ file: page,
162
+ message: `Die Route \`${route}\` kann nicht vorgerendert werden: \`entries\` fehlt.`,
163
+ fix: `Exportiere in \`${dir}/+page.server.ts\` \`export const entries = () => collectionEntries('<key>')\` (Import aus \`@dealsystem/site/content\`, dazu \`prerender = true\`).`,
164
+ });
165
+ }
166
+ return out;
167
+ });
168
+ const str005 = sourceRule('STR-005', (ctx) => ctx
169
+ .siteConfig()
170
+ .problems.filter((p) => p.kind === 'structure')
171
+ .map((p) => ({
172
+ file: 'dealsystem.config.ts',
173
+ line: p.line,
174
+ // Die Meldung des SDK nennt die Korrektur schon; sie soll nicht zweimal dastehen.
175
+ message: p.message.replace(/\s*Führe `npx dealsystem init` aus\.$/, ''),
176
+ ...(p.fix ? { fix: p.fix } : {}),
177
+ })));
178
+ function dependencyMap(pkg, field) {
179
+ const v = pkg?.[field];
180
+ if (!v || typeof v !== 'object')
181
+ return {};
182
+ return Object.fromEntries(Object.entries(v).filter((e) => typeof e[1] === 'string'));
183
+ }
184
+ const DEP_FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
185
+ function lineOfKey(ctx, path, key) {
186
+ const text = ctx.text(path) ?? '';
187
+ const idx = text.indexOf(`"${key}"`);
188
+ return idx >= 0 ? ctx.lines(path).at(idx).line : null;
189
+ }
190
+ const str006 = sourceRule('STR-006', (ctx) => {
191
+ const pkg = ctx.json('package.json').data;
192
+ if (!pkg)
193
+ return [];
194
+ const declared = DEP_FIELDS.some((f) => dependencyMap(pkg, f)[SDK_PACKAGE] !== undefined);
195
+ if (!declared) {
196
+ return [
197
+ {
198
+ file: 'package.json',
199
+ message: `\`${SDK_PACKAGE}\` fehlt in package.json.`,
200
+ fix: `Installiere das SDK: \`npm install ${SDK_PACKAGE}@latest\` und führe \`npx dealsystem sync\` aus.`,
201
+ },
202
+ ];
203
+ }
204
+ const version = ctx.sdkVersion();
205
+ if (!version)
206
+ return []; // STR-007 meldet das fehlende oder unpassende Lockfile.
207
+ const range = ctx.options.sdkRange ?? DEFAULT_SDK_RANGE;
208
+ if (semver.valid(version) && semver.satisfies(version, range, { includePrerelease: true }))
209
+ return [];
210
+ return [
211
+ {
212
+ file: 'package-lock.json',
213
+ line: lineOfKey(ctx, 'package-lock.json', `node_modules/${SDK_PACKAGE}`),
214
+ message: `\`${SDK_PACKAGE}\` ${version} wird nicht unterstützt (erlaubt: ${range}).`,
215
+ },
216
+ ];
217
+ });
218
+ const str007 = sourceRule('STR-007', (ctx) => {
219
+ const pkg = ctx.json('package.json');
220
+ if (!pkg.data) {
221
+ return [
222
+ {
223
+ file: 'package.json',
224
+ message: pkg.error === 'fehlt'
225
+ ? 'package.json fehlt.'
226
+ : `package.json ist kein gültiges JSON (${pkg.error}).`,
227
+ fix: 'Stelle package.json aus dem Starter wieder her und führe `npm install` aus.',
228
+ },
229
+ ];
230
+ }
231
+ const lock = ctx.json('package-lock.json');
232
+ if (!lock.data) {
233
+ return [
234
+ {
235
+ file: 'package-lock.json',
236
+ message: lock.error === 'fehlt'
237
+ ? 'package-lock.json fehlt.'
238
+ : `package-lock.json ist kein gültiges JSON (${lock.error}).`,
239
+ },
240
+ ];
241
+ }
242
+ const version = lock.data.lockfileVersion;
243
+ if (typeof version !== 'number' || version < 2) {
244
+ return [{ file: 'package-lock.json', message: 'package-lock.json ist zu alt (lockfileVersion < 2).' }];
245
+ }
246
+ const root = lock.data.packages?.[''] ?? null;
247
+ const out = [];
248
+ for (const field of ['dependencies', 'devDependencies', 'optionalDependencies']) {
249
+ const want = dependencyMap(pkg.data, field);
250
+ const have = dependencyMap(root, field);
251
+ const names = [...new Set([...Object.keys(want), ...Object.keys(have)])].sort();
252
+ for (const name of names) {
253
+ if (want[name] === have[name])
254
+ continue;
255
+ out.push({
256
+ file: 'package-lock.json',
257
+ message: want[name] === undefined
258
+ ? `package-lock.json enthält \`${name}\`, package.json nicht.`
259
+ : have[name] === undefined
260
+ ? `\`${name}\` steht in package.json, aber nicht in package-lock.json.`
261
+ : `\`${name}\`: package.json verlangt \`${want[name]}\`, package-lock.json hat \`${have[name]}\`.`,
262
+ });
263
+ }
264
+ }
265
+ return out;
266
+ });
267
+ const dep001 = sourceRule('DEP-001', (ctx) => {
268
+ const pkg = ctx.json('package.json').data;
269
+ if (!pkg)
270
+ return [];
271
+ const out = [];
272
+ for (const field of DEP_FIELDS) {
273
+ for (const name of Object.keys(dependencyMap(pkg, field)).sort()) {
274
+ if (isAllowedPackage(name))
275
+ continue;
276
+ const alt = ALTERNATIVES[name];
277
+ out.push({
278
+ file: 'package.json',
279
+ line: lineOfKey(ctx, 'package.json', name),
280
+ message: `Das Paket \`${name}\` ist nicht freigegeben.`,
281
+ fix: alt
282
+ ? `Entferne es mit \`npm uninstall ${name}\` und nutze ${alt}. Freigegebene Pakete: \`npx dealsystem check --allowed\`.`
283
+ : `Entferne es mit \`npm uninstall ${name}\`. Freigegebene Pakete: \`npx dealsystem check --allowed\`.`,
284
+ });
285
+ }
286
+ }
287
+ return out;
288
+ });
289
+ const REGISTRY = 'https://registry.npmjs.org/';
290
+ const NON_REGISTRY_SPEC = /^(git\+|git:|github:|gitlab:|bitbucket:|gist:|https?:|file:|link:|workspace:|npm:|\.{0,2}\/)/;
291
+ const dep002 = sourceRule('DEP-002', (ctx) => {
292
+ const out = [];
293
+ const pkg = ctx.json('package.json').data;
294
+ for (const field of DEP_FIELDS) {
295
+ for (const [name, spec] of Object.entries(dependencyMap(pkg, field))) {
296
+ // `user/repo` ist die Kurzform für GitHub.
297
+ if (NON_REGISTRY_SPEC.test(spec) || /^[\w.-]+\/[\w.-]+(#.*)?$/.test(spec)) {
298
+ out.push({
299
+ file: 'package.json',
300
+ line: lineOfKey(ctx, 'package.json', name),
301
+ message: `\`${name}\` kommt nicht aus der npm-Registry (\`${spec.slice(0, 80)}\`).`,
302
+ fix: `Installiere die veröffentlichte Version: \`npm install ${name}@latest\`.`,
303
+ });
304
+ }
305
+ }
306
+ }
307
+ const lock = ctx.json('package-lock.json').data;
308
+ const packages = lock?.packages ?? {};
309
+ for (const [key, entry] of Object.entries(packages)) {
310
+ if (!key.startsWith('node_modules/'))
311
+ continue;
312
+ const name = key.slice(key.lastIndexOf('node_modules/') + 'node_modules/'.length);
313
+ const resolved = typeof entry.resolved === 'string' ? entry.resolved : null;
314
+ const bad = entry.link === true ||
315
+ (resolved !== null && !resolved.startsWith(REGISTRY)) ||
316
+ (typeof entry.version === 'string' && NON_REGISTRY_SPEC.test(entry.version));
317
+ if (!bad)
318
+ continue;
319
+ out.push({
320
+ file: 'package-lock.json',
321
+ line: lineOfKey(ctx, 'package-lock.json', key),
322
+ message: `\`${name}\` kommt nicht aus der npm-Registry (\`${(resolved ?? String(entry.version ?? 'link')).slice(0, 80)}\`).`,
323
+ fix: `Installiere die veröffentlichte Version: \`npm install ${name}@latest\`, dann erneut \`npm install\`.`,
324
+ });
325
+ }
326
+ return out;
327
+ });
328
+ function kitSection(ctx) {
329
+ const path = ctx.svelteConfigPath();
330
+ const mod = path ? ctx.module(path) : null;
331
+ if (!path || !mod)
332
+ return null;
333
+ const config = mod.defaultExport ? evaluate(mod, mod.defaultExport) : undefined;
334
+ return { path, mod, kit: isPlainObject(config) ? config.kit : undefined };
335
+ }
336
+ const str008 = sourceRule('STR-008', (ctx) => {
337
+ const section = kitSection(ctx);
338
+ if (!section)
339
+ return []; // STR-001 meldet die fehlende Datei.
340
+ const prerender = isPlainObject(section.kit) ? section.kit.prerender : undefined;
341
+ const handler = isPlainObject(prerender) ? prerender.handleHttpError : undefined;
342
+ const out = [];
343
+ if (!(isOpaque(handler) && !handler.call && section.mod.imports.get(handler.text) === CONFIG_MODULE)) {
344
+ out.push({
345
+ file: section.path,
346
+ line: isOpaque(handler) ? handler.line : null,
347
+ message: `In svelte.config.js fehlt \`kit.prerender.handleHttpError\` aus \`${CONFIG_MODULE}\`; ohne sie scheitert der Build an Bildern unter \`/_ds/media/\`.`,
348
+ });
349
+ }
350
+ // Ohne 'ignore' scheitert der Build, sobald eine Sammlung keinen veröffentlichten Eintrag mehr hat:
351
+ // Ihre Detailroute (`/angebote/[slug]`) hat dann keine Seite, und SvelteKit wertet das als Fehler.
352
+ const unseen = isPlainObject(prerender) ? prerender.handleUnseenRoutes : undefined;
353
+ if (unseen !== 'ignore') {
354
+ out.push({
355
+ file: section.path,
356
+ line: isOpaque(unseen) ? unseen.line : null,
357
+ message: "In svelte.config.js fehlt `kit.prerender.handleUnseenRoutes: 'ignore'`; ohne sie scheitert der Build, sobald eine Sammlung keine Einträge hat.",
358
+ });
359
+ }
360
+ return out;
361
+ });
362
+ const str009 = sourceRule('STR-009', (ctx) => {
363
+ const path = ['vite.config.ts', 'vite.config.js'].find((p) => ctx.files.has(p));
364
+ if (!path)
365
+ return [{ file: 'vite.config.ts', message: 'vite.config.ts fehlt.' }];
366
+ const mod = ctx.module(path);
367
+ if (!mod)
368
+ return [];
369
+ let config = mod.defaultExport ? evaluate(mod, mod.defaultExport) : undefined;
370
+ if (isOpaque(config) && config.call === 'defineConfig' && config.args?.length === 1)
371
+ config = config.args[0];
372
+ const plugins = isPlainObject(config) && Array.isArray(config.plugins) ? config.plugins : [];
373
+ const index = (module) => plugins.findIndex((p) => isOpaque(p) && p.call !== undefined && mod.imports.get(p.call) === module);
374
+ const ds = index(VITE_MODULE);
375
+ const kit = index('@sveltejs/kit/vite');
376
+ if (ds >= 0 && (kit < 0 || ds < kit))
377
+ return [];
378
+ return [
379
+ {
380
+ file: path,
381
+ message: ds < 0
382
+ ? `In ${path} fehlt das Plugin \`dealsystem(site)\` aus \`${VITE_MODULE}\`.`
383
+ : `In ${path} steht \`dealsystem(site)\` hinter \`sveltekit()\`.`,
384
+ },
385
+ ];
386
+ });
387
+ export const structureRules = [
388
+ str001,
389
+ str002,
390
+ str003,
391
+ str004,
392
+ str005,
393
+ str008,
394
+ str009,
395
+ str006,
396
+ str007,
397
+ dep001,
398
+ dep002,
399
+ ];
@@ -0,0 +1,15 @@
1
+ import { RULES } from './catalog.js';
2
+ import type { RuleImpl } from './rule.js';
3
+ import type { CheckOptions, CheckResult } from './types.js';
4
+ export declare const RULE_IMPLEMENTATIONS: readonly RuleImpl[];
5
+ export declare class RuleSetMismatchError extends Error {
6
+ readonly expected: string;
7
+ readonly actual: string;
8
+ constructor(expected: string, actual: string);
9
+ }
10
+ /**
11
+ * Führt den Regelkatalog aus. Läuft ohne Netz und ohne Browser; liest nur Dateien, führt nichts aus dem
12
+ * Projekt aus. Der Build-Host ruft dieselbe Funktion auf (Quelle vor dem Build, Ausgabe danach).
13
+ */
14
+ export declare function runCheck(options: CheckOptions): Promise<CheckResult>;
15
+ export { RULES };
@@ -0,0 +1,147 @@
1
+ // Ein Prüflauf: Regeln je Stufe ausführen, Funde normalisieren und stabil sortieren.
2
+ import { getRule, RULE_SET_VERSION, RULES } from './catalog.js';
3
+ import { OutputContext, SourceContext } from './context.js';
4
+ import { cspForm } from './util/csp.js';
5
+ import { createDirFileSet, IGNORED_DIRS } from './fileset.js';
6
+ import { a11yOutputRules, a11ySourceRules } from './rules/a11y.js';
7
+ import { privacyOutputRules, privacySourceRules } from './rules/privacy.js';
8
+ import { qualityOutputRules, qualitySourceRules } from './rules/quality.js';
9
+ import { scheduleSourceRules } from './rules/schedule.js';
10
+ import { securityOutputRules, securitySourceRules } from './rules/security.js';
11
+ import { structureRules } from './rules/structure.js';
12
+ export const RULE_IMPLEMENTATIONS = [
13
+ ...structureRules,
14
+ ...securitySourceRules,
15
+ ...privacySourceRules,
16
+ ...a11ySourceRules,
17
+ ...qualitySourceRules,
18
+ ...scheduleSourceRules,
19
+ ...securityOutputRules,
20
+ ...privacyOutputRules,
21
+ ...a11yOutputRules,
22
+ ...qualityOutputRules,
23
+ ];
24
+ export class RuleSetMismatchError extends Error {
25
+ expected;
26
+ actual;
27
+ constructor(expected, actual) {
28
+ super(`Regelkatalog ${actual} passt nicht zur erwarteten Version ${expected}.`);
29
+ this.expected = expected;
30
+ this.actual = actual;
31
+ this.name = 'RuleSetMismatchError';
32
+ }
33
+ }
34
+ function compareFindings(a, b) {
35
+ const key = (f) => [
36
+ f.file ?? '',
37
+ f.line ?? 0,
38
+ f.column ?? 0,
39
+ f.rule,
40
+ f.message,
41
+ ];
42
+ const ka = key(a);
43
+ const kb = key(b);
44
+ for (let i = 0; i < ka.length; i++) {
45
+ const x = ka[i];
46
+ const y = kb[i];
47
+ if (x < y)
48
+ return -1;
49
+ if (x > y)
50
+ return 1;
51
+ }
52
+ return 0;
53
+ }
54
+ function normalize(meta, raw, severity) {
55
+ return {
56
+ rule: meta.id,
57
+ severity,
58
+ file: raw.file ?? null,
59
+ line: raw.line ?? null,
60
+ column: raw.column ?? null,
61
+ message: raw.message,
62
+ fix: raw.fix ?? meta.fix,
63
+ };
64
+ }
65
+ /** Meldung einer Regel, die selbst abgestürzt ist: nie still verschlucken, aber den Lauf nicht abbrechen. */
66
+ function crashFinding(meta, error) {
67
+ return {
68
+ message: `Die Prüfung ${meta.id} ist mit einem internen Fehler abgebrochen: ${error?.message ?? String(error)}`,
69
+ fix: 'Melde den Fehler an DealSystem. Bis dahin hilft es oft, die zuletzt geänderte Datei zu prüfen.',
70
+ };
71
+ }
72
+ /**
73
+ * Führt den Regelkatalog aus. Läuft ohne Netz und ohne Browser; liest nur Dateien, führt nichts aus dem
74
+ * Projekt aus. Der Build-Host ruft dieselbe Funktion auf (Quelle vor dem Build, Ausgabe danach).
75
+ */
76
+ export async function runCheck(options) {
77
+ if (options.ruleSetVersion !== undefined && options.ruleSetVersion !== RULE_SET_VERSION) {
78
+ throw new RuleSetMismatchError(options.ruleSetVersion, RULE_SET_VERSION);
79
+ }
80
+ const source = options.source ??
81
+ (options.projectDir ? createDirFileSet(options.projectDir, { ignoreDirs: IGNORED_DIRS }) : null);
82
+ const output = options.output ?? (options.outputDir ? createDirFileSet(options.outputDir, {}) : null);
83
+ const available = [
84
+ ...(source ? ['source'] : []),
85
+ ...(output ? ['output'] : []),
86
+ ];
87
+ const stages = options.stages ? available.filter((s) => options.stages.includes(s)) : available;
88
+ const disabled = new Set(options.disabledRules ?? []);
89
+ const findings = [];
90
+ const severityOf = (meta, raw) => options.severityOverrides?.[meta.id] ?? raw.severity ?? meta.severity;
91
+ const sourceCtx = source && stages.includes('source') ? new SourceContext(source, options) : null;
92
+ const outputCtx = output && stages.includes('output') ? new OutputContext(output, options) : null;
93
+ if (outputCtx) {
94
+ if (options.external)
95
+ outputCtx.declared = { external: options.external, strict: true };
96
+ else if (source) {
97
+ // Lokal (`check --output build`): Die Deklaration steht in der Quelle, auch wenn nur die Ausgabe läuft.
98
+ const src = sourceCtx ?? new SourceContext(source, options);
99
+ outputCtx.declared = {
100
+ external: src.siteConfig().data?.external ?? [],
101
+ strict: cspForm(src)?.kind === 'dealsystem',
102
+ };
103
+ }
104
+ }
105
+ for (const impl of RULE_IMPLEMENTATIONS) {
106
+ if (disabled.has(impl.id))
107
+ continue;
108
+ const meta = getRule(impl.id);
109
+ if (!meta)
110
+ throw new Error(`Regel ${impl.id} fehlt im Katalog.`);
111
+ let raws;
112
+ try {
113
+ if (impl.stage === 'source') {
114
+ if (!sourceCtx)
115
+ continue;
116
+ raws = impl.run(sourceCtx);
117
+ }
118
+ else {
119
+ if (!outputCtx)
120
+ continue;
121
+ raws = impl.run(outputCtx);
122
+ }
123
+ }
124
+ catch (error) {
125
+ raws = [crashFinding(meta, error)];
126
+ }
127
+ for (const raw of raws)
128
+ findings.push(normalize(meta, raw, severityOf(meta, raw)));
129
+ }
130
+ for (const plugin of options.plugins ?? []) {
131
+ const metas = new Map(plugin.meta.map((m) => [m.id, m]));
132
+ const raws = await plugin.run({ stages, source, output, options });
133
+ for (const raw of raws) {
134
+ const meta = metas.get(raw.rule) ?? getRule(raw.rule);
135
+ if (!meta || disabled.has(meta.id))
136
+ continue;
137
+ findings.push(normalize(meta, raw, severityOf(meta, raw)));
138
+ }
139
+ }
140
+ findings.sort(compareFindings);
141
+ // Gleiche Meldung an gleicher Stelle nur einmal.
142
+ const unique = findings.filter((f, i) => i === 0 || compareFindings(f, findings[i - 1]) !== 0 || f.severity !== findings[i - 1].severity);
143
+ const errors = unique.filter((f) => f.severity === 'error');
144
+ const warnings = unique.filter((f) => f.severity === 'warning');
145
+ return { passed: errors.length === 0, ruleSetVersion: RULE_SET_VERSION, stages, errors, warnings };
146
+ }
147
+ export { RULES };
@@ -0,0 +1,56 @@
1
+ export declare const SDK_PACKAGE = "@dealsystem/site";
2
+ export declare const COMPONENT: {
3
+ readonly leadForm: "LeadForm";
4
+ readonly text: "Text";
5
+ readonly richText: "RichText";
6
+ readonly link: "Link";
7
+ readonly mediaImage: "MediaImage";
8
+ readonly mediaVideo: "MediaVideo";
9
+ readonly collectionList: "CollectionList";
10
+ readonly map: "MapEmbed";
11
+ readonly embed: "Embed";
12
+ readonly externalScript: "ExternalScript";
13
+ readonly cookieBanner: "CookieBanner";
14
+ readonly consentGate: "ConsentGate";
15
+ readonly tracking: "Tracking";
16
+ readonly impressum: "Impressum";
17
+ readonly datenschutz: "Datenschutz";
18
+ readonly siteFooterLegal: "SiteFooterLegal";
19
+ readonly seo: "Seo";
20
+ readonly siteHead: "SiteHead";
21
+ };
22
+ /** Marker im gerenderten HTML (Attribute ohne Wert), gesetzt von den SDK-Komponenten. `ConsentGate` rendert
23
+ * beim Build nichts; der Cookie-Hinweis selbst entsteht erst im Browser, im HTML steht nur sein Marker. */
24
+ export declare const MARKER: {
25
+ readonly impressum: "data-ds-impressum";
26
+ readonly datenschutz: "data-ds-datenschutz";
27
+ readonly cookieBanner: "data-ds-cookie-banner";
28
+ readonly footerLegal: "data-ds-footer-legal";
29
+ readonly leadForm: "data-ds-lead-form";
30
+ readonly video: "data-ds-video";
31
+ readonly richText: "data-ds-richtext";
32
+ readonly image: "data-ds-image";
33
+ readonly collection: "data-ds-collection";
34
+ readonly map: "data-ds-map";
35
+ readonly slot: "data-ds-slot";
36
+ /** `<Embed>`: Schlüssel; dazu `data-ds-src` mit der Adresse des Rahmens (lädt nichts). */
37
+ readonly embed: "data-ds-embed";
38
+ /** `<ExternalScript>`: Schlüssel; dazu `data-ds-src` mit der Adresse des Skripts (lädt nichts). */
39
+ readonly externalScript: "data-ds-external-script";
40
+ readonly src: "data-ds-src";
41
+ };
42
+ /** Build-Helfer aus `@dealsystem/site/content`; laufen nur in `+page.server.ts`/`+layout.server.ts` mit `prerender = true`. */
43
+ export declare const CONTENT_MODULE = "@dealsystem/site/content";
44
+ export declare const CONFIG_MODULE = "@dealsystem/site/config";
45
+ export declare const VITE_MODULE = "@dealsystem/site/vite";
46
+ /** `dealsystemCsp()` aus diesem Modul erzeugt `kit.csp` aus `external` in dealsystem.config.ts (Regelsatz 3). */
47
+ export declare const CSP_MODULE = "@dealsystem/site/csp";
48
+ export declare const DEALSYSTEM_CSP_FN = "dealsystemCsp";
49
+ /** Helfer aus `@dealsystem/site/config`, der in `connect-src` die Adresse der Site-API einsetzt. */
50
+ export declare const SITE_API_ORIGIN_FN = "siteApiOrigin";
51
+ /** AGENTS.md-Block: Marker und Quelle im installierten SDK. */
52
+ export declare const AGENTS_BLOCK_BEGIN: RegExp;
53
+ export declare const AGENTS_BLOCK_END = "<!-- dealsystem:end -->";
54
+ export declare const AGENTS_BLOCK_SOURCE = "node_modules/@dealsystem/site/docs/agents-block.md";
55
+ /** Skills und Cursor-Regel des Starters im installierten SDK (`project/agentFiles.ts`). */
56
+ export declare const AGENT_FILES_SOURCE = "node_modules/@dealsystem/site/agent-files";
@@ -0,0 +1,58 @@
1
+ // Wie `check` die Komponenten von `@dealsystem/site` erkennt. Muss zu packages/site passen
2
+ // (Abstimmung mit P1-12). Im Quellcode zählt der Komponentenname, in der Ausgabe ein Marker-Attribut.
3
+ export const SDK_PACKAGE = '@dealsystem/site';
4
+ export const COMPONENT = {
5
+ leadForm: 'LeadForm',
6
+ text: 'Text',
7
+ richText: 'RichText',
8
+ link: 'Link',
9
+ mediaImage: 'MediaImage',
10
+ mediaVideo: 'MediaVideo',
11
+ collectionList: 'CollectionList',
12
+ map: 'MapEmbed',
13
+ embed: 'Embed',
14
+ externalScript: 'ExternalScript',
15
+ cookieBanner: 'CookieBanner',
16
+ consentGate: 'ConsentGate',
17
+ tracking: 'Tracking',
18
+ impressum: 'Impressum',
19
+ datenschutz: 'Datenschutz',
20
+ siteFooterLegal: 'SiteFooterLegal',
21
+ seo: 'Seo',
22
+ siteHead: 'SiteHead',
23
+ };
24
+ /** Marker im gerenderten HTML (Attribute ohne Wert), gesetzt von den SDK-Komponenten. `ConsentGate` rendert
25
+ * beim Build nichts; der Cookie-Hinweis selbst entsteht erst im Browser, im HTML steht nur sein Marker. */
26
+ export const MARKER = {
27
+ impressum: 'data-ds-impressum',
28
+ datenschutz: 'data-ds-datenschutz',
29
+ cookieBanner: 'data-ds-cookie-banner',
30
+ footerLegal: 'data-ds-footer-legal',
31
+ leadForm: 'data-ds-lead-form',
32
+ video: 'data-ds-video',
33
+ richText: 'data-ds-richtext',
34
+ image: 'data-ds-image',
35
+ collection: 'data-ds-collection',
36
+ map: 'data-ds-map',
37
+ slot: 'data-ds-slot',
38
+ /** `<Embed>`: Schlüssel; dazu `data-ds-src` mit der Adresse des Rahmens (lädt nichts). */
39
+ embed: 'data-ds-embed',
40
+ /** `<ExternalScript>`: Schlüssel; dazu `data-ds-src` mit der Adresse des Skripts (lädt nichts). */
41
+ externalScript: 'data-ds-external-script',
42
+ src: 'data-ds-src',
43
+ };
44
+ /** Build-Helfer aus `@dealsystem/site/content`; laufen nur in `+page.server.ts`/`+layout.server.ts` mit `prerender = true`. */
45
+ export const CONTENT_MODULE = '@dealsystem/site/content';
46
+ export const CONFIG_MODULE = '@dealsystem/site/config';
47
+ export const VITE_MODULE = '@dealsystem/site/vite';
48
+ /** `dealsystemCsp()` aus diesem Modul erzeugt `kit.csp` aus `external` in dealsystem.config.ts (Regelsatz 3). */
49
+ export const CSP_MODULE = '@dealsystem/site/csp';
50
+ export const DEALSYSTEM_CSP_FN = 'dealsystemCsp';
51
+ /** Helfer aus `@dealsystem/site/config`, der in `connect-src` die Adresse der Site-API einsetzt. */
52
+ export const SITE_API_ORIGIN_FN = 'siteApiOrigin';
53
+ /** AGENTS.md-Block: Marker und Quelle im installierten SDK. */
54
+ export const AGENTS_BLOCK_BEGIN = /<!--\s*dealsystem:begin\s+([^\s]+)\s*-->/;
55
+ export const AGENTS_BLOCK_END = '<!-- dealsystem:end -->';
56
+ export const AGENTS_BLOCK_SOURCE = 'node_modules/@dealsystem/site/docs/agents-block.md';
57
+ /** Skills und Cursor-Regel des Starters im installierten SDK (`project/agentFiles.ts`). */
58
+ export const AGENT_FILES_SOURCE = 'node_modules/@dealsystem/site/agent-files';