@usageflow/express 0.4.0 → 0.4.2
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 +17 -78
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +3 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/plugin.ts +4 -2
- package/test/plugin.test.ts +5 -40
package/README.md
CHANGED
|
@@ -20,24 +20,11 @@ const { ExpressUsageFlowAPI } = require('@usageflow/express');
|
|
|
20
20
|
const app = express();
|
|
21
21
|
app.use(express.json());
|
|
22
22
|
|
|
23
|
-
// Initialize UsageFlow with API key
|
|
24
|
-
const usageFlow = new ExpressUsageFlowAPI(
|
|
25
|
-
apiKey: 'YOUR_API_KEY',
|
|
26
|
-
poolSize: 5, // Optional: Number of WebSocket connections (default: 5)
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Create middleware
|
|
30
|
-
const middleware = usageFlow.createMiddleware(
|
|
31
|
-
[
|
|
32
|
-
{ method: '*', url: '*' }, // Track all routes
|
|
33
|
-
],
|
|
34
|
-
[
|
|
35
|
-
{ method: 'GET', url: '/api/health' }, // Whitelist health check
|
|
36
|
-
]
|
|
37
|
-
);
|
|
23
|
+
// Initialize UsageFlow with API key
|
|
24
|
+
const usageFlow = new ExpressUsageFlowAPI('YOUR_API_KEY');
|
|
38
25
|
|
|
39
26
|
// Apply middleware
|
|
40
|
-
app.use(
|
|
27
|
+
app.use(usageFlow.createMiddleware());
|
|
41
28
|
|
|
42
29
|
// Your routes
|
|
43
30
|
app.get('/api/users', (req, res) => {
|
|
@@ -58,24 +45,11 @@ import { ExpressUsageFlowAPI } from '@usageflow/express';
|
|
|
58
45
|
const app = express();
|
|
59
46
|
app.use(express.json());
|
|
60
47
|
|
|
61
|
-
// Initialize UsageFlow with API key
|
|
62
|
-
const usageFlow = new ExpressUsageFlowAPI(
|
|
63
|
-
apiKey: 'YOUR_API_KEY',
|
|
64
|
-
poolSize: 5, // Optional: Number of WebSocket connections (default: 5)
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Create middleware
|
|
68
|
-
const middleware = usageFlow.createMiddleware(
|
|
69
|
-
[
|
|
70
|
-
{ method: '*', url: '*' }, // Track all routes
|
|
71
|
-
],
|
|
72
|
-
[
|
|
73
|
-
{ method: 'GET', url: '/api/health' }, // Whitelist health check
|
|
74
|
-
]
|
|
75
|
-
);
|
|
48
|
+
// Initialize UsageFlow with API key
|
|
49
|
+
const usageFlow = new ExpressUsageFlowAPI('YOUR_API_KEY');
|
|
76
50
|
|
|
77
51
|
// Apply middleware
|
|
78
|
-
app.use(
|
|
52
|
+
app.use(usageFlow.createMiddleware());
|
|
79
53
|
|
|
80
54
|
// Your routes
|
|
81
55
|
app.get('/api/users', (req, res) => {
|
|
@@ -91,66 +65,31 @@ app.listen(3000, () => {
|
|
|
91
65
|
|
|
92
66
|
### ExpressUsageFlowAPI
|
|
93
67
|
|
|
94
|
-
#### Constructor
|
|
68
|
+
#### Constructor
|
|
95
69
|
|
|
96
70
|
```typescript
|
|
97
|
-
|
|
98
|
-
apiKey: string; // Your UsageFlow API key (required)
|
|
99
|
-
poolSize?: number; // Number of WebSocket connections (default: 5)
|
|
100
|
-
}
|
|
71
|
+
constructor(apiKey: string)
|
|
101
72
|
```
|
|
102
73
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Creates Express middleware for tracking API usage.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
createMiddleware(
|
|
109
|
-
routes: Route[], // Routes to track
|
|
110
|
-
whitelistRoutes?: Route[] // Routes to exclude from tracking
|
|
111
|
-
): (req: Request, res: Response, next: NextFunction) => Promise<void>
|
|
112
|
-
```
|
|
74
|
+
- `apiKey`: Your UsageFlow API key (required)
|
|
113
75
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
interface Route {
|
|
118
|
-
method: string; // HTTP method ('GET', 'POST', 'PUT', 'DELETE', etc.) or '*' for all methods
|
|
119
|
-
url: string; // URL pattern or '*' for all URLs
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### Examples
|
|
76
|
+
### createMiddleware
|
|
124
77
|
|
|
125
|
-
|
|
78
|
+
Creates Express middleware for tracking API usage. The middleware automatically tracks all routes and handles route configuration through the UsageFlow dashboard.
|
|
126
79
|
|
|
127
80
|
```typescript
|
|
128
|
-
|
|
81
|
+
createMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void>
|
|
129
82
|
```
|
|
130
83
|
|
|
131
|
-
|
|
84
|
+
#### Usage
|
|
132
85
|
|
|
133
86
|
```typescript
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
{ method: 'PUT', url: '/api/users/:id' },
|
|
138
|
-
]);
|
|
87
|
+
// Simple usage - tracks all routes automatically
|
|
88
|
+
const usageFlow = new ExpressUsageFlowAPI('YOUR_API_KEY');
|
|
89
|
+
app.use(usageFlow.createMiddleware());
|
|
139
90
|
```
|
|
140
91
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
const middleware = usageFlow.createMiddleware(
|
|
145
|
-
[
|
|
146
|
-
{ method: '*', url: '*' }, // Track all routes
|
|
147
|
-
],
|
|
148
|
-
[
|
|
149
|
-
{ method: 'GET', url: '/api/health' }, // Exclude health check
|
|
150
|
-
{ method: 'GET', url: '/api/metrics' }, // Exclude metrics
|
|
151
|
-
]
|
|
152
|
-
);
|
|
153
|
-
```
|
|
92
|
+
Route configuration (which routes to track, whitelist, etc.) is managed through the UsageFlow dashboard, not through code parameters.
|
|
154
93
|
|
|
155
94
|
## Features
|
|
156
95
|
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { UsageFlowAPI
|
|
2
|
+
import { UsageFlowAPI } from "@usageflow/core";
|
|
3
3
|
export declare class ExpressUsageFlowAPI extends UsageFlowAPI {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(apiKey: string);
|
|
5
5
|
/**
|
|
6
6
|
* Get the route pattern (e.g., /express/users/:id) from the request
|
|
7
7
|
* Tries multiple methods to get the route pattern since request.route
|
package/dist/plugin.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExpressUsageFlowAPI = void 0;
|
|
4
4
|
const core_1 = require("@usageflow/core");
|
|
5
5
|
class ExpressUsageFlowAPI extends core_1.UsageFlowAPI {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
6
|
+
constructor(apiKey) {
|
|
7
|
+
super({ apiKey });
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Get the route pattern (e.g., /express/users/:id) from the request
|
|
@@ -54,6 +54,7 @@ class ExpressUsageFlowAPI extends core_1.UsageFlowAPI {
|
|
|
54
54
|
metadata,
|
|
55
55
|
duration: 1000
|
|
56
56
|
};
|
|
57
|
+
console.log("executeRequestWithMetadata", payload);
|
|
57
58
|
await this.allocationRequest(request, payload, metadata, hasLimit);
|
|
58
59
|
}
|
|
59
60
|
createMiddleware() {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AACA,0CAAmJ;AAInJ,MAAa,mBAAoB,SAAQ,mBAAY;IACjD,YAAY,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AACA,0CAAmJ;AAInJ,MAAa,mBAAoB,SAAQ,mBAAY;IACjD,YAAY,MAAc;QACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACtB,CAAC;IACD;;;;OAIG;IAEK,KAAK,CAAC,sBAAsB,CAChC,OAAgB;QAEhB,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CA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,EAAE,QAAQ;wBACf,MAAM,EAAE,CAAC;wBACT,YAAY,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO;wBACxC,QAAQ,EAAE,QAA2B;qBACxC,CAAC;oBAEF,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;oBAClC,kCAAkC;oBAGlC,kCAAkC;oBAClC,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC9B,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5D,CAAC;oBACD,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;wBACjC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAC3D,CAAC;oBACD,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;gBACjE,CAAwB,CAAC;gBAEzB,IAAI,EAAE,CAAC;YACX,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBAClB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,OAAO,EAAE,IAAI;iBAChB,CAAC,CAAC;gBACH,OAAO;YACX,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CAEJ;AA1MD,kDA0MC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usageflow/express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "UsageFlow plugin for Express applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@usageflow/core": "^0.4.
|
|
17
|
+
"@usageflow/core": "^0.4.2",
|
|
18
18
|
"@usageflow/logger": "^0.1.1",
|
|
19
19
|
"express": "^4.18.0",
|
|
20
20
|
"ws": "^8.16.0"
|
package/src/plugin.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { UsageFlowAPI, Route, RequestMetadata, RequestForAllocation, UsageFlowRe
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class ExpressUsageFlowAPI extends UsageFlowAPI {
|
|
7
|
-
constructor(
|
|
8
|
-
super(
|
|
7
|
+
constructor(apiKey: string) {
|
|
8
|
+
super({ apiKey });
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Get the route pattern (e.g., /express/users/:id) from the request
|
|
@@ -74,6 +74,8 @@ export class ExpressUsageFlowAPI extends UsageFlowAPI {
|
|
|
74
74
|
duration: 1000
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
console.log("executeRequestWithMetadata", payload);
|
|
78
|
+
|
|
77
79
|
await this.allocationRequest(request as unknown as UsageFlowRequest, payload, metadata, hasLimit);
|
|
78
80
|
}
|
|
79
81
|
|
package/test/plugin.test.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { test, describe, beforeEach, afterEach } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
3
|
import { ExpressUsageFlowAPI } from '../src/plugin';
|
|
4
|
-
import { Route } from '@usageflow/core';
|
|
5
4
|
|
|
6
5
|
describe('ExpressUsageFlowAPI', () => {
|
|
7
6
|
let api: ExpressUsageFlowAPI;
|
|
8
7
|
|
|
9
8
|
beforeEach(() => {
|
|
10
|
-
api = new ExpressUsageFlowAPI(
|
|
11
|
-
apiKey: 'test-api-key',
|
|
12
|
-
poolSize: 1
|
|
13
|
-
});
|
|
9
|
+
api = new ExpressUsageFlowAPI('test-api-key');
|
|
14
10
|
// Mock socket manager
|
|
15
11
|
api.socketManager = {
|
|
16
12
|
connected: false,
|
|
@@ -30,36 +26,13 @@ describe('ExpressUsageFlowAPI', () => {
|
|
|
30
26
|
});
|
|
31
27
|
|
|
32
28
|
test('should create middleware', () => {
|
|
33
|
-
const
|
|
34
|
-
{ method: 'GET', url: '/users' }
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
const middleware = api.createMiddleware(routes);
|
|
29
|
+
const middleware = api.createMiddleware();
|
|
38
30
|
assert.strictEqual(typeof middleware, 'function');
|
|
39
31
|
assert.strictEqual(middleware.length, 3); // Express middleware signature
|
|
40
32
|
});
|
|
41
33
|
|
|
42
|
-
test('should create middleware with whitelist', () => {
|
|
43
|
-
const routes: Route[] = [
|
|
44
|
-
{ method: '*', url: '*' }
|
|
45
|
-
];
|
|
46
|
-
const whitelistRoutes: Route[] = [
|
|
47
|
-
{ method: 'GET', url: '/health' }
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const middleware = api.createMiddleware(routes, whitelistRoutes);
|
|
51
|
-
assert.strictEqual(typeof middleware, 'function');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
34
|
test.skip('should skip whitelisted routes', async () => {
|
|
55
|
-
const
|
|
56
|
-
{ method: '*', url: '*' }
|
|
57
|
-
];
|
|
58
|
-
const whitelistRoutes: Route[] = [
|
|
59
|
-
{ method: 'GET', url: '/health' }
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const middleware = api.createMiddleware(routes, whitelistRoutes);
|
|
35
|
+
const middleware = api.createMiddleware();
|
|
63
36
|
|
|
64
37
|
const req: any = {
|
|
65
38
|
method: 'GET',
|
|
@@ -97,11 +70,7 @@ describe('ExpressUsageFlowAPI', () => {
|
|
|
97
70
|
});
|
|
98
71
|
|
|
99
72
|
test('should monitor matching routes', async () => {
|
|
100
|
-
const
|
|
101
|
-
{ method: 'GET', url: '/users' }
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
const middleware = api.createMiddleware(routes);
|
|
73
|
+
const middleware = api.createMiddleware();
|
|
105
74
|
|
|
106
75
|
const req: any = {
|
|
107
76
|
method: 'GET',
|
|
@@ -155,11 +124,7 @@ describe('ExpressUsageFlowAPI', () => {
|
|
|
155
124
|
destroy() { }
|
|
156
125
|
} as any;
|
|
157
126
|
|
|
158
|
-
const
|
|
159
|
-
{ method: 'GET', url: '/users' }
|
|
160
|
-
];
|
|
161
|
-
|
|
162
|
-
const middleware = api.createMiddleware(routes);
|
|
127
|
+
const middleware = api.createMiddleware();
|
|
163
128
|
|
|
164
129
|
const req: any = {
|
|
165
130
|
method: 'GET',
|