import python from "bun_python"; export class TransactionIdGenerator { private initialHtmlContent!: string; private client_transaction: any; private cookie: string; private headers: any; private BeautifulSoup: any; private ClientTransaction: any; constructor(cookie: string) { this.cookie = cookie; } public async init() { const genheaders = await python.import("x_client_transaction.utils") .generate_headers; const hs = genheaders(); this.headers = { ...hs, Cookie: this.cookie }; const currentUrl = "https://x.com"; const response = await fetch(currentUrl, { headers: this.headers }); const html = await response.text(); this.initialHtmlContent = html; } public async getTransactionId(method: string, path: string): Promise { if (!this.BeautifulSoup || !this.ClientTransaction) { this.BeautifulSoup = await python.import("bs4").BeautifulSoup; this.ClientTransaction = await python.import("x_client_transaction") .ClientTransaction; } if (!this.client_transaction) { const soup = this.BeautifulSoup(this.initialHtmlContent, "lxml"); const onDemand = await python.import("x_client_transaction.utils") .get_ondemand_file_url; const file = onDemand(soup); const ondemand_res = await fetch(file, { method: "GET", headers: this.headers, }); const ondemand_text = await ondemand_res.text(); this.client_transaction = this.ClientTransaction(soup, ondemand_text); } const transaction_id = this.client_transaction.generate_transaction_id( method, path, ); return transaction_id; } }