Support server-determined build expiration

This commit is contained in:
Josh Perez 2020-09-09 18:50:44 -04:00 committed by Scott Nonnenberg
parent a04f9a0e51
commit d87335f5a6
14 changed files with 147 additions and 28 deletions

View file

@ -0,0 +1,33 @@
import semver from 'semver';
type RemoteVersion = {
'min-version': string;
iso8601: string;
};
export function parseRemoteClientExpiration(
remoteExpirationValue: string
): number | null {
const remoteVersions = JSON.parse(remoteExpirationValue) || [];
const ourVersion = window.getVersion();
return remoteVersions.reduce(
(acc: number | null, remoteVersion: RemoteVersion) => {
const minVersion = remoteVersion['min-version'];
const { iso8601 } = remoteVersion;
if (semver.gt(minVersion, ourVersion)) {
const timestamp = new Date(iso8601).getTime();
if (!acc) {
return timestamp;
}
return timestamp < acc ? timestamp : acc;
}
return acc;
},
null
);
}