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,113 @@
1
+ // Gerätecode-Login (RFC 8628) gegen den Core: `/oauth/device_authorization` und `/oauth/token`.
2
+ // Vorgaben: docs/entscheidungen/geraetecode-login.md und Konzept 5.2 (Client `dealsystem-cli`).
3
+ import { CliError, EXIT } from './errors.js';
4
+ export const CLI_CLIENT_ID = 'dealsystem-cli';
5
+ export const CLI_SCOPES = 'website:read website:write offline_access';
6
+ function base(apiUrl) {
7
+ return apiUrl.replace(/\/+$/, '');
8
+ }
9
+ /** Audience der CLI-Tokens: `<issuer>/api/v1`. */
10
+ export function apiResource(apiUrl) {
11
+ return `${base(apiUrl)}/api/v1`;
12
+ }
13
+ async function postForm(fetchImpl, url, params) {
14
+ let res;
15
+ try {
16
+ res = await fetchImpl(url, {
17
+ method: 'POST',
18
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
19
+ body: new URLSearchParams(params).toString(),
20
+ });
21
+ }
22
+ catch (e) {
23
+ throw new CliError('network_error', `${url} ist nicht erreichbar (${e.message}).`, 'Prüfe die Internetverbindung und versuche es erneut.', EXIT.api);
24
+ }
25
+ let json = {};
26
+ try {
27
+ const parsed = (await res.json());
28
+ if (parsed && typeof parsed === 'object')
29
+ json = parsed;
30
+ }
31
+ catch {
32
+ // leer lassen
33
+ }
34
+ return { status: res.status, json };
35
+ }
36
+ function toTokens(json, now) {
37
+ const access = json.access_token;
38
+ if (typeof access !== 'string' || !access) {
39
+ throw new CliError('bad_response', 'Der Server hat keinen Zugangstoken geliefert.', 'Führe `npx dealsystem login` erneut aus.', EXIT.api);
40
+ }
41
+ const expiresIn = typeof json.expires_in === 'number' ? json.expires_in : 3600;
42
+ return {
43
+ accessToken: access,
44
+ refreshToken: typeof json.refresh_token === 'string' ? json.refresh_token : null,
45
+ expiresAt: now + expiresIn * 1000,
46
+ scope: typeof json.scope === 'string' ? json.scope : null,
47
+ };
48
+ }
49
+ function oauthFailure(json, status) {
50
+ const error = typeof json.error === 'string' ? json.error : `http_${status}`;
51
+ const description = typeof json.error_description === 'string' ? json.error_description : `Status ${status}`;
52
+ const fix = error === 'unauthorized_client' || error === 'invalid_client'
53
+ ? 'Der Server kennt den CLI-Zugang noch nicht. Prüfe `--api-url` oder melde es an DealSystem.'
54
+ : error === 'temporarily_unavailable' || status === 429
55
+ ? 'Warte eine Minute und versuche es erneut.'
56
+ : 'Führe `npx dealsystem login` erneut aus.';
57
+ return new CliError(`oauth_${error}`, `Anmeldung fehlgeschlagen: ${description}.`, fix, EXIT.auth);
58
+ }
59
+ export async function startDeviceAuthorization(apiUrl, fetchImpl) {
60
+ const { status, json } = await postForm(fetchImpl, `${base(apiUrl)}/oauth/device_authorization`, {
61
+ client_id: CLI_CLIENT_ID,
62
+ scope: CLI_SCOPES,
63
+ resource: apiResource(apiUrl),
64
+ });
65
+ if (status !== 200)
66
+ throw oauthFailure(json, status);
67
+ const s = (k) => (typeof json[k] === 'string' ? json[k] : '');
68
+ const n = (k, d) => (typeof json[k] === 'number' ? json[k] : d);
69
+ if (!s('device_code') || !s('user_code'))
70
+ throw oauthFailure(json, status);
71
+ return {
72
+ deviceCode: s('device_code'),
73
+ userCode: s('user_code'),
74
+ verificationUri: s('verification_uri'),
75
+ verificationUriComplete: s('verification_uri_complete') || s('verification_uri'),
76
+ expiresIn: n('expires_in', 900),
77
+ interval: n('interval', 5),
78
+ };
79
+ }
80
+ export async function pollDeviceToken(apiUrl, deviceCode, fetchImpl, now) {
81
+ const { status, json } = await postForm(fetchImpl, `${base(apiUrl)}/oauth/token`, {
82
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
83
+ device_code: deviceCode,
84
+ client_id: CLI_CLIENT_ID,
85
+ });
86
+ if (status === 200)
87
+ return { kind: 'tokens', tokens: toTokens(json, now) };
88
+ switch (json.error) {
89
+ case 'authorization_pending':
90
+ return { kind: 'pending' };
91
+ case 'slow_down':
92
+ return { kind: 'slow_down' };
93
+ case 'access_denied':
94
+ return { kind: 'denied' };
95
+ case 'expired_token':
96
+ return { kind: 'expired' };
97
+ default:
98
+ throw oauthFailure(json, status);
99
+ }
100
+ }
101
+ export async function refreshTokens(apiUrl, refreshToken, fetchImpl, now) {
102
+ const { status, json } = await postForm(fetchImpl, `${base(apiUrl)}/oauth/token`, {
103
+ grant_type: 'refresh_token',
104
+ refresh_token: refreshToken,
105
+ client_id: CLI_CLIENT_ID,
106
+ resource: apiResource(apiUrl),
107
+ });
108
+ if (status !== 200)
109
+ return null;
110
+ const tokens = toTokens(json, now);
111
+ // Refresh-Rotation: ohne neuen Refresh-Token bleibt der alte gültig.
112
+ return { ...tokens, refreshToken: tokens.refreshToken ?? refreshToken };
113
+ }
@@ -0,0 +1,142 @@
1
+ export interface Website {
2
+ id: string;
3
+ name: string;
4
+ slug: string;
5
+ status: string;
6
+ liveVersionId: string | null;
7
+ /** Standard-Host `<slug>.<SITES_DOMAIN>`, falls der Core ihn mitliefert. */
8
+ defaultHost: string | null;
9
+ /** Aktive Hauptdomain, sonst `null`. */
10
+ primaryHost: string | null;
11
+ }
12
+ export interface WebsiteDomain {
13
+ host: string;
14
+ kind: string;
15
+ active: boolean;
16
+ }
17
+ export interface WebsiteDetails extends Website {
18
+ domains: WebsiteDomain[];
19
+ liveVersion: VersionSummary | null;
20
+ /**
21
+ * Pflichtangaben für Rechtstexte, die im CRM noch fehlen (`legalProfileMissing`: `company`, `email`,
22
+ * `imprintHtml`, `privacyHtml`); leer = vollständig. `null`, wenn der Server das Feld nicht liefert.
23
+ */
24
+ legalProfileMissing: string[] | null;
25
+ }
26
+ export interface CheckFinding {
27
+ rule: string;
28
+ file: string | null;
29
+ line: number | null;
30
+ message: string;
31
+ fix: string | null;
32
+ }
33
+ export interface VersionCheckResult {
34
+ passed: boolean;
35
+ ruleSetVersion: string;
36
+ errors: CheckFinding[];
37
+ warnings: CheckFinding[];
38
+ }
39
+ export interface VersionSummary {
40
+ id: string;
41
+ number: number;
42
+ status: string;
43
+ trigger: string;
44
+ message: string | null;
45
+ createdAt: string | null;
46
+ previewUrl: string | null;
47
+ }
48
+ export interface Version extends VersionSummary {
49
+ checkResult: VersionCheckResult | null;
50
+ /** Auszug aus dem Build-Log; fremder Text, nur anzeigen. */
51
+ logExcerpt: string | null;
52
+ }
53
+ export interface PreparedUpload {
54
+ versionId: string;
55
+ uploadUrl: string;
56
+ /** Laut Vertrag immer `PUT`. */
57
+ uploadMethod: string;
58
+ expiresAt: string | null;
59
+ /** Header, die der signierte Upload genau so verlangt (`Content-Length` ist mitsigniert). */
60
+ uploadHeaders: Record<string, string>;
61
+ }
62
+ /** Quellpaket einer Version (`GET …/versions/{id}/source`). */
63
+ export interface SourceDownload {
64
+ versionId: string;
65
+ versionNumber: number;
66
+ /** `content` = Inhalts-Version; geliefert wird dann der Code von `codeVersion*`. */
67
+ trigger: string;
68
+ codeVersionId: string;
69
+ codeVersionNumber: number | null;
70
+ sha256: string;
71
+ bytes: number;
72
+ /** Signierte Adresse, kurz gültig; ohne Anmelde-Header abrufen. */
73
+ url: string;
74
+ expiresAt: string | null;
75
+ }
76
+ export interface ReleaseResult {
77
+ liveVersionId: string;
78
+ /** `false`, wenn die Version schon live war (`release: null`). */
79
+ changed: boolean;
80
+ url: string | null;
81
+ }
82
+ export interface DeployApi {
83
+ listWebsites(): Promise<Website[]>;
84
+ createWebsite(input: {
85
+ name: string;
86
+ slug: string;
87
+ }): Promise<Website>;
88
+ getWebsite(id: string): Promise<WebsiteDetails>;
89
+ getContent(id: string): Promise<unknown>;
90
+ listVersions(id: string, limit?: number): Promise<VersionSummary[]>;
91
+ prepareUpload(id: string, input: {
92
+ sha256: string;
93
+ bytes: number;
94
+ message?: string;
95
+ }): Promise<PreparedUpload>;
96
+ uploadSource(upload: PreparedUpload, body: Uint8Array): Promise<void>;
97
+ completeUpload(id: string, versionId: string): Promise<Version>;
98
+ getVersion(id: string, versionId: string): Promise<Version>;
99
+ publish(id: string, versionId: string): Promise<ReleaseResult>;
100
+ rollback(id: string, versionId?: string): Promise<ReleaseResult>;
101
+ /** Signierte Download-Adresse des Quellpakets (Recht „Website verwalten“). */
102
+ getSourceDownload(id: string, versionId: string): Promise<SourceDownload>;
103
+ /** Lädt das Quellpaket; bricht ab, sobald mehr als `maxBytes` kommen. */
104
+ downloadSource(source: SourceDownload, maxBytes: number): Promise<Uint8Array>;
105
+ /** Website-Texte und Bild-Plätze der Seite (`GET /websites/{id}/slots`). */
106
+ listSlots(id: string): Promise<WebsiteSlot[]>;
107
+ /** Foto für einen Bild-Platz, Schritt 1: signierte PUT-Adresse (`POST /websites/{id}/media`). */
108
+ prepareImageUpload(id: string, input: {
109
+ slotKey: string;
110
+ bytes: number;
111
+ }): Promise<PreparedImageUpload>;
112
+ /** Lädt das Foto an die signierte Adresse (ohne Authorization-Header). */
113
+ uploadImage(upload: PreparedImageUpload, body: Uint8Array): Promise<void>;
114
+ /** Schritt 2: Foto auf den Bild-Platz setzen (`POST /websites/{id}/media/{uploadId}/complete`). */
115
+ completeImageUpload(id: string, uploadId: string, input: {
116
+ slotKey: string;
117
+ alt: string;
118
+ }): Promise<WebsiteSlot | null>;
119
+ /** Probe-Einsendung aus `dealsystem dev` (immer `dryRun` im Core). Antwort wird unverändert durchgereicht. */
120
+ devLead(id: string, body: unknown): Promise<{
121
+ status: number;
122
+ body: unknown;
123
+ }>;
124
+ }
125
+ /** Endzustände einer Version. */
126
+ export declare const SETTLED_VERSION_STATUSES: ReadonlySet<string>;
127
+ /** Ein Website-Text oder Bild-Platz, wie `GET /websites/{id}/slots` ihn liefert (nur, was die CLI braucht). */
128
+ export interface WebsiteSlot {
129
+ key: string;
130
+ type: string;
131
+ label: string;
132
+ inUse: boolean;
133
+ overridden: boolean;
134
+ mediaId: string | null;
135
+ }
136
+ export interface PreparedImageUpload {
137
+ uploadId: string;
138
+ url: string;
139
+ method: string;
140
+ headers: Record<string, string>;
141
+ expiresAt: string | null;
142
+ }
@@ -0,0 +1,9 @@
1
+ // Vertrag der Verwaltungs- und Deploy-API (Konzept 5.2, `/api/v1/websites/…`). Die CLI hängt nur an
2
+ // diesem Interface; `HttpDeployApi` ist die einzige Implementierung gegen HTTP, Tests nutzen einen Mock-Server.
3
+ /** Endzustände einer Version. */
4
+ export const SETTLED_VERSION_STATUSES = new Set([
5
+ 'ready',
6
+ 'rejected',
7
+ 'failed',
8
+ 'expired',
9
+ ]);
@@ -0,0 +1,28 @@
1
+ import type { TokenSet } from '../api/oauth.js';
2
+ export interface StoredAccount extends TokenSet {
3
+ apiUrl: string;
4
+ savedAt: string;
5
+ }
6
+ export interface PendingLogin {
7
+ apiUrl: string;
8
+ deviceCode: string;
9
+ userCode: string;
10
+ verificationUriComplete: string;
11
+ interval: number;
12
+ /** Unix-Millisekunden. */
13
+ expiresAt: number;
14
+ }
15
+ export declare function configDir(env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
16
+ export declare class CredentialStore {
17
+ readonly dir: string;
18
+ constructor(env: NodeJS.ProcessEnv);
19
+ get credentialsPath(): string;
20
+ get pendingPath(): string;
21
+ private read;
22
+ get(apiUrl: string): StoredAccount | null;
23
+ save(apiUrl: string, tokens: TokenSet, now: Date): StoredAccount;
24
+ remove(apiUrl: string): boolean;
25
+ savePending(pending: PendingLogin): void;
26
+ readPending(): PendingLogin | null;
27
+ clearPending(): void;
28
+ }
@@ -0,0 +1,96 @@
1
+ // Tokens liegen im Benutzerprofil, nie im Projekt (sonst landen sie im Upload oder im Git).
2
+ // Datei 0600, Ordner 0700. Geschrieben wird atomar (temporäre Datei + rename).
3
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ export function configDir(env, platform = process.platform) {
7
+ if (env.DEALSYSTEM_CONFIG_DIR)
8
+ return env.DEALSYSTEM_CONFIG_DIR;
9
+ if (platform === 'win32' && env.APPDATA)
10
+ return join(env.APPDATA, 'dealsystem');
11
+ if (platform === 'darwin')
12
+ return join(homedir(), 'Library', 'Application Support', 'dealsystem');
13
+ return join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'dealsystem');
14
+ }
15
+ function writePrivate(path, content) {
16
+ const tmp = `${path}.${process.pid}.tmp`;
17
+ writeFileSync(tmp, content, { mode: 0o600 });
18
+ chmodSync(tmp, 0o600);
19
+ renameSync(tmp, path);
20
+ chmodSync(path, 0o600);
21
+ }
22
+ function ensureDir(dir) {
23
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
24
+ try {
25
+ chmodSync(dir, 0o700);
26
+ }
27
+ catch {
28
+ // Windows kennt keine Unix-Rechte.
29
+ }
30
+ }
31
+ function normalizeApiUrl(apiUrl) {
32
+ return apiUrl.replace(/\/+$/, '');
33
+ }
34
+ export class CredentialStore {
35
+ dir;
36
+ constructor(env) {
37
+ this.dir = configDir(env);
38
+ }
39
+ get credentialsPath() {
40
+ return join(this.dir, 'credentials.json');
41
+ }
42
+ get pendingPath() {
43
+ return join(this.dir, 'pending-login.json');
44
+ }
45
+ read() {
46
+ try {
47
+ const data = JSON.parse(readFileSync(this.credentialsPath, 'utf8'));
48
+ if (data.version === 1 && data.accounts && typeof data.accounts === 'object')
49
+ return data;
50
+ }
51
+ catch {
52
+ // fehlt oder kaputt → leer
53
+ }
54
+ return { version: 1, accounts: {} };
55
+ }
56
+ get(apiUrl) {
57
+ return this.read().accounts[normalizeApiUrl(apiUrl)] ?? null;
58
+ }
59
+ save(apiUrl, tokens, now) {
60
+ ensureDir(this.dir);
61
+ const file = this.read();
62
+ const account = { ...tokens, apiUrl: normalizeApiUrl(apiUrl), savedAt: now.toISOString() };
63
+ file.accounts[account.apiUrl] = account;
64
+ writePrivate(this.credentialsPath, `${JSON.stringify(file, null, '\t')}\n`);
65
+ return account;
66
+ }
67
+ remove(apiUrl) {
68
+ const file = this.read();
69
+ const key = normalizeApiUrl(apiUrl);
70
+ if (!file.accounts[key])
71
+ return false;
72
+ delete file.accounts[key];
73
+ if (Object.keys(file.accounts).length === 0)
74
+ rmSync(this.credentialsPath, { force: true });
75
+ else
76
+ writePrivate(this.credentialsPath, `${JSON.stringify(file, null, '\t')}\n`);
77
+ return true;
78
+ }
79
+ savePending(pending) {
80
+ ensureDir(this.dir);
81
+ writePrivate(this.pendingPath, `${JSON.stringify(pending, null, '\t')}\n`);
82
+ }
83
+ readPending() {
84
+ if (!existsSync(this.pendingPath))
85
+ return null;
86
+ try {
87
+ return JSON.parse(readFileSync(this.pendingPath, 'utf8'));
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ clearPending() {
94
+ rmSync(this.pendingPath, { force: true });
95
+ }
96
+ }
@@ -0,0 +1,10 @@
1
+ import type { FetchLike, TokenProvider } from '../api/http.js';
2
+ import type { CredentialStore } from './credentials.js';
3
+ export interface SessionDeps {
4
+ apiUrl: string;
5
+ env: NodeJS.ProcessEnv;
6
+ store: CredentialStore;
7
+ fetch: FetchLike;
8
+ now: () => Date;
9
+ }
10
+ export declare function createTokenProvider(deps: SessionDeps): TokenProvider;
@@ -0,0 +1,46 @@
1
+ // Liefert einen gültigen Token: aus `DEALSYSTEM_TOKEN` (API-Schlüssel für eigene CI) oder aus dem
2
+ // gespeicherten Login, bei Bedarf per Refresh-Token erneuert.
3
+ import { notLoggedIn } from '../api/errors.js';
4
+ import { refreshTokens } from '../api/oauth.js';
5
+ /** Token gilt als abgelaufen, wenn er in weniger als einer Minute abläuft. */
6
+ const EXPIRY_MARGIN_MS = 60_000;
7
+ export function createTokenProvider(deps) {
8
+ const fromEnv = deps.env.DEALSYSTEM_TOKEN?.trim();
9
+ if (fromEnv) {
10
+ return { getToken: async () => fromEnv, refresh: async () => null };
11
+ }
12
+ // Refresh-Rotation: ein Refresh-Token gilt genau einmal. Parallele Anfragen dürfen deshalb nur eine
13
+ // Auffrischung auslösen und teilen sich deren Ergebnis.
14
+ let inflight = null;
15
+ const doRefresh = async () => {
16
+ const account = deps.store.get(deps.apiUrl);
17
+ if (!account?.refreshToken)
18
+ return null;
19
+ const now = deps.now();
20
+ const tokens = await refreshTokens(deps.apiUrl, account.refreshToken, deps.fetch, now.getTime());
21
+ if (!tokens)
22
+ return null;
23
+ deps.store.save(deps.apiUrl, tokens, now);
24
+ return tokens.accessToken;
25
+ };
26
+ const refresh = () => {
27
+ inflight ??= doRefresh().finally(() => {
28
+ inflight = null;
29
+ });
30
+ return inflight;
31
+ };
32
+ return {
33
+ async getToken() {
34
+ const account = deps.store.get(deps.apiUrl);
35
+ if (!account)
36
+ throw notLoggedIn();
37
+ if (account.expiresAt - EXPIRY_MARGIN_MS > deps.now().getTime())
38
+ return account.accessToken;
39
+ const fresh = await refresh();
40
+ if (!fresh)
41
+ throw notLoggedIn();
42
+ return fresh;
43
+ },
44
+ refresh,
45
+ };
46
+ }
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from './cli/main.js';
3
+ import { nodeIO } from './cli/io.js';
4
+ process.exitCode = await run(process.argv.slice(2), nodeIO());
@@ -0,0 +1,9 @@
1
+ export interface AllowedPackage {
2
+ /** Paketname oder Präfix mit `*` am Ende (`@fontsource/*`). */
3
+ name: string;
4
+ reason: string;
5
+ }
6
+ export declare const ALLOWED_PACKAGES: readonly AllowedPackage[];
7
+ /** Häufige Pakete, die nicht freigegeben sind, mit Alternative für die Meldung. */
8
+ export declare const ALTERNATIVES: Readonly<Record<string, string>>;
9
+ export declare function isAllowedPackage(name: string): boolean;
@@ -0,0 +1,74 @@
1
+ // Positiv-Liste der direkten Abhängigkeiten (DEP-001). Versioniert im SDK-Repo; der Build-Host nimmt die
2
+ // Liste aus seinem eigenen Image. Neue Einträge nur nach Prüfung: kein Laufzeit-Netzverkehr zu Dritten,
3
+ // keine Installationsskripte, die für den Build nötig wären (`npm ci --ignore-scripts`).
4
+ export const ALLOWED_PACKAGES = [
5
+ { name: '@dealsystem/site', reason: 'DealSystem-SDK' },
6
+ { name: 'dealsystem', reason: 'DealSystem-CLI' },
7
+ { name: '@sveltejs/kit', reason: 'SvelteKit' },
8
+ { name: '@sveltejs/adapter-static', reason: 'statischer Build' },
9
+ { name: '@sveltejs/vite-plugin-svelte', reason: 'Svelte für Vite' },
10
+ { name: '@sveltejs/enhanced-img', reason: 'Bilder in WebP/AVIF mit srcset' },
11
+ { name: 'svelte', reason: 'Svelte' },
12
+ { name: 'vite', reason: 'Build' },
13
+ { name: 'typescript', reason: 'Typen' },
14
+ { name: 'tslib', reason: 'Typen' },
15
+ { name: 'svelte-check', reason: 'Typprüfung' },
16
+ { name: '@types/node', reason: 'Typen' },
17
+ { name: 'tailwindcss', reason: 'CSS' },
18
+ { name: '@tailwindcss/vite', reason: 'CSS' },
19
+ { name: '@tailwindcss/typography', reason: 'CSS' },
20
+ { name: '@tailwindcss/forms', reason: 'CSS' },
21
+ { name: 'postcss', reason: 'CSS' },
22
+ { name: 'autoprefixer', reason: 'CSS' },
23
+ { name: 'sass', reason: 'CSS' },
24
+ { name: 'clsx', reason: 'CSS-Klassen' },
25
+ { name: 'tailwind-merge', reason: 'CSS-Klassen' },
26
+ { name: '@fontsource/*', reason: 'lokale Schriften' },
27
+ { name: '@fontsource-variable/*', reason: 'lokale Schriften' },
28
+ { name: '@lucide/svelte', reason: 'Icons' },
29
+ { name: 'lucide-svelte', reason: 'Icons' },
30
+ { name: '@iconify/svelte', reason: 'Icons (nur mit lokal gebündelten Icons)' },
31
+ { name: 'embla-carousel', reason: 'Karussell' },
32
+ { name: 'embla-carousel-svelte', reason: 'Karussell' },
33
+ { name: 'date-fns', reason: 'Datumsformat' },
34
+ { name: 'prettier', reason: 'Formatierung' },
35
+ { name: 'prettier-plugin-svelte', reason: 'Formatierung' },
36
+ { name: 'prettier-plugin-tailwindcss', reason: 'Formatierung' },
37
+ { name: 'eslint', reason: 'Linter' },
38
+ { name: '@eslint/js', reason: 'Linter' },
39
+ { name: 'eslint-plugin-svelte', reason: 'Linter' },
40
+ { name: 'typescript-eslint', reason: 'Linter' },
41
+ { name: 'globals', reason: 'Linter' },
42
+ ];
43
+ /** Häufige Pakete, die nicht freigegeben sind, mit Alternative für die Meldung. */
44
+ export const ALTERNATIVES = {
45
+ '@sveltejs/adapter-auto': '`@sveltejs/adapter-static`',
46
+ '@sveltejs/adapter-node': '`@sveltejs/adapter-static`',
47
+ '@sveltejs/adapter-vercel': '`@sveltejs/adapter-static`',
48
+ '@sveltejs/adapter-netlify': '`@sveltejs/adapter-static`',
49
+ '@sveltejs/adapter-cloudflare': '`@sveltejs/adapter-static`',
50
+ axios: 'nichts: die Seite ruft keine APIs auf. Formulare über `<LeadForm>`, Inhalte über `getCollection()`',
51
+ 'node-fetch': 'nichts: die Seite ruft keine APIs auf',
52
+ dotenv: 'nichts: eine statische Seite hat keine Secrets',
53
+ react: 'Svelte',
54
+ 'react-dom': 'Svelte',
55
+ vue: 'Svelte',
56
+ jquery: 'Svelte',
57
+ bootstrap: '`tailwindcss`',
58
+ marked: '`<RichText>`',
59
+ 'markdown-it': '`<RichText>`',
60
+ dompurify: '`<RichText>`',
61
+ '@emailjs/browser': '`<LeadForm>`',
62
+ '@formspree/svelte': '`<LeadForm>`',
63
+ webfontloader: '`@fontsource/<name>`',
64
+ 'google-fonts': '`@fontsource/<name>`',
65
+ 'react-ga': '`<ConsentGate><Tracking /></ConsentGate>`',
66
+ 'react-ga4': '`<ConsentGate><Tracking /></ConsentGate>`',
67
+ 'svelte-gtag': '`<ConsentGate><Tracking /></ConsentGate>`',
68
+ swiper: '`embla-carousel-svelte`',
69
+ 'lucide-react': '`@lucide/svelte`',
70
+ moment: '`date-fns`',
71
+ };
72
+ export function isAllowedPackage(name) {
73
+ return ALLOWED_PACKAGES.some((p) => p.name.endsWith('/*') ? name.startsWith(p.name.slice(0, -1)) : p.name === name);
74
+ }
@@ -0,0 +1,6 @@
1
+ import type { RuleMeta } from './types.js';
2
+ export declare const RULE_SET_VERSION = "3";
3
+ /** Bereich von `@dealsystem/site`, den dieser Regelkatalog kennt. Der Build-Host gibt seinen eigenen mit. */
4
+ export declare const DEFAULT_SDK_RANGE = ">=0.1.0 <2.0.0";
5
+ export declare const RULES: readonly RuleMeta[];
6
+ export declare function getRule(id: string): RuleMeta | undefined;