@open-wa/cli 5.11.0 → 5.12.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 (2) hide show
  1. package/dist/bin.cjs +0 -162
  2. package/package.json +4 -5
package/dist/bin.cjs CHANGED
@@ -23,141 +23,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  const require_event_projection_store = require("./event-projection-store-C-W1A_Mi.cjs");
25
25
  let _open_wa_wa_automate = require("@open-wa/wa-automate");
26
- let ws = require("ws");
27
- ws = __toESM(ws, 1);
28
26
  let qrcode = require("qrcode");
29
27
  qrcode = __toESM(qrcode, 1);
30
- //#region src/tunnel-client.ts
31
- var TunnelClient = class {
32
- options;
33
- ws = null;
34
- reconnectTimeout = null;
35
- isDestroyed = false;
36
- constructor(options) {
37
- this.options = options;
38
- }
39
- log(level, message) {
40
- if (this.options.log) {
41
- this.options.log(level, message);
42
- return;
43
- }
44
- if (level === "warn") {
45
- console.warn(message);
46
- return;
47
- }
48
- if (level === "error") {
49
- console.error(message);
50
- return;
51
- }
52
- console.log(message);
53
- }
54
- connect() {
55
- if (this.isDestroyed) return;
56
- let urlStr = this.options.proxyHost;
57
- if (urlStr.startsWith("http")) urlStr = urlStr.replace(/^http/, "ws");
58
- const connectUrl = `${urlStr}/sessions/${encodeURIComponent(this.options.sessionId)}/upstream?token=${encodeURIComponent(this.options.proxyToken)}`;
59
- this.ws = new ws.default(connectUrl);
60
- this.ws.on("open", () => {
61
- this.log("info", `[TunnelClient] Connected upstream for session ${this.options.sessionId}`);
62
- });
63
- this.ws.on("message", async (data) => {
64
- let msg;
65
- try {
66
- msg = JSON.parse(data.toString("utf-8"));
67
- } catch {
68
- return;
69
- }
70
- if (msg.type === "ping") {
71
- this.ws?.send(JSON.stringify({ type: "pong" }));
72
- return;
73
- }
74
- if (msg.type === "http_request") await this.handleHttpRequest(msg);
75
- else if (msg.type === "rpc_request") await this.handleRpcAsHttp(msg);
76
- });
77
- this.ws.on("close", () => {
78
- if (!this.isDestroyed) {
79
- this.log("warn", `[TunnelClient] Disconnected. Reconnecting in 3s...`);
80
- this.reconnectTimeout = setTimeout(() => this.connect(), 3e3);
81
- }
82
- });
83
- this.ws.on("error", (err) => {
84
- this.log("error", `[TunnelClient] WebSocket error: ${err.message}`);
85
- });
86
- }
87
- async handleHttpRequest(msg) {
88
- const localUrl = `http://localhost:${this.options.localSessionPort}${msg.path}`;
89
- try {
90
- const fetchOpts = {
91
- method: msg.method,
92
- headers: msg.headers || {}
93
- };
94
- if (msg.body) {
95
- if (typeof msg.body === "string") fetchOpts.body = Buffer.from(msg.body, "base64");
96
- }
97
- const res = await fetch(localUrl, fetchOpts);
98
- const resBuffer = await res.arrayBuffer();
99
- const responseMsg = {
100
- type: "http_response",
101
- id: msg.id,
102
- status: res.status,
103
- headers: Object.fromEntries(res.headers.entries()),
104
- body: Buffer.from(resBuffer).toString("base64")
105
- };
106
- this.ws?.send(JSON.stringify(responseMsg));
107
- } catch (e) {
108
- this.log("error", `[TunnelClient] Failed to proxy http_request: ${e instanceof Error ? e.message : String(e)}`);
109
- this.ws?.send(JSON.stringify({
110
- type: "http_response",
111
- id: msg.id,
112
- status: 502,
113
- headers: { "content-type": "text/plain" },
114
- body: Buffer.from("Bad Gateway: " + e.message).toString("base64")
115
- }));
116
- }
117
- }
118
- async handleRpcAsHttp(msg) {
119
- const refreshControl = msg.method === "requestRefresh" || msg.method === "getRefreshStatus";
120
- const localUrl = `http://localhost:${this.options.localSessionPort}${refreshControl ? "/api/session/refresh" : `/api/${msg.method}`}`;
121
- try {
122
- const method = msg.method === "getRefreshStatus" ? "GET" : "POST";
123
- const res = await fetch(localUrl, {
124
- method,
125
- headers: {
126
- "Content-Type": "application/json",
127
- ...refreshControl && this.options.localApiKey ? { "X-API-Key": this.options.localApiKey } : {}
128
- },
129
- ...method === "POST" ? { body: JSON.stringify(refreshControl ? msg.args ?? {} : { args: msg.args }) } : {}
130
- });
131
- const resData = await res.json();
132
- if (refreshControl && !res.ok) throw new Error(resData.error || "Session controls are unavailable.");
133
- const responseMsg = {
134
- type: "rpc_response",
135
- id: msg.id,
136
- result: resData
137
- };
138
- this.ws?.send(JSON.stringify(responseMsg));
139
- } catch (e) {
140
- this.log("error", `[TunnelClient] Failed to proxy rpc_request: ${e instanceof Error ? e.message : String(e)}`);
141
- this.ws?.send(JSON.stringify({
142
- type: "rpc_response",
143
- id: msg.id,
144
- error: e.message
145
- }));
146
- }
147
- }
148
- destroy() {
149
- this.isDestroyed = true;
150
- if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
151
- if (this.ws) {
152
- this.ws.close();
153
- this.ws = null;
154
- }
155
- }
156
- disconnect() {
157
- this.destroy();
158
- }
159
- };
160
- //#endregion
161
28
  //#region src/presenter/interactive-terminal.ts
