Skip to content

Commit

Permalink
Merge pull request #154 from adobe/staging
Browse files Browse the repository at this point in the history
staging to main for 4.0.2 release
  • Loading branch information
sbenedicadb authored Oct 12, 2023
2 parents 2628a73 + 1f6eba0 commit 7c38e04
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 26 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/update_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a basic workflow that is manually triggered

name: Update Versions

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
version:
description: 'New version to use for the Target extension. Example: 4.0.2'
required: true

branch:
description: 'Branch to be used when updating versions'
required: true

core-dependency:
description: 'If a version is provided, update AEPCore dependency in podspec and Package.swift'
required: false

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
update-versions:
runs-on: macos-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:

- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.branch }}

- name: Update AEPTarget
run: (sh ./Script/update-versions.sh -n Target -v ${{ github.event.inputs.version }} -d "AEPCore ${{ github.event.inputs.core-dependency }}")

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ github.token }}
commit-message: Updating version to ${{ github.event.inputs.version }}.
branch: version-${{ github.event.inputs.version }}-update
delete-branch: true
title: Updating version to ${{ github.event.inputs.version }}
body: Updating version to ${{ github.event.inputs.version }}
2 changes: 1 addition & 1 deletion AEPTarget.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AEPTarget"
s.version = "4.0.1"
s.version = "4.0.2"
s.summary = "Experience Platform Target extension for Adobe Experience Platform Mobile SDK. Written and maintained by Adobe."
s.description = <<-DESC
The Experience Platform Target extension provides APIs that allow use of the Target product in the Adobe Experience Platform SDK.
Expand Down
4 changes: 2 additions & 2 deletions AEPTarget.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.0.1;
MARKETING_VERSION = 4.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.adobe.aep.target;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1205,7 +1205,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.0.1;
MARKETING_VERSION = 4.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.adobe.aep.target;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableAddressSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -60,6 +61,13 @@
ReferencedContainer = "container:AEPTarget.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
47 changes: 43 additions & 4 deletions AEPTarget/Sources/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,35 @@ public class Target: NSObject, Extension {
return String(format: TargetConstants.DELIVERY_API_URL_BASE, String(format: TargetConstants.API_URL_HOST_BASE, clientCode), clientCode, targetState.sessionId)
}

private func getSdkVersion(eventHubData: [String: Any]?) -> String {
guard let eventHubData = eventHubData else {
return ""
}

let coreVersion = eventHubData[TargetConstants.EventHub.SharedState.Keys.VERSION] as? String ?? "unknown"

// sdkVersion is a combination of Mobile Core+Target SDK version
return "\(coreVersion)+\(TargetConstants.EXTENSION_VERSION)"
}

private func getSdkInfo(eventHubData: [String: Any]?) -> String {
let sdkBase = TargetConstants.HEADER_X_EXC_SDK_BASE_TARGET_MOBILE_IOS

guard let eventHubData = eventHubData else {
return sdkBase
}

guard let wrapper = eventHubData[TargetConstants.EventHub.SharedState.Keys.WRAPPER] as? [String: Any],
let wrapperFriendlyName = wrapper[TargetConstants.EventHub.SharedState.Keys.WRAPPER_FRIENDLY_NAME] as? String,
wrapperFriendlyName != "None"
else {
return sdkBase
}

// sdkInfo is of the format AdobeTargetMobile-iOS-<wrapperFriendlyName>
return "\(sdkBase)-\(wrapperFriendlyName)"
}

