@badzz88/baileys 8.5.7 → 8.5.8

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 (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +747 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,114 +1,48 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.getPlatformId = exports.Browsers = void 0
4
- const os_1 = require('os')
5
- const index_js_1 = require('../../WAProto/index.js')
6
- const COMPANION_PLATFORM_MAP = {
7
- Chrome: '49',
8
- Edge: '50',
9
- Firefox: '51',
10
- Opera: '53',
11
- Safari: '54',
12
- Brave: '1.79.112',
13
- Vivaldi: '6.2.3105.58',
14
- Tor: '12.5.3',
15
- Yandex: '23.7.1',
16
- Falkon: '22.08.3',
17
- Epiphany: '44.2'
18
- }
1
+ import { platform, release } from 'os';
2
+ import { proto } from '../../WAProto/index.js';
19
3
  const PLATFORM_MAP = {
20
- aix: 'AIX',
21
- darwin: 'Mac OS',
22
- win32: 'Windows',
23
- android: 'Android',
24
- freebsd: 'FreeBSD',
25
- openbsd: 'OpenBSD',
26
- sunos: 'Solaris',
27
- linux: 'Linux',
28
- ubuntu: 'Ubuntu',
29
- ios: 'iOS',
30
- baileys: 'Baileys',
31
- chromeos: 'Chrome OS',
32
- tizen: 'Tizen',
33
- watchos: 'watchOS',
34
- wearos: 'Wear OS',
35
- harmonyos: 'HarmonyOS',
36
- kaios: 'KaiOS',
37
- smarttv: 'Smart TV',
38
- raspberrypi: 'Raspberry Pi OS',
39
- symbian: 'Symbian',
40
- blackberry: 'Blackberry OS',
41
- windowsphone: 'Windows Phone',
42
- safari: 'Safari'
43
- }
44
-
45
- const PLATFORM_VERSIONS = {
46
- ubuntu: '22.04.4',
47
- darwin: '18.5',
48
- win32: '10.0.22631',
49
- android: '14.0.0',
50
- freebsd: '13.2',
51
- openbsd: '7.3',
52
- sunos: '11',
53
- linux: '6.5',
54
- ios: '18.2',
55
- baileys: '6.5.0',
56
- chromeos: '117.0.5938.132',
57
- tizen: '6.5',
58
- watchos: '10.1',
59
- wearos: '4.1',
60
- harmonyos: '4.0.0',
61
- kaios: '3.1',
62
- smarttv: '23.3.1',
63
- raspberrypi: '11 (Bullseye)',
64
- symbian: '3',
65
- blackberry: '10.3.3',
66
- windowsphone: '8.1'
67
- }
68
-
69
- exports.Browsers = {
70
- ubuntu: browser => {
71
- return [PLATFORM_MAP['ubuntu'], browser, PLATFORM_VERSIONS['ubuntu']]
72
- },
73
- macOS: browser => {
74
- return [PLATFORM_MAP['darwin'], browser, PLATFORM_VERSIONS['darwin']]
75
- },
76
- windows: browser => {
77
- return [PLATFORM_MAP['win32'], browser, PLATFORM_VERSIONS['win32']]
78
- },
79
- linux: browser => {
80
- return [PLATFORM_MAP['linux'], browser, PLATFORM_VERSIONS['linux']]
81
- },
82
- solaris: browser => {
83
- return [PLATFORM_MAP['sunos'], browser, PLATFORM_VERSIONS['sunos']]
84
- },
85
- baileys: browser => {
86
- return [PLATFORM_MAP['baileys'], browser, PLATFORM_VERSIONS['baileys']]
87
- },
88
- android: browser => {
89
- return [PLATFORM_MAP['android'], browser, PLATFORM_VERSIONS['android']]
90
- },
91
- iOS: browser => {
92
- return [PLATFORM_MAP['ios'], browser, PLATFORM_VERSIONS['ios']]
93
- },
94
- kaiOS: browser => {
95
- return [PLATFORM_MAP['kaios'], browser, PLATFORM_VERSIONS['kaios']]
96
- },
97
- chromeOS: browser => {
98
- return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
99
- },
100
- appropriate: browser => {
101
- const platform = os_1.platform()
102
- const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
103
- return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
104
- },
105
- custom: (platform, browser, version) => {
106
- const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform
107
- return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest']
108
- }
109
- }
110
- const getPlatformId = browser => {
111
- const platformType = index_js_1.proto.DeviceProps.PlatformType[browser.toUpperCase()]
112
- return platformType ? platformType.toString() : '1' //chrome
113
- }
114
- exports.getPlatformId = getPlatformId
4
+ aix: 'AIX',
5
+ darwin: 'Mac OS',
6
+ win32: 'Windows',
7
+ android: 'Android',
8
+ freebsd: 'FreeBSD',
9
+ openbsd: 'OpenBSD',
10
+ sunos: 'Solaris',
11
+ linux: 'Linux',
12
+ haiku: undefined,
13
+ cygwin: undefined,
14
+ netbsd: undefined
15
+ };
16
+ const BROWSER_MAP = {
17
+ safari: 'Safari',
18
+ chrome: 'Chrome',
19
+ edge: 'Edge',
20
+ firefox: 'Firefox',
21
+ opera: 'Opera',
22
+ brave: 'Brave',
23
+ samsung: 'Samsung Internet'
24
+ };
25
+ const getBrowserN = (bros) => {
26
+ const brosN = BROWSER_MAP[bros] || bros;
27
+ return brosN;
28
+ };
29
+ export const Browsers = {
30
+ ubuntu: browser => ['Ubuntu', getBrowserN(browser), '22.04.4'],
31
+ macOS: browser => ['Mac OS', getBrowserN(browser), '14.4.1'],
32
+ baileys: browser => ['Baileys', getBrowserN(browser), '6.5.0'],
33
+ windows: browser => ['Windows', getBrowserN(browser), '10.0.22631'],
34
+ iOS: browser => ['iOS', getBrowserN(browser), '18.2'],
35
+ android: browser => ['Android', getBrowserN(browser), '14.0.0'],
36
+ safari: browser => ['Safari', getBrowserN(browser), '26.5'],
37
+ custom: (platform, browser, ver) => {
38
+ let platformN = PLATFORM_MAP[platform].toLowerCase() || platform;
39
+ return [platformN, getBrowserN(browser), ver];
40
+ },
41
+ /** The appropriate browser based on your OS & release */
42
+ appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', getBrowserN(browser), release()]
43
+ };
44
+ export const getPlatformId = (browser) => {
45
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
46
+ return platformType ? platformType.toString() : '1'; //chrome
47
+ };
48
+ //# sourceMappingURL=browser-utils.js.map
@@ -1,247 +1,231 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.uploadingNecessaryImages =
4
- exports.parseProductNode =
5
- exports.toProductNode =
6
- exports.parseOrderDetailsNode =
7
- exports.parseCollectionsNode =
8
- exports.parseCatalogNode =
9
- void 0
10
- exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct
11
- const boom_1 = require('@hapi/boom')
12
- const crypto_1 = require('crypto')
13
- const fs_1 = require('fs')
14
- const os_1 = require('os')
15
- const path_1 = require('path')
16
- const WABinary_1 = require('../WABinary')
17
- const generics_1 = require('./generics')
18
- const messages_media_1 = require('./messages-media')
19
- const parseCatalogNode = node => {
20
- const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog')
21
- const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode)
22
- const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging')
23
- return {
24
- products,
25
- nextPageCursor: paging ? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after') : undefined
26
- }
27
- }
28
- exports.parseCatalogNode = parseCatalogNode
29
- const parseCollectionsNode = node => {
30
- const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections')
31
- const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
32
- const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id')
33
- const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name')
34
- const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode)
35
- return {
36
- id,
37
- name,
38
- products,
39
- status: parseStatusInfo(collectionNode)
40
- }
41
- })
42
- return {
43
- collections
44
- }
45
- }
46
- exports.parseCollectionsNode = parseCollectionsNode
47
- const parseOrderDetailsNode = node => {
48
- const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order')
49
- const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
50
- const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image')
51
- return {
52
- id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
53
- name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
54
- imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
55
- price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
56
- currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
57
- quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
58
- }
59
- })
60
- const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price')
61
- const orderDetails = {
62
- price: {
63
- total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
64
- currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency')
65
- },
66
- products
67
- }
68
- return orderDetails
69
- }
70
- exports.parseOrderDetailsNode = parseOrderDetailsNode
71
- const toProductNode = (productId, product) => {
72
- const attrs = {}
73
- const content = []
74
- if (typeof productId !== 'undefined') {
75
- content.push({
76
- tag: 'id',
77
- attrs: {},
78
- content: Buffer.from(productId)
79
- })
80
- }
81
- if (typeof product.name !== 'undefined') {
82
- content.push({
83
- tag: 'name',
84
- attrs: {},
85
- content: Buffer.from(product.name)
86
- })
87
- }
88
- if (typeof product.description !== 'undefined') {
89
- content.push({
90
- tag: 'description',
91
- attrs: {},
92
- content: Buffer.from(product.description)
93
- })
94
- }
95
- if (typeof product.retailerId !== 'undefined') {
96
- content.push({
97
- tag: 'retailer_id',
98
- attrs: {},
99
- content: Buffer.from(product.retailerId)
100
- })
101
- }
102
- if (product.images.length) {
103
- content.push({
104
- tag: 'media',
105
- attrs: {},
106
- content: product.images.map(img => {
107
- if (!('url' in img)) {
108
- throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
109
- }
110
- return {
111
- tag: 'image',
112
- attrs: {},
113
- content: [
114
- {
115
- tag: 'url',
116
- attrs: {},
117
- content: Buffer.from(img.url.toString())
118
- }
119
- ]
120
- }
121
- })
122
- })
123
- }
124
- if (typeof product.price !== 'undefined') {
125
- content.push({
126
- tag: 'price',
127
- attrs: {},
128
- content: Buffer.from(product.price.toString())
129
- })
130
- }
131
- if (typeof product.currency !== 'undefined') {
132
- content.push({
133
- tag: 'currency',
134
- attrs: {},
135
- content: Buffer.from(product.currency)
136
- })
137
- }
138
- if ('originCountryCode' in product) {
139
- if (typeof product.originCountryCode === 'undefined') {
140
- attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
141
- } else {
142
- content.push({
143
- tag: 'compliance_info',
144
- attrs: {},
145
- content: [
146
- {
147
- tag: 'country_code_origin',
148
- attrs: {},
149
- content: Buffer.from(product.originCountryCode)
150
- }
151
- ]
152
- })
153
- }
154
- }
155
- if (typeof product.isHidden !== 'undefined') {
156
- attrs['is_hidden'] = product.isHidden.toString()
157
- }
158
- const node = {
159
- tag: 'product',
160
- attrs,
161
- content
162
- }
163
- return node
164
- }
165
- exports.toProductNode = toProductNode
166
- const parseProductNode = productNode => {
167
- const isHidden = productNode.attrs.is_hidden === 'true'
168
- const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id')
169
- const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media')
170
- const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info')
171
- const product = {
172
- id,
173
- imageUrls: parseImageUrls(mediaNode),
174
- reviewStatus: {
175
- whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status')
176
- },
177
- availability: 'in stock',
178
- name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
179
- retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
180
- url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
181
- description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
182
- price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
183
- currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
184
- isHidden
185
- }
186
- return product
187
- }
188
- exports.parseProductNode = parseProductNode
1
+ import { Boom } from '@hapi/boom';
2
+ import { createHash } from 'crypto';
3
+ import { createWriteStream, promises as fs } from 'fs';
4
+ import { tmpdir } from 'os';
5
+ import { join } from 'path';
6
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../WABinary/index.js';
7
+ import { generateMessageIDV2 } from './generics.js';
8
+ import { getStream, getUrlFromDirectPath } from './messages-media.js';
9
+ export const parseCatalogNode = (node) => {
10
+ const catalogNode = getBinaryNodeChild(node, 'product_catalog');
11
+ const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode);
12
+ const paging = getBinaryNodeChild(catalogNode, 'paging');
13
+ return {
14
+ products,
15
+ nextPageCursor: paging ? getBinaryNodeChildString(paging, 'after') : undefined
16
+ };
17
+ };
18
+ export const parseCollectionsNode = (node) => {
19
+ const collectionsNode = getBinaryNodeChild(node, 'collections');
20
+ const collections = getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
21
+ const id = getBinaryNodeChildString(collectionNode, 'id');
22
+ const name = getBinaryNodeChildString(collectionNode, 'name');
23
+ const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode);
24
+ return {
25
+ id,
26
+ name,
27
+ products,
28
+ status: parseStatusInfo(collectionNode)
29
+ };
30
+ });
31
+ return {
32
+ collections
33
+ };
34
+ };
35
+ export const parseOrderDetailsNode = (node) => {
36
+ const orderNode = getBinaryNodeChild(node, 'order');
37
+ const products = getBinaryNodeChildren(orderNode, 'product').map(productNode => {
38
+ const imageNode = getBinaryNodeChild(productNode, 'image');
39
+ return {
40
+ id: getBinaryNodeChildString(productNode, 'id'),
41
+ name: getBinaryNodeChildString(productNode, 'name'),
42
+ imageUrl: getBinaryNodeChildString(imageNode, 'url'),
43
+ price: +getBinaryNodeChildString(productNode, 'price'),
44
+ currency: getBinaryNodeChildString(productNode, 'currency'),
45
+ quantity: +getBinaryNodeChildString(productNode, 'quantity')
46
+ };
47
+ });
48
+ const priceNode = getBinaryNodeChild(orderNode, 'price');
49
+ const orderDetails = {
50
+ price: {
51
+ total: +getBinaryNodeChildString(priceNode, 'total'),
52
+ currency: getBinaryNodeChildString(priceNode, 'currency')
53
+ },
54
+ products
55
+ };
56
+ return orderDetails;
57
+ };
58
+ export const toProductNode = (productId, product) => {
59
+ const attrs = {};
60
+ const content = [];
61
+ if (typeof productId !== 'undefined') {
62
+ content.push({
63
+ tag: 'id',
64
+ attrs: {},
65
+ content: Buffer.from(productId)
66
+ });
67
+ }
68
+ if (typeof product.name !== 'undefined') {
69
+ content.push({
70
+ tag: 'name',
71
+ attrs: {},
72
+ content: Buffer.from(product.name)
73
+ });
74
+ }
75
+ if (typeof product.description !== 'undefined') {
76
+ content.push({
77
+ tag: 'description',
78
+ attrs: {},
79
+ content: Buffer.from(product.description)
80
+ });
81
+ }
82
+ if (typeof product.retailerId !== 'undefined') {
83
+ content.push({
84
+ tag: 'retailer_id',
85
+ attrs: {},
86
+ content: Buffer.from(product.retailerId)
87
+ });
88
+ }
89
+ if (product.images.length) {
90
+ content.push({
91
+ tag: 'media',
92
+ attrs: {},
93
+ content: product.images.map(img => {
94
+ if (!('url' in img)) {
95
+ throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 });
96
+ }
97
+ return {
98
+ tag: 'image',
99
+ attrs: {},
100
+ content: [
101
+ {
102
+ tag: 'url',
103
+ attrs: {},
104
+ content: Buffer.from(img.url.toString())
105
+ }
106
+ ]
107
+ };
108
+ })
109
+ });
110
+ }
111
+ if (typeof product.price !== 'undefined') {
112
+ content.push({
113
+ tag: 'price',
114
+ attrs: {},
115
+ content: Buffer.from(product.price.toString())
116
+ });
117
+ }
118
+ if (typeof product.currency !== 'undefined') {
119
+ content.push({
120
+ tag: 'currency',
121
+ attrs: {},
122
+ content: Buffer.from(product.currency)
123
+ });
124
+ }
125
+ if ('originCountryCode' in product) {
126
+ if (typeof product.originCountryCode === 'undefined') {
127
+ attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
128
+ }
129
+ else {
130
+ content.push({
131
+ tag: 'compliance_info',
132
+ attrs: {},
133
+ content: [
134
+ {
135
+ tag: 'country_code_origin',
136
+ attrs: {},
137
+ content: Buffer.from(product.originCountryCode)
138
+ }
139
+ ]
140
+ });
141
+ }
142
+ }
143
+ if (typeof product.isHidden !== 'undefined') {
144
+ attrs['is_hidden'] = product.isHidden.toString();
145
+ }
146
+ const node = {
147
+ tag: 'product',
148
+ attrs,
149
+ content
150
+ };
151
+ return node;
152
+ };
153
+ export const parseProductNode = (productNode) => {
154
+ const isHidden = productNode.attrs.is_hidden === 'true';
155
+ const id = getBinaryNodeChildString(productNode, 'id');
156
+ const mediaNode = getBinaryNodeChild(productNode, 'media');
157
+ const statusInfoNode = getBinaryNodeChild(productNode, 'status_info');
158
+ const product = {
159
+ id,
160
+ imageUrls: parseImageUrls(mediaNode),
161
+ reviewStatus: {
162
+ whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
163
+ },
164
+ availability: 'in stock',
165
+ name: getBinaryNodeChildString(productNode, 'name'),
166
+ retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
167
+ url: getBinaryNodeChildString(productNode, 'url'),
168
+ description: getBinaryNodeChildString(productNode, 'description'),
169
+ price: +getBinaryNodeChildString(productNode, 'price'),
170
+ currency: getBinaryNodeChildString(productNode, 'currency'),
171
+ isHidden
172
+ };
173
+ return product;
174
+ };
189
175
  /**
190
176
  * Uploads images not already uploaded to WA's servers
191
177
  */
