Skip to content

[FME-4222] Events - New Events and InternalEvents with metadata #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: FME-4220-events_baseline
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15a175d
New Events and InternalEvents with metadata
MartinCardozo-SDK Jun 9, 2025
52f912b
ActionTask updated
MartinCardozo-SDK Jun 9, 2025
d58c5d6
Cleanup
MartinCardozo-SDK Jun 9, 2025
4d77b9f
Test added
MartinCardozo-SDK Jun 9, 2025
568d378
Add new channels
MartinCardozo-SDK Jun 10, 2025
2a4c597
Initial commit
MartinCardozo-SDK Jun 10, 2025
d865743
Action handlers unified
MartinCardozo-SDK Jun 10, 2025
2df6b41
Executing with metadata
MartinCardozo-SDK Jun 10, 2025
388ad8f
Event managers adapted to metadata events
MartinCardozo-SDK Jun 10, 2025
d030345
Tests updated. Minimum classes required updated too
MartinCardozo-SDK Jun 10, 2025
0a078f0
Merge branch 'FME-4233-events-managers' into FME-4224-events-defaultC…
MartinCardozo-SDK Jun 10, 2025
e6964ec
Clients updated
MartinCardozo-SDK Jun 10, 2025
a767914
Update Split/Api/FailHelpers.swift
MartinCardozo-SDK Jun 11, 2025
343d473
Merge pull request #685 from splitio/FME-4224-events-defaultClient
MartinCardozo-SDK Jun 11, 2025
0a291cd
Merge pull request #686 from splitio/FME-4233-events-managers
MartinCardozo-SDK Jun 11, 2025
e73495a
Removed unnecessary method
MartinCardozo-SDK Jun 11, 2025
4db5ec7
Removed unnecessary method
MartinCardozo-SDK Jun 11, 2025
493f10a
Merge pull request #684 from splitio/FME-4223-events-actionTask
MartinCardozo-SDK Jun 11, 2025
3455299
Equatables added
MartinCardozo-SDK Jun 12, 2025
e5bd927
Removed unnecessary comparations and methods
MartinCardozo-SDK Jun 12, 2025
cfa37ef
Cleanup
MartinCardozo-SDK Jun 12, 2025
f0bbdb0
Cleanup
MartinCardozo-SDK Jun 12, 2025
2e93d05
Initial commit
MartinCardozo-SDK Jun 17, 2025
b8c44e8
Merge pull request #691 from splitio/FME-4232-events-cleanup
MartinCardozo-SDK Jun 17, 2025
d432609
Entities made public
MartinCardozo-SDK Jun 17, 2025
8319054
Properties made public
MartinCardozo-SDK Jun 17, 2025
f4b0fb5
New metadata structure
MartinCardozo-SDK Jun 25, 2025
172e28e
Merge pull request #694 from splitio/FME-4222-events-metadataFix
MartinCardozo-SDK Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions Split/Api/DefaultSplitClient.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
//
// DefaultSplitClient.swift
// Split
//
// Created by Brian Sztamfater on 20/9/17.
// Modified by Natalia Stele on 11/10/17.
//
//

import Foundation

typealias DestroyHandler = () -> Void

public final class DefaultSplitClient: NSObject, SplitClient, TelemetrySplitClient {

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitPushManagerUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitPushManagerUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitPushManagerUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitPushManagerUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_3) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_3) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_3) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_3) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitStreamingUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitStreamingUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitStreamingUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitStreamingUT) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SemVer) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SemVer) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SemVer) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SemVer) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSStreaming) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_4) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_4) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_4) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_4) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration_1) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSIntegration) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

Check warning on line 8 in Split/Api/DefaultSplitClient.swift

View workflow job for this annotation

GitHub Actions / test (SplitiOSUnit_2) / test

parameter of 'on(event:executeWithMetadata:)' has different optionality than expected by protocol 'SplitClient'

private var storageContainer: SplitStorageContainer
private var key: Key
Expand Down Expand Up @@ -55,7 +49,7 @@
}
}

// MARK: Events
// MARK: Customers Listeners
extension DefaultSplitClient {

public func on(event: SplitEvent, execute action: @escaping SplitAction) {
Expand Down Expand Up @@ -89,14 +83,23 @@
on(event: event, executeTask: task)
}

private func on(event: SplitEvent, executeTask task: SplitEventTask) {
if event != .sdkReadyFromCache,
eventsManager.eventAlreadyTriggered(event: event) {
Logger.w("A handler was added for \(event.toString()) on the SDK, " +
"which has already fired and won’t be emitted again. The callback won’t be executed.")
private func onWithMetadata(event: SplitEventWithMetadata, runInBackground: Bool, queue: DispatchQueue?, execute actionWithMetadata: @escaping SplitActionWithMetadata) {
guard let factory = clientManager?.splitFactory else { return }
let task = SplitEventActionTask(action: actionWithMetadata, event: event.type, runInBackground: runInBackground, factory: factory, queue: queue)
on(event: event.type, executeTask: task)
}

public func on(event: SplitEvent, executeWithMetadata action: SplitActionWithMetadata?) {
guard let action = action else { return }
onWithMetadata(event: SplitEventWithMetadata(type: event, metadata: nil), runInBackground: true, queue: nil, execute: action)
}

private func on(event: SplitEvent, executeTask task: SplitEventActionTask) {
if event != .sdkReadyFromCache, eventsManager.eventAlreadyTriggered(event: event) {
Logger.w("A handler was added for \(event.toString()) on the SDK, which has already fired and won’t be emitted again. The callback won’t be executed.")
return
}
eventsManager.register(event: event, task: task)
eventsManager.register(event: SplitEventWithMetadata(type: event, metadata: nil), task: task)
}
}

Expand Down Expand Up @@ -164,7 +167,7 @@
}
}

