sanka-baileyss 2.3.2 → 2.3.4
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/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
- package/WAProto/BotMetadata/BotMetadata.js +1910 -148
- package/WAProto/BotMetadata/BotMetadata.proto +36 -0
- package/WAProto/E2E/E2E.d.ts +570 -6
- package/WAProto/E2E/E2E.js +1591 -26
- package/WAProto/E2E/E2E.proto +10 -1
- package/WAProto/HistorySync/HistorySync.d.ts +806 -6
- package/WAProto/HistorySync/HistorySync.js +2193 -29
- package/WAProto/HistorySync/HistorySync.proto +2 -1
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
- package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
- package/WAProto/SyncAction/SyncAction.d.ts +230 -0
- package/WAProto/SyncAction/SyncAction.js +578 -2
- package/WAProto/SyncAction/SyncAction.proto +13 -1
- package/WAProto/Web/Web.d.ts +570 -6
- package/WAProto/Web/Web.js +1591 -26
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +42 -25
- package/lib/Defaults/index.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +23 -28
- package/lib/Signal/libsignal.d.ts +1 -0
- package/lib/Socket/Client/index.js +13 -9
- package/lib/Socket/Client/types.d.ts +11 -10
- package/lib/Socket/Client/types.js +11 -7
- package/lib/Socket/Client/websocket.d.ts +9 -8
- package/lib/Socket/Client/websocket.js +52 -47
- package/lib/Socket/business.d.ts +185 -182
- package/lib/Socket/business.js +258 -249
- package/lib/Socket/chats.d.ts +90 -87
- package/lib/Socket/chats.js +1095 -888
- package/lib/Socket/community.d.ts +131 -0
- package/lib/Socket/community.js +369 -0
- package/lib/Socket/groups.d.ts +50 -41
- package/lib/Socket/groups.js +10 -3
- package/lib/Socket/index.d.ts +5 -1
- package/lib/Socket/index.js +19 -5
- package/lib/Socket/messages-recv.d.ts +6 -2
- package/lib/Socket/messages-recv.js +31 -8
- package/lib/Socket/messages-send.d.ts +5 -1
- package/lib/Socket/messages-send.js +1293 -1351
- package/lib/Socket/newsletter.d.ts +142 -135
- package/lib/Socket/newsletter.js +274 -230
- package/lib/Socket/socket.d.ts +37 -35
- package/lib/Socket/usync.d.ts +31 -30
- package/lib/Socket/usync.js +74 -62
- package/lib/Types/Auth.d.ts +89 -72
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Call.d.ts +11 -10
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +85 -62
- package/lib/Types/Chat.js +4 -1
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +209 -191
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +12 -27
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +41 -39
- package/lib/Types/Label.js +24 -21
- package/lib/Types/LabelAssociation.d.ts +18 -12
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.d.ts +3 -2
- package/lib/Types/Message.js +7 -3
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +84 -67
- package/lib/Types/Newsletter.js +30 -23
- package/lib/Types/Product.d.ts +70 -56
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +46 -35
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +105 -101
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +37 -23
- package/lib/Types/State.js +13 -1
- package/lib/Types/USync.d.ts +21 -20
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +51 -42
- package/lib/Types/index.js +25 -19
- package/lib/Utils/auth-utils.d.ts +14 -11
- package/lib/Utils/auth-utils.js +189 -182
- package/lib/Utils/baileys-event-stream.d.ts +12 -10
- package/lib/Utils/baileys-event-stream.js +52 -46
- package/lib/Utils/business.d.ts +15 -8
- package/lib/Utils/business.js +229 -217
- package/lib/Utils/chat-utils.d.ts +22 -12
- package/lib/Utils/chat-utils.js +57 -27
- package/lib/Utils/crypto.d.ts +31 -15
- package/lib/Utils/crypto.js +136 -107
- package/lib/Utils/decode-wa-message.d.ts +34 -245
- package/lib/Utils/decode-wa-message.js +205 -217
- package/lib/Utils/event-buffer.d.ts +30 -26
- package/lib/Utils/event-buffer.js +519 -515
- package/lib/Utils/history.d.ts +2 -8
- package/lib/Utils/index.js +13 -9
- package/lib/Utils/link-preview.d.ts +16 -14
- package/lib/Utils/link-preview.js +100 -92
- package/lib/Utils/logger.d.ts +9 -7
- package/lib/Utils/logger.js +1 -1
- package/lib/Utils/lt-hash.d.ts +10 -8
- package/lib/Utils/lt-hash.js +49 -44
- package/lib/Utils/make-mutex.d.ts +4 -2
- package/lib/Utils/make-mutex.js +43 -39
- package/lib/Utils/messages-media.d.ts +75 -50
- package/lib/Utils/messages.d.ts +60 -35
- package/lib/Utils/messages.js +87 -8
- package/lib/Utils/noise-handler.d.ts +13 -12
- package/lib/Utils/noise-handler.js +143 -138
- package/lib/Utils/process-message.d.ts +32 -24
- package/lib/Utils/process-message.js +387 -367
- package/lib/Utils/signal.d.ts +24 -15
- package/lib/Utils/signal.js +143 -131
- package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
- package/lib/Utils/use-mongo-file-auth-state.js +72 -63
- package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
- package/lib/Utils/use-multi-file-auth-state.js +110 -102
- package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
- package/lib/Utils/use-single-file-auth-state.js +66 -61
- package/lib/Utils/validate-connection.d.ts +5 -2
- package/lib/Utils/validate-connection.js +7 -6
- package/lib/WABinary/constants.d.ts +24 -21
- package/lib/WABinary/constants.js +1302 -31
- package/lib/WABinary/decode.d.ts +4 -1
- package/lib/WABinary/decode.js +267 -234
- package/lib/WABinary/encode.d.ts +1 -0
- package/lib/WABinary/encode.js +248 -226
- package/lib/WABinary/generic-utils.d.ts +13 -1
- package/lib/WABinary/generic-utils.js +113 -96
- package/lib/WABinary/index.js +13 -9
- package/lib/WABinary/jid-utils.d.ts +23 -4
- package/lib/WABinary/jid-utils.js +58 -39
- package/lib/WABinary/types.d.ts +15 -11
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +14 -14
- package/lib/WAM/BinaryInfo.js +11 -8
- package/lib/WAM/constants.d.ts +34 -26
- package/lib/WAM/constants.js +15358 -15349
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +153 -144
- package/lib/WAM/index.js +13 -9
- package/lib/index.js +11 -11
- package/package.json +1 -66
- package/WASignalGroup/GroupProtocol.js +0 -1771
- package/WASignalGroup/ciphertext_message.js +0 -10
- package/WASignalGroup/group_cipher.js +0 -103
- package/WASignalGroup/group_session_builder.js +0 -39
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -17
- package/WASignalGroup/protobufs.js +0 -2
- package/WASignalGroup/queue_job.js +0 -64
- package/WASignalGroup/sender_chain_key.js +0 -38
- package/WASignalGroup/sender_key_distribution_message.js +0 -68
- package/WASignalGroup/sender_key_message.js +0 -79
- package/WASignalGroup/sender_key_name.js +0 -59
- package/WASignalGroup/sender_key_record.js +0 -47
- package/WASignalGroup/sender_key_state.js +0 -110
- package/WASignalGroup/sender_message_key.js +0 -30
package/lib/Utils/business.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
+
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
3
5
|
const boom_1 = require("@hapi/boom")
|
|
4
6
|
const crypto_1 = require("crypto")
|
|
5
7
|
const path_1 = require("path")
|
|
@@ -8,236 +10,246 @@ const fs_1 = require("fs")
|
|
|
8
10
|
const WABinary_1 = require("../WABinary")
|
|
9
11
|
const generics_1 = require("./generics")
|
|
10
12
|
const messages_media_1 = require("./messages-media")
|
|
13
|
+
|
|
11
14
|
const parseCatalogNode = (node) => {
|
|
12
|
-
const catalogNode = WABinary_1.getBinaryNodeChild(node, 'product_catalog')
|
|
13
|
-
const products = WABinary_1.getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
|
|
14
|
-
const paging = WABinary_1.getBinaryNodeChild(catalogNode, 'paging')
|
|
15
|
-
return {
|
|
16
|
-
products,
|
|
17
|
-
nextPageCursor: paging
|
|
18
|
-
? WABinary_1.getBinaryNodeChildString(paging, 'after')
|
|
19
|
-
: undefined
|
|
20
|
-
}
|
|
21
|
-
}
|
|
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')
|
|
18
|
+
return {
|
|
19
|
+
products,
|
|
20
|
+
nextPageCursor: paging
|
|
21
|
+
? WABinary_1.getBinaryNodeChildString(paging, 'after')
|
|
22
|
+
: undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
const parseCollectionsNode = (node) => {
|
|
23
|
-
const collectionsNode = WABinary_1.getBinaryNodeChild(node, 'collections')
|
|
24
|
-
const collections = WABinary_1.getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
|
|
25
|
-
const id = WABinary_1.getBinaryNodeChildString(collectionNode, 'id')
|
|
26
|
-
const name = WABinary_1.getBinaryNodeChildString(collectionNode, 'name')
|
|
27
|
-
const products = WABinary_1.getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
|
|
28
|
-
return {
|
|
29
|
-
id,
|
|
30
|
-
name,
|
|
31
|
-
products,
|
|
32
|
-
status: parseStatusInfo(collectionNode)
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
return {
|
|
36
|
-
collections
|
|
37
|
-
}
|
|
38
|
-
}
|
|
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)
|
|
32
|
+
return {
|
|
33
|
+
id,
|
|
34
|
+
name,
|
|
35
|
+
products,
|
|
36
|
+
status: parseStatusInfo(collectionNode)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
return {
|
|
40
|
+
collections
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
const parseOrderDetailsNode = (node) => {
|
|
40
|
-
const orderNode = WABinary_1.getBinaryNodeChild(node, 'order')
|
|
41
|
-
const products = WABinary_1.getBinaryNodeChildren(orderNode, 'product').map(productNode => {
|
|
42
|
-
const imageNode = WABinary_1.getBinaryNodeChild(productNode, 'image')
|
|
43
|
-
return {
|
|
44
|
-
id: WABinary_1.getBinaryNodeChildString(productNode, 'id'),
|
|
45
|
-
name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
|
|
46
|
-
imageUrl: WABinary_1.getBinaryNodeChildString(imageNode, 'url'),
|
|
47
|
-
price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
|
|
48
|
-
currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
|
|
49
|
-
quantity: +WABinary_1.getBinaryNodeChildString(productNode, 'quantity')
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
const priceNode = WABinary_1.getBinaryNodeChild(orderNode, 'price')
|
|
53
|
-
const orderDetails = {
|
|
54
|
-
price: {
|
|
55
|
-
total: +WABinary_1.getBinaryNodeChildString(priceNode, 'total'),
|
|
56
|
-
currency: WABinary_1.getBinaryNodeChildString(priceNode, 'currency'),
|
|
57
|
-
},
|
|
58
|
-
products
|
|
59
|
-
}
|
|
60
|
-
return orderDetails
|
|
61
|
-
}
|
|
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')
|
|
48
|
+
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')
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
const priceNode = WABinary_1.getBinaryNodeChild(orderNode, 'price')
|
|
58
|
+
const orderDetails = {
|
|
59
|
+
price: {
|
|
60
|
+
total: +WABinary_1.getBinaryNodeChildString(priceNode, 'total'),
|
|
61
|
+
currency: WABinary_1.getBinaryNodeChildString(priceNode, 'currency'),
|
|
62
|
+
},
|
|
63
|
+
products
|
|
64
|
+
}
|
|
65
|
+
return orderDetails
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
const toProductNode = (productId, product) => {
|
|
63
|
-
const attrs = {}
|
|
64
|
-
const content = []
|
|
65
|
-
if (typeof productId !== 'undefined') {
|
|
66
|
-
content.push({
|
|
67
|
-
tag: 'id',
|
|
68
|
-
attrs: {},
|
|
69
|
-
content: Buffer.from(productId)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
if (typeof product.name !== 'undefined') {
|
|
73
|
-
content.push({
|
|
74
|
-
tag: 'name',
|
|
75
|
-
attrs: {},
|
|
76
|
-
content: Buffer.from(product.name)
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
if (typeof product.description !== 'undefined') {
|
|
80
|
-
content.push({
|
|
81
|
-
tag: 'description',
|
|
82
|
-
attrs: {},
|
|
83
|
-
content: Buffer.from(product.description)
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
if (typeof product.retailerId !== 'undefined') {
|
|
87
|
-
content.push({
|
|
88
|
-
tag: 'retailer_id',
|
|
89
|
-
attrs: {},
|
|
90
|
-
content: Buffer.from(product.retailerId)
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
if (product.images.length) {
|
|
94
|
-
content.push({
|
|
95
|
-
tag: 'media',
|
|
96
|
-
attrs: {},
|
|
97
|
-
content: product.images.map(img => {
|
|
98
|
-
if (!('url' in img)) {
|
|
99
|
-
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
tag: 'image',
|
|
103
|
-
attrs: {},
|
|
104
|
-
content: [
|
|
105
|
-
{
|
|
106
|
-
tag: 'url',
|
|
107
|
-
attrs: {},
|
|
108
|
-
content: Buffer.from(img.url.toString())
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
if (typeof product.price !== 'undefined') {
|
|
116
|
-
content.push({
|
|
117
|
-
tag: 'price',
|
|
118
|
-
attrs: {},
|
|
119
|
-
content: Buffer.from(product.price.toString())
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
if (typeof product.currency !== 'undefined') {
|
|
123
|
-
content.push({
|
|
124
|
-
tag: 'currency',
|
|
125
|
-
attrs: {},
|
|
126
|
-
content: Buffer.from(product.currency)
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
if ('originCountryCode' in product) {
|
|
130
|
-
if (typeof product.originCountryCode === 'undefined') {
|
|
131
|
-
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
content.push({
|
|
135
|
-
tag: 'compliance_info',
|
|
136
|
-
attrs: {},
|
|
137
|
-
content: [
|
|
138
|
-
{
|
|
139
|
-
tag: 'country_code_origin',
|
|
140
|
-
attrs: {},
|
|
141
|
-
content: Buffer.from(product.originCountryCode)
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (typeof product.isHidden !== 'undefined') {
|
|
148
|
-
attrs['is_hidden'] = product.isHidden.toString()
|
|
149
|
-
}
|
|
150
|
-
const node = {
|
|
151
|
-
tag: 'product',
|
|
152
|
-
attrs,
|
|
153
|
-
content
|
|
154
|
-
}
|
|
155
|
-
return node
|
|
156
|
-
}
|
|
69
|
+
const attrs = {}
|
|
70
|
+
const content = []
|
|
71
|
+
if (typeof productId !== 'undefined') {
|
|
72
|
+
content.push({
|
|
73
|
+
tag: 'id',
|
|
74
|
+
attrs: {},
|
|
75
|
+
content: Buffer.from(productId)
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
if (typeof product.name !== 'undefined') {
|
|
79
|
+
content.push({
|
|
80
|
+
tag: 'name',
|
|
81
|
+
attrs: {},
|
|
82
|
+
content: Buffer.from(product.name)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
if (typeof product.description !== 'undefined') {
|
|
86
|
+
content.push({
|
|
87
|
+
tag: 'description',
|
|
88
|
+
attrs: {},
|
|
89
|
+
content: Buffer.from(product.description)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
if (typeof product.retailerId !== 'undefined') {
|
|
93
|
+
content.push({
|
|
94
|
+
tag: 'retailer_id',
|
|
95
|
+
attrs: {},
|
|
96
|
+
content: Buffer.from(product.retailerId)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
if (product.images.length) {
|
|
100
|
+
content.push({
|
|
101
|
+
tag: 'media',
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: product.images.map(img => {
|
|
104
|
+
if (!('url' in img)) {
|
|
105
|
+
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
tag: 'image',
|
|
109
|
+
attrs: {},
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
tag: 'url',
|
|
113
|
+
attrs: {},
|
|
114
|
+
content: Buffer.from(img.url.toString())
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
if (typeof product.price !== 'undefined') {
|
|
122
|
+
content.push({
|
|
123
|
+
tag: 'price',
|
|
124
|
+
attrs: {},
|
|
125
|
+
content: Buffer.from(product.price.toString())
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
if (typeof product.currency !== 'undefined') {
|
|
129
|
+
content.push({
|
|
130
|
+
tag: 'currency',
|
|
131
|
+
attrs: {},
|
|
132
|
+
content: Buffer.from(product.currency)
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
if ('originCountryCode' in product) {
|
|
136
|
+
if (typeof product.originCountryCode === 'undefined') {
|
|
137
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
content.push({
|
|
141
|
+
tag: 'compliance_info',
|
|
142
|
+
attrs: {},
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
tag: 'country_code_origin',
|
|
146
|
+
attrs: {},
|
|
147
|
+
content: Buffer.from(product.originCountryCode)
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (typeof product.isHidden !== 'undefined') {
|
|
154
|
+
attrs['is_hidden'] = product.isHidden.toString()
|
|
155
|
+
}
|
|
156
|
+
const node = {
|
|
157
|
+
tag: 'product',
|
|
158
|
+
attrs,
|
|
159
|
+
content
|
|
160
|
+
}
|
|
161
|
+
return node
|
|
162
|
+
}
|
|
163
|
+
|
|
157
164
|
const parseProductNode = (productNode) => {
|
|
158
|
-
const isHidden = productNode.attrs.is_hidden === 'true'
|
|
159
|
-
const id = WABinary_1.getBinaryNodeChildString(productNode, 'id')
|
|
160
|
-
const mediaNode = WABinary_1.getBinaryNodeChild(productNode, 'media')
|
|
161
|
-
const statusInfoNode = WABinary_1.getBinaryNodeChild(productNode, 'status_info')
|
|
162
|
-
const product = {
|
|
163
|
-
id,
|
|
164
|
-
imageUrls: parseImageUrls(mediaNode),
|
|
165
|
-
reviewStatus: {
|
|
166
|
-
whatsapp: WABinary_1.getBinaryNodeChildString(statusInfoNode, 'status'),
|
|
167
|
-
},
|
|
168
|
-
availability: 'in stock',
|
|
169
|
-
name: WABinary_1.getBinaryNodeChildString(productNode, 'name'),
|
|
170
|
-
retailerId: WABinary_1.getBinaryNodeChildString(productNode, 'retailer_id'),
|
|
171
|
-
url: WABinary_1.getBinaryNodeChildString(productNode, 'url'),
|
|
172
|
-
description: WABinary_1.getBinaryNodeChildString(productNode, 'description'),
|
|
173
|
-
price: +WABinary_1.getBinaryNodeChildString(productNode, 'price'),
|
|
174
|
-
currency: WABinary_1.getBinaryNodeChildString(productNode, 'currency'),
|
|
175
|
-
isHidden,
|
|
176
|
-
}
|
|
177
|
-
return product
|
|
178
|
-
}
|
|
165
|
+
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')
|
|
169
|
+
const product = {
|
|
170
|
+
id,
|
|
171
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
172
|
+
reviewStatus: {
|
|
173
|
+
whatsapp: WABinary_1.getBinaryNodeChildString(statusInfoNode, 'status'),
|
|
174
|
+
},
|
|
175
|
+
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,
|
|
183
|
+
}
|
|
184
|
+
return product
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
/**
|
|
180
|
-
* Uploads images not already uploaded to WA's servers
|
|
181
|
-
*/
|
|
188
|
+
* Uploads images not already uploaded to WA's servers
|
|
189
|
+
*/
|
|
182
190
|
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
183
|
-
product = {
|
|
184
|
-
...product,
|
|
185
|
-
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
186
|
-
}
|
|
187
|
-
return product
|
|
191
|
+
product = {
|
|
192
|
+
...product,
|
|
193
|
+
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
194
|
+
}
|
|
195
|
+
return product
|
|
188
196
|
}
|
|
197
|
+
|
|
189
198
|
/**
|
|
190
|
-
* Uploads images not already uploaded to WA's servers
|
|
191
|
-
*/
|
|
199
|
+
* Uploads images not already uploaded to WA's servers
|
|
200
|
+
*/
|
|
192
201
|
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
193
|
-
const results = await Promise.all(images.map(async (img) => {
|
|
194
|
-
if ('url' in img) {
|
|
195
|
-
const url = img.url.toString()
|
|
196
|
-
if (url.includes('.whatsapp.net')) {
|
|
197
|
-
return { url }
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const { stream } = await messages_media_1.getStream(img)
|
|
201
|
-
const hasher = crypto_1.createHash('sha256')
|
|
202
|
-
const filePath = path_1.join(os_1.tmpdir(), 'img' + generics_1.generateMessageID())
|
|
203
|
-
const encFileWriteStream = fs_1.createWriteStream(filePath)
|
|
204
|
-
for await (const block of stream) {
|
|
205
|
-
hasher.update(block)
|
|
206
|
-
encFileWriteStream.write(block)
|
|
207
|
-
}
|
|
208
|
-
const sha = hasher.digest('base64')
|
|
209
|
-
const { directPath } = await waUploadToServer(filePath, {
|
|
210
|
-
mediaType: 'product-catalog-image',
|
|
211
|
-
fileEncSha256B64: sha,
|
|
212
|
-
timeoutMs
|
|
213
|
-
})
|
|
214
|
-
await fs_1.promises
|
|
215
|
-
.unlink(filePath)
|
|
216
|
-
.catch(err => console.log('Error deleting temp file ', err))
|
|
217
|
-
return { url: messages_media_1.getUrlFromDirectPath(directPath) }
|
|
218
|
-
}))
|
|
219
|
-
return results
|
|
220
|
-
}
|
|
202
|
+
const results = await Promise.all(images.map(async (img) => {
|
|
203
|
+
if ('url' in img) {
|
|
204
|
+
const url = img.url.toString()
|
|
205
|
+
if (url.includes('.whatsapp.net')) {
|
|
206
|
+
return { url }
|
|
207
|
+
}
|
|
208
|
+
}
|
|
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)
|
|
213
|
+
for await (const block of stream) {
|
|
214
|
+
hasher.update(block)
|
|
215
|
+
encFileWriteStream.write(block)
|
|
216
|
+
}
|
|
217
|
+
const sha = hasher.digest('base64')
|
|
218
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
219
|
+
mediaType: 'product-catalog-image',
|
|
220
|
+
fileEncSha256B64: sha,
|
|
221
|
+
timeoutMs
|
|
222
|
+
})
|
|
223
|
+
await fs_1.promises
|
|
224
|
+
.unlink(filePath)
|
|
225
|
+
.catch(err => console.log('Error deleting temp file ', err))
|
|
226
|
+
return { url: messages_media_1.getUrlFromDirectPath(directPath) }
|
|
227
|
+
}))
|
|
228
|
+
return results
|
|
229
|
+
}
|
|
230
|
+
|
|
221
231
|
const parseImageUrls = (mediaNode) => {
|
|
222
|
-
const imgNode = WABinary_1.getBinaryNodeChild(mediaNode, 'image')
|
|
223
|
-
return {
|
|
224
|
-
requested: WABinary_1.getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
225
|
-
original: WABinary_1.getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
226
|
-
}
|
|
232
|
+
const imgNode = WABinary_1.getBinaryNodeChild(mediaNode, 'image')
|
|
233
|
+
return {
|
|
234
|
+
requested: WABinary_1.getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
235
|
+
original: WABinary_1.getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
236
|
+
}
|
|
227
237
|
}
|
|
238
|
+
|
|
228
239
|
const parseStatusInfo = (mediaNode) => {
|
|
229
|
-
const node = WABinary_1.getBinaryNodeChild(mediaNode, 'status_info')
|
|
230
|
-
return {
|
|
231
|
-
status: WABinary_1.getBinaryNodeChildString(node, 'status'),
|
|
232
|
-
canAppeal: WABinary_1.getBinaryNodeChildString(node, 'can_appeal') === 'true',
|
|
233
|
-
}
|
|
240
|
+
const node = WABinary_1.getBinaryNodeChild(mediaNode, 'status_info')
|
|
241
|
+
return {
|
|
242
|
+
status: WABinary_1.getBinaryNodeChildString(node, 'status'),
|
|
243
|
+
canAppeal: WABinary_1.getBinaryNodeChildString(node, 'can_appeal') === 'true',
|
|
244
|
+
}
|
|
234
245
|
}
|
|
246
|
+
|
|
235
247
|
module.exports = {
|
|
236
|
-
parseCatalogNode,
|
|
237
|
-
parseCollectionsNode,
|
|
238
|
-
parseOrderDetailsNode,
|
|
239
|
-
toProductNode,
|
|
240
|
-
parseProductNode,
|
|
241
|
-
uploadingNecessaryImagesOfProduct,
|
|
242
|
-
uploadingNecessaryImages
|
|
248
|
+
parseCatalogNode,
|
|
249
|
+
parseCollectionsNode,
|
|
250
|
+
parseOrderDetailsNode,
|
|
251
|
+
toProductNode,
|
|
252
|
+
parseProductNode,
|
|
253
|
+
uploadingNecessaryImagesOfProduct,
|
|
254
|
+
uploadingNecessaryImages
|
|
243
255
|
}
|
|
@@ -3,7 +3,6 @@ import { proto } from '../../WAProto'
|
|
|
3
3
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
|
4
4
|
import { BinaryNode } from '../WABinary'
|
|
5
5
|
import { ILogger } from './logger'
|
|
6
|
-
import { LabelAssociationType } from '../Types/LabelAssociation'
|
|
7
6
|
|
|
8
7
|
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>
|
|
9
8
|
|
|
@@ -37,7 +36,27 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
|
37
36
|
}>
|
|
38
37
|
|
|
39
38
|
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
40
|
-
|
|
39
|
+
critical_block: {
|
|
40
|
+
patches: proto.ISyncdPatch[]
|
|
41
|
+
hasMorePatches: boolean
|
|
42
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
43
|
+
}
|
|
44
|
+
critical_unblock_low: {
|
|
45
|
+
patches: proto.ISyncdPatch[]
|
|
46
|
+
hasMorePatches: boolean
|
|
47
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
48
|
+
}
|
|
49
|
+
regular_high: {
|
|
50
|
+
patches: proto.ISyncdPatch[]
|
|
51
|
+
hasMorePatches: boolean
|
|
52
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
53
|
+
}
|
|
54
|
+
regular_low: {
|
|
55
|
+
patches: proto.ISyncdPatch[]
|
|
56
|
+
hasMorePatches: boolean
|
|
57
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
58
|
+
}
|
|
59
|
+
regular: {
|
|
41
60
|
patches: proto.ISyncdPatch[]
|
|
42
61
|
hasMorePatches: boolean
|
|
43
62
|
snapshot?: proto.ISyncdSnapshot | undefined
|
|
@@ -46,7 +65,6 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
|
46
65
|
|
|
47
66
|
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>
|
|
48
67
|
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>
|
|
49
|
-
|
|
50
68
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
51
69
|
state: LTHashState
|
|
52
70
|
mutationMap: ChatMutationMap
|
|
@@ -57,15 +75,7 @@ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatc
|
|
|
57
75
|
mutationMap: ChatMutationMap
|
|
58
76
|
}>
|
|
59
77
|
|
|
60
|
-
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate
|
|
61
|
-
syncAction: {
|
|
62
|
-
timestamp?: number
|
|
63
|
-
contactAction?: {
|
|
64
|
-
fullName?: string
|
|
65
|
-
lidJid?: string
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
78
|
+
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate
|
|
69
79
|
|
|
70
80
|
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void
|
|
71
81
|
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -324,6 +324,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
324
324
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber
|
|
325
325
|
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
326
326
|
? mutation => {
|
|
327
|
+
var _a
|
|
327
328
|
const index = mutation.syncAction.index?.toString()
|
|
328
329
|
mutationMap[index] = mutation
|
|
329
330
|
}
|
|
@@ -439,7 +440,9 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
439
440
|
else if ('clear' in mod) {
|
|
440
441
|
patch = {
|
|
441
442
|
syncAction: {
|
|
442
|
-
clearChatAction: {
|
|
443
|
+
clearChatAction: {
|
|
444
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
445
|
+
}
|
|
443
446
|
},
|
|
444
447
|
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
445
448
|
type: 'regular_high',
|
|
@@ -461,19 +464,27 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
461
464
|
}
|
|
462
465
|
}
|
|
463
466
|
else if ('contact' in mod) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
},
|
|
471
|
-
index: ['contact', jid],
|
|
472
|
-
type: 'critical_unblock_low',
|
|
467
|
+
patch = {
|
|
468
|
+
syncAction: {
|
|
469
|
+
contactAction: mod?.contact || {}
|
|
470
|
+
},
|
|
471
|
+
index: ['contact', jid],
|
|
472
|
+
type: 'critical_unblock_low',
|
|
473
473
|
apiVersion: 2,
|
|
474
474
|
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
+
else if ('disableLinkPreviews' in mod) {
|
|
478
|
+
patch = {
|
|
479
|
+
syncAction: {
|
|
480
|
+
privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
|
|
481
|
+
},
|
|
482
|
+
index: ['setting_disableLinkPreviews'],
|
|
483
|
+
type: 'regular',
|
|
484
|
+
apiVersion: 8,
|
|
485
|
+
operation: OP.SET
|
|
486
|
+
}
|
|
487
|
+
}
|
|
477
488
|
else if ('star' in mod) {
|
|
478
489
|
const key = mod.star.messages[0]
|
|
479
490
|
patch = {
|
|
@@ -620,11 +631,27 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
620
631
|
])
|
|
621
632
|
}
|
|
622
633
|
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
634
|
+
// okay so we've to do some annoying computation here
|
|
635
|
+
// when we're initially syncing the app state
|
|
636
|
+
// there are a few cases we need to handle
|
|
637
|
+
// 1. if the account unarchiveChats setting is true
|
|
638
|
+
// a. if the chat is archived, and no further messages have been received -- simple, keep archived
|
|
639
|
+
// b. if the chat was archived, and the user received messages from the other person afterwards
|
|
640
|
+
// then the chat should be marked unarchved --
|
|
641
|
+
// we compare the timestamp of latest message from the other person to determine this
|
|
642
|
+
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
643
|
+
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
623
644
|
const archiveAction = action?.archiveChatAction
|
|
624
645
|
const isArchived = archiveAction
|
|
625
646
|
? archiveAction.archived
|
|
626
647
|
: type === 'archive'
|
|
648
|
+
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
649
|
+
// // this only applies for the initial sync
|
|
650
|
+
// if(isInitialSync && !isArchived) {
|
|
651
|
+
// isArchived = false
|
|
652
|
+
// }
|
|
627
653
|
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange
|
|
654
|
+
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
628
655
|
ev.emit('chats.update', [{
|
|
629
656
|
id,
|
|
630
657
|
archived: isArchived,
|
|
@@ -633,6 +660,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
633
660
|
}
|
|
634
661
|
else if (action?.markChatAsReadAction) {
|
|
635
662
|
const markReadAction = action.markChatAsReadAction
|
|
663
|
+
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
664
|
+
// because the chat is read by default
|
|
665
|
+
// this only applies for the initial sync
|
|
636
666
|
const isNullUpdate = isInitialSync && markReadAction.read
|
|
637
667
|
ev.emit('chats.update', [{
|
|
638
668
|
id,
|
|
@@ -652,12 +682,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
652
682
|
})
|
|
653
683
|
}
|
|
654
684
|
else if (action?.contactAction) {
|
|
655
|
-
|
|
656
|
-
id
|
|
657
|
-
name: action.contactAction.fullName,
|
|
658
|
-
lid: action.contactAction.lidJid || undefined,
|
|
685
|
+
ev.emit('contacts.upsert', [{
|
|
686
|
+
id,
|
|
687
|
+
name: action.contactAction.fullName,
|
|
688
|
+
lid: action.contactAction.lidJid || undefined,
|
|
659
689
|
jid: WABinary_1.isJidUser(id) ? id : undefined
|
|
660
|
-
}])
|
|
690
|
+
}])
|
|
661
691
|
}
|
|
662
692
|
else if (action?.pushNameSetting) {
|
|
663
693
|
const name = action?.pushNameSetting?.name
|
|
@@ -747,16 +777,16 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
747
777
|
}
|
|
748
778
|
|
|
749
779
|
module.exports = {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
780
|
+
mutationKeys,
|
|
781
|
+
newLTHashState,
|
|
782
|
+
encodeSyncdPatch,
|
|
783
|
+
decodeSyncdMutations,
|
|
784
|
+
decodeSyncdPatch,
|
|
785
|
+
extractSyncdPatches,
|
|
786
|
+
downloadExternalBlob,
|
|
787
|
+
downloadExternalPatch,
|
|
788
|
+
decodeSyncdSnapshot,
|
|
789
|
+
decodePatches,
|
|
790
|
+
chatModificationToAppPatch,
|
|
791
|
+
processSyncAction
|
|
762
792
|
}
|