sanka-baileyss 2.3.2 → 2.3.4

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 (159) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/Group/sender-key-record.js +23 -28
  24. package/lib/Signal/libsignal.d.ts +1 -0
  25. package/lib/Socket/Client/index.js +13 -9
  26. package/lib/Socket/Client/types.d.ts +11 -10
  27. package/lib/Socket/Client/types.js +11 -7
  28. package/lib/Socket/Client/websocket.d.ts +9 -8
  29. package/lib/Socket/Client/websocket.js +52 -47
  30. package/lib/Socket/business.d.ts +185 -182
  31. package/lib/Socket/business.js +258 -249
  32. package/lib/Socket/chats.d.ts +90 -87
  33. package/lib/Socket/chats.js +1095 -888
  34. package/lib/Socket/community.d.ts +131 -0
  35. package/lib/Socket/community.js +369 -0
  36. package/lib/Socket/groups.d.ts +50 -41
  37. package/lib/Socket/groups.js +10 -3
  38. package/lib/Socket/index.d.ts +5 -1
  39. package/lib/Socket/index.js +19 -5
  40. package/lib/Socket/messages-recv.d.ts +6 -2
  41. package/lib/Socket/messages-recv.js +31 -8
  42. package/lib/Socket/messages-send.d.ts +5 -1
  43. package/lib/Socket/messages-send.js +1293 -1351
  44. package/lib/Socket/newsletter.d.ts +142 -135
  45. package/lib/Socket/newsletter.js +274 -230
  46. package/lib/Socket/socket.d.ts +37 -35
  47. package/lib/Socket/usync.d.ts +31 -30
  48. package/lib/Socket/usync.js +74 -62
  49. package/lib/Types/Auth.d.ts +89 -72
  50. package/lib/Types/Auth.js +1 -0
  51. package/lib/Types/Call.d.ts +11 -10
  52. package/lib/Types/Call.js +1 -0
  53. package/lib/Types/Chat.d.ts +85 -62
  54. package/lib/Types/Chat.js +4 -1
  55. package/lib/Types/Contact.js +1 -0
  56. package/lib/Types/Events.d.ts +209 -191
  57. package/lib/Types/Events.js +1 -0
  58. package/lib/Types/GroupMetadata.d.ts +12 -27
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.d.ts +41 -39
  61. package/lib/Types/Label.js +24 -21
  62. package/lib/Types/LabelAssociation.d.ts +18 -12
  63. package/lib/Types/LabelAssociation.js +6 -3
  64. package/lib/Types/Message.d.ts +3 -2
  65. package/lib/Types/Message.js +7 -3
  66. package/lib/Types/MexUpdates.d.ts +9 -0
  67. package/lib/Types/MexUpdates.js +18 -0
  68. package/lib/Types/Newsletter.d.ts +84 -67
  69. package/lib/Types/Newsletter.js +30 -23
  70. package/lib/Types/Product.d.ts +70 -56
  71. package/lib/Types/Product.js +1 -0
  72. package/lib/Types/Signal.d.ts +46 -35
  73. package/lib/Types/Signal.js +1 -0
  74. package/lib/Types/Socket.d.ts +105 -101
  75. package/lib/Types/Socket.js +1 -0
  76. package/lib/Types/State.d.ts +37 -23
  77. package/lib/Types/State.js +13 -1
  78. package/lib/Types/USync.d.ts +21 -20
  79. package/lib/Types/USync.js +1 -0
  80. package/lib/Types/index.d.ts +51 -42
  81. package/lib/Types/index.js +25 -19
  82. package/lib/Utils/auth-utils.d.ts +14 -11
  83. package/lib/Utils/auth-utils.js +189 -182
  84. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  85. package/lib/Utils/baileys-event-stream.js +52 -46
  86. package/lib/Utils/business.d.ts +15 -8
  87. package/lib/Utils/business.js +229 -217
  88. package/lib/Utils/chat-utils.d.ts +22 -12
  89. package/lib/Utils/chat-utils.js +57 -27
  90. package/lib/Utils/crypto.d.ts +31 -15
  91. package/lib/Utils/crypto.js +136 -107
  92. package/lib/Utils/decode-wa-message.d.ts +34 -245
  93. package/lib/Utils/decode-wa-message.js +205 -217
  94. package/lib/Utils/event-buffer.d.ts +30 -26
  95. package/lib/Utils/event-buffer.js +519 -515
  96. package/lib/Utils/history.d.ts +2 -8
  97. package/lib/Utils/index.js +13 -9
  98. package/lib/Utils/link-preview.d.ts +16 -14
  99. package/lib/Utils/link-preview.js +100 -92
  100. package/lib/Utils/logger.d.ts +9 -7
  101. package/lib/Utils/logger.js +1 -1
  102. package/lib/Utils/lt-hash.d.ts +10 -8
  103. package/lib/Utils/lt-hash.js +49 -44
  104. package/lib/Utils/make-mutex.d.ts +4 -2
  105. package/lib/Utils/make-mutex.js +43 -39
  106. package/lib/Utils/messages-media.d.ts +75 -50
  107. package/lib/Utils/messages.d.ts +60 -35
  108. package/lib/Utils/messages.js +87 -8
  109. package/lib/Utils/noise-handler.d.ts +13 -12
  110. package/lib/Utils/noise-handler.js +143 -138
  111. package/lib/Utils/process-message.d.ts +32 -24
  112. package/lib/Utils/process-message.js +387 -367
  113. package/lib/Utils/signal.d.ts +24 -15
  114. package/lib/Utils/signal.js +143 -131
  115. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  116. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  117. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  118. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  119. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  120. package/lib/Utils/use-single-file-auth-state.js +66 -61
  121. package/lib/Utils/validate-connection.d.ts +5 -2
  122. package/lib/Utils/validate-connection.js +7 -6
  123. package/lib/WABinary/constants.d.ts +24 -21
  124. package/lib/WABinary/constants.js +1302 -31
  125. package/lib/WABinary/decode.d.ts +4 -1
  126. package/lib/WABinary/decode.js +267 -234
  127. package/lib/WABinary/encode.d.ts +1 -0
  128. package/lib/WABinary/encode.js +248 -226
  129. package/lib/WABinary/generic-utils.d.ts +13 -1
  130. package/lib/WABinary/generic-utils.js +113 -96
  131. package/lib/WABinary/index.js +13 -9
  132. package/lib/WABinary/jid-utils.d.ts +23 -4
  133. package/lib/WABinary/jid-utils.js +58 -39
  134. package/lib/WABinary/types.d.ts +15 -11
  135. package/lib/WABinary/types.js +1 -0
  136. package/lib/WAM/BinaryInfo.d.ts +14 -14
  137. package/lib/WAM/BinaryInfo.js +11 -8
  138. package/lib/WAM/constants.d.ts +34 -26
  139. package/lib/WAM/constants.js +15358 -15349
  140. package/lib/WAM/encode.d.ts +1 -0
  141. package/lib/WAM/encode.js +153 -144
  142. package/lib/WAM/index.js +13 -9
  143. package/lib/index.js +11 -11
  144. package/package.json +1 -66
  145. package/WASignalGroup/GroupProtocol.js +0 -1771
  146. package/WASignalGroup/ciphertext_message.js +0 -10
  147. package/WASignalGroup/group_cipher.js +0 -103
  148. package/WASignalGroup/group_session_builder.js +0 -39
  149. package/WASignalGroup/index.js +0 -5
  150. package/WASignalGroup/keyhelper.js +0 -17
  151. package/WASignalGroup/protobufs.js +0 -2
  152. package/WASignalGroup/queue_job.js +0 -64
  153. package/WASignalGroup/sender_chain_key.js +0 -38
  154. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  155. package/WASignalGroup/sender_key_message.js +0 -79
  156. package/WASignalGroup/sender_key_name.js +0 -59
  157. package/WASignalGroup/sender_key_record.js +0 -47
  158. package/WASignalGroup/sender_key_state.js +0 -110
  159. package/WASignalGroup/sender_message_key.js +0 -30
