99 validateSplits ,
1010 validateTrafficType ,
1111 validateIfNotDestroyed ,
12- validateIfOperational
12+ validateIfOperational ,
13+ validateEvaluationOptions
1314} from '../utils/inputValidation' ;
1415import { startsWith } from '../utils/lang' ;
1516import { CONTROL , CONTROL_WITH_CONFIG , GET_TREATMENT , GET_TREATMENTS , GET_TREATMENTS_BY_FLAG_SET , GET_TREATMENTS_BY_FLAG_SETS , GET_TREATMENTS_WITH_CONFIG , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS , GET_TREATMENT_WITH_CONFIG , TRACK_FN_LABEL } from '../utils/constants' ;
@@ -32,7 +33,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
3233 /**
3334 * Avoid repeating this validations code
3435 */
35- function validateEvaluationParams ( maybeKey : SplitIO . SplitKey , maybeNameOrNames : string | string [ ] , maybeAttributes : SplitIO . Attributes | undefined , methodName : string ) {
36+ function validateEvaluationParams ( methodName : string , maybeKey : SplitIO . SplitKey , maybeNameOrNames : string | string [ ] , maybeAttributes ? : SplitIO . Attributes , maybeOptions ?: SplitIO . EvaluationOptions ) {
3637 const key = validateKey ( log , maybeKey , methodName ) ;
3738
3839 const nameOrNames = methodName . indexOf ( 'ByFlagSet' ) > - 1 ?
@@ -43,6 +44,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
4344
4445 const attributes = validateAttributes ( log , maybeAttributes , methodName ) ;
4546 const isNotDestroyed = validateIfNotDestroyed ( log , readinessManager , methodName ) ;
47+ const options = validateEvaluationOptions ( log , maybeOptions , methodName ) ;
4648
4749 validateIfOperational ( log , readinessManager , methodName , nameOrNames ) ;
4850
@@ -52,16 +54,17 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
5254 valid,
5355 key,
5456 nameOrNames,
55- attributes
57+ attributes,
58+ options
5659 } ;
5760 }
5861
5962 function wrapResult < T > ( value : T ) : MaybeThenable < T > {
6063 return isAsync ? Promise . resolve ( value ) : value ;
6164 }
6265
63- function getTreatment ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagName : string , maybeAttributes ?: SplitIO . Attributes ) {
64- const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT ) ;
66+ function getTreatment ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagName : string , maybeAttributes ?: SplitIO . Attributes , maybeOptions ?: SplitIO . EvaluationOptions ) {
67+ const params = validateEvaluationParams ( GET_TREATMENT , maybeKey , maybeFeatureFlagName , maybeAttributes , maybeOptions ) ;
6568
6669 if ( params . valid ) {
6770 return client . getTreatment ( params . key as SplitIO . SplitKey , params . nameOrNames as string , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -71,7 +74,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
7174 }
7275
7376 function getTreatmentWithConfig ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagName : string , maybeAttributes ?: SplitIO . Attributes ) {
74- const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT_WITH_CONFIG ) ;
77+ const params = validateEvaluationParams ( GET_TREATMENT_WITH_CONFIG , maybeKey , maybeFeatureFlagName , maybeAttributes ) ;
7578
7679 if ( params . valid ) {
7780 return client . getTreatmentWithConfig ( params . key as SplitIO . SplitKey , params . nameOrNames as string , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -81,10 +84,10 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
8184 }
8285
8386 function getTreatments ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagNames : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
84- const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS ) ;
87+ const params = validateEvaluationParams ( GET_TREATMENTS , maybeKey , maybeFeatureFlagNames , maybeAttributes ) ;
8588
8689 if ( params . valid ) {
87- return client . getTreatments ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
90+ return client . getTreatments ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined , ) ;
8891 } else {
8992 const res : SplitIO . Treatments = { } ;
9093 if ( params . nameOrNames ) ( params . nameOrNames as string [ ] ) . forEach ( ( split : string ) => res [ split ] = CONTROL ) ;
@@ -94,7 +97,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
9497 }
9598
9699 function getTreatmentsWithConfig ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagNames : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
97- const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS_WITH_CONFIG ) ;
100+ const params = validateEvaluationParams ( GET_TREATMENTS_WITH_CONFIG , maybeKey , maybeFeatureFlagNames , maybeAttributes ) ;
98101
99102 if ( params . valid ) {
100103 return client . getTreatmentsWithConfig ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -107,7 +110,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
107110 }
108111
109112 function getTreatmentsByFlagSets ( maybeKey : SplitIO . SplitKey , maybeFlagSets : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
110- const params = validateEvaluationParams ( maybeKey , maybeFlagSets , maybeAttributes , GET_TREATMENTS_BY_FLAG_SETS ) ;
113+ const params = validateEvaluationParams ( GET_TREATMENTS_BY_FLAG_SETS , maybeKey , maybeFlagSets , maybeAttributes , ) ;
111114
112115 if ( params . valid ) {
113116 return client . getTreatmentsByFlagSets ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -117,7 +120,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
117120 }
118121
119122 function getTreatmentsWithConfigByFlagSets ( maybeKey : SplitIO . SplitKey , maybeFlagSets : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
120- const params = validateEvaluationParams ( maybeKey , maybeFlagSets , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS ) ;
123+ const params = validateEvaluationParams ( GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS , maybeKey , maybeFlagSets , maybeAttributes ) ;
121124
122125 if ( params . valid ) {
123126 return client . getTreatmentsWithConfigByFlagSets ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -127,7 +130,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
127130 }
128131
129132 function getTreatmentsByFlagSet ( maybeKey : SplitIO . SplitKey , maybeFlagSet : string , maybeAttributes ?: SplitIO . Attributes ) {
130- const params = validateEvaluationParams ( maybeKey , [ maybeFlagSet ] , maybeAttributes , GET_TREATMENTS_BY_FLAG_SET ) ;
133+ const params = validateEvaluationParams ( GET_TREATMENTS_BY_FLAG_SET , maybeKey , [ maybeFlagSet ] , maybeAttributes ) ;
131134
132135 if ( params . valid ) {
133136 return client . getTreatmentsByFlagSet ( params . key as SplitIO . SplitKey , ( params . nameOrNames as string [ ] ) [ 0 ] , params . attributes as SplitIO . Attributes | undefined ) ;
@@ -137,7 +140,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
137140 }
138141
139142 function getTreatmentsWithConfigByFlagSet ( maybeKey : SplitIO . SplitKey , maybeFlagSet : string , maybeAttributes ?: SplitIO . Attributes ) {
140- const params = validateEvaluationParams ( maybeKey , [ maybeFlagSet ] , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET ) ;
143+ const params = validateEvaluationParams ( GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET , maybeKey , [ maybeFlagSet ] , maybeAttributes ) ;
141144
142145 if ( params . valid ) {
143146 return client . getTreatmentsWithConfigByFlagSet ( params . key as SplitIO . SplitKey , ( params . nameOrNames as string [ ] ) [ 0 ] , params . attributes as SplitIO . Attributes | undefined ) ;
0 commit comments