All files / lib terms.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22        1x       17x             2x 1x          
// Terms version enforcement for signup and re-acceptance flows.
// IMPORTANT: Keep in sync with apps/portal/src/lib/terms.ts
 
// Set to null to disable enforcement. Set to "v1.0" when terms are finalized.
export const CURRENT_TERMS_VERSION = "v1.0-rc";
 
/** Parse major version number from "v1.0" → 1 */
export function getMajorVersion(version: string): number {
	return parseInt(version.replace("v", "").split(".")[0], 10);
}
 
/** Returns true if user needs to accept current terms */
export function needsTermsAcceptance(
	userTermsVersion: string | null,
): boolean {
	if (!userTermsVersion) return true; // never accepted
	return (
		getMajorVersion(userTermsVersion) <
		getMajorVersion(CURRENT_TERMS_VERSION)
	);
}