...
 
Commits (4)
{
"name": "@rocket.chat/apps-engine",
"version": "1.5.0",
"version": "1.5.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "@rocket.chat/apps-engine",
"version": "1.5.0",
"version": "1.5.2",
"description": "The engine code for the Rocket.Chat Apps which manages, runs, translates, coordinates and all of that.",
"main": "index",
"typings": "index",
......
This diff is collapsed.
......@@ -4,6 +4,7 @@ import { InvalidLicenseError } from '../errors';
import { IMarketplaceInfo } from '../marketplace';
import { AppLicenseValidationResult } from '../marketplace/license';
import { Crypto } from '../marketplace/license';
import { MarketplacePurchaseType } from '../marketplace/MarketplacePurchaseType';
enum LicenseVersion {
v1 = 1,
......@@ -18,27 +19,29 @@ export class AppLicenseManager {
}
public async validate(validationResult: AppLicenseValidationResult, appMarketplaceInfo?: IMarketplaceInfo): Promise<void> {
if (!appMarketplaceInfo || !appMarketplaceInfo.subscriptionInfo) {
if (!appMarketplaceInfo || appMarketplaceInfo.purchaseType !== MarketplacePurchaseType.PurchaseTypeSubscription) {
return;
}
validationResult.setValidated(true);
const { id: appId, subscriptionInfo } = appMarketplaceInfo;
const encryptedLicense = appMarketplaceInfo.subscriptionInfo.license.license;
if (!encryptedLicense) {
validationResult.addError('license', 'License for app is invalid');
throw new InvalidLicenseError(validationResult);
}
let license;
try {
license = await this.crypto.decryptLicense(subscriptionInfo.license.license) as any;
license = await this.crypto.decryptLicense(encryptedLicense) as any;
} catch (err) {
validationResult.addError('publicKey', err.message);
throw new InvalidLicenseError(validationResult);
}
if (license.appId !== appId) {
validationResult.addError('appId', `License hasn't been issued for this app`);
}
switch (license.version) {
case LicenseVersion.v1:
await this.validateV1(appMarketplaceInfo, license, validationResult);
......@@ -47,18 +50,24 @@ export class AppLicenseManager {
}
private async validateV1(appMarketplaceInfo: IMarketplaceInfo, license: any, validationResult: AppLicenseValidationResult): Promise<void> {
if (license.isBundle && (!appMarketplaceInfo.bundledIn || !appMarketplaceInfo.bundledIn.find((value) => value.bundleId === license.appId))) {
validationResult.addError('bundle', 'License issued for a bundle that does not contain the app');
} else if (!license.isBundle && license.appId !== appMarketplaceInfo.id) {
validationResult.addError('appId', `License hasn't been issued for this app`);
}
const renewal = new Date(license.renewalDate);
const expire = new Date(license.expireDate);
const now = new Date();
if (expire < now) {
validationResult.addError('expire', 'License is no longer valid');
validationResult.addError('expire', 'License is no longer valid and needs to be renewed');
}
const currentActiveUsers = await this.userBridge.getActiveUserCount();
if (license.maxSeats < currentActiveUsers) {
validationResult.addError('maxSeats', 'License does not accomodate the currently active users');
validationResult.addError('maxSeats', 'License does not accomodate the current amount of active users. Please increase the number of seats');
}
if (validationResult.hasErrors) {
......@@ -72,9 +81,7 @@ export class AppLicenseManager {
if (license.seats < currentActiveUsers) {
validationResult.addWarning(
'seats',
`The license for the app "${
appMarketplaceInfo.name
}" does not have enough seats to accommodate the current amount of active users. Please increase the number of seats`,
'License does not have enough seats to accommodate the current amount of active users. Please increase the number of seats',
);
}
}
......
......@@ -17,7 +17,7 @@ export interface IMarketplaceInfo extends IAppInfo {
modifiedDate: string;
price: number;
subscriptionInfo?: IMarketplaceSubscriptionInfo;
puchaseType: MarketplacePurchaseType;
purchaseType: MarketplacePurchaseType;
pricingPlans?: Array<IMarketplacePricingPlan>;
bundledIn?: Array<IMarketplaceSimpleBundleInfo>;
}