@accounter/modern-poalim-scraper
Version:
Modern scraper for Israeli banks (Hapoalim, Isracard, Max)
42 lines (41 loc) • 2.27 kB
TypeScript
import type { Page } from 'puppeteer';
export declare function fetchPostWithinPage<TResult>(page: Page, url: string, data: Record<string, unknown>, extraHeaders?: Record<string, string>): Promise<TResult | null>;
export declare function fetchGetWithinPage<TResult>(page: Page, url: string): Promise<TResult | null>;
/**
* Reads the XSRF token for the page's own host.
*
* Cookies are read from the browser context rather than the page (the
* page-level cookie API is deprecated), but every scraper shares the default
* context — so the result must be filtered by domain, otherwise another bank's
* `XSRF-TOKEN` could be picked up.
*/
export declare function getXsrfToken(page: Page): Promise<string | undefined>;
/** Session headers the mytrade SPA attaches to its own API calls. */
export type MytradeSession = {
/** Server-issued session key. Generating one yields `InvalidSessionException`. */
session: string;
csession?: string | undefined;
};
/**
* Captures the `session` / `csession` headers the mytrade SPA sends on its own
* API calls, by listening to the page's outgoing requests.
*
* The session key is minted server-side when the SPA boots — the API rejects
* anything we invent with `InvalidSessionException`, echoing the bad key back.
* Rather than guessing where the SPA stashes it, let it authenticate and reuse
* the headers off the wire.
*
* Attach this *before* navigating, then await it after `goto` resolves.
*/
export declare function captureMytradeSession(page: Page, timeoutMs?: number): Promise<MytradeSession>;
/**
* The "mytrade" portfolio API sits behind a different gateway than the rest of
* the Poalim REST surface: it wants the XSRF token like everything else, plus
* the SPA's server-issued `session` key, and is called with an empty body
* rather than `{}`.
*
* The method is per-endpoint: `account/view` is a POST, while the order
* executions history is a GET (sending it as POST returns nothing).
*/
export declare function fetchPoalimMytradeWithinPage<TResult>(page: Page, url: string, mytradeSession: MytradeSession, method?: 'GET' | 'POST'): Promise<TResult | null>;
export declare function fetchPoalimXSRFWithinPage<TResult>(page: Page, url: string, pageUuid: string): Promise<TResult | null>;