@@ -1,125 +1,142 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const boom_1 = require("@hapi/boom")
4
6
  const WAProto_1 = require("../../WAProto")
7
+
5
8
  // some extra useful utilities
6
9
  const getBinaryNodeChildren = (node, childTag) => {
7
- if (Array.isArray(node?.content)) {
8
- return node.content.filter(item => item.tag === childTag)
9
- }
10
- return []
10
+ if (Array.isArray(node?.content)) {
11
+ return node.content.filter(item => item.tag === childTag)
12
+ }
13
+ return []
11
14
  }
15
+
12
16
  const getAllBinaryNodeChildren = ({ content }) => {
13
- if (Array.isArray(content)) {
14
- return content
15
- }
16
- return []
17
+ if (Array.isArray(content)) {
18
+ return content
19
+ }
20
+ return []
17
21
  }
22
+
18
23
  const getBinaryNodeChild = (node, childTag) => {
19
- if (Array.isArray(node?.content)) {
20
- return node?.content.find(item => item.tag === childTag)
21
- }
24
+ if (Array.isArray(node?.content)) {
25
+ return node?.content.find(item => item.tag === childTag)
26
+ }
22
27
  }
28
+
23
29
  const getBinaryNodeChildBuffer = (node, childTag) => {
24
- const child = getBinaryNodeChild(node, childTag)?.content
25
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
26
- return child
27
- }
30
+ const child = getBinaryNodeChild(node, childTag)?.content
31
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
32
+ return child
33
+ }
28
34
  }
