-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteConfig.ts
More file actions
69 lines (63 loc) · 2.25 KB
/
RemoteConfig.ts
File metadata and controls
69 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
export type GbfsVersionConfig = string[];
// FEATUTRE BYPASS CURRENTLY DISABLED
export interface RemoteConfigValues {
[key: string]: boolean | number | string;
enableLanguageToggle: boolean;
/** Enable Metrics view
* Values:
* true: renders the metrics view
* false: hides the metrics view
*/
enableMetrics: boolean;
/** GTFS metrics' bucket endpoint */
gtfsMetricsBucketEndpoint: string;
/** GBFS metrics' bucket endpoint */
gbfsMetricsBucketEndpoint: string;
featureFlagBypass: string;
enableFeedStatusBadge: boolean;
gbfsVersions: string;
/** Max number of data stuff to display on top of the map to avoid overflow */
visualizationMapPreviewDataLimit: number;
visualizationMapFullDataLimit: number;
// This feature flag enable or the coovered area component with expected behavior:
// 1- hides/shows the toggle button for gtfs feeds
// 2- use bounding box view for GBFS instead of full covered area map
enableDetailedCoveredArea: boolean;
gbfsValidator: boolean;
}
const gbfsVersionsDefault: GbfsVersionConfig = [];
// Add default values for remote config here
export const defaultRemoteConfigValues: RemoteConfigValues = {
enableLanguageToggle: false,
enableMetrics: false,
gtfsMetricsBucketEndpoint:
'https://storage.googleapis.com/mobilitydata-gtfs-analytics-dev',
gbfsMetricsBucketEndpoint:
'https://storage.googleapis.com/mobilitydata-gbfs-analytics-dev',
featureFlagBypass: '',
enableFeedStatusBadge: false,
gbfsVersions: JSON.stringify(gbfsVersionsDefault),
visualizationMapFullDataLimit: 5,
visualizationMapPreviewDataLimit: 3,
enableDetailedCoveredArea: false,
gbfsValidator: false,
};
/**
* Returns true if the given email matches any regex pattern in the
* featureFlagBypass config value (format: `{ "regex": [".+@example.org"] }`).
*/
export function matchesFeatureFlagBypass(
email: string | null | undefined,
featureFlagBypass: string,
): boolean {
if (email == null || email === '' || featureFlagBypass === '') return false;
try {
const parsed = JSON.parse(featureFlagBypass) as { regex?: unknown };
if (!Array.isArray(parsed.regex)) return false;
return (parsed.regex as string[]).some((pattern) =>
new RegExp(pattern).test(email),
);
} catch {
return false;
}
}