Сервис qbo_auth: OAuth-токены QuickBooks Online (callback services/api/qbo/callback), исследование и предложение quickbooks_bookkeeper (п.84)
All checks were successful
ci / test (push) Successful in 36s
ci / deploy (push) Successful in 5m18s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 22:19:06 +03:00
parent 6c4767c806
commit d8926bc6dc
19 changed files with 880 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
import { createLogger, createPool, itNotify, loadServiceSettings } from "khb_common";
import { parseKey } from "./crypto.js";
import { buildApi } from "./http-api.js";
import { QboAuth } from "./service.js";
import { qboAuthSchema } from "./settings.js";
import { PgStore } from "./store.js";
const { common, service: s } = loadServiceSettings("qbo_auth", qboAuthSchema);
const log = createLogger("qbo_auth", common.logLevel);
const pool = createPool(common.database.url, 3);
const auth = new QboAuth({
store: new PgStore(pool, parseKey(s.encryptionKey)),
fetchFn: (url, init) => fetch(url, init),
env: s.environment,
clientId: s.clientId,
clientSecret: s.clientSecret,
redirectUri: s.redirectUri,
scope: s.scope,
keepAliveHours: s.keepAliveHours,
notify: async (text) => {
await itNotify(common, text).catch(() => false);
},
});
const app = buildApi(auth, s.http.token);
await app.listen({ host: s.http.host, port: s.http.port });
log.info({ port: s.http.port, environment: s.environment }, "qbo_auth запущен");
// поддержание токенов: раз в час проверяем, не пора ли обновить (скользящий refresh token)
const timer = setInterval(() => void auth.keepAlive().catch((e) => log.error({ err: String(e) }, "keepalive")), 60 * 60_000);
process.on("SIGTERM", () => {
clearInterval(timer);
void app.close();
});