jagproject 26.3.22 → 26.3.25
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 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +51 -33
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1184 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1099 -400
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +10 -6
- package/readme.md +97 -0
- package/LICENSE +0 -21
package/lib/Socket/usync.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeUSyncSocket = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const index_js_1 = require("../WABinary/index.js");
|
|
6
|
+
const socket_js_1 = require("./socket.js");
|
|
7
7
|
const makeUSyncSocket = (config) => {
|
|
8
|
-
const sock = (0,
|
|
9
|
-
const { generateMessageTag, query
|
|
8
|
+
const sock = (0, socket_js_1.makeSocket)(config);
|
|
9
|
+
const { generateMessageTag, query } = sock;
|
|
10
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
11
|
if (usyncQuery.protocols.length === 0) {
|
|
12
12
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
@@ -38,7 +38,7 @@ const makeUSyncSocket = (config) => {
|
|
|
38
38
|
const iq = {
|
|
39
39
|
tag: 'iq',
|
|
40
40
|
attrs: {
|
|
41
|
-
to:
|
|
41
|
+
to: index_js_1.S_WHATSAPP_NET,
|
|
42
42
|
type: 'get',
|
|
43
43
|
xmlns: 'usync',
|
|
44
44
|
},
|
|
@@ -64,7 +64,7 @@ const makeUSyncSocket = (config) => {
|
|
|
64
64
|
};
|
|
65
65
|
return {
|
|
66
66
|
...sock,
|
|
67
|
-
executeUSyncQuery
|
|
67
|
+
executeUSyncQuery
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
70
|
exports.makeUSyncSocket = makeUSyncSocket;
|
package/lib/Store/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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);
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
__exportStar(require("./make-cache-manager-store.js"), exports);
|
|
18
|
+
__exportStar(require("./make-in-memory-store.js"), exports);
|
|
19
|
+
__exportStar(require("./make-ordered-dictionary.js"), exports);
|
|
20
|
+
__exportStar(require("./object-repository.js"), exports);
|
|
@@ -0,0 +1,83 @@
|
|
|
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.makeCacheManagerAuthState = void 0;
|
|
7
|
+
const cache_manager_1 = require("cache-manager");
|
|
8
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
9
|
+
const index_js_2 = require("../Utils/index.js");
|
|
10
|
+
const logger_js_1 = __importDefault(require("../Utils/logger.js"));
|
|
11
|
+
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
12
|
+
const defaultKey = (file) => `${sessionKey}:${file}`;
|
|
13
|
+
const databaseConn = await (0, cache_manager_1.caching)(store);
|
|
14
|
+
const writeData = async (file, data) => {
|
|
15
|
+
let ttl = undefined;
|
|
16
|
+
if (file === 'creds') {
|
|
17
|
+
ttl = 63115200; // 2 years
|
|
18
|
+
}
|
|
19
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, index_js_2.BufferJSON.replacer), ttl);
|
|
20
|
+
};
|
|
21
|
+
const readData = async (file) => {
|
|
22
|
+
try {
|
|
23
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
24
|
+
if (data) {
|
|
25
|
+
return JSON.parse(data, index_js_2.BufferJSON.reviver);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
logger_js_1.default.error(error);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const removeData = async (file) => {
|
|
35
|
+
try {
|
|
36
|
+
return await databaseConn.del(defaultKey(file));
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
logger_js_1.default.error(`Error removing ${file} from session ${sessionKey}`);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const clearState = async () => {
|
|
43
|
+
try {
|
|
44
|
+
const result = await databaseConn.store.keys(`${sessionKey}*`);
|
|
45
|
+
await Promise.all(result.map(async (key) => await databaseConn.del(key)));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const creds = (await readData('creds')) || (0, index_js_2.initAuthCreds)();
|
|
51
|
+
return {
|
|
52
|
+
clearState,
|
|
53
|
+
saveCreds: () => writeData('creds', creds),
|
|
54
|
+
state: {
|
|
55
|
+
creds,
|
|
56
|
+
keys: {
|
|
57
|
+
get: async (type, ids) => {
|
|
58
|
+
const data = {};
|
|
59
|
+
await Promise.all(ids.map(async (id) => {
|
|
60
|
+
let value = await readData(`${type}-${id}`);
|
|
61
|
+
if (type === 'app-state-sync-key' && value) {
|
|
62
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
63
|
+
}
|
|
64
|
+
data[id] = value;
|
|
65
|
+
}));
|
|
66
|
+
return data;
|
|
67
|
+
},
|
|
68
|
+
set: async (data) => {
|
|
69
|
+
const tasks = [];
|
|
70
|
+
for (const category in data) {
|
|
71
|
+
for (const id in data[category]) {
|
|
72
|
+
const value = data[category][id];
|
|
73
|
+
const key = `${category}-${id}`;
|
|
74
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await Promise.all(tasks);
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.makeCacheManagerAuthState = makeCacheManagerAuthState;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.waLabelAssociationKey = exports.waMessageID = exports.waChatKey = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
3
|
+
exports.makeInMemoryStore = exports.waLabelAssociationKey = exports.waMessageID = exports.waChatKey = void 0;
|
|
4
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
5
|
+
const index_js_2 = require("../Defaults/index.js");
|
|
6
|
+
const LabelAssociation_js_1 = require("../Types/LabelAssociation.js");
|
|
7
|
+
const index_js_3 = require("../Utils/index.js");
|
|
8
|
+
const index_js_4 = require("../WABinary/index.js");
|
|
9
|
+
const make_ordered_dictionary_js_1 = require("./make-ordered-dictionary.js");
|
|
10
|
+
const object_repository_js_1 = require("./object-repository.js");
|
|
14
11
|
const waChatKey = (pin) => ({
|
|
15
12
|
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
16
13
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
@@ -19,15 +16,15 @@ exports.waChatKey = waChatKey;
|
|
|
19
16
|
const waMessageID = (m) => m.key.id || '';
|
|
20
17
|
exports.waMessageID = waMessageID;
|
|
21
18
|
exports.waLabelAssociationKey = {
|
|
22
|
-
key: (la) => (la.type ===
|
|
19
|
+
key: (la) => (la.type === LabelAssociation_js_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
23
20
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
24
21
|
};
|
|
25
|
-
const makeMessagesDictionary = () => (0,
|
|
26
|
-
|
|
22
|
+
const makeMessagesDictionary = () => (0, make_ordered_dictionary_js_1.makeOrderedDictionary)(exports.waMessageID);
|
|
23
|
+
const makeInMemoryStore = (config) => {
|
|
27
24
|
const socket = config.socket;
|
|
28
25
|
const chatKey = config.chatKey || (0, exports.waChatKey)(true);
|
|
29
26
|
const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
|
|
30
|
-
const logger = config.logger ||
|
|
27
|
+
const logger = config.logger || index_js_2.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
28
|
const KeyedDB = require('@adiwajshing/keyed-db').default;
|
|
32
29
|
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
30
|
const messages = {};
|
|
@@ -35,7 +32,7 @@ exports.default = (config) => {
|
|
|
35
32
|
const groupMetadata = {};
|
|
36
33
|
const presences = {};
|
|
37
34
|
const state = { connection: 'close' };
|
|
38
|
-
const labels = new
|
|
35
|
+
const labels = new object_repository_js_1.ObjectRepository();
|
|
39
36
|
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
|
|
40
37
|
const assertMessageList = (jid) => {
|
|
41
38
|
if (!messages[jid]) {
|
|
@@ -56,16 +53,8 @@ exports.default = (config) => {
|
|
|
56
53
|
labels.upsertById(label.id, label);
|
|
57
54
|
}
|
|
58
55
|
};
|
|
59
|
-
const getValidContacts = () => {
|
|
60
|
-
for (const contact of Object.keys(contacts)) {
|
|
61
|
-
if (contact.indexOf('@') < 0) {
|
|
62
|
-
delete contacts[contact];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Object.keys(contacts);
|
|
66
|
-
};
|
|
67
56
|
/**
|
|
68
|
-
* binds to a
|
|
57
|
+
* binds to a BaileysEventEmitter.
|
|
69
58
|
* It listens to all events and constructs a state that you can query accurate data from.
|
|
70
59
|
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
71
60
|
* @param ev typically the event emitter from the socket connection
|
|
@@ -75,9 +64,8 @@ exports.default = (config) => {
|
|
|
75
64
|
Object.assign(state, update);
|
|
76
65
|
});
|
|
77
66
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
78
|
-
if (syncType ===
|
|
79
|
-
return; // FOR NOW,
|
|
80
|
-
//TODO: HANDLE
|
|
67
|
+
if (syncType === index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
68
|
+
return; // FOR NOW, TODO: HANDLE
|
|
81
69
|
}
|
|
82
70
|
if (isLatest) {
|
|
83
71
|
chats.clear();
|
|
@@ -105,32 +93,30 @@ exports.default = (config) => {
|
|
|
105
93
|
contactsUpsert(contacts);
|
|
106
94
|
});
|
|
107
95
|
ev.on('contacts.update', async (updates) => {
|
|
108
|
-
var _a;
|
|
109
96
|
for (const update of updates) {
|
|
110
97
|
let contact;
|
|
111
98
|
if (contacts[update.id]) {
|
|
112
99
|
contact = contacts[update.id];
|
|
113
100
|
}
|
|
114
101
|
else {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
|
102
|
+
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
103
|
+
const { user } = (0, index_js_4.jidDecode)(contactId);
|
|
104
|
+
return [contactId, (await (0, index_js_3.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
|
105
|
+
}));
|
|
106
|
+
contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''];
|
|
121
107
|
}
|
|
122
108
|
if (contact) {
|
|
123
109
|
if (update.imgUrl === 'changed') {
|
|
124
|
-
contact.imgUrl = socket ? await
|
|
110
|
+
contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined;
|
|
125
111
|
}
|
|
126
112
|
else if (update.imgUrl === 'removed') {
|
|
127
113
|
delete contact.imgUrl;
|
|
128
114
|
}
|
|
129
|
-
Object.assign(contacts[contact.id], contact);
|
|
130
115
|
}
|
|
131
116
|
else {
|
|
132
|
-
logger.debug({ update }, 'got update for non-existant contact');
|
|
117
|
+
return logger.debug({ update }, 'got update for non-existant contact');
|
|
133
118
|
}
|
|
119
|
+
Object.assign(contacts[contact.id], contact);
|
|
134
120
|
}
|
|
135
121
|
});
|
|
136
122
|
ev.on('chats.upsert', newChats => {
|
|
@@ -188,14 +174,14 @@ exports.default = (config) => {
|
|
|
188
174
|
case 'append':
|
|
189
175
|
case 'notify':
|
|
190
176
|
for (const msg of newMessages) {
|
|
191
|
-
const jid = (0,
|
|
177
|
+
const jid = (0, index_js_4.jidNormalizedUser)(msg.key.remoteJid);
|
|
192
178
|
const list = assertMessageList(jid);
|
|
193
179
|
list.upsert(msg, 'append');
|
|
194
180
|
if (type === 'notify' && !chats.get(jid)) {
|
|
195
181
|
ev.emit('chats.upsert', [
|
|
196
182
|
{
|
|
197
183
|
id: jid,
|
|
198
|
-
conversationTimestamp: (0,
|
|
184
|
+
conversationTimestamp: (0, index_js_3.toNumber)(msg.messageTimestamp),
|
|
199
185
|
unreadCount: 1
|
|
200
186
|
}
|
|
201
187
|
]);
|
|
@@ -205,12 +191,11 @@ exports.default = (config) => {
|
|
|
205
191
|
}
|
|
206
192
|
});
|
|
207
193
|
ev.on('messages.update', updates => {
|
|
208
|
-
var _a;
|
|
209
194
|
for (const { update, key } of updates) {
|
|
210
|
-
const list = assertMessageList((0,
|
|
211
|
-
if (update
|
|
212
|
-
const listStatus =
|
|
213
|
-
if (listStatus &&
|
|
195
|
+
const list = assertMessageList((0, index_js_4.jidNormalizedUser)(key.remoteJid));
|
|
196
|
+
if (update?.status) {
|
|
197
|
+
const listStatus = list.get(key.id)?.status;
|
|
198
|
+
if (listStatus && update?.status <= listStatus) {
|
|
214
199
|
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
|
|
215
200
|
delete update.status;
|
|
216
201
|
logger.debug({ update }, 'new update object');
|
|
@@ -225,7 +210,7 @@ exports.default = (config) => {
|
|
|
225
210
|
ev.on('messages.delete', item => {
|
|
226
211
|
if ('all' in item) {
|
|
227
212
|
const list = messages[item.jid];
|
|
228
|
-
list
|
|
213
|
+
list?.clear();
|
|
229
214
|
}
|
|
230
215
|
else {
|
|
231
216
|
const jid = item.keys[0].remoteJid;
|
|
@@ -271,18 +256,18 @@ exports.default = (config) => {
|
|
|
271
256
|
ev.on('message-receipt.update', updates => {
|
|
272
257
|
for (const { key, receipt } of updates) {
|
|
273
258
|
const obj = messages[key.remoteJid];
|
|
274
|
-
const msg = obj
|
|
259
|
+
const msg = obj?.get(key.id);
|
|
275
260
|
if (msg) {
|
|
276
|
-
(0,
|
|
261
|
+
(0, index_js_3.updateMessageWithReceipt)(msg, receipt);
|
|
277
262
|
}
|
|
278
263
|
}
|
|
279
264
|
});
|
|
280
265
|
ev.on('messages.reaction', (reactions) => {
|
|
281
266
|
for (const { key, reaction } of reactions) {
|
|
282
267
|
const obj = messages[key.remoteJid];
|
|
283
|
-
const msg = obj
|
|
268
|
+
const msg = obj?.get(key.id);
|
|
284
269
|
if (msg) {
|
|
285
|
-
(0,
|
|
270
|
+
(0, index_js_3.updateMessageWithReaction)(msg, reaction);
|
|
286
271
|
}
|
|
287
272
|
}
|
|
288
273
|
});
|
|
@@ -302,7 +287,7 @@ exports.default = (config) => {
|
|
|
302
287
|
for (const jid in json.messages) {
|
|
303
288
|
const list = assertMessageList(jid);
|
|
304
289
|
for (const msg of json.messages[jid]) {
|
|
305
|
-
list.upsert(
|
|
290
|
+
list.upsert(index_js_1.proto.WebMessageInfo.fromObject(msg), 'append');
|
|
306
291
|
}
|
|
307
292
|
}
|
|
308
293
|
};
|
|
@@ -325,7 +310,7 @@ exports.default = (config) => {
|
|
|
325
310
|
let messages;
|
|
326
311
|
if (list && mode === 'before' && (!cursorKey || cursorValue)) {
|
|
327
312
|
if (cursorValue) {
|
|
328
|
-
const msgIdx = list.array.findIndex(m => m.key.id ===
|
|
313
|
+
const msgIdx = list.array.findIndex(m => m.key.id === cursorKey?.id);
|
|
329
314
|
messages = list.array.slice(0, msgIdx);
|
|
330
315
|
}
|
|
331
316
|
else {
|
|
@@ -343,16 +328,12 @@ exports.default = (config) => {
|
|
|
343
328
|
},
|
|
344
329
|
/**
|
|
345
330
|
* Get all available labels for profile
|
|
346
|
-
*
|
|
347
|
-
* Keep in mind that the list is formed from predefined tags and tags
|
|
348
|
-
* that were "caught" during their editing.
|
|
349
331
|
*/
|
|
350
332
|
getLabels: () => {
|
|
351
333
|
return labels;
|
|
352
334
|
},
|
|
353
335
|
/**
|
|
354
336
|
* Get labels for chat
|
|
355
|
-
*
|
|
356
337
|
* @returns Label IDs
|
|
357
338
|
**/
|
|
358
339
|
getChatLabels: (chatId) => {
|
|
@@ -360,7 +341,6 @@ exports.default = (config) => {
|
|
|
360
341
|
},
|
|
361
342
|
/**
|
|
362
343
|
* Get labels for message
|
|
363
|
-
*
|
|
364
344
|
* @returns Label IDs
|
|
365
345
|
**/
|
|
366
346
|
getMessageLabels: (messageId) => {
|
|
@@ -369,71 +349,50 @@ exports.default = (config) => {
|
|
|
369
349
|
.all();
|
|
370
350
|
return associations.map(({ labelId }) => labelId);
|
|
371
351
|
},
|
|
372
|
-
loadMessage: async (jid, id) =>
|
|
352
|
+
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
373
353
|
mostRecentMessage: async (jid) => {
|
|
374
|
-
|
|
375
|
-
const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
|
|
354
|
+
const message = messages[jid]?.array.slice(-1)[0];
|
|
376
355
|
return message;
|
|
377
356
|
},
|
|
378
357
|
fetchImageUrl: async (jid, sock) => {
|
|
379
358
|
const contact = contacts[jid];
|
|
380
359
|
if (!contact) {
|
|
381
|
-
return sock
|
|
360
|
+
return sock?.profilePictureUrl(jid);
|
|
382
361
|
}
|
|
383
362
|
if (typeof contact.imgUrl === 'undefined') {
|
|
384
|
-
contact.imgUrl = await
|
|
363
|
+
contact.imgUrl = await sock?.profilePictureUrl(jid);
|
|
385
364
|
}
|
|
386
365
|
return contact.imgUrl;
|
|
387
366
|
},
|
|
388
367
|
fetchGroupMetadata: async (jid, sock) => {
|
|
389
368
|
if (!groupMetadata[jid]) {
|
|
390
|
-
const metadata = await
|
|
369
|
+
const metadata = await sock?.groupMetadata(jid);
|
|
391
370
|
if (metadata) {
|
|
392
371
|
groupMetadata[jid] = metadata;
|
|
393
372
|
}
|
|
394
373
|
}
|
|
395
374
|
return groupMetadata[jid];
|
|
396
375
|
},
|
|
397
|
-
// fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
|
|
398
|
-
// if(!groupMetadata[jid]) {
|
|
399
|
-
// const metadata = await sock?.getBroadcastListInfo(jid)
|
|
400
|
-
// if(metadata) {
|
|
401
|
-
// groupMetadata[jid] = metadata
|
|
402
|
-
// }
|
|
403
|
-
// }
|
|
404
|
-
// return groupMetadata[jid]
|
|
405
|
-
// },
|
|
406
376
|
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
407
377
|
const list = messages[remoteJid];
|
|
408
|
-
const msg = list
|
|
409
|
-
return msg
|
|
378
|
+
const msg = list?.get(id);
|
|
379
|
+
return msg?.userReceipt;
|
|
410
380
|
},
|
|
411
381
|
toJSON,
|
|
412
382
|
fromJSON,
|
|
413
383
|
writeToFile: (path) => {
|
|
414
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
415
384
|
const { writeFileSync } = require('fs');
|
|
416
385
|
writeFileSync(path, JSON.stringify(toJSON()));
|
|
417
386
|
},
|
|
418
387
|
readFromFile: (path) => {
|
|
419
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
420
388
|
const { readFileSync, existsSync } = require('fs');
|
|
421
389
|
if (existsSync(path)) {
|
|
422
390
|
logger.debug({ path }, 'reading from file');
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const json = JSON.parse(jsonStr);
|
|
427
|
-
fromJSON(json);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
logger.warn({ path }, 'skipping empty json file');
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
catch (err) {
|
|
434
|
-
logger.warn({ path, err }, 'failed to parse json from file');
|
|
435
|
-
}
|
|
391
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
392
|
+
const json = JSON.parse(jsonStr);
|
|
393
|
+
fromJSON(json);
|
|
436
394
|
}
|
|
437
395
|
}
|
|
438
396
|
};
|
|
439
397
|
};
|
|
398
|
+
exports.makeInMemoryStore = makeInMemoryStore;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeOrderedDictionary = makeOrderedDictionary;
|
|
3
4
|
function makeOrderedDictionary(idGetter) {
|
|
4
5
|
const array = [];
|
|
5
6
|
const dict = {};
|
|
@@ -78,4 +79,3 @@ function makeOrderedDictionary(idGetter) {
|
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
|
-
exports.default = makeOrderedDictionary;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { Contact } from './Contact.js';
|
|
3
|
+
import type { MinimalMessage } from './Message.js';
|
|
4
|
+
export type KeyPair = {
|
|
5
|
+
public: Uint8Array;
|
|
6
|
+
private: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
export type SignedKeyPair = {
|
|
9
|
+
keyPair: KeyPair;
|
|
10
|
+
signature: Uint8Array;
|
|
11
|
+
keyId: number;
|
|
12
|
+
timestampS?: number;
|
|
13
|
+
};
|
|
14
|
+
export type ProtocolAddress = {
|
|
15
|
+
name: string;
|
|
16
|
+
deviceId: number;
|
|
17
|
+
};
|
|
18
|
+
export type SignalIdentity = {
|
|
19
|
+
identifier: ProtocolAddress;
|
|
20
|
+
identifierKey: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
export type LIDMapping = {
|
|
23
|
+
pn: string;
|
|
24
|
+
lid: string;
|
|
25
|
+
};
|
|
26
|
+
export type LTHashState = {
|
|
27
|
+
version: number;
|
|
28
|
+
hash: Buffer;
|
|
29
|
+
indexValueMap: {
|
|
30
|
+
[indexMacBase64: string]: {
|
|
31
|
+
valueMac: Uint8Array | Buffer;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type SignalCreds = {
|
|
36
|
+
readonly signedIdentityKey: KeyPair;
|
|
37
|
+
readonly signedPreKey: SignedKeyPair;
|
|
38
|
+
readonly registrationId: number;
|
|
39
|
+
};
|
|
40
|
+
export type AccountSettings = {
|
|
41
|
+
/** unarchive chats when a new message is received */
|
|
42
|
+
unarchiveChats: boolean;
|
|
43
|
+
/** the default mode to start new conversations with */
|
|
44
|
+
defaultDisappearingMode?: Pick<proto.IConversation, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>;
|
|
45
|
+
};
|
|
46
|
+
export type AuthenticationCreds = SignalCreds & {
|
|
47
|
+
readonly noiseKey: KeyPair;
|
|
48
|
+
readonly pairingEphemeralKeyPair: KeyPair;
|
|
49
|
+
advSecretKey: string;
|
|
50
|
+
me?: Contact;
|
|
51
|
+
account?: proto.IADVSignedDeviceIdentity;
|
|
52
|
+
signalIdentities?: SignalIdentity[];
|
|
53
|
+
myAppStateKeyId?: string;
|
|
54
|
+
firstUnuploadedPreKeyId: number;
|
|
55
|
+
nextPreKeyId: number;
|
|
56
|
+
lastAccountSyncTimestamp?: number;
|
|
57
|
+
platform?: string;
|
|
58
|
+
processedHistoryMessages: MinimalMessage[];
|
|
59
|
+
/** number of times history & app state has been synced */
|
|
60
|
+
accountSyncCounter: number;
|
|
61
|
+
accountSettings: AccountSettings;
|
|
62
|
+
registered: boolean;
|
|
63
|
+
pairingCode: string | undefined;
|
|
64
|
+
lastPropHash: string | undefined;
|
|
65
|
+
routingInfo: Buffer | undefined;
|
|
66
|
+
additionalData?: any | undefined;
|
|
67
|
+
};
|
|
68
|
+
export type SignalDataTypeMap = {
|
|
69
|
+
'pre-key': KeyPair;
|
|
70
|
+
session: Uint8Array;
|
|
71
|
+
'sender-key': Uint8Array;
|
|
72
|
+
'sender-key-memory': {
|
|
73
|
+
[jid: string]: boolean;
|
|
74
|
+
};
|
|
75
|
+
'app-state-sync-key': proto.Message.IAppStateSyncKeyData;
|
|
76
|
+
'app-state-sync-version': LTHashState;
|
|
77
|
+
'lid-mapping': string;
|
|
78
|
+
'device-list': string[];
|
|
79
|
+
tctoken: {
|
|
80
|
+
token: Buffer;
|
|
81
|
+
timestamp?: string;
|
|
82
|
+
};
|
|
83
|
+
'identity-key': Uint8Array;
|
|
84
|
+
};
|
|
85
|
+
export type SignalDataSet = {
|
|
86
|
+
[T in keyof SignalDataTypeMap]?: {
|
|
87
|
+
[id: string]: SignalDataTypeMap[T] | null;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type Awaitable<T> = T | Promise<T>;
|
|
91
|
+
export type SignalKeyStore = {
|
|
92
|
+
get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{
|
|
93
|
+
[id: string]: SignalDataTypeMap[T];
|
|
94
|
+
}>;
|
|
95
|
+
set(data: SignalDataSet): Awaitable<void>;
|
|
96
|
+
/** clear all the data in the store */
|
|
97
|
+
clear?(): Awaitable<void>;
|
|
98
|
+
};
|
|
99
|
+
export type SignalKeyStoreWithTransaction = SignalKeyStore & {
|
|
100
|
+
isInTransaction: () => boolean;
|
|
101
|
+
transaction<T>(exec: () => Promise<T>, key: string): Promise<T>;
|
|
102
|
+
};
|
|
103
|
+
export type TransactionCapabilityOptions = {
|
|
104
|
+
maxCommitRetries: number;
|
|
105
|
+
delayBetweenTriesMs: number;
|
|
106
|
+
};
|
|
107
|
+
export type SignalAuthState = {
|
|
108
|
+
creds: SignalCreds;
|
|
109
|
+
keys: SignalKeyStore | SignalKeyStoreWithTransaction;
|
|
110
|
+
};
|
|
111
|
+
export type AuthenticationState = {
|
|
112
|
+
creds: AuthenticationCreds;
|
|
113
|
+
keys: SignalKeyStore;
|
|
114
|
+
};
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=Auth.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto';
|
|
2
|
+
export type DayOfWeekBussines = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';
|
|
3
|
+
export type HoursDay = {
|
|
4
|
+
day: DayOfWeekBussines;
|
|
5
|
+
mode: 'specific_hours';
|
|
6
|
+
openTimeInMinutes: string;
|
|
7
|
+
closeTimeInMinutes: string;
|
|
8
|
+
} | {
|
|
9
|
+
day: DayOfWeekBussines;
|
|
10
|
+
mode: 'open_24h' | 'appointment_only';
|
|
11
|
+
};
|
|
12
|
+
export type UpdateBussinesProfileProps = {
|
|
13
|
+
address?: string;
|
|
14
|
+
websites?: string[];
|
|
15
|
+
email?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
hours?: {
|
|
18
|
+
timezone: string;
|
|
19
|
+
days: HoursDay[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type QuickReplyAction = proto.SyncActionValue.IQuickReplyAction & {
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=Bussines.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept' | 'terminate';
|
|
2
|
+
export type WACallEvent = {
|
|
3
|
+
chatId: string;
|
|
4
|
+
from: string;
|
|
5
|
+
callerPn?: string;
|
|
6
|
+
isGroup?: boolean;
|
|
7
|
+
groupJid?: string;
|
|
8
|
+
id: string;
|
|
9
|
+
date: Date;
|
|
10
|
+
isVideo?: boolean;
|
|
11
|
+
status: WACallUpdateType;
|
|
12
|
+
offline: boolean;
|
|
13
|
+
latencyMs?: number;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=Call.d.ts.map
|