mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-26 19:06:34 +00:00
feat: pass request obs into claimPairing for traced logging
claimPairing now receives the request Observable and logs the specific reason for pending (not_found/expired/not_consumed/ missing_key). Success logged at info level with kiosk_id. All logs correlated via request trace. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5768e325b1
commit
925d9fd6dc
2 changed files with 12 additions and 5 deletions
|
|
@ -327,7 +327,8 @@ function registerPairingRoutes(
|
||||||
const code = (body?.code ?? "").trim().toUpperCase();
|
const code = (body?.code ?? "").trim().toUpperCase();
|
||||||
if (!code) throw createError({ statusCode: 400, statusMessage: "code required" });
|
if (!code) throw createError({ statusCode: 400, statusMessage: "code required" });
|
||||||
|
|
||||||
const result = await claimPairing(repo, code);
|
const reqObs = event.context.obs!;
|
||||||
|
const result = await claimPairing(repo, code, reqObs);
|
||||||
if (result.status === "pending") {
|
if (result.status === "pending") {
|
||||||
return new Response(JSON.stringify({ status: "pending" }), {
|
return new Response(JSON.stringify({ status: "pending" }), {
|
||||||
status: 202,
|
status: 202,
|
||||||
|
|
@ -335,6 +336,10 @@ function registerPairingRoutes(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqObs.log.info("pair/claim success for code {code} kiosk {kioskId}", {
|
||||||
|
code,
|
||||||
|
kioskId: String(result.kioskId),
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
status: "claimed",
|
status: "claimed",
|
||||||
kiosk_id: result.kioskId,
|
kiosk_id: result.kioskId,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
* 3. Admin enters code in UI → confirmPairing creates kiosk + kiosk_key
|
* 3. Admin enters code in UI → confirmPairing creates kiosk + kiosk_key
|
||||||
*/
|
*/
|
||||||
import { randomBytes } from "node:crypto";
|
import { randomBytes } from "node:crypto";
|
||||||
|
import type { Observable } from "@bsb/base";
|
||||||
import type { Repository } from "./db/repository.js";
|
import type { Repository } from "./db/repository.js";
|
||||||
import type { AuthApi } from "./auth.js";
|
import type { AuthApi } from "./auth.js";
|
||||||
import type { SecretsApi } from "./secrets.js";
|
import type { SecretsApi } from "./secrets.js";
|
||||||
|
|
@ -76,16 +77,17 @@ export interface PairingClaimResult {
|
||||||
export async function claimPairing(
|
export async function claimPairing(
|
||||||
repo: Repository,
|
repo: Repository,
|
||||||
code: string,
|
code: string,
|
||||||
|
obs?: Observable,
|
||||||
): Promise<PairingClaimResult> {
|
): Promise<PairingClaimResult> {
|
||||||
const pc = await repo.getPairingCode(code);
|
const pc = await repo.getPairingCode(code);
|
||||||
if (!pc) return { status: "pending" };
|
if (!pc) { obs?.log.debug("claim {code}: code not found", { code }); return { status: "pending" }; }
|
||||||
if (new Date(pc.expires_at) < new Date()) return { status: "pending" };
|
if (new Date(pc.expires_at) < new Date()) { obs?.log.debug("claim {code}: expired", { code }); return { status: "pending" }; }
|
||||||
if (!pc.consumed_at) return { status: "pending" };
|
if (!pc.consumed_at) { obs?.log.debug("claim {code}: not yet consumed", { code }); return { status: "pending" }; }
|
||||||
|
|
||||||
const extras = pc.extras as Record<string, unknown>;
|
const extras = pc.extras as Record<string, unknown>;
|
||||||
const kioskKey = extras["kiosk_key_plaintext"] as string | undefined;
|
const kioskKey = extras["kiosk_key_plaintext"] as string | undefined;
|
||||||
|
|
||||||
if (!kioskKey || !pc.consumed_by_kiosk_id) return { status: "pending" };
|
if (!kioskKey || !pc.consumed_by_kiosk_id) { obs?.log.warn("claim {code}: consumed but missing key/id", { code }); return { status: "pending" }; }
|
||||||
|
|
||||||
const kiosk = await repo.getKioskById(pc.consumed_by_kiosk_id);
|
const kiosk = await repo.getKioskById(pc.consumed_by_kiosk_id);
|
||||||
const clusterKey = extras["cluster_key"] as string | undefined;
|
const clusterKey = extras["cluster_key"] as string | undefined;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue