const PLAN_PRESETS = {
basic: { plan: "basic", maxProjects: 3 },
pro: { plan: "pro", maxProjects: 10, features: "export,api" },
enterprise: {
plan: "enterprise",
maxProjects: 50,
features: "export,api,priority-support,sso",
},
};
async function createTieredLicense(appId, plan, label) {
// Create the license
const createRes = await fetch("https://api.authforge.cc/v1/licenses", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.AUTHFORGE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
appId,
quantity: 1,
maxHwidSlots: plan === "enterprise" ? 5 : 1,
label,
}),
});
const { licenses } = await createRes.json();
const licenseKey = licenses[0].licenseKey;
// Set tier variables
await fetch(
`https://api.authforge.cc/v1/licenses/${licenseKey}/variables`,
{
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.AUTHFORGE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(PLAN_PRESETS[plan]),
}
);
return licenseKey;
}