@miguelmorales13/nestkit 0.1.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 (59) hide show
  1. package/README.md +411 -0
  2. package/dist/bootstrap/apply-defaults.d.ts +23 -0
  3. package/dist/bootstrap/index.d.ts +2 -0
  4. package/dist/bootstrap/index.js +10 -0
  5. package/dist/chunk-4MGIQFAJ.js +16 -0
  6. package/dist/chunk-EBO6UKHL.js +20 -0
  7. package/dist/chunk-EPVKCBPT.js +0 -0
  8. package/dist/chunk-EQXYK6AL.js +81 -0
  9. package/dist/chunk-EYURGACO.js +40 -0
  10. package/dist/chunk-HGJX2GPE.js +39 -0
  11. package/dist/chunk-IYUUYCP5.js +36 -0
  12. package/dist/chunk-JOVBJDJ2.js +104 -0
  13. package/dist/chunk-KDAA6GFF.js +29 -0
  14. package/dist/chunk-KP7GRCZW.js +32 -0
  15. package/dist/chunk-NAK4WDKS.js +0 -0
  16. package/dist/chunk-PA24P76K.js +39 -0
  17. package/dist/chunk-VKOPDDCC.js +50 -0
  18. package/dist/chunk-XX2HPTRU.js +12 -0
  19. package/dist/crud/crud.controller.d.ts +39 -0
  20. package/dist/crud/crud.service.d.ts +29 -0
  21. package/dist/crud/index.d.ts +5 -0
  22. package/dist/crud/index.js +9 -0
  23. package/dist/crud/repository.port.d.ts +14 -0
  24. package/dist/database/mongo/index.d.ts +1 -0
  25. package/dist/database/mongo/index.js +1 -0
  26. package/dist/database/mongo/repository.port.d.ts +1 -0
  27. package/dist/database/postgres/index.d.ts +2 -0
  28. package/dist/database/postgres/index.js +11 -0
  29. package/dist/database/postgres/postgres.module.d.ts +4 -0
  30. package/dist/database/postgres/tenant-scope.d.ts +11 -0
  31. package/dist/database/supabase/index.d.ts +1 -0
  32. package/dist/database/supabase/index.js +11 -0
  33. package/dist/database/supabase/supabase.module.d.ts +6 -0
  34. package/dist/entities/base-response.dto.d.ts +15 -0
  35. package/dist/entities/base.entity.d.ts +11 -0
  36. package/dist/entities/index.d.ts +3 -0
  37. package/dist/entities/index.js +7 -0
  38. package/dist/entities/soft-delete.entity.d.ts +8 -0
  39. package/dist/errors/app.exception.d.ts +11 -0
  40. package/dist/errors/common.exceptions.d.ts +16 -0
  41. package/dist/errors/global-exception.filter.d.ts +13 -0
  42. package/dist/errors/index.d.ts +3 -0
  43. package/dist/errors/index.js +22 -0
  44. package/dist/i18n/i18n.module.d.ts +18 -0
  45. package/dist/i18n/index.d.ts +3 -0
  46. package/dist/i18n/index.js +9 -0
  47. package/dist/i18n/translate.helper.d.ts +7 -0
  48. package/dist/index.d.ts +10 -0
  49. package/dist/index.js +75 -0
  50. package/dist/response/api-response.d.ts +20 -0
  51. package/dist/response/index.d.ts +2 -0
  52. package/dist/response/index.js +9 -0
  53. package/dist/response/response.interceptor.d.ts +13 -0
  54. package/dist/tracking/index.d.ts +4 -0
  55. package/dist/tracking/index.js +15 -0
  56. package/dist/tracking/request-context.d.ts +14 -0
  57. package/dist/tracking/request-id.middleware.d.ts +17 -0
  58. package/dist/tracking/tracking.module.d.ts +9 -0
  59. package/package.json +112 -0
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ import "./chunk-EPVKCBPT.js";
2
+ import {
3
+ PG_POOL,
4
+ PgModule,
5
+ withTenantScope
6
+ } from "./chunk-VKOPDDCC.js";
7
+ import {
8
+ SUPABASE_ANON_CLIENT,
9
+ SUPABASE_SERVICE_ROLE_CLIENT,
10
+ SupabaseModule
11
+ } from "./chunk-PA24P76K.js";
12
+ import {
13
+ applyNestKitDefaults
14
+ } from "./chunk-KP7GRCZW.js";
15
+ import {
16
+ BaseCrudService,
17
+ createCrudController
18
+ } from "./chunk-JOVBJDJ2.js";
19
+ import {
20
+ I18nModule,
21
+ translateOr
22
+ } from "./chunk-IYUUYCP5.js";
23
+ import {
24
+ BaseResponseDto
25
+ } from "./chunk-XX2HPTRU.js";
26
+ import "./chunk-NAK4WDKS.js";
27
+ import {
28
+ ResponseInterceptor
29
+ } from "./chunk-KDAA6GFF.js";
30
+ import {
31
+ REQUEST_ID_HEADER,
32
+ RequestIdMiddleware,
33
+ TrackingModule
34
+ } from "./chunk-EYURGACO.js";
35
+ import {
36
+ ConflictAppException,
37
+ ForbiddenAppException,
38
+ NotFoundAppException,
39
+ UnauthorizedAppException,
40
+ ValidationAppException
41
+ } from "./chunk-HGJX2GPE.js";
42
+ import {
43
+ AppException,
44
+ GlobalExceptionFilter
45
+ } from "./chunk-EQXYK6AL.js";
46
+ import {
47
+ RequestContext
48
+ } from "./chunk-EBO6UKHL.js";
49
+ import "./chunk-4MGIQFAJ.js";
50
+ export {
51
+ AppException,
52
+ BaseCrudService,
53
+ BaseResponseDto,
54
+ ConflictAppException,
55
+ ForbiddenAppException,
56
+ GlobalExceptionFilter,
57
+ I18nModule,
58
+ NotFoundAppException,
59
+ PG_POOL,
60
+ PgModule,
61
+ REQUEST_ID_HEADER,
62
+ RequestContext,
63
+ RequestIdMiddleware,
64
+ ResponseInterceptor,
65
+ SUPABASE_ANON_CLIENT,
66
+ SUPABASE_SERVICE_ROLE_CLIENT,
67
+ SupabaseModule,
68
+ TrackingModule,
69
+ UnauthorizedAppException,
70
+ ValidationAppException,
71
+ applyNestKitDefaults,
72
+ createCrudController,
73
+ translateOr,
74
+ withTenantScope
75
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Envelope shared by every response nestkit produces, success or error.
3
+ */
4
+ export interface BaseApiResponse {
5
+ requestId: string;
6
+ timestamp: string;
7
+ }
8
+ export interface ApiSuccessResponse<T> extends BaseApiResponse {
9
+ success: true;
10
+ data: T;
11
+ }
12
+ export interface ApiErrorResponse extends BaseApiResponse {
13
+ success: false;
14
+ error: {
15
+ code: string;
16
+ message: string;
17
+ details?: unknown;
18
+ };
19
+ }
20
+ export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
@@ -0,0 +1,2 @@
1
+ export type { ApiResponse, ApiSuccessResponse, ApiErrorResponse, BaseApiResponse } from './api-response.js';
2
+ export { ResponseInterceptor } from './response.interceptor.js';
@@ -0,0 +1,9 @@
1
+ import "../chunk-NAK4WDKS.js";
2
+ import {
3
+ ResponseInterceptor
4
+ } from "../chunk-KDAA6GFF.js";
5
+ import "../chunk-EBO6UKHL.js";
6
+ import "../chunk-4MGIQFAJ.js";
7
+ export {
8
+ ResponseInterceptor
9
+ };
@@ -0,0 +1,13 @@
1
+ import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
2
+ import type { Observable } from 'rxjs';
3
+ import type { ApiSuccessResponse } from './api-response.js';
4
+ /**
5
+ * Global interceptor that wraps every controller return value in the
6
+ * standard ApiSuccessResponse envelope. Register it with
7
+ * `app.useGlobalInterceptors(new ResponseInterceptor())` (or via
8
+ * `applyNestKitDefaults`). Relies on TrackingModule's RequestIdMiddleware
9
+ * having already populated RequestContext for the current request.
10
+ */
11
+ export declare class ResponseInterceptor<T> implements NestInterceptor<T, ApiSuccessResponse<T>> {
12
+ intercept(_context: ExecutionContext, next: CallHandler<T>): Observable<ApiSuccessResponse<T>>;
13
+ }
@@ -0,0 +1,4 @@
1
+ export { RequestContext } from './request-context.js';
2
+ export type { RequestContextStore } from './request-context.js';
3
+ export { RequestIdMiddleware, REQUEST_ID_HEADER } from './request-id.middleware.js';
4
+ export { TrackingModule } from './tracking.module.js';
@@ -0,0 +1,15 @@
1
+ import {
2
+ REQUEST_ID_HEADER,
3
+ RequestIdMiddleware,
4
+ TrackingModule
5
+ } from "../chunk-EYURGACO.js";
6
+ import {
7
+ RequestContext
8
+ } from "../chunk-EBO6UKHL.js";
9
+ import "../chunk-4MGIQFAJ.js";
10
+ export {
11
+ REQUEST_ID_HEADER,
12
+ RequestContext,
13
+ RequestIdMiddleware,
14
+ TrackingModule
15
+ };
@@ -0,0 +1,14 @@
1
+ export interface RequestContextStore {
2
+ requestId: string;
3
+ }
4
+ /**
5
+ * Thin wrapper around AsyncLocalStorage so any layer (filters, interceptors,
6
+ * services, repositories) can read the current request's id without it
7
+ * being threaded through every function signature by hand.
8
+ */
9
+ export declare class RequestContext {
10
+ private static readonly storage;
11
+ static run<T>(store: RequestContextStore, fn: () => T): T;
12
+ static getStore(): RequestContextStore | undefined;
13
+ static getRequestId(): string | undefined;
14
+ }
@@ -0,0 +1,17 @@
1
+ import { type NestMiddleware } from '@nestjs/common';
2
+ /**
3
+ * Structural (not express/fastify-specific) shapes so this middleware works
4
+ * on either HTTP adapter without pulling in extra type dependencies.
5
+ */
6
+ interface RequestIdRequest {
7
+ headers: Record<string, string | string[] | undefined>;
8
+ requestId?: string;
9
+ }
10
+ interface RequestIdResponse {
11
+ setHeader(name: string, value: string): unknown;
12
+ }
13
+ export declare const REQUEST_ID_HEADER = "x-request-id";
14
+ export declare class RequestIdMiddleware implements NestMiddleware {
15
+ use(req: RequestIdRequest, res: RequestIdResponse, next: () => void): void;
16
+ }
17
+ export {};
@@ -0,0 +1,9 @@
1
+ import { type MiddlewareConsumer, type NestModule } from '@nestjs/common';
2
+ /**
3
+ * Wires RequestIdMiddleware globally. Import this module in the consumer's
4
+ * root AppModule so every request gets a request id before it reaches
5
+ * controllers, the ResponseInterceptor, and the GlobalExceptionFilter.
6
+ */
7
+ export declare class TrackingModule implements NestModule {
8
+ configure(consumer: MiddlewareConsumer): void;
9
+ }
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "name": "@miguelmorales13/nestkit",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "description": "Reusable NestJS building blocks: i18n, error handling, standardized responses, request tracking, base entities, generic CRUD, and Postgres/Supabase connection helpers.",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "sideEffects": false,
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "main": "./dist/index.js",
16
+ "module": "./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
+ "./entities": {
24
+ "types": "./dist/entities/index.d.ts",
25
+ "import": "./dist/entities/index.js"
26
+ },
27
+ "./response": {
28
+ "types": "./dist/response/index.d.ts",
29
+ "import": "./dist/response/index.js"
30
+ },
31
+ "./errors": {
32
+ "types": "./dist/errors/index.d.ts",
33
+ "import": "./dist/errors/index.js"
34
+ },
35
+ "./tracking": {
36
+ "types": "./dist/tracking/index.d.ts",
37
+ "import": "./dist/tracking/index.js"
38
+ },
39
+ "./crud": {
40
+ "types": "./dist/crud/index.d.ts",
41
+ "import": "./dist/crud/index.js"
42
+ },
43
+ "./database/postgres": {
44
+ "types": "./dist/database/postgres/index.d.ts",
45
+ "import": "./dist/database/postgres/index.js"
46
+ },
47
+ "./database/supabase": {
48
+ "types": "./dist/database/supabase/index.d.ts",
49
+ "import": "./dist/database/supabase/index.js"
50
+ },
51
+ "./database/mongo": {
52
+ "types": "./dist/database/mongo/index.d.ts",
53
+ "import": "./dist/database/mongo/index.js"
54
+ },
55
+ "./i18n": {
56
+ "types": "./dist/i18n/index.d.ts",
57
+ "import": "./dist/i18n/index.js"
58
+ },
59
+ "./bootstrap": {
60
+ "types": "./dist/bootstrap/index.d.ts",
61
+ "import": "./dist/bootstrap/index.js"
62
+ }
63
+ },
64
+ "scripts": {
65
+ "build": "tsup && tsc -p tsconfig.build.json",
66
+ "typecheck": "tsc --noEmit",
67
+ "dev": "tsup --watch"
68
+ },
69
+ "peerDependencies": {
70
+ "@nestjs/common": "^11.0.0",
71
+ "@nestjs/core": "^11.0.0",
72
+ "@nestjs/swagger": "^11.0.0",
73
+ "@supabase/supabase-js": "^2.45.0",
74
+ "helmet": "^8.0.0",
75
+ "pg": "^8.11.0",
76
+ "reflect-metadata": "^0.2.0",
77
+ "rxjs": "^7.8.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "pg": {
81
+ "optional": true
82
+ },
83
+ "@nestjs/swagger": {
84
+ "optional": true
85
+ },
86
+ "@supabase/supabase-js": {
87
+ "optional": true
88
+ },
89
+ "helmet": {
90
+ "optional": true
91
+ }
92
+ },
93
+ "dependencies": {
94
+ "nestjs-i18n": "^10.4.5"
95
+ },
96
+ "devDependencies": {
97
+ "typescript": "^5.6.0",
98
+ "tsup": "^8.5.1",
99
+ "@types/node": "^22.0.0",
100
+ "@nestjs/common": "^11.0.0",
101
+ "@nestjs/core": "^11.0.0",
102
+ "@nestjs/swagger": "^11.0.0",
103
+ "@supabase/supabase-js": "^2.45.0",
104
+ "pg": "^8.11.0",
105
+ "@types/pg": "^8.11.0",
106
+ "helmet": "^8.0.0",
107
+ "reflect-metadata": "^0.2.0",
108
+ "rxjs": "^7.8.0",
109
+ "class-validator": "^0.14.0",
110
+ "class-transformer": "^0.5.1"
111
+ }
112
+ }