mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-09 22:35:56 +05:45
* ci: announce modifications in the SDK API feed (#7451) An attribute-only modification is neither an addition nor a break, so it reached the feed as a headline and a link, with the headline claiming new API. * Implement the IAM network operations # Conflicts: # RevenueCat.xcodeproj/project.pbxproj # Conflicts: # RevenueCat.xcodeproj/project.pbxproj * target membership # Conflicts: # RevenueCat.xcodeproj/project.pbxproj * fix test * address cursor feedback * fix imports * revert fetch policy * missed one --------- Co-authored-by: Álvaro Brey <alvaro.brey@revenuecat.com>
50 lines
1.8 KiB
Swift
50 lines
1.8 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// IdentityAPI.swift
|
|
//
|
|
// Created by Joshua Liebowitz on 6/15/22.
|
|
|
|
import Foundation
|
|
|
|
class IdentityAPI {
|
|
typealias LogInResponse = Result<(info: CustomerInfo, created: Bool), BackendError>
|
|
typealias LogInResponseHandler = (LogInResponse) -> Void
|
|
|
|
private let logInCallbacksCache: CallbackCache<LogInCallback>
|
|
|
|
private let backendConfig: BackendConfiguration
|
|
|
|
init(backendConfig: BackendConfiguration) {
|
|
self.backendConfig = backendConfig
|
|
self.logInCallbacksCache = CallbackCache<LogInCallback>()
|
|
}
|
|
|
|
func logIn(currentAppUserID: String,
|
|
newAppUserID: String,
|
|
completion: @escaping LogInResponseHandler) {
|
|
let config = NetworkOperation.UserSpecificConfiguration(httpClient: self.backendConfig.httpClient,
|
|
appUserID: currentAppUserID)
|
|
|
|
let factory = LogInOperation.createFactory(configuration: config,
|
|
newAppUserID: newAppUserID,
|
|
loginCallbackCache: self.logInCallbacksCache)
|
|
|
|
let loginCallback = LogInCallback(cacheKey: factory.cacheKey, completion: completion)
|
|
let cacheStatus = self.logInCallbacksCache.add(loginCallback)
|
|
|
|
self.backendConfig.operationQueue.addCacheableOperation(with: factory, cacheStatus: cacheStatus)
|
|
}
|
|
|
|
}
|
|
|
|
// @unchecked because:
|
|
// - Class is not `final` (it's mocked). This implicitly makes subclasses `Sendable` even if they're not thread-safe.
|
|
extension IdentityAPI: @unchecked Sendable {}
|