prembly-react-native-kyc 1.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/README.md +64 -0
- package/dist/PremblyIdentityWidget.d.ts +13 -0
- package/dist/PremblyIdentityWidget.js +209 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# prembly-react-native-kyc
|
|
2
|
+
|
|
3
|
+
React Native version of the Prembly Identity KYC Verification SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install prembly-react-native-kyc
|
|
9
|
+
# Also install peer dependencies if not already present
|
|
10
|
+
npm install react-native-webview
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import React, { useState } from 'react';
|
|
17
|
+
import { View, Button } from 'react-native';
|
|
18
|
+
import { PremblyIdentityWidget } from 'prembly-react-native-kyc';
|
|
19
|
+
|
|
20
|
+
const App = () => {
|
|
21
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
25
|
+
<Button title="Verify Identity" onPress={() => setIsVisible(true)} />
|
|
26
|
+
|
|
27
|
+
<PremblyIdentityWidget
|
|
28
|
+
isVisible={isVisible}
|
|
29
|
+
widgetKey="your_widget_key_here"
|
|
30
|
+
widgetId="your_widget_id_here"
|
|
31
|
+
email="john@example.com"
|
|
32
|
+
phone="+2348012345678"
|
|
33
|
+
firstName="John"
|
|
34
|
+
lastName="Doe"
|
|
35
|
+
callback={(response) => {
|
|
36
|
+
console.log('Widget Response:', response);
|
|
37
|
+
if (response.status === 'closed' || response.status === 'error_display_closed' || response.status === 'success') {
|
|
38
|
+
setIsVisible(false);
|
|
39
|
+
}
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default App;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Properties
|
|
50
|
+
|
|
51
|
+
| Prop | Type | Required | Description |
|
|
52
|
+
|---|---|---|---|
|
|
53
|
+
| `isVisible` | `boolean` | Yes | Controls the visibility of the widget modal |
|
|
54
|
+
| `widgetKey` | `string` | Yes | Your Prembly widget public key |
|
|
55
|
+
| `widgetId` | `string` | Yes | Your configuration/widget ID from the dashboard |
|
|
56
|
+
| `email` | `string` | No | User's email address |
|
|
57
|
+
| `phone` | `string` | No | User's phone number |
|
|
58
|
+
| `firstName` | `string` | No | User's first name |
|
|
59
|
+
| `lastName` | `string` | No | User's last name |
|
|
60
|
+
| `metadata` | `object` | No | Additional metadata to pass to the session |
|
|
61
|
+
| `callback` | `function` | Yes | Called with payload indicating `closed`, `error`, or `success` |
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface PremblyIdentityWidgetProps {
|
|
3
|
+
isVisible: boolean;
|
|
4
|
+
widgetKey: string;
|
|
5
|
+
widgetId: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
phone?: string;
|
|
8
|
+
firstName?: string;
|
|
9
|
+
lastName?: string;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
callback: (response: any) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const PremblyIdentityWidget: ({ isVisible, widgetKey, widgetId, email, phone, firstName, lastName, metadata, callback, }: PremblyIdentityWidgetProps) => React.JSX.Element | null;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.PremblyIdentityWidget = void 0;
|
|
46
|
+
const react_1 = __importStar(require("react"));
|
|
47
|
+
const react_native_1 = require("react-native");
|
|
48
|
+
const react_native_webview_1 = require("react-native-webview");
|
|
49
|
+
const PremblyIdentityWidget = ({ isVisible, widgetKey, widgetId, email = '', phone = '', firstName = '', lastName = '', metadata = {}, callback, }) => {
|
|
50
|
+
const [webViewUrl, setWebViewUrl] = (0, react_1.useState)(null);
|
|
51
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
52
|
+
const [errorMessage, setErrorMessage] = (0, react_1.useState)(null);
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
if (isVisible) {
|
|
55
|
+
initializePremblyWidget();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
setWebViewUrl(null);
|
|
59
|
+
setIsLoading(true);
|
|
60
|
+
setErrorMessage(null);
|
|
61
|
+
}
|
|
62
|
+
}, [isVisible]);
|
|
63
|
+
const initializePremblyWidget = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
setIsLoading(true);
|
|
65
|
+
setErrorMessage(null);
|
|
66
|
+
const apiUrl = 'https://api.prembly.com/api/v1/checker-widget/sdk/sessions/initiate/';
|
|
67
|
+
const requestBody = {
|
|
68
|
+
first_name: firstName,
|
|
69
|
+
last_name: lastName,
|
|
70
|
+
email: email,
|
|
71
|
+
phone: phone,
|
|
72
|
+
widget_key: widgetKey,
|
|
73
|
+
widget_id: widgetId,
|
|
74
|
+
metadata: metadata,
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
const response = yield fetch(apiUrl, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
'Accept': '*/*',
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify(requestBody),
|
|
84
|
+
});
|
|
85
|
+
if (response.ok) {
|
|
86
|
+
const responseData = yield response.json();
|
|
87
|
+
if (responseData.status === true && responseData.data) {
|
|
88
|
+
const sessionId = responseData.data.session.session_id;
|
|
89
|
+
setWebViewUrl(`https://sdk-live.prembly.com/?session=${sessionId}`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const errorMsg = responseData.detail || 'Failed to get widget ID from API.';
|
|
93
|
+
setErrorMessage(errorMsg);
|
|
94
|
+
callback({ status: 'api_error', message: errorMsg });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const text = yield response.text();
|
|
99
|
+
const errorMsg = `API call failed with status: ${response.status}. Response: ${text}`;
|
|
100
|
+
setErrorMessage(errorMsg);
|
|
101
|
+
callback({ status: 'api_error', message: errorMsg });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
const errorMsg = `Network error or data parsing error: ${e.message}`;
|
|
106
|
+
setErrorMessage(errorMsg);
|
|
107
|
+
callback({ status: 'network_error', message: errorMsg });
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
setIsLoading(false);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const handleMessage = (event) => {
|
|
114
|
+
try {
|
|
115
|
+
const data = JSON.parse(event.nativeEvent.data);
|
|
116
|
+
if (data.event) {
|
|
117
|
+
switch (data.event) {
|
|
118
|
+
case 'closed':
|
|
119
|
+
callback({ status: 'closed' });
|
|
120
|
+
break;
|
|
121
|
+
case 'error':
|
|
122
|
+
callback({ status: 'error', message: data.message });
|
|
123
|
+
break;
|
|
124
|
+
case 'verified':
|
|
125
|
+
callback({ status: 'success', data: data });
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
console.warn('Received unknown event from WebView:', data.event);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
console.error('Error decoding JSON from WebView:', e);
|
|
135
|
+
callback({ status: 'error', message: `Failed to process message from WebView: ${e}` });
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
if (!isVisible)
|
|
139
|
+
return null;
|
|
140
|
+
return (<react_native_1.Modal visible={isVisible} animationType="slide" transparent={false}>
|
|
141
|
+
<react_native_1.SafeAreaView style={styles.container}>
|
|
142
|
+
{isLoading ? (<react_native_1.View style={styles.center}>
|
|
143
|
+
<react_native_1.ActivityIndicator size="large" color="#0000ff"/>
|
|
144
|
+
<react_native_1.Text style={styles.loadingText}>Initializing secure session...</react_native_1.Text>
|
|
145
|
+
</react_native_1.View>) : errorMessage ? (<react_native_1.View style={styles.center}>
|
|
146
|
+
<react_native_1.Text style={styles.errorText}>Error: {errorMessage}</react_native_1.Text>
|
|
147
|
+
<react_native_1.TouchableOpacity style={styles.button} onPress={initializePremblyWidget}>
|
|
148
|
+
<react_native_1.Text style={styles.buttonText}>Retry</react_native_1.Text>
|
|
149
|
+
</react_native_1.TouchableOpacity>
|
|
150
|
+
<react_native_1.TouchableOpacity style={styles.buttonSecondary} onPress={() => callback({ status: 'error_display_closed' })}>
|
|
151
|
+
<react_native_1.Text style={styles.buttonTextSecondary}>Cancel</react_native_1.Text>
|
|
152
|
+
</react_native_1.TouchableOpacity>
|
|
153
|
+
</react_native_1.View>) : (<react_native_webview_1.WebView source={{ uri: webViewUrl }} onMessage={handleMessage} injectedJavaScript={`
|
|
154
|
+
window.addEventListener("message", (event) => {
|
|
155
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(event.data));
|
|
156
|
+
}, false);
|
|
157
|
+
true; // note: this is required, or you'll sometimes get silent failures
|
|
158
|
+
`} style={styles.webview} allowsInlineMediaPlayback mediaPlaybackRequiresUserAction={false}/>)}
|
|
159
|
+
</react_native_1.SafeAreaView>
|
|
160
|
+
</react_native_1.Modal>);
|
|
161
|
+
};
|
|
162
|
+
exports.PremblyIdentityWidget = PremblyIdentityWidget;
|
|
163
|
+
const styles = react_native_1.StyleSheet.create({
|
|
164
|
+
container: {
|
|
165
|
+
flex: 1,
|
|
166
|
+
backgroundColor: '#fff',
|
|
167
|
+
},
|
|
168
|
+
center: {
|
|
169
|
+
flex: 1,
|
|
170
|
+
justifyContent: 'center',
|
|
171
|
+
alignItems: 'center',
|
|
172
|
+
padding: 20,
|
|
173
|
+
},
|
|
174
|
+
loadingText: {
|
|
175
|
+
marginTop: 16,
|
|
176
|
+
fontSize: 16,
|
|
177
|
+
color: '#333',
|
|
178
|
+
},
|
|
179
|
+
errorText: {
|
|
180
|
+
color: 'red',
|
|
181
|
+
fontSize: 16,
|
|
182
|
+
textAlign: 'center',
|
|
183
|
+
marginBottom: 20,
|
|
184
|
+
},
|
|
185
|
+
webview: {
|
|
186
|
+
flex: 1,
|
|
187
|
+
},
|
|
188
|
+
button: {
|
|
189
|
+
backgroundColor: '#007bff',
|
|
190
|
+
paddingVertical: 12,
|
|
191
|
+
paddingHorizontal: 24,
|
|
192
|
+
borderRadius: 8,
|
|
193
|
+
marginBottom: 10,
|
|
194
|
+
},
|
|
195
|
+
buttonText: {
|
|
196
|
+
color: '#fff',
|
|
197
|
+
fontSize: 16,
|
|
198
|
+
fontWeight: '600',
|
|
199
|
+
},
|
|
200
|
+
buttonSecondary: {
|
|
201
|
+
backgroundColor: 'transparent',
|
|
202
|
+
paddingVertical: 12,
|
|
203
|
+
paddingHorizontal: 24,
|
|
204
|
+
},
|
|
205
|
+
buttonTextSecondary: {
|
|
206
|
+
color: '#007bff',
|
|
207
|
+
fontSize: 16,
|
|
208
|
+
},
|
|
209
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PremblyIdentityWidget';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PremblyIdentityWidget"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prembly-react-native-kyc",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React Native Identity KYC Verification library",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepack": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react-native",
|
|
13
|
+
"prembly",
|
|
14
|
+
"kyc",
|
|
15
|
+
"identity"
|
|
16
|
+
],
|
|
17
|
+
"author": "Prembly",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18.0.0",
|
|
21
|
+
"react-native": ">=0.70.0",
|
|
22
|
+
"react-native-webview": ">=11.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"react": "^18.2.0",
|
|
26
|
+
"react-native": "^0.74.0",
|
|
27
|
+
"react-native-webview": "^13.10.0",
|
|
28
|
+
"@types/react": "^18.2.0",
|
|
29
|
+
"@types/react-native": "^0.72.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
33
|
+
}
|