@mrlegendbot/baileys 1.2.5 → 1.2.7

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 (212) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/fix-imports.js +85 -0
  3. package/WAProto/index.d.ts +14017 -0
  4. package/WAProto/index.js +97691 -2
  5. package/lib/Defaults/index.d.ts +75 -0
  6. package/lib/Defaults/index.js +92 -89
  7. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  8. package/lib/Signal/Group/ciphertext-message.js +10 -9
  9. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  10. package/lib/Signal/Group/group-session-builder.js +22 -21
  11. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  12. package/lib/Signal/Group/group_cipher.js +69 -75
  13. package/lib/Signal/Group/index.d.ts +12 -0
  14. package/lib/Signal/Group/index.js +1 -0
  15. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  16. package/lib/Signal/Group/keyhelper.js +10 -9
  17. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  18. package/lib/Signal/Group/sender-chain-key.js +22 -21
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
  21. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  22. package/lib/Signal/Group/sender-key-message.js +62 -56
  23. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  24. package/lib/Signal/Group/sender-key-name.js +40 -38
  25. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  26. package/lib/Signal/Group/sender-key-record.js +34 -33
  27. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  28. package/lib/Signal/Group/sender-key-state.js +76 -72
  29. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  30. package/lib/Signal/Group/sender-message-key.js +23 -22
  31. package/lib/Signal/libsignal.d.ts +5 -0
  32. package/lib/Signal/libsignal.js +405 -506
  33. package/lib/Signal/lid-mapping.d.ts +23 -0
  34. package/lib/Signal/lid-mapping.js +258 -276
  35. package/lib/Socket/Client/index.d.ts +3 -0
  36. package/lib/Socket/Client/index.js +1 -0
  37. package/lib/Socket/Client/types.d.ts +16 -0
  38. package/lib/Socket/Client/types.js +7 -6
  39. package/lib/Socket/Client/websocket.d.ts +13 -0
  40. package/lib/Socket/Client/websocket.js +49 -48
  41. package/lib/Socket/business.d.ts +217 -0
  42. package/lib/Socket/business.js +369 -349
  43. package/lib/Socket/chats.d.ts +125 -0
  44. package/lib/Socket/chats.js +1148 -1172
  45. package/lib/Socket/communities.d.ts +273 -0
  46. package/lib/Socket/communities.js +413 -473
  47. package/lib/Socket/groups.d.ts +161 -0
  48. package/lib/Socket/groups.js +331 -387
  49. package/lib/Socket/index.d.ts +260 -0
  50. package/lib/Socket/index.js +8 -6
  51. package/lib/Socket/messages-recv.d.ts +203 -0
  52. package/lib/Socket/messages-recv.js +1719 -1782
  53. package/lib/Socket/messages-send.d.ts +200 -0
  54. package/lib/Socket/messages-send.js +2508 -1384
  55. package/lib/Socket/mex.d.ts +3 -0
  56. package/lib/Socket/mex.js +35 -40
  57. package/lib/Socket/newsletter.d.ts +170 -0
  58. package/lib/Socket/newsletter.js +191 -239
  59. package/lib/Socket/socket.d.ts +59 -0
  60. package/lib/Socket/socket.js +923 -992
  61. package/lib/Types/Auth.d.ts +117 -0
  62. package/lib/Types/Auth.js +1 -0
  63. package/lib/Types/Bussines.d.ts +25 -0
  64. package/lib/Types/Bussines.js +1 -0
  65. package/lib/Types/Call.d.ts +15 -0
  66. package/lib/Types/Call.js +1 -0
  67. package/lib/Types/Chat.d.ts +124 -0
  68. package/lib/Types/Chat.js +8 -1
  69. package/lib/Types/Contact.d.ts +26 -0
  70. package/lib/Types/Contact.js +1 -0
  71. package/lib/Types/Events.d.ts +256 -0
  72. package/lib/Types/Events.js +2 -1
  73. package/lib/Types/GroupMetadata.d.ts +71 -0
  74. package/lib/Types/GroupMetadata.js +1 -0
  75. package/lib/Types/Label.d.ts +47 -0
  76. package/lib/Types/Label.js +22 -20
  77. package/lib/Types/LabelAssociation.d.ts +30 -0
  78. package/lib/Types/LabelAssociation.js +4 -2
  79. package/lib/Types/Message.d.ts +320 -0
  80. package/lib/Types/Message.js +5 -3
  81. package/lib/Types/Mex.d.ts +141 -0
  82. package/lib/Types/Mex.js +31 -26
  83. package/lib/Types/Product.d.ts +79 -0
  84. package/lib/Types/Product.js +1 -0
  85. package/lib/Types/Signal.d.ts +87 -0
  86. package/lib/Types/Signal.js +2 -1
  87. package/lib/Types/Socket.d.ts +136 -0
  88. package/lib/Types/Socket.js +3 -2
  89. package/lib/Types/State.d.ts +97 -0
  90. package/lib/Types/State.js +52 -4
  91. package/lib/Types/USync.d.ts +26 -0
  92. package/lib/Types/USync.js +1 -0
  93. package/lib/Types/index.d.ts +66 -0
  94. package/lib/Types/index.js +11 -10
  95. package/lib/Utils/auth-utils.d.ts +24 -0
  96. package/lib/Utils/auth-utils.js +277 -240
  97. package/lib/Utils/browser-utils.d.ts +4 -0
  98. package/lib/Utils/browser-utils.js +23 -20
  99. package/lib/Utils/business.d.ts +23 -0
  100. package/lib/Utils/business.js +204 -200
  101. package/lib/Utils/chat-utils.d.ts +100 -0
  102. package/lib/Utils/chat-utils.js +810 -836
  103. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  104. package/lib/Utils/companion-reg-client-utils.js +25 -23
  105. package/lib/Utils/crypto.d.ts +37 -0
  106. package/lib/Utils/crypto.js +86 -70
  107. package/lib/Utils/decode-wa-message.d.ts +66 -0
  108. package/lib/Utils/decode-wa-message.js +284 -277
  109. package/lib/Utils/event-buffer.d.ts +36 -0
  110. package/lib/Utils/event-buffer.js +595 -592
  111. package/lib/Utils/generics.d.ts +92 -0
  112. package/lib/Utils/generics.js +335 -312
  113. package/lib/Utils/history.d.ts +24 -0
  114. package/lib/Utils/history.js +115 -123
  115. package/lib/Utils/identity-change-handler.d.ts +44 -0
  116. package/lib/Utils/identity-change-handler.js +50 -0
  117. package/lib/Utils/index.d.ts +22 -0
  118. package/lib/Utils/index.js +2 -1
  119. package/lib/Utils/link-preview.d.ts +21 -0
  120. package/lib/Utils/link-preview.js +73 -74
  121. package/lib/Utils/logger.d.ts +12 -0
  122. package/lib/Utils/logger.js +2 -3
  123. package/lib/Utils/lt-hash.d.ts +8 -0
  124. package/lib/Utils/lt-hash.js +6 -0
  125. package/lib/Utils/make-mutex.d.ts +9 -0
  126. package/lib/Utils/make-mutex.js +27 -27
  127. package/lib/Utils/message-retry-manager.d.ts +115 -0
  128. package/lib/Utils/message-retry-manager.js +254 -213
  129. package/lib/Utils/messages-media.d.ts +133 -0
  130. package/lib/Utils/messages-media.js +715 -741
  131. package/lib/Utils/messages.d.ts +91 -0
  132. package/lib/Utils/messages.js +827 -791
  133. package/lib/Utils/noise-handler.d.ts +20 -0
  134. package/lib/Utils/noise-handler.js +187 -215
  135. package/lib/Utils/offline-node-processor.d.ts +17 -0
  136. package/lib/Utils/offline-node-processor.js +40 -0
  137. package/lib/Utils/pre-key-manager.d.ts +28 -0
  138. package/lib/Utils/pre-key-manager.js +98 -69
  139. package/lib/Utils/process-message.d.ts +60 -0
  140. package/lib/Utils/process-message.js +586 -617
  141. package/lib/Utils/reporting-utils.d.ts +11 -0
  142. package/lib/Utils/reporting-utils.js +234 -553
  143. package/lib/Utils/signal.d.ts +47 -0
  144. package/lib/Utils/signal.js +170 -217
  145. package/lib/Utils/stanza-ack.d.ts +11 -0
  146. package/lib/Utils/stanza-ack.js +35 -27
  147. package/lib/Utils/sync-action-utils.d.ts +19 -0
  148. package/lib/Utils/sync-action-utils.js +41 -37
  149. package/lib/Utils/tc-token-utils.d.ts +37 -0
  150. package/lib/Utils/tc-token-utils.js +141 -120
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  152. package/lib/Utils/use-multi-file-auth-state.js +105 -87
  153. package/lib/Utils/validate-connection.d.ts +11 -0
  154. package/lib/Utils/validate-connection.js +188 -190
  155. package/lib/WABinary/constants.d.ts +28 -0
  156. package/lib/WABinary/constants.js +1294 -28
  157. package/lib/WABinary/decode.d.ts +7 -0
  158. package/lib/WABinary/decode.js +249 -245
  159. package/lib/WABinary/encode.d.ts +3 -0
  160. package/lib/WABinary/encode.js +206 -201
  161. package/lib/WABinary/generic-utils.d.ts +15 -0
  162. package/lib/WABinary/generic-utils.js +89 -86
  163. package/lib/WABinary/index.d.ts +6 -0
  164. package/lib/WABinary/index.js +1 -0
  165. package/lib/WABinary/jid-utils.d.ts +48 -0
  166. package/lib/WABinary/jid-utils.js +77 -68
  167. package/lib/WABinary/types.d.ts +19 -0
  168. package/lib/WABinary/types.js +1 -0
  169. package/lib/WAM/BinaryInfo.d.ts +9 -0
  170. package/lib/WAM/BinaryInfo.js +8 -7
  171. package/lib/WAM/constants.d.ts +40 -0
  172. package/lib/WAM/constants.js +22853 -19892
  173. package/lib/WAM/encode.d.ts +3 -0
  174. package/lib/WAM/encode.js +132 -121
  175. package/lib/WAM/index.d.ts +4 -0
  176. package/lib/WAM/index.js +1 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
  185. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  186. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
  187. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  188. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
  189. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  190. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  191. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  192. package/lib/WAUSync/Protocols/index.js +1 -0
  193. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  194. package/lib/WAUSync/USyncQuery.js +88 -79
  195. package/lib/WAUSync/USyncUser.d.ts +17 -0
  196. package/lib/WAUSync/USyncUser.js +29 -28
  197. package/lib/WAUSync/index.d.ts +4 -0
  198. package/lib/WAUSync/index.js +1 -0
  199. package/lib/index.d.ts +12 -0
  200. package/lib/index.js +2 -2
  201. package/package.json +86 -22
  202. package/README.upstream.md +0 -1312
  203. package/WAProto/WAProto.json +0 -1
  204. package/WAProto/WAProto.proto +0 -6275
  205. package/WAProto/compiler.js +0 -550
  206. package/lib/Store/index.js +0 -8
  207. package/lib/Store/keyed-db.js +0 -108
  208. package/lib/Store/make-cache-manager-store.js +0 -70
  209. package/lib/Store/make-in-memory-store.js +0 -417
  210. package/lib/Store/make-ordered-dictionary.js +0 -69
  211. package/lib/Store/object-repository.js +0 -27
  212. package/lib/Utils/use-sqlite-auth-state.js +0 -162
