@@ -14,7 +14,6 @@ interface AuxiaApiRequestPayloadContextualAttributes {
1414
1515interface AuxiaApiRequestPayloadSurface {
1616 surface : string ;
17- minimumTreatmentCount : number ;
1817 maximumTreatmentCount : number ;
1918}
2019
@@ -26,7 +25,7 @@ interface AuxiaAPIRequestPayload {
2625 languageCode : string ;
2726}
2827
29- interface AuxiaAPIAnswerDataUserTreatment {
28+ interface AuxiaAPIResponseDataUserTreatment {
3029 treatmentId : string ;
3130 treatmentTrackingId : string ;
3231 rank : string ;
@@ -36,13 +35,14 @@ interface AuxiaAPIAnswerDataUserTreatment {
3635 surface : string ;
3736}
3837
39- interface AuxiaAPIAnswerData {
38+ interface AuxiaAPIResponseData {
4039 responseId : string ;
41- userTreatments : AuxiaAPIAnswerDataUserTreatment [ ] ;
40+ userTreatments : AuxiaAPIResponseDataUserTreatment [ ] ;
4241}
4342
4443interface AuxiaProxyResponseData {
45- shouldShowSignInGate : boolean ;
44+ responseId : string ;
45+ userTreatment ?: AuxiaAPIResponseDataUserTreatment ;
4646}
4747
4848const buildAuxiaAPIRequestPayload = ( projectId : string , userId : string ) : AuxiaAPIRequestPayload => {
@@ -63,8 +63,7 @@ const buildAuxiaAPIRequestPayload = (projectId: string, userId: string): AuxiaAP
6363 surfaces : [
6464 {
6565 surface : 'ARTICLE_PAGE' ,
66- minimumTreatmentCount : 1 ,
67- maximumTreatmentCount : 5 ,
66+ maximumTreatmentCount : 1 ,
6867 } ,
6968 ] ,
7069 languageCode : 'en-GB' ,
@@ -75,7 +74,7 @@ const fetchAuxiaData = async (
7574 apiKey : string ,
7675 projectId : string ,
7776 userId : string ,
78- ) : Promise < AuxiaAPIAnswerData > => {
77+ ) : Promise < AuxiaAPIResponseData > => {
7978 const url = 'https://apis.auxia.io/v1/GetTreatments' ;
8079
8180 const headers = {
@@ -95,19 +94,17 @@ const fetchAuxiaData = async (
9594
9695 const responseBody = await response . json ( ) ;
9796
98- return Promise . resolve ( responseBody as AuxiaAPIAnswerData ) ;
97+ return Promise . resolve ( responseBody as AuxiaAPIResponseData ) ;
9998} ;
10099
101- const buildAuxiaProxyResponseData = ( auxiaData : AuxiaAPIAnswerData ) : AuxiaProxyResponseData => {
102- // This is the most important function of this router, it takes the answer from auxia and
103- // and decides if the sign in gate should be shown or not.
104-
105- // In the current interpretation we are saying that a non empty userTreatments array means
106- // that the sign in gate should be shown.
107-
108- const shouldShowSignInGate = auxiaData . userTreatments . length > 0 ;
109-
110- return { shouldShowSignInGate } ;
100+ const buildAuxiaProxyResponseData = ( auxiaData : AuxiaAPIResponseData ) : AuxiaProxyResponseData => {
101+ // Note the small difference between AuxiaAPIResponseData and AuxiaProxyResponseData
102+ // In the case of AuxiaProxyResponseData, we have an optional userTreatment field, instead of an array of userTreatments.
103+ // This is to reflect the what the client expect semantically.
104+ return {
105+ responseId : auxiaData . responseId ,
106+ userTreatment : auxiaData . userTreatments [ 0 ] ,
107+ } ;
111108} ;
112109
113110export const getAuxiaRouterConfig = async ( ) : Promise < AuxiaRouterConfig > => {
0 commit comments