@splitsoftware/splitio-commons 3.1.1-rc.1 → 3.1.1-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,12 @@ function treatmentsException(definitionNames) {
25
25
  });
26
26
  return evaluations;
27
27
  }
28
+ function setEvaluationDataFromDefinition(evaluation, definition) {
29
+ return (0, objectAssign_1.objectAssign)(evaluation, {
30
+ definition: definition,
31
+ config: definition.configurations && definition.configurations[evaluation.treatment] || null
32
+ });
33
+ }
28
34
  function evaluateFeature(log, key, definitionName, attributes, storage) {
29
35
  var definition;
30
36
  try {
@@ -98,8 +104,8 @@ function getEvaluation(log, key, definition, attributes, storage) {
98
104
  var split = (0, Engine_1.engineParser)(log, definition, storage);
99
105
  var evaluation = split.getTreatment(key, attributes, evaluateFeature);
100
106
  return (0, thenable_1.thenable)(evaluation) ?
101
- evaluation.then(function (result) { return (0, objectAssign_1.objectAssign)(result, { definition: definition }); }) :
102
- (0, objectAssign_1.objectAssign)(evaluation, { definition: definition });
107
+ evaluation.then(function (result) { return setEvaluationDataFromDefinition(result, definition); }) :
108
+ setEvaluationDataFromDefinition(evaluation, definition);
103
109
  }
104
110
  return EVALUATION_DEFINITION_NOT_FOUND;
105
111
  }
@@ -131,11 +137,10 @@ function evaluateDefaultTreatment(definitionName, storage) {
131
137
  exports.evaluateDefaultTreatment = evaluateDefaultTreatment;
132
138
  function getDefaultTreatment(definition) {
133
139
  if (definition) {
134
- return {
140
+ return setEvaluationDataFromDefinition({
135
141
  treatment: definition.defaultTreatment,
136
- label: labels_1.NO_CONDITION_MATCH,
137
- definition: definition,
138
- };
142
+ label: labels_1.NO_CONDITION_MATCH, // "default rule"
143
+ }, definition);
139
144
  }
140
145
  return EVALUATION_DEFINITION_NOT_FOUND;
141
146
  }
@@ -112,13 +112,11 @@ function clientFactory(params) {
112
112
  }
113
113
  // Internal function
114
114
  function processEvaluation(evaluation, featureFlagName, key, withConfig, invokingMethodName, queue, options) {
115
- var _a;
116
115
  if (options === void 0) { options = {}; }
117
116
  var matchingKey = (0, key_1.getMatching)(key);
118
117
  var bucketingKey = (0, key_1.getBucketing)(key);
119
118
  var definition = evaluation.definition;
120
- var treatment = evaluation.treatment, label = evaluation.label;
121
- var config = ((_a = definition === null || definition === void 0 ? void 0 : definition.configurations) === null || _a === void 0 ? void 0 : _a[treatment]) || null;
119
+ var treatment = evaluation.treatment, label = evaluation.label, _a = evaluation.config, config = _a === void 0 ? null : _a;
122
120
  if (treatment === constants_1.CONTROL) {
123
121
  var fallbackTreatment = fallbackCalculator(featureFlagName, label);
124
122
  treatment = fallbackTreatment.treatment;
@@ -22,6 +22,12 @@ function treatmentsException(definitionNames) {
22
22
  });
23
23
  return evaluations;
24
24
  }
25
+ function setEvaluationDataFromDefinition(evaluation, definition) {
26
+ return objectAssign(evaluation, {
27
+ definition: definition,
28
+ config: definition.configurations && definition.configurations[evaluation.treatment] || null
29
+ });
30
+ }
25
31
  export function evaluateFeature(log, key, definitionName, attributes, storage) {
26
32
  var definition;
27
33
  try {
@@ -92,8 +98,8 @@ function getEvaluation(log, key, definition, attributes, storage) {
92
98
  var split = engineParser(log, definition, storage);
93
99
  var evaluation = split.getTreatment(key, attributes, evaluateFeature);
94
100
  return thenable(evaluation) ?
95
- evaluation.then(function (result) { return objectAssign(result, { definition: definition }); }) :
96
- objectAssign(evaluation, { definition: definition });
101
+ evaluation.then(function (result) { return setEvaluationDataFromDefinition(result, definition); }) :
102
+ setEvaluationDataFromDefinition(evaluation, definition);
97
103
  }
98
104
  return EVALUATION_DEFINITION_NOT_FOUND;
99
105
  }
@@ -124,11 +130,10 @@ export function evaluateDefaultTreatment(definitionName, storage) {
124
130
  }
125
131
  function getDefaultTreatment(definition) {
126
132
  if (definition) {
127
- return {
133
+ return setEvaluationDataFromDefinition({
128
134
  treatment: definition.defaultTreatment,
129
- label: NO_CONDITION_MATCH,
130
- definition: definition,
131
- };
135
+ label: NO_CONDITION_MATCH, // "default rule"
136
+ }, definition);
132
137
  }
133
138
  return EVALUATION_DEFINITION_NOT_FOUND;
134
139
  }
@@ -108,13 +108,11 @@ export function clientFactory(params) {
108
108
  }
109
109
  // Internal function
110
110
  function processEvaluation(evaluation, featureFlagName, key, withConfig, invokingMethodName, queue, options) {
111
- var _a;
112
111
  if (options === void 0) { options = {}; }
113
112
  var matchingKey = getMatching(key);
114
113
  var bucketingKey = getBucketing(key);
115
114
  var definition = evaluation.definition;
116
- var treatment = evaluation.treatment, label = evaluation.label;
117
- var config = ((_a = definition === null || definition === void 0 ? void 0 : definition.configurations) === null || _a === void 0 ? void 0 : _a[treatment]) || null;
115
+ var treatment = evaluation.treatment, label = evaluation.label, _a = evaluation.config, config = _a === void 0 ? null : _a;
118
116
  if (treatment === CONTROL) {
119
117
  var fallbackTreatment = fallbackCalculator(featureFlagName, label);
120
118
  treatment = fallbackTreatment.treatment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "3.1.1-rc.1",
3
+ "version": "3.1.1-rc.2",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -31,6 +31,13 @@ function treatmentsException(definitionNames: string[]) {
31
31
  return evaluations;
32
32
  }
33
33
 
34
+ function setEvaluationDataFromDefinition(evaluation: IEvaluation, definition: IDefinition): IEvaluation {
35
+ return objectAssign(evaluation, {
36
+ definition,
37
+ config: definition.configurations && definition.configurations[evaluation.treatment] || null
38
+ });
39
+ }
40
+
34
41
  export function evaluateFeature(
35
42
  log: ILogger,
36
43
  key: SplitIO.SplitKey,
@@ -137,8 +144,8 @@ function getEvaluation(
137
144
  const evaluation = split.getTreatment(key, attributes, evaluateFeature);
138
145
 
139
146
  return thenable(evaluation) ?
140
- evaluation.then(result => objectAssign(result, { definition })) :
141
- objectAssign(evaluation, { definition });
147
+ evaluation.then(result => setEvaluationDataFromDefinition(result, definition)) :
148
+ setEvaluationDataFromDefinition(evaluation, definition);
142
149
  }
143
150
 
144
151
  return EVALUATION_DEFINITION_NOT_FOUND;
@@ -187,11 +194,10 @@ function getDefaultTreatment(
187
194
  definition: IDefinition | null,
188
195
  ): MaybeThenable<IEvaluation> {
189
196
  if (definition) {
190
- return {
197
+ return setEvaluationDataFromDefinition({
191
198
  treatment: definition.defaultTreatment,
192
199
  label: NO_CONDITION_MATCH, // "default rule"
193
- definition,
194
- };
200
+ }, definition);
195
201
  }
196
202
 
197
203
  return EVALUATION_DEFINITION_NOT_FOUND;
@@ -22,6 +22,7 @@ export interface IEvaluation {
22
22
  treatment: string,
23
23
  label: string,
24
24
  definition?: IDefinition
25
+ config?: string | null | SplitIO.JsonObject
25
26
  }
26
27
 
27
28
  export type IDefinitionEvaluator = (log: ILogger, key: SplitIO.SplitKey, definitionName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
@@ -142,8 +142,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
142
142
  const bucketingKey = getBucketing(key);
143
143
 
144
144
  const { definition } = evaluation;
145
- let { treatment, label } = evaluation;
146
- let config = definition?.configurations?.[treatment] || null;
145
+ let { treatment, label, config = null } = evaluation;
147
146
 
148
147
  if (treatment === CONTROL) {
149
148
  const fallbackTreatment = fallbackCalculator(featureFlagName, label);