@nauth-toolkit/core 0.1.98 → 0.1.99

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.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Build-time OpenAPI schema generator for nauth-toolkit DTOs.
3
+ *
4
+ * Why this exists:
5
+ * - Consumer apps often import DTO classes from `node_modules`.
6
+ * - Many OpenAPI integrations (including NestJS Swagger plugin transforms)
7
+ * don't introspect external packages well enough to "expand" DTO shapes.
8
+ * - To keep `@nauth-toolkit/core` framework-agnostic, we generate and ship
9
+ * OpenAPI component schemas as plain JSON.
10
+ *
11
+ * Output:
12
+ * - `dist/openapi/components.schemas.json`
13
+ *
14
+ * Implementation approach (Option A):
15
+ * - Parse `src/dto/index.ts` to find exported DTO/type files.
16
+ * - Collect exported symbols (classes/interfaces/enums/types) from those files.
17
+ * - Create a temporary "registry" type that references all symbols.
18
+ * - Generate a single JSON Schema document and convert `definitions` into
19
+ * OpenAPI `components.schemas` (with `$ref` rewrites).
20
+ *
21
+ * @example
22
+ * ```bash
23
+ * # Executed by the core build:
24
+ * node dist/openapi/generate-openapi.js
25
+ * ```
26
+ */
27
+ export declare function generateOpenApiSchemas(): void;
28
+ //# sourceMappingURL=generate-openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-openapi.d.ts","sourceRoot":"","sources":["../../src/openapi/generate-openapi.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAgD7C"}
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateOpenApiSchemas = generateOpenApiSchemas;
37
+ const node_fs_1 = require("node:fs");
38
+ const node_path_1 = require("node:path");
39
+ const ts_json_schema_generator_1 = require("ts-json-schema-generator");
40
+ const ts = __importStar(require("typescript"));
41
+ /**
42
+ * Build-time OpenAPI schema generator for nauth-toolkit DTOs.
43
+ *
44
+ * Why this exists:
45
+ * - Consumer apps often import DTO classes from `node_modules`.
46
+ * - Many OpenAPI integrations (including NestJS Swagger plugin transforms)
47
+ * don't introspect external packages well enough to "expand" DTO shapes.
48
+ * - To keep `@nauth-toolkit/core` framework-agnostic, we generate and ship
49
+ * OpenAPI component schemas as plain JSON.
50
+ *
51
+ * Output:
52
+ * - `dist/openapi/components.schemas.json`
53
+ *
54
+ * Implementation approach (Option A):
55
+ * - Parse `src/dto/index.ts` to find exported DTO/type files.
56
+ * - Collect exported symbols (classes/interfaces/enums/types) from those files.
57
+ * - Create a temporary "registry" type that references all symbols.
58
+ * - Generate a single JSON Schema document and convert `definitions` into
59
+ * OpenAPI `components.schemas` (with `$ref` rewrites).
60
+ *
61
+ * @example
62
+ * ```bash
63
+ * # Executed by the core build:
64
+ * node dist/openapi/generate-openapi.js
65
+ * ```
66
+ */
67
+ function generateOpenApiSchemas() {
68
+ const packageRoot = (0, node_path_1.resolve)(__dirname, '..', '..');
69
+ const tsconfigPath = (0, node_path_1.join)(packageRoot, 'tsconfig.json');
70
+ const dtoIndexPath = (0, node_path_1.join)(packageRoot, 'src', 'dto', 'index.ts');
71
+ // `dist/openapi` (same folder as this compiled script)
72
+ const outputDir = __dirname;
73
+ const outputJsonPath = (0, node_path_1.join)(outputDir, 'components.schemas.json');
74
+ // Temporary TS source file used only for schema generation.
75
+ //
76
+ // Important: this must live under `rootDir` (src/) because the generator
77
+ // type-checks using the project's tsconfig.
78
+ const tempRegistryPath = (0, node_path_1.join)(packageRoot, 'src', 'openapi', '_nauth-openapi-dto-registry.ts');
79
+ (0, node_fs_1.mkdirSync)(outputDir, { recursive: true });
80
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(tempRegistryPath), { recursive: true });
81
+ const dtoExportFiles = parseDtoExportFiles(dtoIndexPath);
82
+ const exportedSymbols = collectExportedSymbols(dtoExportFiles);
83
+ // Avoid generating an empty schema file if parsing fails.
84
+ if (exportedSymbols.length === 0) {
85
+ throw new Error(`OpenAPI generation failed: no exported DTO symbols found from ${dtoIndexPath}.`);
86
+ }
87
+ (0, node_fs_1.writeFileSync)(tempRegistryPath, renderRegistryType(exportedSymbols), 'utf8');
88
+ try {
89
+ const generatorConfig = {
90
+ path: tempRegistryPath,
91
+ tsconfig: tsconfigPath,
92
+ type: 'NAuthOpenApiDtoRegistry',
93
+ expose: 'all',
94
+ // We already run `tsc -b` as part of the build. Skipping type-check here
95
+ // avoids TypeScript project-file-list issues when generating schemas.
96
+ skipTypeCheck: true,
97
+ };
98
+ const generator = (0, ts_json_schema_generator_1.createGenerator)(generatorConfig);
99
+ const jsonSchema = generator.createSchema('NAuthOpenApiDtoRegistry');
100
+ const openApiDoc = buildOpenApiDocumentFromJsonSchema(jsonSchema);
101
+ (0, node_fs_1.writeFileSync)(outputJsonPath, `${JSON.stringify(openApiDoc, null, 2)}\n`, 'utf8');
102
+ }
103
+ finally {
104
+ // Best-effort cleanup. Even if this fails, it doesn't affect consumers.
105
+ (0, node_fs_1.rmSync)(tempRegistryPath, { force: true });
106
+ }
107
+ }
108
+ /**
109
+ * Parse `src/dto/index.ts` to get the list of `export * from './x';` files.
110
+ */
111
+ function parseDtoExportFiles(dtoIndexPath) {
112
+ const content = (0, node_fs_1.readFileSync)(dtoIndexPath, 'utf8');
113
+ const baseDir = (0, node_path_1.dirname)(dtoIndexPath);
114
+ const files = new Set();
115
+ for (const line of content.split('\n')) {
116
+ const match = line.match(/^\s*export\s+\*\s+from\s+['"](\.\/[^'"]+)['"]\s*;\s*$/);
117
+ if (!match)
118
+ continue;
119
+ const relative = match[1];
120
+ const resolved = (0, node_path_1.join)(baseDir, `${relative}.ts`).replace(/\.ts\.ts$/, '.ts');
121
+ files.add(resolved);
122
+ }
123
+ return Array.from(files).sort();
124
+ }
125
+ /**
126
+ * Collect exported symbol names from DTO source files.
127
+ *
128
+ * We intentionally keep this limited to common exported declarations:
129
+ * - `export class Foo`
130
+ * - `export interface Foo`
131
+ * - `export enum Foo`
132
+ * - `export type Foo = ...`
133
+ */
134
+ function collectExportedSymbols(dtoFiles) {
135
+ const symbols = new Set();
136
+ for (const filePath of dtoFiles) {
137
+ const src = (0, node_fs_1.readFileSync)(filePath, 'utf8');
138
+ const sourceFile = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2022, true);
139
+ for (const statement of sourceFile.statements) {
140
+ if (!hasExportModifier(statement))
141
+ continue;
142
+ if (ts.isClassDeclaration(statement) && statement.name) {
143
+ symbols.add(statement.name.text);
144
+ continue;
145
+ }
146
+ if (ts.isInterfaceDeclaration(statement) && statement.name) {
147
+ symbols.add(statement.name.text);
148
+ continue;
149
+ }
150
+ if (ts.isEnumDeclaration(statement) && statement.name) {
151
+ symbols.add(statement.name.text);
152
+ continue;
153
+ }
154
+ if (ts.isTypeAliasDeclaration(statement) && statement.name) {
155
+ symbols.add(statement.name.text);
156
+ continue;
157
+ }
158
+ }
159
+ }
160
+ return Array.from(symbols).sort();
161
+ }
162
+ function hasExportModifier(node) {
163
+ const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
164
+ return !!modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
165
+ }
166
+ /**
167
+ * Render a temporary DTO registry type referencing all exported DTO symbols.
168
+ */
169
+ function renderRegistryType(symbols) {
170
+ const lines = [];
171
+ lines.push('/**');
172
+ lines.push(' * AUTO-GENERATED FILE (build-time only)');
173
+ lines.push(' *');
174
+ lines.push(' * This file is created temporarily during the core build to');
175
+ lines.push(' * generate OpenAPI component schemas. It is not published.');
176
+ lines.push(' */');
177
+ // Temp file lives in `src/openapi/`, so `../dto` resolves to `src/dto/`.
178
+ lines.push("import type * as Dtos from '../dto';");
179
+ lines.push('');
180
+ lines.push('export type NAuthOpenApiDtoRegistry = {');
181
+ for (const name of symbols) {
182
+ // Keep it purely in the type space.
183
+ lines.push(` ${name}: Dtos.${name};`);
184
+ }
185
+ lines.push('};');
186
+ lines.push('');
187
+ return lines.join('\n');
188
+ }
189
+ /**
190
+ * Convert a JSON Schema document into an OpenAPI document containing
191
+ * `components.schemas`.
192
+ *
193
+ * OpenAPI tooling generally expects shared schemas to be addressed via:
194
+ * - `#/components/schemas/<Name>`
195
+ *
196
+ * JSON Schema generators often emit shared types under:
197
+ * - `#/definitions/<Name>`
198
+ */
199
+ function buildOpenApiDocumentFromJsonSchema(jsonSchema) {
200
+ if (typeof jsonSchema !== 'object' || jsonSchema === null || !('definitions' in jsonSchema)) {
201
+ throw new Error('OpenAPI generation failed: JSON Schema missing `definitions`.');
202
+ }
203
+ const definitions = jsonSchema.definitions ?? {};
204
+ const schemas = {};
205
+ for (const [name, schema] of Object.entries(definitions)) {
206
+ schemas[name] = rewriteRefs(schema);
207
+ }
208
+ // Remove registry type if it got emitted as a definition.
209
+ delete schemas.NAuthOpenApiDtoRegistry;
210
+ // Also rewrite refs in case any schema object references the registry name.
211
+ for (const [name, schema] of Object.entries(schemas)) {
212
+ schemas[name] = rewriteRefs(schema);
213
+ }
214
+ return {
215
+ openapi: '3.0.3',
216
+ components: { schemas },
217
+ };
218
+ }
219
+ /**
220
+ * Recursively rewrite JSON Schema `$ref` pointers to OpenAPI pointers.
221
+ */
222
+ function rewriteRefs(value) {
223
+ if (Array.isArray(value)) {
224
+ return value.map((v) => rewriteRefs(v));
225
+ }
226
+ if (typeof value !== 'object' || value === null) {
227
+ return value;
228
+ }
229
+ const obj = value;
230
+ const next = {};
231
+ for (const [key, val] of Object.entries(obj)) {
232
+ if (key === '$ref' && typeof val === 'string') {
233
+ next[key] = val.replace(/^#\/definitions\//, '#/components/schemas/');
234
+ continue;
235
+ }
236
+ next[key] = rewriteRefs(val);
237
+ }
238
+ return next;
239
+ }
240
+ // ============================================================================
241
+ // CLI entrypoint (build-time)
242
+ // ============================================================================
243
+ // When executed directly by `node dist/openapi/generate-openapi.js`
244
+ if (require.main === module) {
245
+ generateOpenApiSchemas();
246
+ }
247
+ //# sourceMappingURL=generate-openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-openapi.js","sourceRoot":"","sources":["../../src/openapi/generate-openapi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,wDAgDC;AA/ED,qCAAyE;AACzE,yCAAmD;AACnD,uEAAwE;AACxE,+CAAiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,sBAAsB;IACpC,MAAM,WAAW,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,WAAW,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EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7C,IAAI,GAAG,KAAK,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,EAAE,uBAAuB,CAAC,CAAC;YACtE,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,oEAAoE;AACpE,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,sBAAsB,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * OpenAPI component schemas exported by `@nauth-toolkit/core`.
3
+ *
4
+ * This is intentionally framework-agnostic: consumer apps can merge these
5
+ * schemas into their OpenAPI document (NestJS, Express, Fastify, etc.).
6
+ *
7
+ * Notes:
8
+ * - Schemas are generated at build time into `dist/openapi/components.schemas.json`
9
+ * - The schema names match the exported DTO/type names (e.g. `SignupDTO`)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { loadNAuthOpenApiSchemas } from '@nauth-toolkit/core/openapi';
14
+ *
15
+ * // Merge into your OpenAPI document:
16
+ * const schemas = loadNAuthOpenApiSchemas();
17
+ * openapi.components = openapi.components ?? {};
18
+ * openapi.components.schemas = {
19
+ * ...(openapi.components.schemas ?? {}),
20
+ * ...schemas,
21
+ * };
22
+ * ```
23
+ */
24
+ export interface NAuthOpenApiDocument {
25
+ /**
26
+ * OpenAPI version string.
27
+ *
28
+ * Example: `"3.0.3"`
29
+ */
30
+ openapi: string;
31
+ /**
32
+ * OpenAPI components section containing reusable schemas.
33
+ */
34
+ components: {
35
+ /**
36
+ * Generated schemas keyed by DTO/type name.
37
+ *
38
+ * Values are OpenAPI Schema Objects (kept as `unknown` to avoid introducing
39
+ * a runtime dependency on an OpenAPI typings package).
40
+ */
41
+ schemas: Record<string, unknown>;
42
+ };
43
+ }
44
+ /**
45
+ * Load the generated OpenAPI document from the packaged JSON file.
46
+ *
47
+ * This is safe to call in production code. The JSON is generated during the
48
+ * library build and shipped in `dist/`.
49
+ *
50
+ * @returns The generated OpenAPI document containing `components.schemas`.
51
+ *
52
+ * @throws {Error} When the generated OpenAPI JSON file is missing or invalid.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { loadNAuthOpenApiDocument } from '@nauth-toolkit/core/openapi';
57
+ *
58
+ * const doc = loadNAuthOpenApiDocument();
59
+ * console.log(Object.keys(doc.components.schemas));
60
+ * ```
61
+ */
62
+ export declare function loadNAuthOpenApiDocument(): NAuthOpenApiDocument;
63
+ /**
64
+ * Load only the OpenAPI component schemas (`components.schemas`).
65
+ *
66
+ * @returns The generated OpenAPI schemas keyed by DTO/type name.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { loadNAuthOpenApiSchemas } from '@nauth-toolkit/core/openapi';
71
+ *
72
+ * const schemas = loadNAuthOpenApiSchemas();
73
+ * console.log(Object.keys(schemas));
74
+ * ```
75
+ */
76
+ export declare function loadNAuthOpenApiSchemas(): Record<string, unknown>;
77
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,UAAU,EAAE;QACV;;;;;WAKG;QACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,IAAI,oBAAoB,CAI/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjE"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadNAuthOpenApiDocument = loadNAuthOpenApiDocument;
4
+ exports.loadNAuthOpenApiSchemas = loadNAuthOpenApiSchemas;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ /**
8
+ * Load the generated OpenAPI document from the packaged JSON file.
9
+ *
10
+ * This is safe to call in production code. The JSON is generated during the
11
+ * library build and shipped in `dist/`.
12
+ *
13
+ * @returns The generated OpenAPI document containing `components.schemas`.
14
+ *
15
+ * @throws {Error} When the generated OpenAPI JSON file is missing or invalid.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { loadNAuthOpenApiDocument } from '@nauth-toolkit/core/openapi';
20
+ *
21
+ * const doc = loadNAuthOpenApiDocument();
22
+ * console.log(Object.keys(doc.components.schemas));
23
+ * ```
24
+ */
25
+ function loadNAuthOpenApiDocument() {
26
+ const filePath = (0, node_path_1.join)(__dirname, 'components.schemas.json');
27
+ const json = (0, node_fs_1.readFileSync)(filePath, 'utf8');
28
+ return JSON.parse(json);
29
+ }
30
+ /**
31
+ * Load only the OpenAPI component schemas (`components.schemas`).
32
+ *
33
+ * @returns The generated OpenAPI schemas keyed by DTO/type name.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { loadNAuthOpenApiSchemas } from '@nauth-toolkit/core/openapi';
38
+ *
39
+ * const schemas = loadNAuthOpenApiSchemas();
40
+ * console.log(Object.keys(schemas));
41
+ * ```
42
+ */
43
+ function loadNAuthOpenApiSchemas() {
44
+ return loadNAuthOpenApiDocument().components.schemas;
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":";;AAkEA,4DAIC;AAeD,0DAEC;AAvFD,qCAAuC;AACvC,yCAAiC;AA+CjC;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,wBAAwB;IACtC,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,IAAA,sBAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAyB,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB;IACrC,OAAO,wBAAwB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;AACvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nauth-toolkit/core",
3
- "version": "0.1.98",
3
+ "version": "0.1.99",
4
4
  "description": "Core authentication toolkit for Node JS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,6 +10,11 @@
10
10
  "require": "./dist/index.js",
11
11
  "default": "./dist/index.js"
12
12
  },
13
+ "./openapi": {
14
+ "types": "./dist/openapi/index.d.ts",
15
+ "require": "./dist/openapi/index.js",
16
+ "default": "./dist/openapi/index.js"
17
+ },
13
18
  "./internal": {
14
19
  "types": "./dist/internal.d.ts",
15
20
  "require": "./dist/internal.js",
@@ -18,13 +23,16 @@
18
23
  },
19
24
  "typesVersions": {
20
25
  "*": {
26
+ "openapi": [
27
+ "dist/openapi/index.d.ts"
28
+ ],
21
29
  "internal": [
22
30
  "dist/internal.d.ts"
23
31
  ]
24
32
  }
25
33
  },
26
34
  "scripts": {
27
- "build": "yarn clean && tsc -b",
35
+ "build": "yarn clean && tsc -b && node dist/openapi/generate-openapi.js",
28
36
  "clean": "rm -rf dist *.tsbuildinfo",
29
37
  "test": "jest",
30
38
  "lint": "eslint src --ext .ts",
@@ -41,8 +49,8 @@
41
49
  },
42
50
  "peerDependencies": {
43
51
  "@maxmind/geoip2-node": "^4.0.0 || ^5.0.0 || ^6.0.0",
44
- "typeorm": "^0.3.0",
45
- "@nauth-toolkit/recaptcha": "^0.1.98"
52
+ "@nauth-toolkit/recaptcha": "^0.1.99",
53
+ "typeorm": "^0.3.0"
46
54
  },
47
55
  "peerDependenciesMeta": {
48
56
  "@maxmind/geoip2-node": {
@@ -57,6 +65,7 @@
57
65
  "jest": "^29.7.0",
58
66
  "reflect-metadata": "^0.2.2",
59
67
  "ts-jest": "^29.2.0",
68
+ "ts-json-schema-generator": "^2.4.0",
60
69
  "typeorm": "^0.3.27",
61
70
  "typescript": "^5.5.0"
62
71
  },