@ih8e/express-cli 0.1.2 → 0.1.3

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/index.js CHANGED
@@ -6,6 +6,9 @@ import { Command as Command15 } from "commander";
6
6
  // src/cli/auth.ts
7
7
  import { Command } from "commander";
8
8
 
9
+ // src/config/loader.ts
10
+ import { ZodError } from "zod";
11
+
9
12
  // src/types/config.ts
10
13
  import { z } from "zod";
11
14
  var configSchema = z.object({
@@ -135,7 +138,18 @@ function loadConfig(cliOverrides = {}) {
135
138
  const storedToken = getAuthToken();
136
139
  if (storedToken) merged.token = storedToken;
137
140
  }
138
- return configSchema.parse(merged);
141
+ try {
142
+ return configSchema.parse(merged);
143
+ } catch (err) {
144
+ if (err instanceof ZodError) {
145
+ const details = err.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
146
+ throw new Error(`Configuration error:
147
+ ${details}
148
+
149
+ Run: express-cli config set host <hostname>`);
150
+ }
151
+ throw err;
152
+ }
139
153
  }
140
154
  function getBaseUrl(config) {
141
155
  return `${config.protocol}://${config.host}`;
@@ -1946,6 +1960,7 @@ import { Command as Command5 } from "commander";
1946
1960
  import chalk2 from "chalk";
1947
1961
 
1948
1962
  // src/api/websocket.ts
1963
+ import WebSocket from "ws";
1949
1964
  import { randomUUID as randomUUID3 } from "crypto";
1950
1965
  async function fetchChatListViaWebSocket(params) {
1951
1966
  const { host, ctsToken, encryptionKeyId, timeoutMs = 15e3 } = params;
@@ -2037,20 +2052,24 @@ var ChatsApi = class {
2037
2052
  const ctsToken = getAuthToken();
2038
2053
  const keys = loadApigwKeys();
2039
2054
  const ctsKeyId = (keys?.ctsKey ?? keys?.encryptionKey)?.keyId;
2040
- if (ctsToken && ctsKeyId) {
2041
- try {
2042
- return await fetchChatListViaWebSocket({
2043
- host,
2044
- ctsToken,
2045
- encryptionKeyId: ctsKeyId
2046
- });
2047
- } catch (err) {
2048
- if (process.env.EXPRESS_DEBUG) {
2049
- console.error(` [DEBUG] WebSocket failed, falling back to directory: ${err.message}`);
2050
- }
2051
- }
2055
+ if (!ctsToken || !ctsKeyId) {
2056
+ console.error(
2057
+ !ctsToken ? "Warning: no auth token \u2014 run `express-cli auth import <token>` or `express-cli auth qr`" : "Warning: no encryption keys \u2014 run `express-cli auth qr` to authenticate"
2058
+ );
2059
+ console.error("Falling back to corporate directory (shows only global/public chats).\n");
2060
+ return this.listChatsViaDirectory();
2061
+ }
2062
+ try {
2063
+ return await fetchChatListViaWebSocket({
2064
+ host,
2065
+ ctsToken,
2066
+ encryptionKeyId: ctsKeyId
2067
+ });
2068
+ } catch (err) {
2069
+ console.error(`Warning: WebSocket failed (${err.message}), falling back to corporate directory.
2070
+ `);
2071
+ return this.listChatsViaDirectory();
2052
2072
  }
2053
- return this.listChatsViaDirectory();
2054
2073
  }
2055
2074
  async listChatsViaDirectory() {
2056
2075
  const data = await this.client.get("/api/v1/corporate_directory/entries");
@@ -2529,6 +2548,7 @@ var MessagingApi = class {
2529
2548
  };
2530
2549
 
2531
2550
  // src/api/messaging-ws.ts
2551
+ import WebSocket2 from "ws";
2532
2552
  import { randomBytes as randomBytes3, randomUUID as randomUUID4 } from "crypto";
2533
2553
  import nacl4 from "tweetnacl";
2534
2554
  import sodium from "libsodium-wrappers-sumo";
@@ -2635,7 +2655,7 @@ async function getChatKeyIds(host, webOrigin, ctsToken, encKeyId, chatId) {
2635
2655
  }
2636
2656
  done(() => reject(new Error("Timeout getting chat key_ids")));
2637
2657
  }, 1e4);
2638
- const ws = new WebSocket(wsUrl, {
2658
+ const ws = new WebSocket2(wsUrl, {
2639
2659
  headers: { Origin: webOrigin, "User-Agent": "Mozilla/5.0" }
2640
2660
  });
2641
2661
  let ref = 0;
@@ -2688,7 +2708,7 @@ async function sendMessageNew(params) {
2688
2708
  }
2689
2709
  done(() => reject(new Error("Timeout sending message")));
2690
2710
  }, timeoutMs);
2691
- const ws = new WebSocket(wsUrl, {
2711
+ const ws = new WebSocket2(wsUrl, {
2692
2712
  headers: { Origin: webOrigin, "User-Agent": "Mozilla/5.0" }
2693
2713
  });
2694
2714
  let ref = 0;
@@ -2926,6 +2946,7 @@ function createDownloadCommand() {
2926
2946
  import { Command as Command11 } from "commander";
2927
2947
 
2928
2948
  // src/api/messages-read.ts
2949
+ import WebSocket3 from "ws";
2929
2950
  import { randomUUID as randomUUID5 } from "crypto";
2930
2951
 
2931
2952
  // src/api/decrypt.ts
@@ -3029,7 +3050,7 @@ async function fetchEventsHistory(host, webOrigin, ctsToken, encKeyId, chatId, l
3029
3050
  }
3030
3051
  done(() => reject(new Error("Timeout fetching messages")));
3031
3052
  }, timeoutMs);
3032
- const ws = new WebSocket(wsUrl, {
3053
+ const ws = new WebSocket3(wsUrl, {
3033
3054
  headers: { Origin: webOrigin, "User-Agent": "Mozilla/5.0" }
3034
3055
  });
3035
3056
  let ref = 0;
@@ -3122,6 +3143,7 @@ import { Command as Command12 } from "commander";
3122
3143
  import chalk4 from "chalk";
3123
3144
 
3124
3145
  // src/session/session.ts
3146
+ import WebSocket4 from "ws";
3125
3147
  import { EventEmitter } from "events";
3126
3148
  import { randomUUID as randomUUID6 } from "crypto";
3127
3149
  var HEARTBEAT_MS = 25e3;
@@ -3175,7 +3197,7 @@ var ExpressSession = class _ExpressSession extends EventEmitter {
3175
3197
  throw new Error("Not authenticated. Run 'express auth qr'.");
3176
3198
  }
3177
3199
  const url = `wss://${this.host}/socket/user/websocket?vsn=1.0.0&auto_join=true&key_id=${this.keyId}&version=6&background=false&voex_unencrypted=true&voex_multistream=true&voex_audio_bridge=true&instance_id=${randomUUID6()}`;
3178
- const ws = new WebSocket(url, {
3200
+ const ws = new WebSocket4(url, {
3179
3201
  headers: { Origin: this.webOrigin, "User-Agent": "Mozilla/5.0" }
3180
3202
  });
3181
3203
  this.ws = ws;
@@ -4033,7 +4055,7 @@ function createMcpCommand() {
4033
4055
  // src/cli/root.ts
4034
4056
  function createRootCommand() {
4035
4057
  const program2 = new Command15();
4036
- program2.name("express-cli").description("CLI client for eXpress Chat").version("0.1.2");
4058
+ program2.name("express-cli").description("CLI client for eXpress Chat").version("0.1.3");
4037
4059
  program2.addCommand(createAuthCommand());
4038
4060
  program2.addCommand(createApiCommand());
4039
4061
  program2.addCommand(createConfigCommand());