@umeshindu222/apisnap 1.1.2 → 1.1.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/README.md +18 -25
- package/dist/core/runner.js +26 -60
- package/dist/core/runner.js.map +1 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +0 -13
- package/dist/middleware/index.js.map +1 -1
- package/package.json +42 -42
package/README.md
CHANGED
|
@@ -28,59 +28,52 @@
|
|
|
28
28
|
|
|
29
29
|
## 🚀 Quick Start
|
|
30
30
|
|
|
31
|
-
### 1
|
|
31
|
+
### Step 1: Install and add the middleware to your Express app
|
|
32
|
+
|
|
32
33
|
```bash
|
|
33
34
|
npm install @umeshindu222/apisnap
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
In your Express application, initialize APISnap **after** all your routes:
|
|
37
37
|
```javascript
|
|
38
38
|
const express = require('express');
|
|
39
39
|
const apisnap = require('@umeshindu222/apisnap');
|
|
40
|
+
|
|
40
41
|
const app = express();
|
|
41
42
|
|
|
43
|
+
// Your routes here
|
|
42
44
|
app.get('/users', (req, res) => res.json({ users: [] }));
|
|
45
|
+
app.post('/users', (req, res) => res.json({ message: 'Created' }));
|
|
43
46
|
|
|
44
|
-
// Add APISnap
|
|
47
|
+
// Add APISnap — place AFTER your routes
|
|
45
48
|
apisnap.init(app);
|
|
46
49
|
|
|
47
50
|
app.listen(3000);
|
|
48
51
|
```
|
|
49
52
|
|
|
50
|
-
### 2
|
|
51
|
-
Run this once in your project root to generate config templates:
|
|
52
|
-
```bash
|
|
53
|
-
npx @umeshindu222/apisnap init
|
|
54
|
-
```
|
|
53
|
+
### Step 2: Run the health check
|
|
55
54
|
|
|
56
|
-
### 3. Run the Check
|
|
57
55
|
```bash
|
|
58
|
-
npx @umeshindu222/apisnap
|
|
56
|
+
npx @umeshindu222/apisnap --port 3000
|
|
59
57
|
```
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## ⚙️ Configuration
|
|
64
|
-
|
|
65
|
-
APISnap uses a dual-config system to keep your secrets safe:
|
|
66
|
-
|
|
67
|
-
| File | Purpose | Git Status |
|
|
68
|
-
| :--- | :--- | :--- |
|
|
69
|
-
| `apisnap.json` | Shared team settings (Port, Slow Threshold) | **Commit to Git** |
|
|
70
|
-
| `apisnap.local.json` | Personal secrets (Auth Tokens, API Keys) | **Add to .gitignore** |
|
|
59
|
+
That's it. APISnap finds and tests every route automatically.
|
|
71
60
|
|
|
72
61
|
---
|
|
73
62
|
|
|
74
|
-
##
|
|
63
|
+
## 📋 CLI Usage
|
|
75
64
|
|
|
76
65
|
```bash
|
|
77
66
|
npx @umeshindu222/apisnap [options]
|
|
78
67
|
```
|
|
79
68
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
| Option | Description | Default |
|
|
70
|
+
|--------|-------------|---------|
|
|
71
|
+
| `-p, --port <number>` | Port your server is running on | `3000` |
|
|
72
|
+
| `-H, --header <string>` | Custom header for auth (e.g., `"Authorization: Bearer token"`) | — |
|
|
73
|
+
| `-s, --slow <number>` | Response time threshold in ms for slow warnings | `200` |
|
|
74
|
+
| `-e, --export <filename>` | Export results to a JSON file | — |
|
|
75
|
+
| `-V, --version` | Show version number | — |
|
|
76
|
+
| `-h, --help` | Show help | — |
|
|
84
77
|
|
|
85
78
|
---
|
|
86
79
|
|
package/dist/core/runner.js
CHANGED
|
@@ -8,48 +8,39 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const ora_1 = __importDefault(require("ora"));
|
|
10
10
|
const commander_1 = require("commander");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
11
|
const program = new commander_1.Command();
|
|
13
12
|
const { version } = require('../../package.json');
|
|
14
13
|
program
|
|
15
14
|
.name('apisnap')
|
|
16
15
|
.description('Instant API health-check CLI for Express.js')
|
|
17
16
|
.version(version)
|
|
18
|
-
.option('-p, --port <number>', '
|
|
19
|
-
.option('-H, --header <string>', '
|
|
20
|
-
.option('-s, --slow <number>', '
|
|
21
|
-
.option('-e, --export <filename>', 'Export results to JSON file (e.g., report.json)')
|
|
17
|
+
.option('-p, --port <number>', 'The port your server is running on', '3000')
|
|
18
|
+
.option('-H, --header <string>', 'Add a custom header (e.g., "Authorization: Bearer token")')
|
|
19
|
+
.option('-s, --slow <number>', 'Threshold for slow response warning (ms)', '200')
|
|
20
|
+
.option('-e, --export <filename>', 'Export results to a JSON file (e.g., report.json)')
|
|
22
21
|
.action(async (options) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
['apisnap.json', 'apisnap.local.json'].forEach(file => {
|
|
26
|
-
const filePath = path_1.default.join(process.cwd(), file);
|
|
27
|
-
if (fs_1.default.existsSync(filePath)) {
|
|
28
|
-
try {
|
|
29
|
-
const fileData = JSON.parse(fs_1.default.readFileSync(filePath, 'utf8'));
|
|
30
|
-
config = {
|
|
31
|
-
...config,
|
|
32
|
-
...fileData,
|
|
33
|
-
headers: { ...config.headers, ...fileData.headers }
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
console.log(chalk_1.default.yellow(`⚠️ Warning: Failed to parse ${file}`));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
// Final Priority: CLI Flags always win
|
|
42
|
-
const port = options.port || config.port;
|
|
43
|
-
const slowThreshold = options.slow ? parseInt(options.slow) : config.slowThreshold;
|
|
44
|
-
const finalHeaders = { ...config.headers };
|
|
45
|
-
if (options.header) {
|
|
46
|
-
const [key, ...val] = options.header.split(':');
|
|
47
|
-
finalHeaders[key.trim()] = val.join(':').trim();
|
|
48
|
-
}
|
|
22
|
+
const port = options.port;
|
|
23
|
+
const slowThreshold = parseInt(options.slow);
|
|
49
24
|
const discoveryUrl = `http://localhost:${port}/__apisnap_discovery`;
|
|
50
25
|
const results = []; // Collect all test results here
|
|
26
|
+
// Parse custom header from CLI flag
|
|
27
|
+
const customHeaders = {};
|
|
28
|
+
if (options.header) {
|
|
29
|
+
const [key, ...value] = options.header.split(':');
|
|
30
|
+
if (key && value) {
|
|
31
|
+
customHeaders[key.trim()] = value.join(':').trim();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
51
34
|
console.log(chalk_1.default.bold.cyan(`\n📸 APISnap v${version}`));
|
|
52
|
-
|
|
35
|
+
// Show active options
|
|
36
|
+
if (Object.keys(customHeaders).length > 0) {
|
|
37
|
+
console.log(chalk_1.default.gray(` Headers: ${JSON.stringify(customHeaders)}`));
|
|
38
|
+
}
|
|
39
|
+
console.log(chalk_1.default.gray(` Slow threshold: ${slowThreshold}ms`));
|
|
40
|
+
if (options.export) {
|
|
41
|
+
console.log(chalk_1.default.gray(` Export: ${options.export}`));
|
|
42
|
+
}
|
|
43
|
+
console.log();
|
|
53
44
|
const spinner = (0, ora_1.default)('Connecting to your API...').start();
|
|
54
45
|
try {
|
|
55
46
|
// 1. Fetch the route map from the middleware
|
|
@@ -86,9 +77,8 @@ program
|
|
|
86
77
|
method: method,
|
|
87
78
|
url: fullUrl,
|
|
88
79
|
headers: {
|
|
89
|
-
...
|
|
90
|
-
'
|
|
91
|
-
'User-Agent': `APISnap/${version}`,
|
|
80
|
+
...customHeaders,
|
|
81
|
+
'User-Agent': 'APISnap/1.0.0',
|
|
92
82
|
},
|
|
93
83
|
timeout: 5000,
|
|
94
84
|
});
|
|
@@ -146,7 +136,7 @@ program
|
|
|
146
136
|
config: {
|
|
147
137
|
port,
|
|
148
138
|
slowThreshold,
|
|
149
|
-
headers:
|
|
139
|
+
headers: customHeaders,
|
|
150
140
|
},
|
|
151
141
|
summary: {
|
|
152
142
|
total: endpoints.length,
|
|
@@ -166,29 +156,5 @@ program
|
|
|
166
156
|
process.exit(1);
|
|
167
157
|
}
|
|
168
158
|
});
|
|
169
|
-
program
|
|
170
|
-
.command('init')
|
|
171
|
-
.description('Initialize APISnap configuration files')
|
|
172
|
-
.action(() => {
|
|
173
|
-
const sharedConfig = {
|
|
174
|
-
port: 3000,
|
|
175
|
-
slowThreshold: 200,
|
|
176
|
-
description: "Shared project API settings"
|
|
177
|
-
};
|
|
178
|
-
const localConfig = {
|
|
179
|
-
headers: {
|
|
180
|
-
Authorization: "Bearer YOUR_PRIVATE_TOKEN_HERE"
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
// Create the files in the user's current directory
|
|
184
|
-
fs_1.default.writeFileSync('apisnap.json', JSON.stringify(sharedConfig, null, 2));
|
|
185
|
-
fs_1.default.writeFileSync('apisnap.local.json', JSON.stringify(localConfig, null, 2));
|
|
186
|
-
console.log(chalk_1.default.green.bold('\n✨ APISnap Initialized Successfully!'));
|
|
187
|
-
console.log(chalk_1.default.cyan('Created:'));
|
|
188
|
-
console.log(` 📄 ${chalk_1.default.white('apisnap.json')} (Shared - Push to GitHub)`);
|
|
189
|
-
console.log(` 📄 ${chalk_1.default.yellow('apisnap.local.json')} (Private - DO NOT PUSH)`);
|
|
190
|
-
console.log(chalk_1.default.red.bold('\n⚠️ IMPORTANT SECURITY STEP:'));
|
|
191
|
-
console.log(`Add ${chalk_1.default.yellow.bold('apisnap.local.json')} to your ${chalk_1.default.white('.gitignore')} file now!\n`);
|
|
192
|
-
});
|
|
193
159
|
program.parse(process.argv);
|
|
194
160
|
//# sourceMappingURL=runner.js.map
|
package/dist/core/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/core/runner.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,kDAA0B;AAC1B,kDAA0B;AAC1B,8CAAsB;AACtB,yCAAoC;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/core/runner.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,kDAA0B;AAC1B,kDAA0B;AAC1B,8CAAsB;AACtB,yCAAoC;AAEpC,MAAM,OA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B,eAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CACpE,CAAC;QACN,CAAC;IACL,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,GAAG,CAAC,wBAAwB,YAAY,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,MAAM,CACR,iEAAiE,CACpE,CACJ,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEP,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,GAAI,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,GAAI,KAAK,GAAG,SA4E5B,CAAC;;gBA5EwB,GAAG;;AA8E7B,wBAAwB"}
|
package/dist/middleware/index.js
CHANGED
|
@@ -2,20 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = void 0;
|
|
4
4
|
const init = (app) => {
|
|
5
|
-
const MASTER_KEY = 'apisnap_secret_handshake_2024';
|
|
6
5
|
const DISCOVERY_PATH = '/__apisnap_discovery';
|
|
7
|
-
// --- THE VIP GATE ---
|
|
8
|
-
app.use((req, res, next) => {
|
|
9
|
-
const clientKey = req.headers['x-apisnap-key'];
|
|
10
|
-
const isLocal = req.hostname === 'localhost' || req.hostname === '127.0.0.1';
|
|
11
|
-
// If the key matches AND it's local, we bypass ALL other auth (Better Auth, etc.)
|
|
12
|
-
if (clientKey === MASTER_KEY && isLocal) {
|
|
13
|
-
// We "mock" a dev user so the routes think someone is logged in
|
|
14
|
-
req.user = { id: 'dev-bypass', role: 'admin', name: 'APISnap-Bot' };
|
|
15
|
-
return next();
|
|
16
|
-
}
|
|
17
|
-
next();
|
|
18
|
-
});
|
|
19
6
|
// Recursive function to find ALL routes, even in sub-routers
|
|
20
7
|
const splitRoutes = (stack, prefix = '') => {
|
|
21
8
|
let routes = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":";;;AAEO,MAAM,IAAI,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC7B,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":";;;AAEO,MAAM,IAAI,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC7B,MAAM,cAAc,GAAG,sBAAsB,CAAC;IAE9C,6DAA6D;IAC7D,MAAM,WAAW,GAAG,CAAC,KAAY,EAAE,MAAM,GAAG,EAAE,EAAS,EAAE;QACrD,IAAI,MAAM,GAAU,EAAE,CAAC;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;YACzB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,sBAAsB;gBACtB,MAAM,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;gBACvC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACvD,CAAC,CAAC,WAAW,EAAE,CAClB,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5D,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC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O,CAAC;YACzB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,IAAI,CAAC;oBACD,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;gBACxB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACX,kDAAkD;gBACtD,CAAC;YACL,CAAC;YACD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,4BAA4B,EAAE,CAAC,CAAC;gBAC9D,OAAO;YACX,CAAC;YACD,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5C,GAAG,CAAC,IAAI,CAAC;gBACL,IAAI,EAAE,mBAAmB;gBACzB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,KAAK,EAAE,SAAS,CAAC,MAAM;gBACvB,SAAS,EAAE,SAAS;aACvB,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACjF,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACP,mBAAmB,EACnB,mCAAmC,cAAc,EAAE,CACtD,CAAC;AACN,CAAC,CAAC;AA5EW,QAAA,IAAI,QA4Ef;AAEF,kBAAe,EAAE,IAAI,EAAJ,YAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@umeshindu222/apisnap",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Instant API auto-discovery and health-check CLI for Express.js",
|
|
5
|
-
"main": "dist/middleware/index.js",
|
|
6
|
-
"types": "dist/middleware/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"apisnap": "bin/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"dist",
|
|
12
|
-
"bin",
|
|
13
|
-
"README.md"
|
|
14
|
-
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc",
|
|
17
|
-
"prepublishOnly": "npm run build"
|
|
18
|
-
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"express",
|
|
21
|
-
"api",
|
|
22
|
-
"testing",
|
|
23
|
-
"health-check",
|
|
24
|
-
"cli",
|
|
25
|
-
"automation"
|
|
26
|
-
],
|
|
27
|
-
"author": "Umesh Induranga",
|
|
28
|
-
"license": "MIT",
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"axios": "^1.13.6",
|
|
31
|
-
"chalk": "^5.6.2",
|
|
32
|
-
"commander": "^14.0.3",
|
|
33
|
-
"express": "^4.22.1",
|
|
34
|
-
"ora": "^9.3.0"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/express": "^5.0.6",
|
|
38
|
-
"@types/node": "^25.3.3",
|
|
39
|
-
"ts-node": "^10.9.2",
|
|
40
|
-
"typescript": "^5.9.3"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@umeshindu222/apisnap",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"description": "Instant API auto-discovery and health-check CLI for Express.js",
|
|
5
|
+
"main": "dist/middleware/index.js",
|
|
6
|
+
"types": "dist/middleware/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"apisnap": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"bin",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"express",
|
|
21
|
+
"api",
|
|
22
|
+
"testing",
|
|
23
|
+
"health-check",
|
|
24
|
+
"cli",
|
|
25
|
+
"automation"
|
|
26
|
+
],
|
|
27
|
+
"author": "Umesh Induranga",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.13.6",
|
|
31
|
+
"chalk": "^5.6.2",
|
|
32
|
+
"commander": "^14.0.3",
|
|
33
|
+
"express": "^4.22.1",
|
|
34
|
+
"ora": "^9.3.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/express": "^5.0.6",
|
|
38
|
+
"@types/node": "^25.3.3",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"typescript": "^5.9.3"
|
|
41
|
+
}
|
|
42
|
+
}
|