@usageflow/express 0.1.0 → 0.1.1
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 +90 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @usageflow/express
|
|
2
|
+
|
|
3
|
+
Express.js middleware for UsageFlow API tracking. Easily monitor and analyze your Express.js API usage.
|
|
4
|
+
|
|
5
|
+
⚠️ **Beta Version Notice**: This package is currently in beta. Early adopters may encounter issues. We appreciate your feedback and contributions!
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @usageflow/express
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const express = require('express');
|
|
17
|
+
const { ExpressUsageFlowAPI } = require('@usageflow/express');
|
|
18
|
+
|
|
19
|
+
const app = express();
|
|
20
|
+
app.use(express.json());
|
|
21
|
+
|
|
22
|
+
// Initialize UsageFlow
|
|
23
|
+
const usageFlow = new ExpressUsageFlowAPI();
|
|
24
|
+
usageFlow.init('YOUR_API_KEY');
|
|
25
|
+
|
|
26
|
+
// Create middleware
|
|
27
|
+
const middleware = usageFlow.createMiddleware(
|
|
28
|
+
[
|
|
29
|
+
{ method: '*', url: '*' }, // Track all routes
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
{ method: 'GET', url: '/api/health' }, // Whitelist health check
|
|
33
|
+
]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Apply middleware
|
|
37
|
+
app.use(middleware);
|
|
38
|
+
|
|
39
|
+
// Your routes
|
|
40
|
+
app.get('/api/users', (req, res) => {
|
|
41
|
+
res.json({ users: ['John', 'Jane'] });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
app.listen(3000, () => {
|
|
45
|
+
console.log('Server running on port 3000');
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## TypeScript Support
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import express from 'express';
|
|
53
|
+
import { ExpressUsageFlowAPI } from '@usageflow/express';
|
|
54
|
+
|
|
55
|
+
const app = express();
|
|
56
|
+
app.use(express.json());
|
|
57
|
+
|
|
58
|
+
const usageFlow = new ExpressUsageFlowAPI();
|
|
59
|
+
usageFlow.init('YOUR_API_KEY');
|
|
60
|
+
|
|
61
|
+
// Rest of the code remains the same
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Configuration Options
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface Route {
|
|
68
|
+
method: string; // HTTP method or '*' for all methods
|
|
69
|
+
url: string; // URL pattern or '*' for all URLs
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
usageFlow.createMiddleware(
|
|
73
|
+
routes: Route[], // Routes to track
|
|
74
|
+
whitelistRoutes?: Route[] // Routes to exclude from tracking
|
|
75
|
+
);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Beta Status
|
|
79
|
+
|
|
80
|
+
This is a beta release meant for early adopters. You may encounter:
|
|
81
|
+
|
|
82
|
+
- API changes in future versions
|
|
83
|
+
- Incomplete features
|
|
84
|
+
- Potential bugs
|
|
85
|
+
|
|
86
|
+
We're actively working on improvements and appreciate your feedback!
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|