fase(17): licensing module with RSA validation
This commit is contained in:
51
dist/modules/licensing/domain/entities/License.js
vendored
Normal file
51
dist/modules/licensing/domain/entities/License.js
vendored
Normal 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;
|
||||
2
dist/modules/licensing/domain/ports/ILicenseValidator.js
vendored
Normal file
2
dist/modules/licensing/domain/ports/ILicenseValidator.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
43
dist/modules/licensing/domain/value-objects/FeatureEntitlement.js
vendored
Normal file
43
dist/modules/licensing/domain/value-objects/FeatureEntitlement.js
vendored
Normal 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;
|
||||
23
dist/modules/licensing/domain/value-objects/LicensePlan.js
vendored
Normal file
23
dist/modules/licensing/domain/value-objects/LicensePlan.js
vendored
Normal 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;
|
||||
Reference in New Issue
Block a user