junexbaileys 1.1.4 → 1.1.6
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 +3 -3
- package/lib/Socket/mex.js +1 -86
- package/package.json +21 -8
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ To run the example script, download or clone the repo and then type the followin
|
|
|
57
57
|
Install this fork while keeping the standard Baileys package name and imports:
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
npm install @whiskeysockets/baileys@npm:junexbaileys@1.0.
|
|
60
|
+
npm install @whiskeysockets/baileys@npm:junexbaileys@1.0.4
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
This adds the following dependency to your application's `package.json`:
|
|
@@ -65,7 +65,7 @@ This adds the following dependency to your application's `package.json`:
|
|
|
65
65
|
```json
|
|
66
66
|
{
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@whiskeysockets/baileys": "npm:junexbaileys@1.0.
|
|
68
|
+
"@whiskeysockets/baileys": "npm:junexbaileys@1.0.4"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
```
|
|
@@ -76,7 +76,7 @@ Because the package is installed under the standard alias, keep using the normal
|
|
|
76
76
|
import makeWASocket from '@whiskeysockets/baileys'
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
The alias points to `junexbaileys@1.0.
|
|
79
|
+
The alias points to `junexbaileys@1.0.4`, while your application continues to use `@whiskeysockets/baileys` in source code.
|
|
80
80
|
|
|
81
81
|
# Links
|
|
82
82
|
|
package/lib/Socket/mex.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import nodeFs from 'node:fs';
|
|
2
|
-
import nodePath from 'node:path';
|
|
3
1
|
import { Boom } from '@hapi/boom';
|
|
4
2
|
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
5
3
|
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
@@ -20,94 +18,11 @@ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
|
20
18
|
]
|
|
21
19
|
});
|
|
22
20
|
};
|
|
23
|
-
/**
|
|
24
|
-
* WhatsApp occasionally returns the w:mex <result> body with a stray byte-order
|
|
25
|
-
* mark, a NUL or another invisible control character. A bare JSON.parse then
|
|
26
|
-
* throws
|
|
27
|
-
*
|
|
28
|
-
* Unexpected token '', ", ":12036340"... is not valid JSON
|
|
29
|
-
*
|
|
30
|
-
* where the offending token looks empty on screen. Retry against a cleaned copy
|
|
31
|
-
* before giving up, and when we do give up, surface the raw payload (text + hex)
|
|
32
|
-
* so the caller can report the real reason instead of a parser error.
|
|
33
|
-
*/
|
|
34
|
-
const STRIP_INVISIBLE_RE = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u200B-\u200D\uFEFF]/g;
|
|
35
|
-
const tryJSON = (text) => {
|
|
36
|
-
try {
|
|
37
|
-
return { ok: true, data: JSON.parse(text) };
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return { ok: false };
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export const parseWMexContent = (raw) => {
|
|
44
|
-
const strict = tryJSON(raw);
|
|
45
|
-
if (strict.ok)
|
|
46
|
-
return strict.data;
|
|
47
|
-
// 1. invisible bytes (BOM, NUL, zero-width, C0 controls) removed
|
|
48
|
-
const cleaned = raw.replace(STRIP_INVISIBLE_RE, '');
|
|
49
|
-
const stripped = tryJSON(cleaned);
|
|
50
|
-
if (stripped.ok)
|
|
51
|
-
return stripped.data;
|
|
52
|
-
// 2. keep only the outermost JSON region, then retry
|
|
53
|
-
const first = cleaned.search(/[{[]/);
|
|
54
|
-
const last = Math.max(cleaned.lastIndexOf('}'), cleaned.lastIndexOf(']'));
|
|
55
|
-
if (first !== -1 && last > first) {
|
|
56
|
-
const region = tryJSON(cleaned.slice(first, last + 1));
|
|
57
|
-
if (region.ok)
|
|
58
|
-
return region.data;
|
|
59
|
-
}
|
|
60
|
-
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 });
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* WhatsApp answers some newsletter joins with a short BINARY acknowledgement
|
|
64
|
-
* instead of the JSON GraphQL body. Observed shape (45 bytes):
|
|
65
|
-
*
|
|
66
|
-
* 04 3a 31 32 ... "\u0004:120363405182019728@newsletter" + NUL padding
|
|
67
|
-
*
|
|
68
|
-
* The join itself succeeds - only the body shape differs, so a JSON-only reader
|
|
69
|
-
* reports a failure that never happened. Accept it for join/leave and keep the
|
|
70
|
-
* raw bytes on disk so the shape can be inspected after the fact.
|
|
71
|
-
*/
|
|
72
|
-
const BINARY_ACK_RE = /xwa2_newsletter_(join|leave)_v2/;
|
|
73
|
-
const reportedBinaryAcks = new Set();
|
|
74
|
-
const reportBinaryAck = (dataPath, raw) => {
|
|
75
|
-
try {
|
|
76
|
-
const file = nodePath.join(process.env.JUNE_ROOT || process.cwd(), 'w-mex-report.txt');
|
|
77
|
-
const bytes = Buffer.from(raw, 'utf8');
|
|
78
|
-
nodeFs.appendFileSync(file, [
|
|
79
|
-
`[${new Date().toISOString()}] binary-ack ${dataPath}`,
|
|
80
|
-
` bytes: ${bytes.length}`,
|
|
81
|
-
` hex : ${bytes.toString('hex')}`,
|
|
82
|
-
` utf8 : ${JSON.stringify(bytes.toString('utf8'))}`,
|
|
83
|
-
''
|
|
84
|
-
].join('\n'));
|
|
85
|
-
if (nodeFs.statSync(file).size > 256 * 1024)
|
|
86
|
-
nodeFs.writeFileSync(file, '');
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// diagnostics must never break the caller
|
|
90
|
-
}
|
|
91
|
-
if (!reportedBinaryAcks.has(dataPath)) {
|
|
92
|
-
reportedBinaryAcks.add(dataPath);
|
|
93
|
-
console.warn(`[ w:mex ] ${dataPath} answered with a binary ack - treating as accepted (raw bytes in w-mex-report.txt)`);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
21
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
97
22
|
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
98
23
|
const child = getBinaryNodeChild(result, 'result');
|
|
99
24
|
if (child?.content) {
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
data = parseWMexContent(child.content.toString());
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
if (BINARY_ACK_RE.test(dataPath || '')) {
|
|
106
|
-
reportBinaryAck(dataPath, child.content.toString());
|
|
107
|
-
return {};
|
|
108
|
-
}
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
111
26
|
if (data.errors && data.errors.length > 0) {
|
|
112
27
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
113
28
|
const firstError = data.errors[0];
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "junexbaileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.6",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
8
8
|
"automation"
|
|
9
9
|
],
|
|
10
|
-
"homepage": "https://github.com/
|
|
10
|
+
"homepage": "https://github.com/WhiskeySockets/Baileys/",
|
|
11
11
|
"repository": {
|
|
12
|
-
"url": "git
|
|
13
|
-
"type": "git"
|
|
12
|
+
"url": "git@github.com:WhiskeySockets/Baileys.git"
|
|
14
13
|
},
|
|
15
14
|
"license": "MIT",
|
|
16
15
|
"author": "Rajeh Taher",
|
|
@@ -22,7 +21,24 @@
|
|
|
22
21
|
"engine-requirements.js"
|
|
23
22
|
],
|
|
24
23
|
"scripts": {
|
|
25
|
-
"
|
|
24
|
+
"build:all": "npm run build && npm run build:docs",
|
|
25
|
+
"build:docs": "typedoc",
|
|
26
|
+
"build": "tsc -P tsconfig.build.json && tsc-esm-fix --tsconfig=tsconfig.build.json --ext=.js",
|
|
27
|
+
"changelog:last": "conventional-changelog -p angular -r 2",
|
|
28
|
+
"changelog:preview": "conventional-changelog -p angular -u",
|
|
29
|
+
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
30
|
+
"example": "tsx ./Example/example.ts",
|
|
31
|
+
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
32
|
+
"format": "prettier --write \"src/**/*.{ts,js,json,md}\"",
|
|
33
|
+
"lint": "tsc && eslint src --ext .js,.ts",
|
|
34
|
+
"lint:fix": "npm run format && npm run lint -- --fix",
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"prepare": "npm run build",
|
|
37
|
+
"preinstall": "node ./engine-requirements.js",
|
|
38
|
+
"release": "release-it",
|
|
39
|
+
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --testMatch '**/*.test.ts'",
|
|
40
|
+
"test:e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 node --experimental-vm-modules ./node_modules/.bin/jest --runInBand --forceExit --testMatch '**/*.test-e2e.ts'",
|
|
41
|
+
"update:version": "tsx ./scripts/update-version.ts"
|
|
26
42
|
},
|
|
27
43
|
"dependencies": {
|
|
28
44
|
"@cacheable/node-cache": "^1.4.0",
|
|
@@ -119,8 +135,5 @@
|
|
|
119
135
|
"packageManager": "yarn@4.9.2",
|
|
120
136
|
"engines": {
|
|
121
137
|
"node": ">=20.0.0"
|
|
122
|
-
},
|
|
123
|
-
"bugs": {
|
|
124
|
-
"url": "https://github.com/supreme-Lord2/JuneX-baileys/issues"
|
|
125
138
|
}
|
|
126
139
|
}
|