feat: Filter out enterprise apps if there is no ee license

This commit is contained in:
Faruk AYDIN
2025-05-21 13:11:47 +02:00
parent 5df63654f9
commit 6b362b6643
2 changed files with 35 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep.js';
import addAuthenticationSteps from './add-authentication-steps.js';
import addReconnectionSteps from './add-reconnection-steps.js';
import { fileURLToPath, pathToFileURL } from 'url';
import { hasValidLicense } from './license.ee.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -13,9 +14,14 @@ const apps = fs
.reduce((apps, dirent) => {
if (!dirent.isDirectory()) return apps;
apps[dirent.name] = import(
pathToFileURL(join(__dirname, '../apps', dirent.name, 'index.js'))
);
const indexPath = join(__dirname, '../apps', dirent.name, 'index.js');
const indexEePath = join(__dirname, '../apps', dirent.name, 'index.ee.js');
if (fs.existsSync(indexEePath) && hasValidLicense()) {
apps[dirent.name] = import(pathToFileURL(indexEePath));
} else {
apps[dirent.name] = import(pathToFileURL(indexPath));
}
return apps;
}, {});
@@ -85,10 +91,8 @@ const addStaticSubsteps = (stepType, appData, step) => {
arguments: step.arguments,
});
}
computedStep.substeps.push(testStep(stepType));
return computedStep;
};
export default getApp;

View File

@@ -3,26 +3,45 @@ import path, { join } from 'path';
import { fileURLToPath } from 'url';
import appInfoConverter from '../helpers/app-info-converter.js';
import getApp from '../helpers/get-app.js';
import { hasValidLicense } from '../helpers/license.ee.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
class App {
static folderPath = join(__dirname, '../apps');
static list = fs
.readdirSync(this.folderPath)
.filter((file) => fs.statSync(join(this.folderPath, file)).isDirectory());
static async list() {
const directories = fs
.readdirSync(this.folderPath)
.filter((file) => fs.statSync(join(this.folderPath, file)).isDirectory());
if (!(await hasValidLicense())) {
// Filter out enterprise apps if no valid license
const nonEnterpriseApps = [];
for (const dir of directories) {
const appData = await getApp(dir, true);
if (!appData.enterprise) {
nonEnterpriseApps.push(dir);
}
}
return nonEnterpriseApps;
}
return directories;
}
static async findAll(name, stripFuncs = true) {
const appList = await this.list();
if (!name)
return Promise.all(
this.list.map(
async (name) => await this.findOneByName(name, stripFuncs)
)
appList.map(async (name) => await this.findOneByName(name, stripFuncs))
);
return Promise.all(
this.list
appList
.filter((app) => app.includes(name.toLowerCase()))
.map((name) => this.findOneByName(name, stripFuncs))
);