@pontalabs/baileys 1.0.6 → 1.0.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/LICENSE +1 -1
- package/README.md +839 -267
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.d.ts +55 -14017
- package/WAProto/index.js +29 -97689
- package/lib/Defaults/index.d.ts +74 -72
- package/lib/Defaults/index.js +108 -94
- package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
- package/lib/Signal/Group/ciphertext-message.js +16 -9
- package/lib/Signal/Group/group-session-builder.d.ts +13 -11
- package/lib/Signal/Group/group-session-builder.js +61 -19
- package/lib/Signal/Group/group_cipher.d.ts +16 -14
- package/lib/Signal/Group/group_cipher.js +70 -41
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +61 -12
- package/lib/Signal/Group/keyhelper.d.ts +14 -9
- package/lib/Signal/Group/keyhelper.js +58 -10
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.js +34 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.js +45 -38
- package/lib/Signal/Group/sender-key-name.d.ts +15 -14
- package/lib/Signal/Group/sender-key-name.js +31 -20
- package/lib/Signal/Group/sender-key-record.d.ts +25 -24
- package/lib/Signal/Group/sender-key-record.js +35 -18
- package/lib/Signal/Group/sender-key-state.d.ts +34 -29
- package/lib/Signal/Group/sender-key-state.js +100 -37
- package/lib/Signal/Group/sender-message-key.d.ts +10 -11
- package/lib/Signal/Group/sender-message-key.js +22 -15
- package/lib/Signal/libsignal.d.ts +8 -5
- package/lib/Signal/libsignal.js +142 -288
- package/lib/Signal/lid-mapping.d.ts +28 -23
- package/lib/Signal/lid-mapping.js +184 -277
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +37 -29
- package/lib/Socket/business.d.ts +178 -208
- package/lib/Socket/business.js +127 -91
- package/lib/Socket/chats.d.ts +93 -120
- package/lib/Socket/chats.js +652 -727
- package/lib/Socket/community.js +10 -2
- package/lib/Socket/groups.d.ts +111 -143
- package/lib/Socket/groups.js +186 -165
- package/lib/Socket/index.d.ts +183 -252
- package/lib/Socket/index.js +18 -38
- package/lib/Socket/messages-recv.d.ts +167 -196
- package/lib/Socket/messages-recv.js +1567 -1443
- package/lib/Socket/messages-send.d.ts +158 -192
- package/lib/Socket/messages-send.js +1208 -1102
- package/lib/Socket/newsletter.d.ts +138 -163
- package/lib/Socket/newsletter.js +249 -153
- package/lib/Socket/socket.d.ts +36 -50
- package/lib/Socket/socket.js +820 -749
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +24 -4
- package/lib/Store/make-in-memory-store.d.ts +104 -44
- package/lib/Store/make-in-memory-store.js +213 -199
- package/lib/Store/make-ordered-dictionary.d.ts +12 -13
- package/lib/Store/make-ordered-dictionary.js +45 -38
- package/lib/Store/object-repository.d.ts +10 -11
- package/lib/Store/object-repository.js +16 -9
- package/lib/Types/Auth.d.ts +97 -93
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.d.ts +13 -14
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +97 -78
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -12
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +176 -206
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -53
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +412 -248
- package/lib/Types/Message.js +19 -17
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +82 -71
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +81 -76
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -75
- package/lib/Types/State.js +14 -56
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +62 -47
- package/lib/Types/index.js +50 -26
- package/lib/Utils/auth-utils.d.ts +10 -13
- package/lib/Utils/auth-utils.js +472 -213
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +70 -88
- package/lib/Utils/chat-utils.js +403 -466
- package/lib/Utils/crypto.d.ts +46 -27
- package/lib/Utils/crypto.js +188 -117
- package/lib/Utils/decode-wa-message.d.ts +45 -58
- package/lib/Utils/decode-wa-message.js +311 -212
- package/lib/Utils/event-buffer.d.ts +17 -14
- package/lib/Utils/event-buffer.js +296 -321
- package/lib/Utils/generics.d.ts +92 -66
- package/lib/Utils/generics.js +436 -270
- package/lib/Utils/history.d.ts +23 -24
- package/lib/Utils/history.js +76 -106
- package/lib/Utils/index.d.ts +21 -24
- package/lib/Utils/index.js +41 -24
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +14 -8
- package/lib/Utils/lt-hash.js +53 -3
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -28
- package/lib/Utils/message-retry-manager.d.ts +88 -115
- package/lib/Utils/message-retry-manager.js +160 -265
- package/lib/Utils/messages-media.d.ts +107 -105
- package/lib/Utils/messages-media.js +619 -548
- package/lib/Utils/messages.d.ts +66 -52
- package/lib/Utils/messages.js +1558 -1730
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +130 -176
- package/lib/Utils/process-message.d.ts +32 -43
- package/lib/Utils/process-message.js +282 -484
- package/lib/Utils/rich-message-utils.js +724 -1220
- package/lib/Utils/signal.d.ts +32 -37
- package/lib/Utils/signal.js +105 -140
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.js +120 -70
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
- package/lib/Utils/use-single-file-auth-state.js +66 -92
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +113 -128
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1451
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -163
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +105 -177
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +54 -41
- package/lib/WABinary/jid-utils.js +152 -83
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +109 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.js +26 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -27
- package/lib/WAUSync/USyncQuery.js +62 -68
- package/lib/WAUSync/USyncUser.d.ts +10 -15
- package/lib/WAUSync/USyncUser.js +19 -20
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +12 -11
- package/lib/index.js +39 -12
- package/package.json +43 -87
- package/engine-requirements.js +0 -10
package/lib/Utils/business.d.ts
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types'
|
|
2
|
+
import { BinaryNode } from '../WABinary'
|
|
3
|
+
|
|
3
4
|
export declare const parseCatalogNode: (node: BinaryNode) => {
|
|
4
|
-
products: Product[]
|
|
5
|
-
nextPageCursor: string | undefined
|
|
6
|
-
}
|
|
5
|
+
products: Product[]
|
|
6
|
+
nextPageCursor: string | undefined
|
|
7
|
+
}
|
|
8
|
+
|
|
7
9
|
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
|
8
|
-
collections: CatalogCollection[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
10
|
+
collections: CatalogCollection[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails
|
|
14
|
+
|
|
15
|
+
export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode
|
|
16
|
+
|
|
17
|
+
export declare const parseProductNode: (productNode: BinaryNode) => Product
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* Uploads images not already uploaded to WA's servers
|
|
15
21
|
*/
|
|
16
|
-
export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T
|
|
22
|
+
export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>
|
|
23
|
+
|
|
17
24
|
/**
|
|
18
25
|
* Uploads images not already uploaded to WA's servers
|
|
19
26
|
*/
|
|
20
27
|
export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
|
|
21
|
-
url: string
|
|
22
|
-
}[]
|
|
23
|
-
//# sourceMappingURL=business.d.ts.map
|
|
28
|
+
url: string
|
|
29
|
+
}[]>
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,90 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const boom_1 = require("@hapi/boom")
|
|
6
|
+
const crypto_1 = require("crypto")
|
|
7
|
+
const path_1 = require("path")
|
|
8
|
+
const os_1 = require("os")
|
|
9
|
+
const fs_1 = require("fs")
|
|
10
|
+
const WABinary_1 = require("../WABinary")
|
|
11
|
+
const generics_1 = require("./generics")
|
|
12
|
+
const messages_media_1 = require("./messages-media")
|
|
13
|
+
|
|
14
|
+
const parseCatalogNode = (node) => {
|
|
15
|
+
const catalogNode = WABinary_1.getBinaryNodeChild(node, 'product_catalog')
|
|
16
|
+
const products = WABinary_1.getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
|
|
17
|
+
const paging = WABinary_1.getBinaryNodeChild(catalogNode, 'paging')
|
|
13
18
|
return {
|
|
14
19
|
products,
|
|
15
|
-
nextPageCursor: paging
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
nextPageCursor: paging
|
|
21
|
+
? WABinary_1.getBinaryNodeChildString(paging, 'after')
|
|
22
|
+
: undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parseCollectionsNode = (node) => {
|
|
27
|
+
const collectionsNode = WABinary_1.getBinaryNodeChild(node, 'collections')
|
|
28
|
+
const collections = WABinary_1.getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
|
|
29
|
+
const id = WABinary_1.getBinaryNodeChildString(collectionNode, 'id')
|
|
30
|
+
const name = WABinary_1.getBinaryNodeChildString(collectionNode, 'name')
|
|
31
|
+
const products = WABinary_1.getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
|
|
24
32
|
return {
|
|
25
33
|
id,
|
|
26
34
|
name,
|
|
27
35
|
products,
|
|
28
36
|
status: parseStatusInfo(collectionNode)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
37
|
+
}
|
|
38
|
+
})
|
|
31
39
|
return {
|
|
32
40
|
collections
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parseOrderDetailsNode = (node) => {
|
|
45
|
+
const orderNode = WABinary_1.getBinaryNodeChild(node, 'order')
|
|
46
|
+
const products = WABinary_1.getBinaryNodeChildren(orderNode, 'product').map(productNode => {
|
|
47
|
+
const imageNode = WABinary_1.getBinaryNodeChild(productNode, 'image')
|
|
39
48
|
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
|
+
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')
|
|
49
58
|
const orderDetails = {
|
|
50
59
|
price: {
|
|
51
|
-
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
-
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
60
|
+
total: +WABinary_1.getBinaryNodeChildString(priceNode, 'total'),
|
|
61
|
+
currency: WABinary_1.getBinaryNodeChildString(priceNode, 'currency'),
|
|
53
62
|
},
|
|
54
63
|
products
|
|
55
|
-
}
|
|
56
|
-
return orderDetails
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
64
|
+
}
|
|
65
|
+
return orderDetails
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const toProductNode = (productId, product) => {
|
|
69
|
+
const attrs = {}
|
|
70
|
+
const content = []
|
|
61
71
|
if (typeof productId !== 'undefined') {
|
|
62
72
|
content.push({
|
|
63
73
|
tag: 'id',
|
|
64
74
|
attrs: {},
|
|
65
75
|
content: Buffer.from(productId)
|
|
66
|
-
})
|
|
76
|
+
})
|
|
67
77
|
}
|
|
68
78
|
if (typeof product.name !== 'undefined') {
|
|
69
79
|
content.push({
|
|
70
80
|
tag: 'name',
|
|
71
81
|
attrs: {},
|
|
72
82
|
content: Buffer.from(product.name)
|
|
73
|
-
})
|
|
83
|
+
})
|
|
74
84
|
}
|
|
75
85
|
if (typeof product.description !== 'undefined') {
|
|
76
86
|
content.push({
|
|
77
87
|
tag: 'description',
|
|
78
88
|
attrs: {},
|
|
79
89
|
content: Buffer.from(product.description)
|
|
80
|
-
})
|
|
90
|
+
})
|
|
81
91
|
}
|
|
82
92
|
if (typeof product.retailerId !== 'undefined') {
|
|
83
93
|
content.push({
|
|
84
94
|
tag: 'retailer_id',
|
|
85
95
|
attrs: {},
|
|
86
96
|
content: Buffer.from(product.retailerId)
|
|
87
|
-
})
|
|
97
|
+
})
|
|
88
98
|
}
|
|
89
99
|
if (product.images.length) {
|
|
90
100
|
content.push({
|
|
@@ -92,7 +102,7 @@ export const toProductNode = (productId, product) => {
|
|
|
92
102
|
attrs: {},
|
|
93
103
|
content: product.images.map(img => {
|
|
94
104
|
if (!('url' in img)) {
|
|
95
|
-
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
105
|
+
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
96
106
|
}
|
|
97
107
|
return {
|
|
98
108
|
tag: 'image',
|
|
@@ -104,27 +114,27 @@ export const toProductNode = (productId, product) => {
|
|
|
104
114
|
content: Buffer.from(img.url.toString())
|
|
105
115
|
}
|
|
106
116
|
]
|
|
107
|
-
}
|
|
117
|
+
}
|
|
108
118
|
})
|
|
109
|
-
})
|
|
119
|
+
})
|
|
110
120
|
}
|
|
111
121
|
if (typeof product.price !== 'undefined') {
|
|
112
122
|
content.push({
|
|
113
123
|
tag: 'price',
|
|
114
124
|
attrs: {},
|
|
115
125
|
content: Buffer.from(product.price.toString())
|
|
116
|
-
})
|
|
126
|
+
})
|
|
117
127
|
}
|
|
118
128
|
if (typeof product.currency !== 'undefined') {
|
|
119
129
|
content.push({
|
|
120
130
|
tag: 'currency',
|
|
121
131
|
attrs: {},
|
|
122
132
|
content: Buffer.from(product.currency)
|
|
123
|
-
})
|
|
133
|
+
})
|
|
124
134
|
}
|
|
125
135
|
if ('originCountryCode' in product) {
|
|
126
136
|
if (typeof product.originCountryCode === 'undefined') {
|
|
127
|
-
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
137
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
128
138
|
}
|
|
129
139
|
else {
|
|
130
140
|
content.push({
|
|
@@ -137,95 +147,109 @@ export const toProductNode = (productId, product) => {
|
|
|
137
147
|
content: Buffer.from(product.originCountryCode)
|
|
138
148
|
}
|
|
139
149
|
]
|
|
140
|
-
})
|
|
150
|
+
})
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
153
|
if (typeof product.isHidden !== 'undefined') {
|
|
144
|
-
attrs['is_hidden'] = product.isHidden.toString()
|
|
154
|
+
attrs['is_hidden'] = product.isHidden.toString()
|
|
145
155
|
}
|
|
146
156
|
const node = {
|
|
147
157
|
tag: 'product',
|
|
148
158
|
attrs,
|
|
149
159
|
content
|
|
150
|
-
}
|
|
151
|
-
return node
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
160
|
+
}
|
|
161
|
+
return node
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const parseProductNode = (productNode) => {
|
|
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')
|
|
158
169
|
const product = {
|
|
159
170
|
id,
|
|
160
171
|
imageUrls: parseImageUrls(mediaNode),
|
|
161
172
|
reviewStatus: {
|
|
162
|
-
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
173
|
+
whatsapp: WABinary_1.getBinaryNodeChildString(statusInfoNode, 'status'),
|
|
163
174
|
},
|
|
164
175
|
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
|
-
}
|
|
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
|
+
|
|
175
187
|
/**
|
|
176
188
|
* Uploads images not already uploaded to WA's servers
|
|
177
189
|
*/
|
|
178
|
-
|
|
190
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
179
191
|
product = {
|
|
180
192
|
...product,
|
|
181
|
-
images: product.images
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
return product;
|
|
193
|
+
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
194
|
+
}
|
|
195
|
+
return product
|
|
186
196
|
}
|
|
197
|
+
|
|
187
198
|
/**
|
|
188
199
|
* Uploads images not already uploaded to WA's servers
|
|
189
200
|
*/
|
|
190
|
-
|
|
201
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
191
202
|
const results = await Promise.all(images.map(async (img) => {
|
|
192
203
|
if ('url' in img) {
|
|
193
|
-
const url = img.url.toString()
|
|
204
|
+
const url = img.url.toString()
|
|
194
205
|
if (url.includes('.whatsapp.net')) {
|
|
195
|
-
return { url }
|
|
206
|
+
return { url }
|
|
196
207
|
}
|
|
197
208
|
}
|
|
198
|
-
const { stream } = await getStream(img)
|
|
199
|
-
const hasher = createHash('sha256')
|
|
200
|
-
const filePath = join(tmpdir(), 'img' +
|
|
201
|
-
const encFileWriteStream = createWriteStream(filePath)
|
|
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)
|
|
202
213
|
for await (const block of stream) {
|
|
203
|
-
hasher.update(block)
|
|
204
|
-
encFileWriteStream.write(block)
|
|
214
|
+
hasher.update(block)
|
|
215
|
+
encFileWriteStream.write(block)
|
|
205
216
|
}
|
|
206
|
-
const sha = hasher.digest('base64')
|
|
217
|
+
const sha = hasher.digest('base64')
|
|
207
218
|
const { directPath } = await waUploadToServer(filePath, {
|
|
208
219
|
mediaType: 'product-catalog-image',
|
|
209
220
|
fileEncSha256B64: sha,
|
|
210
221
|
timeoutMs
|
|
211
|
-
})
|
|
212
|
-
await
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
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
|
+
|
|
217
231
|
const parseImageUrls = (mediaNode) => {
|
|
218
|
-
const imgNode = getBinaryNodeChild(mediaNode, 'image')
|
|
232
|
+
const imgNode = WABinary_1.getBinaryNodeChild(mediaNode, 'image')
|
|
219
233
|
return {
|
|
220
|
-
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
221
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
222
|
-
}
|
|
223
|
-
}
|
|
234
|
+
requested: WABinary_1.getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
235
|
+
original: WABinary_1.getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
224
239
|
const parseStatusInfo = (mediaNode) => {
|
|
225
|
-
const node = getBinaryNodeChild(mediaNode, 'status_info')
|
|
240
|
+
const node = WABinary_1.getBinaryNodeChild(mediaNode, 'status_info')
|
|
226
241
|
return {
|
|
227
|
-
status: getBinaryNodeChildString(node, 'status'),
|
|
228
|
-
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
242
|
+
status: WABinary_1.getBinaryNodeChildString(node, 'status'),
|
|
243
|
+
canAppeal: WABinary_1.getBinaryNodeChildString(node, 'can_appeal') === 'true',
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
module.exports = {
|
|
248
|
+
parseCatalogNode,
|
|
249
|
+
parseCollectionsNode,
|
|
250
|
+
parseOrderDetailsNode,
|
|
251
|
+
toProductNode,
|
|
252
|
+
parseProductNode,
|
|
253
|
+
uploadingNecessaryImagesOfProduct,
|
|
254
|
+
uploadingNecessaryImages
|
|
255
|
+
}
|
|
@@ -1,100 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { proto } from '../../WAProto'
|
|
3
|
+
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
|
4
|
+
import { BinaryNode } from '../WABinary'
|
|
5
|
+
import { ILogger } from './logger'
|
|
6
|
+
|
|
7
|
+
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>
|
|
8
|
+
|
|
6
9
|
export type ChatMutationMap = {
|
|
7
|
-
[index: string]: ChatMutation
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
operation: proto.SyncdMutation.SyncdOperation;
|
|
13
|
-
};
|
|
14
|
-
export declare const makeLtHashGenerator: ({ indexValueMap, hash }: Pick<LTHashState, "hash" | "indexValueMap">) => {
|
|
15
|
-
mix: ({ indexMac, valueMac, operation }: Mac) => void;
|
|
16
|
-
finish: () => {
|
|
17
|
-
hash: Buffer<ArrayBuffer>;
|
|
18
|
-
indexValueMap: {
|
|
19
|
-
[indexMacBase64: string]: {
|
|
20
|
-
valueMac: Uint8Array | Buffer;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare const newLTHashState: () => LTHashState;
|
|
26
|
-
export declare const ensureLTHashStateVersion: (state: LTHashState) => LTHashState;
|
|
27
|
-
export declare const MAX_SYNC_ATTEMPTS = 2;
|
|
28
|
-
/**
|
|
29
|
-
* Check if an error is a missing app state sync key.
|
|
30
|
-
* WA Web treats these as "Blocked" (waits for key arrival), not fatal.
|
|
31
|
-
* In Baileys we retry with a snapshot which may use a different key.
|
|
32
|
-
*/
|
|
33
|
-
export declare const isMissingKeyError: (error: any) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Determines if an app state sync error is unrecoverable.
|
|
36
|
-
* TypeError indicates a WASM crash; otherwise we give up after MAX_SYNC_ATTEMPTS.
|
|
37
|
-
* Missing keys are NOT checked here — they are handled separately as "Blocked".
|
|
38
|
-
*/
|
|
39
|
-
export declare const isAppStateSyncIrrecoverable: (error: any, attempts: number) => boolean;
|
|
10
|
+
[index: string]: ChatMutation
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare const newLTHashState: () => LTHashState
|
|
14
|
+
|
|
40
15
|
export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, operation }: WAPatchCreate, myAppStateKeyId: string, state: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey) => Promise<{
|
|
41
|
-
patch: proto.ISyncdPatch
|
|
42
|
-
state: LTHashState
|
|
43
|
-
}
|
|
16
|
+
patch: proto.ISyncdPatch
|
|
17
|
+
state: LTHashState
|
|
18
|
+
}>
|
|
19
|
+
|
|
44
20
|
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
45
|
-
hash: Buffer
|
|
21
|
+
hash: Buffer
|
|
46
22
|
indexValueMap: {
|
|
47
23
|
[indexMacBase64: string]: {
|
|
48
|
-
valueMac: Uint8Array | Buffer
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
24
|
+
valueMac: Uint8Array | Buffer
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}>
|
|
28
|
+
|
|
52
29
|
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
53
|
-
hash: Buffer
|
|
30
|
+
hash: Buffer
|
|
54
31
|
indexValueMap: {
|
|
55
32
|
[indexMacBase64: string]: {
|
|
56
|
-
valueMac: Uint8Array | Buffer
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
33
|
+
valueMac: Uint8Array | Buffer
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}>
|
|
37
|
+
|
|
38
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
39
|
+
critical_block: {
|
|
40
|
+
patches: proto.ISyncdPatch[]
|
|
41
|
+
hasMorePatches: boolean
|
|
42
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
43
|
+
}
|
|
61
44
|
critical_unblock_low: {
|
|
62
|
-
patches: proto.ISyncdPatch[]
|
|
63
|
-
hasMorePatches: boolean
|
|
64
|
-
snapshot?: proto.ISyncdSnapshot
|
|
65
|
-
}
|
|
45
|
+
patches: proto.ISyncdPatch[]
|
|
46
|
+
hasMorePatches: boolean
|
|
47
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
48
|
+
}
|
|
66
49
|
regular_high: {
|
|
67
|
-
patches: proto.ISyncdPatch[]
|
|
68
|
-
hasMorePatches: boolean
|
|
69
|
-
snapshot?: proto.ISyncdSnapshot
|
|
70
|
-
}
|
|
50
|
+
patches: proto.ISyncdPatch[]
|
|
51
|
+
hasMorePatches: boolean
|
|
52
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
53
|
+
}
|
|
71
54
|
regular_low: {
|
|
72
|
-
patches: proto.ISyncdPatch[]
|
|
73
|
-
hasMorePatches: boolean
|
|
74
|
-
snapshot?: proto.ISyncdSnapshot
|
|
75
|
-
}
|
|
76
|
-
critical_block: {
|
|
77
|
-
patches: proto.ISyncdPatch[];
|
|
78
|
-
hasMorePatches: boolean;
|
|
79
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
80
|
-
};
|
|
55
|
+
patches: proto.ISyncdPatch[]
|
|
56
|
+
hasMorePatches: boolean
|
|
57
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
58
|
+
}
|
|
81
59
|
regular: {
|
|
82
|
-
patches: proto.ISyncdPatch[]
|
|
83
|
-
hasMorePatches: boolean
|
|
84
|
-
snapshot?: proto.ISyncdSnapshot
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export declare const
|
|
89
|
-
export declare const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
60
|
+
patches: proto.ISyncdPatch[]
|
|
61
|
+
hasMorePatches: boolean
|
|
62
|
+
snapshot?: proto.ISyncdSnapshot | undefined
|
|
63
|
+
}
|
|
64
|
+
}>
|
|
65
|
+
|
|
66
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>
|
|
67
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>
|
|
68
|
+
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
69
|
+
state: LTHashState
|
|
70
|
+
mutationMap: ChatMutationMap
|
|
71
|
+
}>
|
|
72
|
+
|
|
73
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
|
|
74
|
+
state: LTHashState
|
|
75
|
+
mutationMap: ChatMutationMap
|
|
76
|
+
}>
|
|
77
|
+
|
|
78
|
+
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate
|
|
79
|
+
|
|
80
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void
|
|
81
|
+
|
|
82
|
+
export {}
|