@arcaelas/whatsapp 4.5.0 → 6.0.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 (106) hide show
  1. package/README.md +282 -239
  2. package/build/cjs/decorators.js +0 -1
  3. package/build/cjs/index.d.ts +6 -4
  4. package/build/cjs/index.js +22 -3
  5. package/build/cjs/lib/bot/decorator.d.ts +2 -0
  6. package/build/cjs/lib/bot/decorator.js +6 -1
  7. package/build/cjs/lib/bot/decorators.d.ts +2 -2
  8. package/build/cjs/lib/bot/decorators.js +4 -4
  9. package/build/cjs/lib/bot/index.js +0 -1
  10. package/build/cjs/lib/chat/index.d.ts +381 -204
  11. package/build/cjs/lib/chat/index.js +243 -212
  12. package/build/cjs/lib/contact/index.d.ts +162 -179
  13. package/build/cjs/lib/contact/index.js +96 -191
  14. package/build/cjs/lib/internal.d.ts +40 -0
  15. package/build/cjs/lib/internal.js +38 -0
  16. package/build/cjs/lib/message/index.d.ts +468 -289
  17. package/build/cjs/lib/message/index.js +871 -743
  18. package/build/cjs/lib/status/index.d.ts +60 -70
  19. package/build/cjs/lib/status/index.js +106 -112
  20. package/build/cjs/lib/store/engine/index.d.ts +35 -7
  21. package/build/cjs/lib/store/engine/index.js +6 -4
  22. package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +48 -8
  23. package/build/cjs/lib/store/engine/lib/file_system/index.js +117 -66
  24. package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
  25. package/build/cjs/lib/store/engine/lib/index.js +212 -0
  26. package/build/cjs/lib/store/engine/lib/redis/index.d.ts +44 -15
  27. package/build/cjs/lib/store/engine/lib/redis/index.js +75 -43
  28. package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
  29. package/build/cjs/lib/store/engine/lib/s3/index.js +112 -65
  30. package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +110 -0
  31. package/build/cjs/lib/store/engine/lib/sqlite/index.js +132 -0
  32. package/build/cjs/lib/store/index.d.ts +7 -3
  33. package/build/cjs/lib/store/index.js +14 -5
  34. package/build/cjs/lib/whatsapp/index.d.ts +106 -68
  35. package/build/cjs/lib/whatsapp/index.js +393 -167
  36. package/build/esm/decorators.js +0 -1
  37. package/build/esm/index.d.ts +6 -4
  38. package/build/esm/index.js +5 -3
  39. package/build/esm/lib/bot/decorator.d.ts +2 -0
  40. package/build/esm/lib/bot/decorator.js +6 -1
  41. package/build/esm/lib/bot/decorators.d.ts +2 -2
  42. package/build/esm/lib/bot/decorators.js +4 -4
  43. package/build/esm/lib/bot/index.js +0 -1
  44. package/build/esm/lib/chat/index.d.ts +381 -204
  45. package/build/esm/lib/chat/index.js +243 -212
  46. package/build/esm/lib/contact/index.d.ts +162 -179
  47. package/build/esm/lib/contact/index.js +96 -190
  48. package/build/esm/lib/internal.d.ts +40 -0
  49. package/build/esm/lib/internal.js +34 -0
  50. package/build/esm/lib/message/index.d.ts +468 -289
  51. package/build/esm/lib/message/index.js +866 -738
  52. package/build/esm/lib/status/index.d.ts +60 -70
  53. package/build/esm/lib/status/index.js +105 -111
  54. package/build/esm/lib/store/engine/index.d.ts +35 -7
  55. package/build/esm/lib/store/engine/index.js +4 -3
  56. package/build/esm/lib/store/engine/lib/file_system/index.d.ts +48 -8
  57. package/build/esm/lib/store/engine/lib/file_system/index.js +117 -66
  58. package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
  59. package/build/esm/lib/store/engine/lib/index.js +205 -0
  60. package/build/esm/lib/store/engine/lib/redis/index.d.ts +44 -15
  61. package/build/esm/lib/store/engine/lib/redis/index.js +73 -41
  62. package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
  63. package/build/esm/lib/store/engine/lib/s3/index.js +111 -64
  64. package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +110 -0
  65. package/build/esm/lib/store/engine/lib/sqlite/index.js +128 -0
  66. package/build/esm/lib/store/index.d.ts +7 -3
  67. package/build/esm/lib/store/index.js +13 -5
  68. package/build/esm/lib/whatsapp/index.d.ts +106 -68
  69. package/build/esm/lib/whatsapp/index.js +395 -169
  70. package/package.json +25 -6
  71. package/build/cjs/decorators.js.map +0 -1
  72. package/build/cjs/index.js.map +0 -1
  73. package/build/cjs/lib/bot/decorator.js.map +0 -1
  74. package/build/cjs/lib/bot/decorators.js.map +0 -1
  75. package/build/cjs/lib/bot/index.js.map +0 -1
  76. package/build/cjs/lib/chat/index.js.map +0 -1
  77. package/build/cjs/lib/contact/index.js.map +0 -1
  78. package/build/cjs/lib/message/index.js.map +0 -1
  79. package/build/cjs/lib/status/index.js.map +0 -1
  80. package/build/cjs/lib/store/engine/index.js.map +0 -1
  81. package/build/cjs/lib/store/engine/lib/file_system/index.js.map +0 -1
  82. package/build/cjs/lib/store/engine/lib/redis/index.js.map +0 -1
  83. package/build/cjs/lib/store/engine/lib/s3/index.js.map +0 -1
  84. package/build/cjs/lib/store/index.js.map +0 -1
  85. package/build/cjs/lib/whatsapp/index.js.map +0 -1
  86. package/build/cjs/test.d.ts +0 -1
  87. package/build/cjs/test.js +0 -71
  88. package/build/cjs/test.js.map +0 -1
  89. package/build/esm/decorators.js.map +0 -1
  90. package/build/esm/index.js.map +0 -1
  91. package/build/esm/lib/bot/decorator.js.map +0 -1
  92. package/build/esm/lib/bot/decorators.js.map +0 -1
  93. package/build/esm/lib/bot/index.js.map +0 -1
  94. package/build/esm/lib/chat/index.js.map +0 -1
  95. package/build/esm/lib/contact/index.js.map +0 -1
  96. package/build/esm/lib/message/index.js.map +0 -1
  97. package/build/esm/lib/status/index.js.map +0 -1
  98. package/build/esm/lib/store/engine/index.js.map +0 -1
  99. package/build/esm/lib/store/engine/lib/file_system/index.js.map +0 -1
  100. package/build/esm/lib/store/engine/lib/redis/index.js.map +0 -1
  101. package/build/esm/lib/store/engine/lib/s3/index.js.map +0 -1
  102. package/build/esm/lib/store/index.js.map +0 -1
  103. package/build/esm/lib/whatsapp/index.js.map +0 -1
  104. package/build/esm/test.d.ts +0 -1
  105. package/build/esm/test.js +0 -66
  106. package/build/esm/test.js.map +0 -1
