Skip to content

Commit

Permalink
Upgrade the interface of the auxia proxy router
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Jan 28, 2025
1 parent 4a1ce9e commit 772355a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/server/api/auxiaProxyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ interface AuxiaAPIResponseData {
}

interface AuxiaProxyResponseData {
shouldShowSignInGate: boolean;
responseId: string;
userTreatment?: AuxiaAPIResponseDataUserTreatment;
}

const buildAuxiaAPIRequestPayload = (projectId: string, userId: string): AuxiaAPIRequestPayload => {
Expand Down Expand Up @@ -97,15 +98,13 @@ const fetchAuxiaData = async (
};

const buildAuxiaProxyResponseData = (auxiaData: AuxiaAPIResponseData): AuxiaProxyResponseData => {
// This is the most important function of this router, it takes the answer from auxia and
// and decides if the sign in gate should be shown or not.

// In the current interpretation we are saying that a non empty userTreatments array means
// that the sign in gate should be shown.

const shouldShowSignInGate = auxiaData.userTreatments.length > 0;

return { shouldShowSignInGate };
// Note the small difference between AuxiaAPIResponseData and AuxiaProxyResponseData
// In the case of AuxiaProxyResponseData, we have an optional userTreatment field, instead of an array of userTreatments.
// This is to reflect the what the client expect semantically.
return {
responseId: auxiaData.responseId,
userTreatment: auxiaData.userTreatments[0],
};
};

export const getAuxiaRouterConfig = async (): Promise<AuxiaRouterConfig> => {
Expand Down

0 comments on commit 772355a

Please sign in to comment.