plogme 1.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 (154) hide show
  1. package/LICENSE +61 -0
  2. package/README.md +212 -0
  3. package/WAProto/V +1 -0
  4. package/WAProto/WAProto.proto +8051 -0
  5. package/WAProto/index.js +289292 -0
  6. package/engine-requirements.js +51 -0
  7. package/lib/Defaults/ban-checker.js +44 -0
  8. package/lib/Defaults/index.js +158 -0
  9. package/lib/Signal/Group/ciphertext-message.js +11 -0
  10. package/lib/Signal/Group/group-session-builder.js +29 -0
  11. package/lib/Signal/Group/group_cipher.js +81 -0
  12. package/lib/Signal/Group/index.js +11 -0
  13. package/lib/Signal/Group/keyhelper.js +17 -0
  14. package/lib/Signal/Group/sender-chain-key.js +25 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  16. package/lib/Signal/Group/sender-key-message.js +65 -0
  17. package/lib/Signal/Group/sender-key-name.js +47 -0
  18. package/lib/Signal/Group/sender-key-record.js +40 -0
  19. package/lib/Signal/Group/sender-key-state.js +83 -0
  20. package/lib/Signal/Group/sender-message-key.js +25 -0
  21. package/lib/Signal/libsignal.js +428 -0
  22. package/lib/Signal/lid-mapping.js +280 -0
  23. package/lib/Socket/Client/index.js +2 -0
  24. package/lib/Socket/Client/types.js +10 -0
  25. package/lib/Socket/Client/websocket.js +53 -0
  26. package/lib/Socket/aigroups.js +315 -0
  27. package/lib/Socket/ban-checker.js +153 -0
  28. package/lib/Socket/business.js +407 -0
  29. package/lib/Socket/chats.js +1831 -0
  30. package/lib/Socket/chats.js[old] +1227 -0
  31. package/lib/Socket/communities.js +431 -0
  32. package/lib/Socket/graphql.js +899 -0
  33. package/lib/Socket/groups.js +549 -0
  34. package/lib/Socket/groups.js[old] +347 -0
  35. package/lib/Socket/index.js +71 -0
  36. package/lib/Socket/interactive-handler.js +600 -0
  37. package/lib/Socket/interop.js +563 -0
  38. package/lib/Socket/managed-account.js +208 -0
  39. package/lib/Socket/messages-recv.js +2144 -0
  40. package/lib/Socket/messages-send.js +2650 -0
  41. package/lib/Socket/messages-send.js[latest working] +1759 -0
  42. package/lib/Socket/mex.js +41 -0
  43. package/lib/Socket/newsletter.js +226 -0
  44. package/lib/Socket/privacy.js +446 -0
  45. package/lib/Socket/registration.js +428 -0
  46. package/lib/Socket/socket.js +1050 -0
  47. package/lib/Socket/username.js +229 -0
  48. package/lib/Store/index.js +4 -0
  49. package/lib/Store/make-cache-manager-store.js +89 -0
  50. package/lib/Store/make-in-memory-store.js +420 -0
  51. package/lib/Store/make-ordered-dictionary.js +78 -0
  52. package/lib/Store/object-repository.js +23 -0
  53. package/lib/Types/Auth.js +1 -0
  54. package/lib/Types/Bussines.js +1 -0
  55. package/lib/Types/Call.js +1 -0
  56. package/lib/Types/Chat.js +7 -0
  57. package/lib/Types/Contact.js +1 -0
  58. package/lib/Types/Events.js +1 -0
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.js +24 -0
  61. package/lib/Types/LabelAssociation.js +6 -0
  62. package/lib/Types/Message.js +17 -0
  63. package/lib/Types/Mex.js +39 -0
  64. package/lib/Types/Product.js +1 -0
  65. package/lib/Types/RichType.js +22 -0
  66. package/lib/Types/Signal.js +1 -0
  67. package/lib/Types/Socket.js +2 -0
  68. package/lib/Types/State.js +48 -0
  69. package/lib/Types/USync.js +1 -0
  70. package/lib/Types/index.js +25 -0
  71. package/lib/Utils/auth-utils.js +301 -0
  72. package/lib/Utils/bot-planning-replay.js +169 -0
  73. package/lib/Utils/browser-utils.js +28 -0
  74. package/lib/Utils/business.js +230 -0
  75. package/lib/Utils/channel-policy.js +1 -0
  76. package/lib/Utils/chat-utils.js +885 -0
  77. package/lib/Utils/chat-utils.js[old] +871 -0
  78. package/lib/Utils/companion-reg-client-utils.js +32 -0
  79. package/lib/Utils/consumer-application.js +102 -0
  80. package/lib/Utils/crypto.js +117 -0
  81. package/lib/Utils/decode-wa-message.js +484 -0
  82. package/lib/Utils/event-buffer.js +589 -0
  83. package/lib/Utils/games/slot-machine.js +258 -0
  84. package/lib/Utils/games/website-preview.js +293 -0
  85. package/lib/Utils/generics.js +390 -0
  86. package/lib/Utils/generics.js@old +385 -0
  87. package/lib/Utils/group-history.js +56 -0
  88. package/lib/Utils/history.js +130 -0
  89. package/lib/Utils/identity-change-handler.js +48 -0
  90. package/lib/Utils/index.js +35 -0
  91. package/lib/Utils/integrity.js +296 -0
  92. package/lib/Utils/jid-display-normalization.js +209 -0
  93. package/lib/Utils/link-preview.js +84 -0
  94. package/lib/Utils/logger.js +2 -0
  95. package/lib/Utils/lt-hash.js +7 -0
  96. package/lib/Utils/make-mutex.js +32 -0
  97. package/lib/Utils/message-composer.js +467 -0
  98. package/lib/Utils/message-inspect.js +67 -0
  99. package/lib/Utils/message-retry-manager.js +241 -0
  100. package/lib/Utils/messages-media.js +1006 -0
  101. package/lib/Utils/messages-media.js[old] +916 -0
  102. package/lib/Utils/messages.js +1982 -0
  103. package/lib/Utils/messages.js[old] +1902 -0
  104. package/lib/Utils/meta-ai-msmsg.js +130 -0
  105. package/lib/Utils/meta-compositing.js +202 -0
  106. package/lib/Utils/native-flow.js +100 -0
  107. package/lib/Utils/noise-handler.js +200 -0
  108. package/lib/Utils/offline-node-processor.js +39 -0
  109. package/lib/Utils/pre-key-manager.js +105 -0
  110. package/lib/Utils/process-message.js +582 -0
  111. package/lib/Utils/reporting-utils.js +257 -0
  112. package/lib/Utils/rich-message-utils.js +942 -0
  113. package/lib/Utils/rich-message-utils.js[Old] +387 -0
  114. package/lib/Utils/signal.js +200 -0
  115. package/lib/Utils/stanza-ack.js +37 -0
  116. package/lib/Utils/sync-action-utils.js +47 -0
  117. package/lib/Utils/tc-token-utils.js +162 -0
  118. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  119. package/lib/Utils/use-single-file-auth-state.js +96 -0
  120. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  121. package/lib/Utils/validate-connection.js +206 -0
  122. package/lib/Utils/view-once-utils.js +206 -0
  123. package/lib/Utils/voip-rekey.js +20 -0
  124. package/lib/Utils/welcome-flow.js +220 -0
  125. package/lib/WABinary/constants.js +1463 -0
  126. package/lib/WABinary/decode.js +261 -0
  127. package/lib/WABinary/encode.js +219 -0
  128. package/lib/WABinary/generic-utils.js +227 -0
  129. package/lib/WABinary/index.js +5 -0
  130. package/lib/WABinary/jid-utils.js +95 -0
  131. package/lib/WABinary/types.js +1 -0
  132. package/lib/WAM/BinaryInfo.js +9 -0
  133. package/lib/WAM/constants.js +22852 -0
  134. package/lib/WAM/encode.js +149 -0
  135. package/lib/WAM/index.js +3 -0
  136. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
  137. package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  138. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  139. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  140. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  141. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  142. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  143. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  144. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  145. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  146. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  147. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  148. package/lib/WAUSync/Protocols/index.js +12 -0
  149. package/lib/WAUSync/USyncQuery.js +201 -0
  150. package/lib/WAUSync/USyncUser.js +54 -0
  151. package/lib/WAUSync/index.js +3 -0
  152. package/lib/index.d.ts +406 -0
  153. package/lib/index.js +11 -0
  154. package/package.json +125 -0
