@cexi/hoonfca 1.0.0 → 1.0.3

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.0",
5408
+ version: "1.0.3",
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",
@@ -5434,7 +5434,8 @@ var init_package = __esm({
5434
5434
  lint: "eslint --ext .cjs scripts test",
5435
5435
  typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
5436
5436
  build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string --external form-data --external combined-stream && node scripts/cjs-bridge.cjs",
5437
- "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
5437
+ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
5438
+ "release:check": "npm run build && npm run lint && npm run typecheck && npm test && npm pack --dry-run"
5438
5439
  },
5439
5440
  repository: {
5440
5441
  type: "git",
@@ -9416,9 +9417,9 @@ function createRealtimeListener(deps) {
9416
9417
  av: ctx.globalOptions.pageID,
9417
9418
  queries: JSON.stringify({
9418
9419
  o0: {
9419
- doc_id: "3336396659757871",
9420
+ doc_id: "1349387578499440",
9420
9421
  query_params: {
9421
- limit: 1,
9422
+ limit: 0,
9422
9423
  before: null,
9423
9424
  tags: ["INBOX"],
9424
9425
  includeDeliveryReceipts: false,
@@ -13521,18 +13522,24 @@ function createGetSeqID(deps) {
13521
13522
  ctx.t_mqttCalled = false;
13522
13523
  return defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form).then(parseAndCheckLogin2(ctx, defaultFuncs)).then(async (resData) => {
13523
13524
  if (getType13(resData) !== "Array") {
13524
- logger(`getSeqID: Unexpected response type: ${getType13(resData)}, value: ${JSON.stringify(resData).substring(0, 200)}`, "warn");
13525
- if (resData && typeof resData === "object") {
13526
- const errorMsg = resData.error || resData.message || "";
13527
- if (/Not logged in|login|blocked|401|403|checkpoint/i.test(errorMsg)) {
13528
- throw { error: "Not logged in", originalResponse: resData };
13529
- }
13525
+ logger(`getSeqID: Unexpected GraphQL response type: ${getType13(resData)}`, "warn");
13526
+ const responseText = JSON.stringify(resData || {}).toLowerCase();
13527
+ if (/not logged in|login|blocked|401|403|checkpoint|1357001/.test(responseText)) {
13528
+ throw { error: "Not logged in", originalResponse: resData };
13530
13529
  }
13531
- throw { error: "Not logged in", originalResponse: resData };
13530
+ throw { error: "getSeqID: unexpected GraphQL response", code: "SYNC_RESPONSE", originalResponse: resData };
13531
+ }
13532
+ if (!Array.isArray(resData) || !resData.length) {
13533
+ throw { error: "getSeqID: empty GraphQL response", code: "SYNC_EMPTY" };
13532
13534
  }
13533
- if (!Array.isArray(resData) || !resData.length) return;
13534
13535
  const lastRes = resData[resData.length - 1];
13535
- if (lastRes && lastRes.successful_results === 0) return;
13536
+ 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 };
13540
+ }
13541
+ throw { error: "getSeqID: GraphQL returned zero successful results", code: "SYNC_EMPTY", originalResponse: resData };
13542
+ }
13536
13543
  const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
13537
13544
  if (syncSeqId) {
13538
13545
  ctx.lastSeqId = syncSeqId;
@@ -13543,8 +13550,22 @@ function createGetSeqID(deps) {
13543
13550
  }
13544
13551
  }).catch(async (err) => {
13545
13552
  const detail = err && err.detail && err.detail.message ? ` | detail=${err.detail.message}` : "";
13546
- const msg = (err && err.error || err && err.message || String(err || "")) + detail;
13547
- const isAuthError = /Not logged in|no sync_sequence_id found|blocked the login|401|403/i.test(msg);
13553
+ const errorCode = String(err && (err.error || err.code) || "").toLowerCase();
13554
+ const errorMessage = String(err && err.message || "");
13555
+ const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
13556
+ const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
13557
+ if (/login_blocked|blocked the login|1357001/.test(combined)) {
13558
+ logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13559
+ return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13560
+ }
13561
+ const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
13562
+ const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
13563
+ if (isSequenceError && retryCount < MAX_RETRIES) {
13564
+ const delay3 = RETRY_DELAY * (retryCount + 1);
13565
+ logger(`getSeqID: sync-state retry ${retryCount + 1}/${MAX_RETRIES} after ${delay3}ms`, "warn");
13566
+ await new Promise((resolve) => setTimeout(resolve, delay3));
13567
+ return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
13568
+ }
13548
13569
  if (isAuthError) {
13549
13570
  if (retryCount < MAX_RETRIES) {
13550
13571
  const delay3 = RETRY_DELAY * (retryCount + 1);
@@ -13564,10 +13585,7 @@ function createGetSeqID(deps) {
13564
13585
  `getSeqID: authentication retries exhausted; handing recovery to TESSA: ${msg}`,
13565
13586
  "error"
13566
13587
  );
13567
- if (/blocked/i.test(msg)) {
13568
- return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13569
- }
13570
- if (/Not logged in/i.test(msg)) {
13588
+ if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
13571
13589
  return emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13572
13590
  }
13573
13591
  }
@@ -13851,7 +13869,7 @@ var require_connect_mqtt = __commonJS({
13851
13869
  if (ctx._rTimeout) {
13852
13870
  delete ctx._rTimeout;
13853
13871
  }
13854
- if (ctx.globalOptions.emitReady) globalCallback({ type: "ready", error: null });
13872
+ if (ctx.globalOptions.emitReady) globalCallback(null, { type: "ready", error: null });
13855
13873
  delete ctx.tmsWait;
13856
13874
  };
13857
13875
  });
@@ -13871,13 +13889,23 @@ var require_connect_mqtt = __commonJS({
13871
13889
  } else if (jsonMessage.type === "jewel_requests_remove_old") {
13872
13890
  globalCallback(null, { type: "friend_request_cancel", actorFbId: jsonMessage.from.toString(), timestamp: Date.now().toString() });
13873
13891
  } else if (topic === "/t_ms") {
13874
- if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
13875
- if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
13892
+ const hasSyncState = jsonMessage && typeof jsonMessage === "object" && (jsonMessage.syncToken != null || jsonMessage.firstDeltaSeqId != null || jsonMessage.lastIssuedSeqId != null);
13893
+ if (!hasSyncState) {
13894
+ logger("mqtt received an incomplete /t_ms response; waiting for sync state", "warn");
13895
+ return;
13896
+ }
13897
+ if (jsonMessage.firstDeltaSeqId != null) {
13876
13898
  ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
13899
+ }
13900
+ if (jsonMessage.syncToken != null) {
13877
13901
  ctx.syncToken = jsonMessage.syncToken;
13878
13902
  }
13879
- if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
13880
- for (const dlt of jsonMessage.deltas || []) {
13903
+ if (jsonMessage.lastIssuedSeqId != null) {
13904
+ const lastIssuedSeqId = Number.parseInt(String(jsonMessage.lastIssuedSeqId), 10);
13905
+ if (Number.isFinite(lastIssuedSeqId)) ctx.lastSeqId = lastIssuedSeqId;
13906
+ }
13907
+ if (ctx.tmsWait && typeof ctx.tmsWait === "function") ctx.tmsWait();
13908
+ for (const dlt of Array.isArray(jsonMessage.deltas) ? jsonMessage.deltas : []) {
13881
13909
  parseDelta2(defaultFuncs, api, ctx, globalCallback, { delta: dlt });
13882
13910
  }
13883
13911
  } else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
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.0",
5405
+ version: "1.0.3",
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",
@@ -5431,7 +5431,8 @@ var init_package = __esm({
5431
5431
  lint: "eslint --ext .cjs scripts test",
5432
5432
  typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
5433
5433
  build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string --external form-data --external combined-stream && node scripts/cjs-bridge.cjs",
5434
- "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
5434
+ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
5435
+ "release:check": "npm run build && npm run lint && npm run typecheck && npm test && npm pack --dry-run"
5435
5436
  },
5436
5437
  repository: {
5437
5438
  type: "git",
@@ -9412,9 +9413,9 @@ function createRealtimeListener(deps) {
9412
9413
  av: ctx.globalOptions.pageID,
9413
9414
  queries: JSON.stringify({
9414
9415
  o0: {
9415
- doc_id: "3336396659757871",
9416
+ doc_id: "1349387578499440",
9416
9417
  query_params: {
9417
- limit: 1,
9418
+ limit: 0,
9418
9419
  before: null,
9419
9420
  tags: ["INBOX"],
9420
9421
  includeDeliveryReceipts: false,
@@ -13515,18 +13516,24 @@ function createGetSeqID(deps) {
13515
13516
  ctx.t_mqttCalled = false;
13516
13517
  return defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form).then(parseAndCheckLogin2(ctx, defaultFuncs)).then(async (resData) => {
13517
13518
  if (getType13(resData) !== "Array") {
13518
- logger(`getSeqID: Unexpected response type: ${getType13(resData)}, value: ${JSON.stringify(resData).substring(0, 200)}`, "warn");
13519
- if (resData && typeof resData === "object") {
13520
- const errorMsg = resData.error || resData.message || "";
13521
- if (/Not logged in|login|blocked|401|403|checkpoint/i.test(errorMsg)) {
13522
- throw { error: "Not logged in", originalResponse: resData };
13523
- }
13519
+ logger(`getSeqID: Unexpected GraphQL response type: ${getType13(resData)}`, "warn");
13520
+ const responseText = JSON.stringify(resData || {}).toLowerCase();
13521
+ if (/not logged in|login|blocked|401|403|checkpoint|1357001/.test(responseText)) {
13522
+ throw { error: "Not logged in", originalResponse: resData };
13524
13523
  }
13525
- throw { error: "Not logged in", originalResponse: resData };
13524
+ throw { error: "getSeqID: unexpected GraphQL response", code: "SYNC_RESPONSE", originalResponse: resData };
13525
+ }
13526
+ if (!Array.isArray(resData) || !resData.length) {
13527
+ throw { error: "getSeqID: empty GraphQL response", code: "SYNC_EMPTY" };
13526
13528
  }
13527
- if (!Array.isArray(resData) || !resData.length) return;
13528
13529
  const lastRes = resData[resData.length - 1];
13529
- if (lastRes && lastRes.successful_results === 0) return;
13530
+ 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 };
13534
+ }
13535
+ throw { error: "getSeqID: GraphQL returned zero successful results", code: "SYNC_EMPTY", originalResponse: resData };
13536
+ }
13530
13537
  const syncSeqId = resData[0]?.o0?.data?.viewer?.message_threads?.sync_sequence_id;
13531
13538
  if (syncSeqId) {
13532
13539
  ctx.lastSeqId = syncSeqId;
@@ -13537,8 +13544,22 @@ function createGetSeqID(deps) {
13537
13544
  }
13538
13545
  }).catch(async (err) => {
13539
13546
  const detail = err && err.detail && err.detail.message ? ` | detail=${err.detail.message}` : "";
13540
- const msg = (err && err.error || err && err.message || String(err || "")) + detail;
13541
- const isAuthError = /Not logged in|no sync_sequence_id found|blocked the login|401|403/i.test(msg);
13547
+ const errorCode = String(err && (err.error || err.code) || "").toLowerCase();
13548
+ const errorMessage = String(err && err.message || "");
13549
+ const msg = [errorCode, errorMessage].filter(Boolean).join(": ") + detail || String(err || "");
13550
+ const combined = `${errorCode} ${errorMessage} ${msg}`.toLowerCase();
13551
+ if (/login_blocked|blocked the login|1357001/.test(combined)) {
13552
+ logger(`getSeqID: Facebook rejected this session: ${msg}`, "error");
13553
+ return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13554
+ }
13555
+ const isAuthError = /not logged in|not_logged_in|401|403|checkpoint/.test(combined);
13556
+ const isSequenceError = /no sync_sequence_id|sync_empty|sync_response|zero successful results|empty graphql response/.test(combined);
13557
+ if (isSequenceError && retryCount < MAX_RETRIES) {
13558
+ const delay3 = RETRY_DELAY * (retryCount + 1);
13559
+ logger(`getSeqID: sync-state retry ${retryCount + 1}/${MAX_RETRIES} after ${delay3}ms`, "warn");
13560
+ await new Promise((resolve) => setTimeout(resolve, delay3));
13561
+ return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
13562
+ }
13542
13563
  if (isAuthError) {
13543
13564
  if (retryCount < MAX_RETRIES) {
13544
13565
  const delay3 = RETRY_DELAY * (retryCount + 1);
@@ -13558,10 +13579,7 @@ function createGetSeqID(deps) {
13558
13579
  `getSeqID: authentication retries exhausted; handing recovery to TESSA: ${msg}`,
13559
13580
  "error"
13560
13581
  );
13561
- if (/blocked/i.test(msg)) {
13562
- return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
13563
- }
13564
- if (/Not logged in/i.test(msg)) {
13582
+ if (/not logged in|not_logged_in|401|403|checkpoint/i.test(combined)) {
13565
13583
  return emitAuth(ctx, api, globalCallback, "not_logged_in", msg);
13566
13584
  }
13567
13585
  }
@@ -13845,7 +13863,7 @@ var require_connect_mqtt = __commonJS({
13845
13863
  if (ctx._rTimeout) {
13846
13864
  delete ctx._rTimeout;
13847
13865
  }
13848
- if (ctx.globalOptions.emitReady) globalCallback({ type: "ready", error: null });
13866
+ if (ctx.globalOptions.emitReady) globalCallback(null, { type: "ready", error: null });
13849
13867
  delete ctx.tmsWait;
13850
13868
  };
13851
13869
  });
@@ -13865,13 +13883,23 @@ var require_connect_mqtt = __commonJS({
13865
13883
  } else if (jsonMessage.type === "jewel_requests_remove_old") {
13866
13884
  globalCallback(null, { type: "friend_request_cancel", actorFbId: jsonMessage.from.toString(), timestamp: Date.now().toString() });
13867
13885
  } else if (topic === "/t_ms") {
13868
- if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
13869
- if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
13886
+ const hasSyncState = jsonMessage && typeof jsonMessage === "object" && (jsonMessage.syncToken != null || jsonMessage.firstDeltaSeqId != null || jsonMessage.lastIssuedSeqId != null);
13887
+ if (!hasSyncState) {
13888
+ logger("mqtt received an incomplete /t_ms response; waiting for sync state", "warn");
13889
+ return;
13890
+ }
13891
+ if (jsonMessage.firstDeltaSeqId != null) {
13870
13892
  ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
13893
+ }
13894
+ if (jsonMessage.syncToken != null) {
13871
13895
  ctx.syncToken = jsonMessage.syncToken;
13872
13896
  }
13873
- if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
13874
- for (const dlt of jsonMessage.deltas || []) {
13897
+ if (jsonMessage.lastIssuedSeqId != null) {
13898
+ const lastIssuedSeqId = Number.parseInt(String(jsonMessage.lastIssuedSeqId), 10);
13899
+ if (Number.isFinite(lastIssuedSeqId)) ctx.lastSeqId = lastIssuedSeqId;
13900
+ }
13901
+ if (ctx.tmsWait && typeof ctx.tmsWait === "function") ctx.tmsWait();
13902
+ for (const dlt of Array.isArray(jsonMessage.deltas) ? jsonMessage.deltas : []) {
13875
13903
  parseDelta2(defaultFuncs, api, ctx, globalCallback, { delta: dlt });
13876
13904
  }
13877
13905
  } else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
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.0",
3
+ "version": "1.0.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@cexi/hoonfca",
9
- "version": "1.0.0",
9
+ "version": "1.0.3",
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.0",
3
+ "version": "1.0.3",
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",
@@ -29,7 +29,8 @@
29
29
  "lint": "eslint --ext .cjs scripts test",
30
30
  "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
31
31
  "build": "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string --external form-data --external combined-stream && node scripts/cjs-bridge.cjs",
32
- "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
32
+ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
33
+ "release:check": "npm run build && npm run lint && npm run typecheck && npm test && npm pack --dry-run"
33
34
  },
34
35
  "repository": {
35
36
  "type": "git",