Skip to content
← Public packages

@kentcdodds/x

X API v2 helpers for posts, search, DMs, and encrypted X Chat. Generic Activity CRC/HMAC utilities only — @kodykoala Pam wake lives in @kentcdodds/kodykoala-activity.

FollowFork

Files

auth-media.test.mjs

3 lines · 1.1 KB · JavaScript
import{test}from'node:test';import assert from'node:assert/strict';import{registerHooks}from'node:module';
registerHooks({resolve(spec,ctx,next){if(spec==='kody:runtime')return{url:'mock:x-runtime',shortCircuit:true};return next(spec,ctx)},load(url,ctx,next){if(url==='mock:x-runtime')return{format:'module',shortCircuit:true,source:`export const kody={};export async function createAuthenticatedFetch(){throw new Error('Forbidden legacy fallback')};export async function credential(name){if(name!=='x')throw new Error('ambiguous');return{fetch:globalThis.__mediaFetch}}`};return next(url,ctx)}})
test('media credentials select exactly one declared client and never fall back on ambiguity',async()=>{globalThis.__mediaFetch=async()=>new Response('same-account');const{binaryFetchFor}=await import('../src/auth.ts');assert.equal(await(await(await binaryFetchFor('x'))('https://api.x.com/2/users/me')).text(),'same-account');await assert.rejects(()=>binaryFetchFor('x-kodykoala'),/Explicit X credential mapping/);await assert.rejects(()=>binaryFetchFor('other'),/Undeclared/);delete globalThis.__mediaFetch})