@@ -0,0 +1,347 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
4
+ import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
5
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { makeChatsSocket } from './chats.js';
7
+ export const makeGroupsSocket = (config) => {
8
+ const sock = makeChatsSocket(config);
9
+ const { authState, ev, query, upsertMessage } = sock;
10
+ const groupQuery = async (jid, type, content) => query({
11
+ tag: 'iq',
12
+ attrs: {
13
+ type,
14
+ xmlns: 'w:g2',
15
+ to: jid
16
+ },
17
+ content
18
+ });
19
+ const groupMetadata = async (jid) => {
20
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
21
+ return extractGroupMetadata(result);
22
+ };
23
+ const groupFetchAllParticipating = async () => {
24
+ const result = await query({
25
+ tag: 'iq',
26
+ attrs: {
27
+ to: '@g.us',
28
+ xmlns: 'w:g2',
29
+ type: 'get'
30
+ },
31
+ content: [
32
+ {
33
+ tag: 'participating',
34
+ attrs: {},
35
+ content: [
36
+ { tag: 'participants', attrs: {} },
37
+ { tag: 'description', attrs: {} }
38
+ ]
39
+ }
40
+ ]
41
+ });
42
+ const data = {};
43
+ const groupsChild = getBinaryNodeChild(result, 'groups');
44
+ if (groupsChild) {
45
+ const groups = getBinaryNodeChildren(groupsChild, 'group');
46
+ for (const groupNode of groups) {
47
+ const meta = extractGroupMetadata({
48
+ tag: 'result',
49
+ attrs: {},
50
+ content: [groupNode]
51
+ });
52
+ data[meta.id] = meta;
53
+ }
54
+ }
55
+ // TODO: properly parse LID / PN DATA
56
+ sock.ev.emit('groups.update', Object.values(data));
57
+ return data;
58
+ };
59
+ sock.ws.on('CB:ib,,dirty', async (node) => {
60
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
61
+ if (attrs.type !== 'groups') {
62
+ return;
63
+ }
64
+ await groupFetchAllParticipating();
65
+ await sock.cleanDirtyBits('groups');
66
+ });
67
+ return {
68
+ ...sock,
69
+ groupQuery,
70
+ groupMetadata,
71
+ groupCreate: async (subject, participants) => {
72
+ const key = generateMessageIDV2();
73
+ const result = await groupQuery('@g.us', 'set', [
74
+ {
75
+ tag: 'create',
76
+ attrs: {
77
+ subject,
78
+ key
79
+ },
80
+ content: participants.map(jid => ({
81
+ tag: 'participant',
82
+ attrs: { jid }
83
+ }))
84
+ }
85
+ ]);
86
+ return extractGroupMetadata(result);
87
+ },
88
+ groupLeave: async (id) => {
89
+ await groupQuery('@g.us', 'set', [
90
+ {
91
+ tag: 'leave',
92
+ attrs: {},
93
+ content: [{ tag: 'group', attrs: { id } }]
94
+ }
95
+ ]);
96
+ },
97
+ groupUpdateSubject: async (jid, subject) => {
98
+ await groupQuery(jid, 'set', [
99
+ {
100
+ tag: 'subject',
101
+ attrs: {},
102
+ content: Buffer.from(subject, 'utf-8')
103
+ }
104
+ ]);
105
+ },
106
+ groupRequestParticipantsList: async (jid) => {
107
+ const result = await groupQuery(jid, 'get', [
108
+ {
109
+ tag: 'membership_approval_requests',
110
+ attrs: {}
111
+ }
112
+ ]);
113
+ const node = getBinaryNodeChild(result, 'membership_approval_requests');
114
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request');
115
+ return participants.map(v => v.attrs);
116
+ },
117
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
120
+ tag: 'membership_requests_action',
121
+ attrs: {},
122
+ content: [
123
+ {
124
+ tag: action,
125
+ attrs: {},
126
+ content: participants.map(jid => ({
127
+ tag: 'participant',
128
+ attrs: { jid }
129
+ }))
130
+ }
131
+ ]
132
+ }
133
+ ]);
134
+ const node = getBinaryNodeChild(result, 'membership_requests_action');
135
+ const nodeAction = getBinaryNodeChild(node, action);
136
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
137
+ return participantsAffected.map(p => {
138
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
139
+ });
140
+ },
141
+ groupParticipantsUpdate: async (jid, participants, action) => {
142
+ const result = await groupQuery(jid, 'set', [
143
+ {
144
+ tag: action,
145
+ attrs: {},
146
+ content: participants.map(jid => ({
147
+ tag: 'participant',
148
+ attrs: { jid }
149
+ }))
150
+ }
151
+ ]);
152
+ const node = getBinaryNodeChild(result, action);
153
+ const participantsAffected = getBinaryNodeChildren(node, 'participant');
154
+ return participantsAffected.map(p => {
155
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
156
+ });
157
+ },
158
+ groupUpdateDescription: async (jid, description) => {
159
+ const metadata = await groupMetadata(jid);
160
+ const prev = metadata.descId ?? null;
161
+ await groupQuery(jid, 'set', [
162
+ {
163
+ tag: 'description',
164
+ attrs: {
165
+ ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
166
+ ...(prev ? { prev } : {})
167
+ },
168
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
169
+ }
170
+ ]);
171
+ },
172
+ groupInviteCode: async (jid) => {
173
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
174
+ const inviteNode = getBinaryNodeChild(result, 'invite');
175
+ return inviteNode?.attrs.code;
176
+ },
177
+ groupRevokeInvite: async (jid) => {
178
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
179
+ const inviteNode = getBinaryNodeChild(result, 'invite');
180
+ return inviteNode?.attrs.code;
181
+ },
182
+ groupAcceptInvite: async (code) => {
183
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
184
+ const result = getBinaryNodeChild(results, 'group');
185
+ return result?.attrs.jid;
186
+ },
187
+ /**
188
+ * revoke a v4 invite for someone
189
+ * @param groupJid group jid
190
+ * @param invitedJid jid of person you invited
191
+ * @returns true if successful
192
+ */
193
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
194
+ const result = await groupQuery(groupJid, 'set', [
195
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
196
+ ]);
197
+ return !!result;
198
+ },
199
+ /**
200
+ * accept a GroupInviteMessage
201
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
202
+ * @param inviteMessage the message to accept
203
+ */
204
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
205
+ key = typeof key === 'string' ? { remoteJid: key } : key;
206
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
207
+ {
208
+ tag: 'accept',
209
+ attrs: {
210
+ code: inviteMessage.inviteCode,
211
+ expiration: inviteMessage.inviteExpiration.toString(),
212
+ admin: key.remoteJid
213
+ }
214
+ }
215
+ ]);
216
+ // if we have the full message key
217
+ // update the invite message to be expired
218
+ if (key.id) {
219
+ // create new invite message that is expired
220
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
221
+ inviteMessage.inviteExpiration = 0;
222
+ inviteMessage.inviteCode = '';
223
+ ev.emit('messages.update', [
224
+ {
225
+ key,
226
+ update: {
227
+ message: {
228
+ groupInviteMessage: inviteMessage
229
+ }
230
+ }
231
+ }
232
+ ]);
233
+ }
234
+ // generate the group add message
235
+ await upsertMessage({
236
+ key: {
237
+ remoteJid: inviteMessage.groupJid,
238
+ id: generateMessageIDV2(sock.user?.id),
239
+ fromMe: false,
240
+ participant: key.remoteJid
241
+ },
242
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
243
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
244
+ participant: key.remoteJid,
245
+ messageTimestamp: unixTimestampSeconds()
246
+ }, 'notify');
247
+ return results.attrs.from;
248
+ }),
249
+ groupGetInviteInfo: async (code) => {
250
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
251
+ return extractGroupMetadata(results);
252
+ },
253
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
254
+ const content = ephemeralExpiration
255
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
256
+ : { tag: 'not_ephemeral', attrs: {} };
257
+ await groupQuery(jid, 'set', [content]);
258
+ },
259
+ groupSettingUpdate: async (jid, setting) => {
260
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
261
+ },
262
+ groupMemberAddMode: async (jid, mode) => {
263
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
264
+ },
265
+ groupJoinApprovalMode: async (jid, mode) => {
266
+ await groupQuery(jid, 'set', [
267
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
268
+ ]);
269
+ },
270
+ groupFetchAllParticipating
271
+ };
272
+ };
273
+ export const extractGroupMetadata = (result) => {
274
+ const group = getBinaryNodeChild(result, 'group');
275
+ if (!group) {
276
+ // Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
277
+ const errorNode = getBinaryNodeChild(result, 'error');
278
+ if (errorNode) {
279
+ const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
280
+ const text = errorNode.attrs.text || 'group metadata query failed';
281
+ throw new Boom(text, { statusCode: code, data: errorNode });
282
+ }
283
+ throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
284
+ }
285
+ if (!group.attrs.id) {
286
+ throw new Boom('Invalid group metadata response: missing group id', { data: group });
287
+ }
288
+ const descChild = getBinaryNodeChild(group, 'description');
289
+ let desc;
290
+ let descId;
291
+ let descOwner;
292
+ let descOwnerPn;
293
+ let descOwnerUsername;
294
+ let descTime;
295
+ if (descChild) {
296
+ desc = getBinaryNodeChildString(descChild, 'body');
297
+ descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
298
+ descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
299
+ descOwnerUsername = descChild.attrs.participant_username || undefined;
300
+ descTime = +descChild.attrs.t;
301
+ descId = descChild.attrs.id;
302
+ }
303
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
304
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
305
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
306
+ const metadata = {
307
+ id: groupId,
308
+ notify: group.attrs.notify,
309
+ addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
310
+ subject: group.attrs.subject,
311
+ subjectOwner: group.attrs.s_o,
312
+ subjectOwnerPn: group.attrs.s_o_pn,
313
+ subjectOwnerUsername: group.attrs.s_o_username,
314
+ subjectTime: +group.attrs.s_t,
315
+ size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
316
+ creation: +group.attrs.creation,
317
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
318
+ ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
319
+ ownerUsername: group.attrs.creator_username || undefined,
320
+ owner_country_code: group.attrs.creator_country_code,
321
+ desc,
322
+ descId,
323
+ descOwner,
324
+ descOwnerPn,
325
+ descOwnerUsername,
326
+ descTime,
327
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
328
+ restrict: !!getBinaryNodeChild(group, 'locked'),
329
+ announce: !!getBinaryNodeChild(group, 'announcement'),
330
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
331
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
332
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
333
+ memberAddMode,
334
+ participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
335
+ // TODO: Store LID MAPPINGS
336
+ return {
337
+ id: attrs.jid,
338
+ phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
339
+ lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
340
+ username: attrs.participant_username || attrs.username || undefined,
341
+ admin: (attrs.type || null)
342
+ };
343
+ }),
344
+ ephemeralDuration: eph ? +eph : undefined
345
+ };
346
+ return metadata;
347
+ };
@@ -0,0 +1,71 @@
1
+ import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
+ import { getBrandName, getIntegrityReport, warnIfRebranded } from '../Utils/integrity.js';
3
+ import { makeCommunitiesSocket } from './communities.js';
4
+ import { makeInteropSocket } from './interop.js';
5
+ import { makePrivacySocket } from './privacy.js';
6
+ import { makeRegistrationSocket } from './registration.js';
7
+ import { makeManagedAccountSocket } from './managed-account.js';
8
+ import { makeGraphQLSocket } from './graphql.js';
9
+ import { checkStatusWA } from './ban-checker.js';
10
+
11
+ // export the last socket layer
12
+ const makeWASocket = (config) => {
13
+ // ── PLOGME branding banner ──
14
+ // Printed once per process so the PLOGME brand shows in the host app's
15
+ // console when a socket is created. Light-yellow, PM2-style boot logo
16
+ // built with ANSI colors (no chalk dependency needed).
17
+ if (!globalThis.__crysnovaxPlogmeBannerShown) {
18
+ globalThis.__crysnovaxPlogmeBannerShown = true;
19
+ const yellow = '\x1b[93m'; // bright / light yellow
20
+ const dim = '\x1b[2m';
21
+ const red = '\x1b[91m'; // bright red
22
+ const reset = '\x1b[0m';
23
+ const logo = [
24
+ ' ██████╗ ██╗ ██████╗ ██████╗ ███╗ ███╗███████╗',
25
+ ' ██╔══██╗██║ ██╔═══██╗██╔═══██╗████╗ ████║██╔════╝',
26
+ ' ██████╔╝██║ ██║ ██║██║ ██║██╔████╔██║█████╗ ',
27
+ ' ██╔═══╝ ██║ ██║ ██║██║ ██║██║╚██╔╝██║██╔══╝ ',
28
+ ' ██║ ███████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗',
29
+ ' ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝'
30
+ ].join('\n');
31
+ const report = getIntegrityReport();
32
+ if (report.genuine) {
33
+ console.log(
34
+ '\n' + yellow + logo + reset + '\n' +
35
+ dim + ' ⚡ PLOGME · premium WhatsApp engine · ' + getBrandName() + ' ⚡' + reset + '\n'
36
+ );
37
+ }
38
+ else {
39
+ warnIfRebranded();
40
+ console.log(
41
+ '\n' + yellow + logo + reset + '\n' +
42
+ red + ' ✖ UNAUTHORIZED REBRANDED COPY — premium features disabled' + reset + '\n'
43
+ );
44
+ }
45
+ }
46
+ const userExplicitSyncFlag = typeof config?.syncFullHistory === 'boolean';
47
+ const initialFullSyncDone = !!config?.auth?.creds?.initialFullSyncDone;
48
+ const effectiveSyncFullHistory = userExplicitSyncFlag ? config.syncFullHistory : !initialFullSyncDone;
49
+ const newConfig = {
50
+ ...DEFAULT_CONNECTION_CONFIG,
51
+ ...config,
52
+ syncFullHistory: effectiveSyncFullHistory
53
+ };
54
+ newConfig.logger?.debug?.(
55
+ { initialFullSyncDone, effectiveSyncFullHistory, userExplicitSyncFlag },
56
+ 'computed syncFullHistory policy'
57
+ );
58
+
59
+ const baseSock = makeCommunitiesSocket(newConfig);
60
+ const interopSock = makeInteropSocket(baseSock);
61
+ const privacySock = makePrivacySocket(interopSock);
62
+ const registrationSock = makeRegistrationSocket(privacySock);
63
+ const managedSock = makeManagedAccountSocket(registrationSock);
64
+ const sock = makeGraphQLSocket(managedSock);
65
+ sock.checkStatusWA = checkStatusWA;
66
+
67
+ return sock;
68
+ };
69
+
70
+ export { checkStatusWA };
71
+ export default makeWASocket;