@decaf-ts/for-nest 0.2.41 → 0.3.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 (36) hide show
  1. package/README.md +1 -1
  2. package/dist/for-nest.cjs +1 -1
  3. package/dist/for-nest.cjs.map +1 -1
  4. package/dist/for-nest.js +1 -1
  5. package/dist/for-nest.js.map +1 -1
  6. package/lib/controllers.cjs +67 -7
  7. package/lib/controllers.d.ts +4 -2
  8. package/lib/controllers.js.map +1 -1
  9. package/lib/esm/controllers.d.ts +4 -2
  10. package/lib/esm/controllers.js +67 -7
  11. package/lib/esm/controllers.js.map +1 -1
  12. package/lib/esm/factory/exceptions/decorators.d.ts +1 -0
  13. package/lib/esm/factory/exceptions/decorators.js +5 -1
  14. package/lib/esm/factory/exceptions/decorators.js.map +1 -1
  15. package/lib/esm/index.d.ts +2 -1
  16. package/lib/esm/index.js +4 -1
  17. package/lib/esm/index.js.map +1 -1
  18. package/lib/esm/request/DecafResponseInterceptor.d.ts +8 -0
  19. package/lib/esm/request/DecafResponseInterceptor.js +29 -0
  20. package/lib/esm/request/DecafResponseInterceptor.js.map +1 -0
  21. package/lib/esm/request/index.d.ts +1 -0
  22. package/lib/esm/request/index.js +1 -0
  23. package/lib/esm/request/index.js.map +1 -1
  24. package/lib/factory/exceptions/decorators.cjs +5 -0
  25. package/lib/factory/exceptions/decorators.d.ts +1 -0
  26. package/lib/factory/exceptions/decorators.js.map +1 -1
  27. package/lib/index.cjs +4 -1
  28. package/lib/index.d.ts +2 -1
  29. package/lib/index.js.map +1 -1
  30. package/lib/request/DecafResponseInterceptor.cjs +32 -0
  31. package/lib/request/DecafResponseInterceptor.d.ts +8 -0
  32. package/lib/request/DecafResponseInterceptor.js.map +1 -0
  33. package/lib/request/index.cjs +1 -0
  34. package/lib/request/index.d.ts +1 -0
  35. package/lib/request/index.js.map +1 -1
  36. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.js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ChC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAA4C;IACpE,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,MAAM,OAAO,GAAI,GAAe,CAAC,OAGhC,CAAC;IACF,MAAM,SAAS,GACb,aAAa,CAAC,OAAO,EAAE,CAAC,iBAAiB,CAAC,CAAC;QAC3C,aAAa,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC;QACrC,aAAa,CAAC,OAAO,EAAE,CAAC,iBAAiB,CAAC,CAAC;QAC3C,aAAa,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IACxC,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,IACE,OAAQ,GAAe,CAAC,EAAE,KAAK,QAAQ;QACrC,GAAe,CAAC,EAAU,CAAC,MAAM;QAEnC,OAAQ,GAAe,CAAC,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAI,GAAe,CAAC,MAAM,IAAK,GAAW,CAAC,UAAU,CAAC;IAClE,IACE,MAAM;QACN,OAAO,MAAM,CAAC,aAAa,KAAK,QAAQ;QACxC,MAAM,CAAC,aAAa,CAAC,MAAM;QAE3B,OAAO,MAAM,CAAC,aAAa,CAAC;IAC9B,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAsB,CAAC,IAAI,KAAK,UAAU,CACnD,CAAC;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { Context, ContextOf, ContextualizedArgs, FlagsOf, MaybeContextualArg, MethodOrOperation, ModelService, Repo, Service } from "@decaf-ts/core";
2
+ import { type Request } from "express";
2
3
  import { DecafServerCtx } from "./constants";
3
4
  import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
4
5
  import { DecafRequestContext } from "./request/DecafRequestContext";
@@ -8,6 +9,7 @@ export declare abstract class DecafController<CONTEXT extends DecafServerCtx> ex
8
9
  protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD): ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>;
9
10
  protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: false, overrides?: Partial<FlagsOf<CONTEXT>>): ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>;
10
11
  protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: true, overrides?: Partial<FlagsOf<CONTEXT>>): Promise<ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>>;
12
+ protected bindLoggerToRequest<RESULT extends ContextualizedArgs<any, any>>(value: RESULT | Promise<RESULT>, request?: Request): RESULT | Promise<RESULT>;
11
13
  }
