Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Dec 7, 2023
1 parent f1013a3 commit 2db46e9
Show file tree
Hide file tree
Showing 29 changed files with 235 additions and 215 deletions.
2 changes: 1 addition & 1 deletion ee/packages/ddp-client/src/types/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import type {
ILivechatAgent,
IImportProgress,
IBanner,
LicenseLimitKind,
} from '@rocket.chat/core-typings';
import type { LicenseLimitKind } from '@rocket.chat/license';
import type * as UiKit from '@rocket.chat/ui-kit';

type ClientAction = 'inserted' | 'updated' | 'removed' | 'changed';
Expand Down
5 changes: 1 addition & 4 deletions ee/packages/license/src/definition/ILicenseTag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export interface ILicenseTag {
name: string;
color: string;
}
export { ILicenseTag } from '@rocket.chat/core-typings';
23 changes: 1 addition & 22 deletions ee/packages/license/src/definition/ILicenseV2.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
import type { ILicenseTag } from './ILicenseTag';

export interface ILicenseV2 {
url: string;
expiry: string;
maxActiveUsers: number;
modules: string[];
maxGuestUsers: number;
maxRoomsPerGuest: number;
tag?: ILicenseTag;
meta?: {
trial: boolean;
trialEnd: string;
workspaceId: string;
};
apps?: {
maxPrivateApps: number;
maxMarketplaceApps: number;
};
}

export type LicenseAppSources = 'private' | 'marketplace';
export { ILicenseV2, LicenseAppSources } from '@rocket.chat/core-typings';
66 changes: 1 addition & 65 deletions ee/packages/license/src/definition/ILicenseV3.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1 @@
import type { ILicenseTag } from './ILicenseTag';
import type { LicenseLimit } from './LicenseLimit';
import type { LicenseModule } from './LicenseModule';
import type { LicensePeriod, Timestamp } from './LicensePeriod';

export interface ILicenseV3 {
version: '3.0';
information: {
id?: string;
autoRenew: boolean;
visualExpiration?: Timestamp;
notifyAdminsAt?: Timestamp;
notifyUsersAt?: Timestamp;
trial: boolean;
cancellable?: boolean;
offline: boolean;
createdAt: Timestamp;
grantedBy: {
method: 'manual' | 'self-service' | 'sales' | 'support' | 'reseller';
seller?: string;
};
grantedTo?: {
name?: string;
company?: string;
email?: string;
};
legalText?: string;
notes?: string;
tags?: ILicenseTag[];
};
validation: {
serverUrls: {
value: string;
type: 'url' | 'regex' | 'hash';
}[];
serverVersions?: {
value: string;
}[];
serverUniqueId?: string;
cloudWorkspaceId?: string;
validPeriods: LicensePeriod[];
legalTextAgreement?: {
type: 'required' | 'not-required' | 'accepted';
acceptedVia?: 'cloud';
};
statisticsReport: {
required: boolean;
allowedStaleInDays?: number;
};
};
grantedModules: {
module: LicenseModule;
}[];
limits: {
activeUsers?: LicenseLimit[];
guestUsers?: LicenseLimit[];
roomsPerGuest?: LicenseLimit<'prevent_action'>[];
privateApps?: LicenseLimit[];
marketplaceApps?: LicenseLimit[];
monthlyActiveContacts?: LicenseLimit[];
};
cloudMeta?: Record<string, any>;
}

export type LicenseLimitKind = keyof ILicenseV3['limits'];
export { ILicenseV3, LicenseLimitKind } from '@rocket.chat/core-typings';
24 changes: 1 addition & 23 deletions ee/packages/license/src/definition/LicenseBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
import type { LicenseLimitKind } from './ILicenseV3';
import type { LicenseModule } from './LicenseModule';

export type LicenseBehavior =
| 'invalidate_license'
| 'start_fair_policy'
| 'prevent_action'
| 'allow_action'
| 'prevent_installation'
| 'disable_modules';

export type BehaviorWithContext =
| {
behavior: LicenseBehavior;
modules?: LicenseModule[];
reason: 'limit';
limit?: LicenseLimitKind;
}
| {
behavior: LicenseBehavior;
modules?: LicenseModule[];
reason: 'period' | 'url';
};
export { LicenseBehavior, BehaviorWithContext } from '@rocket.chat/core-typings';
13 changes: 1 addition & 12 deletions ee/packages/license/src/definition/LicenseInfo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import type { ILicenseTag } from './ILicenseTag';
import type { ILicenseV3, LicenseLimitKind } from './ILicenseV3';
import type { LicenseModule } from './LicenseModule';

