* Resolves a public username to its numeric user ID via * GET /2/users/by/username/:username.
( accessToken: string, username: string, retryOptions?: Parameters<typeof fetchWithRetry>[2] )
| 179 | * GET /2/users/by/username/:username. |
| 180 | */ |
| 181 | async function resolveUsernameId( |
| 182 | accessToken: string, |
| 183 | username: string, |
| 184 | retryOptions?: Parameters<typeof fetchWithRetry>[2] |
| 185 | ): Promise<string> { |
| 186 | const handle = username.trim().replace(/^@/, '') |
| 187 | const data = (await xApiGet( |
| 188 | `/users/by/username/${encodeURIComponent(handle)}`, |
| 189 | accessToken, |
| 190 | undefined, |
| 191 | retryOptions |
| 192 | )) as { data?: { id?: string }; errors?: Array<{ detail?: string }> } |
| 193 | const id = data.data?.id |
| 194 | if (!id) { |
| 195 | throw new Error(data.errors?.[0]?.detail || `User @${handle} not found`) |
| 196 | } |
| 197 | return id |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Builds a deterministic, metadata-based content hash for a tweet. |