Skip to content

feat(v2): missing common endpoints and OAuth 1.0a token exchange - #656

Merged
plhery merged 1 commit into
masterfrom
feat/v2-endpoints
Oct 25, 2026
Merged

plhery merged 1 commit into
masterfrom
feat/v2-endpoints

Conversation

@plhery

@plhery plhery commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Adds commonly needed X API v2 endpoints that the library was missing, each checked against X's OpenAPI spec:

  • Users: searchUsers(query), with its own paginator, since this endpoint pages with next_token.
  • Retweets: retweets(tweetId) (the retweets of a tweet) and retweetsOfMe().
  • DMs: dmEvent(id), deleteDmEvent(id), blockDms(userId) and unblockDms(userId).
  • Lists: listsPinned(loggedUserId).
  • Usage: usageCredits(), the pay-per-use balance.
  • Trends: trendsByWoeid(woeid) and personalizedTrends().
  • Filtered stream:
    • streamRuleCounts();
    • streamConnections(), terminateAllStreamConnections() and terminateStreamConnections(endpoint), to close a connection left open, the cause of the 429 TooManyConnections.
  • Auth: exchangeOAuth1Token({ accessToken, accessSecret }) moves OAuth 1.0a users to OAuth 2.0 without asking them to log in again (X docs). It sends what X documents: a form body, with a Basic header for confidential clients, or client_id in the body for public ones.

The deprecated v1 methods that now have a v2 equivalent point to it. The new methods are documented in doc/v2.md, doc/streaming.md and doc/auth.md.

Each one has a row in test/endpoints.test.ts (method, path, query, auth scheme) against the fake X. There are also tests for the next_token paging of user search, and for the token exchange of confidential and public clients. All 17 new tests fail without the change.

Left out: deleting connections by UUID, which needs a DELETE request with a body, and the request maker never sends one. User search has no previous_token parameter, so fetchPrevious() on it sends the previous token as next_token. That's a guess.

Users search, retweets of a tweet, retweets of me, get and delete a DM event, DM block and unblock, pinned lists, usage credits, trends by WOEID and personalized trends, stream rule counts, streaming connections (list, terminate all, terminate by endpoint), and exchangeOAuth1Token() for OAuth 1.0a to OAuth 2.0 migration.
@plhery
plhery merged commit 9e0799d into master Oct 25, 2026
3 checks passed
@plhery
plhery deleted the feat/v2-endpoints branch October 25, 2026 20:45
@plhery

plhery commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Shipped in 1.31.0

