@mrlegendbot/baileys 1.2.5 → 1.2.7
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/GenerateStatics.sh +3 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -2
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.js +92 -89
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -9
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +22 -21
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +69 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +10 -9
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +22 -21
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +62 -56
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +40 -38
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +34 -33
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +76 -72
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -22
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +405 -506
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +258 -276
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +7 -6
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +49 -48
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.js +369 -349
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.js +1148 -1172
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.js +413 -473
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.js +331 -387
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.js +8 -6
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.js +1719 -1782
- package/lib/Socket/messages-send.d.ts +200 -0
- package/lib/Socket/messages-send.js +2508 -1384
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +35 -40
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.js +191 -239
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.js +923 -992
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -1
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +22 -20
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +4 -2
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.js +5 -3
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +31 -26
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.js +52 -4
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +11 -10
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.js +277 -240
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +23 -20
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +204 -200
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.js +810 -836
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +25 -23
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +86 -70
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.js +284 -277
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.js +595 -592
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +335 -312
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.js +115 -123
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +2 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +73 -74
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -3
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +6 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +254 -213
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.js +715 -741
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +827 -791
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +187 -215
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +98 -69
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +586 -617
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +234 -553
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.js +170 -217
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +35 -27
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +41 -37
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +141 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +105 -87
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -190
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1294 -28
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -245
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +206 -201
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +89 -86
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +77 -68
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +8 -7
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -19892
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +132 -121
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.js +88 -79
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +29 -28
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -2
- package/package.json +86 -22
- package/README.upstream.md +0 -1312
- package/WAProto/WAProto.json +0 -1
- package/WAProto/WAProto.proto +0 -6275
- package/WAProto/compiler.js +0 -550
- package/lib/Store/index.js +0 -8
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -70
- package/lib/Store/make-in-memory-store.js +0 -417
- package/lib/Store/make-ordered-dictionary.js +0 -69
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
package/lib/Utils/business.js
CHANGED
|
@@ -6,222 +6,226 @@ import { join } from 'path';
|
|
|
6
6
|
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../WABinary/index.js';
|
|
7
7
|
import { generateMessageIDV2 } from './generics.js';
|
|
8
8
|
import { getStream, getUrlFromDirectPath } from './messages-media.js';
|
|
9
|
-
export const parseCatalogNode = node => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
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');
|
|
24
13
|
return {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
products,
|
|
28
|
-
status: parseStatusInfo(collectionNode)
|
|
14
|
+
products,
|
|
15
|
+
nextPageCursor: paging ? getBinaryNodeChildString(paging, 'after') : undefined
|
|
29
16
|
};
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
collections
|
|
33
|
-
};
|
|
34
17
|
};
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
});
|
|
39
31
|
return {
|
|
40
|
-
|
|
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')
|
|
32
|
+
collections
|
|
46
33
|
};
|
|
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
34
|
};
|
|
58
|
-
export const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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', {
|
|
96
|
-
statusCode: 400
|
|
97
|
-
});
|
|
98
|
-
}
|
|
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');
|
|
99
39
|
return {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}]
|
|
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')
|
|
107
46
|
};
|
|
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
47
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
});
|
|
138
81
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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;
|
|
149
152
|
};
|
|
150
|
-
export const parseProductNode = productNode => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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;
|
|
171
174
|
};
|
|
175
|
+
/**
|
|
176
|
+
* Uploads images not already uploaded to WA's servers
|
|
177
|
+
*/
|
|
172
178
|
export async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
product = {
|
|
180
|
+
...product,
|
|
181
|
+
images: product.images
|
|
182
|
+
? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
|
|
183
|
+
: product.images
|
|
184
|
+
};
|
|
185
|
+
return product;
|
|
178
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Uploads images not already uploaded to WA's servers
|
|
189
|
+
*/
|
|
179
190
|
export const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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');
|
|
208
219
|
return {
|
|
209
|
-
|
|
220
|
+
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
221
|
+
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
210
222
|
};
|
|
211
|
-
}));
|
|
212
|
-
return results;
|
|
213
|
-
};
|
|
214
|
-
const parseImageUrls = mediaNode => {
|
|
215
|
-
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
216
|
-
return {
|
|
217
|
-
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
218
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
219
|
-
};
|
|
220
223
|
};
|
|
221
|
-
const parseStatusInfo = mediaNode => {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
+
};
|
|
227
230
|
};
|
|
231
|
+
//# sourceMappingURL=business.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types/index.js';
|
|
3
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
4
|
+
import type { ILogger } from './logger.js';
|
|
5
|
+
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
|
|
6
|
+
export type ChatMutationMap = {
|
|
7
|
+
[index: string]: ChatMutation;
|
|
8
|
+
};
|
|
9
|
+
type Mac = {
|
|
10
|
+
indexMac: Uint8Array;
|
|
11
|
+
valueMac: Uint8Array;
|
|
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;
|
|
40
|
+
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
|
+
}>;
|
|
44
|
+
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
45
|
+
hash: Buffer<ArrayBuffer>;
|
|
46
|
+
indexValueMap: {
|
|
47
|
+
[indexMacBase64: string]: {
|
|
48
|
+
valueMac: Uint8Array | Buffer;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
53
|
+
hash: Buffer<ArrayBuffer>;
|
|
54
|
+
indexValueMap: {
|
|
55
|
+
[indexMacBase64: string]: {
|
|
56
|
+
valueMac: Uint8Array | Buffer;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}>;
|
|
60
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: RequestInit) => Promise<{
|
|
61
|
+
critical_unblock_low: {
|
|
62
|
+
patches: proto.ISyncdPatch[];
|
|
63
|
+
hasMorePatches: boolean;
|
|
64
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
65
|
+
};
|
|
66
|
+
regular_high: {
|
|
67
|
+
patches: proto.ISyncdPatch[];
|
|
68
|
+
hasMorePatches: boolean;
|
|
69
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
70
|
+
};
|
|
71
|
+
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
|
+
};
|
|
81
|
+
regular: {
|
|
82
|
+
patches: proto.ISyncdPatch[];
|
|
83
|
+
hasMorePatches: boolean;
|
|
84
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
85
|
+
};
|
|
86
|
+
}>;
|
|
87
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: RequestInit) => Promise<Buffer<ArrayBuffer>>;
|
|
88
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: RequestInit) => Promise<proto.SyncdMutations>;
|
|
89
|
+
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean, logger?: ILogger) => Promise<{
|
|
90
|
+
state: LTHashState;
|
|
91
|
+
mutationMap: ChatMutationMap;
|
|
92
|
+
}>;
|
|
93
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: RequestInit, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
|
|
94
|
+
state: LTHashState;
|
|
95
|
+
mutationMap: ChatMutationMap;
|
|
96
|
+
}>;
|
|
97
|
+
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
|
|
98
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void;
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=chat-utils.d.ts.map
|