From 5e77de1202675c9abe17ea0bbe9ebf552a0a61b9 Mon Sep 17 00:00:00 2001 From: Padreug Date: Wed, 27 May 2026 17:04:53 +0200 Subject: [PATCH] fix: convert policyId to Int before Prisma insert in create_new_token MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wire-level `create_new_token` RPC carries `policyId` as a string (everything in NDK RPC params is string). The handler correctly parseInts it for the `findUnique({where:{id:parseInt(policyId)}})` call but then forwards the unparsed string straight into the Prisma `token.create({data:{...policyId}})` payload. Prisma rejects with "Argument `policyId`: Invalid value provided. Expected Int or Null, provided String" because `Token.policyId` is declared `Int` per the schema (references `Policy.id`, which is autoincrement Int). Hoist `policyIdInt = parseInt(policyId)` and use it for both the findUnique lookup and the create payload. Latent upstream bug — no one would have seen it before because the wrong-kind error response (fixed in the previous commit) made the symptom look like a transport timeout rather than a Prisma validation error. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/daemon/admin/commands/create_new_token.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/daemon/admin/commands/create_new_token.ts b/src/daemon/admin/commands/create_new_token.ts index df145a2..04588c4 100644 --- a/src/daemon/admin/commands/create_new_token.ts +++ b/src/daemon/admin/commands/create_new_token.ts @@ -7,15 +7,19 @@ export default async function createNewToken(admin: AdminInterface, req: NDKRpcR if (!clientName || !policyId) throw new Error("Invalid params"); - const policy = await prisma.policy.findUnique({ where: { id: parseInt(policyId) }, include: { rules: true } }); + const policyIdInt = parseInt(policyId); + const policy = await prisma.policy.findUnique({ where: { id: policyIdInt }, include: { rules: true } }); if (!policy) throw new Error("Policy not found"); console.log({clientName, policy, durationInHours}); const token = [...Array(64)].map(() => Math.floor(Math.random() * 16).toString(16)).join(''); + // policyId must be Int per the Prisma schema (Token.policyId references + // Policy.id which is autoincrement Int). Upstream passes the raw string + // from the wire — caught during aiolabs/nsecbunkerd#7 diagnosis 2026-05-27. const data: any = { - keyName, clientName, policyId, + keyName, clientName, policyId: policyIdInt, createdBy: req.pubkey, token };