@dongdev/fca-unofficial 3.0.30 → 3.0.31
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/CHANGELOG.md +3 -0
- package/package.json +2 -1
- package/src/api/http/httpGet.js +2 -2
- package/src/api/messaging/addUserToGroup.js +1 -1
- package/src/api/messaging/changeGroupImage.js +1 -1
- package/src/api/messaging/changeNickname.js +1 -1
- package/src/api/messaging/changeThreadColor.js +1 -1
- package/src/api/messaging/editMessage.js +1 -1
- package/src/api/messaging/searchForThread.js +2 -1
- package/src/api/messaging/sendTypingIndicator.js +1 -1
- package/src/api/messaging/setMessageReaction.js +3 -4
- package/src/api/messaging/unsendMessage.js +1 -1
- package/src/api/threads/getThreadInfo.js +2 -1
- package/src/api/users/getUserInfo.js +7 -4
- package/src/database/helpers.js +53 -0
- package/src/database/models/index.js +2 -1
- package/src/database/threadData.js +49 -53
- package/src/database/userData.js +46 -37
- package/src/utils/format/attachment.js +357 -0
- package/src/utils/format/cookie.js +9 -0
- package/src/utils/format/date.js +50 -0
- package/src/utils/format/decode.js +44 -0
- package/src/utils/format/delta.js +194 -0
- package/src/utils/format/ids.js +64 -0
- package/src/utils/format/index.js +64 -0
- package/src/utils/format/message.js +88 -0
- package/src/utils/format/presence.js +132 -0
- package/src/utils/format/readTyp.js +44 -0
- package/src/utils/format/thread.js +42 -0
- package/src/utils/format/utils.js +141 -0
- package/src/utils/loginParser/autoLogin.js +125 -0
- package/src/utils/loginParser/helpers.js +43 -0
- package/src/utils/loginParser/index.js +10 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
- package/src/utils/loginParser/textUtils.js +28 -0
- package/src/utils/request/client.js +26 -0
- package/src/utils/request/config.js +23 -0
- package/src/utils/request/defaults.js +46 -0
- package/src/utils/request/helpers.js +46 -0
- package/src/utils/request/index.js +17 -0
- package/src/utils/request/methods.js +163 -0
- package/src/utils/request/proxy.js +21 -0
- package/src/utils/request/retry.js +77 -0
- package/src/utils/request/sanitize.js +49 -0
- package/src/utils/format.js +0 -1174
- package/src/utils/loginParser.js +0 -365
- package/src/utils/messageFormat.js +0 -1173
- package/src/utils/request.js +0 -332
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { delay } = require("./client");
|
|
4
|
+
|
|
5
|
+
async function requestWithRetry(fn, retries = 3, baseDelay = 1000, ctx) {
|
|
6
|
+
let lastError;
|
|
7
|
+
const emit = (event, payload) => {
|
|
8
|
+
try {
|
|
9
|
+
if (ctx && ctx._emitter && typeof ctx._emitter.emit === "function") {
|
|
10
|
+
ctx._emitter.emit(event, payload);
|
|
11
|
+
}
|
|
12
|
+
} catch {}
|
|
13
|
+
};
|
|
14
|
+
for (let i = 0; i < retries; i++) {
|
|
15
|
+
try {
|
|
16
|
+
return await fn();
|
|
17
|
+
} catch (e) {
|
|
18
|
+
lastError = e;
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
e?.code === "ERR_INVALID_CHAR" ||
|
|
22
|
+
(e?.message && e.message.includes("Invalid character in header"))
|
|
23
|
+
) {
|
|
24
|
+
const err = new Error(
|
|
25
|
+
"Invalid header content detected. Request aborted to prevent crash."
|
|
26
|
+
);
|
|
27
|
+
err.error = "Invalid header content";
|
|
28
|
+
err.originalError = e;
|
|
29
|
+
err.code = "ERR_INVALID_CHAR";
|
|
30
|
+
return Promise.reject(err);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const status = e?.response?.status || e?.statusCode || 0;
|
|
34
|
+
const url = e?.config?.url || "";
|
|
35
|
+
const method = String(e?.config?.method || "").toUpperCase();
|
|
36
|
+
if (status === 429) {
|
|
37
|
+
emit("rateLimit", { status, url, method });
|
|
38
|
+
}
|
|
39
|
+
if (status >= 400 && status < 500 && status !== 429) {
|
|
40
|
+
return e.response || Promise.reject(e);
|
|
41
|
+
}
|
|
42
|
+
if (i === retries - 1) {
|
|
43
|
+
return e.response || Promise.reject(e);
|
|
44
|
+
}
|
|
45
|
+
const netCode = e?.code || "";
|
|
46
|
+
const msg = e && e.message ? e.message : String(e || "");
|
|
47
|
+
if (
|
|
48
|
+
!status &&
|
|
49
|
+
(netCode === "UND_ERR_CONNECT_TIMEOUT" ||
|
|
50
|
+
netCode === "ETIMEDOUT" ||
|
|
51
|
+
netCode === "ECONNRESET" ||
|
|
52
|
+
netCode === "ECONNREFUSED" ||
|
|
53
|
+
netCode === "ENOTFOUND" ||
|
|
54
|
+
/timeout|connect timeout|network error|fetch failed/i.test(msg))
|
|
55
|
+
) {
|
|
56
|
+
emit("networkError", {
|
|
57
|
+
code: netCode,
|
|
58
|
+
message: msg,
|
|
59
|
+
url,
|
|
60
|
+
method,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const backoffDelay = Math.min(
|
|
65
|
+
baseDelay * Math.pow(2, i) + Math.floor(Math.random() * 200),
|
|
66
|
+
30000
|
|
67
|
+
);
|
|
68
|
+
await delay(backoffDelay);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const finalError = lastError || new Error("Request failed after retries");
|
|
72
|
+
return Promise.reject(finalError);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
requestWithRetry,
|
|
77
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function sanitizeHeaderValue(value) {
|
|
4
|
+
if (value === null || value === undefined) return "";
|
|
5
|
+
const str = String(value);
|
|
6
|
+
return str.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F\r\n]/g, "").trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function sanitizeHeaderName(name) {
|
|
10
|
+
if (!name || typeof name !== "string") return "";
|
|
11
|
+
return name.replace(/[^\x21-\x7E]/g, "").trim();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function sanitizeHeaders(headers) {
|
|
15
|
+
if (!headers || typeof headers !== "object") return {};
|
|
16
|
+
const sanitized = {};
|
|
17
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
18
|
+
const sanitizedKey = sanitizeHeaderName(key);
|
|
19
|
+
if (!sanitizedKey) continue;
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value)) continue;
|
|
22
|
+
if (value !== null && typeof value === "object") continue;
|
|
23
|
+
if (typeof value === "function") continue;
|
|
24
|
+
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
const trimmed = value.trim();
|
|
27
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(trimmed);
|
|
30
|
+
if (Array.isArray(parsed)) continue;
|
|
31
|
+
} catch {
|
|
32
|
+
// continue with normal sanitization
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sanitizedValue = sanitizeHeaderValue(value);
|
|
38
|
+
if (sanitizedValue !== "") {
|
|
39
|
+
sanitized[sanitizedKey] = sanitizedValue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return sanitized;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
sanitizeHeaderValue,
|
|
47
|
+
sanitizeHeaderName,
|
|
48
|
+
sanitizeHeaders,
|
|
49
|
+
};
|