@ezychat/wa 0.0.0-stage → 0.1.39

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.
@@ -0,0 +1,96 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { type BaileysEventMap, type MessageUpsertType, type MessageUserReceiptUpdate, type WAMessageUpdate, type WAMessage } from 'baileys';
3
+ import type { WaStatus } from '@ezychat/shared';
4
+ import { type SendResult, type WaAdapter, type WaAdapterEvents, type WaAdapterOptions, type WaContactAlias, type WaGroupInfo, type WaMessageStatusUpdate, type WaSendFile, type WaSendOptions } from '../types.js';
5
+ /** True when a send error means "the connection went away" (retry later) rather than a real rejection. */
6
+ export declare function isConnectionError(err: unknown): boolean;
7
+ /** Per-participant group receipt → our status (read wins over delivered). */
8
+ export declare function receiptStatus(r: MessageUserReceiptUpdate['receipt']): WaMessageStatusUpdate['status'] | null;
9
+ /**
10
+ * Real WhatsApp connection via Baileys (WhatsApp Web multi-device protocol).
11
+ * This is the only module in the repo allowed to import `baileys`.
12
+ */
13
+ /**
14
+ * Browser identity sent at registration. WhatsApp terminates the registration (428 before any QR)
15
+ * for 'Desktop' identities such as Browsers.appropriate('Desktop'); a Chrome web client is accepted
16
+ * and is also required for phone-number pairing codes.
17
+ */
18
+ export declare const WA_BROWSER: [string, string, string];
19
+ /** Digits only, with country code (8–15 digits, E.164 without '+'). */
20
+ export declare function normalizePairingPhone(phone: string): string;
21
+ export declare class BaileysAdapter extends EventEmitter implements WaAdapter {
22
+ private _status;
23
+ private sock;
24
+ private readonly auth;
25
+ private readonly logger;
26
+ private readonly historyDaysOpt;
27
+ private raw;
28
+ private attempt;
29
+ private reconnectTimer;
30
+ /** true when the socket was closed on purpose (disconnect/logout/replaced/blocked). */
31
+ private stopped;
32
+ private connecting;
33
+ private signalKeys;
34
+ private readonly contactAliases;
35
+ /** Invalidates local-key reads when a socket closes or the linked account changes. */
36
+ private aliasGeneration;
37
+ constructor(opts: WaAdapterOptions);
38
+ /** current history_days (re-read each time so a settings change applies on the next relink) */
39
+ private get historyDays();
40
+ get status(): WaStatus;
41
+ on<K extends keyof WaAdapterEvents>(ev: K, fn: (...a: WaAdapterEvents[K]) => void): this;
42
+ off<K extends keyof WaAdapterEvents>(ev: K, fn: (...a: WaAdapterEvents[K]) => void): this;
43
+ private emitTyped;
44
+ private setStatus;
45
+ connect(): Promise<void>;
46
+ disconnect(): Promise<void>;
47
+ logout(): Promise<void>;
48
+ takeover(): Promise<void>;
49
+ /**
50
+ * Link by phone number instead of QR: returns the 8-character code the user types in
51
+ * WhatsApp → Linked devices → Link with phone number instead.
52
+ */
53
+ requestPairingCode(phone: string): Promise<string>;
54
+ /** The socket can request a code once the server has offered a QR (i.e. registration started). */
55
+ private waitForPairingReady;
56
+ private clearReconnect;
57
+ private closeSocket;
58
+ private scheduleReconnect;
59
+ private open;
60
+ private onConnectionUpdate;
61
+ private handleClose;
62
+ private historyCutoff;
63
+ /**
64
+ * messages.upsert. 'notify' = live; 'append' = messages queued while we were offline (or our own
65
+ * sends / notifications) — also live: they are new to us, must bump unread / reopen / notify, and
66
+ * must never be dropped by the history cutoff. Only messaging-history.set is history.
67
+ * @internal exposed for tests
68
+ */
69
+ handleUpsert(messages: WAMessage[], _type: MessageUpsertType): void;
70
+ /** @internal exposed for tests */
71
+ handleMessageUpdates(updates: WAMessageUpdate[]): void;
72
+ /** @internal exposed for tests */
73
+ handleReceipts(updates: MessageUserReceiptUpdate[]): void;
74
+ private ingest;
75
+ /** @internal exposed for tests */
76
+ onHistory(h: BaileysEventMap['messaging-history.set']): void;
77
+ private emitContacts;
78
+ private clearContactAliases;
79
+ /** Cache and emit only explicit PN/LID associations; reject contradictory associations. */
80
+ private emitAliasPairs;
81
+ private rememberAlias;
82
+ getContactAliases(jids: string[]): Promise<WaContactAlias[]>;
83
+ private emitChats;
84
+ private emitGroups;
85
+ private download;
86
+ private requireOpen;
87
+ private send;
88
+ sendText(chatJid: string, text: string, opts?: WaSendOptions): Promise<SendResult>;
89
+ sendMedia(chatJid: string, file: WaSendFile, opts?: WaSendOptions): Promise<SendResult>;
90
+ markRead(chatJid: string, messageIds: string[]): Promise<void>;
91
+ sendPresence(chatJid: string, presence: 'composing' | 'paused'): Promise<void>;
92
+ downloadMedia(messageId: string): Promise<Buffer | null>;
93
+ getGroupInfo(groupJid: string): Promise<WaGroupInfo>;
94
+ getAbout(jid: string): Promise<string | null>;
95
+ getProfilePicture(jid: string): Promise<string | null>;
96
+ }