/// Prepares for the target requests and checks whether a target request can be sent.
/// - returns: error indicating why the request can't be sent, nil otherwise
private func prepareForTargetRequest() -> String? {
Expand Down Expand Up @@ -667,8 +696,6 @@ public class Target: NSObject, Extension {
return "Failed to generate request parameter(JSON) for target delivery API call"
}

let headers = [TargetConstants.HEADER_CONTENT_TYPE: TargetConstants.HEADER_CONTENT_TYPE_JSON]

guard let clientCode = targetState.clientCode else {
return "Missing client code"
}
Expand All @@ -677,7 +704,13 @@ public class Target: NSObject, Extension {
return "Failed to generate the url for target API call"
}

let eventHubSharedState = getSharedState(extensionName: TargetConstants.EventHub.EXTENSION_NAME, event: event)?.value
let timeout = targetState.networkTimeout
let headers = [
TargetConstants.HEADER_CONTENT_TYPE: TargetConstants.HEADER_CONTENT_TYPE_JSON,
TargetConstants.HEADER_X_EXC_SDK: getSdkInfo(eventHubData: eventHubSharedState),
TargetConstants.HEADER_X_EXC_SDK_VERSION: getSdkVersion(eventHubData: eventHubSharedState),
]

// https://developers.adobetarget.com/api/delivery-api/#tag/Delivery-API
let request = NetworkRequest(url: url, httpMethod: .post, connectPayload: requestJson, httpHeaders: headers, connectTimeout: timeout, readTimeout: timeout)
Expand Down Expand Up @@ -903,8 +936,13 @@ public class Target: NSObject, Extension {
return
}

let eventHubSharedState = getSharedState(extensionName: TargetConstants.EventHub.EXTENSION_NAME, event: event)?.value
let timeout = targetState.networkTimeout
let headers = [TargetConstants.HEADER_CONTENT_TYPE: TargetConstants.HEADER_CONTENT_TYPE_JSON]
let headers = [
TargetConstants.HEADER_CONTENT_TYPE: TargetConstants.HEADER_CONTENT_TYPE_JSON,
TargetConstants.HEADER_X_EXC_SDK: getSdkInfo(eventHubData: eventHubSharedState),
TargetConstants.HEADER_X_EXC_SDK_VERSION: getSdkVersion(eventHubData: eventHubSharedState),
]

// https://developers.adobetarget.com/api/delivery-api/#tag/Delivery-API
let request = NetworkRequest(url: url, httpMethod: .post, connectPayload: requestJson, httpHeaders: headers, connectTimeout: timeout, readTimeout: timeout)
Expand All @@ -916,8 +954,9 @@ public class Target: NSObject, Extension {
Log.debug(label: Target.LOG_TAG, "handleRawRequest - Target response is received with code: \(connection.responseCode ?? -1) and data: \(connection.responseString ?? "").")
self.targetState.updateSessionTimestamp()
self.processTargetRawResponse(event: event, isContentRequest: isContentRequest, connection: connection)

self.startEvents()
}
startEvents()
}

