react-native-shield-fraud-plugin 1.0.10 → 2.0.0
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/android/build.gradle +30 -12
- package/android/src/main/java/com/shieldfraudplugin/ShieldFraudPluginModule.java +354 -123
- package/android/src/main/java/com/shieldfraudplugin/ShieldFraudPluginPackage.java +71 -21
- package/android/src/newarch/java/com/shieldfraudplugin/ShieldFraudPluginSpec.java +41 -0
- package/android/src/oldarch/java/com/shieldfraudplugin/ShieldFraudPluginSpec.java +36 -0
- package/ios/ShieldFraudPlugin.h +11 -2
- package/ios/ShieldFraudPlugin.mm +289 -0
- package/lib/commonjs/NativeShieldFraudPlugin.js +15 -0
- package/lib/commonjs/NativeShieldFraudPlugin.js.map +1 -0
- package/lib/commonjs/index.js +80 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeShieldFraudPlugin.js +10 -0
- package/lib/module/NativeShieldFraudPlugin.js.map +1 -0
- package/lib/module/index.js +81 -9
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeShieldFraudPlugin.d.ts +52 -0
- package/lib/typescript/NativeShieldFraudPlugin.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +41 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +10 -2
- package/react-native-shield-fraud-plugin.podspec +13 -3
- package/src/NativeShieldFraudPlugin.ts +85 -0
- package/src/index.tsx +115 -11
- package/ios/ShieldFraudPlugin.m +0 -98
- package/ios/ShieldFraudPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/ShieldFraudPlugin.xcodeproj/project.xcworkspace/xcuserdata/deepakraj.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/ShieldFraudPlugin.xcodeproj/xcuserdata/deepakraj.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/src/index.tsx
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
Platform,
|
|
5
|
+
TurboModuleRegistry,
|
|
6
|
+
} from "react-native";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the native module through TurboModuleRegistry (New Architecture)
|
|
10
|
+
* with a fallback to NativeModules bridge (Old Architecture).
|
|
11
|
+
*/
|
|
12
|
+
const ShieldFraudPluginNativeModule =
|
|
13
|
+
TurboModuleRegistry.get<any>("ShieldFraudPlugin") ??
|
|
14
|
+
NativeModules.ShieldFraudPlugin;
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* Enum representing the log levels for ShieldFraud.
|
|
5
18
|
*/
|
|
6
19
|
export enum LogLevel {
|
|
20
|
+
LogLevelVerbose = 4,
|
|
7
21
|
LogLevelDebug = 3,
|
|
8
22
|
LogLevelInfo = 2,
|
|
9
23
|
LogLevelNone = 1,
|
|
@@ -13,9 +27,9 @@ export enum LogLevel {
|
|
|
13
27
|
* Enum representing the environment information for ShieldFraud.
|
|
14
28
|
*/
|
|
15
29
|
export enum EnvironmentInfo {
|
|
16
|
-
EnvironmentProd = 0,
|
|
17
|
-
EnvironmentDev = 1,
|
|
18
|
-
|
|
30
|
+
EnvironmentProd = 0, // Environment.PROD
|
|
31
|
+
EnvironmentDev = 1, // Environment.DEV
|
|
32
|
+
EnvironmentStaging = 2, // Environment.STAGING
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
/**
|
|
@@ -30,6 +44,12 @@ export interface Config {
|
|
|
30
44
|
} | null;
|
|
31
45
|
logLevel?: LogLevel;
|
|
32
46
|
environmentInfo?: EnvironmentInfo;
|
|
47
|
+
/**
|
|
48
|
+
* Android-only: when true, the Shield SDK will block screen recording
|
|
49
|
+
* while it is active. Has no effect on iOS (the value is forwarded but
|
|
50
|
+
* the native side ignores it). Defaults to false when not provided.
|
|
51
|
+
*/
|
|
52
|
+
blockScreenRecording?: boolean;
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
/**
|
|
@@ -58,8 +78,10 @@ export type ShieldCallback = {
|
|
|
58
78
|
class ShieldFraud {
|
|
59
79
|
/**
|
|
60
80
|
* The native module for accessing the ShieldFraudPlugin.
|
|
81
|
+
* Resolved via TurboModuleRegistry on New Architecture, with
|
|
82
|
+
* a NativeModules bridge fallback for Old Architecture.
|
|
61
83
|
*/
|
|
62
|
-
private static PlatformWrapper =
|
|
84
|
+
private static PlatformWrapper = ShieldFraudPluginNativeModule;
|
|
63
85
|
|
|
64
86
|
/**
|
|
65
87
|
* The event emitter for listening to success and error events.
|
|
@@ -86,15 +108,25 @@ class ShieldFraud {
|
|
|
86
108
|
// Set default values if environmentInfo is not provided
|
|
87
109
|
const environmentInfo =
|
|
88
110
|
config.environmentInfo || EnvironmentInfo.EnvironmentProd;
|
|
111
|
+
|
|
112
|
+
// Set cross-platform parameters internally (React Native and version from package.json)
|
|
113
|
+
ShieldFraud.setCrossPlatformParameters();
|
|
114
|
+
|
|
115
|
+
// blockScreenRecording is Android-only; iOS native ignores the value.
|
|
116
|
+
// Always send a real boolean — the Old Arch bridge cannot handle null
|
|
117
|
+
// for boolean parameters (causes NPE in ReadableNativeArray.getBoolean).
|
|
118
|
+
const blockScreenRecording =
|
|
119
|
+
Platform.OS === "android" ? (config.blockScreenRecording ?? false) : false;
|
|
89
120
|
|
|
90
121
|
// Call the native method to initialize ShieldFraud with the provided configuration.
|
|
91
122
|
await ShieldFraud.PlatformWrapper.initShield(
|
|
92
123
|
config.siteID,
|
|
93
124
|
config.secretKey,
|
|
94
125
|
isOptimizedListener,
|
|
95
|
-
config.blockedDialog,
|
|
126
|
+
config.blockedDialog ?? null,
|
|
96
127
|
logLevel,
|
|
97
|
-
environmentInfo
|
|
128
|
+
environmentInfo,
|
|
129
|
+
blockScreenRecording
|
|
98
130
|
);
|
|
99
131
|
|
|
100
132
|
if (isOptimizedListener) {
|
|
@@ -103,6 +135,20 @@ class ShieldFraud {
|
|
|
103
135
|
}
|
|
104
136
|
}
|
|
105
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Private method to set cross-platform parameters.
|
|
140
|
+
* The cross-platform name and the version is fetched from package.json.
|
|
141
|
+
*/
|
|
142
|
+
private static setCrossPlatformParameters(): void {
|
|
143
|
+
const crossPlatformName = "react-native-shield-fraud-plugin";
|
|
144
|
+
const crossPlatformVersion = "2.0.0";
|
|
145
|
+
|
|
146
|
+
ShieldFraud.PlatformWrapper.setCrossPlatformParameters(
|
|
147
|
+
crossPlatformName,
|
|
148
|
+
crossPlatformVersion
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
106
152
|
/**
|
|
107
153
|
* Sets up event listeners for success and error events.
|
|
108
154
|
*
|
|
@@ -143,14 +189,25 @@ class ShieldFraud {
|
|
|
143
189
|
}
|
|
144
190
|
|
|
145
191
|
/**
|
|
146
|
-
*
|
|
192
|
+
* iOS only — checks if the ShieldFraud SDK is ready and invokes the provided
|
|
193
|
+
* callback with the readiness state.
|
|
194
|
+
*
|
|
195
|
+
* On Android (SDK 2.x) device result events fire automatically via the
|
|
196
|
+
* Sentinel inside createShieldWithCallback. There is no subscription call
|
|
197
|
+
* and no reliable way to intercept the event after the fact, so this method
|
|
198
|
+
* is a no-op on Android. Use the `callbacks` parameter of `initShield`
|
|
199
|
+
* instead to receive device results on Android.
|
|
147
200
|
*
|
|
148
201
|
* @param callback - A callback function to be invoked with the readiness state.
|
|
149
|
-
* - `isReady` (boolean):
|
|
202
|
+
* - `isReady` (boolean): true when the SDK has produced a device result.
|
|
150
203
|
*/
|
|
151
204
|
public static async isSDKready(
|
|
152
205
|
callback: (isReady: boolean) => void
|
|
153
206
|
): Promise<void> {
|
|
207
|
+
if (Platform.OS !== "ios") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
154
211
|
try {
|
|
155
212
|
// Adding a timeout of 100 milliseconds
|
|
156
213
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -174,6 +231,8 @@ class ShieldFraud {
|
|
|
174
231
|
"device_result_state",
|
|
175
232
|
deviceResultListener
|
|
176
233
|
);
|
|
234
|
+
|
|
235
|
+
// Trigger the SDK subscription — iOS 1.x requires this explicit call.
|
|
177
236
|
ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
|
|
178
237
|
} catch (error) {
|
|
179
238
|
console.error("An error occurred:", error);
|
|
@@ -191,6 +250,31 @@ class ShieldFraud {
|
|
|
191
250
|
ShieldFraud.PlatformWrapper.sendAttributes(screenName, data);
|
|
192
251
|
}
|
|
193
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Sends attributes and resolves with `true` when the native SDK confirms success.
|
|
255
|
+
*
|
|
256
|
+
* @param screenName - The name of the screen.
|
|
257
|
+
* @param data - The attribute data object.
|
|
258
|
+
* @returns A Promise that resolves to true on success and rejects on error.
|
|
259
|
+
*/
|
|
260
|
+
public static sendAttributesWithCallback(
|
|
261
|
+
screenName: string,
|
|
262
|
+
data: object
|
|
263
|
+
): Promise<boolean> {
|
|
264
|
+
return new Promise((resolve, reject) => {
|
|
265
|
+
ShieldFraud.PlatformWrapper.sendAttributesWithCallback(
|
|
266
|
+
screenName,
|
|
267
|
+
data,
|
|
268
|
+
(result: boolean) => {
|
|
269
|
+
resolve(!!result);
|
|
270
|
+
},
|
|
271
|
+
(error: object) => {
|
|
272
|
+
reject(error);
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
194
278
|
/**
|
|
195
279
|
* Retrieves the latest device result from the ShieldFraud plugin.
|
|
196
280
|
*
|
|
@@ -200,11 +284,31 @@ class ShieldFraud {
|
|
|
200
284
|
return new Promise((resolve, reject) => {
|
|
201
285
|
ShieldFraud.PlatformWrapper.getLatestDeviceResult(
|
|
202
286
|
(result: object) => {
|
|
203
|
-
// Handle success with the result object
|
|
204
287
|
resolve(result);
|
|
205
288
|
},
|
|
206
289
|
(error: object) => {
|
|
207
|
-
|
|
290
|
+
reject(error);
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Triggers a device signature computation for a given screen name.
|
|
298
|
+
* On success, resolves with the latest device result object.
|
|
299
|
+
* On failure, rejects with the error message.
|
|
300
|
+
*
|
|
301
|
+
* @param screenName - The name of the screen triggering the signature.
|
|
302
|
+
* @returns A Promise that resolves with the device result or rejects with an error.
|
|
303
|
+
*/
|
|
304
|
+
public static sendDeviceSignature(screenName: string): Promise<object> {
|
|
305
|
+
return new Promise((resolve, reject) => {
|
|
306
|
+
ShieldFraud.PlatformWrapper.sendDeviceSignature(
|
|
307
|
+
screenName,
|
|
308
|
+
(result: object) => {
|
|
309
|
+
resolve(result);
|
|
310
|
+
},
|
|
311
|
+
(error: string) => {
|
|
208
312
|
reject(error);
|
|
209
313
|
}
|
|
210
314
|
);
|
package/ios/ShieldFraudPlugin.m
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#import "ShieldFraudPlugin.h"
|
|
2
|
-
|
|
3
|
-
@implementation ShieldFraudPlugin
|
|
4
|
-
|
|
5
|
-
static BOOL isShieldInitialized = NO;
|
|
6
|
-
|
|
7
|
-
RCT_EXPORT_MODULE();
|
|
8
|
-
|
|
9
|
-
RCT_EXPORT_METHOD(initShield:(NSString *)siteID secretKey:(NSString *)secretKey isOptimizedListener:(BOOL)isOptimizedListener blockedDialog:(NSDictionary *)blockedDialog logLevel:(NSInteger)logLevel environmentInfo:(NSInteger)environmentInfo)
|
|
10
|
-
{
|
|
11
|
-
if (!isShieldInitialized) {
|
|
12
|
-
Configuration *config = [[Configuration alloc] initWithSiteId:siteID secretKey:secretKey];
|
|
13
|
-
|
|
14
|
-
if (isOptimizedListener) {
|
|
15
|
-
config.deviceShieldCallback = self;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (blockedDialog != nil) {
|
|
19
|
-
NSString *title = [blockedDialog objectForKey:@"title"];
|
|
20
|
-
NSString *body = [blockedDialog objectForKey:@"body"];
|
|
21
|
-
config.defaultBlockedDialog = [[BlockedDialog alloc] initWithTitle:title body:body];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Use logLevel parameter as needed
|
|
25
|
-
config.logLevel = logLevel;
|
|
26
|
-
config.environment = environmentInfo;
|
|
27
|
-
[Shield setUpWith:config];
|
|
28
|
-
isShieldInitialized = YES;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// get session id from shield sdk
|
|
33
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSessionId) {
|
|
34
|
-
return [[Shield shared]sessionId];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isShieldInitialized) {
|
|
38
|
-
return @(isShieldInitialized);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// get device result to shield
|
|
42
|
-
RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback errorCallback: (RCTResponseSenderBlock)errorCallback)
|
|
43
|
-
{
|
|
44
|
-
NSDictionary<NSString *, id> *result = [[Shield shared] getLatestDeviceResult];
|
|
45
|
-
if (result != NULL) {
|
|
46
|
-
successCallback(@[result]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
NSError *error = [[Shield shared] getErrorResponse];
|
|
50
|
-
if (error != NULL) {
|
|
51
|
-
errorCallback(@[error]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
RCT_EXPORT_METHOD(setDeviceResultStateListener)
|
|
56
|
-
{
|
|
57
|
-
double delayInSeconds = 1.5;
|
|
58
|
-
|
|
59
|
-
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
|
|
60
|
-
|
|
61
|
-
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
|
62
|
-
[[Shield shared] setDeviceResultStateListener:^{
|
|
63
|
-
[self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
|
|
64
|
-
}];
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
70
|
-
return @[@"success", @"error", @"device_result_state"];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
- (void)addListener:(NSString *)eventName {
|
|
74
|
-
[super addListener:eventName];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
- (void)removeListeners:(double)count {
|
|
78
|
-
[super removeListeners:count];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (void)didErrorWithError:(NSError *)error
|
|
82
|
-
{
|
|
83
|
-
[self sendEventWithName:@"error" body:[error localizedDescription]];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
- (void)didSuccessWithResult:(NSDictionary<NSString *,id> *)result
|
|
87
|
-
{
|
|
88
|
-
[self sendEventWithName:@"success" body: result];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
RCT_EXPORT_METHOD(sendAttributes: (NSString *)screenName data: (NSDictionary *)data)
|
|
92
|
-
{
|
|
93
|
-
[[Shield shared] sendAttributesWithScreenName:screenName data:data];
|
|
94
|
-
}
|
|
95
|
-
@end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>ShieldFraudPlugin.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
</dict>
|
|
14
|
-
</plist>
|