Skip to content

chore: objc compatibitlity for cmp #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OtplessBM.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'OtplessBM'
s.version = '1.1.2'
s.version = '1.1.3'
s.summary = 'Standalone SDK for Otpless Headless functionality.'

s.description = <<-DESC
Expand Down
16 changes: 16 additions & 0 deletions Sources/OtplessBM/Otpless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ import Network

internal private(set) var otpLength: Int = -1

internal private(set) var objcResponseDelegate: ((String) -> Void)?

@objc public func initialise(
withAppId appId: String,
loginUri: String? = nil,
Expand Down Expand Up @@ -278,6 +280,15 @@ import Network
self.responseDelegate = nil
self.oneTapDataDelegate = nil
}

@objc public func objcCommit(_ otplessResponse: String?) {
let responseDict = Utils.convertStringToDictionary(otplessResponse ?? "") ?? [:]
let responseType = ResponseTypes(rawValue: responseDict["responseType"] as? String ?? "") ?? .FAILED
let response = responseDict["response"] as? [String: Any]
let statusCode = responseDict["statusCode"] as? Int ?? -10699
let otplResponse = OtplessResponse(responseType: responseType, response: response, statusCode: statusCode)
commitOtplessResponse(otplResponse)
}
}

internal extension Otpless {
Expand All @@ -297,6 +308,11 @@ extension Otpless {
sendEvent(event: .SET_HEADLESS_CALLBACK)
}

@objc public func setOtplessObjcResponseDelegate(_ otplessResponseDelegate: @escaping (String) -> Void) {
self.objcResponseDelegate = otplessResponseDelegate
sendEvent(event: .SET_HEADLESS_CALLBACK)
}

public func setLoggerDelegate(_ otplessLoggerDelegate: OtplessLoggerDelegate) {
self.loggerDelegate = otplessLoggerDelegate
}
Expand Down
24 changes: 24 additions & 0 deletions Sources/OtplessBM/dto/OtplessChannelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,27 @@ public enum OtplessChannelType: String, CaseIterable {
return OtplessChannelType.allCases.first { $0.rawValue.caseInsensitiveCompare(value) == .orderedSame } ?? .WHATSAPP
}
}

@objc public class OtplessChannelTypeObjC: NSObject {
@objc public static let WHATSAPP = "WHATSAPP"
@objc public static let GOOGLE_SDK = "GOOGLE_SDK"
@objc public static let FACEBOOK_SDK = "FACEBOOK_SDK"
@objc public static let APPLE_SDK = "APPLE_SDK"
@objc public static let APPLE = "APPLE_EMAIL"
@objc public static let GMAIL = "GMAIL"
@objc public static let TWITTER = "TWITTER"
@objc public static let DISCORD = "DISCORD"
@objc public static let SLACK = "SLACK"
@objc public static let FACEBOOK = "FACEBOOK"
@objc public static let LINKEDIN = "LINKEDIN"
@objc public static let MICROSOFT = "MICROSOFT"
@objc public static let LINE = "LINE"
@objc public static let LINEAR = "LINEAR"
@objc public static let NOTION = "NOTION"
@objc public static let TWITCH = "TWITCH"
@objc public static let GITHUB = "GITHUB"
@objc public static let BITBUCKET = "BITBUCKET"
@objc public static let ATLASSIAN = "ATLASSIAN"
@objc public static let GITLAB = "GITLAB"
@objc public static let TRUE_CALLER = "TRUE_CALLER"
}
32 changes: 20 additions & 12 deletions Sources/OtplessBM/dto/OtplessRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import Foundation
private var oneTapValue: String?
private var tid: String?

public func set(phoneNumber: String, withCountryCode countryCode: String) {
@objc public func set(phoneNumber: String, withCountryCode countryCode: String) {
self.phoneNumber = phoneNumber
self.countryCode = countryCode
self.authenticationMedium = .PHONE
self.email = nil
}

public func set(email: String) {
@objc public func set(email: String) {
self.email = email
self.authenticationMedium = .EMAIL
self.phoneNumber = nil
Expand All @@ -46,44 +46,52 @@ import Foundation
self.email = nil
}

public func set(requestIdForWebAuthn requestId: String) {
@objc public func set(objcChannelType: String) {
self.channelType = OtplessChannelType.fromString(objcChannelType)
self.authenticationMedium = .OAUTH
self.phoneNumber = nil
self.countryCode = nil
self.email = nil
}

@objc public func set(requestIdForWebAuthn requestId: String) {
self.requestId = requestId
self.authenticationMedium = .WEB_AUTHN
}

public func set(otp: String) {
@objc public func set(otp: String) {
self.otp = otp
}

public func set(otpExpiry: String) {
@objc public func set(otpExpiry: String) {
self.expiry = otpExpiry
}

public func set(otpLength: String) {
@objc public func set(otpLength: String) {
self.otpLength = otpLength
}

public func set(deliveryChannelForTransaction deliveryChannel: String) {
@objc public func set(deliveryChannelForTransaction deliveryChannel: String) {
self.deliveryChannel = deliveryChannel
}

public func set(locale: String) {
@objc public func set(locale: String) {
self.locale = locale
}

public func set(code: String) {
@objc public func set(code: String) {
self.code = code
}

public func set(extras: [String: String]) {
@objc public func set(extras: [String: String]) {
self.extras = extras
}

public func set(tid: String) {
@objc public func set(tid: String) {
self.tid = tid
}

public func getRequestId() -> String {
@objc public func getRequestId() -> String {
return self.requestId ?? ""
}
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/OtplessBM/dto/OtplessResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ public struct OtplessResponse: @unchecked Sendable {
self.statusCode = statusCode
}

internal func toJsonString() -> String {
var dict: [String: Any] = [
"responseType": responseType.rawValue
]
if let response = response {
dict["response"] = response
}
dict["statusCode"] = statusCode
return Utils.convertDictionaryToString(dict)
}

internal static let failedToInitializeResponse = OtplessResponse(responseType: .FAILED, response: [
"errorCode": "5003",
"errorMessage": "Failed to initialize the SDK"
Expand Down
1 change: 1 addition & 0 deletions Sources/OtplessBM/extensions/OtplessExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ extension Otpless {

DispatchQueue.main.async {
self.responseDelegate?.onResponse(otplessResponse)
self.objcResponseDelegate?(otplessResponse.toJsonString())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OtplessBM/utils/DeviceInfoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class DeviceInfoUtils : @unchecked Sendable {
params["tsid"] = tsid
}

params["sdkVersion"] = "1.1.2"
params["sdkVersion"] = "1.1.3"

params["osVersion"] = os.majorVersion.description + "." + os.minorVersion.description
params["hasWhatsapp"] = hasWhatsApp.description
Expand Down
2 changes: 1 addition & 1 deletion Sources/OtplessBM/utils/EventHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func sendEvent(event: EventConstants, extras: [String: String] = [:], musId: Str
var params = [String: String]()
params["event_name"] = event.rawValue
params["platform"] = "iOS-headless"
params["sdk_version"] = "1.1.2"
params["sdk_version"] = "1.1.3"
params["mid"] = Otpless.shared.merchantAppId
params["event_timestamp"] = Utils.formatCurrentTimeToDateString()

Expand Down