markharding pushed a commit to futo-org/Harbor that referenced this pull request Nov 3, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [twitter-api-v2](https://github.com/plhery/node-twitter-api-v2) | [`1.29.1` → `1.31.0`](https://renovatebot.com/diffs/npm/twitter-api-v2/1.29.1/1.31.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/twitter-api-v2/1.31.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/twitter-api-v2/1.29.1/1.31.0?slim=true) |

---

### Release Notes

<details>
<summary>plhery/node-twitter-api-v2 (twitter-api-v2)</summary>

### [`v1.31.0`](https://github.com/plhery/node-twitter-api-v2/blob/HEAD/changelog.md#1310)

[Compare Source](plhery/node-twitter-api-v2@1.30.0...1.31.0)

- docs: fix wrong snippets, add a credentials guide and common errors [#&#8203;654](plhery/node-twitter-api-v2#654) ([@&#8203;plhery](https://github.com/plhery))
- fix(stream): close() stops pending reconnections, for await survives reconnections [#&#8203;655](plhery/node-twitter-api-v2#655) ([@&#8203;plhery](https://github.com/plhery))
- feat(v2): missing common endpoints and OAuth 1.0a token exchange [#&#8203;656](plhery/node-twitter-api-v2#656) ([@&#8203;plhery](https://github.com/plhery))
- fix(paginators): stop at the last page, and dedupe merged includes [#&#8203;651](plhery/node-twitter-api-v2#651) ([@&#8203;plhery](https://github.com/plhery))
- feat(types): bring the v2 types up to date with X's docs [#&#8203;653](plhery/node-twitter-api-v2#653) ([@&#8203;plhery](https://github.com/plhery))
- fix(errors): match v2 problem types, explain X's errors, reject cut responses [#&#8203;652](plhery/node-twitter-api-v2#652) ([@&#8203;plhery](https://github.com/plhery))
- fix(client): retry a failed current user fetch, plugin hook errors, cloneWithPrefix() [#&#8203;650](plhery/node-twitter-api-v2#650) ([@&#8203;plhery](https://github.com/plhery))
- fix: TwitterApiReadOnly and TwitterApiReadWrite named imports crashed on Node 22 [#&#8203;649](plhery/node-twitter-api-v2#649) ([@&#8203;plhery](https://github.com/plhery))
- fix: encode URL parameters, so that an ID can't change the endpoint [#&#8203;648](plhery/node-twitter-api-v2#648) ([@&#8203;plhery](https://github.com/plhery))
- test: a fake X API for offline tests, CI on pull requests [#&#8203;647](plhery/node-twitter-api-v2#647) ([@&#8203;plhery](https://github.com/plhery))

### [`v1.30.0`](https://github.com/plhery/node-twitter-api-v2/blob/HEAD/changelog.md#1300)

[Compare Source](plhery/node-twitter-api-v2@1.29.2...1.30.0)

- fix(paginators): v1 searchUsers fetchNext() and fetchLast() kept asking for page 2 [#&#8203;644](plhery/node-twitter-api-v2#644) ([@&#8203;plhery](https://github.com/plhery))
- fix(types): tweet entity lists and user description entities are optional [#&#8203;645](plhery/node-twitter-api-v2#645) ([@&#8203;plhery](https://github.com/plhery))
- feat(media): report the upload progress of v2.uploadMedia with onProgress [#&#8203;646](plhery/node-twitter-api-v2#646) ([@&#8203;plhery](https://github.com/plhery))
- refactor: remove the redundant socket close listener of requests [#&#8203;643](plhery/node-twitter-api-v2#643) ([@&#8203;plhery](https://github.com/plhery))
- fix: ApiRequestError.requestError was always undefined [#&#8203;642](plhery/node-twitter-api-v2#642) ([@&#8203;plhery](https://github.com/plhery))
- docs: deprecate retired v1.1 and Labs methods, flag Enterprise-only endpoints [#&#8203;641](plhery/node-twitter-api-v2#641) ([@&#8203;plhery](https://github.com/plhery))
- fix: reject instead of hanging when a compressed response fails [#&#8203;640](plhery/node-twitter-api-v2#640) ([@&#8203;plhery](https://github.com/plhery))
- feat(media): accept file paths and handles in v2.uploadMedia [#&#8203;639](plhery/node-twitter-api-v2#639) ([@&#8203;plhery](https://github.com/plhery))

### [`v1.29.2`](https://github.com/plhery/node-twitter-api-v2/blob/HEAD/changelog.md#1292)

[Compare Source](plhery/node-twitter-api-v2@1.29.1...1.29.2)

- fix(paginators): keep oldest_id when fetchNext() returns an empty page [#&#8203;638](plhery/node-twitter-api-v2#638) ([@&#8203;plhery](https://github.com/plhery))
- fix(stream): don't drop a payload whose CRLF separator arrives alone [#&#8203;638](plhery/node-twitter-api-v2#638) ([@&#8203;plhery](https://github.com/plhery))
- fix(paginators): keep the cursor when previous() returns an empty page [#&#8203;637](plhery/node-twitter-api-v2#637) ([@&#8203;OsamaAnsar](https://github.com/OsamaAnsar))
- fix(stream): decode chunks with a stateful UTF-8 decoder [#&#8203;636](plhery/node-twitter-api-v2#636) ([@&#8203;OsamaAnsar](https://github.com/OsamaAnsar))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODguMiIsInVwZGF0ZWRJblZlciI6IjQ0LjE4OC4yIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/2162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant