node-karin 1.3.21 → 1.3.22-pr.284.51e08fd

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 (41) hide show
  1. package/dist/index.js +83 -27
  2. package/dist/web/assets/cssMode-CbD7NRo2.js.gz +0 -0
  3. package/dist/web/assets/freemarker2-CmEg6ok0.js.gz +0 -0
  4. package/dist/web/assets/handlebars-Ba2z_L5p.js.gz +0 -0
  5. package/dist/web/assets/html-B_rLa2Iw.js.gz +0 -0
  6. package/dist/web/assets/htmlMode-elhiPcPa.js.gz +0 -0
  7. package/dist/web/assets/index-BGVAquX8.js +1 -0
  8. package/dist/web/assets/index-Bswf77Ah.js.gz +0 -0
  9. package/dist/web/assets/index-C93ejmwj.js +1 -0
  10. package/dist/web/assets/javascript-DAWnWc01.js.gz +0 -0
  11. package/dist/web/assets/jsonMode-DiAIRZf1.js.gz +0 -0
  12. package/dist/web/assets/liquid-7-OzV4NU.js.gz +0 -0
  13. package/dist/web/assets/mdx-DSznKLX2.js.gz +0 -0
  14. package/dist/web/assets/python-DHAwsB7p.js.gz +0 -0
  15. package/dist/web/assets/razor-C_mcHwHT.js.gz +0 -0
  16. package/dist/web/assets/ts.worker-Bd4z-OY3.js.gz +0 -0
  17. package/dist/web/assets/tsMode-DN8mHtc9.js.gz +0 -0
  18. package/dist/web/assets/typescript-BhTBqlRk.js.gz +0 -0
  19. package/dist/web/assets/xml-Bz_17ZdD.js.gz +0 -0
  20. package/dist/web/assets/yaml-lxHDnpl6.js.gz +0 -0
  21. package/dist/web/index.html +1 -1
  22. package/package.json +2 -1
  23. package/dist/web/assets/cssMode-CXt7sC6Q.js.gz +0 -0
  24. package/dist/web/assets/freemarker2-BLcwjvni.js.gz +0 -0
  25. package/dist/web/assets/handlebars-BeoMr5t2.js.gz +0 -0
  26. package/dist/web/assets/html--oHLJbOk.js.gz +0 -0
  27. package/dist/web/assets/htmlMode-CTOVHQWr.js.gz +0 -0
  28. package/dist/web/assets/index-2uUnpL8J.js +0 -1
  29. package/dist/web/assets/index-DGetM7dl.js.gz +0 -0
  30. package/dist/web/assets/index-DoJKQ5We.js +0 -1
  31. package/dist/web/assets/javascript-DoSLL0Rs.js.gz +0 -0
  32. package/dist/web/assets/jsonMode-BtZSHYnG.js.gz +0 -0
  33. package/dist/web/assets/liquid-119c8epZ.js.gz +0 -0
  34. package/dist/web/assets/mdx-BIG6P5wX.js.gz +0 -0
  35. package/dist/web/assets/python-BS9UkpxF.js.gz +0 -0
  36. package/dist/web/assets/razor-DEK9xP0N.js.gz +0 -0
  37. package/dist/web/assets/ts.worker-B_RpyLgm.js.gz +0 -0
  38. package/dist/web/assets/tsMode-6TGGnvhR.js.gz +0 -0
  39. package/dist/web/assets/typescript-CSABQyh4.js.gz +0 -0
  40. package/dist/web/assets/xml-DGLphCom.js.gz +0 -0
  41. package/dist/web/assets/yaml-7MPaJ_zV.js.gz +0 -0
package/dist/index.js CHANGED
@@ -14,9 +14,9 @@ var __export = (target, all) => {
14
14
  __defProp(target, name, { get: all[name], enumerable: true });
15
15
  };
16
16
 
