nrx-bails 0.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 +21 -0
- package/README.md +1541 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +169661 -0
- package/lib/Defaults/index.d.ts +113 -0
- package/lib/Defaults/index.js +156 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/ye-bail-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +41 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +90 -0
- package/lib/Signal/Group/group_cipher.d.ts +12 -0
- package/lib/Signal/Group/group_cipher.js +122 -0
- package/lib/Signal/Group/index.d.ts +22 -0
- package/lib/Signal/Group/index.js +83 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +81 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.js +83 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +60 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +95 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +77 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +79 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +125 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +55 -0
- package/lib/Signal/libsignal.d.ts +37 -0
- package/lib/Signal/libsignal.js +200 -0
- package/lib/Socket/Client/index.d.ts +1 -0
- package/lib/Socket/Client/index.js +44 -0
- package/lib/Socket/Client/types.d.ts +7 -0
- package/lib/Socket/Client/types.js +39 -0
- package/lib/Socket/Client/websocket.d.ts +19 -0
- package/lib/Socket/Client/websocket.js +137 -0
- package/lib/Socket/business.d.ts +329 -0
- package/lib/Socket/business.js +286 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +1022 -0
- package/lib/Socket/groups.d.ts +216 -0
- package/lib/Socket/groups.js +358 -0
- package/lib/Socket/index.d.ts +330 -0
- package/lib/Socket/index.js +36 -0
- package/lib/Socket/messages-recv.d.ts +271 -0
- package/lib/Socket/messages-recv.js +1079 -0
- package/lib/Socket/messages-send.d.ts +258 -0
- package/lib/Socket/messages-send.js +1190 -0
- package/lib/Socket/newsletter.d.ts +253 -0
- package/lib/Socket/newsletter.js +362 -0
- package/lib/Socket/registration.d.ts +361 -0
- package/lib/Socket/registration.js +179 -0
- package/lib/Socket/socket.d.ts +33 -0
- package/lib/Socket/socket.js +699 -0
- package/lib/Socket/usync.d.ts +27 -0
- package/lib/Socket/usync.js +96 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
- package/lib/Store/make-cache-manager-auth-state.js +118 -0
- package/lib/Store/make-in-memory-store.d.ts +64 -0
- package/lib/Store/make-in-memory-store.js +465 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/make-ordered-dictionary.js +107 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +53 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +28 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +28 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +30 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +28 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +28 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +28 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +53 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +35 -0
- package/lib/Types/Message.d.ts +2 -0
- package/lib/Types/Message.js +33 -0
- package/lib/Types/Newsletter.d.ts +4 -0
- package/lib/Types/Newsletter.js +62 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +28 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +28 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +28 -0
- package/lib/Types/State.d.ts +1 -0
- package/lib/Types/State.js +28 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +28 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +68 -0
- package/lib/Utils/auth-utils.d.ts +63 -0
- package/lib/Utils/auth-utils.js +248 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +61 -0
- package/lib/Utils/business.d.ts +53 -0
- package/lib/Utils/business.js +260 -0
- package/lib/Utils/chat-utils.d.ts +253 -0
- package/lib/Utils/chat-utils.js +756 -0
- package/lib/Utils/crypto.d.ts +43 -0
- package/lib/Utils/crypto.js +219 -0
- package/lib/Utils/decode-wa-message.d.ts +61 -0
- package/lib/Utils/decode-wa-message.js +233 -0
- package/lib/Utils/event-buffer.d.ts +17 -0
- package/lib/Utils/event-buffer.js +544 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +59 -0
- package/lib/Utils/history.js +120 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/link-preview.d.ts +19 -0
- package/lib/Utils/link-preview.js +152 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +33 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +77 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +69 -0
- package/lib/Utils/message-retry-manager.d.ts +34 -0
- package/lib/Utils/message-retry-manager.js +154 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +1024 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +1407 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +176 -0
- package/lib/Utils/pre-key-manager.d.ts +13 -0
- package/lib/Utils/pre-key-manager.js +93 -0
- package/lib/Utils/process-message.d.ts +40 -0
- package/lib/Utils/process-message.js +430 -0
- package/lib/Utils/signal.d.ts +72 -0
- package/lib/Utils/signal.js +179 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +151 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +255 -0
- package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
- package/lib/Utils/ye-bail-event-stream.js +89 -0
- package/lib/WABinary/constants.d.ts +23 -0
- package/lib/WABinary/constants.js +1328 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +291 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +276 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +155 -0
- package/lib/WABinary/index.d.ts +1 -0
- package/lib/WABinary/index.js +47 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +111 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +28 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +39 -0
- package/lib/WAM/constants.d.ts +35374 -0
- package/lib/WAM/constants.js +15376 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +181 -0
- package/lib/WAM/index.d.ts +1 -0
- package/lib/WAM/index.js +45 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.js +46 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +115 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +52 -0
- package/lib/WAUSync/index.d.ts +1 -0
- package/lib/WAUSync/index.js +45 -0
- package/lib/index.js +81 -0
- package/package.json +113 -0
- package/requirements.js +32 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
63
|
+
const libsignal = __importStar(require("libsignal"));
|
|
64
|
+
const Utils_1 = require("../Utils");
|
|
65
|
+
const WABinary_1 = require("../WABinary");
|
|
66
|
+
const sender_key_name_1 = require("./Group/sender-key-name");
|
|
67
|
+
const sender_key_record_1 = require("./Group/sender-key-record");
|
|
68
|
+
const Group_1 = require("./Group");
|
|
69
|
+
function makeLibSignalRepository(auth) {
|
|
70
|
+
const storage = signalStorage(auth);
|
|
71
|
+
return {
|
|
72
|
+
decryptGroupMessage({ group, authorJid, msg }) {
|
|
73
|
+
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
74
|
+
const cipher = new Group_1.GroupCipher(storage, senderName);
|
|
75
|
+
return cipher.decrypt(msg);
|
|
76
|
+
},
|
|
77
|
+
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
78
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
79
|
+
if (!item.groupId) {
|
|
80
|
+
throw new Error('Group ID is required for sender key distribution message');
|
|
81
|
+
}
|
|
82
|
+
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
83
|
+
const senderMsg = new Group_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
84
|
+
const senderNameStr = senderName.toString();
|
|
85
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
86
|
+
if (!senderKey) {
|
|
87
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
88
|
+
}
|
|
89
|
+
await builder.process(senderName, senderMsg);
|
|
90
|
+
},
|
|
91
|
+
async decryptMessage({ jid, type, ciphertext }) {
|
|
92
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
93
|
+
const session = new libsignal.SessionCipher(storage, addr);
|
|
94
|
+
let result;
|
|
95
|
+
switch (type) {
|
|
96
|
+
case 'pkmsg':
|
|
97
|
+
result = await session.decryptPreKeyWhisperMessage(ciphertext);
|
|
98
|
+
break;
|
|
99
|
+
case 'msg':
|
|
100
|
+
result = await session.decryptWhisperMessage(ciphertext);
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
},
|
|
107
|
+
async encryptMessage({ jid, data }) {
|
|
108
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
109
|
+
const cipher = new libsignal.SessionCipher(storage, addr);
|
|
110
|
+
const { type: sigType, body } = await cipher.encrypt(data);
|
|
111
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg';
|
|
112
|
+
return { type, ciphertext: Buffer.from(body, 'binary') };
|
|
113
|
+
},
|
|
114
|
+
async encryptGroupMessage({ group, meId, data }) {
|
|
115
|
+
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
116
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
117
|
+
const senderNameStr = senderName.toString();
|
|
118
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
119
|
+
if (!senderKey) {
|
|
120
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
121
|
+
}
|
|
122
|
+
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
123
|
+
const session = new Group_1.GroupCipher(storage, senderName);
|
|
124
|
+
const ciphertext = await session.encrypt(data);
|
|
125
|
+
return {
|
|
126
|
+
ciphertext,
|
|
127
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
async injectE2ESession({ jid, session }) {
|
|
131
|
+
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
|
|
132
|
+
await cipher.initOutgoing(session);
|
|
133
|
+
},
|
|
134
|
+
jidToSignalProtocolAddress(jid) {
|
|
135
|
+
return jidToSignalProtocolAddress(jid).toString();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const jidToSignalProtocolAddress = (jid) => {
|
|
140
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
141
|
+
return new libsignal.ProtocolAddress(user, device || 0);
|
|
142
|
+
};
|
|
143
|
+
const jidToSignalSenderKeyName = (group, user) => {
|
|
144
|
+
return new sender_key_name_1.SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
145
|
+
};
|
|
146
|
+
function signalStorage({ creds, keys }) {
|
|
147
|
+
return {
|
|
148
|
+
loadSession: async (id) => {
|
|
149
|
+
const { [id]: sess } = await keys.get('session', [id]);
|
|
150
|
+
if (sess) {
|
|
151
|
+
return libsignal.SessionRecord.deserialize(sess);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
storeSession: async (id, session) => {
|
|
155
|
+
await keys.set({ session: { [id]: session.serialize() } });
|
|
156
|
+
},
|
|
157
|
+
isTrustedIdentity: () => {
|
|
158
|
+
return true;
|
|
159
|
+
},
|
|
160
|
+
loadPreKey: async (id) => {
|
|
161
|
+
const keyId = id.toString();
|
|
162
|
+
const { [keyId]: key } = await keys.get('pre-key', [keyId]);
|
|
163
|
+
if (key) {
|
|
164
|
+
return {
|
|
165
|
+
privKey: Buffer.from(key.private),
|
|
166
|
+
pubKey: Buffer.from(key.public)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
|
|
171
|
+
loadSignedPreKey: () => {
|
|
172
|
+
const key = creds.signedPreKey;
|
|
173
|
+
return {
|
|
174
|
+
privKey: Buffer.from(key.keyPair.private),
|
|
175
|
+
pubKey: Buffer.from(key.keyPair.public)
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
loadSenderKey: async (senderKeyName) => {
|
|
179
|
+
const keyId = senderKeyName.toString();
|
|
180
|
+
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
181
|
+
if (key) {
|
|
182
|
+
return sender_key_record_1.SenderKeyRecord.deserialize(key);
|
|
183
|
+
}
|
|
184
|
+
return new sender_key_record_1.SenderKeyRecord();
|
|
185
|
+
},
|
|
186
|
+
storeSenderKey: async (senderKeyName, key) => {
|
|
187
|
+
const keyId = senderKeyName.toString();
|
|
188
|
+
const serialized = JSON.stringify(key.serialize());
|
|
189
|
+
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
190
|
+
},
|
|
191
|
+
getOurRegistrationId: () => creds.registrationId,
|
|
192
|
+
getOurIdentity: () => {
|
|
193
|
+
const { signedIdentityKey } = creds;
|
|
194
|
+
return {
|
|
195
|
+
privKey: Buffer.from(signedIdentityKey.private),
|
|
196
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
40
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
__exportStar(require("./types"), exports);
|
|
44
|
+
__exportStar(require("./websocket"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.AbstractSocketClient = void 0;
|
|
30
|
+
const events_1 = require("events");
|
|
31
|
+
class AbstractSocketClient extends events_1.EventEmitter {
|
|
32
|
+
constructor(url, config) {
|
|
33
|
+
super();
|
|
34
|
+
this.url = url;
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.setMaxListeners(0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
export class WebSocketClient extends types_1.AbstractSocketClient {
|
|
3
|
+
constructor(...args: any[]);
|
|
4
|
+
socket: any;
|
|
5
|
+
_queue: any[];
|
|
6
|
+
_isDispatching: boolean;
|
|
7
|
+
_lastDispatch: number;
|
|
8
|
+
_minSendIntervalMs: any;
|
|
9
|
+
get isOpen(): boolean;
|
|
10
|
+
get isClosed(): boolean;
|
|
11
|
+
get isClosing(): boolean;
|
|
12
|
+
get isConnecting(): boolean;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
restart(): Promise<void>;
|
|
16
|
+
send(str: any, cb: any): boolean;
|
|
17
|
+
_dispatch(): void;
|
|
18
|
+
}
|
|
19
|
+
import types_1 = require("./types");
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.WebSocketClient = void 0;
|
|
33
|
+
const ws_1 = __importDefault(require("ws"));
|
|
34
|
+
const Defaults_1 = require("../../Defaults");
|
|
35
|
+
const types_1 = require("./types");
|
|
36
|
+
class WebSocketClient extends types_1.AbstractSocketClient {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(...arguments);
|
|
39
|
+
this.socket = null;
|
|
40
|
+
|
|
41
|
+
this._queue = [];
|
|
42
|
+
this._isDispatching = false;
|
|
43
|
+
this._lastDispatch = 0;
|
|
44
|
+
this._minSendIntervalMs = (Defaults_1.DEFAULT_CONNECTION_CONFIG && Defaults_1.DEFAULT_CONNECTION_CONFIG.minSendIntervalMs) || 50;
|
|
45
|
+
}
|
|
46
|
+
get isOpen() {
|
|
47
|
+
var _a;
|
|
48
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
49
|
+
}
|
|
50
|
+
get isClosed() {
|
|
51
|
+
var _a;
|
|
52
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
53
|
+
}
|
|
54
|
+
get isClosing() {
|
|
55
|
+
var _a;
|
|
56
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
57
|
+
}
|
|
58
|
+
get isConnecting() {
|
|
59
|
+
var _a;
|
|
60
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
61
|
+
}
|
|
62
|
+
async connect() {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
if (this.socket) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.socket = new ws_1.default(this.url, {
|
|
68
|
+
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
69
|
+
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
70
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
71
|
+
timeout: this.config.connectTimeoutMs,
|
|
72
|
+
agent: this.config.agent,
|
|
73
|
+
});
|
|
74
|
+
this.socket.setMaxListeners(0);
|
|
75
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
76
|
+
for (const event of events) {
|
|
77
|
+
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async close() {
|
|
81
|
+
if (!this.socket) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.socket.close();
|
|
85
|
+
this.socket = null;
|
|
86
|
+
}
|
|
87
|
+
async restart() {
|
|
88
|
+
if (this.socket) {
|
|
89
|
+
await new Promise(resolve => {
|
|
90
|
+
this.socket.once('close', resolve);
|
|
91
|
+
this.socket.terminate();
|
|
92
|
+
});
|
|
93
|
+
this.socket = null;
|
|
94
|
+
}
|
|
95
|
+
await this.connect();
|
|
96
|
+
}
|
|
97
|
+
send(str, cb) {
|
|
98
|
+
|
|
99
|
+
const doSend = () => {
|
|
100
|
+
var _a;
|
|
101
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
102
|
+
return Boolean(this.socket);
|
|
103
|
+
};
|
|
104
|
+
this._queue.push(doSend);
|
|
105
|
+
this._dispatch();
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_dispatch() {
|
|
110
|
+
if (this._isDispatching) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this._isDispatching = true;
|
|
114
|
+
const tick = () => {
|
|
115
|
+
const now = Date.now();
|
|
116
|
+
if (this._queue.length === 0) {
|
|
117
|
+
this._isDispatching = false;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const delta = now - this._lastDispatch;
|
|
121
|
+
const wait = Math.max(0, this._minSendIntervalMs - delta);
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
const fn = this._queue.shift();
|
|
124
|
+
this._lastDispatch = Date.now();
|
|
125
|
+
try {
|
|
126
|
+
fn && fn();
|
|
127
|
+
}
|
|
128
|
+
catch (_err) {
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
tick();
|
|
132
|
+
}, wait);
|
|
133
|
+
};
|
|
134
|
+
tick();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.WebSocketClient = WebSocketClient;
|