@dependabit/monitor 0.1.14 → 0.1.15
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.
- package/CHANGELOG.md +9 -0
- package/dist/checkers/github-repo.js.map +1 -1
- package/dist/checkers/openapi.js.map +1 -1
- package/dist/checkers/url-content.js.map +1 -1
- package/dist/comparator.js.map +1 -1
- package/dist/monitor.d.ts +81 -0
- package/dist/monitor.d.ts.map +1 -1
- package/dist/monitor.js +50 -0
- package/dist/monitor.js.map +1 -1
- package/dist/normalizer.js.map +1 -1
- package/dist/scheduler.js.map +1 -1
- package/dist/severity.js.map +1 -1
- package/dist/types.d.ts +73 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -1
- package/dist/types.js.map +1 -1
- package/package.json +26 -9
- package/src/checkers/github-repo.ts +0 -150
- package/src/checkers/index.ts +0 -7
- package/src/checkers/openapi.ts +0 -310
- package/src/checkers/url-content.ts +0 -78
- package/src/comparator.ts +0 -68
- package/src/index.ts +0 -20
- package/src/monitor.ts +0 -120
- package/src/normalizer.ts +0 -122
- package/src/scheduler.ts +0 -175
- package/src/severity.ts +0 -112
- package/src/types.ts +0 -40
- package/test/checkers/github-repo.test.ts +0 -124
- package/test/checkers/openapi.test.ts +0 -352
- package/test/checkers/url-content.test.ts +0 -99
- package/test/comparator.test.ts +0 -108
- package/test/monitor.test.ts +0 -177
- package/test/normalizer.test.ts +0 -66
- package/test/scheduler.test.ts +0 -674
- package/test/severity.test.ts +0 -122
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GitHub Repository Checker
|
|
3
|
-
* Monitors GitHub repositories for new releases and changes
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Checker, DependencySnapshot, ChangeDetection, AccessConfig } from '../types.js';
|
|
7
|
-
import crypto from 'node:crypto';
|
|
8
|
-
|
|
9
|
-
export class GitHubRepoChecker implements Checker {
|
|
10
|
-
/**
|
|
11
|
-
* Fetches latest release information from a GitHub repository
|
|
12
|
-
*/
|
|
13
|
-
async fetch(config: AccessConfig): Promise<DependencySnapshot> {
|
|
14
|
-
const { url } = config;
|
|
15
|
-
|
|
16
|
-
// Extract owner and repo from GitHub URL
|
|
17
|
-
const match = url.match(/github\.com\/([^/]+)\/([^/]+)/);
|
|
18
|
-
if (!match || !match[1] || !match[2]) {
|
|
19
|
-
throw new Error(`Invalid GitHub URL: ${url}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const owner = match[1];
|
|
23
|
-
const repo = match[2];
|
|
24
|
-
const cleanRepo = repo.replace(/\.git$/, '');
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Fetch latest release from GitHub API
|
|
28
|
-
const apiUrl = `https://api.github.com/repos/${owner}/${cleanRepo}/releases/latest`;
|
|
29
|
-
const response = await fetch(apiUrl, {
|
|
30
|
-
headers: {
|
|
31
|
-
Accept: 'application/vnd.github+json',
|
|
32
|
-
'User-Agent': 'dependabit',
|
|
33
|
-
...(config.auth?.secret && { Authorization: `Bearer ${config.auth.secret}` })
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (response.status === 404) {
|
|
38
|
-
// No releases found, fall back to latest commit
|
|
39
|
-
return this.fetchLatestCommit(owner, cleanRepo, config.auth?.secret);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const release = (await response.json()) as {
|
|
47
|
-
tag_name: string;
|
|
48
|
-
name: string;
|
|
49
|
-
published_at: string;
|
|
50
|
-
body: string;
|
|
51
|
-
html_url: string;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Create state hash from release info
|
|
55
|
-
const stateContent = JSON.stringify({
|
|
56
|
-
tagName: release.tag_name,
|
|
57
|
-
name: release.name,
|
|
58
|
-
publishedAt: release.published_at
|
|
59
|
-
});
|
|
60
|
-
const stateHash = crypto.createHash('sha256').update(stateContent).digest('hex');
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
version: release.tag_name,
|
|
64
|
-
stateHash,
|
|
65
|
-
fetchedAt: new Date(),
|
|
66
|
-
metadata: {
|
|
67
|
-
name: release.name,
|
|
68
|
-
publishedAt: release.published_at,
|
|
69
|
-
body: release.body,
|
|
70
|
-
htmlUrl: release.html_url
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
} catch (error) {
|
|
74
|
-
throw new Error(`Failed to fetch GitHub release: ${(error as Error).message}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Fallback: Fetch latest commit when no releases exist
|
|
80
|
-
*/
|
|
81
|
-
private async fetchLatestCommit(
|
|
82
|
-
owner: string,
|
|
83
|
-
repo: string,
|
|
84
|
-
token?: string
|
|
85
|
-
): Promise<DependencySnapshot> {
|
|
86
|
-
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/commits?per_page=1`;
|
|
87
|
-
const response = await fetch(apiUrl, {
|
|
88
|
-
headers: {
|
|
89
|
-
Accept: 'application/vnd.github+json',
|
|
90
|
-
'User-Agent': 'dependabit',
|
|
91
|
-
...(token && { Authorization: `Bearer ${token}` })
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const commits = (await response.json()) as Array<{
|
|
100
|
-
sha: string;
|
|
101
|
-
commit: {
|
|
102
|
-
message: string;
|
|
103
|
-
author: { date: string };
|
|
104
|
-
};
|
|
105
|
-
}>;
|
|
106
|
-
|
|
107
|
-
if (commits.length === 0 || !commits[0]) {
|
|
108
|
-
throw new Error('No commits found in repository');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const latestCommit = commits[0];
|
|
112
|
-
const stateHash = latestCommit.sha;
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
stateHash,
|
|
116
|
-
fetchedAt: new Date(),
|
|
117
|
-
metadata: {
|
|
118
|
-
sha: latestCommit.sha,
|
|
119
|
-
message: latestCommit.commit.message,
|
|
120
|
-
date: latestCommit.commit.author.date
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Compares two snapshots to detect version/state changes
|
|
127
|
-
*/
|
|
128
|
-
async compare(prev: DependencySnapshot, curr: DependencySnapshot): Promise<ChangeDetection> {
|
|
129
|
-
const changes: string[] = [];
|
|
130
|
-
|
|
131
|
-
// Check version change
|
|
132
|
-
if (prev.version !== curr.version) {
|
|
133
|
-
if (prev.version && curr.version) {
|
|
134
|
-
changes.push('version');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Check state hash change
|
|
139
|
-
if (prev.stateHash !== curr.stateHash) {
|
|
140
|
-
changes.push('stateHash');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
hasChanged: changes.length > 0,
|
|
145
|
-
changes,
|
|
146
|
-
oldVersion: prev.version,
|
|
147
|
-
newVersion: curr.version
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
package/src/checkers/index.ts
DELETED
package/src/checkers/openapi.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAPI Spec Checker
|
|
3
|
-
* Monitors OpenAPI/Swagger specifications for changes with semantic diffing
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Checker, DependencySnapshot, ChangeDetection, AccessConfig } from '../types.js';
|
|
7
|
-
import crypto from 'node:crypto';
|
|
8
|
-
import { parse as parseYAML } from 'yaml';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* OpenAPI document structure (partial, for what we need)
|
|
12
|
-
*/
|
|
13
|
-
interface OpenAPIDocument {
|
|
14
|
-
openapi?: string;
|
|
15
|
-
swagger?: string;
|
|
16
|
-
info?: {
|
|
17
|
-
title?: string;
|
|
18
|
-
version?: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
};
|
|
21
|
-
paths?: Record<string, PathItem>;
|
|
22
|
-
components?: {
|
|
23
|
-
schemas?: Record<string, unknown>;
|
|
24
|
-
securitySchemes?: Record<string, unknown>;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface PathItem {
|
|
29
|
-
get?: Operation;
|
|
30
|
-
post?: Operation;
|
|
31
|
-
put?: Operation;
|
|
32
|
-
patch?: Operation;
|
|
33
|
-
delete?: Operation;
|
|
34
|
-
options?: Operation;
|
|
35
|
-
head?: Operation;
|
|
36
|
-
trace?: Operation;
|
|
37
|
-
parameters?: unknown[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface Operation {
|
|
41
|
-
operationId?: string;
|
|
42
|
-
summary?: string;
|
|
43
|
-
description?: string;
|
|
44
|
-
parameters?: unknown[];
|
|
45
|
-
requestBody?: unknown;
|
|
46
|
-
responses?: Record<string, unknown>;
|
|
47
|
-
deprecated?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Semantic diff result for OpenAPI specs
|
|
52
|
-
*/
|
|
53
|
-
interface OpenAPIDiff {
|
|
54
|
-
addedEndpoints: string[];
|
|
55
|
-
removedEndpoints: string[];
|
|
56
|
-
modifiedEndpoints: string[];
|
|
57
|
-
addedSchemas: string[];
|
|
58
|
-
removedSchemas: string[];
|
|
59
|
-
modifiedSchemas: string[];
|
|
60
|
-
versionChanged: boolean;
|
|
61
|
-
oldVersion?: string;
|
|
62
|
-
newVersion?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class OpenAPIChecker implements Checker {
|
|
66
|
-
/**
|
|
67
|
-
* Fetches and parses OpenAPI specification
|
|
68
|
-
*/
|
|
69
|
-
async fetch(config: AccessConfig): Promise<DependencySnapshot> {
|
|
70
|
-
const { url } = config;
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const headers: Record<string, string> = {
|
|
74
|
-
Accept: 'application/json, application/yaml, text/yaml, */*',
|
|
75
|
-
'User-Agent': 'dependabit-monitor/1.0'
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (config.auth?.secret) {
|
|
79
|
-
if (config.auth.type === 'token' || config.auth.type === 'oauth') {
|
|
80
|
-
headers['Authorization'] = `Bearer ${config.auth.secret}`;
|
|
81
|
-
} else if (config.auth.type === 'basic') {
|
|
82
|
-
headers['Authorization'] = `Basic ${config.auth.secret}`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const response = await fetch(url, {
|
|
87
|
-
headers
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const contentType = response.headers.get('content-type') || '';
|
|
95
|
-
const content = await response.text();
|
|
96
|
-
|
|
97
|
-
// Parse the OpenAPI spec
|
|
98
|
-
let spec: OpenAPIDocument;
|
|
99
|
-
if (contentType.includes('yaml') || url.endsWith('.yaml') || url.endsWith('.yml')) {
|
|
100
|
-
// Parse YAML using standard yaml library
|
|
101
|
-
spec = parseYAML(content) as OpenAPIDocument;
|
|
102
|
-
} else {
|
|
103
|
-
spec = JSON.parse(content) as OpenAPIDocument;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Extract key information for semantic comparison
|
|
107
|
-
const endpoints = this.extractEndpoints(spec);
|
|
108
|
-
const schemas = this.extractSchemas(spec);
|
|
109
|
-
const version = spec.info?.version;
|
|
110
|
-
|
|
111
|
-
// Create a deterministic hash from the semantic content
|
|
112
|
-
const semanticContent = JSON.stringify({
|
|
113
|
-
version,
|
|
114
|
-
endpoints: Object.keys(endpoints).sort(),
|
|
115
|
-
schemas: Object.keys(schemas).sort(),
|
|
116
|
-
endpointDetails: endpoints,
|
|
117
|
-
schemaDetails: schemas
|
|
118
|
-
});
|
|
119
|
-
const stateHash = crypto.createHash('sha256').update(semanticContent).digest('hex');
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
version,
|
|
123
|
-
stateHash,
|
|
124
|
-
fetchedAt: new Date(),
|
|
125
|
-
metadata: {
|
|
126
|
-
title: spec.info?.title,
|
|
127
|
-
description: spec.info?.description,
|
|
128
|
-
specVersion: spec.openapi || spec.swagger,
|
|
129
|
-
endpointCount: Object.keys(endpoints).length,
|
|
130
|
-
schemaCount: Object.keys(schemas).length,
|
|
131
|
-
endpoints,
|
|
132
|
-
schemas
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
} catch (error) {
|
|
136
|
-
throw new Error(`Failed to fetch OpenAPI spec: ${(error as Error).message}`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Extract endpoints from OpenAPI spec
|
|
142
|
-
*/
|
|
143
|
-
private extractEndpoints(spec: OpenAPIDocument): Record<string, string[]> {
|
|
144
|
-
const endpoints: Record<string, string[]> = {};
|
|
145
|
-
|
|
146
|
-
if (!spec.paths) return endpoints;
|
|
147
|
-
|
|
148
|
-
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
149
|
-
const methods: string[] = [];
|
|
150
|
-
const httpMethods = [
|
|
151
|
-
'get',
|
|
152
|
-
'post',
|
|
153
|
-
'put',
|
|
154
|
-
'patch',
|
|
155
|
-
'delete',
|
|
156
|
-
'options',
|
|
157
|
-
'head',
|
|
158
|
-
'trace'
|
|
159
|
-
] as const;
|
|
160
|
-
|
|
161
|
-
for (const method of httpMethods) {
|
|
162
|
-
if (pathItem[method]) {
|
|
163
|
-
methods.push(method.toUpperCase());
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (methods.length > 0) {
|
|
168
|
-
endpoints[path] = methods;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return endpoints;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Extract schemas from OpenAPI spec
|
|
177
|
-
*/
|
|
178
|
-
private extractSchemas(spec: OpenAPIDocument): Record<string, unknown> {
|
|
179
|
-
return spec.components?.schemas || {};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Compares two OpenAPI snapshots with semantic diffing
|
|
184
|
-
*/
|
|
185
|
-
async compare(prev: DependencySnapshot, curr: DependencySnapshot): Promise<ChangeDetection> {
|
|
186
|
-
const changes: string[] = [];
|
|
187
|
-
let severity: 'breaking' | 'major' | 'minor' = 'minor';
|
|
188
|
-
|
|
189
|
-
// Extract endpoints and schemas from metadata
|
|
190
|
-
let prevEndpoints = (prev.metadata?.['endpoints'] as Record<string, string[]>) || {};
|
|
191
|
-
let currEndpoints = (curr.metadata?.['endpoints'] as Record<string, string[]>) || {};
|
|
192
|
-
let prevSchemas = (prev.metadata?.['schemas'] as Record<string, unknown>) || {};
|
|
193
|
-
let currSchemas = (curr.metadata?.['schemas'] as Record<string, unknown>) || {};
|
|
194
|
-
|
|
195
|
-
// If the state hashes match but previous metadata is missing, avoid spurious diffs
|
|
196
|
-
if (
|
|
197
|
-
prev.stateHash !== undefined &&
|
|
198
|
-
curr.stateHash !== undefined &&
|
|
199
|
-
prev.stateHash === curr.stateHash
|
|
200
|
-
) {
|
|
201
|
-
prevEndpoints = currEndpoints;
|
|
202
|
-
prevSchemas = currSchemas;
|
|
203
|
-
}
|
|
204
|
-
const diff: OpenAPIDiff = {
|
|
205
|
-
addedEndpoints: [],
|
|
206
|
-
removedEndpoints: [],
|
|
207
|
-
modifiedEndpoints: [],
|
|
208
|
-
addedSchemas: [],
|
|
209
|
-
removedSchemas: [],
|
|
210
|
-
modifiedSchemas: [],
|
|
211
|
-
versionChanged: prev.version !== curr.version
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
if (prev.version !== undefined) {
|
|
215
|
-
diff.oldVersion = prev.version;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (curr.version !== undefined) {
|
|
219
|
-
diff.newVersion = curr.version;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Compare endpoints
|
|
223
|
-
const prevEndpointKeys = Object.keys(prevEndpoints);
|
|
224
|
-
const currEndpointKeys = Object.keys(currEndpoints);
|
|
225
|
-
|
|
226
|
-
for (const path of currEndpointKeys) {
|
|
227
|
-
if (!prevEndpointKeys.includes(path)) {
|
|
228
|
-
diff.addedEndpoints.push(path);
|
|
229
|
-
} else if (JSON.stringify(prevEndpoints[path]) !== JSON.stringify(currEndpoints[path])) {
|
|
230
|
-
diff.modifiedEndpoints.push(path);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
for (const path of prevEndpointKeys) {
|
|
235
|
-
if (!currEndpointKeys.includes(path)) {
|
|
236
|
-
diff.removedEndpoints.push(path);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Compare schemas
|
|
241
|
-
const prevSchemaKeys = Object.keys(prevSchemas);
|
|
242
|
-
const currSchemaKeys = Object.keys(currSchemas);
|
|
243
|
-
|
|
244
|
-
for (const schema of currSchemaKeys) {
|
|
245
|
-
if (!prevSchemaKeys.includes(schema)) {
|
|
246
|
-
diff.addedSchemas.push(schema);
|
|
247
|
-
} else if (JSON.stringify(prevSchemas[schema]) !== JSON.stringify(currSchemas[schema])) {
|
|
248
|
-
diff.modifiedSchemas.push(schema);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
for (const schema of prevSchemaKeys) {
|
|
253
|
-
if (!currSchemaKeys.includes(schema)) {
|
|
254
|
-
diff.removedSchemas.push(schema);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Determine changes and severity
|
|
259
|
-
if (diff.removedEndpoints.length > 0) {
|
|
260
|
-
changes.push('endpoints_removed');
|
|
261
|
-
severity = 'breaking';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (diff.removedSchemas.length > 0) {
|
|
265
|
-
changes.push('schemas_removed');
|
|
266
|
-
severity = 'breaking';
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (diff.modifiedEndpoints.length > 0) {
|
|
270
|
-
changes.push('endpoints_modified');
|
|
271
|
-
if (severity !== 'breaking') severity = 'major';
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (diff.modifiedSchemas.length > 0) {
|
|
275
|
-
changes.push('schemas_modified');
|
|
276
|
-
if (severity !== 'breaking') severity = 'major';
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (diff.addedEndpoints.length > 0) {
|
|
280
|
-
changes.push('endpoints_added');
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (diff.addedSchemas.length > 0) {
|
|
284
|
-
changes.push('schemas_added');
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (diff.versionChanged) {
|
|
288
|
-
changes.push('version');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Check overall hash change
|
|
292
|
-
if (prev.stateHash !== curr.stateHash && changes.length === 0) {
|
|
293
|
-
changes.push('content');
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const result: ChangeDetection = {
|
|
297
|
-
hasChanged: changes.length > 0,
|
|
298
|
-
changes,
|
|
299
|
-
oldVersion: prev.version,
|
|
300
|
-
newVersion: curr.version,
|
|
301
|
-
diff
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
if (changes.length > 0) {
|
|
305
|
-
result.severity = severity;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return result;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* URL Content Checker
|
|
3
|
-
* Monitors documentation URLs for content changes using SHA256 hashing
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Checker, DependencySnapshot, ChangeDetection, AccessConfig } from '../types.js';
|
|
7
|
-
import { normalizeHTML } from '../normalizer.js';
|
|
8
|
-
import crypto from 'node:crypto';
|
|
9
|
-
|
|
10
|
-
export class URLContentChecker implements Checker {
|
|
11
|
-
/**
|
|
12
|
-
* Fetches and hashes URL content
|
|
13
|
-
*/
|
|
14
|
-
async fetch(config: AccessConfig): Promise<DependencySnapshot> {
|
|
15
|
-
const { url } = config;
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const response = await fetch(url, {
|
|
19
|
-
headers: {
|
|
20
|
-
'User-Agent': 'dependabit-monitor/1.0'
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const contentType = response.headers.get('content-type') || '';
|
|
29
|
-
const content = await response.text();
|
|
30
|
-
|
|
31
|
-
let normalizedContent: string;
|
|
32
|
-
|
|
33
|
-
// Apply HTML normalization if content is HTML
|
|
34
|
-
if (
|
|
35
|
-
contentType.includes('text/html') ||
|
|
36
|
-
content.trim().startsWith('<!DOCTYPE') ||
|
|
37
|
-
content.trim().startsWith('<html')
|
|
38
|
-
) {
|
|
39
|
-
normalizedContent = normalizeHTML(content);
|
|
40
|
-
} else {
|
|
41
|
-
// For non-HTML content (markdown, plain text, etc.), just normalize whitespace
|
|
42
|
-
normalizedContent = content.replace(/\s+/g, ' ').trim();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Generate SHA256 hash of normalized content
|
|
46
|
-
const stateHash = crypto.createHash('sha256').update(normalizedContent).digest('hex');
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
stateHash,
|
|
50
|
-
fetchedAt: new Date(),
|
|
51
|
-
metadata: {
|
|
52
|
-
contentType,
|
|
53
|
-
contentLength: content.length,
|
|
54
|
-
normalizedLength: normalizedContent.length
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw new Error(`Failed to fetch URL content: ${(error as Error).message}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Compares two snapshots to detect content changes
|
|
64
|
-
*/
|
|
65
|
-
async compare(prev: DependencySnapshot, curr: DependencySnapshot): Promise<ChangeDetection> {
|
|
66
|
-
const changes: string[] = [];
|
|
67
|
-
|
|
68
|
-
// Content changed if hashes differ
|
|
69
|
-
if (prev.stateHash !== curr.stateHash) {
|
|
70
|
-
changes.push('content');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
hasChanged: changes.length > 0,
|
|
75
|
-
changes
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
package/src/comparator.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State Comparator
|
|
3
|
-
* Generic comparison logic for dependency state snapshots
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { DependencySnapshot, ChangeDetection } from './types.js';
|
|
7
|
-
|
|
8
|
-
export class StateComparator {
|
|
9
|
-
/**
|
|
10
|
-
* Compares two dependency snapshots to detect changes
|
|
11
|
-
*/
|
|
12
|
-
compare(oldState: DependencySnapshot, newState: DependencySnapshot): ChangeDetection {
|
|
13
|
-
const changes: string[] = [];
|
|
14
|
-
|
|
15
|
-
// Check state hash
|
|
16
|
-
if (oldState.stateHash !== newState.stateHash) {
|
|
17
|
-
changes.push('stateHash');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Check version
|
|
21
|
-
if (oldState.version !== newState.version) {
|
|
22
|
-
changes.push('version');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Check metadata changes (shallow comparison)
|
|
26
|
-
if (this.hasMetadataChanges(oldState.metadata, newState.metadata)) {
|
|
27
|
-
changes.push('metadata');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
hasChanged: changes.length > 0,
|
|
32
|
-
changes,
|
|
33
|
-
oldVersion: oldState.version,
|
|
34
|
-
newVersion: newState.version
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Checks if metadata has changed (shallow comparison)
|
|
40
|
-
*/
|
|
41
|
-
private hasMetadataChanges(
|
|
42
|
-
oldMeta?: Record<string, unknown>,
|
|
43
|
-
newMeta?: Record<string, unknown>
|
|
44
|
-
): boolean {
|
|
45
|
-
if (!oldMeta && !newMeta) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!oldMeta || !newMeta) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const oldKeys = Object.keys(oldMeta);
|
|
54
|
-
const newKeys = Object.keys(newMeta);
|
|
55
|
-
|
|
56
|
-
if (oldKeys.length !== newKeys.length) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (const key of oldKeys) {
|
|
61
|
-
if (oldMeta[key] !== newMeta[key]) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @dependabit/monitor - Dependency change detection and monitoring
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { Monitor } from './monitor.js';
|
|
6
|
-
export type { DependencyConfig, CheckResult } from './monitor.js';
|
|
7
|
-
|
|
8
|
-
export { GitHubRepoChecker } from './checkers/github-repo.js';
|
|
9
|
-
export { URLContentChecker } from './checkers/url-content.js';
|
|
10
|
-
export { OpenAPIChecker } from './checkers/openapi.js';
|
|
11
|
-
|
|
12
|
-
export { StateComparator } from './comparator.js';
|
|
13
|
-
export { SeverityClassifier } from './severity.js';
|
|
14
|
-
export type { Severity } from './severity.js';
|
|
15
|
-
|
|
16
|
-
export { normalizeHTML, normalizeURL } from './normalizer.js';
|
|
17
|
-
|
|
18
|
-
export { Scheduler } from './scheduler.js';
|
|
19
|
-
|
|
20
|
-
export type { Checker, DependencySnapshot, ChangeDetection, AccessConfig } from './types.js';
|