@lennyyaawa/lannysecx 9.9.18
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/README.md +61 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +3344 -0
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +130281 -0
- package/lib/Database/mongoAdapter.js +77 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +130 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/PaxHeaders.0/swzesty st 1963.d.ts +1 -0
- package/lib/Socket/PaxHeaders.0/swzesty st 1963.js +1 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +890 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +317 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1110 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +805 -0
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +630 -0
- package/lib/Socket/sw/303/250zesty /303/250st 1963.d.ts" +220 -0
- package/lib/Socket/sw/303/250zesty /303/250st 1963.js" +437 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +729 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +151 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +198 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +391 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +96 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +731 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +825 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +321 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +151 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +81 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +252 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +228 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +199 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +85 -0
- package/lib/index.js.bak +44 -0
- package/lib/index.js.bak2 +133 -0
- package/package.json +108 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Contact } from './Contact';
|
2
|
+
export type WAConnectionState = 'open' | 'connecting' | 'close';
|
3
|
+
export type ConnectionState = {
|
4
|
+
/** connection is now open, connecting or closed */
|
5
|
+
connection: WAConnectionState;
|
6
|
+
/** the error that caused the connection to close */
|
7
|
+
lastDisconnect?: {
|
8
|
+
error: Error | undefined;
|
9
|
+
date: Date;
|
10
|
+
};
|
11
|
+
/** is this a new login */
|
12
|
+
isNewLogin?: boolean;
|
13
|
+
/** the current QR code */
|
14
|
+
qr?: string;
|
15
|
+
/** has the device received all pending notifications while it was offline */
|
16
|
+
receivedPendingNotifications?: boolean;
|
17
|
+
/** legacy connection options */
|
18
|
+
legacy?: {
|
19
|
+
phoneConnected: boolean;
|
20
|
+
user?: Contact;
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* if the client is shown as an active, online client.
|
24
|
+
* If this is false, the primary phone and other devices will receive notifs
|
25
|
+
* */
|
26
|
+
isOnline?: boolean;
|
27
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { BinaryNode } from '../WABinary';
|
2
|
+
import { USyncUser } from '../WAUSync';
|
3
|
+
/**
|
4
|
+
* Defines the interface for a USyncQuery protocol
|
5
|
+
*/
|
6
|
+
export interface USyncQueryProtocol {
|
7
|
+
/**
|
8
|
+
* The name of the protocol
|
9
|
+
*/
|
10
|
+
name: string;
|
11
|
+
/**
|
12
|
+
* Defines what goes inside the query part of a USyncQuery
|
13
|
+
*/
|
14
|
+
getQueryElement: () => BinaryNode;
|
15
|
+
/**
|
16
|
+
* Defines what goes inside the user part of a USyncQuery
|
17
|
+
*/
|
18
|
+
getUserElement: (user: USyncUser) => BinaryNode | null;
|
19
|
+
/**
|
20
|
+
* Parse the result of the query
|
21
|
+
* @param data Data from the result
|
22
|
+
* @returns Whatever the protocol is supposed to return
|
23
|
+
*/
|
24
|
+
parser: (data: BinaryNode) => unknown;
|
25
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
export * from './Auth';
|
2
|
+
export * from './GroupMetadata';
|
3
|
+
export * from './Chat';
|
4
|
+
export * from './Contact';
|
5
|
+
export * from './State';
|
6
|
+
export * from './Message';
|
7
|
+
export * from './Newsletter';
|
8
|
+
export * from './Socket';
|
9
|
+
export * from './Events';
|
10
|
+
export * from './Product';
|
11
|
+
export * from './Call';
|
12
|
+
export * from './Signal';
|
13
|
+
import { AuthenticationState } from './Auth';
|
14
|
+
import { SocketConfig } from './Socket';
|
15
|
+
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
16
|
+
auth: AuthenticationState;
|
17
|
+
};
|
18
|
+
export declare enum DisconnectReason {
|
19
|
+
connectionClosed = 428,
|
20
|
+
connectionLost = 408,
|
21
|
+
connectionReplaced = 440,
|
22
|
+
timedOut = 408,
|
23
|
+
loggedOut = 401,
|
24
|
+
badSession = 500,
|
25
|
+
restartRequired = 515,
|
26
|
+
multideviceMismatch = 411,
|
27
|
+
forbidden = 403,
|
28
|
+
unavailableService = 503
|
29
|
+
}
|
30
|
+
export type WAInitResponse = {
|
31
|
+
ref: string;
|
32
|
+
ttl: number;
|
33
|
+
status: 200;
|
34
|
+
};
|
35
|
+
export type WABusinessHoursConfig = {
|
36
|
+
day_of_week: string;
|
37
|
+
mode: string;
|
38
|
+
open_time?: number;
|
39
|
+
close_time?: number;
|
40
|
+
};
|
41
|
+
export type WABusinessProfile = {
|
42
|
+
description: string;
|
43
|
+
email: string | undefined;
|
44
|
+
business_hours: {
|
45
|
+
timezone?: string;
|
46
|
+
config?: WABusinessHoursConfig[];
|
47
|
+
business_config?: WABusinessHoursConfig[];
|
48
|
+
};
|
49
|
+
website: string[];
|
50
|
+
category?: string;
|
51
|
+
wid?: string;
|
52
|
+
address?: string;
|
53
|
+
};
|
54
|
+
export type CurveKeyPair = {
|
55
|
+
private: Uint8Array;
|
56
|
+
public: Uint8Array;
|
57
|
+
};
|
@@ -0,0 +1,42 @@
|
|
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
|
+
exports.DisconnectReason = void 0;
|
18
|
+
__exportStar(require("./Auth"), exports);
|
19
|
+
__exportStar(require("./GroupMetadata"), exports);
|
20
|
+
__exportStar(require("./Chat"), exports);
|
21
|
+
__exportStar(require("./Contact"), exports);
|
22
|
+
__exportStar(require("./State"), exports);
|
23
|
+
__exportStar(require("./Message"), exports);
|
24
|
+
__exportStar(require("./Newsletter"), exports);
|
25
|
+
__exportStar(require("./Socket"), exports);
|
26
|
+
__exportStar(require("./Events"), exports);
|
27
|
+
__exportStar(require("./Product"), exports);
|
28
|
+
__exportStar(require("./Call"), exports);
|
29
|
+
__exportStar(require("./Signal"), exports);
|
30
|
+
var DisconnectReason;
|
31
|
+
(function (DisconnectReason) {
|
32
|
+
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
33
|
+
DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
|
34
|
+
DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
|
35
|
+
DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
|
36
|
+
DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
|
37
|
+
DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
|
38
|
+
DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
|
39
|
+
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
40
|
+
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
41
|
+
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
42
|
+
})(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { Logger } from 'pino';
|
2
|
+
import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
|
3
|
+
/**
|
4
|
+
* Adds caching capability to a SignalKeyStore
|
5
|
+
* @param store the store to add caching to
|
6
|
+
* @param logger to log trace events
|
7
|
+
* @param _cache cache store to use
|
8
|
+
*/
|
9
|
+
export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger: Logger, _cache?: CacheStore): SignalKeyStore;
|
10
|
+
/**
|
11
|
+
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
12
|
+
* this allows batch read & write operations & improves the performance of the lib
|
13
|
+
* @param state the key store to apply this capability to
|
14
|
+
* @param logger logger to log events
|
15
|
+
* @returns SignalKeyStore with transaction capability
|
16
|
+
*/
|
17
|
+
export declare const addTransactionCapability: (state: SignalKeyStore, logger: Logger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
|
18
|
+
export declare const initAuthCreds: () => AuthenticationCreds;
|
@@ -0,0 +1,206 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
|
7
|
+
const crypto_1 = require("crypto");
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
9
|
+
const uuid_1 = require("uuid");
|
10
|
+
const Defaults_1 = require("../Defaults");
|
11
|
+
const crypto_2 = require("./crypto");
|
12
|
+
const generics_1 = require("./generics");
|
13
|
+
/**
|
14
|
+
* Adds caching capability to a SignalKeyStore
|
15
|
+
* @param store the store to add caching to
|
16
|
+
* @param logger to log trace events
|
17
|
+
* @param _cache cache store to use
|
18
|
+
*/
|
19
|
+
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
20
|
+
const cache = _cache || new node_cache_1.default({
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
22
|
+
useClones: false,
|
23
|
+
deleteOnExpire: true,
|
24
|
+
});
|
25
|
+
function getUniqueId(type, id) {
|
26
|
+
return `${type}.${id}`;
|
27
|
+
}
|
28
|
+
return {
|
29
|
+
async get(type, ids) {
|
30
|
+
const data = {};
|
31
|
+
const idsToFetch = [];
|
32
|
+
for (const id of ids) {
|
33
|
+
const item = cache.get(getUniqueId(type, id));
|
34
|
+
if (typeof item !== 'undefined') {
|
35
|
+
data[id] = item;
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
idsToFetch.push(id);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
if (idsToFetch.length) {
|
42
|
+
logger.trace({ items: idsToFetch.length }, 'loading from store');
|
43
|
+
const fetched = await store.get(type, idsToFetch);
|
44
|
+
for (const id of idsToFetch) {
|
45
|
+
const item = fetched[id];
|
46
|
+
if (item) {
|
47
|
+
data[id] = item;
|
48
|
+
cache.set(getUniqueId(type, id), item);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return data;
|
53
|
+
},
|
54
|
+
async set(data) {
|
55
|
+
let keys = 0;
|
56
|
+
for (const type in data) {
|
57
|
+
for (const id in data[type]) {
|
58
|
+
cache.set(getUniqueId(type, id), data[type][id]);
|
59
|
+
keys += 1;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
logger.trace({ keys }, 'updated cache');
|
63
|
+
await store.set(data);
|
64
|
+
},
|
65
|
+
async clear() {
|
66
|
+
var _a;
|
67
|
+
cache.flushAll();
|
68
|
+
await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
|
69
|
+
}
|
70
|
+
};
|
71
|
+
}
|
72
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
73
|
+
/**
|
74
|
+
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
75
|
+
* this allows batch read & write operations & improves the performance of the lib
|
76
|
+
* @param state the key store to apply this capability to
|
77
|
+
* @param logger logger to log events
|
78
|
+
* @returns SignalKeyStore with transaction capability
|
79
|
+
*/
|
80
|
+
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
81
|
+
// number of queries made to the DB during the transaction
|
82
|
+
// only there for logging purposes
|
83
|
+
let dbQueriesInTransaction = 0;
|
84
|
+
let transactionCache = {};
|
85
|
+
let mutations = {};
|
86
|
+
let transactionsInProgress = 0;
|
87
|
+
return {
|
88
|
+
get: async (type, ids) => {
|
89
|
+
if (isInTransaction()) {
|
90
|
+
const dict = transactionCache[type];
|
91
|
+
const idsRequiringFetch = dict
|
92
|
+
? ids.filter(item => typeof dict[item] === 'undefined')
|
93
|
+
: ids;
|
94
|
+
// only fetch if there are any items to fetch
|
95
|
+
if (idsRequiringFetch.length) {
|
96
|
+
dbQueriesInTransaction += 1;
|
97
|
+
const result = await state.get(type, idsRequiringFetch);
|
98
|
+
transactionCache[type] || (transactionCache[type] = {});
|
99
|
+
Object.assign(transactionCache[type], result);
|
100
|
+
}
|
101
|
+
return ids.reduce((dict, id) => {
|
102
|
+
var _a;
|
103
|
+
const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
|
104
|
+
if (value) {
|
105
|
+
dict[id] = value;
|
106
|
+
}
|
107
|
+
return dict;
|
108
|
+
}, {});
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
return state.get(type, ids);
|
112
|
+
}
|
113
|
+
},
|
114
|
+
set: data => {
|
115
|
+
if (isInTransaction()) {
|
116
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
117
|
+
for (const key in data) {
|
118
|
+
transactionCache[key] = transactionCache[key] || {};
|
119
|
+
Object.assign(transactionCache[key], data[key]);
|
120
|
+
mutations[key] = mutations[key] || {};
|
121
|
+
Object.assign(mutations[key], data[key]);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
else {
|
125
|
+
return state.set(data);
|
126
|
+
}
|
127
|
+
},
|
128
|
+
isInTransaction,
|
129
|
+
async transaction(work) {
|
130
|
+
let result;
|
131
|
+
transactionsInProgress += 1;
|
132
|
+
if (transactionsInProgress === 1) {
|
133
|
+
logger.trace('entering transaction');
|
134
|
+
}
|
135
|
+
try {
|
136
|
+
result = await work();
|
137
|
+
// commit if this is the outermost transaction
|
138
|
+
if (transactionsInProgress === 1) {
|
139
|
+
if (Object.keys(mutations).length) {
|
140
|
+
logger.trace('committing transaction');
|
141
|
+
// retry mechanism to ensure we've some recovery
|
142
|
+
// in case a transaction fails in the first attempt
|
143
|
+
let tries = maxCommitRetries;
|
144
|
+
while (tries) {
|
145
|
+
tries -= 1;
|
146
|
+
try {
|
147
|
+
await state.set(mutations);
|
148
|
+
logger.trace({ dbQueriesInTransaction }, 'committed transaction');
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
catch (error) {
|
152
|
+
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
153
|
+
await (0, generics_1.delay)(delayBetweenTriesMs);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
logger.trace('no mutations in transaction');
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
finally {
|
163
|
+
transactionsInProgress -= 1;
|
164
|
+
if (transactionsInProgress === 0) {
|
165
|
+
transactionCache = {};
|
166
|
+
mutations = {};
|
167
|
+
dbQueriesInTransaction = 0;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
return result;
|
171
|
+
}
|
172
|
+
};
|
173
|
+
function isInTransaction() {
|
174
|
+
return transactionsInProgress > 0;
|
175
|
+
}
|
176
|
+
};
|
177
|
+
exports.addTransactionCapability = addTransactionCapability;
|
178
|
+
const initAuthCreds = () => {
|
179
|
+
const identityKey = crypto_2.Curve.generateKeyPair();
|
180
|
+
return {
|
181
|
+
noiseKey: crypto_2.Curve.generateKeyPair(),
|
182
|
+
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
183
|
+
signedIdentityKey: identityKey,
|
184
|
+
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
185
|
+
registrationId: (0, generics_1.generateRegistrationId)(),
|
186
|
+
advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
|
187
|
+
processedHistoryMessages: [],
|
188
|
+
nextPreKeyId: 1,
|
189
|
+
firstUnuploadedPreKeyId: 1,
|
190
|
+
accountSyncCounter: 0,
|
191
|
+
accountSettings: {
|
192
|
+
unarchiveChats: false
|
193
|
+
},
|
194
|
+
// mobile creds
|
195
|
+
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
196
|
+
phoneId: (0, uuid_1.v4)(),
|
197
|
+
identityId: (0, crypto_1.randomBytes)(20),
|
198
|
+
registered: false,
|
199
|
+
backupToken: (0, crypto_1.randomBytes)(20),
|
200
|
+
registration: {},
|
201
|
+
pairingCode: undefined,
|
202
|
+
lastPropHash: undefined,
|
203
|
+
routingInfo: undefined,
|
204
|
+
};
|
205
|
+
};
|
206
|
+
exports.initAuthCreds = initAuthCreds;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { BaileysEventEmitter } from '../Types';
|
2
|
+
/**
|
3
|
+
* Captures events from a baileys event emitter & stores them in a file
|
4
|
+
* @param ev The event emitter to read events from
|
5
|
+
* @param filename File to save to
|
6
|
+
*/
|
7
|
+
export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void;
|
8
|
+
/**
|
9
|
+
* Read event file and emit events from there
|
10
|
+
* @param filename filename containing event data
|
11
|
+
* @param delayIntervalMs delay between each event emit
|
12
|
+
*/
|
13
|
+
export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
|
14
|
+
ev: BaileysEventEmitter;
|
15
|
+
task: Promise<void>;
|
16
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.readAndEmitEventStream = exports.captureEventStream = void 0;
|
7
|
+
const events_1 = __importDefault(require("events"));
|
8
|
+
const fs_1 = require("fs");
|
9
|
+
const promises_1 = require("fs/promises");
|
10
|
+
const readline_1 = require("readline");
|
11
|
+
const generics_1 = require("./generics");
|
12
|
+
const make_mutex_1 = require("./make-mutex");
|
13
|
+
/**
|
14
|
+
* Captures events from a baileys event emitter & stores them in a file
|
15
|
+
* @param ev The event emitter to read events from
|
16
|
+
* @param filename File to save to
|
17
|
+
*/
|
18
|
+
const captureEventStream = (ev, filename) => {
|
19
|
+
const oldEmit = ev.emit;
|
20
|
+
// write mutex so data is appended in order
|
21
|
+
const writeMutex = (0, make_mutex_1.makeMutex)();
|
22
|
+
// monkey patch eventemitter to capture all events
|
23
|
+
ev.emit = function (...args) {
|
24
|
+
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
|
25
|
+
const result = oldEmit.apply(ev, args);
|
26
|
+
writeMutex.mutex(async () => {
|
27
|
+
await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
|
28
|
+
});
|
29
|
+
return result;
|
30
|
+
};
|
31
|
+
};
|
32
|
+
exports.captureEventStream = captureEventStream;
|
33
|
+
/**
|
34
|
+
* Read event file and emit events from there
|
35
|
+
* @param filename filename containing event data
|
36
|
+
* @param delayIntervalMs delay between each event emit
|
37
|
+
*/
|
38
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
39
|
+
const ev = new events_1.default();
|
40
|
+
const fireEvents = async () => {
|
41
|
+
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
42
|
+
const fileStream = (0, fs_1.createReadStream)(filename);
|
43
|
+
const rl = (0, readline_1.createInterface)({
|
44
|
+
input: fileStream,
|
45
|
+
crlfDelay: Infinity
|
46
|
+
});
|
47
|
+
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
48
|
+
// ('\r\n') in input.txt as a single line break.
|
49
|
+
for await (const line of rl) {
|
50
|
+
if (line) {
|
51
|
+
const { event, data } = JSON.parse(line);
|
52
|
+
ev.emit(event, data);
|
53
|
+
delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
fileStream.close();
|
57
|
+
};
|
58
|
+
return {
|
59
|
+
ev,
|
60
|
+
task: fireEvents()
|
61
|
+
};
|
62
|
+
};
|
63
|
+
exports.readAndEmitEventStream = readAndEmitEventStream;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types';
|
2
|
+
import { BinaryNode } from '../WABinary';
|
3
|
+
export declare const parseCatalogNode: (node: BinaryNode) => {
|
4
|
+
products: Product[];
|
5
|
+
nextPageCursor: string | undefined;
|
6
|
+
};
|
7
|
+
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
8
|
+
collections: CatalogCollection[];
|
9
|
+
};
|
10
|
+
export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
|
11
|
+
export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
|
12
|
+
export declare const parseProductNode: (productNode: BinaryNode) => Product;
|
13
|
+
/**
|
14
|
+
* Uploads images not already uploaded to WA's servers
|
15
|
+
*/
|
16
|
+
export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
|
17
|
+
/**
|
18
|
+
* Uploads images not already uploaded to WA's servers
|
19
|
+
*/
|
20
|
+
export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
|
21
|
+
url: string;
|
22
|
+
}[]>;
|