Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions ee/app/license/client/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions ee/app/license/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CachedCollectionManager } from '../../../../app/ui-cached-collection';
import { callMethod } from '../../../../app/ui-utils/client/lib/callMethod';

const allModules = new Promise<Set<string>>((resolve, reject) => {
CachedCollectionManager.onLogin(async () => {
try {
const features: string[] = await callMethod('license:getModules');
resolve(new Set(features));
} catch (e) {
console.error('Error getting modules', e);
reject(e);
}
});
});

export async function hasLicense(feature: string): Promise<boolean> {
try {
const features = await allModules;
return features.has(feature);
} catch (e) {
return false;
}
}
18 changes: 11 additions & 7 deletions ee/app/license/server/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { getBundleModules, isBundle } from './bundles';

const EnterpriseLicenses = new EventEmitter();

export interface IModules {
[key: string]: number;
}

export interface ILicense {
url: string;
expiry: string;
Expand All @@ -27,7 +23,7 @@ class LicenseClass {

private licenses: IValidLicense[] = [];

private modules: IModules = {};
private modules = new Set<string>();

_validateExpiration(expiration: string): boolean {
return new Date() > new Date(expiration);
Expand All @@ -49,7 +45,7 @@ class LicenseClass {
: [licenseModule];

modules.forEach((module) => {
this.modules[module] = 1;
this.modules.add(module);
EnterpriseLicenses.emit(`valid:${ module }`);
});
});
Expand Down Expand Up @@ -79,7 +75,11 @@ class LicenseClass {
}

hasModule(module: string): boolean {
return typeof this.modules[module] !== 'undefined';
return this.modules.has(module);
}

getModules(): string[] {
return [...this.modules];
}

setURL(url: string): void {
Expand Down Expand Up @@ -185,6 +185,10 @@ export function hasLicense(feature: string): boolean {
return License.hasModule(feature);
}

export function getModules(): string[] {
return License.getModules();
}

export function onLicense(feature: string, cb: (...args: any[]) => void): void {
if (hasLicense(feature)) {
return cb();
Expand Down
5 changes: 4 additions & 1 deletion ee/app/license/server/methods.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { hasLicense } from './license';
import { hasLicense, getModules } from './license';

Meteor.methods({
'license:hasLicense'(feature: string) {
check(feature, String);

return hasLicense(feature);
},
'license:getModules'() {
return getModules();
},
});