Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json|^.secrets.baseline$",
"lines": null
},
"generated_at": "2025-07-17T19:49:02Z",
"generated_at": "2025-08-06T10:27:10Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ibm-appconfiguration-js-client-sdk",
"version": "0.2.0-beta.3",
"version": "0.2.0-beta.4",
"description": "IBM Cloud App Configuration JavaScript Client SDK",
"keywords": [
"client-sdk",
Expand Down
3 changes: 2 additions & 1 deletion src/models/Experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export interface IExperiment {
export interface TrafficDistribution {
type: string;
rule_id: string;
control_group: Group;
experimental_group: Group[];
control_variation: string;
non_experimental_group?: Group;
traffic_reassignment: boolean;
}

Expand Down
58 changes: 32 additions & 26 deletions src/models/Feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ interface EvaluationResult {
value: any;
is_enabled: boolean;
variation_id: string;
audience_group: string;
group_type: string;
}

// variation details with audience type (experiment or control)
interface VariationWithAudience {
// variation details with group type (experimental or non_experimental)
interface VariationWithGroup {
variation_id: string;
rollout_percentage: number;
audience_group: string;
group_type: string;
}

export default class Feature {
Expand Down Expand Up @@ -185,7 +185,7 @@ export default class Feature {
value: undefined,
is_enabled: false,
variation_id: '',
audience_group: '',
group_type: '',
};
try {
// evaluate the feature flag only if the toggle state is enabled
Expand All @@ -196,17 +196,19 @@ export default class Feature {
const { iteration } = this.experiment;
const { variations } = this.experiment;
if (trafficDistribution.type === 'ALL') {
const allVariations: VariationWithAudience[] = [];
const allVariations: VariationWithGroup[] = [];
for (const expV of trafficDistribution.experimental_group) {
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, audience_group: 'experiment' });
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, group_type: 'experimental' });
}
if (trafficDistribution.non_experimental_group) {
allVariations.push({ variation_id: trafficDistribution.non_experimental_group.variation_id, rollout_percentage: trafficDistribution.non_experimental_group.rollout_percentage, group_type: 'non_experimental' });
}
allVariations.push({ variation_id: trafficDistribution.control_group.variation_id, rollout_percentage: trafficDistribution.control_group.rollout_percentage, audience_group: 'control' });
let variationId = '';
let totalPercentage = 0;
let audienceGroup = '';
let groupType = '';
const hashValue = getNormalizedValue(''.concat(entityId, ':', this.feature_id, ':', iteration.iteration_key));
for (const v of allVariations) {
audienceGroup = v.audience_group;
groupType = v.group_type;
variationId = v.variation_id;
totalPercentage += v.rollout_percentage;
if (hashValue < totalPercentage) {
Expand All @@ -215,7 +217,7 @@ export default class Feature {
}
for (const v of variations) {
if (variationId === v.variation_id) {
evaluationResult.audience_group = audienceGroup;
evaluationResult.group_type = groupType;
evaluationResult.variation_id = v.variation_id
return { current_value: v.variation_value };
}
Expand Down Expand Up @@ -265,17 +267,19 @@ export default class Feature {
// case 1: user doesn't belong to any of the rules
// case 2: feature flag is not targeted with rules
// case 3: feature flag is targeted with rules, but entityAttributes are not passed
const allVariations: VariationWithAudience[] = [];
const allVariations: VariationWithGroup[] = [];
for (const expV of trafficDistribution.experimental_group) {
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, audience_group: 'experiment' });
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, group_type: 'experimental' });
}
if (trafficDistribution.non_experimental_group) {
allVariations.push({ variation_id: trafficDistribution.non_experimental_group.variation_id, rollout_percentage: trafficDistribution.non_experimental_group.rollout_percentage, group_type: 'non_experimental' });
}
allVariations.push({ variation_id: trafficDistribution.control_group.variation_id, rollout_percentage: trafficDistribution.control_group.rollout_percentage, audience_group: 'control' });
let variationId = '';
let totalPercentage = 0;
let audienceGroup = '';
let groupType = '';
const hashValue = getNormalizedValue(''.concat(entityId, ':', this.feature_id, ':', iteration.iteration_key));
for (const v of allVariations) {
audienceGroup = v.audience_group;
groupType = v.group_type;
variationId = v.variation_id;
totalPercentage += v.rollout_percentage;
if (hashValue < totalPercentage) {
Expand All @@ -284,7 +288,7 @@ export default class Feature {
}
for (const v of variations) {
if (variationId === v.variation_id) {
evaluationResult.audience_group = audienceGroup;
evaluationResult.group_type = groupType;
evaluationResult.variation_id = v.variation_id
return { current_value: v.variation_value };
}
Expand All @@ -311,17 +315,19 @@ export default class Feature {
evaluationResult.evaluated_segment_id = segmentId;
const expRuleId = parseInt(trafficDistribution.rule_id)
if (expRuleId === segmentRule.order) {
const allVariations: VariationWithAudience[] = [];
const allVariations: VariationWithGroup[] = [];
for (const expV of trafficDistribution.experimental_group) {
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, audience_group: 'experiment' });
allVariations.push({ variation_id: expV.variation_id, rollout_percentage: expV.rollout_percentage, group_type: 'experimental' });
}
if (trafficDistribution.non_experimental_group) {
allVariations.push({ variation_id: trafficDistribution.non_experimental_group.variation_id, rollout_percentage: trafficDistribution.non_experimental_group.rollout_percentage, group_type: 'non_experimental' });
}
allVariations.push({ variation_id: trafficDistribution.control_group.variation_id, rollout_percentage: trafficDistribution.control_group.rollout_percentage, audience_group: 'control' });
let variationId = '';
let totalPercentage = 0;
let audienceGroup = '';
let groupType = '';
const hashValue = getNormalizedValue(''.concat(entityId, ':', this.feature_id, ':', iteration.iteration_key));
for (const v of allVariations) {
audienceGroup = v.audience_group;
groupType = v.group_type;
variationId = v.variation_id;
totalPercentage += v.rollout_percentage;
if (hashValue < totalPercentage) {
Expand All @@ -330,7 +336,7 @@ export default class Feature {
}
for (const v of variations) {
if (variationId === v.variation_id) {
evaluationResult.audience_group = audienceGroup;
evaluationResult.group_type = groupType;
evaluationResult.variation_id = v.variation_id
return { current_value: v.variation_value };
}
Expand Down Expand Up @@ -386,8 +392,8 @@ export default class Feature {
}
return { current_value: this.disabled_value, is_enabled: false };
} finally {
if (this.experiment && this.experiment.experiment_status === 'RUNNING' && evaluationResult.variation_id.length > 0) {
ExpEvalMetering.getInstance().addMetering({ experiment_id: this.experiment.experiment_id, iteration_id: this.experiment?.iteration.iteration_id, feature_id: this.feature_id, variation_id: evaluationResult.variation_id, entity_id: entityId, audience_group: evaluationResult.audience_group, })
if (this.experiment && this.experiment.experiment_status === 'RUNNING' && evaluationResult.variation_id.length > 0 && evaluationResult.group_type === 'experimental') {
ExpEvalMetering.getInstance().addMetering({ experiment_id: this.experiment.experiment_id, iteration_id: this.experiment?.iteration.iteration_id, feature_id: this.feature_id, variation_id: evaluationResult.variation_id, entity_id: entityId, })
} else {
Metering.getInstance().addMetering(entityId, evaluationResult.evaluated_segment_id, this.feature_id, null);
}
Expand All @@ -408,7 +414,7 @@ export default class Feature {
value: undefined,
is_enabled: false,
variation_id: '',
audience_group: ''
group_type: ''
};

try {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/expevaluationmetering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface EvaluationUsage {
feature_id: string;
variation_id: string;
entity_id: string;
audience_group: string;
timestamp?: string;
}

Expand All @@ -41,7 +40,7 @@ export default class ExpEvalMetering {

private environmentId: string | undefined;

private meteringInterval: number = 60 * 1000; // 1 minute
private meteringInterval: number = 30 * 1000; // 30 seconds

private timer: any;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/expmetricmetering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ExpMetricMetering {

private environmentId: string | undefined;

private meteringInterval: number = 60 * 1000; // 1 minute
private meteringInterval: number = 30 * 1000; // 30 seconds

private timer: any;

Expand Down