supunmd-bail 2.0.1

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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +5519 -0
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +11969 -0
  6. package/WAProto/index.js +84368 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.d.ts +62 -0
  10. package/lib/Defaults/index.js +115 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  14. package/lib/Signal/Group/group-session-builder.js +30 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +82 -0
  17. package/lib/Signal/Group/index.d.ts +12 -0
  18. package/lib/Signal/Group/index.js +12 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  20. package/lib/Signal/Group/keyhelper.js +18 -0
  21. package/lib/Signal/Group/queue-job.d.ts +2 -0
  22. package/lib/Signal/Group/queue-job.js +54 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  24. package/lib/Signal/Group/sender-chain-key.js +26 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  28. package/lib/Signal/Group/sender-key-message.js +66 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-name.js +48 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  32. package/lib/Signal/Group/sender-key-record.js +41 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  34. package/lib/Signal/Group/sender-key-state.js +84 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  36. package/lib/Signal/Group/sender-message-key.js +26 -0
  37. package/lib/Signal/libsignal.d.ts +5 -0
  38. package/lib/Signal/libsignal.js +342 -0
  39. package/lib/Signal/lid-mapping.d.ts +23 -0
  40. package/lib/Signal/lid-mapping.js +171 -0
  41. package/lib/Socket/Client/index.d.ts +3 -0
  42. package/lib/Socket/Client/index.js +3 -0
  43. package/lib/Socket/Client/types.d.ts +16 -0
  44. package/lib/Socket/Client/types.js +11 -0
  45. package/lib/Socket/Client/websocket.d.ts +13 -0
  46. package/lib/Socket/Client/websocket.js +50 -0
  47. package/lib/Socket/business.d.ts +188 -0
  48. package/lib/Socket/business.js +376 -0
  49. package/lib/Socket/chats.d.ts +98 -0
  50. package/lib/Socket/chats.js +962 -0
  51. package/lib/Socket/communities.d.ts +244 -0
  52. package/lib/Socket/communities.js +431 -0
  53. package/lib/Socket/groups.d.ts +137 -0
  54. package/lib/Socket/groups.js +327 -0
  55. package/lib/Socket/index.d.ts +231 -0
  56. package/lib/Socket/index.js +18 -0
  57. package/lib/Socket/messages-recv.d.ts +173 -0
  58. package/lib/Socket/messages-recv.js +1228 -0
  59. package/lib/Socket/messages-send.d.ts +169 -0
  60. package/lib/Socket/messages-send.js +1070 -0
  61. package/lib/Socket/mex.d.ts +3 -0
  62. package/lib/Socket/mex.js +42 -0
  63. package/lib/Socket/newsletter.d.ts +147 -0
  64. package/lib/Socket/newsletter.js +181 -0
  65. package/lib/Socket/socket.d.ts +51 -0
  66. package/lib/Socket/socket.js +883 -0
  67. package/lib/Socket/usync.d.ts +37 -0
  68. package/lib/Socket/usync.js +63 -0
  69. package/lib/Types/Auth.d.ts +111 -0
  70. package/lib/Types/Auth.js +2 -0
  71. package/lib/Types/Bussines.d.ts +25 -0
  72. package/lib/Types/Bussines.js +2 -0
  73. package/lib/Types/Call.d.ts +14 -0
  74. package/lib/Types/Call.js +2 -0
  75. package/lib/Types/Chat.d.ts +123 -0
  76. package/lib/Types/Chat.js +8 -0
  77. package/lib/Types/Contact.d.ts +24 -0
  78. package/lib/Types/Contact.js +2 -0
  79. package/lib/Types/Events.d.ts +202 -0
  80. package/lib/Types/Events.js +2 -0
  81. package/lib/Types/GroupMetadata.d.ts +67 -0
  82. package/lib/Types/GroupMetadata.js +2 -0
  83. package/lib/Types/Label.d.ts +47 -0
  84. package/lib/Types/Label.js +25 -0
  85. package/lib/Types/LabelAssociation.d.ts +30 -0
  86. package/lib/Types/LabelAssociation.js +7 -0
  87. package/lib/Types/Message.d.ts +303 -0
  88. package/lib/Types/Message.js +11 -0
  89. package/lib/Types/Newsletter.d.ts +135 -0
  90. package/lib/Types/Newsletter.js +31 -0
  91. package/lib/Types/Product.d.ts +79 -0
  92. package/lib/Types/Product.js +2 -0
  93. package/lib/Types/Signal.d.ts +76 -0
  94. package/lib/Types/Signal.js +2 -0
  95. package/lib/Types/Socket.d.ts +133 -0
  96. package/lib/Types/Socket.js +3 -0
  97. package/lib/Types/State.d.ts +39 -0
  98. package/lib/Types/State.js +13 -0
  99. package/lib/Types/USync.d.ts +26 -0
  100. package/lib/Types/USync.js +2 -0
  101. package/lib/Types/index.d.ts +65 -0
  102. package/lib/Types/index.js +26 -0
  103. package/lib/Utils/auth-utils.d.ts +19 -0
  104. package/lib/Utils/auth-utils.js +257 -0
  105. package/lib/Utils/baileys-event-stream.d.ts +17 -0
  106. package/lib/Utils/baileys-event-stream.js +56 -0
  107. package/lib/Utils/browser-utils.d.ts +4 -0
  108. package/lib/Utils/browser-utils.js +28 -0
  109. package/lib/Utils/business.d.ts +23 -0
  110. package/lib/Utils/business.js +231 -0
  111. package/lib/Utils/chat-utils.d.ts +70 -0
  112. package/lib/Utils/chat-utils.js +763 -0
  113. package/lib/Utils/crypto.d.ts +41 -0
  114. package/lib/Utils/crypto.js +142 -0
  115. package/lib/Utils/decode-wa-message.d.ts +48 -0
  116. package/lib/Utils/decode-wa-message.js +279 -0
  117. package/lib/Utils/event-buffer.d.ts +34 -0
  118. package/lib/Utils/event-buffer.js +548 -0
  119. package/lib/Utils/generics.d.ts +90 -0
  120. package/lib/Utils/generics.js +381 -0
  121. package/lib/Utils/history.d.ts +19 -0
  122. package/lib/Utils/history.js +84 -0
  123. package/lib/Utils/index.d.ts +20 -0
  124. package/lib/Utils/index.js +20 -0
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +85 -0
  127. package/lib/Utils/logger.d.ts +12 -0
  128. package/lib/Utils/logger.js +3 -0
  129. package/lib/Utils/lt-hash.d.ts +13 -0
  130. package/lib/Utils/lt-hash.js +48 -0
  131. package/lib/Utils/make-mutex.d.ts +8 -0
  132. package/lib/Utils/make-mutex.js +40 -0
  133. package/lib/Utils/message-retry-manager.d.ts +82 -0
  134. package/lib/Utils/message-retry-manager.js +149 -0
  135. package/lib/Utils/messages-media.d.ts +114 -0
  136. package/lib/Utils/messages-media.js +663 -0
  137. package/lib/Utils/messages.d.ts +76 -0
  138. package/lib/Utils/messages.js +908 -0
  139. package/lib/Utils/noise-handler.d.ts +20 -0
  140. package/lib/Utils/noise-handler.js +147 -0
  141. package/lib/Utils/pre-key-manager.d.ts +28 -0
  142. package/lib/Utils/pre-key-manager.js +106 -0
  143. package/lib/Utils/process-message.d.ts +42 -0
  144. package/lib/Utils/process-message.js +413 -0
  145. package/lib/Utils/signal.d.ts +34 -0
  146. package/lib/Utils/signal.js +159 -0
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  148. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  149. package/lib/Utils/validate-connection.d.ts +11 -0
  150. package/lib/Utils/validate-connection.js +195 -0
  151. package/lib/WABinary/constants.d.ts +28 -0
  152. package/lib/WABinary/constants.js +1301 -0
  153. package/lib/WABinary/decode.d.ts +7 -0
  154. package/lib/WABinary/decode.js +238 -0
  155. package/lib/WABinary/encode.d.ts +3 -0
  156. package/lib/WABinary/encode.js +216 -0
  157. package/lib/WABinary/generic-utils.d.ts +15 -0
  158. package/lib/WABinary/generic-utils.js +191 -0
  159. package/lib/WABinary/index.d.ts +6 -0
  160. package/lib/WABinary/index.js +6 -0
  161. package/lib/WABinary/jid-utils.d.ts +48 -0
  162. package/lib/WABinary/jid-utils.js +96 -0
  163. package/lib/WABinary/types.d.ts +19 -0
  164. package/lib/WABinary/types.js +2 -0
  165. package/lib/WAM/BinaryInfo.d.ts +9 -0
  166. package/lib/WAM/BinaryInfo.js +10 -0
  167. package/lib/WAM/constants.d.ts +40 -0
  168. package/lib/WAM/constants.js +22853 -0
  169. package/lib/WAM/encode.d.ts +3 -0
  170. package/lib/WAM/encode.js +150 -0
  171. package/lib/WAM/index.d.ts +4 -0
  172. package/lib/WAM/index.js +4 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  185. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  186. package/lib/WAUSync/Protocols/index.js +5 -0
  187. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  188. package/lib/WAUSync/USyncQuery.js +94 -0
  189. package/lib/WAUSync/USyncUser.d.ts +13 -0
  190. package/lib/WAUSync/USyncUser.js +23 -0
  191. package/lib/WAUSync/index.d.ts +4 -0
  192. package/lib/WAUSync/index.js +4 -0
  193. package/lib/index.d.ts +22 -0
  194. package/lib/index.js +36 -0
  195. package/lib/supun +1 -0
  196. package/package.json +104 -0
