Replace AnyCodable with JSONSerialization in IAFNativeBridgeEvent#536
Replace AnyCodable with JSONSerialization in IAFNativeBridgeEvent#536ab1470 wants to merge 1 commit intofeat/flyouts-formsfrom
Conversation
07ce4ae to
bc5abd4
Compare
Sources/KlaviyoForms/InAppForms/Models/IAFNativeBridgeEvent.swift
Outdated
Show resolved
Hide resolved
Decode formWillAppear, trackProfileEvent, and trackAggregateEvent into typed Codable structs instead of round-tripping through AnyCodable to opaque Data. This gives compile-time safety, eliminates the external dependency from this file, and simplifies downstream consumers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bc5abd4 to
d439c23
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| formLifecycleContinuation.yield(.dismiss) | ||
| case let .trackProfileEvent(data): | ||
| if let jsonEventData = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], | ||
| let metricName = jsonEventData["metric"] as? String { |
There was a problem hiding this comment.
Aggregate event re-encoding silently drops unknown JSON fields
Medium Severity
The trackAggregateEvent path still performs a decode-then-re-encode round-trip (decoding to TrackAggregateEventPayload, then encoding back to Data via JSONEncoder), but now uses a typed struct instead of AnyCodable. Any JSON fields sent by JavaScript that aren't explicitly modeled in the struct (e.g., future server-side additions) are silently dropped during decoding, causing incomplete aggregate event data to reach the backend. The previous AnyCodable approach preserved all fields.


Summary
AnyCodabledecode-then-re-encode pattern with typedCodablepayload structs (FormWillAppearPayload,TrackProfileEventPayload,TrackAggregateEventPayload)Datapassthrough, no re-parsing downstreamimport AnyCodablefrom both source and test filespayload.metric,payload.formId) instead of deserializingDatablobsTest plan
IAFNativeBridgeEventTestspass🤖 Generated with Claude Code