ctx-router 1.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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -0
  3. package/dist/ctx/ctx.err.d.ts +28 -0
  4. package/dist/ctx/ctx.err.d.ts.map +1 -0
  5. package/dist/ctx/ctx.err.js +43 -0
  6. package/dist/ctx/ctx.err.js.map +1 -0
  7. package/dist/ctx/ctx.router.d.ts +9 -0
  8. package/dist/ctx/ctx.router.d.ts.map +1 -0
  9. package/dist/ctx/ctx.router.js +45 -0
  10. package/dist/ctx/ctx.router.js.map +1 -0
  11. package/dist/ctx/ctx.types.d.ts +96 -0
  12. package/dist/ctx/ctx.types.d.ts.map +1 -0
  13. package/dist/ctx/ctx.types.js +10 -0
  14. package/dist/ctx/ctx.types.js.map +1 -0
  15. package/dist/ctx.types.d.ts +96 -0
  16. package/dist/ctx.types.d.ts.map +1 -0
  17. package/dist/ctx.types.js +10 -0
  18. package/dist/ctx.types.js.map +1 -0
  19. package/dist/ctxErr.d.ts +28 -0
  20. package/dist/ctxErr.d.ts.map +1 -0
  21. package/dist/ctxErr.js +43 -0
  22. package/dist/ctxErr.js.map +1 -0
  23. package/dist/example/api/health/healthPing.api.d.ts +14 -0
  24. package/dist/example/api/health/healthPing.api.d.ts.map +1 -0
  25. package/dist/example/api/health/healthPing.api.js +30 -0
  26. package/dist/example/api/health/healthPing.api.js.map +1 -0
  27. package/dist/example/api/health/index.d.ts +3 -0
  28. package/dist/example/api/health/index.d.ts.map +1 -0
  29. package/dist/example/api/health/index.js +43 -0
  30. package/dist/example/api/health/index.js.map +1 -0
  31. package/dist/example/api/index.d.ts +3 -0
  32. package/dist/example/api/index.d.ts.map +1 -0
  33. package/dist/example/api/index.js +39 -0
  34. package/dist/example/api/index.js.map +1 -0
  35. package/dist/example/api/user/index.d.ts +4 -0
  36. package/dist/example/api/user/index.d.ts.map +1 -0
  37. package/dist/example/api/user/index.js +50 -0
  38. package/dist/example/api/user/index.js.map +1 -0
  39. package/dist/example/api/user/userDetail.api.d.ts +15 -0
  40. package/dist/example/api/user/userDetail.api.d.ts.map +1 -0
  41. package/dist/example/api/user/userDetail.api.js +29 -0
  42. package/dist/example/api/user/userDetail.api.js.map +1 -0
  43. package/dist/example/api/user/userUpdate.api.d.ts +14 -0
  44. package/dist/example/api/user/userUpdate.api.d.ts.map +1 -0
  45. package/dist/example/api/user/userUpdate.api.js +27 -0
  46. package/dist/example/api/user/userUpdate.api.js.map +1 -0
  47. package/dist/example/express.d.ts +2 -0
  48. package/dist/example/express.d.ts.map +1 -0
  49. package/dist/example/express.js +25 -0
  50. package/dist/example/express.js.map +1 -0
  51. package/dist/example/router.d.ts +4 -0
  52. package/dist/example/router.d.ts.map +1 -0
  53. package/dist/example/router.js +51 -0
  54. package/dist/example/router.js.map +1 -0
  55. package/dist/index.d.ts +9 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +13 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/producer/express.d.ts +4 -0
  60. package/dist/producer/express.d.ts.map +1 -0
  61. package/dist/producer/express.js +22 -0
  62. package/dist/producer/express.js.map +1 -0
  63. package/dist/router.d.ts +9 -0
  64. package/dist/router.d.ts.map +1 -0
  65. package/dist/router.js +45 -0
  66. package/dist/router.js.map +1 -0
  67. package/dist/transform.d.ts +91 -0
  68. package/dist/transform.d.ts.map +1 -0
  69. package/dist/transform.js +121 -0
  70. package/dist/transform.js.map +1 -0
  71. package/dist/transformer/express.d.ts +4 -0
  72. package/dist/transformer/express.d.ts.map +1 -0
  73. package/dist/transformer/express.js +22 -0
  74. package/dist/transformer/express.js.map +1 -0
  75. package/dist/transformer/index.d.ts +91 -0
  76. package/dist/transformer/index.d.ts.map +1 -0
  77. package/dist/transformer/index.js +121 -0
  78. package/dist/transformer/index.js.map +1 -0
  79. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hyugorix
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 ADDED
@@ -0,0 +1,130 @@
1
+ # Context Router
2
+
3
+ A TypeScript router library for handling context-based routing with type safety.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install ctx-router
9
+ ```
10
+
11
+ Or using pnpm:
12
+
13
+ ```bash
14
+ pnpm add ctx-router
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Basic Usage
20
+
21
+ ```typescript
22
+ import { CtxRouter, TCtx, USER_ROLE } from "ctx-router";
23
+
24
+ // Create a router instance
25
+ const router = new CtxRouter<TCtx>();
26
+
27
+ // Define a handler
28
+ async function myHandler(ctx: TCtx): Promise<TCtx> {
29
+ // Your logic here
30
+ ctx.res.data = { message: "Hello World" };
31
+ return ctx;
32
+ }
33
+
34
+ // Register routes
35
+ router.handle("GET", "/hello", myHandler);
36
+ router.handle("POST", "/api/data", myHandler);
37
+
38
+ // Handle errors
39
+ router.onError(async (ctx, error) => {
40
+ console.error("Route error:", error);
41
+ ctx.res.code = "ERROR";
42
+ ctx.res.msg = "Something went wrong";
43
+ return ctx;
44
+ });
45
+
46
+ // Execute routes
47
+ const result = await router.exec("GET", "/hello", context);
48
+ ```
49
+
50
+ ### Express.js Integration
51
+
52
+ Here's how to use it with Express.js by splitting router configuration and server setup:
53
+
54
+ #### `router.ts` - Router Configuration
55
+
56
+ ```typescript
57
+ import { CtxRouter, TCtx } from "ctx-router";
58
+ import * as api from "./api/index";
59
+
60
+ // Set your router
61
+ const router = new CtxRouter<TCtx>();
62
+
63
+ router.handle("GET", "/health/ping", api.health.ping);
64
+ router.handle("POST", "/user/update", api.user.update);
65
+ router.handle("GET", "/user/detail", api.user.detail);
66
+
67
+ router.onError(async (ctx, error) => {
68
+ console.error("Route error:", error);
69
+ ctx.res.code = "ERROR";
70
+ ctx.res.msg = "Something went wrong";
71
+ return ctx;
72
+ });
73
+
74
+ export { router };
75
+ ```
76
+
77
+ #### `express.ts` - Express Server Setup
78
+
79
+ ```typescript
80
+ import express, { Request, Response } from "express";
81
+ import { toCtx, TCtx } from "ctx-router";
82
+ import { router } from "./router";
83
+
84
+ const app = express();
85
+
86
+ function getHttpCode(ctx: TCtx) {
87
+ if (ctx.res.code === "OK") return 200;
88
+ if (ctx.res.code === "UNKNOWN_ERROR") return 500;
89
+ return 400;
90
+ }
91
+
92
+ app.all("/{*any}", async (req: Request, res: Response) => {
93
+ const ctx: TCtx = toCtx.fromExpress(req);
94
+ await router.exec(ctx.req.method, ctx.req.path, ctx);
95
+ res.type("application/json").status(getHttpCode(ctx)).send(ctx.res);
96
+ });
97
+
98
+ app.listen(3000, () => {
99
+ console.log(`Express server listening on port 3000`);
100
+ });
101
+ ```
102
+
103
+ ## Exports
104
+
105
+ ### Classes
106
+
107
+ - `CtxRouter<TContext>` - Main router class for handling context-based routing
108
+
109
+ ### Types
110
+
111
+ - `TCtx` - Main context type with request, response, user, and metadata
112
+ - `IBaseApi` - Interface for base API implementation
113
+
114
+ ### Constants
115
+
116
+ - `USER_ROLE` - User role constants (user, admin, server, none)
117
+
118
+ ## API Reference
119
+
120
+ ### CtxRouter
121
+
122
+ #### Methods
123
+
124
+ - `handle(method: string, path: string, handler: (ctx: TContext) => Promise<TContext>)` - Register a route handler
125
+ - `exec(method: string, path: string, ctx: TContext): Promise<TContext>` - Execute a route
126
+ - `onError(handler: (ctx: TContext, error: Error | unknown) => Promise<TContext>)` - Set error handler
127
+
128
+ ## License
129
+
130
+ MIT
@@ -0,0 +1,28 @@
1
+ type TCtxErrorData = {
2
+ [key: string]: number | string | object | boolean | null;
3
+ };
4
+ type TCtxError = {
5
+ name: string;
6
+ msg: string;
7
+ data?: TCtxErrorData;
8
+ info?: unknown;
9
+ };
10
+ export declare class CtxError extends Error {
11
+ data: {
12
+ [key: string]: number | string | object | boolean | null;
13
+ };
14
+ info?: unknown;
15
+ constructor({ name, msg, data, info }: TCtxError);
16
+ }
17
+ type TResErr = Partial<Pick<TCtxError, "data" | "info" | "msg">>;
18
+ export declare namespace ctxErr {
19
+ const general: {
20
+ unknown: (e?: TResErr) => CtxError;
21
+ responseNotSet: (e?: TResErr) => CtxError;
22
+ malformedRequestData: (e?: TResErr) => CtxError;
23
+ handlerNotFound: (e?: TResErr) => CtxError;
24
+ notAuthorized: (e?: TResErr) => CtxError;
25
+ };
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=ctx.err.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.err.d.ts","sourceRoot":"","sources":["../../src/ctx/ctx.err.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CAC1D,CAAC;AACF,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AACF,qBAAa,QAAS,SAAQ,KAAK;IACjC,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC;IACnE,IAAI,CAAC,EAAE,OAAO,CAAC;gBACH,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS;CAMjD;AAED,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;AAEjE,yBAAiB,MAAM,CAAC;IACf,MAAM,OAAO;sBACJ,OAAO;6BAMA,OAAO;mCAMD,OAAO;8BAMZ,OAAO;4BAMT,OAAO;KAM5B,CAAC;CACH"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ctxErr = exports.CtxError = void 0;
4
+ class CtxError extends Error {
5
+ constructor({ name, msg, data, info }) {
6
+ super(msg);
7
+ super.name = name;
8
+ this.data = data || {};
9
+ this.info = info;
10
+ }
11
+ }
12
+ exports.CtxError = CtxError;
13
+ var ctxErr;
14
+ (function (ctxErr) {
15
+ ctxErr.general = {
16
+ unknown: (e) => new CtxError({
17
+ name: "UNKNOWN_ERROR",
18
+ msg: "Something went wrong",
19
+ ...e,
20
+ }),
21
+ responseNotSet: (e) => new CtxError({
22
+ name: "RESPONSE_NOT_SET",
23
+ msg: "Response not set",
24
+ ...e,
25
+ }),
26
+ malformedRequestData: (e) => new CtxError({
27
+ name: "MALFORMED_REQUEST_DATA",
28
+ msg: "Malformed request data",
29
+ ...e,
30
+ }),
31
+ handlerNotFound: (e) => new CtxError({
32
+ name: "HANDLER_NOT_FOUND",
33
+ msg: "Handler not found",
34
+ ...e,
35
+ }),
36
+ notAuthorized: (e) => new CtxError({
37
+ name: "NOT_AUTHORIZED",
38
+ msg: "Not authorized",
39
+ ...e,
40
+ }),
41
+ };
42
+ })(ctxErr || (exports.ctxErr = ctxErr = {}));
43
+ //# sourceMappingURL=ctx.err.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.err.js","sourceRoot":"","sources":["../../src/ctx/ctx.err.ts"],"names":[],"mappings":";;;AASA,MAAa,QAAS,SAAQ,KAAK;IAGjC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAa;QAC9C,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AATD,4BASC;AAID,IAAiB,MAAM,CAiCtB;AAjCD,WAAiB,MAAM;IACR,cAAO,GAAG;QACrB,OAAO,EAAE,CAAC,CAAW,EAAE,EAAE,CACvB,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,eAAe;YACrB,GAAG,EAAE,sBAAsB;YAC3B,GAAG,CAAC;SACL,CAAC;QACJ,cAAc,EAAE,CAAC,CAAW,EAAE,EAAE,CAC9B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,kBAAkB;YACvB,GAAG,CAAC;SACL,CAAC;QACJ,oBAAoB,EAAE,CAAC,CAAW,EAAE,EAAE,CACpC,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,wBAAwB;YAC9B,GAAG,EAAE,wBAAwB;YAC7B,GAAG,CAAC;SACL,CAAC;QACJ,eAAe,EAAE,CAAC,CAAW,EAAE,EAAE,CAC/B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,mBAAmB;YACzB,GAAG,EAAE,mBAAmB;YACxB,GAAG,CAAC;SACL,CAAC;QACJ,aAAa,EAAE,CAAC,CAAW,EAAE,EAAE,CAC7B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,gBAAgB;YACtB,GAAG,EAAE,gBAAgB;YACrB,GAAG,CAAC;SACL,CAAC;KACL,CAAC;AACJ,CAAC,EAjCgB,MAAM,sBAAN,MAAM,QAiCtB"}
@@ -0,0 +1,9 @@
1
+ import { CtxError } from "./ctx.err";
2
+ export declare class CtxRouter<TContext> {
3
+ private routeObj;
4
+ private onErrorHandler;
5
+ exec(method: string, path: string, ctx: TContext): Promise<TContext>;
6
+ handle(method: string, path: string, handler: (ctx: TContext) => Promise<TContext>): void;
7
+ onError(handler: (ctx: TContext, error: CtxError | Error | unknown) => Promise<TContext>): void;
8
+ }
9
+ //# sourceMappingURL=ctx.router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.router.d.ts","sourceRoot":"","sources":["../../src/ctx/ctx.router.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,QAAQ,EAAE,MAAM,WAAW,CAAC;AAO7C,qBAAa,SAAS,CAAC,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,cAAc,CAMpB;IAEI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc1E,MAAM,CACJ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC;IAM/C,OAAO,CACL,OAAO,EAAE,CACP,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,KAC9B,OAAO,CAAC,QAAQ,CAAC;CAIzB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CtxRouter = void 0;
4
+ const ctx_err_1 = require("./ctx.err");
5
+ class CtxRouter {
6
+ constructor() {
7
+ this.routeObj = {};
8
+ this.onErrorHandler = async (ctx, error) => {
9
+ console.log("CtxError:onErrorHandler", error);
10
+ return ctx;
11
+ };
12
+ }
13
+ async exec(method, path, ctx) {
14
+ const handler = this.routeObj[method]?.[path];
15
+ if (!handler) {
16
+ throw ctx_err_1.ctxErr.general.handlerNotFound({
17
+ data: { method, path },
18
+ });
19
+ }
20
+ try {
21
+ return await handler(ctx);
22
+ }
23
+ catch (error) {
24
+ return await this.onErrorHandler(ctx, error);
25
+ }
26
+ }
27
+ handle(method, path, handler) {
28
+ const methodRoute = this.routeObj[method] || (this.routeObj[method] = {});
29
+ methodRoute[path] = handler;
30
+ }
31
+ onError(handler) {
32
+ this.onErrorHandler = handler;
33
+ }
34
+ }
35
+ exports.CtxRouter = CtxRouter;
36
+ const ctxRouter = new CtxRouter();
37
+ async function handler(ctx) {
38
+ console.log(ctx);
39
+ return ctx;
40
+ }
41
+ ctxRouter.handle("GET", "/", handler);
42
+ ctxRouter.handle("GET", "/instance/ping", handler);
43
+ ctxRouter.handle("GET", "/instance/health", handler);
44
+ ctxRouter.handle("POST", "/route/test", handler);
45
+ //# sourceMappingURL=ctx.router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.router.js","sourceRoot":"","sources":["../../src/ctx/ctx.router.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAO7C,MAAa,SAAS;IAAtB;QACU,aAAQ,GAAwB,EAAE,CAAC;QACnC,mBAAc,GAGG,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YAC5C,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;IAiCJ,CAAC;IA/BC,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,IAAY,EAAE,GAAa;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CA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declare const USER_ROLE: {
2
+ readonly user: "user";
3
+ readonly admin: "admin";
4
+ readonly server: "server";
5
+ readonly none: "none";
6
+ };
7
+ type CtxReq = {
8
+ header: {
9
+ authorization?: string;
10
+ "x-ctx-device-name"?: string;
11
+ "x-ctx-device-id"?: string;
12
+ "x-ctx-os"?: string;
13
+ "x-ctx-app-version"?: string;
14
+ "x-ctx-api-version"?: string;
15
+ "x-ctx-session-id"?: string;
16
+ "x-ctx-seq"?: string;
17
+ "x-ctx-refresh-token"?: string;
18
+ [key: string]: string | string[] | undefined;
19
+ };
20
+ method: string;
21
+ path: string;
22
+ data: {
23
+ userId?: string;
24
+ [key: string]: unknown;
25
+ };
26
+ ip: string;
27
+ ips: string[];
28
+ };
29
+ type CtxRes = {
30
+ code: string;
31
+ msg: string;
32
+ data: {
33
+ [key: string]: unknown;
34
+ };
35
+ meta?: {
36
+ ctxId: string;
37
+ seq: number;
38
+ traceId: string;
39
+ spanId: string;
40
+ inTime: Date;
41
+ outTime: Date;
42
+ execTime: number;
43
+ owd: number;
44
+ };
45
+ };
46
+ type CtxMeta = {
47
+ serviceName: string;
48
+ instance: {
49
+ id: string;
50
+ createdAt: Date;
51
+ seq: number;
52
+ inflight: number;
53
+ };
54
+ ts: {
55
+ in: Date;
56
+ clientIn: Date;
57
+ owd: number;
58
+ out?: Date;
59
+ execTime?: number;
60
+ };
61
+ monitor: {
62
+ traceId: string;
63
+ spanId: string;
64
+ stdout: string[];
65
+ dbLog: string[];
66
+ };
67
+ };
68
+ type CtxUser = {
69
+ id: string;
70
+ role: keyof typeof USER_ROLE;
71
+ deviceName: string;
72
+ deviceId: string;
73
+ os: string;
74
+ appVersion: string;
75
+ sessionId: string;
76
+ seq: number;
77
+ apiVersion: string;
78
+ auth: {
79
+ token: string;
80
+ refresh: string;
81
+ };
82
+ };
83
+ export type TCtx = {
84
+ id: string;
85
+ meta: CtxMeta;
86
+ req: CtxReq;
87
+ res: CtxRes;
88
+ user: CtxUser;
89
+ };
90
+ export interface IBaseApi {
91
+ auth(ctx: TCtx): Promise<TCtx>;
92
+ validate(ctx: TCtx): Promise<TCtx>;
93
+ handle(ctx: TCtx): Promise<TCtx>;
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=ctx.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.types.d.ts","sourceRoot":"","sources":["../../src/ctx/ctx.types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;CAKZ,CAAC;AAEX,KAAK,MAAM,GAAG;IACZ,MAAM,EAAE;QACN,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;KAC9C,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACjC,IAAI,CAAC,EAAE;QACL,KAAK,EAAE,MAAM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AAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_ROLE = void 0;
4
+ exports.USER_ROLE = {
5
+ user: "user",
6
+ admin: "admin",
7
+ server: "server",
8
+ none: "none",
9
+ };
10
+ //# sourceMappingURL=ctx.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.types.js","sourceRoot":"","sources":["../../src/ctx/ctx.types.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC"}
@@ -0,0 +1,96 @@
1
+ export declare const USER_ROLE: {
2
+ readonly user: "user";
3
+ readonly admin: "admin";
4
+ readonly server: "server";
5
+ readonly none: "none";
6
+ };
7
+ type CtxReq = {
8
+ header: {
9
+ authorization?: string;
10
+ "x-ctx-device-name"?: string;
11
+ "x-ctx-device-id"?: string;
12
+ "x-ctx-os"?: string;
13
+ "x-ctx-app-version"?: string;
14
+ "x-ctx-api-version"?: string;
15
+ "x-ctx-session-id"?: string;
16
+ "x-ctx-seq"?: string;
17
+ "x-ctx-refresh-token"?: string;
18
+ [key: string]: string | string[] | undefined;
19
+ };
20
+ method: string;
21
+ path: string;
22
+ data: {
23
+ userId?: string;
24
+ [key: string]: unknown;
25
+ };
26
+ ip: string;
27
+ ips: string[];
28
+ };
29
+ type CtxRes = {
30
+ code: string;
31
+ msg: string;
32
+ data: {
33
+ [key: string]: unknown;
34
+ };
35
+ meta?: {
36
+ ctxId: string;
37
+ seq: number;
38
+ traceId: string;
39
+ spanId: string;
40
+ inTime: Date;
41
+ outTime: Date;
42
+ execTime: number;
43
+ owd: number;
44
+ };
45
+ };
46
+ type CtxMeta = {
47
+ serviceName: string;
48
+ instance: {
49
+ id: string;
50
+ createdAt: Date;
51
+ seq: number;
52
+ inflight: number;
53
+ };
54
+ ts: {
55
+ in: Date;
56
+ clientIn: Date;
57
+ owd: number;
58
+ out?: Date;
59
+ execTime?: number;
60
+ };
61
+ monitor: {
62
+ traceId: string;
63
+ spanId: string;
64
+ stdout: string[];
65
+ dbLog: string[];
66
+ };
67
+ };
68
+ type CtxUser = {
69
+ id: string;
70
+ role: keyof typeof USER_ROLE;
71
+ deviceName: string;
72
+ deviceId: string;
73
+ os: string;
74
+ appVersion: string;
75
+ sessionId: string;
76
+ seq: number;
77
+ apiVersion: string;
78
+ auth: {
79
+ token: string;
80
+ refresh: string;
81
+ };
82
+ };
83
+ export type TCtx = {
84
+ id: string;
85
+ meta: CtxMeta;
86
+ req: CtxReq;
87
+ res: CtxRes;
88
+ user: CtxUser;
89
+ };
90
+ export interface IBaseApi {
91
+ auth(ctx: TCtx): Promise<TCtx>;
92
+ validate(ctx: TCtx): Promise<TCtx>;
93
+ handle(ctx: TCtx): Promise<TCtx>;
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=ctx.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.types.d.ts","sourceRoot":"","sources":["../src/ctx.types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;CAKZ,CAAC;AAEX,KAAK,MAAM,GAAG;IACZ,MAAM,EAAE;QACN,aAAa,CAAC,EAAE,MAA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AI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_ROLE = void 0;
4
+ exports.USER_ROLE = {
5
+ user: "user",
6
+ admin: "admin",
7
+ server: "server",
8
+ none: "none",
9
+ };
10
+ //# sourceMappingURL=ctx.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.types.js","sourceRoot":"","sources":["../src/ctx.types.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ type TCtxErrorData = {
2
+ [key: string]: number | string | object | boolean | null;
3
+ };
4
+ type TCtxError = {
5
+ name: string;
6
+ msg: string;
7
+ data?: TCtxErrorData;
8
+ info?: unknown;
9
+ };
10
+ export declare class CtxError extends Error {
11
+ data: {
12
+ [key: string]: number | string | object | boolean | null;
13
+ };
14
+ info?: unknown;
15
+ constructor({ name, msg, data, info }: TCtxError);
16
+ }
17
+ type TResErr = Partial<Pick<TCtxError, "data" | "info" | "msg">>;
18
+ export declare namespace ctxErr {
19
+ const general: {
20
+ unknown: (e?: TResErr) => CtxError;
21
+ responseNotSet: (e?: TResErr) => CtxError;
22
+ malformedRequestData: (e?: TResErr) => CtxError;
23
+ handlerNotFound: (e?: TResErr) => CtxError;
24
+ notAuthorized: (e?: TResErr) => CtxError;
25
+ };
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=ctxErr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctxErr.d.ts","sourceRoot":"","sources":["../src/ctxErr.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CAC1D,CAAC;AACF,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AACF,qBAAa,QAAS,SAAQ,KAAK;IACjC,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC;IACnE,IAAI,CAAC,EAAE,OAAO,CAAC;gBACH,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS;CAMjD;AAED,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;AAEjE,yBAAiB,MAAM,CAAC;IACf,MAAM,OAAO;sBACJ,OAAO;6BAMA,OAAO;mCAMD,OAAO;8BAMZ,OAAO;4BAMT,OAAO;KAM5B,CAAC;CACH"}
package/dist/ctxErr.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ctxErr = exports.CtxError = void 0;
4
+ class CtxError extends Error {
5
+ constructor({ name, msg, data, info }) {
6
+ super(msg);
7
+ super.name = name;
8
+ this.data = data || {};
9
+ this.info = info;
10
+ }
11
+ }
12
+ exports.CtxError = CtxError;
13
+ var ctxErr;
14
+ (function (ctxErr) {
15
+ ctxErr.general = {
16
+ unknown: (e) => new CtxError({
17
+ name: "UNKNOWN_ERROR",
18
+ msg: "Something went wrong",
19
+ ...e,
20
+ }),
21
+ responseNotSet: (e) => new CtxError({
22
+ name: "RESPONSE_NOT_SET",
23
+ msg: "Response not set",
24
+ ...e,
25
+ }),
26
+ malformedRequestData: (e) => new CtxError({
27
+ name: "MALFORMED_REQUEST_DATA",
28
+ msg: "Malformed request data",
29
+ ...e,
30
+ }),
31
+ handlerNotFound: (e) => new CtxError({
32
+ name: "HANDLER_NOT_FOUND",
33
+ msg: "Handler not found",
34
+ ...e,
35
+ }),
36
+ notAuthorized: (e) => new CtxError({
37
+ name: "NOT_AUTHORIZED",
38
+ msg: "Not authorized",
39
+ ...e,
40
+ }),
41
+ };
42
+ })(ctxErr || (exports.ctxErr = ctxErr = {}));
43
+ //# sourceMappingURL=ctxErr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctxErr.js","sourceRoot":"","sources":["../src/ctxErr.ts"],"names":[],"mappings":";;;AASA,MAAa,QAAS,SAAQ,KAAK;IAGjC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAa;QAC9C,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AATD,4BASC;AAID,IAAiB,MAAM,CAiCtB;AAjCD,WAAiB,MAAM;IACR,cAAO,GAAG;QACrB,OAAO,EAAE,CAAC,CAAW,EAAE,EAAE,CACvB,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,eAAe;YACrB,GAAG,EAAE,sBAAsB;YAC3B,GAAG,CAAC;SACL,CAAC;QACJ,cAAc,EAAE,CAAC,CAAW,EAAE,EAAE,CAC9B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,kBAAkB;YACvB,GAAG,CAAC;SACL,CAAC;QACJ,oBAAoB,EAAE,CAAC,CAAW,EAAE,EAAE,CACpC,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,wBAAwB;YAC9B,GAAG,EAAE,wBAAwB;YAC7B,GAAG,CAAC;SACL,CAAC;QACJ,eAAe,EAAE,CAAC,CAAW,EAAE,EAAE,CAC/B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,mBAAmB;YACzB,GAAG,EAAE,mBAAmB;YACxB,GAAG,CAAC;SACL,CAAC;QACJ,aAAa,EAAE,CAAC,CAAW,EAAE,EAAE,CAC7B,IAAI,QAAQ,CAAC;YACX,IAAI,EAAE,gBAAgB;YACtB,GAAG,EAAE,gBAAgB;YACrB,GAAG,CAAC;SACL,CAAC;KACL,CAAC;AACJ,CAAC,EAjCgB,MAAM,sBAAN,MAAM,QAiCtB"}
@@ -0,0 +1,14 @@
1
+ import { TCtx } from "../../..";
2
+ export declare function execute(reqData: TReqData): Promise<TResData>;
3
+ export declare function auth(ctx: TCtx): Promise<TCtx>;
4
+ export declare function validate(ctx: TCtx): Promise<TReqData>;
5
+ type TReqData = {
6
+ userId: string;
7
+ pingAt: Date;
8
+ };
9
+ type TResData = {
10
+ pingAt: Date;
11
+ pongAt: Date;
12
+ };
13
+ export {};
14
+ //# sourceMappingURL=healthPing.api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthPing.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,UAAU,CAAC;AAG3C,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAOnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG3D;AAED,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;CACd,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.execute = execute;
4
+ exports.auth = auth;
5
+ exports.validate = validate;
6
+ const __1 = require("../../..");
7
+ const ctx_err_1 = require("../../../ctx/ctx.err");
8
+ async function execute(reqData) {
9
+ const pongAt = new Date();
10
+ return {
11
+ pingAt: reqData.pingAt,
12
+ pongAt,
13
+ };
14
+ }
15
+ async function auth(ctx) {
16
+ // authenticate the request, and return the context if the request is authenticated
17
+ // await authRequest(ctx);
18
+ if (__1.USER_ROLE.user === ctx.user.role)
19
+ return ctx;
20
+ if (__1.USER_ROLE.admin === ctx.user.role)
21
+ return ctx;
22
+ if (__1.USER_ROLE.server === ctx.user.role)
23
+ return ctx;
24
+ throw ctx_err_1.ctxErr.general.notAuthorized();
25
+ }
26
+ async function validate(ctx) {
27
+ // Validate request data and return the request data
28
+ return ctx.req.data;
29
+ }
30
+ //# sourceMappingURL=healthPing.api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthPing.api.js","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":";;AAGA,0BAMC;AAED,oBAOC;AAED,4BAGC;AAvBD,gCAA2C;AAC3C,kDAA8C;AAEvC,KAAK,UAAU,OAAO,CAAC,OAAiB;IAC7C,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;IAC1B,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM;KACP,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,mFAAmF;IACnF,0BAA0B;IAC1B,IAAI,aAAS,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IACjD,IAAI,aAAS,CAAC,KAAK,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IAClD,IAAI,aAAS,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IACnD,MAAM,gBAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;AACvC,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,oDAAoD;IACpD,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}