qbo_auth: вебхуки Intuit (/webhook, подпись HMAC, фоновая загрузка по событиям); токены вебхуков в настройках
Some checks failed
ci / test (push) Successful in 40s
ci / deploy (push) Failing after 2m48s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 23:21:57 +03:00
parent dc224e375b
commit 2806941fb3
5 changed files with 159 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { createLogger, createPool, itNotify, loadServiceSettings, withTx } from "khb_common";
import { parseKey } from "./crypto.js";
import { buildApi } from "./http-api.js";
import { SyncTrigger } from "./webhook.js";
import { QboAuth } from "./service.js";
import { qboAuthSchema } from "./settings.js";
import { PgStore } from "./store.js";
@@ -31,7 +32,20 @@ const sync = new QboSync({
environment: s.environment,
log: (msg, extra) => log.info(extra ?? {}, msg),
});
const app = buildApi(auth, s.http.token, sync);
const trigger = new SyncTrigger(
async () => {
const r = await sync.run().catch((e) => ({ status: "error", error: String(e) }));
log.info({ status: r.status }, "загрузка по вебхуку");
},
() => sync.isRunning,
);
const app = buildApi(auth, s.http.token, sync, {
tokens: s.webhookVerifierTokens,
onEvents: (events) => {
log.info({ count: events.length, entities: [...new Set(events.map((e) => `${e.name}:${e.operation}`))].slice(0, 20) }, "вебхук QuickBooks");
trigger.poke();
},
});
await app.listen({ host: s.http.host, port: s.http.port });
log.info({ port: s.http.port, environment: s.environment }, "qbo_auth запущен");
@@ -39,5 +53,6 @@ log.info({ port: s.http.port, environment: s.environment }, "qbo_auth запущ
const timer = setInterval(() => void auth.keepAlive().catch((e) => log.error({ err: String(e) }, "keepalive")), 60 * 60_000);
process.on("SIGTERM", () => {
clearInterval(timer);
trigger.stop();
void app.close();
});