Skip to content

Commit 3cfb33c

Browse files
committed
refactor getTreatmentsRequestPayloadToGateType and export types from types.ts
1 parent 048f5e1 commit 3cfb33c

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/server/signin-gate/libPure.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export const decideGuGateTypeNonConsentedIreland = (
355355
};
356356

357357
export const getTreatmentsRequestPayloadToGateType = (
358-
getTreatmentsRequestPayload: GetTreatmentsRequestPayload,
358+
payload: GetTreatmentsRequestPayload,
359359
): GateType => {
360360
// This function is a pure function (without any side effects) which gets the body
361361
// of a '/auxia/get-treatments' request and returns the correct GateType.
@@ -378,18 +378,15 @@ export const getTreatmentsRequestPayloadToGateType = (
378378
// body.shouldServeDismissible take priority over the fact that body.showDefaultGate
379379
// could possibly have value 'mandatory'
380380

381-
if (
382-
getTreatmentsRequestPayload.showDefaultGate !== undefined &&
383-
getTreatmentsRequestPayload.shouldServeDismissible
384-
) {
381+
if (payload.showDefaultGate !== undefined && payload.shouldServeDismissible) {
385382
return 'GuDismissible';
386383
}
387384

388385
// --------------------------------------------------------------
389386
// The attribute showDefaultGate overrides any other behavior
390387

391-
if (getTreatmentsRequestPayload.showDefaultGate) {
392-
if (getTreatmentsRequestPayload.showDefaultGate == 'mandatory') {
388+
if (payload.showDefaultGate) {
389+
if (payload.showDefaultGate == 'mandatory') {
393390
return 'GuMandatory';
394391
} else {
395392
return 'GuDismissible';
@@ -403,10 +400,10 @@ export const getTreatmentsRequestPayloadToGateType = (
403400
// might be decommissioned in the future.
404401

405402
if (
406-
!isValidContentType(getTreatmentsRequestPayload.contentType) ||
407-
!isValidSection(getTreatmentsRequestPayload.sectionId) ||
408-
!isValidTagIds(getTreatmentsRequestPayload.tagIds) ||
409-
!articleIdentifierIsAllowed(getTreatmentsRequestPayload.articleIdentifier)
403+
!isValidContentType(payload.contentType) ||
404+
!isValidSection(payload.sectionId) ||
405+
!isValidTagIds(payload.tagIds) ||
406+
!articleIdentifierIsAllowed(payload.articleIdentifier)
410407
) {
411408
return 'None';
412409
}
@@ -417,13 +414,13 @@ export const getTreatmentsRequestPayloadToGateType = (
417414
// traffic (consented or not consented) to Auxia. (For privacy vigilantes reading this,
418415
// Auxia is not going to process non consented traffic for targetting.)
419416

420-
if (getTreatmentsRequestPayload.countryCode === 'IE') {
421-
if (mvtIdIsAuxiaAudienceShare(getTreatmentsRequestPayload.mvtId)) {
417+
if (payload.countryCode === 'IE') {
418+
if (mvtIdIsAuxiaAudienceShare(payload.mvtId)) {
422419
return 'AuxiaAPI';
423420
} else {
424421
return decideGuGateTypeNonConsentedIreland(
425-
getTreatmentsRequestPayload.dailyArticleCount,
426-
getTreatmentsRequestPayload.gateDisplayCount,
422+
payload.dailyArticleCount,
423+
payload.gateDisplayCount,
427424
);
428425
}
429426
}
@@ -440,9 +437,9 @@ export const getTreatmentsRequestPayloadToGateType = (
440437
// That split used to be done client side, but it's now been moved to SDC and is driven by
441438
// `mvtIdIsAuxiaAudienceShare`.
442439

443-
if (!mvtIdIsAuxiaAudienceShare(getTreatmentsRequestPayload.mvtId)) {
444-
if (getTreatmentsRequestPayload.should_show_legacy_gate_tmp) {
445-
return decideGateTypeNoneOrDismissible(getTreatmentsRequestPayload.gateDismissCount);
440+
if (!mvtIdIsAuxiaAudienceShare(payload.mvtId)) {
441+
if (payload.should_show_legacy_gate_tmp) {
442+
return decideGateTypeNoneOrDismissible(payload.gateDismissCount);
446443
} else {
447444
return 'None';
448445
}

src/server/signin-gate/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
// Types
33
// --------------------------------------------------------
44

5-
interface AuxiaAPIContextualAttributeString {
5+
export interface AuxiaAPIContextualAttributeString {
66
key: string;
77
stringValue: string;
88
}
99

10-
interface AuxiaAPIContextualAttributeBoolean {
10+
export interface AuxiaAPIContextualAttributeBoolean {
1111
key: string;
1212
boolValue: boolean;
1313
}
1414

15-
interface AuxiaAPIContextualAttributeInteger {
15+
export interface AuxiaAPIContextualAttributeInteger {
1616
key: string;
1717
integerValue: number;
1818
}
1919

20-
type AuxiaAPIGenericContexualAttribute =
20+
export type AuxiaAPIGenericContexualAttribute =
2121
| AuxiaAPIContextualAttributeString
2222
| AuxiaAPIContextualAttributeBoolean
2323
| AuxiaAPIContextualAttributeInteger;
2424

25-
interface AuxiaAPISurface {
25+
export interface AuxiaAPISurface {
2626
surface: string;
2727
maximumTreatmentCount: number;
2828
}

0 commit comments

Comments
 (0)