@cexi/hoonfca 1.0.4 → 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 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.4",
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,6 +9433,7 @@ 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;
@@ -9446,6 +9447,28 @@ function createRealtimeListener(deps) {
9446
9447
  logger("mqtt reconnect paused - authentication recovery is required", "warn");
9447
9448
  return;
9448
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
+ }
9449
9472
  if (ctx.globalOptions.autoReconnect) {
9450
9473
  const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
9451
9474
  logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
@@ -13566,6 +13589,12 @@ function createGetSeqID(deps) {
13566
13589
  const diagnostics = summarizeGraphqlFailure(resData);
13567
13590
  const diagnosticText = JSON.stringify(diagnostics);
13568
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
+ );
13597
+ }
13569
13598
  if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
13570
13599
  throw {
13571
13600
  error: "login_blocked",
@@ -13593,6 +13622,14 @@ function createGetSeqID(deps) {
13593
13622
  const errorMessage = String(err && err.message || "");
13594
13623
  const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
13595
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
+ }
13596
13633
  if (/login_blocked|blocked the login|1357001/.test(combined)) {
13597
13634
  logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13598
13635
  emitAuth(ctx, api, globalCallback, "login_blocked", msg);
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.4",
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,6 +9429,7 @@ 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;
@@ -9442,6 +9443,28 @@ function createRealtimeListener(deps) {
9442
9443
  logger("mqtt reconnect paused - authentication recovery is required", "warn");
9443
9444
  return;
9444
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
+ }
9445
9468
  if (ctx.globalOptions.autoReconnect) {
9446
9469
  const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
9447
9470
  logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
@@ -13560,6 +13583,12 @@ function createGetSeqID(deps) {
13560
13583
  const diagnostics = summarizeGraphqlFailure(resData);
13561
13584
  const diagnosticText = JSON.stringify(diagnostics);
13562
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
+ );
13591
+ }
13563
13592
  if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
13564
13593
  throw {
13565
13594
  error: "login_blocked",
@@ -13587,6 +13616,14 @@ function createGetSeqID(deps) {
13587
13616
  const errorMessage = String(err && err.message || "");
13588
13617
  const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
13589
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
+ }
13590
13627
  if (/login_blocked|blocked the login|1357001/.test(combined)) {
13591
13628
  logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13592
13629
  emitAuth(ctx, api, globalCallback, "login_blocked", msg);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@cexi/hoonfca",
3
- "version": "1.0.4",
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.4",
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.3",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cexi/hoonfca",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
5
  "main": "dist/cjs.cjs",
6
6
  "types": "dist/index.d.ts",