From ccb4da08bdea3d77f6f528f6b462f19da77157a2 Mon Sep 17 00:00:00 2001 From: Mauro Restuccia Date: Mon, 8 May 2023 13:22:08 -0400 Subject: [PATCH] fix: Carry on production to the package --- Example/AlloyCodelessLiteiOSDemo/ContentView.swift | 2 +- .../Internal/Model/Settings/AlloySettings.swift | 4 ++-- .../Internal/Model/Settings/JourneySettings.swift | 5 +++-- .../Internal/Network/Endpoints/JourneyEndpoint.swift | 4 ++-- .../Public/Utility/PluginURLBuilde.swift | 6 ++++-- .../alloy-codeless-lite-ios/Services/JourneyService.swift | 6 ++++-- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Example/AlloyCodelessLiteiOSDemo/ContentView.swift b/Example/AlloyCodelessLiteiOSDemo/ContentView.swift index e5f9c9e..355cd83 100644 --- a/Example/AlloyCodelessLiteiOSDemo/ContentView.swift +++ b/Example/AlloyCodelessLiteiOSDemo/ContentView.swift @@ -79,7 +79,7 @@ struct ContentView: View { let entities = EntityData(entities: [entityPerson, entityPerson2], additionalEntities: false) // *** this key is part of a working example *** // You should obtain your journey token from the journey's list - let journeySettings = JourneySettings(journeyToken: "J-UMEhLDP3p759425pz1uP", entities: entities) + let journeySettings = JourneySettings(journeyToken: "J-UMEhLDP3p759425pz1uP", entities: entities, production: false) let journeyResult = try await AlloyCodelessLiteiOS.shared.startJourney(journeySettings: journeySettings, onFinish: { _ in showResultJourney.toggle() }) diff --git a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/AlloySettings.swift b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/AlloySettings.swift index 3aa1691..acfa916 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/AlloySettings.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/AlloySettings.swift @@ -15,8 +15,8 @@ public class AlloySettings { // Configure SDK with production environment (default is false) public var production = false - // Configure SDK for make tests in environment (default is false) - public var realProduction = false + // Configure SDK for make tests in environment (default is true) + public var realProduction = true public var codelessFinalValidation = false diff --git a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift index 4aec395..c786e52 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift @@ -10,12 +10,13 @@ public class JourneySettings { public var journeyToken: String = "" public var entities: EntityData = EntityData(entities: [], additionalEntities: false) - + public var production: Bool = false; init() {} - public init(journeyToken: String, entities: EntityData) { + public init(journeyToken: String, entities: EntityData, production: Bool) { self.journeyToken = journeyToken self.entities = entities + self.production = production } public func getFirstNameEntity(withIndex i: Int) -> String { diff --git a/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/JourneyEndpoint.swift b/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/JourneyEndpoint.swift index 300762c..a8416b6 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/JourneyEndpoint.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Network/Endpoints/JourneyEndpoint.swift @@ -50,12 +50,12 @@ headers.add(HTTPHeader.authorization(bearerToken: TokenHolder.tokens.accessToken)) switch self { - case .createJourney: + case .createJourney(_, let journeySettings): headers.add(name:"alloy-journey-override-sync", value: "true") + headers.add(name:"alloy-sandbox", value: "\(!journeySettings.production)") default: break } - return headers } diff --git a/Sources/alloy-codeless-lite-ios/Public/Utility/PluginURLBuilde.swift b/Sources/alloy-codeless-lite-ios/Public/Utility/PluginURLBuilde.swift index abef796..738fe8f 100644 --- a/Sources/alloy-codeless-lite-ios/Public/Utility/PluginURLBuilde.swift +++ b/Sources/alloy-codeless-lite-ios/Public/Utility/PluginURLBuilde.swift @@ -7,14 +7,16 @@ internal struct PluginURLBuilder { var apiKey: String var journeyToken: String var applicationToken: String + var production: Bool - init(apiKey: String, journeyToken: String, applicationToken: String) { + init(apiKey: String, journeyToken: String, applicationToken: String, production: Bool) { self.apiKey = apiKey self.journeyToken = journeyToken self.applicationToken = applicationToken + self.production = production && false } public func getPluginURL() -> String { - baseUrl + "journeyApplicationToken=\(applicationToken)&journeyToken=\(journeyToken)&key=\(apiKey)" + baseUrl + "journeyApplicationToken=\(applicationToken)&journeyToken=\(journeyToken)&key=\(apiKey)&production=\(production)" } } diff --git a/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift b/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift index 0b123bc..cca193a 100644 --- a/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift +++ b/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift @@ -20,7 +20,8 @@ internal struct JourneyService { let urlPlugin = PluginURLBuilder( apiKey: AlloyCodelessLiteiOS.shared.alloySettings.apiKey ?? "", journeyToken: journeySettings.journeyToken, - applicationToken: TokenHolder.tokens.journeyApplicationToken + applicationToken: TokenHolder.tokens.journeyApplicationToken, + production: journeySettings.production ) UIUtils.presentView(viewController: WebViewController(url: urlPlugin.getPluginURL(), onFinish: onFinish), presentationStyle: .overFullScreen) } @@ -50,7 +51,8 @@ internal struct JourneyService { let urlPlugin = PluginURLBuilder( apiKey: AlloyCodelessLiteiOS.shared.alloySettings.apiKey ?? "", journeyToken: journeySettings.journeyToken, - applicationToken: TokenHolder.tokens.journeyApplicationToken + applicationToken: TokenHolder.tokens.journeyApplicationToken, + production: journeySettings.production ) await UIUtils.presentView(viewController: WebViewController(url: urlPlugin.getPluginURL(), onFinish: onFinish), presentationStyle: .overFullScreen) }