@cexi/hoonfca 1.0.1 → 1.0.4

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.1",
5408
+ version: "1.0.4",
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",
@@ -9417,9 +9417,9 @@ function createRealtimeListener(deps) {
9417
9417
  av: ctx.globalOptions.pageID,
9418
9418
  queries: JSON.stringify({
9419
9419
  o0: {
9420
- doc_id: "3336396659757871",
9420
+ doc_id: "1349387578499440",
9421
9421
  query_params: {
9422
- limit: 1,
9422
+ limit: 0,
9423
9423
  before: null,
9424
9424
  tags: ["INBOX"],
9425
9425
  includeDeliveryReceipts: false,
@@ -9437,10 +9437,15 @@ function createRealtimeListener(deps) {
9437
9437
  ctx._cycling = false;
9438
9438
  ctx._getSeqInFlight = false;
9439
9439
  const message = error && error.message ? error.message : String(error || "Unknown error");
9440
- logger(`mqtt getSeqID error: ${message}`, "error");
9440
+ const errorCode = String(error && error.code || "").toUpperCase();
9441
+ logger(`mqtt getSeqID error [${errorCode || "UNKNOWN"}]: ${message}`, "error");
9441
9442
  if (ctx._ending) {
9442
9443
  return;
9443
9444
  }
9445
+ if (errorCode === "AUTH_ERROR" || errorCode === "LOGIN_BLOCKED") {
9446
+ logger("mqtt reconnect paused - authentication recovery is required", "warn");
9447
+ return;
9448
+ }
9444
9449
  if (ctx.globalOptions.autoReconnect) {
9445
9450
  const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
9446
9451
  logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
@@ -13514,6 +13519,30 @@ var require_parse_delta = __commonJS({
13514
13519
  });
13515
13520
 
13516
13521
  // src/transport/realtime/get-seq-id.ts
13522
+ function safeDiagnosticText(value) {
13523
+ 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);
13524
+ }
13525
+ function summarizeGraphqlFailure(response) {
13526
+ const last = response[response.length - 1] || {};
13527
+ const operation = response[0]?.o0 || last?.o0 || {};
13528
+ const rawErrors = [
13529
+ ...Array.isArray(operation.errors) ? operation.errors : [],
13530
+ ...Array.isArray(last.errors) ? last.errors : [],
13531
+ ...Array.isArray(last.error_results) ? last.error_results : []
13532
+ ];
13533
+ const errors = rawErrors.slice(0, 5).map((item) => ({
13534
+ code: item?.code ?? item?.extensions?.code ?? item?.error_code ?? null,
13535
+ message: safeDiagnosticText((typeof item === "string" ? item : item?.message || item?.description || item?.error) || "GraphQL operation failed")
13536
+ }));
13537
+ return {
13538
+ resultCount: response.length,
13539
+ successfulResults: last.successful_results ?? null,
13540
+ errorResults: last.error_results ?? null,
13541
+ responseKeys: Object.keys(last).slice(0, 20),
13542
+ operationKeys: Object.keys(operation).slice(0, 20),
13543
+ errors
13544
+ };
13545
+ }
13517
13546
  function createGetSeqID(deps) {
13518
13547
  const { listenMqtt: listenMqtt2, logger, emitAuth } = deps;
13519
13548
  return function getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount = 0) {
@@ -13534,11 +13563,21 @@ function createGetSeqID(deps) {
13534
13563
  }
13535
13564
  const lastRes = resData[resData.length - 1];
13536
13565
  if (lastRes && lastRes.successful_results === 0) {
13537
- const responseText = JSON.stringify(resData).toLowerCase();
13538
- if (responseText.includes("1357001") || responseText.includes("login_blocked") || responseText.includes("blocked the login")) {
13539
- throw { error: "login_blocked", message: "Facebook blocked the login", code: "1357001", originalResponse: resData };
13566
+ const diagnostics = summarizeGraphqlFailure(resData);
13567
+ const diagnosticText = JSON.stringify(diagnostics);
13568
+ const normalized = diagnosticText.toLowerCase();
13569
+ if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
13570
+ throw {
13571
+ error: "login_blocked",
13572
+ message: "Facebook blocked the login",
13573
+ code: "1357001",
13574
+ graphqlDiagnostics: diagnostics
13575
+ };
13540
13576
  }
13541
- throw { error: "getSeqID: GraphQL returned zero successful results", code: "SYNC_EMPTY", originalResponse: resData };
13577
+ throw Object.assign(
13578
+ new Error(`getSeqID: GraphQL returned zero successful results; diagnostics=${diagnosticText}`),
13579
+ { code: "SYNC_EMPTY", graphqlDiagnostics: diagnostics }
13580
+ );
13542
13581
  }
13543
13582
  const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
13544
13583
  if (syncSeqId) {
@@ -13556,7 +13595,8 @@ function createGetSeqID(deps) {
13556
13595
  const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
13557
13596
  if (/login_blocked|blocked the login|1357001/.test(combined)) {
13558
13597
  logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13559
- return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13598
+ emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13599
+ throw Object.assign(new Error(msg), { code: "LOGIN_BLOCKED" });
13560
13600
  }
13561
13601
  const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
13562
13602
  const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
@@ -13586,11 +13626,15 @@ function createGetSeqID(deps) {
13586
13626
  "error"
13587
13627
  );
13588
13628
  if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
13589
- return emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13629
+ emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13630
+ throw Object.assign(new Error(msg), { code: "AUTH_ERROR" });
13590
13631
  }
13591
13632
  }
13592
13633
  logger(`getSeqID error: ${msg}`, "error");
13593
- return emitAuth(ctx, api, globalCallback, "auth_error", msg);
13634
+ emitAuth(ctx, api, globalCallback, "auth_error", msg);
13635
+ throw Object.assign(new Error(msg), {
13636
+ code: isSequenceError ? "SYNC_EMPTY" : "SYNC_ERROR"
13637
+ });
13594
13638
  });
13595
13639
  };
13596
13640
  }
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.1",
5405
+ version: "1.0.4",
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",
@@ -9413,9 +9413,9 @@ function createRealtimeListener(deps) {
9413
9413
  av: ctx.globalOptions.pageID,
9414
9414
  queries: JSON.stringify({
9415
9415
  o0: {
9416
- doc_id: "3336396659757871",
9416
+ doc_id: "1349387578499440",
9417
9417
  query_params: {
9418
- limit: 1,
9418
+ limit: 0,
9419
9419
  before: null,
9420
9420
  tags: ["INBOX"],
9421
9421
  includeDeliveryReceipts: false,
@@ -9433,10 +9433,15 @@ function createRealtimeListener(deps) {
9433
9433
  ctx._cycling = false;
9434
9434
  ctx._getSeqInFlight = false;
9435
9435
  const message = error && error.message ? error.message : String(error || "Unknown error");
9436
- logger(`mqtt getSeqID error: ${message}`, "error");
9436
+ const errorCode = String(error && error.code || "").toUpperCase();
9437
+ logger(`mqtt getSeqID error [${errorCode || "UNKNOWN"}]: ${message}`, "error");
9437
9438
  if (ctx._ending) {
9438
9439
  return;
9439
9440
  }
9441
+ if (errorCode === "AUTH_ERROR" || errorCode === "LOGIN_BLOCKED") {
9442
+ logger("mqtt reconnect paused - authentication recovery is required", "warn");
9443
+ return;
9444
+ }
9440
9445
  if (ctx.globalOptions.autoReconnect) {
9441
9446
  const delay3 = conf.reconnectDelayMs + Math.floor(Math.random() * 400);
9442
9447
  logger(`mqtt getSeqID will retry in ~${delay3}ms`, "warn");
@@ -13508,6 +13513,30 @@ var require_parse_delta = __commonJS({
13508
13513
  });
13509
13514
 
13510
13515
  // src/transport/realtime/get-seq-id.ts
13516
+ function safeDiagnosticText(value) {
13517
+ 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);
13518
+ }
13519
+ function summarizeGraphqlFailure(response) {
13520
+ const last = response[response.length - 1] || {};
13521
+ const operation = response[0]?.o0 || last?.o0 || {};
13522
+ const rawErrors = [
13523
+ ...Array.isArray(operation.errors) ? operation.errors : [],
13524
+ ...Array.isArray(last.errors) ? last.errors : [],
13525
+ ...Array.isArray(last.error_results) ? last.error_results : []
13526
+ ];
13527
+ const errors = rawErrors.slice(0, 5).map((item) => ({
13528
+ code: item?.code ?? item?.extensions?.code ?? item?.error_code ?? null,
13529
+ message: safeDiagnosticText((typeof item === "string" ? item : item?.message || item?.description || item?.error) || "GraphQL operation failed")
13530
+ }));
13531
+ return {
13532
+ resultCount: response.length,
13533
+ successfulResults: last.successful_results ?? null,
13534
+ errorResults: last.error_results ?? null,
13535
+ responseKeys: Object.keys(last).slice(0, 20),
13536
+ operationKeys: Object.keys(operation).slice(0, 20),
13537
+ errors
13538
+ };
13539
+ }
13511
13540
  function createGetSeqID(deps) {
13512
13541
  const { listenMqtt: listenMqtt2, logger, emitAuth } = deps;
13513
13542
  return function getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount = 0) {
@@ -13528,11 +13557,21 @@ function createGetSeqID(deps) {
13528
13557
  }
13529
13558
  const lastRes = resData[resData.length - 1];
13530
13559
  if (lastRes && lastRes.successful_results === 0) {
13531
- const responseText = JSON.stringify(resData).toLowerCase();
13532
- if (responseText.includes("1357001") || responseText.includes("login_blocked") || responseText.includes("blocked the login")) {
13533
- throw { error: "login_blocked", message: "Facebook blocked the login", code: "1357001", originalResponse: resData };
13560
+ const diagnostics = summarizeGraphqlFailure(resData);
13561
+ const diagnosticText = JSON.stringify(diagnostics);
13562
+ const normalized = diagnosticText.toLowerCase();
13563
+ if (normalized.includes("1357001") || normalized.includes("login_blocked") || normalized.includes("blocked the login")) {
13564
+ throw {
13565
+ error: "login_blocked",
13566
+ message: "Facebook blocked the login",
13567
+ code: "1357001",
13568
+ graphqlDiagnostics: diagnostics
13569
+ };
13534
13570
  }
13535
- throw { error: "getSeqID: GraphQL returned zero successful results", code: "SYNC_EMPTY", originalResponse: resData };
13571
+ throw Object.assign(
13572
+ new Error(`getSeqID: GraphQL returned zero successful results; diagnostics=${diagnosticText}`),
13573
+ { code: "SYNC_EMPTY", graphqlDiagnostics: diagnostics }
13574
+ );
13536
13575
  }
13537
13576
  const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
13538
13577
  if (syncSeqId) {
@@ -13550,7 +13589,8 @@ function createGetSeqID(deps) {
13550
13589
  const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
13551
13590
  if (/login_blocked|blocked the login|1357001/.test(combined)) {
13552
13591
  logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13553
- return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13592
+ emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13593
+ throw Object.assign(new Error(msg), { code: "LOGIN_BLOCKED" });
13554
13594
  }
13555
13595
  const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
13556
13596
  const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
@@ -13580,11 +13620,15 @@ function createGetSeqID(deps) {
13580
13620
  "error"
13581
13621
  );
13582
13622
  if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
13583
- return emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13623
+ emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13624
+ throw Object.assign(new Error(msg), { code: "AUTH_ERROR" });
13584
13625
  }
13585
13626
  }
13586
13627
  logger(`getSeqID error: ${msg}`, "error");
13587
- return emitAuth(ctx, api, globalCallback, "auth_error", msg);
13628
+ emitAuth(ctx, api, globalCallback, "auth_error", msg);
13629
+ throw Object.assign(new Error(msg), {
13630
+ code: isSequenceError ? "SYNC_EMPTY" : "SYNC_ERROR"
13631
+ });
13588
13632
  });
13589
13633
  };
13590
13634
  }
package/docs/DOCS.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @cexi/hoonfca — Documentation
2
2
 
3
- Comprehensive API reference for `@cexi/hoonfca@1.0.0`. The library is written in TypeScript; the published package ships `dist/` only. Source under `src/` is on [GitHub](https://github.com/bdrakib123/hoon-fca).
3
+ Comprehensive API reference for `@cexi/hoonfca@1.0.1`. The library is written in TypeScript; the published package ships `dist/` only. Source under `src/` is on [GitHub](https://github.com/bdrakib123/hoon-fca).
4
4
 
5
5
  ---
6
6
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@cexi/hoonfca",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@cexi/hoonfca",
9
- "version": "1.0.1",
9
+ "version": "1.0.4",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "axios": "^1.13.5",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cexi/hoonfca",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
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",