Skip to content

Commit

Permalink
MOB-1000 #comment mapped all native ios apis and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
shachartransmit committed May 1, 2024
1 parent 55ec677 commit 481e246
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = M3RV2Q6B99;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = TsIdentityOrchestrationExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -480,7 +481,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "com.transmitsecurity.reactnative-ido-example";
PRODUCT_NAME = TsIdentityOrchestrationExample;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -495,6 +496,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = M3RV2Q6B99;
INFOPLIST_FILE = TsIdentityOrchestrationExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -506,7 +508,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "com.transmitsecurity.reactnative-ido-example";
PRODUCT_NAME = TsIdentityOrchestrationExample;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -586,10 +588,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -661,10 +660,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
1 change: 0 additions & 1 deletion example/ios/TsIdentityOrchestrationExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
Expand Down
143 changes: 142 additions & 1 deletion ios/TsIdentityOrchestration.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import IdentityOrchestration
import React

@objc(TsIdentityOrchestration)
class TsIdentityOrchestration: NSObject {
class TsIdentityOrchestration: RCTEventEmitter {

private static let ResponseHandlerEventName = "tsido_response_handler_event"
private let kTag = "TSIdentityOrchestration"
private var isListening: Bool = false

@objc(initializeSDK:withRejecter:)
func initializeSDK(
Expand All @@ -13,6 +16,7 @@ class TsIdentityOrchestration: NSObject {
guard let self = self else { return }

do {
TSIdo.delegate = self
try TSIdo.initializeSDK()
resolve(true)
} catch {
Expand Down Expand Up @@ -75,6 +79,33 @@ class TsIdentityOrchestration: NSObject {
)
}

// MARK: - Events

@objc override func supportedEvents() -> [String]! {
return [TsIdentityOrchestration.ResponseHandlerEventName]
}

override func startObserving() {
isListening = true
}

override func stopObserving() {
isListening = false
}

// MARK: - RCTEventEmitter

private func reportResponseEvent(_ success: Bool, additionalData: [String: Any?]) {
guard isListening else { return }
self.sendEvent(
withName: TsIdentityOrchestration.ResponseHandlerEventName,
body: [
"success": success,
"additionalData": additionalData
]
)
}

// MARK: - Threading

private func runBlockOnMain(_ block: @escaping () -> Void) {
Expand All @@ -83,3 +114,113 @@ class TsIdentityOrchestration: NSObject {
}
}
}

extension TsIdentityOrchestration: TSIdoDelegate {
func TSIdoDidReceiveResult(_ result: Result<TSIdoServiceResponse, TSIdoJourneyError>) {
switch result {
case .success(let response):
reportResponseEvent(true, additionalData: convertServiceResponse(response))
case .failure(let error):
reportResponseEvent(false, additionalData: convertServiceError(error))
}
}

private func convertServiceResponse(_ response: TSIdoServiceResponse) -> [String: Any?] {
let options = response.clientResponseOptions

var jsResponse: [String: Any?] = [
"data": response.data,
"errorData": convertErrorData(response.errorData),
"journeyStepId": idoJourneyStepIdToString(response.journeyStepId),
"clientResponseOptions": convertClientResponseOption(response.clientResponseOptions),
"token": response.token
]

return jsResponse
}

private func convertServiceError(_ error: TSIdoJourneyError) -> [String: Any] {
return ["error": idoErrorCodeToString(error)]
}

// MARK: Convertion Helpers

private func convertErrorData(_ errorData: TSIdoSdkError?) -> [String: Any?]? {
guard let errorData = errorData else { return nil }

return [
"errorCode": idoErrorCodeToString(errorData.errorCode),
"description": errorData.description,
"data": errorData.data
]
}

private func idoJourneyStepIdToString(_ journeyStepId: IdentityOrchestration.TSIdoJourneyActionType?) -> String? {
guard let journeyStepId = journeyStepId else { return nil }

switch journeyStepId {

case .success: return "success"
case .rejection: return "rejection"
case .information: return "information"
case .debugBreak: return "debugBreak"
case .waitForAnotherDevice: return "waitForAnotherDevice"
case .drsTriggerAction: return "drsTriggerAction"
case .identityVerification: return "identityVerification"
case .webAuthnRegistration: return "webAuthnRegistration"
case .registerDeviceAction: return "registerDeviceAction"
case .validateDeviceAction: return "validateDeviceAction"
case .nativeBiometricsRegistration: return "nativeBiometricsRegistration"
case .nativeBiometricsAuthenticaton: return "nativeBiometricsAuthenticaton"
case .emailOTPAuthentication: return "emailOTPAuthentication"
case .smsOTPAuthentication: return "smsOTPAuthentication"
case .custom(name: let name): return "\(name)"
@unknown default: return "@unknown"
}
}

private func idoErrorCodeToString(_ errorCode: IdentityOrchestration.TSIdoJourneyError) -> String {
switch errorCode {
case .notInitialized: return "notInitialized"
case .networkError: return "networkError"
case .clientResponseNotValid: return "clientResponseNotValid"
case .serverError(_): return "serverError"
case .initializationError: return "initializationError"
case .invalidCredentials: return "invalidCredentials"
@unknown default: return "@unknown"
}
}

private func convertClientResponseOption(
_ responseOptions: [String : IdentityOrchestration.TSIdoClientResponseOption]?
) -> [String: Any?]? {

guard let responseOptions = responseOptions else { return nil }

var jsOptions: [String: Any?] = [:]

for (key, value) in responseOptions {
let option: [String: Any?] = [
"type": responseOptionTypeToString(value.type),
"id": value.id,
"label": value.label
]
jsOptions[key] = option
}

return jsOptions
}

private func responseOptionTypeToString(
_ optionType: IdentityOrchestration.TSIdoClientResponseOptionType
) -> String {
switch optionType {
case .clientInput: return "clientInput"
case .cancel: return "cancel"
case .fail: return "fail"
case .resend: return "resend"
case .custom(id: let id): return "\(id)"
@unknown default: return "unknown"
}
}
}
6 changes: 1 addition & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ export namespace TSIDOModule {
token?: string | null;
}

export interface JourneyError {

}

export interface ResponseHandler {
success: (results: TSIDOModule.ServiceResponse) => void;
error: (results: TSIDOModule.JourneyError) => void;
error: (results: TSIDOModule.JourneyErrorType) => void;
}

// Module API
Expand Down

0 comments on commit 481e246

Please sign in to comment.