npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

x-client-transaction-id-glacier

v1.0.0

Published

Client Transaction ID generator library for X (formerly Twitter) API requests

Readme

x-client-transaction-id

Client Transaction ID generator library for X (formerly Twitter) API requests

jsr npm License: MIT

English | 日本語 | 中文

Overview

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.

Installation

Package Managers

NPM / PNPM / Yarn

# NPM
npm i x-client-transaction-id

# PNPM
pnpm i x-client-transaction-id

# Yarn
yarn add x-client-transaction-id

Deno

deno add npm:x-client-transaction-id

Bun

bun add x-client-transaction-id

Import

// import maps
import { ClientTransaction } from "jsr:@lami/[email protected]";

Runtime Compatibility

This library has been tested and confirmed to work with the following runtimes:

  • Node.js
  • Deno
  • Bun
  • Cloudflare Workers

Usage

Basic Example

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
});

Manual Document Retrieval

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
);

Key Features

  • ClientTransaction: Main class for generating transaction IDs for X API requests
  • handleXMigration: Utility function to retrieve the DOM document from X (Twitter) homepage
  • Cubic: Class for cubic interpolation calculations used in animation key generation
  • interpolate/interpolateNum: Utility functions for value interpolation
  • convertRotationToMatrix: Function to convert rotation values to matrices
  • Other utility functions: floatToHex, isOdd, encodeBase64, decodeBase64

API Reference

ClientTransaction

Main class for handling X client transactions.

Constructor

constructor(homePageDocument: Document)
  • homePageDocument: The DOM document from the Twitter homepage

Methods

  • async initialize(): Initialize the instance (must be called after constructor)
  • static async create(homePageDocument: Document): Promise<ClientTransaction>: Static factory method that creates an initialized instance
  • async generateTransactionId(method: string, path: string, ...): Promise<string>: Generate a transaction ID for the specified HTTP method and API path

handleXMigration

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.

Disclaimer

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.

License

MIT