fix: some details on supported versions (#5284)
* Ignore patches * Fix null versions find * Fix cloud request * Fix inverted date comparison to trigger action sheet
This commit is contained in:
parent
18b77ab4d6
commit
f1b7cfe510
|
@ -120,6 +120,27 @@ jest.useFakeTimers('modern');
|
||||||
jest.setSystemTime(new Date(TODAY));
|
jest.setSystemTime(new Date(TODAY));
|
||||||
|
|
||||||
describe('checkSupportedVersions', () => {
|
describe('checkSupportedVersions', () => {
|
||||||
|
describe('General', () => {
|
||||||
|
test('ignore the patch and compare as minor', () => {
|
||||||
|
expect(
|
||||||
|
checkSupportedVersions({
|
||||||
|
supportedVersions: MOCK,
|
||||||
|
serverVersion: '1.5.1'
|
||||||
|
})
|
||||||
|
).toMatchObject({
|
||||||
|
status: 'supported'
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
checkSupportedVersions({
|
||||||
|
supportedVersions: MOCK,
|
||||||
|
serverVersion: '1.2.1'
|
||||||
|
})
|
||||||
|
).toMatchObject({
|
||||||
|
status: 'expired'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Built-in supported versions', () => {
|
describe('Built-in supported versions', () => {
|
||||||
test('no supported versions', () => {
|
test('no supported versions', () => {
|
||||||
expect(checkSupportedVersions({ supportedVersions: undefined, serverVersion: '1.5.0' })).toMatchObject({
|
expect(checkSupportedVersions({ supportedVersions: undefined, serverVersion: '1.5.0' })).toMatchObject({
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import coerce from 'semver/functions/coerce';
|
import coerce from 'semver/functions/coerce';
|
||||||
|
import satisfies from 'semver/functions/satisfies';
|
||||||
|
|
||||||
import { ISupportedVersionsData, TSVDictionary, TSVMessage, TSVStatus } from '../../definitions';
|
import { ISupportedVersionsData, TSVDictionary, TSVMessage, TSVStatus } from '../../definitions';
|
||||||
import builtInSupportedVersions from '../../../app-supportedversions.json';
|
import builtInSupportedVersions from '../../../app-supportedversions.json';
|
||||||
|
@ -40,6 +41,7 @@ export const checkSupportedVersions = function ({
|
||||||
i18n?: TSVDictionary;
|
i18n?: TSVDictionary;
|
||||||
expiration?: string;
|
expiration?: string;
|
||||||
} {
|
} {
|
||||||
|
const serverVersionTilde = `~${serverVersion.split('.').slice(0, 2).join('.')}`;
|
||||||
let sv: ISupportedVersionsData;
|
let sv: ISupportedVersionsData;
|
||||||
if (!supportedVersions || supportedVersions.timestamp < builtInSupportedVersions.timestamp) {
|
if (!supportedVersions || supportedVersions.timestamp < builtInSupportedVersions.timestamp) {
|
||||||
// Built-in supported versions
|
// Built-in supported versions
|
||||||
|
@ -49,7 +51,7 @@ export const checkSupportedVersions = function ({
|
||||||
sv = supportedVersions;
|
sv = supportedVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionInfo = sv.versions.find(({ version }) => coerce(version)?.version === serverVersion);
|
const versionInfo = sv.versions.find(({ version }) => satisfies(coerce(version)?.version ?? '', serverVersionTilde));
|
||||||
if (versionInfo && new Date(versionInfo.expiration) >= new Date()) {
|
if (versionInfo && new Date(versionInfo.expiration) >= new Date()) {
|
||||||
const messages = versionInfo?.messages || sv?.messages;
|
const messages = versionInfo?.messages || sv?.messages;
|
||||||
const message = getMessage({ messages, expiration: versionInfo.expiration });
|
const message = getMessage({ messages, expiration: versionInfo.expiration });
|
||||||
|
@ -62,7 +64,7 @@ export const checkSupportedVersions = function ({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions
|
// Exceptions
|
||||||
const exception = sv.exceptions?.versions.find(({ version }) => coerce(version)?.version === serverVersion);
|
const exception = sv.exceptions?.versions?.find(({ version }) => satisfies(coerce(version)?.version ?? '', serverVersionTilde));
|
||||||
const messages = exception?.messages || sv.exceptions?.messages || versionInfo?.messages || sv.messages;
|
const messages = exception?.messages || sv.exceptions?.messages || versionInfo?.messages || sv.messages;
|
||||||
const message = getMessage({ messages, expiration: exception?.expiration });
|
const message = getMessage({ messages, expiration: exception?.expiration });
|
||||||
const status = getStatus({ expiration: exception?.expiration, message });
|
const status = getStatus({ expiration: exception?.expiration, message });
|
||||||
|
|
|
@ -57,7 +57,7 @@ export async function getServerInfo(server: string): Promise<TServerInfoResult>
|
||||||
|
|
||||||
// if backend doesn't have supported versions or JWT is invalid, request from cloud
|
// if backend doesn't have supported versions or JWT is invalid, request from cloud
|
||||||
if (!supportedVersions) {
|
if (!supportedVersions) {
|
||||||
const cloudInfo = await getCloudInfo();
|
const cloudInfo = await getCloudInfo(server);
|
||||||
|
|
||||||
// Makes use of signed JWT to get supported versions
|
// Makes use of signed JWT to get supported versions
|
||||||
const supportedVersionsCloud = verifyJWT(cloudInfo?.signed);
|
const supportedVersionsCloud = verifyJWT(cloudInfo?.signed);
|
||||||
|
@ -96,9 +96,14 @@ export async function getServerInfo(server: string): Promise<TServerInfoResult>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCloudInfo = async (): Promise<TCloudInfo | null> => {
|
const getUniqueId = async (server: string): Promise<string> => {
|
||||||
const uniqueId = store.getState().settings.uniqueID as string;
|
const response = await fetch(`${server}/api/v1/settings.public?query={"_id": "uniqueID"}`);
|
||||||
const domain = store.getState().server.server;
|
const result = await response.json();
|
||||||
|
return result?.settings?.[0]?.value;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCloudInfo = async (domain: string): Promise<TCloudInfo | null> => {
|
||||||
|
const uniqueId = await getUniqueId(domain);
|
||||||
const response = await getSupportedVersionsCloud(uniqueId, domain);
|
const response = await getSupportedVersionsCloud(uniqueId, domain);
|
||||||
return response.json() as unknown as TCloudInfo;
|
return response.json() as unknown as TCloudInfo;
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,8 +56,7 @@ const showSupportedVersionsWarning = function* showSupportedVersionsWarning(serv
|
||||||
}
|
}
|
||||||
const serverRecord = yield getServerById(server);
|
const serverRecord = yield getServerById(server);
|
||||||
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
||||||
|
if (!serverRecord || moment(new Date()).diff(serverRecord?.supportedVersionsWarningAt, 'hours') <= 12) {
|
||||||
if (!serverRecord || moment(serverRecord?.supportedVersionsWarningAt).diff(new Date(), 'hours') <= 12) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue