emusks 2.0.17 → 2.0.18
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/package.json +1 -1
- package/src/v1.1.js +27 -2
package/package.json
CHANGED
package/src/v1.1.js
CHANGED
|
@@ -20,11 +20,36 @@ export default async function v1_1(queryName, { params, body, headers } = {}) {
|
|
|
20
20
|
const url = new URL(finalUrl);
|
|
21
21
|
const pathname = url.pathname;
|
|
22
22
|
|
|
23
|
+
// v1.1 endpoints want form-urlencoded bodies. helpers historically passed
|
|
24
|
+
// `body: JSON.stringify(...)`, which twitter silently rejected — the most
|
|
25
|
+
// recent example was friendships/create returning "Cannot find specified
|
|
26
|
+
// user" because user_id wasn't extractable from a JSON body. if the caller
|
|
27
|
+
// hasn't set its own content-type, transparently convert a JSON-string body
|
|
28
|
+
// into form-urlencoded so existing helpers Just Work.
|
|
29
|
+
const callerSetContentType = headers && Object.keys(headers).some(
|
|
30
|
+
(k) => k.toLowerCase() === "content-type",
|
|
31
|
+
);
|
|
32
|
+
let finalBody = body;
|
|
33
|
+
let coercedContentType = null;
|
|
34
|
+
if (!callerSetContentType && typeof finalBody === "string" && finalBody.startsWith("{")) {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(finalBody);
|
|
37
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
38
|
+
finalBody = new URLSearchParams(
|
|
39
|
+
Object.fromEntries(
|
|
40
|
+
Object.entries(parsed).map(([k, v]) => [k, v == null ? "" : String(v)]),
|
|
41
|
+
),
|
|
42
|
+
).toString();
|
|
43
|
+
coercedContentType = "application/x-www-form-urlencoded";
|
|
44
|
+
}
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
|
|
23
48
|
const requestHeaders = {
|
|
24
49
|
accept: "*/*",
|
|
25
50
|
"accept-language": "en-US,en;q=0.9",
|
|
26
51
|
authorization: `Bearer ${this.auth.client.bearer}`,
|
|
27
|
-
"content-type": "application/json",
|
|
52
|
+
"content-type": coercedContentType ?? "application/json",
|
|
28
53
|
"x-csrf-token": this.auth.csrfToken,
|
|
29
54
|
"x-twitter-active-user": "yes",
|
|
30
55
|
"x-twitter-auth-type": "OAuth2Session",
|
|
@@ -55,7 +80,7 @@ export default async function v1_1(queryName, { params, body, headers } = {}) {
|
|
|
55
80
|
userAgent: this.auth.client.fingerprints.userAgent,
|
|
56
81
|
ja3: this.auth.client.fingerprints.ja3,
|
|
57
82
|
ja4r: this.auth.client.fingerprints.ja4r,
|
|
58
|
-
body:
|
|
83
|
+
body: finalBody || undefined,
|
|
59
84
|
proxy: this.proxy || undefined,
|
|
60
85
|
referrer: "https://x.com/",
|
|
61
86
|
},
|