[PM-26063] Consolidate shared service protocols in BitwardenKit (#2111)

This commit is contained in:
Matt Czech 2025-11-06 16:39:38 -06:00 committed by GitHub
parent 2a09b36797
commit f9ae28de1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 88 additions and 57 deletions

View File

@ -42,13 +42,13 @@ public class ServiceContainer: Services {
let clientService: ClientService
/// The service to get locally-specified configuration
let configService: ConfigService
public let configService: ConfigService
/// The service used by the application to encrypt and decrypt items
let cryptographyService: CryptographyService
/// The service used by the application to report non-fatal errors.
let errorReporter: ErrorReporter
public let errorReporter: ErrorReporter
/// The service used to export items.
let exportItemsService: ExportItemsService
@ -69,7 +69,7 @@ public class ServiceContainer: Services {
let stateService: StateService
/// Provides the present time for TOTP Code Calculation.
let timeProvider: TimeProvider
public let timeProvider: TimeProvider
/// The factory to create TOTP expiration managers.
let totpExpirationManagerFactory: TOTPExpirationManagerFactory

View File

@ -54,13 +54,6 @@ protocol HasCameraService {
var cameraService: CameraService { get }
}
/// Protocol for an object that provides a `ConfigService`.
///
protocol HasConfigService {
/// The service to get server-specified configuration.
var configService: ConfigService { get }
}
/// Protocol for an object that provides a `CryptographyService`
///
protocol HasCryptographyService {
@ -68,13 +61,6 @@ protocol HasCryptographyService {
var cryptographyService: CryptographyService { get }
}
/// Protocol for an object that provides an `ErrorReporter`.
///
protocol HasErrorReporter {
/// The service used by the application to report non-fatal errors.
var errorReporter: ErrorReporter { get }
}
/// Protocol for an object that provides an `ExportItemsService`.
///
protocol HasExportItemsService {
@ -117,13 +103,6 @@ protocol HasTOTPService {
var totpService: TOTPService { get }
}
/// Protocol for an object that provides a `TimeProvider`.
///
protocol HasTimeProvider {
/// Provides the present time for TOTP Code Calculation.
var timeProvider: TimeProvider { get }
}
/// Protocol for an object that provides a `TOTPExpirationManagerFactory`.
///
protocol HasTOTPExpirationManagerFactory {

View File

@ -9,7 +9,9 @@ extension ExternalLinksConstants {
// MARK: Properties
/// A link to Apple's guide on backing up iPhone.
static let backupInformation = URL(string: "https://support.apple.com/guide/iphone/back-up-iphone-iph3ecf67d29/ios")!
static let backupInformation = URL(
string: "https://support.apple.com/guide/iphone/back-up-iphone-iph3ecf67d29/ios",
)!
/// A link to the password manager app within the app store.
static let passwordManagerLink = URL(string: "https://itunes.apple.com/app/id1137397744?mt=8")!

View File

@ -1,3 +1,4 @@
import BitwardenKit
import Foundation
// MARK: - AuthRouter

View File

@ -0,0 +1,46 @@
import BitwardenKit
import BitwardenKitMocks
/// The services provided by the test `ServiceContainer`.
///
typealias Services = HasConfigService
& HasEnvironmentService
& HasErrorReporter
& HasTimeProvider
/// A service container used for testing processors within `BitwardenKitTests`.
///
class ServiceContainer: Services {
let configService: ConfigService
let environmentService: EnvironmentService
let errorReporter: ErrorReporter
let timeProvider: TimeProvider
required init(
configService: ConfigService,
environmentService: EnvironmentService,
errorReporter: ErrorReporter,
timeProvider: TimeProvider,
) {
self.configService = configService
self.environmentService = environmentService
self.errorReporter = errorReporter
self.timeProvider = timeProvider
}
}
extension ServiceContainer {
static func withMocks(
configService: ConfigService = MockConfigService(),
environmentService: EnvironmentService = MockEnvironmentService(),
errorReporter: ErrorReporter = MockErrorReporter(),
timeProvider: TimeProvider = MockTimeProvider(.currentTime),
) -> ServiceContainer {
self.init(
configService: configService,
environmentService: environmentService,
errorReporter: errorReporter,
timeProvider: timeProvider,
)
}
}

View File

@ -0,0 +1,29 @@
// swiftlint:disable:this file_name
/// Protocol for an object that provides a `ConfigService`.
///
public protocol HasConfigService {
/// The service to get server-specified configuration.
var configService: ConfigService { get }
}
/// Protocol for an object that provides an `EnvironmentService`.
///
public protocol HasEnvironmentService {
/// The service used by the application to manage the environment settings.
var environmentService: EnvironmentService { get }
}
/// Protocol for an object that provides an `ErrorReporter`.
///
public protocol HasErrorReporter {
/// The service used by the application to report non-fatal errors.
var errorReporter: ErrorReporter { get }
}
/// Protocol for an object that provides a `TimeProvider`.
///
public protocol HasTimeProvider {
/// Provides the present time for TOTP Code Calculation.
var timeProvider: TimeProvider { get }
}

View File

@ -70,16 +70,16 @@ public class ServiceContainer: Services { // swiftlint:disable:this type_body_le
let clientService: ClientService
/// The service to get server-specified configuration
let configService: ConfigService
public let configService: ConfigService
/// The service used by the application to manage the environment settings.
let environmentService: EnvironmentService
public let environmentService: EnvironmentService
/// A helper for building an error report containing the details of an error that occurred.
let errorReportBuilder: ErrorReportBuilder
/// The service used by the application to report non-fatal errors.
let errorReporter: ErrorReporter
public let errorReporter: ErrorReporter
/// The service used to record and send events.
let eventService: EventService
@ -164,7 +164,7 @@ public class ServiceContainer: Services { // swiftlint:disable:this type_body_le
let textAutofillHelperFactory: TextAutofillHelperFactory
/// Provides the present time for TOTP Code Calculation.
let timeProvider: TimeProvider
public let timeProvider: TimeProvider
/// The service used by the application to manage account access tokens.
let tokenService: TokenService

View File

@ -159,13 +159,6 @@ protocol HasClientService {
var clientService: ClientService { get }
}
/// Protocol for an object that provides a `ConfigService`.
///
protocol HasConfigService {
/// The service to get server-specified configuration.
var configService: ConfigService { get }
}
/// Protocol for an object that provides a `DeviceAPIService`.
///
protocol HasDeviceAPIService {
@ -173,13 +166,6 @@ protocol HasDeviceAPIService {
var deviceAPIService: DeviceAPIService { get }
}
/// Protocol for an object that provides an `EnvironmentService`.
///
protocol HasEnvironmentService {
/// The service used by the application to manage the environment settings.
var environmentService: EnvironmentService { get }
}
/// Protocol for an object that provides an `ErrorReportBuilder`.
///
protocol HasErrorReportBuilder {
@ -187,13 +173,6 @@ protocol HasErrorReportBuilder {
var errorReportBuilder: ErrorReportBuilder { get }
}
/// Protocol for an object that provides an `ErrorReporter`.
///
protocol HasErrorReporter {
/// The service used by the application to report non-fatal errors.
var errorReporter: ErrorReporter { get }
}
/// Protocol for an object that provides an `EventService`.
///
protocol HasEventService {
@ -368,13 +347,6 @@ protocol HasTextAutofillHelperFactory {
var textAutofillHelperFactory: TextAutofillHelperFactory { get }
}
/// Protocol for an object that provides a `TimeProvider`.
///
protocol HasTimeProvider {
/// Provides the present time for TOTP Code Calculation.
var timeProvider: TimeProvider { get }
}
/// Protocol for an object that provides a `TOTPExpirationManagerFactory`.
///
protocol HasTOTPExpirationManagerFactory {

View File

@ -1,3 +1,4 @@
import BitwardenKit
import Foundation
// MARK: - AuthManager

View File

@ -1,3 +1,4 @@
import BitwardenKit
import BitwardenSdk
// MARK: - MasterPasswordRepromptHelper