fase(17): licensing module with RSA validation

This commit is contained in:
debian
2026-03-08 05:20:54 -04:00
parent 1f1678af17
commit 5a28270dc9
45 changed files with 1789 additions and 48 deletions

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.License = void 0;
const Entity_1 = require("../../../../shared/domain/Entity");
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
const LicensePlan_1 = require("../value-objects/LicensePlan");
const FeatureEntitlement_1 = require("../value-objects/FeatureEntitlement");
class License extends Entity_1.Entity {
static createFree() {
return new License({
plan: LicensePlan_1.LicensePlan.free(),
organizationName: 'Community',
email: '',
expiresAt: null,
issuedAt: new Date(),
signature: 'free',
rawKey: 'free',
}, UniqueId_1.UniqueId.create());
}
static reconstitute(props, id) {
return new License(props, id);
}
get plan() { return this.props.plan; }
get organizationName() { return this.props.organizationName; }
get email() { return this.props.email; }
get expiresAt() { return this.props.expiresAt; }
get issuedAt() { return this.props.issuedAt; }
get signature() { return this.props.signature; }
get rawKey() { return this.props.rawKey; }
get isExpired() {
if (!this.props.expiresAt)
return false;
return this.props.expiresAt < new Date();
}
get isValid() {
return !this.isExpired;
}
getEntitlements() {
if (!this.isValid)
return FeatureEntitlement_1.FeatureEntitlement.forFeatures(FeatureEntitlement_1.FREE_FEATURES);
if (this.props.plan.isEnterprise)
return FeatureEntitlement_1.FeatureEntitlement.forFeatures(FeatureEntitlement_1.ENTERPRISE_FEATURES);
if (this.props.plan.isPro)
return FeatureEntitlement_1.FeatureEntitlement.forFeatures(FeatureEntitlement_1.PRO_FEATURES);
return FeatureEntitlement_1.FeatureEntitlement.forFeatures(FeatureEntitlement_1.FREE_FEATURES);
}
hasFeature(feature) {
return this.getEntitlements().has(feature);
}
}
exports.License = License;

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureEntitlement = exports.ENTERPRISE_FEATURES = exports.PRO_FEATURES = exports.FREE_FEATURES = void 0;
exports.FREE_FEATURES = [
'exploration:basic',
'findings:basic',
'findings:export',
'reports:basic',
'auth:apikeys',
];
exports.PRO_FEATURES = [
...exports.FREE_FEATURES,
'exploration:scheduled',
'reports:pdf',
'integrations:webhook',
'integrations:slack',
'integrations:github',
'integrations:jira',
];
exports.ENTERPRISE_FEATURES = [
...exports.PRO_FEATURES,
'auth:sso',
'auth:ldap',
'audit:logs',
'branding:whitelabel',
'data:retention',
'infra:postgres',
];
class FeatureEntitlement {
constructor(features) {
this.features = features;
}
static forFeatures(features) {
return new FeatureEntitlement(new Set(features));
}
has(feature) {
return this.features.has(feature);
}
toArray() {
return Array.from(this.features);
}
}
exports.FeatureEntitlement = FeatureEntitlement;

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LicensePlan = void 0;
class LicensePlan {
constructor(value) {
this.value = value;
}
static free() { return new LicensePlan('free'); }
static pro() { return new LicensePlan('pro'); }
static enterprise() { return new LicensePlan('enterprise'); }
static fromString(value) {
if (value === 'free' || value === 'pro' || value === 'enterprise') {
return new LicensePlan(value);
}
throw new Error(`Invalid license plan: ${value}`);
}
get isFree() { return this.value === 'free'; }
get isPro() { return this.value === 'pro'; }
get isEnterprise() { return this.value === 'enterprise'; }
toString() { return this.value; }
equals(other) { return this.value === other.value; }
}
exports.LicensePlan = LicensePlan;