@zedtech/zedkit-nest 0.0.0-stage → 0.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -2
  3. package/package.json +70 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zedtech-fr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,83 @@
1
- # Temporary Holding Version
1
+ # @zedtech/zedkit-nest
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generic NestJS bootstrap factory. Original work by the same author.
4
+
5
+ `createNestApp({ module, envSchema, docs, ... })` wires only standard
6
+ pieces and returns the app ready to `listen()`:
7
+
8
+ - Fastify platform (`platform-fastify`) with exact raw bodies
9
+ (`{ rawBody: true }`, proven by test) and a configurable body cap.
10
+ - Validated env (`@nestjs/config` + a class-validator schema per app;
11
+ boot fails fast with one readable error).
12
+ - Request-id JSON logs (`nestjs-pino`): honors `x-request-id`,
13
+ generates a UUID otherwise; one id across logs and error bodies.
14
+ `Authorization` and cookies are redacted from logs by default.
15
+ - Strict global `ValidationPipe` (whitelist, forbid non-whitelisted,
16
+ transform; implicit conversion off — see below). Relax per app with
17
+ `validation: { whitelist: false, forbidNonWhitelisted: false }`.
18
+ - One global error shape: `{ code, message, requestId }` (+ status).
19
+ 4xx carries the safe message; 5xx never leaks internals. Every response
20
+ echoes `x-request-id` (interceptor on handled routes, filter otherwise).
21
+ Apps with domain errors pass their own filter via `exceptionFilter`.
22
+ - Optional global throttler (`@nestjs/throttler`, default 100/min;
23
+ in-memory, single process — set `trustProxy` before running behind a
24
+ proxy or every client shares one bucket).
25
+ - Generated OpenAPI (`@nestjs/swagger`), served as raw Fastify routes:
26
+ public by design, guards do not apply. Enabled by default except in
27
+ production (`NODE_ENV=production`) — opt back in explicitly if you
28
+ serve docs in prod. `docs.aliases` serves the same JSON from extra
29
+ absolute paths. Shutdown hooks.
30
+ - Custom body parsers per content type (`bodyParsers`), installed
31
+ before Nest's defaults so an `application/json` entry replaces the
32
+ default parser; rawBody capture included.
33
+
34
+ ```ts
35
+ import "reflect-metadata";
36
+ import { createNestApp } from "@zedtech/zedkit-nest";
37
+
38
+ const app = await createNestApp({
39
+ module: AppModule,
40
+ envSchema: AppEnv,
41
+ docs: { title: "My API", version: "v1" },
42
+ });
43
+ await app.listen(3000);
44
+ ```
45
+
46
+ Framework pieces are peer dependencies (one copy per app — required for
47
+ Nest DI). Install them alongside:
48
+
49
+ ```sh
50
+ pnpm add @zedtech/zedkit-nest @fastify/static @nestjs/common @nestjs/config \
51
+ @nestjs/core @nestjs/platform-fastify @nestjs/swagger @nestjs/throttler \
52
+ class-transformer class-validator fastify nestjs-pino pino pino-http \
53
+ reflect-metadata
54
+ ```
55
+
56
+ Rules (non-negotiable):
57
+
58
+ - Zero product names or logic.
59
+ - Numbers need explicit `@Type(() => Number)` (env ints, nested
60
+ DTOs): implicit conversion relies on decorator metadata, which
61
+ vitest can only emit via SWC — and the day one suite forgets SWC,
62
+ implicit conversion silently diverges from `tsc`.
63
+ - Tests boot the factory with a product-free fixture domain and hit
64
+ it over HTTP (supertest, ephemeral ports): validation, exact raw
65
+ bytes, error shapes, throttling, request ids, docs, env failure.
66
+
67
+ Vitest transforms via SWC (`swc.vite()`, options inferred from
68
+ tsconfig): esbuild cannot emit decorator metadata, which would
69
+ silently disable the global `ValidationPipe` in tests. Never remove
70
+ it. Agent rules: [AGENTS.md](AGENTS.md)
71
+
72
+ Find helpers by need in [CATALOG.md](CATALOG.md).
73
+
74
+ ## Install or copy?
75
+
76
+ Install: this package is framework integration (DI, decorators, peer
77
+ dependencies), not suitable for source-copying.
78
+
79
+ ## Verify
80
+
81
+ ```sh
82
+ pnpm --filter @zedtech/zedkit-nest typecheck && pnpm --filter @zedtech/zedkit-nest lint && pnpm --filter @zedtech/zedkit-nest build && pnpm --filter @zedtech/zedkit-nest test
83
+ ```
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@zedtech/zedkit-nest",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.0",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org/"
7
+ },
8
+ "description": "Generic NestJS bootstrap factory: platform, config, logging, validation, errors, throttling, docs, shutdown. Original work by the same author.",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/zedtech-fr/zedkit",
13
+ "directory": "packages/nest"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "peerDependencies": {
29
+ "@fastify/static": "^10.1.7",
30
+ "@nestjs/common": "^12.2.0",
31
+ "@nestjs/config": "^12.0.1",
32
+ "@nestjs/core": "^12.2.0",
33
+ "@nestjs/platform-fastify": "^12.2.0",
34
+ "@nestjs/swagger": "^12.0.4",
35
+ "@nestjs/throttler": "^6.7.1",
36
+ "class-transformer": "^0.5.1",
37
+ "class-validator": "^0.15.1",
38
+ "fastify": "^5.12.7",
39
+ "nestjs-pino": "^5.3.1",
40
+ "pino": "^10.4.0",
41
+ "pino-http": "^11.0.0",
42
+ "reflect-metadata": "^0.2.2"
43
+ },
44
+ "devDependencies": {
45
+ "@fastify/static": "10.1.7",
46
+ "@nestjs/common": "12.2.0",
47
+ "@nestjs/config": "12.0.1",
48
+ "@nestjs/core": "12.2.0",
49
+ "@nestjs/platform-fastify": "12.2.0",
50
+ "@nestjs/swagger": "12.0.4",
51
+ "@nestjs/throttler": "6.7.1",
52
+ "@swc/core": "1.16.20",
53
+ "@types/node": "22.20.5",
54
+ "@types/supertest": "7.2.1",
55
+ "class-transformer": "0.5.1",
56
+ "class-validator": "0.15.1",
57
+ "fastify": "5.12.7",
58
+ "nestjs-pino": "5.3.1",
59
+ "pino": "10.4.0",
60
+ "pino-http": "11.0.0",
61
+ "reflect-metadata": "0.2.2",
62
+ "supertest": "7.3.1",
63
+ "typescript": "5.9.3",
64
+ "unplugin-swc": "2.0.0",
65
+ "vitest": "2.1.9"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.build.json",
69
+ "test": "vitest run",
70
+ "typecheck": "tsc --noEmit -p tsconfig.json",
71
+ "lint": "eslint src tests"
72
+ }
6
73
  }