nook: surface per-license maxDevices in activate + status responses

This commit is contained in:
2026-08-27 09:26:14 -04:00
parent 082e503d4f
commit a161c96b05
2 changed files with 7 additions and 7 deletions

View File

@@ -68,7 +68,7 @@ export async function POST(event: APIEvent) {
args: [new Date().toISOString(), existing.id]
});
const count = await activeCount(conn, license.id);
return json({ ok: true, email: license.email, activatedCount: count });
return json({ ok: true, email: license.email, activatedCount: count, maxDevices: license.maxDevices });
}
const count = await activeCount(conn, license.id);
@@ -88,7 +88,7 @@ export async function POST(event: APIEvent) {
new Date().toISOString()
]
});
return json({ ok: true, email: license.email, activatedCount: count + 1 });
return json({ ok: true, email: license.email, activatedCount: count + 1, maxDevices: license.maxDevices });
}
async function activeCount(

View File

@@ -29,16 +29,16 @@ export async function POST(event: APIEvent) {
const conn = NookConnectionFactory();
const licenseRes = await conn.execute({
sql: "SELECT id, revoked FROM licenses WHERE key = ?",
sql: "SELECT id, revoked, max_devices FROM licenses WHERE key = ?",
args: [key]
});
if (licenseRes.rows.length === 0) {
return json({ state: "unknown_key", activatedCount: 0 });
return json({ state: "unknown_key", activatedCount: 0, maxDevices: 0 });
}
const license = licenseRes.rows[0] as { id: string; revoked: number };
const license = licenseRes.rows[0] as { id: string; revoked: number; maxDevices: number };
if (license.revoked === 1) {
return json({ state: "revoked", activatedCount: 0 });
return json({ state: "revoked", activatedCount: 0, maxDevices: 0 });
}
const countRes = await conn.execute({
@@ -47,5 +47,5 @@ export async function POST(event: APIEvent) {
});
const activatedCount = Number((countRes.rows[0] as { n: number | bigint }).n);
return json({ state: "valid", activatedCount });
return json({ state: "valid", activatedCount, maxDevices: license.maxDevices });
}