node-karin 1.0.4 → 1.0.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.0.9](https://github.com/KarinJS/Karin/compare/core-v1.0.8...core-v1.0.9) (2025-01-15)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * 哦~该死 ([aee10ea](https://github.com/KarinJS/Karin/commit/aee10eaa6c6b383f9c8e8953a614e49d653970e4))
9
+
10
+ ## [1.0.8](https://github.com/KarinJS/Karin/compare/core-v1.0.7...core-v1.0.8) (2025-01-15)
11
+
12
+
13
+ ### 🐛 Bug Fixes
14
+
15
+ * close [#217](https://github.com/KarinJS/Karin/issues/217) [#215](https://github.com/KarinJS/Karin/issues/215) ([75e9ea7](https://github.com/KarinJS/Karin/commit/75e9ea7268082fce53862bdca2f4156a3210039b))
16
+ * fix 215 ([036f40d](https://github.com/KarinJS/Karin/commit/036f40da34d599d5b5cc6e184c009bb09fa3d80b))
17
+
18
+ ## [1.0.7](https://github.com/KarinJS/Karin/compare/core-v1.0.6...core-v1.0.7) (2025-01-15)
19
+
20
+
21
+ ### 🐛 Bug Fixes
22
+
23
+ * build types error ([f732ca3](https://github.com/KarinJS/Karin/commit/f732ca38155f08adefed7a9f8d42d373a9fc9cc7))
24
+ * ci ([1d25234](https://github.com/KarinJS/Karin/commit/1d252344a1384314bab30e663be019c6d2536317))
25
+ * ci ([56b3823](https://github.com/KarinJS/Karin/commit/56b382335d63577078e5aa8572d6238c63caf3e9))
26
+ * registerBot ws_client ([a9d7905](https://github.com/KarinJS/Karin/commit/a9d7905b5c0c739eb1e8c64beafb658a3c12c64d))
27
+ * test ci ([e998b9d](https://github.com/KarinJS/Karin/commit/e998b9de51941141d842c1e6032fdc6c721efdf8))
28
+ * test ci ([d2c0771](https://github.com/KarinJS/Karin/commit/d2c077180e0f495dd5918a2cb2f0c51683192c0c))
29
+ * test ci ([437350f](https://github.com/KarinJS/Karin/commit/437350f3376af7bc7f3fca6e51e8c6d846f1d798))
30
+ * tips ([9f67525](https://github.com/KarinJS/Karin/commit/9f67525d592094532a3a29fe1f3de41bc1ec1936))
31
+ * version ([1b15d0b](https://github.com/KarinJS/Karin/commit/1b15d0b6c1583a8abc674b97cd746aac97b918c1))
32
+ * 导出 ([33b0683](https://github.com/KarinJS/Karin/commit/33b06831c3c4e6679edb3353962d88d7e2cb4d9b))
33
+
34
+
35
+ ### 🎫 Chores
36
+
37
+ * release main ([#219](https://github.com/KarinJS/Karin/issues/219)) ([bfe073f](https://github.com/KarinJS/Karin/commit/bfe073fa5af28364f12e3143bf3aab612cd87c59))
38
+ * release main ([#220](https://github.com/KarinJS/Karin/issues/220)) ([9cb7b59](https://github.com/KarinJS/Karin/commit/9cb7b59d003a1a3582d222413056af1d8ce5b13a))
39
+ * release main ([#221](https://github.com/KarinJS/Karin/issues/221)) ([0c871c5](https://github.com/KarinJS/Karin/commit/0c871c58b3fc26d5cb66b0d2f6e33a0c3bef4bb9))
40
+ * release main ([#224](https://github.com/KarinJS/Karin/issues/224)) ([abdf414](https://github.com/KarinJS/Karin/commit/abdf4149a171f8c9c58ea9f8d4cf7705690e1941))
41
+ * release main ([#225](https://github.com/KarinJS/Karin/issues/225)) ([4343d8d](https://github.com/KarinJS/Karin/commit/4343d8dab7f58f5c913345ee818d19ad14ebac48))
42
+ * release main ([#226](https://github.com/KarinJS/Karin/issues/226)) ([bedfe6a](https://github.com/KarinJS/Karin/commit/bedfe6a98d4637b59d0752565d353caf4a776251))
43
+ * **release:** node-karin 1.0.1 [skip-ci] ([#218](https://github.com/KarinJS/Karin/issues/218)) ([f3ce8b7](https://github.com/KarinJS/Karin/commit/f3ce8b7d0e7ad19ebe96a97e818e8aa4c52130c7))
44
+
45
+ ## [1.0.6](https://github.com/KarinJS/Karin/compare/node-karin-v1.0.5...node-karin-v1.0.6) (2025-01-15)
46
+
47
+
48
+ ### 🐛 Bug Fixes
49
+
50
+ * test ci ([e998b9d](https://github.com/KarinJS/Karin/commit/e998b9de51941141d842c1e6032fdc6c721efdf8))
51
+
52
+ ## [1.0.5](https://github.com/KarinJS/Karin/compare/node-karin-v1.0.4...node-karin-v1.0.5) (2025-01-15)
53
+
54
+
55
+ ### 🐛 Bug Fixes
56
+
57
+ * test ci ([d2c0771](https://github.com/KarinJS/Karin/commit/d2c077180e0f495dd5918a2cb2f0c51683192c0c))
58
+
3
59
  ## [1.0.4](https://github.com/KarinJS/Karin/compare/node-karin-v1.0.3...node-karin-v1.0.4) (2025-01-15)
4
60
 
5
61
 
@@ -87,11 +87,15 @@ var stop = () => {
87
87
  process.exit(0);
88
88
  };
89
89
  var restart = () => {
90
+ console.log("[pm2] \u91CD\u542F\u4E2D...");
90
91
  if (!fs2__default.default.existsSync(pm2Dir)) {
91
92
  console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
92
93
  console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
93
94
  process.exit(1);
94
95
  }
96
+ execSync(`pm2 restart ${pm2Dir}`, { cwd: process.cwd() });
97
+ console.log("[pm2] \u91CD\u542F\u6210\u529F");
98
+ process.exit(0);
95
99
  };
96
100
  var pm2 = {
97
101
  start,
package/dist/cli/index.js CHANGED
@@ -78,11 +78,15 @@ var stop = () => {
78
78
  process.exit(0);
79
79
  };
80
80
  var restart = () => {
81
+ console.log("[pm2] \u91CD\u542F\u4E2D...");
81
82
  if (!fs2.existsSync(pm2Dir)) {
82
83
  console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
83
84
  console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
84
85
  process.exit(1);
85
86
  }
87
+ execSync(`pm2 restart ${pm2Dir}`, { cwd: process.cwd() });
88
+ console.log("[pm2] \u91CD\u542F\u6210\u529F");
89
+ process.exit(0);
86
90
  };
87
91
  var pm2 = {
88
92
  start,
package/dist/index.d.ts CHANGED
@@ -8742,14 +8742,14 @@ type AxiosFn = {
8742
8742
  * 对axios进行简单封装,超时、错误后返回null,不会抛出异常
8743
8743
  * @param param axios参数
8744
8744
  */
8745
- (param: AxiosRequestConfig): Promise<AxiosResponse<any> | null>;
8745
+ (param: AxiosRequestConfig): Promise<AxiosResponse<any> | null | undefined>;
8746
8746
  /**
8747
8747
  * 对axios进行简单封装,超时、错误后返回null,不会抛出异常
8748
8748
  * @param url 请求地址
8749
8749
  * @param type 请求类型
8750
8750
  * @param param axios参数
8751
8751
  */
8752
- (url: string, type: 'get' | 'post', param?: AxiosRequestConfig): Promise<AxiosResponse<any> | null>;
8752
+ (url: string, type: 'get' | 'post', param?: AxiosRequestConfig): Promise<AxiosResponse<any> | null | undefined>;
8753
8753
  };
8754
8754
  interface NpmInfo {
8755
8755
  plugin: string;
@@ -8768,6 +8768,7 @@ interface NpmInfo {
8768
8768
  declare const sleep: (ms: number) => Promise<unknown>;
8769
8769
  /**
8770
8770
  * axios请求
8771
+ * @description 401时返回 `undefined`
8771
8772
  * @param paramOrUrl axios参数或url
8772
8773
  * @param type 请求类型 只有在传入url时有效
8773
8774
  * @param param axios参数 只有在传入url时有效
package/dist/index.js CHANGED
@@ -2718,8 +2718,8 @@ __export(common_exports, {
2718
2718
  writeYaml: () => write
2719
2719
  });
2720
2720
  import fs13 from "node:fs";
2721
- import Axios from "axios";
2722
2721
  import path9 from "node:path";
2722
+ import Axios, { AxiosError as AxiosError2 } from "axios";
2723
2723
  var sleep, axios3, uptime2, formatTime2, updateYaml, getNpmPlugins, getPlugins2, getGitPlugins, mergeImage, getAbsPath, getImageSize, generateLayout, buildFilterComplex;
2724
2724
  var init_common = __esm({
2725
2725
  "src/utils/common/index.ts"() {
@@ -2742,10 +2742,14 @@ var init_common = __esm({
2742
2742
  init_message();
2743
2743
  sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2744
2744
  axios3 = async (paramOrUrl, type, param) => {
2745
+ var _a;
2745
2746
  try {
2746
2747
  const config2 = typeof paramOrUrl === "string" ? { ...param, url: paramOrUrl, method: type } : paramOrUrl;
2747
2748
  return await Axios(config2);
2748
2749
  } catch (error) {
2750
+ if (error instanceof AxiosError2) {
2751
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) return void 0;
2752
+ }
2749
2753
  logger.debug("[common] axios\u8BF7\u6C42\u5931\u8D25:");
2750
2754
  logger.debug(error.stack || error);
2751
2755
  return null;
@@ -3870,10 +3874,14 @@ var init_process = __esm({
3870
3874
  return;
3871
3875
  }
3872
3876
  logger.error("\u68C0\u6D4B\u5230\u540E\u53F0\u8FDB\u7A0B \u6B63\u5728\u5173\u95ED...");
3873
- await axios3({ url: `${host2}/exit`, method: "get", timeout: 500 });
3877
+ const result = await axios3({ url: `${host2}/exit`, method: "get", timeout: 500 });
3878
+ if (typeof result === "undefined") {
3879
+ logger.fatal(logger.red(`\u5F53\u524D\u5B58\u5728\u591A\u5F00Bot\u5360\u7528 ${port2}\u7AEF\u53E3\uFF0C\u8BF7\u66F4\u6362\u7AEF\u53E3\u6216\u8005\u5173\u95ED\u5BF9\u5E94Bot`));
3880
+ processExit(1);
3881
+ }
3874
3882
  for (let i = 0; i < 100; i++) {
3875
- const result = await axios3({ url: `${host2}/ping`, method: "get", timeout: 100 });
3876
- if (result) {
3883
+ const result2 = await axios3({ url: `${host2}/ping`, method: "get", timeout: 100 });
3884
+ if (result2) {
3877
3885
  await sleep(50);
3878
3886
  continue;
3879
3887
  }
@@ -8890,12 +8898,33 @@ var init_ws2 = __esm({
8890
8898
 
8891
8899
  // src/adapter/render/connect/client.ts
8892
8900
  import WebSocket from "ws";
8901
+ import crypto2 from "node:crypto";
8902
+ var WebSocketClientRenderer, createWebSocketRenderClient;
8893
8903
  var init_client = __esm({
8894
8904
  async "src/adapter/render/connect/client.ts"() {
8895
8905
  "use strict";
8896
8906
  init_esm_shims();
8897
8907
  init_ws2();
8898
8908
  await init_render();
8909
+ WebSocketClientRenderer = class extends WebSocketRender {
8910
+ };
8911
+ createWebSocketRenderClient = () => {
8912
+ const cfg = render();
8913
+ if (!cfg.ws_client || !Array.isArray(cfg.ws_client) || cfg.ws_client.length === 0) {
8914
+ logger.trace("[render][WebSocket] \u672A\u914D\u7F6E\u4EFB\u4F55\u6B63\u5411WebSocket \u5DF2\u8DF3\u8FC7\u521B\u5EFA");
8915
+ return;
8916
+ }
8917
+ return Promise.allSettled(cfg.ws_client.map(async (item) => {
8918
+ const { url, token, enable } = item;
8919
+ if (!enable) return;
8920
+ const headers = { Authorization: crypto2.createHash("md5").update(`Bearer ${token}`).digest("hex") };
8921
+ const socket = new WebSocket(url, { headers });
8922
+ socket.once("open", async () => {
8923
+ logger.info(`[render][WebSocket] \u8FDE\u63A5\u6210\u529F: ${url}`);
8924
+ await new WebSocketClientRenderer(socket).init();
8925
+ });
8926
+ }));
8927
+ };
8899
8928
  }
8900
8929
  });
8901
8930
 
@@ -8945,7 +8974,7 @@ var init_server2 = __esm({
8945
8974
 
8946
8975
  // src/adapter/render/connect/http.ts
8947
8976
  import axios4 from "axios";
8948
- import crypto2 from "node:crypto";
8977
+ import crypto3 from "node:crypto";
8949
8978
  var createHttpRenderClient;
8950
8979
  var init_http = __esm({
8951
8980
  async "src/adapter/render/connect/http.ts"() {
@@ -8963,7 +8992,7 @@ var init_http = __esm({
8963
8992
  let { url, token, enable } = item;
8964
8993
  if (!enable) return;
8965
8994
  url = url.replace("/puppeteer", "");
8966
- const headers = { authorization: crypto2.createHash("md5").update(`Bearer ${token}`).digest("hex") };
8995
+ const headers = { authorization: crypto3.createHash("md5").update(`Bearer ${token}`).digest("hex") };
8967
8996
  try {
8968
8997
  const result = await axios4.get(`${url}/ping`, { timeout: 5e3 });
8969
8998
  if (result.status !== 200 || String(result.data.status) !== "200") {
@@ -9022,7 +9051,11 @@ var init_render2 = __esm({
9022
9051
  await init_client();
9023
9052
  await init_server2();
9024
9053
  await init_http();
9025
- createHttpRenderClient();
9054
+ await init_client();
9055
+ setTimeout(() => {
9056
+ createHttpRenderClient();
9057
+ createWebSocketRenderClient();
9058
+ }, 1e3);
9026
9059
  }
9027
9060
  });
9028
9061
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.0.4",
3
+ "version": "1.0.9",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",
@@ -91,7 +91,7 @@
91
91
  "access": "public",
92
92
  "registry": "https://registry.npmjs.org"
93
93
  },
94
- "time": "2025-01-15",
94
+ "time": "2025-01-15-2",
95
95
  "exports": {
96
96
  ".": {
97
97
  "import": "./dist/index.js",