@lazyneoaz/metachat 4.0.4 → 4.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1649 -299
- package/dist/index.d.mts +397 -1
- package/dist/index.d.ts +397 -1
- package/dist/index.mjs +1610 -300
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
import { ReadStream } from 'fs';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Single source of truth for browser and device identity.
|
|
6
|
+
*
|
|
7
|
+
* Facebook cross-checks the User-Agent against the Client Hints it receives
|
|
8
|
+
* (`sec-ch-ua*`), the `navigator`-derived values it can infer from request
|
|
9
|
+
* shape (platform, viewport, timezone, locale), and the `a` field on the MQTT
|
|
10
|
+
* username. Every one of those must describe the *same* device, so they are all
|
|
11
|
+
* derived from one profile here instead of being hardcoded across files.
|
|
12
|
+
*/
|
|
13
|
+
interface BrowserProfile {
|
|
14
|
+
/** Full navigator.userAgent string. */
|
|
15
|
+
userAgent: string;
|
|
16
|
+
/** Value for the `sec-ch-ua` header. */
|
|
17
|
+
secChUa: string;
|
|
18
|
+
/** Value for the `sec-ch-ua-full-version-list` header. */
|
|
19
|
+
secChUaFullVersionList: string;
|
|
20
|
+
/** Value for the `sec-ch-ua-platform` header (quoted). */
|
|
21
|
+
secChUaPlatform: string;
|
|
22
|
+
/** Value for the `sec-ch-ua-platform-version` header (quoted). */
|
|
23
|
+
secChUaPlatformVersion: string;
|
|
24
|
+
/** Value for `sec-ch-ua-arch` (quoted, only meaningful on desktop). */
|
|
25
|
+
secChUaArch: string;
|
|
26
|
+
/** Value for `sec-ch-ua-bitness` (quoted). */
|
|
27
|
+
secChUaBitness: string;
|
|
28
|
+
/** Value for `sec-ch-ua-model` (`""` on desktop). */
|
|
29
|
+
secChUaModel: string;
|
|
30
|
+
/** Value for `sec-ch-ua-wow64` (`?1` only on Windows x64 emulation). */
|
|
31
|
+
secChUaWow64: string;
|
|
32
|
+
/** Value for `sec-ch-ua-form-factors` (quoted brand list). */
|
|
33
|
+
secChUaFormFactors: string;
|
|
34
|
+
/** Value for `sec-ch-ua-mobile`. */
|
|
35
|
+
secChUaMobile: string;
|
|
36
|
+
/** Value for `Accept-Language`. */
|
|
37
|
+
acceptLanguage: string;
|
|
38
|
+
/** Primary language tag, e.g. `en-US`. */
|
|
39
|
+
language: string;
|
|
40
|
+
/** IANA timezone the session claims, e.g. `Europe/London`. */
|
|
41
|
+
timezone: string;
|
|
42
|
+
/** Device screen geometry, used to keep a stable `dpr`/viewport identity. */
|
|
43
|
+
screen: {
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
availWidth: number;
|
|
47
|
+
availHeight: number;
|
|
48
|
+
colorDepth: number;
|
|
49
|
+
pixelDepth: number;
|
|
50
|
+
};
|
|
51
|
+
/** Device DPR for the `dpr` request parameter. */
|
|
52
|
+
devicePixelRatio: number;
|
|
53
|
+
/** navigator.hardwareConcurrency. */
|
|
54
|
+
hardwareConcurrency: number;
|
|
55
|
+
/** navigator.deviceMemory (GB). */
|
|
56
|
+
deviceMemory: number;
|
|
57
|
+
/** Stable, per-profile name surfaced in logs/debug. */
|
|
58
|
+
label: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Deterministic default profile. Using a fixed identity avoids the "every
|
|
62
|
+
* request a different browser" smell while still being configurable through
|
|
63
|
+
* `login({ userAgent })` / `login({ randomUserAgent: true })`.
|
|
64
|
+
*/
|
|
65
|
+
declare const defaultBrowserProfile: BrowserProfile;
|
|
66
|
+
/**
|
|
67
|
+
* Produce a coherent random browser profile. The UA and every Client Hint are
|
|
68
|
+
* generated from the same (major, platform) pair, so they can never disagree.
|
|
69
|
+
*/
|
|
70
|
+
declare function randomUserAgent(): BrowserProfile;
|
|
71
|
+
/**
|
|
72
|
+
* Fold a caller-supplied partial identity into a complete, coherent profile.
|
|
73
|
+
* Used when `login({ userAgent })` is given a bare string: the UA is honored
|
|
74
|
+
* but every dependent hint is recomputed from it so the pair cannot disagree.
|
|
75
|
+
*/
|
|
76
|
+
declare function normalizeBrowserProfile(input?: Partial<BrowserProfile> & Record<string, any>): BrowserProfile;
|
|
77
|
+
|
|
4
78
|
interface LoginOptions$1 {
|
|
5
79
|
online?: boolean;
|
|
6
80
|
selfListen?: boolean;
|
|
@@ -14,11 +88,17 @@ interface LoginOptions$1 {
|
|
|
14
88
|
proxy?: string;
|
|
15
89
|
autoReconnect?: boolean;
|
|
16
90
|
userAgent?: string;
|
|
91
|
+
/** Full browser identity (UA + Client Hints). Resolved once at login. */
|
|
92
|
+
browser?: BrowserProfile;
|
|
17
93
|
emitReady?: boolean;
|
|
18
94
|
randomUserAgent?: boolean;
|
|
19
95
|
bypassRegion?: string;
|
|
20
96
|
advancedProtection?: boolean;
|
|
21
97
|
autoRotateSession?: boolean;
|
|
98
|
+
/** Visit the natural browser surfaces (home, inbox) before first use. */
|
|
99
|
+
warmUp?: boolean;
|
|
100
|
+
/** Alternate foreground/background on a human rhythm to avoid detection. */
|
|
101
|
+
liveness?: boolean;
|
|
22
102
|
logging?: boolean;
|
|
23
103
|
pageID?: string;
|
|
24
104
|
[key: string]: any;
|
|
@@ -542,6 +622,322 @@ declare namespace publicTypes {
|
|
|
542
622
|
export { type publicTypes_API as API, type publicTypes_AddedStickerPackInfo as AddedStickerPackInfo, type publicTypes_AiTheme as AiTheme, type publicTypes_AnyAttachment as AnyAttachment, type publicTypes_Attachment as Attachment, type publicTypes_AudioAttachment as AudioAttachment, type publicTypes_Callback as Callback, type publicTypes_CommentMessage as CommentMessage, type publicTypes_CommentResult as CommentResult, type publicTypes_Coordinates as Coordinates, type publicTypes_EmojiEvent as EmojiEvent, type publicTypes_Event as Event, type publicTypes_FileAttachment as FileAttachment, type publicTypes_GroupNameEvent as GroupNameEvent, type publicTypes_ListenEvent as ListenEvent, type publicTypes_LoginCredentials as LoginCredentials, type publicTypes_LoginOptions as LoginOptions, type publicTypes_Mention as Mention, type publicTypes_Message as Message, type publicTypes_MessageID as MessageID, type publicTypes_MessageObject as MessageObject, type publicTypes_MessageReply as MessageReply, type publicTypes_MusicTag as MusicTag, type publicTypes_MusicTrack as MusicTrack, type publicTypes_NicknameEvent as NicknameEvent, type publicTypes_PhotoAttachment as PhotoAttachment, type publicTypes_Reaction as Reaction, type publicTypes_SearchMusicOptions as SearchMusicOptions, type publicTypes_SearchMusicResult as SearchMusicResult, type publicTypes_ShareAttachment as ShareAttachment, type publicTypes_ShareResult as ShareResult, type publicTypes_StickerAttachment as StickerAttachment, type publicTypes_StickerInfo as StickerInfo, type publicTypes_StickerPackInfo as StickerPackInfo, type publicTypes_ThreadID as ThreadID, type publicTypes_ThreadInfo as ThreadInfo, type publicTypes_ThreadThemeEvent as ThreadThemeEvent, type publicTypes_TypingIndicator as TypingIndicator, type publicTypes_UnsendMessageEvent as UnsendMessageEvent, type publicTypes_UserID as UserID, type publicTypes_UserInfo as UserInfo, type publicTypes_VideoAttachment as VideoAttachment, publicTypes_login as login };
|
|
543
623
|
}
|
|
544
624
|
|
|
625
|
+
/**
|
|
626
|
+
* Resolve the browser profile for a request. Precedence:
|
|
627
|
+
* 1. an explicitly supplied profile on the options object
|
|
628
|
+
* 2. the session profile resolved once at login (`globalOptions.browser`)
|
|
629
|
+
* 3. the library default
|
|
630
|
+
*
|
|
631
|
+
* Individual `sec-ch-ua*` overrides on `options` are honored so a caller can
|
|
632
|
+
* pin a specific browser without breaking the UA/CH parity contract.
|
|
633
|
+
*/
|
|
634
|
+
declare function resolveProfile(options?: Record<string, any>): BrowserProfile;
|
|
635
|
+
declare function getHeaders(url: string, options?: Record<string, any>, ctx?: Record<string, any>, customHeader?: Record<string, any>): Record<string, string>;
|
|
636
|
+
/**
|
|
637
|
+
* Build the headers used on a WebSocket / MQTT upgrade. These are the browser
|
|
638
|
+
* headers minus the hop-by-hop ones the transport owns, and with the same
|
|
639
|
+
* Client Hints so the socket matches the HTTP traffic from the same session.
|
|
640
|
+
*/
|
|
641
|
+
declare function getWebSocketHeaders(url: string, options?: Record<string, any>, ctx?: Record<string, any>): Record<string, string>;
|
|
642
|
+
/**
|
|
643
|
+
* Query parameters the real web client appends to every GraphQL/form POST.
|
|
644
|
+
* Sending the same `dpr` and viewport as the browser identity keeps the
|
|
645
|
+
* request fingerprint coherent with the Client Hints.
|
|
646
|
+
*/
|
|
647
|
+
declare function getFingerprintParams(options?: Record<string, any>): Record<string, string>;
|
|
648
|
+
|
|
649
|
+
interface CookieExtractionResult {
|
|
650
|
+
/** Human-readable name -> value for every cookie found. */
|
|
651
|
+
cookies: Record<string, string>;
|
|
652
|
+
/** Total distinct cookie names harvested. */
|
|
653
|
+
count: number;
|
|
654
|
+
/** Sources that contributed at least one cookie. */
|
|
655
|
+
sources: string[];
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Collect cookies from a live cookie jar for every Facebook/Messenger origin.
|
|
659
|
+
* `getCookiesSync(url)` returns Cookie objects; `cookieString()` yields the
|
|
660
|
+
* exact `name=value` pair that must be sent on the wire.
|
|
661
|
+
*/
|
|
662
|
+
declare function extractCookiesFromJar(jar: any): Record<string, string>;
|
|
663
|
+
/**
|
|
664
|
+
* Parse a raw `Set-Cookie` header (or an array of them) into name/value pairs.
|
|
665
|
+
* Multiple `Set-Cookie` headers arrive as an array; a single one may also be
|
|
666
|
+
* comma-joined by some transports, so handle both.
|
|
667
|
+
*/
|
|
668
|
+
declare function extractCookiesFromSetCookie(header: any): Record<string, string>;
|
|
669
|
+
/**
|
|
670
|
+
* Some Facebook responses embed cookie assignments inside JSON (`jsmods`) or
|
|
671
|
+
* inline scripts rather than in a `Set-Cookie` header. Harvest those too so a
|
|
672
|
+
* rotated cookie cannot hide from the jar.
|
|
673
|
+
*/
|
|
674
|
+
declare function extractCookiesFromBody(body: any): Record<string, string>;
|
|
675
|
+
/**
|
|
676
|
+
* Run every extractor and merge the results. Later sources win so a cookie
|
|
677
|
+
* freshly set by Facebook overrides the stale jar copy.
|
|
678
|
+
*/
|
|
679
|
+
declare function extractCookies(sources: {
|
|
680
|
+
jar?: any;
|
|
681
|
+
setCookie?: any;
|
|
682
|
+
body?: any;
|
|
683
|
+
}): CookieExtractionResult;
|
|
684
|
+
/**
|
|
685
|
+
* Fold a `Set-Cookie` header into the jar for both facebook and messenger.
|
|
686
|
+
* Preserves the attributes Facebook sent instead of rebuilding the cookie, so
|
|
687
|
+
* `Secure` / `SameSite` / `HttpOnly` / expiry survive.
|
|
688
|
+
*/
|
|
689
|
+
declare function applySetCookie(jar: any, header: any): number;
|
|
690
|
+
/** True when the jar still holds an authenticated session (`c_user` + `xs`). */
|
|
691
|
+
declare function hasAuthenticatedSession(jar: any): boolean;
|
|
692
|
+
/**
|
|
693
|
+
* Build the `Cookie:` header value for a socket/HTTP target.
|
|
694
|
+
*
|
|
695
|
+
* Cookies are scoped to `.facebook.com`/`.messenger.com`, so a jar lookup for
|
|
696
|
+
* an `edge-chat.messenger.com` or `gateway.facebook.com` host returns only the
|
|
697
|
+
* handful of host-less cookies (typically just `fr`). Sending that partial set
|
|
698
|
+
* is what makes Facebook refuse an authenticated handshake. This unions the
|
|
699
|
+
* jar across every origin the session legitimately holds cookies for, dedupes
|
|
700
|
+
* by name, and preserves `cookieString()` (the exact wire form).
|
|
701
|
+
*/
|
|
702
|
+
declare function collectSessionCookies(ctx: any, host?: string): string;
|
|
703
|
+
/** Names of the session cookies that are currently missing. */
|
|
704
|
+
declare function missingSessionCookies(jar: any): string[];
|
|
705
|
+
/**
|
|
706
|
+
* Re-fetch the Facebook/Messenger surfaces and fold every `Set-Cookie` back
|
|
707
|
+
* into the jar. This is the cookie extractor's refresh step: it is how a
|
|
708
|
+
* long-running session obtains rotated `datr`/`fr`/`xs` values instead of
|
|
709
|
+
* slowly dying as they expire.
|
|
710
|
+
*
|
|
711
|
+
* Returns the merged cookie map so callers can persist it (e.g. as a new
|
|
712
|
+
* appState), plus whether the session still looks authenticated.
|
|
713
|
+
*/
|
|
714
|
+
declare function refreshSessionCookies(ctx: any, defaultFuncs: any, options?: {
|
|
715
|
+
surfaces?: string[];
|
|
716
|
+
}): Promise<CookieExtractionResult & {
|
|
717
|
+
applied: number;
|
|
718
|
+
authenticated: boolean;
|
|
719
|
+
errors: string[];
|
|
720
|
+
}>;
|
|
721
|
+
/** Detect an auth/document-token failure in a thrown or returned payload. */
|
|
722
|
+
declare function isAuthFailure(value: any): boolean;
|
|
723
|
+
/**
|
|
724
|
+
* Wrap a network operation with one repair-and-retry pass.
|
|
725
|
+
*
|
|
726
|
+
* On an auth failure it refreshes the session cookies, invalidates the Comet
|
|
727
|
+
* tokens, and runs the operation once more. This is what converts "works after
|
|
728
|
+
* startup, then stops" into "works, and recovers on its own".
|
|
729
|
+
*/
|
|
730
|
+
declare function withSessionRetry<T>(ctx: any, defaultFuncs: any, operation: () => Promise<T>, options?: {
|
|
731
|
+
attempts?: number;
|
|
732
|
+
onRecover?: (info: any) => void;
|
|
733
|
+
}): Promise<T>;
|
|
734
|
+
/** Repair a session: refresh cookies, drop stale tokens, reset MQTT backoff. */
|
|
735
|
+
declare function repairSession(ctx: any, defaultFuncs: any): Promise<boolean>;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Populate `ctx.lsd` / `ctx.fb_dtsg` (and `ctx.__spin` / `ctx.jazoest`) from
|
|
739
|
+
* Facebook's own Comet markup.
|
|
740
|
+
*
|
|
741
|
+
* Safe to call from every GraphQL module: it is a no-op while the cached pair
|
|
742
|
+
* is fresh, and it maintains exponential backoff when the scrape keeps failing
|
|
743
|
+
* so a broken session cannot turn into a request storm.
|
|
744
|
+
*/
|
|
745
|
+
declare function ensureCometTokens(ctx: any, defaultFuncs: any, force?: boolean): Promise<void>;
|
|
746
|
+
/**
|
|
747
|
+
* Drop the cached document tokens so the next {@link ensureCometTokens} call is
|
|
748
|
+
* forced to re-scrape. Call this from any error path that observes a
|
|
749
|
+
* document-token rejection.
|
|
750
|
+
*/
|
|
751
|
+
declare function invalidateCometTokens(ctx: any): void;
|
|
752
|
+
/** True when an error/response payload signals a stale document token. */
|
|
753
|
+
declare function isStaleTokenError(value: any): boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Run a GraphQL request with document-token resilience.
|
|
756
|
+
*
|
|
757
|
+
* `run(host)` must perform the request using the tokens currently on `ctx`
|
|
758
|
+
* (read `ctx.lsd` / `ctx.fb_dtsg`), and resolve to the parsed payload. This
|
|
759
|
+
* helper makes sure the tokens exist first, detects a stale-token rejection in
|
|
760
|
+
* the result, re-scrapes, and retries once. It is the shared implementation
|
|
761
|
+
* behind searchMusic and every other token-sensitive query.
|
|
762
|
+
*/
|
|
763
|
+
declare function withCometTokens<T>(ctx: any, defaultFuncs: any, run: () => Promise<T>, options?: {
|
|
764
|
+
retries?: number;
|
|
765
|
+
}): Promise<T>;
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Human-like pacing and request sequencing.
|
|
769
|
+
*
|
|
770
|
+
* Facebook does not rate-limit on volume alone; it also looks at *shape*. A
|
|
771
|
+
* bot that issues ten GraphQL calls in the same millisecond, or that always
|
|
772
|
+
* waits exactly the same amount between retries, is trivially separable from a
|
|
773
|
+
* person. Real clients:
|
|
774
|
+
*
|
|
775
|
+
* - space requests out by a few tens to a few hundreds of milliseconds,
|
|
776
|
+
* - take longer after a heavy call and shorter after a trivial one,
|
|
777
|
+
* - jitter their retry delays instead of using a fixed ramp,
|
|
778
|
+
* - pause noticeably between distinct "actions" (open thread, then send).
|
|
779
|
+
*
|
|
780
|
+
* This module centralizes that behavior. It is deliberately cheap: a single
|
|
781
|
+
* shared queue guarantees requests never leave simultaneously, while still
|
|
782
|
+
* letting independent callers await their own turn.
|
|
783
|
+
*/
|
|
784
|
+
/**
|
|
785
|
+
* A jittered wait. Uses a log-normal-ish shape (mostly short, occasionally
|
|
786
|
+
* longer) so the distribution does not look uniform to a classifier.
|
|
787
|
+
*/
|
|
788
|
+
declare function humanDelay(baseMs?: number, spreadMs?: number): number;
|
|
789
|
+
declare function sleep(ms: number): Promise<void>;
|
|
790
|
+
/**
|
|
791
|
+
* Await this session's turn before sending a request, then record the send
|
|
792
|
+
* time. Concurrent callers are serialized in call order so two modules cannot
|
|
793
|
+
* fire in the same tick.
|
|
794
|
+
*
|
|
795
|
+
* `weight` lets a caller request a longer pause for an action that would be a
|
|
796
|
+
* "big" step for a human (opening a thread, sending a message) versus a small
|
|
797
|
+
* poll.
|
|
798
|
+
*/
|
|
799
|
+
declare function paceRequest(ctx: any, weight?: "light" | "normal" | "heavy"): Promise<void>;
|
|
800
|
+
/**
|
|
801
|
+
* An exponentially backed-off, fully jittered retry delay. Replaces the fixed
|
|
802
|
+
* `base * 2 ** i` ramps used across the library, which are a pattern tell and
|
|
803
|
+
* synchronized across every process started at the same time.
|
|
804
|
+
*/
|
|
805
|
+
declare function retryDelay(attempt: number, baseMs?: number, capMs?: number): number;
|
|
806
|
+
/** Mark a heavy action so the next request gets a longer pause. */
|
|
807
|
+
declare function noteAction(ctx: any, weight?: "light" | "normal" | "heavy"): void;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Account safety: a per-session request budget and circuit breaker.
|
|
811
|
+
*
|
|
812
|
+
* The single most common way a bot gets its session invalidated is not a bad
|
|
813
|
+
* header — it is a *storm*. A loop that retries a failing call, a reconnect
|
|
814
|
+
* ramp that re-arms a limiter, or several modules firing at once can push a
|
|
815
|
+
* healthy account into Facebook's risk system, which then logs the session out
|
|
816
|
+
* or asks for a password. Once that happens, no amount of header tuning helps.
|
|
817
|
+
*
|
|
818
|
+
* This module caps how fast a session can emit requests and trips a breaker
|
|
819
|
+
* when Facebook starts signalling that it is unhappy (429s, repeated auth
|
|
820
|
+
* failures, checkpoint/consent redirects). A tripped breaker parks all traffic
|
|
821
|
+
* for a cooling-off window, which is exactly what a person would do after
|
|
822
|
+
* being warned.
|
|
823
|
+
*/
|
|
824
|
+
type BreakerReason = "rate-limit" | "auth-failure" | "checkpoint" | "manual";
|
|
825
|
+
interface SafetySnapshot {
|
|
826
|
+
closed: boolean;
|
|
827
|
+
reason?: BreakerReason;
|
|
828
|
+
cooldownRemainingMs: number;
|
|
829
|
+
requestsInWindow: number;
|
|
830
|
+
authFailures: number;
|
|
831
|
+
cappedCount: number;
|
|
832
|
+
}
|
|
833
|
+
/** True while the breaker is open (traffic should be parked). */
|
|
834
|
+
declare function isBreakerOpen(ctx: any): boolean;
|
|
835
|
+
/** Trip the breaker for a cooling-off period. */
|
|
836
|
+
declare function tripBreaker(ctx: any, reason?: BreakerReason): void;
|
|
837
|
+
/** Close the breaker immediately (e.g. after a confirmed-good request). */
|
|
838
|
+
declare function resetBreaker(ctx: any): void;
|
|
839
|
+
/** Record an auth-looking failure; trips the breaker at the threshold. */
|
|
840
|
+
declare function noteAuthFailure(ctx: any): void;
|
|
841
|
+
/** Record a Facebook rate-limit response. */
|
|
842
|
+
declare function noteRateLimit(ctx: any): void;
|
|
843
|
+
/** Record a checkpoint/consent redirect that means the session is at risk. */
|
|
844
|
+
declare function noteCheckpoint(ctx: any): void;
|
|
845
|
+
/**
|
|
846
|
+
* Reserve a request slot. Returns the number of ms the caller must wait before
|
|
847
|
+
* emitting (0 when it may proceed immediately). Throws nothing: a caller that
|
|
848
|
+
* cannot wait is still bounded by the sliding window.
|
|
849
|
+
*/
|
|
850
|
+
declare function reserveRequest(ctx: any): number;
|
|
851
|
+
/** A diagnostic snapshot for logs / health checks. */
|
|
852
|
+
declare function safetySnapshot(ctx: any): SafetySnapshot;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Session warm-up.
|
|
856
|
+
*
|
|
857
|
+
* A freshly-authenticated session that immediately fires GraphQL queries is
|
|
858
|
+
* distinguishable from a real client, which first loads the home document, then
|
|
859
|
+
* the Messenger inbox, and only afterwards starts issuing API calls. Those
|
|
860
|
+
* document loads also hand out the `datr`/`fr` rotation and the Comet document
|
|
861
|
+
* tokens that later calls depend on.
|
|
862
|
+
*
|
|
863
|
+
* {@link warmUpSession} performs that short, realistic sequence with human
|
|
864
|
+
* pacing. It is best-effort: a failure never aborts login, because the tokens
|
|
865
|
+
* can always be re-scraped lazily.
|
|
866
|
+
*/
|
|
867
|
+
|
|
868
|
+
interface WarmUpResult {
|
|
869
|
+
visited: string[];
|
|
870
|
+
cookiesApplied: number;
|
|
871
|
+
authenticated: boolean;
|
|
872
|
+
tokensSeeded: boolean;
|
|
873
|
+
errors: string[];
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Visit the surfaces a real browser would on a normal session start.
|
|
877
|
+
*
|
|
878
|
+
* @param ctx session context (needs `jar`)
|
|
879
|
+
* @param getter a `defaultFuncs.get`-compatible function
|
|
880
|
+
* @param options.includeMessenger visit messenger.com as well (default true)
|
|
881
|
+
*/
|
|
882
|
+
declare function warmUpSession(ctx: any, getter: (url: string, jar: any, qs?: any, options?: any, ctx?: any, customHeader?: any) => Promise<any>, options?: {
|
|
883
|
+
includeMessenger?: boolean;
|
|
884
|
+
}): Promise<WarmUpResult>;
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Human-like liveness engine.
|
|
888
|
+
*
|
|
889
|
+
* This is the piece that makes a long-running bot account behave like a person
|
|
890
|
+
* instead of a script. Facebook's risk system does not just look at one request
|
|
891
|
+
* — it looks at the *shape of the session over time*:
|
|
892
|
+
*
|
|
893
|
+
* - requests spread out, never a burst,
|
|
894
|
+
* - activity in bursts followed by quiet periods (people leave the app),
|
|
895
|
+
* - a stable presence heartbeat instead of a permanent "always typing" state,
|
|
896
|
+
* - no reconnect storms when the socket drops,
|
|
897
|
+
* - a deliberate pause after being told to slow down.
|
|
898
|
+
*
|
|
899
|
+
* {@link startLiveness} installs a single worker that owns that rhythm. Every
|
|
900
|
+
* outbound request funnels through it (via `paceRequest`), and it maintains a
|
|
901
|
+
* natural foreground/background rhythm so the session never looks pinned open.
|
|
902
|
+
*/
|
|
903
|
+
|
|
904
|
+
interface LivenessHandle {
|
|
905
|
+
stop: () => void;
|
|
906
|
+
/** Current activity state, for diagnostics. */
|
|
907
|
+
state: () => LivenessState;
|
|
908
|
+
}
|
|
909
|
+
interface LivenessState {
|
|
910
|
+
active: boolean;
|
|
911
|
+
/** ms until the next background/foreground transition. */
|
|
912
|
+
nextTransitionMs: number;
|
|
913
|
+
/** Total requests observed through pacing. */
|
|
914
|
+
requests: number;
|
|
915
|
+
breakerOpen: boolean;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Start the liveness worker for a session.
|
|
919
|
+
*
|
|
920
|
+
* @param ctx session context (mutated with `__foreground`)
|
|
921
|
+
* @param options.foregroundPing optional callback invoked when becoming active
|
|
922
|
+
* @param options.backgroundPing optional callback invoked when going idle
|
|
923
|
+
*/
|
|
924
|
+
declare function startLiveness(ctx: any, options?: {
|
|
925
|
+
foregroundPing?: () => void;
|
|
926
|
+
backgroundPing?: () => void;
|
|
927
|
+
}): LivenessHandle;
|
|
928
|
+
/**
|
|
929
|
+
* A guard for *proactive* activity (anything not triggered by an incoming
|
|
930
|
+
* event). Returns false while the session is idle or the safety breaker is
|
|
931
|
+
* open, so a scheduled loop can quietly skip instead of firing off-schedule
|
|
932
|
+
* and looking automated.
|
|
933
|
+
*/
|
|
934
|
+
declare function canActProactively(ctx: any): boolean;
|
|
935
|
+
/** Wait until the session is foregrounded and the breaker is closed. */
|
|
936
|
+
declare function awaitProactiveSlot(ctx: any, maxWaitMs?: number): Promise<boolean>;
|
|
937
|
+
|
|
938
|
+
/** Extract the `CurrentUserInitialData` object from a profile HTML document. */
|
|
939
|
+
declare function extractCurrentUser(html: any): Record<string, any> | null;
|
|
940
|
+
|
|
545
941
|
type ApiContext = ApiContext$1;
|
|
546
942
|
type ApiInternal = Api;
|
|
547
943
|
type DefaultFuncs = DefaultFuncs$1;
|
|
@@ -552,4 +948,4 @@ declare const _default: typeof login$1 & {
|
|
|
552
948
|
default: typeof login$1;
|
|
553
949
|
};
|
|
554
950
|
|
|
555
|
-
export { type API, type AddedStickerPackInfo, type AiTheme, type AnyAttachment, type ApiContext, type ApiInternal, type Attachment, type AudioAttachment, type Callback, type CommentMessage, type CommentResult, type Coordinates, type DefaultFuncs, type EmojiEvent, type Event, type FileAttachment, type GroupNameEvent, type ListenEvent, type LoginCredentials, type LoginOptions, type Mention, type Message, type MessageID, type MessageObject, type MessageReply, type MusicTag, type MusicTrack, type NicknameEvent, type PhotoAttachment, type Reaction, type SearchMusicOptions, type SearchMusicResult, type ShareAttachment, type ShareResult, type StickerAttachment, type StickerInfo, type StickerPackInfo, type ThreadID, type ThreadInfo, type ThreadThemeEvent, type TypingIndicator, type UnsendMessageEvent, type UserID, type UserInfo, type VideoAttachment, _default as default, login$1 as login, publicTypes };
|
|
951
|
+
export { type API, type AddedStickerPackInfo, type AiTheme, type AnyAttachment, type ApiContext, type ApiInternal, type Attachment, type AudioAttachment, type BrowserProfile, type Callback, type CommentMessage, type CommentResult, type Coordinates, type DefaultFuncs, type EmojiEvent, type Event, type FileAttachment, type GroupNameEvent, type ListenEvent, type LivenessHandle, type LivenessState, type LoginCredentials, type LoginOptions, type Mention, type Message, type MessageID, type MessageObject, type MessageReply, type MusicTag, type MusicTrack, type NicknameEvent, type PhotoAttachment, type Reaction, type SearchMusicOptions, type SearchMusicResult, type ShareAttachment, type ShareResult, type StickerAttachment, type StickerInfo, type StickerPackInfo, type ThreadID, type ThreadInfo, type ThreadThemeEvent, type TypingIndicator, type UnsendMessageEvent, type UserID, type UserInfo, type VideoAttachment, type WarmUpResult, applySetCookie, awaitProactiveSlot, canActProactively, collectSessionCookies, _default as default, defaultBrowserProfile, ensureCometTokens, extractCookies, extractCookiesFromBody, extractCookiesFromJar, extractCookiesFromSetCookie, extractCurrentUser, getFingerprintParams, getHeaders, getWebSocketHeaders, hasAuthenticatedSession, humanDelay, invalidateCometTokens, isAuthFailure, isBreakerOpen, isStaleTokenError, login$1 as login, missingSessionCookies, normalizeBrowserProfile, noteAction, noteAuthFailure, noteCheckpoint, noteRateLimit, paceRequest, publicTypes, randomUserAgent, refreshSessionCookies, repairSession, reserveRequest, resetBreaker, resolveProfile, retryDelay, safetySnapshot, sleep, startLiveness, tripBreaker, warmUpSession, withCometTokens, withSessionRetry };
|