@zervonexx/baileys 5.0.0 → 5.0.1
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 +22 -22
- package/README.md +4112 -4112
- package/WAProto/WAProtoCompile.js +322 -322
- package/WAProto/fetcher.js +67 -67
- package/WAProto/index.js +95 -95
- package/WAProto/parser.js +333 -333
- package/lib/Builders/AIRich.js +673 -673
- package/lib/Builders/auto.js +49 -49
- package/lib/Builders/base.js +144 -144
- package/lib/Builders/builders.js +588 -588
- package/lib/Builders/index.js +3 -3
- package/lib/Defaults/index.js +248 -248
- package/lib/Signal/index.js +2 -2
- package/lib/Signal/libsignal.js +526 -526
- package/lib/Signal/lid-mapping.js +282 -282
- package/lib/Socket/Client/index.js +1 -1
- package/lib/Socket/Client/types.js +9 -9
- package/lib/Socket/Client/websocket.js +83 -83
- package/lib/Socket/business.js +151 -151
- package/lib/Socket/chats.js +854 -854
- package/lib/Socket/communities.js +146 -146
- package/lib/Socket/groups.js +293 -293
- package/lib/Socket/index.js +14 -14
- package/lib/Socket/messages-recv.js +993 -993
- package/lib/Socket/messages-send.js +722 -722
- package/lib/Socket/mex.js +33 -33
- package/lib/Socket/newsletter.js +783 -783
- package/lib/Socket/registration.js +154 -154
- package/lib/Socket/socket.js +797 -797
- package/lib/Socket/spam-report.js +143 -143
- package/lib/Socket/username.js +81 -81
- package/lib/Socket/zervonex-handler.js +57 -57
- package/lib/Store/index.js +6 -6
- package/lib/Store/make-cache-manager-store.js +80 -80
- package/lib/Store/make-in-memory-store.js +426 -426
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Store/reporting-info-store.js +37 -37
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +14 -14
- package/lib/Types/Newsletter.js +99 -99
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +14 -14
- package/lib/Types/State.js +26 -26
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +30 -30
- package/lib/Utils/auth-utils.js +159 -159
- package/lib/Utils/baileys-event-stream.js +32 -32
- package/lib/Utils/bot-capabilities.js +40 -40
- package/lib/Utils/bot-planning-replay.js +43 -43
- package/lib/Utils/browser-utils.js +29 -29
- package/lib/Utils/business.js +74 -74
- package/lib/Utils/chat-utils.js +316 -316
- package/lib/Utils/companion-reg-client-utils.js +19 -19
- package/lib/Utils/consumer-application.js +37 -37
- package/lib/Utils/crypto.js +52 -52
- package/lib/Utils/cstoken.js +14 -14
- package/lib/Utils/decode-wa-message.js +199 -199
- package/lib/Utils/event-buffer.js +272 -272
- package/lib/Utils/extras.js +186 -186
- package/lib/Utils/generics.js +194 -194
- package/lib/Utils/history.js +50 -50
- package/lib/Utils/identity-change-handler.js +18 -18
- package/lib/Utils/index.js +40 -40
- package/lib/Utils/link-preview.js +50 -50
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/make-mutex.js +15 -15
- package/lib/Utils/message-composer.js +61 -61
- package/lib/Utils/message-retry-manager.js +47 -47
- package/lib/Utils/messages-media.js +501 -501
- package/lib/Utils/messages.js +942 -942
- package/lib/Utils/meta-ai-msmsg.js +121 -121
- package/lib/Utils/meta-compositing.js +74 -74
- package/lib/Utils/modern-messages.js +234 -234
- package/lib/Utils/native-flow.js +80 -80
- package/lib/Utils/noise-handler.js +160 -160
- package/lib/Utils/pre-key-manager.js +75 -75
- package/lib/Utils/process-message.js +400 -400
- package/lib/Utils/reporting-utils.js +170 -170
- package/lib/Utils/signal.js +166 -166
- package/lib/Utils/spam-report-utils.js +165 -165
- package/lib/Utils/sync-action-utils.js +33 -33
- package/lib/Utils/tc-token-utils.js +153 -153
- package/lib/Utils/use-keyv-auth-state.js +199 -199
- package/lib/Utils/use-multi-file-auth-state.js +83 -83
- package/lib/Utils/validate-connection.js +171 -171
- package/lib/WABinary/constants.js +1320 -1320
- package/lib/WABinary/decode.js +151 -151
- package/lib/WABinary/encode.js +139 -139
- package/lib/WABinary/generic-utils.js +202 -202
- package/lib/WABinary/index.js +6 -6
- package/lib/WABinary/jid-utils.js +235 -235
- package/lib/WABinary/types.js +4 -4
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -30
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -15
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -24
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -21
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -16
- package/lib/WAUSync/Protocols/index.js +12 -12
- package/lib/WAUSync/USyncQuery.js +88 -88
- package/lib/WAUSync/USyncUser.js +20 -20
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +191 -192
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export const USYNC_FEATURES = ['document', 'encrypt', 'encrypt_blist', 'encrypt_contact', 'encrypt_group_gen2', 'encrypt_image', 'encrypt_location', 'encrypt_url', 'encrypt_v2', 'voip', 'voip_legacy', 'multi_agent', 'bot_eligible'];
|
|
4
|
-
|
|
5
|
-
const CAMEL_MAP = { encrypt_v2: 'encryptV2', voip_legacy: 'voipLegacy', multi_agent: 'multiAgent', bot_eligible: 'botEligible', encrypt_blist: 'encryptBlist', encrypt_contact: 'encryptContact', encrypt_group_gen2: 'encryptGroupGen2', encrypt_image: 'encryptImage', encrypt_location: 'encryptLocation', encrypt_url: 'encryptUrl' };
|
|
6
|
-
|
|
7
|
-
export class USyncFeatureProtocol {
|
|
8
|
-
constructor(features) { this.name = 'feature'; this.features = features?.length ? features : USYNC_FEATURES; }
|
|
9
|
-
|
|
10
|
-
getQueryElement() { return { tag: 'feature', attrs: {}, content: this.features.map(f => ({ tag: f, attrs: {} })) }; }
|
|
11
|
-
|
|
12
|
-
getUserElement() { return null; }
|
|
13
|
-
|
|
14
|
-
parser(node) {
|
|
15
|
-
if (node.tag !== 'feature') return null;
|
|
16
|
-
const errorNode = getBinaryNodeChild(node, 'error');
|
|
17
|
-
if (errorNode) return { errorCode: errorNode.attrs?.code ? +errorNode.attrs.code : undefined, errorText: errorNode.attrs?.text };
|
|
18
|
-
const features = {};
|
|
19
|
-
for (const child of (Array.isArray(node.content) ? node.content : [])) {
|
|
20
|
-
if (child?.attrs && child.attrs.value !== undefined) features[CAMEL_MAP[child.tag] || child.tag] = child.attrs.value;
|
|
21
|
-
}
|
|
22
|
-
return features;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export const USYNC_FEATURES = ['document', 'encrypt', 'encrypt_blist', 'encrypt_contact', 'encrypt_group_gen2', 'encrypt_image', 'encrypt_location', 'encrypt_url', 'encrypt_v2', 'voip', 'voip_legacy', 'multi_agent', 'bot_eligible'];
|
|
4
|
+
|
|
5
|
+
const CAMEL_MAP = { encrypt_v2: 'encryptV2', voip_legacy: 'voipLegacy', multi_agent: 'multiAgent', bot_eligible: 'botEligible', encrypt_blist: 'encryptBlist', encrypt_contact: 'encryptContact', encrypt_group_gen2: 'encryptGroupGen2', encrypt_image: 'encryptImage', encrypt_location: 'encryptLocation', encrypt_url: 'encryptUrl' };
|
|
6
|
+
|
|
7
|
+
export class USyncFeatureProtocol {
|
|
8
|
+
constructor(features) { this.name = 'feature'; this.features = features?.length ? features : USYNC_FEATURES; }
|
|
9
|
+
|
|
10
|
+
getQueryElement() { return { tag: 'feature', attrs: {}, content: this.features.map(f => ({ tag: f, attrs: {} })) }; }
|
|
11
|
+
|
|
12
|
+
getUserElement() { return null; }
|
|
13
|
+
|
|
14
|
+
parser(node) {
|
|
15
|
+
if (node.tag !== 'feature') return null;
|
|
16
|
+
const errorNode = getBinaryNodeChild(node, 'error');
|
|
17
|
+
if (errorNode) return { errorCode: errorNode.attrs?.code ? +errorNode.attrs.code : undefined, errorText: errorNode.attrs?.text };
|
|
18
|
+
const features = {};
|
|
19
|
+
for (const child of (Array.isArray(node.content) ? node.content : [])) {
|
|
20
|
+
if (child?.attrs && child.attrs.value !== undefined) features[CAMEL_MAP[child.tag] || child.tag] = child.attrs.value;
|
|
21
|
+
}
|
|
22
|
+
return features;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export class USyncLIDProtocol {
|
|
2
|
-
constructor() { this.name = 'lid'; }
|
|
3
|
-
|
|
4
|
-
getQueryElement() { return { tag: 'lid', attrs: {} }; }
|
|
5
|
-
|
|
6
|
-
getUserElement(user) { return user.lid ? { tag: 'lid', attrs: { jid: user.lid } } : null; }
|
|
7
|
-
|
|
8
|
-
parser(node) { return node.tag === 'lid' ? node.attrs.val : null; }
|
|
9
|
-
}
|
|
1
|
+
export class USyncLIDProtocol {
|
|
2
|
+
constructor() { this.name = 'lid'; }
|
|
3
|
+
|
|
4
|
+
getQueryElement() { return { tag: 'lid', attrs: {} }; }
|
|
5
|
+
|
|
6
|
+
getUserElement(user) { return user.lid ? { tag: 'lid', attrs: { jid: user.lid } } : null; }
|
|
7
|
+
|
|
8
|
+
parser(node) { return node.tag === 'lid' ? node.attrs.val : null; }
|
|
9
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncPictureProtocol {
|
|
4
|
-
constructor(type = 'image') { this.name = 'picture'; this.type = type; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'picture', attrs: { type: this.type } }; }
|
|
7
|
-
|
|
8
|
-
getUserElement(user) {
|
|
9
|
-
const attrs = {};
|
|
10
|
-
if (user.pictureId != null) attrs.id = String(user.pictureId);
|
|
11
|
-
return Object.keys(attrs).length > 0 ? { tag: 'picture', attrs } : null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
parser(node) {
|
|
15
|
-
if (node.tag !== 'picture') return null;
|
|
16
|
-
assertNodeErrorFree(node);
|
|
17
|
-
const id = node.attrs?.id ?? null, directPath = node.attrs?.direct_path ?? null, hash = node.attrs?.hash ?? null;
|
|
18
|
-
if (!id && !directPath) return null;
|
|
19
|
-
return { id, directPath, hash };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncPictureProtocol {
|
|
4
|
+
constructor(type = 'image') { this.name = 'picture'; this.type = type; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'picture', attrs: { type: this.type } }; }
|
|
7
|
+
|
|
8
|
+
getUserElement(user) {
|
|
9
|
+
const attrs = {};
|
|
10
|
+
if (user.pictureId != null) attrs.id = String(user.pictureId);
|
|
11
|
+
return Object.keys(attrs).length > 0 ? { tag: 'picture', attrs } : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
parser(node) {
|
|
15
|
+
if (node.tag !== 'picture') return null;
|
|
16
|
+
assertNodeErrorFree(node);
|
|
17
|
+
const id = node.attrs?.id ?? null, directPath = node.attrs?.direct_path ?? null, hash = node.attrs?.hash ?? null;
|
|
18
|
+
if (!id && !directPath) return null;
|
|
19
|
+
return { id, directPath, hash };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncSidelistProtocol {
|
|
4
|
-
constructor(useLidAddressing = true) { this.name = 'sidelist'; this.useLidAddressing = useLidAddressing; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() {
|
|
7
|
-
const attrs = {};
|
|
8
|
-
if (this.useLidAddressing) attrs.addressing_mode = 'lid';
|
|
9
|
-
return { tag: 'sidelist', attrs };
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
getUserElement(user) { return user.sidelistDelete ? { tag: 'sidelist', attrs: { type: 'delete' } } : null; }
|
|
13
|
-
|
|
14
|
-
parser(node) {
|
|
15
|
-
if (node.tag !== 'sidelist' && node.tag !== 'side_list') return null;
|
|
16
|
-
assertNodeErrorFree(node);
|
|
17
|
-
return { type: node.attrs?.type ?? null };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncSidelistProtocol {
|
|
4
|
+
constructor(useLidAddressing = true) { this.name = 'sidelist'; this.useLidAddressing = useLidAddressing; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() {
|
|
7
|
+
const attrs = {};
|
|
8
|
+
if (this.useLidAddressing) attrs.addressing_mode = 'lid';
|
|
9
|
+
return { tag: 'sidelist', attrs };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getUserElement(user) { return user.sidelistDelete ? { tag: 'sidelist', attrs: { type: 'delete' } } : null; }
|
|
13
|
+
|
|
14
|
+
parser(node) {
|
|
15
|
+
if (node.tag !== 'sidelist' && node.tag !== 'side_list') return null;
|
|
16
|
+
assertNodeErrorFree(node);
|
|
17
|
+
return { type: node.attrs?.type ?? null };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncStatusProtocol {
|
|
4
|
-
constructor() { this.name = 'status'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'status', attrs: {} }; }
|
|
7
|
-
|
|
8
|
-
getUserElement() { return null; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
if (node.tag !== 'status') return;
|
|
12
|
-
assertNodeErrorFree(node);
|
|
13
|
-
const setAt = new Date(+(node.attrs.t || 0) * 1000);
|
|
14
|
-
let status = node.content?.toString() ?? null;
|
|
15
|
-
if (!status) status = (node.attrs?.code && +node.attrs.code === 401) ? '' : null;
|
|
16
|
-
else if (status.length === 0) status = null;
|
|
17
|
-
return { status, setAt };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncStatusProtocol {
|
|
4
|
+
constructor() { this.name = 'status'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'status', attrs: {} }; }
|
|
7
|
+
|
|
8
|
+
getUserElement() { return null; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
if (node.tag !== 'status') return;
|
|
12
|
+
assertNodeErrorFree(node);
|
|
13
|
+
const setAt = new Date(+(node.attrs.t || 0) * 1000);
|
|
14
|
+
let status = node.content?.toString() ?? null;
|
|
15
|
+
if (!status) status = (node.attrs?.code && +node.attrs.code === 401) ? '' : null;
|
|
16
|
+
else if (status.length === 0) status = null;
|
|
17
|
+
return { status, setAt };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncTextStatusProtocol {
|
|
4
|
-
constructor() { this.name = 'text_status'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'text_status', attrs: {} }; }
|
|
7
|
-
|
|
8
|
-
getUserElement() { return null; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
if (node.tag !== 'text_status') return null;
|
|
12
|
-
assertNodeErrorFree(node);
|
|
13
|
-
const lastUpdateTimeSec = node.attrs?.last_update_time ? +node.attrs.last_update_time : 0;
|
|
14
|
-
const ephemeralDurationSec = node.attrs?.ephemeral_duration_sec ? +node.attrs.ephemeral_duration_sec : 0;
|
|
15
|
-
return {
|
|
16
|
-
text: node.attrs?.text ?? null,
|
|
17
|
-
emoji: getBinaryNodeChild(node, 'emoji')?.attrs?.content ?? null,
|
|
18
|
-
setAt: new Date(lastUpdateTimeSec * 1000),
|
|
19
|
-
expiresAt: ephemeralDurationSec > 0 ? new Date((lastUpdateTimeSec + ephemeralDurationSec) * 1000) : null
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncTextStatusProtocol {
|
|
4
|
+
constructor() { this.name = 'text_status'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'text_status', attrs: {} }; }
|
|
7
|
+
|
|
8
|
+
getUserElement() { return null; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
if (node.tag !== 'text_status') return null;
|
|
12
|
+
assertNodeErrorFree(node);
|
|
13
|
+
const lastUpdateTimeSec = node.attrs?.last_update_time ? +node.attrs.last_update_time : 0;
|
|
14
|
+
const ephemeralDurationSec = node.attrs?.ephemeral_duration_sec ? +node.attrs.ephemeral_duration_sec : 0;
|
|
15
|
+
return {
|
|
16
|
+
text: node.attrs?.text ?? null,
|
|
17
|
+
emoji: getBinaryNodeChild(node, 'emoji')?.attrs?.content ?? null,
|
|
18
|
+
setAt: new Date(lastUpdateTimeSec * 1000),
|
|
19
|
+
expiresAt: ephemeralDurationSec > 0 ? new Date((lastUpdateTimeSec + ephemeralDurationSec) * 1000) : null
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncUsernameProtocol {
|
|
4
|
-
constructor() { this.name = 'username'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'username', attrs: {} }; }
|
|
7
|
-
|
|
8
|
-
getUserElement(user) { void user; return null; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
if (node.tag !== 'username') return null;
|
|
12
|
-
assertNodeErrorFree(node);
|
|
13
|
-
const username = node.content != null ? node.content.toString() : null;
|
|
14
|
-
return username && username.length > 0 ? username : null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncUsernameProtocol {
|
|
4
|
+
constructor() { this.name = 'username'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'username', attrs: {} }; }
|
|
7
|
+
|
|
8
|
+
getUserElement(user) { void user; return null; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
if (node.tag !== 'username') return null;
|
|
12
|
+
assertNodeErrorFree(node);
|
|
13
|
+
const username = node.content != null ? node.content.toString() : null;
|
|
14
|
+
return username && username.length > 0 ? username : null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './USyncDeviceProtocol.js';
|
|
2
|
-
export * from './USyncContactProtocol.js';
|
|
3
|
-
export * from './USyncStatusProtocol.js';
|
|
4
|
-
export * from './USyncDisappearingModeProtocol.js';
|
|
5
|
-
export * from './USyncUsernameProtocol.js';
|
|
6
|
-
export * from './USyncBotProfileProtocol.js';
|
|
7
|
-
export * from './USyncLIDProtocol.js';
|
|
8
|
-
export * from './USyncBusinessProtocol.js';
|
|
9
|
-
export * from './USyncPictureProtocol.js';
|
|
10
|
-
export * from './USyncTextStatusProtocol.js';
|
|
11
|
-
export * from './USyncSidelistProtocol.js';
|
|
12
|
-
export * from './USyncFeatureProtocol.js';
|
|
1
|
+
export * from './USyncDeviceProtocol.js';
|
|
2
|
+
export * from './USyncContactProtocol.js';
|
|
3
|
+
export * from './USyncStatusProtocol.js';
|
|
4
|
+
export * from './USyncDisappearingModeProtocol.js';
|
|
5
|
+
export * from './USyncUsernameProtocol.js';
|
|
6
|
+
export * from './USyncBotProfileProtocol.js';
|
|
7
|
+
export * from './USyncLIDProtocol.js';
|
|
8
|
+
export * from './USyncBusinessProtocol.js';
|
|
9
|
+
export * from './USyncPictureProtocol.js';
|
|
10
|
+
export * from './USyncTextStatusProtocol.js';
|
|
11
|
+
export * from './USyncSidelistProtocol.js';
|
|
12
|
+
export * from './USyncFeatureProtocol.js';
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
2
|
-
import {
|
|
3
|
-
USyncContactProtocol,
|
|
4
|
-
USyncDeviceProtocol,
|
|
5
|
-
USyncDisappearingModeProtocol,
|
|
6
|
-
USyncStatusProtocol,
|
|
7
|
-
USyncUsernameProtocol,
|
|
8
|
-
USyncBotProfileProtocol,
|
|
9
|
-
USyncLIDProtocol,
|
|
10
|
-
USyncBusinessProtocol,
|
|
11
|
-
USyncPictureProtocol,
|
|
12
|
-
USyncTextStatusProtocol,
|
|
13
|
-
USyncSidelistProtocol,
|
|
14
|
-
USyncFeatureProtocol,
|
|
15
|
-
} from './Protocols/index.js';
|
|
16
|
-
export class USyncQuery {
|
|
17
|
-
constructor() { this.protocols = []; this.users = []; this.context = 'interactive'; this.mode = 'query'; }
|
|
18
|
-
withMode(mode) { this.mode = mode; return this; }
|
|
19
|
-
withContext(context) { this.context = context; return this; }
|
|
20
|
-
withUser(user) { this.users.push(user); return this; }
|
|
21
|
-
parseUSyncQueryResult(result) {
|
|
22
|
-
if (!result || result.attrs.type !== 'result') return;
|
|
23
|
-
const protocolMap = Object.fromEntries(this.protocols.map(p => [p.name, p.parser.bind(p)]));
|
|
24
|
-
const queryResult = { errors: {}, refresh: {}, list: [], sideList: [] };
|
|
25
|
-
const usyncNode = getBinaryNodeChild(result, 'usync');
|
|
26
|
-
// Collect per-protocol errors and refresh hints from the result node
|
|
27
|
-
const resultNode = usyncNode ? getBinaryNodeChild(usyncNode, 'result') : undefined;
|
|
28
|
-
if (resultNode) {
|
|
29
|
-
for (const protocol of this.protocols) {
|
|
30
|
-
const pNode = getBinaryNodeChild(resultNode, protocol.name);
|
|
31
|
-
if (!pNode) continue;
|
|
32
|
-
const errorNode = getBinaryNodeChild(pNode, 'error');
|
|
33
|
-
if (errorNode) queryResult.errors[protocol.name] = { errorCode: errorNode.attrs.code ? +errorNode.attrs.code : undefined, errorText: errorNode.attrs.text, errorBackoff: errorNode.attrs.backoff ? +errorNode.attrs.backoff : undefined };
|
|
34
|
-
else if (pNode.attrs.refresh !== undefined) queryResult.refresh[protocol.name] = +pNode.attrs.refresh;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const parseUserNodes = nodes => nodes.reduce((acc, node) => {
|
|
38
|
-
const id = node?.attrs?.jid;
|
|
39
|
-
if (!id) return acc;
|
|
40
|
-
// 401/403/405 on the <user> node means blocked-by
|
|
41
|
-
const userErrCode = node.attrs?.error ? parseInt(node.attrs.error, 10) : 0;
|
|
42
|
-
const isBlockedByAttr = userErrCode === 401 || userErrCode === 403 || userErrCode === 405;
|
|
43
|
-
const data = Array.isArray(node.content)
|
|
44
|
-
? Object.fromEntries(node.content.map(content => {
|
|
45
|
-
const tag = content.tag;
|
|
46
|
-
// Extract privacy token inline without a registered protocol
|
|
47
|
-
if (tag === 'privacy') {
|
|
48
|
-
const tokenNode = getBinaryNodeChild(content, 'token');
|
|
49
|
-
const modeTsNode = getBinaryNodeChild(content, 'mode_ts');
|
|
50
|
-
const tokenVal = tokenNode?.content || content.attrs?.token;
|
|
51
|
-
if (!tokenVal) return ['privacy', null];
|
|
52
|
-
return ['privacy', { token: Buffer.isBuffer(tokenVal) || tokenVal instanceof Uint8Array ? Buffer.from(tokenVal) : tokenVal, modeTs: modeTsNode?.content?.toString?.() || modeTsNode?.attrs?.value || content.attrs?.mode_ts || null }];
|
|
53
|
-
}
|
|
54
|
-
const parser = protocolMap[tag];
|
|
55
|
-
if (!parser) return [tag, null];
|
|
56
|
-
try { return [tag, parser(content)]; }
|
|
57
|
-
catch (err) {
|
|
58
|
-
const code = err?.data ?? err?.output?.payload?.data;
|
|
59
|
-
if (code === 401 || code === 403 || code === 405) return ['isBlockedByContact', true];
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
62
|
-
}).filter(([, v]) => v !== null))
|
|
63
|
-
: {};
|
|
64
|
-
if (isBlockedByAttr) data.isBlockedByContact = true;
|
|
65
|
-
// Remap snake_case key to camelCase
|
|
66
|
-
if ('disappearing_mode' in data) { data.disappearingMode = data.disappearing_mode; delete data.disappearing_mode; }
|
|
67
|
-
acc.push({ ...data, id });
|
|
68
|
-
return acc;
|
|
69
|
-
}, []);
|
|
70
|
-
const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined;
|
|
71
|
-
const sideListNode = usyncNode ? getBinaryNodeChild(usyncNode, 'side_list') : undefined;
|
|
72
|
-
if (listNode?.content && Array.isArray(listNode.content)) queryResult.list = parseUserNodes(listNode.content);
|
|
73
|
-
if (sideListNode?.content && Array.isArray(sideListNode.content)) queryResult.sideList = parseUserNodes(sideListNode.content);
|
|
74
|
-
return queryResult;
|
|
75
|
-
}
|
|
76
|
-
withDeviceProtocol() { this.protocols.push(new USyncDeviceProtocol()); return this; }
|
|
77
|
-
withContactProtocol() { this.protocols.push(new USyncContactProtocol()); return this; }
|
|
78
|
-
withStatusProtocol() { this.protocols.push(new USyncStatusProtocol()); return this; }
|
|
79
|
-
withDisappearingModeProtocol() { this.protocols.push(new USyncDisappearingModeProtocol()); return this; }
|
|
80
|
-
withBotProfileProtocol() { this.protocols.push(new USyncBotProfileProtocol()); return this; }
|
|
81
|
-
withLIDProtocol() { this.protocols.push(new USyncLIDProtocol()); return this; }
|
|
82
|
-
withUsernameProtocol() { this.protocols.push(new USyncUsernameProtocol()); return this; }
|
|
83
|
-
withBusinessProtocol(profileVersion) { this.protocols.push(new USyncBusinessProtocol(profileVersion)); return this; }
|
|
84
|
-
withPictureProtocol(type) { this.protocols.push(new USyncPictureProtocol(type)); return this; }
|
|
85
|
-
withTextStatusProtocol() { this.protocols.push(new USyncTextStatusProtocol()); return this; }
|
|
86
|
-
withSidelistProtocol(useLidAddressing) { this.protocols.push(new USyncSidelistProtocol(useLidAddressing)); return this; }
|
|
87
|
-
withFeatureProtocol(features) { this.protocols.push(new USyncFeatureProtocol(features)); return this; }
|
|
88
|
-
}
|
|
1
|
+
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
2
|
+
import {
|
|
3
|
+
USyncContactProtocol,
|
|
4
|
+
USyncDeviceProtocol,
|
|
5
|
+
USyncDisappearingModeProtocol,
|
|
6
|
+
USyncStatusProtocol,
|
|
7
|
+
USyncUsernameProtocol,
|
|
8
|
+
USyncBotProfileProtocol,
|
|
9
|
+
USyncLIDProtocol,
|
|
10
|
+
USyncBusinessProtocol,
|
|
11
|
+
USyncPictureProtocol,
|
|
12
|
+
USyncTextStatusProtocol,
|
|
13
|
+
USyncSidelistProtocol,
|
|
14
|
+
USyncFeatureProtocol,
|
|
15
|
+
} from './Protocols/index.js';
|
|
16
|
+
export class USyncQuery {
|
|
17
|
+
constructor() { this.protocols = []; this.users = []; this.context = 'interactive'; this.mode = 'query'; }
|
|
18
|
+
withMode(mode) { this.mode = mode; return this; }
|
|
19
|
+
withContext(context) { this.context = context; return this; }
|
|
20
|
+
withUser(user) { this.users.push(user); return this; }
|
|
21
|
+
parseUSyncQueryResult(result) {
|
|
22
|
+
if (!result || result.attrs.type !== 'result') return;
|
|
23
|
+
const protocolMap = Object.fromEntries(this.protocols.map(p => [p.name, p.parser.bind(p)]));
|
|
24
|
+
const queryResult = { errors: {}, refresh: {}, list: [], sideList: [] };
|
|
25
|
+
const usyncNode = getBinaryNodeChild(result, 'usync');
|
|
26
|
+
// Collect per-protocol errors and refresh hints from the result node
|
|
27
|
+
const resultNode = usyncNode ? getBinaryNodeChild(usyncNode, 'result') : undefined;
|
|
28
|
+
if (resultNode) {
|
|
29
|
+
for (const protocol of this.protocols) {
|
|
30
|
+
const pNode = getBinaryNodeChild(resultNode, protocol.name);
|
|
31
|
+
if (!pNode) continue;
|
|
32
|
+
const errorNode = getBinaryNodeChild(pNode, 'error');
|
|
33
|
+
if (errorNode) queryResult.errors[protocol.name] = { errorCode: errorNode.attrs.code ? +errorNode.attrs.code : undefined, errorText: errorNode.attrs.text, errorBackoff: errorNode.attrs.backoff ? +errorNode.attrs.backoff : undefined };
|
|
34
|
+
else if (pNode.attrs.refresh !== undefined) queryResult.refresh[protocol.name] = +pNode.attrs.refresh;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const parseUserNodes = nodes => nodes.reduce((acc, node) => {
|
|
38
|
+
const id = node?.attrs?.jid;
|
|
39
|
+
if (!id) return acc;
|
|
40
|
+
// 401/403/405 on the <user> node means blocked-by
|
|
41
|
+
const userErrCode = node.attrs?.error ? parseInt(node.attrs.error, 10) : 0;
|
|
42
|
+
const isBlockedByAttr = userErrCode === 401 || userErrCode === 403 || userErrCode === 405;
|
|
43
|
+
const data = Array.isArray(node.content)
|
|
44
|
+
? Object.fromEntries(node.content.map(content => {
|
|
45
|
+
const tag = content.tag;
|
|
46
|
+
// Extract privacy token inline without a registered protocol
|
|
47
|
+
if (tag === 'privacy') {
|
|
48
|
+
const tokenNode = getBinaryNodeChild(content, 'token');
|
|
49
|
+
const modeTsNode = getBinaryNodeChild(content, 'mode_ts');
|
|
50
|
+
const tokenVal = tokenNode?.content || content.attrs?.token;
|
|
51
|
+
if (!tokenVal) return ['privacy', null];
|
|
52
|
+
return ['privacy', { token: Buffer.isBuffer(tokenVal) || tokenVal instanceof Uint8Array ? Buffer.from(tokenVal) : tokenVal, modeTs: modeTsNode?.content?.toString?.() || modeTsNode?.attrs?.value || content.attrs?.mode_ts || null }];
|
|
53
|
+
}
|
|
54
|
+
const parser = protocolMap[tag];
|
|
55
|
+
if (!parser) return [tag, null];
|
|
56
|
+
try { return [tag, parser(content)]; }
|
|
57
|
+
catch (err) {
|
|
58
|
+
const code = err?.data ?? err?.output?.payload?.data;
|
|
59
|
+
if (code === 401 || code === 403 || code === 405) return ['isBlockedByContact', true];
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}).filter(([, v]) => v !== null))
|
|
63
|
+
: {};
|
|
64
|
+
if (isBlockedByAttr) data.isBlockedByContact = true;
|
|
65
|
+
// Remap snake_case key to camelCase
|
|
66
|
+
if ('disappearing_mode' in data) { data.disappearingMode = data.disappearing_mode; delete data.disappearing_mode; }
|
|
67
|
+
acc.push({ ...data, id });
|
|
68
|
+
return acc;
|
|
69
|
+
}, []);
|
|
70
|
+
const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined;
|
|
71
|
+
const sideListNode = usyncNode ? getBinaryNodeChild(usyncNode, 'side_list') : undefined;
|
|
72
|
+
if (listNode?.content && Array.isArray(listNode.content)) queryResult.list = parseUserNodes(listNode.content);
|
|
73
|
+
if (sideListNode?.content && Array.isArray(sideListNode.content)) queryResult.sideList = parseUserNodes(sideListNode.content);
|
|
74
|
+
return queryResult;
|
|
75
|
+
}
|
|
76
|
+
withDeviceProtocol() { this.protocols.push(new USyncDeviceProtocol()); return this; }
|
|
77
|
+
withContactProtocol() { this.protocols.push(new USyncContactProtocol()); return this; }
|
|
78
|
+
withStatusProtocol() { this.protocols.push(new USyncStatusProtocol()); return this; }
|
|
79
|
+
withDisappearingModeProtocol() { this.protocols.push(new USyncDisappearingModeProtocol()); return this; }
|
|
80
|
+
withBotProfileProtocol() { this.protocols.push(new USyncBotProfileProtocol()); return this; }
|
|
81
|
+
withLIDProtocol() { this.protocols.push(new USyncLIDProtocol()); return this; }
|
|
82
|
+
withUsernameProtocol() { this.protocols.push(new USyncUsernameProtocol()); return this; }
|
|
83
|
+
withBusinessProtocol(profileVersion) { this.protocols.push(new USyncBusinessProtocol(profileVersion)); return this; }
|
|
84
|
+
withPictureProtocol(type) { this.protocols.push(new USyncPictureProtocol(type)); return this; }
|
|
85
|
+
withTextStatusProtocol() { this.protocols.push(new USyncTextStatusProtocol()); return this; }
|
|
86
|
+
withSidelistProtocol(useLidAddressing) { this.protocols.push(new USyncSidelistProtocol(useLidAddressing)); return this; }
|
|
87
|
+
withFeatureProtocol(features) { this.protocols.push(new USyncFeatureProtocol(features)); return this; }
|
|
88
|
+
}
|
package/lib/WAUSync/USyncUser.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export class USyncUser {
|
|
2
|
-
withId(id) { this.id = id; return this; }
|
|
3
|
-
withLid(lid) { this.lid = lid; return this; }
|
|
4
|
-
withPhone(phone) { this.phone = phone; return this; }
|
|
5
|
-
withUsername(username) { this.username = username; return this; }
|
|
6
|
-
withUsernameKey(usernameKey) { this.usernameKey = usernameKey; return this; }
|
|
7
|
-
withType(type) { this.type = type; return this; }
|
|
8
|
-
withPersonaId(personaId) { this.personaId = personaId; return this; }
|
|
9
|
-
withPictureId(pictureId) { this.pictureId = pictureId; return this; }
|
|
10
|
-
withTcToken(tcToken) { this.tcToken = tcToken; return this; }
|
|
11
|
-
withPnJid(pnJid) { this.pnJid = pnJid; return this; }
|
|
12
|
-
withDeviceHash(deviceHash) { this.deviceHash = deviceHash; return this; }
|
|
13
|
-
withTs(ts) { this.ts = ts; return this; }
|
|
14
|
-
withExpectedTs(expectedTs) { this.expectedTs = expectedTs; return this; }
|
|
15
|
-
withVerifiedNameSerial(serial) { this.verifiedNameSerial = serial; return this; }
|
|
16
|
-
withBusinessProfileTag(tag) { this.businessProfileTag = tag; return this; }
|
|
17
|
-
withSidelistDelete(del = true) { this.sidelistDelete = del; return this; }
|
|
18
|
-
// At least one addressable field required for a valid usync user
|
|
19
|
-
validate() { return !!(this.id || this.phone || this.username || this.pnJid); }
|
|
20
|
-
}
|
|
1
|
+
export class USyncUser {
|
|
2
|
+
withId(id) { this.id = id; return this; }
|
|
3
|
+
withLid(lid) { this.lid = lid; return this; }
|
|
4
|
+
withPhone(phone) { this.phone = phone; return this; }
|
|
5
|
+
withUsername(username) { this.username = username; return this; }
|
|
6
|
+
withUsernameKey(usernameKey) { this.usernameKey = usernameKey; return this; }
|
|
7
|
+
withType(type) { this.type = type; return this; }
|
|
8
|
+
withPersonaId(personaId) { this.personaId = personaId; return this; }
|
|
9
|
+
withPictureId(pictureId) { this.pictureId = pictureId; return this; }
|
|
10
|
+
withTcToken(tcToken) { this.tcToken = tcToken; return this; }
|
|
11
|
+
withPnJid(pnJid) { this.pnJid = pnJid; return this; }
|
|
12
|
+
withDeviceHash(deviceHash) { this.deviceHash = deviceHash; return this; }
|
|
13
|
+
withTs(ts) { this.ts = ts; return this; }
|
|
14
|
+
withExpectedTs(expectedTs) { this.expectedTs = expectedTs; return this; }
|
|
15
|
+
withVerifiedNameSerial(serial) { this.verifiedNameSerial = serial; return this; }
|
|
16
|
+
withBusinessProfileTag(tag) { this.businessProfileTag = tag; return this; }
|
|
17
|
+
withSidelistDelete(del = true) { this.sidelistDelete = del; return this; }
|
|
18
|
+
// At least one addressable field required for a valid usync user
|
|
19
|
+
validate() { return !!(this.id || this.phone || this.username || this.pnJid); }
|
|
20
|
+
}
|
package/lib/WAUSync/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './Protocols/index.js';
|
|
2
|
-
export * from './USyncQuery.js';
|
|
3
|
-
export * from './USyncUser.js';
|
|
1
|
+
export * from './Protocols/index.js';
|
|
2
|
+
export * from './USyncQuery.js';
|
|
3
|
+
export * from './USyncUser.js';
|