{"id":27733373,"url":"https://github.com/lqm1/x-client-transaction-id","last_synced_at":"2025-08-16T05:37:35.324Z","repository":{"id":290160449,"uuid":"973553060","full_name":"Lqm1/x-client-transaction-id","owner":"Lqm1","description":"Client Transaction ID generator library for X (formerly Twitter) API requests","archived":false,"fork":false,"pushed_at":"2025-07-01T13:47:33.000Z","size":105,"stargazers_count":28,"open_issues_count":2,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-08T07:56:02.912Z","etag":null,"topics":["bun","deno","jsr","node","npm","twitter","typescript","x","x-client-transaction-id"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/x-client-transaction-id","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lqm1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-27T08:32:05.000Z","updated_at":"2025-07-29T22:01:58.000Z","dependencies_parsed_at":"2025-04-27T09:39:41.254Z","dependency_job_id":null,"html_url":"https://github.com/Lqm1/x-client-transaction-id","commit_stats":null,"previous_names":["lqm1/x-client-transaction-id"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Lqm1/x-client-transaction-id","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lqm1%2Fx-client-transaction-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lqm1%2Fx-client-transaction-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lqm1%2Fx-client-transaction-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lqm1%2Fx-client-transaction-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lqm1","download_url":"https://codeload.github.com/Lqm1/x-client-transaction-id/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lqm1%2Fx-client-transaction-id/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270672768,"owners_count":24626015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","deno","jsr","node","npm","twitter","typescript","x","x-client-transaction-id"],"created_at":"2025-04-28T12:38:11.878Z","updated_at":"2025-08-16T05:37:35.305Z","avatar_url":"https://github.com/Lqm1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# x-client-transaction-id\n\nClient Transaction ID generator library for X (formerly Twitter) API requests\n\n[![jsr](https://jsr.io/badges/@lami/x-client-transaction-id)](https://jsr.io/@lami/x-client-transaction-id)\n[![npm](https://img.shields.io/npm/v/x-client-transaction-id)](https://www.npmjs.com/package/x-client-transaction-id)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n[English](README.md) | [日本語](README_JA.md) | [中文](README_CN.md)\n\n## Overview\n\nThis library provides functionality to generate the `x-client-transaction-id`\nheader value required for X (formerly Twitter) API requests. This transaction ID\nis necessary when making authenticated requests to X APIs.\n\n## Installation\n\n### Package Managers\n\n#### NPM / PNPM / Yarn\n\n```bash\n# NPM\nnpm i x-client-transaction-id\n\n# PNPM\npnpm i x-client-transaction-id\n\n# Yarn\nyarn add x-client-transaction-id\n```\n\n#### Deno\n\n```bash\ndeno add npm:x-client-transaction-id\n```\n\n#### Bun\n\n```bash\nbun add x-client-transaction-id\n```\n\n### Import\n\n```ts\n// import maps\nimport { ClientTransaction } from \"jsr:@lami/x-client-transaction-id@0.1.0\";\n```\n\n## Runtime Compatibility\n\nThis library has been tested and confirmed to work with the following runtimes:\n\n- Node.js\n- Deno\n- Bun\n- Cloudflare Workers\n\n## Usage\n\n### Basic Example\n\n```ts\nimport { ClientTransaction, handleXMigration } from \"x-client-transaction-id\";\n\n// Get the X homepage HTML document (using utility function)\nconst document = await handleXMigration();\n\n// Create and initialize ClientTransaction instance\nconst transaction = await ClientTransaction.create(document);\n\n// Generate a transaction ID\nconst transactionId = await transaction.generateTransactionId(\n  \"GET\", // HTTP method\n  \"/1.1/jot/client_event.json\", // API path\n);\n\nconsole.log(\"Transaction ID:\", transactionId);\n\n// Use as a header in API requests\nconst headers = {\n  \"x-client-transaction-id\": transactionId,\n  // Other required headers\n};\n\nconst apiResponse = await fetch(\n  \"https://api.twitter.com/1.1/jot/client_event.json\",\n  {\n    method: \"GET\",\n    headers,\n  },\n);\n```\n\n### Manual Document Retrieval\n\n```ts\nimport { ClientTransaction } from \"x-client-transaction-id\";\n\n// Get Twitter homepage HTML document\nconst response = await fetch(\"https://twitter.com/\");\nconst html = await response.text();\nconst parser = new DOMParser();\nconst document = parser.parseFromString(html, \"text/html\");\n\n// Create and initialize ClientTransaction instance\nconst transaction = new ClientTransaction(document);\nawait transaction.initialize();\n\n// Generate a transaction ID\nconst transactionId = await transaction.generateTransactionId(\n  \"POST\", // HTTP method\n  \"/graphql/abcdefg/TweetDetail\", // API path\n);\n```\n\n## Key Features\n\n- `ClientTransaction`: Main class for generating transaction IDs for X API\n  requests\n- `handleXMigration`: Utility function to retrieve the DOM document from X\n  (Twitter) homepage\n- `Cubic`: Class for cubic interpolation calculations used in animation key\n  generation\n- `interpolate`/`interpolateNum`: Utility functions for value interpolation\n- `convertRotationToMatrix`: Function to convert rotation values to matrices\n- Other utility functions: `floatToHex`, `isOdd`, `encodeBase64`, `decodeBase64`\n\n## API Reference\n\n### `ClientTransaction`\n\nMain class for handling X client transactions.\n\n#### Constructor\n\n```ts\nconstructor(homePageDocument: Document)\n```\n\n- `homePageDocument`: The DOM document from the Twitter homepage\n\n#### Methods\n\n- `async initialize()`: Initialize the instance (must be called after\n  constructor)\n- `static async create(homePageDocument: Document): Promise\u003cClientTransaction\u003e`:\n  Static factory method that creates an initialized instance\n- `async generateTransactionId(method: string, path: string, ...): Promise\u003cstring\u003e`:\n  Generate a transaction ID for the specified HTTP method and API path\n\n### `handleXMigration`\n\n```ts\nasync function handleXMigration(): Promise\u003cDocument\u003e;\n```\n\nRetrieves the X (Twitter) homepage and returns a DOM-parsed Document object.\nThis makes it easy to get the document needed for ClientTransaction\ninitialization.\n\n## Disclaimer\n\nThis library is provided \"as is\" without warranty of any kind, either express or\nimplied, including but not limited to the warranties of merchantability, fitness\nfor a particular purpose, and non-infringement. In no event shall the authors or\ncopyright holders be liable for any claim, damages, or other liability, whether\nin an action of contract, tort or otherwise, arising from, out of, or in\nconnection with the library or the use or other dealings in the library.\n\nThis is an unofficial library and is not affiliated with, endorsed, or sponsored\nby X Corp. (formerly Twitter, Inc.). All X/Twitter-related trademarks and\ncopyrights belong to X Corp. This project is intended for educational and\npersonal use only. Users of this library are responsible for ensuring their\nusage complies with X's terms of service and developer policies.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flqm1%2Fx-client-transaction-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flqm1%2Fx-client-transaction-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flqm1%2Fx-client-transaction-id/lists"}