@@ -1,65 +1,64 @@
1
1
  /**
2
2
  * @file contact/index.ts
3
- * @description Entidad Contact — lectura/escritura documental sobre `wa.engine`.
4
- * Contact entity — documental read/write over `wa.engine`.
3
+ * @description Entidad Contact — una ficha mínima derivada del raw del contacto.
4
+ * Contact entity — a minimal card derived from the raw contact document.
5
5
  */
6
6
  import { jidNormalizedUser } from 'baileys';
7
+ import { internals } from '../../lib/internal.js';
7
8
  import { deserialize, serialize } from '../../lib/store/index.js';
8
9
  /**
9
- * Resuelve el nombre mostrado de un contacto con prioridad local push teléfono.
10
- * Resolves a contact's display name with priority local push phone number.
11
- *
12
- * @param raw - Documento persistido del contacto / Persisted contact document
13
- * @returns Nombre mostrado / Display name
14
- */
15
- export function contact_name(raw) {
16
- return raw.name ?? raw.notify ?? raw.id.split('@')[0];
17
- }
18
- /**
19
- * Clase base del contacto (forma pública, solo lectura).
20
- * Base Contact class (public shape, read-only).
10
+ * Clase base del contacto: recibe el raw de baileys y deriva todo con getters.
11
+ * Base Contact class: receives the baileys raw and derives everything via getters.
21
12
  */
22
13
  export class Contact {
23
- constructor(raw, chat) {
24
- this._raw = raw;
25
- this._chat = chat;
14
+ /**
15
+ * @internal Documento crudo del contacto en snake_case. `id` llega en formato LID o PN
16
+ * según el addressing; `phone_number` es el JID PN cuando baileys lo conoce.
17
+ * Raw contact document in snake_case. `id` arrives in LID or PN format depending on
18
+ * addressing; `phone_number` is the PN JID when baileys knows it.
19
+ */
20
+ constructor(_raw) {
21
+ this._raw = _raw;
26
22
  }
27
- /** JID único. / Unique JID. */
28
- get id() {
29
- return this._raw.id;
23
+ /** Nombre: agenda → público → verificado → teléfono. / Name: address book → public → verified → phone. */
24
+ get name() {
25
+ const { name, notify, verified_name } = this._raw;
26
+ return name ?? notify ?? verified_name ?? this.phone ?? this._raw.id.split('@')[0];
30
27
  }
31
- /** JID (alias). / JID (alias). */
28
+ /**
29
+ * JID legado (`@s.whatsapp.net`): el reportado por baileys o generado desde el id
30
+ * cuando ya viene en formato PN; null si no es determinable.
31
+ * Legacy JID (`@s.whatsapp.net`): the one baileys reports or generated from the id
32
+ * when it is already PN-formatted; null when not determinable.
33
+ */
32
34
  get jid() {
33
- return this._raw.id;
35
+ if (this._raw.phone_number)
36
+ return jidNormalizedUser(this._raw.phone_number);
37
+ if (this._raw.id.endsWith('@s.whatsapp.net'))
38
+ return jidNormalizedUser(this._raw.id);
39
+ return null;
34
40
  }
35
- /** LID si está disponible. / LID when available. */
41
+ /** LID (`@lid`) cuando es definible; null si no. / LID (`@lid`) when definable; null otherwise. */
36
42
  get lid() {
37
- return this._raw.lid ?? null;
38
- }
39
- /** Nombre: local → push → teléfono. / Name: local → push → phone. */
40
- get name() {
41
- return contact_name(this._raw);
43
+ if (this._raw.lid)
44
+ return this._raw.lid;
45
+ if (this._raw.id.endsWith('@lid'))
46
+ return this._raw.id;
47
+ return null;
42
48
  }
43
- /** Número sin formato. / Raw phone number. */
49
+ /**
50
+ * Teléfono del contacto, derivado únicamente del JID PN (nunca del LID);
51
+ * null cuando no hay JID determinable.
52
+ * Contact phone, derived from the PN JID only (never from the LID);
53
+ * null when no JID is determinable.
54
+ */
44
55
  get phone() {
45
- return this._raw.id.split('@')[0];
56
+ return this.jid?.split('@')[0] ?? null;
46
57
  }
47
- /** URL de foto de perfil. / Profile picture URL. */
58
+ /** URL de la foto de perfil, o null. / Profile picture URL, or null. */
48
59
  get photo() {
49
- return this._raw.img_url ?? null;
50
- }
51
- /** Bio del contacto. / Contact bio. */
52
- get content() {
53
- return this._raw.status ?? '';
54
- }
55
- /**
56
- * Chat 1:1 asociado al contacto. Async por coherencia con `Message.chat()` /
57
- * `Message.author()`, aunque la instancia ya está hidratada en memoria.
58
- * 1:1 chat associated with the contact. Async for consistency with
59
- * `Message.chat()` / `Message.author()`, though already hydrated in memory.
60
- */
61
- async chat() {
62
- return this._chat;
60
+ const url = this._raw.img_url;
61
+ return url?.startsWith('http') ? url : null;
63
62
  }
64
63
  }
65
64
  /**
@@ -69,174 +68,81 @@ export class Contact {
69
68
  * @param wa - Instancia principal / Main WhatsApp instance
70
69
  */
71
70
  export function contact(wa) {
72
- /**
73
- * Descubre el JID canónico y el LID (cuando aplica) de un número consultando al socket.
74
- * Discovers the canonical JID and LID (when applicable) of a phone number via the socket.
75
- */
76
- async function discover_by_phone(phone) {
77
- let result = null;
78
- if (wa._socket && phone.length > 0) {
79
- const found = (await wa._socket.onWhatsApp(phone))?.[0];
80
- if (found?.exists) {
81
- result = { jid: jidNormalizedUser(found.jid), lid: found.lid ?? null };
82
- }
83
- }
84
- return result;
85
- }
86
- /**
87
- * Obtiene foto y bio del contacto desde el socket.
88
- * Fetches profile picture and bio from the socket.
89
- */
90
- async function fetch_profile_data(id) {
91
- let img_url = null;
92
- let status = null;
93
- if (wa._socket) {
94
- try {
95
- img_url = (await wa._socket.profilePictureUrl(id, 'image')) ?? null;
96
- }
97
- catch {
98
- /* may not exist */
99
- }
100
- try {
101
- const result = await wa._socket.fetchStatus(id);
102
- const data = result?.[0];
103
- status = data?.status?.status ?? null;
104
- }
105
- catch {
106
- /* may fail */
107
- }
108
- }
109
- return { img_url, status };
110
- }
111
- /**
112
- * Carga la instancia Chat 1:1 del contacto. Si no existe en engine, fabrica una mínima.
113
- * Loads the 1:1 Chat instance for a contact. Falls back to a minimal instance if missing.
114
- */
115
- async function load_chat_for(jid, fallback_name) {
116
- const cached = deserialize(await wa.engine.get(`/chat/${jid}`));
117
- return new wa.Chat(cached ?? { id: jid, name: fallback_name });
118
- }
119
71
  return class _Contact extends Contact {
120
- constructor(raw, chat) {
121
- super(raw, chat);
122
- }
123
- /** Chat 1:1 asociado (subclase enriquecida). / Associated 1:1 chat (enriched subclass). */
72
+ /**
73
+ * Chat 1:1 del contacto: el persistido en el engine, o una instancia mínima.
74
+ * The contact's 1:1 chat: the engine-persisted one, or a minimal instance.
75
+ *
76
+ * @returns Instancia de Chat / Chat instance
77
+ */
124
78
  async chat() {
125
- return this._chat;
126
- }
127
- /** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
128
- get me() {
129
- const self_id = wa._socket?.user?.id;
130
- return Boolean(self_id) && jidNormalizedUser(self_id) === this.id;
79
+ const cid = this.jid ?? this.lid ?? this._raw.id;
80
+ const cached = deserialize(await wa.engine.get(`/chat/${cid}`));
81
+ return new wa.Chat(cached ?? { id: cid, name: this.name });
131
82
  }
132
83
  /**
133
- * Obtiene un contacto. Dispatch inteligente:
134
- * - Si `uid` contiene `@` → se interpreta como JID (`@s.whatsapp.net` / `@g.us`) o LID (`@lid`) y se resuelve con el mapping.
135
- * - Si no contiene `@` se limpian los dígitos y se consulta `socket.onWhatsApp(phone)` para obtener el JID canónico.
84
+ * Carga un contacto por teléfono, JID o LID: primero el engine; si no está
85
+ * persistido lo descubre por red (`onWhatsApp` + foto + bio) y lo materializa.
86
+ * Loads a contact by phone, JID or LID: engine first; when not persisted it
87
+ * discovers it over the network (`onWhatsApp` + photo + bio) and materializes it.
136
88
  *
137
- * Retrieves a contact. Smart dispatch:
138
- * - If `uid` contains `@` treated as JID or LID, resolved via mapping.
139
- * - If `uid` lacks `@` → digits are extracted and `socket.onWhatsApp(phone)` resolves the canonical JID.
89
+ * @param uid - Teléfono, JID o LID / Phone, JID or LID
90
+ * @returns Contacto o null si no existe en WhatsApp / Contact or null when not on WhatsApp
140
91
  */
141
92
  static async get(uid) {
142
- let result = null;
143
- let jid = null;
144
- let lid = null;
145
- if (uid.includes('@')) {
146
- jid = await wa._resolve_jid(uid);
147
- }
148
- else {
149
- const discovered = await discover_by_phone(uid.replace(/\D+/g, ''));
150
- if (discovered) {
151
- jid = discovered.jid;
152
- lid = discovered.lid;
153
- }
154
- }
93
+ const digits = String(uid).replace(/\D+/g, '');
94
+ const jid = String(uid).includes('@')
95
+ ? await internals(wa).resolve_jid(String(uid))
96
+ : digits
97
+ ? `${digits}@s.whatsapp.net`
98
+ : null;
155
99
  if (jid && !jid.endsWith('@g.us')) {
156
100
  const cached = deserialize(await wa.engine.get(`/contact/${jid}`));
157
- if (cached) {
158
- result = new _Contact(cached, await load_chat_for(jid, contact_name(cached)));
159
- }
160
- else if (wa._socket) {
161
- const needs_check = !lid && !uid.endsWith('@lid');
162
- const discovered = needs_check
163
- ? await discover_by_phone(jid.split('@')[0])
164
- : { jid, lid };
165
- if (discovered) {
166
- const { img_url, status } = await fetch_profile_data(discovered.jid);
101
+ if (cached)
102
+ return new _Contact(cached);
103
+ const socket = internals(wa).socket;
104
+ if (socket) {
105
+ const found = (await socket.onWhatsApp(jid.split('@')[0]))?.[0];
106
+ if (found?.exists) {
107
+ const id = jidNormalizedUser(found.jid);
108
+ const img_url = await socket.profilePictureUrl(id, 'image').catch(() => null);
109
+ const status = await socket
110
+ .fetchStatus(id)
111
+ .then((result) => result?.[0]?.status?.status ?? null)
112
+ .catch(() => null);
167
113
  const raw = {
168
- id: discovered.jid,
169
- lid: discovered.lid,
114
+ id,
115
+ lid: found.lid ?? null,
116
+ phone_number: id,
170
117
  name: null,
171
118
  notify: null,
172
119
  verified_name: null,
173
- img_url,
120
+ img_url: img_url ?? null,
174
121
  status,
175
122
  };
176
- await wa.engine.set(`/contact/${discovered.jid}`, serialize(raw));
177
- if (discovered.lid) {
178
- await wa.engine.set(`/lid/${discovered.lid}`, serialize(discovered.jid));
123
+ await wa.engine.set(`/contact/${id}`, serialize(raw));
124
+ if (found.lid) {
125
+ await wa.engine.set(`/lid/${found.lid}`, serialize(id));
179
126
  }
180
- result = new _Contact(raw, await load_chat_for(discovered.jid, discovered.jid.split('@')[0]));
127
+ return new _Contact(raw);
181
128
  }
182
129
  }
183
130
  }
184
- return result;
131
+ return null;
185
132
  }
186
133
  /**
187
- * Pagina los contactos persistidos por mtime DESC, pre-cargando el chat de cada uno.
188
- * Paginates persisted contacts by mtime DESC, pre-loading the chat of each one.
134
+ * Pagina los contactos persistidos.
135
+ * Paginates persisted contacts.
136
+ *
137
+ * @param offset - Desplazamiento / Offset
138
+ * @param limit - Tamaño de página / Page size
139
+ * @returns Página de contactos / Contact page
189
140
  */
190
141
  static async list(offset = 0, limit = 50) {
191
- const contacts = [];
192
- for (const raw of await wa.engine.list('/contact', offset, limit)) {
193
- const parsed = deserialize(raw);
194
- if (parsed) {
195
- contacts.push(new _Contact(parsed, await load_chat_for(parsed.id, contact_name(parsed))));
196
- }
197
- }
198
- return contacts;
199
- }
200
- /**
201
- * Renombra localmente un contacto por id.
202
- * Renames a contact locally by id.
203
- */
204
- static async rename(uid, name) {
205
- const c = await _Contact.get(uid);
206
- return c ? c.rename(name) : false;
207
- }
208
- /**
209
- * Re-hidrata los datos del contacto por id desde el socket.
210
- * Re-hydrates contact data from the socket by id.
211
- */
212
- static async refresh(uid) {
213
- const c = await _Contact.get(uid);
214
- return c ? c.refresh() : null;
215
- }
216
- /**
217
- * Renombra el contacto localmente (solo agenda del dispositivo).
218
- * Renames the contact locally (device address book only).
219
- */
220
- async rename(name) {
221
- this._raw.name = name;
222
- await wa.engine.set(`/contact/${this.id}`, serialize(this._raw));
223
- return true;
224
- }
225
- /**
226
- * Re-hidrata foto y bio desde el socket.
227
- * Re-hydrates profile picture and bio from the socket.
228
- */
229
- async refresh() {
230
- let ok = false;
231
- if (wa._socket) {
232
- const { img_url, status } = await fetch_profile_data(this.id);
233
- this._raw.img_url = img_url;
234
- this._raw.status = status;
235
- await wa.engine.set(`/contact/${this.id}`, serialize(this._raw));
236
- ok = true;
237
- }
238
- return ok ? this : null;
142
+ return (await wa.engine.list('/contact', offset, limit))
143
+ .map((raw) => deserialize(raw))
144
+ .filter((parsed) => parsed !== null)
145
+ .map((parsed) => new _Contact(parsed));
239
146
  }
240
147
  };
241
148
  }
242
- //# sourceMappingURL=index.js.map
@@ -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,34 @@
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
+ const channel = new WeakMap();
13
+ /**
14
+ * Publica el estado interno de un cliente para las entidades de la librería.
15
+ * Publishes a client's internal state for the library entities.
16
+ *
17
+ * @param owner - Cliente dueño del estado / Client owning the state
18
+ * @param state - Estado compartido, mutable por el cliente / Shared state, mutated by the client
19
+ */
20
+ export function bind(owner, state) {
21
+ channel.set(owner, state);
22
+ }
23
+ /**
24
+ * Estado interno del cliente. Sólo lo resuelven los módulos de la librería: el objeto
25
+ * nunca se expone al consumidor.
26
+ * A client's internal state. Only library modules resolve it: the object is never exposed
27
+ * to the consumer.
28
+ *
29
+ * @param owner - Cliente construido por la librería / Client built by the library
30
+ * @returns Estado compartido / Shared state
31
+ */
32
+ export function internals(owner) {
33
+ return channel.get(owner);
34
+ }