17
- // ../../node_modules/.pnpm/tsup@8.3.6_@swc+core@1.10.18_@swc+helpers@0.5.15__jiti@1.21.7_postcss@8.5.3_tsx@4.19.3_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js
17
+ // ../../node_modules/.pnpm/tsup@8.4.0_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/esm_shims.js
18
18
  var init_esm_shims = __esm({
19
- "../../node_modules/.pnpm/tsup@8.3.6_@swc+core@1.10.18_@swc+helpers@0.5.15__jiti@1.21.7_postcss@8.5.3_tsx@4.19.3_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js"() {
19
+ "../../node_modules/.pnpm/tsup@8.4.0_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/esm_shims.js"() {
20
20
  "use strict";
21
21
  }
22
22
  });
@@ -2947,35 +2947,77 @@ var init_config2 = __esm({
2947
2947
  });
2948
2948
 
2949
2949
  // src/server/auth/index.ts
2950
- var auth;
2950
+ import jwt from "jsonwebtoken";
2951
+ import crypto from "node:crypto";
2952
+ var loginAuth, setToken2Level, verifyToken, auth;
2951
2953
  var init_auth = __esm({
2952
2954
  "src/server/auth/index.ts"() {
2953
2955
  "use strict";
2954
2956
  init_esm_shims();
2955
2957
  init_config2();
2958
+ init_index();
2959
+ loginAuth = async (req) => {
2960
+ var _a;
2961
+ const token = (_a = req == null ? void 0 : req.headers) == null ? void 0 : _a.password;
2962
+ if (!token) return false;
2963
+ const uToken = authKey();
2964
+ const hashedData = crypto.createHash("sha256").update(uToken).digest("hex");
2965
+ if (token === hashedData) {
2966
+ const payload = { userId: uToken, passWord: hashedData };
2967
+ const jwtToken = await setToken2Level(payload, payload.userId);
2968
+ await level.set(`HTTP_AUTH_TOKEN:${uToken}`, jwtToken);
2969
+ return true;
2970
+ }
2971
+ return false;
2972
+ };
2973
+ setToken2Level = async (payload, token) => {
2974
+ const secretKey = jwt.sign(payload, token, { expiresIn: "3h" });
2975
+ await level.set(`HTTP_AUTH_TOKEN:${payload.userId}`, secretKey);
2976
+ return secretKey;
2977
+ };
2978
+ verifyToken = async (secreKey, token) => {
2979
+ const uToken = authKey();
2980
+ const cacheSecreKey = await level.get(`HTTP_AUTH_TOKEN:${uToken}`);
2981
+ if (secreKey === cacheSecreKey || token === uToken) {
2982
+ try {
2983
+ const isValid = !!jwt.verify(secreKey, token);
2984
+ if (!isValid) return { status: false };
2985
+ return { status: true };
2986
+ } catch {
2987
+ logger.debug(logger.yellow("\u7F51\u9875\u767B\u5F55\u4EE4\u724C\u5DF2\u8FC7\u671F\uFF0C\u5C06\u91CD\u65B0\u91CD\u65B0\u751F\u6210\u4EE4\u724C"));
2988
+ const newsecreKey = crypto.createHash("sha256").update(token).digest("hex");
2989
+ const payload = { userId: uToken, passWord: newsecreKey };
2990
+ const newJwtToken = await setToken2Level(payload, payload.userId);
2991
+ return { status: true, newToken: newJwtToken };
2992
+ }
2993
+ }
2994
+ return { status: false };
2995
+ };
2956
2996
  auth = {
2957
2997
  /**
2958
2998
  * get请求鉴权
2959
2999
  * @description 支持请求头中携带`Authorization`字段
2960
3000
  * @description 支持请求参数中携带`token`字段
2961
3001
  */
2962
- getAuth: (req) => {
2963
- var _a, _b;
2964
- const token = ((_a = req == null ? void 0 : req.headers) == null ? void 0 : _a.authorization) || ((_b = req == null ? void 0 : req.query) == null ? void 0 : _b.token);
2965
- if (!token) return false;
2966
- const value = authKey();
2967
- return token === `Bearer ${value}` || token === value;
3002
+ getAuth: async (req) => {
3003
+ var _a, _b, _c;
3004
+ const secreKey = ((_b = (_a = req == null ? void 0 : req.headers) == null ? void 0 : _a.authorization) == null ? void 0 : _b.replace("Bearer ", "")) || ((_c = req == null ? void 0 : req.query) == null ? void 0 : _c.token);
3005
+ if (!secreKey) return { status: false };
3006
+ const uToken = authKey();
3007
+ const verifyStatus = await verifyToken(secreKey, uToken);
3008
+ return verifyStatus;
2968
3009
  },
2969
3010
  /**
2970
3011
  * post请求鉴权
2971
3012
  * @description 仅支持请求头中携带`Authorization`字段
2972
3013
  */
2973
- postAuth: (req) => {
2974
- var _a;
2975
- const token = (_a = req == null ? void 0 : req.headers) == null ? void 0 : _a.authorization;
2976
- if (!token) return false;
2977
- const value = authKey();
2978
- return token === `Bearer ${value}` || token === value;
3014
+ postAuth: async (req) => {
3015
+ var _a, _b;
3016
+ const secreKey = (_b = (_a = req == null ? void 0 : req.headers) == null ? void 0 : _a.authorization) == null ? void 0 : _b.replace("Bearer ", "");
3017
+ if (!secreKey) return { status: false };
3018
+ const uToken = authKey();
3019
+ const verifyStatus = await verifyToken(secreKey, uToken);
3020
+ return verifyStatus;
2979
3021
  }
2980
3022
  };
2981
3023
  }
@@ -3043,20 +3085,25 @@ headers: ${JSON.stringify(req.headers)}
3043
3085
  body: ${JSON.stringify(req.body)}
3044
3086
  `
3045
3087
  );
3046
- const Pass = auth.getAuth(req) || auth.postAuth(req);
3088
+ const checkResult = await auth.getAuth(req) || await auth.postAuth(req);
3089
+ const Pass = checkResult.status;
3047
3090
  if (req.path === "/ping" || req.path.startsWith("/console")) {
3048
3091
  next();
3049
3092
  return;
3050
3093
  }
3051
- if (!Pass && req.path === "/login") {
3052
- createServerErrorResponse(res, "HTTP \u9274\u6743\u5BC6\u94A5\u9519\u8BEF");
3094
+ const loginPass = await loginAuth(req);
3095
+ if (!loginPass && req.path === "/login") {
3096
+ createResponse(res, 500 /* InternalServerError */, { e: "HTTP \u9274\u6743\u5BC6\u94A5\u9519\u8BEF" }, "HTTP \u9274\u6743\u5BC6\u94A5\u9519\u8BEF");
3053
3097
  return;
3054
3098
  }
3055
- if (!Pass) {
3099
+ if (!Pass && req.path !== "/login") {
3056
3100
  createUnauthorizedResponse(res, "\u9274\u6743\u5931\u8D25 / check failed");
3057
3101
  logger.error(`[express][${req.ip}] \u9274\u6743\u9519\u8BEF: /api/v1/${req.path}`);
3058
3102
  return;
3059
3103
  }
3104
+ if (checkResult.newToken) {
3105
+ res.setHeader("authorization", checkResult.newToken);
3106
+ }
3060
3107
  next();
3061
3108
  };
3062
3109
  }
@@ -5669,6 +5716,7 @@ var init_log = __esm({
5669
5716
  });
5670
5717
 
5671
5718
  // src/server/api/system/login.ts
5719
+ import crypto2 from "crypto";
5672
5720
  var loginRouter;
5673
5721
  var init_login = __esm({
5674
5722
  "src/server/api/system/login.ts"() {
@@ -5676,8 +5724,16 @@ var init_login = __esm({
5676
5724
  init_esm_shims();
5677
5725
  init_router();
5678
5726
  init_response();
5727
+ init_index();
5728
+ init_config2();
5679
5729
  loginRouter = async (_req, res) => {
5680
- createSuccessResponse(res, null, "\u767B\u5F55\u6210\u529F");
5730
+ const uToken = authKey();
5731
+ const hashedData = crypto2.createHash("sha256").update(uToken).digest("hex");
5732
+ let authorization = "";
5733
+ if (_req.body.password === hashedData) {
5734
+ authorization = await level.get(`HTTP_AUTH_TOKEN:${uToken}`);
5735
+ }
5736
+ createSuccessResponse(res, { authorization }, "\u767B\u5F55\u6210\u529F");
5681
5737
  };
5682
5738
  router.post("/login", loginRouter);
5683
5739
  }
@@ -13720,7 +13776,7 @@ var init_cache4 = __esm({
13720
13776
 
13721
13777
  // src/adapter/render/connect/http.ts
13722
13778
  import axios9 from "axios";
13723
- import crypto from "node:crypto";
13779
+ import crypto3 from "node:crypto";
13724
13780
  var createHttpRenderClient;
13725
13781
  var init_http = __esm({
13726
13782
  "src/adapter/render/connect/http.ts"() {
@@ -13738,7 +13794,7 @@ var init_http = __esm({
13738
13794
  let { url, token, enable } = item;
13739
13795
  if (!enable) return;
13740
13796
  url = url.replace("/puppeteer", "");
13741
- const headers = { authorization: crypto.createHash("md5").update(`Bearer ${token}`).digest("hex") };
13797
+ const headers = { authorization: crypto3.createHash("md5").update(`Bearer ${token}`).digest("hex") };
13742
13798
  try {
13743
13799
  const result = await axios9.get(`${url}/ping`, { timeout: 5e3 });
13744
13800
  if (result.status !== 200 || String(result.data.status) !== "200") {
@@ -13865,7 +13921,7 @@ var init_template = __esm({
13865
13921
 
13866
13922
  // src/adapter/render/connect/ws.ts
13867
13923
  import fs28 from "node:fs";
13868
- import crypto2 from "node:crypto";
13924
+ import crypto4 from "node:crypto";
13869
13925
  var WebSocketRender;
13870
13926
  var init_ws2 = __esm({
13871
13927
  "src/adapter/render/connect/ws.ts"() {
@@ -13918,10 +13974,10 @@ var init_ws2 = __esm({
13918
13974
  auth(token, targetToken) {
13919
13975
  if (token !== targetToken) {
13920
13976
  if (token.length !== 32) {
13921
- token = crypto2.createHash("md5").update(`Bearer ${token}`).digest("hex");
13977
+ token = crypto4.createHash("md5").update(`Bearer ${token}`).digest("hex");
13922
13978
  }
13923
13979
  if (targetToken.length !== 32) {
13924
- targetToken = crypto2.createHash("md5").update(`Bearer ${targetToken}`).digest("hex");
13980
+ targetToken = crypto4.createHash("md5").update(`Bearer ${targetToken}`).digest("hex");
13925
13981
  }
13926
13982
  if (token !== targetToken) {
13927
13983
  return false;
@@ -13976,7 +14032,7 @@ var init_ws2 = __esm({
13976
14032
 
13977
14033
  // src/adapter/render/connect/client.ts
13978
14034
  import WebSocket from "ws";
13979
- import crypto3 from "node:crypto";
14035
+ import crypto5 from "node:crypto";
13980
14036
  var WebSocketClientRenderer, createWebSocketRenderClient;
13981
14037
  var init_client = __esm({
13982
14038
  "src/adapter/render/connect/client.ts"() {
@@ -14050,7 +14106,7 @@ var init_client = __esm({
14050
14106
  return Promise.allSettled(cfg.ws_client.map(async (item) => {
14051
14107
  const { url, token, enable } = item;
14052
14108
  if (!enable) return;
14053
- const headers = { Authorization: crypto3.createHash("md5").update(`Bearer ${token}`).digest("hex") };
14109
+ const headers = { Authorization: crypto5.createHash("md5").update(`Bearer ${token}`).digest("hex") };
14054
14110
  const socket = new WebSocket(url, { headers });
14055
14111
  const renderer = new WebSocketClientRenderer(socket, url, headers);
14056
14112
  socket.once("open", async () => {
@@ -0,0 +1 @@
1
+ import{d as a}from"./index-Bswf77Ah.js";var o=a;export{o as default};
@@ -0,0 +1 @@
1
+ import{d as a}from"./index-Bswf77Ah.js";var r=a;export{r as default};
@@ -14,7 +14,7 @@
14
14
  content="viewport-fit=cover, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
15
15
  name="viewport" />
16
16
  <link href="/web/assets/favicon-BoqZd694.ico" rel="icon" />
17
- <script type="module" crossorigin src="/web/assets/index-DGetM7dl.js"></script>
17
+ <script type="module" crossorigin src="/web/assets/index-Bswf77Ah.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/web/assets/index-CIP0gmfD.css">
19
19
  </head>
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.3.21",
3
+ "version": "1.3.22-pr.284.51e08fd",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",
@@ -76,6 +76,7 @@
76
76
  "commander": "^13.0.0",
77
77
  "dotenv": "^16.4.7",
78
78
  "express": "4.21.2",
79
+ "jsonwebtoken": "^9.0.2",
79
80
  "level": "9.0.0",
80
81
  "lodash": "4.17.21",
81
82
  "log4js": "6.9.1",
Binary file
@@ -1 +0,0 @@
1
- import{d as a}from"./index-DGetM7dl.js";var r=a;export{r as default};
@@ -1 +0,0 @@
1
- import{d as a}from"./index-DGetM7dl.js";var o=a;export{o as default};
Binary file
Binary file
Binary file