Skip to content

Commit

Permalink
Add manual exposure APIs (#223)
Browse files Browse the repository at this point in the history
* Add manual exposure APIs

* Address feedback
  • Loading branch information
daniel-statsig authored Nov 16, 2022
1 parent f8594a9 commit d3a0f0c
Show file tree
Hide file tree
Showing 9 changed files with 600 additions and 139 deletions.
6 changes: 6 additions & 0 deletions jest-debug.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('./jest.config');

module.exports = {
...base,
...{ transform: undefined },
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"prepare": "rm -rf build/ && rm -rf dist/ && tsc && webpack",
"postbuild": "rm -rf build/**/*.map",
"test": "jest",
"test:debug": "jest --config=jest-debug.config.js",
"test:watch": "jest --watch",
"build:dryrun": "npx tsc --noEmit",
"types": "npx tsc"
Expand Down Expand Up @@ -63,4 +64,4 @@
"parser": "typescript"
}
}
}
}
49 changes: 23 additions & 26 deletions src/Layer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { IHasStatsigInternal } from './StatsigClient';
import { EvaluationDetails } from './StatsigStore';

export type LogParameterFunction = (
layer: Layer,
parameterName: string,
) => void;

export default class Layer {
private sdkInternal: IHasStatsigInternal | null;
private logParameterFunction: LogParameterFunction | null;
private name: string;
private value: Record<string, any>;
private ruleID: string;
Expand All @@ -17,13 +21,13 @@ export default class Layer {
layerValue: Record<string, any>,
ruleID: string,
evaluationDetails: EvaluationDetails,
sdkInternal: IHasStatsigInternal | null = null,
logParameterFunction: LogParameterFunction | null = null,
secondaryExposures: Record<string, string>[] = [],
undelegatedSecondaryExposures: Record<string, string>[] = [],
allocatedExperimentName: string = '',
explicitParameters: string[] = [],
) {
this.sdkInternal = sdkInternal;
this.logParameterFunction = logParameterFunction;
this.name = name;
this.value = JSON.parse(JSON.stringify(layerValue ?? {}));
this.ruleID = ruleID ?? '';
Expand All @@ -39,7 +43,7 @@ export default class Layer {
value: Record<string, any>,
ruleID: string,
evaluationDetails: EvaluationDetails,
sdkInternal: IHasStatsigInternal | null = null,
logParameterFunction: LogParameterFunction | null = null,
secondaryExposures: Record<string, string>[] = [],
undelegatedSecondaryExposures: Record<string, string>[] = [],
allocatedExperimentName: string = '',
Expand All @@ -50,7 +54,7 @@ export default class Layer {
value,
ruleID,
evaluationDetails,
sdkInternal,
logParameterFunction,
secondaryExposures,
undelegatedSecondaryExposures,
allocatedExperimentName,
Expand Down Expand Up @@ -124,30 +128,23 @@ export default class Layer {
return this.secondaryExposures;
}

public _getUndelegatedSecondaryExposures(): Record<string, string>[] {
return this.undelegatedSecondaryExposures;
}

public _getAllocatedExperimentName(): string {
return this.allocatedExperimentName;
}

private logLayerParameterExposure(parameterName: string) {
let allocatedExperiment = '';
let exposures = this.undelegatedSecondaryExposures;
const isExplicit = this.explicitParameters.includes(parameterName);
if (isExplicit) {
allocatedExperiment = this.allocatedExperimentName;
exposures = this.secondaryExposures;
}
public _getExplicitParameters(): string[] {
return this.explicitParameters;
}

this.sdkInternal
?.getLogger()
.logLayerExposure(
this.sdkInternal.getCurrentUser(),
this.name,
this.ruleID,
exposures,
allocatedExperiment,
parameterName,
isExplicit,
this.evaluationDetails,
);
public _getEvaluationDetails(): EvaluationDetails {
return this.evaluationDetails;
}

private logLayerParameterExposure(parameterName: string) {
this.logParameterFunction?.(this, parameterName);
}
}
Loading

0 comments on commit d3a0f0c

Please sign in to comment.