-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathcontext.ts
45 lines (38 loc) · 1.42 KB
/
context.ts
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
import {ObjectUtils} from "../objectUtils";
import * as Log from "./log";
export interface Context {
requirementsAreMet(requirements: { [key: string]: string | number | boolean }): boolean;
}
export class NoRequirements implements Context {
requirementsAreMet(requirements: { [key: string]: string | number | boolean }): boolean {
return true;
}
}
export class ProductionRequirements implements Context {
private prodProperties = [
Log.Context.toString(Log.Context.Custom.AppInfoId),
Log.Context.toString(Log.Context.Custom.AppInfoVersion),
Log.Context.toString(Log.Context.Custom.BrowserLanguage),
Log.Context.toString(Log.Context.Custom.ExtensionLifecycleId),
Log.Context.toString(Log.Context.Custom.ClipperType),
Log.Context.toString(Log.Context.Custom.DeviceInfoId),
Log.Context.toString(Log.Context.Custom.FlightInfo),
Log.Context.toString(Log.Context.Custom.InPrivateBrowsing)
];
private requiredProperties: string[];
constructor(requiredProperties?: string[]) {
this.requiredProperties = requiredProperties ? requiredProperties : this.prodProperties;
}
requirementsAreMet(contextProps: { [key: string]: string | number | boolean }): boolean {
if (ObjectUtils.isNullOrUndefined(contextProps)) {
return false;
}
for (let i = 0; i < this.requiredProperties.length; ++i) {
let prop = this.requiredProperties[i];
if (!contextProps.hasOwnProperty(prop)) {
return false;
}
}
return true;
}
}