@unlinearity/cli-wechat-bridge 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.
@@ -88,6 +88,49 @@ function readJsonFile(filePath) {
88
88
  function isRecord(value) {
89
89
  return typeof value === "object" && value !== null;
90
90
  }
91
+ function readNumericResponseField(response, key) {
92
+ const value = response[key];
93
+ if (typeof value === "number" && Number.isFinite(value)) {
94
+ return value;
95
+ }
96
+ if (typeof value === "string" && value.trim()) {
97
+ const parsed = Number(value);
98
+ return Number.isFinite(parsed) ? parsed : undefined;
99
+ }
100
+ return undefined;
101
+ }
102
+ function readStringResponseField(response, key) {
103
+ const value = response[key];
104
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
105
+ }
106
+ export function assertWechatApiResponseOk(endpoint, raw) {
107
+ const trimmed = raw.trim();
108
+ if (!trimmed) {
109
+ return;
110
+ }
111
+ let response;
112
+ try {
113
+ response = JSON.parse(trimmed);
114
+ }
115
+ catch {
116
+ return;
117
+ }
118
+ if (!isRecord(response)) {
119
+ return;
120
+ }
121
+ const ret = readNumericResponseField(response, "ret");
122
+ const errcode = readNumericResponseField(response, "errcode");
123
+ const failed = (ret !== undefined && ret !== 0) ||
124
+ (errcode !== undefined && errcode !== 0);
125
+ if (!failed) {
126
+ return;
127
+ }
128
+ const errmsg = readStringResponseField(response, "errmsg") ??
129
+ readStringResponseField(response, "message") ??
130
+ readStringResponseField(response, "msg") ??
131
+ "";
132
+ throw new Error(`${endpoint} failed: ret=${ret} errcode=${errcode} errmsg=${errmsg}`);
133
+ }
91
134
  function describeErrorNode(value) {
92
135
  if (value instanceof Error) {
93
136
  const error = value;
@@ -587,7 +630,7 @@ export class WeChatTransport {
587
630
  if (rawMessage.context_token) {
588
631
  this.cacheContextToken(senderId, rawMessage.context_token);
589
632
  }
590
- const createdAtMs = rawMessage.create_time_ms;
633
+ const createdAtMs = rawMessage.create_time_ms ?? 0;
591
634
  if (typeof options.minCreatedAtMs === "number" &&
592
635
  (!Number.isFinite(createdAtMs) || createdAtMs < options.minCreatedAtMs)) {
593
636
  ignoredBacklogCount += 1;
@@ -736,7 +779,7 @@ export class WeChatTransport {
736
779
  ]);
737
780
  }
738
781
  async sendMessage(account, recipientId, contextToken, itemList) {
739
- await apiFetch({
782
+ const raw = await apiFetch({
740
783
  baseUrl: account.baseUrl,
741
784
  endpoint: "ilink/bot/sendmessage",
742
785
  body: JSON.stringify({
@@ -754,6 +797,7 @@ export class WeChatTransport {
754
797
  token: account.token,
755
798
  timeoutMs: SEND_TIMEOUT_MS,
756
799
  });
800
+ assertWechatApiResponseOk("sendmessage", raw);
757
801
  }
758
802
  async prepareUpload(account, recipientId, filePath, mediaType, label) {
759
803
  const stat = this.requireExistingFile(filePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unlinearity/cli-wechat-bridge",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CLI WeChat Bridge for Codex, Claude Code, OpenCode, and PowerShell over WeChat",
5
5
  "type": "module",
6
6
  "files": [
@@ -50,6 +50,11 @@
50
50
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
51
51
  "build": "npm run clean && tsc -p tsconfig.build.json",
52
52
  "prepack": "npm run build",
53
+ "lint": "eslint bin src test",
54
+ "lint:fix": "eslint bin src test --fix",
55
+ "typecheck:src": "tsc -p tsconfig.typecheck.src.json --noEmit --pretty false",
56
+ "quality": "npm run lint && npm run typecheck:src && bun test test && npm run build",
57
+ "smoke:global": "node scripts/smoke-global-install.mjs",
53
58
  "setup": "node --no-warnings --experimental-strip-types src/wechat/setup.ts",
54
59
  "start": "node --no-warnings --experimental-strip-types src/wechat/wechat-channel.ts",
55
60
  "check": "node --no-warnings --experimental-strip-types src/wechat/wechat-channel.ts --check",
@@ -80,8 +85,11 @@
80
85
  "qrcode-terminal": "^0.12.0"
81
86
  },
82
87
  "devDependencies": {
88
+ "@eslint/js": "^10.0.1",
83
89
  "@types/bun": "latest",
84
- "typescript": "^6.0.2"
90
+ "eslint": "^10.3.0",
91
+ "typescript": "^6.0.2",
92
+ "typescript-eslint": "^8.59.3"
85
93
  },
86
94
  "engines": {
87
95
  "bun": ">=1.0.0",