Skip to content
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

Dev to main #463

Merged
merged 14 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions AEPCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
218C813B24EC3EBC009B4F31 /* V5Migrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218C813A24EC3EBC009B4F31 /* V5Migrator.swift */; };
218C813E24EC4101009B4F31 /* V5MigrationConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218C813D24EC4101009B4F31 /* V5MigrationConstants.swift */; };
218E01C024C7595000BEC470 /* HitQueuing+PrivacyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218E01BF24C7595000BEC470 /* HitQueuing+PrivacyTests.swift */; };
21A6737325434AE600A7E906 /* SharedStateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A6737225434AE600A7E906 /* SharedStateType.swift */; };
21CAC0E02422917600C11388 /* AEPCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21CAC0D62422917600C11388 /* AEPCore.framework */; };
21CAC0E72422917600C11388 /* AEPCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 21CAC0D92422917600C11388 /* AEPCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
21CD581124EC7B8900D9D590 /* V5MigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21CD581024EC7B8900D9D590 /* V5MigratorTests.swift */; };
Expand Down Expand Up @@ -574,6 +575,7 @@
218C813A24EC3EBC009B4F31 /* V5Migrator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V5Migrator.swift; sourceTree = "<group>"; };
218C813D24EC4101009B4F31 /* V5MigrationConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V5MigrationConstants.swift; sourceTree = "<group>"; };
218E01BF24C7595000BEC470 /* HitQueuing+PrivacyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HitQueuing+PrivacyTests.swift"; sourceTree = "<group>"; };
21A6737225434AE600A7E906 /* SharedStateType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedStateType.swift; sourceTree = "<group>"; };
21CAC0D62422917600C11388 /* AEPCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AEPCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
21CAC0D92422917600C11388 /* AEPCore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AEPCore.h; sourceTree = "<group>"; };
21CAC0DA2422917600C11388 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1595,6 +1597,7 @@
3FB66AAD24CA004400502CAF /* ExtensionRuntime.swift */,
3FB66AAB24CA004400502CAF /* SharedState.swift */,
217E220424D1FD7900B70B3E /* SharedStateResult.swift */,
21A6737225434AE600A7E906 /* SharedStateType.swift */,
);
path = eventhub;
sourceTree = "<group>";
Expand Down Expand Up @@ -2460,6 +2463,7 @@
3FB66AD024CA004400502CAF /* AEPError.swift in Sources */,
3FB66AD424CA004400502CAF /* EventType.swift in Sources */,
3F5D45F8251903030040E298 /* LaunchRuleTransformer.swift in Sources */,
21A6737325434AE600A7E906 /* SharedStateType.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
37 changes: 37 additions & 0 deletions AEPCore/Mocks/TestableExtensionRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class TestableExtensionRuntime: ExtensionRuntime {
public var listeners: [String: EventListener] = [:]
public var dispatchedEvents: [Event] = []
public var createdSharedStates: [[String: Any]?] = []
public var createdXdmSharedStates: [[String: Any]?] = []
public var mockedSharedStates: [String: SharedStateResult] = [:]
public var mockedXdmSharedStates: [String: SharedStateResult] = [:]

public init() {}

Expand Down Expand Up @@ -55,6 +57,24 @@ public class TestableExtensionRuntime: ExtensionRuntime {
return mockedSharedStates["\(extensionName)"]
}

public func createXDMSharedState(data: [String : Any], event: Event?) {
createdXdmSharedStates += [data]
}

public func createPendingXDMSharedState(event: Event?) -> SharedStateResolver {
return { data in
self.createdXdmSharedStates += [data]
}
}

public func getXDMSharedState(extensionName: String, event: Event?) -> SharedStateResult? {
// if there is an shared state setup for the specific (extension, event id) pair, return it. Otherwise, return the shared state that is setup for the extension.
if let id = event?.id {
return mockedXdmSharedStates["\(extensionName)-\(id)"] ?? mockedXdmSharedStates["\(extensionName)"]
}
return mockedXdmSharedStates["\(extensionName)"]
}

public func startEvents() {}

public func stopEvents() {}
Expand Down Expand Up @@ -95,10 +115,27 @@ public class TestableExtensionRuntime: ExtensionRuntime {
mockedSharedStates["\(extensionName)"] = SharedStateResult(status: data.status, value: data.value)
}

/// Simulate the XDM shared state of an extension for a matching event
/// - Parameters:
/// - pair: the (extension, event) pair
/// - data: the shared state tuple (value, status)
public func simulateXDMSharedState(for pair: (extensionName: String, event: Event), data: (value: [String: Any]?, status: SharedStateStatus)) {
mockedXdmSharedStates["\(pair.extensionName)-\(pair.event.id)"] = SharedStateResult(status: data.status, value: data.value)
}

/// Simulate the XDM shared state of an certain extension ignoring the event id
/// - Parameters:
/// - extensionName: extension name
/// - data: the shared state tuple (value, status)
public func simulateXDMSharedState(for extensionName: String, data: (value: [String: Any]?, status: SharedStateStatus)) {
mockedXdmSharedStates["\(extensionName)"] = SharedStateResult(status: data.status, value: data.value)
}

/// clear the events and shared states that have been created by the current extension
public func resetDispatchedEventAndCreatedSharedStates() {
dispatchedEvents = []
createdSharedStates = []
createdXdmSharedStates = []
}
}

Expand Down
2 changes: 1 addition & 1 deletion AEPCore/Sources/configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Configuration: Extension {
registerListener(type: EventType.lifecycle, source: EventSource.responseContent, listener: receiveLifecycleResponse(event:))

// If we have an appId stored in persistence, kick off the configureWithAppId event
if let appId = appIdManager.loadAppId(), !appId.isEmpty {
if let appId = appIdManager.loadAppIdFromManifest(), !appId.isEmpty {
dispatchConfigurationRequest(data: [ConfigurationConstants.Keys.JSON_APP_ID: appId])
}

Expand Down
6 changes: 3 additions & 3 deletions AEPCore/Sources/core/MobileCore+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public extension MobileCore {
/// Get a JSON string containing all of the user's identities known by the SDK and calls a handler upon completion.
/// - Parameter completion: a closure that is invoked with a `String?` containing the SDK identities in JSON format and an `AEPError` if the request failed
@objc(getSdkIdentities:)
static func getSdkIdentities(completion: @escaping (String?, AEPError) -> Void) {
static func getSdkIdentities(completion: @escaping (String?, Error?) -> Void) {
let event = Event(name: CoreConstants.EventNames.GET_SDK_IDENTITIES, type: EventType.configuration, source: EventSource.requestIdentity, data: nil)

EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 1) { responseEvent in
guard let responseEvent = responseEvent else {
completion(nil, .callbackTimeout)
completion(nil, AEPError.callbackTimeout)
return
}

guard let identities = responseEvent.data?[CoreConstants.Keys.ALL_IDENTIFIERS] as? String else {
completion(nil, .unexpected)
completion(nil, AEPError.unexpected)
return
}

Expand Down
19 changes: 19 additions & 0 deletions AEPCore/Sources/core/MobileCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public final class MobileCore: NSObject {
}
}

/// Fetches a list of registered extensions along with their respective versions
/// - Returns: list of registered extensions along with their respective versions
@objc
public static func getRegisteredExtensions() -> String {
let registeredExtensions = EventHub.shared.getSharedState(extensionName: EventHubConstants.NAME, event: nil)?.value
guard let jsonData = try? JSONSerialization.data(withJSONObject: registeredExtensions ?? [:], options: .prettyPrinted) else { return "{}" }
return String(data: jsonData, encoding: .utf8) ?? "{}"
}

/// Dispatches an `Event` through the `EventHub`
/// - Parameter event: The `Event` to be dispatched
@objc(dispatch:)
Expand All @@ -92,6 +101,16 @@ public final class MobileCore: NSObject {
EventHub.shared.dispatch(event: event)
}

/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched
/// - Parameters:
/// - type: A `String` indicating the event type the current listener is listening for
/// - source: A `String` indicating the event source the current listener is listening for
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched type and source
@objc(registerEventListenerWithType:source:listener:)
public static func registerEventListener(type: String, source: String, listener: @escaping EventListener) {
EventHub.shared.registerEventListener(type: type, source: source, listener: listener)
}

/// Submits a generic event containing the provided IDFA with event type `generic.identity`.
/// - Parameter identifier: the advertising identifier string.
@objc(setAdvertisingIdentifier:)
Expand Down
4 changes: 4 additions & 0 deletions AEPCore/Sources/eventhub/AEPError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ import Foundation
case callbackTimeout = 1
case callbackNil = 2
case none = 3
case serverError = 4
case networkError = 5
case invalidRequest = 6
case invalidResponse = 7
case errorExtensionNotInitialized = 11
}
Loading