35
+
29
36
  const getBinaryNodeChildString = (node, childTag) => {
30
- const child = getBinaryNodeChild(node, childTag)?.content
31
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
32
- return Buffer.from(child).toString('utf-8')
33
- }
34
- else if (typeof child === 'string') {
35
- return child
36
- }
37
- }
37
+ const child = getBinaryNodeChild(node, childTag)?.content
38
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
39
+ return Buffer.from(child).toString('utf-8')
40
+ }
41
+ else if (typeof child === 'string') {
42
+ return child
43
+ }
44
+ }
45
+
38
46
  const getBinaryNodeChildUInt = (node, childTag, length) => {
39
- const buff = getBinaryNodeChildBuffer(node, childTag)
40
- if (buff) {
41
- return bufferToUInt(buff, length)
42
- }
47
+ const buff = getBinaryNodeChildBuffer(node, childTag)
48
+ if (buff) {
49
+ return bufferToUInt(buff, length)
50
+ }
43
51
  }
52
+
44
53
  const assertNodeErrorFree = (node) => {
45
- const errNode = getBinaryNodeChild(node, 'error')
46
- if (errNode) {
47
- throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
48
- }
54
+ const errNode = getBinaryNodeChild(node, 'error')
55
+ if (errNode) {
56
+ throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
57
+ }
49
58
  }