12
14
  export declare abstract class DecafModelController<M extends Model<boolean>, C extends DecafServerCtx = DecafServerCtx> extends DecafController<C> {
13
15
  private _persistence?;
@@ -15,6 +17,6 @@ export declare abstract class DecafModelController<M extends Model<boolean>, C e
15
17
  persistence(ctx?: Context<any>): Repo<M> | ModelService<M>;
16
18
  protected constructor(clientContext: DecafRequestContext, name: string);
17
19
  protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<any, ARGS>, operation: METHOD): ContextualizedArgs<ContextOf<ReturnType<this["persistence"]>>, ARGS, METHOD extends string ? true : false>;
18
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<ReturnType<this["persistence"]>>, ARGS>, operation: METHOD, allowCreate: false): ContextualizedArgs<ContextOf<ReturnType<this["persistence"]>>, ARGS, METHOD extends string ? true : false>;
19
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<ReturnType<this["persistence"]>>, ARGS>, operation: METHOD, allowCreate: true): Promise<ContextualizedArgs<ContextOf<ReturnType<this["persistence"]>>, ARGS, METHOD extends string ? true : false>>;
20
+ protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<ReturnType<this["persistence"]>>, ARGS>, operation: METHOD, allowCreate: false, overrides?: Partial<FlagsOf<ContextOf<ReturnType<this["persistence"]>>>>): ContextualizedArgs<ContextOf<ReturnType<this["persistence"]>>, ARGS, METHOD extends string ? true : false>;
21
+ protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<ReturnType<this["persistence"]>>, ARGS>, operation: METHOD, allowCreate: true, overrides?: Partial<FlagsOf<ContextOf<ReturnType<this["persistence"]>>>>): Promise<ContextualizedArgs<ContextOf<ReturnType<this["persistence"]>>, ARGS, METHOD extends string ? true : false>>;
20
22
  }
@@ -8,7 +8,31 @@ export class DecafController extends Service {
8
8
  logCtx(args, operation, allowCreate = false, overrides) {
9
9
  const ctx = this.clientContext.ctx;
10
10
  args = args.filter((e) => typeof e !== "undefined");
11
- return ContextualLoggedClass.logCtx.call(this, operation, overrides || {}, allowCreate, ...[...args, ctx]);
11
+ let request = undefined;
12
+ if (overrides && (overrides.headers || overrides.ip)) {
13
+ request = overrides;
14
+ overrides = {};
15
+ }
16
+ const result = ContextualLoggedClass.logCtx.call(this, operation, overrides || {}, allowCreate, ...[...args, ctx]);
17
+ return this.bindLoggerToRequest(result, request);
18
+ }
19
+ bindLoggerToRequest(value, request) {
20
+ const self = this;
21
+ function applyRequestIp(ctxArgs, request) {
22
+ ctxArgs.log = decorateLoggerWithIp(ctxArgs.log, request);
23
+ return ctxArgs;
24
+ }
25
+ function decorateLoggerWithIp(log, request) {
26
+ const ip = extractRequestIp(request ?? self.clientContext.request);
27
+ if (!ip)
28
+ return log;
29
+ const config = { ip };
30
+ return log.for(config);
31
+ }
32
+ if (isPromise(value)) {
33
+ return value.then((ctxArgs) => applyRequestIp(ctxArgs, request));
34
+ }
35
+ return applyRequestIp(value, request);
12
36
  }
13
37
  }