export type LicenseInfo = {
license?: ILicenseV3;
activeModules: LicenseModule[];
preventedActions: Record<LicenseLimitKind, boolean>;
limits: Record<LicenseLimitKind, { value?: number; max: number }>;
tags: ILicenseTag[];
trial: boolean;
};
export { LicenseInfo } from '@rocket.chat/core-typings';
8 changes: 1 addition & 7 deletions ee/packages/license/src/definition/LicenseLimit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import type { LicenseBehavior } from './LicenseBehavior';
import type { LicenseModule } from './LicenseModule';

export type LicenseLimit<T extends LicenseBehavior = LicenseBehavior> = {
max: number;
behavior: T;
} & (T extends 'disable_modules' ? { behavior: T; modules: LicenseModule[] } : { behavior: T });
export { LicenseLimit } from '@rocket.chat/core-typings';
22 changes: 1 addition & 21 deletions ee/packages/license/src/definition/LicenseModule.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
export type LicenseModule =
| 'auditing'
| 'canned-responses'
| 'ldap-enterprise'
| 'livechat-enterprise'
| 'voip-enterprise'
| 'omnichannel-mobile-enterprise'
| 'engagement-dashboard'
| 'push-privacy'
| 'scalability'
| 'teams-mention'
| 'saml-enterprise'
| 'oauth-enterprise'
| 'device-management'
| 'federation'
| 'videoconference-enterprise'
| 'message-read-receipt'
| 'outlook-calendar'
| 'hide-watermark'
| 'custom-roles'
| 'accessibility-certification';
export { LicenseModule } from '@rocket.chat/core-typings';
14 changes: 1 addition & 13 deletions ee/packages/license/src/definition/LicensePeriod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
import type { LicenseBehavior } from './LicenseBehavior';
import type { LicenseModule } from './LicenseModule';

export type Timestamp = string;

export type LicensePeriod = {
validFrom?: Timestamp;
validUntil?: Timestamp;
invalidBehavior: LicenseBehavior;
} & ({ validFrom: Timestamp } | { validUntil: Timestamp }) &
({ invalidBehavior: 'disable_modules'; modules: LicenseModule[] } | { invalidBehavior: Exclude<LicenseBehavior, 'disable_modules'> });

export type LicensePeriodBehavior = Exclude<LicenseBehavior, 'prevent_action'>;
export { LicensePeriod, LicensePeriodBehavior, Timestamp } from '@rocket.chat/core-typings';
13 changes: 1 addition & 12 deletions ee/packages/license/src/definition/LicenseValidationOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import type { LicenseLimitKind } from './ILicenseV3';
import type { LicenseBehavior } from './LicenseBehavior';
import type { LimitContext } from './LimitContext';

export type LicenseValidationOptions = {
behaviors?: LicenseBehavior[];
limits?: LicenseLimitKind[];
suppressLog?: boolean;
isNewLicense?: boolean;
context?: Partial<{ [K in LicenseLimitKind]: Partial<LimitContext<LicenseLimitKind>> }>;
triggerSync?: boolean;
};
export { LicenseValidationOptions } from '@rocket.chat/core-typings';
8 changes: 1 addition & 7 deletions ee/packages/license/src/definition/LimitContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import type { IUser } from '@rocket.chat/core-typings';

import type { LicenseLimitKind } from './ILicenseV3';

export type LimitContext<T extends LicenseLimitKind> = { extraCount?: number } & (T extends 'roomsPerGuest'
? { userId: IUser['_id'] }
: Record<string, never>);
export { LimitContext } from '@rocket.chat/core-typings';
25 changes: 1 addition & 24 deletions ee/packages/license/src/definition/events.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
import type { LicenseLimitKind } from './ILicenseV3';
import type { BehaviorWithContext, LicenseBehavior } from './LicenseBehavior';
import type { LicenseModule } from './LicenseModule';

type ModuleValidation = Record<`${'invalid' | 'valid'}:${LicenseModule}`, undefined>;
type BehaviorTriggered = Record<`behavior:${LicenseBehavior}`, { reason: BehaviorWithContext['reason']; limit?: LicenseLimitKind }>;
type BehaviorTriggeredToggled = Record<
`behaviorToggled:${LicenseBehavior}`,
{ reason: BehaviorWithContext['reason']; limit?: LicenseLimitKind }
>;

type LimitReached = Record<`limitReached:${LicenseLimitKind}`, undefined>;

export type LicenseEvents = ModuleValidation &
BehaviorTriggeredToggled &
BehaviorTriggered &
LimitReached & {
installed: undefined;
removed: undefined;
validate: undefined;
invalidate: undefined;
module: { module: LicenseModule; valid: boolean };
sync: undefined;
};
export { LicenseEvents } from '@rocket.chat/core-typings';
2 changes: 1 addition & 1 deletion packages/core-services/src/events/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import type {
ILivechatAgent,
IBanner,
ILivechatVisitor,
LicenseLimitKind,
} from '@rocket.chat/core-typings';
import type { LicenseLimitKind } from '@rocket.chat/license';
import type * as UiKit from '@rocket.chat/ui-kit';

