request-scope-api 1.0.16 → 1.0.18

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.
Files changed (2) hide show
  1. package/README.md +22 -157
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,16 +16,16 @@ npm install request-scope-api
16
16
 
17
17
  ```javascript
18
18
  import express from 'express';
19
- import request-scope-api from 'request-scope-api';
19
+ import { setup } from 'request-scope-api';
20
20
 
21
21
  const app = express();
22
22
 
23
- app.use(request-scope-api({
23
+ setup(app, {
24
24
  storage: {
25
25
  type: 'mongodb',
26
26
  uri: 'mongodb://localhost:27017/myapp'
27
27
  }
28
- }));
28
+ });
29
29
 
30
30
  app.listen(3000);
31
31
  ```
@@ -34,20 +34,23 @@ app.listen(3000);
34
34
 
35
35
  ```javascript
36
36
  import express from 'express';
37
- import request-scope-api from 'request-scope-api';
37
+ import { setup } from 'request-scope-api';
38
38
 
39
39
  const app = express();
40
40
 
41
- app.use(request-scope-api({
41
+ setup(app, {
42
42
  storage: {
43
43
  type: 'mysql',
44
44
  host: 'localhost',
45
45
  port: 3306,
46
- database: 'myapp',
47
- username: 'user',
48
- password: 'pass'
49
- }
50
- }));
46
+ database: 'truck_match_live_leatest',
47
+ username: 'root',
48
+ password: ''
49
+ },
50
+ retentionDays: 30,
51
+ ignore: ['/health', '/favicon.ico'],
52
+ maskFields: ['password']
53
+ });
51
54
 
52
55
  app.listen(3000);
53
56
  ```
@@ -56,11 +59,11 @@ app.listen(3000);
56
59
 
57
60
  ```javascript
58
61
  import express from 'express';
59
- import request-scope-api from 'request-scope-api';
62
+ import { setup } from 'request-scope-api';
60
63
 
61
64
  const app = express();
62
65
 
63
- app.use(request-scope-api({
66
+ setup(app, {
64
67
  storage: {
65
68
  type: 'postgresql',
66
69
  host: 'localhost',
@@ -69,123 +72,11 @@ app.use(request-scope-api({
69
72
  username: 'user',
70
73
  password: 'pass'
71
74
  }
72
- }));
75
+ });
73
76
 
74
77
  app.listen(3000);
75
78
  ```
76
79
 
77
- ## Dashboard
78
-
79
- Mount the dashboard at a specific path with optional authentication:
80
-
81
- ```javascript
82
- import request-scope-api from 'request-scope-api';
83
-
84
- const app = express();
85
-
86
- // Capture middleware
87
- app.use(request-scope-api({
88
- storage: {
89
- type: 'mongodb',
90
- uri: 'mongodb://localhost:27017/myapp'
91
- }
92
- }));
93
-
94
-
95
- ## Configuration
96
-
97
- ### request-scope-apiConfig
98
-
99
- | Option | Type | Default | Description |
100
- |--------|------|---------|-------------|
101
- | `storage` | `StorageConfig` | **required** | Database storage configuration |
102
- | `retentionDays` | `number` | `30` | Number of days to retain records (1-365) |
103
- | `ignore` | `string[]` | `[]` | URL paths to skip (no capture) |
104
- | `maskFields` | `string[]` | `[]` | Additional field names to mask (merged with built-in defaults) |
105
- | `dashboard` | `DashboardConfig` | `undefined` | Dashboard configuration |
106
-
107
- ### StorageConfig
108
-
109
- | Option | Type | Required For | Description |
110
- |--------|------|---------------|-------------|
111
- | `type` | `'mongodb' \| 'mysql' \| 'postgresql'` | All | Storage backend type |
112
- | `uri` | `string` | MongoDB | MongoDB connection URI |
113
- | `host` | `string` | MySQL, PostgreSQL | Database host |
114
- | `port` | `number` | MySQL, PostgreSQL | Database port |
115
- | `database` | `string` | MySQL, PostgreSQL | Database name |
116
- | `username` | `string` | MySQL, PostgreSQL | Database username |
117
- | `password` | `string` | MySQL, PostgreSQL | Database password |
118
- | `poolSize` | `number` | All | Connection pool size (default: 5) |
119
- | `ssl` | `boolean` | All | Enable SSL/TLS (default: false) |
120
-
121
- ### DashboardConfig
122
-
123
- | Option | Type | Default | Description |
124
- |--------|------|---------|-------------|
125
- | `auth` | `AuthConfig` | `undefined` | Authentication configuration |
126
- | `mountPath` | `string` | `"/request-scope-api"` | Mount path for the dashboard |
127
-
128
- ### AuthConfig
129
-
130
- | Option | Type | Description |
131
- |--------|------|-------------|
132
- | `username` | `string` | Basic auth username |
133
- | `password` | `string` | Basic auth password |
134
-
135
- ## Database-Specific Setup
136
-
137
- ### MongoDB
138
-
139
- - **URI Format**: `mongodb://[username:password@]host[:port][/database][?options]`
140
- - **Required Fields**: `uri`
141
- - **Optional**: `poolSize`, `ssl`
142
-
143
- Example:
144
- ```javascript
145
- storage: {
146
- type: 'mongodb',
147
- uri: 'mongodb://user:pass@localhost:27017/myapp?authSource=admin'
148
- }
149
- ```
150
-
151
- ### MySQL
152
-
153
- - **Required Fields**: `host`, `port`, `database`, `username`, `password`
154
- - **Optional**: `poolSize`, `ssl`
155
-
156
- Example:
157
- ```javascript
158
- storage: {
159
- type: 'mysql',
160
- host: 'localhost',
161
- port: 3306,
162
- database: 'myapp',
163
- username: 'user',
164
- password: 'pass',
165
- poolSize: 10,
166
- ssl: true
167
- }
168
- ```
169
-
170
- ### PostgreSQL
171
-
172
- - **Required Fields**: `host`, `port`, `database`, `username`, `password`
173
- - **Optional**: `poolSize`, `ssl`
174
-
175
- Example:
176
- ```javascript
177
- storage: {
178
- type: 'postgresql',
179
- host: 'localhost',
180
- port: 5432,
181
- database: 'myapp',
182
- username: 'user',
183
- password: 'pass',
184
- poolSize: 10,
185
- ssl: true
186
- }
187
- ```
188
-
189
80
  ## Features
