@devshub198211/devguard 2.0.2 → 2.0.3
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/MODULES.md +261 -102
- package/README.md +130 -139
- package/SETUP.md +66 -123
- package/dist/ai.d.ts +8 -0
- package/dist/ai.js +1 -1
- package/dist/{chunk-4WCL5IUZ.js → chunk-UXM7HRTI.js} +12 -2
- package/dist/cli.js +530 -173
- package/dist/index.js +1 -1
- package/package.json +13 -38
- package/dist/ai.cjs +0 -867
- package/dist/ai.d.cts +0 -169
- package/dist/api-contract-5kJEwFIh.d.cts +0 -157
- package/dist/auth.cjs +0 -787
- package/dist/auth.d.cts +0 -245
- package/dist/cli.cjs +0 -1162
- package/dist/cli.d.cts +0 -1
- package/dist/dx.cjs +0 -747
- package/dist/dx.d.cts +0 -96
- package/dist/index.cjs +0 -2655
- package/dist/index.d.cts +0 -38
- package/dist/security.cjs +0 -654
- package/dist/security.d.cts +0 -114
package/MODULES.md
CHANGED
|
@@ -1,122 +1,281 @@
|
|
|
1
|
-
# DevGuard
|
|
1
|
+
# DevGuard Modules Reference
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ 1. Security Modules
|
|
8
|
-
|
|
9
|
-
### lockfile-guardian
|
|
10
|
-
* **What it does:** Prevents "Supply Chain Attacks" by ensuring your `package-lock.json` hasn't been tampered with.
|
|
11
|
-
* **Usefulness:** Critical for CI/CD to prevent malicious code from sneaking into your build.
|
|
12
|
-
* **Example:**
|
|
13
|
-
```typescript
|
|
14
|
-
import { verifyLockfile } from 'devguard';
|
|
15
|
-
const result = verifyLockfile(); // Returns { valid: true/false }
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### hook-scanner
|
|
19
|
-
* **What it does:** Scans all `node_modules` for malicious install hooks (preinstall/postinstall).
|
|
20
|
-
* **Usefulness:** Stops malware from running on your machine immediately after `npm install`.
|
|
21
|
-
* **Example:**
|
|
22
|
-
```bash
|
|
23
|
-
devguard scan
|
|
24
|
-
```
|
|
3
|
+
All 14 modules explained with examples.
|
|
25
4
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Security Modules
|
|
8
|
+
|
|
9
|
+
### 1. lockfile-guardian
|
|
10
|
+
**What:** Detects tampering in `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml` using SHA-512 hashing.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { verifyLockfile, createSnapshot } from '@devshub198211/devguard/security';
|
|
14
|
+
|
|
15
|
+
// Create a trusted baseline after clean install
|
|
16
|
+
createSnapshot();
|
|
17
|
+
|
|
18
|
+
// Later, verify nothing has changed
|
|
19
|
+
const result = verifyLockfile();
|
|
20
|
+
if (!result.valid) console.log('Tampered files:', result.tampered);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
devguard snapshot # Create baseline
|
|
25
|
+
devguard check # Verify integrity
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### 2. hook-scanner
|
|
31
|
+
**What:** Scans `node_modules` for 23+ malicious patterns in install scripts (obfuscation, network exfiltration, shell commands).
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { scanProject } from '@devshub198211/devguard/security';
|
|
35
|
+
|
|
36
|
+
const findings = scanProject();
|
|
37
|
+
findings.forEach(f => console.log(`${f.package}: ${f.pattern} [${f.severity}]`));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
devguard scan
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### 3. token-rotator
|
|
47
|
+
**What:** Checks API token age and verifies tokens are still valid via live API calls (opt-in).
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { checkTokenAge, loadTokensFromEnv } from '@devshub198211/devguard/security';
|
|
51
|
+
|
|
52
|
+
const tokens = loadTokensFromEnv(['NPM_TOKEN', 'GITHUB_TOKEN']);
|
|
53
|
+
const alerts = checkTokenAge(tokens);
|
|
54
|
+
alerts.filter(a => a.status === 'stale').forEach(a => console.log(`Rotate: ${a.name}`));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
devguard tokens
|
|
59
|
+
```
|
|
33
60
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### 4. dep-pincer
|
|
64
|
+
**What:** Finds dependencies using ranges (`^1.0.0`) and pins them to exact versions. Generates SRI hashes.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { autoPin } from '@devshub198211/devguard/security';
|
|
68
|
+
|
|
69
|
+
const result = autoPin('.', true); // true = auto-fix
|
|
70
|
+
console.log(`Pinned ${result.fixed} dependencies`);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
devguard pin --fix
|
|
75
|
+
```
|
|
41
76
|
|
|
42
77
|
---
|
|
43
78
|
|
|
44
|
-
##
|
|
79
|
+
## AI & Code Modules
|
|
80
|
+
|
|
81
|
+
### 5. refactor-engine
|
|
82
|
+
**What:** Analyzes code for complexity (O(n) vs O(n²)), security flaws (eval, innerHTML), and structural issues. Opens a browser-based diff reviewer.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
devguard refactor src/utils.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Detects and fixes:
|
|
89
|
+
- `eval()` → `JSON.parse()` (security)
|
|
90
|
+
- `.innerHTML` → `.textContent` (XSS prevention)
|
|
91
|
+
- `var` → `const` (modern JS)
|
|
92
|
+
- Deep nesting → guard clauses (readability)
|
|
93
|
+
- Missing try/catch in async functions (error safety)
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### 6. agent-schema
|
|
98
|
+
**What:** Type-safe schema builder for validating LLM JSON output with auto-retry and structural repair.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { c, parseWithRetry } from '@devshub198211/devguard/ai';
|
|
102
|
+
|
|
103
|
+
const TaskSchema = c.object({
|
|
104
|
+
title: c.string().min(1),
|
|
105
|
+
priority: c.string().enum(['high', 'medium', 'low']),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const result = await parseWithRetry(TaskSchema, async (ctx) => {
|
|
109
|
+
return await callYourLLM(ctx);
|
|
110
|
+
});
|
|
111
|
+
// result.data is fully typed: { title: string; priority: 'high'|'medium'|'low' }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### 7. mcp-server-kit
|
|
117
|
+
**What:** Build Model Context Protocol servers that work with Claude Desktop and other MCP clients.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { MCPServerBuilder } from '@devshub198211/devguard/ai';
|
|
121
|
+
|
|
122
|
+
new MCPServerBuilder('my-tools', '1.0.0')
|
|
123
|
+
.addTool({
|
|
124
|
+
name: 'get_weather',
|
|
125
|
+
description: 'Get weather for a city',
|
|
126
|
+
inputSchema: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },
|
|
127
|
+
handler: async ({ city }) => ({ temp: '22°C', city })
|
|
128
|
+
})
|
|
129
|
+
.startStdio();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
devguard mcp
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 8. agent-memory
|
|
139
|
+
**What:** Persistent state storage for AI agents. Supports FileSystem and in-memory adapters.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { FileSystemAdapter } from '@devshub198211/devguard/ai';
|
|
143
|
+
|
|
144
|
+
const memory = new FileSystemAdapter('.agent-data');
|
|
145
|
+
await memory.save('agent-1', {
|
|
146
|
+
id: '1', role: 'user', content: 'Hello', timestamp: Date.now()
|
|
147
|
+
});
|
|
148
|
+
const history = await memory.getHistory('agent-1', 10);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### 9. llm-budget
|
|
154
|
+
**What:** Track token usage and spending across OpenAI, Anthropic, Google, and other LLM providers.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { LLMBudget } from '@devshub198211/devguard/ai';
|
|
158
|
+
|
|
159
|
+
const budget = new LLMBudget({ monthlyLimitUSD: 50, warnAtUSD: 40 });
|
|
160
|
+
budget.track({
|
|
161
|
+
model: 'gpt-4o', provider: 'openai',
|
|
162
|
+
tokensPrompt: 1000, tokensCompletion: 500, costUSD: 0.015
|
|
163
|
+
});
|
|
164
|
+
console.log(budget.report()); // { totalCost, isOverBudget, ... }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Auth Modules
|
|
170
|
+
|
|
171
|
+
### 10. zero-trust-jwt
|
|
172
|
+
**What:** JWT verification with HS256/RS256/JWKS support, revocation lists, and anomaly detection.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { JWTVerifier } from '@devshub198211/devguard/auth';
|
|
176
|
+
|
|
177
|
+
const verifier = new JWTVerifier({ secret: process.env.JWT_SECRET });
|
|
178
|
+
const { valid, payload, anomalies } = await verifier.verify(token);
|
|
179
|
+
// anomalies: { score: 0, level: 'safe', warnings: [] }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
devguard jwt-verify --token <jwt> --secret <key>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### 11. bot-fence
|
|
189
|
+
**What:** Multi-signal bot detection for Express/Fastify middleware. Checks IP, headers, rate limits.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { createMiddleware, IPRateLimiter } from '@devshub198211/devguard/auth';
|
|
193
|
+
|
|
194
|
+
app.use(createMiddleware({
|
|
195
|
+
blockThreshold: 70,
|
|
196
|
+
rateLimiter: new IPRateLimiter(100, 60_000)
|
|
197
|
+
}));
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
devguard bot-check
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 12. passkey-node
|
|
207
|
+
**What:** Complete WebAuthn/Passkey implementation using only Node.js crypto. Supports ES256 and RS256.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import {
|
|
211
|
+
generateRegistrationOptions,
|
|
212
|
+
verifyRegistration,
|
|
213
|
+
generateAuthenticationOptions,
|
|
214
|
+
verifyAuthentication
|
|
215
|
+
} from '@devshub198211/devguard/auth';
|
|
216
|
+
|
|
217
|
+
const options = generateRegistrationOptions({
|
|
218
|
+
rpId: 'example.com', rpName: 'My App',
|
|
219
|
+
userId: 'user-1', userName: 'alice'
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## DX Modules
|
|
226
|
+
|
|
227
|
+
### 13. env-safe
|
|
228
|
+
**What:** Validates `.env` files against a typed schema at startup. Fails fast with clear error messages.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { loadEnv } from '@devshub198211/devguard/dx';
|
|
232
|
+
|
|
233
|
+
const env = loadEnv({
|
|
234
|
+
DATABASE_URL: { type: 'url', required: true },
|
|
235
|
+
PORT: { type: 'integer', default: '3000', min: 1, max: 65535 },
|
|
236
|
+
NODE_ENV: { type: 'string', enum: ['development', 'production', 'test'] },
|
|
237
|
+
});
|
|
238
|
+
// Throws immediately if any variable is missing or invalid
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
45
242
|
|
|
46
|
-
###
|
|
47
|
-
|
|
48
|
-
* **Usefulness:** Ensures AI models send perfectly formatted data to your backend tools.
|
|
49
|
-
* **Example:**
|
|
50
|
-
```typescript
|
|
51
|
-
const tool = s.obj({
|
|
52
|
-
city: s.str().desc("The city name")
|
|
53
|
-
});
|
|
54
|
-
```
|
|
243
|
+
### 14. log-otlp
|
|
244
|
+
**What:** Structured JSON logger compatible with OpenTelemetry. Supports child loggers and trace injection.
|
|
55
245
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* **Usefulness:** Connect your custom tools and data directly to Claude, ChatGPT, or other AI agents.
|
|
59
|
-
* **Example:**
|
|
60
|
-
```typescript
|
|
61
|
-
const server = new MCPServerBuilder("MyServer");
|
|
62
|
-
server.addTool({ name: "get_weather", handler: async () => "Sunny" });
|
|
63
|
-
server.startStdio();
|
|
64
|
-
```
|
|
246
|
+
```typescript
|
|
247
|
+
import { createLogger } from '@devshub198211/devguard/dx';
|
|
65
248
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* **Example:**
|
|
70
|
-
```bash
|
|
71
|
-
devguard refactor src/utils.ts
|
|
72
|
-
```
|
|
249
|
+
const log = createLogger({ service: 'api', level: 'info' });
|
|
250
|
+
log.info('Request received', { userId: 'u-123', path: '/orders' });
|
|
251
|
+
log.error('Payment failed', { orderId: 'o-456', reason: 'declined' });
|
|
73
252
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
253
|
+
const reqLog = log.child({ requestId: 'req-789' });
|
|
254
|
+
reqLog.info('Processing');
|
|
255
|
+
```
|
|
77
256
|
|
|
78
257
|
---
|
|
79
258
|
|
|
80
|
-
|
|
259
|
+
### Bonus: api-contract
|
|
260
|
+
**What:** Zero-dependency schema builder with full TypeScript type inference for API validation.
|
|
81
261
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* **Usefulness:** Hardened against "Algorithm Confusion" and "Replay Attacks." Uses constant-time comparisons.
|
|
85
|
-
* **Example:**
|
|
86
|
-
```typescript
|
|
87
|
-
const verifier = new JWTVerifier({ secret: process.env.SECRET });
|
|
88
|
-
const payload = await verifier.verify(token);
|
|
89
|
-
```
|
|
262
|
+
```typescript
|
|
263
|
+
import { c, validateBody } from '@devshub198211/devguard/dx';
|
|
90
264
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
265
|
+
const UserSchema = c.object({
|
|
266
|
+
name: c.string().min(1).max(100),
|
|
267
|
+
email: c.string(),
|
|
268
|
+
age: c.number().min(0).max(150).optional(),
|
|
269
|
+
});
|
|
94
270
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
271
|
+
// Express middleware
|
|
272
|
+
app.post('/users', validateBody(UserSchema), (req, res) => {
|
|
273
|
+
// req.body is fully typed
|
|
274
|
+
});
|
|
275
|
+
```
|
|
98
276
|
|
|
99
277
|
---
|
|
100
278
|
|
|
101
|
-
|
|
279
|
+
*Your custom notes below:*
|
|
102
280
|
|
|
103
|
-
|
|
104
|
-
* **What it does:** Startup validation for `.env` files with full TypeScript types.
|
|
105
|
-
* **Usefulness:** Prevents your app from starting if a critical secret (like DB_URL) is missing or malformed.
|
|
106
|
-
* **Example:**
|
|
107
|
-
```typescript
|
|
108
|
-
const env = loadEnv({ PORT: s.num().default(3000) });
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### log-otlp
|
|
112
|
-
* **What it does:** High-performance logger that sends data to OpenTelemetry (Grafana/Honeycomb).
|
|
113
|
-
* **Usefulness:** Cloud-native observability with zero external dependencies.
|
|
114
|
-
|
|
115
|
-
### api-contract
|
|
116
|
-
* **What it does:** Type-safe fetch and request validation.
|
|
117
|
-
* **Usefulness:** Shares types between your frontend and backend so they never "break" each other.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
### Its for testing purpous if you like it leave some reviews and also if you got some sugestion you can contact me to Update it i am a student and it was an idea so let me know what i can add more and make it more usefull for developers.
|
|
122
|
-
### you can contact me at [devs.hub.604@gmail.com]
|
|
281
|
+
<!-- Add your personal notes, contact info, or acknowledgments here -->
|