@hansaka02/baileys 7.3.2 → 7.3.6

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 (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
@@ -1,70 +1,69 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
9
- const events_1 = __importDefault(require("events"))
10
- const fs_1 = require("fs")
11
- const promises_1 = require("fs/promises")
12
- const readline_1 = require("readline")
13
- const generics_1 = require("./generics")
14
- const make_mutex_1 = require("./make-mutex")
15
-
16
- /**
17
- * Captures events from a baileys event emitter & stores them in a file
18
- * @param ev The event emitter to read events from
19
- * @param filename File to save to
20
- */
21
- const captureEventStream = (ev, filename) => {
22
- const oldEmit = ev.emit
23
- // write mutex so data is appended in order
24
- const writeMutex = make_mutex_1.makeMutex()
25
- // monkey patch eventemitter to capture all events
26
- ev.emit = function (...args) {
27
- const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
28
- const result = oldEmit.apply(ev, args)
29
- writeMutex.mutex(async () => {
30
- await promises_1.writeFile(filename, content, { flag: 'a' })
31
- })
32
- return result
33
- }
34
- }
35
-
36
- /**
37
- * Read event file and emit events from there
38
- * @param filename filename containing event data
39
- * @param delayIntervalMs delay between each event emit
40
- */
41
- const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
42
- const ev = new events_1.default()
43
- const fireEvents = async () => {
44
- // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
45
- const fileStream = fs_1.createReadStream(filename)
46
- const rl = readline_1.createInterface({
47
- input: fileStream,
48
- crlfDelay: Infinity
49
- })
50
- // Note: we use the crlfDelay option to recognize all instances of CR LF
51
- // ('\r\n') in input.txt as a single line break.
52
- for await (const line of rl) {
53
- if (line) {
54
- const { event, data } = JSON.parse(line)
55
- ev.emit(event, data)
56
- delayIntervalMs && await generics_1.delay(delayIntervalMs)
57
- }
58
- }
59
- fileStream.close()
60
- }
61
- return {
62
- ev,
63
- task: fireEvents()
64
- }
65
- }
66
-
67
- module.exports = {
68
- captureEventStream,
69
- readAndEmitEventStream
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const Events = require("events")
6
+ const {
7
+ promises,
8
+ createReadStream
9
+ } = require("fs")
10
+ const { writeFile } = require("fs/promises")
11
+ const { createInterface } = require("readline")
12
+ const { delay } = require("./generics")
13
+ const { makeMutex } = require("./make-mutex")
14
+
15
+ /**
16
+ * Captures events from a baileys event emitter & stores them in a file
17
+ * @param ev The event emitter to read events from
18
+ * @param filename File to save to
19
+ */
20
+ const captureEventStream = (ev, filename) => {
21
+ const oldEmit = ev.emit
22
+ // write mutex so data is appended in order
23
+ const writeMutex = makeMutex()
24
+ // monkey patch eventemitter to capture all events
25
+ ev.emit = function (...args) {
26
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
27
+ const result = oldEmit.apply(ev, args)
28
+ writeMutex.mutex(async () => {
29
+ await promises.writeFile(filename, content, { flag: 'a' })
30
+ })
31
+ return result
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Read event file and emit events from there
37
+ * @param filename filename containing event data
38
+ * @param delayIntervalMs delay between each event emit
39
+ */
40
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
41
+ const ev = new Events()
42
+ const fireEvents = async () => {
43
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
44
+ const fileStream = createReadStream(filename)
45
+ const rl = createInterface({
46
+ input: fileStream,
47
+ crlfDelay: Infinity
48
+ })
49
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
50
+ // ('\r\n') in input.txt as a single line break.
51
+ for await (const line of rl) {
52
+ if (line) {
53
+ const { event, data } = JSON.parse(line)
54
+ ev.emit(event, data)
55
+ delayIntervalMs && await delay(delayIntervalMs)
56
+ }
57
+ }
58
+ fileStream.close()
59
+ }
60
+ return {
61
+ ev,
62
+ task: fireEvents()
63
+ }
64
+ }
65
+
66
+ module.exports = {
67
+ captureEventStream,
68
+ readAndEmitEventStream
70
69
  }
@@ -0,0 +1,43 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const {
6
+ platform,
7
+ release
8
+ } = require("os")
9
+ const { proto } = require("../../WAProto")
10
+
11
+ const PLATFORM_MAP = {
12
+ aix: 'AIX',
13
+ darwin: 'Mac OS',
14
+ win32: 'Windows',
15
+ android: 'Android',
16
+ freebsd: 'FreeBSD',
17
+ openbsd: 'OpenBSD',
18
+ sunos: 'Solaris',
19
+ linux: undefined,
20
+ haiku: undefined,
21
+ cygwin: undefined,
22
+ netbsd: undefined
23
+ }
24
+
25
+ const Browsers = {
26
+ ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
27
+ macOS: browser => ['Mac OS', browser, '14.4.1'],
28
+ baileys: browser => ['Baileys', browser, '6.5.0'],
29
+ windows: browser => ['Windows', browser, '10.0.22631'],
30
+ //android: browser => [browser, 'Android', ''],
31
+ /** The appropriate browser based on your OS & release */
32
+ appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
33
+ }
34
+
35
+ const getPlatformId = (browser) => {
36
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()]
37
+ return platformType ? platformType.toString() : '1' //chrome
38
+ }
39
+
40
+ module.exports = {
41
+ Browsers,
42
+ getPlatformId
43
+ }
@@ -2,33 +2,43 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const boom_1 = require("@hapi/boom")
6
- const crypto_1 = require("crypto")
7
- const path_1 = require("path")
8
- const os_1 = require("os")
9
- const fs_1 = require("fs")
10
- const WABinary_1 = require("../WABinary")
11
- const generics_1 = require("./generics")
12
- const messages_media_1 = require("./messages-media")
5
+ const { Boom } = require("@hapi/boom")
6
+ const { createHash } = require("crypto")
7
+ const { join } = require("path")
8
+ const { tmpdir } = require("os")
9
+ const {
10
+ promises,
11
+ createWriteStream
12
+ } = require("fs")
13
+ const {
14
+ getBinaryNodeChild,
15
+ getBinaryNodeChildren,
16
+ getBinaryNodeChildString
17
+ } = require("../WABinary")
18
+ const {
19
+ getStream,
20
+ getUrlFromDirectPath
21
+ } = require("./messages-media")
22
+ const { generateMessageID } = require("./generics")
13
23
 
14
24
  const parseCatalogNode = (node) => {
15
- const catalogNode = WABinary_1.getBinaryNodeChild(node, 'product_catalog')
16
- const products = WABinary_1.getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
17
- const paging = WABinary_1.getBinaryNodeChild(catalogNode, 'paging')
25
+ const catalogNode = getBinaryNodeChild(node, 'product_catalog')
26
+ const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
27
+ const paging = getBinaryNodeChild(catalogNode, 'paging')
18
28
  return {
19
29
  products,
20
30
  nextPageCursor: paging
21
- ? WABinary_1.getBinaryNodeChildString(paging, 'after')
31
+ ? getBinaryNodeChildString(paging, 'after')
22
32
  : undefined
23
33
  }
24
34
  }
25
35
 
26
36
  const parseCollectionsNode = (node) => {
27
- const collectionsNode = WABinary_1.getBinaryNodeChild(node, 'collections')
28
- const collections = WABinary_1.getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
29
- const id = WABinary_1.getBinaryNodeChildString(collectionNode, 'id')
30
- const name = WABinary_1.getBinaryNodeChildString(collectionNode, 'name')
31
- const products = WABinary_1.getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
37
+ const collectionsNode = getBinaryNodeChild(node, 'collections')
38
+ const collections = getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
39
+ const id = getBinaryNodeChildString(collectionNode, 'id')
40
+ const name = getBinaryNodeChildString(collectionNode, 'name')
41
+ const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
32
42
  return {
33
43
  id,
34
44
  name,
@@ -42,23 +52,23 @@ const parseCollectionsNode = (node) => {
42
52
  }
43
53
 
44
54
  const parseOrderDetailsNode = (node) => {
45
- const orderNode = WABinary_1.getBinaryNodeChild(node, 'order')
46
- const products = WABinary_1.getBinaryNodeChildren(orderNode, 'product').map(productNode => {
47
- const imageNode = WABinary_1.getBinaryNodeChild(productNode, 'image')
55
+ const orderNode = getBinaryNodeChild(node, 'order')
56
+ const products = getBinaryNodeChildren(orderNode, 'product').map(productNode => {
57
+ const imageNode = getBinaryNodeChild(productNode, 'image')
48
58
  return {
49
- id: WABinary_1.getBinaryNodeChildString(productNode, 'id'),
50
- name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
51
- imageUrl: WABinary_1.getBinaryNodeChildString(imageNode, 'url'),
52
- price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
53
- currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
54
- quantity: +WABinary_1.getBinaryNodeChildString(productNode, 'quantity')
59
+ id: getBinaryNodeChildString(productNode, 'id'),
60
+ name: getBinaryNodeChildString(productNode, 'name'),
61
+ imageUrl: getBinaryNodeChildString(imageNode, 'url'),
62
+ price: +getBinaryNodeChildString(productNode, 'price'),
63
+ currency: getBinaryNodeChildString(productNode, 'currency'),
64
+ quantity: +getBinaryNodeChildString(productNode, 'quantity')
55
65
  }
56
66
  })
57
- const priceNode = WABinary_1.getBinaryNodeChild(orderNode, 'price')
67
+ const priceNode = getBinaryNodeChild(orderNode, 'price')
58
68
  const orderDetails = {
59
69
  price: {
60
- total: +WABinary_1.getBinaryNodeChildString(priceNode, 'total'),
61
- currency: WABinary_1.getBinaryNodeChildString(priceNode, 'currency'),
70
+ total: +getBinaryNodeChildString(priceNode, 'total'),
71
+ currency: getBinaryNodeChildString(priceNode, 'currency'),
62
72
  },
63
73
  products
64
74
  }
@@ -102,7 +112,7 @@ const toProductNode = (productId, product) => {
102
112
  attrs: {},
103
113
  content: product.images.map(img => {
104
114
  if (!('url' in img)) {
105
- throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
115
+ throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 })
106
116
  }
107
117
  return {
108
118
  tag: 'image',
@@ -163,23 +173,23 @@ const toProductNode = (productId, product) => {
163
173
 
164
174
  const parseProductNode = (productNode) => {
165
175
  const isHidden = productNode.attrs.is_hidden === 'true'
166
- const id = WABinary_1.getBinaryNodeChildString(productNode, 'id')
167
- const mediaNode = WABinary_1.getBinaryNodeChild(productNode, 'media')
168
- const statusInfoNode = WABinary_1.getBinaryNodeChild(productNode, 'status_info')
176
+ const id = getBinaryNodeChildString(productNode, 'id')
177
+ const mediaNode = getBinaryNodeChild(productNode, 'media')
178
+ const statusInfoNode = getBinaryNodeChild(productNode, 'status_info')
169
179
  const product = {
170
180
  id,
171
181
  imageUrls: parseImageUrls(mediaNode),
172
182
  reviewStatus: {
173
- whatsapp: WABinary_1.getBinaryNodeChildString(statusInfoNode, 'status'),
183
+ whatsapp: getBinaryNodeChildString(statusInfoNode, 'status'),
174
184
  },
175
185
  availability: 'in stock',
176
- name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
177
- retailerId: WABinary_1.getBinaryNodeChildString(productNode, 'retailer_id'),
178
- url: WABinary_1.getBinaryNodeChildString(productNode, 'url'),
179
- description: WABinary_1.getBinaryNodeChildString(productNode, 'description'),
180
- price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
181
- currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
182
- isHidden,
186
+ name: getBinaryNodeChildString(productNode, 'name'),
187
+ retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
188
+ url: getBinaryNodeChildString(productNode, 'url'),
189
+ description: getBinaryNodeChildString(productNode, 'description'),
190
+ price: +getBinaryNodeChildString(productNode, 'price'),
191
+ currency: getBinaryNodeChildString(productNode, 'currency'),
192
+ isHidden
183
193
  }
184
194
  return product
185
195
  }
@@ -206,10 +216,10 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
206
216
  return { url }
207
217
  }
208
218
  }
209
- const { stream } = await messages_media_1.getStream(img)
210
- const hasher = crypto_1.createHash('sha256')
211
- const filePath = path_1.join(os_1.tmpdir(), 'img' + generics_1.generateMessageID())
212
- const encFileWriteStream = fs_1.createWriteStream(filePath)
219
+ const { stream } = await getStream(img)
220
+ const hasher = createHash('sha256')
221
+ const filePath = join(tmpdir(), 'img' + generateMessageID())
222
+ const encFileWriteStream = createWriteStream(filePath)
213
223
  for await (const block of stream) {
214
224
  hasher.update(block)
215
225
  encFileWriteStream.write(block)
@@ -220,27 +230,27 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
220
230
  fileEncSha256B64: sha,
221
231
  timeoutMs
222
232
  })
223
- await fs_1.promises
233
+ await promises
224
234
  .unlink(filePath)
225
235
  .catch(err => console.log('Error deleting temp file ', err))
226
- return { url: messages_media_1.getUrlFromDirectPath(directPath) }
236
+ return { url: getUrlFromDirectPath(directPath) }
227
237
  }))
228
238
  return results
229
239
  }
230
240
 
231
241
  const parseImageUrls = (mediaNode) => {
232
- const imgNode = WABinary_1.getBinaryNodeChild(mediaNode, 'image')
242
+ const imgNode = getBinaryNodeChild(mediaNode, 'image')
233
243
  return {
234
- requested: WABinary_1.getBinaryNodeChildString(imgNode, 'request_image_url'),
235
- original: WABinary_1.getBinaryNodeChildString(imgNode, 'original_image_url')
244
+ requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
245
+ original: getBinaryNodeChildString(imgNode, 'original_image_url')
236
246
  }
237
247
  }
238
248
 
239
249
  const parseStatusInfo = (mediaNode) => {
240
- const node = WABinary_1.getBinaryNodeChild(mediaNode, 'status_info')
250
+ const node = getBinaryNodeChild(mediaNode, 'status_info')
241
251
  return {
242
- status: WABinary_1.getBinaryNodeChildString(node, 'status'),
243
- canAppeal: WABinary_1.getBinaryNodeChildString(node, 'can_appeal') === 'true',
252
+ status: getBinaryNodeChildString(node, 'status'),
253
+ canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true',
244
254
  }
245
255
  }
246
256