@badzz88/baileys 8.4.7 → 8.5.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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/index.js +5 -5
  4. package/lib/Defaults/index.js +187 -127
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +14 -11
  7. package/lib/Signal/Group/group-session-builder.js +91 -29
  8. package/lib/Signal/Group/group_cipher.js +88 -81
  9. package/lib/Signal/Group/index.js +136 -12
  10. package/lib/Signal/Group/keyhelper.js +70 -15
  11. package/lib/Signal/Group/sender-chain-key.js +31 -25
  12. package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
  13. package/lib/Signal/Group/sender-key-message.js +68 -65
  14. package/lib/Signal/Group/sender-key-name.js +43 -41
  15. package/lib/Signal/Group/sender-key-record.js +43 -40
  16. package/lib/Signal/Group/sender-key-state.js +96 -83
  17. package/lib/Signal/Group/sender-message-key.js +29 -25
  18. package/lib/Signal/libsignal.js +483 -424
  19. package/lib/Signal/lid-mapping.js +261 -276
  20. package/lib/Socket/Client/index.js +30 -3
  21. package/lib/Socket/Client/types.js +12 -10
  22. package/lib/Socket/Client/websocket.js +61 -53
  23. package/lib/Socket/aigroups.js +240 -0
  24. package/lib/Socket/business.js +422 -379
  25. package/lib/Socket/chats.js +1816 -1193
  26. package/lib/Socket/communities.js +549 -431
  27. package/lib/Socket/graphql.js +656 -0
  28. package/lib/Socket/groups.js +764 -374
  29. package/lib/Socket/index.js +38 -11
  30. package/lib/Socket/interactive-handler.js +522 -0
  31. package/lib/Socket/interop.js +549 -0
  32. package/lib/Socket/luxu.js +6 -5
  33. package/lib/Socket/managed-account.js +183 -0
  34. package/lib/Socket/messages-recv.js +2439 -1915
  35. package/lib/Socket/messages-send.js +1642 -1242
  36. package/lib/Socket/mex.js +59 -40
  37. package/lib/Socket/newsletter.js +812 -249
  38. package/lib/Socket/privacy.js +449 -0
  39. package/lib/Socket/registration.js +427 -0
  40. package/lib/Socket/socket.js +1077 -965
  41. package/lib/Socket/text-router.js +83 -0
  42. package/lib/Socket/username.js +237 -140
  43. package/lib/Store/index.js +36 -10
  44. package/lib/Store/make-cache-manager-store.js +85 -80
  45. package/lib/Store/make-in-memory-store.js +591 -185
  46. package/lib/Store/make-ordered-dictionary.js +78 -72
  47. package/lib/Store/object-repository.js +25 -28
  48. package/lib/Types/Auth.js +38 -2
  49. package/lib/Types/Bussines.js +2 -2
  50. package/lib/Types/Call.js +2 -2
  51. package/lib/Types/Chat.js +4 -8
  52. package/lib/Types/Contact.js +2 -2
  53. package/lib/Types/Events.js +2 -2
  54. package/lib/Types/GroupMetadata.js +2 -2
  55. package/lib/Types/Label.js +26 -24
  56. package/lib/Types/LabelAssociation.js +8 -6
  57. package/lib/Types/Message.js +95 -11
  58. package/lib/Types/Mex.js +112 -37
  59. package/lib/Types/Newsletter.js +121 -0
  60. package/lib/Types/Product.js +2 -2
  61. package/lib/Types/Signal.js +2 -2
  62. package/lib/Types/Socket.js +2 -3
  63. package/lib/Types/State.js +70 -56
  64. package/lib/Types/USync.js +2 -2
  65. package/lib/Types/index.js +55 -26
  66. package/lib/Utils/auth-utils.js +292 -288
  67. package/lib/Utils/browser-utils.js +113 -48
  68. package/lib/Utils/business.js +240 -224
  69. package/lib/Utils/chat-utils.js +1205 -869
  70. package/lib/Utils/command-loader.d.ts +31 -0
  71. package/lib/Utils/command-loader.js +100 -0
  72. package/lib/Utils/companion-reg-client-utils.js +41 -34
  73. package/lib/Utils/consumer-application.js +107 -0
  74. package/lib/Utils/crypto.js +144 -107
  75. package/lib/Utils/curve25519-js.js +275 -0
  76. package/lib/Utils/decode-wa-message.js +518 -308
  77. package/lib/Utils/event-buffer.js +596 -611
  78. package/lib/Utils/generics.js +514 -354
  79. package/lib/Utils/group-history.js +60 -0
  80. package/lib/Utils/history.js +244 -134
  81. package/lib/Utils/identity-change-handler.js +51 -49
  82. package/lib/Utils/index.js +57 -23
  83. package/lib/Utils/jid-display-normalization.js +218 -0
  84. package/lib/Utils/link-preview.js +135 -77
  85. package/lib/Utils/logger.js +9 -3
  86. package/lib/Utils/lt-hash.js +37 -6
  87. package/lib/Utils/make-mutex.js +36 -33
  88. package/lib/Utils/message-composer.js +439 -233
  89. package/lib/Utils/message-retry-manager.js +265 -260
  90. package/lib/Utils/messages-media.js +855 -747
  91. package/lib/Utils/messages.js +2528 -884
  92. package/lib/Utils/meta-ai-msmsg.js +262 -0
  93. package/lib/Utils/native-bridge.js +82 -0
  94. package/lib/Utils/noise-handler.js +195 -200
  95. package/lib/Utils/offline-node-processor.js +35 -33
  96. package/lib/Utils/pre-key-manager.js +103 -102
  97. package/lib/Utils/process-message.js +978 -560
  98. package/lib/Utils/reporting-utils.js +257 -253
  99. package/lib/Utils/session-pool.d.ts +16 -0
  100. package/lib/Utils/session-pool.js +94 -0
  101. package/lib/Utils/signal.js +218 -195
  102. package/lib/Utils/stanza-ack.js +31 -29
  103. package/lib/Utils/sticker.d.ts +17 -0
  104. package/lib/Utils/sticker.js +145 -0
  105. package/lib/Utils/sync-action-utils.js +50 -45
  106. package/lib/Utils/tc-token-utils.js +137 -139
  107. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  108. package/lib/Utils/validate-connection.js +218 -202
  109. package/lib/Utils/view-once-cache.d.ts +9 -0
  110. package/lib/Utils/view-once-cache.js +79 -0
  111. package/lib/Utils/voip-rekey.js +22 -0
  112. package/lib/WABinary/constants.js +1302 -1299
  113. package/lib/WABinary/decode.js +343 -262
  114. package/lib/WABinary/encode.js +12 -4
  115. package/lib/WABinary/generic-utils.js +223 -187
  116. package/lib/WABinary/index.js +33 -6
  117. package/lib/WABinary/jid-utils.js +351 -88
  118. package/lib/WABinary/types.js +2 -2
  119. package/lib/WAM/BinaryInfo.js +12 -9
  120. package/lib/WAM/constants.js +39486 -22853
  121. package/lib/WAM/encode.js +132 -140
  122. package/lib/WAM/index.js +31 -4
  123. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  124. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
  128. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  129. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  130. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  131. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
  133. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  134. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
  135. package/lib/WAUSync/Protocols/index.js +39 -6
  136. package/lib/WAUSync/USyncQuery.js +132 -97
  137. package/lib/WAUSync/USyncUser.js +49 -30
  138. package/lib/WAUSync/index.js +31 -4
  139. package/lib/antiban.js +4637 -0
  140. package/lib/index.js +48 -15
  141. package/package.json +55 -92
  142. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
  143. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  144. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
