@shieldaai/security-watch 0.0.0-stage → 0.1.0-alpha.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 (62) hide show
  1. package/CONTRIBUTING.md +90 -0
  2. package/LICENSE +202 -0
  3. package/README.md +269 -2
  4. package/SECURITY.md +47 -0
  5. package/dist/assessment.d.ts +5 -0
  6. package/dist/assessment.js +398 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.js +792 -0
  9. package/dist/config.d.ts +242 -0
  10. package/dist/config.js +298 -0
  11. package/dist/cve-now.d.ts +5 -0
  12. package/dist/cve-now.js +413 -0
  13. package/dist/delivery.d.ts +26 -0
  14. package/dist/delivery.js +394 -0
  15. package/dist/ecosystems.d.ts +25 -0
  16. package/dist/ecosystems.js +254 -0
  17. package/dist/engine.d.ts +26 -0
  18. package/dist/engine.js +307 -0
  19. package/dist/health.d.ts +17 -0
  20. package/dist/health.js +70 -0
  21. package/dist/heartbeat.d.ts +13 -0
  22. package/dist/heartbeat.js +74 -0
  23. package/dist/http.d.ts +8 -0
  24. package/dist/http.js +251 -0
  25. package/dist/index.d.ts +18 -0
  26. package/dist/index.js +15 -0
  27. package/dist/inventory.d.ts +3 -0
  28. package/dist/inventory.js +143 -0
  29. package/dist/lock.d.ts +3 -0
  30. package/dist/lock.js +112 -0
  31. package/dist/maintenance.d.ts +43 -0
  32. package/dist/maintenance.js +227 -0
  33. package/dist/models.d.ts +20 -0
  34. package/dist/models.js +602 -0
  35. package/dist/operations.d.ts +17 -0
  36. package/dist/operations.js +117 -0
  37. package/dist/providers.d.ts +209 -0
  38. package/dist/providers.js +459 -0
  39. package/dist/setup.d.ts +113 -0
  40. package/dist/setup.js +100 -0
  41. package/dist/source-error.d.ts +22 -0
  42. package/dist/source-error.js +56 -0
  43. package/dist/sources.d.ts +3 -0
  44. package/dist/sources.js +1071 -0
  45. package/dist/store.d.ts +71 -0
  46. package/dist/store.js +651 -0
  47. package/dist/types.d.ts +247 -0
  48. package/dist/types.js +1 -0
  49. package/dist/util.d.ts +6 -0
  50. package/dist/util.js +14 -0
  51. package/dist/vendor-sources.d.ts +24 -0
  52. package/dist/vendor-sources.js +56 -0
  53. package/docs/configuration.md +406 -0
  54. package/docs/quality-review.md +104 -0
  55. package/examples/advisories.json +17 -0
  56. package/examples/common-systems.yaml +243 -0
  57. package/examples/libraries.example.txt +16 -0
  58. package/examples/libraries.example.yaml +38 -0
  59. package/examples/library-watch.example.yaml +27 -0
  60. package/examples/security-watch.example.yaml +86 -0
  61. package/examples/systems.example.yaml +31 -0
  62. package/package.json +69 -4
