react-native-shield-fraud-plugin 1.0.11 → 2.0.1
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 +25 -18
- package/android/src/main/java/com/shieldfraudplugin/ShieldFraudPluginModule.java +348 -125
- 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 +67 -9
- 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 +68 -10
- 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 +33 -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 +98 -12
- package/ios/ShieldFraudPlugin.m +0 -106
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.
|
|
@@ -90,14 +112,21 @@ class ShieldFraud {
|
|
|
90
112
|
// Set cross-platform parameters internally (React Native and version from package.json)
|
|
91
113
|
ShieldFraud.setCrossPlatformParameters();
|
|
92
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;
|
|
120
|
+
|
|
93
121
|
// Call the native method to initialize ShieldFraud with the provided configuration.
|
|
94
122
|
await ShieldFraud.PlatformWrapper.initShield(
|
|
95
123
|
config.siteID,
|
|
96
124
|
config.secretKey,
|
|
97
125
|
isOptimizedListener,
|
|
98
|
-
config.blockedDialog,
|
|
126
|
+
config.blockedDialog ?? null,
|
|
99
127
|
logLevel,
|
|
100
|
-
environmentInfo
|
|
128
|
+
environmentInfo,
|
|
129
|
+
blockScreenRecording
|
|
101
130
|
);
|
|
102
131
|
|
|
103
132
|
if (isOptimizedListener) {
|
|
@@ -112,7 +141,7 @@ class ShieldFraud {
|
|
|
112
141
|
*/
|
|
113
142
|
private static setCrossPlatformParameters(): void {
|
|
114
143
|
const crossPlatformName = "react-native-shield-fraud-plugin";
|
|
115
|
-
const crossPlatformVersion = "
|
|
144
|
+
const crossPlatformVersion = "2.0.1";
|
|
116
145
|
|
|
117
146
|
ShieldFraud.PlatformWrapper.setCrossPlatformParameters(
|
|
118
147
|
crossPlatformName,
|
|
@@ -160,14 +189,24 @@ class ShieldFraud {
|
|
|
160
189
|
}
|
|
161
190
|
|
|
162
191
|
/**
|
|
163
|
-
* Checks if the ShieldFraud SDK is ready and invokes the provided callback
|
|
192
|
+
* Checks if the ShieldFraud SDK is ready and invokes the provided callback
|
|
193
|
+
* with the readiness state.
|
|
194
|
+
*
|
|
195
|
+
* On Android, readiness is approximated by the native initialization state
|
|
196
|
+
* to preserve backward compatibility without reporting ready before init.
|
|
164
197
|
*
|
|
165
198
|
* @param callback - A callback function to be invoked with the readiness state.
|
|
166
|
-
* - `isReady` (boolean):
|
|
199
|
+
* - `isReady` (boolean): true when the SDK has produced a device result.
|
|
167
200
|
*/
|
|
168
201
|
public static async isSDKready(
|
|
169
202
|
callback: (isReady: boolean) => void
|
|
170
203
|
): Promise<void> {
|
|
204
|
+
if (Platform.OS === "android") {
|
|
205
|
+
const isInitialized = await this.isShieldInitialized();
|
|
206
|
+
callback(isInitialized);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
171
210
|
try {
|
|
172
211
|
// Adding a timeout of 100 milliseconds
|
|
173
212
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -191,6 +230,8 @@ class ShieldFraud {
|
|
|
191
230
|
"device_result_state",
|
|
192
231
|
deviceResultListener
|
|
193
232
|
);
|
|
233
|
+
|
|
234
|
+
// Trigger the SDK subscription — iOS 1.x requires this explicit call.
|
|
194
235
|
ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
|
|
195
236
|
} catch (error) {
|
|
196
237
|
console.error("An error occurred:", error);
|
|
@@ -208,6 +249,31 @@ class ShieldFraud {
|
|
|
208
249
|
ShieldFraud.PlatformWrapper.sendAttributes(screenName, data);
|
|
209
250
|
}
|
|
210
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Sends attributes and resolves with `true` when the native SDK confirms success.
|
|
254
|
+
*
|
|
255
|
+
* @param screenName - The name of the screen.
|
|
256
|
+
* @param data - The attribute data object.
|
|
257
|
+
* @returns A Promise that resolves to true on success and rejects on error.
|
|
258
|
+
*/
|
|
259
|
+
public static sendAttributesWithCallback(
|
|
260
|
+
screenName: string,
|
|
261
|
+
data: object
|
|
262
|
+
): Promise<boolean> {
|
|
263
|
+
return new Promise((resolve, reject) => {
|
|
264
|
+
ShieldFraud.PlatformWrapper.sendAttributesWithCallback(
|
|
265
|
+
screenName,
|
|
266
|
+
data,
|
|
267
|
+
(result: boolean) => {
|
|
268
|
+
resolve(!!result);
|
|
269
|
+
},
|
|
270
|
+
(error: object) => {
|
|
271
|
+
reject(error);
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
211
277
|
/**
|
|
212
278
|
* Retrieves the latest device result from the ShieldFraud plugin.
|
|
213
279
|
*
|
|
@@ -217,11 +283,31 @@ class ShieldFraud {
|
|
|
217
283
|
return new Promise((resolve, reject) => {
|
|
218
284
|
ShieldFraud.PlatformWrapper.getLatestDeviceResult(
|
|
219
285
|
(result: object) => {
|
|
220
|
-
// Handle success with the result object
|
|
221
286
|
resolve(result);
|
|
222
287
|
},
|
|
223
288
|
(error: object) => {
|
|
224
|
-
|
|
289
|
+
reject(error);
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Triggers a device signature computation for a given screen name.
|
|
297
|
+
* On success, resolves with the latest device result object.
|
|
298
|
+
* On failure, rejects with the error message.
|
|
299
|
+
*
|
|
300
|
+
* @param screenName - The name of the screen triggering the signature.
|
|
301
|
+
* @returns A Promise that resolves with the device result or rejects with an error.
|
|
302
|
+
*/
|
|
303
|
+
public static sendDeviceSignature(screenName: string): Promise<object> {
|
|
304
|
+
return new Promise((resolve, reject) => {
|
|
305
|
+
ShieldFraud.PlatformWrapper.sendDeviceSignature(
|
|
306
|
+
screenName,
|
|
307
|
+
(result: object) => {
|
|
308
|
+
resolve(result);
|
|
309
|
+
},
|
|
310
|
+
(error: string) => {
|
|
225
311
|
reject(error);
|
|
226
312
|
}
|
|
227
313
|
);
|
package/ios/ShieldFraudPlugin.m
DELETED
|
@@ -1,106 +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
|
-
// New method to set cross-platform parameters
|
|
33
|
-
RCT_EXPORT_METHOD(setCrossPlatformParameters:(NSString *)crossPlatformName
|
|
34
|
-
crossPlatformVersion:(NSString *)crossPlatformVersion)
|
|
35
|
-
{
|
|
36
|
-
ShieldCrossPlatformParams *params = [[ShieldCrossPlatformParams alloc] initWithName:crossPlatformName version:crossPlatformVersion];
|
|
37
|
-
[ShieldCrossPlatformHelper setCrossPlatformParameters:params];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// get session id from shield sdk
|
|
41
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSessionId) {
|
|
42
|
-
return [[Shield shared]sessionId];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isShieldInitialized) {
|
|
46
|
-
return @(isShieldInitialized);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// get device result to shield
|
|
50
|
-
RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback errorCallback: (RCTResponseSenderBlock)errorCallback)
|
|
51
|
-
{
|
|
52
|
-
NSDictionary<NSString *, id> *result = [[Shield shared] getLatestDeviceResult];
|
|
53
|
-
if (result != NULL) {
|
|
54
|
-
successCallback(@[result]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
NSError *error = [[Shield shared] getErrorResponse];
|
|
58
|
-
if (error != NULL) {
|
|
59
|
-
errorCallback(@[error]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
RCT_EXPORT_METHOD(setDeviceResultStateListener)
|
|
64
|
-
{
|
|
65
|
-
double delayInSeconds = 1.5;
|
|
66
|
-
|
|
67
|
-
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
|
|
68
|
-
|
|
69
|
-
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
|
70
|
-
[[Shield shared] setDeviceResultStateListener:^{
|
|
71
|
-
[self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
|
|
72
|
-
}];
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
78
|
-
return @[@"success", @"error", @"device_result_state"];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (void)addListener:(NSString *)eventName {
|
|
82
|
-
[super addListener:eventName];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
- (void)removeListeners:(double)count {
|
|
86
|
-
[super removeListeners:count];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
- (void)didErrorWithError:(NSError *)error
|
|
90
|
-
{
|
|
91
|
-
[self sendEventWithName:@"error" body:[error localizedDescription]];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
- (void)didSuccessWithResult:(NSDictionary<NSString *,id> *)result
|
|
95
|
-
{
|
|
96
|
-
[self sendEventWithName:@"success" body: result];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
RCT_EXPORT_METHOD(sendAttributes: (NSString *)screenName data: (NSDictionary *)data)
|
|
100
|
-
{
|
|
101
|
-
[[Shield shared] sendAttributesWithScreenName:screenName data:data];
|
|
102
|
-
}
|
|
103
|
-
@end
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|