@dongdev/fca-unofficial 4.0.0 → 4.0.2
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 +29 -7
- package/dist/cjs.cjs +9 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +76 -120
- package/dist/index.mjs +75 -120
- package/docs/DOCS.md +30 -7
- package/fca-config.example.json +1 -1
- package/package.json +5 -6
- package/test/fca.test.cjs +7 -0
package/README.md
CHANGED
|
@@ -37,13 +37,14 @@ npm install
|
|
|
37
37
|
npm run build
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
The build produces
|
|
40
|
+
The build produces these artifacts in `dist/`:
|
|
41
41
|
|
|
42
|
-
| File | Format
|
|
43
|
-
|
|
44
|
-
| `dist/
|
|
45
|
-
| `dist/index.
|
|
46
|
-
| `dist/index.
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -65,8 +65,7 @@ function makeStyles(theme) {
|
|
|
65
65
|
info: (v) => import_picocolors.default.cyan(v),
|
|
66
66
|
warn: (v) => import_picocolors.default.yellow(v),
|
|
67
67
|
error: (v) => import_picocolors.default.red(v),
|
|
68
|
-
sys: (v) => import_picocolors.default.blue(v)
|
|
69
|
-
banner: (v) => import_picocolors.default.white(v)
|
|
68
|
+
sys: (v) => import_picocolors.default.blue(v)
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
return {
|
|
@@ -75,8 +74,7 @@ function makeStyles(theme) {
|
|
|
75
74
|
info: (v) => import_picocolors.default.cyan(v),
|
|
76
75
|
warn: (v) => import_picocolors.default.yellow(v),
|
|
77
76
|
error: (v) => import_picocolors.default.red(v),
|
|
78
|
-
sys: (v) => import_picocolors.default.blue(v)
|
|
79
|
-
banner: (v) => import_picocolors.default.cyan(v)
|
|
77
|
+
sys: (v) => import_picocolors.default.blue(v)
|
|
80
78
|
};
|
|
81
79
|
}
|
|
82
80
|
function parseLabel(message, fallback) {
|
|
@@ -109,22 +107,7 @@ function formatSuccessBody(body, grad, fallbackPaint) {
|
|
|
109
107
|
}
|
|
110
108
|
return fallbackPaint(body);
|
|
111
109
|
}
|
|
112
|
-
function donixAsciiBlock() {
|
|
113
|
-
return [
|
|
114
|
-
"____ ____ ____ ____ ____",
|
|
115
|
-
"||D ||||O ||||N ||||I ||||X ||",
|
|
116
|
-
"||__||||__||||__||||__||||__||",
|
|
117
|
-
"|/__\\||/__\\||/__\\||/__\\||/__\\|"
|
|
118
|
-
].join("\n");
|
|
119
|
-
}
|
|
120
110
|
async function ensureUiLibs() {
|
|
121
|
-
if (!boxenLib) {
|
|
122
|
-
try {
|
|
123
|
-
const boxenMod = await import("boxen");
|
|
124
|
-
boxenLib = boxenMod.default ?? boxenMod;
|
|
125
|
-
} catch {
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
111
|
if (!oraFactory) {
|
|
129
112
|
try {
|
|
130
113
|
const oraMod = await import("ora");
|
|
@@ -141,51 +124,6 @@ async function ensureUiLibs() {
|
|
|
141
124
|
}
|
|
142
125
|
}
|
|
143
126
|
}
|
|
144
|
-
function printBootBanner(styles) {
|
|
145
|
-
if (didPrintBootBanner) return;
|
|
146
|
-
didPrintBootBanner = true;
|
|
147
|
-
const version = process.env.npm_package_version || "4.0.0";
|
|
148
|
-
const theme = getTheme();
|
|
149
|
-
const grad = theme === "cyberpunk" ? loadGradientFns() : null;
|
|
150
|
-
if (theme === "cyberpunk" && grad && boxenLib) {
|
|
151
|
-
const asciiStyled = grad.cyberpunk(donixAsciiBlock());
|
|
152
|
-
const titleLine = `${import_picocolors.default.bold(grad.coolStatus("FCA-UNOFFICIAL"))} ${import_picocolors.default.dim(`v${version}`)}`;
|
|
153
|
-
const body2 = `${asciiStyled}
|
|
154
|
-
${titleLine}
|
|
155
|
-
${styles.text("Author:")} ${grad.coolStatus("DongDev (Donix-VN)")}
|
|
156
|
-
${styles.text("Status:")} ${import_picocolors.default.green("Ready to Connect")}`;
|
|
157
|
-
writeStdout(
|
|
158
|
-
boxenLib(body2, {
|
|
159
|
-
padding: 1,
|
|
160
|
-
margin: 0,
|
|
161
|
-
borderStyle: "double",
|
|
162
|
-
borderColor: "cyan"
|
|
163
|
-
})
|
|
164
|
-
);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const art = [
|
|
168
|
-
"\u2554\u2566\u2557\u2554\u2550\u2557\u2554\u2557\u2554\u2566\u2550\u2557\u2566 \u2566",
|
|
169
|
-
" \u2551\u2551\u2551 \u2551\u2551\u2551\u2551\u2560\u2566\u255D\u255A\u2566\u255D",
|
|
170
|
-
"\u2550\u2569\u255D\u255A\u2550\u255D\u255D\u255A\u255D\u2569\u255A\u2550 \u2569 DONIX"
|
|
171
|
-
].join("\n");
|
|
172
|
-
const body = `${import_picocolors.default.bold(styles.info("FCA-UNOFFICIAL"))} ${import_picocolors.default.dim(`v${version}`)}
|
|
173
|
-
${styles.text("Author:")} ${styles.info("DongDev (Donix-VN)")}
|
|
174
|
-
${styles.text("Status:")} ${import_picocolors.default.green("Ready to Connect")}
|
|
175
|
-
${styles.banner(art)}`;
|
|
176
|
-
if (boxenLib) {
|
|
177
|
-
writeStdout(
|
|
178
|
-
boxenLib(body, {
|
|
179
|
-
padding: 1,
|
|
180
|
-
margin: 0,
|
|
181
|
-
borderStyle: "round",
|
|
182
|
-
borderColor: "cyan"
|
|
183
|
-
})
|
|
184
|
-
);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
writeStdout(styles.banner(body));
|
|
188
|
-
}
|
|
189
127
|
function logLine(text, type) {
|
|
190
128
|
const level = String(type || "info").toLowerCase();
|
|
191
129
|
const message = String(text ?? "");
|
|
@@ -222,14 +160,12 @@ function logLine(text, type) {
|
|
|
222
160
|
const bodyOut = grad ? grad.coolStatus(parts.body) : styles.info(parts.body);
|
|
223
161
|
writeStdout(`${ts} ${labelOut} : ${bodyOut}`);
|
|
224
162
|
}
|
|
225
|
-
var import_picocolors, import_gradient_string,
|
|
163
|
+
var import_picocolors, import_gradient_string, oraFactory, progressCtor, progressPreset, gradientFns, baseLogger, logger_default;
|
|
226
164
|
var init_logger = __esm({
|
|
227
165
|
"src/func/logger.ts"() {
|
|
228
166
|
"use strict";
|
|
229
167
|
import_picocolors = __toESM(require("picocolors"));
|
|
230
168
|
import_gradient_string = __toESM(require("gradient-string"));
|
|
231
|
-
didPrintBootBanner = false;
|
|
232
|
-
boxenLib = null;
|
|
233
169
|
oraFactory = null;
|
|
234
170
|
progressCtor = null;
|
|
235
171
|
progressPreset = null;
|
|
@@ -240,8 +176,6 @@ var init_logger = __esm({
|
|
|
240
176
|
baseLogger.warn = (text) => baseLogger(text, "warn");
|
|
241
177
|
baseLogger.error = (text) => baseLogger(text, "error");
|
|
242
178
|
baseLogger.showBanner = async () => {
|
|
243
|
-
await ensureUiLibs();
|
|
244
|
-
printBootBanner(makeStyles(getTheme()));
|
|
245
179
|
};
|
|
246
180
|
baseLogger.startSpinner = async (text) => {
|
|
247
181
|
await ensureUiLibs();
|
|
@@ -15652,16 +15586,16 @@ var init_package = __esm({
|
|
|
15652
15586
|
"package.json"() {
|
|
15653
15587
|
package_default = {
|
|
15654
15588
|
name: "@dongdev/fca-unofficial",
|
|
15655
|
-
version: "4.0.
|
|
15589
|
+
version: "4.0.2",
|
|
15656
15590
|
description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
15657
|
-
main: "dist/
|
|
15591
|
+
main: "dist/cjs.cjs",
|
|
15658
15592
|
types: "dist/index.d.ts",
|
|
15659
15593
|
exports: {
|
|
15660
15594
|
".": {
|
|
15661
15595
|
types: "./dist/index.d.ts",
|
|
15662
|
-
require: "./dist/
|
|
15596
|
+
require: "./dist/cjs.cjs",
|
|
15663
15597
|
import: "./dist/index.mjs",
|
|
15664
|
-
default: "./dist/index.
|
|
15598
|
+
default: "./dist/index.mjs"
|
|
15665
15599
|
}
|
|
15666
15600
|
},
|
|
15667
15601
|
files: [
|
|
@@ -15677,7 +15611,7 @@ var init_package = __esm({
|
|
|
15677
15611
|
"test:build": "npm run build && node ./test/fca.test.cjs",
|
|
15678
15612
|
lint: "eslint .",
|
|
15679
15613
|
typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
|
|
15680
|
-
build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string",
|
|
15614
|
+
build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string && node scripts/cjs-bridge.cjs",
|
|
15681
15615
|
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
|
|
15682
15616
|
},
|
|
15683
15617
|
repository: {
|
|
@@ -15721,7 +15655,6 @@ var init_package = __esm({
|
|
|
15721
15655
|
axios: "^1.13.5",
|
|
15722
15656
|
"axios-cookiejar-support": "^5.0.5",
|
|
15723
15657
|
bluebird: "^3.7.2",
|
|
15724
|
-
boxen: "^8.0.1",
|
|
15725
15658
|
cheerio: "^1.0.0-rc.10",
|
|
15726
15659
|
"cli-progress": "^3.12.0",
|
|
15727
15660
|
duplexify: "^4.1.3",
|
|
@@ -27146,19 +27079,83 @@ function appStateToFbid(appState) {
|
|
|
27146
27079
|
const iUser = appState.find((c) => c?.key === "i_user" || c?.name === "i_user");
|
|
27147
27080
|
return String(cUser && cUser.value || iUser && iUser.value || "");
|
|
27148
27081
|
}
|
|
27082
|
+
async function loginAsync(credentials, customOptions = {}) {
|
|
27083
|
+
const { config: config2 } = loadConfig();
|
|
27084
|
+
g2.fca = g2.fca || {};
|
|
27085
|
+
g2.fca.config = config2;
|
|
27086
|
+
const ctx = createDefaultContext();
|
|
27087
|
+
const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
|
|
27088
|
+
setOptions(globalOptions, customOptions || {});
|
|
27089
|
+
ctx.options = { ...ctx.options, ...globalOptions };
|
|
27090
|
+
ctx.globalOptions = globalOptions;
|
|
27091
|
+
ctx.cookieString = appStateToCookieString(credentials.appState);
|
|
27092
|
+
ctx.fbid = appStateToFbid(credentials.appState);
|
|
27093
|
+
ctx._request = createRequestHelper(ctx);
|
|
27094
|
+
const runLogin = () => new Promise((resolve, reject) => {
|
|
27095
|
+
(0, import_login_helper.default)(
|
|
27096
|
+
credentials.appState,
|
|
27097
|
+
credentials.Cookie,
|
|
27098
|
+
credentials.email,
|
|
27099
|
+
credentials.password,
|
|
27100
|
+
globalOptions,
|
|
27101
|
+
(error, api2) => {
|
|
27102
|
+
if (error) return reject(error);
|
|
27103
|
+
return resolve(api2);
|
|
27104
|
+
}
|
|
27105
|
+
);
|
|
27106
|
+
});
|
|
27107
|
+
let api;
|
|
27108
|
+
if (config2.checkUpdate.enabled) {
|
|
27109
|
+
await runConfiguredUpdateCheck(config2, logger_default);
|
|
27110
|
+
}
|
|
27111
|
+
api = await runLogin();
|
|
27112
|
+
ctx.api = api;
|
|
27113
|
+
try {
|
|
27114
|
+
if (typeof api.getCurrentUserID === "function") {
|
|
27115
|
+
ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
|
|
27116
|
+
ctx.userID = ctx.fbid;
|
|
27117
|
+
}
|
|
27118
|
+
if (typeof api.getCookies === "function") {
|
|
27119
|
+
ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
|
|
27120
|
+
}
|
|
27121
|
+
} catch {
|
|
27122
|
+
}
|
|
27123
|
+
return ctx;
|
|
27124
|
+
}
|
|
27125
|
+
function login(credentials, optionsOrCallback, callback) {
|
|
27126
|
+
if (typeof optionsOrCallback === "function") {
|
|
27127
|
+
const cb = optionsOrCallback;
|
|
27128
|
+
void loginAsync(credentials, {}).then((ctx) => {
|
|
27129
|
+
cb(null, ctx.api);
|
|
27130
|
+
}).catch((err) => {
|
|
27131
|
+
cb(err instanceof Error ? err : new Error(String(err?.message ?? err)));
|
|
27132
|
+
});
|
|
27133
|
+
return;
|
|
27134
|
+
}
|
|
27135
|
+
if (typeof callback === "function") {
|
|
27136
|
+
const opts = optionsOrCallback || {};
|
|
27137
|
+
void loginAsync(credentials, opts).then((ctx) => {
|
|
27138
|
+
callback(null, ctx.api);
|
|
27139
|
+
}).catch((err) => {
|
|
27140
|
+
callback(err instanceof Error ? err : new Error(String(err?.message ?? err)));
|
|
27141
|
+
});
|
|
27142
|
+
return;
|
|
27143
|
+
}
|
|
27144
|
+
return loginAsync(credentials, optionsOrCallback || {});
|
|
27145
|
+
}
|
|
27149
27146
|
function loginLegacy(credentials, options, callback) {
|
|
27150
27147
|
if (getType14(options) === "Function" || getType14(options) === "AsyncFunction") {
|
|
27151
27148
|
callback = options;
|
|
27152
27149
|
options = {};
|
|
27153
27150
|
}
|
|
27154
|
-
const p =
|
|
27151
|
+
const p = loginAsync(credentials, options || {});
|
|
27155
27152
|
if (typeof callback === "function") {
|
|
27156
27153
|
p.then((res) => callback?.(null, res)).catch((err) => callback?.(err));
|
|
27157
27154
|
return;
|
|
27158
27155
|
}
|
|
27159
27156
|
return p;
|
|
27160
27157
|
}
|
|
27161
|
-
var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS,
|
|
27158
|
+
var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
|
|
27162
27159
|
var init_auth = __esm({
|
|
27163
27160
|
"src/core/auth.ts"() {
|
|
27164
27161
|
"use strict";
|
|
@@ -27230,49 +27227,6 @@ var init_auth = __esm({
|
|
|
27230
27227
|
emitReady: false,
|
|
27231
27228
|
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
27229
|
};
|
|
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
27230
|
tokensViaAPI = (email, password, twoFactor, apiBaseUrl) => import_login_helper.default.tokensViaAPI(email, password, twoFactor, apiBaseUrl);
|
|
27277
27231
|
loginViaAPI2 = (email, password, twoFactor, apiBaseUrl, apiKey) => import_login_helper.default.loginViaAPI(email, password, twoFactor, apiBaseUrl, apiKey);
|
|
27278
27232
|
normalizeCookieHeaderString = (cookieHeader) => import_login_helper.default.normalizeCookieHeaderString(cookieHeader);
|
|
@@ -27307,6 +27261,7 @@ __export(index_exports, {
|
|
|
27307
27261
|
listenMqtt: () => listenMqtt,
|
|
27308
27262
|
loadConfig: () => loadConfig,
|
|
27309
27263
|
login: () => login,
|
|
27264
|
+
loginAsync: () => loginAsync,
|
|
27310
27265
|
loginLegacy: () => loginLegacy,
|
|
27311
27266
|
loginViaAPI: () => loginViaAPI2,
|
|
27312
27267
|
normalizeCookieHeaderString: () => normalizeCookieHeaderString,
|
|
@@ -27688,6 +27643,7 @@ init_scheduler();
|
|
|
27688
27643
|
listenMqtt,
|
|
27689
27644
|
loadConfig,
|
|
27690
27645
|
login,
|
|
27646
|
+
loginAsync,
|
|
27691
27647
|
loginLegacy,
|
|
27692
27648
|
loginViaAPI,
|
|
27693
27649
|
normalizeCookieHeaderString,
|
package/dist/index.mjs
CHANGED
|
@@ -72,8 +72,7 @@ function makeStyles(theme) {
|
|
|
72
72
|
info: (v) => pc.cyan(v),
|
|
73
73
|
warn: (v) => pc.yellow(v),
|
|
74
74
|
error: (v) => pc.red(v),
|
|
75
|
-
sys: (v) => pc.blue(v)
|
|
76
|
-
banner: (v) => pc.white(v)
|
|
75
|
+
sys: (v) => pc.blue(v)
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
return {
|
|
@@ -82,8 +81,7 @@ function makeStyles(theme) {
|
|
|
82
81
|
info: (v) => pc.cyan(v),
|
|
83
82
|
warn: (v) => pc.yellow(v),
|
|
84
83
|
error: (v) => pc.red(v),
|
|
85
|
-
sys: (v) => pc.blue(v)
|
|
86
|
-
banner: (v) => pc.cyan(v)
|
|
84
|
+
sys: (v) => pc.blue(v)
|
|
87
85
|
};
|
|
88
86
|
}
|
|
89
87
|
function parseLabel(message, fallback) {
|
|
@@ -116,22 +114,7 @@ function formatSuccessBody(body, grad, fallbackPaint) {
|
|
|
116
114
|
}
|
|
117
115
|
return fallbackPaint(body);
|
|
118
116
|
}
|
|
119
|
-
function donixAsciiBlock() {
|
|
120
|
-
return [
|
|
121
|
-
"____ ____ ____ ____ ____",
|
|
122
|
-
"||D ||||O ||||N ||||I ||||X ||",
|
|
123
|
-
"||__||||__||||__||||__||||__||",
|
|
124
|
-
"|/__\\||/__\\||/__\\||/__\\||/__\\|"
|
|
125
|
-
].join("\n");
|
|
126
|
-
}
|
|
127
117
|
async function ensureUiLibs() {
|
|
128
|
-
if (!boxenLib) {
|
|
129
|
-
try {
|
|
130
|
-
const boxenMod = await import("boxen");
|
|
131
|
-
boxenLib = boxenMod.default ?? boxenMod;
|
|
132
|
-
} catch {
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
118
|
if (!oraFactory) {
|
|
136
119
|
try {
|
|
137
120
|
const oraMod = await import("ora");
|
|
@@ -148,51 +131,6 @@ async function ensureUiLibs() {
|
|
|
148
131
|
}
|
|
149
132
|
}
|
|
150
133
|
}
|
|
151
|
-
function printBootBanner(styles) {
|
|
152
|
-
if (didPrintBootBanner) return;
|
|
153
|
-
didPrintBootBanner = true;
|
|
154
|
-
const version = process.env.npm_package_version || "4.0.0";
|
|
155
|
-
const theme = getTheme();
|
|
156
|
-
const grad = theme === "cyberpunk" ? loadGradientFns() : null;
|
|
157
|
-
if (theme === "cyberpunk" && grad && boxenLib) {
|
|
158
|
-
const asciiStyled = grad.cyberpunk(donixAsciiBlock());
|
|
159
|
-
const titleLine = `${pc.bold(grad.coolStatus("FCA-UNOFFICIAL"))} ${pc.dim(`v${version}`)}`;
|
|
160
|
-
const body2 = `${asciiStyled}
|
|
161
|
-
${titleLine}
|
|
162
|
-
${styles.text("Author:")} ${grad.coolStatus("DongDev (Donix-VN)")}
|
|
163
|
-
${styles.text("Status:")} ${pc.green("Ready to Connect")}`;
|
|
164
|
-
writeStdout(
|
|
165
|
-
boxenLib(body2, {
|
|
166
|
-
padding: 1,
|
|
167
|
-
margin: 0,
|
|
168
|
-
borderStyle: "double",
|
|
169
|
-
borderColor: "cyan"
|
|
170
|
-
})
|
|
171
|
-
);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const art = [
|
|
175
|
-
"\u2554\u2566\u2557\u2554\u2550\u2557\u2554\u2557\u2554\u2566\u2550\u2557\u2566 \u2566",
|
|
176
|
-
" \u2551\u2551\u2551 \u2551\u2551\u2551\u2551\u2560\u2566\u255D\u255A\u2566\u255D",
|
|
177
|
-
"\u2550\u2569\u255D\u255A\u2550\u255D\u255D\u255A\u255D\u2569\u255A\u2550 \u2569 DONIX"
|
|
178
|
-
].join("\n");
|
|
179
|
-
const body = `${pc.bold(styles.info("FCA-UNOFFICIAL"))} ${pc.dim(`v${version}`)}
|
|
180
|
-
${styles.text("Author:")} ${styles.info("DongDev (Donix-VN)")}
|
|
181
|
-
${styles.text("Status:")} ${pc.green("Ready to Connect")}
|
|
182
|
-
${styles.banner(art)}`;
|
|
183
|
-
if (boxenLib) {
|
|
184
|
-
writeStdout(
|
|
185
|
-
boxenLib(body, {
|
|
186
|
-
padding: 1,
|
|
187
|
-
margin: 0,
|
|
188
|
-
borderStyle: "round",
|
|
189
|
-
borderColor: "cyan"
|
|
190
|
-
})
|
|
191
|
-
);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
writeStdout(styles.banner(body));
|
|
195
|
-
}
|
|
196
134
|
function logLine(text, type) {
|
|
197
135
|
const level = String(type || "info").toLowerCase();
|
|
198
136
|
const message = String(text ?? "");
|
|
@@ -229,12 +167,10 @@ function logLine(text, type) {
|
|
|
229
167
|
const bodyOut = grad ? grad.coolStatus(parts.body) : styles.info(parts.body);
|
|
230
168
|
writeStdout(`${ts} ${labelOut} : ${bodyOut}`);
|
|
231
169
|
}
|
|
232
|
-
var
|
|
170
|
+
var oraFactory, progressCtor, progressPreset, gradientFns, baseLogger, logger_default;
|
|
233
171
|
var init_logger = __esm({
|
|
234
172
|
"src/func/logger.ts"() {
|
|
235
173
|
"use strict";
|
|
236
|
-
didPrintBootBanner = false;
|
|
237
|
-
boxenLib = null;
|
|
238
174
|
oraFactory = null;
|
|
239
175
|
progressCtor = null;
|
|
240
176
|
progressPreset = null;
|
|
@@ -245,8 +181,6 @@ var init_logger = __esm({
|
|
|
245
181
|
baseLogger.warn = (text) => baseLogger(text, "warn");
|
|
246
182
|
baseLogger.error = (text) => baseLogger(text, "error");
|
|
247
183
|
baseLogger.showBanner = async () => {
|
|
248
|
-
await ensureUiLibs();
|
|
249
|
-
printBootBanner(makeStyles(getTheme()));
|
|
250
184
|
};
|
|
251
185
|
baseLogger.startSpinner = async (text) => {
|
|
252
186
|
await ensureUiLibs();
|
|
@@ -15656,16 +15590,16 @@ var init_package = __esm({
|
|
|
15656
15590
|
"package.json"() {
|
|
15657
15591
|
package_default = {
|
|
15658
15592
|
name: "@dongdev/fca-unofficial",
|
|
15659
|
-
version: "4.0.
|
|
15593
|
+
version: "4.0.2",
|
|
15660
15594
|
description: "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
15661
|
-
main: "dist/
|
|
15595
|
+
main: "dist/cjs.cjs",
|
|
15662
15596
|
types: "dist/index.d.ts",
|
|
15663
15597
|
exports: {
|
|
15664
15598
|
".": {
|
|
15665
15599
|
types: "./dist/index.d.ts",
|
|
15666
|
-
require: "./dist/
|
|
15600
|
+
require: "./dist/cjs.cjs",
|
|
15667
15601
|
import: "./dist/index.mjs",
|
|
15668
|
-
default: "./dist/index.
|
|
15602
|
+
default: "./dist/index.mjs"
|
|
15669
15603
|
}
|
|
15670
15604
|
},
|
|
15671
15605
|
files: [
|
|
@@ -15681,7 +15615,7 @@ var init_package = __esm({
|
|
|
15681
15615
|
"test:build": "npm run build && node ./test/fca.test.cjs",
|
|
15682
15616
|
lint: "eslint .",
|
|
15683
15617
|
typecheck: "tsc -p tsconfig.typecheck.json --noEmit",
|
|
15684
|
-
build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string",
|
|
15618
|
+
build: "tsup src/index.ts --format cjs,esm --dts --clean --out-dir dist --external gradient-string && node scripts/cjs-bridge.cjs",
|
|
15685
15619
|
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly"
|
|
15686
15620
|
},
|
|
15687
15621
|
repository: {
|
|
@@ -15725,7 +15659,6 @@ var init_package = __esm({
|
|
|
15725
15659
|
axios: "^1.13.5",
|
|
15726
15660
|
"axios-cookiejar-support": "^5.0.5",
|
|
15727
15661
|
bluebird: "^3.7.2",
|
|
15728
|
-
boxen: "^8.0.1",
|
|
15729
15662
|
cheerio: "^1.0.0-rc.10",
|
|
15730
15663
|
"cli-progress": "^3.12.0",
|
|
15731
15664
|
duplexify: "^4.1.3",
|
|
@@ -27146,19 +27079,83 @@ function appStateToFbid(appState) {
|
|
|
27146
27079
|
const iUser = appState.find((c) => c?.key === "i_user" || c?.name === "i_user");
|
|
27147
27080
|
return String(cUser && cUser.value || iUser && iUser.value || "");
|
|
27148
27081
|
}
|
|
27082
|
+
async function loginAsync(credentials, customOptions = {}) {
|
|
27083
|
+
const { config: config2 } = loadConfig();
|
|
27084
|
+
g2.fca = g2.fca || {};
|
|
27085
|
+
g2.fca.config = config2;
|
|
27086
|
+
const ctx = createDefaultContext();
|
|
27087
|
+
const globalOptions = { ...DEFAULT_LOGIN_OPTIONS };
|
|
27088
|
+
setOptions(globalOptions, customOptions || {});
|
|
27089
|
+
ctx.options = { ...ctx.options, ...globalOptions };
|
|
27090
|
+
ctx.globalOptions = globalOptions;
|
|
27091
|
+
ctx.cookieString = appStateToCookieString(credentials.appState);
|
|
27092
|
+
ctx.fbid = appStateToFbid(credentials.appState);
|
|
27093
|
+
ctx._request = createRequestHelper(ctx);
|
|
27094
|
+
const runLogin = () => new Promise((resolve, reject) => {
|
|
27095
|
+
(0, import_login_helper.default)(
|
|
27096
|
+
credentials.appState,
|
|
27097
|
+
credentials.Cookie,
|
|
27098
|
+
credentials.email,
|
|
27099
|
+
credentials.password,
|
|
27100
|
+
globalOptions,
|
|
27101
|
+
(error, api2) => {
|
|
27102
|
+
if (error) return reject(error);
|
|
27103
|
+
return resolve(api2);
|
|
27104
|
+
}
|
|
27105
|
+
);
|
|
27106
|
+
});
|
|
27107
|
+
let api;
|
|
27108
|
+
if (config2.checkUpdate.enabled) {
|
|
27109
|
+
await runConfiguredUpdateCheck(config2, logger_default);
|
|
27110
|
+
}
|
|
27111
|
+
api = await runLogin();
|
|
27112
|
+
ctx.api = api;
|
|
27113
|
+
try {
|
|
27114
|
+
if (typeof api.getCurrentUserID === "function") {
|
|
27115
|
+
ctx.fbid = String(api.getCurrentUserID() || ctx.fbid || "");
|
|
27116
|
+
ctx.userID = ctx.fbid;
|
|
27117
|
+
}
|
|
27118
|
+
if (typeof api.getCookies === "function") {
|
|
27119
|
+
ctx.cookieString = String(api.getCookies() || ctx.cookieString || "");
|
|
27120
|
+
}
|
|
27121
|
+
} catch {
|
|
27122
|
+
}
|
|
27123
|
+
return ctx;
|
|
27124
|
+
}
|
|
27125
|
+
function login(credentials, optionsOrCallback, callback) {
|
|
27126
|
+
if (typeof optionsOrCallback === "function") {
|
|
27127
|
+
const cb = optionsOrCallback;
|
|
27128
|
+
void loginAsync(credentials, {}).then((ctx) => {
|
|
27129
|
+
cb(null, ctx.api);
|
|
27130
|
+
}).catch((err) => {
|
|
27131
|
+
cb(err instanceof Error ? err : new Error(String(err?.message ?? err)));
|
|
27132
|
+
});
|
|
27133
|
+
return;
|
|
27134
|
+
}
|
|
27135
|
+
if (typeof callback === "function") {
|
|
27136
|
+
const opts = optionsOrCallback || {};
|
|
27137
|
+
void loginAsync(credentials, opts).then((ctx) => {
|
|
27138
|
+
callback(null, ctx.api);
|
|
27139
|
+
}).catch((err) => {
|
|
27140
|
+
callback(err instanceof Error ? err : new Error(String(err?.message ?? err)));
|
|
27141
|
+
});
|
|
27142
|
+
return;
|
|
27143
|
+
}
|
|
27144
|
+
return loginAsync(credentials, optionsOrCallback || {});
|
|
27145
|
+
}
|
|
27149
27146
|
function loginLegacy(credentials, options, callback) {
|
|
27150
27147
|
if (getType14(options) === "Function" || getType14(options) === "AsyncFunction") {
|
|
27151
27148
|
callback = options;
|
|
27152
27149
|
options = {};
|
|
27153
27150
|
}
|
|
27154
|
-
const p =
|
|
27151
|
+
const p = loginAsync(credentials, options || {});
|
|
27155
27152
|
if (typeof callback === "function") {
|
|
27156
27153
|
p.then((res) => callback?.(null, res)).catch((err) => callback?.(err));
|
|
27157
27154
|
return;
|
|
27158
27155
|
}
|
|
27159
27156
|
return p;
|
|
27160
27157
|
}
|
|
27161
|
-
var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS,
|
|
27158
|
+
var import_format19, import_login_helper, getType14, g2, initialConfig, DEFAULT_LOGIN_OPTIONS, tokensViaAPI, loginViaAPI2, normalizeCookieHeaderString, setJarFromPairs2;
|
|
27162
27159
|
var init_auth = __esm({
|
|
27163
27160
|
"src/core/auth.ts"() {
|
|
27164
27161
|
"use strict";
|
|
@@ -27230,49 +27227,6 @@ var init_auth = __esm({
|
|
|
27230
27227
|
emitReady: false,
|
|
27231
27228
|
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
27229
|
};
|
|
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
27230
|
tokensViaAPI = (email, password, twoFactor, apiBaseUrl) => import_login_helper.default.tokensViaAPI(email, password, twoFactor, apiBaseUrl);
|
|
27277
27231
|
loginViaAPI2 = (email, password, twoFactor, apiBaseUrl, apiKey) => import_login_helper.default.loginViaAPI(email, password, twoFactor, apiBaseUrl, apiKey);
|
|
27278
27232
|
normalizeCookieHeaderString = (cookieHeader) => import_login_helper.default.normalizeCookieHeaderString(cookieHeader);
|
|
@@ -27652,6 +27606,7 @@ export {
|
|
|
27652
27606
|
listenMqtt,
|
|
27653
27607
|
loadConfig,
|
|
27654
27608
|
login,
|
|
27609
|
+
loginAsync,
|
|
27655
27610
|
loginLegacy,
|
|
27656
27611
|
loginViaAPI2 as loginViaAPI,
|
|
27657
27612
|
normalizeCookieHeaderString,
|
package/docs/DOCS.md
CHANGED
|
@@ -63,7 +63,27 @@ Additional scripts:
|
|
|
63
63
|
|
|
64
64
|
## 2. Authentication
|
|
65
65
|
|
|
66
|
-
### 2.1. `
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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 |
|
|
623
|
-
| `
|
|
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/fca-config.example.json
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dongdev/fca-unofficial",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
5
|
-
"main": "dist/
|
|
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/
|
|
10
|
+
"require": "./dist/cjs.cjs",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
|
-
"default": "./dist/index.
|
|
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": {
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"axios": "^1.13.5",
|
|
70
70
|
"axios-cookiejar-support": "^5.0.5",
|
|
71
71
|
"bluebird": "^3.7.2",
|
|
72
|
-
"boxen": "^8.0.1",
|
|
73
72
|
"cheerio": "^1.0.0-rc.10",
|
|
74
73
|
"cli-progress": "^3.12.0",
|
|
75
74
|
"duplexify": "^4.1.3",
|
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,
|