fix(licensing): resolve Admiral variant detection and lifetime license handling (#376)

* fix(licensing): resolve Admiral variant detection and lifetime license handling

The Lemon Squeezy variant name for Admiral licenses contains "Admiral"
(not "Team"), but getVariant() only checked for "team" and "personal".
This caused Admiral licenses to be misidentified as Skipper, locking all
Admiral-exclusive features.

- Map "admiral" variant names to internal "team" value, "skipper" to "personal"
- Add isLifetime field to LicenseInfo API response
- Hide "Manage Subscription" button for lifetime licenses (no billing portal)
- Show "Duration: Lifetime" instead of empty renewal date
- Hide upgrade cards for active Admiral users
- Add 23 unit tests covering variant resolution, tier computation, and lifetime detection
- Add troubleshooting entries for wrong tier label, locked features, and billing portal errors

* fix(licensing): address code review findings

- Fix nested ternary in LicenseSection JSX; restore conditional rendering
  to avoid showing an empty "N/A" row for non-subscription states
- Clean up test file: use shared svc variable, remove redundant comments,
  add trialDaysRemaining assertions, rename describe block
This commit is contained in:
Anso
2026-04-05 07:00:21 -04:00
committed by GitHub
parent f516275834
commit f841c402b2
8 changed files with 310 additions and 22 deletions
+10 -3
View File
@@ -33,6 +33,7 @@ export interface LicenseInfo {
trialDaysRemaining: number | null;
instanceId: string;
portalUrl: string | null;
isLifetime: boolean;
}
/** Seat limits per variant. null = unlimited. */
@@ -194,7 +195,9 @@ export class LicenseService {
/**
* Get the license variant (personal or team) from stored metadata.
* Trial licenses default to "personal" - Admiral features require an Admiral license.
* Trial licenses default to "personal"; Admiral features require an Admiral license.
* Maps Lemon Squeezy variant names (which may use brand names like "Admiral"
* or "Skipper") to the internal 'team' or 'personal' values.
*/
public getVariant(): LicenseVariant {
const db = DatabaseService.getInstance();
@@ -203,8 +206,8 @@ export class LicenseService {
const variantName = db.getSystemState('license_variant_name');
if (!variantName) return null;
const lower = variantName.toLowerCase();
if (lower.includes('team')) return 'team';
if (lower.includes('personal')) return 'personal';
if (lower.includes('team') || lower.includes('admiral')) return 'team';
if (lower.includes('personal') || lower.includes('skipper')) return 'personal';
return 'personal'; // default activated licenses to personal
}
@@ -233,6 +236,9 @@ export class LicenseService {
trialDaysRemaining = Math.max(0, Math.ceil(remaining));
}
// Lifetime license: active with a stored key but no expiry date
const isLifetime = status === 'active' && !!key && !validUntil;
return {
tier: this.getTier(),
status,
@@ -244,6 +250,7 @@ export class LicenseService {
trialDaysRemaining,
instanceId,
portalUrl: db.getSystemState('billing_portal_url') || db.getSystemState('customer_portal_url') || null,
isLifetime,
};
}