@flonkid/kyc 1.4.2 → 1.5.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/README.md +77 -33
- package/dist/index.cjs +15 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,45 +11,66 @@ Official SDK for [Flonk](https://flonk.id) identity verification.
|
|
|
11
11
|
npm install @flonkid/kyc
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
| Import | Use |
|
|
15
|
+
|--------|-----|
|
|
16
|
+
| `@flonkid/kyc` | Browser — widget + React component |
|
|
17
|
+
| `@flonkid/kyc/server` | Node.js — sessions API + webhook verification |
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
import { FlonkKYC } from '@flonkid/kyc';
|
|
19
|
+
## React Component (recommended)
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
const widget = await kyc.init({
|
|
21
|
-
publishableKey: 'pk_live_...',
|
|
22
|
-
onSuccess: (result) => console.log('Verified:', result),
|
|
23
|
-
onError: (err) => console.error(err),
|
|
24
|
-
});
|
|
21
|
+
### Option A: SDK handles session creation
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
```tsx
|
|
24
|
+
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
25
|
+
|
|
26
|
+
<FlonkKYCWidget
|
|
27
|
+
serverUrl="/api/kyc/create-session"
|
|
28
|
+
clientMetadata={{ email: 'user@example.com', userId: 'user_123' }}
|
|
29
|
+
lang="de"
|
|
30
|
+
onSuccess={(result) => console.log('Verified:', result)}
|
|
31
|
+
onError={(error) => console.error(error)}
|
|
32
|
+
onCancel={() => console.log('Cancelled')}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
// With authenticated backend
|
|
36
|
+
<FlonkKYCWidget
|
|
37
|
+
serverUrl="/api/kyc/create-session"
|
|
38
|
+
requestHeaders={{ Authorization: `Bearer ${token}` }}
|
|
39
|
+
...
|
|
40
|
+
/>
|
|
27
41
|
```
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
### Option B: You control session creation
|
|
30
44
|
|
|
31
45
|
```tsx
|
|
32
46
|
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
33
47
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
48
|
+
// 1. Create session on your backend first
|
|
49
|
+
const { sessionId, embedToken } = await fetch('/api/kyc/create-session', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
body: JSON.stringify({ email: user.email }),
|
|
52
|
+
}).then(r => r.json());
|
|
53
|
+
|
|
54
|
+
// 2. Pass credentials to widget
|
|
55
|
+
<FlonkKYCWidget
|
|
56
|
+
sessionId={sessionId}
|
|
57
|
+
embedToken={embedToken}
|
|
58
|
+
lang="de"
|
|
59
|
+
onSuccess={(result) => console.log('Verified:', result)}
|
|
60
|
+
onError={(error) => console.error(error)}
|
|
61
|
+
onCancel={() => console.log('Cancelled')}
|
|
62
|
+
/>
|
|
43
63
|
```
|
|
44
64
|
|
|
45
65
|
### Props
|
|
46
66
|
|
|
47
67
|
| Prop | Type | Description |
|
|
48
68
|
|------|------|-------------|
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
69
|
+
| `serverUrl` | `string` | Your backend endpoint — SDK auto-creates session |
|
|
70
|
+
| `sessionId` | `string` | Pre-created session ID (Option B) |
|
|
71
|
+
| `embedToken` | `string` | JWT token from your backend (Option B) |
|
|
72
|
+
| `requestHeaders` | `Record<string, string>` | Extra headers for serverUrl (e.g. JWT auth) |
|
|
73
|
+
| `clientMetadata` | `Record<string, unknown>` | Custom data passed to session |
|
|
53
74
|
| `lang` | `'en' \| 'de' \| 'uk'` | Widget language |
|
|
54
75
|
| `onSuccess` | `(result) => void` | Verification completed |
|
|
55
76
|
| `onError` | `(error) => void` | Error occurred |
|
|
@@ -57,6 +78,26 @@ function App() {
|
|
|
57
78
|
| `onReady` | `() => void` | Widget loaded |
|
|
58
79
|
| `autoOpen` | `boolean` | Open on mount (default: `true`) |
|
|
59
80
|
|
|
81
|
+
## Imperative API (non-React)
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { FlonkKYC } from '@flonkid/kyc';
|
|
85
|
+
|
|
86
|
+
const kyc = new FlonkKYC();
|
|
87
|
+
|
|
88
|
+
const widget = await kyc.init({
|
|
89
|
+
serverUrl: '/api/kyc/create-session',
|
|
90
|
+
clientMetadata: { email: 'user@example.com' },
|
|
91
|
+
lang: 'de',
|
|
92
|
+
onSuccess: (result) => console.log('Verified:', result),
|
|
93
|
+
onError: (error) => console.error(error),
|
|
94
|
+
onCancel: () => console.log('Cancelled'),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Cleanup
|
|
98
|
+
widget.destroy();
|
|
99
|
+
```
|
|
100
|
+
|
|
60
101
|
## Server — Node.js
|
|
61
102
|
|
|
62
103
|
```typescript
|
|
@@ -65,11 +106,14 @@ import { FlonkKYCServer } from '@flonkid/kyc/server';
|
|
|
65
106
|
const flonk = new FlonkKYCServer({ secretKey: 'sk_live_...' });
|
|
66
107
|
|
|
67
108
|
// Create session
|
|
68
|
-
const session = await flonk.
|
|
69
|
-
clientMetadata: { userId: 'user_123' },
|
|
109
|
+
const session = await flonk.createSession({
|
|
110
|
+
clientMetadata: { email: 'user@example.com', userId: 'user_123' },
|
|
111
|
+
expiryMinutes: 30,
|
|
112
|
+
language: 'de',
|
|
70
113
|
});
|
|
114
|
+
// → { id, embedToken, status, expiresAt, widgetUrl, qrCodeUrl }
|
|
71
115
|
|
|
72
|
-
// Verify webhook
|
|
116
|
+
// Verify webhook
|
|
73
117
|
const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
|
|
74
118
|
```
|
|
75
119
|
|
|
@@ -78,7 +122,7 @@ const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
|
|
|
78
122
|
| Event | Description |
|
|
79
123
|
|-------|-------------|
|
|
80
124
|
| `verification.completed` | AI verification finished |
|
|
81
|
-
| `verification.status_changed` | Admin changed status |
|
|
125
|
+
| `verification.status_changed` | Admin changed status (approved/rejected) |
|
|
82
126
|
| `verification.updated` | Admin edited verification data |
|
|
83
127
|
|
|
84
128
|
```typescript
|
|
@@ -86,13 +130,13 @@ const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
|
|
|
86
130
|
|
|
87
131
|
switch (event.type) {
|
|
88
132
|
case 'verification.completed':
|
|
89
|
-
|
|
133
|
+
console.log('Extracted:', event.data.object.extracted_data);
|
|
90
134
|
break;
|
|
91
135
|
case 'verification.status_changed':
|
|
92
|
-
|
|
136
|
+
console.log('New status:', event.data.object.status);
|
|
93
137
|
break;
|
|
94
138
|
case 'verification.updated':
|
|
95
|
-
|
|
139
|
+
console.log('Updated by:', event.data.object.updated_by);
|
|
96
140
|
break;
|
|
97
141
|
}
|
|
98
142
|
```
|
|
@@ -100,9 +144,9 @@ switch (event.type) {
|
|
|
100
144
|
## Links
|
|
101
145
|
|
|
102
146
|
- [Full Documentation](https://docs.flonk.id)
|
|
103
|
-
- [
|
|
147
|
+
- [Integration Guide](https://docs.flonk.id/docs/integration-frontend-backend)
|
|
104
148
|
- [Webhook Guide](https://docs.flonk.id/docs/webhooks)
|
|
105
|
-
- [
|
|
149
|
+
- [Dashboard](https://dashboard.flonk.id)
|
|
106
150
|
|
|
107
151
|
## License
|
|
108
152
|
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ var react = require('react');
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
|
|
6
6
|
// src/shared/constants.ts
|
|
7
|
-
var SDK_VERSION = "1.
|
|
7
|
+
var SDK_VERSION = "1.5.1";
|
|
8
8
|
var DEFAULT_WIDGET_URL = "https://widget.flonk.id";
|
|
9
9
|
var DEFAULT_API_BASE = "https://api.flonk.id/v1";
|
|
10
10
|
var WIDGET_EVENTS = {
|
|
@@ -121,11 +121,12 @@ function validateServerUrl(url) {
|
|
|
121
121
|
throw new Error(`Invalid serverUrl: ${url}`);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
async function fetchSessionFromServer(serverUrl, clientMetadata) {
|
|
124
|
+
async function fetchSessionFromServer(serverUrl, clientMetadata, requestHeaders) {
|
|
125
125
|
validateServerUrl(serverUrl);
|
|
126
126
|
const res = await fetch(serverUrl, {
|
|
127
127
|
method: "POST",
|
|
128
|
-
headers: { "Content-Type": "application/json" },
|
|
128
|
+
headers: { "Content-Type": "application/json", ...requestHeaders },
|
|
129
|
+
credentials: "include",
|
|
129
130
|
body: JSON.stringify({ clientMetadata })
|
|
130
131
|
});
|
|
131
132
|
if (!res.ok) {
|
|
@@ -769,18 +770,23 @@ var FlonkKYC = class {
|
|
|
769
770
|
/**
|
|
770
771
|
* Flow 1: serverUrl — POST to client's backend, get sessionId + embedToken.
|
|
771
772
|
*/
|
|
773
|
+
/**
|
|
774
|
+
* POST to serverUrl to get sessionId + embedToken, then same path as embed token flow.
|
|
775
|
+
* No loader here — avoids wrong brand color before design tokens exist; initWithEmbedToken
|
|
776
|
+
* fetches tokens first, then shows loader with project primary color.
|
|
777
|
+
*/
|
|
772
778
|
async initWithServerUrl(config) {
|
|
773
|
-
const loader = new Loader();
|
|
774
|
-
loader.show("#15BA68", config.lang);
|
|
775
779
|
try {
|
|
776
780
|
const { sessionId, embedToken } = await fetchSessionFromServer(
|
|
777
781
|
config.serverUrl,
|
|
778
|
-
config.clientMetadata
|
|
782
|
+
config.clientMetadata,
|
|
783
|
+
config.requestHeaders
|
|
779
784
|
);
|
|
780
|
-
loader.destroy();
|
|
781
785
|
return this.initWithEmbedToken({ ...config, sessionId, embedToken });
|
|
782
786
|
} catch (err) {
|
|
783
787
|
const msg = err.message || "Failed to create session";
|
|
788
|
+
const loader = new Loader();
|
|
789
|
+
loader.show("#15BA68", config.lang);
|
|
784
790
|
loader.showError(msg, config.lang);
|
|
785
791
|
config.onError?.(msg);
|
|
786
792
|
throw err;
|
|
@@ -984,6 +990,7 @@ function FlonkKYCWidget({
|
|
|
984
990
|
lang,
|
|
985
991
|
overlayColor,
|
|
986
992
|
allowManualUpload,
|
|
993
|
+
requestHeaders,
|
|
987
994
|
onSuccess,
|
|
988
995
|
onError,
|
|
989
996
|
onCancel,
|
|
@@ -1007,6 +1014,7 @@ function FlonkKYCWidget({
|
|
|
1007
1014
|
lang,
|
|
1008
1015
|
overlayColor,
|
|
1009
1016
|
allowManualUpload,
|
|
1017
|
+
requestHeaders,
|
|
1010
1018
|
mount: mountRef.current || void 0,
|
|
1011
1019
|
onSuccess: (r) => callbacksRef.current.onSuccess?.(r),
|
|
1012
1020
|
onError: (e) => callbacksRef.current.onError?.(e),
|