junexbaileys 1.1.2 → 1.1.3
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/lib/Socket/mex.js +34 -1
- package/package.json +3 -20
package/lib/Socket/mex.js
CHANGED
|
@@ -18,11 +18,44 @@ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
|
18
18
|
]
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* WhatsApp sometimes returns the w:mex <result> body with a byte-order mark, a NUL
|
|
23
|
+
* or another invisible control character, which makes a bare JSON.parse throw
|
|
24
|
+
* Unexpected token '', ", ":12036340"... is not valid JSON
|
|
25
|
+
* Retry against a cleaned copy, then against the outermost JSON region, and only
|
|
26
|
+
* then fail - with the raw payload included so the caller can report the reason.
|
|
27
|
+
*/
|
|
28
|
+
const STRIP_INVISIBLE_RE = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u200B-\u200D\uFEFF]/g;
|
|
29
|
+
const tryJSON = (text) => {
|
|
30
|
+
try {
|
|
31
|
+
return { ok: true, data: JSON.parse(text) };
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
return { ok: false };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const parseWMexContent = (raw) => {
|
|
38
|
+
const strict = tryJSON(raw);
|
|
39
|
+
if (strict.ok)
|
|
40
|
+
return strict.data;
|
|
41
|
+
const cleaned = raw.replace(STRIP_INVISIBLE_RE, '');
|
|
42
|
+
const stripped = tryJSON(cleaned);
|
|
43
|
+
if (stripped.ok)
|
|
44
|
+
return stripped.data;
|
|
45
|
+
const first = cleaned.search(/[{[]/);
|
|
46
|
+
const last = Math.max(cleaned.lastIndexOf('}'), cleaned.lastIndexOf(']'));
|
|
47
|
+
if (first !== -1 && last > first) {
|
|
48
|
+
const region = tryJSON(cleaned.slice(first, last + 1));
|
|
49
|
+
if (region.ok)
|
|
50
|
+
return region.data;
|
|
51
|
+
}
|
|
52
|
+
throw new Boom(`w:mex non-JSON payload (${Buffer.byteLength(raw, 'utf8')} bytes, hex ${Buffer.from(raw, 'utf8').subarray(0, 48).toString('hex')}): ${raw.slice(0, 200)}`, { statusCode: 400 });
|
|
53
|
+
};
|
|
21
54
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
55
|
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
56
|
const child = getBinaryNodeChild(result, 'result');
|
|
24
57
|
if (child?.content) {
|
|
25
|
-
const data =
|
|
58
|
+
const data = parseWMexContent(child.content.toString());
|
|
26
59
|
if (data.errors && data.errors.length > 0) {
|
|
27
60
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
61
|
const firstError = data.errors[0];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "junexbaileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -22,24 +22,7 @@
|
|
|
22
22
|
"engine-requirements.js"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"build:docs": "typedoc",
|
|
27
|
-
"build": "tsc -P tsconfig.build.json && tsc-esm-fix --tsconfig=tsconfig.build.json --ext=.js",
|
|
28
|
-
"changelog:last": "conventional-changelog -p angular -r 2",
|
|
29
|
-
"changelog:preview": "conventional-changelog -p angular -u",
|
|
30
|
-
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
31
|
-
"example": "tsx ./Example/example.ts",
|
|
32
|
-
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
33
|
-
"format": "prettier --write \"src/**/*.{ts,js,json,md}\"",
|
|
34
|
-
"lint": "tsc && eslint src --ext .js,.ts",
|
|
35
|
-
"lint:fix": "npm run format && npm run lint -- --fix",
|
|
36
|
-
"prepack": "npm run build",
|
|
37
|
-
"prepare": "npm run build",
|
|
38
|
-
"preinstall": "node ./engine-requirements.js",
|
|
39
|
-
"release": "release-it",
|
|
40
|
-
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --testMatch '**/*.test.ts'",
|
|
41
|
-
"test:e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 node --experimental-vm-modules ./node_modules/.bin/jest --runInBand --forceExit --testMatch '**/*.test-e2e.ts'",
|
|
42
|
-
"update:version": "tsx ./scripts/update-version.ts"
|
|
25
|
+
"preinstall": "node ./engine-requirements.js"
|
|
43
26
|
},
|
|
44
27
|
"dependencies": {
|
|
45
28
|
"@cacheable/node-cache": "^1.4.0",
|
|
@@ -140,4 +123,4 @@
|
|
|
140
123
|
"bugs": {
|
|
141
124
|
"url": "https://github.com/supreme-Lord2/JuneX-baileys/issues"
|
|
142
125
|
}
|
|
143
|
-
}
|
|
126
|
+
}
|