162
29
  var InteractiveTerminalPresenter = class {
163
30
  store;
@@ -350,13 +217,11 @@ async function main() {
350
217
  (0, _open_wa_wa_automate.setCliOutputSink)(session.sink);
351
218
  }
352
219
  let runtime;
353
- let tunnelClient;
354
220
  const shutdownController = require_event_projection_store.createShutdownController({
355
221
  timeoutMs: 1e4,
356
222
  gracefulShutdown: async (signal) => {
357
223
  await require_event_projection_store.performGracefulShutdown({
358
224
  runtime,
359
- tunnelClient,
360
225
  store
361
226
  }, signal);
362
227
  },
@@ -373,33 +238,6 @@ async function main() {
373
238
  return;
374
239
  }
375
240
  if (store) detachEvents = store.attachEmitter(runtime.events);
376
- if (runtime?.config.proxyHost && runtime.config.proxyToken) {
377
- const log = (level, message) => {
378
- if (broker) {
379
- broker.write(level, message);
380
- return;
381
- }
382
- if (level === "warn") {
383
- console.warn(message);
384
- return;
385
- }
386
- if (level === "error") {
387
- console.error(message);
388
- return;
389
- }
390
- console.log(message);
391
- };
392
- log("info", `[CLI] Starting TunnelClient connecting to ${runtime.config.proxyHost}...`);
393
- tunnelClient = new TunnelClient({
394
- proxyHost: runtime.config.proxyHost,
395
- proxyToken: runtime.config.proxyToken,
396
- sessionId: runtime.config.sessionId,
397
- localSessionPort: runtime.config.port,
398
- localApiKey: runtime.config.apiKey,
399
- log
400
- });
401
- tunnelClient.connect();
402
- }
403
241
  } catch (err) {
404
242
  const message = err instanceof Error ? `${err.message}${err.stack ? `\n${err.stack}` : ""}` : String(err);
405
243
  store?.projectStatus({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/cli",
3
- "version": "5.11.0",
3
+ "version": "5.12.0",
4
4
  "description": "CLI for @open-wa WhatsApp automation - Easy API mode",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.cjs",
@@ -18,13 +18,12 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@open-wa/core": "5.11.0",
22
- "@open-wa/hyperemitter": "5.11.0",
23
- "@open-wa/wa-automate": "5.11.0",
21
+ "@open-wa/core": "5.12.0",
22
+ "@open-wa/hyperemitter": "5.12.0",
23
+ "@open-wa/wa-automate": "5.12.0",
24
24
  "ink": "^7.1.1",
25
25
  "qrcode": "^1.5.4",
26
26
  "react": "^19.3.0",
27
- "ws": "^8.22.0",
28
27
  "zod": "^4.6.5"
29
28
  },
30
29
  "devDependencies": {