@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.
- package/README.md +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +747 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
|
@@ -1,114 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,247 +1,231 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|