@reproapp/node-sdk 0.0.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 +343 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +2535 -0
- package/dist/integrations/sendgrid.d.ts +20 -0
- package/dist/integrations/sendgrid.js +177 -0
- package/dist/redaction.d.ts +44 -0
- package/dist/redaction.js +167 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +26 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# Repro Nest SDK
|
|
2
|
+
|
|
3
|
+
Capture NestJS request/response data, function traces, and Mongoose activity for
|
|
4
|
+
Repro sessions. This SDK is designed for Nest apps running on Express, with
|
|
5
|
+
optional tracing and masking controls.
|
|
6
|
+
|
|
7
|
+
## 1) Install
|
|
8
|
+
|
|
9
|
+
Requirements:
|
|
10
|
+
- Node.js 18+
|
|
11
|
+
- NestJS app using Express (default) and optionally Mongoose 6+
|
|
12
|
+
|
|
13
|
+
Install the package:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install repro-nest
|
|
17
|
+
# or
|
|
18
|
+
yarn add repro-nest
|
|
19
|
+
# or
|
|
20
|
+
pnpm add repro-nest
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 2) Configure
|
|
24
|
+
|
|
25
|
+
At minimum, provide your Repro credentials and wire the middleware. If you want
|
|
26
|
+
function tracing, call `initReproTracing` before importing your `AppModule` so
|
|
27
|
+
Nest classes are instrumented at load time.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import 'reflect-metadata';
|
|
31
|
+
import { NestFactory } from '@nestjs/core';
|
|
32
|
+
import mongoose from 'mongoose';
|
|
33
|
+
import {
|
|
34
|
+
initReproTracing,
|
|
35
|
+
reproMiddleware,
|
|
36
|
+
reproMongoosePlugin,
|
|
37
|
+
} from 'repro-nest';
|
|
38
|
+
|
|
39
|
+
const reproConfig = {
|
|
40
|
+
appId: process.env.REPRO_APP_ID as string,
|
|
41
|
+
appName: process.env.REPRO_APP_NAME as string,
|
|
42
|
+
tenantId: process.env.REPRO_TENANT_ID as string,
|
|
43
|
+
appSecret: process.env.REPRO_APP_SECRET as string,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
async function bootstrap() {
|
|
47
|
+
// Enable function tracing before loading your modules.
|
|
48
|
+
initReproTracing({
|
|
49
|
+
disableFunctionTypes: ['constructor'],
|
|
50
|
+
logFunctionCalls: false,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Optional: capture MongoDB queries + document diffs.
|
|
54
|
+
mongoose.plugin(reproMongoosePlugin(reproConfig));
|
|
55
|
+
|
|
56
|
+
const { AppModule } = await import('./app.module');
|
|
57
|
+
const app = await NestFactory.create(AppModule);
|
|
58
|
+
|
|
59
|
+
// Capture request/response payloads for tagged Repro sessions.
|
|
60
|
+
app.use(reproMiddleware(reproConfig));
|
|
61
|
+
|
|
62
|
+
await app.listen(3000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bootstrap();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Configuration notes:
|
|
69
|
+
- `REPRO_API_BASE` (optional) overrides the backend base URL used to send data.
|
|
70
|
+
- `REPRO_APP_NAME` (optional) sets `appName`, which is sent as `X-App-Name`.
|
|
71
|
+
|
|
72
|
+
### initReproTracing
|
|
73
|
+
|
|
74
|
+
Enables function tracing. Call this before importing `AppModule` so Nest classes
|
|
75
|
+
are loaded through the tracer.
|
|
76
|
+
|
|
77
|
+
Options (type -> purpose):
|
|
78
|
+
- `instrument` (boolean): enable or disable instrumentation of loaded modules.
|
|
79
|
+
- `include` (RegExp[]): file path include patterns for instrumentation.
|
|
80
|
+
- `exclude` (RegExp[]): file path exclude patterns for instrumentation.
|
|
81
|
+
- `mode` (string): tracer mode (defaults to `TRACE_MODE` or `trace`).
|
|
82
|
+
- `samplingMs` (number): sampling interval in milliseconds.
|
|
83
|
+
- `disableFunctionTraces` (DisableFunctionTraceConfig[] | null): drop trace events
|
|
84
|
+
that match rule objects or predicates.
|
|
85
|
+
- `disableFunctionTypes` (TraceRulePattern | null): drop events for matching
|
|
86
|
+
function kinds (for example, constructors).
|
|
87
|
+
- `disableTraceFiles` (DisableTraceFileConfig | DisableTraceFileConfig[] | null):
|
|
88
|
+
drop events emitted from matching files.
|
|
89
|
+
- `traceInterceptors` (boolean): include Nest interceptors in traces (default false).
|
|
90
|
+
- `logFunctionCalls` (boolean): log enter/exit events to console.
|
|
91
|
+
|
|
92
|
+
Type reference:
|
|
93
|
+
- `TraceRulePattern`: `string | number | RegExp | Array<string | number | RegExp>`
|
|
94
|
+
- `DisableFunctionTraceConfig`: `DisableFunctionTraceRule | DisableFunctionTracePredicate`
|
|
95
|
+
- `DisableFunctionTracePredicate`: `(event: TraceEventForFilter) => boolean`
|
|
96
|
+
- `DisableFunctionTraceRule` fields (all accept `TraceRulePattern`):
|
|
97
|
+
- `fn` / `functionName`: function name substring/regex
|
|
98
|
+
- `wrapper` / `wrapperClass` / `className` / `owner`: wrapper/owner name
|
|
99
|
+
- `file`: source filename
|
|
100
|
+
- `line`: source line number
|
|
101
|
+
- `lib` / `library`: npm package name inferred from path
|
|
102
|
+
- `type` / `functionType`: function kind (`method`, `constructor`, etc.)
|
|
103
|
+
- `event` / `eventType`: trace phase (`enter` or `exit`)
|
|
104
|
+
- `DisableTraceByFilename`: `{ file: TraceRulePattern }`
|
|
105
|
+
- `DisableTraceFileConfig`: `TraceRulePattern | DisableTraceByFilename | null | undefined`
|
|
106
|
+
|
|
107
|
+
Full config example (shows every option; aliases are interchangeable, use one per group in real configs):
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { initReproTracing } from 'repro-nest';
|
|
111
|
+
|
|
112
|
+
initReproTracing({
|
|
113
|
+
instrument: true,
|
|
114
|
+
include: [/^\/app\/src\//],
|
|
115
|
+
exclude: [/node_modules\//, /dist\//],
|
|
116
|
+
mode: process.env.TRACE_MODE || 'trace',
|
|
117
|
+
samplingMs: 10,
|
|
118
|
+
disableFunctionTraces: [
|
|
119
|
+
{
|
|
120
|
+
fn: 'findAll',
|
|
121
|
+
wrapper: 'TasksService',
|
|
122
|
+
file: 'src/tasks/tasks.service.ts',
|
|
123
|
+
line: 27,
|
|
124
|
+
lib: 'mongoose',
|
|
125
|
+
type: 'method',
|
|
126
|
+
event: 'exit',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
functionName: 'formatSensitiveData',
|
|
130
|
+
wrapperClass: 'AuthService',
|
|
131
|
+
className: 'AuthService',
|
|
132
|
+
owner: 'AuthService',
|
|
133
|
+
library: 'bcrypt',
|
|
134
|
+
functionType: 'method',
|
|
135
|
+
eventType: 'enter',
|
|
136
|
+
},
|
|
137
|
+
(event) => event.fn?.startsWith('debug') ?? false,
|
|
138
|
+
],
|
|
139
|
+
disableFunctionTypes: ['constructor', /getter/i],
|
|
140
|
+
disableTraceFiles: [
|
|
141
|
+
/node_modules\/some-logger\//,
|
|
142
|
+
{ file: 'dist/health.check.js' },
|
|
143
|
+
'dist/generated.js',
|
|
144
|
+
],
|
|
145
|
+
traceInterceptors: true,
|
|
146
|
+
logFunctionCalls: false,
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### reproMiddleware
|
|
151
|
+
|
|
152
|
+
Captures request/response payloads for active Repro sessions. Requests must
|
|
153
|
+
include `x-bug-session-id` and `x-bug-action-id` headers to be captured.
|
|
154
|
+
|
|
155
|
+
Options (type -> purpose):
|
|
156
|
+
- `appId` (string): Repro app id.
|
|
157
|
+
- `appName` (string, optional): Repro app name (sent as `X-App-Name`).
|
|
158
|
+
- `tenantId` (string): Repro tenant id.
|
|
159
|
+
- `appSecret` (string): Repro app secret.
|
|
160
|
+
- `captureHeaders` (boolean | HeaderCaptureOptions): enable/disable header capture
|
|
161
|
+
and masking.
|
|
162
|
+
- `masking` (ReproMaskingConfig): mask request/response bodies and trace args/returns.
|
|
163
|
+
|
|
164
|
+
Header capture options (`HeaderCaptureOptions`):
|
|
165
|
+
- `allowSensitiveHeaders` (boolean): keep default sensitive headers unmasked.
|
|
166
|
+
- `maskHeaders` (HeaderRule | HeaderRule[]): header names to mask.
|
|
167
|
+
- `dropHeaders` (HeaderRule | HeaderRule[]): alias for `maskHeaders`.
|
|
168
|
+
- `unmaskHeaders` (HeaderRule | HeaderRule[]): header names to keep unmasked.
|
|
169
|
+
- `keepHeaders` (HeaderRule | HeaderRule[]): alias for `unmaskHeaders`.
|
|
170
|
+
- `HeaderRule`: `string | RegExp`
|
|
171
|
+
|
|
172
|
+
Masking options (`ReproMaskingConfig`):
|
|
173
|
+
- `replacement` (any): default replacement value (defaults to `"[REDACTED]"`).
|
|
174
|
+
- `rules` (ReproMaskRule[] | null): list of masking rules.
|
|
175
|
+
|
|
176
|
+
Masking rule options (`ReproMaskRule`):
|
|
177
|
+
- `when` (ReproMaskWhen): scope rules by request or function trace fields.
|
|
178
|
+
- `target` (ReproMaskTarget | ReproMaskTarget[]): where to apply the mask.
|
|
179
|
+
- `paths` (string | string[]): dot/bracket paths to mask.
|
|
180
|
+
- `keys` (TraceRulePattern): mask keys anywhere in the payload.
|
|
181
|
+
- `replacement` (any): override replacement value for this rule.
|
|
182
|
+
|
|
183
|
+
`ReproMaskTarget` values:
|
|
184
|
+
- `request.headers`, `request.body`, `request.params`, `request.query`
|
|
185
|
+
- `response.body`, `trace.args`, `trace.returnValue`, `trace.error`
|
|
186
|
+
|
|
187
|
+
`ReproMaskWhen` fields (all accept `TraceRulePattern` unless noted):
|
|
188
|
+
- Request scope: `method`, `path`, `key`
|
|
189
|
+
- Function scope: `fn` / `functionName`, `wrapper` / `wrapperClass` / `className` / `owner`,
|
|
190
|
+
`file`, `line`, `lib` / `library`, `type` / `functionType`, `event` / `eventType`
|
|
191
|
+
|
|
192
|
+
Full config example (shows every option; aliases are interchangeable, use one per group in real configs):
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { reproMiddleware } from 'repro-nest';
|
|
196
|
+
|
|
197
|
+
app.use(reproMiddleware({
|
|
198
|
+
appId: process.env.REPRO_APP_ID as string,
|
|
199
|
+
appName: process.env.REPRO_APP_NAME as string,
|
|
200
|
+
tenantId: process.env.REPRO_TENANT_ID as string,
|
|
201
|
+
appSecret: process.env.REPRO_APP_SECRET as string,
|
|
202
|
+
captureHeaders: {
|
|
203
|
+
allowSensitiveHeaders: false,
|
|
204
|
+
maskHeaders: [/authorization/i, /cookie/i],
|
|
205
|
+
dropHeaders: ['x-api-key'],
|
|
206
|
+
unmaskHeaders: ['x-request-id'],
|
|
207
|
+
keepHeaders: ['x-trace-id'],
|
|
208
|
+
},
|
|
209
|
+
masking: {
|
|
210
|
+
replacement: '[REDACTED]',
|
|
211
|
+
rules: [
|
|
212
|
+
{
|
|
213
|
+
when: { method: 'POST', path: '/api/auth/login', key: 'POST /api/auth/login' },
|
|
214
|
+
target: ['request.body', 'response.body'],
|
|
215
|
+
paths: ['password'],
|
|
216
|
+
keys: [/token/i],
|
|
217
|
+
replacement: '[FILTERED]',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
when: {
|
|
221
|
+
functionName: 'findAll',
|
|
222
|
+
wrapperClass: 'TasksService',
|
|
223
|
+
file: 'src/tasks/tasks.service.ts',
|
|
224
|
+
line: 27,
|
|
225
|
+
library: 'mongoose',
|
|
226
|
+
functionType: 'method',
|
|
227
|
+
eventType: 'exit',
|
|
228
|
+
},
|
|
229
|
+
target: ['trace.args', 'trace.returnValue', 'trace.error'],
|
|
230
|
+
paths: ['0.user.token'],
|
|
231
|
+
keys: ['password'],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
when: {
|
|
235
|
+
fn: 'create',
|
|
236
|
+
wrapper: 'UsersService',
|
|
237
|
+
className: 'UsersService',
|
|
238
|
+
owner: 'UsersService',
|
|
239
|
+
lib: 'mongoose',
|
|
240
|
+
type: 'method',
|
|
241
|
+
event: 'enter',
|
|
242
|
+
},
|
|
243
|
+
target: 'trace.args',
|
|
244
|
+
paths: ['0.password'],
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
}));
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
See `docs/tracing.md` for full masking and trace filtering details.
|
|
252
|
+
|
|
253
|
+
### Mongoose plugin
|
|
254
|
+
|
|
255
|
+
`reproMongoosePlugin` attaches schema middleware to capture query activity and
|
|
256
|
+
document diffs. It emits data only when a Repro session is active (i.e., when
|
|
257
|
+
`reproMiddleware` has set the session context for the current request).
|
|
258
|
+
|
|
259
|
+
Arguments:
|
|
260
|
+
- `appId` (string): Repro app id
|
|
261
|
+
- `appName` (string, optional): Repro app name (sent as `X-App-Name`)
|
|
262
|
+
- `tenantId` (string): Repro tenant id
|
|
263
|
+
- `appSecret` (string): Repro app secret
|
|
264
|
+
|
|
265
|
+
Example: global plugin (all schemas)
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
import mongoose from 'mongoose';
|
|
269
|
+
import { reproMongoosePlugin } from 'repro-nest';
|
|
270
|
+
|
|
271
|
+
mongoose.plugin(reproMongoosePlugin({
|
|
272
|
+
appId: process.env.REPRO_APP_ID as string,
|
|
273
|
+
appName: process.env.REPRO_APP_NAME as string,
|
|
274
|
+
tenantId: process.env.REPRO_TENANT_ID as string,
|
|
275
|
+
appSecret: process.env.REPRO_APP_SECRET as string,
|
|
276
|
+
}));
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Example: Nest `MongooseModule` connection factory
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
import { MongooseModule } from '@nestjs/mongoose';
|
|
283
|
+
import { reproMongoosePlugin } from 'repro-nest';
|
|
284
|
+
|
|
285
|
+
MongooseModule.forRoot(process.env.MONGO_URL as string, {
|
|
286
|
+
connectionFactory: (connection) => {
|
|
287
|
+
connection.plugin(reproMongoosePlugin({
|
|
288
|
+
appId: process.env.REPRO_APP_ID as string,
|
|
289
|
+
appName: process.env.REPRO_APP_NAME as string,
|
|
290
|
+
tenantId: process.env.REPRO_TENANT_ID as string,
|
|
291
|
+
appSecret: process.env.REPRO_APP_SECRET as string,
|
|
292
|
+
}));
|
|
293
|
+
return connection;
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Example: schema-level plugin (single model)
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
import { Schema } from 'mongoose';
|
|
302
|
+
import { reproMongoosePlugin } from 'repro-nest';
|
|
303
|
+
|
|
304
|
+
const userSchema = new Schema({ email: String });
|
|
305
|
+
userSchema.plugin(reproMongoosePlugin({
|
|
306
|
+
appId: process.env.REPRO_APP_ID as string,
|
|
307
|
+
appName: process.env.REPRO_APP_NAME as string,
|
|
308
|
+
tenantId: process.env.REPRO_TENANT_ID as string,
|
|
309
|
+
appSecret: process.env.REPRO_APP_SECRET as string,
|
|
310
|
+
}));
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## 3) Run
|
|
314
|
+
|
|
315
|
+
Run your Nest app as usual after wiring the SDK:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
npm run start:dev
|
|
319
|
+
# or
|
|
320
|
+
node dist/main.js
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
If you use `initReproTracing`, keep it at the top of your bootstrap so modules
|
|
324
|
+
load after instrumentation is enabled.
|
|
325
|
+
|
|
326
|
+
## 4) Verify It Works
|
|
327
|
+
|
|
328
|
+
Send a request with Repro headers and confirm the session shows up in Repro.
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
curl \
|
|
332
|
+
-H "x-bug-session-id: session-123" \
|
|
333
|
+
-H "x-bug-action-id: action-123" \
|
|
334
|
+
http://localhost:3000/health
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Verification tips:
|
|
338
|
+
- If the Repro UI does not show the session, confirm `REPRO_API_BASE` and
|
|
339
|
+
credentials are correct.
|
|
340
|
+
- Temporarily set `logFunctionCalls: true` in `initReproTracing` to see trace
|
|
341
|
+
enter/exit logs in your console.
|
|
342
|
+
- If you use Mongoose, exercise a query/mutation and verify DB entries appear
|
|
343
|
+
in the session trace.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/session" />
|
|
19
|
+
/// <reference types="mongoose/types/types" />
|
|
20
|
+
/// <reference types="mongoose/types/utility" />
|
|
21
|
+
/// <reference types="mongoose/types/validation" />
|
|
22
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
27
|
+
import type { Schema } from 'mongoose';
|
|
28
|
+
type SpanContext = {
|
|
29
|
+
traceId: string | null;
|
|
30
|
+
spanId: string | number | null;
|
|
31
|
+
parentSpanId: string | number | null;
|
|
32
|
+
depth: number | null;
|
|
33
|
+
};
|
|
34
|
+
type TracerApi = {
|
|
35
|
+
init?: (opts: any) => void;
|
|
36
|
+
tracer?: {
|
|
37
|
+
on: (fn: (ev: any) => void) => () => void;
|
|
38
|
+
};
|
|
39
|
+
getCurrentTraceId?: () => string | null;
|
|
40
|
+
getCurrentSpanContext?: () => SpanContext | null;
|
|
41
|
+
patchHttp?: () => void;
|
|
42
|
+
setFunctionLogsEnabled?: (enabled: boolean) => void;
|
|
43
|
+
};
|
|
44
|
+
type TraceEventPhase = 'enter' | 'exit';
|
|
45
|
+
export type TraceRulePattern = string | number | RegExp | Array<string | number | RegExp>;
|
|
46
|
+
export type TraceEventForFilter = {
|
|
47
|
+
type: TraceEventPhase;
|
|
48
|
+
eventType: TraceEventPhase;
|
|
49
|
+
functionType?: string | null;
|
|
50
|
+
fn?: string;
|
|
51
|
+
wrapperClass?: string | null;
|
|
52
|
+
file?: string | null;
|
|
53
|
+
line?: number | null;
|
|
54
|
+
depth?: number;
|
|
55
|
+
library?: string | null;
|
|
56
|
+
};
|
|
57
|
+
export type HeaderRule = string | RegExp;
|
|
58
|
+
export type HeaderCaptureOptions = {
|
|
59
|
+
/** When true, sensitive headers such as Authorization are kept unmasked; default masks them. */
|
|
60
|
+
allowSensitiveHeaders?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Header names (string or RegExp) to mask.
|
|
63
|
+
* `dropHeaders` is kept for backward-compatibility and treated as an alias for `maskHeaders`.
|
|
64
|
+
*/
|
|
65
|
+
maskHeaders?: HeaderRule | HeaderRule[];
|
|
66
|
+
/** @deprecated Alias for {@link maskHeaders}. */
|
|
67
|
+
dropHeaders?: HeaderRule | HeaderRule[];
|
|
68
|
+
/**
|
|
69
|
+
* Header names (string or RegExp) to keep unmasked, overriding defaults and `maskHeaders`.
|
|
70
|
+
* `keepHeaders` is kept for backward-compatibility and treated as an alias for `unmaskHeaders`.
|
|
71
|
+
*/
|
|
72
|
+
unmaskHeaders?: HeaderRule | HeaderRule[];
|
|
73
|
+
/** @deprecated Alias for {@link unmaskHeaders}. */
|
|
74
|
+
keepHeaders?: HeaderRule | HeaderRule[];
|
|
75
|
+
};
|
|
76
|
+
/** Lightweight helper to disable every trace emitted from specific files. */
|
|
77
|
+
export interface DisableTraceByFilename {
|
|
78
|
+
file: TraceRulePattern;
|
|
79
|
+
}
|
|
80
|
+
type DisableTraceFileConfig = TraceRulePattern | DisableTraceByFilename | null | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Declarative rule that disables trace events matching the provided patterns.
|
|
83
|
+
*
|
|
84
|
+
* Each property accepts a string (substring match), a RegExp, or an array of
|
|
85
|
+
* either. When an array is provided, a single match of any entry is enough to
|
|
86
|
+
* drop the event. Provide no value to leave that dimension unrestricted.
|
|
87
|
+
*/
|
|
88
|
+
export type DisableFunctionTraceRule = {
|
|
89
|
+
/** Shortcut for {@link functionName}. */
|
|
90
|
+
fn?: TraceRulePattern;
|
|
91
|
+
/** Function name (e.g. `"findOne"`, `/^UserService\./`). */
|
|
92
|
+
functionName?: TraceRulePattern;
|
|
93
|
+
/** Shortcut for {@link wrapperClass}. */
|
|
94
|
+
wrapper?: TraceRulePattern;
|
|
95
|
+
/**
|
|
96
|
+
* Wrapper/owner name derived from {@link functionName} (e.g. `"UserService"` in `"UserService.create"`).
|
|
97
|
+
* Useful when multiple functions share the same method name.
|
|
98
|
+
*/
|
|
99
|
+
wrapperClass?: TraceRulePattern;
|
|
100
|
+
/** Alias for {@link wrapperClass}. */
|
|
101
|
+
className?: TraceRulePattern;
|
|
102
|
+
/** Alias for {@link wrapperClass}. */
|
|
103
|
+
owner?: TraceRulePattern;
|
|
104
|
+
/** Source filename reported by the trace event. */
|
|
105
|
+
file?: TraceRulePattern;
|
|
106
|
+
/** Line number reported by the trace event. */
|
|
107
|
+
line?: TraceRulePattern;
|
|
108
|
+
/** Shortcut for {@link library}. */
|
|
109
|
+
lib?: TraceRulePattern;
|
|
110
|
+
/** Library/package name inferred from the file path (e.g. `"mongoose"`). */
|
|
111
|
+
library?: TraceRulePattern;
|
|
112
|
+
/** Shortcut for {@link functionType}. */
|
|
113
|
+
type?: TraceRulePattern;
|
|
114
|
+
/** Function classification such as `"constructor"`, `"method"`, or `"arrow"`. */
|
|
115
|
+
functionType?: TraceRulePattern;
|
|
116
|
+
/** Shortcut for {@link eventType}. */
|
|
117
|
+
event?: TraceRulePattern;
|
|
118
|
+
/** Trace phase to filter (`"enter"` or `"exit"`). */
|
|
119
|
+
eventType?: TraceRulePattern;
|
|
120
|
+
};
|
|
121
|
+
export type DisableFunctionTracePredicate = (event: TraceEventForFilter) => boolean;
|
|
122
|
+
export type DisableFunctionTraceConfig = DisableFunctionTraceRule | DisableFunctionTracePredicate;
|
|
123
|
+
export type ReproMaskTarget = 'request.headers' | 'request.body' | 'request.params' | 'request.query' | 'response.body' | 'trace.args' | 'trace.returnValue' | 'trace.error';
|
|
124
|
+
export type ReproMaskWhen = DisableFunctionTraceRule & {
|
|
125
|
+
/** Match HTTP method (e.g. `"GET"`, `/^post$/i`). */
|
|
126
|
+
method?: TraceRulePattern;
|
|
127
|
+
/** Match request path without query string (e.g. `"/api/auth/login"`). */
|
|
128
|
+
path?: TraceRulePattern;
|
|
129
|
+
/** Match normalized endpoint key (e.g. `"POST /api/auth/login"`). */
|
|
130
|
+
key?: TraceRulePattern;
|
|
131
|
+
};
|
|
132
|
+
export type ReproMaskRule = {
|
|
133
|
+
when?: ReproMaskWhen;
|
|
134
|
+
target: ReproMaskTarget | ReproMaskTarget[];
|
|
135
|
+
/**
|
|
136
|
+
* Dot/bracket paths to mask (supports `*`, `[0]`, `[*]`).
|
|
137
|
+
* Examples: `"password"`, `"user.token"`, `"items[*].serial"`, `"0.password"` (for trace args arrays).
|
|
138
|
+
*/
|
|
139
|
+
paths?: string | string[];
|
|
140
|
+
/** Key name patterns to mask anywhere in the payload. */
|
|
141
|
+
keys?: TraceRulePattern;
|
|
142
|
+
/** Override replacement value for this rule (defaults to config replacement / `"[REDACTED]"`). */
|
|
143
|
+
replacement?: any;
|
|
144
|
+
};
|
|
145
|
+
export type ReproMaskingConfig = {
|
|
146
|
+
/** Default replacement value (defaults to `"[REDACTED]"`). */
|
|
147
|
+
replacement?: any;
|
|
148
|
+
rules?: ReproMaskRule[] | null;
|
|
149
|
+
};
|
|
150
|
+
export declare function setDisabledFunctionTraces(rules?: DisableFunctionTraceConfig[] | null): void;
|
|
151
|
+
export declare function setDisabledFunctionTypes(patterns?: TraceRulePattern | null): void;
|
|
152
|
+
export declare function setDisabledTraceFiles(config?: DisableTraceFileConfig | DisableTraceFileConfig[] | null): void;
|
|
153
|
+
export declare function setReproTraceLogsEnabled(enabled: boolean): void;
|
|
154
|
+
export declare function enableReproTraceLogs(): void;
|
|
155
|
+
export declare function disableReproTraceLogs(): void;
|
|
156
|
+
type TracerInitOpts = {
|
|
157
|
+
instrument?: boolean;
|
|
158
|
+
include?: RegExp[];
|
|
159
|
+
exclude?: RegExp[];
|
|
160
|
+
mode?: string;
|
|
161
|
+
samplingMs?: number;
|
|
162
|
+
};
|
|
163
|
+
export type ReproTracingInitOptions = TracerInitOpts & {
|
|
164
|
+
/**
|
|
165
|
+
* Optional list of rules or predicates that suppress unwanted function
|
|
166
|
+
* trace events. When omitted, every instrumented function will be
|
|
167
|
+
* recorded. Provide an empty array to reset filters after a previous call.
|
|
168
|
+
*/
|
|
169
|
+
disableFunctionTraces?: DisableFunctionTraceConfig[] | null;
|
|
170
|
+
/**
|
|
171
|
+
* Convenience filter that disables every trace event emitted for the
|
|
172
|
+
* provided function types (e.g. `"constructor"`). Accepts a string,
|
|
173
|
+
* regular expression, or array matching the rule syntax above.
|
|
174
|
+
*/
|
|
175
|
+
disableFunctionTypes?: TraceRulePattern | null;
|
|
176
|
+
/**
|
|
177
|
+
* Prevents traces emitted from specific files. Accepts glob-like substrings
|
|
178
|
+
* or regular expressions, or the {@link DisableTraceByFilename} helper.
|
|
179
|
+
*/
|
|
180
|
+
disableTraceFiles?: DisableTraceFileConfig | DisableTraceFileConfig[] | null;
|
|
181
|
+
/**
|
|
182
|
+
* When `false` (default) Nest interceptors are stripped from traces.
|
|
183
|
+
* Set to `true` to include them if you need to debug interceptor logic.
|
|
184
|
+
*/
|
|
185
|
+
traceInterceptors?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Enables or silences console logs emitted by the tracer when functions
|
|
188
|
+
* are entered/exited. Equivalent to calling `setReproTraceLogsEnabled`.
|
|
189
|
+
*/
|
|
190
|
+
logFunctionCalls?: boolean;
|
|
191
|
+
};
|
|
192
|
+
/** Call this from the client app to enable tracing. Safe to call multiple times. */
|
|
193
|
+
export declare function initReproTracing(opts?: ReproTracingInitOptions): TracerApi | null;
|
|
194
|
+
/** Optional helper if users want to check it. */
|
|
195
|
+
export declare function isReproTracingEnabled(): boolean;
|
|
196
|
+
export type ReproMiddlewareConfig = {
|
|
197
|
+
appId: string;
|
|
198
|
+
appSecret: string;
|
|
199
|
+
appName?: string;
|
|
200
|
+
/** Configure header capture/masking. Defaults to capturing with sensitive headers masked. */
|
|
201
|
+
captureHeaders?: boolean | HeaderCaptureOptions;
|
|
202
|
+
/** Optional masking rules for request/response payloads and function traces. */
|
|
203
|
+
masking?: ReproMaskingConfig;
|
|
204
|
+
};
|
|
205
|
+
export declare function reproMiddleware(cfg: ReproMiddlewareConfig): (req: Request, res: Response, next: NextFunction) => void;
|
|
206
|
+
export declare function reproMongoosePlugin(cfg: {
|
|
207
|
+
appId: string;
|
|
208
|
+
appSecret: string;
|
|
209
|
+
appName?: string;
|
|
210
|
+
}): (schema: Schema) => void;
|
|
211
|
+
export type SendgridPatchConfig = {
|
|
212
|
+
appId: string;
|
|
213
|
+
appSecret: string;
|
|
214
|
+
appName?: string;
|
|
215
|
+
resolveContext?: () => {
|
|
216
|
+
sid?: string;
|
|
217
|
+
aid?: string;
|
|
218
|
+
} | undefined;
|
|
219
|
+
};
|
|
220
|
+
export declare function patchSendgridMail(cfg: SendgridPatchConfig): void;
|
|
221
|
+
export {};
|