/// Processes the network response after the Target delivery API call for raw request.
Expand Down
16 changes: 15 additions & 1 deletion AEPTarget/Sources/TargetConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ import Foundation
enum TargetConstants {
static let EXTENSION_NAME = "com.adobe.module.target"
static let FRIENDLY_NAME = "Target"
static let EXTENSION_VERSION = "4.0.1"
static let EXTENSION_VERSION = "4.0.2"
static let DATASTORE_NAME = EXTENSION_NAME
static let DEFAULT_SESSION_TIMEOUT: Int = 30 * 60 // 30 mins
static let DELIVERY_API_URL_BASE = "https://%@/rest/v1/delivery/?client=%@&sessionId=%@"
static let EDGE_HOST_BASE = "mboxedge%@"
static let API_URL_HOST_BASE = "%@.tt.omtrdc.net"
static let HEADER_CONTENT_TYPE = "Content-Type"
static let HEADER_X_EXC_SDK = "X-EXC-SDK"
static let HEADER_X_EXC_SDK_VERSION = "X-EXC-SDK-Version"
static let HEADER_CONTENT_TYPE_JSON = "application/json"
static let HEADER_X_EXC_SDK_BASE_TARGET_MOBILE_IOS = "AdobeTargetMobile-iOS"
static let A4T_ACTION_NAME = "AnalyticsForTarget"

static let MAP_TO_CONTEXT_DATA_KEYS: [String: String] = [
Expand Down Expand Up @@ -234,6 +237,17 @@ enum TargetConstants {
}
}

enum EventHub {
static let EXTENSION_NAME = "com.adobe.module.eventhub"
enum SharedState {
enum Keys {
static let VERSION = "version"
static let WRAPPER = "wrapper"
static let WRAPPER_FRIENDLY_NAME = "friendlyName"
}
}
}

enum Identity {
static let EXTENSION_NAME = "com.adobe.module.identity"
enum SharedState {
Expand Down
28 changes: 24 additions & 4 deletions AEPTarget/Sources/TargetState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@ import Foundation

/// Represents the state of the `Target` extension
class TargetState {
private(set) var prefetchedMboxJsonDicts = [String: [String: Any]]()
private(set) var loadedMboxJsonDicts = [String: [String: Any]]()
private(set) var notifications = [Notification]()
private let queue: DispatchQueue = .init(label: "com.adobe.targetstate.queue")

private(set) var storedConfigurationSharedState: [String: Any]?
private var _prefetchedMboxJsonDicts: [String: [String: Any]] = [:]
private(set) var prefetchedMboxJsonDicts: [String: [String: Any]] {
get { queue.sync { self._prefetchedMboxJsonDicts } }
set { queue.async { self._prefetchedMboxJsonDicts = newValue } }
}

private var _loadedMboxJsonDicts: [String: [String: Any]] = [:]
private(set) var loadedMboxJsonDicts: [String: [String: Any]] {
get { queue.sync { self._loadedMboxJsonDicts } }
set { queue.async { self._loadedMboxJsonDicts = newValue } }
}

private var _notifications: [Notification] = []
private(set) var notifications: [Notification] {
get { queue.sync { self._notifications } }
set { queue.async { self._notifications = newValue } }
}

private var _storedConfigurationSharedState: [String: Any]?
private(set) var storedConfigurationSharedState: [String: Any]? {
get { queue.sync { self._storedConfigurationSharedState } }
set { queue.async { self._storedConfigurationSharedState = newValue } }
}

private(set) var thirdPartyId: String?
private(set) var tntId: String?
Expand Down
48 changes: 48 additions & 0 deletions AEPTarget/Tests/IntegrationTests/TargetIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class TargetIntegrationTests: XCTestCase {
mockNetworkService.mock { request in
Log.debug(label: self.T_LOG_TAG, "request url is: \(request.url.absoluteString)")
if request.url.absoluteString.contains("https://amsdk.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

if let payloadDictionary = try? JSONSerialization.jsonObject(with: request.connectPayload, options: .allowFragments) as? [String: Any]
{
Log.debug(label: self.T_LOG_TAG, "request payload is: \n \(self.prettify(payloadDictionary))")
Expand Down Expand Up @@ -407,6 +413,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://amsdk.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

return (data: responseString.data(using: .utf8), response: validResponse, error: nil)
}
return nil
Expand Down Expand Up @@ -1093,6 +1105,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://amsdk.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

let connectPayloadString = String(decoding: request.connectPayload, as: UTF8.self)
if connectPayloadString.contains("ADCKKBC") {
targetRequestExpectation.fulfill()
Expand Down Expand Up @@ -1219,6 +1237,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://amsdk.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

let connectPayloadString = String(decoding: request.connectPayload, as: UTF8.self)
if connectPayloadString.contains("ADCKKBC") {
targetRequestExpectation.fulfill()
Expand Down Expand Up @@ -1662,6 +1686,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://acopprod3.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

return (data: responseString.data(using: .utf8), response: validResponse, error: nil)
}
return nil
Expand Down Expand Up @@ -1802,6 +1832,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://acopprod3.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

return (data: responseString.data(using: .utf8), response: validResponse, error: nil)
}
return nil
Expand Down Expand Up @@ -1954,6 +1990,12 @@ class TargetIntegrationTests: XCTestCase {
ServiceProvider.shared.networkService = mockNetworkService
mockNetworkService.mock { request in
if request.url.absoluteString.contains("https://acopprod3.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

return (data: responseString.data(using: .utf8), response: validResponse, error: nil)
}

Expand Down Expand Up @@ -2096,6 +2138,12 @@ class TargetIntegrationTests: XCTestCase {
}

if request.url.absoluteString.contains("https://mboxedge35.tt.omtrdc.net/rest/v1/delivery/?client=acopprod3&sessionId=") {
// verify request headers
let coreVersion = self.getLastValidSharedState("com.adobe.module.eventhub")?.value?["version"] ?? "unknown"
let requestHeaders: [String: String] = request.httpHeaders
XCTAssertEqual("AdobeTargetMobile-iOS", requestHeaders["X-EXC-SDK"])
XCTAssertEqual("\(coreVersion)+\(TargetTestConstants.EXTENSION_VERSION)", requestHeaders["X-EXC-SDK-Version"])

targetNotificationExpectation.fulfill()
return nil
}
Expand Down
1 change: 1 addition & 0 deletions AEPTarget/Tests/TestHelpers/TargetTestConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

enum TargetTestConstants {
static let EXTENSION_VERSION = "4.0.2"
// preview parameters
static let PREVIEW_MESSAGE_ID = "target-preview-message-id"
static let PREVIEW_PARAMETERS = "at_preview_params"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ test-podspec:

pod-lint:
(pod lib lint --allow-warnings --verbose --swift-version=5.1)

# used to test update-versions.sh script locally
test-update-version:
(sh ./Script/update-versions.sh -n Target -v 9.9.9 -d "AEPCore 9.9.3")
Loading

0 comments on commit 7c38e04

Please sign in to comment.