@@ -0,0 +1,3 @@
1
+ import type { BinaryNode } from '../WABinary/index.js';
2
+ export declare const executeWMexQuery: <T>(variables: Record<string, unknown>, queryId: string, dataPath: string, query: (node: BinaryNode) => Promise<BinaryNode>, generateMessageTag: () => string) => Promise<T>;
3
+ //# sourceMappingURL=mex.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
3
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
+ return query({
5
+ tag: 'iq',
6
+ attrs: {
7
+ id: generateMessageTag(),
8
+ type: 'get',
9
+ to: S_WHATSAPP_NET,
10
+ xmlns: 'w:mex'
11
+ },
12
+ content: [
13
+ {
14
+ tag: 'query',
15
+ attrs: { query_id: queryId },
16
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
17
+ }
18
+ ]
19
+ });
20
+ };
21
+ export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
22
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
23
+ const child = getBinaryNodeChild(result, 'result');
24
+ if (child?.content) {
25
+ const data = JSON.parse(child.content.toString());
26
+ if (data.errors && data.errors.length > 0) {
27
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
28
+ const firstError = data.errors[0];
29
+ const errorCode = firstError.extensions?.error_code || 400;
30
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
31
+ }
32
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
33
+ if (typeof response !== 'undefined') {
34
+ return response;
35
+ }
36
+ }
37
+ const action = (dataPath || '').startsWith('xwa2_')
38
+ ? dataPath.substring(5).replace(/_/g, ' ')
39
+ : dataPath?.replace(/_/g, ' ');
40
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
+ };
42
+ //# sourceMappingURL=mex.js.map
@@ -0,0 +1,147 @@
1
+ import type { SocketConfig, WAMediaUpload } from '../Types/index.js';
2
+ import type { NewsletterMetadata, NewsletterUpdate } from '../Types/index.js';
3
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
4
+ newsletterCreate: (name: string, description?: string) => Promise<NewsletterMetadata>;
5
+ newsletterUpdate: (jid: string, updates: NewsletterUpdate) => Promise<unknown>;
6
+ newsletterSubscribers: (jid: string) => Promise<{
7
+ subscribers: number;
8
+ }>;
9
+ newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<NewsletterMetadata | null>;
10
+ newsletterFollow: (jid: string) => Promise<unknown>;
11
+ newsletterUnfollow: (jid: string) => Promise<unknown>;
12
+ newsletterMute: (jid: string) => Promise<unknown>;
13
+ newsletterUnmute: (jid: string) => Promise<unknown>;
14
+ newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
15
+ newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
16
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<unknown>;
17
+ newsletterRemovePicture: (jid: string) => Promise<unknown>;
18
+ newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
19
+ newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
20
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
21
+ duration: string;
22
+ } | null>;
23
+ newsletterAdminCount: (jid: string) => Promise<number>;
24
+ newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
25
+ newsletterDemote: (jid: string, userJid: string) => Promise<void>;
26
+ newsletterDelete: (jid: string) => Promise<void>;
27
+ groupMetadata: (jid: string) => Promise<import("../index.js").GroupMetadata>;
28
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../index.js").GroupMetadata>;
29
+ groupLeave: (id: string) => Promise<void>;
30
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
31
+ groupRequestParticipantsList: (jid: string) => Promise<{
32
+ [key: string]: string;
33
+ }[]>;
34
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
35
+ status: string;
36
+ jid: string | undefined;
37
+ }[]>;
38
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../index.js").ParticipantAction) => Promise<{
39
+ status: string;
40
+ jid: string | undefined;
41
+ content: import("../index.js").BinaryNode;
42
+ }[]>;
43
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
44
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
45
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
46
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
47
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
48
+ groupAcceptInviteV4: (key: string | import("../index.js").WAMessageKey, inviteMessage: import("../index.js").proto.Message.IGroupInviteMessage) => Promise<any>;
49
+ groupGetInviteInfo: (code: string) => Promise<import("../index.js").GroupMetadata>;
50
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
51
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
52
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
53
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
54
+ groupFetchAllParticipating: () => Promise<{
55
+ [_: string]: import("../index.js").GroupMetadata;
56
+ }>;
57
+ createCallLink: (type: "audio" | "video", event?: {
58
+ startTime: number;
59
+ }, timeoutMs?: number) => Promise<string | undefined>;
60
+ getBotListV2: () => Promise<import("../index.js").BotListInfo[]>;
61
+ processingMutex: {
62
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
63
+ };
64
+ fetchPrivacySettings: (force?: boolean) => Promise<{
65
+ [_: string]: string;
66
+ }>;
67
+ upsertMessage: (msg: import("../index.js").WAMessage, type: import("../index.js").MessageUpsertType) => Promise<void>;
68
+ appPatch: (patchCreate: import("../index.js").WAPatchCreate) => Promise<void>;
69
+ sendPresenceUpdate: (type: import("../index.js").WAPresence, toJid?: string) => Promise<void>;
70
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
71
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
72
+ fetchBlocklist: () => Promise<(string | undefined)[]>;
73
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
74
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
75
+ updateProfilePicture: (jid: string, content: WAMediaUpload, dimensions?: {
76
+ width: number;
77
+ height: number;
78
+ }) => Promise<void>;
79
+ removeProfilePicture: (jid: string) => Promise<void>;
80
+ updateProfileStatus: (status: string) => Promise<void>;
81
+ updateProfileName: (name: string) => Promise<void>;
82
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
83
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
84
+ updateCallPrivacy: (value: import("../index.js").WAPrivacyCallValue) => Promise<void>;
85
+ updateMessagesPrivacy: (value: import("../index.js").WAPrivacyMessagesValue) => Promise<void>;
86
+ updateLastSeenPrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
87
+ updateOnlinePrivacy: (value: import("../index.js").WAPrivacyOnlineValue) => Promise<void>;
88
+ updateProfilePicturePrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
89
+ updateStatusPrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
90
+ updateReadReceiptsPrivacy: (value: import("../index.js").WAReadReceiptsValue) => Promise<void>;
91
+ updateGroupsAddPrivacy: (value: import("../index.js").WAPrivacyGroupAddValue) => Promise<void>;
92
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
93
+ getBusinessProfile: (jid: string) => Promise<import("../index.js").WABusinessProfile | void>;
94
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
95
+ chatModify: (mod: import("../index.js").ChatModification, jid: string) => Promise<void>;
96
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
97
+ addOrEditContact: (jid: string, contact: import("../index.js").proto.SyncActionValue.IContactAction) => Promise<void>;
98
+ removeContact: (jid: string) => Promise<void>;
99
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
100
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
101
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
102
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
103
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
104
+ star: (jid: string, messages: {
105
+ id: string;
106
+ fromMe?: boolean;
107
+ }[], star: boolean) => Promise<void>;
108
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
109
+ removeQuickReply: (timestamp: string) => Promise<void>;
110
+ type: "md";
111
+ ws: import("./Client/index.js").WebSocketClient;
112
+ ev: import("../index.js").BaileysEventEmitter & {
113
+ process(handler: (events: Partial<import("../index.js").BaileysEventMap>) => void | Promise<void>): () => void;
114
+ buffer(): void;
115
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
116
+ flush(): boolean;
117
+ isBuffering(): boolean;
118
+ };
119
+ authState: {
120
+ creds: import("../index.js").AuthenticationCreds;
121
+ keys: import("../index.js").SignalKeyStoreWithTransaction;
122
+ };
123
+ signalRepository: import("../index.js").SignalRepositoryWithLIDStore;
124
+ user: import("../index.js").Contact | undefined;
125
+ generateMessageTag: () => string;
126
+ query: (node: import("../index.js").BinaryNode, timeoutMs?: number) => Promise<any>;
127
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
128
+ waitForSocketOpen: () => Promise<void>;
129
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
130
+ sendNode: (frame: import("../index.js").BinaryNode) => Promise<void>;
131
+ logout: (msg?: string) => Promise<void>;
132
+ end: (error: Error | undefined) => void;
133
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
134
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
135
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
136
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
137
+ wamBuffer: import("../index.js").BinaryInfo;
138
+ waitForConnectionUpdate: (check: (u: Partial<import("../index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
139
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
140
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
141
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
142
+ jid: string;
143
+ exists: boolean;
144
+ }[] | undefined>;
145
+ };
146
+ export type NewsletterSocket = ReturnType<typeof makeNewsletterSocket>;
147
+ //# sourceMappingURL=newsletter.d.ts.map
@@ -0,0 +1,181 @@
1
+ import { QueryIds, XWAPaths } 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 as genericExecuteWMexQuery } from './mex.js';
6
+ const parseNewsletterCreateResponse = (response) => {
7
+ const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
8
+ return {
9
+ id: id,
10
+ owner: undefined,
11
+ name: thread.name.text,
12
+ creation_time: parseInt(thread.creation_time, 10),
13
+ description: thread.description.text,
14
+ invite: thread.invite,
15
+ subscribers: parseInt(thread.subscribers_count, 10),
16
+ verification: thread.verification,
17
+ picture: {
18
+ id: thread.picture.id,
19
+ directPath: thread.picture.direct_path
20
+ },
21
+ mute_state: viewer.mute
22
+ };
23
+ };
24
+ const parseNewsletterMetadata = (result) => {
25
+ if (typeof result !== 'object' || result === null) {
26
+ return null;
27
+ }
28
+ if ('id' in result && typeof result.id === 'string') {
29
+ return result;
30
+ }
31
+ if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
32
+ return result.result;
33
+ }
34
+ return null;
35
+ };
36
+ export const makeNewsletterSocket = (config) => {
37
+ const sock = makeGroupsSocket(config);
38
+ const { query, generateMessageTag } = sock;
39
+ const executeWMexQuery = (variables, queryId, dataPath) => {
40
+ return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
41
+ };
42
+ const newsletterUpdate = async (jid, updates) => {
43
+ const variables = {
44
+ newsletter_id: jid,
45
+ updates: {
46
+ ...updates,
47
+ settings: null
48
+ }
49
+ };
50
+ return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
51
+ };
52
+ return {
53
+ ...sock,
54
+ newsletterCreate: async (name, description) => {
55
+ const variables = {
56
+ input: {
57
+ name,
58
+ description: description ?? null
59
+ }
60
+ };
61
+ const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
62
+ return parseNewsletterCreateResponse(rawResponse);
63
+ },
64
+ newsletterUpdate,
65
+ newsletterSubscribers: async (jid) => {
66
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
67
+ },
68
+ newsletterMetadata: async (type, key) => {
69
+ const variables = {
70
+ fetch_creation_time: true,
71
+ fetch_full_image: true,
72
+ fetch_viewer_metadata: true,
73
+ input: {
74
+ key,
75
+ type: type.toUpperCase()
76
+ }
77
+ };
78
+ const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
79
+ return parseNewsletterMetadata(result);
80
+ },
81
+ newsletterFollow: (jid) => {
82
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
83
+ },
84
+ newsletterUnfollow: (jid) => {
85
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
86
+ },
87
+ newsletterMute: (jid) => {
88
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
89
+ },
90
+ newsletterUnmute: (jid) => {
91
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
92
+ },
93
+ newsletterUpdateName: async (jid, name) => {
94
+ return await newsletterUpdate(jid, { name });
95
+ },
96
+ newsletterUpdateDescription: async (jid, description) => {
97
+ return await newsletterUpdate(jid, { description });
98
+ },
99
+ newsletterUpdatePicture: async (jid, content) => {
100
+ const { img } = await generateProfilePicture(content);
101
+ return await newsletterUpdate(jid, { picture: img.toString('base64') });
102
+ },
103
+ newsletterRemovePicture: async (jid) => {
104
+ return await newsletterUpdate(jid, { picture: '' });
105
+ },
106
+ newsletterReactMessage: async (jid, serverId, reaction) => {
107
+ await query({
108
+ tag: 'message',
109
+ attrs: {
110
+ to: jid,
111
+ ...(reaction ? {} : { edit: '7' }),
112
+ type: 'reaction',
113
+ server_id: serverId,
114
+ id: generateMessageTag()
115
+ },
116
+ content: [
117
+ {
118
+ tag: 'reaction',
119
+ attrs: reaction ? { code: reaction } : {}
120
+ }
121
+ ]
122
+ });
123
+ },
124
+ newsletterFetchMessages: async (jid, count, since, after) => {
125
+ const messageUpdateAttrs = {
126
+ count: count.toString()
127
+ };
128
+ if (typeof since === 'number') {
129
+ messageUpdateAttrs.since = since.toString();
130
+ }
131
+ if (after) {
132
+ messageUpdateAttrs.after = after.toString();
133
+ }
134
+ const result = await query({
135
+ tag: 'iq',
136
+ attrs: {
137
+ id: generateMessageTag(),
138
+ type: 'get',
139
+ xmlns: 'newsletter',
140
+ to: jid
141
+ },
142
+ content: [
143
+ {
144
+ tag: 'message_updates',
145
+ attrs: messageUpdateAttrs
146
+ }
147
+ ]
148
+ });
149
+ return result;
150
+ },
151
+ subscribeNewsletterUpdates: async (jid) => {
152
+ const result = await query({
153
+ tag: 'iq',
154
+ attrs: {
155
+ id: generateMessageTag(),
156
+ type: 'set',
157
+ xmlns: 'newsletter',
158
+ to: jid
159
+ },
160
+ content: [{ tag: 'live_updates', attrs: {}, content: [] }]
161
+ });
162
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
163
+ const duration = liveUpdatesNode?.attrs?.duration;
164
+ return duration ? { duration: duration } : null;
165
+ },
166
+ newsletterAdminCount: async (jid) => {
167
+ const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
168
+ return response.admin_count;
169
+ },
170
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
171
+ await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
172
+ },
173
+ newsletterDemote: async (jid, userJid) => {
174
+ await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
175
+ },
176
+ newsletterDelete: async (jid) => {
177
+ await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
178
+ }
179
+ };
180
+ };
181
+ //# sourceMappingURL=newsletter.js.map
@@ -0,0 +1,51 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import type { SocketConfig } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ import { BinaryInfo } from '../WAM/BinaryInfo.js';
5
+ import { USyncQuery } from '../WAUSync/index.js';
6
+ import { WebSocketClient } from './Client/index.js';
7
+ /**
8
+ * Connects to WA servers and performs:
9
+ * - simple queries (no retry mechanism, wait for connection establishment)
10
+ * - listen to messages and emit events
11
+ * - query phone connection
12
+ */
13
+ export declare const makeSocket: (config: SocketConfig) => {
14
+ type: "md";
15
+ ws: WebSocketClient;
16
+ ev: import("../Types/index.js").BaileysEventEmitter & {
17
+ process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
18
+ buffer(): void;
19
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
20
+ flush(): boolean;
21
+ isBuffering(): boolean;
22
+ };
23
+ authState: {
24
+ creds: import("../Types/index.js").AuthenticationCreds;
25
+ keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
26
+ };
27
+ signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
28
+ readonly user: import("../Types/index.js").Contact | undefined;
29
+ generateMessageTag: () => string;
30
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
31
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
32
+ waitForSocketOpen: () => Promise<void>;
33
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
34
+ sendNode: (frame: BinaryNode) => Promise<void>;
35
+ logout: (msg?: string) => Promise<void>;
36
+ end: (error: Error | undefined) => void;
37
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
38
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
39
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
40
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
41
+ wamBuffer: BinaryInfo;
42
+ /** Waits for the connection to WA to reach a state */
43
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
44
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
45
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
46
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
47
+ jid: string;
48
+ exists: boolean;
49
+ }[] | undefined>;
50
+ };
51
+ //# sourceMappingURL=socket.d.ts.map