import type { AutoUpdateRecord } from '../types/IMeteor';
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './IRocketChatAssets';
export * from './IPushToken';
export * from './IPushNotificationConfig';
export * from './SlashCommands';
export * from './license';

export * from './IUserDataFile';
export * from './IUserSession';
Expand Down
4 changes: 4 additions & 0 deletions packages/core-typings/src/license/ILicenseTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ILicenseTag {
name: string;
color: string;
}
22 changes: 22 additions & 0 deletions packages/core-typings/src/license/ILicenseV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { ILicenseTag } from './ILicenseTag';

export interface ILicenseV2 {
url: string;
expiry: string;
maxActiveUsers: number;
modules: string[];
maxGuestUsers: number;
maxRoomsPerGuest: number;
tag?: ILicenseTag;
meta?: {
trial: boolean;
trialEnd: string;
workspaceId: string;
};
apps?: {
maxPrivateApps: number;
maxMarketplaceApps: number;
};
}

export type LicenseAppSources = 'private' | 'marketplace';
65 changes: 65 additions & 0 deletions packages/core-typings/src/license/ILicenseV3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { ILicenseTag } from './ILicenseTag';
import type { LicenseLimit } from './LicenseLimit';
import type { LicenseModule } from './LicenseModule';
import type { LicensePeriod, Timestamp } from './LicensePeriod';

export interface ILicenseV3 {
version: '3.0';
information: {
id?: string;
autoRenew: boolean;
visualExpiration?: Timestamp;
notifyAdminsAt?: Timestamp;
notifyUsersAt?: Timestamp;
trial: boolean;
cancellable?: boolean;
offline: boolean;
createdAt: Timestamp;
grantedBy: {
method: 'manual' | 'self-service' | 'sales' | 'support' | 'reseller';
seller?: string;
};
grantedTo?: {
name?: string;
company?: string;
email?: string;
};
legalText?: string;
notes?: string;
tags?: ILicenseTag[];
};
validation: {
serverUrls: {
value: string;
type: 'url' | 'regex' | 'hash';
}[];
serverVersions?: {
value: string;
}[];
serverUniqueId?: string;
cloudWorkspaceId?: string;
validPeriods: LicensePeriod[];
legalTextAgreement?: {
type: 'required' | 'not-required' | 'accepted';
acceptedVia?: 'cloud';
};
statisticsReport: {
required: boolean;
allowedStaleInDays?: number;
};
};
grantedModules: {
module: LicenseModule;
}[];
limits: {
activeUsers?: LicenseLimit[];
guestUsers?: LicenseLimit[];
roomsPerGuest?: LicenseLimit<'prevent_action'>[];
privateApps?: LicenseLimit[];
marketplaceApps?: LicenseLimit[];
monthlyActiveContacts?: LicenseLimit[];
};
cloudMeta?: Record<string, any>;
}

export type LicenseLimitKind = keyof ILicenseV3['limits'];
23 changes: 23 additions & 0 deletions packages/core-typings/src/license/LicenseBehavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { LicenseLimitKind } from './ILicenseV3';
import type { LicenseModule } from './LicenseModule';

export type LicenseBehavior =
| 'invalidate_license'
| 'start_fair_policy'
| 'prevent_action'
| 'allow_action'
| 'prevent_installation'
| 'disable_modules';

export type BehaviorWithContext =
| {
behavior: LicenseBehavior;
modules?: LicenseModule[];
reason: 'limit';
limit?: LicenseLimitKind;
}
| {
behavior: LicenseBehavior;
modules?: LicenseModule[];
reason: 'period' | 'url';
};
12 changes: 12 additions & 0 deletions packages/core-typings/src/license/LicenseInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { ILicenseTag } from './ILicenseTag';
import type { ILicenseV3, LicenseLimitKind } from './ILicenseV3';
import type { LicenseModule } from './LicenseModule';

export type LicenseInfo = {
license?: ILicenseV3;
activeModules: LicenseModule[];
preventedActions: Record<LicenseLimitKind, boolean>;
limits: Record<LicenseLimitKind, { value?: number; max: number }>;
tags: ILicenseTag[];
trial: boolean;
};
7 changes: 7 additions & 0 deletions packages/core-typings/src/license/LicenseLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { LicenseBehavior } from './LicenseBehavior';
import type { LicenseModule } from './LicenseModule';

export type LicenseLimit<T extends LicenseBehavior = LicenseBehavior> = {
max: number;
behavior: T;
} & (T extends 'disable_modules' ? { behavior: T; modules: LicenseModule[] } : { behavior: T });
Loading

0 comments on commit 2db46e9

Please sign in to comment.