@dongdev/fca-unofficial 4.0.0 → 4.0.1

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/README.md CHANGED
@@ -37,13 +37,14 @@ npm install
37
37
  npm run build
38
38
  ```
39
39
 
40
- The build produces three artifacts in `dist/`:
40
+ The build produces these artifacts in `dist/`:
41
41
 
42
- | File | Format |
43
- |-------------------|---------------------|
44
- | `dist/index.js` | CommonJS (CJS) |
45
- | `dist/index.mjs` | ES Modules (ESM) |
46
- | `dist/index.d.ts` | TypeScript typings |
42
+ | File | Format / role |
43
+ |-------------------|----------------------------------------------------|
44
+ | `dist/cjs.cjs` | **CommonJS entry** — `require()` resolves here; the export **is** the `login` function (Mirai / classic FCA). |
45
+ | `dist/index.js` | Internal CJS bundle (required by `cjs.cjs`) |
46
+ | `dist/index.mjs` | ES Modules (ESM) |
47
+ | `dist/index.d.ts` | TypeScript typings |
47
48
 
48
49
  ---
49
50
 
@@ -80,7 +81,26 @@ async function main() {
80
81
  main();
81
82
  ```
82
83
 
83
- ### Legacy callback style
84
+ ### Classic `require` (default export = `login`)
85
+
86
+ Same pattern as older FCA forks: the required module **is** `login`. Callback gets **`api`**, not `ctx`.
87
+
88
+ ```javascript
89
+ const login = require("@dongdev/fca-unofficial");
90
+
91
+ login({ appState: require("./appstate.json") }, (err, api) => {
92
+ if (err) return console.error(err);
93
+ api.setOptions({ listenEvents: true });
94
+ api.listenMqtt((e, ev) => {
95
+ if (e) return console.error(e);
96
+ if (ev.type === "message") api.sendMessage(ev.body, ev.threadID);
97
+ });
98
+ });
99
+ ```
100
+
101
+ Optional FCA options before the callback: `login(credentials, { listenEvents: true }, (err, api) => { ... })`.
102
+
103
+ ### Async / Promise style
84
104
 
