@aseppxyzz12/baileys 1.1.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 +25 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.js +658 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.js +1509 -0
- package/lib/Socket/messages-send.js +1505 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +171 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/rich-content.js +279 -0
- package/lib/Socket/socket.js +905 -0
- package/lib/Socket/username.js +157 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +37 -0
- package/lib/Store/keyed-db.js +114 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +40 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +60 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/bot-toolkit.js +455 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +904 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +411 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/identity-change-handler.js +53 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +289 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1908 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/reporting-utils.js +264 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/stanza-ack.js +36 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.js +167 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +38 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.js +33 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +113 -0
- package/lib/messages-send.js +1496 -0
- package/package.json +100 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported & adapted from PouCode fork for AsepXyz Baileys
|
|
3
|
+
// Adds @username support: check availability, set/get/delete your own username,
|
|
4
|
+
// PIN protection, and lookup of contacts by username.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeUsernameSocket = exports.USERNAME_SOURCE = exports.USERNAME_CHECK_RESULT = exports.USERNAME_QUERY_IDS = void 0;
|
|
7
|
+
const { executeWMexQuery } = require("./mex");
|
|
8
|
+
const { USyncQuery, USyncUser } = require("../WAUSync");
|
|
9
|
+
const { makeCommunitiesSocket } = require("./community");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* w:mex query IDs for username operations.
|
|
13
|
+
* These numeric IDs are assigned by WhatsApp's Pando/MEX infrastructure.
|
|
14
|
+
*/
|
|
15
|
+
const USERNAME_QUERY_IDS = {
|
|
16
|
+
CHECK: '26124072630599520',
|
|
17
|
+
CHECK_MULTI: '27134626522840290',
|
|
18
|
+
SET: '27108705368767936',
|
|
19
|
+
GET: '32618050064506056',
|
|
20
|
+
GET_RECOMMENDATIONS: '26077456248616956',
|
|
21
|
+
PIN_SET: '25529696019976770'
|
|
22
|
+
};
|
|
23
|
+
exports.USERNAME_QUERY_IDS = USERNAME_QUERY_IDS;
|
|
24
|
+
|
|
25
|
+
const USERNAME_CHECK_RESULT = {
|
|
26
|
+
SUCCESS: 'SUCCESS',
|
|
27
|
+
INVALID: 'INVALID'
|
|
28
|
+
};
|
|
29
|
+
exports.USERNAME_CHECK_RESULT = USERNAME_CHECK_RESULT;
|
|
30
|
+
|
|
31
|
+
const USERNAME_SOURCE = {
|
|
32
|
+
FB: 'FB',
|
|
33
|
+
IG: 'IG',
|
|
34
|
+
USER_INPUT: 'USER_INPUT',
|
|
35
|
+
SUGGESTION: 'SUGGESTION'
|
|
36
|
+
};
|
|
37
|
+
exports.USERNAME_SOURCE = USERNAME_SOURCE;
|
|
38
|
+
|
|
39
|
+
const makeUsernameSocket = (config) => {
|
|
40
|
+
const sock = makeCommunitiesSocket(config);
|
|
41
|
+
const { query, generateMessageTag, executeUSyncQuery } = sock;
|
|
42
|
+
|
|
43
|
+
const mexQuery = (variables, queryId, dataPath) => executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
44
|
+
|
|
45
|
+
/** Check whether a username is available. */
|
|
46
|
+
const checkUsername = async (username, includeSuggestions = true) => {
|
|
47
|
+
if (!USERNAME_QUERY_IDS.CHECK) {
|
|
48
|
+
throw new Error('Username CHECK query_id not configured — capture a live WA session to obtain it');
|
|
49
|
+
}
|
|
50
|
+
const data = await mexQuery({ username, include_suggestions: includeSuggestions }, USERNAME_QUERY_IDS.CHECK, 'xwa2_username_check');
|
|
51
|
+
if (data?.result === USERNAME_CHECK_RESULT.SUCCESS) {
|
|
52
|
+
return { available: true, username };
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
available: false,
|
|
56
|
+
username,
|
|
57
|
+
suggestions: data?.suggestions ?? [],
|
|
58
|
+
rejectionReasons: data?.rejection_reasons ?? [],
|
|
59
|
+
suggestionsEligible: data?.suggestions_eligible ?? true
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Set your own username. */
|
|
64
|
+
const setUsername = async (username, options = {}) => {
|
|
65
|
+
if (!USERNAME_QUERY_IDS.SET) {
|
|
66
|
+
throw new Error('Username SET query_id not configured — capture a live WA session to obtain it');
|
|
67
|
+
}
|
|
68
|
+
const { source = USERNAME_SOURCE.USER_INPUT, sessionId, pin } = options;
|
|
69
|
+
const variables = {
|
|
70
|
+
username,
|
|
71
|
+
reserved: false,
|
|
72
|
+
source,
|
|
73
|
+
...(sessionId ? { session_id: sessionId } : {}),
|
|
74
|
+
...(pin ? { pin } : {})
|
|
75
|
+
};
|
|
76
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.SET, 'xwa2_username_set');
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Delete (unset) your own username. */
|
|
80
|
+
const deleteUsername = async () => {
|
|
81
|
+
if (!USERNAME_QUERY_IDS.SET) {
|
|
82
|
+
throw new Error('Username SET query_id not configured — capture a live WA session to obtain it');
|
|
83
|
+
}
|
|
84
|
+
return mexQuery({ username: null }, USERNAME_QUERY_IDS.SET, 'xwa2_username_delete');
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Get your own current username. */
|
|
88
|
+
const getMyUsername = async () => {
|
|
89
|
+
if (!USERNAME_QUERY_IDS.GET) {
|
|
90
|
+
throw new Error('Username GET query_id not configured — capture a live WA session to obtain it');
|
|
91
|
+
}
|
|
92
|
+
const data = await mexQuery({}, USERNAME_QUERY_IDS.GET, 'xwa2_username_get');
|
|
93
|
+
return data?.username ?? null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Set or delete the PIN that protects your username. */
|
|
97
|
+
const setUsernamePin = async (pin) => {
|
|
98
|
+
if (!USERNAME_QUERY_IDS.PIN_SET) {
|
|
99
|
+
throw new Error('Username PIN_SET query_id not configured — capture a live WA session to obtain it');
|
|
100
|
+
}
|
|
101
|
+
return mexQuery({ pin }, USERNAME_QUERY_IDS.PIN_SET, 'xwa2_username_pin_set');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Look up a contact by their @username via USync. */
|
|
105
|
+
const findUserByUsername = async (username, pin) => {
|
|
106
|
+
const usyncQuery = new USyncQuery().withContactProtocol();
|
|
107
|
+
const user = new USyncUser().withUsername(username);
|
|
108
|
+
if (pin) user.withUsernameKey(pin);
|
|
109
|
+
usyncQuery.withUser(user);
|
|
110
|
+
const result = await executeUSyncQuery(usyncQuery);
|
|
111
|
+
if (!result?.list?.length) return null;
|
|
112
|
+
const entry = result.list[0];
|
|
113
|
+
return {
|
|
114
|
+
jid: entry.id,
|
|
115
|
+
contact: entry.contact ?? false
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Fetch the username of one or more contacts by their JID. */
|
|
120
|
+
const fetchContactUsernames = async (...jids) => {
|
|
121
|
+
const usyncQuery = new USyncQuery().withUsernameProtocol();
|
|
122
|
+
for (const jid of jids) {
|
|
123
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
124
|
+
}
|
|
125
|
+
const result = await executeUSyncQuery(usyncQuery);
|
|
126
|
+
return result?.list ?? [];
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** Check multiple usernames for availability at once. */
|
|
130
|
+
const checkUsernameMulti = async (usernames) => {
|
|
131
|
+
return mexQuery({ usernames }, USERNAME_QUERY_IDS.CHECK_MULTI, 'xwa2_username_check_multi');
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/** Fetch username recommendations for the current user. */
|
|
135
|
+
const getUsernameRecommendations = async (source = null) => {
|
|
136
|
+
const variables = {};
|
|
137
|
+
if (source) variables.source = source;
|
|
138
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.GET_RECOMMENDATIONS, 'xwa2_username_get_recommendations');
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
...sock,
|
|
143
|
+
checkUsername,
|
|
144
|
+
checkUsernameMulti,
|
|
145
|
+
setUsername,
|
|
146
|
+
deleteUsername,
|
|
147
|
+
getMyUsername,
|
|
148
|
+
getUsernameRecommendations,
|
|
149
|
+
setUsernamePin,
|
|
150
|
+
findUserByUsername,
|
|
151
|
+
fetchContactUsernames,
|
|
152
|
+
USERNAME_QUERY_IDS,
|
|
153
|
+
USERNAME_CHECK_RESULT,
|
|
154
|
+
USERNAME_SOURCE
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
exports.makeUsernameSocket = makeUsernameSocket;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUSyncSocket = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const socket_1 = require("./socket");
|
|
7
|
+
const makeUSyncSocket = (config) => {
|
|
8
|
+
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
+
const { generateMessageTag, query, } = sock;
|
|
10
|
+
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
|
+
if (usyncQuery.protocols.length === 0) {
|
|
12
|
+
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
13
|
+
}
|
|
14
|
+
// todo: validate users, throw WARNING on no valid users
|
|
15
|
+
// variable below has only validated users
|
|
16
|
+
const validUsers = usyncQuery.users;
|
|
17
|
+
const userNodes = validUsers.map((user) => {
|
|
18
|
+
return {
|
|
19
|
+
tag: 'user',
|
|
20
|
+
attrs: {
|
|
21
|
+
jid: !user.phone ? user.id : undefined,
|
|
22
|
+
},
|
|
23
|
+
content: usyncQuery.protocols
|
|
24
|
+
.map((a) => a.getUserElement(user))
|
|
25
|
+
.filter(a => a !== null)
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const listNode = {
|
|
29
|
+
tag: 'list',
|
|
30
|
+
attrs: {},
|
|
31
|
+
content: userNodes
|
|
32
|
+
};
|
|
33
|
+
const queryNode = {
|
|
34
|
+
tag: 'query',
|
|
35
|
+
attrs: {},
|
|
36
|
+
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
37
|
+
};
|
|
38
|
+
const iq = {
|
|
39
|
+
tag: 'iq',
|
|
40
|
+
attrs: {
|
|
41
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
42
|
+
type: 'get',
|
|
43
|
+
xmlns: 'usync',
|
|
44
|
+
},
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
tag: 'usync',
|
|
48
|
+
attrs: {
|
|
49
|
+
context: usyncQuery.context,
|
|
50
|
+
mode: usyncQuery.mode,
|
|
51
|
+
sid: generateMessageTag(),
|
|
52
|
+
last: 'true',
|
|
53
|
+
index: '0',
|
|
54
|
+
},
|
|
55
|
+
content: [
|
|
56
|
+
queryNode,
|
|
57
|
+
listNode
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const result = await query(iq);
|
|
63
|
+
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
...sock,
|
|
67
|
+
executeUSyncQuery,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.makeUSyncSocket = makeUSyncSocket;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./make-cache-manager-store"), exports);
|
|
33
|
+
__exportStar(require("./make-in-memory-store"), exports);
|
|
34
|
+
__exportStar(require("./make-ordered-dictionary"), exports);
|
|
35
|
+
__exportStar(require("./object-repository"), exports);
|
|
36
|
+
exports.KeyedDB = require("./keyed-db");
|
|
37
|
+
exports.keyedDB = require("./keyed-db");
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported & adapted from PouCode fork for AsepXyz Baileys
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
class KeyedDB {
|
|
5
|
+
constructor(compareFn, idGetter) {
|
|
6
|
+
if (typeof compareFn !== "function" || typeof idGetter !== "function") {
|
|
7
|
+
throw new Error("KeyedDB requires compare and idGetter functions");
|
|
8
|
+
}
|
|
9
|
+
this._compare = compareFn;
|
|
10
|
+
this._idGetter = idGetter;
|
|
11
|
+
this._array = [];
|
|
12
|
+
this._dict = {};
|
|
13
|
+
}
|
|
14
|
+
get length() {
|
|
15
|
+
return this._array.length;
|
|
16
|
+
}
|
|
17
|
+
get(id) {
|
|
18
|
+
return this._dict[id];
|
|
19
|
+
}
|
|
20
|
+
insert(entry, mode = "insert") {
|
|
21
|
+
const id = this._idGetter(entry);
|
|
22
|
+
const existing = this._dict[id];
|
|
23
|
+
if (existing && mode === "insert") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
this._dict[id] = entry;
|
|
27
|
+
let inserted = false;
|
|
28
|
+
for (let i = 0; i < this._array.length; i++) {
|
|
29
|
+
const cmp = this._compare(this._idGetter(this._array[i]), id);
|
|
30
|
+
if (cmp < 0) {
|
|
31
|
+
this._array.splice(i, 0, entry);
|
|
32
|
+
inserted = true;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!inserted) this._array.push(entry);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
insertIfAbsent(...entries) {
|
|
40
|
+
const added = [];
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
if (!this._dict[this._idGetter(entry)]) {
|
|
43
|
+
this.insert(entry);
|
|
44
|
+
added.push(entry);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return added;
|
|
48
|
+
}
|
|
49
|
+
upsert(...entries) {
|
|
50
|
+
const added = [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const id = this._idGetter(entry);
|
|
53
|
+
if (this._dict[id]) {
|
|
54
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
55
|
+
if (idx >= 0) this._array[idx] = entry;
|
|
56
|
+
this._dict[id] = entry;
|
|
57
|
+
} else {
|
|
58
|
+
this.insert(entry);
|
|
59
|
+
added.push(entry);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return added;
|
|
63
|
+
}
|
|
64
|
+
update(id, updater) {
|
|
65
|
+
const item = this._dict[id];
|
|
66
|
+
if (!item) return false;
|
|
67
|
+
updater(item);
|
|
68
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
69
|
+
if (idx >= 0) this._array[idx] = item;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
updateAssign(id, update) {
|
|
73
|
+
const item = this._dict[id];
|
|
74
|
+
if (!item) return false;
|
|
75
|
+
Object.assign(item, update);
|
|
76
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
77
|
+
if (idx >= 0) this._array[idx] = item;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
deleteById(id) {
|
|
81
|
+
if (!this._dict[id]) return false;
|
|
82
|
+
delete this._dict[id];
|
|
83
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
84
|
+
if (idx >= 0) this._array.splice(idx, 1);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
clear() {
|
|
88
|
+
this._array = [];
|
|
89
|
+
this._dict = {};
|
|
90
|
+
}
|
|
91
|
+
all() {
|
|
92
|
+
return [...this._array];
|
|
93
|
+
}
|
|
94
|
+
filter(predicate) {
|
|
95
|
+
this._array = this._array.filter(predicate);
|
|
96
|
+
this._dict = {};
|
|
97
|
+
for (const entry of this._array) {
|
|
98
|
+
this._dict[this._idGetter(entry)] = entry;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
count() {
|
|
102
|
+
return this._array.length;
|
|
103
|
+
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return this._array;
|
|
106
|
+
}
|
|
107
|
+
fromJSON(array) {
|
|
108
|
+
this.clear();
|
|
109
|
+
for (const entry of array) this.insert(entry);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.default = KeyedDB;
|
|
113
|
+
module.exports = KeyedDB;
|
|
114
|
+
module.exports.default = KeyedDB;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { caching: caching } = require("cache-manager");
|
|
4
|
+
const { proto: proto } = require("../../WAProto");
|
|
5
|
+
const { BufferJSON: BufferJSON, initAuthCreds: initAuthCreds } = require("../Utils");
|
|
6
|
+
const { default: logger } = require("../Utils/logger");
|
|
7
|
+
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
8
|
+
const defaultKey = (file) => `${sessionKey}:${file}`;
|
|
9
|
+
const databaseConn = await caching(store);
|
|
10
|
+
const writeData = async (file, data) => {
|
|
11
|
+
let ttl = undefined;
|
|
12
|
+
if (file === "creds") {
|
|
13
|
+
ttl = 63115200;
|
|
14
|
+
}
|
|
15
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, BufferJSON.replacer), ttl);
|
|
16
|
+
};
|
|
17
|
+
const readData = async (file) => {
|
|
18
|
+
try {
|
|
19
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
20
|
+
if (data) {
|
|
21
|
+
return JSON.parse(data, BufferJSON.reviver);
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
logger.error(error);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const removeData = async (file) => {
|
|
30
|
+
try {
|
|
31
|
+
return await databaseConn.del(defaultKey(file));
|
|
32
|
+
} catch (_a) {
|
|
33
|
+
logger.error(`Error removing ${file} from session ${sessionKey}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const clearState = async () => {
|
|
37
|
+
try {
|
|
38
|
+
const result = await databaseConn.store.keys(`${sessionKey}*`);
|
|
39
|
+
await Promise.all(result.map(async (key) => await databaseConn.del(key)));
|
|
40
|
+
} catch (err) {}
|
|
41
|
+
};
|
|
42
|
+
const creds = (await readData("creds")) || initAuthCreds();
|
|
43
|
+
return {
|
|
44
|
+
clearState: clearState,
|
|
45
|
+
saveCreds: () => writeData("creds", creds),
|
|
46
|
+
state: {
|
|
47
|
+
creds: creds,
|
|
48
|
+
keys: {
|
|
49
|
+
get: async (type, ids) => {
|
|
50
|
+
const data = {};
|
|
51
|
+
await Promise.all(
|
|
52
|
+
ids.map(async (id) => {
|
|
53
|
+
let value = await readData(`${type}-${id}`);
|
|
54
|
+
if (type === "app-state-sync-key" && value) {
|
|
55
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
56
|
+
}
|
|
57
|
+
data[id] = value;
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
return data;
|
|
61
|
+
},
|
|
62
|
+
set: async (data) => {
|
|
63
|
+
const tasks = [];
|
|
64
|
+
for (const category in data) {
|
|
65
|
+
for (const id in data[category]) {
|
|
66
|
+
const value = data[category][id];
|
|
67
|
+
const key = `${category}-${id}`;
|
|
68
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
await Promise.all(tasks);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
module.exports = { makeCacheManagerAuthState: makeCacheManagerAuthState };
|