@cexi/hoonfca 1.0.3 → 1.0.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/dist/index.js +90 -9
- package/dist/index.mjs +90 -9
- package/npm-shrinkwrap.json +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5405,7 +5405,7 @@ var init_package = __esm({
|
|
|
5405
5405
|
"package.json"() {
|
|
5406
5406
|
package_default = {
|
|
5407
5407
|
name: "@cexi/hoonfca",
|
|
5408
|
-
version: "1.0.
|
|
5408
|
+
version: "1.0.5",
|
|
5409
5409
|
description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
5410
5410
|
main: "dist/cjs.cjs",
|
|
5411
5411
|
types: "dist/index.d.ts",
|
|
@@ -9433,14 +9433,42 @@ function createRealtimeListener(deps) {
|
|
|
9433
9433
|
logger("mqtt getSeqID done", "info");
|
|
9434
9434
|
ctx._cycling = false;
|
|
9435
9435
|
ctx._getSeqInFlight = false;
|
|
9436
|
+
ctx._rateLimitAttempts = 0;
|
|
9436
9437
|
}).catch((error) => {
|
|
9437
9438
|
ctx._cycling = false;
|
|
9438
9439
|
ctx._getSeqInFlight = false;
|
|
9439
9440
|
const message = error && error.message ? error.message : String(error || "Unknown error");
|
|
9440
|
-
|
|
9441
|
+
const errorCode = String(error && error.code || "").toUpperCase();
|
|
9442
|
+
logger(`mqtt getSeqID error [${errorCode || "UNKNOWN"}]: ${message}`, "error");
|
|
9441
9443
|
if (ctx._ending) {
|
|
9442
9444
|
return;
|
|
9443
9445
|
}
|
|
9446
|
+
if (errorCode === "AUTH_ERROR" || errorCode === "LOGIN_BLOCKED") {
|
|
9447
|
+
logger("mqtt reconnect paused - authentication recovery is required", "warn");
|
|
9448
|
+
return;
|
|
9449
|
+
}
|
|
9450
|
+
if (errorCode === "RATE_LIMITED") {
|
|
9451
|
+
ctx._rateLimitAttempts = Math.min((ctx._rateLimitAttempts || 0) + 1, 8);
|
|
9452
|
+
const baseCooldownMs = 15 * 60 * 1e3;
|
|
9453
|
+
const maxCooldownMs = 6 * 60 * 60 * 1e3;
|
|
9454
|
+
const cooldownMs = Math.min(
|
|
9455
|
+
baseCooldownMs * 2 ** (ctx._rateLimitAttempts - 1),
|
|
9456
|
+
maxCooldownMs
|
|
9457
|
+
);
|
|
9458
|
+
logger(
|
|
9459
|
+
`mqtt rate limit cooldown ${Math.round(cooldownMs / 6e4)} minutes (attempt ${ctx._rateLimitAttempts}/8)`,
|
|
9460
|
+
"warn"
|
|
9461
|
+
);
|
|
9462
|
+
if (ctx.globalOptions.autoReconnect) {
|
|
9463
|
+
ctx._getSeqRetryTimer = setTimeout(() => {
|
|
9464
|
+
ctx._getSeqRetryTimer = null;
|
|
9465
|
+
if (!ctx._ending) {
|
|
9466
|
+
getSeqIDWrapper();
|
|
9467
|
+
}
|
|
9468
|
+
}, cooldownMs);
|
|
9469
|
+
}
|
|
9470
|
+
return;
|
|
9471
|
+
}
|
|
9444
9472
|
if (ctx.globalOptions.autoReconnect) {
|
|
9445
9473
|
const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
|
|
9446
9474
|
logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
|
|
@@ -13514,6 +13542,30 @@ var require_parse_delta = __commonJS({
|
|
|
13514
13542
|
});
|
|
13515
13543
|
|
|
13516
13544
|
// src/transport/realtime/get-seq-id.ts
|
|
13545
|
+
function safeDiagnosticText(value) {
|
|
13546
|
+
return String(value ?? "").replace(/(cookie|authorization|fb_dtsg|lsd|jazoest|access_token|sessionid)\s*[:=]\s*[^\s,;]+/gi, "$1=[redacted]").replace(/EA[A-Za-z0-9]{20,}/g, "[redacted-token]").slice(0, 240);
|
|
13547
|
+
}
|
|
13548
|
+
function summarizeGraphqlFailure(response) {
|
|
13549
|
+
const last = response[response.length - 1] || {};
|
|
13550
|
+
const operation = response[0]?.o0 || last?.o0 || {};
|
|
13551
|
+
const rawErrors = [
|
|
13552
|
+
...Array.isArray(operation.errors) ? operation.errors : [],
|
|
13553
|
+
...Array.isArray(last.errors) ? last.errors : [],
|
|
13554
|
+
...Array.isArray(last.error_results) ? last.error_results : []
|
|
13555
|
+
];
|
|
13556
|
+
const errors = rawErrors.slice(0, 5).map((item) => ({
|
|
13557
|
+
code: item?.code ?? item?.extensions?.code ?? item?.error_code ?? null,
|
|
13558
|
+
message: safeDiagnosticText((typeof item === "string" ? item : item?.message || item?.description || item?.error) || "GraphQL operation failed")
|
|
13559
|
+
}));
|
|
13560
|
+
return {
|
|
13561
|
+
resultCount: response.length,
|
|
13562
|
+
successfulResults: last.successful_results ?? null,
|
|
13563
|
+
errorResults: last.error_results ?? null,
|
|
13564
|
+
responseKeys: Object.keys(last).slice(0, 20),
|
|
13565
|
+
operationKeys: Object.keys(operation).slice(0, 20),
|
|
13566
|
+
errors
|
|
13567
|
+
};
|
|
13568
|
+
}
|
|
13517
13569
|
function createGetSeqID(deps) {
|
|
13518
13570
|
const { listenMqtt: listenMqtt2, logger, emitAuth } = deps;
|
|
13519
13571
|
return function getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount = 0) {
|
|
@@ -13534,11 +13586,27 @@ function createGetSeqID(deps) {
|
|
|
13534
13586
|
}
|
|
13535
13587
|
const lastRes = resData[resData.length - 1];
|
|
13536
13588
|
if (lastRes && lastRes.successful_results === 0) {
|
|
13537
|
-
const
|
|
13538
|
-
|
|
13539
|
-
|
|
13589
|
+
const diagnostics = summarizeGraphqlFailure(resData);
|
|
13590
|
+
const diagnosticText = JSON.stringify(diagnostics);
|
|
13591
|
+
const normalized = diagnosticText.toLowerCase();
|
|
13592
|
+
if (normalized.includes("1675004") || normalized.includes("rate limit exceeded")) {
|
|
13593
|
+
throw Object.assign(
|
|
13594
|
+
new Error(`getSeqID: Facebook rate limit exceeded; diagnostics=${diagnosticText}`),
|
|
13595
|
+
{ code: "RATE_LIMITED", graphqlDiagnostics: diagnostics }
|
|
13596
|
+
);
|
|
13540
13597
|
}
|
|
13541
|
-
|
|
13598
|
+
if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
|
|
13599
|
+
throw {
|
|
13600
|
+
error: "login_blocked",
|
|
13601
|
+
message: "Facebook blocked the login",
|
|
13602
|
+
code: "1357001",
|
|
13603
|
+
graphqlDiagnostics: diagnostics
|
|
13604
|
+
};
|
|
13605
|
+
}
|
|
13606
|
+
throw Object.assign(
|
|
13607
|
+
new Error(`getSeqID: GraphQL returned zero successful results; diagnostics=${diagnosticText}`),
|
|
13608
|
+
{ code: "SYNC_EMPTY", graphqlDiagnostics: diagnostics }
|
|
13609
|
+
);
|
|
13542
13610
|
}
|
|
13543
13611
|
const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
|
|
13544
13612
|
if (syncSeqId) {
|
|
@@ -13554,9 +13622,18 @@ function createGetSeqID(deps) {
|
|
|
13554
13622
|
const errorMessage = String(err && err.message || "");
|
|
13555
13623
|
const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
|
|
13556
13624
|
const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
|
|
13625
|
+
if (/1675004|rate limit exceeded|rate_limited/.test(combined)) {
|
|
13626
|
+
const diagnostic = err && err.graphqlDiagnostics ? ` diagnostics=${JSON.stringify(err.graphqlDiagnostics)}` : "";
|
|
13627
|
+
logger("getSeqID: Facebook rate limit detected; handing cooldown to MQTT listener", "warn");
|
|
13628
|
+
throw Object.assign(
|
|
13629
|
+
new Error(`Facebook rate limit exceeded (1675004).${diagnostic}`),
|
|
13630
|
+
{ code: "RATE_LIMITED", graphqlDiagnostics: err && err.graphqlDiagnostics }
|
|
13631
|
+
);
|
|
13632
|
+
}
|
|
13557
13633
|
if (/login_blocked|blocked the login|1357001/.test(combined)) {
|
|
13558
13634
|
logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
|
|
13559
|
-
|
|
13635
|
+
emitAuth(ctx, api, globalCallback, "login_blocked", msg);
|
|
13636
|
+
throw Object.assign(new Error(msg), { code: "LOGIN_BLOCKED" });
|
|
13560
13637
|
}
|
|
13561
13638
|
const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
|
|
13562
13639
|
const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
|
|
@@ -13586,11 +13663,15 @@ function createGetSeqID(deps) {
|
|
|
13586
13663
|
"error"
|
|
13587
13664
|
);
|
|
13588
13665
|
if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
|
|
13589
|
-
|
|
13666
|
+
emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
|
|
13667
|
+
throw Object.assign(new Error(msg), { code: "AUTH_ERROR" });
|
|
13590
13668
|
}
|
|
13591
13669
|
}
|
|
13592
13670
|
logger(`getSeqID error: ${msg}`, "error");
|
|
13593
|
-
|
|
13671
|
+
emitAuth(ctx, api, globalCallback, "auth_error", msg);
|
|
13672
|
+
throw Object.assign(new Error(msg), {
|
|
13673
|
+
code: isSequenceError ? "SYNC_EMPTY" : "SYNC_ERROR"
|
|
13674
|
+
});
|
|
13594
13675
|
});
|
|
13595
13676
|
};
|
|
13596
13677
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5402,7 +5402,7 @@ var init_package = __esm({
|
|
|
5402
5402
|
"package.json"() {
|
|
5403
5403
|
package_default = {
|
|
5404
5404
|
name: "@cexi/hoonfca",
|
|
5405
|
-
version: "1.0.
|
|
5405
|
+
version: "1.0.5",
|
|
5406
5406
|
description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
5407
5407
|
main: "dist/cjs.cjs",
|
|
5408
5408
|
types: "dist/index.d.ts",
|
|
@@ -9429,14 +9429,42 @@ function createRealtimeListener(deps) {
|
|
|
9429
9429
|
logger("mqtt getSeqID done", "info");
|
|
9430
9430
|
ctx._cycling = false;
|
|
9431
9431
|
ctx._getSeqInFlight = false;
|
|
9432
|
+
ctx._rateLimitAttempts = 0;
|
|
9432
9433
|
}).catch((error) => {
|
|
9433
9434
|
ctx._cycling = false;
|
|
9434
9435
|
ctx._getSeqInFlight = false;
|
|
9435
9436
|
const message = error && error.message ? error.message : String(error || "Unknown error");
|
|
9436
|
-
|
|
9437
|
+
const errorCode = String(error && error.code || "").toUpperCase();
|
|
9438
|
+
logger(`mqtt getSeqID error [${errorCode || "UNKNOWN"}]: ${message}`, "error");
|
|
9437
9439
|
if (ctx._ending) {
|
|
9438
9440
|
return;
|
|
9439
9441
|
}
|
|
9442
|
+
if (errorCode === "AUTH_ERROR" || errorCode === "LOGIN_BLOCKED") {
|
|
9443
|
+
logger("mqtt reconnect paused - authentication recovery is required", "warn");
|
|
9444
|
+
return;
|
|
9445
|
+
}
|
|
9446
|
+
if (errorCode === "RATE_LIMITED") {
|
|
9447
|
+
ctx._rateLimitAttempts = Math.min((ctx._rateLimitAttempts || 0) + 1, 8);
|
|
9448
|
+
const baseCooldownMs = 15 * 60 * 1e3;
|
|
9449
|
+
const maxCooldownMs = 6 * 60 * 60 * 1e3;
|
|
9450
|
+
const cooldownMs = Math.min(
|
|
9451
|
+
baseCooldownMs * 2 ** (ctx._rateLimitAttempts - 1),
|
|
9452
|
+
maxCooldownMs
|
|
9453
|
+
);
|
|
9454
|
+
logger(
|
|
9455
|
+
`mqtt rate limit cooldown ${Math.round(cooldownMs / 6e4)} minutes (attempt ${ctx._rateLimitAttempts}/8)`,
|
|
9456
|
+
"warn"
|
|
9457
|
+
);
|
|
9458
|
+
if (ctx.globalOptions.autoReconnect) {
|
|
9459
|
+
ctx._getSeqRetryTimer = setTimeout(() => {
|
|
9460
|
+
ctx._getSeqRetryTimer = null;
|
|
9461
|
+
if (!ctx._ending) {
|
|
9462
|
+
getSeqIDWrapper();
|
|
9463
|
+
}
|
|
9464
|
+
}, cooldownMs);
|
|
9465
|
+
}
|
|
9466
|
+
return;
|
|
9467
|
+
}
|
|
9440
9468
|
if (ctx.globalOptions.autoReconnect) {
|
|
9441
9469
|
const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
|
|
9442
9470
|
logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
|
|
@@ -13508,6 +13536,30 @@ var require_parse_delta = __commonJS({
|
|
|
13508
13536
|
});
|
|
13509
13537
|
|
|
13510
13538
|
// src/transport/realtime/get-seq-id.ts
|
|
13539
|
+
function safeDiagnosticText(value) {
|
|
13540
|
+
return String(value ?? "").replace(/(cookie|authorization|fb_dtsg|lsd|jazoest|access_token|sessionid)\s*[:=]\s*[^\s,;]+/gi, "$1=[redacted]").replace(/EA[A-Za-z0-9]{20,}/g, "[redacted-token]").slice(0, 240);
|
|
13541
|
+
}
|
|
13542
|
+
function summarizeGraphqlFailure(response) {
|
|
13543
|
+
const last = response[response.length - 1] || {};
|
|
13544
|
+
const operation = response[0]?.o0 || last?.o0 || {};
|
|
13545
|
+
const rawErrors = [
|
|
13546
|
+
...Array.isArray(operation.errors) ? operation.errors : [],
|
|
13547
|
+
...Array.isArray(last.errors) ? last.errors : [],
|
|
13548
|
+
...Array.isArray(last.error_results) ? last.error_results : []
|
|
13549
|
+
];
|
|
13550
|
+
const errors = rawErrors.slice(0, 5).map((item) => ({
|
|
13551
|
+
code: item?.code ?? item?.extensions?.code ?? item?.error_code ?? null,
|
|
13552
|
+
message: safeDiagnosticText((typeof item === "string" ? item : item?.message || item?.description || item?.error) || "GraphQL operation failed")
|
|
13553
|
+
}));
|
|
13554
|
+
return {
|
|
13555
|
+
resultCount: response.length,
|
|
13556
|
+
successfulResults: last.successful_results ?? null,
|
|
13557
|
+
errorResults: last.error_results ?? null,
|
|
13558
|
+
responseKeys: Object.keys(last).slice(0, 20),
|
|
13559
|
+
operationKeys: Object.keys(operation).slice(0, 20),
|
|
13560
|
+
errors
|
|
13561
|
+
};
|
|
13562
|
+
}
|
|
13511
13563
|
function createGetSeqID(deps) {
|
|
13512
13564
|
const { listenMqtt: listenMqtt2, logger, emitAuth } = deps;
|
|
13513
13565
|
return function getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount = 0) {
|
|
@@ -13528,11 +13580,27 @@ function createGetSeqID(deps) {
|
|
|
13528
13580
|
}
|
|
13529
13581
|
const lastRes = resData[resData.length - 1];
|
|
13530
13582
|
if (lastRes && lastRes.successful_results === 0) {
|
|
13531
|
-
const
|
|
13532
|
-
|
|
13533
|
-
|
|
13583
|
+
const diagnostics = summarizeGraphqlFailure(resData);
|
|
13584
|
+
const diagnosticText = JSON.stringify(diagnostics);
|
|
13585
|
+
const normalized = diagnosticText.toLowerCase();
|
|
13586
|
+
if (normalized.includes("1675004") || normalized.includes("rate limit exceeded")) {
|
|
13587
|
+
throw Object.assign(
|
|
13588
|
+
new Error(`getSeqID: Facebook rate limit exceeded; diagnostics=${diagnosticText}`),
|
|
13589
|
+
{ code: "RATE_LIMITED", graphqlDiagnostics: diagnostics }
|
|
13590
|
+
);
|
|
13534
13591
|
}
|
|
13535
|
-
|
|
13592
|
+
if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
|
|
13593
|
+
throw {
|
|
13594
|
+
error: "login_blocked",
|
|
13595
|
+
message: "Facebook blocked the login",
|
|
13596
|
+
code: "1357001",
|
|
13597
|
+
graphqlDiagnostics: diagnostics
|
|
13598
|
+
};
|
|
13599
|
+
}
|
|
13600
|
+
throw Object.assign(
|
|
13601
|
+
new Error(`getSeqID: GraphQL returned zero successful results; diagnostics=${diagnosticText}`),
|
|
13602
|
+
{ code: "SYNC_EMPTY", graphqlDiagnostics: diagnostics }
|
|
13603
|
+
);
|
|
13536
13604
|
}
|
|
13537
13605
|
const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
|
|
13538
13606
|
if (syncSeqId) {
|
|
@@ -13548,9 +13616,18 @@ function createGetSeqID(deps) {
|
|
|
13548
13616
|
const errorMessage = String(err && err.message || "");
|
|
13549
13617
|
const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
|
|
13550
13618
|
const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
|
|
13619
|
+
if (/1675004|rate limit exceeded|rate_limited/.test(combined)) {
|
|
13620
|
+
const diagnostic = err && err.graphqlDiagnostics ? ` diagnostics=${JSON.stringify(err.graphqlDiagnostics)}` : "";
|
|
13621
|
+
logger("getSeqID: Facebook rate limit detected; handing cooldown to MQTT listener", "warn");
|
|
13622
|
+
throw Object.assign(
|
|
13623
|
+
new Error(`Facebook rate limit exceeded (1675004).${diagnostic}`),
|
|
13624
|
+
{ code: "RATE_LIMITED", graphqlDiagnostics: err && err.graphqlDiagnostics }
|
|
13625
|
+
);
|
|
13626
|
+
}
|
|
13551
13627
|
if (/login_blocked|blocked the login|1357001/.test(combined)) {
|
|
13552
13628
|
logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
|
|
13553
|
-
|
|
13629
|
+
emitAuth(ctx, api, globalCallback, "login_blocked", msg);
|
|
13630
|
+
throw Object.assign(new Error(msg), { code: "LOGIN_BLOCKED" });
|
|
13554
13631
|
}
|
|
13555
13632
|
const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
|
|
13556
13633
|
const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
|
|
@@ -13580,11 +13657,15 @@ function createGetSeqID(deps) {
|
|
|
13580
13657
|
"error"
|
|
13581
13658
|
);
|
|
13582
13659
|
if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
|
|
13583
|
-
|
|
13660
|
+
emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
|
|
13661
|
+
throw Object.assign(new Error(msg), { code: "AUTH_ERROR" });
|
|
13584
13662
|
}
|
|
13585
13663
|
}
|
|
13586
13664
|
logger(`getSeqID error: ${msg}`, "error");
|
|
13587
|
-
|
|
13665
|
+
emitAuth(ctx, api, globalCallback, "auth_error", msg);
|
|
13666
|
+
throw Object.assign(new Error(msg), {
|
|
13667
|
+
code: isSequenceError ? "SYNC_EMPTY" : "SYNC_ERROR"
|
|
13668
|
+
});
|
|
13588
13669
|
});
|
|
13589
13670
|
};
|
|
13590
13671
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cexi/hoonfca",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@cexi/hoonfca",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.5",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"axios": "^1.13.5",
|
|
@@ -4269,7 +4269,7 @@
|
|
|
4269
4269
|
}
|
|
4270
4270
|
},
|
|
4271
4271
|
"node_modules/stream-shift": {
|
|
4272
|
-
"version": "1.0.
|
|
4272
|
+
"version": "1.0.5",
|
|
4273
4273
|
"resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz",
|
|
4274
4274
|
"integrity": "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ==",
|
|
4275
4275
|
"license": "MIT"
|
package/package.json
CHANGED