dcodeindra-baileyspro 2.3.9

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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2534 -0
  3. package/WAProto/Adv/Adv.d.ts +518 -0
  4. package/WAProto/Adv/Adv.js +1734 -0
  5. package/WAProto/Adv/Adv.proto +36 -0
  6. package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +16291 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +463 -0
  9. package/WAProto/Cert/Cert.d.ts +497 -0
  10. package/WAProto/Cert/Cert.js +1503 -0
  11. package/WAProto/Cert/Cert.proto +28 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  13. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  14. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  15. package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
  16. package/WAProto/CompanionReg/CompanionReg.js +3532 -0
  17. package/WAProto/CompanionReg/CompanionReg.proto +89 -0
  18. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  19. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  20. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  21. package/WAProto/E2E/E2E.d.ts +28417 -0
  22. package/WAProto/E2E/E2E.js +98438 -0
  23. package/WAProto/E2E/E2E.proto +2289 -0
  24. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  25. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  26. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  27. package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
  28. package/WAProto/HistorySync/HistorySync.js +142980 -0
  29. package/WAProto/HistorySync/HistorySync.proto +207 -0
  30. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  31. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  32. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  33. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  34. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  35. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  36. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
  37. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
  38. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  39. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  40. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  41. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  42. package/WAProto/Protocol/Protocol.d.ts +218 -0
  43. package/WAProto/Protocol/Protocol.js +701 -0
  44. package/WAProto/Protocol/Protocol.proto +20 -0
  45. package/WAProto/Reporting/Reporting.d.ts +301 -0
  46. package/WAProto/Reporting/Reporting.js +989 -0
  47. package/WAProto/Reporting/Reporting.proto +19 -0
  48. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  49. package/WAProto/ServerSync/ServerSync.js +3176 -0
  50. package/WAProto/ServerSync/ServerSync.proto +59 -0
  51. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  52. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  53. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  54. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  55. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  56. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  57. package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
  58. package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
  59. package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
  60. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  61. package/WAProto/SyncAction/SyncAction.js +22271 -0
  62. package/WAProto/SyncAction/SyncAction.proto +423 -0
  63. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  64. package/WAProto/UserPassword/UserPassword.js +898 -0
  65. package/WAProto/UserPassword/UserPassword.proto +27 -0
  66. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  67. package/WAProto/VnameCert/VnameCert.js +2225 -0
  68. package/WAProto/VnameCert/VnameCert.proto +60 -0
  69. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  70. package/WAProto/Wa6/Wa6.js +6299 -0
  71. package/WAProto/Wa6/Wa6.proto +229 -0
  72. package/WAProto/Web/Web.d.ts +31718 -0
  73. package/WAProto/Web/Web.js +113402 -0
  74. package/WAProto/Web/Web.proto +545 -0
  75. package/WAProto/index.d.ts +49 -0
  76. package/WAProto/index.js +28 -0
  77. package/WASignalGroup/GroupProtocol.js +1771 -0
  78. package/WASignalGroup/ciphertext_message.js +10 -0
  79. package/WASignalGroup/group_cipher.js +103 -0
  80. package/WASignalGroup/group_session_builder.js +39 -0
  81. package/WASignalGroup/index.js +5 -0
  82. package/WASignalGroup/keyhelper.js +17 -0
  83. package/WASignalGroup/protobufs.js +2 -0
  84. package/WASignalGroup/queue_job.js +64 -0
  85. package/WASignalGroup/sender_chain_key.js +38 -0
  86. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  87. package/WASignalGroup/sender_key_message.js +79 -0
  88. package/WASignalGroup/sender_key_name.js +59 -0
  89. package/WASignalGroup/sender_key_record.js +47 -0
  90. package/WASignalGroup/sender_key_state.js +110 -0
  91. package/WASignalGroup/sender_message_key.js +30 -0
  92. package/check-node-version.js +10 -0
  93. package/lib/Defaults/baileys-version.json +3 -0
  94. package/lib/Defaults/index.d.ts +51 -0
  95. package/lib/Defaults/index.js +108 -0
  96. package/lib/Defaults/phonenumber-mcc.json +223 -0
  97. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  98. package/lib/Signal/Group/ciphertext-message.js +19 -0
  99. package/lib/Signal/Group/group-session-builder.d.ts +17 -0
  100. package/lib/Signal/Group/group-session-builder.js +72 -0
  101. package/lib/Signal/Group/group_cipher.d.ts +19 -0
  102. package/lib/Signal/Group/group_cipher.js +99 -0
  103. package/lib/Signal/Group/index.d.ts +11 -0
  104. package/lib/Signal/Group/index.js +61 -0
  105. package/lib/Signal/Group/keyhelper.d.ts +16 -0
  106. package/lib/Signal/Group/keyhelper.js +66 -0
  107. package/lib/Signal/Group/queue-job.d.ts +1 -0
  108. package/lib/Signal/Group/queue-job.js +64 -0
  109. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  110. package/lib/Signal/Group/sender-chain-key.js +39 -0
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  112. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  113. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  114. package/lib/Signal/Group/sender-key-message.js +73 -0
  115. package/lib/Signal/Group/sender-key-name.d.ts +19 -0
  116. package/lib/Signal/Group/sender-key-name.js +59 -0
  117. package/lib/Signal/Group/sender-key-record.d.ts +32 -0
  118. package/lib/Signal/Group/sender-key-record.js +53 -0
  119. package/lib/Signal/Group/sender-key-record.ts +77 -0
  120. package/lib/Signal/Group/sender-key-state.d.ts +44 -0
  121. package/lib/Signal/Group/sender-key-state.js +104 -0
  122. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  123. package/lib/Signal/Group/sender-message-key.js +33 -0
  124. package/lib/Signal/libsignal.d.ts +3 -0
  125. package/lib/Signal/libsignal.js +153 -0
  126. package/lib/Socket/Client/index.d.ts +2 -0
  127. package/lib/Socket/Client/index.js +18 -0
  128. package/lib/Socket/Client/types.d.ts +15 -0
  129. package/lib/Socket/Client/types.js +14 -0
  130. package/lib/Socket/Client/websocket.d.ts +12 -0
  131. package/lib/Socket/Client/websocket.js +57 -0
  132. package/lib/Socket/business.d.ts +181 -0
  133. package/lib/Socket/business.js +259 -0
  134. package/lib/Socket/chats.d.ts +95 -0
  135. package/lib/Socket/chats.js +906 -0
  136. package/lib/Socket/community.d.ts +131 -0
  137. package/lib/Socket/community.js +369 -0
  138. package/lib/Socket/groups.d.ts +122 -0
  139. package/lib/Socket/groups.js +360 -0
  140. package/lib/Socket/index.d.ts +183 -0
  141. package/lib/Socket/index.js +10 -0
  142. package/lib/Socket/messages-recv.d.ts +170 -0
  143. package/lib/Socket/messages-recv.js +1074 -0
  144. package/lib/Socket/messages-send.d.ts +161 -0
  145. package/lib/Socket/messages-send.js +982 -0
  146. package/lib/Socket/newsletter.d.ts +140 -0
  147. package/lib/Socket/newsletter.js +242 -0
  148. package/lib/Socket/socket.d.ts +43 -0
  149. package/lib/Socket/socket.js +749 -0
  150. package/lib/Socket/usync.d.ts +36 -0
  151. package/lib/Socket/usync.js +71 -0
  152. package/lib/Store/index.d.ts +4 -0
  153. package/lib/Store/index.js +20 -0
  154. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  155. package/lib/Store/make-cache-manager-store.js +77 -0
  156. package/lib/Store/make-in-memory-store.d.ts +117 -0
  157. package/lib/Store/make-in-memory-store.js +420 -0
  158. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  159. package/lib/Store/make-ordered-dictionary.js +83 -0
  160. package/lib/Store/object-repository.d.ts +10 -0
  161. package/lib/Store/object-repository.js +28 -0
  162. package/lib/Types/Auth.d.ts +103 -0
  163. package/lib/Types/Auth.js +2 -0
  164. package/lib/Types/Call.d.ts +13 -0
  165. package/lib/Types/Call.js +2 -0
  166. package/lib/Types/Chat.d.ts +115 -0
  167. package/lib/Types/Chat.js +6 -0
  168. package/lib/Types/Contact.d.ts +35 -0
  169. package/lib/Types/Contact.js +2 -0
  170. package/lib/Types/Events.d.ts +208 -0
  171. package/lib/Types/Events.js +2 -0
  172. package/lib/Types/GroupMetadata.d.ts +81 -0
  173. package/lib/Types/GroupMetadata.js +2 -0
  174. package/lib/Types/Label.d.ts +46 -0
  175. package/lib/Types/Label.js +28 -0
  176. package/lib/Types/LabelAssociation.d.ts +29 -0
  177. package/lib/Types/LabelAssociation.js +10 -0
  178. package/lib/Types/Message.d.ts +480 -0
  179. package/lib/Types/Message.js +9 -0
  180. package/lib/Types/MexUpdates.d.ts +9 -0
  181. package/lib/Types/MexUpdates.js +18 -0
  182. package/lib/Types/Newsletter.d.ts +92 -0
  183. package/lib/Types/Newsletter.js +33 -0
  184. package/lib/Types/Product.d.ts +78 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Signal.d.ts +57 -0
  187. package/lib/Types/Signal.js +2 -0
  188. package/lib/Types/Socket.d.ts +116 -0
  189. package/lib/Types/Socket.js +2 -0
  190. package/lib/Types/State.d.ts +27 -0
  191. package/lib/Types/State.js +2 -0
  192. package/lib/Types/USync.d.ts +25 -0
  193. package/lib/Types/USync.js +2 -0
  194. package/lib/Types/index.d.ts +70 -0
  195. package/lib/Types/index.js +42 -0
  196. package/lib/Utils/auth-utils.d.ts +18 -0
  197. package/lib/Utils/auth-utils.js +198 -0
  198. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  199. package/lib/Utils/baileys-event-stream.js +64 -0
  200. package/lib/Utils/business.d.ts +22 -0
  201. package/lib/Utils/business.js +243 -0
  202. package/lib/Utils/chat-utils.d.ts +72 -0
  203. package/lib/Utils/chat-utils.js +762 -0
  204. package/lib/Utils/crypto.d.ts +40 -0
  205. package/lib/Utils/crypto.js +150 -0
  206. package/lib/Utils/decode-wa-message.d.ts +252 -0
  207. package/lib/Utils/decode-wa-message.js +232 -0
  208. package/lib/Utils/event-buffer.d.ts +35 -0
  209. package/lib/Utils/event-buffer.js +539 -0
  210. package/lib/Utils/generics.d.ts +96 -0
  211. package/lib/Utils/generics.js +553 -0
  212. package/lib/Utils/history.d.ts +29 -0
  213. package/lib/Utils/history.js +109 -0
  214. package/lib/Utils/index.d.ts +19 -0
  215. package/lib/Utils/index.js +35 -0
  216. package/lib/Utils/link-preview.d.ts +21 -0
  217. package/lib/Utils/link-preview.js +112 -0
  218. package/lib/Utils/logger.d.ts +11 -0
  219. package/lib/Utils/logger.js +7 -0
  220. package/lib/Utils/lt-hash.d.ts +12 -0
  221. package/lib/Utils/lt-hash.js +53 -0
  222. package/lib/Utils/make-mutex.d.ts +7 -0
  223. package/lib/Utils/make-mutex.js +45 -0
  224. package/lib/Utils/messages-media.d.ts +104 -0
  225. package/lib/Utils/messages-media.js +751 -0
  226. package/lib/Utils/messages.d.ts +80 -0
  227. package/lib/Utils/messages.js +1741 -0
  228. package/lib/Utils/noise-handler.d.ts +19 -0
  229. package/lib/Utils/noise-handler.js +150 -0
  230. package/lib/Utils/process-message.d.ts +41 -0
  231. package/lib/Utils/process-message.js +391 -0
  232. package/lib/Utils/signal.d.ts +33 -0
  233. package/lib/Utils/signal.js +154 -0
  234. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  235. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  236. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  237. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  238. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  239. package/lib/Utils/use-single-file-auth-state.js +75 -0
  240. package/lib/Utils/validate-connection.d.ts +10 -0
  241. package/lib/Utils/validate-connection.js +174 -0
  242. package/lib/WABinary/constants.d.ts +27 -0
  243. package/lib/WABinary/constants.js +45 -0
  244. package/lib/WABinary/decode.d.ts +6 -0
  245. package/lib/WABinary/decode.js +255 -0
  246. package/lib/WABinary/encode.d.ts +2 -0
  247. package/lib/WABinary/encode.js +243 -0
  248. package/lib/WABinary/generic-utils.d.ts +16 -0
  249. package/lib/WABinary/generic-utils.js +125 -0
  250. package/lib/WABinary/index.d.ts +5 -0
  251. package/lib/WABinary/index.js +21 -0
  252. package/lib/WABinary/jid-utils.d.ts +34 -0
  253. package/lib/WABinary/jid-utils.js +73 -0
  254. package/lib/WABinary/types.d.ts +18 -0
  255. package/lib/WABinary/types.js +2 -0
  256. package/lib/WAM/BinaryInfo.d.ts +16 -0
  257. package/lib/WAM/BinaryInfo.js +14 -0
  258. package/lib/WAM/constants.d.ts +39 -0
  259. package/lib/WAM/constants.js +15362 -0
  260. package/lib/WAM/encode.d.ts +2 -0
  261. package/lib/WAM/encode.js +156 -0
  262. package/lib/WAM/index.d.ts +3 -0
  263. package/lib/WAM/index.js +19 -0
  264. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  265. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  266. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  267. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  268. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  269. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  270. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  271. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  272. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  273. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  274. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  275. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  276. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  277. package/lib/WAUSync/Protocols/index.js +22 -0
  278. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  279. package/lib/WAUSync/USyncQuery.js +88 -0
  280. package/lib/WAUSync/USyncUser.d.ts +12 -0
  281. package/lib/WAUSync/USyncUser.js +27 -0
  282. package/lib/WAUSync/index.d.ts +3 -0
  283. package/lib/WAUSync/index.js +19 -0
  284. package/lib/index.d.ts +13 -0
  285. package/lib/index.js +45 -0
  286. package/package.json +63 -0
