Skip to content

Commit f335f68

Browse files
chore: add support for accessing idType (#446)
I'm attempting to standardize the Kong APIs. This SDK is missing idType on all configs. Adding it to FeatureGate as a start
1 parent 97264af commit f335f68

File tree

8 files changed

+14
-8
lines changed

8 files changed

+14
-8
lines changed

src/main/kotlin/com/statsig/sdk/ConfigEvaluation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ConfigEvaluation(
1717
var forwardAllExposures: Boolean = false,
1818
var samplingRate: Long? = null,
1919
var isActive: Boolean = false,
20+
var idType: String = Const.EMPTY_STR,
2021
) {
2122
internal var isDelegate: Boolean = false
2223

src/main/kotlin/com/statsig/sdk/DataTypes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ data class APIFeatureGate(
8282
val secondaryExposures: ArrayList<Map<String, String>> = arrayListOf(),
8383
val reason: EvaluationReason?,
8484
val evaluationDetails: EvaluationDetails?,
85+
@SerializedName("id_type") val idType: String?,
8586
)
8687

8788
internal data class APIDynamicConfig(

src/main/kotlin/com/statsig/sdk/Evaluator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ internal class Evaluator(
502502
ctx.evaluation.evaluationDetails = createEvaluationDetails(specStore.getEvaluationReason())
503503
ctx.evaluation.configVersion = config.version
504504
ctx.evaluation.isActive = config.isActive
505+
ctx.evaluation.idType = config.idType
505506

506507
if (!config.enabled) {
507508
logger.debug("${config.name} is not enabled.")
@@ -573,6 +574,7 @@ internal class Evaluator(
573574
ctx.evaluation.jsonValue = config.defaultValue
574575
ctx.evaluation.ruleID = Const.DEFAULT
575576
ctx.evaluation.groupName = null
577+
ctx.evaluation.idType = config.idType
576578
}
577579

578580
private fun evaluateDelegate(

src/main/kotlin/com/statsig/sdk/Statsig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class Statsig {
582582
@JvmOverloads
583583
fun getFeatureGate(user: StatsigUser, gateName: String, option: GetFeatureGateOptions? = null): APIFeatureGate {
584584
if (!checkInitialized()) {
585-
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null)
585+
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null, null)
586586
}
587587
return statsigServer.getFeatureGate(user, gateName, option)
588588
}

src/main/kotlin/com/statsig/sdk/StatsigServer.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ private class StatsigServerImpl() :
430430

431431
override fun getFeatureGate(user: StatsigUser, gateName: String): APIFeatureGate {
432432
if (!isSDKInitialized()) {
433-
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null)
433+
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null, null)
434434
}
435435
return errorBoundary.captureSync(
436436
"getFeatureGate",
@@ -444,16 +444,17 @@ private class StatsigServerImpl() :
444444
result.secondaryExposures,
445445
result.evaluationDetails?.reason,
446446
result.evaluationDetails,
447+
result.idType
447448
)
448449
},
449-
{ return@captureSync APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.DEFAULT, null) },
450+
{ return@captureSync APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.DEFAULT, null, null) },
450451
configName = gateName,
451452
)
452453
}
453454

454455
override fun getFeatureGate(user: StatsigUser, gateName: String, option: GetFeatureGateOptions?): APIFeatureGate {
455456
if (!isSDKInitialized()) {
456-
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null)
457+
return APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.UNINITIALIZED, null, null)
457458
}
458459
return errorBoundary.captureSync(
459460
"getFeatureGate",
@@ -469,9 +470,10 @@ private class StatsigServerImpl() :
469470
result.secondaryExposures,
470471
result.evaluationDetails?.reason,
471472
result.evaluationDetails,
473+
result.idType
472474
)
473475
},
474-
{ return@captureSync APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.DEFAULT, null) },
476+
{ return@captureSync APIFeatureGate(gateName, false, null, arrayListOf(), EvaluationReason.DEFAULT, null, null) },
475477
configName = gateName,
476478
)
477479
}

src/test/java/com/statsig/sdk/ExceptionHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExceptionHandlerTest {
2626
user = StatsigUser("abc")
2727
eventLogInputCompletable = CompletableDeferred()
2828

29-
val mockGateResponse = APIFeatureGate("a_gate", true, "ruleID", arrayListOf(), EvaluationReason.DEFAULT, null)
29+
val mockGateResponse = APIFeatureGate("a_gate", true, "ruleID", arrayListOf(), EvaluationReason.DEFAULT, null, null)
3030
val mockResponseBody = gson.toJson(mockGateResponse)
3131

3232
val downloadConfigSpecsResponse =

src/test/java/com/statsig/sdk/ExposureLoggingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExposureLoggingTest {
2828
user = StatsigUser("abc")
2929
eventLogInputCompletable = CompletableDeferred()
3030

31-
val mockGateResponse = APIFeatureGate("a_gate", true, "ruleID", arrayListOf(), EvaluationReason.DEFAULT, null)
31+
val mockGateResponse = APIFeatureGate("a_gate", true, "ruleID", arrayListOf(), EvaluationReason.DEFAULT, null, null)
3232
val mockResponseBody = gson.toJson(mockGateResponse)
3333

3434
val downloadConfigSpecsResponse =

src/test/java/com/statsig/sdk/ExposureLoggingTestJava.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void setUp() {
3939
user = new StatsigUser("abc");
4040
eventLogInputCompletable = new CompletableFuture();
4141

42-
APIFeatureGate mockGateResponse = new APIFeatureGate("a_gate", true, "ruleID", new ArrayList<>(), EvaluationReason.DEFAULT, null);
42+
APIFeatureGate mockGateResponse = new APIFeatureGate("a_gate", true, "ruleID", new ArrayList<>(), EvaluationReason.DEFAULT, null, null);
4343
String mockResponseBody = gson.toJson(mockGateResponse);
4444

4545
String downloadConfigSpecsResponse =

0 commit comments

Comments
 (0)