@@ -1,49 +1,114 @@
1
- import { platform, release } from 'os';
2
- import { proto } from '../../WAProto/index.js';
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
+ }
3
19
  const PLATFORM_MAP = {
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
- cikikomo: browser => ['cikikomo', getBrowserN(browser), '1.0.0'],
34
- windows: browser => ['Windows', getBrowserN(browser), '10.0.22631'],
35
- iOS: browser => ['iOS', getBrowserN(browser), '18.2'],
36
- android: browser => ['Android', getBrowserN(browser), '14.0.0'],
37
- safari: browser => ['Safari', getBrowserN(browser), '26.5'],
38
- custom: (platform, browser, ver) => {
39
- let platformN = PLATFORM_MAP[platform].toLowerCase() || platform;
40
- return [platformN, getBrowserN(browser), ver];
41
- },
42
- /** The appropriate browser based on your OS & release */
43
- appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', getBrowserN(browser), release()]
44
- };
45
- export const getPlatformId = (browser) => {
46
- const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
47
- return platformType ? platformType.toString() : '1'; //chrome
48
- };
49
- //# sourceMappingURL=browser-utils.js.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
@@ -1,231 +1,247 @@
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
- };
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
175
189
  /**
176
190
  * Uploads images not already uploaded to WA's servers
177
191
  */
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;
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
186
200
  }
187
201
  /**
188
202
  * Uploads images not already uploaded to WA's servers
189
203
  */
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
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
+ }