scaffolding hermes flow and audit logging
This commit is contained in:
@@ -25,4 +25,34 @@ final class HermesAnalyticsClient: ObservableObject, AnalyticsTracking {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func flush(using repository: HermesRepository) async {
|
||||
guard repository.currentSession != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
let pendingEvents = trackedEvents
|
||||
guard !pendingEvents.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
try await repository.submitAnalyticsBatch(
|
||||
HermesAnalyticsBatchRequest(
|
||||
events: pendingEvents.map { event in
|
||||
HermesAnalyticsEventInput(
|
||||
eventName: event.event,
|
||||
occurredAt: event.timestamp,
|
||||
attributes: event.attributes.map { HermesAnalyticsAttributeInput(key: $0.key, value: $0.value) }
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
let deliveredIds = Set(pendingEvents.map(\.id))
|
||||
trackedEvents.removeAll { deliveredIds.contains($0.id) }
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user