Skip to content

Commit

Permalink
Update initialize response (#177)
Browse files Browse the repository at this point in the history
* Update initialize response

* Cleanup e2e test

* Add generator, debug differences

* using new fields

* Finalize

* Hit prod
  • Loading branch information
tore-statsig authored Jun 2, 2022
1 parent 7a5cb40 commit c9665c4
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 264 deletions.
9 changes: 8 additions & 1 deletion src/ConfigEvaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class ConfigEvaluation {
public config_delegate: string | null;
public fetch_from_server: boolean;
public undelegated_secondary_exposures: Record<string, string>[] | undefined;
public is_experiment_group: boolean;

constructor(
value: boolean,
Expand All @@ -20,7 +21,8 @@ export default class ConfigEvaluation {
) {
this.value = value;
this.rule_id = rule_id;
if (typeof json_value === 'boolean') { // handle legacy gate case
if (typeof json_value === 'boolean') {
// handle legacy gate case
this.json_value = {};
} else {
this.json_value = json_value;
Expand All @@ -30,6 +32,11 @@ export default class ConfigEvaluation {
this.config_delegate = config_delegate;
this.fetch_from_server = fetch_from_server;
this.explicit_parameters = explicit_parameters;
this.is_experiment_group = false;
}

public setIsExperimentGroup(isExperimentGroup: boolean = false) {
this.is_experiment_group = isExperimentGroup;
}

public static fetchFromServer() {
Expand Down
14 changes: 14 additions & 0 deletions src/ConfigSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class ConfigSpec {
public rules: ConfigRule[];
public entity: string;
public explicitParameters: string[] | null;
public hasSharedParams: boolean;
public isActive?: boolean;

constructor(specJSON: Record<string, unknown>) {
this.name = specJSON.name as string;
Expand All @@ -19,6 +21,13 @@ export class ConfigSpec {
this.rules = this.parseRules(specJSON.rules);
this.entity = specJSON.entity as string;
this.explicitParameters = specJSON.explicitParameters as string[];
if (specJSON.isActive !== null) {
this.isActive = specJSON.isActive as boolean;
}
this.hasSharedParams =
specJSON.hasSharedParams != null
? specJSON.hasSharedParams === true
: false;
}

parseRules(rulesJSON: unknown) {
Expand All @@ -41,6 +50,7 @@ export class ConfigRule {
public salt: string;
public idType: string;
public configDelegate: string | null;
public isExperimentGroup?: boolean;

constructor(ruleJSON: Record<string, unknown>) {
this.name = ruleJSON.name as string;
Expand All @@ -51,6 +61,10 @@ export class ConfigRule {
this.salt = ruleJSON.salt as string;
this.idType = ruleJSON.idType as string;
this.configDelegate = (ruleJSON.configDelegate as string) ?? null;

if (ruleJSON.isExperimentGroup !== null) {
this.isExperimentGroup = ruleJSON.isExperimentGroup as boolean;
}
}

parseConditions(conditionsJSON: unknown) {
Expand Down
Loading

0 comments on commit c9665c4

Please sign in to comment.