192
- async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
193
- product = {
194
- ...product,
195
- images: product.images
196
- ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs)
197
- : product.images
198
- }
199
- return product
178
+ export async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
179
+ product = {
180
+ ...product,
181
+ images: product.images
182
+ ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
183
+ : product.images
184
+ };
185
+ return product;
200
186
  }
201
187
  /**
202
188
  * Uploads images not already uploaded to WA's servers
203
189
  */
204
- const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
205
- const results = await Promise.all(
206
- images.map(async img => {
207
- if ('url' in img) {
208
- const url = img.url.toString()
209
- if (url.includes('.whatsapp.net')) {
210
- return { url }
211
- }
212
- }
213
- const { stream } = await (0, messages_media_1.getStream)(img)
214
- const hasher = (0, crypto_1.createHash)('sha256')
215
- const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_1.generateMessageIDV2)())
216
- const encFileWriteStream = (0, fs_1.createWriteStream)(filePath)
217
- for await (const block of stream) {
218
- hasher.update(block)
219
- encFileWriteStream.write(block)
220
- }
221
- const sha = hasher.digest('base64')
222
- const { directPath } = await waUploadToServer(filePath, {
223
- mediaType: 'product-catalog-image',
224
- fileEncSha256B64: sha,
225
- timeoutMs
226
- })
227
- await fs_1.promises.unlink(filePath).catch(() => {})
228
- return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) }
229
- })
230
- )
231
- return results
232
- }
233
- exports.uploadingNecessaryImages = uploadingNecessaryImages
234
- const parseImageUrls = mediaNode => {
235
- const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image')
236
- return {
237
- requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
238
- original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
239
- }
240
- }
241
- const parseStatusInfo = mediaNode => {
242
- const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info')
243
- return {
244
- status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
245
- canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
246
- }
247
- }
190
+ export const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
191
+ const results = await Promise.all(images.map(async (img) => {
192
+ if ('url' in img) {
193
+ const url = img.url.toString();
194
+ if (url.includes('.whatsapp.net')) {
195
+ return { url };
196
+ }
197
+ }
198
+ const { stream } = await getStream(img);
199
+ const hasher = createHash('sha256');
200
+ const filePath = join(tmpdir(), 'img' + generateMessageIDV2());
201
+ const encFileWriteStream = createWriteStream(filePath);
202
+ for await (const block of stream) {
203
+ hasher.update(block);
204
+ encFileWriteStream.write(block);
205
+ }
206
+ const sha = hasher.digest('base64');
207
+ const { directPath } = await waUploadToServer(filePath, {
208
+ mediaType: 'product-catalog-image',
209
+ fileEncSha256B64: sha,
210
+ timeoutMs
211
+ });
212
+ await fs.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
213
+ return { url: getUrlFromDirectPath(directPath) };
214
+ }));
215
+ return results;
216
+ };
217
+ const parseImageUrls = (mediaNode) => {
218
+ const imgNode = getBinaryNodeChild(mediaNode, 'image');
219
+ return {
220
+ requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
221
+ original: getBinaryNodeChildString(imgNode, 'original_image_url')
222
+ };
223
+ };
224
+ const parseStatusInfo = (mediaNode) => {
225
+ const node = getBinaryNodeChild(mediaNode, 'status_info');
226
+ return {
227
+ status: getBinaryNodeChildString(node, 'status'),
228
+ canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
229
+ };
230
+ };
231
+ //# sourceMappingURL=business.js.map