Skip to content

Commit 31960f4

Browse files
[BWA-155] refactor: Bring ConfigService into BitwardenKit (#1572)
1 parent 45194f4 commit 31960f4

38 files changed

+425
-1337
lines changed

AuthenticatorShared/Core/Platform/Models/Enum/FeatureFlag.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension FeatureFlag: @retroactive CaseIterable {
1515

1616
public static var allCases: [FeatureFlag] {
1717
[
18-
.enablePasswordManagerSync
18+
.enablePasswordManagerSync,
1919
]
2020
}
2121
}

AuthenticatorShared/Core/Platform/Services/StateService.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,12 @@ protocol StateService: AnyObject {
4848
///
4949
func getClearClipboardValue(userId: String?) async throws -> ClearClipboardValue
5050

51-
/// Gets the server config used by the app prior to the user authenticating.
52-
/// - Returns: The server config used prior to user authentication.
53-
func getPreAuthServerConfig() async -> ServerConfig?
54-
5551
/// Gets the user's encryption secret key.
5652
///
5753
/// - Returns: The user's encryption secret key.
5854
///
5955
func getSecretKey(userId: String?) async throws -> String?
6056

61-
/// Gets the server config for a user ID, as set by the server.
62-
///
63-
/// - Parameter userId: The user ID associated with the server config. Defaults to the active account if `nil`.
64-
/// - Returns: The user's server config.
65-
///
66-
func getServerConfig(userId: String?) async throws -> ServerConfig?
67-
6857
/// Get whether to show website icons.
6958
///
7059
/// - Returns: Whether to show the website icons.
@@ -105,25 +94,13 @@ protocol StateService: AnyObject {
10594
///
10695
func setClearClipboardValue(_ clearClipboardValue: ClearClipboardValue?, userId: String?) async throws
10796

108-
/// Sets the server config used prior to user authentication
109-
/// - Parameter config: The server config to use prior to user authentication.
110-
func setPreAuthServerConfig(config: ServerConfig) async
111-
11297
/// Sets the user's encryption secreet key.
11398
///
11499
/// - Parameters:
115100
/// - key: The key to set
116101
///
117102
func setSecretKey(_ key: String, userId: String?) async throws
118103

119-
/// Sets the server configuration as provided by a server for a user ID.
120-
///
121-
/// - Parameters:
122-
/// - configModel: The config values to set as provided by the server.
123-
/// - userId: The user ID associated with the server config.
124-
///
125-
func setServerConfig(_ config: ServerConfig?, userId: String?) async throws
126-
127104
/// Set whether to show the website icons.
128105
///
129106
/// - Parameter showWebIcons: Whether to show the website icons.
@@ -167,7 +144,7 @@ enum StateServiceError: Error {
167144

168145
/// A default implementation of `StateService`.
169146
///
170-
actor DefaultStateService: StateService {
147+
actor DefaultStateService: StateService, ConfigStateService {
171148
// MARK: Properties
172149

173150
/// The language option currently selected for the app.
@@ -304,16 +281,6 @@ actor DefaultStateService: StateService {
304281
}
305282
}
306283

307-
extension StateService {
308-
/// Gets the server config for the active account.
309-
///
310-
/// - Returns: The server config sent by the server for the active account.
311-
///
312-
func getServerConfig() async throws -> ServerConfig? {
313-
try await getServerConfig(userId: getActiveAccountId())
314-
}
315-
}
316-
317284
// MARK: Biometrics
318285

319286
extension DefaultStateService {

AuthenticatorShared/Core/Platform/Services/Stores/AppSettingsStore.swift

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ protocol AppSettingsStore: AnyObject {
6464
///
6565
func clearClipboardValue(userId: String) -> ClearClipboardValue
6666

67-
/// Retrieves a feature flag value from the app's settings store.
68-
///
69-
/// This method fetches the value for a specified feature flag from the app's settings store.
70-
/// The value is returned as a `Bool`. If the flag does not exist or cannot be decoded,
71-
/// the method returns `nil`.
72-
///
73-
/// - Parameter name: The name of the feature flag to retrieve, represented as a `String`.
74-
/// - Returns: The value of the feature flag as a `Bool`, or `nil` if the flag does not exist
75-
/// or cannot be decoded.
76-
///
77-
func debugFeatureFlag(name: String) -> Bool?
78-
7967
/// Flag to identify if the user has previously synced with the named account. `true` if they have previously
8068
/// synced with the named account, `false` if they have not synced previously.
8169
///
@@ -104,19 +92,6 @@ protocol AppSettingsStore: AnyObject {
10492
///
10593
func lastActiveTime(userId: String) -> Date?
10694

107-
/// Sets a feature flag value in the app's settings store.
108-
///
109-
/// This method updates or removes the value for a specified feature flag in the app's settings store.
110-
/// If the `value` parameter is `nil`, the feature flag is removed from the store. Otherwise, the flag
111-
/// is set to the provided boolean value.
112-
///
113-
/// - Parameters:
114-
/// - name: The name of the feature flag to set or remove, represented as a `String`.
115-
/// - value: The boolean value to assign to the feature flag. If `nil`, the feature flag will be removed
116-
/// from the settings store.
117-
///
118-
func overrideDebugFeatureFlag(name: String, value: Bool?)
119-
12095
/// Gets the user's secret encryption key.
12196
///
12297
/// - Parameters:
@@ -321,7 +296,7 @@ class DefaultAppSettingsStore {
321296
}
322297
}
323298

324-
extension DefaultAppSettingsStore: AppSettingsStore {
299+
extension DefaultAppSettingsStore: AppSettingsStore, ConfigSettingsStore {
325300
/// The keys used to store their associated values.
326301
///
327302
enum Keys {

AuthenticatorShared/Core/Platform/Services/TestHelpers/MockConfigService.swift

Lines changed: 0 additions & 74 deletions
This file was deleted.

AuthenticatorShared/UI/DebugMenu/DebugMenuCoordinatorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKitMocks
12
import SwiftUI
23
import XCTest
34

AuthenticatorShared/UI/DebugMenu/DebugMenuFeatureFlag.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

AuthenticatorShared/UI/DebugMenu/DebugMenuProcessorTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import BitwardenKit
2+
import BitwardenKitMocks
13
import XCTest
24

35
@testable import AuthenticatorShared

AuthenticatorShared/UI/DebugMenu/DebugMenuState.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import Foundation
23

34
// MARK: - DebugMenuState

AuthenticatorShared/UI/DebugMenu/DebugMenuView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import SwiftUI
23

34
// MARK: - DebugMenuView

AuthenticatorShared/UI/Platform/Settings/Settings/SettingsProcessorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKitMocks
12
import XCTest
23

34
@testable import AuthenticatorShared

AuthenticatorShared/UI/Vault/VaultItem/AuthenticatorKeyCapture/ManualEntryProcessorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKitMocks
12
import XCTest
23

34
@testable import AuthenticatorShared
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import BitwardenKit
21
import Foundation
32

43
// MARK: - DebugMenuFeatureFlag
54

65
/// A structure representing a feature flag in the debug menu, including its enabled state.
76
/// This is used to display and manage feature flags within the debug menu interface.
87
///
9-
struct DebugMenuFeatureFlag: Equatable, Identifiable {
8+
public struct DebugMenuFeatureFlag: Equatable, Identifiable, Sendable {
109
/// A unique identifier for the feature flag, based on its raw value.
11-
var id: String {
10+
public var id: String {
1211
feature.rawValue
1312
}
1413

1514
/// The feature flag enum that this instance represents.
16-
let feature: FeatureFlag
15+
public let feature: FeatureFlag
1716

1817
/// A boolean value indicating whether the feature is enabled or not.
19-
let isEnabled: Bool
18+
public let isEnabled: Bool
19+
20+
/// Public version of synthesized initializer.
21+
public init(feature: FeatureFlag, isEnabled: Bool) {
22+
self.feature = feature
23+
self.isEnabled = isEnabled
24+
}
2025
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// Helper object to send updated server config object with extra metadata
2+
/// like whether it comes from pre-auth and the user ID it belongs to.
3+
/// This is useful for getting the config on background and establishing which was the original context.
4+
public struct MetaServerConfig {
5+
/// If true, the call is coming before the user is authenticated or when adding a new account
6+
public let isPreAuth: Bool
7+
/// The user ID the requested the server config.
8+
public let userId: String?
9+
/// The server config.
10+
public let serverConfig: ServerConfig?
11+
12+
/// Public version of synthesized initializer.
13+
public init(isPreAuth: Bool, userId: String?, serverConfig: ServerConfig?) {
14+
self.isPreAuth = isPreAuth
15+
self.userId = userId
16+
self.serverConfig = serverConfig
17+
}
18+
}
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,72 @@
1+
// swiftlint:disable:this file_name
2+
13
import BitwardenKit
24

3-
public extension FeatureFlag {
5+
extension FeatureFlag: @retroactive CaseIterable {
46
/// A test feature flag that isn't remotely configured and has no initial value.
5-
static let testLocalFeatureFlag = FeatureFlag(
7+
public static let testLocalFeatureFlag = FeatureFlag(
68
rawValue: "test-local-feature-flag",
79
isRemotelyConfigured: false
810
)
911

1012
/// A test feature flag that has an initial boolean value and is not remotely configured.
11-
static let testLocalInitialBoolFlag = FeatureFlag(
13+
public static let testLocalInitialBoolFlag = FeatureFlag(
1214
rawValue: "test-local-initial-bool-flag",
1315
initialValue: .bool(true),
1416
isRemotelyConfigured: false
1517
)
1618

1719
/// A test feature flag that has an initial integer value and is not remotely configured.
18-
static let testLocalInitialIntFlag = FeatureFlag(
20+
public static let testLocalInitialIntFlag = FeatureFlag(
1921
rawValue: "test-local-initial-int-flag",
2022
initialValue: .int(42),
2123
isRemotelyConfigured: false
2224
)
2325

2426
/// A test feature flag that has an initial string value and is not remotely configured.
25-
static let testLocalInitialStringFlag = FeatureFlag(
27+
public static let testLocalInitialStringFlag = FeatureFlag(
2628
rawValue: "test-local-initial-string-flag",
2729
initialValue: .string("Test String"),
2830
isRemotelyConfigured: false
2931
)
3032

3133
/// A test feature flag that can be remotely configured.
32-
static let testRemoteFeatureFlag = FeatureFlag(
34+
public static let testRemoteFeatureFlag = FeatureFlag(
3335
rawValue: "test-remote-feature-flag",
3436
isRemotelyConfigured: true
3537
)
3638

3739
/// A test feature flag that has an initial boolean value and is not remotely configured.
38-
static let testRemoteInitialBoolFlag = FeatureFlag(
40+
public static let testRemoteInitialBoolFlag = FeatureFlag(
3941
rawValue: "test-remote-initial-bool-flag",
4042
initialValue: .bool(true),
4143
isRemotelyConfigured: true
4244
)
4345

4446
/// A test feature flag that has an initial integer value and is not remotely configured.
45-
static let testRemoteInitialIntFlag = FeatureFlag(
47+
public static let testRemoteInitialIntFlag = FeatureFlag(
4648
rawValue: "test-remote-initial-int-flag",
4749
initialValue: .int(42),
4850
isRemotelyConfigured: true
4951
)
5052

5153
/// A test feature flag that has an initial string value and is not remotely configured.
52-
static let testRemoteInitialStringFlag = FeatureFlag(
54+
public static let testRemoteInitialStringFlag = FeatureFlag(
5355
rawValue: "test-remote-initial-string-flag",
5456
initialValue: .string("Test String"),
5557
isRemotelyConfigured: true
5658
)
59+
60+
public static var allCases: [FeatureFlag] {
61+
[
62+
.testLocalFeatureFlag,
63+
.testLocalInitialBoolFlag,
64+
.testLocalInitialIntFlag,
65+
.testLocalInitialStringFlag,
66+
.testRemoteFeatureFlag,
67+
.testRemoteInitialBoolFlag,
68+
.testRemoteInitialIntFlag,
69+
.testRemoteInitialStringFlag,
70+
]
71+
}
5772
}

0 commit comments

Comments
 (0)