@arcaelas/whatsapp 4.2.0 → 4.4.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/build/cjs/index.d.ts +1 -1
- package/build/cjs/index.js +4 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/lib/bot/decorator.d.ts +18 -1
- package/build/cjs/lib/bot/decorator.js +20 -14
- package/build/cjs/lib/bot/decorator.js.map +1 -1
- package/build/cjs/lib/bot/decorators.d.ts +1 -1
- package/build/cjs/lib/bot/decorators.js +6 -20
- package/build/cjs/lib/bot/decorators.js.map +1 -1
- package/build/cjs/lib/contact/index.d.ts +8 -0
- package/build/cjs/lib/contact/index.js +14 -5
- package/build/cjs/lib/contact/index.js.map +1 -1
- package/build/cjs/lib/message/index.js +11 -8
- package/build/cjs/lib/message/index.js.map +1 -1
- package/build/cjs/lib/store/engine/index.d.ts +1 -0
- package/build/cjs/lib/store/engine/index.js +3 -1
- package/build/cjs/lib/store/engine/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.js +1 -7
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/redis/index.js +1 -7
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/s3/index.d.ts +66 -0
- package/build/cjs/lib/store/engine/lib/s3/index.js +169 -0
- package/build/cjs/lib/store/engine/lib/s3/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +1 -1
- package/build/cjs/lib/store/index.js +2 -1
- package/build/cjs/lib/store/index.js.map +1 -1
- package/build/cjs/lib/whatsapp/index.d.ts +8 -0
- package/build/cjs/lib/whatsapp/index.js +90 -91
- package/build/cjs/lib/whatsapp/index.js.map +1 -1
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/bot/decorator.d.ts +18 -1
- package/build/esm/lib/bot/decorator.js +18 -14
- package/build/esm/lib/bot/decorator.js.map +1 -1
- package/build/esm/lib/bot/decorators.d.ts +1 -1
- package/build/esm/lib/bot/decorators.js +7 -21
- package/build/esm/lib/bot/decorators.js.map +1 -1
- package/build/esm/lib/contact/index.d.ts +8 -0
- package/build/esm/lib/contact/index.js +13 -5
- package/build/esm/lib/contact/index.js.map +1 -1
- package/build/esm/lib/message/index.js +11 -8
- package/build/esm/lib/message/index.js.map +1 -1
- package/build/esm/lib/store/engine/index.d.ts +1 -0
- package/build/esm/lib/store/engine/index.js +1 -0
- package/build/esm/lib/store/engine/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/file_system/index.js +1 -7
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/redis/index.js +1 -7
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/s3/index.d.ts +66 -0
- package/build/esm/lib/store/engine/lib/s3/index.js +165 -0
- package/build/esm/lib/store/engine/lib/s3/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +1 -1
- package/build/esm/lib/store/index.js +1 -1
- package/build/esm/lib/store/index.js.map +1 -1
- package/build/esm/lib/whatsapp/index.d.ts +8 -0
- package/build/esm/lib/whatsapp/index.js +91 -92
- package/build/esm/lib/whatsapp/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -88,13 +88,7 @@ class RedisEngine {
|
|
|
88
88
|
return [];
|
|
89
89
|
}
|
|
90
90
|
const raws = await this._client.mget(members.map((m) => this._doc_key(m)));
|
|
91
|
-
|
|
92
|
-
for (const raw of raws) {
|
|
93
|
-
if (raw !== null) {
|
|
94
|
-
result.push(raw);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return result;
|
|
91
|
+
return raws.filter((raw) => raw !== null);
|
|
98
92
|
}
|
|
99
93
|
/**
|
|
100
94
|
* Cuenta hijos directos en O(1) usando ZCARD.
|
|
@@ -1 +1 @@
|
|
|
1
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AI,CAAC,CAAC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,eAAe,CAAC,OAAe;QAC3C,IAAI,MAAM,GAAoB,GAAG,CAAC;QAClC,GAAG,CAAC;YACF,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACtF,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,QAAQ,MAAM,KAAK,GAAG,EAAE;IAC3B,CAAC;CACF;AA7GD,kCA6GC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file store/engine/lib/s3/index.ts
|
|
3
|
+
* @description Driver de persistencia con AWS S3 (caché local opcional).
|
|
4
|
+
* AWS S3 persistence driver (optional local cache).
|
|
5
|
+
*/
|
|
6
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
7
|
+
import type { Engine } from '../../../../../lib/store/engine';
|
|
8
|
+
/**
|
|
9
|
+
* Configuración de la caché local. Cada entrada se limpia con un `setTimeout`
|
|
10
|
+
* (no hay campo de expiración en la lectura). `when` decide qué keys se cachean;
|
|
11
|
+
* el resto va directo a S3.
|
|
12
|
+
* Local cache configuration. Each entry is cleared with a `setTimeout` (no
|
|
13
|
+
* expiration field on read). `when` decides which keys get cached; everything
|
|
14
|
+
* else goes straight to S3.
|
|
15
|
+
*/
|
|
16
|
+
interface CacheOptions {
|
|
17
|
+
/** Tiempo de vida de cada entrada en ms. / Time-to-live of each entry in ms. */
|
|
18
|
+
ttl: number;
|
|
19
|
+
/** Predicado que decide si un path se cachea. / Predicate deciding whether a path is cached. */
|
|
20
|
+
when(key: string): boolean;
|
|
21
|
+
}
|
|
22
|
+
interface S3EngineOptions {
|
|
23
|
+
/** Cliente S3 ya configurado. / Pre-configured S3 client. */
|
|
24
|
+
s3: S3Client;
|
|
25
|
+
/** Nombre del bucket. / Bucket name. */
|
|
26
|
+
bucket: string;
|
|
27
|
+
/** Prefijo base de las keys dentro del bucket. / Base key prefix inside the bucket. */
|
|
28
|
+
basedir: string;
|
|
29
|
+
/**
|
|
30
|
+
* Caché local: `false` la desactiva; un objeto `{ ttl, when }` la configura.
|
|
31
|
+
* Default: `false` (sin caché).
|
|
32
|
+
* Local cache: `false` disables it; an object `{ ttl, when }` configures it.
|
|
33
|
+
* Default: `false` (no cache).
|
|
34
|
+
*/
|
|
35
|
+
cache?: false | CacheOptions;
|
|
36
|
+
}
|
|
37
|
+
export declare class S3Engine implements Engine {
|
|
38
|
+
private readonly _client;
|
|
39
|
+
private readonly _bucket;
|
|
40
|
+
private readonly _prefix;
|
|
41
|
+
private readonly _cache_opts;
|
|
42
|
+
/** @internal Caché local de documentos, con su timer de expiración. / Local cache of documents, with its expiration timer. */
|
|
43
|
+
private readonly _cache;
|
|
44
|
+
constructor(options: S3EngineOptions);
|
|
45
|
+
private _key;
|
|
46
|
+
/**
|
|
47
|
+
* Indica si un path es elegible para caché según la configuración `when`.
|
|
48
|
+
* Reports whether a path is eligible for caching per the `when` config.
|
|
49
|
+
*/
|
|
50
|
+
private _cacheable;
|
|
51
|
+
/**
|
|
52
|
+
* Guarda un valor en la caché local y programa su limpieza con un `setTimeout`.
|
|
53
|
+
* Reemplaza el timer previo si la key ya estaba cacheada para no acumular timers.
|
|
54
|
+
* Stores a value in the local cache and schedules its cleanup with a `setTimeout`.
|
|
55
|
+
* Replaces the previous timer when the key was already cached so timers don't pile up.
|
|
56
|
+
*/
|
|
57
|
+
private _cache_set;
|
|
58
|
+
get(key: string): Promise<string | null>;
|
|
59
|
+
set(key: string, value: string): Promise<void>;
|
|
60
|
+
list(path: string, offset?: number, limit?: number): Promise<string[]>;
|
|
61
|
+
delete_prefix(prefix: string): Promise<number>;
|
|
62
|
+
unset(path: string): Promise<boolean>;
|
|
63
|
+
count(path: string): Promise<number>;
|
|
64
|
+
clear(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file store/engine/lib/s3/index.ts
|
|
4
|
+
* @description Driver de persistencia con AWS S3 (caché local opcional).
|
|
5
|
+
* AWS S3 persistence driver (optional local cache).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.S3Engine = void 0;
|
|
9
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
10
|
+
/**
|
|
11
|
+
* Normaliza un path colapsando slashes redundantes.
|
|
12
|
+
* Normalizes a path by collapsing redundant slashes.
|
|
13
|
+
*/
|
|
14
|
+
function normalize_path(path) {
|
|
15
|
+
return path.replace(/\/+/g, '/').replace(/^\/|\/$/g, '');
|
|
16
|
+
}
|
|
17
|
+
class S3Engine {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
/** @internal Caché local de documentos, con su timer de expiración. / Local cache of documents, with its expiration timer. */
|
|
20
|
+
this._cache = new Map();
|
|
21
|
+
this._client = options.s3;
|
|
22
|
+
this._bucket = options.bucket;
|
|
23
|
+
this._prefix = options.basedir.endsWith('/') ? options.basedir : `${options.basedir}/`;
|
|
24
|
+
this._cache_opts = options.cache ?? false;
|
|
25
|
+
}
|
|
26
|
+
_key(key) {
|
|
27
|
+
return `${this._prefix}${normalize_path(key).replace(/@/g, '_at_')}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Indica si un path es elegible para caché según la configuración `when`.
|
|
31
|
+
* Reports whether a path is eligible for caching per the `when` config.
|
|
32
|
+
*/
|
|
33
|
+
_cacheable(path) {
|
|
34
|
+
return this._cache_opts !== false && this._cache_opts.when(path);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Guarda un valor en la caché local y programa su limpieza con un `setTimeout`.
|
|
38
|
+
* Reemplaza el timer previo si la key ya estaba cacheada para no acumular timers.
|
|
39
|
+
* Stores a value in the local cache and schedules its cleanup with a `setTimeout`.
|
|
40
|
+
* Replaces the previous timer when the key was already cached so timers don't pile up.
|
|
41
|
+
*/
|
|
42
|
+
_cache_set(path, value) {
|
|
43
|
+
if (this._cache_opts === false) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
clearTimeout(this._cache.get(path)?.timer);
|
|
47
|
+
this._cache.set(path, {
|
|
48
|
+
value,
|
|
49
|
+
timer: setTimeout(() => this._cache.delete(path), this._cache_opts.ttl),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async get(key) {
|
|
53
|
+
if (this._cacheable(key) && this._cache.has(key)) {
|
|
54
|
+
return this._cache.get(key).value;
|
|
55
|
+
}
|
|
56
|
+
const value = await (async () => {
|
|
57
|
+
try {
|
|
58
|
+
const res = await this._client.send(new client_s3_1.GetObjectCommand({ Bucket: this._bucket, Key: this._key(key) }));
|
|
59
|
+
return (await res.Body?.transformToString('utf-8')) ?? null;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
if (this._cacheable(key)) {
|
|
66
|
+
this._cache_set(key, value);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
async set(key, value) {
|
|
71
|
+
const remote = this._client.send(new client_s3_1.PutObjectCommand({ Bucket: this._bucket, Key: this._key(key), Body: value, ContentType: 'application/json' }));
|
|
72
|
+
if (this._cacheable(key)) {
|
|
73
|
+
this._cache_set(key, value);
|
|
74
|
+
}
|
|
75
|
+
await remote;
|
|
76
|
+
}
|
|
77
|
+
async list(path, offset = 0, limit = 50) {
|
|
78
|
+
const parent = `${this._prefix}${normalize_path(path).replace(/@/g, '_at_')}/`;
|
|
79
|
+
const children = new Map();
|
|
80
|
+
let token;
|
|
81
|
+
do {
|
|
82
|
+
const res = await this._client.send(new client_s3_1.ListObjectsV2Command({
|
|
83
|
+
Bucket: this._bucket,
|
|
84
|
+
Prefix: parent,
|
|
85
|
+
ContinuationToken: token,
|
|
86
|
+
MaxKeys: 1000,
|
|
87
|
+
}));
|
|
88
|
+
for (const obj of res.Contents ?? []) {
|
|
89
|
+
if (!obj.Key)
|
|
90
|
+
continue;
|
|
91
|
+
const rest = obj.Key.slice(parent.length);
|
|
92
|
+
const child_key = `${parent}${rest.split('/')[0]}`;
|
|
93
|
+
const mtime = obj.LastModified?.getTime() ?? 0;
|
|
94
|
+
children.set(child_key, Math.max(children.get(child_key) ?? 0, mtime));
|
|
95
|
+
}
|
|
96
|
+
token = res.NextContinuationToken;
|
|
97
|
+
} while (token);
|
|
98
|
+
const ordered = [...children.entries()]
|
|
99
|
+
.sort((a, b) => b[1] - a[1])
|
|
100
|
+
.slice(offset, offset + limit)
|
|
101
|
+
.map(([key]) => key);
|
|
102
|
+
const values = await Promise.all(ordered.map(async (key) => {
|
|
103
|
+
try {
|
|
104
|
+
const res = await this._client.send(new client_s3_1.GetObjectCommand({ Bucket: this._bucket, Key: key }));
|
|
105
|
+
return (await res.Body?.transformToString('utf-8')) ?? null;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
return values.filter((value) => value !== null);
|
|
112
|
+
}
|
|
113
|
+
async delete_prefix(prefix) {
|
|
114
|
+
const full_prefix = `${this._prefix}${normalize_path(prefix).replace(/@/g, '_at_')}`;
|
|
115
|
+
let deleted = 0;
|
|
116
|
+
let token;
|
|
117
|
+
do {
|
|
118
|
+
const res = await this._client.send(new client_s3_1.ListObjectsV2Command({
|
|
119
|
+
Bucket: this._bucket,
|
|
120
|
+
Prefix: full_prefix,
|
|
121
|
+
ContinuationToken: token,
|
|
122
|
+
MaxKeys: 1000,
|
|
123
|
+
}));
|
|
124
|
+
const keys = (res.Contents ?? []).filter((o) => o.Key).map((o) => ({ Key: o.Key }));
|
|
125
|
+
if (keys.length) {
|
|
126
|
+
await this._client.send(new client_s3_1.DeleteObjectsCommand({ Bucket: this._bucket, Delete: { Objects: keys } }));
|
|
127
|
+
deleted += keys.length;
|
|
128
|
+
}
|
|
129
|
+
token = res.NextContinuationToken;
|
|
130
|
+
} while (token);
|
|
131
|
+
return deleted;
|
|
132
|
+
}
|
|
133
|
+
async unset(path) {
|
|
134
|
+
if (this._cacheable(path)) {
|
|
135
|
+
for (const key of this._cache.keys()) {
|
|
136
|
+
if (key === path || key.startsWith(`${path}/`)) {
|
|
137
|
+
clearTimeout(this._cache.get(key).timer);
|
|
138
|
+
this._cache.delete(key);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return (await this.delete_prefix(path)) > 0;
|
|
143
|
+
}
|
|
144
|
+
async count(path) {
|
|
145
|
+
const full_prefix = `${this._prefix}${normalize_path(path).replace(/@/g, '_at_')}`;
|
|
146
|
+
let total = 0;
|
|
147
|
+
let token;
|
|
148
|
+
do {
|
|
149
|
+
const res = await this._client.send(new client_s3_1.ListObjectsV2Command({
|
|
150
|
+
Bucket: this._bucket,
|
|
151
|
+
Prefix: full_prefix,
|
|
152
|
+
ContinuationToken: token,
|
|
153
|
+
MaxKeys: 1000,
|
|
154
|
+
}));
|
|
155
|
+
total += res.Contents?.length ?? 0;
|
|
156
|
+
token = res.NextContinuationToken;
|
|
157
|
+
} while (token);
|
|
158
|
+
return total;
|
|
159
|
+
}
|
|
160
|
+
async clear() {
|
|
161
|
+
for (const { timer } of this._cache.values()) {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
}
|
|
164
|
+
this._cache.clear();
|
|
165
|
+
await this.delete_prefix('');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.S3Engine = S3Engine;
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/store/engine/lib/s3/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,kDAA8H;AAG9H;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAiCD,MAAa,QAAQ;IAQjB,YAAY,OAAwB;QAHpC,8HAA8H;QAC7G,WAAM,GAAG,IAAI,GAAG,EAA0E,CAAC;QAGxG,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,GAAG,CAAC;QACvF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IAC9C,CAAC;IAEO,IAAI,CAAC,GAAW;QACpB,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;IACzE,CAAC;IAED;;;OAGG;IACK,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,WAAW,KAAK,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAA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,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,KAAK;QACP,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;CACJ;AA/KD,4BA+KC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description Barrel del módulo store — reexporta Engine + drivers y expone helpers de serialización.
|
|
4
4
|
* Store module barrel — re-exports Engine + drivers and provides serialization helpers.
|
|
5
5
|
*/
|
|
6
|
-
export { FileSystemEngine, RedisEngine, type Engine, type RedisClient } from '../../lib/store/engine';
|
|
6
|
+
export { FileSystemEngine, RedisEngine, S3Engine, type Engine, type RedisClient } from '../../lib/store/engine';
|
|
7
7
|
/**
|
|
8
8
|
* Serializa un documento a string preservando Buffers con BufferJSON de baileys.
|
|
9
9
|
* Serializes a document to string preserving Buffers via baileys BufferJSON.
|
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* Store module barrel — re-exports Engine + drivers and provides serialization helpers.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.RedisEngine = exports.FileSystemEngine = void 0;
|
|
8
|
+
exports.S3Engine = exports.RedisEngine = exports.FileSystemEngine = void 0;
|
|
9
9
|
exports.serialize = serialize;
|
|
10
10
|
exports.deserialize = deserialize;
|
|
11
11
|
const baileys_1 = require("baileys");
|
|
12
12
|
var engine_1 = require("../../lib/store/engine");
|
|
13
13
|
Object.defineProperty(exports, "FileSystemEngine", { enumerable: true, get: function () { return engine_1.FileSystemEngine; } });
|
|
14
14
|
Object.defineProperty(exports, "RedisEngine", { enumerable: true, get: function () { return engine_1.RedisEngine; } });
|
|
15
|
+
Object.defineProperty(exports, "S3Engine", { enumerable: true, get: function () { return engine_1.S3Engine; } });
|
|
15
16
|
/**
|
|
16
17
|
* Serializa un documento a string preservando Buffers con BufferJSON de baileys.
|
|
17
18
|
* Serializes a document to string preserving Buffers via baileys BufferJSON.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/store/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAaH,8BAEC;AASD,kCAKC;AA3BD,qCAAqC;AAErC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/store/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAaH,8BAEC;AASD,kCAKC;AA3BD,qCAAqC;AAErC,6CAA4G;AAAnG,0GAAA,gBAAgB,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAEhD;;;;;;GAMG;AACH,SAAgB,SAAS,CAAI,GAAM;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,oBAAU,CAAC,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAI,GAAkB;IAC/C,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,oBAAU,CAAC,OAAO,CAAM,CAAC;AAClD,CAAC"}
|
|
@@ -158,6 +158,14 @@ export declare class WhatsApp {
|
|
|
158
158
|
* @internal
|
|
159
159
|
*/
|
|
160
160
|
private _attach_business_handlers;
|
|
161
|
+
/**
|
|
162
|
+
* Persiste un contacto y su índice LID; emite `contact:created` solo si es nuevo.
|
|
163
|
+
* Persists a contact and its LID index; emits `contact:created` only when new.
|
|
164
|
+
*
|
|
165
|
+
* @param raw - Documento del contacto a persistir / Contact document to persist
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
private _persist_contact;
|
|
161
169
|
/** @internal */
|
|
162
170
|
private _handle_contacts_upsert;
|
|
163
171
|
/** @internal */
|
|
@@ -173,7 +173,7 @@ class WhatsApp {
|
|
|
173
173
|
keys: {
|
|
174
174
|
get: async (type, ids) => {
|
|
175
175
|
const data = {};
|
|
176
|
-
|
|
176
|
+
await Promise.all(ids.map(async (id) => {
|
|
177
177
|
const value = (0, store_1.deserialize)(await this.engine.get(`/session/${type}/${id}`));
|
|
178
178
|
if (value) {
|
|
179
179
|
data[id] =
|
|
@@ -181,21 +181,13 @@ class WhatsApp {
|
|
|
181
181
|
? baileys_1.proto.Message.AppStateSyncKeyData.create(value)
|
|
182
182
|
: value;
|
|
183
183
|
}
|
|
184
|
-
}
|
|
184
|
+
}));
|
|
185
185
|
return data;
|
|
186
186
|
},
|
|
187
187
|
set: async (data) => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (value != null) {
|
|
192
|
-
await this.engine.set(`/session/${category}/${id}`, (0, store_1.serialize)(value));
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
await this.engine.unset(`/session/${category}/${id}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
188
|
+
await Promise.all(Object.entries(data).flatMap(([category, entries]) => Object.entries(entries).map(([id, value]) => value != null
|
|
189
|
+
? this.engine.set(`/session/${category}/${id}`, (0, store_1.serialize)(value))
|
|
190
|
+
: this.engine.unset(`/session/${category}/${id}`))));
|
|
199
191
|
},
|
|
200
192
|
},
|
|
201
193
|
},
|
|
@@ -359,12 +351,30 @@ class WhatsApp {
|
|
|
359
351
|
// void this._handle_messages_reaction(reactions);
|
|
360
352
|
// });
|
|
361
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Persiste un contacto y su índice LID; emite `contact:created` solo si es nuevo.
|
|
356
|
+
* Persists a contact and its LID index; emits `contact:created` only when new.
|
|
357
|
+
*
|
|
358
|
+
* @param raw - Documento del contacto a persistir / Contact document to persist
|
|
359
|
+
* @internal
|
|
360
|
+
*/
|
|
361
|
+
async _persist_contact(raw) {
|
|
362
|
+
const existing = await this.engine.get(`/contact/${raw.id}`);
|
|
363
|
+
await this.engine.set(`/contact/${raw.id}`, (0, store_1.serialize)(raw));
|
|
364
|
+
if (raw.lid) {
|
|
365
|
+
await this.engine.set(`/lid/${raw.lid}`, (0, store_1.serialize)(raw.id));
|
|
366
|
+
}
|
|
367
|
+
if (existing === null) {
|
|
368
|
+
const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${raw.id}`));
|
|
369
|
+
const chat_instance = new this.Chat(cached_chat ?? { id: raw.id, name: (0, contact_1.contact_name)(raw) });
|
|
370
|
+
this._event.emit('contact:created', new this.Contact(raw, chat_instance), chat_instance, this);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
362
373
|
/** @internal */
|
|
363
374
|
async _handle_contacts_upsert(contacts) {
|
|
364
375
|
for (const c of contacts) {
|
|
365
376
|
if (c.id) {
|
|
366
|
-
|
|
367
|
-
const raw = {
|
|
377
|
+
await this._persist_contact({
|
|
368
378
|
id: c.id,
|
|
369
379
|
lid: c.lid ?? null,
|
|
370
380
|
name: c.name ?? null,
|
|
@@ -372,16 +382,7 @@ class WhatsApp {
|
|
|
372
382
|
verified_name: c.verifiedName ?? null,
|
|
373
383
|
img_url: c.imgUrl ?? null,
|
|
374
384
|
status: c.status ?? null,
|
|
375
|
-
};
|
|
376
|
-
await this.engine.set(`/contact/${c.id}`, (0, store_1.serialize)(raw));
|
|
377
|
-
if (raw.lid) {
|
|
378
|
-
await this.engine.set(`/lid/${raw.lid}`, (0, store_1.serialize)(raw.id));
|
|
379
|
-
}
|
|
380
|
-
if (existing === null) {
|
|
381
|
-
const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${raw.id}`));
|
|
382
|
-
const chat_instance = new this.Chat(cached_chat ?? { id: raw.id, name: raw.name ?? raw.notify ?? raw.id.split('@')[0] });
|
|
383
|
-
this._event.emit('contact:created', new this.Contact(raw, chat_instance), chat_instance, this);
|
|
384
|
-
}
|
|
385
|
+
});
|
|
385
386
|
}
|
|
386
387
|
}
|
|
387
388
|
}
|
|
@@ -391,22 +392,13 @@ class WhatsApp {
|
|
|
391
392
|
if (c.id) {
|
|
392
393
|
const current = (0, store_1.deserialize)(await this.engine.get(`/contact/${c.id}`));
|
|
393
394
|
if (current) {
|
|
394
|
-
const patch = {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
if (c.imgUrl) {
|
|
402
|
-
patch.img_url = c.imgUrl;
|
|
403
|
-
}
|
|
404
|
-
if (c.status) {
|
|
405
|
-
patch.status = c.status;
|
|
406
|
-
}
|
|
407
|
-
if (c.lid) {
|
|
408
|
-
patch.lid = c.lid;
|
|
409
|
-
}
|
|
395
|
+
const patch = {
|
|
396
|
+
...(c.notify && { notify: c.notify }),
|
|
397
|
+
...(c.name && { name: c.name }),
|
|
398
|
+
...(c.imgUrl && { img_url: c.imgUrl }),
|
|
399
|
+
...(c.status && { status: c.status }),
|
|
400
|
+
...(c.lid && { lid: c.lid }),
|
|
401
|
+
};
|
|
410
402
|
if (Object.keys(patch).length > 0) {
|
|
411
403
|
const merged = { ...current, ...patch };
|
|
412
404
|
await this.engine.set(`/contact/${c.id}`, (0, store_1.serialize)(merged));
|
|
@@ -414,7 +406,7 @@ class WhatsApp {
|
|
|
414
406
|
await this.engine.set(`/lid/${patch.lid}`, (0, store_1.serialize)(c.id));
|
|
415
407
|
}
|
|
416
408
|
const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${c.id}`));
|
|
417
|
-
const chat_instance = new this.Chat(cached_chat ?? { id: c.id, name:
|
|
409
|
+
const chat_instance = new this.Chat(cached_chat ?? { id: c.id, name: (0, contact_1.contact_name)(merged) });
|
|
418
410
|
this._event.emit('contact:updated', new this.Contact(merged, chat_instance), chat_instance, this);
|
|
419
411
|
}
|
|
420
412
|
}
|
|
@@ -636,45 +628,60 @@ class WhatsApp {
|
|
|
636
628
|
if (poll_doc && message_secret) {
|
|
637
629
|
try {
|
|
638
630
|
const poll_key = poll_doc.raw.key ?? {};
|
|
639
|
-
//
|
|
640
|
-
//
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
//
|
|
631
|
+
// La identidad propia del HMAC depende del addressing del chat
|
|
632
|
+
// (LID en @lid, PN en @s.whatsapp.net), así que para las posiciones
|
|
633
|
+
// fromMe se intenta descifrar con ambas: AES-GCM autentica, la
|
|
634
|
+
// clave equivocada lanza y se prueba la siguiente.
|
|
635
|
+
// Own HMAC identity depends on chat addressing (LID on @lid, PN on
|
|
636
|
+
// @s.whatsapp.net), so fromMe positions try both candidates:
|
|
637
|
+
// AES-GCM authenticates, a wrong key throws and the next is tried.
|
|
644
638
|
const self_id = this._socket?.user?.id ?? '';
|
|
645
639
|
const self_lid = this._socket?.user?.lid ?? '';
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
640
|
+
const selves = [...new Set([self_lid, self_id].filter(Boolean))];
|
|
641
|
+
const foreign_voter = msg.key.remoteJid?.endsWith('@lid')
|
|
642
|
+
? msg.key.remoteJid
|
|
643
|
+
: msg.key.participant ||
|
|
644
|
+
msg.key.remoteJidAlt ||
|
|
645
|
+
msg.key.remoteJid ||
|
|
646
|
+
'';
|
|
647
|
+
const foreign_creator = poll_key.remoteJid?.endsWith('@lid')
|
|
648
|
+
? poll_key.remoteJid
|
|
649
|
+
: poll_key.participant ||
|
|
650
|
+
poll_key.remoteJidAlt ||
|
|
651
|
+
poll_key.remoteJid ||
|
|
652
|
+
'';
|
|
653
|
+
const voters = msg.key.fromMe ? selves : [foreign_voter];
|
|
654
|
+
const creators = poll_key.fromMe ? selves : [foreign_creator];
|
|
655
|
+
let decrypted = null;
|
|
656
|
+
for (const voter of voters) {
|
|
657
|
+
for (const creator of creators) {
|
|
658
|
+
try {
|
|
659
|
+
decrypted = (0, baileys_1.decryptPollVote)({ encPayload: update.vote.encPayload, encIv: update.vote.encIv }, {
|
|
660
|
+
pollCreatorJid: (0, baileys_1.jidNormalizedUser)(creator),
|
|
661
|
+
pollMsgId: target_mid,
|
|
662
|
+
pollEncKey: message_secret,
|
|
663
|
+
voterJid: (0, baileys_1.jidNormalizedUser)(voter),
|
|
664
|
+
});
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
/* identidad equivocada: probar la siguiente */
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (decrypted) {
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (decrypted) {
|
|
676
|
+
(0, baileys_1.updateMessageWithPollUpdate)(poll_doc.raw, {
|
|
677
|
+
pollUpdateMessageKey: msg.key,
|
|
678
|
+
vote: decrypted,
|
|
679
|
+
senderTimestampMs: Number(msg.messageTimestamp) || Date.now(),
|
|
680
|
+
});
|
|
681
|
+
await this.engine.set(`/chat/${resolved_cid}/message/${target_mid}`, (0, store_1.serialize)(poll_doc));
|
|
682
|
+
const msg_instance = await this.Message.build_instance(poll_doc);
|
|
683
|
+
this._event.emit('message:updated', msg_instance, await msg_instance.chat(), this);
|
|
684
|
+
}
|
|
678
685
|
}
|
|
679
686
|
catch {
|
|
680
687
|
/* decrypt may fail */
|
|
@@ -715,23 +722,15 @@ class WhatsApp {
|
|
|
715
722
|
const push_name = msg.pushName ?? null;
|
|
716
723
|
const is_group = cid.endsWith('@g.us');
|
|
717
724
|
if (doc.author && !(await this.engine.get(`/contact/${doc.author}`))) {
|
|
718
|
-
|
|
719
|
-
const contact_raw = {
|
|
725
|
+
await this._persist_contact({
|
|
720
726
|
id: doc.author,
|
|
721
|
-
lid:
|
|
727
|
+
lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
|
|
722
728
|
name: null,
|
|
723
|
-
notify:
|
|
729
|
+
notify: push_name,
|
|
724
730
|
verified_name: msg.verifiedBizName ?? null,
|
|
725
731
|
img_url: null,
|
|
726
732
|
status: null,
|
|
727
|
-
};
|
|
728
|
-
await this.engine.set(`/contact/${doc.author}`, (0, store_1.serialize)(contact_raw));
|
|
729
|
-
if (lid_key) {
|
|
730
|
-
await this.engine.set(`/lid/${lid_key}`, (0, store_1.serialize)(doc.author));
|
|
731
|
-
}
|
|
732
|
-
const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${doc.author}`));
|
|
733
|
-
const author_chat = new this.Chat(cached_chat ?? { id: doc.author, name: push_name ?? doc.author.split('@')[0] });
|
|
734
|
-
this._event.emit('contact:created', new this.Contact(contact_raw, author_chat), author_chat, this);
|
|
733
|
+
});
|
|
735
734
|
}
|
|
736
735
|
if (!(await this.engine.get(`/chat/${cid}`))) {
|
|
737
736
|
const chat_raw = {
|