diff --git a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.spec.ts b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.spec.ts index 888ec4ea7bb09..dc7f95d7b24fd 100644 --- a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.spec.ts +++ b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.spec.ts @@ -1,23 +1,21 @@ -import type { CloudVersionsResponse } from '@rocket.chat/server-cloud-communication'; +import type { SupportedVersions } from '@rocket.chat/server-cloud-communication'; import { supportedVersionsChooseLatest } from './supportedVersionsChooseLatest'; describe('supportedVersionsChooseLatest', () => { test('should return the latest version', async () => { - const versionFromLicense: CloudVersionsResponse = { + const versionFromLicense: SupportedVersions = { timestamp: '2021-08-31T18:00:00.000Z', - signed: 'license', versions: [], }; - const versionFromCloud: CloudVersionsResponse = { + const versionFromCloud: SupportedVersions = { timestamp: '2021-08-31T19:00:00.000Z', - signed: 'cloud', versions: [], }; const result = await supportedVersionsChooseLatest(versionFromLicense, versionFromCloud); - expect(result).toBe(versionFromCloud.signed); + expect(result.timestamp).toBe(versionFromCloud.timestamp); }); }); diff --git a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.ts b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.ts index 3ee89266c2758..ae9ceec69e171 100644 --- a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.ts +++ b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsChooseLatest.ts @@ -1,7 +1,7 @@ -import type { CloudVersionsResponse } from '@rocket.chat/server-cloud-communication'; +import type { SupportedVersions } from '@rocket.chat/server-cloud-communication'; -export const supportedVersionsChooseLatest = async (...tokens: (CloudVersionsResponse | undefined)[]) => { - const [token] = (tokens.filter(Boolean) as CloudVersionsResponse[]).sort((a, b) => { +export const supportedVersionsChooseLatest = async (...tokens: (SupportedVersions | undefined)[]) => { + const [token] = (tokens.filter(Boolean) as SupportedVersions[]).sort((a, b) => { return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime(); }); diff --git a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsToken.ts b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsToken.ts index 6aae9adc96009..b4138b3431a11 100644 --- a/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsToken.ts +++ b/apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsToken.ts @@ -1,10 +1,10 @@ import type { SettingValue } from '@rocket.chat/core-typings'; +import { License } from '@rocket.chat/license'; import { Settings } from '@rocket.chat/models'; -import type { CloudVersionsResponse } from '@rocket.chat/server-cloud-communication'; +import type { SupportedVersions } from '@rocket.chat/server-cloud-communication'; import type { Response } from '@rocket.chat/server-fetch'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; -import { supportedVersions } from '../../../../../ee/app/license/server/license'; import { SystemLogger } from '../../../../../server/lib/logger/system'; import { settings } from '../../../../settings/server'; import { generateWorkspaceBearerHttpHeader } from '../getWorkspaceAccessToken'; @@ -80,9 +80,17 @@ const cacheValueInSettings = ( /** CODE */ const getSupportedVersionsFromCloud = async () => { + if (process.env.CLOUD_SUPPORTED_VERSIONS_TOKEN) { + return { + success: true, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + result: JSON.parse(process.env.CLOUD_SUPPORTED_VERSIONS!), + }; + } + const headers = await generateWorkspaceBearerHttpHeader(); - const response = await handleResponse( + const response = await handleResponse( fetch('https://releases.rocket.chat/supported/server', { headers, }), @@ -107,9 +115,7 @@ const getSupportedVersionsToken = async () => { * return the token */ - const [versionsFromLicense, response] = await Promise.all([supportedVersions(), getSupportedVersionsFromCloud()]); - - // TODO: get values from jtw token + const [versionsFromLicense, response] = await Promise.all([License.supportedVersions(), getSupportedVersionsFromCloud()]); return supportedVersionsChooseLatest(versionsFromLicense, (response.success && response.result) || undefined); }; diff --git a/ee/packages/license/package.json b/ee/packages/license/package.json index f6a1e7a2b7d53..24ecdc30bc490 100644 --- a/ee/packages/license/package.json +++ b/ee/packages/license/package.json @@ -42,6 +42,7 @@ "dependencies": { "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/jwt": "workspace:^", - "@rocket.chat/logger": "workspace:^" + "@rocket.chat/logger": "workspace:^", + "@rocket.chat/server-cloud-communication": "workspace:^" } } diff --git a/ee/packages/license/src/definition/ILicenseV3.ts b/ee/packages/license/src/definition/ILicenseV3.ts index d3a2d7f572a37..e2a8bd424bb24 100644 --- a/ee/packages/license/src/definition/ILicenseV3.ts +++ b/ee/packages/license/src/definition/ILicenseV3.ts @@ -1,3 +1,5 @@ +import type { SignedSupportedVersions } from '@rocket.chat/server-cloud-communication'; + import type { ILicenseTag } from './ILicenseTag'; import type { LicenseLimit } from './LicenseLimit'; import type { LicenseModule } from './LicenseModule'; @@ -59,6 +61,8 @@ export interface ILicenseV3 { monthlyActiveContacts?: LicenseLimit[]; }; cloudMeta?: Record; + + supportedVersions?: SignedSupportedVersions; } export type LicenseLimitKind = keyof ILicenseV3['limits']; diff --git a/ee/packages/license/src/index.ts b/ee/packages/license/src/index.ts index 9dbd94db53edf..11cf3bbbe4c51 100644 --- a/ee/packages/license/src/index.ts +++ b/ee/packages/license/src/index.ts @@ -1,4 +1,4 @@ -import type { LicenseLimitKind } from './definition/ILicenseV3'; +import type { ILicenseV3, LicenseLimitKind } from './definition/ILicenseV3'; import type { LimitContext } from './definition/LimitContext'; import { getAppsConfig, getMaxActiveUsers, getUnmodifiedLicenseAndModules } from './deprecated'; import { onLicense } from './events/deprecated'; @@ -45,6 +45,8 @@ interface License { onInvalidateLicense: typeof onInvalidateLicense; onLimitReached: typeof onLimitReached; + supportedVersions(): ILicenseV3['supportedVersions']; + // Deprecated: onLicense: typeof onLicense; // Deprecated: @@ -56,6 +58,10 @@ interface License { } export class LicenseImp extends LicenseManager implements License { + supportedVersions() { + return this.getLicense()?.supportedVersions; + } + validateFormat = validateFormat; hasModule = hasModule; diff --git a/packages/server-cloud-communication/src/definitions/index.ts b/packages/server-cloud-communication/src/definitions/index.ts index 99ddcdbaa714d..d554aa5380594 100644 --- a/packages/server-cloud-communication/src/definitions/index.ts +++ b/packages/server-cloud-communication/src/definitions/index.ts @@ -35,15 +35,6 @@ export interface SupportedVersions { } // eslint-disable-next-line @typescript-eslint/naming-convention -export interface CloudVersionsResponse { +export interface SignedSupportedVersions extends SupportedVersions { signed: string; // SerializedJWT; - timestamp: string; - messages?: Message[]; - versions: Version[]; - exceptions?: { - domain: string; - uniqueId: string; - messages?: Message[]; - versions: Version[]; - }; } diff --git a/packages/server-cloud-communication/src/index.ts b/packages/server-cloud-communication/src/index.ts index def13791e8a15..a18306b926eb3 100644 --- a/packages/server-cloud-communication/src/index.ts +++ b/packages/server-cloud-communication/src/index.ts @@ -1,3 +1,3 @@ -import type { CloudVersionsResponse } from './definitions'; +import type { SupportedVersions, SignedSupportedVersions } from './definitions'; -export { CloudVersionsResponse }; +export { SupportedVersions, SignedSupportedVersions }; diff --git a/yarn.lock b/yarn.lock index 5bf3d65d6d9ba..368d87e88f053 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8472,6 +8472,7 @@ __metadata: "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/jwt": "workspace:^" "@rocket.chat/logger": "workspace:^" + "@rocket.chat/server-cloud-communication": "workspace:^" "@swc/core": ^1.3.66 "@swc/jest": ^0.2.26 "@types/babel__core": ^7