junexbaileys 1.1.3 → 1.1.5
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 +1 -34
- package/package.json +20 -3
package/lib/Socket/mex.js
CHANGED
|
@@ -18,44 +18,11 @@ 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
|
-
};
|
|
54
21
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
55
22
|
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
56
23
|
const child = getBinaryNodeChild(result, 'result');
|
|
57
24
|
if (child?.content) {
|
|
58
|
-
const data =
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
59
26
|
if (data.errors && data.errors.length > 0) {
|
|
60
27
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
61
28
|
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.5",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -22,7 +22,24 @@
|
|
|
22
22
|
"engine-requirements.js"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
25
|
+
"build:all": "npm run build && npm run build:docs",
|
|
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"
|
|
26
43
|
},
|
|
27
44
|
"dependencies": {
|
|
28
45
|
"@cacheable/node-cache": "^1.4.0",
|
|
@@ -123,4 +140,4 @@
|
|
|
123
140
|
"bugs": {
|
|
124
141
|
"url": "https://github.com/supreme-Lord2/JuneX-baileys/issues"
|
|
125
142
|
}
|
|
126
|
-
}
|
|
143
|
+
}
|