Merge pull request #310 from TouchInstinct/feature/TIAuth_TISwiftUICore
feat: TIAuth module + SwiftUIPresenter & UIViewControllerPresenter
This commit is contained in:
commit
c5db547b82
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
### 1.19.0
|
||||
|
||||
- **Add**: Add presenter protocols to `TISwiftUICore` and `TIUIKitCore` modules
|
||||
- **Add**: `CodeConfirmPresenter` protocol and `DefaultCodeConfirmPresenter` implementation in `TIAuth` module
|
||||
|
||||
### 1.18.0
|
||||
|
||||
- **Add**: add MapManagers for routine maps configuration
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKit"
|
||||
s.version = "1.18.0"
|
||||
s.version = "1.19.0"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/TouchInstinct/LeadKit"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ let package = Package(
|
|||
// MARK: - UIKit
|
||||
.library(name: "TIUIKitCore", targets: ["TIUIKitCore"]),
|
||||
.library(name: "TIUIElements", targets: ["TIUIElements"]),
|
||||
|
||||
// MARK: - SwiftUI
|
||||
.library(name: "TISwiftUICore", targets: ["TISwiftUICore"]),
|
||||
|
||||
// MARK: - Utils
|
||||
.library(name: "TISwiftUtils", targets: ["TISwiftUtils"]),
|
||||
|
|
@ -33,6 +36,7 @@ let package = Package(
|
|||
.library(name: "OTPSwiftView", targets: ["OTPSwiftView"]),
|
||||
.library(name: "TITransitions", targets: ["TITransitions"]),
|
||||
.library(name: "TIPagination", targets: ["TIPagination"]),
|
||||
.library(name: "TIAuth", targets: ["TIAuth"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/maxsokolov/TableKit.git", .upToNextMajor(from: "2.11.0")),
|
||||
|
|
@ -47,6 +51,10 @@ let package = Package(
|
|||
// MARK: - UIKit
|
||||
.target(name: "TIUIKitCore", path: "TIUIKitCore/Sources"),
|
||||
.target(name: "TIUIElements", dependencies: ["TIUIKitCore", "TISwiftUtils"], path: "TIUIElements/Sources"),
|
||||
|
||||
// MARK: - SwiftUI
|
||||
|
||||
.target(name: "TISwiftUICore", path: "TISwiftUICore/Sources"),
|
||||
|
||||
// MARK: - Utils
|
||||
.target(name: "TISwiftUtils", path: "TISwiftUtils/Sources"),
|
||||
|
|
@ -70,6 +78,7 @@ let package = Package(
|
|||
.target(name: "OTPSwiftView", dependencies: ["TIUIElements"], path: "OTPSwiftView/Sources"),
|
||||
.target(name: "TITransitions", path: "TITransitions/Sources"),
|
||||
.target(name: "TIPagination", dependencies: ["Cursors", "TISwiftUtils"], path: "TIPagination/Sources"),
|
||||
.target(name: "TIAuth", dependencies: ["TIFoundationUtils"], path: "TIAuth/Sources"),
|
||||
|
||||
// MARK: - Tests
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIAppleMapUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for map objects clustering and interacting using Apple MapKit.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
# TIAuth
|
||||
|
||||
Login, registration, confirmation and other related actions
|
||||
|
||||
## CodeConfirmPresenter
|
||||
|
||||
### Features
|
||||
|
||||
- Code confirm and code refresh actions
|
||||
- Code refresh countdown in foreground and background
|
||||
- Additional 2FA auth handling
|
||||
- Remaining attempts handling
|
||||
- Code autofill from custom sources (push, etc)
|
||||
- UIKit and SwiftUI compatible
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
protocol CodeConfirmPresenter {
|
||||
// MARK: - User actions handling
|
||||
|
||||
func inputChanged(newInput: String?)
|
||||
func refreshCode()
|
||||
|
||||
// MARK: - View lifecycle handling
|
||||
|
||||
func viewDidPresented()
|
||||
|
||||
// MARK: - Autofill
|
||||
|
||||
func autofill(code: String, with codeId: String?)
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
public protocol CodeConfirmStateStorage: AnyObject {
|
||||
var currentUserInput: String? { get set }
|
||||
var canRefreshCodeAfter: Int? { get set }
|
||||
var remainingAttempts: Int? { get set }
|
||||
var isExecutingRequest: Bool { get set }
|
||||
var canRequestNewCode: Bool { get set }
|
||||
}
|
||||
|
|
@ -0,0 +1,295 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import TIFoundationUtils
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
open class DefaultCodeConfirmPresenter<ConfirmResponse: CodeConfirmResponse,
|
||||
RefreshResponse: CodeRefreshResponse>: CodeConfirmPresenter {
|
||||
|
||||
open class Output {
|
||||
public typealias OnConfirmSuccessClosure = (ConfirmResponse) -> Void
|
||||
|
||||
public var onConfirmSuccess: OnConfirmSuccessClosure
|
||||
|
||||
public init(onConfirmSuccess: @escaping OnConfirmSuccessClosure) {
|
||||
self.onConfirmSuccess = onConfirmSuccess
|
||||
}
|
||||
}
|
||||
|
||||
open class Requests {
|
||||
public typealias ConfirmRequestClosure = (String) async -> ConfirmResponse
|
||||
public typealias RefreshRequestClosure = () async -> RefreshResponse
|
||||
|
||||
public var confirmRequest: ConfirmRequestClosure
|
||||
public var refreshRequest: RefreshRequestClosure
|
||||
|
||||
public init(confirmRequest: @escaping ConfirmRequestClosure,
|
||||
refreshRequest: @escaping RefreshRequestClosure) {
|
||||
|
||||
self.confirmRequest = confirmRequest
|
||||
self.refreshRequest = refreshRequest
|
||||
}
|
||||
}
|
||||
|
||||
public struct Config {
|
||||
public enum Defaults {
|
||||
public static var codeLength: Int {
|
||||
6
|
||||
}
|
||||
|
||||
public static var autoRefresh: Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
public var codeLength: Int
|
||||
public var autoRefresh: Bool
|
||||
|
||||
public init(codeLength: Int = Defaults.codeLength,
|
||||
autoRefresh: Bool = Defaults.autoRefresh) {
|
||||
|
||||
self.codeLength = codeLength
|
||||
self.autoRefresh = autoRefresh
|
||||
}
|
||||
}
|
||||
|
||||
private let codeRefreshTimer = TITimer(mode: .activeAndBackground)
|
||||
private let codeLifetimeTimer = TITimer(mode: .activeAndBackground)
|
||||
|
||||
public var output: Output
|
||||
public var requests: Requests
|
||||
public weak var stateStorage: CodeConfirmStateStorage?
|
||||
public var config = Config()
|
||||
public var currentCodeResponse: CodeResponse
|
||||
|
||||
public init<Input: CodeResponse>(input: Input,
|
||||
output: Output,
|
||||
requests: Requests,
|
||||
stateStorage: CodeConfirmStateStorage? = nil) {
|
||||
|
||||
self.currentCodeResponse = input
|
||||
self.output = output
|
||||
self.requests = requests
|
||||
self.stateStorage = stateStorage
|
||||
}
|
||||
|
||||
// MARK: - Requests
|
||||
|
||||
open func confirm(code: String) async {
|
||||
stateStorage?.isExecutingRequest = true
|
||||
|
||||
let confirmResponse = await requests.confirmRequest(code)
|
||||
|
||||
isSuccessConfirm(response: confirmResponse)
|
||||
? handle(successConfirmResponse: confirmResponse)
|
||||
: handle(failureConfirmResponse: confirmResponse)
|
||||
|
||||
stateStorage?.isExecutingRequest = false
|
||||
}
|
||||
|
||||
open func refreshCode() async {
|
||||
stateStorage?.isExecutingRequest = true
|
||||
|
||||
let refreshResponse = await requests.refreshRequest()
|
||||
|
||||
if isSuccessRefresh(response: refreshResponse) {
|
||||
handle(successRefreshResponse: refreshResponse)
|
||||
} else {
|
||||
handle(failureRefreshResponse: refreshResponse)
|
||||
}
|
||||
|
||||
stateStorage?.isExecutingRequest = false
|
||||
}
|
||||
|
||||
// MARK: - Response handling
|
||||
|
||||
open func handle(successConfirmResponse response: ConfirmResponse) {
|
||||
if let additionalAuth = response.requiredAdditionalAuth {
|
||||
handle(additionalAuth: additionalAuth)
|
||||
} else {
|
||||
output.onConfirmSuccess(response)
|
||||
}
|
||||
}
|
||||
|
||||
open func handle(failureConfirmResponse: ConfirmResponse) {
|
||||
stateStorage?.currentUserInput = nil
|
||||
|
||||
if let remainingAttempts = failureConfirmResponse.remainingAttempts, remainingAttempts <= 0 {
|
||||
onConfirmAttemptsExhausted()
|
||||
}
|
||||
|
||||
// show error message, etc.
|
||||
}
|
||||
|
||||
open func handle(additionalAuth auth: String) {
|
||||
// custom subclass handling
|
||||
}
|
||||
|
||||
open func onConfirmAttemptsExhausted() {
|
||||
// custom subclass handling
|
||||
}
|
||||
|
||||
open func handle(successRefreshResponse response: RefreshResponse) {
|
||||
updateStateStorage(from: response)
|
||||
|
||||
start(codeLifetimeTimer: codeLifetimeTimer,
|
||||
codeRefreshTimer: codeRefreshTimer,
|
||||
for: response)
|
||||
}
|
||||
|
||||
func handle(failureRefreshResponse response: RefreshResponse) {
|
||||
updateStateStorage(from: response)
|
||||
|
||||
// show error message, etc.
|
||||
}
|
||||
|
||||
// MARK: - Response processing
|
||||
|
||||
open func lifetimeDuration(of code: CodeResponse) -> Int? {
|
||||
code.validUntil?.timeIntervalSinceNow.intValue
|
||||
}
|
||||
|
||||
open func nonRefreshableInterval(of code: CodeResponse) -> Int? {
|
||||
code.refreshableAfter?.timeIntervalSinceNow.intValue ?? lifetimeDuration(of: code)
|
||||
}
|
||||
|
||||
open func isSuccessConfirm(response: ConfirmResponse) -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
open func isSuccessRefresh(response: RefreshResponse) -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
// MARK: - User actions handling
|
||||
|
||||
open func inputChanged(newInput: String?) {
|
||||
stateStorage?.currentUserInput = newInput
|
||||
|
||||
if let code = newInput, code.count >= config.codeLength {
|
||||
stateStorage?.isExecutingRequest = true
|
||||
|
||||
Task {
|
||||
await confirm(code: code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open func refreshCode() {
|
||||
stateStorage?.canRequestNewCode = false
|
||||
stateStorage?.canRefreshCodeAfter = nil
|
||||
|
||||
Task {
|
||||
await refreshCode()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - View lifecycle handling
|
||||
|
||||
open func viewDidPresented() {
|
||||
start(codeLifetimeTimer: codeLifetimeTimer,
|
||||
codeRefreshTimer: codeRefreshTimer,
|
||||
for: currentCodeResponse)
|
||||
}
|
||||
|
||||
// MARK: - Autofill
|
||||
|
||||
open func autofill(code: String, with codeId: String? = nil) {
|
||||
guard currentCodeResponse.codeId == codeId else {
|
||||
return
|
||||
}
|
||||
|
||||
inputChanged(newInput: code)
|
||||
}
|
||||
|
||||
// MARK: - Subclass customization
|
||||
|
||||
open func start(codeLifetimeTimer: TITimer,
|
||||
codeRefreshTimer: TITimer,
|
||||
for code: CodeResponse) {
|
||||
|
||||
start(codeRefreshTimer: codeRefreshTimer, for: code)
|
||||
start(codeLifetimeTimer: codeLifetimeTimer, for: code)
|
||||
}
|
||||
|
||||
open func start(codeRefreshTimer: TITimer, for code: CodeResponse) {
|
||||
guard let nonRefreshableInterval = nonRefreshableInterval(of: code) else {
|
||||
return
|
||||
}
|
||||
|
||||
codeRefreshTimer.eventHandler = { [weak self] in
|
||||
self?.updateRemaining(nonRefreshableInterval: nonRefreshableInterval,
|
||||
elapsedInterval: $0)
|
||||
}
|
||||
codeRefreshTimer.start()
|
||||
}
|
||||
|
||||
open func updateRemaining(nonRefreshableInterval: Int, elapsedInterval: TimeInterval) {
|
||||
let secondsLeft = nonRefreshableInterval - elapsedInterval.intValue
|
||||
|
||||
stateStorage?.canRefreshCodeAfter = secondsLeft
|
||||
stateStorage?.canRequestNewCode = secondsLeft <= 0
|
||||
|
||||
if secondsLeft < 0 {
|
||||
codeRefreshTimer.pause()
|
||||
}
|
||||
}
|
||||
|
||||
open func start(codeLifetimeTimer: TITimer, for code: CodeResponse) {
|
||||
guard let lifetimeInterval = lifetimeDuration(of: code) else {
|
||||
return
|
||||
}
|
||||
|
||||
codeLifetimeTimer.eventHandler = { [weak self] in
|
||||
self?.updateRemaining(lifetimeInterval: lifetimeInterval,
|
||||
elapsedInterval: $0)
|
||||
}
|
||||
codeLifetimeTimer.start()
|
||||
}
|
||||
|
||||
open func updateRemaining(lifetimeInterval: Int, elapsedInterval: TimeInterval) {
|
||||
let secondsLeft = lifetimeInterval - elapsedInterval.intValue
|
||||
|
||||
if secondsLeft < 0 {
|
||||
codeLifetimeTimer.pause()
|
||||
|
||||
if config.autoRefresh {
|
||||
refreshCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open func updateStateStorage(from response: CodeResponse) {
|
||||
stateStorage?.remainingAttempts = response.remainingAttempts
|
||||
stateStorage?.currentUserInput = nil
|
||||
stateStorage?.canRefreshCodeAfter = nonRefreshableInterval(of: response)
|
||||
stateStorage?.canRequestNewCode = (stateStorage?.canRefreshCodeAfter ?? 0) <= 0
|
||||
}
|
||||
}
|
||||
|
||||
private extension TimeInterval {
|
||||
var intValue: Int {
|
||||
Int(self)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public protocol CodeConfirmResponse: CodeResponse {
|
||||
var requiredAdditionalAuth: String? { get }
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public protocol CodeRefreshResponse: CodeResponse {
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol CodeResponse {
|
||||
var validUntil: Date? { get }
|
||||
var codeId: String? { get }
|
||||
var refreshableAfter: Date? { get }
|
||||
var confirmationId: String? { get }
|
||||
var remainingAttempts: Int? { get }
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Result {
|
||||
var success: Success? {
|
||||
if case let .success(wrapped) = self {
|
||||
return wrapped
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension Result: CodeResponse where Success: CodeResponse {
|
||||
public var validUntil: Date? {
|
||||
success?.validUntil
|
||||
}
|
||||
|
||||
public var codeId: String? {
|
||||
success?.codeId
|
||||
}
|
||||
|
||||
public var refreshableAfter: Date? {
|
||||
success?.refreshableAfter
|
||||
}
|
||||
|
||||
public var confirmationId: String? {
|
||||
success?.confirmationId
|
||||
}
|
||||
|
||||
public var remainingAttempts: Int? {
|
||||
success?.remainingAttempts
|
||||
}
|
||||
}
|
||||
|
||||
extension Result: CodeRefreshResponse where Success: CodeRefreshResponse {
|
||||
}
|
||||
|
||||
extension Result: CodeConfirmResponse where Success: CodeConfirmResponse {
|
||||
public var remainingAttempts: Int? {
|
||||
success?.remainingAttempts
|
||||
}
|
||||
|
||||
public var requiredAdditionalAuth: String? {
|
||||
success?.requiredAdditionalAuth
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIAuth'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Login, registration, confirmation and other related actions'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.author = { 'petropavel13' => 'ivan.smolin@touchin.ru' }
|
||||
s.source = { :git => 'https://github.com/TouchInstinct/LeadKit.git', :tag => s.version.to_s }
|
||||
|
||||
s.ios.deployment_target = '13.0'
|
||||
s.swift_versions = ['5.3']
|
||||
|
||||
s.source_files = s.name + '/Sources/**/*'
|
||||
|
||||
s.dependency 'TIFoundationUtils', s.version.to_s
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIFoundationUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for Foundation framework classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIGoogleMapUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for map objects clustering and interacting using Google Maps SDK.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIKeychainUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for Keychain classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit.UIGeometry
|
||||
|
||||
open class BaseMapManager<Map,
|
||||
PM: PlacemarkManager,
|
||||
CPM: PlacemarkManager,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIMapUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for map objects clustering and interacting.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import Foundation
|
|||
import TIFoundationUtils
|
||||
|
||||
open class DefaultJsonNetworkService {
|
||||
public typealias RequestResult<S: Decodable, AE: Decodable> = EndpointRequestResult<S, AE, MoyaError>
|
||||
|
||||
public var session: Session
|
||||
|
||||
public var serializationQueue: DispatchQueue = .global(qos: .default)
|
||||
|
|
@ -65,7 +67,7 @@ open class DefaultJsonNetworkService {
|
|||
}
|
||||
|
||||
@available(iOS 13.0.0, *)
|
||||
open func process<B: Encodable, S, F>(request: EndpointRequest<B, S>) async -> EndpointRequestResult<S, F> {
|
||||
open func process<B: Encodable, S, F>(request: EndpointRequest<B, S>) async -> RequestResult<S, F> {
|
||||
await process(request: request,
|
||||
mapSuccess: Result.success,
|
||||
mapFailure: { .failure(.apiError($0)) },
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@
|
|||
import Moya
|
||||
import Foundation
|
||||
|
||||
public enum EndpointErrorResult<E>: Error {
|
||||
case apiError(E)
|
||||
case networkError(MoyaError)
|
||||
public enum EndpointErrorResult<ApiError, NetworkError>: Error {
|
||||
case apiError(ApiError)
|
||||
case networkError(NetworkError)
|
||||
}
|
||||
|
||||
public extension EndpointErrorResult {
|
||||
public extension EndpointErrorResult where NetworkError == MoyaError {
|
||||
var isNetworkConnectionProblem: Bool {
|
||||
guard case let .networkError(moyaError) = self,
|
||||
case let .underlying(error, _) = moyaError,
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public typealias EndpointRequestResult<S: Decodable, F: Decodable> = Result<S, EndpointErrorResult<F>>
|
||||
public typealias EndpointRequestResult<S: Decodable, AE: Decodable, NE> = Result<S, EndpointErrorResult<AE, NE>>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import TISwiftUtils
|
|||
|
||||
@available(iOS 13.0.0, *)
|
||||
open class DefaultRecoverableJsonNetworkService<ApiError: Decodable & Error>: DefaultJsonNetworkService {
|
||||
public typealias ErrorType = EndpointErrorResult<ApiError>
|
||||
public typealias ErrorType = EndpointErrorResult<ApiError, MoyaError>
|
||||
public typealias ErrorHandlerResultType = RecoverableErrorHandlerResult<ErrorType>
|
||||
public typealias ErrorHandlerType = AnyAsyncEventHandler<ErrorType, ErrorHandlerResultType>
|
||||
|
||||
|
|
@ -35,16 +35,16 @@ open class DefaultRecoverableJsonNetworkService<ApiError: Decodable & Error>: De
|
|||
open func process<B: Encodable, S>(recoverableRequest: EndpointRequest<B, S>,
|
||||
prependErrorHandlers: [ErrorHandlerType] = [],
|
||||
appendErrorHandlers: [ErrorHandlerType] = []) async ->
|
||||
EndpointRequestResult<S, ApiError> {
|
||||
RequestResult<S, ApiError> {
|
||||
|
||||
await process(recoverableRequest: recoverableRequest,
|
||||
errorHandlers: prependErrorHandlers + defaultErrorHandlers + appendErrorHandlers)
|
||||
}
|
||||
|
||||
open func process<B: Encodable, S>(recoverableRequest: EndpointRequest<B, S>,
|
||||
errorHandlers: [ErrorHandlerType]) async -> EndpointRequestResult<S, ApiError> {
|
||||
errorHandlers: [ErrorHandlerType]) async -> RequestResult<S, ApiError> {
|
||||
|
||||
let result: EndpointRequestResult<S, ApiError> = await process(request: recoverableRequest)
|
||||
let result: RequestResult<S, ApiError> = await process(request: recoverableRequest)
|
||||
|
||||
if case let .failure(errorResponse) = result {
|
||||
for handler in errorHandlers {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIMoyaNetworking'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Moya + Swagger network service.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TINetworking'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Swagger-frendly networking layer helpers.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TINetworkingCache'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Caching results of EndpointRequests.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIPagination'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Generic pagination component.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# TISwiftUICore
|
||||
|
||||
Core UI elements: protocols, views and helpers.
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
@available(iOS 13.0, *)
|
||||
public protocol SwiftUIPresenter: ObservableObject {
|
||||
associatedtype View: SwiftUI.View
|
||||
|
||||
func createView() -> View
|
||||
|
||||
#if DEBUG
|
||||
static func assembleForPreview() -> Self
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TISwiftUICore'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Core UI elements: protocols, views and helpers..'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.author = { 'petropavel13' => 'ivan.smolin@touchin.ru' }
|
||||
s.source = { :git => 'https://github.com/TouchInstinct/LeadKit.git', :tag => s.version.to_s }
|
||||
|
||||
s.ios.deployment_target = '13.0'
|
||||
s.swift_versions = ['5.3']
|
||||
|
||||
s.source_files = s.name + '/Sources/**/*'
|
||||
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TISwiftUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Bunch of useful helpers for Swift development.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TITableKitUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for TableKit classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TITransitions'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of custom transitions to present controller. '
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIUIElements'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Bunch of useful protocols and views.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Copyright (c) 2022 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import UIKit.UIViewController
|
||||
|
||||
@MainActor
|
||||
public protocol UIViewControllerPresenter {
|
||||
associatedtype ViewController: UIViewController
|
||||
|
||||
func createViewController() -> ViewController
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIUIKitCore'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Core UI elements: protocols, views and helpers.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIYandexMapUtils'
|
||||
s.version = '1.18.0'
|
||||
s.version = '1.19.0'
|
||||
s.summary = 'Set of helpers for map objects clustering and interacting using Yandex Maps SDK.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ ORDERED_PODSPECS="../TISwiftUtils/TISwiftUtils.podspec
|
|||
../TIFoundationUtils/TIFoundationUtils.podspec
|
||||
../TIKeychainUtils/TIKeychainUtils.podspec
|
||||
../TIUIKitCore/TIUIKitCore.podspec
|
||||
../TISwiftUICore/TISwiftUICore.podspec
|
||||
../TIUIElements/TIUIElements.podspec
|
||||
../TIAuth/TIAuth.podspec
|
||||
../TITableKitUtils/TITableKitUtils.podspec
|
||||
../TINetworking/TINetworking.podspec
|
||||
../TINetworkingCache/TINetworkingCache.podspec
|
||||
|
|
|
|||
Loading…
Reference in New Issue