TypeScript/Node.js generator for X/Twitter x-client-transaction-id values.
npm install x-txid-generatorimport {
ClientTransaction,
generateHeaders,
getOndemandFileUrl,
handleXMigrationAsync,
} from 'x-txid-generator';
const headers = generateHeaders();
const session = {
async request({ method, url, data }: { method: string; url: string; data?: Record<string, string> }) {
const response = await fetch(url, {
method,
headers,
body: data ? new URLSearchParams(data) : undefined,
});
return { content: await response.text() };
},
};
const homePageHtml = await handleXMigrationAsync(session);
const ondemandUrl = getOndemandFileUrl(homePageHtml);
const ondemandResponse = await fetch(ondemandUrl, { headers });
const ondemandFileJs = await ondemandResponse.text();
const transaction = new ClientTransaction(homePageHtml, ondemandFileJs);
const transactionId = transaction.generateTransactionId(
'POST',
'/i/api/1.1/jot/client_event.json',
);
console.log(transactionId);ClientTransactionderives keys and generates transaction IDs.generateHeaders()returns browser-like headers for X requests.getOndemandFileUrl(homePageHtml)extracts theondemand.s.jsasset URL.handleXMigration(session)handles the synchronous X migration flow.handleXMigrationAsync(session)handles the asynchronous X migration flow.
The session object may expose request({ method, url, data }),
request(method, url, data), or get(url) for simple GET-only flows.
npm test
npm run build
npm run lint