@vanzxy/baileys 1.4.0 → 1.4.2

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.
Files changed (114) hide show
  1. package/cjs/WAProto/index.js +106053 -0
  2. package/cjs/lib/Defaults/index.js +168 -0
  3. package/cjs/lib/Signal/Group/ciphertext-message.js +16 -0
  4. package/cjs/lib/Signal/Group/group-session-builder.js +67 -0
  5. package/cjs/lib/Signal/Group/group_cipher.js +86 -0
  6. package/cjs/lib/Signal/Group/index.js +58 -0
  7. package/cjs/lib/Signal/Group/keyhelper.js +56 -0
  8. package/cjs/lib/Signal/Group/sender-chain-key.js +30 -0
  9. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +67 -0
  10. package/cjs/lib/Signal/Group/sender-key-message.js +70 -0
  11. package/cjs/lib/Signal/Group/sender-key-name.js +52 -0
  12. package/cjs/lib/Signal/Group/sender-key-record.js +45 -0
  13. package/cjs/lib/Signal/Group/sender-key-state.js +88 -0
  14. package/cjs/lib/Signal/Group/sender-message-key.js +30 -0
  15. package/cjs/lib/Signal/libsignal.js +467 -0
  16. package/cjs/lib/Signal/lid-mapping.js +281 -0
  17. package/cjs/lib/Socket/Client/index.js +19 -0
  18. package/cjs/lib/Socket/Client/types.js +15 -0
  19. package/cjs/lib/Socket/Client/websocket.js +61 -0
  20. package/cjs/lib/Socket/business.js +384 -0
  21. package/cjs/lib/Socket/chats.js +1257 -0
  22. package/cjs/lib/Socket/communities.js +442 -0
  23. package/cjs/lib/Socket/dugong.js +753 -0
  24. package/cjs/lib/Socket/groups.js +360 -0
  25. package/cjs/lib/Socket/index.js +19 -0
  26. package/cjs/lib/Socket/messages-recv.js +1790 -0
  27. package/cjs/lib/Socket/messages-send.js +1390 -0
  28. package/cjs/lib/Socket/mex.js +46 -0
  29. package/cjs/lib/Socket/newsletter.js +340 -0
  30. package/cjs/lib/Socket/socket.js +1007 -0
  31. package/cjs/lib/Store/index.js +20 -0
  32. package/cjs/lib/Store/make-in-memory-store.js +438 -0
  33. package/cjs/lib/Store/make-ordered-dictionary.js +82 -0
  34. package/cjs/lib/Store/object-repository.js +28 -0
  35. package/cjs/lib/Types/Auth.js +3 -0
  36. package/cjs/lib/Types/Bussines.js +3 -0
  37. package/cjs/lib/Types/Call.js +3 -0
  38. package/cjs/lib/Types/Chat.js +11 -0
  39. package/cjs/lib/Types/Contact.js +3 -0
  40. package/cjs/lib/Types/Events.js +4 -0
  41. package/cjs/lib/Types/GroupMetadata.js +3 -0
  42. package/cjs/lib/Types/Label.js +26 -0
  43. package/cjs/lib/Types/LabelAssociation.js +8 -0
  44. package/cjs/lib/Types/Message.js +19 -0
  45. package/cjs/lib/Types/Mex.js +40 -0
  46. package/cjs/lib/Types/Product.js +3 -0
  47. package/cjs/lib/Types/RichType.js +24 -0
  48. package/cjs/lib/Types/Signal.js +4 -0
  49. package/cjs/lib/Types/Socket.js +4 -0
  50. package/cjs/lib/Types/State.js +54 -0
  51. package/cjs/lib/Types/USync.js +4 -0
  52. package/cjs/lib/Types/index.js +42 -0
  53. package/cjs/lib/Utils/MessageBuilder.js +2164 -0
  54. package/cjs/lib/Utils/auth-utils.js +312 -0
  55. package/cjs/lib/Utils/browser-utils.js +32 -0
  56. package/cjs/lib/Utils/business.js +245 -0
  57. package/cjs/lib/Utils/chat-utils.js +937 -0
  58. package/cjs/lib/Utils/companion-reg-client-utils.js +45 -0
  59. package/cjs/lib/Utils/crypto.js +196 -0
  60. package/cjs/lib/Utils/decode-wa-message.js +324 -0
  61. package/cjs/lib/Utils/event-buffer.js +643 -0
  62. package/cjs/lib/Utils/generics.js +429 -0
  63. package/cjs/lib/Utils/history.js +151 -0
  64. package/cjs/lib/Utils/identity-change-handler.js +56 -0
  65. package/cjs/lib/Utils/index.js +42 -0
  66. package/cjs/lib/Utils/link-preview.js +122 -0
  67. package/cjs/lib/Utils/logger.js +8 -0
  68. package/cjs/lib/Utils/lt-hash.js +62 -0
  69. package/cjs/lib/Utils/make-mutex.js +38 -0
  70. package/cjs/lib/Utils/message-retry-manager.js +267 -0
  71. package/cjs/lib/Utils/messages-media.js +933 -0
  72. package/cjs/lib/Utils/messages.js +2175 -0
  73. package/cjs/lib/Utils/noise-handler.js +205 -0
  74. package/cjs/lib/Utils/offline-node-processor.js +43 -0
  75. package/cjs/lib/Utils/pre-key-manager.js +113 -0
  76. package/cjs/lib/Utils/process-message.js +772 -0
  77. package/cjs/lib/Utils/reporting-utils.js +263 -0
  78. package/cjs/lib/Utils/rich-message-utils.js +439 -0
  79. package/cjs/lib/Utils/signal.js +214 -0
  80. package/cjs/lib/Utils/stanza-ack.js +41 -0
  81. package/cjs/lib/Utils/sync-action-utils.js +54 -0
  82. package/cjs/lib/Utils/tc-token-utils.js +174 -0
  83. package/cjs/lib/Utils/use-multi-file-auth-state.js +125 -0
  84. package/cjs/lib/Utils/use-single-file-auth-state.js +121 -0
  85. package/cjs/lib/Utils/use-sqlite-auth-state.js +182 -0
  86. package/cjs/lib/Utils/validate-connection.js +210 -0
  87. package/cjs/lib/WABinary/constants.js +1470 -0
  88. package/cjs/lib/WABinary/decode.js +301 -0
  89. package/cjs/lib/WABinary/encode.js +257 -0
  90. package/cjs/lib/WABinary/generic-utils.js +274 -0
  91. package/cjs/lib/WABinary/index.js +22 -0
  92. package/cjs/lib/WABinary/jid-utils.js +114 -0
  93. package/cjs/lib/WABinary/types.js +37 -0
  94. package/cjs/lib/WAM/BinaryInfo.js +14 -0
  95. package/cjs/lib/WAM/constants.js +22856 -0
  96. package/cjs/lib/WAM/encode.js +154 -0
  97. package/cjs/lib/WAM/index.js +20 -0
  98. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  99. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +67 -0
  100. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  101. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  102. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +29 -0
  103. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +55 -0
  104. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
  105. package/cjs/lib/WAUSync/Protocols/index.js +24 -0
  106. package/cjs/lib/WAUSync/USyncQuery.js +126 -0
  107. package/cjs/lib/WAUSync/USyncUser.js +35 -0
  108. package/cjs/lib/WAUSync/index.js +20 -0
  109. package/cjs/lib/index.js +34 -0
  110. package/cjs/package.json +1 -0
  111. package/lib/Socket/messages-send.js +4 -3
  112. package/lib/Utils/messages.js +4 -1
  113. package/package.json +16 -5
  114. package/postinstall-banner.js +3 -2
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeWAM = void 0;
4
+ const BinaryInfo_js_1 = require("./BinaryInfo.js");
5
+ const constants_js_1 = require("./constants.js");
6
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
7
+ const encodeWAM = (binaryInfo) => {
8
+ binaryInfo.buffer = [];
9
+ encodeWAMHeader(binaryInfo);
10
+ encodeEvents(binaryInfo);
11
+ const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
12
+ const buffer = Buffer.alloc(totalSize);
13
+ let offset = 0;
14
+ for (const buffer_ of binaryInfo.buffer) {
15
+ buffer_.copy(buffer, offset);
16
+ offset += buffer_.length;
17
+ }
18
+ return buffer;
19
+ };
20
+ exports.encodeWAM = encodeWAM;
21
+ function encodeWAMHeader(binaryInfo) {
22
+ const headerBuffer = Buffer.alloc(8); // starting buffer
23
+ headerBuffer.write('WAM', 0, 'utf8');
24
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
25
+ headerBuffer.writeUInt8(1, 4); //random flag
26
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
27
+ headerBuffer.writeUInt8(0, 7); // regular channel
28
+ binaryInfo.buffer.push(headerBuffer);
29
+ }
30
+ function encodeGlobalAttributes(binaryInfo, globals) {
31
+ for (const [key, _value] of Object.entries(globals)) {
32
+ const id = constants_js_1.WEB_GLOBALS.find(a => a?.name === key).id;
33
+ let value = _value;
34
+ if (typeof value === 'boolean') {
35
+ value = value ? 1 : 0;
36
+ }
37
+ binaryInfo.buffer.push(serializeData(id, value, constants_js_1.FLAG_GLOBAL));
38
+ }
39
+ }
40
+ function encodeEvents(binaryInfo) {
41
+ for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
42
+ encodeGlobalAttributes(binaryInfo, globals);
43
+ const event = constants_js_1.WEB_EVENTS.find(a => a.name === name);
44
+ const props_ = Object.entries(props);
45
+ let extended = false;
46
+ for (const [, value] of props_) {
47
+ extended || (extended = value !== null);
48
+ }
49
+ const eventFlag = extended ? constants_js_1.FLAG_EVENT : constants_js_1.FLAG_EVENT | constants_js_1.FLAG_EXTENDED;
50
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
51
+ for (let i = 0; i < props_.length; i++) {
52
+ const [key, _value] = props_[i];
53
+ const id = event.props[key]?.[0];
54
+ extended = i < props_.length - 1;
55
+ let value = _value;
56
+ if (typeof value === 'boolean') {
57
+ value = value ? 1 : 0;
58
+ }
59
+ const fieldFlag = extended ? constants_js_1.FLAG_EVENT : constants_js_1.FLAG_FIELD | constants_js_1.FLAG_EXTENDED;
60
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
61
+ }
62
+ }
63
+ }
64
+ function serializeData(key, value, flag) {
65
+ const bufferLength = getHeaderBitLength(key);
66
+ let buffer;
67
+ let offset = 0;
68
+ if (value === null) {
69
+ if (flag === constants_js_1.FLAG_GLOBAL) {
70
+ buffer = Buffer.alloc(bufferLength);
71
+ offset = serializeHeader(buffer, offset, key, flag);
72
+ return buffer;
73
+ }
74
+ }
75
+ else if (typeof value === 'number' && Number.isInteger(value)) {
76
+ // is number
77
+ if (value === 0 || value === 1) {
78
+ buffer = Buffer.alloc(bufferLength);
79
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
80
+ return buffer;
81
+ }
82
+ else if (-128 <= value && value < 128) {
83
+ buffer = Buffer.alloc(bufferLength + 1);
84
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
85
+ buffer.writeInt8(value, offset);
86
+ return buffer;
87
+ }
88
+ else if (-32768 <= value && value < 32768) {
89
+ buffer = Buffer.alloc(bufferLength + 2);
90
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
91
+ buffer.writeInt16LE(value, offset);
92
+ return buffer;
93
+ }
94
+ else if (-2147483648 <= value && value < 2147483648) {
95
+ buffer = Buffer.alloc(bufferLength + 4);
96
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
97
+ buffer.writeInt32LE(value, offset);
98
+ return buffer;
99
+ }
100
+ else {
101
+ buffer = Buffer.alloc(bufferLength + 8);
102
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
103
+ buffer.writeDoubleLE(value, offset);
104
+ return buffer;
105
+ }
106
+ }
107
+ else if (typeof value === 'number') {
108
+ // is float
109
+ buffer = Buffer.alloc(bufferLength + 8);
110
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
111
+ buffer.writeDoubleLE(value, offset);
112
+ return buffer;
113
+ }
114
+ else if (typeof value === 'string') {
115
+ // is string
116
+ const utf8Bytes = Buffer.byteLength(value, 'utf8');
117
+ if (utf8Bytes < 256) {
118
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
119
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
120
+ buffer.writeUint8(utf8Bytes, offset++);
121
+ }
122
+ else if (utf8Bytes < 65536) {
123
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
124
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
125
+ buffer.writeUInt16LE(utf8Bytes, offset);
126
+ offset += 2;
127
+ }
128
+ else {
129
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
130
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
131
+ buffer.writeUInt32LE(utf8Bytes, offset);
132
+ offset += 4;
133
+ }
134
+ buffer.write(value, offset, 'utf8');
135
+ return buffer;
136
+ }
137
+ throw 'missing';
138
+ }
139
+ function serializeHeader(buffer, offset, key, flag) {
140
+ if (key < 256) {
141
+ buffer.writeUInt8(flag, offset);
142
+ offset += 1;
143
+ buffer.writeUInt8(key, offset);
144
+ offset += 1;
145
+ }
146
+ else {
147
+ buffer.writeUInt8(flag | constants_js_1.FLAG_BYTE, offset);
148
+ offset += 1;
149
+ buffer.writeUInt16LE(key, offset);
150
+ offset += 2;
151
+ }
152
+ return offset;
153
+ }
154
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants.js"), exports);
18
+ __exportStar(require("./encode.js"), exports);
19
+ __exportStar(require("./BinaryInfo.js"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncContactProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ const USyncUser_js_1 = require("../USyncUser.js");
6
+ class USyncContactProtocol {
7
+ constructor() {
8
+ this.name = 'contact';
9
+ }
10
+ getQueryElement() {
11
+ return {
12
+ tag: 'contact',
13
+ attrs: {}
14
+ };
15
+ }
16
+ getUserElement(user) {
17
+ if (user.phone) {
18
+ return {
19
+ tag: 'contact',
20
+ attrs: {},
21
+ content: user.phone
22
+ };
23
+ }
24
+ if (user.username) {
25
+ return {
26
+ tag: 'contact',
27
+ attrs: {
28
+ username: user.username,
29
+ ...(user.usernameKey ? { pin: user.usernameKey } : {}),
30
+ ...(user.lid ? { lid: user.lid } : {})
31
+ }
32
+ };
33
+ }
34
+ if (user.type) {
35
+ return {
36
+ tag: 'contact',
37
+ attrs: {
38
+ type: user.type
39
+ }
40
+ };
41
+ }
42
+ return {
43
+ tag: 'contact',
44
+ attrs: {}
45
+ };
46
+ }
47
+ parser(node) {
48
+ if (node.tag === 'contact') {
49
+ (0, index_js_1.assertNodeErrorFree)(node);
50
+ return node?.attrs?.type === 'in';
51
+ }
52
+ return false;
53
+ }
54
+ }
55
+ exports.USyncContactProtocol = USyncContactProtocol;
56
+ //# sourceMappingURL=USyncContactProtocol.js.map
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncDeviceProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ class USyncDeviceProtocol {
6
+ constructor() {
7
+ this.name = 'devices';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'devices',
12
+ attrs: {
13
+ version: '2'
14
+ }
15
+ };
16
+ }
17
+ getUserElement(user) {
18
+ // Vanz@Fix (bug 51): Implement device phashing for sync
19
+ // Include phash (participant hash) if devices exist to enable proper sync
20
+ if (user?.devices?.deviceList && user.devices.deviceList.length > 0) {
21
+ return {
22
+ tag: 'devices',
23
+ attrs: {
24
+ phash: user.devices.phash || '',
25
+ ts: user.devices.keyIndex?.timestamp?.toString() || '',
26
+ expectedTs: user.devices.keyIndex?.expectedTimestamp?.toString() || ''
27
+ }
28
+ };
29
+ }
30
+ return null;
31
+ }
32
+ parser(node) {
33
+ const deviceList = [];
34
+ let keyIndex = undefined;
35
+ if (node.tag === 'devices') {
36
+ (0, index_js_1.assertNodeErrorFree)(node);
37
+ const deviceListNode = (0, index_js_1.getBinaryNodeChild)(node, 'device-list');
38
+ const keyIndexNode = (0, index_js_1.getBinaryNodeChild)(node, 'key-index-list');
39
+ if (Array.isArray(deviceListNode?.content)) {
40
+ for (const { tag, attrs } of deviceListNode.content) {
41
+ const id = +attrs.id;
42
+ const keyIndex = +attrs['key-index'];
43
+ if (tag === 'device') {
44
+ deviceList.push({
45
+ id,
46
+ keyIndex,
47
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
48
+ });
49
+ }
50
+ }
51
+ }
52
+ if (keyIndexNode?.tag === 'key-index-list') {
53
+ keyIndex = {
54
+ timestamp: +keyIndexNode.attrs['ts'],
55
+ signedKeyIndex: keyIndexNode?.content,
56
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
57
+ };
58
+ }
59
+ }
60
+ return {
61
+ deviceList,
62
+ keyIndex
63
+ };
64
+ }
65
+ }
66
+ exports.USyncDeviceProtocol = USyncDeviceProtocol;
67
+ //# sourceMappingURL=USyncDeviceProtocol.js.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncDisappearingModeProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ class USyncDisappearingModeProtocol {
6
+ constructor() {
7
+ this.name = 'disappearing_mode';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'disappearing_mode',
12
+ attrs: {}
13
+ };
14
+ }
15
+ getUserElement() {
16
+ return null;
17
+ }
18
+ parser(node) {
19
+ if (node.tag === 'disappearing_mode') {
20
+ (0, index_js_1.assertNodeErrorFree)(node);
21
+ const duration = +node?.attrs.duration;
22
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
23
+ return {
24
+ duration,
25
+ setAt
26
+ };
27
+ }
28
+ }
29
+ }
30
+ exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
31
+ //# sourceMappingURL=USyncDisappearingModeProtocol.js.map
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncStatusProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ class USyncStatusProtocol {
6
+ constructor() {
7
+ this.name = 'status';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'status',
12
+ attrs: {}
13
+ };
14
+ }
15
+ getUserElement() {
16
+ return null;
17
+ }
18
+ parser(node) {
19
+ if (node.tag === 'status') {
20
+ (0, index_js_1.assertNodeErrorFree)(node);
21
+ let status = node?.content?.toString() ?? null;
22
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
23
+ if (!status) {
24
+ if (node.attrs?.code && +node.attrs.code === 401) {
25
+ status = '';
26
+ }
27
+ else {
28
+ status = null;
29
+ }
30
+ }
31
+ else if (typeof status === 'string' && status.length === 0) {
32
+ status = null;
33
+ }
34
+ return {
35
+ status,
36
+ setAt
37
+ };
38
+ }
39
+ }
40
+ }
41
+ exports.USyncStatusProtocol = USyncStatusProtocol;
42
+ //# sourceMappingURL=USyncStatusProtocol.js.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncUsernameProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ const USyncUser_js_1 = require("../USyncUser.js");
6
+ class USyncUsernameProtocol {
7
+ constructor() {
8
+ this.name = 'username';
9
+ }
10
+ getQueryElement() {
11
+ return {
12
+ tag: 'username',
13
+ attrs: {}
14
+ };
15
+ }
16
+ getUserElement(user) {
17
+ void user;
18
+ return null;
19
+ }
20
+ parser(node) {
21
+ if (node.tag === 'username') {
22
+ (0, index_js_1.assertNodeErrorFree)(node);
23
+ return typeof node.content === 'string' ? node.content : null;
24
+ }
25
+ return null;
26
+ }
27
+ }
28
+ exports.USyncUsernameProtocol = USyncUsernameProtocol;
29
+ //# sourceMappingURL=USyncUsernameProtocol.js.map
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncBotProfileProtocol = void 0;
4
+ const index_js_1 = require("../../WABinary/index.js");
5
+ const USyncUser_js_1 = require("../USyncUser.js");
6
+ class USyncBotProfileProtocol {
7
+ constructor() {
8
+ this.name = 'bot';
9
+ }
10
+ getQueryElement() {
11
+ return {
12
+ tag: 'bot',
13
+ attrs: {},
14
+ content: [{ tag: 'profile', attrs: { v: '1' } }]
15
+ };
16
+ }
17
+ getUserElement(user) {
18
+ return {
19
+ tag: 'bot',
20
+ attrs: {},
21
+ content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
22
+ };
23
+ }
24
+ parser(node) {
25
+ const botNode = (0, index_js_1.getBinaryNodeChild)(node, 'bot');
26
+ const profile = (0, index_js_1.getBinaryNodeChild)(botNode, 'profile');
27
+ const commandsNode = (0, index_js_1.getBinaryNodeChild)(profile, 'commands');
28
+ const promptsNode = (0, index_js_1.getBinaryNodeChild)(profile, 'prompts');
29
+ const commands = [];
30
+ const prompts = [];
31
+ for (const command of (0, index_js_1.getBinaryNodeChildren)(commandsNode, 'command')) {
32
+ commands.push({
33
+ name: (0, index_js_1.getBinaryNodeChildString)(command, 'name'),
34
+ description: (0, index_js_1.getBinaryNodeChildString)(command, 'description')
35
+ });
36
+ }
37
+ for (const prompt of (0, index_js_1.getBinaryNodeChildren)(promptsNode, 'prompt')) {
38
+ prompts.push(`${(0, index_js_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, index_js_1.getBinaryNodeChildString)(prompt, 'text')}`);
39
+ }
40
+ return {
41
+ isDefault: !!(0, index_js_1.getBinaryNodeChild)(profile, 'default'),
42
+ jid: node.attrs.jid,
43
+ name: (0, index_js_1.getBinaryNodeChildString)(profile, 'name'),
44
+ attributes: (0, index_js_1.getBinaryNodeChildString)(profile, 'attributes'),
45
+ description: (0, index_js_1.getBinaryNodeChildString)(profile, 'description'),
46
+ category: (0, index_js_1.getBinaryNodeChildString)(profile, 'category'),
47
+ personaId: profile.attrs['persona_id'],
48
+ commandsDescription: (0, index_js_1.getBinaryNodeChildString)(commandsNode, 'description'),
49
+ commands,
50
+ prompts
51
+ };
52
+ }
53
+ }
54
+ exports.USyncBotProfileProtocol = USyncBotProfileProtocol;
55
+ //# sourceMappingURL=UsyncBotProfileProtocol.js.map
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncLIDProtocol = void 0;
4
+ class USyncLIDProtocol {
5
+ constructor() {
6
+ this.name = 'lid';
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'lid',
11
+ attrs: {}
12
+ };
13
+ }
14
+ getUserElement(user) {
15
+ if (user.lid) {
16
+ return {
17
+ tag: 'lid',
18
+ attrs: { jid: user.lid }
19
+ };
20
+ }
21
+ else {
22
+ return null;
23
+ }
24
+ }
25
+ parser(node) {
26
+ if (node.tag === 'lid') {
27
+ return node.attrs.val;
28
+ }
29
+ return null;
30
+ }
31
+ }
32
+ exports.USyncLIDProtocol = USyncLIDProtocol;
33
+ //# sourceMappingURL=UsyncLIDProtocol.js.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./USyncDeviceProtocol.js"), exports);
18
+ __exportStar(require("./USyncContactProtocol.js"), exports);
19
+ __exportStar(require("./USyncStatusProtocol.js"), exports);
20
+ __exportStar(require("./USyncDisappearingModeProtocol.js"), exports);
21
+ __exportStar(require("./USyncUsernameProtocol.js"), exports);
22
+ __exportStar(require("./UsyncBotProfileProtocol.js"), exports); // Vanz@Fix: was missing
23
+ __exportStar(require("./UsyncLIDProtocol.js"), exports); // Vanz@Fix: was missing
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncQuery = void 0;
4
+ const index_js_1 = require("../WABinary/index.js");
5
+ const UsyncBotProfileProtocol_js_1 = require("./Protocols/UsyncBotProfileProtocol.js");
6
+ const UsyncLIDProtocol_js_1 = require("./Protocols/UsyncLIDProtocol.js");
7
+ const index_js_2 = require("./Protocols/index.js");
8
+ const USyncUser_js_1 = require("./USyncUser.js");
9
+ class USyncQuery {
10
+ constructor() {
11
+ this.protocols = [];
12
+ this.users = [];
13
+ this.context = 'interactive';
14
+ this.mode = 'query';
15
+ }
16
+ withMode(mode) {
17
+ this.mode = mode;
18
+ return this;
19
+ }
20
+ withContext(context) {
21
+ this.context = context;
22
+ return this;
23
+ }
24
+ withUser(user) {
25
+ this.users.push(user);
26
+ return this;
27
+ }
28
+ parseUSyncQueryResult(result) {
29
+ if (result?.attrs.type !== 'result') {
30
+ return;
31
+ }
32
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
33
+ return [protocol.name, protocol.parser];
34
+ }));
35
+ const queryResult = {
36
+ // TODO: implement errors etc.
37
+ list: [],
38
+ sideList: []
39
+ };
40
+ const usyncNode = (0, index_js_1.getBinaryNodeChild)(result, 'usync');
41
+ //TODO: implement error backoff, refresh etc.
42
+ //TODO: see if there are any errors in the result node
43
+ //const resultNode = getBinaryNodeChild(usyncNode, 'result')
44
+ const listNode = usyncNode ? (0, index_js_1.getBinaryNodeChild)(usyncNode, 'list') : undefined;
45
+ if (listNode?.content && Array.isArray(listNode.content)) {
46
+ queryResult.list = listNode.content.reduce((acc, node) => {
47
+ const id = node?.attrs.jid;
48
+ if (id) {
49
+ const data = Array.isArray(node?.content)
50
+ ? Object.fromEntries(node.content
51
+ .map(content => {
52
+ const protocol = content.tag;
53
+ const parser = protocolMap[protocol];
54
+ if (parser) {
55
+ return [protocol, parser(content)];
56
+ }
57
+ else {
58
+ return [protocol, null];
59
+ }
60
+ })
61
+ .filter(([, b]) => b !== null))
62
+ : {};
63
+ acc.push({ ...data, id });
64
+ }
65
+ return acc;
66
+ }, []);
67
+ }
68
+ // Vanz@Fix (bug 52): implement sideList for side band sync
69
+ // sideList contains additional sync data that should be processed separately
70
+ const sideListNode = usyncNode ? (0, index_js_1.getBinaryNodeChild)(usyncNode, 'side_list') : undefined;
71
+ if (sideListNode?.content && Array.isArray(sideListNode.content)) {
72
+ queryResult.sideList = sideListNode.content.reduce((acc, node) => {
73
+ const id = node?.attrs.jid;
74
+ if (id) {
75
+ const data = Array.isArray(node?.content)
76
+ ? Object.fromEntries(node.content
77
+ .map(content => {
78
+ const protocol = content.tag;
79
+ const parser = protocolMap[protocol];
80
+ if (parser) {
81
+ return [protocol, parser(content)];
82
+ }
83
+ else {
84
+ return [protocol, null];
85
+ }
86
+ })
87
+ .filter(([, b]) => b !== null))
88
+ : {};
89
+ acc.push({ ...data, id });
90
+ }
91
+ return acc;
92
+ }, []);
93
+ }
94
+ return queryResult;
95
+ }
96
+ withDeviceProtocol() {
97
+ this.protocols.push(new index_js_2.USyncDeviceProtocol());
98
+ return this;
99
+ }
100
+ withContactProtocol() {
101
+ this.protocols.push(new index_js_2.USyncContactProtocol());
102
+ return this;
103
+ }
104
+ withStatusProtocol() {
105
+ this.protocols.push(new index_js_2.USyncStatusProtocol());
106
+ return this;
107
+ }
108
+ withDisappearingModeProtocol() {
109
+ this.protocols.push(new index_js_2.USyncDisappearingModeProtocol());
110
+ return this;
111
+ }
112
+ withBotProfileProtocol() {
113
+ this.protocols.push(new UsyncBotProfileProtocol_js_1.USyncBotProfileProtocol());
114
+ return this;
115
+ }
116
+ withLIDProtocol() {
117
+ this.protocols.push(new UsyncLIDProtocol_js_1.USyncLIDProtocol());
118
+ return this;
119
+ }
120
+ withUsernameProtocol() {
121
+ this.protocols.push(new index_js_2.USyncUsernameProtocol());
122
+ return this;
123
+ }
124
+ }
125
+ exports.USyncQuery = USyncQuery;
126
+ //# sourceMappingURL=USyncQuery.js.map
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncUser = void 0;
4
+ class USyncUser {
5
+ withId(id) {
6
+ this.id = id;
7
+ return this;
8
+ }
9
+ withLid(lid) {
10
+ this.lid = lid;
11
+ return this;
12
+ }
13
+ withPhone(phone) {
14
+ this.phone = phone;
15
+ return this;
16
+ }
17
+ withUsername(username) {
18
+ this.username = username;
19
+ return this;
20
+ }
21
+ withUsernameKey(usernameKey) {
22
+ this.usernameKey = usernameKey;
23
+ return this;
24
+ }
25
+ withType(type) {
26
+ this.type = type;
27
+ return this;
28
+ }
29
+ withPersonaId(personaId) {
30
+ this.personaId = personaId;
31
+ return this;
32
+ }
33
+ }
34
+ exports.USyncUser = USyncUser;
35
+ //# sourceMappingURL=USyncUser.js.map