85
105
  ```javascript
86
106
  const { login } = require("@dongdev/fca-unofficial");
@@ -104,6 +124,8 @@ main();
104
124
 
105
125
  ## Authentication
106
126
 
127
+ With **`require("@dongdev/fca-unofficial")`**, you get the **`login`** function directly (see [Quick Start](#quick-start)). With **named** imports / ESM, use `import { login } from "..."` or `import login from "..."`.
128
+
107
129
  The library supports multiple credential strategies. Pass **one** of the following to `login()` or `createMessengerBot()`:
108
130
 
109
131
  | Credential | Description |
package/dist/cjs.cjs ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ const m = require("./index.js");
3
+ const core = typeof m.login === "function" ? m.login : m.default;
4
+ if (typeof core !== "function") {
5
+ throw new Error("@dongdev/fca-unofficial: expected login to be a function (check dist/index.js exports).");
6
+ }
7
+ Object.assign(core, m);
8
+ core.default = core;
9
+ module.exports = core;
package/dist/index.d.mts CHANGED
@@ -71,7 +71,16 @@ interface LoginCredentials$1 {
71
71
  password?: string;
72
72
  Cookie?: string | string[] | Record<string, string>;
73
73
  }
74
- declare const login: (credentials: LoginCredentials$1, customOptions?: FcaOptions) => Promise<FcaContext>;
74
+ /** Classic FCA-style callback receives the flat `api` object (same as `ctx.api`). */
75
+ type LoginApiCallback = (err: Error | null | undefined, api?: Loose) => void;
76
+ declare function loginAsync(credentials: LoginCredentials$1, customOptions?: FcaOptions): Promise<FcaContext>;
77
+ /**
78
+ * Login: Promise API, or legacy `login(credentials, (err, api) => …)` like classic FCA.
79
+ * For `const login = require('@dongdev/fca-unofficial')`, use the published `dist/cjs.cjs` entry.
80
+ */
81
+ declare function login(credentials: LoginCredentials$1, callback: LoginApiCallback): void;
82
+ declare function login(credentials: LoginCredentials$1, options: FcaOptions, callback: LoginApiCallback): void;
83
+ declare function login(credentials: LoginCredentials$1, customOptions?: FcaOptions): Promise<FcaContext>;
75
84
  declare function loginLegacy(credentials: LoginCredentials$1, options?: FcaOptions | ((err: Error | null, ctx?: FcaContext) => void), callback?: (err: Error | null, ctx?: FcaContext) => void): Promise<FcaContext> | undefined;
76
85
  interface TokensApiResponse {
77
86
  status?: boolean;
@@ -1238,4 +1247,4 @@ interface MqttCore {
1238
1247
  }) => NodeJS.Timeout | null;
1239
1248
  }
1240
1249
 
1241
- export { type AccountInactiveEvent, type AttachmentPayload, type AuthCore, type ChangeGroupImageResult, type ChangeThreadColorResult, type ChangeThreadEmojiResult, type CreateThemeAIResult, type DeleteMessageResult, type EditMessageResult, type EmojiPayload, type EventBase, type FcaClientFacade, type FcaClientNamespace, type FcaClientNamespaces, type FcaGlobalOptions, type FcaID, type FcaState, type ForwardAttachmentResult, type ForwardPayload, type FriendRequestCancelEvent, type FriendRequestReceivedEvent, type LegacyApiLike, type ListenMqttError, type LocationPayload, type LoginCredentials, type MentionPayload, type MessageEvent, type MessageReaction, type MessageUnsendEvent, MessengerBot, type MessengerBotLike, type MessengerBotOptions, MessengerContext, type MessengerMiddleware, type MessengerNext, type MqttCore, type MqttEvent, type PreUploadedAttachment, type PresenceEvent, type ReactionEvent, type ReadEvent, type ReadyEvent, type ReplyPayload, type RequestCore, type ScheduledMessageInfo, type SchedulerDomain, type SchedulerOptions, type SendMessageAttachment, type SendMessageContentPayload, type SendMessageEmojiSize, type SendMessageLocation, type SendMessageMention, type SendMessageObjectPayload, type SendMessagePayload, type SendMessageResult, type SendTypingOptions, type SetMessageReactionResult, type ShareContactResult, type StateCore, type StickerPayload, type StopListenEvent, type StreamAttachment, type TextPayload, type ThemeAssetImage, type ThemeBackgroundAsset, type ThemePicturesResult, type ThreadColorMap, type ThreadEvent, type TypingEvent, type UnsendMessageResult, type UploadAttachmentDescriptor, type UploadAttachmentInput, type UploadAttachmentMetadata, type UploadAttachmentOptions, type UploadAttachmentResult, type UrlPayload, attachClientFacade, attachThreadInfoRealtimeSync, checkForPackageUpdate, createAccountDomain, createApiFacade, createAuthCore, createDefaultContext, createFcaClient, createFcaState, createHttpDomain, createMessagesDomain, createMessengerBot, createRealtimeDomain, createRequestHelper, createSchedulerDomain, createThreadsDomain, createUsersDomain, login as default, defaultConfig, listenMqtt, loadConfig, login, loginLegacy, loginViaAPI, normalizeCookieHeaderString, resolveConfig, runConfiguredUpdateCheck, setJarFromPairs, tokensViaAPI, writeConfigTemplate };
1250
+ export { type AccountInactiveEvent, type AttachmentPayload, type AuthCore, type ChangeGroupImageResult, type ChangeThreadColorResult, type ChangeThreadEmojiResult, type CreateThemeAIResult, type DeleteMessageResult, type EditMessageResult, type EmojiPayload, type EventBase, type FcaClientFacade, type FcaClientNamespace, type FcaClientNamespaces, type FcaGlobalOptions, type FcaID, type FcaState, type ForwardAttachmentResult, type ForwardPayload, type FriendRequestCancelEvent, type FriendRequestReceivedEvent, type LegacyApiLike, type ListenMqttError, type LocationPayload, type LoginApiCallback, type LoginCredentials, type MentionPayload, type MessageEvent, type MessageReaction, type MessageUnsendEvent, MessengerBot, type MessengerBotLike, type MessengerBotOptions, MessengerContext, type MessengerMiddleware, type MessengerNext, type MqttCore, type MqttEvent, type PreUploadedAttachment, type PresenceEvent, type ReactionEvent, type ReadEvent, type ReadyEvent, type ReplyPayload, type RequestCore, type ScheduledMessageInfo, type SchedulerDomain, type SchedulerOptions, type SendMessageAttachment, type SendMessageContentPayload, type SendMessageEmojiSize, type SendMessageLocation, type SendMessageMention, type SendMessageObjectPayload, type SendMessagePayload, type SendMessageResult, type SendTypingOptions, type SetMessageReactionResult, type ShareContactResult, type StateCore, type StickerPayload, type StopListenEvent, type StreamAttachment, type TextPayload, type ThemeAssetImage, type ThemeBackgroundAsset, type ThemePicturesResult, type ThreadColorMap, type ThreadEvent, type TypingEvent, type UnsendMessageResult, type UploadAttachmentDescriptor, type UploadAttachmentInput, type UploadAttachmentMetadata, type UploadAttachmentOptions, type UploadAttachmentResult, type UrlPayload, attachClientFacade, attachThreadInfoRealtimeSync, checkForPackageUpdate, createAccountDomain, createApiFacade, createAuthCore, createDefaultContext, createFcaClient, createFcaState, createHttpDomain, createMessagesDomain, createMessengerBot, createRealtimeDomain, createRequestHelper, createSchedulerDomain, createThreadsDomain, createUsersDomain, login as default, defaultConfig, listenMqtt, loadConfig, login, loginAsync, loginLegacy, loginViaAPI, normalizeCookieHeaderString, resolveConfig, runConfiguredUpdateCheck, setJarFromPairs, tokensViaAPI, writeConfigTemplate };
package/dist/index.d.ts CHANGED
@@ -71,7 +71,16 @@ interface LoginCredentials$1 {
71
71
  password?: string;
72
72
  Cookie?: string | string[] | Record<string, string>;
73
73
  }
74
- declare const login: (credentials: LoginCredentials$1, customOptions?: FcaOptions) => Promise<FcaContext>;
74
+ /** Classic FCA-style callback receives the flat `api` object (same as `ctx.api`). */
75
+ type LoginApiCallback = (err: Error | null | undefined, api?: Loose) => void;
76
+ declare function loginAsync(credentials: LoginCredentials$1, customOptions?: FcaOptions): Promise<FcaContext>;
77
+ /**
78
+ * Login: Promise API, or legacy `login(credentials, (err, api) => …)` like classic FCA.
79
+ * For `const login = require('@dongdev/fca-unofficial')`, use the published `dist/cjs.cjs` entry.
80
+ */
81
+ declare function login(credentials: LoginCredentials$1, callback: LoginApiCallback): void;
82
+ declare function login(credentials: LoginCredentials$1, options: FcaOptions, callback: LoginApiCallback): void;
83
+ declare function login(credentials: LoginCredentials$1, customOptions?: FcaOptions): Promise<FcaContext>;
75
84
  declare function loginLegacy(credentials: LoginCredentials$1, options?: FcaOptions | ((err: Error | null, ctx?: FcaContext) => void), callback?: (err: Error | null, ctx?: FcaContext) => void): Promise<FcaContext> | undefined;
76
85
  interface TokensApiResponse {
77
86
  status?: boolean;
@@ -1238,4 +1247,4 @@ interface MqttCore {
1238
1247
  }) => NodeJS.Timeout | null;
1239
1248
  }
1240
1249
 
1241
- export { type AccountInactiveEvent, type AttachmentPayload, type AuthCore, type ChangeGroupImageResult, type ChangeThreadColorResult, type ChangeThreadEmojiResult, type CreateThemeAIResult, type DeleteMessageResult, type EditMessageResult, type EmojiPayload, type EventBase, type FcaClientFacade, type FcaClientNamespace, type FcaClientNamespaces, type FcaGlobalOptions, type FcaID, type FcaState, type ForwardAttachmentResult, type ForwardPayload, type FriendRequestCancelEvent, type FriendRequestReceivedEvent, type LegacyApiLike, type ListenMqttError, type LocationPayload, type LoginCredentials, type MentionPayload, type MessageEvent, type MessageReaction, type MessageUnsendEvent, MessengerBot, type MessengerBotLike, type MessengerBotOptions, MessengerContext, type MessengerMiddleware, type MessengerNext, type MqttCore, type MqttEvent, type PreUploadedAttachment, type PresenceEvent, type ReactionEvent, type ReadEvent, type ReadyEvent, type ReplyPayload, type RequestCore, type ScheduledMessageInfo, type SchedulerDomain, type SchedulerOptions, type SendMessageAttachment, type SendMessageContentPayload, type SendMessageEmojiSize, type SendMessageLocation, type SendMessageMention, type SendMessageObjectPayload, type SendMessagePayload, type SendMessageResult, type SendTypingOptions, type SetMessageReactionResult, type ShareContactResult, type StateCore, type StickerPayload, type StopListenEvent, type StreamAttachment, type TextPayload, type ThemeAssetImage, type ThemeBackgroundAsset, type ThemePicturesResult, type ThreadColorMap, type ThreadEvent, type TypingEvent, type UnsendMessageResult, type UploadAttachmentDescriptor, type UploadAttachmentInput, type UploadAttachmentMetadata, type UploadAttachmentOptions, type UploadAttachmentResult, type UrlPayload, attachClientFacade, attachThreadInfoRealtimeSync, checkForPackageUpdate, createAccountDomain, createApiFacade, createAuthCore, createDefaultContext, createFcaClient, createFcaState, createHttpDomain, createMessagesDomain, createMessengerBot, createRealtimeDomain, createRequestHelper, createSchedulerDomain, createThreadsDomain, createUsersDomain, login as default, defaultConfig, listenMqtt, loadConfig, login, loginLegacy, loginViaAPI, normalizeCookieHeaderString, resolveConfig, runConfiguredUpdateCheck, setJarFromPairs, tokensViaAPI, writeConfigTemplate };
1250
+ export { type AccountInactiveEvent, type AttachmentPayload, type AuthCore, type ChangeGroupImageResult, type ChangeThreadColorResult, type ChangeThreadEmojiResult, type CreateThemeAIResult, type DeleteMessageResult, type EditMessageResult, type EmojiPayload, type EventBase, type FcaClientFacade, type FcaClientNamespace, type FcaClientNamespaces, type FcaGlobalOptions, type FcaID, type FcaState, type ForwardAttachmentResult, type ForwardPayload, type FriendRequestCancelEvent, type FriendRequestReceivedEvent, type LegacyApiLike, type ListenMqttError, type LocationPayload, type LoginApiCallback, type LoginCredentials, type MentionPayload, type MessageEvent, type MessageReaction, type MessageUnsendEvent, MessengerBot, type MessengerBotLike, type MessengerBotOptions, MessengerContext, type MessengerMiddleware, type MessengerNext, type MqttCore, type MqttEvent, type PreUploadedAttachment, type PresenceEvent, type ReactionEvent, type ReadEvent, type ReadyEvent, type ReplyPayload, type RequestCore, type ScheduledMessageInfo, type SchedulerDomain, type SchedulerOptions, type SendMessageAttachment, type SendMessageContentPayload, type SendMessageEmojiSize, type SendMessageLocation, type SendMessageMention, type SendMessageObjectPayload, type SendMessagePayload, type SendMessageResult, type SendTypingOptions, type SetMessageReactionResult, type ShareContactResult, type StateCore, type StickerPayload, type StopListenEvent, type StreamAttachment, type TextPayload, type ThemeAssetImage, type ThemeBackgroundAsset, type ThemePicturesResult, type ThreadColorMap, type ThreadEvent, type TypingEvent, type UnsendMessageResult, type UploadAttachmentDescriptor, type UploadAttachmentInput, type UploadAttachmentMetadata, type UploadAttachmentOptions, type UploadAttachmentResult, type UrlPayload, attachClientFacade, attachThreadInfoRealtimeSync, checkForPackageUpdate, createAccountDomain, createApiFacade, createAuthCore, createDefaultContext, createFcaClient, createFcaState, createHttpDomain, createMessagesDomain, createMessengerBot, createRealtimeDomain, createRequestHelper, createSchedulerDomain, createThreadsDomain, createUsersDomain, login as default, defaultConfig, listenMqtt, loadConfig, login, loginAsync, loginLegacy, loginViaAPI, normalizeCookieHeaderString, resolveConfig, runConfiguredUpdateCheck, setJarFromPairs, tokensViaAPI, writeConfigTemplate };
package/dist/index.js CHANGED
@@ -144,7 +144,7 @@ async function ensureUiLibs() {
144
144
  function printBootBanner(styles) {
145
145
  if (didPrintBootBanner) return;
146
146
  didPrintBootBanner = true;
147
- const version = process.env.npm_package_version || "4.0.0";
147
+ const version = process.env.npm_package_version || "4.0.1";
148
148
  const theme = getTheme();
149
149
  const grad = theme === "cyberpunk" ? loadGradientFns() : null;
150
150
  if (theme === "cyberpunk" && grad && boxenLib) {
@@ -15652,16 +15652,16 @@ var init_package = __esm({
15652
15652
  "package.json"() {
15653
15653
  package_default = {
15654
15654
  name: "@dongdev/fca-unofficial",
15655
- version: "4.0.0",
15655
+ version: "4.0.1",
15656
15656
  description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
15657
- main: "dist/index.js",
15657
+ main: "dist/cjs.cjs",
15658
15658
  types: "dist/index.d.ts",
15659
15659
  exports: {
15660
15660
  ".": {
15661
15661
  types: "./dist/index.d.ts",
15662
- require: "./dist/index.js",
15662
+ require: "./dist/cjs.cjs",
15663
15663
  import: "./dist/index.mjs",
15664
- default: "./dist/index.js"
15664
+ default: "./dist/index.mjs"
15665
15665
  }
15666
15666
  },
15667
15667
  files: [
@@ -15677,7 +15677,7 @@ var init_package = __esm({
15677
15677
  "test:build": "npm run build && node ./test/fca.test.cjs",
15678
15678
  lint: "eslint .",
15679
15679
  typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
15680
- build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string",
15680
+ build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string && node scripts/cjs-bridge.cjs",
15681
15681
  "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
15682
15682
  },
15683
15683
  repository: {
@@ -27146,19 +27146,83 @@ function appStateToFbid(appState) {
27146
27146
  const iUser = appState.find((c) => c?.key === "i_user" || c?.name === "i_user");
27147
27147
  return String(cUser && cUser.value || iUser && iUser.value || "");
27148
27148
  }
27149
+ async function loginAsync(credentials, customOptions = {}) {
27150
+ const { config: config2 } = loadConfig();
27151
+ g2.fca = g2.fca || {};
27152
+ g2.fca.config = config2;
27153
+ const ctx = createDefaultContext();
27154
+ const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
27155
+ setOptions(globalOptions, customOptions || {});
27156
+ ctx.options = { ...ctx.options, ...globalOptions };
27157
+ ctx.globalOptions = globalOptions;
27158
+ ctx.cookieString = appStateToCookieString(credentials.appState);
27159
+ ctx.fbid = appStateToFbid(credentials.appState);
27160
+ ctx._request = createRequestHelper(ctx);
27161
+ const runLogin = () => new Promise((resolve, reject) => {
27162
+ (0, import_login_helper.default)(
27163
+ credentials.appState,
27164
+ credentials.Cookie,
27165
+ credentials.email,
27166
+ credentials.password,
27167
+ globalOptions,
27168
+ (error, api2) => {
27169
+ if (error) return reject(error);
27170
+ return resolve(api2);
27171
+ }
27172
+ );
27173
+ });
27174
+ let api;
27175
+ if (config2.checkUpdate.enabled) {
27176
+ await runConfiguredUpdateCheck(config2, logger_default);
27177
+ }
27178
+ api = await runLogin();
27179
+ ctx.api = api;
27180
+ try {
27181
+ if (typeof api.getCurrentUserID === "function") {
27182
+ ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
27183
+ ctx.userID = ctx.fbid;
27184
+ }
27185
+ if (typeof api.getCookies === "function") {
27186
+ ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
27187
+ }
27188
+ } catch {
27189
+ }
27190
+ return ctx;
27191
+ }
27192
+ function login(credentials, optionsOrCallback, callback) {
27193
+ if (typeof optionsOrCallback === "function") {
27194
+ const cb = optionsOrCallback;
27195
+ void loginAsync(credentials, {}).then((ctx) => {
27196
+ cb(null, ctx.api);
27197
+ }).catch((err) => {
27198
+ cb(err instanceof Error ? err : new Error(String(err?.message ?? err)));
27199
+ });
27200
+ return;
27201
+ }
27202
+ if (typeof callback === "function") {
27203
+ const opts = optionsOrCallback || {};
27204
+ void loginAsync(credentials, opts).then((ctx) => {
27205
+ callback(null, ctx.api);
27206
+ }).catch((err) => {
27207
+ callback(err instanceof Error ? err : new Error(String(err?.message ?? err)));
27208
+ });
27209
+ return;
27210
+ }
27211
+ return loginAsync(credentials, optionsOrCallback || {});
27212
+ }
27149
27213
  function loginLegacy(credentials, options, callback) {
27150
27214
  if (getType14(options) === "Function" || getType14(options) === "AsyncFunction") {
27151
27215
  callback = options;
27152
27216
  options = {};
27153
27217
  }
27154
- const p = login(credentials, options || {});
27218
+ const p = loginAsync(credentials, options || {});
27155
27219
  if (typeof callback === "function") {
27156
27220
  p.then((res) => callback?.(null, res)).catch((err) => callback?.(err));
27157
27221
  return;
27158
27222
  }
27159
27223
  return p;
27160
27224
  }
27161
- var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, login, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
27225
+ var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
27162
27226
  var init_auth = __esm({
27163
27227
  "src/core/auth.ts"() {
27164
27228
  "use strict";
@@ -27230,49 +27294,6 @@ var init_auth = __esm({
27230
27294
  emitReady: false,
27231
27295
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
27232
27296
  };
27233
- login = async (credentials, customOptions = {}) => {
27234
- const { config: config2 } = loadConfig();
27235
- g2.fca = g2.fca || {};
27236
- g2.fca.config = config2;
27237
- const ctx = createDefaultContext();
27238
- const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
27239
- setOptions(globalOptions, customOptions || {});
27240
- ctx.options = { ...ctx.options, ...globalOptions };
27241
- ctx.globalOptions = globalOptions;
27242
- ctx.cookieString = appStateToCookieString(credentials.appState);
27243
- ctx.fbid = appStateToFbid(credentials.appState);
27244
- ctx._request = createRequestHelper(ctx);
27245
- const runLogin = () => new Promise((resolve, reject) => {
27246
- (0, import_login_helper.default)(
27247
- credentials.appState,
27248
- credentials.Cookie,
27249
- credentials.email,
27250
- credentials.password,
27251
- globalOptions,
27252
- (error, api2) => {
27253
- if (error) return reject(error);
27254
- return resolve(api2);
27255
- }
27256
- );
27257
- });
27258
- let api;
27259
- if (config2.checkUpdate.enabled) {
27260
- await runConfiguredUpdateCheck(config2, logger_default);
27261
- }
27262
- api = await runLogin();
27263
- ctx.api = api;
27264
- try {
27265
- if (typeof api.getCurrentUserID === "function") {
27266
- ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
27267
- ctx.userID = ctx.fbid;
27268
- }
27269
- if (typeof api.getCookies === "function") {
27270
- ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
27271
- }
27272
- } catch {
27273
- }
27274
- return ctx;
27275
- };
27276
27297
  tokensViaAPI = (email, password, twoFactor, apiBaseUrl) => import_login_helper.default.tokensViaAPI(email, password, twoFactor, apiBaseUrl);
27277
27298
  loginViaAPI2 = (email, password, twoFactor, apiBaseUrl, apiKey) => import_login_helper.default.loginViaAPI(email, password, twoFactor, apiBaseUrl, apiKey);
27278
27299
  normalizeCookieHeaderString = (cookieHeader) => import_login_helper.default.normalizeCookieHeaderString(cookieHeader);
@@ -27307,6 +27328,7 @@ __export(index_exports, {
27307
27328
  listenMqtt: () => listenMqtt,
27308
27329
  loadConfig: () => loadConfig,
27309
27330
  login: () => login,
27331
+ loginAsync: () => loginAsync,
27310
27332
  loginLegacy: () => loginLegacy,
27311
27333
  loginViaAPI: () => loginViaAPI2,
27312
27334
  normalizeCookieHeaderString: () => normalizeCookieHeaderString,
@@ -27688,6 +27710,7 @@ init_scheduler();
27688
27710
  listenMqtt,
27689
27711
  loadConfig,
27690
27712
  login,
27713
+ loginAsync,
27691
27714
  loginLegacy,
27692
27715
  loginViaAPI,
27693
27716
  normalizeCookieHeaderString,
package/dist/index.mjs CHANGED
@@ -151,7 +151,7 @@ async function ensureUiLibs() {
151
151
  function printBootBanner(styles) {
152
152
  if (didPrintBootBanner) return;
153
153
  didPrintBootBanner = true;
154
- const version = process.env.npm_package_version || "4.0.0";
154
+ const version = process.env.npm_package_version || "4.0.1";
155
155
  const theme = getTheme();
156
156
  const grad = theme === "cyberpunk" ? loadGradientFns() : null;
157
157
  if (theme === "cyberpunk" && grad && boxenLib) {
@@ -15656,16 +15656,16 @@ var init_package = __esm({
15656
15656
  "package.json"() {
15657
15657
  package_default = {
15658
15658
  name: "@dongdev/fca-unofficial",
15659
- version: "4.0.0",
15659
+ version: "4.0.1",
15660
15660
  description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
15661
- main: "dist/index.js",
15661
+ main: "dist/cjs.cjs",
15662
15662
  types: "dist/index.d.ts",
15663
15663
  exports: {
15664
15664
  ".": {
15665
15665
  types: "./dist/index.d.ts",
15666
- require: "./dist/index.js",
15666
+ require: "./dist/cjs.cjs",
15667
15667
  import: "./dist/index.mjs",
15668
- default: "./dist/index.js"
15668
+ default: "./dist/index.mjs"
15669
15669
  }
15670
15670
  },
15671
15671
  files: [
@@ -15681,7 +15681,7 @@ var init_package = __esm({
15681
15681
  "test:build": "npm run build && node ./test/fca.test.cjs",
15682
15682
  lint: "eslint .",
15683
15683
  typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
15684
- build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string",
15684
+ build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string && node scripts/cjs-bridge.cjs",
15685
15685
  "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
15686
15686
  },
15687
15687
  repository: {
@@ -27146,19 +27146,83 @@ function appStateToFbid(appState) {
27146
27146
  const iUser = appState.find((c) => c?.key === "i_user" || c?.name === "i_user");
27147
27147
  return String(cUser && cUser.value || iUser && iUser.value || "");
27148
27148
  }
27149
+ async function loginAsync(credentials, customOptions = {}) {
27150
+ const { config: config2 } = loadConfig();
27151
+ g2.fca = g2.fca || {};
27152
+ g2.fca.config = config2;
27153
+ const ctx = createDefaultContext();
27154
+ const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
27155
+ setOptions(globalOptions, customOptions || {});
27156
+ ctx.options = { ...ctx.options, ...globalOptions };
27157
+ ctx.globalOptions = globalOptions;
27158
+ ctx.cookieString = appStateToCookieString(credentials.appState);
27159
+ ctx.fbid = appStateToFbid(credentials.appState);
27160
+ ctx._request = createRequestHelper(ctx);
27161
+ const runLogin = () => new Promise((resolve, reject) => {
27162
+ (0, import_login_helper.default)(
27163
+ credentials.appState,
27164
+ credentials.Cookie,
27165
+ credentials.email,
27166
+ credentials.password,
27167
+ globalOptions,
27168
+ (error, api2) => {
27169
+ if (error) return reject(error);
27170
+ return resolve(api2);
27171
+ }
27172
+ );
27173
+ });
27174
+ let api;
27175
+ if (config2.checkUpdate.enabled) {
27176
+ await runConfiguredUpdateCheck(config2, logger_default);
27177
+ }
27178
+ api = await runLogin();
27179
+ ctx.api = api;
27180
+ try {
27181
+ if (typeof api.getCurrentUserID === "function") {
27182
+ ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
27183
+ ctx.userID = ctx.fbid;
27184
+ }
27185
+ if (typeof api.getCookies === "function") {
27186
+ ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
27187
+ }
27188
+ } catch {
27189
+ }
27190
+ return ctx;
27191
+ }
27192
+ function login(credentials, optionsOrCallback, callback) {
27193
+ if (typeof optionsOrCallback === "function") {
27194
+ const cb = optionsOrCallback;
27195
+ void loginAsync(credentials, {}).then((ctx) => {
27196
+ cb(null, ctx.api);
27197
+ }).catch((err) => {
27198
+ cb(err instanceof Error ? err : new Error(String(err?.message ?? err)));
27199
+ });
27200
+ return;
27201
+ }
27202
+ if (typeof callback === "function") {
27203
+ const opts = optionsOrCallback || {};
27204
+ void loginAsync(credentials, opts).then((ctx) => {
27205
+ callback(null, ctx.api);
27206
+ }).catch((err) => {
27207
+ callback(err instanceof Error ? err : new Error(String(err?.message ?? err)));
27208
+ });
27209
+ return;
27210
+ }
27211
+ return loginAsync(credentials, optionsOrCallback || {});
27212
+ }
27149
27213
  function loginLegacy(credentials, options, callback) {
27150
27214
  if (getType14(options) === "Function" || getType14(options) === "AsyncFunction") {
27151
27215
  callback = options;
27152
27216
  options = {};
27153
27217
  }
27154
- const p = login(credentials, options || {});
27218
+ const p = loginAsync(credentials, options || {});
27155
27219
  if (typeof callback === "function") {
27156
27220
  p.then((res) => callback?.(null, res)).catch((err) => callback?.(err));
27157
27221
  return;
27158
27222
  }
27159
27223
  return p;
27160
27224
  }
27161
- var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, login, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
27225
+ var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
27162
27226
  var init_auth = __esm({
27163
27227
  "src/core/auth.ts"() {
27164
27228
  "use strict";
@@ -27230,49 +27294,6 @@ var init_auth = __esm({
27230
27294
  emitReady: false,
27231
27295
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
27232
27296
  };
27233
- login = async (credentials, customOptions = {}) => {
27234
- const { config: config2 } = loadConfig();
27235
- g2.fca = g2.fca || {};
27236
- g2.fca.config = config2;
27237
- const ctx = createDefaultContext();
27238
- const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
27239
- setOptions(globalOptions, customOptions || {});
27240
- ctx.options = { ...ctx.options, ...globalOptions };
27241
- ctx.globalOptions = globalOptions;
27242
- ctx.cookieString = appStateToCookieString(credentials.appState);
27243
- ctx.fbid = appStateToFbid(credentials.appState);
27244
- ctx._request = createRequestHelper(ctx);
27245
- const runLogin = () => new Promise((resolve, reject) => {
27246
- (0, import_login_helper.default)(
27247
- credentials.appState,
27248
- credentials.Cookie,
27249
- credentials.email,
27250
- credentials.password,
27251
- globalOptions,
27252
- (error, api2) => {
27253
- if (error) return reject(error);
27254
- return resolve(api2);
27255
- }
27256
- );
27257
- });
27258
- let api;
27259
- if (config2.checkUpdate.enabled) {
27260
- await runConfiguredUpdateCheck(config2, logger_default);
27261
- }
27262
- api = await runLogin();
27263
- ctx.api = api;
27264
- try {
27265
- if (typeof api.getCurrentUserID === "function") {
27266
- ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
27267
- ctx.userID = ctx.fbid;
27268
- }
27269
- if (typeof api.getCookies === "function") {
27270
- ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
27271
- }
27272
- } catch {
27273
- }
27274
- return ctx;
27275
- };
27276
27297
  tokensViaAPI = (email, password, twoFactor, apiBaseUrl) => import_login_helper.default.tokensViaAPI(email, password, twoFactor, apiBaseUrl);
27277
27298
  loginViaAPI2 = (email, password, twoFactor, apiBaseUrl, apiKey) => import_login_helper.default.loginViaAPI(email, password, twoFactor, apiBaseUrl, apiKey);
27278
27299
  normalizeCookieHeaderString = (cookieHeader) => import_login_helper.default.normalizeCookieHeaderString(cookieHeader);
@@ -27652,6 +27673,7 @@ export {
27652
27673
  listenMqtt,
27653
27674
  loadConfig,
27654
27675
  login,
27676
+ loginAsync,
27655
27677
  loginLegacy,
27656
27678
  loginViaAPI2 as loginViaAPI,
27657
27679
  normalizeCookieHeaderString,
package/docs/DOCS.md CHANGED
@@ -63,7 +63,27 @@ Additional scripts:
63
63
 
64
64
  ## 2. Authentication
65
65
 
66
- ### 2.1. `login()` async, returns `FcaContext`
66
+ ### 2.1. `require()` default = `login` (classic FCA / Mirai)
67
+
68
+ `package.json` points CommonJS `require` at `dist/cjs.cjs`, so the module itself **is** the `login` function (with all named exports copied onto it):
69
+
70
+ ```javascript
71
+ const login = require("@dongdev/fca-unofficial");
72
+
73
+ login({ appState: require("./appstate.json") }, (err, api) => {
74
+ if (err) return console.error(err);
75
+ api.setOptions({ listenEvents: true });
76
+ // api.getAppState(), api.listenMqtt(), …
77
+ });
78
+ ```
79
+
80
+ The callback receives **`api`** (flat legacy API), not `FcaContext`. For options + callback:
81
+
82
+ ```javascript
83
+ login({ appState: [...] }, { listenEvents: true }, (err, api) => { ... });
84
+ ```
85
+
86
+ ### 2.2. `login()` — Promise, returns `FcaContext`
67
87
 
68
88
  ```typescript
69
89
  import { login } from "@dongdev/fca-unofficial";
@@ -75,7 +95,9 @@ const ctx = await login(
75
95
  const api = ctx.api;
76
96
  ```
77
97
 
78
- ### 2.2. Credential strategies
98
+ Use **`loginAsync`** if you need an explicit async function reference without overload resolution.
99
+
100
+ ### 2.3. Credential strategies
79
101
 
80
102
  | Field | Description |
81
103
  |--------------------|-----------------------------------------------------------------------------|
@@ -83,7 +105,7 @@ const api = ctx.api;
83
105
  | `Cookie` | Raw cookie header string: `"c_user=...; xs=...; ..."`. |
84
106
  | `email` + `password` | Web login credentials. Easily triggers checkpoints; **not recommended** for production bots. |
85
107
 
86
- ### 2.3. `loginLegacy()` — callback style
108
+ ### 2.4. `loginLegacy()` — callback with `FcaContext`
87
109
 
88
110
  ```javascript
89
111
  const { loginLegacy } = require("@dongdev/fca-unofficial");
@@ -95,11 +117,11 @@ loginLegacy({ appState: require("./appstate.json") }, (err, ctx) => {
95
117
  });
96
118
  ```
97
119
 
98
- ### 2.4. Token-based login
120
+ ### 2.5. Token-based login
99
121
 
100
122
  `tokensViaAPI` and `loginViaAPI` authenticate through an external API server. Configure the `apiServer` and `credentials` fields in `fca-config.json`. See `src/core/auth.ts` for implementation details.
101
123
 
102
- ### 2.5. Login options (`FcaOptions`)
124
+ ### 2.6. Login options (`FcaOptions`)
103
125
 
104
126
  | Option | Type | Default | Description |
105
127
  |-------------------|-----------|-------------|------------------------------------------------|
@@ -619,8 +641,9 @@ All public exports from `@dongdev/fca-unofficial`:
619
641
 
620
642
  | Export | Category | Description |
621
643
  |---------------------------------|----------------|---------------------------------------------------|
622
- | `login` | Auth | Async login, returns `FcaContext` |
623
- | `loginLegacy` | Auth | Callback-style login |
644
+ | `login` | Auth | Promise login **or** `login(cred, (err, api) => …)` / `login(cred, opts, cb)` (classic FCA) |
645
+ | `loginAsync` | Auth | Always `Promise<FcaContext>` (no callback overload) |
646
+ | `loginLegacy` | Auth | Callback receives `FcaContext` |
624
647
  | `loginViaAPI` | Auth | Token-based login via external API |
625
648
  | `tokensViaAPI` | Auth | Fetch tokens from external API |
626
649
  | `normalizeCookieHeaderString` | Auth | Normalize a raw cookie string |
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
- "main": "dist/index.js",
5
+ "main": "dist/cjs.cjs",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
- "require": "./dist/index.js",
10
+ "require": "./dist/cjs.cjs",
11
11
  "import": "./dist/index.mjs",
12
- "default": "./dist/index.js"
12
+ "default": "./dist/index.mjs"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -25,7 +25,7 @@
25
25
  "test:build": "npm run build && node ./test/fca.test.cjs",
26
26
  "lint": "eslint .",
27
27
  "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
28
- "build": "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string",
28
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string && node scripts/cjs-bridge.cjs",
29
29
  "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
30
30
  },
31
31
  "repository": {
package/test/fca.test.cjs CHANGED
@@ -366,6 +366,13 @@ test("public exports are available", () => {
366
366
  assert.strictEqual(typeof fca.loadConfig, "function");
367
367
  });
368
368
 
369
+ test("dist/cjs.cjs default export is callable login (Mirai / classic require)", () => {
370
+ const login = require("../dist/cjs.cjs");
371
+ assert.strictEqual(typeof login, "function");
372
+ assert.strictEqual(typeof login.login, "function");
373
+ assert.strictEqual(typeof login.createMessengerBot, "function");
374
+ });
375
+
369
376
  test("resolveConfig honors legacy autoUpdate alias", () => {
370
377
  const resolved = fca.resolveConfig({
371
378
  autoUpdate: false,