UNPKG

@n8n-plus/n8n-plus

Version:

n8n Workflow Automation Tool (plus edition)

191 lines 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LicenseManager = void 0; const constants_1 = require("@n8n/constants"); const node_crypto_1 = require("node:crypto"); const uuid_1 = require("uuid"); const UNLIMITED_LICENSE_QUOTA = -1; class LicenseManager { constructor(config) { this.config = config; this.MANUALLY_DISABLED_FEATURES = [ constants_1.LICENSE_FEATURES.API_DISABLED, constants_1.LICENSE_FEATURES.SHOW_NON_PROD_BANNER, ]; this.initialized = false; this.currentFeatures = Object.values(constants_1.LICENSE_FEATURES).reduce((features, feature) => { features[feature] = !this.MANUALLY_DISABLED_FEATURES.includes(feature); return features; }, {}); Object.values(constants_1.LICENSE_QUOTAS).forEach((quota) => { this.currentFeatures[quota] = UNLIMITED_LICENSE_QUOTA; }); this.currentFeatures.planName = 'n8n+'; const farFuture = new Date(); farFuture.setFullYear(farFuture.getFullYear() + 100); const deviceFingerprint = this.generateUUID(); const consumerId = this.generateUUID(); const renewalToken = this.generateSecureToken(); const managementJwt = this.generateJWT(); this.licenseCert = { consumerId, version: 1, tenantId: this.config.tenantId, renewalToken, deviceLock: false, deviceFingerprint, createdAt: new Date(), issuedAt: new Date(), expiresAt: farFuture, terminatesAt: farFuture, entitlements: [this.createEntitlement()], detachedEntitlementsCount: 0, managementJwt, isEphemeral: false, }; } generateUUID() { return (0, uuid_1.v4)(); } generateSecureToken() { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; for (let i = 0; i < 64; i++) { result += chars.charAt(Math.floor(Math.random() * chars.length)); } return `rt_${result}`; } generateJWT() { const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })) .toString('base64') .replace(/=/g, '') .replace(/\+/g, '-') .replace(/\//g, '_'); const payload = Buffer.from(JSON.stringify({ sub: this.generateUUID(), name: 'n8n Plus License', iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + 86400 * 365, })) .toString('base64') .replace(/=/g, '') .replace(/\+/g, '-') .replace(/\//g, '_'); const signatureChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; let signature = ''; for (let i = 0; i < 43; i++) { signature += signatureChars.charAt(Math.floor(Math.random() * signatureChars.length)); } return `${header}.${payload}.${signature}`; } get isInitialized() { return this.initialized; } createEntitlement() { const now = new Date(); const farFuture = new Date(); farFuture.setFullYear(farFuture.getFullYear() + 100); return { id: 'n8n-plus-' + this.generateUUID(), productId: 'n8n-plus-' + this.generateUUID(), productMetadata: { terms: { isMainPlan: true }, metadataKey1: 'n8n-plus', }, features: this.currentFeatures, featureOverrides: {}, validFrom: now, validTo: farFuture, isFloatable: false, }; } async initialize() { this.initialized = true; if (this.config.onFeatureChange) { await this.config.onFeatureChange(this.currentFeatures); } } async _doInitialization() { return await this.initialize(); } clearSingleTimer() { } setupRepeatingTimer() { return setTimeout(() => { }, 100000); } clearRepeatingTimer() { } async reload() { if (this.config.onFeatureChange) { await this.config.onFeatureChange(this.currentFeatures); } } async reset() { } async computeDeviceFingerprint() { return this.licenseCert.deviceFingerprint; } async activate(_reservationId, _eulaUri) { } async renew() { } hasCert() { return true; } isTerminated() { return false; } getExpiryDate() { const farFuture = new Date(); farFuture.setFullYear(farFuture.getFullYear() + 100); return farFuture; } getTerminationDate() { const farFuture = new Date(); farFuture.setFullYear(farFuture.getFullYear() + 100); return farFuture; } isValid() { return true; } hasFeatureEnabled(feature) { return this.currentFeatures[feature] === true; } getFeatureValue(feature) { return this.currentFeatures[feature]; } getFeatures() { return this.currentFeatures; } getCurrentEntitlements() { return [this.createEntitlement()]; } getManagementJwt() { return this.licenseCert.managementJwt; } async getCertStr() { return 'license-block'; } getConsumerId() { return this.licenseCert.consumerId; } isRenewalDue() { return false; } toString() { return `${this.currentFeatures.planName} License`; } getIssuerCert() { return new node_crypto_1.X509Certificate(''); } async clear() { } async shutdown() { } enableAutoRenewals() { } disableAutoRenewals() { } } exports.LicenseManager = LicenseManager; //# sourceMappingURL=license-manager.js.map