Extracts duplicated platform integration code from ChronoMind + LysnrAI into a single Swift Package. Eliminates ~1,100+ lines of copied code per product app. Components: - BLPlatformConfig — product-specific configuration (productId, baseURL, bundleId) - BLPlatformClient — generic HTTP client with auth injection, x-request-id, timeout - BLKeychain — Keychain CRUD for secure token storage - BLTelemetryClient — telemetry queue + batch flush (matches @bytelyst/telemetry-client) - BLAuthClient — full auth operations (matches @bytelyst/auth-client) - BLFeatureFlagClient — feature flag polling from platform-service /flags/poll - BLSyncEngine — generic offline-first sync with delta pull + batch push Platforms: iOS 17+, watchOS 10+, macOS 14+
65 lines
2.2 KiB
Swift
65 lines
2.2 KiB
Swift
// ── Platform Configuration ───────────────────────────────────
|
|
// Product-specific config that every BL* service reads from.
|
|
// Each app creates ONE config at launch and passes it to all services.
|
|
|
|
import Foundation
|
|
|
|
/// Configuration for all ByteLyst platform services.
|
|
/// Create one instance at app launch and inject into BLTelemetryClient, BLAuthClient, etc.
|
|
public struct BLPlatformConfig {
|
|
/// Product identifier (e.g. "chronomind", "lysnrai", "peakpulse", "nomgap", "mindlyst").
|
|
public let productId: String
|
|
|
|
/// Platform-service base URL (e.g. "https://api.chronomind.app" or "http://localhost:4003/api").
|
|
public let baseURL: String
|
|
|
|
/// Platform string sent in telemetry (e.g. "ios", "watchos", "macos").
|
|
public let platform: String
|
|
|
|
/// Channel string sent in telemetry (e.g. "native", "mobile_app").
|
|
public let channel: String
|
|
|
|
/// Bundle ID used as Keychain service identifier.
|
|
public let bundleId: String
|
|
|
|
/// App Group ID for sharing data between app and extensions (optional).
|
|
public let appGroupId: String?
|
|
|
|
public init(
|
|
productId: String,
|
|
baseURL: String,
|
|
platform: String = "ios",
|
|
channel: String = "native",
|
|
bundleId: String,
|
|
appGroupId: String? = nil
|
|
) {
|
|
self.productId = productId
|
|
self.baseURL = baseURL
|
|
self.platform = platform
|
|
self.channel = channel
|
|
self.bundleId = bundleId
|
|
self.appGroupId = appGroupId
|
|
}
|
|
|
|
/// Convenience: read PLATFORM_SERVICE_URL from Info.plist, fall back to provided default.
|
|
public static func fromInfoPlist(
|
|
productId: String,
|
|
defaultBaseURL: String,
|
|
platform: String = "ios",
|
|
channel: String = "native",
|
|
bundleId: String,
|
|
appGroupId: String? = nil
|
|
) -> BLPlatformConfig {
|
|
let url = Bundle.main.object(forInfoDictionaryKey: "PLATFORM_SERVICE_URL") as? String
|
|
?? defaultBaseURL
|
|
return BLPlatformConfig(
|
|
productId: productId,
|
|
baseURL: url,
|
|
platform: platform,
|
|
channel: channel,
|
|
bundleId: bundleId,
|
|
appGroupId: appGroupId
|
|
)
|
|
}
|
|
}
|