@baileys-md/baileys 11.0.2 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +3 -1
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
package/lib/Types/Message.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
|
|
4
|
+
const WAProto_1 = require("../../WAProto");
|
|
5
|
+
Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
|
|
6
|
+
exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
|
|
7
|
+
exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XWAPaths = exports.MexOperations = void 0;
|
|
4
|
+
var MexOperations;
|
|
5
|
+
(function (MexOperations) {
|
|
6
|
+
MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
|
|
7
|
+
MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
|
|
8
|
+
MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
|
|
9
|
+
})(MexOperations || (exports.MexOperations = MexOperations = {}));
|
|
10
|
+
var XWAPaths;
|
|
2
11
|
(function (XWAPaths) {
|
|
3
|
-
XWAPaths["
|
|
4
|
-
XWAPaths["
|
|
5
|
-
XWAPaths["
|
|
6
|
-
XWAPaths["
|
|
7
|
-
XWAPaths["
|
|
8
|
-
XWAPaths["
|
|
9
|
-
|
|
10
|
-
XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
|
|
11
|
-
XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
|
|
12
|
-
XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
|
|
13
|
-
XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
|
|
14
|
-
XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
|
|
15
|
-
})(XWAPaths || (XWAPaths = {}));
|
|
16
|
-
export var QueryIds;
|
|
17
|
-
(function (QueryIds) {
|
|
18
|
-
QueryIds["CREATE"] = "8823471724422422";
|
|
19
|
-
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
20
|
-
QueryIds["METADATA"] = "6563316087068696";
|
|
21
|
-
QueryIds["SUBSCRIBERS"] = "9783111038412085";
|
|
22
|
-
QueryIds["FOLLOW"] = "7871414976211147";
|
|
23
|
-
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
24
|
-
QueryIds["MUTE"] = "29766401636284406";
|
|
25
|
-
QueryIds["UNMUTE"] = "9864994326891137";
|
|
26
|
-
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
27
|
-
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
28
|
-
QueryIds["DEMOTE"] = "6551828931592903";
|
|
29
|
-
QueryIds["DELETE"] = "30062808666639665";
|
|
30
|
-
})(QueryIds || (QueryIds = {}));
|
|
31
|
-
//# sourceMappingURL=Newsletter.js.map
|
|
12
|
+
XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
|
|
13
|
+
XWAPaths["DEMOTE"] = "xwa2_notify_newsletter_admin_demote";
|
|
14
|
+
XWAPaths["ADMIN_COUNT"] = "xwa2_newsletter_admin";
|
|
15
|
+
XWAPaths["CREATE"] = "xwa2_newsletter_create";
|
|
16
|
+
XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
|
|
17
|
+
XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
|
|
18
|
+
})(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
|
package/lib/Types/Product.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Types/Signal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Types/Socket.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=Socket.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Types/State.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Types/USync.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Types/index.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DisconnectReason = void 0;
|
|
18
|
+
__exportStar(require("./Auth"), exports);
|
|
19
|
+
__exportStar(require("./GroupMetadata"), exports);
|
|
20
|
+
__exportStar(require("./Newsletter"), exports);
|
|
21
|
+
__exportStar(require("./Chat"), exports);
|
|
22
|
+
__exportStar(require("./Contact"), exports);
|
|
23
|
+
__exportStar(require("./State"), exports);
|
|
24
|
+
__exportStar(require("./Message"), exports);
|
|
25
|
+
__exportStar(require("./Socket"), exports);
|
|
26
|
+
__exportStar(require("./Events"), exports);
|
|
27
|
+
__exportStar(require("./Product"), exports);
|
|
28
|
+
__exportStar(require("./Call"), exports);
|
|
29
|
+
__exportStar(require("./Signal"), exports);
|
|
30
|
+
var DisconnectReason;
|
|
14
31
|
(function (DisconnectReason) {
|
|
15
32
|
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
|
16
33
|
DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
|
|
@@ -22,5 +39,4 @@ export var DisconnectReason;
|
|
|
22
39
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
23
40
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
24
41
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
25
|
-
})(DisconnectReason || (DisconnectReason = {}));
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
|
42
|
+
})(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
7
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const Defaults_1 = require("../Defaults");
|
|
12
|
+
const crypto_2 = require("./crypto");
|
|
13
|
+
const generics_1 = require("./generics");
|
|
6
14
|
/**
|
|
7
15
|
* Adds caching capability to a SignalKeyStore
|
|
8
16
|
* @param store the store to add caching to
|
|
9
17
|
* @param logger to log trace events
|
|
10
18
|
* @param _cache cache store to use
|
|
11
19
|
*/
|
|
12
|
-
|
|
13
|
-
const cache = _cache ||
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
20
|
+
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
21
|
+
const cache = _cache || new node_cache_1.default({
|
|
22
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
23
|
+
useClones: false,
|
|
24
|
+
deleteOnExpire: true,
|
|
25
|
+
});
|
|
19
26
|
function getUniqueId(type, id) {
|
|
20
27
|
return `${type}.${id}`;
|
|
21
28
|
}
|
|
@@ -33,7 +40,7 @@ export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
if (idsToFetch.length) {
|
|
36
|
-
logger
|
|
43
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
37
44
|
const fetched = await store.get(type, idsToFetch);
|
|
38
45
|
for (const id of idsToFetch) {
|
|
39
46
|
const item = fetched[id];
|
|
@@ -53,12 +60,13 @@ export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
53
60
|
keys += 1;
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
logger
|
|
63
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
|
|
57
64
|
await store.set(data);
|
|
58
65
|
},
|
|
59
66
|
async clear() {
|
|
67
|
+
var _a;
|
|
60
68
|
cache.flushAll();
|
|
61
|
-
await store.clear
|
|
69
|
+
await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
|
|
62
70
|
}
|
|
63
71
|
};
|
|
64
72
|
}
|
|
@@ -69,7 +77,7 @@ export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
69
77
|
* @param logger logger to log events
|
|
70
78
|
* @returns SignalKeyStore with transaction capability
|
|
71
79
|
*/
|
|
72
|
-
|
|
80
|
+
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
73
81
|
// number of queries made to the DB during the transaction
|
|
74
82
|
// only there for logging purposes
|
|
75
83
|
let dbQueriesInTransaction = 0;
|
|
@@ -80,7 +88,9 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
80
88
|
get: async (type, ids) => {
|
|
81
89
|
if (isInTransaction()) {
|
|
82
90
|
const dict = transactionCache[type];
|
|
83
|
-
const idsRequiringFetch = dict
|
|
91
|
+
const idsRequiringFetch = dict
|
|
92
|
+
? ids.filter(item => typeof dict[item] === 'undefined')
|
|
93
|
+
: ids;
|
|
84
94
|
// only fetch if there are any items to fetch
|
|
85
95
|
if (idsRequiringFetch.length) {
|
|
86
96
|
dbQueriesInTransaction += 1;
|
|
@@ -89,7 +99,8 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
89
99
|
Object.assign(transactionCache[type], result);
|
|
90
100
|
}
|
|
91
101
|
return ids.reduce((dict, id) => {
|
|
92
|
-
|
|
102
|
+
var _a;
|
|
103
|
+
const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
|
|
93
104
|
if (value) {
|
|
94
105
|
dict[id] = value;
|
|
95
106
|
}
|
|
@@ -103,8 +114,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
103
114
|
set: data => {
|
|
104
115
|
if (isInTransaction()) {
|
|
105
116
|
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
106
|
-
for (const
|
|
107
|
-
const key = key_;
|
|
117
|
+
for (const key in data) {
|
|
108
118
|
transactionCache[key] = transactionCache[key] || {};
|
|
109
119
|
Object.assign(transactionCache[key], data[key]);
|
|
110
120
|
mutations[key] = mutations[key] || {};
|
|
@@ -133,7 +143,6 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
133
143
|
let tries = maxCommitRetries;
|
|
134
144
|
while (tries) {
|
|
135
145
|
tries -= 1;
|
|
136
|
-
//eslint-disable-next-line max-depth
|
|
137
146
|
try {
|
|
138
147
|
await state.set(mutations);
|
|
139
148
|
logger.trace({ dbQueriesInTransaction }, 'committed transaction');
|
|
@@ -141,7 +150,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
141
150
|
}
|
|
142
151
|
catch (error) {
|
|
143
152
|
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
144
|
-
await delay(delayBetweenTriesMs);
|
|
153
|
+
await (0, generics_1.delay)(delayBetweenTriesMs);
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
}
|
|
@@ -165,15 +174,16 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
165
174
|
return transactionsInProgress > 0;
|
|
166
175
|
}
|
|
167
176
|
};
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
exports.addTransactionCapability = addTransactionCapability;
|
|
178
|
+
const initAuthCreds = () => {
|
|
179
|
+
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
170
180
|
return {
|
|
171
|
-
noiseKey: Curve.generateKeyPair(),
|
|
172
|
-
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
181
|
+
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
182
|
+
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
173
183
|
signedIdentityKey: identityKey,
|
|
174
|
-
signedPreKey: signedKeyPair(identityKey, 1),
|
|
175
|
-
registrationId: generateRegistrationId(),
|
|
176
|
-
advSecretKey: randomBytes(32).toString('base64'),
|
|
184
|
+
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
|
185
|
+
registrationId: (0, generics_1.generateRegistrationId)(),
|
|
186
|
+
advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
|
|
177
187
|
processedHistoryMessages: [],
|
|
178
188
|
nextPreKeyId: 1,
|
|
179
189
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -181,10 +191,16 @@ export const initAuthCreds = () => {
|
|
|
181
191
|
accountSettings: {
|
|
182
192
|
unarchiveChats: false
|
|
183
193
|
},
|
|
194
|
+
// mobile creds
|
|
195
|
+
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
+
phoneId: (0, uuid_1.v4)(),
|
|
197
|
+
identityId: (0, crypto_1.randomBytes)(20),
|
|
184
198
|
registered: false,
|
|
199
|
+
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
+
registration: {},
|
|
185
201
|
pairingCode: undefined,
|
|
186
202
|
lastPropHash: undefined,
|
|
187
|
-
routingInfo: undefined
|
|
203
|
+
routingInfo: undefined,
|
|
188
204
|
};
|
|
189
205
|
};
|
|
190
|
-
|
|
206
|
+
exports.initAuthCreds = initAuthCreds;
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readAndEmitEventStream = exports.captureEventStream = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const promises_1 = require("fs/promises");
|
|
10
|
+
const readline_1 = require("readline");
|
|
11
|
+
const generics_1 = require("./generics");
|
|
12
|
+
const make_mutex_1 = require("./make-mutex");
|
|
7
13
|
/**
|
|
8
14
|
* Captures events from a baileys event emitter & stores them in a file
|
|
9
15
|
* @param ev The event emitter to read events from
|
|
10
16
|
* @param filename File to save to
|
|
11
17
|
*/
|
|
12
|
-
|
|
18
|
+
const captureEventStream = (ev, filename) => {
|
|
13
19
|
const oldEmit = ev.emit;
|
|
14
20
|
// write mutex so data is appended in order
|
|
15
|
-
const writeMutex = makeMutex();
|
|
21
|
+
const writeMutex = (0, make_mutex_1.makeMutex)();
|
|
16
22
|
// monkey patch eventemitter to capture all events
|
|
17
23
|
ev.emit = function (...args) {
|
|
18
24
|
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
|
|
19
25
|
const result = oldEmit.apply(ev, args);
|
|
20
26
|
writeMutex.mutex(async () => {
|
|
21
|
-
await writeFile(filename, content, { flag: 'a' });
|
|
27
|
+
await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
|
|
22
28
|
});
|
|
23
29
|
return result;
|
|
24
30
|
};
|
|
25
31
|
};
|
|
32
|
+
exports.captureEventStream = captureEventStream;
|
|
26
33
|
/**
|
|
27
34
|
* Read event file and emit events from there
|
|
28
35
|
* @param filename filename containing event data
|
|
29
36
|
* @param delayIntervalMs delay between each event emit
|
|
30
37
|
*/
|
|
31
|
-
|
|
32
|
-
const ev = new
|
|
38
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
39
|
+
const ev = new events_1.default();
|
|
33
40
|
const fireEvents = async () => {
|
|
34
41
|
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
|
35
|
-
const fileStream = createReadStream(filename);
|
|
36
|
-
const rl = createInterface({
|
|
42
|
+
const fileStream = (0, fs_1.createReadStream)(filename);
|
|
43
|
+
const rl = (0, readline_1.createInterface)({
|
|
37
44
|
input: fileStream,
|
|
38
45
|
crlfDelay: Infinity
|
|
39
46
|
});
|
|
@@ -43,7 +50,7 @@ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
43
50
|
if (line) {
|
|
44
51
|
const { event, data } = JSON.parse(line);
|
|
45
52
|
ev.emit(event, data);
|
|
46
|
-
delayIntervalMs &&
|
|
53
|
+
delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
fileStream.close();
|
|
@@ -53,4 +60,4 @@ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
53
60
|
task: fireEvents()
|
|
54
61
|
};
|
|
55
62
|
};
|
|
56
|
-
|
|
63
|
+
exports.readAndEmitEventStream = readAndEmitEventStream;
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const catalogNode = getBinaryNodeChild(node, 'product_catalog');
|
|
11
|
-
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode);
|
|
12
|
-
const paging = getBinaryNodeChild(catalogNode, 'paging');
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
4
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
5
|
+
const boom_1 = require("@hapi/boom");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const WABinary_1 = require("../WABinary");
|
|
8
|
+
const messages_media_1 = require("./messages-media");
|
|
9
|
+
const parseCatalogNode = (node) => {
|
|
10
|
+
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
|
|
11
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
|
|
12
|
+
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
|
|
13
13
|
return {
|
|
14
14
|
products,
|
|
15
|
-
nextPageCursor: paging
|
|
15
|
+
nextPageCursor: paging
|
|
16
|
+
? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
|
|
17
|
+
: undefined
|
|
16
18
|
};
|
|
17
19
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
20
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
21
|
+
const parseCollectionsNode = (node) => {
|
|
22
|
+
const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections');
|
|
23
|
+
const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
24
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id');
|
|
25
|
+
const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name');
|
|
26
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
|
|
24
27
|
return {
|
|
25
28
|
id,
|
|
26
29
|
name,
|
|
@@ -32,30 +35,32 @@ export const parseCollectionsNode = (node) => {
|
|
|
32
35
|
collections
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
39
|
+
const parseOrderDetailsNode = (node) => {
|
|
40
|
+
const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order');
|
|
41
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
42
|
+
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image');
|
|
39
43
|
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')
|
|
44
|
+
id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
|
|
45
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
46
|
+
imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
|
|
47
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
48
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
49
|
+
quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
|
|
46
50
|
};
|
|
47
51
|
});
|
|
48
|
-
const priceNode = getBinaryNodeChild(orderNode, 'price');
|
|
52
|
+
const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price');
|
|
49
53
|
const orderDetails = {
|
|
50
54
|
price: {
|
|
51
|
-
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
-
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
55
|
+
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
|
|
56
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency'),
|
|
53
57
|
},
|
|
54
58
|
products
|
|
55
59
|
};
|
|
56
60
|
return orderDetails;
|
|
57
61
|
};
|
|
58
|
-
|
|
62
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
63
|
+
const toProductNode = (productId, product) => {
|
|
59
64
|
const attrs = {};
|
|
60
65
|
const content = [];
|
|
61
66
|
if (typeof productId !== 'undefined') {
|
|
@@ -92,7 +97,7 @@ export const toProductNode = (productId, product) => {
|
|
|
92
97
|
attrs: {},
|
|
93
98
|
content: product.images.map(img => {
|
|
94
99
|
if (!('url' in img)) {
|
|
95
|
-
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
100
|
+
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
96
101
|
}
|
|
97
102
|
return {
|
|
98
103
|
tag: 'image',
|
|
@@ -150,44 +155,44 @@ export const toProductNode = (productId, product) => {
|
|
|
150
155
|
};
|
|
151
156
|
return node;
|
|
152
157
|
};
|
|
153
|
-
|
|
158
|
+
exports.toProductNode = toProductNode;
|
|
159
|
+
const parseProductNode = (productNode) => {
|
|
154
160
|
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');
|
|
161
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id');
|
|
162
|
+
const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media');
|
|
163
|
+
const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info');
|
|
158
164
|
const product = {
|
|
159
165
|
id,
|
|
160
166
|
imageUrls: parseImageUrls(mediaNode),
|
|
161
167
|
reviewStatus: {
|
|
162
|
-
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
168
|
+
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status'),
|
|
163
169
|
},
|
|
164
170
|
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
|
|
171
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
172
|
+
retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
173
|
+
url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
|
|
174
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
|
|
175
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
176
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
177
|
+
isHidden,
|
|
172
178
|
};
|
|
173
179
|
return product;
|
|
174
180
|
};
|
|
181
|
+
exports.parseProductNode = parseProductNode;
|
|
175
182
|
/**
|
|
176
183
|
* Uploads images not already uploaded to WA's servers
|
|
177
184
|
*/
|
|
178
|
-
|
|
185
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
179
186
|
product = {
|
|
180
187
|
...product,
|
|
181
|
-
images: product.images
|
|
182
|
-
? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
|
|
183
|
-
: product.images
|
|
188
|
+
images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
|
|
184
189
|
};
|
|
185
190
|
return product;
|
|
186
191
|
}
|
|
187
192
|
/**
|
|
188
193
|
* Uploads images not already uploaded to WA's servers
|
|
189
194
|
*/
|
|
190
|
-
|
|
195
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
191
196
|
const results = await Promise.all(images.map(async (img) => {
|
|
192
197
|
if ('url' in img) {
|
|
193
198
|
const url = img.url.toString();
|
|
@@ -195,37 +200,35 @@ export const uploadingNecessaryImages = async (images, waUploadToServer, timeout
|
|
|
195
200
|
return { url };
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
|
-
const { stream } = await getStream(img);
|
|
199
|
-
const hasher = createHash('sha256');
|
|
200
|
-
const
|
|
201
|
-
const encFileWriteStream = createWriteStream(filePath);
|
|
203
|
+
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
204
|
+
const hasher = (0, crypto_1.createHash)('sha256');
|
|
205
|
+
const contentBlocks = [];
|
|
202
206
|
for await (const block of stream) {
|
|
203
207
|
hasher.update(block);
|
|
204
|
-
|
|
208
|
+
contentBlocks.push(block);
|
|
205
209
|
}
|
|
206
210
|
const sha = hasher.digest('base64');
|
|
207
|
-
const { directPath } = await waUploadToServer(
|
|
211
|
+
const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
|
|
208
212
|
mediaType: 'product-catalog-image',
|
|
209
213
|
fileEncSha256B64: sha,
|
|
210
214
|
timeoutMs
|
|
211
215
|
});
|
|
212
|
-
|
|
213
|
-
return { url: getUrlFromDirectPath(directPath) };
|
|
216
|
+
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
214
217
|
}));
|
|
215
218
|
return results;
|
|
216
219
|
};
|
|
220
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
217
221
|
const parseImageUrls = (mediaNode) => {
|
|
218
|
-
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
222
|
+
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
|
|
219
223
|
return {
|
|
220
|
-
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
221
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
224
|
+
requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
225
|
+
original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
222
226
|
};
|
|
223
227
|
};
|
|
224
228
|
const parseStatusInfo = (mediaNode) => {
|
|
225
|
-
const node = getBinaryNodeChild(mediaNode, 'status_info');
|
|
229
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
226
230
|
return {
|
|
227
|
-
status: getBinaryNodeChildString(node, 'status'),
|
|
228
|
-
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
231
|
+
status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
|
|
232
|
+
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
|
|
229
233
|
};
|
|
230
234
|
};
|
|
231
|
-
//# sourceMappingURL=business.js.map
|