snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { SignedSupportedVersions } from '@rocket.chat/server-cloud-communication';
|
||||
|
||||
import { supportedVersionsChooseLatest } from './supportedVersionsChooseLatest';
|
||||
|
||||
describe('supportedVersionsChooseLatest', () => {
|
||||
test('should return the latest version', async () => {
|
||||
const versionFromLicense: SignedSupportedVersions = {
|
||||
signed: 'signed____',
|
||||
timestamp: '2021-08-31T18:00:00.000Z',
|
||||
versions: [],
|
||||
};
|
||||
|
||||
const versionFromCloud: SignedSupportedVersions = {
|
||||
signed: 'signed_------',
|
||||
timestamp: '2021-08-31T19:00:00.000Z',
|
||||
versions: [],
|
||||
};
|
||||
|
||||
const result = await supportedVersionsChooseLatest(versionFromLicense, versionFromCloud);
|
||||
|
||||
expect(result.timestamp).toBe(versionFromCloud.timestamp);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { SignedSupportedVersions } from '@rocket.chat/server-cloud-communication';
|
||||
|
||||
export const supportedVersionsChooseLatest = async (...tokens: (SignedSupportedVersions | undefined)[]) => {
|
||||
const [token] = (tokens.filter((r) => r?.timestamp != null) as SignedSupportedVersions[]).sort((a, b) => {
|
||||
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
|
||||
});
|
||||
|
||||
return token;
|
||||
};
|
||||
@@ -0,0 +1,208 @@
|
||||
import type { SettingValue } from '@rocket.chat/core-typings';
|
||||
import { License } from '@rocket.chat/license';
|
||||
import { Settings } from '@rocket.chat/models';
|
||||
import type { SignedSupportedVersions, 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 { supportedVersionsChooseLatest } from './supportedVersionsChooseLatest';
|
||||
import { supportedVersions as supportedVersionsFromBuild } from '../../../../app/utils/rocketchat-supported-versions.info';
|
||||
import { settings } from '../../../settings';
|
||||
import { updateAuditedBySystem } from '../../../settings/lib/auditedSettingUpdates';
|
||||
import { SystemLogger } from '../../logger/system';
|
||||
import { notifyOnSettingChangedById } from '../../notifyListener';
|
||||
import { generateWorkspaceBearerHttpHeader } from '../getWorkspaceAccessToken';
|
||||
import { buildVersionUpdateMessage } from '../version-check/functions/buildVersionUpdateMessage';
|
||||
|
||||
declare module '@rocket.chat/core-typings' {
|
||||
interface ILicenseV3 {
|
||||
supportedVersions?: SignedSupportedVersions;
|
||||
}
|
||||
}
|
||||
|
||||
/** HELPERS */
|
||||
|
||||
export const wrapPromise = <T>(
|
||||
promise: Promise<T>,
|
||||
): Promise<
|
||||
| {
|
||||
success: true;
|
||||
result: T;
|
||||
}
|
||||
| {
|
||||
success: false;
|
||||
error: any;
|
||||
}
|
||||
> =>
|
||||
promise
|
||||
.then((result) => ({ success: true, result }) as const)
|
||||
.catch((error) => ({
|
||||
success: false,
|
||||
error,
|
||||
}));
|
||||
|
||||
export const handleResponse = async <T>(promise: Promise<Response>) => {
|
||||
return wrapPromise<T>(
|
||||
(async () => {
|
||||
const request = await promise;
|
||||
if (!request.ok) {
|
||||
if (request.size > 0) {
|
||||
throw new Error((await request.json()).error);
|
||||
}
|
||||
throw new Error(request.statusText);
|
||||
}
|
||||
|
||||
return request.json();
|
||||
})(),
|
||||
);
|
||||
};
|
||||
|
||||
const cacheValueInSettings = <T extends SettingValue>(
|
||||
key: string,
|
||||
fn: (retry?: number) => Promise<T>,
|
||||
): (() => Promise<T>) & {
|
||||
reset: (retry?: number) => Promise<T>;
|
||||
} => {
|
||||
const reset = async (retry?: number) => {
|
||||
SystemLogger.debug({
|
||||
msg: 'Resetting cached value in settings',
|
||||
key,
|
||||
});
|
||||
const value = await fn(retry);
|
||||
|
||||
if (
|
||||
(
|
||||
await updateAuditedBySystem({
|
||||
reason: 'cacheValueInSettings reset',
|
||||
})(Settings.updateValueById, key, value)
|
||||
).modifiedCount
|
||||
) {
|
||||
void notifyOnSettingChangedById(key);
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
return Object.assign(
|
||||
async () => {
|
||||
const storedValue = settings.get<T>(key);
|
||||
|
||||
if (storedValue) {
|
||||
return storedValue;
|
||||
}
|
||||
|
||||
return reset();
|
||||
},
|
||||
{
|
||||
reset,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const releaseEndpoint = process.env.OVERWRITE_INTERNAL_RELEASE_URL?.trim()
|
||||
? process.env.OVERWRITE_INTERNAL_RELEASE_URL.trim()
|
||||
: 'https://releases.rocket.chat/v2/server/supportedVersions';
|
||||
|
||||
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();
|
||||
|
||||
// Re-validated at dispatch time: an offline license applied while this async
|
||||
// operation was in flight must still suppress the request.
|
||||
if (License.hasOfflineLicense()) {
|
||||
return { success: true, result: undefined } as const;
|
||||
}
|
||||
|
||||
const response = await handleResponse<SupportedVersions>(
|
||||
fetch(releaseEndpoint, {
|
||||
headers,
|
||||
timeout: 5000,
|
||||
// SECURITY: the URL is a default hardcoded value or an envvar set by an admin. It's safe to disable this check.
|
||||
ignoreSsrfValidation: true,
|
||||
}),
|
||||
);
|
||||
|
||||
if (!response.success) {
|
||||
SystemLogger.error({
|
||||
msg: 'Failed to communicate with Rocket.Chat Cloud',
|
||||
url: releaseEndpoint,
|
||||
err: response.error,
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
const getSupportedVersionsToken = async (retry = 0) => {
|
||||
/**
|
||||
* Gets the supported versions from the license
|
||||
* Gets the supported versions from the cloud
|
||||
* Gets the latest version
|
||||
* return the token
|
||||
*/
|
||||
const [versionsFromLicense, cloudResponse] = await Promise.all([
|
||||
License.getLicense(),
|
||||
License.hasOfflineLicense() ? ({ success: true, result: undefined } as const) : getSupportedVersionsFromCloud(),
|
||||
]);
|
||||
|
||||
const supportedVersions = await supportedVersionsChooseLatest(
|
||||
supportedVersionsFromBuild,
|
||||
versionsFromLicense?.supportedVersions,
|
||||
(cloudResponse.success && cloudResponse.result) || undefined,
|
||||
);
|
||||
|
||||
SystemLogger.debug({
|
||||
msg: 'Supported versions',
|
||||
supportedVersionsFromBuild: supportedVersionsFromBuild.timestamp,
|
||||
versionsFromLicense: versionsFromLicense?.supportedVersions?.timestamp,
|
||||
response: cloudResponse.success && cloudResponse.result?.timestamp,
|
||||
});
|
||||
|
||||
switch (supportedVersions) {
|
||||
case supportedVersionsFromBuild:
|
||||
SystemLogger.info({
|
||||
msg: 'Using supported versions from build',
|
||||
});
|
||||
break;
|
||||
case versionsFromLicense?.supportedVersions:
|
||||
SystemLogger.info({
|
||||
msg: 'Using supported versions from license',
|
||||
});
|
||||
break;
|
||||
case cloudResponse.success && cloudResponse.result:
|
||||
SystemLogger.info({
|
||||
msg: 'Using supported versions from cloud',
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// to avoid a possibly wrong message, we only send the message if the cloud response was successful
|
||||
if (cloudResponse.success) {
|
||||
await buildVersionUpdateMessage(supportedVersions?.versions);
|
||||
} else if (retry < 5) {
|
||||
// in case of failure we'll try again later
|
||||
setTimeout(
|
||||
async () => {
|
||||
await getCachedSupportedVersionsToken.reset(retry + 1);
|
||||
},
|
||||
5000 * Math.pow(2, retry),
|
||||
);
|
||||
} else {
|
||||
SystemLogger.error({
|
||||
msg: 'Failed to get supported versions from cloud after retries.',
|
||||
retry,
|
||||
});
|
||||
await buildVersionUpdateMessage(supportedVersions?.versions);
|
||||
}
|
||||
|
||||
return supportedVersions?.signed;
|
||||
};
|
||||
|
||||
export const getCachedSupportedVersionsToken = cacheValueInSettings('Cloud_Workspace_Supported_Versions_Token', getSupportedVersionsToken);
|
||||
Reference in New Issue
Block a user