@telamonjs/data 1.0.1 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 91e6434: Audit trail: `createAuditInterceptor()` and `@SkipAudit()` in `@telamonjs/data/nest` hand every successful, authenticated mutation to your `write` as an `AuditEntry` (user, impersonator, action, entity, redacted body, IP, user agent, method, path, status), without blocking the response or failing it when the write fails. The root entry gains the pure helpers `computeDiff`, `redactPayload` and `DEFAULT_REDACT_KEYS`. `rxjs` joins `@nestjs/common` as an optional peer of the `./nest` entry.
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 5fd314b: New `@telamonjs/data/nest` entry (needs `@nestjs/common` 10 or 11, an optional peer; never imports `@prisma/client`). `PrismaExceptionFilter` answers Prisma errors with HTTP statuses (P2002 → 409 with `field`, P2003 → 400, P2025 → 404, P2011/P2012/P2014 and validation errors → 400, P1000–P1003 → 503, other codes → 500 logged), matching them by shape so only Prisma errors reach it; English messages, overridable per code with `messages`. `HealthModule.forRoot({ checks, inject?, imports?, path?, decorators? })` serves `GET /health` with `{ status, timestamp, uptime, <check>: 'connected' | 'disconnected' }` and answers 503 when a check is down. The monorepo template's API now uses both instead of its own filter and health controller, and requires Node 22.12+.
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  The server half of a TelamonJS list. A `ListPage` sends page, page size, search, sort and filters.
4
4
  This package reads them on the endpoint and turns them into a query, with no dependencies and
5
- without React, Next or Prisma.
5
+ without React, Next or Prisma. A NestJS API also gets the Prisma exception filter, health
6
+ endpoint and audit interceptor every API repeats.
6
7
 
