@arcaelas/whatsapp 4.5.0 → 5.1.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.
- package/build/cjs/index.d.ts +6 -4
- package/build/cjs/index.js +22 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/lib/bot/decorator.d.ts +2 -0
- package/build/cjs/lib/bot/decorator.js +6 -0
- package/build/cjs/lib/bot/decorator.js.map +1 -1
- package/build/cjs/lib/chat/index.d.ts +340 -204
- package/build/cjs/lib/chat/index.js +225 -213
- package/build/cjs/lib/chat/index.js.map +1 -1
- package/build/cjs/lib/contact/index.d.ts +162 -179
- package/build/cjs/lib/contact/index.js +96 -190
- package/build/cjs/lib/contact/index.js.map +1 -1
- package/build/cjs/lib/internal.d.ts +40 -0
- package/build/cjs/lib/internal.js +39 -0
- package/build/cjs/lib/internal.js.map +1 -0
- package/build/cjs/lib/message/index.d.ts +462 -289
- package/build/cjs/lib/message/index.js +825 -741
- package/build/cjs/lib/message/index.js.map +1 -1
- package/build/cjs/lib/status/index.d.ts +60 -70
- package/build/cjs/lib/status/index.js +106 -111
- package/build/cjs/lib/status/index.js.map +1 -1
- package/build/cjs/lib/store/engine/index.d.ts +21 -7
- package/build/cjs/lib/store/engine/index.js +6 -3
- package/build/cjs/lib/store/engine/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/cjs/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
- package/build/cjs/lib/store/engine/lib/index.js +213 -0
- package/build/cjs/lib/store/engine/lib/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/cjs/lib/store/engine/lib/redis/index.js +56 -42
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/cjs/lib/store/engine/lib/s3/index.js +112 -64
- package/build/cjs/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js +114 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +7 -3
- package/build/cjs/lib/store/index.js +14 -4
- package/build/cjs/lib/store/index.js.map +1 -1
- package/build/cjs/lib/whatsapp/index.d.ts +106 -68
- package/build/cjs/lib/whatsapp/index.js +380 -170
- package/build/cjs/lib/whatsapp/index.js.map +1 -1
- package/build/cjs/test.js +5 -4
- package/build/cjs/test.js.map +1 -1
- package/build/esm/index.d.ts +6 -4
- package/build/esm/index.js +5 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/bot/decorator.d.ts +2 -0
- package/build/esm/lib/bot/decorator.js +6 -0
- package/build/esm/lib/bot/decorator.js.map +1 -1
- package/build/esm/lib/chat/index.d.ts +340 -204
- package/build/esm/lib/chat/index.js +225 -213
- package/build/esm/lib/chat/index.js.map +1 -1
- package/build/esm/lib/contact/index.d.ts +162 -179
- package/build/esm/lib/contact/index.js +96 -189
- package/build/esm/lib/contact/index.js.map +1 -1
- package/build/esm/lib/internal.d.ts +40 -0
- package/build/esm/lib/internal.js +35 -0
- package/build/esm/lib/internal.js.map +1 -0
- package/build/esm/lib/message/index.d.ts +462 -289
- package/build/esm/lib/message/index.js +820 -736
- package/build/esm/lib/message/index.js.map +1 -1
- package/build/esm/lib/status/index.d.ts +60 -70
- package/build/esm/lib/status/index.js +105 -110
- package/build/esm/lib/status/index.js.map +1 -1
- package/build/esm/lib/store/engine/index.d.ts +21 -7
- package/build/esm/lib/store/engine/index.js +4 -2
- package/build/esm/lib/store/engine/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/esm/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
- package/build/esm/lib/store/engine/lib/index.js +206 -0
- package/build/esm/lib/store/engine/lib/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/esm/lib/store/engine/lib/redis/index.js +54 -40
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/esm/lib/store/engine/lib/s3/index.js +111 -63
- package/build/esm/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js +110 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +7 -3
- package/build/esm/lib/store/index.js +13 -4
- package/build/esm/lib/store/index.js.map +1 -1
- package/build/esm/lib/whatsapp/index.d.ts +106 -68
- package/build/esm/lib/whatsapp/index.js +382 -172
- package/build/esm/lib/whatsapp/index.js.map +1 -1
- package/build/esm/test.js +5 -4
- package/build/esm/test.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,70 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @file contact/index.ts
|
|
4
|
-
* @description Entidad Contact —
|
|
5
|
-
* Contact entity —
|
|
4
|
+
* @description Entidad Contact — una ficha mínima derivada del raw del contacto.
|
|
5
|
+
* Contact entity — a minimal card derived from the raw contact document.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.Contact = void 0;
|
|
9
|
-
exports.contact_name = contact_name;
|
|
10
9
|
exports.contact = contact;
|
|
11
10
|
const baileys_1 = require("baileys");
|
|
11
|
+
const internal_1 = require("../../lib/internal");
|
|
12
12
|
const store_1 = require("../../lib/store");
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param raw - Documento persistido del contacto / Persisted contact document
|
|
18
|
-
* @returns Nombre mostrado / Display name
|
|
19
|
-
*/
|
|
20
|
-
function contact_name(raw) {
|
|
21
|
-
return raw.name ?? raw.notify ?? raw.id.split('@')[0];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Clase base del contacto (forma pública, solo lectura).
|
|
25
|
-
* Base Contact class (public shape, read-only).
|
|
14
|
+
* Clase base del contacto: recibe el raw de baileys y deriva todo con getters.
|
|
15
|
+
* Base Contact class: receives the baileys raw and derives everything via getters.
|
|
26
16
|
*/
|
|
27
17
|
class Contact {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @internal Documento crudo del contacto en snake_case. `id` llega en formato LID o PN
|
|
20
|
+
* según el addressing; `phone_number` es el JID PN cuando baileys lo conoce.
|
|
21
|
+
* Raw contact document in snake_case. `id` arrives in LID or PN format depending on
|
|
22
|
+
* addressing; `phone_number` is the PN JID when baileys knows it.
|
|
23
|
+
*/
|
|
24
|
+
constructor(_raw) {
|
|
25
|
+
this._raw = _raw;
|
|
31
26
|
}
|
|
32
|
-
/**
|
|
33
|
-
get
|
|
34
|
-
|
|
27
|
+
/** Nombre: agenda → público → verificado → teléfono. / Name: address book → public → verified → phone. */
|
|
28
|
+
get name() {
|
|
29
|
+
const { name, notify, verified_name } = this._raw;
|
|
30
|
+
return name ?? notify ?? verified_name ?? this.phone ?? this._raw.id.split('@')[0];
|
|
35
31
|
}
|
|
36
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* JID legado (`@s.whatsapp.net`): el reportado por baileys o generado desde el id
|
|
34
|
+
* cuando ya viene en formato PN; null si no es determinable.
|
|
35
|
+
* Legacy JID (`@s.whatsapp.net`): the one baileys reports or generated from the id
|
|
36
|
+
* when it is already PN-formatted; null when not determinable.
|
|
37
|
+
*/
|
|
37
38
|
get jid() {
|
|
38
|
-
|
|
39
|
+
if (this._raw.phone_number)
|
|
40
|
+
return (0, baileys_1.jidNormalizedUser)(this._raw.phone_number);
|
|
41
|
+
if (this._raw.id.endsWith('@s.whatsapp.net'))
|
|
42
|
+
return (0, baileys_1.jidNormalizedUser)(this._raw.id);
|
|
43
|
+
return null;
|
|
39
44
|
}
|
|
40
|
-
/** LID si
|
|
45
|
+
/** LID (`@lid`) cuando es definible; null si no. / LID (`@lid`) when definable; null otherwise. */
|
|
41
46
|
get lid() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
+
if (this._raw.lid)
|
|
48
|
+
return this._raw.lid;
|
|
49
|
+
if (this._raw.id.endsWith('@lid'))
|
|
50
|
+
return this._raw.id;
|
|
51
|
+
return null;
|
|
47
52
|
}
|
|
48
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Teléfono del contacto, derivado únicamente del JID PN (nunca del LID);
|
|
55
|
+
* null cuando no hay JID determinable.
|
|
56
|
+
* Contact phone, derived from the PN JID only (never from the LID);
|
|
57
|
+
* null when no JID is determinable.
|
|
58
|
+
*/
|
|
49
59
|
get phone() {
|
|
50
|
-
return this.
|
|
60
|
+
return this.jid?.split('@')[0] ?? null;
|
|
51
61
|
}
|
|
52
|
-
/** URL de foto de perfil. / Profile picture URL. */
|
|
62
|
+
/** URL de la foto de perfil, o null. / Profile picture URL, or null. */
|
|
53
63
|
get photo() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/** Bio del contacto. / Contact bio. */
|
|
57
|
-
get content() {
|
|
58
|
-
return this._raw.status ?? '';
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Chat 1:1 asociado al contacto. Async por coherencia con `Message.chat()` /
|
|
62
|
-
* `Message.author()`, aunque la instancia ya está hidratada en memoria.
|
|
63
|
-
* 1:1 chat associated with the contact. Async for consistency with
|
|
64
|
-
* `Message.chat()` / `Message.author()`, though already hydrated in memory.
|
|
65
|
-
*/
|
|
66
|
-
async chat() {
|
|
67
|
-
return this._chat;
|
|
64
|
+
const url = this._raw.img_url;
|
|
65
|
+
return url?.startsWith('http') ? url : null;
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
exports.Contact = Contact;
|
|
@@ -75,173 +73,81 @@ exports.Contact = Contact;
|
|
|
75
73
|
* @param wa - Instancia principal / Main WhatsApp instance
|
|
76
74
|
*/
|
|
77
75
|
function contact(wa) {
|
|
78
|
-
/**
|
|
79
|
-
* Descubre el JID canónico y el LID (cuando aplica) de un número consultando al socket.
|
|
80
|
-
* Discovers the canonical JID and LID (when applicable) of a phone number via the socket.
|
|
81
|
-
*/
|
|
82
|
-
async function discover_by_phone(phone) {
|
|
83
|
-
let result = null;
|
|
84
|
-
if (wa._socket && phone.length > 0) {
|
|
85
|
-
const found = (await wa._socket.onWhatsApp(phone))?.[0];
|
|
86
|
-
if (found?.exists) {
|
|
87
|
-
result = { jid: (0, baileys_1.jidNormalizedUser)(found.jid), lid: found.lid ?? null };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Obtiene foto y bio del contacto desde el socket.
|
|
94
|
-
* Fetches profile picture and bio from the socket.
|
|
95
|
-
*/
|
|
96
|
-
async function fetch_profile_data(id) {
|
|
97
|
-
let img_url = null;
|
|
98
|
-
let status = null;
|
|
99
|
-
if (wa._socket) {
|
|
100
|
-
try {
|
|
101
|
-
img_url = (await wa._socket.profilePictureUrl(id, 'image')) ?? null;
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
/* may not exist */
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const result = await wa._socket.fetchStatus(id);
|
|
108
|
-
const data = result?.[0];
|
|
109
|
-
status = data?.status?.status ?? null;
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
/* may fail */
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return { img_url, status };
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Carga la instancia Chat 1:1 del contacto. Si no existe en engine, fabrica una mínima.
|
|
119
|
-
* Loads the 1:1 Chat instance for a contact. Falls back to a minimal instance if missing.
|
|
120
|
-
*/
|
|
121
|
-
async function load_chat_for(jid, fallback_name) {
|
|
122
|
-
const cached = (0, store_1.deserialize)(await wa.engine.get(`/chat/${jid}`));
|
|
123
|
-
return new wa.Chat(cached ?? { id: jid, name: fallback_name });
|
|
124
|
-
}
|
|
125
76
|
return class _Contact extends Contact {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Chat 1:1 del contacto: el persistido en el engine, o una instancia mínima.
|
|
79
|
+
* The contact's 1:1 chat: the engine-persisted one, or a minimal instance.
|
|
80
|
+
*
|
|
81
|
+
* @returns Instancia de Chat / Chat instance
|
|
82
|
+
*/
|
|
130
83
|
async chat() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
get me() {
|
|
135
|
-
const self_id = wa._socket?.user?.id;
|
|
136
|
-
return Boolean(self_id) && (0, baileys_1.jidNormalizedUser)(self_id) === this.id;
|
|
84
|
+
const cid = this.jid ?? this.lid ?? this._raw.id;
|
|
85
|
+
const cached = (0, store_1.deserialize)(await wa.engine.get(`/chat/${cid}`));
|
|
86
|
+
return new wa.Chat(cached ?? { id: cid, name: this.name });
|
|
137
87
|
}
|
|
138
88
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
89
|
+
* Carga un contacto por teléfono, JID o LID: primero el engine; si no está
|
|
90
|
+
* persistido lo descubre por red (`onWhatsApp` + foto + bio) y lo materializa.
|
|
91
|
+
* Loads a contact by phone, JID or LID: engine first; when not persisted it
|
|
92
|
+
* discovers it over the network (`onWhatsApp` + photo + bio) and materializes it.
|
|
142
93
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* - If `uid` lacks `@` → digits are extracted and `socket.onWhatsApp(phone)` resolves the canonical JID.
|
|
94
|
+
* @param uid - Teléfono, JID o LID / Phone, JID or LID
|
|
95
|
+
* @returns Contacto o null si no existe en WhatsApp / Contact or null when not on WhatsApp
|
|
146
96
|
*/
|
|
147
97
|
static async get(uid) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
else {
|
|
155
|
-
const discovered = await discover_by_phone(uid.replace(/\D+/g, ''));
|
|
156
|
-
if (discovered) {
|
|
157
|
-
jid = discovered.jid;
|
|
158
|
-
lid = discovered.lid;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
98
|
+
const digits = String(uid).replace(/\D+/g, '');
|
|
99
|
+
const jid = String(uid).includes('@')
|
|
100
|
+
? await (0, internal_1.internals)(wa).resolve_jid(String(uid))
|
|
101
|
+
: digits
|
|
102
|
+
? `${digits}@s.whatsapp.net`
|
|
103
|
+
: null;
|
|
161
104
|
if (jid && !jid.endsWith('@g.us')) {
|
|
162
105
|
const cached = (0, store_1.deserialize)(await wa.engine.get(`/contact/${jid}`));
|
|
163
|
-
if (cached)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
106
|
+
if (cached)
|
|
107
|
+
return new _Contact(cached);
|
|
108
|
+
const socket = (0, internal_1.internals)(wa).socket;
|
|
109
|
+
if (socket) {
|
|
110
|
+
const found = (await socket.onWhatsApp(jid.split('@')[0]))?.[0];
|
|
111
|
+
if (found?.exists) {
|
|
112
|
+
const id = (0, baileys_1.jidNormalizedUser)(found.jid);
|
|
113
|
+
const img_url = await socket.profilePictureUrl(id, 'image').catch(() => null);
|
|
114
|
+
const status = await socket
|
|
115
|
+
.fetchStatus(id)
|
|
116
|
+
.then((result) => result?.[0]?.status?.status ?? null)
|
|
117
|
+
.catch(() => null);
|
|
173
118
|
const raw = {
|
|
174
|
-
id
|
|
175
|
-
lid:
|
|
119
|
+
id,
|
|
120
|
+
lid: found.lid ?? null,
|
|
121
|
+
phone_number: id,
|
|
176
122
|
name: null,
|
|
177
123
|
notify: null,
|
|
178
124
|
verified_name: null,
|
|
179
|
-
img_url,
|
|
125
|
+
img_url: img_url ?? null,
|
|
180
126
|
status,
|
|
181
127
|
};
|
|
182
|
-
await wa.engine.set(`/contact/${
|
|
183
|
-
if (
|
|
184
|
-
await wa.engine.set(`/lid/${
|
|
128
|
+
await wa.engine.set(`/contact/${id}`, (0, store_1.serialize)(raw));
|
|
129
|
+
if (found.lid) {
|
|
130
|
+
await wa.engine.set(`/lid/${found.lid}`, (0, store_1.serialize)(id));
|
|
185
131
|
}
|
|
186
|
-
|
|
132
|
+
return new _Contact(raw);
|
|
187
133
|
}
|
|
188
134
|
}
|
|
189
135
|
}
|
|
190
|
-
return
|
|
136
|
+
return null;
|
|
191
137
|
}
|
|
192
138
|
/**
|
|
193
|
-
* Pagina los contactos persistidos
|
|
194
|
-
* Paginates persisted contacts
|
|
139
|
+
* Pagina los contactos persistidos.
|
|
140
|
+
* Paginates persisted contacts.
|
|
141
|
+
*
|
|
142
|
+
* @param offset - Desplazamiento / Offset
|
|
143
|
+
* @param limit - Tamaño de página / Page size
|
|
144
|
+
* @returns Página de contactos / Contact page
|
|
195
145
|
*/
|
|
196
146
|
static async list(offset = 0, limit = 50) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
contacts.push(new _Contact(parsed, await load_chat_for(parsed.id, contact_name(parsed))));
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return contacts;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Renombra localmente un contacto por id.
|
|
208
|
-
* Renames a contact locally by id.
|
|
209
|
-
*/
|
|
210
|
-
static async rename(uid, name) {
|
|
211
|
-
const c = await _Contact.get(uid);
|
|
212
|
-
return c ? c.rename(name) : false;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Re-hidrata los datos del contacto por id desde el socket.
|
|
216
|
-
* Re-hydrates contact data from the socket by id.
|
|
217
|
-
*/
|
|
218
|
-
static async refresh(uid) {
|
|
219
|
-
const c = await _Contact.get(uid);
|
|
220
|
-
return c ? c.refresh() : null;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
224
|
-
* Renames the contact locally (device address book only).
|
|
225
|
-
*/
|
|
226
|
-
async rename(name) {
|
|
227
|
-
this._raw.name = name;
|
|
228
|
-
await wa.engine.set(`/contact/${this.id}`, (0, store_1.serialize)(this._raw));
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Re-hidrata foto y bio desde el socket.
|
|
233
|
-
* Re-hydrates profile picture and bio from the socket.
|
|
234
|
-
*/
|
|
235
|
-
async refresh() {
|
|
236
|
-
let ok = false;
|
|
237
|
-
if (wa._socket) {
|
|
238
|
-
const { img_url, status } = await fetch_profile_data(this.id);
|
|
239
|
-
this._raw.img_url = img_url;
|
|
240
|
-
this._raw.status = status;
|
|
241
|
-
await wa.engine.set(`/contact/${this.id}`, (0, store_1.serialize)(this._raw));
|
|
242
|
-
ok = true;
|
|
243
|
-
}
|
|
244
|
-
return ok ? this : null;
|
|
147
|
+
return (await wa.engine.list('/contact', offset, limit))
|
|
148
|
+
.map((raw) => (0, store_1.deserialize)(raw))
|
|
149
|
+
.filter((parsed) => parsed !== null)
|
|
150
|
+
.map((parsed) => new _Contact(parsed));
|
|
245
151
|
}
|
|
246
152
|
};
|
|
247
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/contact/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/contact/index.ts"],"names":[],"mappings":";AAAA;;;;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MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,EAAE,IAAA,iBAAS,EAAC,GAAG,CAAC,CAAC,CAAC;wBACtD,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;4BACd,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC,GAAG,EAAE,EAAE,IAAA,iBAAS,EAAC,EAAE,CAAC,CAAC,CAAC;wBAC1D,CAAC;wBACD,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED;;;;;;;WAOG;QACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE;YACtC,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;iBACrD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,mBAAW,EAAkB,GAAG,CAAC,CAAC;iBAC/C,MAAM,CAAC,CAAC,MAAM,EAA6B,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC;iBAC9D,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file internal.ts
|
|
3
|
+
* @description Canal privado entre el cliente y sus entidades. Vive en un `WeakMap` fuera de
|
|
4
|
+
* la instancia, así el socket de baileys y la resolución de JIDs quedan disponibles para
|
|
5
|
+
* `Contact`, `Chat`, `Message` y `Feed` sin exponerse en la superficie pública de `WhatsApp`:
|
|
6
|
+
* el consumidor sólo ve `on`/`once`/`off`/`emit` y los métodos documentados.
|
|
7
|
+
* Private channel between the client and its entities. It lives in a `WeakMap` outside the
|
|
8
|
+
* instance, so the baileys socket and JID resolution stay available to `Contact`, `Chat`,
|
|
9
|
+
* `Message` and `Feed` without surfacing on `WhatsApp`'s public API: consumers only see
|
|
10
|
+
* `on`/`once`/`off`/`emit` and the documented methods.
|
|
11
|
+
*/
|
|
12
|
+
import type { WASocket } from 'baileys';
|
|
13
|
+
/**
|
|
14
|
+
* Estado que el cliente comparte con sus entidades.
|
|
15
|
+
* State the client shares with its entities.
|
|
16
|
+
*/
|
|
17
|
+
export interface Internals {
|
|
18
|
+
/** Socket vivo de baileys, o null mientras no hay conexión. / Live baileys socket, or null while disconnected. */
|
|
19
|
+
socket: WASocket | null;
|
|
20
|
+
/** Normaliza cualquier identificador (JID, LID o teléfono) a JID canónico. / Normalizes any identifier (JID, LID or phone) into a canonical JID. */
|
|
21
|
+
resolve_jid(uid: string): Promise<string | null>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Publica el estado interno de un cliente para las entidades de la librería.
|
|
25
|
+
* Publishes a client's internal state for the library entities.
|
|
26
|
+
*
|
|
27
|
+
* @param owner - Cliente dueño del estado / Client owning the state
|
|
28
|
+
* @param state - Estado compartido, mutable por el cliente / Shared state, mutated by the client
|
|
29
|
+
*/
|
|
30
|
+
export declare function bind(owner: object, state: Internals): void;
|
|
31
|
+
/**
|
|
32
|
+
* Estado interno del cliente. Sólo lo resuelven los módulos de la librería: el objeto
|
|
33
|
+
* nunca se expone al consumidor.
|
|
34
|
+
* A client's internal state. Only library modules resolve it: the object is never exposed
|
|
35
|
+
* to the consumer.
|
|
36
|
+
*
|
|
37
|
+
* @param owner - Cliente construido por la librería / Client built by the library
|
|
38
|
+
* @returns Estado compartido / Shared state
|
|
39
|
+
*/
|
|
40
|
+
export declare function internals(owner: object): Internals;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file internal.ts
|
|
4
|
+
* @description Canal privado entre el cliente y sus entidades. Vive en un `WeakMap` fuera de
|
|
5
|
+
* la instancia, así el socket de baileys y la resolución de JIDs quedan disponibles para
|
|
6
|
+
* `Contact`, `Chat`, `Message` y `Feed` sin exponerse en la superficie pública de `WhatsApp`:
|
|
7
|
+
* el consumidor sólo ve `on`/`once`/`off`/`emit` y los métodos documentados.
|
|
8
|
+
* Private channel between the client and its entities. It lives in a `WeakMap` outside the
|
|
9
|
+
* instance, so the baileys socket and JID resolution stay available to `Contact`, `Chat`,
|
|
10
|
+
* `Message` and `Feed` without surfacing on `WhatsApp`'s public API: consumers only see
|
|
11
|
+
* `on`/`once`/`off`/`emit` and the documented methods.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.bind = bind;
|
|
15
|
+
exports.internals = internals;
|
|
16
|
+
const channel = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Publica el estado interno de un cliente para las entidades de la librería.
|
|
19
|
+
* Publishes a client's internal state for the library entities.
|
|
20
|
+
*
|
|
21
|
+
* @param owner - Cliente dueño del estado / Client owning the state
|
|
22
|
+
* @param state - Estado compartido, mutable por el cliente / Shared state, mutated by the client
|
|
23
|
+
*/
|
|
24
|
+
function bind(owner, state) {
|
|
25
|
+
channel.set(owner, state);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Estado interno del cliente. Sólo lo resuelven los módulos de la librería: el objeto
|
|
29
|
+
* nunca se expone al consumidor.
|
|
30
|
+
* A client's internal state. Only library modules resolve it: the object is never exposed
|
|
31
|
+
* to the consumer.
|
|
32
|
+
*
|
|
33
|
+
* @param owner - Cliente construido por la librería / Client built by the library
|
|
34
|
+
* @returns Estado compartido / Shared state
|
|
35
|
+
*/
|
|
36
|
+
function internals(owner) {
|
|
37
|
+
return channel.get(owner);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/lib/internal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAwBH,oBAEC;AAWD,8BAEC;AAxBD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAqB,CAAC;AAEjD;;;;;;GAMG;AACH,SAAgB,IAAI,CAAC,KAAa,EAAE,KAAgB;IAChD,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,KAAa;IACnC,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC;AAC/B,CAAC"}
|