qbo_auth: захват intuit_tid в логах и ошибках; документ требований Intuit (intuit_requirements.md)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,10 @@ export const TOKEN_URL = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bea
|
||||
export const apiBase = (env: "sandbox" | "production"): string =>
|
||||
env === "sandbox" ? "https://sandbox-quickbooks.api.intuit.com" : "https://quickbooks.api.intuit.com";
|
||||
|
||||
export type FetchFn = (url: string, init: { method: string; headers: Record<string, string>; body: string }) => Promise<{ ok: boolean; status: number; json(): Promise<unknown> }>;
|
||||
export type FetchFn = (url: string, init: { method: string; headers: Record<string, string>; body: string }) => Promise<{ ok: boolean; status: number; json(): Promise<unknown>; headers?: { get(name: string): string | null } }>;
|
||||
|
||||
/** Идентификатор запроса Intuit (заголовок intuit_tid): нужен поддержке Intuit для разбора ошибок. */
|
||||
export const intuitTid = (r: { headers?: { get(name: string): string | null } }): string | undefined => r.headers?.get("intuit_tid") ?? undefined;
|
||||
|
||||
export interface TokenSet {
|
||||
accessToken: string;
|
||||
@@ -40,7 +43,8 @@ async function tokenCall(fetchFn: FetchFn, creds: { clientId: string; clientSecr
|
||||
if (!r.ok) {
|
||||
const err = typeof j.error === "string" ? j.error : "unknown";
|
||||
// в сообщение попадает только код ошибки Intuit, без тел с токенами
|
||||
throw new TokenError(`Intuit token endpoint: ${r.status} ${err}`, r.status, err === "invalid_grant");
|
||||
const tid = intuitTid(r);
|
||||
throw new TokenError(`Intuit token endpoint: ${r.status} ${err}${tid ? ` intuit_tid=${tid}` : ""}`, r.status, err === "invalid_grant");
|
||||
}
|
||||
const at = j.access_token, rt = j.refresh_token;
|
||||
if (typeof at !== "string" || typeof rt !== "string") throw new TokenError("в ответе Intuit нет токенов", r.status, false);
|
||||
|
||||
Reference in New Issue
Block a user