Update deps to latest and align tests

This commit is contained in:
Peter Steinberger
2025-11-24 17:33:59 +01:00
parent 657188a7e2
commit f88b3ceb7a
4 changed files with 39 additions and 30 deletions

View File

@@ -38,8 +38,8 @@
"json5": "^2.2.3",
"qrcode-terminal": "^0.12.0",
"twilio": "^5.10.6",
"@whiskeysockets/baileys": "^6.7.7",
"pino": "^9.4.0"
"pino": "^10.1.0",
"baileys": "^7.0.0-rc.9"
},
"devDependencies": {
"@biomejs/biome": "^2.3.7",
@@ -49,6 +49,11 @@
"@types/node": "^24.10.1",
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"vitest": "^2.1.4"
"vitest": "^4.0.13"
},
"vitest": {
"exclude": [
"dist/**"
]
}
}

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { normalizeE164, toWhatsappJid, assertProvider } from "./index.js";
import { assertProvider, normalizeE164, toWhatsappJid } from "./index.js";
describe("normalizeE164", () => {
it("strips whatsapp: prefix and whitespace", () => {

View File

@@ -5,23 +5,23 @@ import net from "node:net";
import os from "node:os";
import path from "node:path";
import process, { stdin as input, stdout as output } from "node:process";
import { fileURLToPath } from "node:url";
import readline from "node:readline/promises";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import bodyParser from "body-parser";
import chalk from "chalk";
import { Command } from "commander";
import dotenv from "dotenv";
import express, { type Request, type Response } from "express";
import JSON5 from "json5";
import type { ConnectionState } from "baileys";
import {
DisconnectReason,
fetchLatestBaileysVersion,
makeCacheableSignalKeyStore,
makeWASocket,
useMultiFileAuthState,
} from "@whiskeysockets/baileys";
import type { ConnectionState } from "@whiskeysockets/baileys";
} from "baileys";
import bodyParser from "body-parser";
import chalk from "chalk";
import { Command } from "commander";
import dotenv from "dotenv";
import express, { type Request, type Response } from "express";
import JSON5 from "json5";
import pino from "pino";
import qrcode from "qrcode-terminal";
import Twilio from "twilio";
@@ -729,10 +729,13 @@ async function createWaSocket(printQr: boolean, verbose: boolean) {
qrcode.generate(qr, { small: true });
}
if (connection === "close") {
const code = (lastDisconnect?.error as { output?: { statusCode?: number } })
?.output?.statusCode;
const code = (
lastDisconnect?.error as { output?: { statusCode?: number } }
)?.output?.statusCode;
if (code === DisconnectReason.loggedOut) {
console.error(danger("WhatsApp session logged out. Run: warelay web:login"));
console.error(
danger("WhatsApp session logged out. Run: warelay web:login"),
);
}
}
if (connection === "open" && verbose) {
@@ -745,22 +748,23 @@ async function createWaSocket(printQr: boolean, verbose: boolean) {
async function waitForWaConnection(sock: ReturnType<typeof makeWASocket>) {
return new Promise<void>((resolve, reject) => {
const handler = (update: Partial<ConnectionState>) => {
type OffCapable = {
off?: (event: string, listener: (...args: unknown[]) => void) => void;
};
const evWithOff = sock.ev as unknown as OffCapable;
const handler = (...args: unknown[]) => {
const update = (args[0] ?? {}) as Partial<ConnectionState>;
if (update.connection === "open") {
(sock.ev as unknown as { off?: Function }).off?.(
"connection.update",
handler,
);
evWithOff.off?.("connection.update", handler);
resolve();
}
if (update.connection === "close") {
(sock.ev as unknown as { off?: Function }).off?.(
"connection.update",
handler,
);
evWithOff.off?.("connection.update", handler);
reject(update.lastDisconnect ?? new Error("Connection closed"));
}
};
sock.ev.on("connection.update", handler);
});
}
@@ -778,9 +782,7 @@ async function sendMessageWeb(to: string, body: string) {
const result = await sock.sendMessage(jid, { text: body });
const messageId = result?.key?.id ?? "unknown";
console.log(
success(
`✅ Sent via web session. Message ID: ${messageId} -> ${jid}`,
),
success(`✅ Sent via web session. Message ID: ${messageId} -> ${jid}`),
);
} finally {
try {
@@ -1579,7 +1581,9 @@ Examples:
if (opts.provider === "web") {
if (waitSeconds !== 0) {
console.log(info("Wait/poll are Twilio-only; ignored for provider=web."));
console.log(
info("Wait/poll are Twilio-only; ignored for provider=web."),
);
}
await sendMessageWeb(opts.to, opts.message);
return;

View File

@@ -14,5 +14,5 @@
"allowSyntheticDefaultImports": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "src/**/*.test.ts", "src/**/*.test.tsx"]
}