Skip to content

Commit 8585e31

Browse files
MichaelGHSegclaude
andauthored
Align e2e-cli types with sdk-e2e-tests (#533)
* Align e2e-cli types with sdk-e2e-tests definitions Add missing field extraction: timestamp, category, context, integrations. Wire timestamp, messageId, context, and integrations through to the Java SDK MessageBuilder for full fidelity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Replace SimpleDateFormat with java.time.Instant for timestamp parsing Instant.parse() handles all ISO 8601 formats natively, avoids deprecated SimpleDateFormat, and throws DateTimeParseException with clear context on invalid input instead of returning null. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3d4dd86 commit 8585e31

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

e2e-cli/src/main/kotlin/cli/Main.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.google.gson.reflect.TypeToken
55
import com.segment.analytics.Analytics
66
import com.segment.analytics.Callback
77
import com.segment.analytics.messages.*
8+
import java.time.Instant
9+
import java.util.Date
810
import java.util.concurrent.CountDownLatch
911
import java.util.concurrent.TimeUnit
1012
import java.util.concurrent.atomic.AtomicBoolean
@@ -107,14 +109,20 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
107109
val userId = event["userId"] as? String ?: ""
108110
val anonymousId = event["anonymousId"] as? String
109111
val messageId = event["messageId"] as? String
112+
val timestamp = event["timestamp"] as? String
110113
@Suppress("UNCHECKED_CAST")
111114
val traits = event["traits"] as? Map<String, Any> ?: emptyMap()
112115
@Suppress("UNCHECKED_CAST")
113116
val properties = event["properties"] as? Map<String, Any> ?: emptyMap()
114117
val eventName = event["event"] as? String
115118
val name = event["name"] as? String
119+
val category = event["category"] as? String
116120
val groupId = event["groupId"] as? String
117121
val previousId = event["previousId"] as? String
122+
@Suppress("UNCHECKED_CAST")
123+
val context = event["context"] as? Map<String, Any>
124+
@Suppress("UNCHECKED_CAST")
125+
val integrations = event["integrations"] as? Map<String, Any>
118126

119127
val messageBuilder: MessageBuilder<*, *> = when (type) {
120128
"identify" -> {
@@ -154,6 +162,28 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
154162
if (anonymousId != null) {
155163
messageBuilder.anonymousId(anonymousId)
156164
}
165+
if (messageId != null) {
166+
messageBuilder.messageId(messageId)
167+
}
168+
if (timestamp != null) {
169+
messageBuilder.timestamp(parseTimestamp(timestamp))
170+
}
171+
if (context != null) {
172+
messageBuilder.context(context)
173+
}
174+
if (integrations != null) {
175+
for ((key, value) in integrations) {
176+
when (value) {
177+
is Boolean -> messageBuilder.enableIntegration(key, value)
178+
is Map<*, *> -> @Suppress("UNCHECKED_CAST")
179+
messageBuilder.integrationOptions(key, value as Map<String, Any>)
180+
}
181+
}
182+
}
157183

158184
analytics.enqueue(messageBuilder)
159185
}
186+
187+
private fun parseTimestamp(iso: String): Date {
188+
return Date.from(Instant.parse(iso))
189+
}

0 commit comments

Comments
 (0)