Defensively set feature flags from window.parent (#594)

This doesn't really fix the fact that portal feature flags are not
being set, but it does re-enable feature flags in hosted mode.
This commit is contained in:
Jordi Bunster 2021-03-30 14:01:30 -07:00 committed by GitHub
parent a9ed187213
commit 813dbfee5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -23,11 +23,18 @@ export type Features = {
readonly ttl90Days: boolean;
};
export function extractFeatures(params?: URLSearchParams): Features {
params = params || new URLSearchParams(window.location.search);
export function extractFeatures(given = new URLSearchParams()): Features {
const downcased = new URLSearchParams();
params.forEach((value, key) => downcased.append(key.toLocaleLowerCase(), value));
const get = (key: string) => downcased.get("feature." + key.toLocaleLowerCase()) ?? undefined;
const set = (value: string, key: string) => downcased.set(key.toLowerCase(), value);
const get = (key: string) => downcased.get("feature." + key) ?? undefined;
try {
new URLSearchParams(window.parent.location.search).forEach(set);
} catch {
//
} finally {
given.forEach(set);
}
return {
canExceedMaximumValue: "true" === get("canexceedmaximumvalue"),