@@ -0,0 +1,64 @@
1
+ "use strict"
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod }
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true })
6
+ const events_1 = __importDefault(require("events"))
7
+ const fs_1 = require("fs")
8
+ const promises_1 = require("fs/promises")
9
+ const readline_1 = require("readline")
10
+ const generics_1 = require("./generics")
11
+ const make_mutex_1 = require("./make-mutex")
12
+ /**
13
+ * Captures events from a baileys event emitter & stores them in a file
14
+ * @param ev The event emitter to read events from
15
+ * @param filename File to save to
16
+ */
17
+ const captureEventStream = (ev, filename) => {
18
+ const oldEmit = ev.emit
19
+ // write mutex so data is appended in order
20
+ const writeMutex = make_mutex_1.makeMutex()
21
+ // monkey patch eventemitter to capture all events
22
+ ev.emit = function (...args) {
23
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
24
+ const result = oldEmit.apply(ev, args)
25
+ writeMutex.mutex(async () => {
26
+ await promises_1.writeFile(filename, content, { flag: 'a' })
27
+ })
28
+ return result
29
+ }
30
+ }
31
+ /**
32
+ * Read event file and emit events from there
33
+ * @param filename filename containing event data
34
+ * @param delayIntervalMs delay between each event emit
35
+ */
36
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
37
+ const ev = new events_1.default()
38
+ const fireEvents = async () => {
39
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
40
+ const fileStream = fs_1.createReadStream(filename)
41
+ const rl = readline_1.createInterface({
42
+ input: fileStream,
43
+ crlfDelay: Infinity
44
+ })
45
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
46
+ // ('\r\n') in input.txt as a single line break.
47
+ for await (const line of rl) {
48
+ if (line) {
49
+ const { event, data } = JSON.parse(line)
50
+ ev.emit(event, data)
51
+ delayIntervalMs && await generics_1.delay(delayIntervalMs)
52
+ }
53
+ }
54
+ fileStream.close()
55
+ }
56
+ return {
57
+ ev,
58
+ task: fireEvents()
59
+ }
60
+ }
61
+ module.exports = {
62
+ captureEventStream,
63
+ readAndEmitEventStream
64
+ }
@@ -0,0 +1,22 @@
1
+ import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types'
2
+ import { BinaryNode } from '../WABinary'
3
+ export declare const parseCatalogNode: (node: BinaryNode) => {
4
+ products: Product[]
5
+ nextPageCursor: string | undefined
6
+ }
7
+ export declare const parseCollectionsNode: (node: BinaryNode) => {
8
+ collections: CatalogCollection[]
9
+ }
10
+ export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails
11
+ export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode
12
+ export declare const parseProductNode: (productNode: BinaryNode) => Product
13
+ /**
14
+ * Uploads images not already uploaded to WA's servers
15
+ */
16
+ export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>
17
+ /**
18
+ * Uploads images not already uploaded to WA's servers
19
+ */
20
+ export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
21
+ url: string
22
+ }[]>
@@ -0,0 +1,243 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const boom_1 = require("@hapi/boom")
4
+ const crypto_1 = require("crypto")
5
+ const path_1 = require("path")
6
+ const os_1 = require("os")
7
+ const fs_1 = require("fs")
8
+ const WABinary_1 = require("../WABinary")
9
+ const generics_1 = require("./generics")
10
+ const messages_media_1 = require("./messages-media")
11
+ const parseCatalogNode = (node) => {
12
+ const catalogNode = WABinary_1.getBinaryNodeChild(node, 'product_catalog')
13
+ const products = WABinary_1.getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
14
+ const paging = WABinary_1.getBinaryNodeChild(catalogNode, 'paging')
15
+ return {
16
+ products,
17
+ nextPageCursor: paging
18
+ ? WABinary_1.getBinaryNodeChildString(paging, 'after')
19
+ : undefined
20
+ }
21
+ }
22
+ const parseCollectionsNode = (node) => {
23
+ const collectionsNode = WABinary_1.getBinaryNodeChild(node, 'collections')
24
+ const collections = WABinary_1.getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
25
+ const id = WABinary_1.getBinaryNodeChildString(collectionNode, 'id')
26
+ const name = WABinary_1.getBinaryNodeChildString(collectionNode, 'name')
27
+ const products = WABinary_1.getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
28
+ return {
29
+ id,
30
+ name,
31
+ products,
32
+ status: parseStatusInfo(collectionNode)
33
+ }
34
+ })
35
+ return {
36
+ collections
37
+ }
38
+ }
39
+ const parseOrderDetailsNode = (node) => {
40
+ const orderNode = WABinary_1.getBinaryNodeChild(node, 'order')
41
+ const products = WABinary_1.getBinaryNodeChildren(orderNode, 'product').map(productNode => {
42
+ const imageNode = WABinary_1.getBinaryNodeChild(productNode, 'image')
43
+ return {
44
+ id: WABinary_1.getBinaryNodeChildString(productNode, 'id'),
45
+ name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
46
+ imageUrl: WABinary_1.getBinaryNodeChildString(imageNode, 'url'),
47
+ price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
48
+ currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
49
+ quantity: +WABinary_1.getBinaryNodeChildString(productNode, 'quantity')
50
+ }
51
+ })
52
+ const priceNode = WABinary_1.getBinaryNodeChild(orderNode, 'price')
53
+ const orderDetails = {
54
+ price: {
55
+ total: +WABinary_1.getBinaryNodeChildString(priceNode, 'total'),
56
+ currency: WABinary_1.getBinaryNodeChildString(priceNode, 'currency'),
57
+ },
58
+ products
59
+ }
60
+ return orderDetails
61
+ }
62
+ const toProductNode = (productId, product) => {
63
+ const attrs = {}
64
+ const content = []
65
+ if (typeof productId !== 'undefined') {
66
+ content.push({
67
+ tag: 'id',
68
+ attrs: {},
69
+ content: Buffer.from(productId)
70
+ })
71
+ }
72
+ if (typeof product.name !== 'undefined') {
73
+ content.push({
74
+ tag: 'name',
75
+ attrs: {},
76
+ content: Buffer.from(product.name)
77
+ })
78
+ }
79
+ if (typeof product.description !== 'undefined') {
80
+ content.push({
81
+ tag: 'description',
82
+ attrs: {},
83
+ content: Buffer.from(product.description)
84
+ })
85
+ }
86
+ if (typeof product.retailerId !== 'undefined') {
87
+ content.push({
88
+ tag: 'retailer_id',
89
+ attrs: {},
90
+ content: Buffer.from(product.retailerId)
91
+ })
92
+ }
93
+ if (product.images.length) {
94
+ content.push({
95
+ tag: 'media',
96
+ attrs: {},
97
+ content: product.images.map(img => {
98
+ if (!('url' in img)) {
99
+ throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
100
+ }
101
+ return {
102
+ tag: 'image',
103
+ attrs: {},
104
+ content: [
105
+ {
106
+ tag: 'url',
107
+ attrs: {},
108
+ content: Buffer.from(img.url.toString())
109
+ }
110
+ ]
111
+ }
112
+ })
113
+ })
114
+ }
115
+ if (typeof product.price !== 'undefined') {
116
+ content.push({
117
+ tag: 'price',
118
+ attrs: {},
119
+ content: Buffer.from(product.price.toString())
120
+ })
121
+ }
122
+ if (typeof product.currency !== 'undefined') {
123
+ content.push({
124
+ tag: 'currency',
125
+ attrs: {},
126
+ content: Buffer.from(product.currency)
127
+ })
128
+ }
129
+ if ('originCountryCode' in product) {
130
+ if (typeof product.originCountryCode === 'undefined') {
131
+ attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
132
+ }
133
+ else {
134
+ content.push({
135
+ tag: 'compliance_info',
136
+ attrs: {},
137
+ content: [
138
+ {
139
+ tag: 'country_code_origin',
140
+ attrs: {},
141
+ content: Buffer.from(product.originCountryCode)
142
+ }
143
+ ]
144
+ })
145
+ }
146
+ }
147
+ if (typeof product.isHidden !== 'undefined') {
148
+ attrs['is_hidden'] = product.isHidden.toString()
149
+ }
150
+ const node = {
151
+ tag: 'product',
152
+ attrs,
153
+ content
154
+ }
155
+ return node
156
+ }
157
+ const parseProductNode = (productNode) => {
158
+ const isHidden = productNode.attrs.is_hidden === 'true'
159
+ const id = WABinary_1.getBinaryNodeChildString(productNode, 'id')
160
+ const mediaNode = WABinary_1.getBinaryNodeChild(productNode, 'media')
161
+ const statusInfoNode = WABinary_1.getBinaryNodeChild(productNode, 'status_info')
162
+ const product = {
163
+ id,
164
+ imageUrls: parseImageUrls(mediaNode),
165
+ reviewStatus: {
166
+ whatsapp: WABinary_1.getBinaryNodeChildString(statusInfoNode, 'status'),
167
+ },
168
+ availability: 'in stock',
169
+ name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
170
+ retailerId: WABinary_1.getBinaryNodeChildString(productNode, 'retailer_id'),
171
+ url: WABinary_1.getBinaryNodeChildString(productNode, 'url'),
172
+ description: WABinary_1.getBinaryNodeChildString(productNode, 'description'),
173
+ price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
174
+ currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
175
+ isHidden,
176
+ }
177
+ return product
178
+ }
179
+ /**
180
+ * Uploads images not already uploaded to WA's servers
181
+ */
182
+ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
183
+ product = {
184
+ ...product,
185
+ images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
186
+ }
187
+ return product
188
+ }
189
+ /**
190
+ * Uploads images not already uploaded to WA's servers
191
+ */
192
+ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
193
+ const results = await Promise.all(images.map(async (img) => {
194
+ if ('url' in img) {
195
+ const url = img.url.toString()
196
+ if (url.includes('.whatsapp.net')) {
197
+ return { url }
198
+ }
199
+ }
200
+ const { stream } = await messages_media_1.getStream(img)
201
+ const hasher = crypto_1.createHash('sha256')
202
+ const filePath = path_1.join(os_1.tmpdir(), 'img' + generics_1.generateMessageID())
203
+ const encFileWriteStream = fs_1.createWriteStream(filePath)
204
+ for await (const block of stream) {
205
+ hasher.update(block)
206
+ encFileWriteStream.write(block)
207
+ }
208
+ const sha = hasher.digest('base64')
209
+ const { directPath } = await waUploadToServer(filePath, {
210
+ mediaType: 'product-catalog-image',
211
+ fileEncSha256B64: sha,
212
+ timeoutMs
213
+ })
214
+ await fs_1.promises
215
+ .unlink(filePath)
216
+ .catch(err => console.log('Error deleting temp file ', err))
217
+ return { url: messages_media_1.getUrlFromDirectPath(directPath) }
218
+ }))
219
+ return results
220
+ }
221
+ const parseImageUrls = (mediaNode) => {
222
+ const imgNode = WABinary_1.getBinaryNodeChild(mediaNode, 'image')
223
+ return {
224
+ requested: WABinary_1.getBinaryNodeChildString(imgNode, 'request_image_url'),
225
+ original: WABinary_1.getBinaryNodeChildString(imgNode, 'original_image_url')
226
+ }
227
+ }
228
+ const parseStatusInfo = (mediaNode) => {
229
+ const node = WABinary_1.getBinaryNodeChild(mediaNode, 'status_info')
230
+ return {
231
+ status: WABinary_1.getBinaryNodeChildString(node, 'status'),
232
+ canAppeal: WABinary_1.getBinaryNodeChildString(node, 'can_appeal') === 'true',
233
+ }
234
+ }
235
+ module.exports = {
236
+ parseCatalogNode,
237
+ parseCollectionsNode,
238
+ parseOrderDetailsNode,
239
+ toProductNode,
240
+ parseProductNode,
241
+ uploadingNecessaryImagesOfProduct,
242
+ uploadingNecessaryImages
243
+ }
@@ -0,0 +1,72 @@
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import { proto } from '../../WAProto'
3
+ import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
4
+ import { BinaryNode } from '../WABinary'
5
+ import { ILogger } from './logger'
6
+ import { LabelAssociationType } from '../Types/LabelAssociation'
7
+
8
+ type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>
9
+
10
+ export type ChatMutationMap = {
11
+ [index: string]: ChatMutation
12
+ }
13
+
14
+ export declare const newLTHashState: () => LTHashState
15
+
16
+ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, operation }: WAPatchCreate, myAppStateKeyId: string, state: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey) => Promise<{
17
+ patch: proto.ISyncdPatch
18
+ state: LTHashState
19
+ }>
20
+
21
+ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
22
+ hash: Buffer
23
+ indexValueMap: {
24
+ [indexMacBase64: string]: {
25
+ valueMac: Uint8Array | Buffer
26
+ }
27
+ }
28
+ }>
29
+
30
+ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
31
+ hash: Buffer
32
+ indexValueMap: {
33
+ [indexMacBase64: string]: {
34
+ valueMac: Uint8Array | Buffer
35
+ }
36
+ }
37
+ }>
38
+
39
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
40
+ [T in WAPatchName]: {
41
+ patches: proto.ISyncdPatch[]
42
+ hasMorePatches: boolean
43
+ snapshot?: proto.ISyncdSnapshot | undefined
44
+ }
45
+ }>
46
+
47
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>
48
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>
49
+
50
+ export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
51
+ state: LTHashState
52
+ mutationMap: ChatMutationMap
53
+ }>
54
+
55
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
56
+ state: LTHashState
57
+ mutationMap: ChatMutationMap
58
+ }>
59
+
60
+ export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate & {
61
+ syncAction: {
62
+ timestamp?: number
63
+ contactAction?: {
64
+ fullName?: string
65
+ lidJid?: string
66
+ }
67
+ }
68
+ }
69
+
70
+ export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void
71
+
72
+ export {}