Skip to content

Commit

Permalink
feat: add support for client-side prerequisite events
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Oct 15, 2024
1 parent 57277e3 commit 992dded
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion relay/relay_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strconv"
"time"

ldeval "github.com/launchdarkly/go-server-sdk-evaluation/v3"

"github.com/launchdarkly/ld-relay/v8/internal/basictypes"
"github.com/launchdarkly/ld-relay/v8/internal/logging"
"github.com/launchdarkly/ld-relay/v8/internal/middleware"
Expand Down Expand Up @@ -247,7 +249,13 @@ func evaluateAllShared(w http.ResponseWriter, req *http.Request, sdkKind basicty
}
}

result := evaluator.Evaluate(flag, ldContext, nil)
var prerequisites []string
result := evaluator.Evaluate(flag, ldContext, func(event ldeval.PrerequisiteFlagEvent) {
if event.TargetFlagKey == flag.Key {
prerequisites = append(prerequisites, event.PrerequisiteFlag.Key)
}
})

detail := result.Detail
isExperiment := result.IsExperiment

Expand All @@ -262,6 +270,15 @@ func evaluateAllShared(w http.ResponseWriter, req *http.Request, sdkKind basicty
}
valueObj.Maybe("debugEventsUntilDate", flag.DebugEventsUntilDate != 0).
Float64(float64(flag.DebugEventsUntilDate))

if len(prerequisites) > 0 {
prereqArray := valueObj.Name("prerequisites").Array()
for _, p := range prerequisites {
prereqArray.String(p)
}
prereqArray.End()
}

valueObj.End()
}
}
Expand Down

0 comments on commit 992dded

Please sign in to comment.