@humansecurity/expo-mobile-sdk 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/android/build.gradle +53 -0
- package/android/libs/HUMAN-4.0.3.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/humansdk/ExpoHumanSdkModule.kt +167 -0
- package/build/ExpoHumanSdk.types.d.ts +19 -0
- package/build/ExpoHumanSdk.types.d.ts.map +1 -0
- package/build/ExpoHumanSdk.types.js +7 -0
- package/build/ExpoHumanSdk.types.js.map +1 -0
- package/build/ExpoHumanSdkModule.d.ts +25 -0
- package/build/ExpoHumanSdkModule.d.ts.map +1 -0
- package/build/ExpoHumanSdkModule.js +8 -0
- package/build/ExpoHumanSdkModule.js.map +1 -0
- package/build/HumanSecurity.d.ts +37 -0
- package/build/HumanSecurity.d.ts.map +1 -0
- package/build/HumanSecurity.js +62 -0
- package/build/HumanSecurity.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +16 -0
- package/ios/ExpoHumanSdkModule.swift +221 -0
- package/ios/HumanSecurity.podspec +30 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# expo-mobile-sdk
|
|
2
|
+
|
|
3
|
+
A model implementing our native SDK's with the expo framework.
|
|
4
|
+
|
|
5
|
+
# API documentation
|
|
6
|
+
|
|
7
|
+
# Installation in managed Expo projects -
|
|
8
|
+
From the terminal run:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install @humansecurity/expo-mobile-sdk
|
|
12
|
+
npx expo prebuild
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Usage example
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
import { HumanSecurity } from '@humansecurity/expo-mobile-sdk';
|
|
19
|
+
|
|
20
|
+
//Display the version text in a tag to confirm integration:
|
|
21
|
+
<ThemedText type="title">{HumanSecurity.sdkVersion()}</ThemedText>
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
The full Documentation and usage examples can be found at our [official site](https://docs.humansecurity.com/applications-and-accounts/docs/expo-integration).
|
|
25
|
+
|
|
26
|
+
### The current API:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
sdkVersion(): string;
|
|
30
|
+
startWithAppId(appId: string, policy?: HSPolicy): Promise<void>;
|
|
31
|
+
startWithAppIds(appIds: string[], policy?: HSPolicy): Promise<void>;
|
|
32
|
+
vid(appId: string): string | null;
|
|
33
|
+
|
|
34
|
+
// BD functionality
|
|
35
|
+
headersForURLRequest(appId?: string): { [key: string]: string };
|
|
36
|
+
handleResponse(response: string, code: number, url: string): Promise<HSBotDefenderChallengeResult>;
|
|
37
|
+
canHandleResponse(response: string, code: number, url: string): boolean;
|
|
38
|
+
challengeReferenceId(): string;
|
|
39
|
+
setCustomParameters(parameters: { [key: string]: string }, appId?: string): void;
|
|
40
|
+
|
|
41
|
+
// Adding AD functions
|
|
42
|
+
setUserId(userId: string | null, appId?: string): void;
|
|
43
|
+
registerOutgoingUrlRequest(url: string, appId?: string): void;
|
|
44
|
+
setAdditionalData(parameters: { [key: string]: string }, appId?: string): void;
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
# Installation in bare React Native projects
|
|
49
|
+
|
|
50
|
+
For the react-native bare workflow projects see our [integration guide](https://docs.humansecurity.com/applications-and-accounts/docs/react-native-integration).
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
group = 'expo.modules.humansdk'
|
|
4
|
+
version = '1.0.3'
|
|
5
|
+
|
|
6
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useExpoPublishing()
|
|
11
|
+
|
|
12
|
+
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
|
13
|
+
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
|
14
|
+
// Most of the time, you may like to manage the Android SDK versions yourself.
|
|
15
|
+
def useManagedAndroidSdkVersions = false
|
|
16
|
+
if (useManagedAndroidSdkVersions) {
|
|
17
|
+
useDefaultAndroidSdkVersions()
|
|
18
|
+
} else {
|
|
19
|
+
buildscript {
|
|
20
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
+
ext.safeExtGet = { prop, fallback ->
|
|
22
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
project.android {
|
|
26
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
27
|
+
defaultConfig {
|
|
28
|
+
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
29
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
dependencies {
|
|
35
|
+
implementation files('libs/HUMAN-4.0.3.aar')
|
|
36
|
+
implementation "androidx.core:core-ktx:1.13.1"
|
|
37
|
+
implementation "androidx.lifecycle:lifecycle-process:2.8.2"
|
|
38
|
+
implementation "androidx.datastore:datastore-preferences:1.1.1"
|
|
39
|
+
implementation "com.google.android.material:material:1.12.0"
|
|
40
|
+
implementation "com.fasterxml.uuid:java-uuid-generator:4.3.0"
|
|
41
|
+
implementation "io.ktor:ktor-client-okhttp:2.3.11"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
android {
|
|
45
|
+
namespace "expo.modules.humansdk"
|
|
46
|
+
defaultConfig {
|
|
47
|
+
versionCode 3
|
|
48
|
+
versionName "1.0.3"
|
|
49
|
+
}
|
|
50
|
+
lintOptions {
|
|
51
|
+
abortOnError false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
package expo.modules.humansdk
|
|
2
|
+
|
|
3
|
+
import android.app.Application
|
|
4
|
+
import expo.modules.kotlin.modules.Module
|
|
5
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
6
|
+
import expo.modules.kotlin.Promise
|
|
7
|
+
|
|
8
|
+
import com.humansecurity.mobile_sdk.HumanSecurity
|
|
9
|
+
import com.humansecurity.mobile_sdk.main.HSBotDefenderDelegate
|
|
10
|
+
import com.humansecurity.mobile_sdk.main.HSBotDefenderChallengeResult
|
|
11
|
+
import com.humansecurity.mobile_sdk.main.policy.HSAutomaticInterceptorType
|
|
12
|
+
import com.humansecurity.mobile_sdk.main.policy.HSPolicy
|
|
13
|
+
|
|
14
|
+
class ExpoHumanSdkModule : Module() {
|
|
15
|
+
|
|
16
|
+
companion object {
|
|
17
|
+
private var hasStarted = false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override fun definition() = ModuleDefinition {
|
|
21
|
+
Name("HumanSecurity")
|
|
22
|
+
|
|
23
|
+
Events(
|
|
24
|
+
"botDefenderRequestBlocked",
|
|
25
|
+
"botDefenderChallengeSolved",
|
|
26
|
+
"botDefenderChallengeCancelled",
|
|
27
|
+
"botDefenderChallengeRendered",
|
|
28
|
+
"botDefenderChallengeRenderFailed",
|
|
29
|
+
"botDefenderDidUpdateHeaders"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
Function("sdkVersion") {
|
|
33
|
+
HumanSecurity.sdkVersion()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
AsyncFunction("startWithAppId") { appId: String, policyMap: Map<String, Any>?, promise: Promise ->
|
|
37
|
+
startSDK(listOf(appId), policyMap, promise)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
AsyncFunction("startWithAppIds") { appIds: List<String>, policyMap: Map<String, Any>?, promise: Promise ->
|
|
41
|
+
startSDK(appIds, policyMap, promise)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Function("vid") { appId: String ->
|
|
45
|
+
HumanSecurity.vid(appId)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// BD functions
|
|
49
|
+
|
|
50
|
+
Function("headersForURLRequest") { appId: String? ->
|
|
51
|
+
HumanSecurity.BD.headersForURLRequest(appId)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
AsyncFunction("handleResponse") { response: String, code: Int, url: String, promise: Promise ->
|
|
55
|
+
val handled = HumanSecurity.BD.handleResponse(response) { result ->
|
|
56
|
+
promise.resolve(result.ordinal) // Return the raw ordinal value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!handled) {
|
|
60
|
+
promise.resolve(2)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Function("canHandleResponse") { response: String, code: Int, url: String ->
|
|
65
|
+
HumanSecurity.BD.canHandleResponse(response)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Function("challengeReferenceId") {
|
|
69
|
+
HumanSecurity.BD.challengeReferenceId()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Function("setCustomParameters") { parameters: Map<String, String>, appId: String? ->
|
|
73
|
+
HumanSecurity.BD.setCustomParameters(HashMap(parameters), appId)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// AD functions
|
|
77
|
+
|
|
78
|
+
Function("setUserId") { userId: String?, appId: String? ->
|
|
79
|
+
HumanSecurity.AD.setUserId(userId, appId)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Function("registerOutgoingUrlRequest") { url: String, appId: String? ->
|
|
83
|
+
HumanSecurity.AD.registerOutgoingUrlRequest(url, appId)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Function("setAdditionalData") { parameters: Map<String, String>, appId: String? ->
|
|
87
|
+
HumanSecurity.AD.setAdditionalData(HashMap(parameters), appId)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private fun startSDK(appIds: List<String>, policyMap: Map<String, Any>?, promise: Promise) {
|
|
92
|
+
if (hasStarted) {
|
|
93
|
+
promise.resolve(null)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
hasStarted = true
|
|
97
|
+
try {
|
|
98
|
+
val policy = createPolicy(policyMap)
|
|
99
|
+
val application = appContext.reactContext?.applicationContext as? Application
|
|
100
|
+
?: throw IllegalStateException("Application context is null")
|
|
101
|
+
|
|
102
|
+
HumanSecurity.start(application, ArrayList(appIds), policy)
|
|
103
|
+
HumanSecurity.BD.delegate = botDefenderDelegate
|
|
104
|
+
promise.resolve(null)
|
|
105
|
+
} catch (exception: Exception) {
|
|
106
|
+
promise.reject("START_ERROR", "Failed to start HumanSecurity SDK: ${exception.message}", exception)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun createPolicy(policyMap: Map<String, Any>?): HSPolicy {
|
|
111
|
+
val policy = HSPolicy()
|
|
112
|
+
policy.automaticInterceptorPolicy.interceptorType = HSAutomaticInterceptorType.NONE
|
|
113
|
+
policy.hybridAppPolicy.supportExternalWebViews = true
|
|
114
|
+
|
|
115
|
+
policyMap?.let {
|
|
116
|
+
val hybridPolicy = (it["hybridAppPolicy"] as? Map<*, *>)?.mapNotNull { entry ->
|
|
117
|
+
val key = entry.key as? String
|
|
118
|
+
val value = (entry.value as? List<*>)?.filterIsInstance<String>()
|
|
119
|
+
if (key != null && value != null) key to value else null
|
|
120
|
+
}?.toMap()
|
|
121
|
+
|
|
122
|
+
hybridPolicy?.forEach { (appId, domainList) ->
|
|
123
|
+
val domainSet = domainList.toSet()
|
|
124
|
+
policy.hybridAppPolicy.setWebRootDomains(domainSet, appId)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
val detectionPolicy = (it["detectionPolicy"] as? Map<*, *>)?.mapNotNull { entry ->
|
|
128
|
+
val key = entry.key as? String
|
|
129
|
+
val value = entry.value
|
|
130
|
+
if (key != null) key to value else null
|
|
131
|
+
}?.toMap()
|
|
132
|
+
|
|
133
|
+
detectionPolicy?.let { dp ->
|
|
134
|
+
policy.detectionPolicy.allowTouchDetection = dp["allowTouchDetection"] as? Boolean ?: false
|
|
135
|
+
policy.detectionPolicy.allowDeviceMotionDetection = dp["allowDeviceMotionDetection"] as? Boolean ?: false
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return policy
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private val botDefenderDelegate = object : HSBotDefenderDelegate {
|
|
143
|
+
override fun botDefenderRequestBlocked(url: String?, appId: String) {
|
|
144
|
+
sendEvent("botDefenderRequestBlocked", mapOf("url" to url, "appId" to appId))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
override fun botDefenderChallengeSolved(appId: String) {
|
|
148
|
+
sendEvent("botDefenderChallengeSolved", mapOf("appId" to appId))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
override fun botDefenderChallengeCancelled(appId: String) {
|
|
152
|
+
sendEvent("botDefenderChallengeCancelled", mapOf("appId" to appId))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
override fun botDefenderChallengeRendered(appId: String) {
|
|
156
|
+
sendEvent("botDefenderChallengeRendered", mapOf("appId" to appId))
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
override fun botDefenderChallengeRenderFailed(appId: String) {
|
|
160
|
+
sendEvent("botDefenderChallengeRenderFailed", mapOf("appId" to appId))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
override fun botDefenderDidUpdateHeaders(headers: HashMap<String, String>, appId: String) {
|
|
164
|
+
sendEvent("botDefenderDidUpdateHeaders", mapOf("headers" to headers, "appId" to appId))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HSPolicy = {
|
|
2
|
+
hybridAppPolicy?: HSHybridAppPolicy;
|
|
3
|
+
detectionPolicy?: HSDetectionPolicy;
|
|
4
|
+
};
|
|
5
|
+
export type HSHybridAppPolicy = {
|
|
6
|
+
webRootDomains: {
|
|
7
|
+
[key: string]: string[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type HSDetectionPolicy = {
|
|
11
|
+
allowTouchDetection: boolean;
|
|
12
|
+
allowDeviceMotionDetection: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare enum HSBotDefenderChallengeResult {
|
|
15
|
+
SOLVED = 0,// Native ordinal for solved
|
|
16
|
+
CANCELLED = 1,// Native ordinal for cancelled
|
|
17
|
+
FAILED = 2
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ExpoHumanSdk.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoHumanSdk.types.d.ts","sourceRoot":"","sources":["../src/ExpoHumanSdk.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,eAAe,CAAC,EAAE,iBAAiB,CAAC;IACpC,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,0BAA0B,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF,oBAAY,4BAA4B;IACtC,MAAM,IAAI,CAAE,4BAA4B;IACxC,SAAS,IAAI,CAAE,+BAA+B;IAC9C,MAAM,IAAI;CACX"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var HSBotDefenderChallengeResult;
|
|
2
|
+
(function (HSBotDefenderChallengeResult) {
|
|
3
|
+
HSBotDefenderChallengeResult[HSBotDefenderChallengeResult["SOLVED"] = 0] = "SOLVED";
|
|
4
|
+
HSBotDefenderChallengeResult[HSBotDefenderChallengeResult["CANCELLED"] = 1] = "CANCELLED";
|
|
5
|
+
HSBotDefenderChallengeResult[HSBotDefenderChallengeResult["FAILED"] = 2] = "FAILED";
|
|
6
|
+
})(HSBotDefenderChallengeResult || (HSBotDefenderChallengeResult = {}));
|
|
7
|
+
//# sourceMappingURL=ExpoHumanSdk.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoHumanSdk.types.js","sourceRoot":"","sources":["../src/ExpoHumanSdk.types.ts"],"names":[],"mappings":"AAcA,MAAM,CAAN,IAAY,4BAIX;AAJD,WAAY,4BAA4B;IACtC,mFAAU,CAAA;IACV,yFAAa,CAAA;IACb,mFAAU,CAAA;AACZ,CAAC,EAJW,4BAA4B,KAA5B,4BAA4B,QAIvC","sourcesContent":["export type HSPolicy = {\n hybridAppPolicy?: HSHybridAppPolicy;\n detectionPolicy?: HSDetectionPolicy;\n};\n\nexport type HSHybridAppPolicy = {\n webRootDomains: { [key: string]: string[] };\n};\n\nexport type HSDetectionPolicy = {\n allowTouchDetection: boolean;\n allowDeviceMotionDetection: boolean;\n};\n\nexport enum HSBotDefenderChallengeResult {\n SOLVED = 0, // Native ordinal for solved\n CANCELLED = 1, // Native ordinal for cancelled\n FAILED = 2, // Indicates getting false from handle response - failed to handle the challenge.\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HSPolicy, HSBotDefenderChallengeResult } from "./ExpoHumanSdk.types";
|
|
2
|
+
declare class ExpoHumanSdkModule {
|
|
3
|
+
sdkVersion(): string;
|
|
4
|
+
startWithAppId(appId: string, policy?: HSPolicy): Promise<void>;
|
|
5
|
+
startWithAppIds(appIds: string[], policy?: HSPolicy): Promise<void>;
|
|
6
|
+
vid(appId: string): string | null;
|
|
7
|
+
headersForURLRequest(appId?: string): {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
handleResponse(response: string, code: number, url: string): Promise<HSBotDefenderChallengeResult>;
|
|
11
|
+
canHandleResponse(response: string, code: number, url: string): boolean;
|
|
12
|
+
challengeReferenceId(): string;
|
|
13
|
+
setCustomParameters(parameters: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
}, appId?: string): void;
|
|
16
|
+
setUserId(userId: string | null, appId?: string): void;
|
|
17
|
+
registerOutgoingUrlRequest(url: string, appId?: string): void;
|
|
18
|
+
setAdditionalData(parameters: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
}, appId?: string): void;
|
|
21
|
+
}
|
|
22
|
+
export declare const addEventListener: (eventName: string, listener: (data: any) => void) => import("expo-modules-core").Subscription;
|
|
23
|
+
declare const _default: ExpoHumanSdkModule;
|
|
24
|
+
export default _default;
|
|
25
|
+
//# sourceMappingURL=ExpoHumanSdkModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoHumanSdkModule.d.ts","sourceRoot":"","sources":["../src/ExpoHumanSdkModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAI9E,OAAO,OAAO,kBAAkB;IAC9B,UAAU,IAAI,MAAM;IAEpB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAC/D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IACnE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAGjC,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAC/D,cAAc,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,4BAA4B,CAAC;IACxC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IACvE,oBAAoB,IAAI,MAAM;IAC9B,mBAAmB,CACjB,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EACrC,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;IAGP,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IACtD,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAC7D,iBAAiB,CACf,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EACrC,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;CACR;AAED,eAAO,MAAM,gBAAgB,cAChB,MAAM,YACP,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,6CAG9B,CAAC;;AAGF,wBAAwE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { requireNativeModule, EventEmitter } from "expo-modules-core";
|
|
2
|
+
const eventEmitter = new EventEmitter(requireNativeModule("HumanSecurity"));
|
|
3
|
+
export const addEventListener = (eventName, listener) => {
|
|
4
|
+
return eventEmitter.addListener(eventName, listener);
|
|
5
|
+
};
|
|
6
|
+
// This call loads the native module object from the JSI.
|
|
7
|
+
export default requireNativeModule("HumanSecurity");
|
|
8
|
+
//# sourceMappingURL=ExpoHumanSdkModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoHumanSdkModule.js","sourceRoot":"","sources":["../src/ExpoHumanSdkModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItE,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAAC;AAgC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,SAAiB,EACjB,QAA6B,EAC7B,EAAE;IACF,OAAO,YAAY,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,yDAAyD;AACzD,eAAe,mBAAmB,CAAqB,eAAe,CAAC,CAAC","sourcesContent":["import { requireNativeModule, EventEmitter } from \"expo-modules-core\";\n\nimport { HSPolicy, HSBotDefenderChallengeResult } from \"./ExpoHumanSdk.types\";\n\nconst eventEmitter = new EventEmitter(requireNativeModule(\"HumanSecurity\"));\n\ndeclare class ExpoHumanSdkModule {\n sdkVersion(): string;\n\n startWithAppId(appId: string, policy?: HSPolicy): Promise<void>;\n startWithAppIds(appIds: string[], policy?: HSPolicy): Promise<void>;\n vid(appId: string): string | null;\n\n // BD functionality\n headersForURLRequest(appId?: string): { [key: string]: string };\n handleResponse(\n response: string,\n code: number,\n url: string,\n ): Promise<HSBotDefenderChallengeResult>;\n canHandleResponse(response: string, code: number, url: string): boolean;\n challengeReferenceId(): string;\n setCustomParameters(\n parameters: { [key: string]: string },\n appId?: string,\n ): void;\n\n // Adding AD functions\n setUserId(userId: string | null, appId?: string): void;\n registerOutgoingUrlRequest(url: string, appId?: string): void;\n setAdditionalData(\n parameters: { [key: string]: string },\n appId?: string,\n ): void;\n}\n\nexport const addEventListener = (\n eventName: string,\n listener: (data: any) => void,\n) => {\n return eventEmitter.addListener(eventName, listener);\n};\n\n// This call loads the native module object from the JSI.\nexport default requireNativeModule<ExpoHumanSdkModule>(\"HumanSecurity\");\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HSPolicy, HSBotDefenderChallengeResult } from "./ExpoHumanSdk.types";
|
|
2
|
+
declare const HS_EVENTS: {
|
|
3
|
+
BOT_DEFENDER_REQUEST_BLOCKED: string;
|
|
4
|
+
BOT_DEFENDER_CHALLENGE_SOLVED: string;
|
|
5
|
+
BOT_DEFENDER_CHALLENGE_CANCELLED: string;
|
|
6
|
+
BOT_DEFENDER_CHALLENGE_RENDERED: string;
|
|
7
|
+
BOT_DEFENDER_CHALLENGE_RENDER_FAILED: string;
|
|
8
|
+
BOT_DEFENDER_DID_UPDATE_HEADERS: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class HumanSecurity {
|
|
11
|
+
static sdkVersion(): string;
|
|
12
|
+
static startWithAppId(appId: string, policy?: HSPolicy): Promise<void>;
|
|
13
|
+
static startWithAppIds(appIds: string[], policy?: HSPolicy): Promise<void>;
|
|
14
|
+
static vid(appId: string): string | null;
|
|
15
|
+
static BD: {
|
|
16
|
+
headersForURLRequest(appId?: string): {
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
};
|
|
19
|
+
handleResponse(response: string, code: number, url: string): Promise<HSBotDefenderChallengeResult>;
|
|
20
|
+
canHandleResponse(response: string, code: number, url: string): boolean;
|
|
21
|
+
challengeReferenceId(): string;
|
|
22
|
+
setCustomParameters(parameters: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
}, appId?: string): void;
|
|
25
|
+
addListener(eventName: string, callback: (data: any) => void): import("expo-modules-core").Subscription;
|
|
26
|
+
};
|
|
27
|
+
static AD: {
|
|
28
|
+
setUserId(userId: string | null, appId?: string): void;
|
|
29
|
+
registerOutgoingUrlRequest(url: string, appId?: string): void;
|
|
30
|
+
setAdditionalData(parameters: {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
}, appId?: string): void;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { HS_EVENTS };
|
|
36
|
+
export default HumanSecurity;
|
|
37
|
+
//# sourceMappingURL=HumanSecurity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HumanSecurity.d.ts","sourceRoot":"","sources":["../src/HumanSecurity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAG9E,QAAA,MAAM,SAAS;;;;;;;CAOd,CAAC;AAEF,qBAAa,aAAa;IACxB,MAAM,CAAC,UAAU,IAAI,MAAM;WAId,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;WAI/D,eAAe,CAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,CAAC,EAAE,QAAQ,GAChB,OAAO,CAAC,IAAI,CAAC;IAIhB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIxC,MAAM,CAAC,EAAE;qCACsB,MAAM,GAAG;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE;iCAInD,MAAM,QACV,MAAM,OACP,MAAM,GACV,OAAO,CAAC,4BAA4B,CAAC;oCAWZ,MAAM,QAAQ,MAAM,OAAO,MAAM,GAAG,OAAO;gCAG/C,MAAM;wCAIhB;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,UAC7B,MAAM,GACb,IAAI;+BAGgB,MAAM,YAAY,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;MAG5D;IAEF,MAAM,CAAC,EAAE;0BACW,MAAM,GAAG,IAAI,UAAU,MAAM,GAAG,IAAI;wCAGtB,MAAM,UAAU,MAAM,GAAG,IAAI;sCAI/C;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,UAC7B,MAAM,GACb,IAAI;MAGP;CACH;AAED,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HSBotDefenderChallengeResult } from "./ExpoHumanSdk.types";
|
|
2
|
+
import ExpoHumanSdkModule, { addEventListener } from "./ExpoHumanSdkModule";
|
|
3
|
+
const HS_EVENTS = {
|
|
4
|
+
BOT_DEFENDER_REQUEST_BLOCKED: "botDefenderRequestBlocked",
|
|
5
|
+
BOT_DEFENDER_CHALLENGE_SOLVED: "botDefenderChallengeSolved",
|
|
6
|
+
BOT_DEFENDER_CHALLENGE_CANCELLED: "botDefenderChallengeCancelled",
|
|
7
|
+
BOT_DEFENDER_CHALLENGE_RENDERED: "botDefenderChallengeRendered",
|
|
8
|
+
BOT_DEFENDER_CHALLENGE_RENDER_FAILED: "botDefenderChallengeRenderFailed",
|
|
9
|
+
BOT_DEFENDER_DID_UPDATE_HEADERS: "botDefenderDidUpdateHeaders",
|
|
10
|
+
};
|
|
11
|
+
export class HumanSecurity {
|
|
12
|
+
static sdkVersion() {
|
|
13
|
+
return ExpoHumanSdkModule.sdkVersion();
|
|
14
|
+
}
|
|
15
|
+
static async startWithAppId(appId, policy) {
|
|
16
|
+
return await ExpoHumanSdkModule.startWithAppId(appId, policy);
|
|
17
|
+
}
|
|
18
|
+
static async startWithAppIds(appIds, policy) {
|
|
19
|
+
return await ExpoHumanSdkModule.startWithAppIds(appIds, policy);
|
|
20
|
+
}
|
|
21
|
+
static vid(appId) {
|
|
22
|
+
return ExpoHumanSdkModule.vid(appId);
|
|
23
|
+
}
|
|
24
|
+
static BD = {
|
|
25
|
+
headersForURLRequest(appId) {
|
|
26
|
+
return ExpoHumanSdkModule.headersForURLRequest(appId);
|
|
27
|
+
},
|
|
28
|
+
async handleResponse(response, code, url) {
|
|
29
|
+
const resultOrdinal = await ExpoHumanSdkModule.handleResponse(response, code, url);
|
|
30
|
+
if (resultOrdinal in HSBotDefenderChallengeResult) {
|
|
31
|
+
return resultOrdinal;
|
|
32
|
+
}
|
|
33
|
+
return HSBotDefenderChallengeResult.FAILED;
|
|
34
|
+
},
|
|
35
|
+
canHandleResponse(response, code, url) {
|
|
36
|
+
return ExpoHumanSdkModule.canHandleResponse(response, code, url);
|
|
37
|
+
},
|
|
38
|
+
challengeReferenceId() {
|
|
39
|
+
return ExpoHumanSdkModule.challengeReferenceId();
|
|
40
|
+
},
|
|
41
|
+
setCustomParameters(parameters, appId) {
|
|
42
|
+
ExpoHumanSdkModule.setCustomParameters(parameters, appId);
|
|
43
|
+
},
|
|
44
|
+
addListener(eventName, callback) {
|
|
45
|
+
return addEventListener(eventName, callback);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
static AD = {
|
|
49
|
+
setUserId(userId, appId) {
|
|
50
|
+
ExpoHumanSdkModule.setUserId(userId, appId);
|
|
51
|
+
},
|
|
52
|
+
registerOutgoingUrlRequest(url, appId) {
|
|
53
|
+
ExpoHumanSdkModule.registerOutgoingUrlRequest(url, appId);
|
|
54
|
+
},
|
|
55
|
+
setAdditionalData(parameters, appId) {
|
|
56
|
+
ExpoHumanSdkModule.setAdditionalData(parameters, appId);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { HS_EVENTS };
|
|
61
|
+
export default HumanSecurity;
|
|
62
|
+
//# sourceMappingURL=HumanSecurity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HumanSecurity.js","sourceRoot":"","sources":["../src/HumanSecurity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,kBAAkB,EAAE,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5E,MAAM,SAAS,GAAG;IAChB,4BAA4B,EAAE,2BAA2B;IACzD,6BAA6B,EAAE,4BAA4B;IAC3D,gCAAgC,EAAE,+BAA+B;IACjE,+BAA+B,EAAE,8BAA8B;IAC/D,oCAAoC,EAAE,kCAAkC;IACxE,+BAA+B,EAAE,6BAA6B;CAC/D,CAAC;AAEF,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,UAAU;QACf,OAAO,kBAAkB,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,KAAa,EAAE,MAAiB;QAC1D,OAAO,MAAM,kBAAkB,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,eAAe,CAC1B,MAAgB,EAChB,MAAiB;QAEjB,OAAO,MAAM,kBAAkB,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,KAAa;QACtB,OAAO,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,EAAE,GAAG;QACV,oBAAoB,CAAC,KAAc;YACjC,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,IAAY,EACZ,GAAW;YAEX,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC,cAAc,CAC3D,QAAQ,EACR,IAAI,EACJ,GAAG,CACJ,CAAC;YACF,IAAI,aAAa,IAAI,4BAA4B,EAAE,CAAC;gBAClD,OAAO,aAA6C,CAAC;YACvD,CAAC;YACD,OAAO,4BAA4B,CAAC,MAAM,CAAC;QAC7C,CAAC;QACD,iBAAiB,CAAC,QAAgB,EAAE,IAAY,EAAE,GAAW;YAC3D,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,oBAAoB;YAClB,OAAO,kBAAkB,CAAC,oBAAoB,EAAE,CAAC;QACnD,CAAC;QACD,mBAAmB,CACjB,UAAqC,EACrC,KAAc;YAEd,kBAAkB,CAAC,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC5D,CAAC;QACD,WAAW,CAAC,SAAiB,EAAE,QAA6B;YAC1D,OAAO,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,EAAE,GAAG;QACV,SAAS,CAAC,MAAqB,EAAE,KAAc;YAC7C,kBAAkB,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,0BAA0B,CAAC,GAAW,EAAE,KAAc;YACpD,kBAAkB,CAAC,0BAA0B,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5D,CAAC;QACD,iBAAiB,CACf,UAAqC,EACrC,KAAc;YAEd,kBAAkB,CAAC,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;KACF,CAAC;;AAGJ,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,eAAe,aAAa,CAAC","sourcesContent":["import { HSPolicy, HSBotDefenderChallengeResult } from \"./ExpoHumanSdk.types\";\nimport ExpoHumanSdkModule, { addEventListener } from \"./ExpoHumanSdkModule\";\n\nconst HS_EVENTS = {\n BOT_DEFENDER_REQUEST_BLOCKED: \"botDefenderRequestBlocked\",\n BOT_DEFENDER_CHALLENGE_SOLVED: \"botDefenderChallengeSolved\",\n BOT_DEFENDER_CHALLENGE_CANCELLED: \"botDefenderChallengeCancelled\",\n BOT_DEFENDER_CHALLENGE_RENDERED: \"botDefenderChallengeRendered\",\n BOT_DEFENDER_CHALLENGE_RENDER_FAILED: \"botDefenderChallengeRenderFailed\",\n BOT_DEFENDER_DID_UPDATE_HEADERS: \"botDefenderDidUpdateHeaders\",\n};\n\nexport class HumanSecurity {\n static sdkVersion(): string {\n return ExpoHumanSdkModule.sdkVersion();\n }\n\n static async startWithAppId(appId: string, policy?: HSPolicy): Promise<void> {\n return await ExpoHumanSdkModule.startWithAppId(appId, policy);\n }\n\n static async startWithAppIds(\n appIds: string[],\n policy?: HSPolicy,\n ): Promise<void> {\n return await ExpoHumanSdkModule.startWithAppIds(appIds, policy);\n }\n\n static vid(appId: string): string | null {\n return ExpoHumanSdkModule.vid(appId);\n }\n\n static BD = {\n headersForURLRequest(appId?: string): { [key: string]: string } {\n return ExpoHumanSdkModule.headersForURLRequest(appId);\n },\n async handleResponse(\n response: string,\n code: number,\n url: string,\n ): Promise<HSBotDefenderChallengeResult> {\n const resultOrdinal = await ExpoHumanSdkModule.handleResponse(\n response,\n code,\n url,\n );\n if (resultOrdinal in HSBotDefenderChallengeResult) {\n return resultOrdinal as HSBotDefenderChallengeResult;\n }\n return HSBotDefenderChallengeResult.FAILED;\n },\n canHandleResponse(response: string, code: number, url: string): boolean {\n return ExpoHumanSdkModule.canHandleResponse(response, code, url);\n },\n challengeReferenceId(): string {\n return ExpoHumanSdkModule.challengeReferenceId();\n },\n setCustomParameters(\n parameters: { [key: string]: string },\n appId?: string,\n ): void {\n ExpoHumanSdkModule.setCustomParameters(parameters, appId);\n },\n addListener(eventName: string, callback: (data: any) => void) {\n return addEventListener(eventName, callback);\n },\n };\n\n static AD = {\n setUserId(userId: string | null, appId?: string): void {\n ExpoHumanSdkModule.setUserId(userId, appId);\n },\n registerOutgoingUrlRequest(url: string, appId?: string): void {\n ExpoHumanSdkModule.registerOutgoingUrlRequest(url, appId);\n },\n setAdditionalData(\n parameters: { [key: string]: string },\n appId?: string,\n ): void {\n ExpoHumanSdkModule.setAdditionalData(parameters, appId);\n },\n };\n}\n\nexport { HS_EVENTS };\nexport default HumanSecurity;\n"]}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAY,4BAA4B,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { default as HumanSecurity, HS_EVENTS } from \"./HumanSecurity\";\nexport { HSPolicy, HSBotDefenderChallengeResult } from \"./ExpoHumanSdk.types\";\n"]}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import HUMAN
|
|
3
|
+
|
|
4
|
+
public class ExpoHumanSdkModule: Module {
|
|
5
|
+
private static let botDefenderDelegate = BotDefenderDelegate(appContext: nil)
|
|
6
|
+
private static var hasStarted = false
|
|
7
|
+
public func definition() -> ModuleDefinition {
|
|
8
|
+
Name("HumanSecurity")
|
|
9
|
+
|
|
10
|
+
Events(
|
|
11
|
+
"botDefenderRequestBlocked",
|
|
12
|
+
"botDefenderChallengeSolved",
|
|
13
|
+
"botDefenderChallengeCancelled",
|
|
14
|
+
"botDefenderChallengeRendered",
|
|
15
|
+
"botDefenderChallengeRenderFailed",
|
|
16
|
+
"botDefenderDidUpdateHeaders"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
Function("sdkVersion") { () -> String in
|
|
20
|
+
return HumanSecurity.sdkVersion()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
AsyncFunction("startWithAppId") { (appId: String, policyDict: [String: Any]?, promise: Promise) in
|
|
24
|
+
self.startSDK(appIds: [appId], policyDict: policyDict, promise: promise)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
AsyncFunction("startWithAppIds") { (appIds: [String], policyDict: [String: Any]?, promise: Promise) in
|
|
28
|
+
self.startSDK(appIds: appIds, policyDict: policyDict, promise: promise)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Function("vid") { (appId: String) -> String? in
|
|
32
|
+
return HumanSecurity.vid(forAppId: appId)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// BD functions
|
|
36
|
+
Function("headersForURLRequest") { (appId: String? ) -> [String: String] in
|
|
37
|
+
return HumanSecurity.BD.headersForURLRequest(forAppId: appId)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Function("canHandleResponse") { (responseData: String, responseCode: Int, url: String) -> Bool in
|
|
41
|
+
let (httpResponse, data) = self.createHttpResponse(responseData: responseData, responseCode: responseCode, url: url)
|
|
42
|
+
|
|
43
|
+
guard let httpResponse = httpResponse else {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
return HumanSecurity.BD.canHandleResponse(response: httpResponse, data: data)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
AsyncFunction("handleResponse") { (responseData: String, responseCode: Int, url: String, promise: Promise) in
|
|
50
|
+
let (httpResponse, data) = self.createHttpResponse(responseData: responseData, responseCode: responseCode, url: url)
|
|
51
|
+
|
|
52
|
+
if let httpResponse = httpResponse {
|
|
53
|
+
let handled = HumanSecurity.BD.handleResponse(response: httpResponse, data: data) { result in
|
|
54
|
+
promise.resolve(result.rawValue)
|
|
55
|
+
}
|
|
56
|
+
if handled {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
promise.resolve(2)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Function("challengeReferenceId") { () -> String in
|
|
65
|
+
return HumanSecurity.BD.challengeReferenceId()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Function("setCustomParameters") { (parameters: [String: String], appId: String?) in
|
|
69
|
+
do {
|
|
70
|
+
try HumanSecurity.BD.setCustomParameters(parameters: parameters, forAppId: appId)
|
|
71
|
+
} catch {
|
|
72
|
+
throw error
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// AD functions
|
|
77
|
+
Function("setUserId") { (userId: String?, appId: String?) in
|
|
78
|
+
do {
|
|
79
|
+
try HumanSecurity.AD.setUserId(userId: userId, forAppId: appId)
|
|
80
|
+
} catch {
|
|
81
|
+
throw error
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Function("registerOutgoingUrlRequest") { (url: String, appId: String?) in
|
|
86
|
+
do {
|
|
87
|
+
try HumanSecurity.AD.registerOutgoingUrlRequest(url: url, forAppId: appId)
|
|
88
|
+
} catch {
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Function("setAdditionalData") { (parameters: [String: String], appId: String?) in
|
|
94
|
+
do {
|
|
95
|
+
try HumanSecurity.AD.setAdditionalData(parameters: parameters, forAppId: appId)
|
|
96
|
+
} catch {
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private func createHttpResponse(responseData: String, responseCode: Int, url: String) -> (HTTPURLResponse?, Data) {
|
|
103
|
+
guard let responseURL = URL(string: url) else {
|
|
104
|
+
return (nil, Data())
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let httpResponse = HTTPURLResponse(
|
|
108
|
+
url: responseURL,
|
|
109
|
+
statusCode: responseCode,
|
|
110
|
+
httpVersion: nil,
|
|
111
|
+
headerFields: [:]
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
let data = Data(responseData.utf8)
|
|
115
|
+
return (httpResponse, data)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private func startSDK(appIds: [String], policyDict: [String: Any]?, promise: Promise) {
|
|
119
|
+
guard !Self.hasStarted else {
|
|
120
|
+
promise.resolve(nil)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
Self.hasStarted = true
|
|
124
|
+
DispatchQueue.main.async {
|
|
125
|
+
do {
|
|
126
|
+
let policy = self.createPolicy(from: policyDict)
|
|
127
|
+
try HumanSecurity.start(appIds: appIds, policy: policy)
|
|
128
|
+
ExpoHumanSdkModule.botDefenderDelegate.appContext = self.appContext // Update appContext
|
|
129
|
+
HumanSecurity.BD.delegate = ExpoHumanSdkModule.botDefenderDelegate
|
|
130
|
+
promise.resolve(nil)
|
|
131
|
+
} catch {
|
|
132
|
+
promise.reject("START_ERROR", "Failed to start HumanSecurity SDK: \(error.localizedDescription)")
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private func createPolicy(from policyDict: [String: Any]?) -> HSPolicy {
|
|
138
|
+
let policy = HSPolicy()
|
|
139
|
+
// Set defaults for react and expo.
|
|
140
|
+
policy.automaticInterceptorPolicy.interceptorType = .none
|
|
141
|
+
policy.hybridAppPolicy.supportExternalWebViews = true
|
|
142
|
+
|
|
143
|
+
if let policyDict = policyDict {
|
|
144
|
+
if let hybridAppPolicy = policyDict["hybridAppPolicy"] as? [String: Any],
|
|
145
|
+
let webRootDomains = hybridAppPolicy["webRootDomains"] as? [String: [String]] {
|
|
146
|
+
// Extract the appId (key) and corresponding domains (value)
|
|
147
|
+
for (appIdFromPolicy, domainList) in webRootDomains {
|
|
148
|
+
let domainSet = Set(domainList)
|
|
149
|
+
print("Setting webRootDomains: \(domainSet) for appId: \(appIdFromPolicy)")
|
|
150
|
+
// Call the function to set webRootDomains for the extracted appId
|
|
151
|
+
policy.hybridAppPolicy.set(webRootDomains: domainSet, forAppId: appIdFromPolicy)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if let detectionPolicy = policyDict["detectionPolicy"] as? [String: Any] {
|
|
156
|
+
policy.detectionPolicy.allowTouchDetection = detectionPolicy["allowTouchDetection"] as? Bool ?? false
|
|
157
|
+
policy.detectionPolicy.allowDeviceMotionDetection = detectionPolicy["allowDeviceMotionDetection"] as? Bool ?? false
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return policy
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private class BotDefenderDelegate: NSObject, HSBotDefenderDelegate {
|
|
165
|
+
weak var appContext: AppContext?
|
|
166
|
+
|
|
167
|
+
init(appContext: AppContext?) {
|
|
168
|
+
self.appContext = appContext
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
func botDefenderRequestBlocked(url: URL?, appId: String) {
|
|
172
|
+
sendEvent("botDefenderRequestBlocked", [
|
|
173
|
+
"url": url?.absoluteString ?? "",
|
|
174
|
+
"appId": appId
|
|
175
|
+
])
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func botDefenderChallengeSolved(forAppId appId: String) {
|
|
179
|
+
sendEvent("botDefenderChallengeSolved", [
|
|
180
|
+
"appId": appId
|
|
181
|
+
])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
func botDefenderChallengeCancelled(forAppId appId: String) {
|
|
185
|
+
sendEvent("botDefenderChallengeCancelled", [
|
|
186
|
+
"appId": appId
|
|
187
|
+
])
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func botDefenderChallengeRendered(forAppId appId: String) {
|
|
191
|
+
sendEvent("botDefenderChallengeRendered", [
|
|
192
|
+
"appId": appId
|
|
193
|
+
])
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
func botDefenderChallengeRenderFailed(forAppId appId: String) {
|
|
197
|
+
sendEvent("botDefenderChallengeRenderFailed", [
|
|
198
|
+
"appId": appId
|
|
199
|
+
])
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
func botDefenderDidUpdateHeaders(headers: [String: String], forAppId appId: String) {
|
|
203
|
+
sendEvent("botDefenderDidUpdateHeaders", [
|
|
204
|
+
"headers": headers,
|
|
205
|
+
"appId": appId
|
|
206
|
+
])
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private func sendEvent(_ name: String, _ body: [String: Any]) {
|
|
210
|
+
guard let appContext = self.appContext else {
|
|
211
|
+
print("[ExpoHumanSdkModule] App context is not available. Cannot send event: \(name)")
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
appContext.eventEmitter?.sendEvent(
|
|
216
|
+
withName: name,
|
|
217
|
+
body: body
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'HumanSecurity'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = {
|
|
14
|
+
:ios => '15.1',
|
|
15
|
+
:tvos => '15.1'
|
|
16
|
+
}
|
|
17
|
+
s.swift_version = '5.4'
|
|
18
|
+
s.source = { git: 'https://github.com/PerimeterX/human-security-ios-sdk' }
|
|
19
|
+
s.static_framework = true
|
|
20
|
+
|
|
21
|
+
s.dependency 'ExpoModulesCore'
|
|
22
|
+
s.dependency 'HUMAN', '4.1.0'
|
|
23
|
+
|
|
24
|
+
# Swift/Objective-C compatibility
|
|
25
|
+
s.pod_target_xcconfig = {
|
|
26
|
+
'DEFINES_MODULE' => 'YES',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
|
30
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@humansecurity/expo-mobile-sdk",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "An Expo module to wrap human native SDK for expo users.",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"open:ios": "xed example/ios",
|
|
16
|
+
"open:android": "open -a \"Android Studio\" example/android"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"expo",
|
|
21
|
+
"expo-mobile-sdk",
|
|
22
|
+
"HumanSecurity"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://github.com/PerimeterX/human-security-ios-sdk#readme",
|
|
27
|
+
"dependencies": {},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "~18.3.1",
|
|
30
|
+
"expo-module-scripts": "^4.0.0",
|
|
31
|
+
"expo": "~51.0.37",
|
|
32
|
+
"react-native": "0.74.5"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"expo": "*",
|
|
36
|
+
"react": "*",
|
|
37
|
+
"react-native": "*"
|
|
38
|
+
}
|
|
39
|
+
}
|