@queno/agent-node 0.1.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.
Files changed (154) hide show
  1. package/README.md +421 -0
  2. package/dist/agent.d.ts +222 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +591 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/api-discovery/discovery-buffer.d.ts +27 -0
  7. package/dist/api-discovery/discovery-buffer.d.ts.map +1 -0
  8. package/dist/api-discovery/discovery-buffer.js +50 -0
  9. package/dist/api-discovery/discovery-buffer.js.map +1 -0
  10. package/dist/api-discovery/endpoint-observer.d.ts +25 -0
  11. package/dist/api-discovery/endpoint-observer.d.ts.map +1 -0
  12. package/dist/api-discovery/endpoint-observer.js +127 -0
  13. package/dist/api-discovery/endpoint-observer.js.map +1 -0
  14. package/dist/api-discovery/route-normalizer.d.ts +15 -0
  15. package/dist/api-discovery/route-normalizer.d.ts.map +1 -0
  16. package/dist/api-discovery/route-normalizer.js +34 -0
  17. package/dist/api-discovery/route-normalizer.js.map +1 -0
  18. package/dist/config.d.ts +100 -0
  19. package/dist/config.d.ts.map +1 -0
  20. package/dist/config.js +101 -0
  21. package/dist/config.js.map +1 -0
  22. package/dist/db-hooks/correlate.d.ts +19 -0
  23. package/dist/db-hooks/correlate.d.ts.map +1 -0
  24. package/dist/db-hooks/correlate.js +45 -0
  25. package/dist/db-hooks/correlate.js.map +1 -0
  26. package/dist/db-hooks/instrument.d.ts +27 -0
  27. package/dist/db-hooks/instrument.d.ts.map +1 -0
  28. package/dist/db-hooks/instrument.js +194 -0
  29. package/dist/db-hooks/instrument.js.map +1 -0
  30. package/dist/detectors/base.d.ts +61 -0
  31. package/dist/detectors/base.d.ts.map +1 -0
  32. package/dist/detectors/base.js +57 -0
  33. package/dist/detectors/base.js.map +1 -0
  34. package/dist/detectors/bola.d.ts +60 -0
  35. package/dist/detectors/bola.d.ts.map +1 -0
  36. package/dist/detectors/bola.js +108 -0
  37. package/dist/detectors/bola.js.map +1 -0
  38. package/dist/detectors/command-injection.d.ts +22 -0
  39. package/dist/detectors/command-injection.d.ts.map +1 -0
  40. package/dist/detectors/command-injection.js +41 -0
  41. package/dist/detectors/command-injection.js.map +1 -0
  42. package/dist/detectors/custom-rule.d.ts +24 -0
  43. package/dist/detectors/custom-rule.d.ts.map +1 -0
  44. package/dist/detectors/custom-rule.js +65 -0
  45. package/dist/detectors/custom-rule.js.map +1 -0
  46. package/dist/detectors/index.d.ts +17 -0
  47. package/dist/detectors/index.d.ts.map +1 -0
  48. package/dist/detectors/index.js +31 -0
  49. package/dist/detectors/index.js.map +1 -0
  50. package/dist/detectors/nosql-injection.d.ts +23 -0
  51. package/dist/detectors/nosql-injection.d.ts.map +1 -0
  52. package/dist/detectors/nosql-injection.js +54 -0
  53. package/dist/detectors/nosql-injection.js.map +1 -0
  54. package/dist/detectors/path-traversal.d.ts +21 -0
  55. package/dist/detectors/path-traversal.d.ts.map +1 -0
  56. package/dist/detectors/path-traversal.js +54 -0
  57. package/dist/detectors/path-traversal.js.map +1 -0
  58. package/dist/detectors/prototype-pollution.d.ts +23 -0
  59. package/dist/detectors/prototype-pollution.d.ts.map +1 -0
  60. package/dist/detectors/prototype-pollution.js +50 -0
  61. package/dist/detectors/prototype-pollution.js.map +1 -0
  62. package/dist/detectors/sql-injection.d.ts +22 -0
  63. package/dist/detectors/sql-injection.d.ts.map +1 -0
  64. package/dist/detectors/sql-injection.js +42 -0
  65. package/dist/detectors/sql-injection.js.map +1 -0
  66. package/dist/detectors/ssrf.d.ts +26 -0
  67. package/dist/detectors/ssrf.d.ts.map +1 -0
  68. package/dist/detectors/ssrf.js +37 -0
  69. package/dist/detectors/ssrf.js.map +1 -0
  70. package/dist/detectors/suspicious-headers.d.ts +25 -0
  71. package/dist/detectors/suspicious-headers.d.ts.map +1 -0
  72. package/dist/detectors/suspicious-headers.js +87 -0
  73. package/dist/detectors/suspicious-headers.js.map +1 -0
  74. package/dist/detectors/template-injection.d.ts +27 -0
  75. package/dist/detectors/template-injection.d.ts.map +1 -0
  76. package/dist/detectors/template-injection.js +35 -0
  77. package/dist/detectors/template-injection.js.map +1 -0
  78. package/dist/detectors/xss.d.ts +22 -0
  79. package/dist/detectors/xss.d.ts.map +1 -0
  80. package/dist/detectors/xss.js +38 -0
  81. package/dist/detectors/xss.js.map +1 -0
  82. package/dist/index.d.ts +28 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +24 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/integrations/express.d.ts +39 -0
  87. package/dist/integrations/express.d.ts.map +1 -0
  88. package/dist/integrations/express.js +62 -0
  89. package/dist/integrations/express.js.map +1 -0
  90. package/dist/integrations/fastify.d.ts +33 -0
  91. package/dist/integrations/fastify.d.ts.map +1 -0
  92. package/dist/integrations/fastify.js +63 -0
  93. package/dist/integrations/fastify.js.map +1 -0
  94. package/dist/integrations/nestjs.d.ts +40 -0
  95. package/dist/integrations/nestjs.d.ts.map +1 -0
  96. package/dist/integrations/nestjs.js +58 -0
  97. package/dist/integrations/nestjs.js.map +1 -0
  98. package/dist/policy/canonical.d.ts +23 -0
  99. package/dist/policy/canonical.d.ts.map +1 -0
  100. package/dist/policy/canonical.js +40 -0
  101. package/dist/policy/canonical.js.map +1 -0
  102. package/dist/policy/policy-manager.d.ts +43 -0
  103. package/dist/policy/policy-manager.d.ts.map +1 -0
  104. package/dist/policy/policy-manager.js +89 -0
  105. package/dist/policy/policy-manager.js.map +1 -0
  106. package/dist/policy/types.d.ts +70 -0
  107. package/dist/policy/types.d.ts.map +1 -0
  108. package/dist/policy/types.js +2 -0
  109. package/dist/policy/types.js.map +1 -0
  110. package/dist/policy/verify.d.ts +11 -0
  111. package/dist/policy/verify.d.ts.map +1 -0
  112. package/dist/policy/verify.js +61 -0
  113. package/dist/policy/verify.js.map +1 -0
  114. package/dist/redaction/audit-log.d.ts +40 -0
  115. package/dist/redaction/audit-log.d.ts.map +1 -0
  116. package/dist/redaction/audit-log.js +110 -0
  117. package/dist/redaction/audit-log.js.map +1 -0
  118. package/dist/redaction/engine.d.ts +50 -0
  119. package/dist/redaction/engine.d.ts.map +1 -0
  120. package/dist/redaction/engine.js +143 -0
  121. package/dist/redaction/engine.js.map +1 -0
  122. package/dist/redaction/patterns.d.ts +24 -0
  123. package/dist/redaction/patterns.d.ts.map +1 -0
  124. package/dist/redaction/patterns.js +142 -0
  125. package/dist/redaction/patterns.js.map +1 -0
  126. package/dist/runtime-context.d.ts +33 -0
  127. package/dist/runtime-context.d.ts.map +1 -0
  128. package/dist/runtime-context.js +46 -0
  129. package/dist/runtime-context.js.map +1 -0
  130. package/dist/self-protect.d.ts +34 -0
  131. package/dist/self-protect.d.ts.map +1 -0
  132. package/dist/self-protect.js +134 -0
  133. package/dist/self-protect.js.map +1 -0
  134. package/dist/transport/buffer.d.ts +52 -0
  135. package/dist/transport/buffer.d.ts.map +1 -0
  136. package/dist/transport/buffer.js +57 -0
  137. package/dist/transport/buffer.js.map +1 -0
  138. package/dist/transport/client.d.ts +77 -0
  139. package/dist/transport/client.d.ts.map +1 -0
  140. package/dist/transport/client.js +178 -0
  141. package/dist/transport/client.js.map +1 -0
  142. package/dist/transport/heartbeat.d.ts +86 -0
  143. package/dist/transport/heartbeat.d.ts.map +1 -0
  144. package/dist/transport/heartbeat.js +110 -0
  145. package/dist/transport/heartbeat.js.map +1 -0
  146. package/dist/transport/secure-request.d.ts +30 -0
  147. package/dist/transport/secure-request.d.ts.map +1 -0
  148. package/dist/transport/secure-request.js +95 -0
  149. package/dist/transport/secure-request.js.map +1 -0
  150. package/dist/types.d.ts +311 -0
  151. package/dist/types.d.ts.map +1 -0
  152. package/dist/types.js +12 -0
  153. package/dist/types.js.map +1 -0
  154. package/package.json +60 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-request.js","sourceRoot":"","sources":["../../src/transport/secure-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAA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AAI,EAAE,CAAC,CAAC,CAAC;oBAC9E,OAAO;gBACT,CAAC;gBACD,IAAI,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACxC,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,GAAY,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CAAC,CAAC;QAC5F,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxB,sEAAsE;QACtE,GAAG,CAAC,EAAE,CAAC,eAAwB,EAAE,GAAG,EAAE;YACpC,MAAM,MAAM,GAAG,GAAG,CAAC,MAA+B,CAAC;YACnD,IAAI,MAAM,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;gBAChF,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,wCAAwC,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC;YAC9F,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI;YAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Public type definitions for `@queno/agent-node`.
