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