const res = await fetch("https://api.opentype.dev/v1/keys", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENTYPE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "ticket-triage-worker",
scopes: ["runs_write", "runs_read"],
principal: { type: "service_account", id: "ticket-triage-worker" },
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
// Store body.secret now; it is shown only once.
console.log(body.id, body.principal);