59
+
50
60
  const reduceBinaryNodeToDictionary = (node, tag) => {
51
- const nodes = getBinaryNodeChildren(node, tag)
52
- const dict = nodes.reduce((dict, { attrs }) => {
53
- dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value
54
- return dict
55
- }, {})
56
- return dict
57
- }
61
+ const nodes = getBinaryNodeChildren(node, tag)
62
+ const dict = nodes.reduce((dict, { attrs }) => {
63
+ dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value
64
+ return dict
65
+ }, {})
66
+ return dict
67
+ }
68
+
58
69
  const getBinaryNodeMessages = ({ content }) => {
59
- const msgs = []
60
- if (Array.isArray(content)) {
61
- for (const item of content) {
62
- if (item.tag === 'message') {
63
- msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content))
64
- }
65
- }
66
- }
67
- return msgs
68
- }
70
+ const msgs = []
71
+ if (Array.isArray(content)) {
72
+ for (const item of content) {
73
+ if (item.tag === 'message') {
74
+ msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content))
75
+ }
76
+ }
77
+ }
78
+ return msgs
79
+ }
80
+
69
81
  const getBinaryFilteredButtons = (nodeContent) => {
70
- if (!Array.isArray(nodeContent)) return false
71
- return nodeContent.some(a =>
72
- ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
73
- ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
74
- ['hsm', 'biz'].includes(a?.tag)
75
- )
76
- }
82
+ if (!Array.isArray(nodeContent)) return false
83
+
84
+ return nodeContent.some(a =>
85
+ ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
86
+ ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
87
+ ['hsm', 'biz'].includes(a?.tag)
88
+ )
89
+ }
90
+
77
91
  const getBinaryFilteredBizBot = (nodeContent) => {
78
- if (!Array.isArray(nodeContent)) return false
79
- return nodeContent.some(b =>
80
- ['bot'].includes(b?.tag) && b?.attrs?.biz_bot === '1'
81
- )
92
+ if (!Array.isArray(nodeContent)) return false
93
+
94
+ return nodeContent.some(b =>
95
+ ['bot'].includes(b?.tag) && b?.attrs?.biz_bot === '1'
96
+ )
82
97
  }
98
+
83
99
  function bufferToUInt(e, t) {
84
- let a = 0
85
- for (let i = 0; i < t; i++) {
86
- a = 256 * a + e[i]
87
- }
88
- return a
100
+ let a = 0
101
+ for (let i = 0; i < t; i++) {
102
+ a = 256 * a + e[i]
103
+ }
104
+ return a
89
105
  }
90
106
  const tabs = (n) => '\t'.repeat(n)
