@asapjs/router 1.0.0-alpha.4 → 1.0.0-alpha.40

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 (64) hide show
  1. package/dist/decorator/AutoInject.d.ts +25 -0
  2. package/dist/decorator/AutoInject.d.ts.map +1 -0
  3. package/dist/decorator/AutoInject.js +34 -0
  4. package/dist/decorator/AutoInject.js.map +1 -0
  5. package/dist/decorator/ErrorPayload.d.ts +5 -0
  6. package/dist/decorator/ErrorPayload.d.ts.map +1 -0
  7. package/dist/decorator/ErrorPayload.js +17 -0
  8. package/dist/decorator/ErrorPayload.js.map +1 -0
  9. package/dist/decorator/ResponsePayload.d.ts +20 -0
  10. package/dist/decorator/ResponsePayload.d.ts.map +1 -0
  11. package/dist/decorator/ResponsePayload.js +32 -0
  12. package/dist/decorator/ResponsePayload.js.map +1 -0
  13. package/dist/decorator/index.d.ts +8 -2
  14. package/dist/decorator/index.d.ts.map +1 -1
  15. package/dist/decorator/index.js +11 -3
  16. package/dist/decorator/index.js.map +1 -1
  17. package/dist/express/router.d.ts +13 -3
  18. package/dist/express/router.d.ts.map +1 -1
  19. package/dist/express/router.js +252 -101
  20. package/dist/express/router.js.map +1 -1
  21. package/dist/index.d.ts +11 -6
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +20 -12
  24. package/dist/index.js.map +1 -1
  25. package/dist/middleware/errorHandler.d.ts +2 -2
  26. package/dist/middleware/errorHandler.d.ts.map +1 -1
  27. package/dist/middleware/errorHandler.js +11 -3
  28. package/dist/middleware/errorHandler.js.map +1 -1
  29. package/dist/plugin.d.ts +1 -1
  30. package/dist/plugin.d.ts.map +1 -1
  31. package/dist/plugin.js +23 -11
  32. package/dist/plugin.js.map +1 -1
  33. package/dist/router/index.d.ts.map +1 -1
  34. package/dist/router/index.js +23 -8
  35. package/dist/router/index.js.map +1 -1
  36. package/dist/swagger/index.d.ts +15 -1
  37. package/dist/swagger/index.d.ts.map +1 -1
  38. package/dist/swagger/index.js +147 -22
  39. package/dist/swagger/index.js.map +1 -1
  40. package/dist/utils/collectMiddlewareErrors.d.ts +14 -0
  41. package/dist/utils/collectMiddlewareErrors.d.ts.map +1 -0
  42. package/dist/utils/collectMiddlewareErrors.js +31 -0
  43. package/dist/utils/collectMiddlewareErrors.js.map +1 -0
  44. package/dist/utils/defineConfig.d.ts +49 -0
  45. package/dist/utils/defineConfig.d.ts.map +1 -0
  46. package/dist/utils/defineConfig.js +28 -0
  47. package/dist/utils/defineConfig.js.map +1 -0
  48. package/dist/utils/defineMiddleware.d.ts +6 -0
  49. package/dist/utils/defineMiddleware.d.ts.map +1 -0
  50. package/dist/utils/defineMiddleware.js +43 -0
  51. package/dist/utils/defineMiddleware.js.map +1 -0
  52. package/dist/utils/registeredMiddlewares.d.ts +4 -0
  53. package/dist/utils/registeredMiddlewares.d.ts.map +1 -0
  54. package/dist/utils/registeredMiddlewares.js +12 -0
  55. package/dist/utils/registeredMiddlewares.js.map +1 -0
  56. package/dist/utils/wrapper.d.ts +15 -7
  57. package/dist/utils/wrapper.d.ts.map +1 -1
  58. package/dist/utils/wrapper.js +84 -17
  59. package/dist/utils/wrapper.js.map +1 -1
  60. package/package.json +15 -13
  61. package/dist/middleware/jwtVerification.d.ts +0 -11
  62. package/dist/middleware/jwtVerification.d.ts.map +0 -1
  63. package/dist/middleware/jwtVerification.js +0 -38
  64. package/dist/middleware/jwtVerification.js.map +0 -1
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectMiddlewareErrors = collectMiddlewareErrors;
4
+ exports.deduplicateErrors = deduplicateErrors;
5
+ /**
6
+ * 미들웨어 목록에서 현재 routeOptions 기준으로 포함할 에러들을 수집한다.
7
+ * - __errors가 배열이면 그대로 반환
8
+ * - __errors가 함수이면 routeOptions를 넘겨 호출한 결과를 반환
9
+ * - __errors가 없는 기존 미들웨어는 빈 배열 반환 (backward compatible)
10
+ */
11
+ function collectMiddlewareErrors(middlewares, routeOptions) {
12
+ return middlewares.flatMap((mw) => {
13
+ const errors = mw.__errors;
14
+ if (!errors)
15
+ return [];
16
+ return typeof errors === 'function' ? errors(routeOptions) : errors;
17
+ });
18
+ }
19
+ /**
20
+ * errorCode 기준으로 중복 에러를 제거한다.
21
+ */
22
+ function deduplicateErrors(errors) {
23
+ const seen = new Set();
24
+ return errors.filter((e) => {
25
+ if (seen.has(e._code))
26
+ return false;
27
+ seen.add(e._code);
28
+ return true;
29
+ });
30
+ }
31
+ //# sourceMappingURL=collectMiddlewareErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectMiddlewareErrors.js","sourceRoot":"","sources":["../../src/utils/collectMiddlewareErrors.ts"],"names":[],"mappings":";;AASA,0DAaC;AAKD,8CAOC;AA/BD;;;;;GAKG;AACH,SAAgB,uBAAuB,CACtC,WAAiD,EACjD,YAAiC;IAEjC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QACjC,MAAM,MAAM,GAAI,EAAU,CAAC,QAGf,CAAC;QAEb,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QACvB,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACrE,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAsB;IACvD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACpC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { AsapJSConfig, InferMiddlewareContext, ResponseConfig, TypedMiddleware } from '@asapjs/types';
2
+ import type { ExecuteArgs } from './wrapper';
3
+ /**
4
+ * Defines the application config while preserving the exact tuple type of middleware[],
5
+ * enabling TypeScript to infer the merged context type from all registered middleware.
6
+ *
7
+ * @example
8
+ * import { defineConfig, createJwtMiddleware } from '@asapjs/router';
9
+ *
10
+ * export const config = defineConfig({
11
+ * port: 3000,
12
+ * middleware: [createJwtMiddleware(true)],
13
+ * ...
14
+ * });
15
+ *
16
+ * // Derive your app-specific ExecuteArgs:
17
+ * export type AppExecuteArgs<P = {}, Q = {}, B = {}> =
18
+ * CreateExecuteArgs<typeof config, P, Q, B>;
19
+ */
20
+ export declare function defineConfig<M extends readonly TypedMiddleware<any>[]>(config: Omit<AsapJSConfig, 'middleware'> & {
21
+ middleware?: M;
22
+ }): AsapJSConfig & {
23
+ middleware: M;
24
+ };
25
+ export declare function defineRouterConfig<M extends readonly TypedMiddleware<any>[]>(config: {
26
+ middleware?: M;
27
+ response?: ResponseConfig;
28
+ }): {
29
+ middleware: M;
30
+ } & {
31
+ response?: ResponseConfig;
32
+ };
33
+ /**
34
+ * Derives a typed ExecuteArgs from your app config, automatically including
35
+ * context fields contributed by each registered global middleware.
36
+ *
37
+ * @example
38
+ * export type AppExecuteArgs<P = {}, Q = {}, B = {}> =
39
+ * CreateExecuteArgs<typeof config, P, Q, B>;
40
+ *
41
+ * // In controller:
42
+ * public getList = async ({ user }: AppExecuteArgs<{}, QueryDto, {}>) => {
43
+ * // user is JwtUserPayload — not any!
44
+ * };
45
+ */
46
+ export type CreateExecuteArgs<Config extends {
47
+ middleware?: readonly any[];
48
+ }, P = {}, Q = {}, B = {}> = ExecuteArgs<P, Q, B, InferMiddlewareContext<NonNullable<Config['middleware']>>>;
49
+ //# sourceMappingURL=defineConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig.d.ts","sourceRoot":"","sources":["../../src/utils/defineConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC3G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,eAAe,CAAC,GAAG,CAAC,EAAE,EACrE,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,CAAC,CAAA;CAAE,GAC3D,YAAY,GAAG;IAAE,UAAU,EAAE,CAAC,CAAA;CAAE,CAElC;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE;IACrF,UAAU,CAAC,EAAE,CAAC,CAAC;IACf,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC1B,GAAG;IAAE,UAAU,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,cAAc,CAAA;CAAE,CAEpD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,CAC5B,MAAM,SAAS;IAAE,UAAU,CAAC,EAAE,SAAS,GAAG,EAAE,CAAA;CAAE,EAC9C,CAAC,GAAG,EAAE,EACN,CAAC,GAAG,EAAE,EACN,CAAC,GAAG,EAAE,IACH,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,sBAAsB,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineConfig = defineConfig;
4
+ exports.defineRouterConfig = defineRouterConfig;
5
+ /**
6
+ * Defines the application config while preserving the exact tuple type of middleware[],
7
+ * enabling TypeScript to infer the merged context type from all registered middleware.
8
+ *
9
+ * @example
10
+ * import { defineConfig, createJwtMiddleware } from '@asapjs/router';
11
+ *
12
+ * export const config = defineConfig({
13
+ * port: 3000,
14
+ * middleware: [createJwtMiddleware(true)],
15
+ * ...
16
+ * });
17
+ *
18
+ * // Derive your app-specific ExecuteArgs:
19
+ * export type AppExecuteArgs<P = {}, Q = {}, B = {}> =
20
+ * CreateExecuteArgs<typeof config, P, Q, B>;
21
+ */
22
+ function defineConfig(config) {
23
+ return config;
24
+ }
25
+ function defineRouterConfig(config) {
26
+ return config;
27
+ }
28
+ //# sourceMappingURL=defineConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig.js","sourceRoot":"","sources":["../../src/utils/defineConfig.ts"],"names":[],"mappings":";;AAoBA,oCAIC;AAED,gDAKC;AA5BD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,YAAY,CAC3B,MAA6D;IAE7D,OAAO,MAA0C,CAAC;AACnD,CAAC;AAED,SAAgB,kBAAkB,CAA4C,MAG7E;IACA,OAAO,MAA2D,CAAC;AACpE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ErrorCreator } from '@asapjs/error';
2
+ import type { TypedMiddleware } from '@asapjs/types';
3
+ export declare function defineMiddleware<RouteOptions extends Record<string, any> = {}, Context extends Record<string, any> = {}>(factory: (options: RouteOptions) => (req: any, res: any, next: any) => void, meta?: {
4
+ errors?: ErrorCreator[] | ((options: RouteOptions) => ErrorCreator[]);
5
+ }): TypedMiddleware<RouteOptions, Context>;
6
+ //# sourceMappingURL=defineMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineMiddleware.d.ts","sourceRoot":"","sources":["../../src/utils/defineMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAerD,wBAAgB,gBAAgB,CAC/B,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAC7C,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAExC,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,EAC3E,IAAI,CAAC,EAAE;IACN,MAAM,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,YAAY,EAAE,CAAC,CAAC;CACtE,GACC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAuBxC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineMiddleware = defineMiddleware;
4
+ const error_1 = require("@asapjs/error");
5
+ function respondWithError(err, res) {
6
+ if (err instanceof error_1.HttpError) {
7
+ res.status(err.status).json(err.toJSON());
8
+ }
9
+ else if (err && typeof err === 'object' && 'status' in err && 'message' in err) {
10
+ const { status, message } = err;
11
+ res.status(status).json(new error_1.HttpError(status, 'HTTP_EXCEPTION', String(message)).toJSON());
12
+ }
13
+ else {
14
+ const message = err instanceof Error ? err.message : '알 수 없는 서버 오류가 발생했습니다.';
15
+ res.status(500).json(new error_1.HttpError(500, 'INTERNAL_SERVER_ERROR', message).toJSON());
16
+ }
17
+ }
18
+ function defineMiddleware(factory, meta) {
19
+ var _a;
20
+ const wrappedFactory = (options) => {
21
+ const handler = factory(options);
22
+ return (req, res, next) => {
23
+ try {
24
+ const result = handler(req, res, next);
25
+ if (result instanceof Promise) {
26
+ result.catch((err) => respondWithError(err, res));
27
+ }
28
+ }
29
+ catch (err) {
30
+ respondWithError(err, res);
31
+ }
32
+ };
33
+ };
34
+ const middleware = wrappedFactory;
35
+ Object.defineProperty(middleware, '__errors', {
36
+ value: (_a = meta === null || meta === void 0 ? void 0 : meta.errors) !== null && _a !== void 0 ? _a : [],
37
+ writable: false,
38
+ enumerable: false,
39
+ configurable: false,
40
+ });
41
+ return middleware;
42
+ }
43
+ //# sourceMappingURL=defineMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineMiddleware.js","sourceRoot":"","sources":["../../src/utils/defineMiddleware.ts"],"names":[],"mappings":";;AAiBA,4CA+BC;AA/CD,yCAA0C;AAI1C,SAAS,gBAAgB,CAAC,GAAY,EAAE,GAAa;IACpD,IAAI,GAAG,YAAY,iBAAS,EAAE,CAAC;QAC9B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,QAAQ,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,EAAE,CAAC;QAClF,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAA0C,CAAC;QACvE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,iBAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5F,CAAC;SAAM,CAAC;QACP,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC;QAC7E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,iBAAS,CAAC,GAAG,EAAE,uBAAuB,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACrF,CAAC;AACF,CAAC;AAED,SAAgB,gBAAgB,CAI/B,OAA2E,EAC3E,IAEC;;IAED,MAAM,cAAc,GAAG,CAAC,OAAqB,EAA6C,EAAE;QAC3F,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,CAAC,GAAQ,EAAE,GAAa,EAAE,IAAS,EAAE,EAAE;YAC7C,IAAI,CAAC;gBACJ,MAAM,MAAM,GAAY,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;gBAChD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;oBAC/B,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;gBACnD,CAAC;YACF,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC5B,CAAC;QACF,CAAC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,cAAwD,CAAC;IAC5E,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,EAAE;QAC7C,KAAK,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,EAAE;QACzB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACnB,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { TypedMiddleware } from '@asapjs/types';
2
+ export declare function setRegisteredMiddlewares(mws: readonly TypedMiddleware<any, any>[]): void;
3
+ export declare function getRegisteredMiddlewares(): readonly TypedMiddleware<any, any>[];
4
+ //# sourceMappingURL=registeredMiddlewares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registeredMiddlewares.d.ts","sourceRoot":"","sources":["../../src/utils/registeredMiddlewares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAExF;AAED,wBAAgB,wBAAwB,IAAI,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAE/E"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setRegisteredMiddlewares = setRegisteredMiddlewares;
4
+ exports.getRegisteredMiddlewares = getRegisteredMiddlewares;
5
+ let middlewares = [];
6
+ function setRegisteredMiddlewares(mws) {
7
+ middlewares = mws;
8
+ }
9
+ function getRegisteredMiddlewares() {
10
+ return middlewares;
11
+ }
12
+ //# sourceMappingURL=registeredMiddlewares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registeredMiddlewares.js","sourceRoot":"","sources":["../../src/utils/registeredMiddlewares.ts"],"names":[],"mappings":";;AAIA,4DAEC;AAED,4DAEC;AARD,IAAI,WAAW,GAAyC,EAAE,CAAC;AAE3D,SAAgB,wBAAwB,CAAC,GAAyC;IACjF,WAAW,GAAG,GAAG,CAAC;AACnB,CAAC;AAED,SAAgB,wBAAwB;IACvC,OAAO,WAAW,CAAC;AACpB,CAAC"}
@@ -1,7 +1,16 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- import { PaginationQueryDto } from '@asapjs/types';
1
+ import type { PaginationQueryType } from '@asapjs/sequelize';
2
+ import type { NextFunction, Request, Response } from 'express';
3
3
  type Callback = (request: Request<any, any, any, any>, response: Response, next: NextFunction) => Promise<unknown>;
