ctx-router 1.0.3 → 1.0.4
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.
- package/dist/ctx/ctx.err.d.ts +1 -9
- package/dist/ctx/ctx.err.d.ts.map +1 -1
- package/dist/ctx/ctx.err.js +19 -31
- package/dist/ctx/ctx.err.js.map +1 -1
- package/dist/ctx/ctx.router.d.ts +30 -8
- package/dist/ctx/ctx.router.d.ts.map +1 -1
- package/dist/ctx/ctx.router.js +56 -15
- package/dist/ctx/ctx.router.js.map +1 -1
- package/dist/ctx/ctx.types.d.ts +22 -20
- package/dist/ctx/ctx.types.d.ts.map +1 -1
- package/dist/ctx/ctx.types.js +4 -4
- package/dist/defaultHandler/handle.beforeExec.d.ts +2 -2
- package/dist/defaultHandler/handle.beforeExec.d.ts.map +1 -1
- package/dist/defaultHandler/handle.beforeExec.js +2 -1
- package/dist/defaultHandler/handle.beforeExec.js.map +1 -1
- package/dist/defaultHandler/handle.onError.d.ts +2 -2
- package/dist/defaultHandler/handle.onError.d.ts.map +1 -1
- package/dist/defaultHandler/handle.onError.js +5 -2
- package/dist/defaultHandler/handle.onError.js.map +1 -1
- package/dist/example/api/health/healthPing.api.d.ts +1 -1
- package/dist/example/api/health/healthPing.api.d.ts.map +1 -1
- package/dist/example/api/health/healthPing.api.js +1 -12
- package/dist/example/api/health/healthPing.api.js.map +1 -1
- package/dist/example/api/health/index.d.ts +1 -1
- package/dist/example/api/health/index.d.ts.map +1 -1
- package/dist/example/api/user/index.d.ts +1 -1
- package/dist/example/api/user/index.d.ts.map +1 -1
- package/dist/example/api/user/userDetail.api.d.ts +1 -1
- package/dist/example/api/user/userDetail.api.d.ts.map +1 -1
- package/dist/example/api/user/userDetail.api.js +4 -5
- package/dist/example/api/user/userDetail.api.js.map +1 -1
- package/dist/example/api/user/userUpdate.api.d.ts +1 -1
- package/dist/example/api/user/userUpdate.api.d.ts.map +1 -1
- package/dist/example/api/user/userUpdate.api.js +4 -5
- package/dist/example/api/user/userUpdate.api.js.map +1 -1
- package/dist/example/config/ctx.redis.config.d.ts +2 -0
- package/dist/example/config/ctx.redis.config.d.ts.map +1 -0
- package/dist/example/config/ctx.redis.config.js +7 -0
- package/dist/example/config/ctx.redis.config.js.map +1 -0
- package/dist/example/express.js +10 -2
- package/dist/example/express.js.map +1 -1
- package/dist/example/router.d.ts +82 -1
- package/dist/example/router.d.ts.map +1 -1
- package/dist/example/router.js +27 -8
- package/dist/example/router.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/transform/fromExpress.d.ts +2 -2
- package/dist/transform/fromExpress.d.ts.map +1 -1
- package/dist/transform/index.d.ts +18 -11
- package/dist/transform/index.d.ts.map +1 -1
- package/dist/transform/index.js +14 -15
- package/dist/transform/index.js.map +1 -1
- package/package.json +5 -4
package/dist/ctx/ctx.err.d.ts
CHANGED
|
@@ -15,14 +15,6 @@ export declare class CtxError extends Error {
|
|
|
15
15
|
constructor({ name, msg, data, info }: TCtxError);
|
|
16
16
|
}
|
|
17
17
|
type TResErr = Partial<Pick<TCtxError, "data" | "info" | "msg">>;
|
|
18
|
-
export declare
|
|
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
|
-
}
|
|
18
|
+
export declare function ctxErrMap<T extends Record<string, Record<string, string>>>(errKeyMsg: T): { [K in keyof T]: { [P in keyof T[K]]: (e?: TResErr) => CtxError; }; };
|
|
27
19
|
export {};
|
|
28
20
|
//# sourceMappingURL=ctx.err.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.err.d.ts","sourceRoot":"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O,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;AAWjE,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACxE,SAAS,EAAE,CAAC,GAeP,GACF,CAAC,IAAI,MAAM,CAAC,GAAG,GACb,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,QAAQ,GAC7C,GACF,CACF"}
|
package/dist/ctx/ctx.err.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CtxError = void 0;
|
|
4
|
+
exports.ctxErrMap = ctxErrMap;
|
|
4
5
|
class CtxError extends Error {
|
|
5
6
|
constructor({ name, msg, data, info }) {
|
|
6
7
|
super(msg);
|
|
@@ -10,34 +11,21 @@ class CtxError extends Error {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
exports.CtxError = CtxError;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 = {}));
|
|
14
|
+
// Factory function to create error instances
|
|
15
|
+
function createError(key, msg, e) {
|
|
16
|
+
return new CtxError({
|
|
17
|
+
name: key,
|
|
18
|
+
msg: msg,
|
|
19
|
+
...e,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function ctxErrMap(errKeyMsg) {
|
|
23
|
+
return Object.fromEntries(Object.keys(errKeyMsg).map((category) => [
|
|
24
|
+
category,
|
|
25
|
+
Object.fromEntries(Object.keys(errKeyMsg[category]).map((key) => [
|
|
26
|
+
key,
|
|
27
|
+
(e) => createError(key, errKeyMsg[category][key], e),
|
|
28
|
+
])),
|
|
29
|
+
]));
|
|
30
|
+
}
|
|
43
31
|
//# sourceMappingURL=ctx.err.js.map
|
package/dist/ctx/ctx.err.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.err.js","sourceRoot":"","sources":["../../src/ctx/ctx.err.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ctx.err.js","sourceRoot":"","sources":["../../src/ctx/ctx.err.ts"],"names":[],"mappings":";;;AA+BA,8BAqBC;AA3CD,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,6CAA6C;AAC7C,SAAS,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,CAAW;IACxD,OAAO,IAAI,QAAQ,CAAC;QAClB,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,GAAG;QACR,GAAG,CAAC;KACL,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,SAAS,CACvB,SAAY;IAEZ,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;QACvC,QAAQ;QACR,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,IAAI,CACT,SAAS,CAAC,QAAmB,CAA2B,CACzD,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;YACb,GAAG;YACH,CAAC,CAAW,EAAE,EAAE,CACd,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,QAAmB,CAAE,CAAC,GAAG,CAAW,EAAE,CAAC,CAAC;SACtE,CAAC,CACH;KACF,CAAC,CAKH,CAAC;AACJ,CAAC"}
|
package/dist/ctx/ctx.router.d.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
import { CtxError } from "./ctx.err";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { TDefaultCtx as TDefaultCtx } from "./ctx.types";
|
|
3
|
+
import { RedisClientType } from "@redis/client";
|
|
4
|
+
type THooks = {
|
|
5
|
+
beforeExec<TContext extends TDefaultCtx>(ctx: TContext): Promise<TContext>;
|
|
6
|
+
onError<TContext extends TDefaultCtx>(ctx: TContext, error: CtxError | Error | unknown): Promise<TContext>;
|
|
7
|
+
onFinally<TContext extends TDefaultCtx>(ctx: TContext): Promise<TContext>;
|
|
8
|
+
};
|
|
9
|
+
type CtxRouterConfig = {
|
|
10
|
+
log?: {
|
|
11
|
+
capture: boolean;
|
|
12
|
+
};
|
|
13
|
+
stream?: {
|
|
14
|
+
redisClient: RedisClientType;
|
|
15
|
+
key: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare class CtxRouter<TContext extends TDefaultCtx> {
|
|
4
19
|
private routeObj;
|
|
5
|
-
private
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
|
|
20
|
+
private hooks;
|
|
21
|
+
private consoleLogList;
|
|
22
|
+
private config;
|
|
23
|
+
constructor(config: CtxRouterConfig);
|
|
24
|
+
private setConfig;
|
|
25
|
+
start(): void;
|
|
26
|
+
logGetRef(): unknown[];
|
|
27
|
+
logConsole(...args: unknown[]): void;
|
|
28
|
+
flushToStream(ctx: TContext): Promise<void>;
|
|
29
|
+
beforeExecHook(handler: THooks["beforeExec"]): void;
|
|
9
30
|
exec(ctx: TContext): Promise<TContext>;
|
|
10
31
|
handle(method: string, path: string, handler: (ctx: TContext) => Promise<TContext>): void;
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
onErrorHook(handler: THooks["onError"]): void;
|
|
33
|
+
onFinallyHook(handler: THooks["onFinally"]): void;
|
|
13
34
|
}
|
|
35
|
+
export {};
|
|
14
36
|
//# sourceMappingURL=ctx.router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.router.d.ts","sourceRoot":"","sources":["../../src/ctx/ctx.router.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"ctx.router.d.ts","sourceRoot":"","sources":["../../src/ctx/ctx.router.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAMhD,KAAK,MAAM,GAAG;IACZ,UAAU,CAAC,QAAQ,SAAS,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3E,OAAO,CAAC,QAAQ,SAAS,WAAW,EAClC,GAAG,EAAE,QAAQ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eExec");
|
|
5
5
|
const handle_onError_1 = require("../defaultHandler/handle.onError");
|
|
6
6
|
const ctx_err_1 = require("./ctx.err");
|
|
7
|
+
const ogLog = console.log;
|
|
7
8
|
class CtxRouter {
|
|
8
|
-
constructor() {
|
|
9
|
+
constructor(config) {
|
|
9
10
|
this.routeObj = {};
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
|
|
11
|
+
this.consoleLogList = [];
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.setConfig();
|
|
14
|
+
this.hooks = {
|
|
15
|
+
beforeExec: handle_beforeExec_1.handleBeforeExec,
|
|
16
|
+
onError: handle_onError_1.handleOnError,
|
|
17
|
+
onFinally: async (ctx) => ctx,
|
|
14
18
|
};
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
this.
|
|
20
|
+
setConfig() {
|
|
21
|
+
if (this.config.log?.capture) {
|
|
22
|
+
console.log = (...args) => {
|
|
23
|
+
try {
|
|
24
|
+
ogLog(...args);
|
|
25
|
+
const processedArgs = args.flatMap((arg) => {
|
|
26
|
+
if (arg instanceof Error) {
|
|
27
|
+
return [arg.stack, arg];
|
|
28
|
+
}
|
|
29
|
+
return arg;
|
|
30
|
+
});
|
|
31
|
+
this.consoleLogList.push(...processedArgs);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
ogLog(error);
|
|
35
|
+
this.consoleLogList.push(error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
this.consoleLogList = [];
|
|
42
|
+
}
|
|
43
|
+
logGetRef() {
|
|
44
|
+
return this.consoleLogList;
|
|
45
|
+
}
|
|
46
|
+
logConsole(...args) {
|
|
47
|
+
ogLog(...args);
|
|
48
|
+
}
|
|
49
|
+
async flushToStream(ctx) {
|
|
50
|
+
if (!this.config.stream)
|
|
51
|
+
return;
|
|
52
|
+
const { redisClient, key } = this.config.stream;
|
|
53
|
+
await redisClient.xAdd(key, "*", { ctx: JSON.stringify(ctx) });
|
|
54
|
+
}
|
|
55
|
+
beforeExecHook(handler) {
|
|
56
|
+
this.hooks.beforeExec = handler;
|
|
18
57
|
}
|
|
19
58
|
async exec(ctx) {
|
|
20
59
|
try {
|
|
21
|
-
await this.
|
|
60
|
+
await this.hooks.beforeExec(ctx);
|
|
22
61
|
const handler = this.routeObj[ctx.req.method]?.[ctx.req.path];
|
|
23
62
|
if (!handler) {
|
|
24
|
-
throw ctx_err_1.
|
|
63
|
+
throw new ctx_err_1.CtxError({
|
|
64
|
+
name: "HANDLER_NOT_FOUND",
|
|
65
|
+
msg: "Handler not found",
|
|
25
66
|
data: { method: ctx.req.method, path: ctx.req.path },
|
|
26
67
|
});
|
|
27
68
|
}
|
|
28
69
|
return await handler(ctx);
|
|
29
70
|
}
|
|
30
71
|
catch (error) {
|
|
31
|
-
return await this.
|
|
72
|
+
return await this.hooks.onError(ctx, error);
|
|
32
73
|
}
|
|
33
74
|
finally {
|
|
34
|
-
await this.
|
|
75
|
+
await this.hooks.onFinally(ctx);
|
|
35
76
|
}
|
|
36
77
|
}
|
|
37
78
|
handle(method, path, handler) {
|
|
38
79
|
const methodRoute = this.routeObj[method] || (this.routeObj[method] = {});
|
|
39
80
|
methodRoute[path] = handler;
|
|
40
81
|
}
|
|
41
|
-
|
|
42
|
-
this.
|
|
82
|
+
onErrorHook(handler) {
|
|
83
|
+
this.hooks.onError = handler;
|
|
43
84
|
}
|
|
44
|
-
|
|
45
|
-
this.
|
|
85
|
+
onFinallyHook(handler) {
|
|
86
|
+
this.hooks.onFinally = handler;
|
|
46
87
|
}
|
|
47
88
|
}
|
|
48
89
|
exports.CtxRouter = CtxRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.router.js","sourceRoot":"","sources":["../../src/ctx/ctx.router.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,qEAAiE;AACjE,
|
|
1
|
+
{"version":3,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YACf,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,MAAM,CACJ,MAAc,EACd,IAAY,EACZ,OAA6C;QAE7C,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,WAAW,CAAC,OAA0B;QACpC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IAC/B,CAAC;IACD,aAAa,CAAC,OAA4B;QACxC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC;IACjC,CAAC;CACF;AAxFD,8BAwFC"}
|
package/dist/ctx/ctx.types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const USER_ROLE: {
|
|
2
|
-
readonly
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
2
|
+
readonly USER: "USER";
|
|
3
|
+
readonly ADMIN: "ADMIN";
|
|
4
|
+
readonly SERVER: "SERVER";
|
|
5
|
+
readonly NONE: "NONE";
|
|
6
6
|
};
|
|
7
7
|
type CtxReq = {
|
|
8
8
|
header: {
|
|
@@ -14,7 +14,10 @@ type CtxReq = {
|
|
|
14
14
|
"x-ctx-api-version"?: string;
|
|
15
15
|
"x-ctx-session-id"?: string;
|
|
16
16
|
"x-ctx-seq"?: string;
|
|
17
|
+
"x-ctx-ts"?: string;
|
|
17
18
|
"x-ctx-refresh-token"?: string;
|
|
19
|
+
"x-ctx-csrf"?: string;
|
|
20
|
+
"x-ctx-trace-id"?: string;
|
|
18
21
|
[key: string]: string | string[] | undefined;
|
|
19
22
|
};
|
|
20
23
|
method: string;
|
|
@@ -32,6 +35,7 @@ type CtxRes = {
|
|
|
32
35
|
data: {
|
|
33
36
|
[key: string]: unknown;
|
|
34
37
|
};
|
|
38
|
+
info?: unknown;
|
|
35
39
|
meta?: {
|
|
36
40
|
ctxId: string;
|
|
37
41
|
seq: number;
|
|
@@ -50,6 +54,8 @@ type CtxMeta = {
|
|
|
50
54
|
createdAt: Date;
|
|
51
55
|
seq: number;
|
|
52
56
|
inflight: number;
|
|
57
|
+
cpu: number;
|
|
58
|
+
mem: number;
|
|
53
59
|
};
|
|
54
60
|
ts: {
|
|
55
61
|
in: Date;
|
|
@@ -61,36 +67,32 @@ type CtxMeta = {
|
|
|
61
67
|
monitor: {
|
|
62
68
|
traceId: string;
|
|
63
69
|
spanId: string;
|
|
70
|
+
};
|
|
71
|
+
log: {
|
|
64
72
|
stdout: string[];
|
|
65
|
-
|
|
73
|
+
db: {
|
|
74
|
+
q: string;
|
|
75
|
+
p: unknown[];
|
|
76
|
+
ms: number;
|
|
77
|
+
}[];
|
|
66
78
|
};
|
|
67
79
|
};
|
|
68
80
|
type CtxUser = {
|
|
69
81
|
id: string;
|
|
70
|
-
role: keyof typeof USER_ROLE
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
os: string;
|
|
74
|
-
appVersion: string;
|
|
75
|
-
sessionId: string;
|
|
76
|
-
seq: number;
|
|
77
|
-
apiVersion: string;
|
|
82
|
+
role: Array<keyof typeof USER_ROLE>;
|
|
83
|
+
scope: string[];
|
|
84
|
+
name: string | null;
|
|
78
85
|
auth: {
|
|
79
86
|
token: string;
|
|
80
87
|
refresh: string;
|
|
81
88
|
};
|
|
82
89
|
};
|
|
83
|
-
export type
|
|
90
|
+
export type TDefaultCtx = {
|
|
84
91
|
id: string;
|
|
85
|
-
meta: CtxMeta;
|
|
86
92
|
req: CtxReq;
|
|
87
93
|
res: CtxRes;
|
|
88
94
|
user: CtxUser;
|
|
95
|
+
meta: CtxMeta;
|
|
89
96
|
};
|
|
90
|
-
export interface IBaseApi {
|
|
91
|
-
auth(ctx: TCtx): Promise<TCtx>;
|
|
92
|
-
validate(ctx: TCtx): Promise<TCtx>;
|
|
93
|
-
handle(ctx: TCtx): Promise<TCtx>;
|
|
94
|
-
}
|
|
95
97
|
export {};
|
|
96
98
|
//# sourceMappingURL=ctx.types.d.ts.map
|
|
@@ -1 +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,EA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AE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,GAAG,EAAE;QACH,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,EAAE,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAC/C,CAAC;CACH,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,KAAK,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf,CAAC"}
|
package/dist/ctx/ctx.types.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.USER_ROLE = void 0;
|
|
4
4
|
exports.USER_ROLE = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
USER: "USER",
|
|
6
|
+
ADMIN: "ADMIN",
|
|
7
|
+
SERVER: "SERVER",
|
|
8
|
+
NONE: "NONE",
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=ctx.types.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function handleBeforeExec<TContext extends
|
|
1
|
+
import { TDefaultCtx } from "../ctx/ctx.types";
|
|
2
|
+
export declare function handleBeforeExec<TContext extends TDefaultCtx>(ctx: TContext): Promise<TContext>;
|
|
3
3
|
//# sourceMappingURL=handle.beforeExec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.beforeExec.d.ts","sourceRoot":"","sources":["../../src/defaultHandler/handle.beforeExec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"handle.beforeExec.d.ts","sourceRoot":"","sources":["../../src/defaultHandler/handle.beforeExec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,wBAAsB,gBAAgB,CAAC,QAAQ,SAAS,WAAW,EACjE,GAAG,EAAE,QAAQ,GACZ,OAAO,CAAC,QAAQ,CAAC,CAanB"}
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleBeforeExec = handleBeforeExec;
|
|
4
4
|
async function handleBeforeExec(ctx) {
|
|
5
5
|
const reqPath = `${ctx.req.method} ${ctx.req.path}`;
|
|
6
|
+
const header = ctx.req.header;
|
|
6
7
|
console.log(`CtxReq: [${reqPath}] | [IP: ${ctx.req.ips || ctx.req.ip}] | [TraceId: ${ctx.meta.monitor.traceId}] | [SpanId: ${ctx.meta.monitor.spanId}]`);
|
|
7
|
-
console.log(`CtxUser: [Session: ${ctx
|
|
8
|
+
console.log(`CtxUser: [Session: ${header["x-ctx-session-id"]}] | [Seq: ${header["x-ctx-seq"]}]`);
|
|
8
9
|
console.log(`CtxMeta: [Seq: ${ctx.meta.instance.seq}] | [Inflight: ${ctx.meta.instance.inflight}]`);
|
|
9
10
|
return ctx;
|
|
10
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.beforeExec.js","sourceRoot":"","sources":["../../src/defaultHandler/handle.beforeExec.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"handle.beforeExec.js","sourceRoot":"","sources":["../../src/defaultHandler/handle.beforeExec.ts"],"names":[],"mappings":";;AAEA,4CAeC;AAfM,KAAK,UAAU,gBAAgB,CACpC,GAAa;IAEb,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACpD,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;IAC9B,OAAO,CAAC,GAAG,CACT,YAAY,OAAO,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,iBAAiB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,gBAAgB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAC5I,CAAC;IACF,OAAO,CAAC,GAAG,CACT,sBAAsB,MAAM,CAAC,kBAAkB,CAAC,aAAa,MAAM,CAAC,WAAW,CAAC,GAAG,CACpF,CAAC;IACF,OAAO,CAAC,GAAG,CACT,kBAAkB,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,kBAAkB,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,CACvF,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CtxError } from "../ctx/ctx.err";
|
|
2
|
-
import {
|
|
3
|
-
export declare function handleOnError<TContext extends
|
|
2
|
+
import { TDefaultCtx } from "../ctx/ctx.types";
|
|
3
|
+
export declare function handleOnError<TContext extends TDefaultCtx>(ctx: TContext, e: CtxError | Error | unknown): Promise<TContext>;
|
|
4
4
|
//# sourceMappingURL=handle.onError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.onError.d.ts","sourceRoot":"","sources":["../../src/defaultHandler/handle.onError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"handle.onError.d.ts","sourceRoot":"","sources":["../../src/defaultHandler/handle.onError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,wBAAsB,aAAa,CAAC,QAAQ,SAAS,WAAW,EAC9D,GAAG,EAAE,QAAQ,EACb,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAgCnB"}
|
|
@@ -8,7 +8,7 @@ async function handleOnError(ctx, e) {
|
|
|
8
8
|
console.log("CtxError:message:", e.message);
|
|
9
9
|
console.log("CtxError:data:", e.data);
|
|
10
10
|
if (e.info) {
|
|
11
|
-
ctx.
|
|
11
|
+
ctx.res.info = e.info;
|
|
12
12
|
}
|
|
13
13
|
if (typeof e.info === "object") {
|
|
14
14
|
console.log("CtxError:info:object:", JSON.stringify(e.info));
|
|
@@ -24,7 +24,10 @@ async function handleOnError(ctx, e) {
|
|
|
24
24
|
}
|
|
25
25
|
// ideally should never come here, god forbid it did
|
|
26
26
|
console.log("CtxError:unknown:fatal", e);
|
|
27
|
-
const error = ctx_err_1.
|
|
27
|
+
const error = new ctx_err_1.CtxError({
|
|
28
|
+
name: "UNKNOWN_ERROR",
|
|
29
|
+
msg: "Something went wrong",
|
|
30
|
+
});
|
|
28
31
|
ctx.res = {
|
|
29
32
|
code: error.name,
|
|
30
33
|
msg: error.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.onError.js","sourceRoot":"","sources":["../../src/defaultHandler/handle.onError.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"handle.onError.js","sourceRoot":"","sources":["../../src/defaultHandler/handle.onError.ts"],"names":[],"mappings":";;AAGA,sCAmCC;AAtCD,4CAA0C;AAGnC,KAAK,UAAU,aAAa,CACjC,GAAa,EACb,CAA6B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AI;QAChB,GAAG,EAAE,KAAK,CAAC,OAAO;QAClB,IAAI,EAAE,EAAE;KACT,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthPing.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"healthPing.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE3D;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"}
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.execute = execute;
|
|
4
4
|
exports.auth = auth;
|
|
5
5
|
exports.validate = validate;
|
|
6
|
-
const __1 = require("../../..");
|
|
7
|
-
const ctx_err_1 = require("../../../ctx/ctx.err");
|
|
8
6
|
async function execute(reqData) {
|
|
9
7
|
const pongAt = new Date();
|
|
10
8
|
return {
|
|
@@ -13,18 +11,9 @@ async function execute(reqData) {
|
|
|
13
11
|
};
|
|
14
12
|
}
|
|
15
13
|
async function auth(ctx) {
|
|
16
|
-
|
|
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();
|
|
14
|
+
return ctx;
|
|
25
15
|
}
|
|
26
16
|
async function validate(ctx) {
|
|
27
|
-
// Validate request data and return the request data
|
|
28
17
|
return ctx.req.data;
|
|
29
18
|
}
|
|
30
19
|
//# sourceMappingURL=healthPing.api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthPing.api.js","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"healthPing.api.js","sourceRoot":"","sources":["../../../../src/example/api/health/healthPing.api.ts"],"names":[],"mappings":";;AAEA,0BAMC;AAED,oBAEC;AAED,4BAEC;AAdM,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,OAAO,GAAG,CAAC;AACb,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIpC,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,iBAInC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAKpC,wBAAsB,MAAM,CAAC,GAAG,EAAE,IAAI,iBAIrC;AAED,wBAAsB,MAAM,CAAC,GAAG,EAAE,IAAI,iBAIrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userDetail.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"userDetail.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAqB,MAAM,cAAc,CAAC;AAEvD,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAOlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG3D;AAED,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC"}
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.execute = execute;
|
|
4
4
|
exports.auth = auth;
|
|
5
5
|
exports.validate = validate;
|
|
6
|
-
const
|
|
7
|
-
const ctx_err_1 = require("../../../ctx/ctx.err");
|
|
6
|
+
const router_1 = require("../../router");
|
|
8
7
|
async function execute(reqData) {
|
|
9
8
|
return {
|
|
10
9
|
userDetail: {
|
|
@@ -16,11 +15,11 @@ async function execute(reqData) {
|
|
|
16
15
|
async function auth(ctx) {
|
|
17
16
|
// authenticate the request, and return the context if the request is authenticated
|
|
18
17
|
// await authRequest(ctx);
|
|
19
|
-
if (
|
|
18
|
+
if (ctx.user.role.includes(router_1.USER_ROLE.USER))
|
|
20
19
|
return ctx;
|
|
21
|
-
if (
|
|
20
|
+
if (ctx.user.role.includes(router_1.USER_ROLE.ADMIN))
|
|
22
21
|
return ctx;
|
|
23
|
-
throw
|
|
22
|
+
throw router_1.ctxErr.auth.UNAUTHORIZED();
|
|
24
23
|
}
|
|
25
24
|
async function validate(ctx) {
|
|
26
25
|
// Validate request data and return the request data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userDetail.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"userDetail.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":";;AAEA,0BAOC;AAED,oBAMC;AAED,4BAGC;AAtBD,yCAAuD;AAEhD,KAAK,UAAU,OAAO,CAAC,OAAiB;IAC7C,OAAO;QACL,UAAU,EAAE;YACV,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,SAAS;SACpB;KACF,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,mFAAmF;IACnF,0BAA0B;IAC1B,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAS,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC;IACvD,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAS,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IACxD,MAAM,eAAM,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;AACnC,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,oDAAoD;IACpD,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userUpdate.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"userUpdate.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAqB,MAAM,cAAc,CAAC;AAEvD,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG3D;AAED,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.execute = execute;
|
|
4
4
|
exports.auth = auth;
|
|
5
5
|
exports.validate = validate;
|
|
6
|
-
const
|
|
7
|
-
const ctx_err_1 = require("../../../ctx/ctx.err");
|
|
6
|
+
const router_1 = require("../../router");
|
|
8
7
|
async function execute(reqData) {
|
|
9
8
|
return {
|
|
10
9
|
userId: reqData.userId,
|
|
@@ -14,11 +13,11 @@ async function execute(reqData) {
|
|
|
14
13
|
async function auth(ctx) {
|
|
15
14
|
// authenticate the request, and return the context if the request is authenticated
|
|
16
15
|
// await authRequest(ctx);
|
|
17
|
-
if (
|
|
16
|
+
if (ctx.user.role.includes(router_1.USER_ROLE.USER))
|
|
18
17
|
return ctx;
|
|
19
|
-
if (
|
|
18
|
+
if (ctx.user.role.includes(router_1.USER_ROLE.ADMIN))
|
|
20
19
|
return ctx;
|
|
21
|
-
throw
|
|
20
|
+
throw router_1.ctxErr.auth.UNAUTHORIZED();
|
|
22
21
|
}
|
|
23
22
|
async function validate(ctx) {
|
|
24
23
|
// Validate request data and return the request data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userUpdate.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"userUpdate.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":";;AAEA,0BAKC;AAED,oBAMC;AAED,4BAGC;AApBD,yCAAuD;AAEhD,KAAK,UAAU,OAAO,CAAC,OAAiB;IAC7C,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,mFAAmF;IACnF,0BAA0B;IAC1B,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAS,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC;IACvD,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAS,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IACxD,MAAM,eAAM,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;AACnC,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,oDAAoD;IACpD,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctx.redis.config.d.ts","sourceRoot":"","sources":["../../../src/example/config/ctx.redis.config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,4DAAiB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ctxRedisClient = void 0;
|
|
4
|
+
const client_1 = require("@redis/client");
|
|
5
|
+
exports.ctxRedisClient = (0, client_1.createClient)();
|
|
6
|
+
exports.ctxRedisClient.connect();
|
|
7
|
+
//# sourceMappingURL=ctx.redis.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctx.redis.config.js","sourceRoot":"","sources":["../../../src/example/config/ctx.redis.config.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAEhC,QAAA,cAAc,GAAG,IAAA,qBAAY,GAAE,CAAC;AAC7C,sBAAc,CAAC,OAAO,EAAE,CAAC"}
|
package/dist/example/express.js
CHANGED
|
@@ -7,6 +7,9 @@ const express_1 = __importDefault(require("express"));
|
|
|
7
7
|
const __1 = require("..");
|
|
8
8
|
const router_1 = require("./router");
|
|
9
9
|
const app = (0, express_1.default)();
|
|
10
|
+
// Add body parsing middleware
|
|
11
|
+
app.use(express_1.default.json());
|
|
12
|
+
app.use(express_1.default.urlencoded({ extended: true }));
|
|
10
13
|
function getHttpCode(ctx) {
|
|
11
14
|
if (ctx.res.code === "OK")
|
|
12
15
|
return 200;
|
|
@@ -15,11 +18,16 @@ function getHttpCode(ctx) {
|
|
|
15
18
|
return 400;
|
|
16
19
|
}
|
|
17
20
|
app.all("/{*any}", async (req, res) => {
|
|
21
|
+
router_1.router.logConsole("req:start");
|
|
18
22
|
const ctx = __1.toCtx.fromExpress(req);
|
|
23
|
+
router_1.router.start();
|
|
19
24
|
await router_1.router.exec(ctx);
|
|
25
|
+
ctx.meta.log.stdout = router_1.router.logGetRef();
|
|
26
|
+
router_1.router.logConsole("req:end");
|
|
27
|
+
await router_1.router.flushToStream(ctx);
|
|
20
28
|
res.type("application/json").status(getHttpCode(ctx)).send(ctx.res);
|
|
21
29
|
});
|
|
22
|
-
app.listen(
|
|
23
|
-
console.log(`Express server listening on port
|
|
30
|
+
app.listen(3001, () => {
|
|
31
|
+
console.log(`Express server listening on port 3001`);
|
|
24
32
|
});
|
|
25
33
|
//# sourceMappingURL=express.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/example/express.ts"],"names":[],"mappings":";;;;;AAAA,sDAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/example/express.ts"],"names":[],"mappings":";;;;;AAAA,sDAAqD;AACrD,0BAA2B;AAC3B,qCAAwC;AAExC,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEtB,8BAA8B;AAC9B,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEhD,SAAS,WAAW,CAAC,GAAS;IAC5B,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IACtC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,GAAG,CAAC;IACjD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;IACvD,eAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAS,SAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACzC,eAAM,CAAC,KAAK,EAAE,CAAC;IACf,MAAM,eAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,eAAM,CAAC,SAAS,EAAc,CAAC;IACrD,eAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,eAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/dist/example/router.d.ts
CHANGED
|
@@ -1,4 +1,85 @@
|
|
|
1
|
-
import { CtxRouter,
|
|
1
|
+
import { CtxRouter, TDefaultCtx } from "..";
|
|
2
|
+
export declare const USER_ROLE: {
|
|
3
|
+
readonly USER: "USER";
|
|
4
|
+
readonly ADMIN: "ADMIN";
|
|
5
|
+
readonly SERVER: "SERVER";
|
|
6
|
+
readonly NONE: "NONE";
|
|
7
|
+
};
|
|
8
|
+
export type TCtx = TDefaultCtx & {
|
|
9
|
+
user: {
|
|
10
|
+
role: (keyof typeof USER_ROLE)[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const ctxErr: {
|
|
14
|
+
general: {
|
|
15
|
+
UNKNOWN_ERROR: (e?: Partial<Pick<{
|
|
16
|
+
name: string;
|
|
17
|
+
msg: string;
|
|
18
|
+
data?: {
|
|
19
|
+
[key: string]: string | number | boolean | object | null;
|
|
20
|
+
};
|
|
21
|
+
info?: unknown;
|
|
22
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
23
|
+
RESPONSE_NOT_SET: (e?: Partial<Pick<{
|
|
24
|
+
name: string;
|
|
25
|
+
msg: string;
|
|
26
|
+
data?: {
|
|
27
|
+
[key: string]: string | number | boolean | object | null;
|
|
28
|
+
};
|
|
29
|
+
info?: unknown;
|
|
30
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
31
|
+
MALFORMED_REQUEST_DATA: (e?: Partial<Pick<{
|
|
32
|
+
name: string;
|
|
33
|
+
msg: string;
|
|
34
|
+
data?: {
|
|
35
|
+
[key: string]: string | number | boolean | object | null;
|
|
36
|
+
};
|
|
37
|
+
info?: unknown;
|
|
38
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
39
|
+
HANDLER_NOT_FOUND: (e?: Partial<Pick<{
|
|
40
|
+
name: string;
|
|
41
|
+
msg: string;
|
|
42
|
+
data?: {
|
|
43
|
+
[key: string]: string | number | boolean | object | null;
|
|
44
|
+
};
|
|
45
|
+
info?: unknown;
|
|
46
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
47
|
+
NOT_FOUND: (e?: Partial<Pick<{
|
|
48
|
+
name: string;
|
|
49
|
+
msg: string;
|
|
50
|
+
data?: {
|
|
51
|
+
[key: string]: string | number | boolean | object | null;
|
|
52
|
+
};
|
|
53
|
+
info?: unknown;
|
|
54
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
55
|
+
};
|
|
56
|
+
auth: {
|
|
57
|
+
UNAUTHORIZED: (e?: Partial<Pick<{
|
|
58
|
+
name: string;
|
|
59
|
+
msg: string;
|
|
60
|
+
data?: {
|
|
61
|
+
[key: string]: string | number | boolean | object | null;
|
|
62
|
+
};
|
|
63
|
+
info?: unknown;
|
|
64
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
65
|
+
TOKEN_EXPIRED: (e?: Partial<Pick<{
|
|
66
|
+
name: string;
|
|
67
|
+
msg: string;
|
|
68
|
+
data?: {
|
|
69
|
+
[key: string]: string | number | boolean | object | null;
|
|
70
|
+
};
|
|
71
|
+
info?: unknown;
|
|
72
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
73
|
+
INVALID_TOKEN: (e?: Partial<Pick<{
|
|
74
|
+
name: string;
|
|
75
|
+
msg: string;
|
|
76
|
+
data?: {
|
|
77
|
+
[key: string]: string | number | boolean | object | null;
|
|
78
|
+
};
|
|
79
|
+
info?: unknown;
|
|
80
|
+
}, "msg" | "data" | "info">>) => import("..").CtxError;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
2
83
|
declare const router: CtxRouter<TCtx>;
|
|
3
84
|
export { router };
|
|
4
85
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAI5C,eAAO,MAAM,SAAS;;;;;CAKZ,CAAC;AACX,MAAM,MAAM,IAAI,GAAG,WAAW,GAAG;IAAE,IAAI,EAAE;QAAE,IAAI,EAAE,CAAC,MAAM,OAAO,SAAS,CAAC,EAAE,CAAA;KAAE,CAAA;CAAE,CAAC;AAChF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEH,QAAA,MAAM,MAAM,iBAGV,CAAC;AAMH,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/example/router.js
CHANGED
|
@@ -33,19 +33,38 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.router = void 0;
|
|
36
|
+
exports.router = exports.ctxErr = exports.USER_ROLE = void 0;
|
|
37
37
|
const __1 = require("..");
|
|
38
|
+
const ctx_err_1 = require("../ctx/ctx.err");
|
|
38
39
|
const api = __importStar(require("./api/index"));
|
|
40
|
+
const ctx_redis_config_1 = require("./config/ctx.redis.config");
|
|
41
|
+
exports.USER_ROLE = {
|
|
42
|
+
USER: "USER",
|
|
43
|
+
ADMIN: "ADMIN",
|
|
44
|
+
SERVER: "SERVER",
|
|
45
|
+
NONE: "NONE",
|
|
46
|
+
};
|
|
47
|
+
exports.ctxErr = (0, ctx_err_1.ctxErrMap)({
|
|
48
|
+
general: {
|
|
49
|
+
UNKNOWN_ERROR: "Something went wrong",
|
|
50
|
+
RESPONSE_NOT_SET: "Response not set",
|
|
51
|
+
MALFORMED_REQUEST_DATA: "Malformed request data",
|
|
52
|
+
HANDLER_NOT_FOUND: "Handler not found",
|
|
53
|
+
NOT_FOUND: "Not found",
|
|
54
|
+
},
|
|
55
|
+
auth: {
|
|
56
|
+
UNAUTHORIZED: "Unauthorized",
|
|
57
|
+
TOKEN_EXPIRED: "Token expired",
|
|
58
|
+
INVALID_TOKEN: "Invalid token",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
39
61
|
// Set your router
|
|
40
|
-
const router = new __1.CtxRouter(
|
|
62
|
+
const router = new __1.CtxRouter({
|
|
63
|
+
log: { capture: true },
|
|
64
|
+
stream: { redisClient: ctx_redis_config_1.ctxRedisClient, key: "CTX:OBJ" },
|
|
65
|
+
});
|
|
41
66
|
exports.router = router;
|
|
42
67
|
router.handle("GET", "/health/ping", api.health.ping);
|
|
43
68
|
router.handle("POST", "/user/update", api.user.update);
|
|
44
69
|
router.handle("GET", "/user/detail", api.user.detail);
|
|
45
|
-
router.onError(async (ctx, error) => {
|
|
46
|
-
console.error("Route error:", error);
|
|
47
|
-
ctx.res.code = "ERROR";
|
|
48
|
-
ctx.res.msg = "Something went wrong";
|
|
49
|
-
return ctx;
|
|
50
|
-
});
|
|
51
70
|
//# sourceMappingURL=router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0BAA4C;AAC5C,4CAA2C;AAC3C,iDAAmC;AACnC,gEAA2D;AAC9C,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEE,QAAA,MAAM,GAAG,IAAA,mBAAS,EAAC;IAC9B,OAAO,EAAE;QACP,aAAa,EAAE,sBAAsB;QACrC,gBAAgB,EAAE,kBAAkB;QACpC,sBAAsB,EAAE,wBAAwB;QAChD,iBAAiB,EAAE,mBAAmB;QACtC,SAAS,EAAE,WAAW;KACvB;IACD,IAAI,EAAE;QACJ,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,eAAe;QAC9B,aAAa,EAAE,eAAe;KAC/B;CACF,CAAC,CAAC;AACH,kBAAkB;AAClB,MAAM,MAAM,GAAG,IAAI,aAAS,CAAO;IACjC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;IACtB,MAAM,EAAE,EAAE,WAAW,EAAE,iCAAc,EAAE,GAAG,EAAE,SAAS,EAAE;CACxD,CAAC,CAAC;AAMM,wBAAM;AAJf,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TDefaultCtx, USER_ROLE } from "./ctx/ctx.types";
|
|
2
2
|
import { transformFromExpress } from "./transform/fromExpress";
|
|
3
3
|
import { CtxRouter } from "./ctx/ctx.router";
|
|
4
4
|
import { CtxError } from "./ctx/ctx.err";
|
|
5
|
-
export type {
|
|
5
|
+
export type { TDefaultCtx };
|
|
6
6
|
export { USER_ROLE, CtxRouter, CtxError };
|
|
7
7
|
export declare namespace toCtx {
|
|
8
8
|
const fromExpress: typeof transformFromExpress;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAE1C,yBAAiB,KAAK,CAAC;IACd,MAAM,WAAW,6BAAuB,CAAC;CACjD"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAAyD;AAKhD,0FALa,qBAAS,OAKb;AAJlB,yDAA+D;AAC/D,iDAA6C;AAGzB,0FAHX,sBAAS,OAGW;AAF7B,2CAAyC;AAEV,yFAFtB,kBAAQ,OAEsB;AAEvC,IAAiB,KAAK,CAErB;AAFD,WAAiB,KAAK;IACP,iBAAW,GAAG,kCAAoB,CAAC;AAClD,CAAC,EAFgB,KAAK,qBAAL,KAAK,QAErB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
|
-
import {
|
|
3
|
-
export declare function transformFromExpress(req: Request):
|
|
2
|
+
import { TDefaultCtx } from "../ctx/ctx.types";
|
|
3
|
+
export declare function transformFromExpress(req: Request): TDefaultCtx;
|
|
4
4
|
//# sourceMappingURL=fromExpress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromExpress.d.ts","sourceRoot":"","sources":["../../src/transform/fromExpress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fromExpress.d.ts","sourceRoot":"","sources":["../../src/transform/fromExpress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAS/C,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAU9D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TDefaultCtx } from "../ctx/ctx.types";
|
|
2
2
|
type TCtxBuild = {
|
|
3
3
|
method: string;
|
|
4
4
|
path: string;
|
|
@@ -16,6 +16,8 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
16
16
|
createdAt: Date;
|
|
17
17
|
seq: number;
|
|
18
18
|
inflight: number;
|
|
19
|
+
cpu: number;
|
|
20
|
+
mem: number;
|
|
19
21
|
};
|
|
20
22
|
ts: {
|
|
21
23
|
in: Date;
|
|
@@ -27,8 +29,14 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
27
29
|
monitor: {
|
|
28
30
|
traceId: string;
|
|
29
31
|
spanId: string;
|
|
32
|
+
};
|
|
33
|
+
log: {
|
|
30
34
|
stdout: string[];
|
|
31
|
-
|
|
35
|
+
db: {
|
|
36
|
+
q: string;
|
|
37
|
+
p: unknown[];
|
|
38
|
+
ms: number;
|
|
39
|
+
}[];
|
|
32
40
|
};
|
|
33
41
|
};
|
|
34
42
|
req: {
|
|
@@ -41,7 +49,10 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
41
49
|
"x-ctx-api-version"?: string;
|
|
42
50
|
"x-ctx-session-id"?: string;
|
|
43
51
|
"x-ctx-seq"?: string;
|
|
52
|
+
"x-ctx-ts"?: string;
|
|
44
53
|
"x-ctx-refresh-token"?: string;
|
|
54
|
+
"x-ctx-csrf"?: string;
|
|
55
|
+
"x-ctx-trace-id"?: string;
|
|
45
56
|
[key: string]: string | string[] | undefined;
|
|
46
57
|
};
|
|
47
58
|
method: string;
|
|
@@ -55,14 +66,9 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
55
66
|
};
|
|
56
67
|
user: {
|
|
57
68
|
id: string;
|
|
58
|
-
role: keyof typeof USER_ROLE
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
os: string;
|
|
62
|
-
appVersion: string;
|
|
63
|
-
sessionId: string;
|
|
64
|
-
seq: number;
|
|
65
|
-
apiVersion: string;
|
|
69
|
+
role: Array<keyof typeof import("../ctx/ctx.types").USER_ROLE>;
|
|
70
|
+
scope: string[];
|
|
71
|
+
name: string | null;
|
|
66
72
|
auth: {
|
|
67
73
|
token: string;
|
|
68
74
|
refresh: string;
|
|
@@ -74,6 +80,7 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
74
80
|
data: {
|
|
75
81
|
[key: string]: unknown;
|
|
76
82
|
};
|
|
83
|
+
info?: unknown;
|
|
77
84
|
meta?: {
|
|
78
85
|
ctxId: string;
|
|
79
86
|
seq: number;
|
|
@@ -86,6 +93,6 @@ export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
|
86
93
|
};
|
|
87
94
|
};
|
|
88
95
|
};
|
|
89
|
-
export declare function doneCtx(ctx:
|
|
96
|
+
export declare function doneCtx(ctx: TDefaultCtx): Promise<void>;
|
|
90
97
|
export {};
|
|
91
98
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transform/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transform/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAa/C,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS;;;;;;;;;;;;;;;;eAqBvC,CAAC;oBAAoB,CAAC;;;;;;;;;;;;;;;;;yBAxCvB,CAAA;+BACe,CAAC;6BAEhB,CAAF;sBAAwB,CAAC;+BACvB,CAAD;+BAEQ,CAAC;8BACE,CAAC;uBAAyB,CAAC;sBAGtC,CAAC;iCAEA,CAAD;wBACU,CAAC;4BAA+B,CAAA;;;;;;kBAMV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOjC;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7D"}
|
package/dist/transform/index.js
CHANGED
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.buildCtx = buildCtx;
|
|
7
7
|
exports.doneCtx = doneCtx;
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const
|
|
9
|
+
const instanceId = crypto_1.default.randomBytes(5).toString("hex");
|
|
10
10
|
const INSTANCE = {
|
|
11
|
-
ID:
|
|
12
|
-
TRACE_ID:
|
|
11
|
+
ID: instanceId,
|
|
12
|
+
TRACE_ID: instanceId,
|
|
13
13
|
CREATED_AT: new Date(),
|
|
14
|
-
SERVICE_NAME: process.env.SERVICE_NAME || "
|
|
14
|
+
SERVICE_NAME: process.env.SERVICE_NAME || "my-service",
|
|
15
15
|
SEQ: 0,
|
|
16
16
|
INFLIGHT: 0,
|
|
17
17
|
LAST_HEARTBEAT: new Date(),
|
|
@@ -55,6 +55,8 @@ function buildMeta(ctxRaw) {
|
|
|
55
55
|
createdAt: INSTANCE.CREATED_AT,
|
|
56
56
|
seq: INSTANCE.SEQ,
|
|
57
57
|
inflight: INSTANCE.INFLIGHT,
|
|
58
|
+
cpu: 0,
|
|
59
|
+
mem: 0,
|
|
58
60
|
},
|
|
59
61
|
ts: {
|
|
60
62
|
in: inTime,
|
|
@@ -64,8 +66,10 @@ function buildMeta(ctxRaw) {
|
|
|
64
66
|
monitor: {
|
|
65
67
|
traceId: `${INSTANCE.ID}-${INSTANCE.SEQ}`,
|
|
66
68
|
spanId: `${INSTANCE.ID}-${INSTANCE.SEQ}`,
|
|
69
|
+
},
|
|
70
|
+
log: {
|
|
67
71
|
stdout: [],
|
|
68
|
-
|
|
72
|
+
db: [],
|
|
69
73
|
},
|
|
70
74
|
};
|
|
71
75
|
}
|
|
@@ -81,17 +85,11 @@ function buildReq(data) {
|
|
|
81
85
|
}
|
|
82
86
|
function buildUser(ctxRaw) {
|
|
83
87
|
const header = ctxRaw.header;
|
|
84
|
-
const clientSeq = Number(header["x-ctx-seq"]);
|
|
85
88
|
return {
|
|
86
89
|
id: "none",
|
|
87
|
-
role:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
deviceId: String(header["x-ctx-device-id"] || "none"),
|
|
91
|
-
deviceName: String(header["x-ctx-device-name"] || "none"),
|
|
92
|
-
appVersion: String(header["x-ctx-app-version"] || "none"),
|
|
93
|
-
os: String(header["x-ctx-os"] || "none"),
|
|
94
|
-
apiVersion: String(header["x-ctx-api-version"] || "none"),
|
|
90
|
+
role: [],
|
|
91
|
+
scope: [],
|
|
92
|
+
name: null,
|
|
95
93
|
auth: {
|
|
96
94
|
token: String(header["authorization"] || header["Authorization"] || "none"),
|
|
97
95
|
refresh: String(header["x-ctx-refresh-token"] || "none"),
|
|
@@ -107,9 +105,10 @@ function buildRes() {
|
|
|
107
105
|
}
|
|
108
106
|
function setResMeta(ctx) {
|
|
109
107
|
const meta = ctx.meta;
|
|
108
|
+
const clientSeq = parseInt(ctx.req.header["x-ctx-seq"] || "0");
|
|
110
109
|
ctx.res.meta = {
|
|
111
110
|
ctxId: ctx.id,
|
|
112
|
-
seq:
|
|
111
|
+
seq: Number.isInteger(clientSeq) ? clientSeq : 0,
|
|
113
112
|
traceId: meta.monitor.traceId,
|
|
114
113
|
spanId: meta.monitor.spanId,
|
|
115
114
|
inTime: meta.ts.in,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transform/index.ts"],"names":[],"mappings":";;;;;AAuBA,4BAOC;AAED,0BASC;AAzCD,oDAA4B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transform/index.ts"],"names":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,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;QAC7B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;QAC3B,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE;QAClB,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,GAAI;QACrB,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,QAAS;QAC3B,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG;KACjB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Context Router",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/
|
|
30
|
+
"url": "git+https://github.com/NeuronEnix/ctx-router.git"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
33
|
"ctx",
|
|
@@ -37,12 +37,13 @@
|
|
|
37
37
|
"author": "Kaushik R Bangera",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/NeuronEnix/ctx-router/issues"
|
|
41
41
|
},
|
|
42
|
-
"homepage": "https://github.com/
|
|
42
|
+
"homepage": "https://github.com/NeuronEnix/ctx-router#readme",
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@eslint/eslintrc": "^3.3.1",
|
|
45
45
|
"@eslint/js": "^9.33.0",
|
|
46
|
+
"@redis/client": "^5.8.2",
|
|
46
47
|
"@types/express": "^5.0.3",
|
|
47
48
|
"@types/node": "^24.3.0",
|
|
48
49
|
"@typescript-eslint/eslint-plugin": "^8.39.1",
|