// MARK: Track Events
// MARK: Tracking
extension DefaultSplitClient {

public func track(trafficType: String, eventType: String) -> Bool {
Expand Down Expand Up @@ -214,7 +217,7 @@
}
}

// MARK: Persistent attributes feature
// MARK: Persistence
extension DefaultSplitClient {

public func setAttribute(name: String, value: Any) -> Bool {
Expand Down Expand Up @@ -256,8 +259,7 @@
}

private func isValidAttribute(_ value: Any) -> Bool {
return anyValueValidator.isPrimitiveValue(value: value) ||
anyValueValidator.isList(value: value)
return anyValueValidator.isPrimitiveValue(value: value) || anyValueValidator.isList(value: value)
}

private func logInvalidAttribute(name: String) {
Expand All @@ -266,31 +268,31 @@
}

private func attributesStorage() -> AttributesStorage {
return storageContainer.attributesStorage
storageContainer.attributesStorage
}
}

// MARK: By Sets evaluation
// MARK: By Flagsets
extension DefaultSplitClient {
public func getTreatmentsByFlagSet(_ flagSet: String, attributes: [String: Any]?) -> [String: String] {
return treatmentManager.getTreatmentsByFlagSet(flagSet: flagSet, attributes: attributes, evaluationOptions: nil)
treatmentManager.getTreatmentsByFlagSet(flagSet: flagSet, attributes: attributes, evaluationOptions: nil)
}

public func getTreatmentsByFlagSets(_ flagSets: [String], attributes: [String: Any]?) -> [String: String] {
return treatmentManager.getTreatmentsByFlagSets(flagSets: flagSets, attributes: attributes, evaluationOptions: nil)
treatmentManager.getTreatmentsByFlagSets(flagSets: flagSets, attributes: attributes, evaluationOptions: nil)
}

public func getTreatmentsWithConfigByFlagSet(_ flagSet: String, attributes: [String: Any]?) -> [String: SplitResult] {
return treatmentManager.getTreatmentsWithConfigByFlagSet(flagSet: flagSet, attributes: attributes, evaluationOptions: nil)
treatmentManager.getTreatmentsWithConfigByFlagSet(flagSet: flagSet, attributes: attributes, evaluationOptions: nil)
}

public func getTreatmentsWithConfigByFlagSets(_ flagSets: [String],
attributes: [String: Any]?) -> [String: SplitResult] {
return treatmentManager.getTreatmentsWithConfigByFlagSets(flagSets: flagSets, attributes: attributes, evaluationOptions: nil)
treatmentManager.getTreatmentsWithConfigByFlagSets(flagSets: flagSets, attributes: attributes, evaluationOptions: nil)
}
}

// MARK: Flush / Destroy
// MARK: Lifecycle
extension DefaultSplitClient {

private func syncFlush() {
Expand Down
52 changes: 21 additions & 31 deletions Split/Api/FailHelpers.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//
// FailHelpers.swift
// Split
//
// Created by Javier Avrudsky on 24-Apr-2022.
// Copyright © 2022 Split. All rights reserved.
//

import Foundation

Expand Down Expand Up @@ -57,52 +52,50 @@ class FailedClient: SplitClient {
func on(event: SplitEvent, execute action: @escaping SplitAction) {
}

func on(event: SplitEvent, runInBackground: Bool,
execute action: @escaping SplitAction) {
}
func on(event: SplitEvent, runInBackground: Bool, execute action: @escaping SplitAction) {}

func on(event: SplitEvent,
queue: DispatchQueue, execute action: @escaping SplitAction) {
}
func on(event: SplitEvent, queue: DispatchQueue, execute action: @escaping SplitAction) {}

func on(event: SplitEvent, executeWithMetadata: @escaping SplitActionWithMetadata) {}

func track(trafficType: String, eventType: String) -> Bool {
return false
false
}

func track(trafficType: String, eventType: String, value: Double) -> Bool {
return false
false
}

func track(eventType: String) -> Bool {
return false
false
}

func track(eventType: String, value: Double) -> Bool {
return false
false
}

func setAttribute(name: String, value: Any) -> Bool {
return false
false
}

func getAttribute(name: String) -> Any? {
return false
false
}

func setAttributes(_ values: [String: Any]) -> Bool {
return false
false
}

func getAttributes() -> [String: Any]? {
return [:]
}

func removeAttribute(name: String) -> Bool {
return false
false
}

func clearAttributes() -> Bool {
return false
false
}

func getTreatmentsByFlagSet(_ flagSet: String, attributes: [String: Any]?) -> [String: String] {
Expand Down Expand Up @@ -137,33 +130,30 @@ class FailedClient: SplitClient {
return [:]
}

func setUserConsent(enabled: Bool) {
}
func setUserConsent(enabled: Bool) {}

func flush() {
}
func flush() {}

func destroy() {
}
func destroy() {}

func destroy(completion: (() -> Void)?) {
completion?()
}

func track(trafficType: String, eventType: String, properties: [String: Any]?) -> Bool {
return false
false
}

func track(trafficType: String, eventType: String, value: Double, properties: [String: Any]?) -> Bool {
return false
false
}

func track(eventType: String, properties: [String: Any]?) -> Bool {
return false
false
}

func track(eventType: String, value: Double, properties: [String: Any]?) -> Bool {
return false
false
}
}

Expand All @@ -173,6 +163,6 @@ class FailedManager: SplitManager {
var splitNames: [String] = []

func split(featureName: String) -> SplitView? {
return nil
nil
}
}
Loading
Loading