3
+ *
4
+ * These types form the contract between:
5
+ * - the customer application (RaspConfig, NormalizedRequest),
6
+ * - the framework integrations (Express/Fastify/NestJS adapters),
7
+ * - the bundled detectors (DetectionResult),
8
+ * - the collector backend (EventPayload, HeartbeatPayload, HeartbeatResponse),
9
+ * - the local redaction audit log (RedactionAuditEntry).
10
+ */
11
+ /** Detection severity, ordered from worst to least severe. */
12
+ export type Severity = "critical" | "high" | "medium" | "low";
13
+ /**
14
+ * Agent enforcement mode.
15
+ *
16
+ * - `monitor` (default): detections are recorded and reported but the request
17
+ * is allowed to continue.
18
+ * - `block`: detections cause the integration to respond with HTTP 403.
19
+ */
20
+ export type AgentMode = "monitor" | "block";
21
+ /**
22
+ * Self-reported agent health, sent on every heartbeat.
23
+ *
24
+ * - `healthy`: agent is operating normally.
25
+ * - `degraded`: agent is running but a non-fatal subsystem has issues.
26
+ * - `error`: agent is in a broken state but still attempting to report.
27
+ */
28
+ export type AgentStatus = "healthy" | "degraded" | "error";
29
+ /**
30
+ * Runtime configuration accepted by {@link RaspAgent}.
31
+ *
32
+ * Only `apiKey`, `projectId` and `agentId` are mandatory. All other fields
33
+ * have sensible defaults applied by the Zod schema in `config.ts`.
34
+ */
35
+ export interface RaspConfig {
36
+ /** Bearer API key issued by the RASP dashboard. Sent as `Authorization: Bearer <key>`. */
37
+ apiKey: string;
38
+ /** Project ID from the RASP dashboard. Scopes all telemetry to a tenant. */
39
+ projectId: string;
40
+ /** Stable identifier for this agent instance (e.g. hostname or pod name). */
41
+ agentId: string;
42
+ /** Free-form agent version string, echoed back in telemetry for debugging. */
43
+ agentVersion?: string;
44
+ /** Enforcement mode. Defaults to `monitor` - see {@link AgentMode}. */
45
+ mode?: AgentMode;
46
+ /** Stability channel for policy/version distribution. Default `stable`. */
47
+ channel?: "stable" | "early" | "edge";
48
+ /** Heartbeat interval in ms. Min 5_000, default 30_000. */
49
+ heartbeatIntervalMs?: number;
50
+ /** Buffer flush interval in ms. Min 1_000, default 5_000. */
51
+ flushIntervalMs?: number;
52
+ /** Max events held in the buffer before a forced flush. Min 1, default 50. */
53
+ bufferMaxSize?: number;
54
+ /** HTTP request timeout to the collector in ms. Min 500, default 5_000. */
55
+ transportTimeoutMs?: number;
56
+ /** Whether to write the local redaction audit log. Default true. */
57
+ auditLog?: boolean;
58
+ /** Filesystem path for the local audit log. Default `./rasp-audit.log`. */
59
+ auditLogPath?: string;
60
+ /** Max audit log file size in bytes before rotation. Default 10 MB. */
61
+ auditLogMaxBytes?: number;
62
+ /** Framework hint included in telemetry (e.g. `express`, `fastify`, `nestjs`). */
63
+ framework?: string;
64
+ /** Runtime hint included in telemetry. Default `node`. */
65
+ runtime?: string;
66
+ /** Discovery flush interval in ms. Min 5_000, default 60_000. */
67
+ discoveryFlushIntervalMs?: number;
68
+ /**
69
+ * Pinned Ed25519 public key (PEM, SPKI) used to verify signed policies
70
+ * distributed by the control plane. This is the trust anchor (Addendum
71
+ * E.4.1). In production it is embedded in the package by default and may be
72
+ * overridden here for sovereign/on-prem deployments. When absent, the agent
73
+ * cannot apply any policy and stays on its boot configuration (fail-safe).
74
+ */
75
+ policyPublicKey?: string;
76
+ /** Per-request HMAC secret used to sign telemetry batches (Addendum E.5). */
77
+ hmacSecret?: string;
78
+ /**
79
+ * Instrument common database drivers (pg, mysql2, mongoose, sequelize, knex)
80
+ * to enable BOLA-via-DB correlation (Addendum A.4). Off by default; enabling
81
+ * monkey-patches driver query methods at agent start.
82
+ */
83
+ instrumentDb?: boolean;
84
+ /**
85
+ * Enable runtime self-protection (Addendum E.7): periodic DB-hook integrity
86
+ * checks and basic anti-debug detection. Secrets are always held encrypted in
87
+ * memory regardless of this flag. Defaults to `false`.
88
+ */
89
+ selfProtect?: boolean;
90
+ /**
91
+ * TLS options for certificate pinning + mutual TLS to the collector
92
+ * (Addendum E.4.2). When set, the agent uses a pinned HTTPS transport.
93
+ */
94
+ tls?: {
95
+ caCert?: string;
96
+ clientCert?: string;
97
+ clientKey?: string;
98
+ collectorFingerprints?: string[];
99
+ rejectUnauthorized?: boolean;
100
+ };
101
+ }
102
+ /**
103
+ * Framework-agnostic view of an incoming HTTP request.
104
+ *
105
+ * Integrations are responsible for mapping their native request object to this
106
+ * shape before calling {@link RaspAgent.inspect}.
107
+ */
108
+ export interface NormalizedRequest {
109
+ /** HTTP verb (e.g. `GET`, `POST`). */
110
+ method: string;
111
+ /** Request path without the query string. */
112
+ path: string;
113
+ /** Parsed query parameters. */
114
+ query: Record<string, unknown>;
115
+ /** Raw HTTP headers as provided by the framework. */
116
+ headers: Record<string, string | string[] | undefined>;
117
+ /** Parsed request body, if available. May be undefined for streaming bodies. */
118
+ body: unknown;
119
+ /** Best-effort source IP, typically resolved from `X-Forwarded-For` or the socket. */
120
+ sourceIp?: string;
121
+ }
122
+ /**
123
+ * The outcome of a single detector run.
124
+ *
125
+ * Returned by {@link Detector.detect} when something suspicious is found, and
126
+ * fed into {@link RaspAgent.inspect}'s event-building pipeline.
127
+ */
128
+ export interface DetectionResult {
129
+ /** Identifier of the detector that produced this result (e.g. `sql-injection`). */
130
+ detectorName: string;
131
+ /** Stable machine-readable event type used by the collector (e.g. `sql_injection`). */
132
+ eventType: string;
133
+ /** Severity assigned by the detector. */
134
+ severity: Severity;
135
+ /** Human-readable description of what was detected. */
136
+ description: string;
137
+ /**
138
+ * The matched value or pattern. This may contain sensitive substrings - the
139
+ * redaction engine MUST be run before the event leaves the process.
140
+ */
141
+ matchedValue?: string;
142
+ /** Which field or location triggered the detection (e.g. `query/body`, `header:host`). */
143
+ location?: string;
144
+ }
145
+ /**
146
+ * Payload sent to the collector's `POST /v1/events` endpoint.
147
+ *
148
+ * Always passes through the redaction engine before being enqueued.
149
+ */
150
+ export interface EventPayload {
151
+ /** Project the event belongs to. */
152
+ projectId: string;
153
+ /** Stable identifier of the agent that produced the event. */
154
+ agentId?: string;
155
+ /** Version of the agent that produced the event. */
156
+ agentVersion?: string;
157
+ /** Runtime hint (e.g. `node`). */
158
+ runtime?: string;
159
+ /** Framework hint (e.g. `express`). */
160
+ framework?: string;
161
+ /** Stable machine-readable event type (see {@link DetectionResult.eventType}). */
162
+ eventType: string;
163
+ /** Severity of the detection. */
164
+ severity: Severity;
165
+ /** Mode in effect when the detection happened (`monitor` or `block`). */
166
+ action: AgentMode;
167
+ /** HTTP method of the originating request. */
168
+ method?: string;
169
+ /** Request path. */
170
+ path?: string;
171
+ /** Best-effort source IP. */
172
+ sourceIp?: string;
173
+ /** ISO-8601 timestamp set by the agent. */
174
+ timestamp?: string;
175
+ /**
176
+ * Detection metadata.
177
+ *
178
+ * `redacted: true` is always present and signals that the redaction engine
179
+ * has processed this payload. `auditLoggedLocally` indicates whether at
180
+ * least one field was redacted (and therefore an audit log line was
181
+ * written). Extra keys are detector-specific.
182
+ */
183
+ metadata: {
184
+ redacted: true;
185
+ matchedRule?: string;
186
+ auditLoggedLocally?: boolean;
187
+ [key: string]: unknown;
188
+ };
189
+ }
190
+ /**
191
+ * Payload sent to the collector's `POST /v1/heartbeat` endpoint.
192
+ *
193
+ * The heartbeat is the agent's liveness signal and the channel through which
194
+ * the backend delivers the kill switch and policy version.
195
+ */
196
+ export interface HeartbeatPayload {
197
+ projectId: string;
198
+ agentId: string;
199
+ agentVersion?: string;
200
+ runtime?: string;
201
+ framework?: string;
202
+ /** Self-reported health. */
203
+ status: AgentStatus;
204
+ /** Mode currently enforced by the agent. */
205
+ mode: AgentMode;
206
+ /** ISO-8601 timestamp set by the agent. */
207
+ timestamp?: string;
208
+ }
209
+ /**
210
+ * Response returned by the collector for `POST /v1/heartbeat`.
211
+ *
212
+ * The agent reacts to three fields:
213
+ * - `killSwitch: true` → the agent stops inspecting and shuts down its buffer.
214
+ * - `policyVersion` change → triggers `onPolicyChange` (reserved for future rule refresh).
215
+ * - `mode` → the enforcement mode stored on the server; the agent applies it immediately.
216
+ */
217
+ export interface HeartbeatResponse {
218
+ ok: boolean;
219
+ killSwitch: boolean;
220
+ policyVersion: string;
221
+ mode?: AgentMode;
222
+ /** Version this agent should be running (canary cohort / pin). */
223
+ targetVersion?: string | null;
224
+ /** True when `targetVersion` differs from the running version. */
225
+ upgradeAvailable?: boolean;
226
+ /** Changelog for the target version (shown in logs). */
227
+ changelog?: string | null;
228
+ /** Expected impact/risk notes for the target version. */
229
+ impact?: string | null;
230
+ }
231
+ /**
232
+ * Auth status heuristic inferred from the presence/absence of an
233
+ * `Authorization` header on the observed request.
234
+ */
235
+ export type AuthStatus = "authenticated" | "unauthenticated" | "unknown";
236
+ /**
237
+ * A single discovered endpoint entry, aggregated by {@link EndpointObserver}
238
+ * and flushed by {@link DiscoveryBuffer}.
239
+ */
240
+ export interface DiscoveryEntry {
241
+ /** HTTP verb (upper-cased). */
242
+ method: string;
243
+ /** Normalised path pattern (e.g. `/api/users/:id`). */
244
+ pathPattern: string;
245
+ /** Auth heuristic for this endpoint. */
246
+ authStatus: AuthStatus;
247
+ /** True when request body/query keys matched sensitive-data patterns. */
248
+ hasSensitiveData: boolean;
249
+ /** Number of observations since the last flush. */
250
+ observationCount: number;
251
+ /**
252
+ * Whether an auth middleware was observed populating the request
253
+ * (e.g. `req.user`/`req.auth`). More reliable than the header heuristic.
254
+ */
255
+ authObserved?: boolean;
256
+ /** Count of responses with status >= 400 since the last flush. */
257
+ errorCount?: number;
258
+ /** Sum of observed response durations (ms); used to derive an average. */
259
+ sumDurationMs?: number;
260
+ /** Number of responses timed (denominator for the average). */
261
+ timedCount?: number;
262
+ /** Inferred parameter schema: field name -> JSON type. */
263
+ schemaFields?: Record<string, string>;
264
+ }
265
+ /**
266
+ * Response-phase outcome fed back to the {@link EndpointObserver} so it can
267
+ * build a traffic profile (error rate, latency) and confirm auth middleware
268
+ * execution.
269
+ */
270
+ export interface RequestOutcome {
271
+ statusCode?: number;
272
+ durationMs?: number;
273
+ /** True if an auth middleware populated the request (req.user / req.auth). */
274
+ authenticated?: boolean;
275
+ }
276
+ /**
277
+ * Payload sent to the collector's `POST /v1/discovery` endpoint.
278
+ */
279
+ export interface DiscoveryPayload {
280
+ projectId: string;
281
+ agentId: string;
282
+ /** ISO-8601 timestamp set by the agent at flush time. */
283
+ timestamp?: string;
284
+ /** Up to 500 entries per batch. */
285
+ endpoints: DiscoveryEntry[];
286
+ }
287
+ /**
288
+ * A single line written to the local redaction audit log.
289
+ *
290
+ * Serialised as one JSON object per line (JSONL). Contains only metadata -
291
+ * never the raw redacted values.
292
+ */
293
+ export interface RedactionAuditEntry {
294
+ /** ISO-8601 timestamp. */
295
+ ts: string;
296
+ agentId: string;
297
+ projectId: string;
298
+ /** Event type that triggered the detection. */
299
+ eventType: string;
300
+ /** Severity of the detection. */
301
+ severity?: string;
302
+ /** Name of the detector that fired. */
303
+ detectorName?: string;
304
+ /** Dotted field paths that were replaced by `[REDACTED]`. */
305
+ redactedFields: string[];
306
+ /** True when the event was dropped (e.g. because redaction failed). */
307
+ dropped: boolean;
308
+ /** Free-form reason set when `dropped` is true. */
309
+ dropReason?: string;
310
+ }
311
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IACtC,2DAA2D;IAC3D,mBAAmB,CAAC,EAA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B,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Public type definitions for `@queno/agent-node`.
3
+ *
4
+ * These types form the contract between:
5
+ * - the customer application (RaspConfig, NormalizedRequest),
6
+ * - the framework integrations (Express/Fastify/NestJS adapters),
7
+ * - the bundled detectors (DetectionResult),
8
+ * - the collector backend (EventPayload, HeartbeatPayload, HeartbeatResponse),
9
+ * - the local redaction audit log (RedactionAuditEntry).
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@queno/agent-node",
3
+ "version": "0.1.2",
4
+ "description": "RASP agent for Node.js - Express, Fastify, NestJS",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc --project tsconfig.build.json",
19
+ "dev": "tsx watch src/index.ts",
20
+ "typecheck": "tsc --noEmit",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest"
23
+ },
24
+ "dependencies": {
25
+ "zod": "^4.4.3"
26
+ },
27
+ "peerDependencies": {
28
+ "@nestjs/common": ">=10",
29
+ "express": ">=4",
30
+ "fastify": ">=4"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "express": {
34
+ "optional": true
35
+ },
36
+ "fastify": {
37
+ "optional": true
38
+ },
39
+ "@nestjs/common": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "@nestjs/common": "^11.1.24",
45
+ "@nestjs/core": "^11.1.24",
46
+ "@types/express": "^5.0.2",
47
+ "@types/node": "^20",
48
+ "fastify": "^5.8.5",
49
+ "reflect-metadata": "^0.2.2",
50
+ "tsx": "^4.22.3",
51
+ "typescript": "^5",
52
+ "vitest": "^4.1.7"
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }