@nirzon-islam/omega-fca 0.0.0-stage → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +155 -2
- package/docs/ARCHITECTURE.md +126 -0
- package/docs/AUTHENTICATION-ATTEMPT.md +52 -0
- package/docs/BROWSER-CAPTURE.md +74 -0
- package/docs/DEPLOYMENT.md +80 -0
- package/docs/FACEBOOK-MQTT-TRANSPORT.md +82 -0
- package/docs/GOATBOT-COMPATIBILITY-MATRIX.md +58 -0
- package/docs/GOATBOT-INTEGRATION-AUDIT.md +64 -0
- package/docs/IMPLEMENTATION-STATUS.md +51 -0
- package/docs/META-MESSENGER-TRANSPORT.md +78 -0
- package/docs/NESTED-REALTIME-PAYLOAD.md +16 -0
- package/docs/NTKHANG-REFERENCE-STUDY.md +69 -0
- package/docs/PROTOCOL-EVIDENCE.md +69 -0
- package/docs/REALTIME-FRAME-EVIDENCE.md +33 -0
- package/docs/REFERENCE-AUDIT.md +63 -0
- package/docs/SAFE-DIAGNOSTICS.md +39 -0
- package/examples/appstate-session-check.js +33 -0
- package/examples/meta-messenger-server.js +96 -0
- package/index.d.ts +407 -0
- package/index.js +62 -0
- package/package.json +63 -4
- package/src/api/client.js +308 -0
- package/src/auth/accountConfig.js +82 -0
- package/src/auth/authenticationAttempt.js +193 -0
- package/src/auth/facebookResponse.js +93 -0
- package/src/auth/facebookWebClient.js +133 -0
- package/src/auth/personalSession.js +335 -0
- package/src/auth/totp.js +39 -0
- package/src/compat/facebookMqttClient.js +74 -0
- package/src/compat/goatbotLogin.js +67 -0
- package/src/compat/legacyFcaTransport.js +136 -0
- package/src/events/dispatcher.js +69 -0
- package/src/license/provider.js +37 -0
- package/src/license/verify.js +42 -0
- package/src/network/cookieJar.js +72 -0
- package/src/network/requestClient.js +104 -0
- package/src/runtime/connection.js +231 -0
- package/src/security/cookies.js +104 -0
- package/src/security/diagnostics.js +98 -0
- package/src/security/redact.js +23 -0
- package/src/security/sessionCrypto.js +61 -0
- package/src/security/sessionState.js +23 -0
- package/src/security/sessionStore.js +64 -0
- package/src/transport/binaryPayloadInspector.js +131 -0
- package/src/transport/contract.js +39 -0
- package/src/transport/facebookGatewayProtocol.js +135 -0
- package/src/transport/facebookMqttDriver.js +60 -0
- package/src/transport/facebookMqttEvents.js +114 -0
- package/src/transport/facebookMqttProtocol.js +213 -0
- package/src/transport/facebookThreadApi.js +284 -0
- package/src/transport/messengerActions.js +64 -0
- package/src/transport/messengerSyncCursorStore.js +53 -0
- package/src/transport/metaMessenger.js +294 -0
- package/src/transport/mqtt311Codec.js +254 -0
- package/src/transport/mqtt311StreamDecoder.js +57 -0
- package/src/transport/mqttRequestTracker.js +60 -0
- package/src/transport/nativeRealtimeTransport.js +388 -0
- package/src/transport/realtimeFrameDecoder.js +92 -0
- package/src/transport/realtimeSyncEnvelope.js +84 -0
- package/src/update/manifest.js +102 -0
- package/tools/browser-capture.js +130 -0
- package/tools/termux-capture-setup.sh +26 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Minimal built-in Node.js HTTPS reverse-proxy target for Meta Messenger webhooks.
|
|
4
|
+
// Terminate TLS at your trusted ingress/proxy and forward only over a private network.
|
|
5
|
+
|
|
6
|
+
const http = require("node:http");
|
|
7
|
+
const {
|
|
8
|
+
createMetaMessengerTransport,
|
|
9
|
+
verifyWebhookChallenge
|
|
10
|
+
} = require("../index");
|
|
11
|
+
|
|
12
|
+
const required = [
|
|
13
|
+
"META_PAGE_ACCESS_TOKEN",
|
|
14
|
+
"META_PAGE_ID",
|
|
15
|
+
"META_GRAPH_API_VERSION",
|
|
16
|
+
"META_APP_SECRET",
|
|
17
|
+
"META_WEBHOOK_VERIFY_TOKEN"
|
|
18
|
+
];
|
|
19
|
+
for (const name of required) {
|
|
20
|
+
if (!process.env[name]) throw new Error("Missing required environment variable: " + name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const transport = createMetaMessengerTransport({
|
|
24
|
+
pageAccessToken: process.env.META_PAGE_ACCESS_TOKEN,
|
|
25
|
+
pageId: process.env.META_PAGE_ID,
|
|
26
|
+
apiVersion: process.env.META_GRAPH_API_VERSION,
|
|
27
|
+
appSecret: process.env.META_APP_SECRET
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
transport.listen((error, event) => {
|
|
31
|
+
if (error) {
|
|
32
|
+
console.error("Messenger event listener failed:", error.message);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log("Messenger event:", event.type, "from", event.senderID || "unknown");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const server = http.createServer(async (request, response) => {
|
|
39
|
+
const url = new URL(request.url, "http://localhost");
|
|
40
|
+
if (request.method === "GET" && url.pathname === "/healthz") {
|
|
41
|
+
response.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ status: "ok" }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (url.pathname !== "/webhook") {
|
|
45
|
+
response.writeHead(404).end("Not found");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (request.method === "GET") {
|
|
50
|
+
const challenge = verifyWebhookChallenge(
|
|
51
|
+
Object.fromEntries(url.searchParams),
|
|
52
|
+
process.env.META_WEBHOOK_VERIFY_TOKEN
|
|
53
|
+
);
|
|
54
|
+
if (challenge === null) {
|
|
55
|
+
response.writeHead(403).end("Webhook verification failed");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
response.writeHead(200, { "content-type": "text/plain; charset=utf-8" }).end(challenge);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (request.method !== "POST") {
|
|
63
|
+
response.writeHead(405, { allow: "GET, POST" }).end("Method not allowed");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const chunks = [];
|
|
69
|
+
let size = 0;
|
|
70
|
+
for await (const chunk of request) {
|
|
71
|
+
size += chunk.length;
|
|
72
|
+
if (size > 1024 * 1024) {
|
|
73
|
+
response.writeHead(413).end("Payload too large");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
chunks.push(chunk);
|
|
77
|
+
}
|
|
78
|
+
const rawBody = Buffer.concat(chunks, size);
|
|
79
|
+
const count = transport.publishWebhook(rawBody, request.headers["x-hub-signature-256"]);
|
|
80
|
+
response.writeHead(200, { "content-type": "text/plain" }).end("EVENT_RECEIVED");
|
|
81
|
+
if (count === 0) console.info("Received a valid webhook with no supported event entries");
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const status = error.code === "META_WEBHOOK_SIGNATURE_INVALID" ? 401 : 400;
|
|
84
|
+
response.writeHead(status, { "content-type": "text/plain" }).end("Invalid webhook");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const port = Number(process.env.PORT) || 3000;
|
|
89
|
+
server.listen(port, () => console.log("OmegA Messenger webhook listening on", port));
|
|
90
|
+
|
|
91
|
+
async function shutdown() {
|
|
92
|
+
server.close();
|
|
93
|
+
await transport.disconnect();
|
|
94
|
+
}
|
|
95
|
+
process.once("SIGINT", () => { void shutdown(); });
|
|
96
|
+
process.once("SIGTERM", () => { void shutdown(); });
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
export type LoginMode = "appstate" | "cookie";
|
|
2
|
+
export type AuthenticationAttemptState = "idle" | "authenticating" | "challenge_required" | "verifying_challenge" | "authenticated" | "failed" | "closed";
|
|
3
|
+
export interface AuthenticationChallenge { readonly type: string; readonly message: string | null; readonly methods: readonly string[]; }
|
|
4
|
+
export interface AuthenticationAttemptSnapshot { readonly state: AuthenticationAttemptState; readonly challenge: AuthenticationChallenge | null; readonly challengeRounds: number; readonly authenticated: boolean; readonly error: Readonly<{ name: string; code: string | null; message: string }> | null; }
|
|
5
|
+
export interface AuthenticationAttemptSession { close?(): void | Promise<void>; [key: string]: unknown; }
|
|
6
|
+
export type AuthenticationAttemptProviderResult = { status: "authenticated"; session: AuthenticationAttemptSession; } | { status: "challenge_required"; challenge: { type?: string; message?: string; methods?: string[] }; resume(answer: string | Record<string, unknown>): Promise<AuthenticationAttemptProviderResult> | AuthenticationAttemptProviderResult; cancel?(): void | Promise<void>; }
|
|
7
|
+
export function createAuthenticationAttempt(options: { authenticate(input: { credentials: Record<string, unknown>; options: Record<string, unknown> }): Promise<AuthenticationAttemptProviderResult> | AuthenticationAttemptProviderResult; maxChallengeRounds?: number }): Readonly<{ begin(credentials: Record<string, unknown>, options?: Record<string, unknown>): Promise<AuthenticationAttemptSession | null>; submitChallenge(answer: string | Record<string, unknown>): Promise<AuthenticationAttemptSession | null>; close(): Promise<void>; snapshot(): AuthenticationAttemptSnapshot }>;
|
|
8
|
+
export const AUTHENTICATION_ATTEMPT_STATES: readonly AuthenticationAttemptState[];
|
|
9
|
+
export interface Cookie {
|
|
10
|
+
key: string; value: string; domain?: string; path?: string; hostOnly?: boolean;
|
|
11
|
+
secure?: boolean; httpOnly?: boolean; sameSite?: string; expires?: number | null;
|
|
12
|
+
}
|
|
13
|
+
export interface Credentials {
|
|
14
|
+
mode: LoginMode; appState?: Cookie[]; cookie?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PersonalSessionOptions {
|
|
17
|
+
appState: Cookie[];
|
|
18
|
+
fetchImpl?: (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
19
|
+
userAgent?: string;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
onDiagnostic?: (event: SafeDiagnosticEvent) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface PersonalSession {
|
|
24
|
+
readonly userId: string;
|
|
25
|
+
readonly state: "active";
|
|
26
|
+
readonly validatedAt: number;
|
|
27
|
+
getTokens(): FacebookRequestTokens;
|
|
28
|
+
getCookieHeader(url?: string | URL): string;
|
|
29
|
+
request(input: string | URL, options?: RequestInit): Promise<Response>;
|
|
30
|
+
getAppState(): Cookie[];
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
33
|
+
export interface SafeDiagnosticEvent { readonly at: string; readonly phase: "request" | "response" | "error"; readonly method: string; readonly url: Readonly<{ origin: string | null; path: string | null; queryParameterNames: readonly string[] }>; readonly requestHeaders: readonly string[]; readonly requestBodyBytes: number; readonly requestFieldNames: readonly string[]; readonly sensitiveFieldCount: number; readonly fieldsTruncated: boolean; readonly status?: number; readonly contentType?: string; readonly responseBodyBytes?: number; readonly errorCode?: string; readonly durationMs?: number; }
|
|
34
|
+
export interface DiagnosticRecorder { record(input?: Record<string, unknown>): SafeDiagnosticEvent; snapshot(): Readonly<{ version: number; generatedAt: string; events: readonly SafeDiagnosticEvent[] }>; toJSON(): string; clear(): void; }
|
|
35
|
+
export function createDiagnosticRecorder(options?: { maxEvents?: number; clock?: () => number }): DiagnosticRecorder;
|
|
36
|
+
export function createPersonalSession(options: PersonalSessionOptions): Promise<PersonalSession>;
|
|
37
|
+
export function detectSessionChallenge(response: Response, html: string): "active" | "checkpoint" | "logged_out";
|
|
38
|
+
export function extractIdentity(html: string): string | null;
|
|
39
|
+
export interface FacebookRequestTokens {
|
|
40
|
+
fbDtsg: string | null; lsd: string | null; jazoest: string | null;
|
|
41
|
+
hsi: string | null; spinR: string | null; spinB: string | null; spinT: string | null;
|
|
42
|
+
}
|
|
43
|
+
export function extractFacebookTokens(html: string): FacebookRequestTokens;
|
|
44
|
+
export interface FacebookWebRequestResult {
|
|
45
|
+
status: number; headers: Headers; payload: unknown; raw: string;
|
|
46
|
+
}
|
|
47
|
+
export interface FacebookWebClient {
|
|
48
|
+
request(input: string | URL, options?: {
|
|
49
|
+
method?: "GET" | "HEAD" | "POST"; query?: Record<string, string | number | boolean>;
|
|
50
|
+
body?: Record<string, unknown> | URLSearchParams | string | Uint8Array;
|
|
51
|
+
headers?: HeadersInit; signal?: AbortSignal;
|
|
52
|
+
}): Promise<FacebookWebRequestResult>;
|
|
53
|
+
get(input: string | URL, options?: { query?: Record<string, string | number | boolean>; headers?: HeadersInit; signal?: AbortSignal }): Promise<FacebookWebRequestResult>;
|
|
54
|
+
post(input: string | URL, body?: Record<string, unknown> | URLSearchParams | string | Uint8Array, options?: { headers?: HeadersInit; signal?: AbortSignal }): Promise<FacebookWebRequestResult>;
|
|
55
|
+
}
|
|
56
|
+
export function createFacebookWebClient(options: {
|
|
57
|
+
session: PersonalSession;
|
|
58
|
+
normalizeResponse?: typeof normalizeFacebookResponse;
|
|
59
|
+
}): FacebookWebClient;
|
|
60
|
+
export function assertFacebookUrl(input: string | URL): URL;
|
|
61
|
+
export function toFormBody(data: Record<string, unknown>, tokens: FacebookRequestTokens, userId: string): URLSearchParams;
|
|
62
|
+
export interface FacebookResponseError extends Error {
|
|
63
|
+
code: string; status: number | null;
|
|
64
|
+
sessionState: "checkpoint" | "logged_out" | "error";
|
|
65
|
+
retryable: boolean;
|
|
66
|
+
}
|
|
67
|
+
export function normalizeFacebookResponse(body: string, options?: { status?: number; contentType?: string }): unknown;
|
|
68
|
+
export function stripFacebookJsonPrefix(body: string): string;
|
|
69
|
+
export function createFacebookError(message: string, options?: {
|
|
70
|
+
code?: string; status?: number; sessionState?: "checkpoint" | "logged_out" | "error"; retryable?: boolean;
|
|
71
|
+
}): FacebookResponseError;
|
|
72
|
+
export interface ConnectionContext { attempt: number; generation: number; signal: AbortSignal; }
|
|
73
|
+
export interface TransportDriver {
|
|
74
|
+
listen(callback: (error: Error | null, event?: unknown) => void): (() => void) | void;
|
|
75
|
+
disconnect?(): void | Promise<void>; getCurrentUserID?(): string | number | null | Promise<string | number | null>;
|
|
76
|
+
sendMessage?(...args: unknown[]): unknown; getUserInfo?(...args: unknown[]): unknown;
|
|
77
|
+
getThreadInfo?(...args: unknown[]): unknown; getThreadList?(...args: unknown[]): unknown;
|
|
78
|
+
markAsRead?(...args: unknown[]): unknown; setMessageReaction?(...args: unknown[]): unknown;
|
|
79
|
+
sendTypingIndicator?(...args: unknown[]): unknown; unsendMessage?(...args: unknown[]): unknown;
|
|
80
|
+
changeNickname?(...args: unknown[]): unknown; addUserToGroup?(...args: unknown[]): unknown;
|
|
81
|
+
removeUserFromGroup?(...args: unknown[]): unknown; createNewGroup?(...args: unknown[]): unknown;
|
|
82
|
+
getThreadHistory?(...args: unknown[]): unknown; getMessage?(...args: unknown[]): unknown;
|
|
83
|
+
getFriendsList?(...args: unknown[]): unknown; getUserID?(...args: unknown[]): unknown;
|
|
84
|
+
sessionGuard?(...args: unknown[]): unknown; stopSessionGuard?(): unknown;
|
|
85
|
+
setOptions?(options: Record<string, unknown>): unknown;
|
|
86
|
+
}
|
|
87
|
+
export interface ClientOptions {
|
|
88
|
+
authenticate(context: { mode: LoginMode; credentials: Cookie[];
|
|
89
|
+
options: Record<string, unknown>; context: ConnectionContext; license: VerifiedLicense | null;
|
|
90
|
+
}): Promise<TransportDriver> | TransportDriver;
|
|
91
|
+
options?: Record<string, unknown>;
|
|
92
|
+
reconnect?: { minDelayMs?: number; maxDelayMs?: number; factor?: number; jitter?: number; maxAttempts?: number };
|
|
93
|
+
license?: LicenseOptions; requireLicense?: boolean; onLicenseError?: (error: Error) => void;
|
|
94
|
+
}
|
|
95
|
+
export interface VerifiedLicense { licenseId: string; ownerId: string; installationId: string; features: string[]; [key: string]: unknown; }
|
|
96
|
+
export interface LicenseOptions {
|
|
97
|
+
token?: string; publicKey?: string; installationId?: string; ownerId?: string;
|
|
98
|
+
checkIntervalMs?: number; refresh?: () => string | Promise<string>;
|
|
99
|
+
}
|
|
100
|
+
export interface ClientApi {
|
|
101
|
+
getCurrentUserID(): string | null; getUserID?(): string | null; getConnectionState(): ConnectionSnapshot; getLicense(): VerifiedLicense | null;
|
|
102
|
+
getCapabilities(): Readonly<{ methods: readonly string[]; events: boolean; sessionGuard: boolean; e2ee: false }>;
|
|
103
|
+
listen(callback: (event: unknown) => void): () => void;
|
|
104
|
+
listenMqtt(callback: (error: Error | null, event?: unknown) => void): () => void;
|
|
105
|
+
stopListening(callback?: () => void): boolean;
|
|
106
|
+
sendRequest?: (payload: Record<string, unknown>, options?: { timeoutMs?: number }) => Promise<unknown>; sendMessage?: { (input: { threadID: string | number; message: string | { body?: string; sticker?: string | number }; replyToMessageID?: string | number }, options?: { timeoutMs?: number }): Promise<unknown>; (message: string | { body?: string; sticker?: string | number }, threadID: string | number, callback: (error: Error | null, result?: unknown) => void, replyToMessageID?: string | number): void; }; getUserInfo?: (...args: any[]) => any;
|
|
107
|
+
getThreadInfo?: (...args: any[]) => any; getThreadList?: (...args: any[]) => any;
|
|
108
|
+
markAsRead?: (...args: any[]) => any; setMessageReaction?: (...args: any[]) => any;
|
|
109
|
+
sendTypingIndicator?: (...args: any[]) => any; unsendMessage?: (...args: any[]) => any;
|
|
110
|
+
changeNickname?: (...args: any[]) => any; addUserToGroup?: (...args: any[]) => any;
|
|
111
|
+
removeUserFromGroup?: (...args: any[]) => any; createNewGroup?: (...args: any[]) => any;
|
|
112
|
+
getThreadHistory?: (...args: any[]) => any; getMessage?: (...args: any[]) => any;
|
|
113
|
+
getFriendsList?: (...args: any[]) => any; getUserID?: (...args: any[]) => any;
|
|
114
|
+
sessionGuard?: (...args: any[]) => any; stopSessionGuard?: () => any;
|
|
115
|
+
setOptions?: (options: Record<string, unknown>) => any;
|
|
116
|
+
}
|
|
117
|
+
export interface AuthenticationError extends Error {
|
|
118
|
+
code?: string; sessionState?: "checkpoint" | "logged_out" | "error" | "unknown"; retryable?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export interface ConnectionSnapshot {
|
|
121
|
+
state: "idle" | "connecting" | "reconnecting" | "connected" | "disconnected" | "failed" | "stopped";
|
|
122
|
+
connected: boolean; generation: number;
|
|
123
|
+
}
|
|
124
|
+
export interface ConnectionSupervisorOptions {
|
|
125
|
+
connect(context: ConnectionContext): Promise<TransportDriver> | TransportDriver;
|
|
126
|
+
disconnect?(driver: TransportDriver): void | Promise<void>;
|
|
127
|
+
options?: { minDelayMs?: number; maxDelayMs?: number; factor?: number; jitter?: number; maxAttempts?: number };
|
|
128
|
+
random?: () => number; sleep?: (milliseconds: number) => Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
export class ConnectionSupervisor {
|
|
131
|
+
constructor(options: ConnectionSupervisorOptions); start(): Promise<TransportDriver | null>; stop(): Promise<void>;
|
|
132
|
+
listen(callback: (event: unknown) => void): () => void; snapshot(): ConnectionSnapshot;
|
|
133
|
+
on(event: string, listener: (...args: any[]) => void): this; off(event: string, listener: (...args: any[]) => void): this;
|
|
134
|
+
}
|
|
135
|
+
export class EventDispatcher {
|
|
136
|
+
constructor(options?: { maxSeen?: number; ttlMs?: number; now?: () => number });
|
|
137
|
+
dispatch<T>(event: unknown, handler: (event: any) => T | Promise<T>): Promise<{ duplicate: boolean; result?: T } | { duplicate: true }>;
|
|
138
|
+
clear(): void;
|
|
139
|
+
}
|
|
140
|
+
export class CookieJar {
|
|
141
|
+
constructor(cookies?: Cookie[], options?: { now?: () => number }); setCookies(cookies: Cookie[]): this; deleteCookies(cookies: Array<{ key: string; domain: string; path: string }>): this;
|
|
142
|
+
getCookieHeader(inputUrl: string | URL): string; clear(): void; readonly size: number;
|
|
143
|
+
}
|
|
144
|
+
export function createClient(options: ClientOptions): {
|
|
145
|
+
login(credentials: Credentials, options?: Record<string, unknown>): Promise<ClientApi>;
|
|
146
|
+
logout(): Promise<void>; getConnectionState(): ConnectionSnapshot; getLicense(): VerifiedLicense | null;
|
|
147
|
+
};
|
|
148
|
+
export function createGoatBotLogin(client: ReturnType<typeof createClient>, accountConfigOptions?: AccountConfigOptions): {
|
|
149
|
+
(credentials: Record<string, unknown>, callback: (error: Error | null, api?: ClientApi | null) => void): Promise<ClientApi | null>;
|
|
150
|
+
(credentials: Record<string, unknown>, options: Record<string, unknown>, callback: (error: Error | null, api?: ClientApi | null) => void): Promise<ClientApi | null>;
|
|
151
|
+
};
|
|
152
|
+
export interface LegacyFcaProviderOptions {
|
|
153
|
+
login(input: Record<string, unknown>, options: Record<string, unknown>, callback: (error: Error | null, api?: any) => void): void;
|
|
154
|
+
options?: Record<string, unknown>; timeoutMs?: number;
|
|
155
|
+
}
|
|
156
|
+
/** Bridges an existing personal-account FCA login implementation; does not implement Facebook's private wire protocol. */
|
|
157
|
+
export function createLegacyFcaProvider(options: LegacyFcaProviderOptions): (context: {
|
|
158
|
+
mode: LoginMode; credentials: Cookie[]; options?: Record<string, unknown>;
|
|
159
|
+
}) => Promise<TransportDriver>;
|
|
160
|
+
export function normalizeCookies(input: Cookie[]): Cookie[];
|
|
161
|
+
export function validateSessionCookies(input: Cookie[]): Cookie[];
|
|
162
|
+
export function parseCookieHeader(header: string): Cookie[];
|
|
163
|
+
export function parseNetscapeCookies(text: string): Cookie[];
|
|
164
|
+
export function redactSecrets<T>(value: T): T;
|
|
165
|
+
export function classifySessionState(input: unknown): string;
|
|
166
|
+
export function describeError(error: unknown): string;
|
|
167
|
+
export function encryptSession(session: unknown, key: string | Uint8Array): Record<string, unknown>;
|
|
168
|
+
export function decryptSession(envelope: Record<string, unknown>, key: string | Uint8Array): unknown;
|
|
169
|
+
export function saveSession(filePath: string, session: unknown, key: string | Uint8Array): string;
|
|
170
|
+
export function loadSession(filePath: string, key: string | Uint8Array): unknown;
|
|
171
|
+
export function deleteSession(filePath: string): void;
|
|
172
|
+
export function createRequestClient(options?: Record<string, unknown>): (input: string | URL, options?: Record<string, unknown> & { retryable?: boolean }) => Promise<any>;
|
|
173
|
+
export function retryAfterMs(value: string | null, now?: number): number | null;
|
|
174
|
+
export function isRetryableStatus(status: number): boolean;
|
|
175
|
+
export function verifyLicenseToken(token: string, publicKey: string, options?: Record<string, unknown>): VerifiedLicense;
|
|
176
|
+
export interface LicenseProviderOptions {
|
|
177
|
+
backendUrl: string; licenseId: string; installationId: string; licenseKey: string; publicKey: string;
|
|
178
|
+
fetchImpl?: (...args: any[]) => Promise<any>;
|
|
179
|
+
}
|
|
180
|
+
export function createLicenseProvider(options: LicenseProviderOptions): () => Promise<string>;
|
|
181
|
+
export function validateTransportDriver(driver: TransportDriver): TransportDriver;
|
|
182
|
+
export function createTransportFactory(provider: (context: ConnectionContext) => Promise<TransportDriver> | TransportDriver): (context: ConnectionContext) => Promise<TransportDriver>;
|
|
183
|
+
export interface MetaMessengerTransportOptions {
|
|
184
|
+
pageAccessToken: string; pageId: string; apiVersion: string; appSecret?: string;
|
|
185
|
+
fetchImpl?: (...args: any[]) => Promise<any>; timeoutMs?: number;
|
|
186
|
+
}
|
|
187
|
+
export interface MetaMessengerTransport {
|
|
188
|
+
getCurrentUserID(): string;
|
|
189
|
+
sendMessage(recipientId: string, message: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
190
|
+
getUserInfo(userId: string, fields?: Array<"first_name" | "last_name" | "profile_pic" | "locale" | "timezone" | "gender">): Promise<Record<string, unknown>>;
|
|
191
|
+
getThreadList(limit?: number, after?: string): Promise<Record<string, unknown>>;
|
|
192
|
+
getThreadInfo(threadId: string): Promise<Record<string, unknown>>;
|
|
193
|
+
getThreadHistory(threadId: string, limit?: number, after?: string): Promise<Record<string, unknown>>;
|
|
194
|
+
getMessage(messageId: string): Promise<Record<string, unknown>>;
|
|
195
|
+
sendTypingIndicator(recipientId: string, typing?: boolean): Promise<Record<string, unknown>>;
|
|
196
|
+
markAsRead(recipientId: string): Promise<Record<string, unknown>>;
|
|
197
|
+
listen(callback: (error: Error | null, event?: MetaWebhookEvent) => void): () => void;
|
|
198
|
+
publishWebhook(rawBody: Uint8Array, signature: string): number; disconnect(): Promise<void>;
|
|
199
|
+
getCapabilities(): Readonly<Record<string, string | boolean>>;
|
|
200
|
+
}
|
|
201
|
+
export interface MetaWebhookEvent {
|
|
202
|
+
object: "page"; pageID: string; senderID: string | null; recipientID: string | null;
|
|
203
|
+
timestamp: number | null; type: "message" | "postback" | "delivery" | "read" | "account_linking" | "referral";
|
|
204
|
+
[key: string]: unknown;
|
|
205
|
+
}
|
|
206
|
+
export function createMetaMessengerTransport(options: MetaMessengerTransportOptions): MetaMessengerTransport;
|
|
207
|
+
export function normalizeWebhookPayload(payload: unknown): MetaWebhookEvent[];
|
|
208
|
+
export function verifyWebhookSignature(rawBody: Uint8Array, signature: string, appSecret: string): boolean;
|
|
209
|
+
export function verifyWebhookChallenge(query: Record<string, unknown>, verifyToken: string): string | null;
|
|
210
|
+
export interface ParsedVersion { major: number; minor: number; patch: number; prerelease: string; }
|
|
211
|
+
export function parseVersion(value: string): ParsedVersion;
|
|
212
|
+
export function compareVersions(left: string, right: string): number;
|
|
213
|
+
export interface VerifiedUpdateManifest {
|
|
214
|
+
product: string; version: string; channel: "stable" | "beta"; minNode: string;
|
|
215
|
+
issuedAt: number; expiresAt: number; releaseNotes: string;
|
|
216
|
+
artifact: Readonly<{ url: string; sha256: string }>; updateAvailable: boolean; isDowngrade: boolean;
|
|
217
|
+
}
|
|
218
|
+
export function verifyUpdateManifest(manifest: unknown, options?: Record<string, unknown>): VerifiedUpdateManifest;
|
|
219
|
+
export function verifyArtifactDigest(data: string | Uint8Array, digest: string): boolean;
|
|
220
|
+
/** Broker-agnostic MQTT 3.1/3.1.1 packet codec primitives. */
|
|
221
|
+
export const mqtt311Codec: {
|
|
222
|
+
readonly MAX_REMAINING_LENGTH: number;
|
|
223
|
+
encodeRemainingLength(value: number): Buffer;
|
|
224
|
+
decodeRemainingLength(buffer: Buffer, offset?: number): Readonly<{ value: number; bytes: number; offset: number }> | null;
|
|
225
|
+
encodeConnect(options: { clientId: string; keepAlive?: number; cleanSession?: boolean; username?: string; password?: Buffer | Uint8Array | string; protocolId?: "MQIsdp" | "MQTT"; protocolVersion?: 3 | 4 }): Buffer;
|
|
226
|
+
encodePublish(options: { topic: string; payload?: Buffer | Uint8Array | string; qos?: 0 | 1 | 2; retain?: boolean; dup?: boolean; packetId?: number }): Buffer;
|
|
227
|
+
encodeSubscribe(packetId: number, subscriptions: Array<{ topic: string; qos?: 0 | 1 | 2 }>): Buffer;
|
|
228
|
+
encodePacketId(type: "puback" | "pubrec" | "pubrel" | "pubcomp", packetId: number): Buffer;
|
|
229
|
+
encodeUnsubscribe(packetId: number, topics: string[]): Buffer;
|
|
230
|
+
encodePingReq(): Buffer;
|
|
231
|
+
encodeDisconnect(): Buffer;
|
|
232
|
+
decodePacket(buffer: Buffer | Uint8Array, options?: { maxPacketBytes?: number }): Readonly<Record<string, unknown>> | null;
|
|
233
|
+
};
|
|
234
|
+
export interface Mqtt311StreamDecoder {
|
|
235
|
+
push(chunk: Buffer | Uint8Array | ArrayBuffer): Array<Readonly<Record<string, unknown>>>;
|
|
236
|
+
reset(): void;
|
|
237
|
+
close(): void;
|
|
238
|
+
readonly bufferedBytes: number;
|
|
239
|
+
readonly closed: boolean;
|
|
240
|
+
}
|
|
241
|
+
export function createMqtt311StreamDecoder(options?: { maxPacketBytes?: number; maxBufferedBytes?: number }): Mqtt311StreamDecoder;
|
|
242
|
+
export interface NativeRealtimeSocket {
|
|
243
|
+
readyState?: number;
|
|
244
|
+
send(data: string | Buffer | Uint8Array | ArrayBuffer, callback?: (error?: Error) => void): void;
|
|
245
|
+
close?(): void;
|
|
246
|
+
on?(event: string, listener: (...args: any[]) => void): unknown;
|
|
247
|
+
off?(event: string, listener: (...args: any[]) => void): unknown;
|
|
248
|
+
removeListener?(event: string, listener: (...args: any[]) => void): unknown;
|
|
249
|
+
addEventListener?(event: string, listener: (event: any) => void): unknown;
|
|
250
|
+
removeEventListener?(event: string, listener: (event: any) => void): unknown;
|
|
251
|
+
}
|
|
252
|
+
export interface NativeRealtimeProtocolAdapter {
|
|
253
|
+
authenticate(socket: NativeRealtimeSocket, context: Record<string, unknown>): void | Promise<void>;
|
|
254
|
+
subscribe(socket: NativeRealtimeSocket, context: Record<string, unknown>): void | Promise<void>;
|
|
255
|
+
decodeFrame(frame: unknown, options: { isBinary: boolean; maxFrameBytes: number }): { events: unknown[] } | unknown[];
|
|
256
|
+
encodeAction(action: unknown): string | Buffer | Uint8Array | ArrayBuffer | Promise<string | Buffer | Uint8Array | ArrayBuffer>;
|
|
257
|
+
}
|
|
258
|
+
export interface NativeRealtimeTransportOptions {
|
|
259
|
+
/** Must be a verified wss:// endpoint; no Facebook endpoint is bundled. */
|
|
260
|
+
url: string;
|
|
261
|
+
socketFactory(input: { url: string; protocols?: string | string[]; headers?: Record<string, string>; signal?: AbortSignal }): NativeRealtimeSocket | Promise<NativeRealtimeSocket>;
|
|
262
|
+
protocol: NativeRealtimeProtocolAdapter;
|
|
263
|
+
protocols?: string | string[];
|
|
264
|
+
headers?: Record<string, string>;
|
|
265
|
+
connectTimeoutMs?: number;
|
|
266
|
+
closeTimeoutMs?: number;
|
|
267
|
+
protocolSetupTimeoutMs?: number;
|
|
268
|
+
maxFrameBytes?: number;
|
|
269
|
+
onDiagnostic?: (event: Readonly<Record<string, unknown>>) => void;
|
|
270
|
+
}
|
|
271
|
+
export interface NativeRealtimeTransport {
|
|
272
|
+
connect(context?: Partial<ConnectionContext>): Promise<TransportDriver & { sendAction(action: unknown): Promise<{ sent: true }>; getConnectionState(): ConnectionSnapshot }>;
|
|
273
|
+
disconnect(): Promise<void>;
|
|
274
|
+
getDriver(): (TransportDriver & { sendAction(action: unknown): Promise<{ sent: true }>; getConnectionState(): ConnectionSnapshot });
|
|
275
|
+
snapshot(): ConnectionSnapshot;
|
|
276
|
+
on(event: string, callback: (...args: any[]) => void): () => void;
|
|
277
|
+
}
|
|
278
|
+
export const DEFAULT_CONNECT_TIMEOUT_MS: number;
|
|
279
|
+
export const DEFAULT_CLOSE_TIMEOUT_MS: number;
|
|
280
|
+
export const DEFAULT_PROTOCOL_SETUP_TIMEOUT_MS: number;
|
|
281
|
+
/**
|
|
282
|
+
* Protocol-neutral WebSocket runtime. A separately verified adapter must supply
|
|
283
|
+
* Facebook-specific authentication, subscriptions, decoding and action encoding.
|
|
284
|
+
*/
|
|
285
|
+
export function createNativeRealtimeTransport(options: NativeRealtimeTransportOptions): NativeRealtimeTransport;
|
|
286
|
+
export interface DecodedRealtimeEvent { readonly name: string; readonly args: unknown | null; }
|
|
287
|
+
export interface DecodedRealtimeFrame { readonly envelope: Readonly<Record<string, unknown>>; readonly events: readonly DecodedRealtimeEvent[]; }
|
|
288
|
+
export interface RealtimeFrameSummary { readonly eventCount: number; readonly eventNames: readonly string[]; }
|
|
289
|
+
export const DEFAULT_MAX_FRAME_BYTES: number;
|
|
290
|
+
/** Extracts an observed JSON events envelope from a bounded binary frame; does not implement the Messenger wire protocol. */
|
|
291
|
+
export function decodeRealtimeFrame(frame: Buffer | Uint8Array, options?: { maxFrameBytes?: number }): DecodedRealtimeFrame;
|
|
292
|
+
/** Returns event names/count only, omitting event argument values. */
|
|
293
|
+
export function summarizeRealtimeFrame(frame: Buffer | Uint8Array, options?: { maxFrameBytes?: number }): RealtimeFrameSummary;
|
|
294
|
+
export interface RealtimeBinaryPayloadSummary {
|
|
295
|
+
readonly envelopeKind: "payload" | "events"; readonly requestIdPresent: boolean;
|
|
296
|
+
readonly payloadEncoding: "non-string" | "non-base64-string" | "base64-binary-unclassified" | "protobuf-wire-compatible" | "base64-json";
|
|
297
|
+
readonly payloadBytes: number | null;
|
|
298
|
+
readonly wireFields: readonly Readonly<{ number: number; wireType: number; byteLength: number | null }>[];
|
|
299
|
+
}
|
|
300
|
+
export const DEFAULT_MAX_BINARY_PAYLOAD_BYTES: number;
|
|
301
|
+
/** Inspects only bounded outer-envelope/Base64 structure and protobuf-wire-compatible field boundaries; never returns payload values. */
|
|
302
|
+
export function inspectRealtimeBinaryPayload(frame: Buffer | Uint8Array, options?: { maxFrameBytes?: number; maxPayloadBytes?: number }): RealtimeBinaryPayloadSummary;
|
|
303
|
+
export const version: string;
|
|
304
|
+
|
|
305
|
+
export interface AccountConfigOptions { cwd?: string; accountFile?: string; configFile?: string; appStateFile?: string | null; env?: NodeJS.ProcessEnv; }
|
|
306
|
+
export type LoadedAccountConfig = { mode: "appstate"; appState: Cookie[]; source: "account.txt" | "appstate.json" };
|
|
307
|
+
export function parseAccountText(text: string): Cookie[];
|
|
308
|
+
export function generateTotp(secret: string, options?: { digits?: number; period?: number; algorithm?: "sha1" | "sha256" | "sha512"; timestamp?: number }): string;
|
|
309
|
+
/** Reads cookie-only account.txt first, then appstate.json. Credential configuration is not loaded in the AppState-only phase. */
|
|
310
|
+
export function loadAccountConfig(options?: AccountConfigOptions): LoadedAccountConfig;
|
|
311
|
+
|
|
312
|
+
export interface RealtimeSyncEnvelope {
|
|
313
|
+
readonly appId: string;
|
|
314
|
+
readonly requestId: number;
|
|
315
|
+
readonly type: number;
|
|
316
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
317
|
+
}
|
|
318
|
+
/** Inspects the observed JSON sync envelope without interpreting the undocumented binary prefix. */
|
|
319
|
+
export function inspectRealtimeSyncEnvelope(frame: Buffer | Uint8Array, options?: { maxFrameBytes?: number }): RealtimeSyncEnvelope;
|
|
320
|
+
export const DEFAULT_MAX_SYNC_FRAME_BYTES: number;
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
/** Facebook web realtime notification/presence gateway; not Messenger message sync. */
|
|
324
|
+
export const DEFAULT_GATEWAY_URL: string;
|
|
325
|
+
export const DEFAULT_APP_ID: string;
|
|
326
|
+
export const FACEBOOK_GATEWAY_SUBSCRIPTIONS: readonly string[];
|
|
327
|
+
export function encodeGatewaySubscription(payload: string, index: number): Buffer;
|
|
328
|
+
export function decodeGatewayFrame(frame: string | Buffer | Uint8Array | ArrayBuffer, options?: { maxFrameBytes?: number }): { events: unknown[] };
|
|
329
|
+
export interface FacebookGatewayProtocolOptions {
|
|
330
|
+
userId: string | number;
|
|
331
|
+
deviceId?: string;
|
|
332
|
+
appId?: string;
|
|
333
|
+
url?: string;
|
|
334
|
+
userAgent?: string;
|
|
335
|
+
cookie?: string;
|
|
336
|
+
subscriptions?: readonly string[];
|
|
337
|
+
}
|
|
338
|
+
export interface FacebookGatewayProtocolConfig {
|
|
339
|
+
url: string;
|
|
340
|
+
headers: Readonly<Record<string, string>>;
|
|
341
|
+
protocol: NativeRealtimeProtocolAdapter;
|
|
342
|
+
}
|
|
343
|
+
export function createFacebookGatewayProtocol(options: FacebookGatewayProtocolOptions): FacebookGatewayProtocolConfig;
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
/** Unofficial Facebook Messenger MQTT 3.1 adapter based on public FCA protocol observations. */
|
|
347
|
+
export const DEFAULT_MQTT_URL: string;
|
|
348
|
+
export const DEFAULT_MQTT_APP_ID: string;
|
|
349
|
+
export const DEFAULT_MQTT_TOPICS: readonly string[];
|
|
350
|
+
export interface FacebookMqttProtocolOptions {
|
|
351
|
+
userId: string | number; clientId?: string; sessionId?: number; deviceId?: string;
|
|
352
|
+
appId?: string; url?: string; region?: string; userAgent?: string; cookie?: string;
|
|
353
|
+
online?: boolean; keepAlive?: number; topics?: readonly string[];
|
|
354
|
+
syncToken?: string; lastSeqId?: string | number | null; syncCursorStore?: MessengerSyncCursorStore; onSyncCursor?: (cursor: MessengerSyncCursor) => void; requestTimeoutMs?: number; maxPendingRequests?: number;
|
|
355
|
+
}
|
|
356
|
+
export interface FacebookMqttProtocolConfig {
|
|
357
|
+
url: string; headers: Readonly<Record<string, string>>;
|
|
358
|
+
session: Readonly<{ userId: string; clientId: string; sessionId: number; deviceId: string; appId: string }>;
|
|
359
|
+
protocol: NativeRealtimeProtocolAdapter;
|
|
360
|
+
}
|
|
361
|
+
export function createFacebookMqttProtocol(options: FacebookMqttProtocolOptions): FacebookMqttProtocolConfig;
|
|
362
|
+
|
|
363
|
+
export interface MessengerSyncCursor { syncToken: string | null; lastSeqId: string | number | null; }
|
|
364
|
+
export interface MessengerSyncParseResult { events: ReadonlyArray<Record<string, unknown>>; envelope: unknown; cursor: MessengerSyncCursor | null; }
|
|
365
|
+
/** Parses known Messenger sync delta envelopes conservatively. */
|
|
366
|
+
export function parseMessengerSyncPayload(input: unknown): MessengerSyncParseResult;
|
|
367
|
+
export function normalizeMessengerDelta(delta: unknown): Record<string, unknown> | null;
|
|
368
|
+
|
|
369
|
+
export interface MqttRequestTracker { allocateId(): number; track(requestId: string | number, timeoutMs?: number): Promise<unknown>; resolve(response: unknown): boolean; rejectAll(reason?: unknown): void; readonly pendingCount: number; }
|
|
370
|
+
export function createMqttRequestTracker(options?: { timeoutMs?: number; maxPending?: number; initialRequestId?: number }): MqttRequestTracker;
|
|
371
|
+
|
|
372
|
+
export const MESSENGER_MQTT_APP_ID: string;
|
|
373
|
+
export const SEND_MESSAGE_VERSION_ID: string;
|
|
374
|
+
export function offlineThreadingId(now?: number, random?: number): string;
|
|
375
|
+
export function createMessengerSendMessageRequest(input: { threadID: string | number; message: string | { body?: string; sticker?: string | number }; replyToMessageID?: string | number; timestamp?: number; otid?: string; epochId?: string; requestId?: number }): Readonly<{ app_id: string; payload: string; request_id: number | null; type: 3 }>;
|
|
376
|
+
|
|
377
|
+
export interface MessengerSyncCursorStore { load(): MessengerSyncCursor | null; save(cursor: MessengerSyncCursor): MessengerSyncCursor; clear(): void; readonly current: MessengerSyncCursor | null; }
|
|
378
|
+
export function createMessengerSyncCursorStore(options: { filePath: string; key: string | Buffer | Uint8Array; userId: string | number }): MessengerSyncCursorStore;
|
|
379
|
+
|
|
380
|
+
export interface FacebookMqttDriverOptions extends Omit<PersonalSessionOptions, "appState"> { appState: Cookie[]; socketFactory(options: { url: string; protocols?: string | string[]; headers?: Record<string, string>; signal: AbortSignal }): unknown | Promise<unknown>; connectTimeoutMs?: number; closeTimeoutMs?: number; protocolSetupTimeoutMs?: number; maxFrameBytes?: number; syncCursorStore?: MessengerSyncCursorStore; onSyncCursor?: (cursor: MessengerSyncCursor) => void; requestTimeoutMs?: number; maxPendingRequests?: number; mqtt?: Record<string, unknown>; }
|
|
381
|
+
export function createFacebookMqttDriver(options: FacebookMqttDriverOptions): Promise<TransportDriver & { getCurrentUserID(): string; getSessionState(): "active"; sendRequest(payload: Record<string, unknown>, options?: { timeoutMs?: number }): Promise<unknown>; sendMessage(input: { threadID: string | number; message: string | { body?: string; sticker?: string | number }; replyToMessageID?: string | number }, options?: { timeoutMs?: number }): Promise<unknown>; disconnect(): Promise<void>; }>;
|
|
382
|
+
export interface MessengerSyncCursor { syncToken: string | null; lastSeqId: string | number | null; }
|
|
383
|
+
|
|
384
|
+
/** Creates the native AppState-only personal Messenger client; caller supplies WebSocket implementation. */
|
|
385
|
+
export interface FacebookMqttClientOptions extends Omit<FacebookMqttDriverOptions, "appState"> {
|
|
386
|
+
reconnect?: { minDelayMs?: number; maxDelayMs?: number; factor?: number; jitter?: number; maxAttempts?: number };
|
|
387
|
+
license?: LicenseOptions;
|
|
388
|
+
requireLicense?: boolean;
|
|
389
|
+
onLicenseError?: (error: Error) => void;
|
|
390
|
+
}
|
|
391
|
+
export function createFacebookMqttClient(options: FacebookMqttClientOptions): ReturnType<typeof createClient>;
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
/** Personal-account thread and group actions following public FCA web request conventions. */
|
|
395
|
+
export interface FacebookThreadApi {
|
|
396
|
+
getThreadList(limit: number, timestamp?: number | null, tags?: string[] | ((error: Error | null, result?: unknown[]) => void), callback?: (error: Error | null, result?: unknown[]) => void): Promise<unknown[]> | void;
|
|
397
|
+
getThreadInfo(threadID: string | number, callback?: (error: Error | null, result?: unknown) => void): Promise<unknown> | void;
|
|
398
|
+
getThreadHistory(threadID: string | number, amount: number, timestamp?: number | null, callback?: (error: Error | null, result?: unknown[]) => void): Promise<unknown[]> | void;
|
|
399
|
+
getUserInfo(ids: string | number | Array<string | number>, callback?: (error: Error | null, result?: Record<string, unknown>) => void): Promise<Record<string, unknown>> | void;
|
|
400
|
+
addUserToGroup(userIDs: string | number | Array<string | number>, threadID: string | number, callback?: (error?: Error | null) => void): Promise<unknown> | void;
|
|
401
|
+
removeUserFromGroup(userID: string | number, threadID: string | number, callback?: (error?: Error | null) => void): Promise<unknown> | void;
|
|
402
|
+
changeNickname(nickname: string, threadID: string | number, participantID: string | number, callback?: (error?: Error | null) => void): Promise<unknown> | void;
|
|
403
|
+
setMessageReaction(reaction: string, messageID: string, callback?: (error?: Error | null) => void): Promise<unknown> | void;
|
|
404
|
+
markAsRead(threadID: string | number, read?: boolean | ((error?: Error | null) => void), callback?: (error?: Error | null) => void): Promise<unknown> | void;
|
|
405
|
+
}
|
|
406
|
+
export const FACEBOOK_THREAD_DOC_IDS: Readonly<{ threadList: string; threadInfo: string; threadHistory: string; reaction: string }>;
|
|
407
|
+
export function createFacebookThreadApi(options: { session: PersonalSession; webClient?: FacebookWebClient }): FacebookThreadApi;
|
package/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { normalizeCookies, validateSessionCookies, parseCookieHeader, parseNetscapeCookies } = require("./src/security/cookies");
|
|
4
|
+
const { redactSecrets } = require("./src/security/redact");
|
|
5
|
+
const { createDiagnosticRecorder } = require("./src/security/diagnostics");
|
|
6
|
+
const { classifySessionState, describeError } = require("./src/security/sessionState");
|
|
7
|
+
const { encryptSession, decryptSession } = require("./src/security/sessionCrypto");
|
|
8
|
+
const { saveSession, loadSession, deleteSession } = require("./src/security/sessionStore");
|
|
9
|
+
const { ConnectionSupervisor } = require("./src/runtime/connection");
|
|
10
|
+
const { EventDispatcher } = require("./src/events/dispatcher");
|
|
11
|
+
const { CookieJar } = require("./src/network/cookieJar");
|
|
12
|
+
const { createRequestClient, retryAfterMs, isRetryableStatus } = require("./src/network/requestClient");
|
|
13
|
+
const { createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens, extractRealtimeConfig } = require("./src/auth/personalSession");
|
|
14
|
+
const { createAuthenticationAttempt, AUTHENTICATION_ATTEMPT_STATES } = require("./src/auth/authenticationAttempt");
|
|
15
|
+
const { parseAccountText, loadAccountConfig } = require("./src/auth/accountConfig");
|
|
16
|
+
const { generateTotp } = require("./src/auth/totp");
|
|
17
|
+
const { normalizeFacebookResponse, stripFacebookJsonPrefix, createFacebookError } = require("./src/auth/facebookResponse");
|
|
18
|
+
const { createFacebookWebClient, assertFacebookUrl, toFormBody } = require("./src/auth/facebookWebClient");
|
|
19
|
+
const { createClient } = require("./src/api/client");
|
|
20
|
+
const { createGoatBotLogin } = require("./src/compat/goatbotLogin");
|
|
21
|
+
const { createFacebookMqttClient } = require("./src/compat/facebookMqttClient");
|
|
22
|
+
const { createLegacyFcaProvider } = require("./src/compat/legacyFcaTransport");
|
|
23
|
+
const { verifyLicenseToken } = require("./src/license/verify");
|
|
24
|
+
const { createLicenseProvider } = require("./src/license/provider");
|
|
25
|
+
const { validateTransportDriver, createTransportFactory } = require("./src/transport/contract");
|
|
26
|
+
const { createMetaMessengerTransport, normalizeWebhookPayload, verifyWebhookSignature, verifyWebhookChallenge } = require("./src/transport/metaMessenger");
|
|
27
|
+
const { decodeRealtimeFrame, summarizeRealtimeFrame, DEFAULT_MAX_FRAME_BYTES } = require("./src/transport/realtimeFrameDecoder");
|
|
28
|
+
const { inspectRealtimeBinaryPayload, DEFAULT_MAX_BINARY_PAYLOAD_BYTES } = require("./src/transport/binaryPayloadInspector");
|
|
29
|
+
const { inspectRealtimeSyncEnvelope, DEFAULT_MAX_SYNC_FRAME_BYTES } = require("./src/transport/realtimeSyncEnvelope");
|
|
30
|
+
const { createNativeRealtimeTransport, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_CLOSE_TIMEOUT_MS, DEFAULT_PROTOCOL_SETUP_TIMEOUT_MS } = require("./src/transport/nativeRealtimeTransport");
|
|
31
|
+
const { DEFAULT_GATEWAY_URL, DEFAULT_APP_ID, FACEBOOK_GATEWAY_SUBSCRIPTIONS, encodeGatewaySubscription, decodeGatewayFrame, createFacebookGatewayProtocol } = require("./src/transport/facebookGatewayProtocol");
|
|
32
|
+
const mqtt311Codec = require("./src/transport/mqtt311Codec");
|
|
33
|
+
const { createMqtt311StreamDecoder } = require("./src/transport/mqtt311StreamDecoder");
|
|
34
|
+
const { createMqttRequestTracker } = require("./src/transport/mqttRequestTracker");
|
|
35
|
+
const { MESSENGER_MQTT_APP_ID, SEND_MESSAGE_VERSION_ID, offlineThreadingId, createMessengerSendMessageRequest } = require("./src/transport/messengerActions");
|
|
36
|
+
const { DEFAULT_MQTT_URL, DEFAULT_MQTT_APP_ID, DEFAULT_MQTT_TOPICS, createFacebookMqttProtocol } = require("./src/transport/facebookMqttProtocol");
|
|
37
|
+
const { parseMessengerSyncPayload, normalizeMessengerDelta } = require("./src/transport/facebookMqttEvents");
|
|
38
|
+
const { createMessengerSyncCursorStore } = require("./src/transport/messengerSyncCursorStore");
|
|
39
|
+
const { createFacebookMqttDriver } = require("./src/transport/facebookMqttDriver");
|
|
40
|
+
const { createFacebookThreadApi, DOC_IDS: FACEBOOK_THREAD_DOC_IDS } = require("./src/transport/facebookThreadApi");
|
|
41
|
+
const { parseVersion, compareVersions, verifyUpdateManifest, verifyArtifactDigest } = require("./src/update/manifest");
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
normalizeCookies, validateSessionCookies, parseCookieHeader, parseNetscapeCookies,
|
|
45
|
+
redactSecrets, createDiagnosticRecorder, classifySessionState, describeError, encryptSession, decryptSession,
|
|
46
|
+
saveSession, loadSession, deleteSession, ConnectionSupervisor, EventDispatcher,
|
|
47
|
+
CookieJar, createRequestClient, retryAfterMs, isRetryableStatus, createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens, extractRealtimeConfig,
|
|
48
|
+
createAuthenticationAttempt, AUTHENTICATION_ATTEMPT_STATES,
|
|
49
|
+
parseAccountText, loadAccountConfig, generateTotp,
|
|
50
|
+
normalizeFacebookResponse, stripFacebookJsonPrefix, createFacebookError,
|
|
51
|
+
createFacebookWebClient, assertFacebookUrl, toFormBody, createClient,
|
|
52
|
+
createGoatBotLogin, createFacebookMqttClient, createLegacyFcaProvider, verifyLicenseToken, createLicenseProvider,
|
|
53
|
+
validateTransportDriver, createTransportFactory, createMetaMessengerTransport,
|
|
54
|
+
normalizeWebhookPayload, verifyWebhookSignature, verifyWebhookChallenge,
|
|
55
|
+
decodeRealtimeFrame, summarizeRealtimeFrame, DEFAULT_MAX_FRAME_BYTES,
|
|
56
|
+
inspectRealtimeBinaryPayload, DEFAULT_MAX_BINARY_PAYLOAD_BYTES,
|
|
57
|
+
inspectRealtimeSyncEnvelope, DEFAULT_MAX_SYNC_FRAME_BYTES,
|
|
58
|
+
createNativeRealtimeTransport, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_CLOSE_TIMEOUT_MS, DEFAULT_PROTOCOL_SETUP_TIMEOUT_MS,
|
|
59
|
+
DEFAULT_GATEWAY_URL, DEFAULT_APP_ID, FACEBOOK_GATEWAY_SUBSCRIPTIONS, encodeGatewaySubscription, decodeGatewayFrame, createFacebookGatewayProtocol, mqtt311Codec, createMqtt311StreamDecoder, createMqttRequestTracker, MESSENGER_MQTT_APP_ID, SEND_MESSAGE_VERSION_ID, offlineThreadingId, createMessengerSendMessageRequest, DEFAULT_MQTT_URL, DEFAULT_MQTT_APP_ID, DEFAULT_MQTT_TOPICS, createFacebookMqttProtocol, parseMessengerSyncPayload, normalizeMessengerDelta, createMessengerSyncCursorStore, createFacebookMqttDriver, createFacebookThreadApi, FACEBOOK_THREAD_DOC_IDS,
|
|
60
|
+
parseVersion, compareVersions, verifyUpdateManifest, verifyArtifactDigest,
|
|
61
|
+
version: require("./package.json").version
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirzon-islam/omega-fca",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "OmegA Bot Facebook integration library, developed and maintained by NirZon",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test",
|
|
12
|
+
"test:syntax": "node -e \"const fs=require('node:fs');const path=require('node:path');const cp=require('node:child_process');const walk=d=>fs.readdirSync(d,{withFileTypes:true}).flatMap(e=>e.isDirectory()?walk(path.join(d,e.name)):[path.join(d,e.name)]);for(const f of ['index.js',...walk('src'),...walk('test'),...walk('examples'),...walk('tools')].filter(f=>f.endsWith('.js'))){const r=cp.spawnSync(process.execPath,['--check',f],{stdio:'inherit'});if(r.status!==0)process.exit(r.status||1)}\"",
|
|
13
|
+
"prepublishOnly": "npm test && npm run test:syntax",
|
|
14
|
+
"test:appstate": "node examples/appstate-session-check.js",
|
|
15
|
+
"capture:browser": "node tools/browser-capture.js"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"facebook",
|
|
20
|
+
"messenger",
|
|
21
|
+
"fca",
|
|
22
|
+
"nodejs",
|
|
23
|
+
"omega"
|
|
24
|
+
],
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"index.js",
|
|
28
|
+
"index.d.ts",
|
|
29
|
+
"src/",
|
|
30
|
+
"examples/",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"docs/META-MESSENGER-TRANSPORT.md",
|
|
34
|
+
"docs/FACEBOOK-MQTT-TRANSPORT.md",
|
|
35
|
+
"docs/DEPLOYMENT.md",
|
|
36
|
+
"docs/PROTOCOL-EVIDENCE.md",
|
|
37
|
+
"docs/AUTHENTICATION-ATTEMPT.md",
|
|
38
|
+
"docs/IMPLEMENTATION-STATUS.md",
|
|
39
|
+
"docs/ARCHITECTURE.md",
|
|
40
|
+
"docs/GOATBOT-COMPATIBILITY-MATRIX.md",
|
|
41
|
+
"docs/GOATBOT-INTEGRATION-AUDIT.md",
|
|
42
|
+
"docs/REFERENCE-AUDIT.md",
|
|
43
|
+
"docs/NTKHANG-REFERENCE-STUDY.md",
|
|
44
|
+
"docs/SAFE-DIAGNOSTICS.md",
|
|
45
|
+
"docs/REALTIME-FRAME-EVIDENCE.md",
|
|
46
|
+
"docs/NESTED-REALTIME-PAYLOAD.md",
|
|
47
|
+
"tools/",
|
|
48
|
+
"docs/BROWSER-CAPTURE.md"
|
|
49
|
+
],
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./index.d.ts",
|
|
53
|
+
"require": "./index.js",
|
|
54
|
+
"default": "./index.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"author": "NirZon",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"ws": "^8.18.3"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"registry": "https://registry.npmjs.org/",
|
|
63
|
+
"access": "public"
|
|
64
|
+
}
|
|
65
|
+
}
|