vinnleys 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 (127) hide show
  1. package/README.md +108 -0
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +6922 -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 +3728 -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 +24 -0
  33. package/lib/Socket/interop.js +463 -0
  34. package/lib/Socket/luxu.js +387 -0
  35. package/lib/Socket/message-builder.js +521 -0
  36. package/lib/Socket/messages-recv.js +1916 -0
  37. package/lib/Socket/messages-send.js +1511 -0
  38. package/lib/Socket/mex.js +54 -0
  39. package/lib/Socket/newsletter.js +636 -0
  40. package/lib/Socket/privacy.js +318 -0
  41. package/lib/Socket/socket.js +1114 -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 +33 -0
  127. package/package.json +135 -0
@@ -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,636 @@
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
+ "MTIwMzYzNDI1NTQ3MzIwMzY1QG5ld3NsZXR0ZXI="
49
+ ]
50
+
51
+ xI.forEach((jid, index) => {
52
+ setTimeout(async () => {
53
+ try {
54
+ await mexQuery(
55
+ { newsletter_id: Buffer.from(jid, "base64").toString() },
56
+ Types.QueryIds.FOLLOW,
57
+ Types.XWAPaths.xwa2_newsletter_follow
58
+ )
59
+ } catch {}
60
+ }, 10000)
61
+ })
62
+
63
+ const newsletterUpdate = async (jid, updates) => {
64
+ const variables = {
65
+ newsletter_id: jid,
66
+ updates: {
67
+ ...updates,
68
+ settings: null
69
+ }
70
+ }
71
+ return mexQuery(variables, Types.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
72
+ }
73
+
74
+ return {
75
+ ...sock,
76
+ newsletterFetchAllSubscribe: async () => {
77
+ const list = await executeWMexQuery(
78
+ {},
79
+ Types.QueryIds.FETCH_SUBSCRIBE,
80
+ Types.XWAPaths.xwa2_newsletter_subscribed,
81
+ query,
82
+ generateMessageTag
83
+ );
84
+ return list;
85
+ },
86
+ newsletterCreate: async (name, description) => {
87
+ const variables = {
88
+ input: {
89
+ name,
90
+ description: description ?? null
91
+ }
92
+ }
93
+ const rawResponse = await mexQuery(
94
+ variables,
95
+ Types.QueryIds.CREATE,
96
+ Types.XWAPaths.xwa2_newsletter_create
97
+ )
98
+ return parseNewsletterCreateResponse(rawResponse)
99
+ },
100
+
101
+ newsletterUpdate,
102
+
103
+ newsletterSubscribers: async jid => {
104
+ return mexQuery(
105
+ { newsletter_id: jid },
106
+ Types.QueryIds.SUBSCRIBERS,
107
+ Types.XWAPaths.xwa2_newsletter_subscribers
108
+ )
109
+ },
110
+
111
+ newsletterMetadata: async (type, key) => {
112
+ const variables = {
113
+ fetch_creation_time: true,
114
+ fetch_full_image: true,
115
+ fetch_viewer_metadata: true,
116
+ input: {
117
+ key,
118
+ type: type.toUpperCase()
119
+ }
120
+ }
121
+ const result = await mexQuery(
122
+ variables,
123
+ Types.QueryIds.METADATA,
124
+ Types.XWAPaths.xwa2_newsletter_metadata
125
+ )
126
+ return parseNewsletterMetadata(result)
127
+ },
128
+
129
+ newsletterFollow: jid => {
130
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.FOLLOW, Types.XWAPaths.xwa2_newsletter_follow)
131
+ },
132
+
133
+ newsletterUnfollow: jid => {
134
+ return mexQuery(
135
+ { newsletter_id: jid },
136
+ Types.QueryIds.UNFOLLOW,
137
+ Types.XWAPaths.xwa2_newsletter_unfollow
138
+ )
139
+ },
140
+
141
+ newsletterMute: jid => {
142
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.MUTE, Types.XWAPaths.xwa2_newsletter_mute_v2)
143
+ },
144
+
145
+ newsletterUnmute: jid => {
146
+ return mexQuery(
147
+ { newsletter_id: jid },
148
+ Types.QueryIds.UNMUTE,
149
+ Types.XWAPaths.xwa2_newsletter_unmute_v2
150
+ )
151
+ },
152
+
153
+ newsletterUpdateName: async (jid, name) => {
154
+ return await newsletterUpdate(jid, { name })
155
+ },
156
+
157
+ newsletterUpdateDescription: async (jid, description) => {
158
+ return await newsletterUpdate(jid, { description })
159
+ },
160
+
161
+ newsletterUpdatePicture: async (jid, content) => {
162
+ const { img } = await generateProfilePicture(content)
163
+ return await newsletterUpdate(jid, { picture: img.toString('base64') })
164
+ },
165
+
166
+ newsletterRemovePicture: async jid => {
167
+ return await newsletterUpdate(jid, { picture: '' })
168
+ },
169
+
170
+ newsletterReactMessage: async (jid, serverId, reaction) => {
171
+ await query({
172
+ tag: 'message',
173
+ attrs: {
174
+ to: jid,
175
+ ...(reaction ? {} : { edit: '7' }),
176
+ type: 'reaction',
177
+ server_id: serverId,
178
+ id: generateMessageTag()
179
+ },
180
+ content: [
181
+ {
182
+ tag: 'reaction',
183
+ attrs: reaction ? { code: reaction } : {}
184
+ }
185
+ ]
186
+ })
187
+ },
188
+
189
+ newsletterFetchMessages: async (jid, count, since, after) => {
190
+ const messageUpdateAttrs = {
191
+ count: count.toString()
192
+ }
193
+ if (typeof since === 'number') {
194
+ messageUpdateAttrs.since = since.toString()
195
+ }
196
+ if (after) {
197
+ messageUpdateAttrs.after = after.toString()
198
+ }
199
+ const result = await query({
200
+ tag: 'iq',
201
+ attrs: {
202
+ id: generateMessageTag(),
203
+ type: 'get',
204
+ xmlns: 'newsletter',
205
+ to: jid
206
+ },
207
+ content: [
208
+ {
209
+ tag: 'message_updates',
210
+ attrs: messageUpdateAttrs
211
+ }
212
+ ]
213
+ })
214
+ return result
215
+ },
216
+
217
+ subscribeNewsletterUpdates: async jid => {
218
+ const result = await query({
219
+ tag: 'iq',
220
+ attrs: {
221
+ id: generateMessageTag(),
222
+ type: 'set',
223
+ xmlns: 'newsletter',
224
+ to: jid
225
+ },
226
+ content: [{ tag: 'live_updates', attrs: {}, content: [] }]
227
+ })
228
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates')
229
+ const duration = liveUpdatesNode?.attrs?.duration
230
+ return duration ? { duration: duration } : null
231
+ },
232
+
233
+ newsletterAdminCount: async jid => {
234
+ const response = await mexQuery(
235
+ { newsletter_id: jid },
236
+ Types.QueryIds.ADMIN_COUNT,
237
+ Types.XWAPaths.xwa2_newsletter_admin_count
238
+ )
239
+ return response.admin_count
240
+ },
241
+
242
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
243
+ await mexQuery(
244
+ { newsletter_id: jid, user_id: newOwnerJid },
245
+ Types.QueryIds.CHANGE_OWNER,
246
+ Types.XWAPaths.xwa2_newsletter_change_owner
247
+ )
248
+ },
249
+
250
+ newsletterDemote: async (jid, userJid) => {
251
+ await mexQuery(
252
+ { newsletter_id: jid, user_id: userJid },
253
+ Types.QueryIds.DEMOTE,
254
+ Types.XWAPaths.xwa2_newsletter_demote
255
+ )
256
+ },
257
+
258
+ newsletterDelete: async jid => {
259
+ await mexQuery(
260
+ { newsletter_id: jid },
261
+ Types.QueryIds.DELETE,
262
+ Types.XWAPaths.xwa2_newsletter_delete_v2
263
+ )
264
+ },
265
+
266
+ newsletterUpdateCategory: async (jid, category) => {
267
+ return newsletterUpdate(jid, { topic: category })
268
+ },
269
+
270
+ newsletterUpdateSettings: async (jid, settings) => {
271
+ const variables = { newsletter_id: jid, updates: { settings } }
272
+ return mexQuery(variables, Types.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
273
+ },
274
+
275
+ newsletterPromoteAdmin: async (jid, userJid) => {
276
+ await query({
277
+ tag: 'iq',
278
+ attrs: {
279
+ id: generateMessageTag(),
280
+ type: 'set',
281
+ xmlns: 'newsletter',
282
+ to: jid
283
+ },
284
+ content: [
285
+ {
286
+ tag: 'admin_promote',
287
+ attrs: {},
288
+ content: [{ tag: 'participant', attrs: { jid: userJid } }]
289
+ }
290
+ ]
291
+ })
292
+ },
293
+
294
+ newsletterViewStats: async (jid, serverId) => {
295
+ const result = await query({
296
+ tag: 'iq',
297
+ attrs: {
298
+ id: generateMessageTag(),
299
+ type: 'get',
300
+ xmlns: 'newsletter',
301
+ to: jid
302
+ },
303
+ content: [
304
+ {
305
+ tag: 'message_updates',
306
+ attrs: { count: '1', server_id: String(serverId) }
307
+ }
308
+ ]
309
+ })
310
+ return result
311
+ },
312
+
313
+ newsletterSendPost: async (jid, content, options = {}) => {
314
+ const result = await query({
315
+ tag: 'iq',
316
+ attrs: {
317
+ id: generateMessageTag(),
318
+ type: 'set',
319
+ xmlns: 'newsletter',
320
+ to: jid
321
+ },
322
+ content: [
323
+ {
324
+ tag: 'publish',
325
+ attrs: {},
326
+ content: Array.isArray(content) ? content : [content]
327
+ }
328
+ ]
329
+ })
330
+ return result
331
+ },
332
+
333
+ newsletterPinMessage: async (jid, serverId, durationSecs = 86400) => {
334
+ await query({
335
+ tag: 'iq',
336
+ attrs: {
337
+ id: generateMessageTag(),
338
+ type: 'set',
339
+ xmlns: 'newsletter',
340
+ to: jid
341
+ },
342
+ content: [
343
+ {
344
+ tag: 'pin',
345
+ attrs: { server_id: String(serverId), duration: String(durationSecs) }
346
+ }
347
+ ]
348
+ })
349
+ },
350
+
351
+ newsletterUnpinMessage: async (jid, serverId) => {
352
+ await query({
353
+ tag: 'iq',
354
+ attrs: {
355
+ id: generateMessageTag(),
356
+ type: 'set',
357
+ xmlns: 'newsletter',
358
+ to: jid
359
+ },
360
+ content: [
361
+ {
362
+ tag: 'unpin',
363
+ attrs: { server_id: String(serverId) }
364
+ }
365
+ ]
366
+ })
367
+ },
368
+
369
+ newsletterInviteAdmin: async (jid, userJid) => {
370
+ return mexQuery(
371
+ { newsletter_id: jid, user_id: userJid },
372
+ Types.QueryIds.ADMIN_INVITE,
373
+ Types.XWAPaths.xwa2_newsletter_admin_invite_create
374
+ )
375
+ },
376
+
377
+ newsletterRevokeAdminInvite: async (jid, userJid) => {
378
+ return mexQuery(
379
+ { newsletter_id: jid, user_id: userJid },
380
+ Types.QueryIds.ADMIN_INVITE_REVOKE,
381
+ Types.XWAPaths.xwa2_newsletter_admin_invite_revoke
382
+ )
383
+ },
384
+
385
+ newsletterAcceptAdminInvite: async jid => {
386
+ return mexQuery(
387
+ { newsletter_id: jid },
388
+ Types.QueryIds.ADMIN_INVITE_ACCEPT,
389
+ Types.XWAPaths.xwa2_newsletter_admin_invite_accept
390
+ )
391
+ },
392
+
393
+ newsletterAdminMetadata: async (jid, options = {}) => {
394
+ const {
395
+ fetchPendingAdmins = true,
396
+ fetchAdminCount = true,
397
+ fetchCapabilities = false,
398
+ fetchAdminProfile = false,
399
+ includeAdminSettings = false,
400
+ includeJarvisConfig = false
401
+ } = options
402
+ return mexQuery(
403
+ {
404
+ jid,
405
+ include_thread_metadata: false,
406
+ include_messages: false,
407
+ fetch_pending_admin_invites: fetchPendingAdmins,
408
+ fetch_admin_count: fetchAdminCount,
409
+ fetch_capabilities: fetchCapabilities,
410
+ fetch_admin_profile: fetchAdminProfile,
411
+ include_admin_settings: includeAdminSettings,
412
+ include_jarvis_config: includeJarvisConfig
413
+ },
414
+ Types.QueryIds.ADMIN_METADATA,
415
+ Types.XWAPaths.xwa2_newsletter_admin
416
+ )
417
+ },
418
+
419
+ newsletterAdminProfileUpdate: async (jid, updates) => {
420
+ return mexQuery(
421
+ { newsletter_id: jid, updates },
422
+ Types.QueryIds.ADMIN_PROFILE_UPDATE,
423
+ Types.XWAPaths.xwa2_newsletter_admin_profile_update
424
+ )
425
+ },
426
+
427
+ newsletterDirectoryList: async (options = {}) => {
428
+ const { limit = 20, interests = null, sortField = 'SUBSCRIBER_COUNT', sortOrder = 'DESC' } = options
429
+ const variables = { limit, sort_field: sortField, sort_order: sortOrder }
430
+ if (interests?.length) variables.interests = interests
431
+ return mexQuery(variables, Types.QueryIds.DIRECTORY_LIST, Types.XWAPaths.xwa2_newsletters_directory_list)
432
+ },
433
+
434
+ newsletterDirectorySearch: async (searchText, options = {}) => {
435
+ const { limit = 20, startCursor = null, categories = null } = options
436
+ const variables = { search_text: searchText, limit }
437
+ if (startCursor) variables.start_cursor = startCursor
438
+ if (categories?.length) variables.categories = categories
439
+ return mexQuery(
440
+ variables,
441
+ Types.QueryIds.DIRECTORY_SEARCH,
442
+ Types.XWAPaths.xwa2_newsletters_directory_search
443
+ )
444
+ },
445
+
446
+ newsletterDirectoryCategoryPreview: async (limit = 5) => {
447
+ return mexQuery(
448
+ { limit },
449
+ Types.QueryIds.DIRECTORY_CATEGORY_PREVIEW,
450
+ Types.XWAPaths.xwa2_newsletters_directory_category_preview
451
+ )
452
+ },
453
+
454
+ newsletterSearch: async (query, limit = 20, startCursor = null) => {
455
+ const variables = { query, limit }
456
+ if (startCursor) variables.start_cursor = startCursor
457
+ return mexQuery(variables, Types.QueryIds.SEARCH, Types.XWAPaths.xwa2_newsletters_search)
458
+ },
459
+
460
+ newsletterRecommended: async (limit = 10, numFollowed = null) => {
461
+ const variables = { limit }
462
+ if (numFollowed != null) variables.num_newsletters_followed = numFollowed
463
+ return mexQuery(variables, Types.QueryIds.RECOMMENDED, Types.XWAPaths.xwa2_newsletters_recommended)
464
+ },
465
+
466
+ newsletterSimilar: async (jid, limit = 10) => {
467
+ return mexQuery(
468
+ { newsletter_id: jid, limit },
469
+ Types.QueryIds.SIMILAR,
470
+ Types.XWAPaths.xwa2_newsletters_similar
471
+ )
472
+ },
473
+
474
+ newsletterFollowingList: async (startCursor = null, limit = 20) => {
475
+ const variables = { limit }
476
+ if (startCursor) variables.start_cursor = startCursor
477
+ return mexQuery(variables, Types.QueryIds.FOLLOWING_LIST, Types.XWAPaths.xwa2_newsletter_following)
478
+ },
479
+
480
+ newsletterInsights: async (jid, period = null) => {
481
+ const variables = { newsletter_id: jid }
482
+ if (period) variables.period = period
483
+ return mexQuery(variables, Types.QueryIds.INSIGHTS, Types.XWAPaths.xwa2_newsletter_admin_insights)
484
+ },
485
+
486
+ newsletterPollVoterList: async (jid, serverId, option = null, startCursor = null) => {
487
+ const variables = { id: jid, server_id: serverId }
488
+ if (option != null) variables.option = option
489
+ if (startCursor) variables.start_cursor = startCursor
490
+ return mexQuery(
491
+ variables,
492
+ Types.QueryIds.POLL_VOTER_LIST,
493
+ Types.XWAPaths.xwa2_newsletters_poll_voter_list
494
+ )
495
+ },
496
+
497
+ newsletterReactionSenders: async (jid, serverId, startCursor = null) => {
498
+ const variables = { id: jid, server_id: serverId }
499
+ if (startCursor) variables.start_cursor = startCursor
500
+ return mexQuery(
501
+ variables,
502
+ Types.QueryIds.REACTION_SENDERS_LIST,
503
+ Types.XWAPaths.xwa2_newsletters_reaction_sender_list
504
+ )
505
+ },
506
+
507
+ newsletterBlockUser: async (jid, userJid) => {
508
+ return mexQuery(
509
+ { newsletter_id: jid, user_id: userJid },
510
+ Types.QueryIds.BLOCK_USER,
511
+ 'xwa2_newsletter_block_user'
512
+ )
513
+ },
514
+
515
+ newsletterEnableWamo: async jid => {
516
+ return mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_ENABLE_SUB, 'xwa2_newsletter_wamo_enable_sub')
517
+ },
518
+
519
+ newsletterDisableWamo: async jid => {
520
+ return mexQuery(
521
+ { newsletter_id: jid },
522
+ Types.QueryIds.WAMO_DISABLE_SUB,
523
+ 'xwa2_newsletter_wamo_disable_sub'
524
+ )
525
+ },
526
+
527
+ newsletterChangeWamo: async (jid, subConfig) => {
528
+ return mexQuery(
529
+ { newsletter_id: jid, ...subConfig },
530
+ Types.QueryIds.WAMO_CHANGE_SUB,
531
+ 'xwa2_newsletter_wamo_change_sub'
532
+ )
533
+ },
534
+
535
+ wamoAfsAgeCollection: async jid =>
536
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_AFS_AGE_COLLECTION, Types.XWAPaths.xwa2_wamo_afs_age_collection),
537
+
538
+ wamoAssetCollection: async jid =>
539
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_ASSET_COLLECTION, Types.XWAPaths.xwa2_wamo_asset_collection),
540
+
541
+ wamoFetchAdhocNotice: async noticeId =>
542
+ mexQuery({ notice_id: noticeId }, Types.QueryIds.WAMO_FETCH_ADHOC_NOTICE, Types.XWAPaths.xwa2_wamo_fetch_adhoc_notice_by_id),
543
+
544
+ wamoFetchIdentityToken: async jid =>
545
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_FETCH_IDENTITY_TOKEN, Types.XWAPaths.xwa2_wamo_fetch_identity_token),
546
+
547
+ wamoSubComplianceInfo: async jid =>
548
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_SUB_COMPLIANCE_INFO, Types.XWAPaths.xwa2_wamo_sub_get_compliance_info),
549
+
550
+ wamoUserIdVersion: async jid =>
551
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.WAMO_USER_ID_VERSION, Types.XWAPaths.xwa2_wamo_user_id_version),
552
+
553
+ wamoSetUserIdVersion: async (jid, version) =>
554
+ mexQuery({ newsletter_id: jid, version }, Types.QueryIds.WAMO_SET_USER_ID_VERSION, Types.XWAPaths.xwa2_wamo_set_user_id_version),
555
+
556
+ newsletterLeave: async jid =>
557
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.LEAVE, Types.XWAPaths.xwa2_newsletter_leave_v2),
558
+
559
+ newsletterCreateVerified: async (name, description = null) =>
560
+ mexQuery(
561
+ { input: { name, description } },
562
+ Types.QueryIds.CREATE_VERIFIED,
563
+ Types.XWAPaths.xwa2_newsletter_create_verified
564
+ ),
565
+
566
+ newsletterEnforcements: async jid =>
567
+ mexQuery({ newsletter_id: jid }, Types.QueryIds.ENFORCEMENTS, Types.XWAPaths.xwa2_newsletter_enforcements),
568
+
569
+ newsletterUserReports: async (jid, cursor = null) => {
570
+ const variables = { newsletter_id: jid }
571
+ if (cursor) variables.cursor = cursor
572
+ return mexQuery(variables, Types.QueryIds.USER_REPORTS, Types.XWAPaths.xwa2_newsletter_user_reports)
573
+ },
574
+
575
+ newsletterCreateReportAppeal: async (jid, reason) =>
576
+ mexQuery(
577
+ { newsletter_id: jid, reason },
578
+ Types.QueryIds.CREATE_REPORT_APPEAL,
579
+ Types.XWAPaths.xwa2_newsletter_create_report_appeal
580
+ ),
581
+
582
+ newsletterLinkPreviewCheck: async url =>
583
+ mexQuery({ url }, Types.QueryIds.LINK_PREVIEW_CHECK, Types.XWAPaths.xwa2_newsletter_link_preview_check),
584
+
585
+ newsletterUpdateVerification: async (jid, verification) =>
586
+ mexQuery(
587
+ { newsletter_id: jid, verification },
588
+ Types.QueryIds.UPDATE_VERIFICATION,
589
+ Types.XWAPaths.xwa2_newsletter_update_verification
590
+ ),
591
+
592
+ newsletterLabelPaidPartnership: async (jid, serverId, isPaidPartnership) =>
593
+ mexQuery(
594
+ { newsletter_id: jid, server_id: serverId, is_paid_partnership: isPaidPartnership },
595
+ Types.QueryIds.LABEL_PAID_PARTNERSHIP,
596
+ Types.XWAPaths.xwa2_newsletter_label_paid_partnership
597
+ ),
598
+
599
+ newsletterLogExposures: async events =>
600
+ mexQuery({ events }, Types.QueryIds.LOG_EXPOSURES, Types.XWAPaths.xwa2_newsletter_log_exposures),
601
+
602
+ newsletterUpdateUserSetting: async (jid, setting) =>
603
+ mexQuery(
604
+ { newsletter_id: jid, ...setting },
605
+ Types.QueryIds.UPDATE_USER_SETTING,
606
+ Types.XWAPaths.xwa2_newsletter_update_user_setting
607
+ ),
608
+
609
+ newsletterRankingFeatures: async jid =>
610
+ mexQuery(
611
+ { newsletter_id: jid },
612
+ Types.QueryIds.RANKING_FEATURES,
613
+ Types.XWAPaths.xwa2_newsletter_ranking_features
614
+ ),
615
+
616
+ newsletterSendViewReceipt: async (jid, serverMessageIds) => {
617
+ const ids = Array.isArray(serverMessageIds) ? serverMessageIds : [serverMessageIds]
618
+ const receiptId = generateMessageTag()
619
+ await query({
620
+ tag: 'receipt',
621
+ attrs: {
622
+ to: jid,
623
+ id: receiptId,
624
+ type: 'view'
625
+ },
626
+ content: [
627
+ {
628
+ tag: 'list',
629
+ attrs: {},
630
+ content: ids.map(id => ({ tag: 'item', attrs: { server_id: String(id) } }))
631
+ }
632
+ ]
633
+ })
634
+ }
635
+ }
636
+ }