7
8
  ```bash
8
9
  pnpm add @telamonjs/data
@@ -10,8 +11,9 @@ pnpm add @telamonjs/data
10
11
 
11
12
  | Entry | What it has | Needs an ORM? |
12
13
  | --- | --- | --- |
13
- | `@telamonjs/data` | The wire contract (`PaginationParams`, `PaginatedResponse`, `SortField`, `createPaginatedResponse`), `sanitizePaginationParams`, `resolveSort`, `resolveSortPath` | No |
14
+ | `@telamonjs/data` | The wire contract (`PaginationParams`, `PaginatedResponse`, `SortField`, `createPaginatedResponse`), `sanitizePaginationParams`, `resolveSort`, `resolveSortPath`; the audit helpers `computeDiff`, `redactPayload`, `DEFAULT_REDACT_KEYS` | No |
14
15
  | `@telamonjs/data/prisma` | `buildPrismaOrderBy(Multi)`, `buildSearchConditions`, `buildFilterConditions`, `buildWhereClause`, `createPaginationContext` | Builds Prisma's object shape; never imports `@prisma/client` |
16
+ | `@telamonjs/data/nest` | `PrismaExceptionFilter`, `HealthModule`, `createAuditInterceptor`, `SkipAudit`, `isPrismaKnownRequestError`, `isPrismaValidationError` | Needs `@nestjs/common` and `rxjs` (optional peers); never imports `@prisma/client` |
15
17
 
16
18
  ## Sorting what a list sends
17
19
 
@@ -87,6 +89,165 @@ export const customers = createPaginatedService({
87
89
  `@telamonjs/ui/server` re-exports these helpers for Next.js server code. A NestJS or plain Node
88
90
  API installs only this package.
89
91
 
92
+ ## NestJS (`@telamonjs/data/nest`)
93
+
94
+ Needs `@nestjs/common` 10 or 11 and `rxjs` 7, optional peers that only this entry imports
95
+ (every Nest app already has both).
96
+
97
+ ### Prisma errors as HTTP statuses
98
+
99
+ `PrismaExceptionFilter` answers Prisma errors with a status instead of a 500. It matches
100
+ Prisma's known-request and validation errors by shape (`code` + `name`/`clientVersion`), so it
101
+ works with any `@prisma/client` copy, and it never claims other errors: your own filters and
102
+ Nest's default handling still get them.
103
+
104
+ ```ts
105
+ import { PrismaExceptionFilter } from '@telamonjs/data/nest'
106
+
107
+ app.useGlobalFilters(new PrismaExceptionFilter())
108
+ ```
109
+
110
+ | Prisma | HTTP |
111
+ | --- | --- |
112
+ | `P2002` unique | 409, `field` = first `target` field |
113
+ | `P2003` foreign key | 400, `field` = constraint |
114
+ | `P2025` not found | 404 |
115
+ | `P2011`, `P2012`, `P2014`, `PrismaClientValidationError` | 400 |
116
+ | `P1000`–`P1003` connection | 503 |
117
+ | any other code | 500, logged with Nest's `Logger` |
118
+
119
+ The body is `{ statusCode, message, error, field?, timestamp, path }`, written with Express's
120
+ `res.status().json()`. Outside HTTP (RPC, WebSocket, GraphQL) the error is rethrown. Messages are
121
+ English; replace them (in your app's language, say) per code, `validation` or `default`, with a
122
+ string or a function of the reported fields:
123
+
124
+ ```ts
125
+ new PrismaExceptionFilter({
126
+ messages: {
127
+ P2025: 'Nothing here',
128
+ P2002: (fields) => `${fields.join(', ')} is already taken`,
129
+ },
130
+ })
131
+ ```
132
+
133
+ To change one case (say, `P2003` on a `DELETE` as 409), subclass it, handle that case in `catch`
134
+ and call `super.catch(exception, host)` for the rest.
135
+
136
+ ### Health endpoint
137
+
138
+ `HealthModule.forRoot()` serves `GET /health`. It runs the checks in parallel and answers 200, or
139
+ 503 with `status: 'error'` when any check is down, so Docker and load balancers can read the
140
+ status code:
141
+
142
+ ```ts
143
+ import { Public } from '@telamonjs/auth/nest'
144
+ import { HealthModule } from '@telamonjs/data/nest'
145
+
146
+ HealthModule.forRoot({
147
+ decorators: [Public()], // class decorators for the controller
148
+ inject: [PrismaService, REDIS],
149
+ checks: (prisma: PrismaService, redis: Redis) => ({
150
+ database: () => prisma.$queryRaw`SELECT 1`,
151
+ redis: () => redis.ping(),
152
+ }),
153
+ })
154
+ // GET /health → { status: 'ok', timestamp, uptime, database: 'connected', redis: 'connected' }
155
+ ```
156
+
157
+ A check is down when it throws, rejects or resolves `false`. `path` changes the route (default
158
+ `'health'`); `imports` brings in the modules of the `inject` tokens when they are not global.
159
+
160
+ ### Audit trail
161
+
162
+ `createAuditInterceptor()` returns an interceptor class that turns every successful,
163
+ authenticated `POST`/`PUT`/`PATCH`/`DELETE` into an `AuditEntry` and hands it to your `write`.
164
+ The package owns no table: you persist the entry wherever you keep audit rows.
165
+
166
+ ```ts
167
+ import { APP_INTERCEPTOR } from '@nestjs/core'
168
+ import { createAuditInterceptor } from '@telamonjs/data/nest'
169
+
170
+ export const AuditInterceptor = createAuditInterceptor({
171
+ inject: [PrismaService],
172
+ write: (entry, _context, prisma: PrismaService) => prisma.auditLog.create({ data: entry }),
173
+ })
174
+
175
+ // app.module.ts
176
+ providers: [{ provide: APP_INTERCEPTOR, useClass: AuditInterceptor }]
177
+ ```
178
+
179
+ A Prisma model that takes the entry as it is:
180
+
181
+ ```prisma
182
+ model AuditLog {
183
+ id String @id @default(cuid())
184
+ userId String
185
+ impersonatedBy String?
186
+ action String // CREATE | UPDATE | DELETE
187
+ entityType String
188
+ entityId String?
189
+ changes Json?
190
+ ipAddress String?
191
+ userAgent String?
192
+ method String
193
+ path String
194
+ statusCode Int
195
+ createdAt DateTime @default(now())
196
+
197
+ @@index([entityType, entityId])
198
+ @@index([userId, createdAt])
199
+ }
200
+ ```
201
+
202
+ | Entry field | Comes from |
203
+ | --- | --- |
204
+ | `userId`, `impersonatedBy` | `request.user.id` and `request.user.originalUser.id`, the `@telamonjs/auth` user (`user` option to read another shape) |
205
+ | `action` | `POST` → `CREATE`, `PUT`/`PATCH` → `UPDATE`, `DELETE` → `DELETE`; any other audited method as is |
206
+ | `entityType`, `entityId` | The first path segment that is not `api` or a version (`/v1/orders/42` → `orders`), and the `:id` param or the response body's `id` (`resolveEntity` option to change both) |
207
+ | `changes` | The request body through `redactPayload`; absent when the body is empty |
208
+ | `ipAddress`, `userAgent` | `request.ip` (set Express's `trust proxy` behind a proxy) and the `User-Agent` header |
209
+ | `method`, `path`, `statusCode` | The request, without the query string, and the status Nest answered with |
210
+
211
+ Nothing is written when the handler throws, when there is no user (logins, public sign-ups) or
212
+ outside HTTP. The response does not wait for `write` (`await: true` makes it wait), and a
213
+ `write` that throws or rejects goes to `onError` (default: Nest's `Logger`) and never fails the
214
+ request.
215
+
216
+ ```ts
217
+ createAuditInterceptor({
218
+ write,
219
+ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], // the default
220
+ ignore: (ctx) => ctx.switchToHttp().getRequest().path.startsWith('/v1/webhooks'),
221
+ redact: ['ssn'], // added to DEFAULT_REDACT_KEYS
222
+ resolveEntity: (ctx, body) => ({ type: ctx.getClass().name, id: (body as { id?: string })?.id }),
223
+ onError: (error, entry) => logger.warn({ error, entry }, 'audit write failed'),
224
+ })
225
+ ```
226
+
227
+ `@SkipAudit()` on a handler or a controller skips it, the same as `ignore`.
228
+
229
+ ### Audit helpers (`@telamonjs/data`)
230
+
231
+ The root entry has the two pure helpers the interceptor and hand-written audit calls share.
232
+ `redactPayload(value, keys = DEFAULT_REDACT_KEYS)` returns a deep copy with the value of every
233
+ secret key replaced by `'[REDACTED]'`. A key is secret when, lowercased and without `-`/`_`, it
234
+ contains one of `keys`: `password` catches `newPassword`, `senha` catches `novaSenha`, `token` catches
235
+ `REFRESH_TOKEN`, `apikey` catches `api-key`. Spread `DEFAULT_REDACT_KEYS` to add your own.
236
+
237
+ `computeDiff(before, after)` returns the fields of `after` that changed, as `{ key: { old, new } }`.
238
+ It reads only the keys of `after`, so a partial DTO works; `null` equals `undefined`, dates compare
239
+ by instant, a Decimal or numeric string compares as a number, and nested objects and arrays compare
240
+ as JSON. `createdAt` and `updatedAt` are skipped (`{ ignore }` replaces that list). Use it where you
241
+ already load the record, for an `UPDATE` row with before and after:
242
+
243
+ ```ts
244
+ import { computeDiff } from '@telamonjs/data'
245
+
246
+ const before = await prisma.order.findUniqueOrThrow({ where: { id } })
247
+ await prisma.order.update({ where: { id }, data: dto })
248
+ const changes = computeDiff(before, dto) // { status: { old: 'OPEN', new: 'PAID' } }; {} when nothing changed
249
+ ```
250
+
90
251
  ## License
91
252
 
92
253
  MIT
@@ -0,0 +1,38 @@
1
+ /** One changed field: the value before and the value sent. */
2
+ export interface FieldChange {
3
+ old: unknown;
4
+ new: unknown;
5
+ }
6
+ export interface ComputeDiffOptions {
7
+ /** Keys never reported. Replaces the default `['createdAt', 'updatedAt']`. */
8
+ ignore?: string[];
9
+ }
10
+ /**
11
+ * The fields of `after` whose value differs from `before`, as `{ key: { old, new } }`
12
+ * (`{}` when nothing changed). Reads only the keys of `after`, so a partial DTO
13
+ * works, and skips its `undefined` values. Shallow: a nested object or array is
14
+ * one value, compared as JSON. `null` equals `undefined`; dates compare by
15
+ * instant (Date or ISO string); a Decimal-like (`toNumber()`) or numeric string
16
+ * compares as a number.
17
+ *
18
+ * ```ts
19
+ * const before = await prisma.order.findUniqueOrThrow({ where: { id } })
20
+ * const diff = computeDiff(before, dto) // { status: { old: 'OPEN', new: 'PAID' } }
21
+ * ```
22
+ */
23
+ export declare function computeDiff(before: object, after: object, options?: ComputeDiffOptions): Record<string, FieldChange>;
24
+ /**
25
+ * Key fragments `redactPayload` masks by default. Spread it to add your own:
26
+ * `redactPayload(body, [...DEFAULT_REDACT_KEYS, 'ssn'])`.
27
+ */
28
+ export declare const DEFAULT_REDACT_KEYS: readonly string[];
29
+ /**
30
+ * A copy of `value` with the value of every secret key replaced by
31
+ * `'[REDACTED]'`, through nested objects and arrays. A key is secret when,
32
+ * lowercased and without `-`/`_`, it contains one of `keys` (so `password`
33
+ * catches `newPassword`, `token` catches `REFRESH_TOKEN`, `apikey` catches
34
+ * `api-key`). `keys` replaces the default list. Dates and class instances
35
+ * (Decimal, Buffer) are returned as they are; the input is never mutated.
36
+ */
37
+ export declare function redactPayload(value: unknown, keys?: readonly string[]): unknown;
38
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,OAAO,CAAA;IACZ,GAAG,EAAE,OAAO,CAAA;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAoBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CASxH;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAahD,CAAA;AAWD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,SAAS,MAAM,EAAwB,GAAG,OAAO,CAapG"}
package/dist/audit.js ADDED
@@ -0,0 +1,92 @@
1
+ const DIFF_IGNORE = ['createdAt', 'updatedAt'];
2
+ const isDecimal = (value) => typeof value === 'object' && value !== null && typeof value.toNumber === 'function';
3
+ function changed(before, after) {
4
+ if (before == null || after == null)
5
+ return (before == null) !== (after == null);
6
+ if (before instanceof Date || after instanceof Date) {
7
+ return new Date(before).getTime() !== new Date(after).getTime();
8
+ }
9
+ const a = isDecimal(before) ? before.toNumber() : before;
10
+ const b = isDecimal(after) ? after.toNumber() : after;
11
+ if (typeof a === 'number' || typeof b === 'number')
12
+ return Number(a) !== Number(b);
13
+ if (typeof a === 'bigint' || typeof b === 'bigint')
14
+ return String(a) !== String(b);
15
+ if (typeof a === 'object' || typeof b === 'object')
16
+ return JSON.stringify(a) !== JSON.stringify(b);
17
+ return a !== b;
18
+ }
19
+ /**
20
+ * The fields of `after` whose value differs from `before`, as `{ key: { old, new } }`
21
+ * (`{}` when nothing changed). Reads only the keys of `after`, so a partial DTO
22
+ * works, and skips its `undefined` values. Shallow: a nested object or array is
23
+ * one value, compared as JSON. `null` equals `undefined`; dates compare by
24
+ * instant (Date or ISO string); a Decimal-like (`toNumber()`) or numeric string
25
+ * compares as a number.
26
+ *
27
+ * ```ts
28
+ * const before = await prisma.order.findUniqueOrThrow({ where: { id } })
29
+ * const diff = computeDiff(before, dto) // { status: { old: 'OPEN', new: 'PAID' } }
30
+ * ```
31
+ */
32
+ export function computeDiff(before, after, options = {}) {
33
+ const ignore = options.ignore ?? DIFF_IGNORE;
34
+ const old = before;
35
+ const diff = {};
36
+ for (const [key, value] of Object.entries(after)) {
37
+ if (value === undefined || ignore.includes(key))
38
+ continue;
39
+ if (changed(old[key], value))
40
+ diff[key] = { old: old[key] ?? null, new: value };
41
+ }
42
+ return diff;
43
+ }
44
+ /**
45
+ * Key fragments `redactPayload` masks by default. Spread it to add your own:
46
+ * `redactPayload(body, [...DEFAULT_REDACT_KEYS, 'ssn'])`.
47
+ */
48
+ export const DEFAULT_REDACT_KEYS = [
49
+ 'password',
50
+ 'passwd',
51
+ // pt-BR schemas name it `senha`; same list as ui's AuditChangesViewer
52
+ 'senha',
53
+ 'secret',
54
+ 'token',
55
+ 'authorization',
56
+ 'cookie',
57
+ 'apikey',
58
+ 'accesskey',
59
+ 'privatekey',
60
+ 'credential',
61
+ ];
62
+ const REDACTED = '[REDACTED]';
63
+ const normalize = (key) => key.toLowerCase().replace(/[-_]/g, '');
64
+ const isPlainObject = (value) => {
65
+ if (typeof value !== 'object' || value === null)
66
+ return false;
67
+ const proto = Object.getPrototypeOf(value);
68
+ return proto === Object.prototype || proto === null;
69
+ };
70
+ /**
71
+ * A copy of `value` with the value of every secret key replaced by
72
+ * `'[REDACTED]'`, through nested objects and arrays. A key is secret when,
73
+ * lowercased and without `-`/`_`, it contains one of `keys` (so `password`
74
+ * catches `newPassword`, `token` catches `REFRESH_TOKEN`, `apikey` catches
75
+ * `api-key`). `keys` replaces the default list. Dates and class instances
76
+ * (Decimal, Buffer) are returned as they are; the input is never mutated.
77
+ */
78
+ export function redactPayload(value, keys = DEFAULT_REDACT_KEYS) {
79
+ const fragments = keys.map(normalize);
80
+ const walk = (node) => {
81
+ if (Array.isArray(node))
82
+ return node.map(walk);
83
+ if (!isPlainObject(node))
84
+ return node;
85
+ return Object.fromEntries(Object.entries(node).map(([key, child]) => {
86
+ const name = normalize(key);
87
+ return [key, fragments.some((fragment) => name.includes(fragment)) ? REDACTED : walk(child)];
88
+ }));
89
+ };
90
+ return walk(value);
91
+ }
92
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;AAE9C,MAAM,SAAS,GAAG,CAAC,KAAc,EAAmC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAQ,KAAgC,CAAC,QAAQ,KAAK,UAAU,CAAA;AAEjH,SAAS,OAAO,CAAC,MAAe,EAAE,KAAc;IAC9C,IAAI,MAAM,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,CAAA;IAChF,IAAI,MAAM,YAAY,IAAI,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACpD,OAAO,IAAI,IAAI,CAAC,MAAuB,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC,KAAsB,CAAC,CAAC,OAAO,EAAE,CAAA;IACnG,CAAC;IACD,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;IACxD,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;IACrD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAA;IAClF,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OA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index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * `@telamonjs/data` — the server half of a TelamonJS list, ORM-agnostic:
3
3
  * the wire contract a `ListPage` sends and expects, and the sort/paging
4
- * sanitizers an endpoint runs on it. ORM adapters live in subpaths
5
- * (`@telamonjs/data/prisma`).
4
+ * sanitizers an endpoint runs on it, plus the audit helpers (`computeDiff`,
5
+ * `redactPayload`). ORM adapters live in subpaths (`@telamonjs/data/prisma`).
6
6
  *
7
7
  * @module data
8
8
  */
9
9
  export type { SortField, PaginationParams, PaginatedResponse } from './contract.js';
10
10
  export { createPaginatedResponse, sanitizePaginationParams } from './contract.js';
11
11
  export { resolveSort, resolveSortPath } from './sort.js';
12
+ export type { FieldChange, ComputeDiffOptions } from './audit.js';
13
+ export { computeDiff, redactPayload, DEFAULT_REDACT_KEYS } from './audit.js';
12
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AACxD,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * `@telamonjs/data` — the server half of a TelamonJS list, ORM-agnostic:
3
3
  * the wire contract a `ListPage` sends and expects, and the sort/paging
4
- * sanitizers an endpoint runs on it. ORM adapters live in subpaths
5
- * (`@telamonjs/data/prisma`).
4
+ * sanitizers an endpoint runs on it, plus the audit helpers (`computeDiff`,
5
+ * `redactPayload`). ORM adapters live in subpaths (`@telamonjs/data/prisma`).
6
6
  *
7
7
  * @module data
8
8
  */
9
9
  export { createPaginatedResponse, sanitizePaginationParams } from './contract.js';
10
10
  export { resolveSort, resolveSortPath } from './sort.js';
11
+ export { computeDiff, redactPayload, DEFAULT_REDACT_KEYS } from './audit.js';
11
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAExD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { type CustomDecorator, type ExecutionContext, type InjectionToken, type NestInterceptor, type Type } from '@nestjs/common';
2
+ /** One audit row, ready for the app to persist. */
3
+ export interface AuditEntry {
4
+ userId: string;
5
+ /** `request.user.originalUser.id` while impersonating. */
6
+ impersonatedBy?: string;
7
+ /** `CREATE` (POST), `UPDATE` (PUT, PATCH), `DELETE`, or the HTTP method for anything else. */
8
+ action: 'CREATE' | 'UPDATE' | 'DELETE' | (string & {});
9
+ entityType: string;
10
+ entityId?: string;
11
+ /** The request body, redacted; absent when the body is empty. */
12
+ changes?: unknown;
13
+ /** `request.ip`: set Express's `trust proxy` so it reads `X-Forwarded-For`. */
14
+ ipAddress?: string;
15
+ userAgent?: string;
16
+ method: string;
17
+ /** Request path without the query string. */
18
+ path: string;
19
+ statusCode: number;
20
+ }
21
+ export interface AuditInterceptorOptions {
22
+ /**
23
+ * Persists one entry. The `inject` tokens follow `context`, in order:
24
+ *
25
+ * ```ts
26
+ * inject: [PrismaService],
27
+ * write: (entry, _context, prisma: PrismaService) => prisma.auditLog.create({ data: entry }),
28
+ * ```
29
+ */
30
+ write: (entry: AuditEntry, context: ExecutionContext, ...deps: never[]) => unknown;
31
+ /** Tokens passed to `write`. */
32
+ inject?: InjectionToken[];
33
+ /** Audited HTTP methods. Default `['POST', 'PUT', 'PATCH', 'DELETE']`. */
34
+ methods?: string[];
35
+ /**
36
+ * Entity of a request; `null` skips it. Default: `type` is the first path
37
+ * segment that is not `api` or a version (`/api/v1/orders/42` → `orders`),
38
+ * `id` the `:id` param or the response body's `id`.
39
+ */
40
+ resolveEntity?: (context: ExecutionContext, responseBody: unknown) => {
41
+ type: string;
42
+ id?: string;
43
+ } | null;
44
+ /** `true` skips the request. `@SkipAudit()` does the same per handler or controller. */
45
+ ignore?: (context: ExecutionContext) => boolean;
46
+ /** Key fragments masked in `changes`, on top of `DEFAULT_REDACT_KEYS`. */
47
+ redact?: string[];
48
+ /**
49
+ * Who acts; no `id` skips the request (anonymous writes are not audited).
50
+ * Default: `request.user.id` and `request.user.originalUser.id`, the
51
+ * `@telamonjs/auth` user.
52
+ */
53
+ user?: (request: unknown) => {
54
+ id?: string;
55
+ impersonatedBy?: string;
56
+ } | null | undefined;
57
+ /** Wait for `write` before answering. Default `false`: the response never waits on the audit. */
58
+ await?: boolean;
59
+ /** A `write` that throws or rejects. Default: logged with Nest's `Logger`. The request never fails. */
60
+ onError?: (error: unknown, entry: AuditEntry) => void;
61
+ }
62
+ /** Skips the audit for one handler, or every handler of a controller. */
63
+ export declare const SkipAudit: () => CustomDecorator<string>;
64
+ /**
65
+ * An interceptor class that hands every successful, authenticated mutation to
66
+ * `write` as an `AuditEntry`. Nothing is written when the handler throws or the
67
+ * request is anonymous; a failing `write` is reported to `onError` and never
68
+ * fails the request. Register it globally or per controller:
69
+ *
70
+ * ```ts
71
+ * const AuditInterceptor = createAuditInterceptor({
72
+ * inject: [PrismaService],
73
+ * write: (entry, _context, prisma: PrismaService) => prisma.auditLog.create({ data: entry }),
74
+ * })
75
+ * // providers: [{ provide: APP_INTERCEPTOR, useClass: AuditInterceptor }]
76
+ * ```
77
+ *
78
+ * Outside HTTP (RPC, WebSocket) requests pass through untouched.
79
+ */
80
+ export declare function createAuditInterceptor(options: AuditInterceptorOptions): Type<NestInterceptor>;
81
+ //# sourceMappingURL=audit.interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.interceptor.d.ts","sourceRoot":"","sources":["../../src/nest/audit.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,IAAI,EACV,MAAM,gBAAgB,CAAA;AAIvB,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,8FAA8F;IAC9F,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IACtD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iEAAiE;IACjE,OAAO,CAA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kC,CAAA;AAmBrF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAC,eAAe,CAAC,CAoE9F"}
@@ -0,0 +1,112 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Inject, Injectable, Logger, SetMetadata, } from '@nestjs/common';
8
+ import { concatMap, tap } from 'rxjs';
9
+ import { DEFAULT_REDACT_KEYS, redactPayload } from '../audit.js';
10
+ const SKIP_AUDIT = 'telamonjs:skip-audit';
11
+ const ACTIONS = { POST: 'CREATE', PUT: 'UPDATE', PATCH: 'UPDATE', DELETE: 'DELETE' };
12
+ // ponytail: leading `api`/`vN` segments are taken as the global prefix; another prefix needs resolveEntity.
13
+ const PREFIX = /^(api|v\d+)$/i;
14
+ /** Skips the audit for one handler, or every handler of a controller. */
15
+ export const SkipAudit = () => SetMetadata(SKIP_AUDIT, true);
16
+ const idOf = (value) => typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
17
+ function defaultEntity(req, path, body) {
18
+ const type = path.split('/').find((segment) => segment && !PREFIX.test(segment));
19
+ if (!type)
20
+ return null;
21
+ return { type, id: idOf(req.params?.id) ?? idOf(body?.id) };
22
+ }
23
+ function defaultUser(req) {
24
+ const user = req.user;
25
+ return { id: idOf(user?.id), impersonatedBy: idOf(user?.originalUser?.id) };
26
+ }
27
+ const isEmpty = (body) => body == null || (typeof body === 'object' && Object.keys(body).length === 0);
28
+ /**
29
+ * An interceptor class that hands every successful, authenticated mutation to
30
+ * `write` as an `AuditEntry`. Nothing is written when the handler throws or the
31
+ * request is anonymous; a failing `write` is reported to `onError` and never
32
+ * fails the request. Register it globally or per controller:
33
+ *
34
+ * ```ts
35
+ * const AuditInterceptor = createAuditInterceptor({
36
+ * inject: [PrismaService],
37
+ * write: (entry, _context, prisma: PrismaService) => prisma.auditLog.create({ data: entry }),
38
+ * })
39
+ * // providers: [{ provide: APP_INTERCEPTOR, useClass: AuditInterceptor }]
40
+ * ```
41
+ *
42
+ * Outside HTTP (RPC, WebSocket) requests pass through untouched.
43
+ */
44
+ export function createAuditInterceptor(options) {
45
+ const methods = options.methods ?? ['POST', 'PUT', 'PATCH', 'DELETE'];
46
+ const keys = [...DEFAULT_REDACT_KEYS, ...(options.redact ?? [])];
47
+ const resolveUser = options.user ?? defaultUser;
48
+ let AuditInterceptor = class AuditInterceptor {
49
+ logger = new Logger('AuditInterceptor');
50
+ deps;
51
+ constructor(...deps) {
52
+ this.deps = deps;
53
+ }
54
+ intercept(context, next) {
55
+ if (context.getType() !== 'http')
56
+ return next.handle();
57
+ const req = context.switchToHttp().getRequest();
58
+ const method = String(req.method).toUpperCase();
59
+ if (!methods.includes(method) ||
60
+ Reflect.getMetadata(SKIP_AUDIT, context.getHandler()) ||
61
+ Reflect.getMetadata(SKIP_AUDIT, context.getClass()) ||
62
+ options.ignore?.(context)) {
63
+ return next.handle();
64
+ }
65
+ const user = resolveUser(req);
66
+ if (!user?.id)
67
+ return next.handle();
68
+ const { id: userId, impersonatedBy } = user;
69
+ const record = async (body) => {
70
+ const path = String(req.originalUrl ?? req.url ?? '').split('?')[0];
71
+ const entity = options.resolveEntity ? options.resolveEntity(context, body) : defaultEntity(req, path, body);
72
+ if (!entity)
73
+ return;
74
+ const userAgent = req.headers['user-agent'];
75
+ const entry = {
76
+ userId,
77
+ ...(impersonatedBy && { impersonatedBy }),
78
+ action: ACTIONS[method] ?? method,
79
+ entityType: entity.type,
80
+ ...(entity.id !== undefined && { entityId: entity.id }),
81
+ ...(!isEmpty(req.body) && { changes: redactPayload(req.body, keys) }),
82
+ ...(req.ip && { ipAddress: req.ip }),
83
+ ...(typeof userAgent === 'string' && { userAgent }),
84
+ method,
85
+ path,
86
+ statusCode: context.switchToHttp().getResponse().statusCode,
87
+ };
88
+ try {
89
+ await options.write(entry, context, ...this.deps);
90
+ }
91
+ catch (error) {
92
+ if (options.onError)
93
+ options.onError(error, entry);
94
+ else
95
+ this.logger.error(`Audit write failed for ${method} ${path}`, error?.stack);
96
+ }
97
+ };
98
+ // A throwing resolveEntity or onError must not become an unhandled rejection either.
99
+ const safeRecord = (body) => record(body).catch((error) => this.logger.error('Audit failed', error?.stack));
100
+ return options.await
101
+ ? next.handle().pipe(concatMap(async (body) => (await safeRecord(body), body)))
102
+ : next.handle().pipe(tap((body) => void safeRecord(body)));
103
+ }
104
+ };
105
+ AuditInterceptor = __decorate([
106
+ Injectable()
107
+ ], AuditInterceptor);
108
+ ;
109
+ (options.inject ?? []).forEach((token, index) => Inject(token)(AuditInterceptor, undefined, index));
110
+ return AuditInterceptor;
111
+ }
112
+ //# sourceMappingURL=audit.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.interceptor.js","sourceRoot":"","sources":["../../src/nest/audit.interceptor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,MAAM,EACN,UAAU,EACV,MAAM,EACN,WAAW,GAOZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,GAAG,EAAmB,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAqEhE,MAAM,UAAU,GAAG,sBAAsB,CAAA;AACzC,MAAM,OAAO,GAA2B,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC5G,4GAA4G;AAC5G,MAAM,MAA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MAAM,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;IACpG,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { type DynamicModule, type InjectionToken, type ModuleMetadata, type OptionalFactoryDependency } from '@nestjs/common';
2
+ /** One probe: resolving `false`, rejecting or throwing means down; anything else means up. */
3
+ export type HealthCheck = () => unknown;
4
+ /** Probes by name; each name becomes a key of the response (`database`, `redis`, …). */
5
+ export type HealthChecks = Record<string, HealthCheck>;
6
+ /** `GET /health` body: `status`, `timestamp`, `uptime`, then each check as `connected` | `disconnected`. */
7
+ export interface HealthResponse {
8
+ status: 'ok' | 'error';
9
+ timestamp: string;
10
+ /** `process.uptime()`, in seconds. */
11
+ uptime: number;
12
+ [check: string]: string | number;
13
+ }
14
+ export interface HealthModuleOptions {
15
+ /**
16
+ * Builds the probes from the injected `inject` tokens, in order (the same
17
+ * convention as a Nest `useFactory`):
18
+ *
19
+ * ```ts
20
+ * inject: [PrismaService],
21
+ * checks: (prisma: PrismaService) => ({ database: () => prisma.$queryRaw`SELECT 1` }),
22
+ * ```
23
+ */
24
+ checks: (...deps: never[]) => HealthChecks | Promise<HealthChecks>;
25
+ /** Tokens passed to `checks`. */
26
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
27
+ /** Modules that provide the `inject` tokens, when they are not global. */
28
+ imports?: ModuleMetadata['imports'];
29
+ /** Route of the controller. Default `'health'`. */
30
+ path?: string;
31
+ /**
32
+ * Class decorators applied to the controller, e.g. the auth package's
33
+ * `@Public()` or `@SkipThrottle()`. This package imports no auth.
34
+ */
35
+ decorators?: ClassDecorator[];
36
+ }
37
+ /**
38
+ * `GET /health`: runs every check in parallel and answers 200 when all are up,
39
+ * 503 (same body, `status: 'error'`) when any is down, so Docker and load
40
+ * balancer health checks can read the status code.
41
+ *
42
+ * ```ts
43
+ * HealthModule.forRoot({
44
+ * decorators: [Public()],
45
+ * inject: [PrismaService],
46
+ * checks: (prisma: PrismaService) => ({ database: () => prisma.$queryRaw`SELECT 1` }),
47
+ * })
48
+ * ```
49
+ */
50
+ export declare class HealthModule {
51
+ static forRoot(options: HealthModuleOptions): DynamicModule;
52
+ }
53
+ //# sourceMappingURL=health.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.module.d.ts","sourceRoot":"","sources":["../../src/nest/health.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC/B,MAAM,gBAAgB,CAAA;AAEvB,8FAA8F;AAC9F,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAA;AAEvC,wFAAwF;AACxF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAEtD,4GAA4G;AAC5G,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,IAAI,GAAG,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;OAQG;IACH,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAClE,iCAAiC;IACjC,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,yBAAyB,CAAC,CAAA;IAC1D,0EAA0E;IAC1E,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;IACnC,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;CAC9B;AAaD;;;;;;;;;;;;GAYG;AACH,qBACa,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;CAwC5D"}
@@ -0,0 +1,89 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ var HealthModule_1;
11
+ import { Controller, Get, Inject, Module, Res, } from '@nestjs/common';
12
+ const HEALTH_CHECKS = Symbol('HEALTH_CHECKS');
13
+ const RESERVED = ['status', 'timestamp', 'uptime'];
14
+ async function probe(check) {
15
+ try {
16
+ return (await check()) === false ? 'disconnected' : 'connected';
17
+ }
18
+ catch {
19
+ return 'disconnected';
20
+ }
21
+ }
22
+ /**
23
+ * `GET /health`: runs every check in parallel and answers 200 when all are up,
24
+ * 503 (same body, `status: 'error'`) when any is down, so Docker and load
25
+ * balancer health checks can read the status code.
26
+ *
27
+ * ```ts
28
+ * HealthModule.forRoot({
29
+ * decorators: [Public()],
30
+ * inject: [PrismaService],
31
+ * checks: (prisma: PrismaService) => ({ database: () => prisma.$queryRaw`SELECT 1` }),
32
+ * })
33
+ * ```
34
+ */
35
+ let HealthModule = HealthModule_1 = class HealthModule {
36
+ static forRoot(options) {
37
+ let HealthController = class HealthController {
38
+ checks;
39
+ constructor(checks) {
40
+ this.checks = checks;
41
+ }
42
+ async check(res) {
43
+ const results = await Promise.all(Object.entries(this.checks).map(async ([name, check]) => [name, await probe(check)]));
44
+ const down = results.some(([, state]) => state === 'disconnected');
45
+ if (down)
46
+ res.status(503);
47
+ return {
48
+ status: down ? 'error' : 'ok',
49
+ timestamp: new Date().toISOString(),
50
+ uptime: process.uptime(),
51
+ ...Object.fromEntries(results),
52
+ };
53
+ }
54
+ };
55
+ __decorate([
56
+ Get(),
57
+ __param(0, Res({ passthrough: true }))
58
+ ], HealthController.prototype, "check", null);
59
+ HealthController = __decorate([
60
+ Controller(options.path ?? 'health'),
61
+ __param(0, Inject(HEALTH_CHECKS))
62
+ ], HealthController);
63
+ for (const decorate of options.decorators ?? [])
64
+ decorate(HealthController);
65
+ return {
66
+ module: HealthModule_1,
67
+ imports: options.imports ?? [],
68
+ controllers: [HealthController],
69
+ providers: [
70
+ {
71
+ provide: HEALTH_CHECKS,
72
+ inject: options.inject ?? [],
73
+ useFactory: async (...deps) => {
74
+ const checks = await options.checks(...deps);
75
+ const clash = Object.keys(checks).find((name) => RESERVED.includes(name));
76
+ if (clash)
77
+ throw new Error(`HealthModule: a check cannot be named "${clash}"`);
78
+ return checks;
79
+ },
80
+ },
81
+ ],
82
+ };
83
+ }
84
+ };
85
+ HealthModule = HealthModule_1 = __decorate([
86
+ Module({})
87
+ ], HealthModule);
88
+ export { HealthModule };
89
+ //# sourceMappingURL=health.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.module.js","sourceRoot":"","sources":["../../src/nest/health.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,GAAG,EACH,MAAM,EACN,MAAM,EACN,GAAG,GAKJ,MAAM,gBAAgB,CAAA;AAyCvB,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AAC7C,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;AAElD,KAAK,UAAU,KAAK,CAAC,KAAkB;IACrC,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,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AQ,CAAC;YAEtB,WAAA,MAAM,CAAC,aAAa,CAAC,CAAA;WAD9B,gBAAgB,CAiBrB;QACD,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;YAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAA;QAE3E,OAAO;YACL,MAAM,EAAE,cAAY;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,WAAW,EAAE,CAAC,gBAAgB,CAAC;YAC/B,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,aAAa;oBACtB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;oBAC5B,UAAU,EAAE,KAAK,EAAE,GAAG,IAAa,EAAyB,EAAE;wBAC5D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;wBAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;wBACzE,IAAI,KAAK;4BAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,GAAG,CAAC,CAAA;wBAC9E,OAAO,MAAM,CAAA;oBACf,CAAC;iBACF;aACF;SACF,CAAA;IACH,CAAC;CACF,CAAA;AAzCY,YAAY;IADxB,MAAM,CAAC,EAAE,CAAC;GACE,YAAY,CAyCxB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `@telamonjs/data/nest` — the NestJS + Prisma plumbing every API repeats:
3
+ * a Prisma exception filter, a health module and an audit interceptor. Needs
4
+ * `@nestjs/common` and `rxjs` (optional peers); never imports `@prisma/client` —
5
+ * the app passes its client.
6
+ *
7
+ * @module data/nest
8
+ */
9
+ export type { PrismaKnownRequestErrorLike, PrismaValidationErrorLike, PrismaErrorMessage, PrismaExceptionFilterOptions, } from './prisma-exception.filter.js';
10
+ export { PrismaExceptionFilter, isPrismaKnownRequestError, isPrismaValidationError, } from './prisma-exception.filter.js';
11
+ export type { HealthCheck, HealthChecks, HealthResponse, HealthModuleOptions } from './health.module.js';
12
+ export { HealthModule } from './health.module.js';
13
+ export type { AuditEntry, AuditInterceptorOptions } from './audit.interceptor.js';
14
+ export { createAuditInterceptor, SkipAudit } from './audit.interceptor.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,8BAA8B,CAAA;AACrC,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@telamonjs/data/nest` — the NestJS + Prisma plumbing every API repeats:
3
+ * a Prisma exception filter, a health module and an audit interceptor. Needs
4
+ * `@nestjs/common` and `rxjs` (optional peers); never imports `@prisma/client` —
5
+ * the app passes its client.
6
+ *
7
+ * @module data/nest
8
+ */
9
+ export { PrismaExceptionFilter, isPrismaKnownRequestError, isPrismaValidationError, } from './prisma-exception.filter.js';
10
+ export { HealthModule } from './health.module.js';
11
+ export { createAuditInterceptor, SkipAudit } from './audit.interceptor.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,67 @@
1
+ import { type ArgumentsHost, type ExceptionFilter } from '@nestjs/common';
2
+ /** Shape of Prisma's `PrismaClientKnownRequestError`, read without importing `@prisma/client`. */
3
+ export interface PrismaKnownRequestErrorLike {
4
+ name: string;
5
+ message: string;
6
+ /** `P` + four digits, e.g. `P2002`. */
7
+ code: string;
8
+ clientVersion?: string;
9
+ meta?: Record<string, unknown>;
10
+ }
11
+ /** Shape of Prisma's `PrismaClientValidationError`. */
12
+ export interface PrismaValidationErrorLike {
13
+ name: 'PrismaClientValidationError';
14
+ message: string;
15
+ }
16
+ /**
17
+ * `true` for a `PrismaClientKnownRequestError` from any `@prisma/client` copy:
18
+ * a `P####` code plus Prisma's `name` or `clientVersion`. A bare `code: 'P2002'`
19
+ * on some other error does not count.
20
+ */
21
+ export declare function isPrismaKnownRequestError(value: unknown): value is PrismaKnownRequestErrorLike;
22
+ /** `true` for a `PrismaClientValidationError` from any `@prisma/client` copy. */
23
+ export declare function isPrismaValidationError(value: unknown): value is PrismaValidationErrorLike;
24
+ /**
25
+ * Text of a response: a literal, or built from the fields Prisma reports
26
+ * (`meta.target` for `P2002`, `meta.field_name` for `P2003`, empty otherwise).
27
+ */
28
+ export type PrismaErrorMessage = string | ((fields: string[], error: PrismaKnownRequestErrorLike | PrismaValidationErrorLike) => string);
29
+ export interface PrismaExceptionFilterOptions {
30
+ /**
31
+ * Replaces the English default text, keyed by Prisma code (`P2002`, …),
32
+ * `validation` (`PrismaClientValidationError`) or `default` (a code this
33
+ * filter does not map, answered with 500).
34
+ */
35
+ messages?: Partial<Record<string, PrismaErrorMessage>>;
36
+ }
37
+ /**
38
+ * Answers Prisma errors with an HTTP status instead of a 500. Catches only
39
+ * Prisma's known-request and validation errors (matched by shape, so a second
40
+ * `@prisma/client` copy works too); every other error still reaches your other
41
+ * filters and Nest's default handling.
42
+ *
43
+ * | Prisma | HTTP |
44
+ * | --- | --- |
45
+ * | `P2002` unique | 409, `field` = first target field |
46
+ * | `P2003` foreign key | 400, `field` = constraint |
47
+ * | `P2025` not found | 404 |
48
+ * | `P2011`, `P2012`, `P2014`, validation error | 400 |
49
+ * | `P1000`–`P1003` connection | 503 |
50
+ * | any other code | 500, logged |
51
+ *
52
+ * Body: `{ statusCode, message, error, field?, timestamp, path }`. Written with
53
+ * Express's `res.status().json()`. Outside HTTP the error is rethrown.
54
+ *
55
+ * ```ts
56
+ * app.useGlobalFilters(new PrismaExceptionFilter({ messages: { P2025: 'Nothing here' } }))
57
+ * ```
58
+ *
59
+ * Subclass and override `catch` to change one case and call `super.catch` for the rest.
60
+ */
61
+ export declare class PrismaExceptionFilter implements ExceptionFilter {
62
+ private readonly options;
63
+ private readonly logger;
64
+ constructor(options?: PrismaExceptionFilterOptions);
65
+ catch(exception: unknown, host: ArgumentsHost): void;
66
+ }
67
+ //# sourceMappingURL=prisma-exception.filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-exception.filter.d.ts","sourceRoot":"","sources":["../../src/nest/prisma-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAExF,kGAAkG;AAClG,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,uDAAuD;AACvD,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,6BAA6B,CAAA;IACnC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,2BAA2B,CAQ9F;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,yBAAyB,CAM1F;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,2BAA2B,GAAG,yBAAyB,KAAK,MAAM,CAAC,CAAA;AAElG,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAA;CACvD;AA+CD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBACa,qBAAsB,YAAW,eAAe;IAG/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;gBAEhC,OAAO,GAAE,4BAAiC;IAEvE,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CA0BrD"}
@@ -0,0 +1,126 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Catch, Logger } from '@nestjs/common';
8
+ /**
9
+ * `true` for a `PrismaClientKnownRequestError` from any `@prisma/client` copy:
10
+ * a `P####` code plus Prisma's `name` or `clientVersion`. A bare `code: 'P2002'`
11
+ * on some other error does not count.
12
+ */
13
+ export function isPrismaKnownRequestError(value) {
14
+ if (typeof value !== 'object' || value === null)
15
+ return false;
16
+ const { code, name, clientVersion } = value;
17
+ return (typeof code === 'string' &&
18
+ /^P\d{4}$/.test(code) &&
19
+ (name === 'PrismaClientKnownRequestError' || typeof clientVersion === 'string'));
20
+ }
21
+ /** `true` for a `PrismaClientValidationError` from any `@prisma/client` copy. */
22
+ export function isPrismaValidationError(value) {
23
+ return (typeof value === 'object' &&
24
+ value !== null &&
25
+ value.name === 'PrismaClientValidationError');
26
+ }
27
+ /** Matches a Prisma error by shape: Nest picks a filter with `instanceof`, which calls this. */
28
+ class PrismaErrorShape {
29
+ static [Symbol.hasInstance](value) {
30
+ return isPrismaKnownRequestError(value) || isPrismaValidationError(value);
31
+ }
32
+ }
33
+ const REASON = {
34
+ 400: 'Bad Request',
35
+ 404: 'Not Found',
36
+ 409: 'Conflict',
37
+ 500: 'Internal Server Error',
38
+ 503: 'Service Unavailable',
39
+ };
40
+ const CONNECTION = { status: 503, message: 'Database connection error' };
41
+ const RULES = {
42
+ P2002: {
43
+ status: 409,
44
+ message: (f) => (f.length ? `Duplicate record: ${f.join(', ')} already exists` : 'Duplicate record'),
45
+ },
46
+ P2003: { status: 400, message: (f) => `Invalid reference: ${f[0] ?? 'related record'} does not exist` },
47
+ P2025: { status: 404, message: 'Record not found' },
48
+ P2011: { status: 400, message: 'Invalid data: a required value is missing' },
49
+ P2012: { status: 400, message: 'Invalid data: a required value is missing' },
50
+ P2014: { status: 400, message: 'Cannot delete: the record is referenced by other records' },
51
+ P1000: CONNECTION,
52
+ P1001: CONNECTION,
53
+ P1002: CONNECTION,
54
+ P1003: CONNECTION,
55
+ validation: { status: 400, message: 'Invalid data' },
56
+ default: { status: 500, message: 'Internal server error' },
57
+ };
58
+ /** The fields a Prisma error names: the unique `target` (P2002) or the foreign key (P2003). */
59
+ function fieldsOf(meta) {
60
+ const raw = meta?.target ?? meta?.field_name;
61
+ if (Array.isArray(raw))
62
+ return raw.map(String);
63
+ return typeof raw === 'string' ? [raw] : [];
64
+ }
65
+ /**
66
+ * Answers Prisma errors with an HTTP status instead of a 500. Catches only
67
+ * Prisma's known-request and validation errors (matched by shape, so a second
68
+ * `@prisma/client` copy works too); every other error still reaches your other
69
+ * filters and Nest's default handling.
70
+ *
71
+ * | Prisma | HTTP |
72
+ * | --- | --- |
73
+ * | `P2002` unique | 409, `field` = first target field |
74
+ * | `P2003` foreign key | 400, `field` = constraint |
75
+ * | `P2025` not found | 404 |
76
+ * | `P2011`, `P2012`, `P2014`, validation error | 400 |
77
+ * | `P1000`–`P1003` connection | 503 |
78
+ * | any other code | 500, logged |
79
+ *
80
+ * Body: `{ statusCode, message, error, field?, timestamp, path }`. Written with
81
+ * Express's `res.status().json()`. Outside HTTP the error is rethrown.
82
+ *
83
+ * ```ts
84
+ * app.useGlobalFilters(new PrismaExceptionFilter({ messages: { P2025: 'Nothing here' } }))
85
+ * ```
86
+ *
87
+ * Subclass and override `catch` to change one case and call `super.catch` for the rest.
88
+ */
89
+ let PrismaExceptionFilter = class PrismaExceptionFilter {
90
+ options;
91
+ logger = new Logger('PrismaExceptionFilter');
92
+ constructor(options = {}) {
93
+ this.options = options;
94
+ }
95
+ catch(exception, host) {
96
+ if (host.getType() !== 'http')
97
+ throw exception;
98
+ if (!isPrismaKnownRequestError(exception) && !isPrismaValidationError(exception))
99
+ throw exception;
100
+ const known = isPrismaKnownRequestError(exception);
101
+ const key = known ? (exception.code in RULES ? exception.code : 'default') : 'validation';
102
+ if (known && key === 'default') {
103
+ this.logger.error(`Unmapped Prisma error ${exception.code}: ${exception.message}`, exception.stack);
104
+ }
105
+ const fields = known ? fieldsOf(exception.meta) : [];
106
+ const rule = RULES[key];
107
+ const text = this.options.messages?.[key] ?? rule.message;
108
+ const http = host.switchToHttp();
109
+ http
110
+ .getResponse()
111
+ .status(rule.status)
112
+ .json({
113
+ statusCode: rule.status,
114
+ message: typeof text === 'function' ? text(fields, exception) : text,
115
+ error: REASON[rule.status],
116
+ ...((key === 'P2002' || key === 'P2003') && fields.length > 0 && { field: fields[0] }),
117
+ timestamp: new Date().toISOString(),
118
+ path: http.getRequest().url,
119
+ });
120
+ }
121
+ };
122
+ PrismaExceptionFilter = __decorate([
123
+ Catch(PrismaErrorShape)
124
+ ], PrismaExceptionFilter);
125
+ export { PrismaExceptionFilter };
126
+ //# sourceMappingURL=prisma-exception.filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-exception.filter.js","sourceRoot":"","sources":["../../src/nest/prisma-exception.filter.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAA4C,MAAM,gBAAgB,CAAA;AAkBxF;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,KAAgC,CAAA;IACtE,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC,IAAI,KAAK,+BAA+B,IAAI,OAAO,aAAa,KAAK,QAAQ,CAAC,CAChF,CAAA;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAA4B,CAAC,IAAI,KAAK,6BAA6B,CACrE,CAAA;AACH,CAAC;AAmBD,gGAAgG;AAChG,MAAM,gBAAgB;IACpB,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAc;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,EAAE,EAAG,SAAmB,CAAC,KAAK,CAAC,CAAA;QAChH,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACpD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAA;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QAChC,IAAI;aACD,WAAW,EAAgB;aAC3B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aACnB,IAAI,CAAC;YACJ,UAAU,EAAE,IAAI,CAAC,MAAM;YACvB,OAAO,EAAE,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI;YACpE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YAC1B,GAAG,CAAC,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACtF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAoB,CAAC,GAAG;SAC9C,CAAC,CAAA;IACN,CAAC;CACF,CAAA;AA/BY,qBAAqB;IADjC,KAAK,CAAC,gBAAgB,CAAC;GACX,qBAAqB,CA+BjC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@telamonjs/data",
3
- "version": "1.0.1",
4
- "description": "The server half of a TelamonJS list: the ListPage wire contract, sort and paging sanitizers, and a Prisma adapter (orderBy, scope-safe where, paginated services). Zero dependencies",
3
+ "version": "1.2.0",
4
+ "description": "The server half of a TelamonJS list: the ListPage wire contract, sort and paging sanitizers, a Prisma adapter (orderBy, scope-safe where, paginated services) and NestJS plumbing (Prisma exception filter, health module, audit interceptor) and audit helpers. Zero dependencies",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -16,12 +16,20 @@
16
16
  "types": "./dist/prisma/index.d.ts",