4
- export interface ExecuteArgs<P = {}, Q = {}, B = {}> {
4
+ declare global {
5
+ namespace Express {
6
+ interface Request {
7
+ user: any;
8
+ }
9
+ }
10
+ }
11
+ export interface GlobalMiddlewareContext {
12
+ }
13
+ export type ExecuteArgs<P = {}, Q = {}, B = {}, Context = GlobalMiddlewareContext> = {
5
14
  req: Request;
6
15
  res: Response;
7
16
  path?: P | {
@@ -16,9 +25,8 @@ export interface ExecuteArgs<P = {}, Q = {}, B = {}> {
16
25
  files?: {
17
26
  [key: string]: any;
18
27
  };
19
- user?: any;
20
- paging: PaginationQueryDto;
21
- }
22
- export default function Wrapper(cb: (args: ExecuteArgs) => Promise<unknown>): Callback;
28
+ paging: PaginationQueryType;
29
+ } & Context;
30
+ export default function Wrapper(cb: (args: ExecuteArgs) => Promise<unknown>, responseDtoClass?: (new () => any) | null): Callback;
23
31
  export {};
24
32
  //# sourceMappingURL=wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,KAAK,QAAQ,GAAG,CACf,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACpC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,YAAY,KACd,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE;IAClD,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAClC,KAAK,EAAE,CAAC,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAClC,IAAI,EAAE,CAAC,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IACjC,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,EAA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AG,GAAG,CAAA;KAAE,CAAC;IAC/B,MAAM,EAAE,mBAAmB,CAAC;CAC5B,GAAG,OAAO,CAAC;AAEZ,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,EAAE,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,QAAQ,CAwDhI"}
@@ -43,14 +43,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.default = Wrapper;
46
- const Sentry = __importStar(require("@sentry/node"));
47
46
  const common_1 = require("@asapjs/common");
48
47
  const error_1 = require("@asapjs/error");
49
- function Wrapper(cb) {
50
- return function _Wrapper(req, res, next) {
48
+ const Sentry = __importStar(require("@sentry/node"));
49
+ const AutoInject_1 = require("../decorator/AutoInject");
50
+ const ErrorPayload_1 = require("../decorator/ErrorPayload");
51
+ const ResponsePayload_1 = require("../decorator/ResponsePayload");
52
+ function Wrapper(cb, responseDtoClass) {
53
+ return function _Wrapper(req, res, _next) {
51
54
  return __awaiter(this, void 0, void 0, function* () {
52
55
  try {
53
- const user = req.user;
54
56
  const { page: pageProp = 0, limit: limitProp = 20 } = req.query;
55
57
  const page = parseInt(String(pageProp), 10);
56
58
  const limit = parseInt(String(limitProp), 10);
@@ -58,18 +60,18 @@ function Wrapper(cb) {
58
60
  page,
59
61
  limit,
60
62
  };
61
- const args = {
62
- req,
63
- res,
64
- query: req.query,
65
- path: req.params,
66
- body: req.body,
67
- user,
68
- paging,
69
- };
63
+ const base = { req, res, query: req.query, path: req.params, body: req.body, paging };
64
+ const args = new Proxy(base, {
65
+ get(target, prop) {
66
+ if (prop in target)
67
+ return target[prop];
68
+ return req[prop];
69
+ },
70
+ });
70
71
  const output = yield cb(args);
71
- if (output) {
72
- res.status(200).json(output);
72
+ if (output !== undefined) {
73
+ const finalResponse = applyGlobalResponse(output, req, responseDtoClass);
74
+ res.status(200).json(finalResponse);
73
75
  }
74
76
  }
75
77
  catch (err) {
@@ -79,13 +81,78 @@ function Wrapper(cb) {
79
81
  err.status === undefined;
80
82
  if (isServerError) {
81
83
  common_1.logger.error('[SERVER ERROR]', err);
82
- if ((0, common_1.getConfig)().sentry !== undefined) {
84
+ if ((0, common_1.hasConfig)() && (0, common_1.getConfig)().sentry !== undefined) {
83
85
  Sentry.captureException(err);
84
86
  }
85
87
  }
86
- (0, error_1.errorToResponse)(err, res);
88
+ let errorBody;
89
+ let statusCode;
90
+ if (err instanceof error_1.HttpError) {
91
+ errorBody = err.toJSON();
92
+ statusCode = err.status;
93
+ }
94
+ else if (err && typeof err === 'object' && 'status' in err && 'message' in err) {
95
+ const { status, message } = err;
96
+ errorBody = new error_1.HttpError(status, 'HTTP_EXCEPTION', String(message)).toJSON();
97
+ statusCode = status;
98
+ }
99
+ else {
100
+ const message = err instanceof Error ? err.message : '알 수 없는 서버 오류가 발생했습니다.';
101
+ errorBody = new error_1.HttpError(500, 'INTERNAL_SERVER_ERROR', message).toJSON();
102
+ statusCode = 500;
103
+ }
104
+ const finalErrorResponse = applyGlobalErrorResponse(errorBody, req, responseDtoClass);
105
+ res.status(statusCode).json(finalErrorResponse);
87
106
  }
88
107
  });
89
108
  };
90
109
  }
110
+ function applyGlobalResponse(output, req, responseDtoClass) {
111
+ const DtoClass = resolveResponseDtoClass(responseDtoClass);
112
+ if (!DtoClass)
113
+ return output;
114
+ const autoInjectEntries = (0, AutoInject_1.getAutoInjectEntries)(DtoClass);
115
+ const payloadKey = (0, ResponsePayload_1.getResponsePayloadKey)(DtoClass);
116
+ const injected = {};
117
+ for (const { key, factory } of autoInjectEntries) {
118
+ injected[key] = factory(req);
119
+ }
120
+ if (payloadKey) {
121
+ return Object.assign(Object.assign({}, injected), { [payloadKey]: output });
122
+ }
123
+ if (typeof output === 'object' && output !== null) {
124
+ return Object.assign(Object.assign({}, injected), output);
125
+ }
126
+ return Object.assign(Object.assign({}, injected), { result: output });
127
+ }
128
+ function resolveResponseDtoClass(controllerDto) {
129
+ var _a, _b;
130
+ if (controllerDto === null)
131
+ return null;
132
+ if (controllerDto)
133
+ return controllerDto;
134
+ if ((0, common_1.hasConfig)()) {
135
+ const config = (0, common_1.getConfig)();
136
+ return ((_b = (_a = config.router) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.responseDto) || null;
137
+ }
138
+ return null;
139
+ }
140
+ function applyGlobalErrorResponse(errorBody, req, responseDtoClass) {
141
+ const DtoClass = resolveResponseDtoClass(responseDtoClass);
142
+ if (!DtoClass)
143
+ return errorBody;
144
+ const errorPayloadKey = (0, ErrorPayload_1.getErrorPayloadKey)(DtoClass);
145
+ if (!errorPayloadKey)
146
+ return errorBody;
147
+ const autoInjectEntries = (0, AutoInject_1.getAutoInjectEntries)(DtoClass);
148
+ const injected = {};
149
+ for (const { key, factory } of autoInjectEntries) {
150
+ injected[key] = factory(req);
151
+ }
152
+ const successKey = Object.keys(injected).find((k) => typeof injected[k] === 'boolean');
153
+ if (successKey) {
154
+ injected[successKey] = false;
155
+ }
156
+ return Object.assign(Object.assign({}, injected), { [errorPayloadKey]: errorBody });
157
+ }
91
158
  //# sourceMappingURL=wrapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../src/utils/wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,0BAwCC;AA/DD,qDAAuC;AAEvC,2CAAmD;AACnD,yCAAgD;AAoBhD,SAAwB,OAAO,CAAC,EAA2C;IAC1E,OAAO,SAAe,QAAQ,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;;YAC7E,IAAI,CAAC;gBACJ,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;gBACtB,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,CAAC,EAA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,eAAe,CAAC,EAAE,SAAS,IAAG;AACtD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asapjs/router",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.40",
4
4
  "description": "Router and API layer for AsapJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,28 +9,30 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "prebuild": "rm -rf dist",
12
- "build": "tsc"
12
+ "build": "tsc",
13
+ "test": "npx jest --config jest.config.js --testPathPatterns='(global-response-dto|runtime-consistency|error-payload)'"
13
14
  },
14
15
  "author": "",
15
16
  "license": "ISC",
17
+ "homepage": "https://www.asapjs.com",
16
18
  "publishConfig": {
17
19
  "access": "public"
18
20
  },
19
21
  "dependencies": {
20
- "@asapjs/common": "1.0.0-alpha.3",
21
- "@asapjs/error": "1.0.0-alpha.3",
22
- "@asapjs/sequelize": "1.0.0-alpha.3",
23
- "@asapjs/types": "1.0.0-alpha.3",
22
+ "@asapjs/common": "^1.0.0-alpha.38",
23
+ "@asapjs/error": "^1.0.0-alpha.38",
24
+ "@asapjs/sequelize": "^1.0.0-alpha.40",
25
+ "@asapjs/types": "^1.0.0-alpha.38",
24
26
  "@sentry/node": "^6.19.7",
25
- "body-parser": "^1.19.2",
27
+ "body-parser": "^1.20.3",
26
28
  "cors": "^2.8.5",
27
- "express": "^4.17.3",
29
+ "express": "^4.20.0",
28
30
  "express-basic-auth": "^1.2.1",
29
31
  "fs": "^0.0.1-security",
30
32
  "jsonwebtoken": "^9.0.3",
31
- "sequelize": "^6.17.0",
32
- "sequelize-typescript": "^2.1.3",
33
- "swagger-ui-express": "^4.3.0",
33
+ "sequelize": "^6.29.0",
34
+ "sequelize-typescript": "^2.1.6",
35
+ "swagger-ui-express": "^5.0.1",
34
36
  "winston": "^3.6.0"
35
37
  },
36
38
  "devDependencies": {
@@ -39,8 +41,8 @@
39
41
  "@types/express": "^4.17.13",
40
42
  "@types/jsonwebtoken": "^9.0.2",
41
43
  "@types/node": "^17.0.21",
42
- "@types/swagger-ui-express": "^4.1.3",
44
+ "@types/swagger-ui-express": "^4.1.8",
43
45
  "typescript": "^5.8.3"
44
46
  },
45
- "gitHead": "de328f7e25a2a58467b0ce6f288a7ee7b555c251"
47
+ "gitHead": "aa1a9e4ec37eb5ee925d7dbf53ad7c65112f7b39"
46
48
  }
@@ -1,11 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- declare global {
3
- namespace Express {
4
- interface Request {
5
- user: any;
6
- }
7
- }
8
- }
9
- declare const jwtVerification: (auth?: boolean) => (req: Request, res: Response, next: NextFunction) => void;
10
- export default jwtVerification;
11
- //# sourceMappingURL=jwtVerification.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwtVerification.d.ts","sourceRoot":"","sources":["../../src/middleware/jwtVerification.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,EAAE,GAAG,CAAC;SACX;KACF;CACF;AAED,QAAA,MAAM,eAAe,GAClB,OAAM,OAAe,MACrB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SA2B/C,CAAC;AAEJ,eAAe,eAAe,CAAC"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const common_1 = require("@asapjs/common");
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- const errorHandler_1 = require("./errorHandler");
9
- const jwtVerification = (auth = false) => (req, res, next) => {
10
- const { authorization } = req.headers;
11
- if (!authorization) {
12
- if (auth === true) {
13
- throw new errorHandler_1.HttpException(403, 'NO Token Provided');
14
- }
15
- next();
16
- }
17
- else {
18
- const token = authorization.split(' ')[1];
19
- jsonwebtoken_1.default.verify(token, (0, common_1.getConfig)().auth.jwt_access_token_secret, (err, decoded) => {
20
- if (err && auth === true) {
21
- if (err.message === 'invalid signature') {
22
- return res.status(403).json({
23
- error: true,
24
- message: 'invaild signature. please use vaild endpoint',
25
- });
26
- }
27
- return res.status(401).json({
28
- error: true,
29
- message: 'Unauthorized access. Please Refresh Token',
30
- });
31
- }
32
- req.user = decoded;
33
- next();
34
- });
35
- }
36
- };
37
- exports.default = jwtVerification;
38
- //# sourceMappingURL=jwtVerification.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwtVerification.js","sourceRoot":"","sources":["../../src/middleware/jwtVerification.ts"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAG3C,gEAA+B;AAE/B,iDAA+C;AAU/C,MAAM,eAAe,GACnB,CAAC,OAAgB,KAAK,EAAE,EAAE,CAC1B,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAClD,MAAM,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;IACtC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,4BAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAG,IAAA,kBAAS,GAAU,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,GAAQ,EAAE,OAAY,EAAE,EAAE;YAC9F,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBACzB,IAAI,GAAG,CAAC,OAAO,KAAK,mBAA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