14
38
  export class DecafModelController extends DecafController {
@@ -40,10 +64,14 @@ export class DecafModelController extends DecafController {
40
64
  constructor(clientContext, name) {
41
65
  super(clientContext, name);
42
66
  }
43
- logCtx(args, operation, allowCreate = false) {
67
+ logCtx(args, operation, allowCreate = false, overrides) {
44
68
  // TODO get nestJS context
45
69
  const ctx = this.clientContext.ctx;
46
- let overrides = {};
70
+ let request = undefined;
71
+ if (overrides && (overrides.headers || overrides.ip)) {
72
+ request = overrides;
73
+ overrides = {};
74
+ }
47
75
  try {
48
76
  overrides = ctx.get("overrides");
49
77
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -63,11 +91,43 @@ export class DecafModelController extends DecafController {
63
91
  let ctxArgs;
64
92
  if (!allowCreate) {
65
93
  ctxArgs = contextual["logCtx"](args, operation, false, overrides);
66
- return ctxArgs;
94
+ return this.bindLoggerToRequest(ctxArgs, request);
67
95
  }
68
- return contextual["logCtx"](args, operation, true, overrides).then((ctxArgs) => {
69
- return ctxArgs;
70
- });
96
+ return contextual["logCtx"](args, operation, true, overrides).then((ctxArgs) => this.bindLoggerToRequest(ctxArgs, request));
71
97
  }
72
98
  }
99
+ function parseIpHeader(value) {
100
+ if (!value)
101
+ return undefined;
102
+ const candidate = Array.isArray(value) ? value[0] : value;
103
+ return candidate
104
+ .split(",")
105
+ .map((segment) => segment.trim())
106
+ .filter(Boolean)[0];
107
+ }
108
+ function extractRequestIp(req) {
109
+ if (!req)
110
+ return undefined;
111
+ const headers = req.headers;
112
+ const forwarded = parseIpHeader(headers?.["x-forwarded-for"]) ??
113
+ parseIpHeader(headers?.["x-real-ip"]) ??
114
+ parseIpHeader(headers?.["X-Forwarded-For"]) ??
115
+ parseIpHeader(headers?.["X-Real-IP"]);
116
+ if (forwarded)
117
+ return forwarded;
118
+ if (typeof req.ip === "string" &&
119
+ req.ip.length)
120
+ return req.ip;
121
+ const socket = req.socket || req.connection;
122
+ if (socket &&
123
+ typeof socket.remoteAddress === "string" &&
124
+ socket.remoteAddress.length)
125
+ return socket.remoteAddress;
126
+ return undefined;
127
+ }
128
+ function isPromise(value) {
129
+ return (typeof value === "object" &&
130
+ value !== null &&
131
+ typeof value.then === "function");
132
+ }
73
133
  //# sourceMappingURL=controllers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.js","sourceRoot":"","sources":["../../src/controllers.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,qBAAqB,EAIrB,YAAY,EAEZ,UAAU,EACV,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAkB,uBAAoB;AAMpE,MAAM,OAAgB,eAEpB,SAAQ,OAAgB;IACxB,YACqB,aAAkC,EACrD,IAAY;QAEZ,KAAK,CAAC,IAAI,CAAC,CAAC;QAHO,kBAAa,GAAb,aAAa,CAAqB;IAIvD,CAAC;IA4BkB,MAAM,CAKvB,IAAuC,EACvC,SAAiB,EACjB,cAAsB,KAAe,EACrC,SAAqC;QAMrC,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;QACnC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC,CAAC;QACpD,OAAO,qBAAqB,CAAC,MAAM,CAAC,IAAI,CACtC,IAAI,EACJ,SAAS,EACT,SAAS,IAAI,EAAE,EACf,WAAW,EACX,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CACX,CAAC;IACX,CAAC;CACF;AAED,MAAM,OAAgB,oBAGpB,SAAQ,eAAkB;IAK1B,WAAW,CAAC,GAAkB;QAC5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AU,CAAC;IAClE,IACE,MAAM;QACN,OAAO,MAAM,CAAC,aAAa,KAAK,QAAQ;QACxC,MAAM,CAAC,aAAa,CAAC,MAAM;QAE3B,OAAO,MAAM,CAAC,aAAa,CAAC;IAC9B,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAsB,CAAC,IAAI,KAAK,UAAU,CACnD,CAAC;AACJ,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare function UseDecafFilter(): MethodDecorator & ClassDecorator;
2
+ export declare function UseDecafHeaders(): MethodDecorator & ClassDecorator;
@@ -1,6 +1,10 @@
1
- import { UseFilters } from "@nestjs/common";
1
+ import { UseFilters, UseInterceptors } from "@nestjs/common";
2
2
  import { DecafExceptionFilter } from "./DecafErrorFilter.js";
3
+ import { DecafResponseInterceptor } from "./../../request/index.js";
3
4
  export function UseDecafFilter() {
4
5
  return UseFilters(new DecafExceptionFilter());
5
6
  }
7
+ export function UseDecafHeaders() {
8
+ return UseInterceptors(DecafResponseInterceptor);
9
+ }
6
10
  //# sourceMappingURL=decorators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/factory/exceptions/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,8BAA2B;AAE1D,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AAChD,CAAC"}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/factory/exceptions/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,8BAA2B;AAC1D,OAAO,EAAE,wBAAwB,EAAE,iCAA4B;AAE/D,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,eAAe,CAAC,wBAAwB,CAAC,CAAC;AACnD,CAAC"}
@@ -29,6 +29,7 @@ export * from "./request";
29
29
  export * from "./constants";
30
30
  export * from "./controllers";
31
31
  export * from "./module";
32
+ export * from "./core-module";
32
33
  export * from "./types";
33
34
  export * from "./utils";
34
35
  export * from "./events-module";
@@ -38,5 +39,5 @@ export * from "./events-module";
38
39
  * @constant
39
40
  * @type {string}
40
41
  */
41
- export declare const VERSION = "0.2.40";
42
+ export declare const VERSION = "0.2.42";
42
43
  export declare const PACKAGE_NAME = "@decaf-ts/for-nest";
package/lib/esm/index.js CHANGED
@@ -30,6 +30,7 @@ export * from "./request/index.js";
30
30
  export * from "./constants.js";
31
31
  export * from "./controllers.js";
32
32
  export * from "./module.js";
33
+ export * from "./core-module.js";
33
34
  export * from "./types.js";
34
35
  export * from "./utils.js";
35
36
  export * from "./events-module/index.js";
@@ -39,7 +40,9 @@ export * from "./events-module/index.js";
39
40
  * @constant
40
41
  * @type {string}
41
42
  */
42
- export const VERSION = "0.2.40";
43
+ export const VERSION = "0.2.42";
43
44
  export const PACKAGE_NAME = "@decaf-ts/for-nest";
45
+ Metadata.allowReregistration(true);
44
46
  Metadata.registerLibrary(PACKAGE_NAME, VERSION);
47
+ Metadata.allowReregistration(false);
45
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,yBAAsB;AAEtB,gCAA6B,CAAC,oBAAoB;AAClD,uCAA8B;AAC9B,mCAA0B;AAC1B,wCAA+B;AAC/B,qCAA4B;AAC5B,mCAA0B;AAC1B,+BAA4B;AAC5B,iCAA8B;AAC9B,4BAAyB;AACzB,2BAAwB;AACxB,2BAAwB;AACxB,yCAAgC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,QAAQ,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,yBAAsB;AAEtB,gCAA6B,CAAC,oBAAoB;AAClD,uCAA8B;AAC9B,mCAA0B;AAC1B,wCAA+B;AAC/B,qCAA4B;AAC5B,mCAA0B;AAC1B,+BAA4B;AAC5B,iCAA8B;AAC9B,4BAAyB;AACzB,iCAA8B;AAC9B,2BAAwB;AACxB,2BAAwB;AACxB,yCAAgC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACnC,QAAQ,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAChD,QAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
2
+ import { Observable } from "rxjs";
3
+ import { DecafRequestContext } from "./index";
4
+ export declare class DecafResponseInterceptor implements NestInterceptor {
5
+ protected ctx: DecafRequestContext;
6
+ constructor(ctx: DecafRequestContext);
7
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
8
+ }
@@ -0,0 +1,29 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable, } from "@nestjs/common";
11
+ import { tap } from "rxjs";
12
+ import { DecafRequestContext } from "./index.js";
13
+ let DecafResponseInterceptor = class DecafResponseInterceptor {
14
+ constructor(ctx) {
15
+ this.ctx = ctx;
16
+ }
17
+ intercept(context, next) {
18
+ let response = context.switchToHttp().getResponse();
19
+ return next.handle().pipe(tap((data) => {
20
+ response = this.ctx.ctx.toResponse(response);
21
+ }));
22
+ }
23
+ };
24
+ DecafResponseInterceptor = __decorate([
25
+ Injectable(),
26
+ __metadata("design:paramtypes", [DecafRequestContext])
27
+ ], DecafResponseInterceptor);
28
+ export { DecafResponseInterceptor };
29
+ //# sourceMappingURL=DecafResponseInterceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafResponseInterceptor.js","sourceRoot":"","sources":["../../../src/request/DecafResponseInterceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,UAAU,GAIX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,mBAAgB;AAGvC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAAsB,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;IAAG,CAAC;IAElD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC;QAEpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACX,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAZY,wBAAwB;IADpC,UAAU,EAAE;qCAEgB,mBAAmB;GADnC,wBAAwB,CAYpC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./DecafAuthHandler";
2
2
  export * from "./DecafRequestContext";
3
3
  export * from "./DecafHandlerExecutor";
4
+ export * from "./DecafResponseInterceptor";
@@ -1,4 +1,5 @@
1
1
  export * from "./DecafAuthHandler.js";
2
2
  export * from "./DecafRequestContext.js";
3
3
  export * from "./DecafHandlerExecutor.js";
4
+ export * from "./DecafResponseInterceptor.js";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request/index.ts"],"names":[],"mappings":"AAAA,sCAAmC;AACnC,yCAAsC;AACtC,0CAAuC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request/index.ts"],"names":[],"mappings":"AAAA,sCAAmC;AACnC,yCAAsC;AACtC,0CAAuC;AACvC,8CAA2C"}
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UseDecafFilter = UseDecafFilter;
4
+ exports.UseDecafHeaders = UseDecafHeaders;
4
5
  const common_1 = require("@nestjs/common");
5
6
  const DecafErrorFilter_1 = require("./DecafErrorFilter.cjs");
7
+ const index_1 = require("./../../request/index.cjs");
6
8
  function UseDecafFilter() {
7
9
  return (0, common_1.UseFilters)(new DecafErrorFilter_1.DecafExceptionFilter());
8
10
  }
11
+ function UseDecafHeaders() {
12
+ return (0, common_1.UseInterceptors)(index_1.DecafResponseInterceptor);
13
+ }
9
14
  //# sourceMappingURL=decorators.js.map
@@ -1 +1,2 @@
1
1
  export declare function UseDecafFilter(): MethodDecorator & ClassDecorator;
2
+ export declare function UseDecafHeaders(): MethodDecorator & ClassDecorator;
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/factory/exceptions/decorators.ts"],"names":[],"mappings":";;AAGA,wCAEC;AALD,2CAA4C;AAC5C,6DAA0D;AAE1D,SAAgB,cAAc;IAC5B,OAAO,IAAA,mBAAU,EAAC,IAAI,uCAAoB,EAAE,CAAC,CAAC;AAChD,CAAC"}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/factory/exceptions/decorators.ts"],"names":[],"mappings":";;AAIA,wCAEC;AAED,0CAEC;AAVD,2CAA6D;AAC7D,6DAA0D;AAC1D,qDAA+D;AAE/D,SAAgB,cAAc;IAC5B,OAAO,IAAA,mBAAU,EAAC,IAAI,uCAAoB,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,eAAe;IAC7B,OAAO,IAAA,wBAAe,EAAC,gCAAwB,CAAC,CAAC;AACnD,CAAC"}
package/lib/index.cjs CHANGED
@@ -47,6 +47,7 @@ __exportStar(require("./request/index.cjs"), exports);
47
47
  __exportStar(require("./constants.cjs"), exports);
48
48
  __exportStar(require("./controllers.cjs"), exports);
49
49
  __exportStar(require("./module.cjs"), exports);
50
+ __exportStar(require("./core-module.cjs"), exports);
50
51
  __exportStar(require("./types.cjs"), exports);
51
52
  __exportStar(require("./utils.cjs"), exports);
52
53
  __exportStar(require("./events-module/index.cjs"), exports);
@@ -56,7 +57,9 @@ __exportStar(require("./events-module/index.cjs"), exports);
56
57
  * @constant
57
58
  * @type {string}
58
59
  */
59
- exports.VERSION = "0.2.40";
60
+ exports.VERSION = "0.2.42";
60
61
  exports.PACKAGE_NAME = "@decaf-ts/for-nest";
62
+ decoration_1.Metadata.allowReregistration(true);
61
63
  decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
64
+ decoration_1.Metadata.allowReregistration(false);
62
65
  //# sourceMappingURL=index.js.map
package/lib/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export * from "./request";
29
29
  export * from "./constants";
30
30
  export * from "./controllers";
31
31
  export * from "./module";
32
+ export * from "./core-module";
32
33
  export * from "./types";
33
34
  export * from "./utils";
34
35
  export * from "./events-module";
@@ -38,5 +39,5 @@ export * from "./events-module";
38
39
  * @constant
39
40
  * @type {string}
40
41
  */
41
- export declare const VERSION = "0.2.40";
42
+ export declare const VERSION = "0.2.42";
42
43
  export declare const PACKAGE_NAME = "@decaf-ts/for-nest";
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,qDAAgD;AAChD,4BAAsB;AAEtB,mDAA6B,CAAC,oBAAoB;AAClD,0DAA8B;AAC9B,sDAA0B;AAC1B,2DAA+B;AAC/B,wDAA4B;AAC5B,sDAA0B;AAC1B,kDAA4B;AAC5B,oDAA8B;AAC9B,+CAAyB;AACzB,8CAAwB;AACxB,8CAAwB;AACxB,4DAAgC;AAEhC;;;;;GAKG;AACU,QAAA,OAAO,GAAG,aAAa,CAAC;AACxB,QAAA,YAAY,GAAG,aAAa,CAAC;AAE1C,qBAAQ,CAAC,eAAe,CAAC,oBAAY,EAAE,eAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,qDAAgD;AAChD,4BAAsB;AAEtB,mDAA6B,CAAC,oBAAoB;AAClD,0DAA8B;AAC9B,sDAA0B;AAC1B,2DAA+B;AAC/B,wDAA4B;AAC5B,sDAA0B;AAC1B,kDAA4B;AAC5B,oDAA8B;AAC9B,+CAAyB;AACzB,oDAA8B;AAC9B,8CAAwB;AACxB,8CAAwB;AACxB,4DAAgC;AAEhC;;;;;GAKG;AACU,QAAA,OAAO,GAAG,aAAa,CAAC;AACxB,QAAA,YAAY,GAAG,aAAa,CAAC;AAE1C,qBAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACnC,qBAAQ,CAAC,eAAe,CAAC,oBAAY,EAAE,eAAO,CAAC,CAAC;AAChD,qBAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DecafResponseInterceptor = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const rxjs_1 = require("rxjs");
15
+ const index_1 = require("./index.cjs");
16
+ let DecafResponseInterceptor = class DecafResponseInterceptor {
17
+ constructor(ctx) {
18
+ this.ctx = ctx;
19
+ }
20
+ intercept(context, next) {
21
+ let response = context.switchToHttp().getResponse();
22
+ return next.handle().pipe((0, rxjs_1.tap)((data) => {
23
+ response = this.ctx.ctx.toResponse(response);
24
+ }));
25
+ }
26
+ };
27
+ exports.DecafResponseInterceptor = DecafResponseInterceptor;
28
+ exports.DecafResponseInterceptor = DecafResponseInterceptor = __decorate([
29
+ (0, common_1.Injectable)(),
30
+ __metadata("design:paramtypes", [index_1.DecafRequestContext])
31
+ ], DecafResponseInterceptor);
32
+ //# sourceMappingURL=DecafResponseInterceptor.js.map
@@ -0,0 +1,8 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
2
+ import { Observable } from "rxjs";
3
+ import { DecafRequestContext } from "./index";
4
+ export declare class DecafResponseInterceptor implements NestInterceptor {
5
+ protected ctx: DecafRequestContext;
6
+ constructor(ctx: DecafRequestContext);
7
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
8
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafResponseInterceptor.js","sourceRoot":"","sources":["../../src/request/DecafResponseInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,+BAAuC;AACvC,uCAA8C;AAGvC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAAsB,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;IAAG,CAAC;IAElD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC;QAEpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,UAAG,EAAC,CAAC,IAAI,EAAE,EAAE;YACX,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAZY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAEgB,2BAAmB;GADnC,wBAAwB,CAYpC"}
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./DecafAuthHandler.cjs"), exports);
18
18
  __exportStar(require("./DecafRequestContext.cjs"), exports);
19
19
  __exportStar(require("./DecafHandlerExecutor.cjs"), exports);
20
+ __exportStar(require("./DecafResponseInterceptor.cjs"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
1
  export * from "./DecafAuthHandler";
2
2
  export * from "./DecafRequestContext";
3
3
  export * from "./DecafHandlerExecutor";
4
+ export * from "./DecafResponseInterceptor";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC;AACnC,4DAAsC;AACtC,6DAAuC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC;AACnC,4DAAsC;AACtC,6DAAuC;AACvC,iEAA2C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-nest",
3
- "version": "0.2.41",
3
+ "version": "0.3.0",
4
4
  "description": "NestJS decaf integration",
5
5
  "type": "module",
6
6
  "exports": {
@@ -88,7 +88,7 @@
88
88
  },
89
89
  "homepage": "https://github.com/decaf-ts/for-nest#readme",
90
90
  "devDependencies": {
91
- "@decaf-ts/for-fabric": "latest",
91
+ "@decaf-ts/for-fabric": "^0.3.44",
92
92
  "@decaf-ts/for-http": "latest",
93
93
  "@decaf-ts/utils": "latest",
94
94
  "@eslint/js": "^9.25.1",
@@ -97,6 +97,7 @@
97
97
  "@nestjs/schematics": "^11.0.9",
98
98
  "@nestjs/swagger": "^11.2.6",
99
99
  "@nestjs/testing": "^11.1.14",
100
+ "@types/express": "^5.0.6",
100
101
  "@types/jest": "^30.0.0",
101
102
  "@types/lodash": "^4.17.20",
102
103
  "commander": "^13.1.0",