@baileys-md/baileys 10.1.0 → 11.0.0
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 +1 -1
- package/README.md +1303 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.js +1 -0
- package/lib/Defaults/index.js +51 -72
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/chats.js +194 -187
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/groups.js +87 -90
- package/lib/Socket/index.js +7 -8
- package/lib/Socket/messages-recv.js +360 -335
- package/lib/Socket/messages-send.js +156 -279
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +144 -213
- package/lib/Socket/socket.js +128 -161
- package/lib/Socket/usync.js +19 -26
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +30 -17
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +31 -47
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +200 -195
- package/lib/Utils/crypto.js +70 -85
- package/lib/Utils/decode-wa-message.js +47 -51
- package/lib/Utils/event-buffer.js +36 -46
- package/lib/Utils/generics.js +116 -188
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
- package/lib/Utils/messages-media.js +236 -368
- package/lib/Utils/messages.js +278 -510
- package/lib/Utils/noise-handler.js +22 -31
- package/lib/{Store → Utils}/object-repository.js +1 -4
- package/lib/Utils/process-message.js +144 -148
- package/lib/Utils/signal.js +71 -64
- package/lib/Utils/use-multi-file-auth-state.js +112 -84
- package/lib/Utils/validate-connection.js +72 -115
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +23 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/encode.js +17 -21
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +11 -33
- package/package.json +25 -54
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
package/lib/Utils/index.js
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__exportStar(require("./messages-media"), exports);
|
|
21
|
-
__exportStar(require("./validate-connection"), exports);
|
|
22
|
-
__exportStar(require("./crypto"), exports);
|
|
23
|
-
__exportStar(require("./signal"), exports);
|
|
24
|
-
__exportStar(require("./noise-handler"), exports);
|
|
25
|
-
__exportStar(require("./history"), exports);
|
|
26
|
-
__exportStar(require("./chat-utils"), exports);
|
|
27
|
-
__exportStar(require("./lt-hash"), exports);
|
|
28
|
-
__exportStar(require("./auth-utils"), exports);
|
|
29
|
-
__exportStar(require("./baileys-event-stream"), exports);
|
|
30
|
-
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
|
-
__exportStar(require("./link-preview"), exports);
|
|
32
|
-
__exportStar(require("./event-buffer"), exports);
|
|
33
|
-
__exportStar(require("./process-message"), exports);
|
|
1
|
+
export * from './generics.js';
|
|
2
|
+
export * from './decode-wa-message.js';
|
|
3
|
+
export * from './messages.js';
|
|
4
|
+
export * from './messages-media.js';
|
|
5
|
+
export * from './validate-connection.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
export * from './signal.js';
|
|
8
|
+
export * from './noise-handler.js';
|
|
9
|
+
export * from './history.js';
|
|
10
|
+
export * from './chat-utils.js';
|
|
11
|
+
export * from './lt-hash.js';
|
|
12
|
+
export * from './auth-utils.js';
|
|
13
|
+
export * from './baileys-event-stream.js';
|
|
14
|
+
export * from './use-multi-file-auth-state.js';
|
|
15
|
+
export * from './link-preview.js';
|
|
16
|
+
export * from './event-buffer.js';
|
|
17
|
+
export * from './process-message.js';
|
|
18
|
+
export * from './make-in-memory-store.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getUrlInfo = void 0;
|
|
37
|
-
const messages_1 = require("./messages");
|
|
38
|
-
const messages_media_1 = require("./messages-media");
|
|
1
|
+
import { prepareWAMessageMedia } from './messages.js';
|
|
2
|
+
import { extractImageThumb, getHttpStream } from './messages-media.js';
|
|
39
3
|
const THUMBNAIL_WIDTH_PX = 192;
|
|
40
4
|
/** Fetches an image and generates a thumbnail for it */
|
|
41
5
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
42
|
-
const stream = await
|
|
43
|
-
const result = await
|
|
6
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
7
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
44
8
|
return result;
|
|
45
9
|
};
|
|
46
10
|
/**
|
|
@@ -49,16 +13,15 @@ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) =>
|
|
|
49
13
|
* @param text first matched URL in text
|
|
50
14
|
* @returns the URL info required to generate link preview
|
|
51
15
|
*/
|
|
52
|
-
const getUrlInfo = async (text, opts = {
|
|
16
|
+
export const getUrlInfo = async (text, opts = {
|
|
53
17
|
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
54
18
|
fetchOpts: { timeout: 3000 }
|
|
55
19
|
}) => {
|
|
56
|
-
var _a;
|
|
57
20
|
try {
|
|
58
21
|
// retries
|
|
59
22
|
const retries = 0;
|
|
60
23
|
const maxRetry = 5;
|
|
61
|
-
const { getLinkPreview } = await
|
|
24
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
62
25
|
let previewLink = text;
|
|
63
26
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
64
27
|
previewLink = 'https://' + previewLink;
|
|
@@ -72,9 +35,9 @@ const getUrlInfo = async (text, opts = {
|
|
|
72
35
|
if (retries >= maxRetry) {
|
|
73
36
|
return false;
|
|
74
37
|
}
|
|
75
|
-
if (forwardedURLObj.hostname === urlObj.hostname
|
|
76
|
-
|
|
77
|
-
|
|
38
|
+
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
39
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
40
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
78
41
|
retries + 1;
|
|
79
42
|
return true;
|
|
80
43
|
}
|
|
@@ -94,24 +57,20 @@ const getUrlInfo = async (text, opts = {
|
|
|
94
57
|
originalThumbnailUrl: image
|
|
95
58
|
};
|
|
96
59
|
if (opts.uploadImage) {
|
|
97
|
-
const { imageMessage } = await
|
|
60
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
98
61
|
upload: opts.uploadImage,
|
|
99
62
|
mediaTypeOverride: 'thumbnail-link',
|
|
100
63
|
options: opts.fetchOpts
|
|
101
64
|
});
|
|
102
|
-
urlInfo.jpegThumbnail =
|
|
103
|
-
? Buffer.from(imageMessage.jpegThumbnail)
|
|
104
|
-
: undefined;
|
|
65
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
105
66
|
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
106
67
|
}
|
|
107
68
|
else {
|
|
108
69
|
try {
|
|
109
|
-
urlInfo.jpegThumbnail = image
|
|
110
|
-
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
111
|
-
: undefined;
|
|
70
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
112
71
|
}
|
|
113
72
|
catch (error) {
|
|
114
|
-
|
|
73
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
115
74
|
}
|
|
116
75
|
}
|
|
117
76
|
return urlInfo;
|
|
@@ -123,4 +82,4 @@ const getUrlInfo = async (text, opts = {
|
|
|
123
82
|
}
|
|
124
83
|
}
|
|
125
84
|
};
|
|
126
|
-
|
|
85
|
+
//# sourceMappingURL=link-preview.js.map
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const pino_1 = __importDefault(require("pino"));
|
|
7
|
-
exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
3
|
+
//# sourceMappingURL=logger.js.map
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -1,51 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LT_HASH_ANTI_TAMPERING = void 0;
|
|
4
|
-
const crypto_1 = require("./crypto");
|
|
1
|
+
import { hkdf } from './crypto.js';
|
|
5
2
|
/**
|
|
6
3
|
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
7
4
|
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
8
5
|
* if the same series of mutations was made sequentially.
|
|
9
6
|
*/
|
|
10
7
|
const o = 128;
|
|
11
|
-
class
|
|
8
|
+
class LTHash {
|
|
12
9
|
constructor(e) {
|
|
13
10
|
this.salt = e;
|
|
14
11
|
}
|
|
15
|
-
add(e, t) {
|
|
16
|
-
var r = this;
|
|
12
|
+
async add(e, t) {
|
|
17
13
|
for (const item of t) {
|
|
18
|
-
e =
|
|
14
|
+
e = await this._addSingle(e, item);
|
|
19
15
|
}
|
|
20
16
|
return e;
|
|
21
17
|
}
|
|
22
|
-
subtract(e, t) {
|
|
23
|
-
var r = this;
|
|
18
|
+
async subtract(e, t) {
|
|
24
19
|
for (const item of t) {
|
|
25
|
-
e =
|
|
20
|
+
e = await this._subtractSingle(e, item);
|
|
26
21
|
}
|
|
27
22
|
return e;
|
|
28
23
|
}
|
|
29
|
-
subtractThenAdd(e,
|
|
30
|
-
|
|
31
|
-
return
|
|
24
|
+
async subtractThenAdd(e, addList, subtractList) {
|
|
25
|
+
const subtracted = await this.subtract(e, subtractList);
|
|
26
|
+
return this.add(subtracted, addList);
|
|
32
27
|
}
|
|
33
28
|
async _addSingle(e, t) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
|
|
29
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
30
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
37
31
|
}
|
|
38
32
|
async _subtractSingle(e, t) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
|
|
33
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
34
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
42
35
|
}
|
|
43
|
-
performPointwiseWithOverflow(e, t,
|
|
44
|
-
const n = new DataView(e)
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
performPointwiseWithOverflow(e, t, op) {
|
|
37
|
+
const n = new DataView(e);
|
|
38
|
+
const i = new DataView(t);
|
|
39
|
+
const out = new ArrayBuffer(n.byteLength);
|
|
40
|
+
const s = new DataView(out);
|
|
41
|
+
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
42
|
+
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
47
43
|
}
|
|
48
|
-
return
|
|
44
|
+
return out;
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
|
-
|
|
47
|
+
export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
|
|
48
|
+
//# sourceMappingURL=lt-hash.js.map
|
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
10
|
-
const Utils_1 = require("../Utils");
|
|
11
|
-
const WABinary_1 = require("../WABinary");
|
|
12
|
-
const make_ordered_dictionary_1 = __importDefault(require("./make-ordered-dictionary"));
|
|
13
|
-
const object_repository_1 = require("./object-repository");
|
|
14
|
-
const waChatKey = (pin) => ({
|
|
1
|
+
import * as WAProto_1 from "../../WAProto/index.js"
|
|
2
|
+
import * as Defaults_1 from "../Defaults/index.js"
|
|
3
|
+
import * as LabelAssociation_1 from "../Types/LabelAssociation.js"
|
|
4
|
+
import * as Utils_1 from "../Utils/index.js"
|
|
5
|
+
import * as WABinary_1 from "../WABinary/index.js"
|
|
6
|
+
import make_ordered_dictionary_1 from "./make-ordered-dictionary.js"
|
|
7
|
+
import * as object_repository_1 from "./object-repository.js"
|
|
8
|
+
export const waChatKey = (pin) => ({
|
|
15
9
|
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
16
10
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
17
11
|
});
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
exports.waMessageID = waMessageID;
|
|
21
|
-
exports.waLabelAssociationKey = {
|
|
12
|
+
export const waMessageID = (m) => m.key.id || '';
|
|
13
|
+
export const waLabelAssociationKey = {
|
|
22
14
|
key: (la) => (la.type === LabelAssociation_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
23
15
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
24
16
|
};
|
|
25
|
-
const makeMessagesDictionary = () => (0, make_ordered_dictionary_1
|
|
26
|
-
|
|
17
|
+
const makeMessagesDictionary = () => (0, make_ordered_dictionary_1)(waMessageID);
|
|
18
|
+
export const makeInMemoryStore = async (config) => {
|
|
27
19
|
const socket = config.socket;
|
|
28
|
-
const chatKey = config.chatKey || (0,
|
|
29
|
-
const labelAssociationKey = config.labelAssociationKey ||
|
|
20
|
+
const chatKey = config.chatKey || (0, waChatKey)(true);
|
|
21
|
+
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
|
|
30
22
|
const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
|
-
const KeyedDB =
|
|
23
|
+
const KeyedDB = ((await import ('@baileys-md/keyed-db')).default).default;
|
|
32
24
|
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
25
|
const messages = {};
|
|
34
26
|
const contacts = {};
|
|
@@ -412,14 +404,14 @@ exports.default = (config) => {
|
|
|
412
404
|
},
|
|
413
405
|
toJSON,
|
|
414
406
|
fromJSON,
|
|
415
|
-
writeToFile: (path) => {
|
|
407
|
+
writeToFile: async (path) => {
|
|
416
408
|
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
417
|
-
const { writeFileSync } =
|
|
409
|
+
const { writeFileSync } = await import('fs');
|
|
418
410
|
writeFileSync(path, JSON.stringify(toJSON()));
|
|
419
411
|
},
|
|
420
|
-
readFromFile: (path) => {
|
|
412
|
+
readFromFile: async (path) => {
|
|
421
413
|
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
422
|
-
const { readFileSync, existsSync } =
|
|
414
|
+
const { readFileSync, existsSync } = await import('fs');
|
|
423
415
|
if (existsSync(path)) {
|
|
424
416
|
logger.debug({ path }, 'reading from file');
|
|
425
417
|
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
|
-
const makeMutex = () => {
|
|
1
|
+
export const makeMutex = () => {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
3
|
let task = Promise.resolve();
|
|
6
4
|
let taskTimeout;
|
|
7
5
|
return {
|
|
@@ -12,7 +10,7 @@ const makeMutex = () => {
|
|
|
12
10
|
try {
|
|
13
11
|
await task;
|
|
14
12
|
}
|
|
15
|
-
catch
|
|
13
|
+
catch { }
|
|
16
14
|
try {
|
|
17
15
|
// execute the current task
|
|
18
16
|
const result = await code();
|
|
@@ -25,19 +23,18 @@ const makeMutex = () => {
|
|
|
25
23
|
// we replace the existing task, appending the new piece of execution to it
|
|
26
24
|
// so the next task will have to wait for this one to finish
|
|
27
25
|
return task;
|
|
28
|
-
}
|
|
26
|
+
}
|
|
29
27
|
};
|
|
30
28
|
};
|
|
31
|
-
|
|
32
|
-
const makeKeyedMutex = () => {
|
|
29
|
+
export const makeKeyedMutex = () => {
|
|
33
30
|
const map = {};
|
|
34
31
|
return {
|
|
35
32
|
mutex(key, task) {
|
|
36
33
|
if (!map[key]) {
|
|
37
|
-
map[key] =
|
|
34
|
+
map[key] = makeMutex();
|
|
38
35
|
}
|
|
39
36
|
return map[key].mutex(task);
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
39
|
};
|
|
43
|
-
|
|
40
|
+
//# sourceMappingURL=make-mutex.js.map
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
function makeOrderedDictionary(idGetter) {
|
|
4
2
|
const array = [];
|
|
5
3
|
const dict = {};
|
|
@@ -78,4 +76,4 @@ function makeOrderedDictionary(idGetter) {
|
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
78
|
}
|
|
81
|
-
|
|
79
|
+
export default makeOrderedDictionary;
|