@@ -0,0 +1,242 @@
1
+ import { z } from 'zod';
2
+ import type { Config } from './types.js';
3
+ export declare const configSchema: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ inventory: z.ZodDefault<z.ZodString>;
6
+ database: z.ZodDefault<z.ZodString>;
7
+ poll_interval_minutes: z.ZodDefault<z.ZodNumber>;
8
+ news_lookback_minutes: z.ZodDefault<z.ZodNumber>;
9
+ inventory_stale_days: z.ZodDefault<z.ZodNumber>;
10
+ digest_interval_hours: z.ZodDefault<z.ZodNumber>;
11
+ sources: z.ZodDefault<z.ZodObject<{
12
+ cve_now: z.ZodDefault<z.ZodBoolean>;
13
+ hacker_news: z.ZodDefault<z.ZodBoolean>;
14
+ osv: z.ZodDefault<z.ZodBoolean>;
15
+ github: z.ZodDefault<z.ZodBoolean>;
16
+ github_token_env: z.ZodDefault<z.ZodString>;
17
+ kev: z.ZodDefault<z.ZodBoolean>;
18
+ feeds: z.ZodDefault<z.ZodArray<z.ZodURL>>;
19
+ vendor_feeds: z.ZodDefault<z.ZodArray<z.ZodEnum<{
20
+ nodejs: "nodejs";
21
+ php: "php";
22
+ python: "python";
23
+ }>>>;
24
+ }, z.core.$strict>>;
25
+ models: z.ZodDefault<z.ZodObject<{
26
+ enabled: z.ZodDefault<z.ZodBoolean>;
27
+ analysis: z.ZodOptional<z.ZodPipe<z.ZodObject<{
28
+ provider: z.ZodEnum<{
29
+ anthropic: "anthropic";
30
+ "azure-openai": "azure-openai";
31
+ cerebras: "cerebras";
32
+ cohere: "cohere";
33
+ deepseek: "deepseek";
34
+ fireworks: "fireworks";
35
+ gemini: "gemini";
36
+ groq: "groq";
37
+ huggingface: "huggingface";
38
+ litellm: "litellm";
39
+ lmstudio: "lmstudio";
40
+ mistral: "mistral";
41
+ nvidia: "nvidia";
42
+ ollama: "ollama";
43
+ openai: "openai";
44
+ "openai-compatible": "openai-compatible";
45
+ openrouter: "openrouter";
46
+ perplexity: "perplexity";
47
+ sambanova: "sambanova";
48
+ together: "together";
49
+ vllm: "vllm";
50
+ xai: "xai";
51
+ }>;
52
+ output_format: z.ZodDefault<z.ZodEnum<{
53
+ auto: "auto";
54
+ json_object: "json_object";
55
+ json_schema: "json_schema";
56
+ prompt: "prompt";
57
+ }>>;
58
+ model: z.ZodString;
59
+ api_key_env: z.ZodOptional<z.ZodString>;
60
+ endpoint: z.ZodOptional<z.ZodURL>;
61
+ allow_private_endpoint: z.ZodDefault<z.ZodBoolean>;
62
+ input_usd_per_million: z.ZodOptional<z.ZodNumber>;
63
+ output_usd_per_million: z.ZodOptional<z.ZodNumber>;
64
+ }, z.core.$strict>, z.ZodTransform<{
65
+ provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
66
+ output_format: "auto" | "json_object" | "json_schema" | "prompt";
67
+ model: string;
68
+ endpoint?: string | undefined;
69
+ allow_private_endpoint: boolean;
70
+ input_usd_per_million?: number | undefined;
71
+ output_usd_per_million?: number | undefined;
72
+ api_key_env: string;
73
+ }, {
74
+ provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
75
+ output_format: "auto" | "json_object" | "json_schema" | "prompt";
76
+ model: string;
77
+ api_key_env?: string | undefined;
78
+ endpoint?: string | undefined;
79
+ allow_private_endpoint: boolean;
80
+ input_usd_per_million?: number | undefined;
81
+ output_usd_per_million?: number | undefined;
82
+ }>>>;
83
+ verification: z.ZodOptional<z.ZodPipe<z.ZodObject<{
84
+ provider: z.ZodEnum<{
85
+ anthropic: "anthropic";
86
+ "azure-openai": "azure-openai";
87
+ cerebras: "cerebras";
88
+ cohere: "cohere";
89
+ deepseek: "deepseek";
90
+ fireworks: "fireworks";
91
+ gemini: "gemini";
92
+ groq: "groq";
93
+ huggingface: "huggingface";
94
+ litellm: "litellm";
95
+ lmstudio: "lmstudio";
96
+ mistral: "mistral";
97
+ nvidia: "nvidia";
98
+ ollama: "ollama";
99
+ openai: "openai";
100
+ "openai-compatible": "openai-compatible";
101
+ openrouter: "openrouter";
102
+ perplexity: "perplexity";
103
+ sambanova: "sambanova";
104
+ together: "together";
105
+ vllm: "vllm";
106
+ xai: "xai";
107
+ }>;
108
+ output_format: z.ZodDefault<z.ZodEnum<{
109
+ auto: "auto";
110
+ json_object: "json_object";
111
+ json_schema: "json_schema";
112
+ prompt: "prompt";
113
+ }>>;
114
+ model: z.ZodString;
115
+ api_key_env: z.ZodOptional<z.ZodString>;
116
+ endpoint: z.ZodOptional<z.ZodURL>;
117
+ allow_private_endpoint: z.ZodDefault<z.ZodBoolean>;
118
+ input_usd_per_million: z.ZodOptional<z.ZodNumber>;
119
+ output_usd_per_million: z.ZodOptional<z.ZodNumber>;
120
+ }, z.core.$strict>, z.ZodTransform<{
121
+ provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
122
+ output_format: "auto" | "json_object" | "json_schema" | "prompt";
123
+ model: string;
124
+ endpoint?: string | undefined;
125
+ allow_private_endpoint: boolean;
126
+ input_usd_per_million?: number | undefined;
127
+ output_usd_per_million?: number | undefined;
128
+ api_key_env: string;
129
+ }, {
130
+ provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
131
+ output_format: "auto" | "json_object" | "json_schema" | "prompt";
132
+ model: string;
133
+ api_key_env?: string | undefined;
134
+ endpoint?: string | undefined;
135
+ allow_private_endpoint: boolean;
136
+ input_usd_per_million?: number | undefined;
137
+ output_usd_per_million?: number | undefined;
138
+ }>>>;
139
+ daily_request_limit: z.ZodDefault<z.ZodNumber>;
140
+ daily_token_limit: z.ZodDefault<z.ZodNumber>;
141
+ daily_budget_usd: z.ZodOptional<z.ZodNumber>;
142
+ max_input_chars: z.ZodDefault<z.ZodNumber>;
143
+ max_output_tokens: z.ZodDefault<z.ZodNumber>;
144
+ timeout_seconds: z.ZodDefault<z.ZodNumber>;
145
+ }, z.core.$strict>>;
146
+ policy: z.ZodDefault<z.ZodObject<{
147
+ library: z.ZodDefault<z.ZodObject<{
148
+ levels: z.ZodArray<z.ZodEnum<{
149
+ critical: "critical";
150
+ high: "high";
151
+ low: "low";
152
+ medium: "medium";
153
+ unknown: "unknown";
154
+ }>>;
155
+ basis: z.ZodDefault<z.ZodEnum<{
156
+ priority: "priority";
157
+ source_severity: "source_severity";
158
+ }>>;
159
+ channels: z.ZodDefault<z.ZodArray<z.ZodEnum<{
160
+ email: "email";
161
+ slack: "slack";
162
+ }>>>;
163
+ }, z.core.$strict>>;
164
+ product: z.ZodDefault<z.ZodObject<{
165
+ levels: z.ZodArray<z.ZodEnum<{
166
+ critical: "critical";
167
+ high: "high";
168
+ low: "low";
169
+ medium: "medium";
170
+ unknown: "unknown";
171
+ }>>;
172
+ basis: z.ZodDefault<z.ZodEnum<{
173
+ priority: "priority";
174
+ source_severity: "source_severity";
175
+ }>>;
176
+ channels: z.ZodDefault<z.ZodArray<z.ZodEnum<{
177
+ email: "email";
178
+ slack: "slack";
179
+ }>>>;
180
+ }, z.core.$strict>>;
181
+ news: z.ZodDefault<z.ZodObject<{
182
+ levels: z.ZodArray<z.ZodEnum<{
183
+ critical: "critical";
184
+ high: "high";
185
+ low: "low";
186
+ medium: "medium";
187
+ unknown: "unknown";
188
+ }>>;
189
+ basis: z.ZodDefault<z.ZodEnum<{
190
+ priority: "priority";
191
+ source_severity: "source_severity";
192
+ }>>;
193
+ channels: z.ZodDefault<z.ZodArray<z.ZodEnum<{
194
+ email: "email";
195
+ slack: "slack";
196
+ }>>>;
197
+ }, z.core.$strict>>;
198
+ urgent_unknown: z.ZodDefault<z.ZodBoolean>;
199
+ exploited_override: z.ZodDefault<z.ZodBoolean>;
200
+ malware_override: z.ZodDefault<z.ZodBoolean>;
201
+ health_channels: z.ZodDefault<z.ZodArray<z.ZodEnum<{
202
+ email: "email";
203
+ slack: "slack";
204
+ }>>>;
205
+ }, z.core.$strict>>;
206
+ notifications: z.ZodDefault<z.ZodObject<{
207
+ slack: z.ZodOptional<z.ZodObject<{
208
+ webhook_url_env: z.ZodString;
209
+ }, z.core.$strict>>;
210
+ email: z.ZodOptional<z.ZodObject<{
211
+ smtp_url_env: z.ZodString;
212
+ from: z.ZodEmail;
213
+ to: z.ZodArray<z.ZodEmail>;
214
+ }, z.core.$strict>>;
215
+ max_attempts: z.ZodDefault<z.ZodNumber>;
216
+ }, z.core.$strict>>;
217
+ monitoring: z.ZodOptional<z.ZodObject<{
218
+ heartbeat_url_env: z.ZodString;
219
+ interval_seconds: z.ZodDefault<z.ZodNumber>;
220
+ allow_private_endpoint: z.ZodDefault<z.ZodBoolean>;
221
+ }, z.core.$strict>>;
222
+ maintenance: z.ZodOptional<z.ZodObject<{
223
+ interval_hours: z.ZodDefault<z.ZodNumber>;
224
+ retention: z.ZodOptional<z.ZodObject<{
225
+ analysis_cache_days: z.ZodOptional<z.ZodNumber>;
226
+ evidence_history_days: z.ZodOptional<z.ZodNumber>;
227
+ finding_history_days: z.ZodOptional<z.ZodNumber>;
228
+ accepted_delivery_days: z.ZodOptional<z.ZodNumber>;
229
+ inactive_findings_days: z.ZodOptional<z.ZodNumber>;
230
+ unreferenced_evidence_days: z.ZodOptional<z.ZodNumber>;
231
+ batch_size: z.ZodDefault<z.ZodNumber>;
232
+ }, z.core.$strict>>;
233
+ backup: z.ZodOptional<z.ZodObject<{
234
+ directory: z.ZodString;
235
+ keep: z.ZodDefault<z.ZodNumber>;
236
+ max_bytes: z.ZodDefault<z.ZodNumber>;
237
+ }, z.core.$strict>>;
238
+ }, z.core.$strict>>;
239
+ }, z.core.$strict>;
240
+ export declare function parseConfig(value: unknown): Config;
241
+ export declare function missingCredentials(config: Config): string[];
242
+ export declare function loadConfig(path: string): Config;
package/dist/config.js ADDED
@@ -0,0 +1,298 @@
1
+ import { readFileSync, statSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { parse } from 'yaml';
4
+ import { z } from 'zod';
5
+ import { PROVIDER_IDS, providerDefinition, allowsMissingKey, modelOutputFormat, modelEndpoint, } from './providers.js';
6
+ const envName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
7
+ const severity = z.enum(['unknown', 'low', 'medium', 'high', 'critical']);
8
+ const channels = z
9
+ .array(z.enum(['slack', 'email']))
10
+ .max(2)
11
+ .refine((a) => new Set(a).size === a.length, 'Duplicate channel');
12
+ const retentionDays = z.number().int().min(1).max(3650).optional();
13
+ const model = z
14
+ .object({
15
+ provider: z.enum(PROVIDER_IDS),
16
+ output_format: z.enum(['auto', 'json_schema', 'json_object', 'prompt']).default('auto'),
17
+ model: z.string().min(1).max(200),
18
+ api_key_env: envName.optional(),
19
+ endpoint: z.url().optional(),
20
+ allow_private_endpoint: z.boolean().default(false),
21
+ input_usd_per_million: z.number().nonnegative().max(10000).optional(),
22
+ output_usd_per_million: z.number().nonnegative().max(10000).optional(),
23
+ })
24
+ .strict()
25
+ .transform((spec) => ({
26
+ ...spec,
27
+ api_key_env: spec.api_key_env ?? providerDefinition(spec.provider).apiKeyEnv,
28
+ }));
29
+ const rule = z
30
+ .object({
31
+ levels: z.array(severity).min(1),
32
+ basis: z.enum(['source_severity', 'priority']).default('priority'),
33
+ channels: channels.default([]),
34
+ })
35
+ .strict();
36
+ export const configSchema = z
37
+ .object({
38
+ version: z.literal(1),
39
+ inventory: z.string().min(1).default('./systems.yaml'),
40
+ database: z.string().min(1).default('./data/watch.db'),
41
+ poll_interval_minutes: z.number().int().min(1).max(1440).default(15),
42
+ news_lookback_minutes: z.number().int().min(1).max(10080).default(60),
43
+ inventory_stale_days: z.number().min(1).max(365).default(7),
44
+ digest_interval_hours: z.number().int().min(1).max(168).default(24),
45
+ sources: z
46
+ .object({
47
+ cve_now: z.boolean().default(true),
48
+ hacker_news: z.boolean().default(true),
49
+ osv: z.boolean().default(false),
50
+ github: z.boolean().default(false),
51
+ github_token_env: envName.default('GITHUB_TOKEN'),
52
+ kev: z.boolean().default(false),
53
+ feeds: z.array(z.url()).max(30).default([]),
54
+ vendor_feeds: z
55
+ .array(z.enum(['nodejs', 'python', 'php']))
56
+ .max(3)
57
+ .refine((values) => new Set(values).size === values.length, 'Duplicate vendor feed')
58
+ .default([]),
59
+ })
60
+ .strict()
61
+ .default({
62
+ cve_now: true,
63
+ hacker_news: true,
64
+ osv: false,
65
+ github: false,
66
+ github_token_env: 'GITHUB_TOKEN',
67
+ kev: false,
68
+ feeds: [],
69
+ vendor_feeds: [],
70
+ }),
71
+ models: z
72
+ .object({
73
+ enabled: z.boolean().default(false),
74
+ analysis: model.optional(),
75
+ verification: model.optional(),
76
+ daily_request_limit: z.number().int().min(1).max(10000).default(100),
77
+ daily_token_limit: z.number().int().min(100).max(10_000_000).default(100_000),
78
+ daily_budget_usd: z.number().positive().max(10000).optional(),
79
+ max_input_chars: z.number().int().min(1000).max(100_000).default(12_000),
80
+ max_output_tokens: z.number().int().min(128).max(8192).default(1500),
81
+ timeout_seconds: z.number().int().min(1).max(120).default(45),
82
+ })
83
+ .strict()
84
+ .default({
85
+ enabled: false,
86
+ daily_request_limit: 100,
87
+ daily_token_limit: 100000,
88
+ max_input_chars: 12000,
89
+ max_output_tokens: 1500,
90
+ timeout_seconds: 45,
91
+ }),
92
+ policy: z
93
+ .object({
94
+ library: rule.default({ levels: ['critical'], basis: 'source_severity', channels: [] }),
95
+ product: rule.default({ levels: ['high', 'critical'], basis: 'priority', channels: [] }),
96
+ news: rule.default({ levels: ['high', 'critical'], basis: 'priority', channels: [] }),
97
+ urgent_unknown: z.boolean().default(true),
98
+ exploited_override: z.boolean().default(true),
99
+ malware_override: z.boolean().default(true),
100
+ health_channels: channels.default([]),
101
+ })
102
+ .strict()
103
+ .default({
104
+ library: { levels: ['critical'], basis: 'source_severity', channels: [] },
105
+ product: { levels: ['high', 'critical'], basis: 'priority', channels: [] },
106
+ news: { levels: ['high', 'critical'], basis: 'priority', channels: [] },
107
+ urgent_unknown: true,
108
+ exploited_override: true,
109
+ malware_override: true,
110
+ health_channels: [],
111
+ }),
112
+ notifications: z
113
+ .object({
114
+ slack: z.object({ webhook_url_env: envName }).strict().optional(),
115
+ email: z
116
+ .object({ smtp_url_env: envName, from: z.email(), to: z.array(z.email()).min(1).max(20) })
117
+ .strict()
118
+ .optional(),
119
+ max_attempts: z.number().int().min(1).max(10).default(3),
120
+ })
121
+ .strict()
122
+ .default({ max_attempts: 3 }),
123
+ monitoring: z
124
+ .object({
125
+ heartbeat_url_env: envName,
126
+ interval_seconds: z.number().int().min(30).max(3600).default(60),
127
+ allow_private_endpoint: z.boolean().default(false),
128
+ })
129
+ .strict()
130
+ .optional(),
131
+ maintenance: z
132
+ .object({
133
+ interval_hours: z.number().int().min(1).max(168).default(24),
134
+ retention: z
135
+ .object({
136
+ analysis_cache_days: retentionDays,
137
+ evidence_history_days: retentionDays,
138
+ finding_history_days: retentionDays,
139
+ accepted_delivery_days: retentionDays,
140
+ inactive_findings_days: retentionDays,
141
+ unreferenced_evidence_days: retentionDays,
142
+ batch_size: z.number().int().min(1).max(10000).default(1000),
143
+ })
144
+ .strict()
145
+ .refine((value) => Object.entries(value).some(([key, days]) => key !== 'batch_size' && days !== undefined), 'Choose at least one retention period')
146
+ .optional(),
147
+ backup: z
148
+ .object({
149
+ directory: z.string().trim().min(1).max(4096),
150
+ keep: z.number().int().min(1).max(365).default(7),
151
+ max_bytes: z
152
+ .number()
153
+ .int()
154
+ .min(1)
155
+ .max(20 * 1024 ** 3)
156
+ .default(512 * 1024 ** 2),
157
+ })
158
+ .strict()
159
+ .optional(),
160
+ })
161
+ .strict()
162
+ .refine((value) => value.retention !== undefined || value.backup !== undefined, 'Configure retention or backups')
163
+ .optional(),
164
+ })
165
+ .strict()
166
+ .superRefine((config, ctx) => {
167
+ if (config.models.enabled && !config.models.analysis)
168
+ ctx.addIssue({
169
+ code: 'custom',
170
+ message: 'Enabled models require an analysis model',
171
+ path: ['models', 'analysis'],
172
+ });
173
+ for (const [name, spec] of Object.entries({
174
+ analysis: config.models.analysis,
175
+ verification: config.models.verification,
176
+ })) {
177
+ if (!spec)
178
+ continue;
179
+ const definition = providerDefinition(spec.provider);
180
+ if (!definition.endpoint && !spec.endpoint)
181
+ ctx.addIssue({
182
+ code: 'custom',
183
+ message: 'This provider requires an endpoint',
184
+ path: ['models', name, 'endpoint'],
185
+ });
186
+ if (definition.local && !spec.allow_private_endpoint)
187
+ ctx.addIssue({
188
+ code: 'custom',
189
+ message: 'Local provider requires allow_private_endpoint: true',
190
+ path: ['models', name, 'allow_private_endpoint'],
191
+ });
192
+ try {
193
+ modelOutputFormat(spec);
194
+ if (spec.endpoint || definition.endpoint)
195
+ modelEndpoint(spec);
196
+ }
197
+ catch (error) {
198
+ ctx.addIssue({ code: 'custom', message: error.message, path: ['models', name] });
199
+ }
200
+ if (config.models.daily_budget_usd !== undefined &&
201
+ (spec.input_usd_per_million === undefined || spec.output_usd_per_million === undefined))
202
+ ctx.addIssue({
203
+ code: 'custom',
204
+ message: 'A dollar budget requires input and output pricing for every configured model',
205
+ path: ['models', name],
206
+ });
207
+ if (spec.endpoint) {
208
+ const url = new URL(spec.endpoint);
209
+ if (url.username ||
210
+ url.password ||
211
+ url.search ||
212
+ url.hash ||
213
+ (!spec.allow_private_endpoint && url.protocol !== 'https:') ||
214
+ !['https:', 'http:'].includes(url.protocol))
215
+ ctx.addIssue({
216
+ code: 'custom',
217
+ message: 'Endpoint must be HTTPS, with no credentials/query/fragment; explicit private endpoints may use HTTP',
218
+ path: ['models', name, 'endpoint'],
219
+ });
220
+ }
221
+ }
222
+ const used = new Set([
223
+ ...config.policy.library.channels,
224
+ ...config.policy.product.channels,
225
+ ...config.policy.news.channels,
226
+ ...config.policy.health_channels,
227
+ ]);
228
+ for (const channel of used)
229
+ if (!config.notifications[channel])
230
+ ctx.addIssue({
231
+ code: 'custom',
232
+ message: `Missing ${channel} notification configuration`,
233
+ path: ['notifications', channel],
234
+ });
235
+ for (const feed of config.sources.feeds) {
236
+ const url = new URL(feed);
237
+ if (url.protocol !== 'https:' || url.username || url.password)
238
+ ctx.addIssue({
239
+ code: 'custom',
240
+ message: 'Feeds must be public HTTPS URLs without credentials',
241
+ path: ['sources', 'feeds'],
242
+ });
243
+ }
244
+ });
245
+ export function parseConfig(value) {
246
+ return configSchema.parse(value);
247
+ }
248
+ export function missingCredentials(config) {
249
+ const missing = [];
250
+ if (config.monitoring && !process.env[config.monitoring.heartbeat_url_env])
251
+ missing.push(config.monitoring.heartbeat_url_env);
252
+ if (config.models.enabled)
253
+ for (const spec of [config.models.analysis, config.models.verification]) {
254
+ if (spec && !process.env[spec.api_key_env] && !allowsMissingKey(spec))
255
+ missing.push(spec.api_key_env);
256
+ }
257
+ const destinations = new Set([
258
+ ...config.policy.library.channels,
259
+ ...config.policy.news.channels,
260
+ ...config.policy.product.channels,
261
+ ...config.policy.health_channels,
262
+ ]);
263
+ for (const channel of destinations) {
264
+ const spec = config.notifications[channel];
265
+ if (spec) {
266
+ const env = 'webhook_url_env' in spec ? spec.webhook_url_env : spec.smtp_url_env;
267
+ if (!process.env[env])
268
+ missing.push(env);
269
+ }
270
+ }
271
+ return [...new Set(missing)];
272
+ }
273
+ export function loadConfig(path) {
274
+ if (statSync(path).size > 1_048_576)
275
+ throw new Error('Configuration exceeds 1 MiB');
276
+ const raw = readFileSync(path, 'utf8');
277
+ // Substitute parsed scalar values only, so an environment value cannot inject YAML syntax.
278
+ function substitute(value) {
279
+ if (typeof value === 'string')
280
+ return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_all, name) => {
281
+ const replacement = process.env[name];
282
+ if (replacement === undefined)
283
+ throw new Error(`Missing configuration variable ${name}`);
284
+ return replacement;
285
+ });
286
+ if (Array.isArray(value))
287
+ return value.map(substitute);
288
+ if (value && typeof value === 'object')
289
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, substitute(v)]));
290
+ return value;
291
+ }
292
+ const config = parseConfig(substitute(parse(raw, { maxAliasCount: 0 })));
293
+ config.inventory = resolve(dirname(resolve(path)), config.inventory);
294
+ config.database = resolve(dirname(resolve(path)), config.database);
295
+ if (config.maintenance?.backup)
296
+ config.maintenance.backup.directory = resolve(dirname(resolve(path)), config.maintenance.backup.directory);
297
+ return config;
298
+ }
@@ -0,0 +1,5 @@
1
+ import type { Evidence, HttpClient, Inventory } from './types.js';
2
+ export declare function evidenceRelevant(item: Evidence, inventory: Inventory): boolean;
3
+ /** Collect recent CVEs, exact npm matches and updates to relevant tracked IDs.
4
+ * The publication-ordered listing does not cover every historical modification. */
5
+ export declare function collectCveNow(inventory: Inventory, checkpoint: string | undefined, previous: Evidence[], news: Evidence[], http: HttpClient, now: number): Promise<Evidence[]>;