91
107
  function binaryNodeToString(node, i = 0) {
92
- if (!node) {
93
- return node
94
- }
95
- if (typeof node === 'string') {
96
- return tabs(i) + node
97
- }
98
- if (node instanceof Uint8Array) {
99
- return tabs(i) + Buffer.from(node).toString('hex')
100
- }
101
- if (Array.isArray(node)) {
102
- return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n')
103
- }
104
- const children = binaryNodeToString(node.content, i + 1)
105
- const tag = `<${node.tag} ${Object.entries(node.attrs || {})
106
- .filter(([, v]) => v !== undefined)
107
- .map(([k, v]) => `${k}='${v}'`)
108
- .join(' ')}`
109
- const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>'
110
- return tag + content
111
- }
108
+ if (!node) {
109
+ return node
110
+ }
111
+ if (typeof node === 'string') {
112
+ return tabs(i) + node
113
+ }
114
+ if (node instanceof Uint8Array) {
115
+ return tabs(i) + Buffer.from(node).toString('hex')
116
+ }
117
+ if (Array.isArray(node)) {
118
+ return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n')
119
+ }
120
+ const children = binaryNodeToString(node.content, i + 1)
121
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {})
122
+ .filter(([, v]) => v !== undefined)
123
+ .map(([k, v]) => `${k}='${v}'`)
124
+ .join(' ')}`
125
+ const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>'
126
+ return tag + content
127
+ }
128
+
112
129
  module.exports = {
113
- getBinaryNodeChildren,
114
- getAllBinaryNodeChildren,
115
- getBinaryNodeChild,
116
- getBinaryNodeChildBuffer,
117
- getBinaryNodeChildString,
118
- getBinaryNodeChildUInt,
119
- assertNodeErrorFree,
120
- reduceBinaryNodeToDictionary,
121
- getBinaryNodeMessages,
122
- getBinaryFilteredButtons,
123
- getBinaryFilteredBizBot,
124
- binaryNodeToString
130
+ getBinaryNodeChildren,
131
+ getAllBinaryNodeChildren,
132
+ getBinaryNodeChild,
133
+ getBinaryNodeChildBuffer,
134
+ getBinaryNodeChildString,
135
+ getBinaryNodeChildUInt,
136
+ assertNodeErrorFree,
137
+ reduceBinaryNodeToDictionary,
138
+ getBinaryNodeMessages,
139
+ getBinaryFilteredButtons,
140
+ getBinaryFilteredBizBot,
141
+ binaryNodeToString
125
142
  }
@@ -1,19 +1,23 @@
1
1
  "use strict"
2
+
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k
4
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k] } }
7
- }
8
- Object.defineProperty(o, k2, desc)
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
9
10
  }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k
11
- o[k2] = m[k]
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
12
13
  }))
14
+
13
15
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
15
17
  }
18
+
16
19
  Object.defineProperty(exports, "__esModule", { value: true })
20
+
17
21
  __exportStar(require("./encode"), exports)
18
22
  __exportStar(require("./decode"), exports)
19
23
  __exportStar(require("./generic-utils"), exports)
@@ -1,34 +1,53 @@
1
1
  export declare const S_WHATSAPP_NET = "@s.whatsapp.net"
2
+
2
3
  export declare const OFFICIAL_BIZ_JID = "16505361212@c.us"
4
+
3
5
  export declare const SERVER_JID = "server@c.us"
6
+
4
7
  export declare const PSA_WID = "0@c.us"
8
+
5
9
  export declare const STORIES_JID = "status@broadcast"
10
+
6
11
  export declare const META_AI_JID = '13135550002@c.us'
12
+
7
13
  export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot'
14
+
8
15
  export type JidWithDevice = {
9
- user: string
10
- device?: number
16
+ user: string
17
+ device?: number
11
18
  }
19
+
12
20
  export type FullJid = JidWithDevice & {
13
- server: JidServer
14
- domainType?: number
21
+ server: JidServer
22
+ domainType?: number
15
23
  }
24
+
16
25
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string
26
+
17
27
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined
28
+
18
29
  /** is the jid a user */
19
30
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean
31
+
20
32
  /** is the lid a user */
21
33
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined
34
+
22
35
  /** is the jid a group */
23
36
  export declare const isLidUser: (jid: string | undefined) => boolean | undefined
37
+
24
38
  /** is the jid a broadcast */
25
39
  export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined
40
+
26
41
  /** is the jid a group */
27
42
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined
43
+
28
44
  /** is the jid the status broadcast */
29
45
  export declare const isJidStatusBroadcast: (jid: string) => boolean
46
+
30
47
  /** is the jid a newsletter */
31
48
  export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined
49
+
32
50
  /** is the jid a bot */
33
51
  export declare const isJidBot: (jid: string | undefined) => boolean | undefined
52
+
34
53
  export declare const jidNormalizedUser: (jid: string | undefined) => string
@@ -1,73 +1,92 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const S_WHATSAPP_NET = '@s.whatsapp.net'
6
+
4
7
  const OFFICIAL_BIZ_JID = '16505361212@c.us'
8
+
5
9
  const SERVER_JID = 'server@c.us'
10
+
6
11
  const PSA_WID = '0@c.us'
12
+
7
13
  const STORIES_JID = 'status@broadcast'
14
+
8
15
  const META_AI_JID = '13135550002@c.us'
16
+
9
17
  const jidEncode = (user, server, device, agent) => {
10
- return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`
18
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`
11
19
  }
20
+
12
21
  const jidDecode = (jid) => {
13
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
14
- if (sepIdx < 0) {
15
- return undefined
16
- }
17
- const server = jid.slice(sepIdx + 1)
18
- const userCombined = jid.slice(0, sepIdx)
19
- const [userAgent, device] = userCombined.split(':')
20
- const user = userAgent.split('_')[0]
21
- return {
22
- server: server,
23
- user,
24
- domainType: server === 'lid' ? 1 : 0,
25
- device: device ? +device : undefined
26
- }
22
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
23
+ if (sepIdx < 0) {
24
+ return undefined
25
+ }
26
+ const server = jid.slice(sepIdx + 1)
27
+ const userCombined = jid.slice(0, sepIdx)
28
+ const [userAgent, device] = userCombined.split(':')
29
+ const user = userAgent.split('_')[0]
30
+ return {
31
+ server: server,
32
+ user,
33
+ domainType: server === 'lid' ? 1 : 0,
34
+ device: device ? +device : undefined
35
+ }
27
36
  }
37
+
28
38
  /** is the jid a user */
29
39
  const areJidsSameUser = (jid1, jid2) => {
30
- return jidDecode(jid1)?.user === jidDecode(jid2)?.user
40
+ return jidDecode(jid1)?.user === jidDecode(jid2)?.user
31
41
  }
42
+
32
43
  /** is the jid a user */
33
44
  const isJidUser = (jid) => jid?.endsWith('@s.whatsapp.net')
45
+
34
46
  /** is the lid a user */
35
47
  const isLidUser = (jid) => jid?.endsWith('@lid')
48
+
36
49
  /** is the jid a broadcast */
37
50
  const isJidBroadcast = (jid) => jid?.endsWith('@broadcast')
51
+
38
52
  /** is the jid a group */
39
53
  const isJidGroup = (jid) => jid?.endsWith('@g.us')
54
+
40
55
  /** is the jid the status broadcast */
41
56
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast'
57
+
42
58
  /** is the jid a newsletter */
43
59
  const isJidNewsletter = (jid) => jid?.endsWith('@newsletter')
60
+
44
61
  /** is the jid a bot */
45
62
  const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
46
63
  const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'))
64
+
47
65
  const jidNormalizedUser = (jid) => {
48
- const result = jidDecode(jid)
49
- if (!result) {
50
- return ''
51
- }
52
- const { user, server } = result
53
- return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server)
66
+ const result = jidDecode(jid)
67
+ if (!result) {
68
+ return ''
69
+ }
70
+ const { user, server } = result
71
+ return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server)
54
72
  }
73
+
55
74
  module.exports = {
56
- S_WHATSAPP_NET,
57
- OFFICIAL_BIZ_JID,
58
- SERVER_JID,
59
- PSA_WID,
60
- STORIES_JID,
61
- META_AI_JID,
62
- jidEncode,
63
- jidDecode,
64
- areJidsSameUser,
65
- isJidUser,
66
- isLidUser,
67
- isJidBroadcast,
68
- isJidGroup,
69
- isJidStatusBroadcast,
70
- isJidNewsletter,
71
- isJidBot,
72
- jidNormalizedUser
75
+ S_WHATSAPP_NET,
76
+ OFFICIAL_BIZ_JID,
77
+ SERVER_JID,
78
+ PSA_WID,
79
+ STORIES_JID,
80
+ META_AI_JID,
81
+ jidEncode,
82
+ jidDecode,
83
+ areJidsSameUser,
84
+ isJidUser,
85
+ isLidUser,
86
+ isJidBroadcast,
87
+ isJidGroup,
88
+ isJidStatusBroadcast,
89
+ isJidNewsletter,
90
+ isJidBot,
91
+ jidNormalizedUser
73
92
  }
@@ -1,18 +1,22 @@
1
1
  import * as constants from './constants'
2
+
2
3
  /**
3
- * the binary node WA uses internally for communication
4
- *
5
- * this is manipulated soley as an object and it does not have any functions.
6
- * This is done for easy serialization, to prevent running into issues with prototypes &
7
- * to maintain functional code structure
8
- * */
4
+ * the binary node WA uses internally for communication
5
+ *
6
+ * this is manipulated soley as an object and it does not have any functions.
7
+ * This is done for easy serialization, to prevent running into issues with prototypes &
8
+ * to maintain functional code structure
9
+ * */
9
10
  export type BinaryNode = {
10
- tag: string
11
- attrs: {
12
- [key: string]: string
13
- }
14
- content?: BinaryNode[] | string | Uint8Array
11
+ tag: string
12
+ attrs: {
13
+ [key: string]: string
14
+ }
15
+ content?: BinaryNode[] | string | Uint8Array
15
16
  }
17
+
16
18
  export type BinaryNodeAttributes = BinaryNode['attrs']
19
+
17
20
  export type BinaryNodeData = BinaryNode['content']
21
+
18
22
  export type BinaryNodeCodingOptions = typeof constants
@@ -1,2 +1,3 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
@@ -1,16 +1,16 @@
1
1
  export declare class BinaryInfo {
2
- protocolVersion: number
3
- sequence: number
4
- events: {
5
- [x: string]: {
6
- props: {
7
- [x: string]: import("./constants").Value
8
- }
9
- globals: {
10
- [x: string]: import("./constants").Value
11
- }
12
- }
13
- }[]
14
- buffer: Buffer[]
15
- constructor(options?: Partial<BinaryInfo>)
2
+ protocolVersion: number
3
+ sequence: number
4
+ events: {
5
+ [x: string]: {
6
+ props: {
7
+ [x: string]: import("./constants").Value
8
+ }
9
+ globals: {
10
+ [x: string]: import("./constants").Value
11
+ }
12
+ }
13
+ }[]
14
+ buffer: Buffer[]
15
+ constructor(options?: Partial<BinaryInfo>)
16
16
  }
@@ -1,14 +1,17 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  class BinaryInfo {
4
- constructor(options = {}) {
5
- this.protocolVersion = 5
6
- this.sequence = 0
7
- this.events = []
8
- this.buffer = []
9
- Object.assign(this, options)
10
- }
6
+ constructor(options = {}) {
7
+ this.protocolVersion = 5
8
+ this.sequence = 0
9
+ this.events = []
10
+ this.buffer = []
11
+ Object.assign(this, options)
12
+ }
11
13
  }
14
+
12
15
  module.exports = {
13
- BinaryInfo
16
+ BinaryInfo
14
17
  }
@@ -1,39 +1,47 @@
1
1
  export declare const WEB_EVENTS: Event[]
2
+
2
3
  export declare const WEB_GLOBALS: Global[]
4
+
3
5
  export declare const FLAG_BYTE = 8, FLAG_GLOBAL = 0, FLAG_EVENT = 1, FLAG_FIELD = 2, FLAG_EXTENDED = 4
6
+
4
7
  export type Event = {
5
- name: string
6
- id: number
7
- props: {
8
- [key: string]: [number, string | {
9
- [key: string]: number
10
- }]
11
- }
12
- weight: number
13
- wamChannel: string
14
- privateStatsIdInt: number
8
+ name: string
9
+ id: number
10
+ props: {
11
+ [key: string]: [number, string | {
12
+ [key: string]: number
13
+ }]
14
+ }
15
+ weight: number
16
+ wamChannel: string
17
+ privateStatsIdInt: number
15
18
  }
19
+
16
20
  export type Global = {
17
- name: string
18
- id: number
19
- type: string | {
20
- [key: string]: number
21
- }
22
- validator?: string
23
- channels: string[]
21
+ name: string
22
+ id: number
23
+ type: string | {
24
+ [key: string]: number
25
+ }
26
+ validator?: string
27
+ channels: string[]
24
28
  }
29
+
25
30
  type EventByName<T extends Event['name']> = Extract<Event, {
26
- name: T
31
+ name: T
27
32
  }>
33
+
28
34
  export type EventInputType = {
29
- [key in Event['name']]: {
30
- props: {
31
- [k in keyof EventByName<key>['props']]: Value
32
- }
33
- globals: {
34
- [x: string]: Value
35
- }
36
- }
35
+ [key in Event['name']]: {
36
+ props: {
37
+ [k in keyof EventByName<key>['props']]: Value
38
+ }
39
+ globals: {
40
+ [x: string]: Value
41
+ }
42
+ }
37
43
  } & {}
44
+
38
45
  export type Value = number | null | string
46
+
39
47
  export {}