@@ -3,357 +3,377 @@ import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parsePro
3
3
  import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
4
4
  import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
5
5
  import { makeMessagesRecvSocket } from './messages-recv.js';
6
- export const makeBusinessSocket = config => {
7
- const sock = makeMessagesRecvSocket(config);
8
- const {
9
- authState,
10
- query,
11
- waUploadToServer
12
- } = sock;
13
- const updateBussinesProfile = async args => {
14
- const node = [];
15
- const simpleFields = ['address', 'email', 'description'];
16
- node.push(...simpleFields.filter(key => args[key] !== undefined && args[key] !== null).map(key => ({
17
- tag: key,
18
- attrs: {},
19
- content: args[key]
20
- })));
21
- if (args.websites !== undefined) {
22
- node.push(...args.websites.map(website => ({
23
- tag: 'website',
24
- attrs: {},
25
- content: website
26
- })));
27
- }
28
- if (args.hours !== undefined) {
29
- node.push({
30
- tag: 'business_hours',
31
- attrs: {
32
- timezone: args.hours.timezone
33
- },
34
- content: args.hours.days.map(dayConfig => {
35
- const base = {
36
- tag: 'business_hours_config',
6
+ export const makeBusinessSocket = (config) => {
7
+ const sock = makeMessagesRecvSocket(config);
8
+ const { authState, query, waUploadToServer } = sock;
9
+ const updateBussinesProfile = async (args) => {
10
+ const node = [];
11
+ const simpleFields = ['address', 'email', 'description'];
12
+ node.push(...simpleFields
13
+ .filter(key => args[key] !== undefined && args[key] !== null)
14
+ .map(key => ({
15
+ tag: key,
16
+ attrs: {},
17
+ content: args[key]
18
+ })));
19
+ if (args.websites !== undefined) {
20
+ node.push(...args.websites.map(website => ({
21
+ tag: 'website',
22
+ attrs: {},
23
+ content: website
24
+ })));
25
+ }
26
+ if (args.hours !== undefined) {
27
+ node.push({
28
+ tag: 'business_hours',
29
+ attrs: { timezone: args.hours.timezone },
30
+ content: args.hours.days.map(dayConfig => {
31
+ const base = {
32
+ tag: 'business_hours_config',
33
+ attrs: {
34
+ day_of_week: dayConfig.day,
35
+ mode: dayConfig.mode
36
+ }
37
+ };
38
+ if (dayConfig.mode === 'specific_hours') {
39
+ return {
40
+ ...base,
41
+ attrs: {
42
+ ...base.attrs,
43
+ open_time: dayConfig.openTimeInMinutes,
44
+ close_time: dayConfig.closeTimeInMinutes
45
+ }
46
+ };
47
+ }
48
+ return base;
49
+ })
50
+ });
51
+ }
52
+ const result = await query({
53
+ tag: 'iq',
54
+ attrs: {
55
+ to: S_WHATSAPP_NET,
56
+ type: 'set',
57
+ xmlns: 'w:biz'
58
+ },
59
+ content: [
60
+ {
61
+ tag: 'business_profile',
62
+ attrs: {
63
+ v: '3',
64
+ mutation_type: 'delta'
65
+ },
66
+ content: node
67
+ }
68
+ ]
69
+ });
70
+ return result;
71
+ };
72
+ const updateCoverPhoto = async (photo) => {
73
+ const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo');
74
+ const fileSha256B64 = fileSha256.toString('base64');
75
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
76
+ fileEncSha256B64: fileSha256B64,
77
+ mediaType: 'biz-cover-photo'
78
+ });
79
+ await query({
80
+ tag: 'iq',
37
81
  attrs: {
38
- day_of_week: dayConfig.day,
39
- mode: dayConfig.mode
82
+ to: S_WHATSAPP_NET,
83
+ type: 'set',
84
+ xmlns: 'w:biz'
85
+ },
86
+ content: [
87
+ {
88
+ tag: 'business_profile',
89
+ attrs: {
90
+ v: '3',
91
+ mutation_type: 'delta'
92
+ },
93
+ content: [
94
+ {
95
+ tag: 'cover_photo',
96
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
97
+ }
98
+ ]
99
+ }
100
+ ]
101
+ });
102
+ return fbid;
103
+ };
104
+ const removeCoverPhoto = async (id) => {
105
+ return await query({
106
+ tag: 'iq',
107
+ attrs: {
108
+ to: S_WHATSAPP_NET,
109
+ type: 'set',
110
+ xmlns: 'w:biz'
111
+ },
112
+ content: [
113
+ {
114
+ tag: 'business_profile',
115
+ attrs: {
116
+ v: '3',
117
+ mutation_type: 'delta'
118
+ },
119
+ content: [
120
+ {
121
+ tag: 'cover_photo',
122
+ attrs: { op: 'delete', id }
123
+ }
124
+ ]
125
+ }
126
+ ]
127
+ });
128
+ };
129
+ const getCatalog = async ({ jid, limit, cursor }) => {
130
+ jid = jid || authState.creds.me?.id;
131
+ jid = jidNormalizedUser(jid);
132
+ const queryParamNodes = [
133
+ {
134
+ tag: 'limit',
135
+ attrs: {},
136
+ content: Buffer.from((limit || 10).toString())
137
+ },
138
+ {
139
+ tag: 'width',
140
+ attrs: {},
141
+ content: Buffer.from('100')
142
+ },
143
+ {
144
+ tag: 'height',
145
+ attrs: {},
146
+ content: Buffer.from('100')
40
147
  }
41
- };
42
- if (dayConfig.mode === 'specific_hours') {
43
- return {
44
- ...base,
45
- attrs: {
46
- ...base.attrs,
47
- open_time: dayConfig.openTimeInMinutes,
48
- close_time: dayConfig.closeTimeInMinutes
49
- }
50
- };
51
- }
52
- return base;
53
- })
54
- });
55
- }
56
- const result = await query({
57
- tag: 'iq',
58
- attrs: {
59
- to: S_WHATSAPP_NET,
60
- type: 'set',
61
- xmlns: 'w:biz'
62
- },
63
- content: [{
64
- tag: 'business_profile',
65
- attrs: {
66
- v: '3',
67
- mutation_type: 'delta'
68
- },
69
- content: node
70
- }]
71
- });
72
- return result;
73
- };
74
- const updateCoverPhoto = async photo => {
75
- const {
76
- fileSha256,
77
- filePath
78
- } = await getRawMediaUploadData(photo, 'biz-cover-photo');
79
- const fileSha256B64 = fileSha256.toString('base64');
80
- const {
81
- meta_hmac,
82
- fbid,
83
- ts
84
- } = await waUploadToServer(filePath, {
85
- fileEncSha256B64: fileSha256B64,
86
- mediaType: 'biz-cover-photo'
87
- });
88
- await query({
89
- tag: 'iq',
90
- attrs: {
91
- to: S_WHATSAPP_NET,
92
- type: 'set',
93
- xmlns: 'w:biz'
94
- },
95
- content: [{
96
- tag: 'business_profile',
97
- attrs: {
98
- v: '3',
99
- mutation_type: 'delta'
100
- },
101
- content: [{
102
- tag: 'cover_photo',
103
- attrs: {
104
- id: String(fbid),
105
- op: 'update',
106
- token: meta_hmac,
107
- ts: String(ts)
108
- }
109
- }]
110
- }]
111
- });
112
- return fbid;
113
- };
114
- const removeCoverPhoto = async id => {
115
- return await query({
116
- tag: 'iq',
117
- attrs: {
118
- to: S_WHATSAPP_NET,
119
- type: 'set',
120
- xmlns: 'w:biz'
121
- },
122
- content: [{
123
- tag: 'business_profile',
124
- attrs: {
125
- v: '3',
126
- mutation_type: 'delta'
127
- },
128
- content: [{
129
- tag: 'cover_photo',
130
- attrs: {
131
- op: 'delete',
132
- id
133
- }
134
- }]
135
- }]
136
- });
137
- };
138
- const getCatalog = async ({
139
- jid,
140
- limit,
141
- cursor
142
- }) => {
143
- jid = jid || authState.creds.me?.id;
144
- jid = jidNormalizedUser(jid);
145
- const queryParamNodes = [{
146
- tag: 'limit',
147
- attrs: {},
148
- content: Buffer.from((limit || 10).toString())
149
- }, {
150
- tag: 'width',
151
- attrs: {},
152
- content: Buffer.from('100')
153
- }, {
154
- tag: 'height',
155
- attrs: {},
156
- content: Buffer.from('100')
157
- }];
158
- if (cursor) {
159
- queryParamNodes.push({
160
- tag: 'after',
161
- attrs: {},
162
- content: cursor
163
- });
164
- }
165
- const result = await query({
166
- tag: 'iq',
167
- attrs: {
168
- to: S_WHATSAPP_NET,
169
- type: 'get',
170
- xmlns: 'w:biz:catalog'
171
- },
172
- content: [{
173
- tag: 'product_catalog',
174
- attrs: {
175
- jid,
176
- allow_shop_source: 'true'
177
- },
178
- content: queryParamNodes
179
- }]
180
- });
181
- return parseCatalogNode(result);
182
- };
183
- const getCollections = async (jid, limit = 51) => {
184
- jid = jid || authState.creds.me?.id;
185
- jid = jidNormalizedUser(jid);
186
- const result = await query({
187
- tag: 'iq',
188
- attrs: {
189
- to: S_WHATSAPP_NET,
190
- type: 'get',
191
- xmlns: 'w:biz:catalog',
192
- smax_id: '35'
193
- },
194
- content: [{
195
- tag: 'collections',
196
- attrs: {
197
- biz_jid: jid
198
- },
199
- content: [{
200
- tag: 'collection_limit',
201
- attrs: {},
202
- content: Buffer.from(limit.toString())
203
- }, {
204
- tag: 'item_limit',
205
- attrs: {},
206
- content: Buffer.from(limit.toString())
207
- }, {
208
- tag: 'width',
209
- attrs: {},
210
- content: Buffer.from('100')
211
- }, {
212
- tag: 'height',
213
- attrs: {},
214
- content: Buffer.from('100')
215
- }]
216
- }]
217
- });
218
- return parseCollectionsNode(result);
219
- };
220
- const getOrderDetails = async (orderId, tokenBase64) => {
221
- const result = await query({
222
- tag: 'iq',
223
- attrs: {
224
- to: S_WHATSAPP_NET,
225
- type: 'get',
226
- xmlns: 'fb:thrift_iq',
227
- smax_id: '5'
228
- },
229
- content: [{
230
- tag: 'order',
231
- attrs: {
232
- op: 'get',
233
- id: orderId
234
- },
235
- content: [{
236
- tag: 'image_dimensions',
237
- attrs: {},
238
- content: [{
239
- tag: 'width',
240
- attrs: {},
241
- content: Buffer.from('100')
242
- }, {
243
- tag: 'height',
244
- attrs: {},
245
- content: Buffer.from('100')
246
- }]
247
- }, {
248
- tag: 'token',
249
- attrs: {},
250
- content: Buffer.from(tokenBase64)
251
- }]
252
- }]
253
- });
254
- return parseOrderDetailsNode(result);
255
- };
256
- const productUpdate = async (productId, update) => {
257
- update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
258
- const editNode = toProductNode(productId, update);
259
- const result = await query({
260
- tag: 'iq',
261
- attrs: {
262
- to: S_WHATSAPP_NET,
263
- type: 'set',
264
- xmlns: 'w:biz:catalog'
265
- },
266
- content: [{
267
- tag: 'product_catalog_edit',
268
- attrs: {
269
- v: '1'
270
- },
271
- content: [editNode, {
272
- tag: 'width',
273
- attrs: {},
274
- content: '100'
275
- }, {
276
- tag: 'height',
277
- attrs: {},
278
- content: '100'
279
- }]
280
- }]
281
- });
282
- const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
283
- const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
284
- return parseProductNode(productNode);
285
- };
286
- const productCreate = async create => {
287
- create.isHidden = !!create.isHidden;
288
- create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
289
- const createNode = toProductNode(undefined, create);
290
- const result = await query({
291
- tag: 'iq',
292
- attrs: {
293
- to: S_WHATSAPP_NET,
294
- type: 'set',
295
- xmlns: 'w:biz:catalog'
296
- },
297
- content: [{
298
- tag: 'product_catalog_add',
299
- attrs: {
300
- v: '1'
301
- },
302
- content: [createNode, {
303
- tag: 'width',
304
- attrs: {},
305
- content: '100'
306
- }, {
307
- tag: 'height',
308
- attrs: {},
309
- content: '100'
310
- }]
311
- }]
312
- });
313
- const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
314
- const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
315
- return parseProductNode(productNode);
316
- };
317
- const productDelete = async productIds => {
318
- const result = await query({
319
- tag: 'iq',
320
- attrs: {
321
- to: S_WHATSAPP_NET,
322
- type: 'set',
323
- xmlns: 'w:biz:catalog'
324
- },
325
- content: [{
326
- tag: 'product_catalog_delete',
327
- attrs: {
328
- v: '1'
329
- },
330
- content: productIds.map(id => ({
331
- tag: 'product',
332
- attrs: {},
333
- content: [{
334
- tag: 'id',
335
- attrs: {},
336
- content: Buffer.from(id)
337
- }]
338
- }))
339
- }]
340
- });
341
- const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
148
+ ];
149
+ if (cursor) {
150
+ queryParamNodes.push({
151
+ tag: 'after',
152
+ attrs: {},
153
+ content: cursor
154
+ });
155
+ }
156
+ const result = await query({
157
+ tag: 'iq',
158
+ attrs: {
159
+ to: S_WHATSAPP_NET,
160
+ type: 'get',
161
+ xmlns: 'w:biz:catalog'
162
+ },
163
+ content: [
164
+ {
165
+ tag: 'product_catalog',
166
+ attrs: {
167
+ jid,
168
+ allow_shop_source: 'true'
169
+ },
170
+ content: queryParamNodes
171
+ }
172
+ ]
173
+ });
174
+ return parseCatalogNode(result);
175
+ };
176
+ const getCollections = async (jid, limit = 51) => {
177
+ jid = jid || authState.creds.me?.id;
178
+ jid = jidNormalizedUser(jid);
179
+ const result = await query({
180
+ tag: 'iq',
181
+ attrs: {
182
+ to: S_WHATSAPP_NET,
183
+ type: 'get',
184
+ xmlns: 'w:biz:catalog',
185
+ smax_id: '35'
186
+ },
187
+ content: [
188
+ {
189
+ tag: 'collections',
190
+ attrs: {
191
+ biz_jid: jid
192
+ },
193
+ content: [
194
+ {
195
+ tag: 'collection_limit',
196
+ attrs: {},
197
+ content: Buffer.from(limit.toString())
198
+ },
199
+ {
200
+ tag: 'item_limit',
201
+ attrs: {},
202
+ content: Buffer.from(limit.toString())
203
+ },
204
+ {
205
+ tag: 'width',
206
+ attrs: {},
207
+ content: Buffer.from('100')
208
+ },
209
+ {
210
+ tag: 'height',
211
+ attrs: {},
212
+ content: Buffer.from('100')
213
+ }
214
+ ]
215
+ }
216
+ ]
217
+ });
218
+ return parseCollectionsNode(result);
219
+ };
220
+ const getOrderDetails = async (orderId, tokenBase64) => {
221
+ const result = await query({
222
+ tag: 'iq',
223
+ attrs: {
224
+ to: S_WHATSAPP_NET,
225
+ type: 'get',
226
+ xmlns: 'fb:thrift_iq',
227
+ smax_id: '5'
228
+ },
229
+ content: [
230
+ {
231
+ tag: 'order',
232
+ attrs: {
233
+ op: 'get',
234
+ id: orderId
235
+ },
236
+ content: [
237
+ {
238
+ tag: 'image_dimensions',
239
+ attrs: {},
240
+ content: [
241
+ {
242
+ tag: 'width',
243
+ attrs: {},
244
+ content: Buffer.from('100')
245
+ },
246
+ {
247
+ tag: 'height',
248
+ attrs: {},
249
+ content: Buffer.from('100')
250
+ }
251
+ ]
252
+ },
253
+ {
254
+ tag: 'token',
255
+ attrs: {},
256
+ content: Buffer.from(tokenBase64)
257
+ }
258
+ ]
259
+ }
260
+ ]
261
+ });
262
+ return parseOrderDetailsNode(result);
263
+ };
264
+ const productUpdate = async (productId, update) => {
265
+ update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
266
+ const editNode = toProductNode(productId, update);
267
+ const result = await query({
268
+ tag: 'iq',
269
+ attrs: {
270
+ to: S_WHATSAPP_NET,
271
+ type: 'set',
272
+ xmlns: 'w:biz:catalog'
273
+ },
274
+ content: [
275
+ {
276
+ tag: 'product_catalog_edit',
277
+ attrs: { v: '1' },
278
+ content: [
279
+ editNode,
280
+ {
281
+ tag: 'width',
282
+ attrs: {},
283
+ content: '100'
284
+ },
285
+ {
286
+ tag: 'height',
287
+ attrs: {},
288
+ content: '100'
289
+ }
290
+ ]
291
+ }
292
+ ]
293
+ });
294
+ const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
295
+ const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
296
+ return parseProductNode(productNode);
297
+ };
298
+ const productCreate = async (create) => {
299
+ // ensure isHidden is defined
300
+ create.isHidden = !!create.isHidden;
301
+ create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
302
+ const createNode = toProductNode(undefined, create);
303
+ const result = await query({
304
+ tag: 'iq',
305
+ attrs: {
306
+ to: S_WHATSAPP_NET,
307
+ type: 'set',
308
+ xmlns: 'w:biz:catalog'
309
+ },
310
+ content: [
311
+ {
312
+ tag: 'product_catalog_add',
313
+ attrs: { v: '1' },
314
+ content: [
315
+ createNode,
316
+ {
317
+ tag: 'width',
318
+ attrs: {},
319
+ content: '100'
320
+ },
321
+ {
322
+ tag: 'height',
323
+ attrs: {},
324
+ content: '100'
325
+ }
326
+ ]
327
+ }
328
+ ]
329
+ });
330
+ const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
331
+ const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
332
+ return parseProductNode(productNode);
333
+ };
334
+ const productDelete = async (productIds) => {
335
+ const result = await query({
336
+ tag: 'iq',
337
+ attrs: {
338
+ to: S_WHATSAPP_NET,
339
+ type: 'set',
340
+ xmlns: 'w:biz:catalog'
341
+ },
342
+ content: [
343
+ {
344
+ tag: 'product_catalog_delete',
345
+ attrs: { v: '1' },
346
+ content: productIds.map(id => ({
347
+ tag: 'product',
348
+ attrs: {},
349
+ content: [
350
+ {
351
+ tag: 'id',
352
+ attrs: {},
353
+ content: Buffer.from(id)
354
+ }
355
+ ]
356
+ }))
357
+ }
358
+ ]
359
+ });
360
+ const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
361
+ return {
362
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
363
+ };
364
+ };
342
365
  return {
343
- deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
366
+ ...sock,
367
+ logger: config.logger,
368
+ getOrderDetails,
369
+ getCatalog,
370
+ getCollections,
371
+ productCreate,
372
+ productDelete,
373
+ productUpdate,
374
+ updateBussinesProfile,
375
+ updateCoverPhoto,
376
+ removeCoverPhoto
344
377
  };
345
- };
346
- return {
347
- ...sock,
348
- logger: config.logger,
349
- getOrderDetails,
350
- getCatalog,
351
- getCollections,
352
- productCreate,
353
- productDelete,
354
- productUpdate,
355
- updateBussinesProfile,
356
- updateCoverPhoto,
357
- removeCoverPhoto
358
- };
359
378
  };
379
+ //# sourceMappingURL=business.js.map