190
81
 
191
82
  - **Zero Configuration**: Works out of the box with sensible defaults
@@ -211,10 +102,10 @@ request-scope-api automatically masks sensitive fields in request headers, reque
211
102
  Add custom fields to mask via the `maskFields` configuration:
212
103
 
213
104
  ```javascript
214
- app.use(request-scope-api({
105
+ setup(app, {
215
106
  storage: { /* ... */ },
216
107
  maskFields: ['creditCard', 'ssn', 'apiKey']
217
- }));
108
+ });
218
109
  ```
219
110
 
220
111
  ## Ignoring Paths
@@ -222,10 +113,10 @@ app.use(request-scope-api({
222
113
  Skip capture for specific URL paths:
223
114
 
224
115
  ```javascript
225
- app.use(request-scope-api({
116
+ setup(app, {
226
117
  storage: { /* ... */ },
227
118
  ignore: ['/health', '/metrics', '/favicon.ico']
228
- }));
119
+ });
229
120
  ```
230
121
 
231
122
  ## Error Handling
@@ -233,9 +124,9 @@ app.use(request-scope-api({
233
124
  To capture error data, use the provided error middleware:
234
125
 
235
126
  ```javascript
236
- import request-scope-api, { errorHandler } from 'request-scope-api';
127
+ import { setup, errorHandler } from 'request-scope-api';
237
128
 
238
- app.use(request-scope-api({ /* ... */ }));
129
+ setup(app, { /* ... */ });
239
130
  app.use(errorHandler);
240
131
 
241
132
  // Your routes
@@ -247,29 +138,3 @@ app.get('/api/users', async (req, res, next) => {
247
138
  }
248
139
  });
249
140
  ```
250
-
251
- ## API Endpoints
252
-
253
- The dashboard provides the following API endpoints:
254
-
255
- - `GET /api/records` - List records with filtering, sorting, and pagination
256
- - `GET /api/records/:id` - Get a single record by ID
257
-
258
- ### Query Parameters (GET /api/records)
259
-
260
- | Parameter | Type | Description |
261
- |-----------|------|-------------|
262
- | `search` | `string` | Case-insensitive substring match on URL |
263
- | `startDate` | `string` | ISO 8601 timestamp (inclusive lower bound) |
264
- | `endDate` | `string` | ISO 8601 timestamp (inclusive upper bound) |
265
- | `statusCodeGroup` | `string` | Status code group: `2xx`, `3xx`, `4xx`, `5xx` |
266
- | `statusCode` | `number` | Exact status code match |
267
- | `method` | `string` | Exact HTTP method match (case-insensitive) |
268
- | `sortBy` | `string` | Sort field: `timestamp`, `responseTime`, `statusCode` |
269
- | `sortOrder` | `string` | Sort order: `asc`, `desc` |
270
- | `page` | `number` | Page number (default: 1) |
271
- | `pageSize` | `number` | Page size (default: 25) |
272
-
273
- ## License
274
-
275
- MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "request-scope-api",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Zero-friction API request observability for Express.js applications",
5
5
  "keywords": [
6
6
  "express",