
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
x-client-transaction-id
Advanced tools
Client Transaction ID generator library for X (formerly Twitter) API requests
Client Transaction ID generator library for X (formerly Twitter) API requests
This library provides functionality to generate the x-client-transaction-id
header value required for X (formerly Twitter) API requests. This transaction ID
is necessary when making authenticated requests to X APIs.
# NPM
npm i x-client-transaction-id
# PNPM
pnpm i x-client-transaction-id
# Yarn
yarn add x-client-transaction-id
deno add npm:x-client-transaction-id
bun add x-client-transaction-id
// import maps
import { ClientTransaction } from "jsr:@lami/x-client-transaction-id@0.1.0";
This library has been tested and confirmed to work with the following runtimes:
import { ClientTransaction, handleXMigration } from "x-client-transaction-id";
// Get the X homepage HTML document (using utility function)
const document = await handleXMigration();
// Create and initialize ClientTransaction instance
const transaction = await ClientTransaction.create(document);
// Generate a transaction ID
const transactionId = await transaction.generateTransactionId(
"GET", // HTTP method
"/1.1/jot/client_event.json", // API path
);
console.log("Transaction ID:", transactionId);
// Use as a header in API requests
const headers = {
"x-client-transaction-id": transactionId,
// Other required headers
};
const apiResponse = await fetch(
"https://api.twitter.com/1.1/jot/client_event.json",
{
method: "GET",
headers,
},
);
import { ClientTransaction } from "x-client-transaction-id";
// Get Twitter homepage HTML document
const response = await fetch("https://twitter.com/");
const html = await response.text();
const parser = new DOMParser();
const document = parser.parseFromString(html, "text/html");
// Create and initialize ClientTransaction instance
const transaction = new ClientTransaction(document);
await transaction.initialize();
// Generate a transaction ID
const transactionId = await transaction.generateTransactionId(
"POST", // HTTP method
"/graphql/abcdefg/TweetDetail", // API path
);
ClientTransaction
: Main class for generating transaction IDs for X API
requestshandleXMigration
: Utility function to retrieve the DOM document from X
(Twitter) homepageCubic
: Class for cubic interpolation calculations used in animation key
generationinterpolate
/interpolateNum
: Utility functions for value interpolationconvertRotationToMatrix
: Function to convert rotation values to matricesfloatToHex
, isOdd
, encodeBase64
, decodeBase64
ClientTransaction
Main class for handling X client transactions.
constructor(homePageDocument: Document)
homePageDocument
: The DOM document from the Twitter homepageasync initialize()
: Initialize the instance (must be called after
constructor)static async create(homePageDocument: Document): Promise<ClientTransaction>
:
Static factory method that creates an initialized instanceasync generateTransactionId(method: string, path: string, ...): Promise<string>
:
Generate a transaction ID for the specified HTTP method and API pathhandleXMigration
async function handleXMigration(): Promise<Document>;
Retrieves the X (Twitter) homepage and returns a DOM-parsed Document object. This makes it easy to get the document needed for ClientTransaction initialization.
This library is provided "as is" without warranty of any kind, either express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort or otherwise, arising from, out of, or in connection with the library or the use or other dealings in the library.
This is an unofficial library and is not affiliated with, endorsed, or sponsored by X Corp. (formerly Twitter, Inc.). All X/Twitter-related trademarks and copyrights belong to X Corp. This project is intended for educational and personal use only. Users of this library are responsible for ensuring their usage complies with X's terms of service and developer policies.
MIT
FAQs
Client Transaction ID generator library for X (formerly Twitter) API requests
The npm package x-client-transaction-id receives a total of 62 weekly downloads. As such, x-client-transaction-id popularity was classified as not popular.
We found that x-client-transaction-id demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.