17
17
  "import": "./dist/prisma/index.js",
18
18
  "require": "./dist/prisma/index.js"
19
+ },
20
+ "./nest": {
21
+ "types": "./dist/nest/index.d.ts",
22
+ "import": "./dist/nest/index.js",
23
+ "require": "./dist/nest/index.js"
19
24
  }
20
25
  },
21
26
  "typesVersions": {
22
27
  "*": {
23
28
  "prisma": [
24
29
  "./dist/prisma/index.d.ts"
30
+ ],
31
+ "nest": [
32
+ "./dist/nest/index.d.ts"
25
33
  ]
26
34
  }
27
35
  },
@@ -31,17 +39,39 @@
31
39
  "prisma",
32
40
  "orderby",
33
41
  "data-provider",
42
+ "nestjs",
34
43
  "admin",
35
44
  "telamonjs",
36
45
  "typescript"
37
46
  ],
38
47
  "author": "Marcos Tullyo (https://github.com/mtullyoc)",
39
48
  "license": "MIT",
49
+ "peerDependencies": {
50
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
51
+ "rxjs": "^7.1.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@nestjs/common": {
55
+ "optional": true
56
+ },
57
+ "rxjs": {
58
+ "optional": true
59
+ }
60
+ },
40
61
  "devDependencies": {
62
+ "@nestjs/common": "^11.1.19",
63
+ "@nestjs/core": "^11.1.19",
64
+ "@nestjs/platform-express": "^11.1.19",
65
+ "@nestjs/testing": "^11.1.19",
66
+ "@prisma/client": "6.2.0",
41
67
  "@types/node": "^20.19.21",
68
+ "@types/supertest": "^7.2.1",
42
69
  "@vitest/coverage-v8": "^3.2.4",
43
70
  "eslint": "^9.37.0",
44
71
  "prettier": "^3.10.1",
72
+ "reflect-metadata": "^0.2.2",
73
+ "rxjs": "^7.8.1",
74
+ "supertest": "^7.3.2",
45
75
  "typescript": "^5.9.3",
46
76
  "vitest": "^3.2.4"
47
77
  },