Skip to content

Prepare release 3.10.3 #528

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

Merged
merged 7 commits into from
Dec 6, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
description: release

env:
VERSION: 3.10.2
VERSION: 3.10.3

jobs:

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Optimizely Swift SDK Changelog

## 3.10.3
December 5, 2023

### Bug Fixes
* Remove redundant post request body in upload task. ([#521](https://github.com/optimizely/swift-sdk/pull/521/)).

### Enhancement
* Add privacy manifest file ([#522](https://github.com/optimizely/swift-sdk/pull/522/)).
* Handle duplicate keys in experiment ([#523](https://github.com/optimizely/swift-sdk/pull/523/)).

## 3.10.2
March 14, 2023

Expand Down
1 change: 1 addition & 0 deletions OptimizelySwiftSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,7 @@
children = (
6E75167A22C520D400B2B157 /* Optimizely.h */,
6E75167B22C520D400B2B157 /* Info.plist */,
987F11D92AF3F56F0083D3F9 /* PrivacyInfo.xcprivacy */,
);
path = "Supporting Files";
sourceTree = "<group>";
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ Add the dependency on the Optimizely Swift SDK with Swift Package Manager in `Xc
#### CocoaPods
1. Add the following lines to the _Podfile_:<pre>
```use_frameworks!```
```pod 'OptimizelySwiftSDK', '~> 3.10.2'```
```pod 'OptimizelySwiftSDK', '~> 3.10.3'```
</pre>

2. Run the following command: <pre>``` pod install ```</pre>

Further installation instructions for Cocoapods: https://guides.cocoapods.org/using/getting-started.html

#### Carthage
1. Add the following lines to the _Cartfile_:<pre>```github "optimizely/swift-sdk" ~> 3.10.2```</pre>
1. Add the following lines to the _Cartfile_:<pre>```github "optimizely/swift-sdk" ~> 3.10.3```</pre>

2. Run the following command:<pre>```carthage update```</pre>

Expand Down
6 changes: 3 additions & 3 deletions Scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#

# unit tests for PR only
if [[ "$BRANCH" == "master" ]]
then
# if [[ "$BRANCH" == "master" ]]
# then
xcodebuild test -derivedDataPath $COVERAGE_DIR -workspace OptimizelySwiftSDK.xcworkspace -scheme $SCHEME -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -sdk $TEST_SDK -destination "platform=$PLATFORM,OS=$OS,name=$NAME" ONLY_ACTIVE_ARCH=YES | tee buildoutput | xcpretty && test ${PIPESTATUS[0]} -eq 0
fi
# fi
1 change: 0 additions & 1 deletion Sources/Customization/DefaultEventDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ open class DefaultEventDispatcher: BackgroundingCallbacks, OPTEventDispatcher {

var request = URLRequest(url: event.url)
request.httpMethod = "POST"
request.httpBody = event.body
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

// send notification BEFORE sending event to the server
Expand Down
2 changes: 1 addition & 1 deletion Sources/Optimizely/OptimizelyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ open class OptimizelyClient: NSObject {
public func getOptimizelyConfig() throws -> OptimizelyConfig {
guard let config = self.config else { throw OptimizelyError.sdkNotReady }

return OptimizelyConfigImp(projectConfig: config)
return OptimizelyConfigImp(projectConfig: config, logger: logger)
}
}

Expand Down
11 changes: 7 additions & 4 deletions Sources/Optimizely/OptimizelyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ struct OptimizelyConfigImp: OptimizelyConfig {
var attributes: [OptimizelyAttribute] = []
var audiences: [OptimizelyAudience] = []
var events: [OptimizelyEvent] = []

init(projectConfig: ProjectConfig) {
init(projectConfig: ProjectConfig, logger: OPTLogger = DefaultLogger()) {
guard let project = projectConfig.project else { return }

self.environmentKey = project.environmentKey ?? ""
Expand Down Expand Up @@ -139,7 +139,7 @@ struct OptimizelyConfigImp: OptimizelyConfig {
return updatedRollout
}

self.experimentsMap = makeExperimentsMap(project: project, experiments: updatedExperiments)
self.experimentsMap = makeExperimentsMap(project: project, experiments: updatedExperiments, logger: logger)
self.featuresMap = makeFeaturesMap(project: project, experiments: updatedExperiments, rollouts: updatedRollouts)
}
}
Expand All @@ -148,9 +148,12 @@ struct OptimizelyConfigImp: OptimizelyConfig {

extension OptimizelyConfigImp {

func makeExperimentsMap(project: Project, experiments: [Experiment]) -> [String: Experiment] {
func makeExperimentsMap(project: Project, experiments: [Experiment], logger: OPTLogger) -> [String: Experiment] {
var map = [String: Experiment]()
experiments.forEach {
if map.keys.contains($0.key) {
logger.w("Duplicate experiment keys found in datafile: \($0.key)")
}
map[$0.key] = $0
}
return map
Expand Down
17 changes: 17 additions & 0 deletions Sources/Supporting Files/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>To store configuration and event data temporarily</string>
</array>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
</dict>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,64 @@ class OptimizelyClientTests_OptimizelyConfig: XCTestCase {
let result = try? self.optimizely.getOptimizelyConfig()
XCTAssertNil(result)
}

func testOptimizelyConfigWithDuplicateKeys() {
let exp0: [String : Any] = [
"id": "10001",
"key": "duplicate_key",
"status": "Running",
"layerId": "22222",
"variations": [],
"trafficAllocation": [],
"audienceIds": ["33333"],
"audienceConditions": [],
"forcedVariations": ["12345": "1234567890"]
]

let exp1: [String : Any] = [
"id": "10005",
"key": "duplicate_key",
"status": "Running",
"layerId": "22222",
"variations": [],
"trafficAllocation": [],
"audienceIds": ["33333"],
"audienceConditions": [],
"forcedVariations": ["12345": "1234567890"]
]

var projectData: [String: Any] = [
"version": "4",
"projectId": "11111",
"experiments": [],
"audiences": [],
"groups": [],
"attributes": [],
"accountId": "1234567890",
"events": [],
"revision": "5",
"anonymizeIP": true,
"rollouts": [],
"typedAudiences": [],
"integrations": [],
"featureFlags": [],
"botFiltering": false,
"sendFlagDecisions": true
]

projectData["experiments"] = [exp0, exp1]
let model: Project = try! OTUtils.model(from: projectData)
let projectConfig = ProjectConfig()
projectConfig.project = model

let logger = TestLogger()
let optiConfigImpl = OptimizelyConfigImp(projectConfig: projectConfig, logger: logger)
let optimizelyExpMap: [String: OptimizelyExperiment] = optiConfigImpl.experimentsMap
XCTAssertEqual(logger.getMessages(.warning), ["Duplicate experiment keys found in datafile: duplicate_key"])

XCTAssertEqual(optimizelyExpMap.count, 1)
XCTAssertEqual(optimizelyExpMap["duplicate_key"]?.id, "10005")
}

}

Expand Down Expand Up @@ -371,3 +429,41 @@ extension OptimizelyEvent {
}
}

// MARK: - Mock Loggers

fileprivate class TestLogger: OPTLogger {
private static var _logLevel: OptimizelyLogLevel?
public static var logLevel: OptimizelyLogLevel {
get {
return _logLevel ?? .info
}
set (newLevel) {
_logLevel = newLevel
}
}

required public init() {
clearMessages()
}

func log(level: OptimizelyLogLevel, message: String) {
logMessages[level.rawValue].append(message)
}

// Utils

var logMessages = [[String]]()

var logCount: Int {
return logMessages.reduce(0) { $0 + $1.count }
}

func getMessages(_ level: OptimizelyLogLevel) -> [String] {
return logMessages[level.rawValue]
}

func clearMessages() {
logMessages = [[String]](repeating: [], count: OptimizelyLogLevel.debug.rawValue + 1)
}

}