fix(12): WR-03 validate PAX8 token response shape in Pax8Client.getToken()

This commit is contained in:
lorentz 2026-07-11 07:22:59 -04:00
parent 76a652ddfd
commit 1bb2b8b0a2

View file

@ -51,9 +51,16 @@ export class Pax8Client {
}
const data = await res.json();
// WR-03: a 200 response with an unexpected body shape (proxy/CDN error
// page reshaped as JSON, a future API version renaming the field, etc.)
// must not silently set accessToken to undefined and mask the failure
// behind a confusing 401 from the data endpoint later.
if (!data.access_token || typeof data.expires_in !== 'number') {
throw new Error('PAX8 token response missing access_token/expires_in');
}
this.accessToken = data.access_token;
this.tokenExpiry = Date.now() + data.expires_in * 1000;
return this.accessToken!;
return this.accessToken;
}
// Phase 11/12 will extend this with 429-aware Retry-After backoff for the