@flonkid/kyc 1.6.1 → 1.7.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 +175 -169
- package/dist/index.cjs +257 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +257 -358
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +21 -46
- 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 +21 -46
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,169 +1,175 @@
|
|
|
1
|
-
# @flonkid/kyc
|
|
2
|
-
|
|
3
|
-
Official SDK for [Flonk](https://flonk.id) identity verification.
|
|
4
|
-
|
|
5
|
-
- **Dashboard**: [dashboard.flonk.id](https://dashboard.flonk.id)
|
|
6
|
-
- **Docs**: [docs.flonk.id](https://docs.flonk.id)
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npm install @flonkid/kyc
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
| Import | Use |
|
|
15
|
-
|--------|-----|
|
|
16
|
-
| `@flonkid/kyc` | Browser — widget + React component |
|
|
17
|
-
| `@flonkid/kyc/server` | Node.js — sessions API + webhook verification |
|
|
18
|
-
|
|
19
|
-
## Keys
|
|
20
|
-
|
|
21
|
-
You'll find two keys in **Dashboard → Project Settings → API Keys**:
|
|
22
|
-
|
|
23
|
-
| Key | Prefix | Where to use | Purpose |
|
|
24
|
-
|-----|--------|--------------|---------|
|
|
25
|
-
| **Publishable key** | `pk_live_*` / `pk_sandbox_*` | Frontend (browser) | Loads your project branding (logo, colors) instantly |
|
|
26
|
-
| **Secret key** | `sk_live_*` / `sk_sandbox_*` | Backend only | Creates sessions, authenticates API calls |
|
|
27
|
-
|
|
28
|
-
> **Never expose your secret key in client-side code.**
|
|
29
|
-
|
|
30
|
-
## React Component (recommended)
|
|
31
|
-
|
|
32
|
-
### Option A: SDK handles session creation
|
|
33
|
-
|
|
34
|
-
```tsx
|
|
35
|
-
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
36
|
-
|
|
37
|
-
<FlonkKYCWidget
|
|
38
|
-
publishableKey="pk_live_..."
|
|
39
|
-
serverUrl="/api/kyc/create-session"
|
|
40
|
-
clientMetadata={{ email: 'user@example.com', userId: 'user_123' }}
|
|
41
|
-
lang="de"
|
|
42
|
-
onSuccess={(result) => console.log('Verified:', result)}
|
|
43
|
-
onError={(error) => console.error(error)}
|
|
44
|
-
onCancel={() => console.log('Cancelled')}
|
|
45
|
-
/>
|
|
46
|
-
|
|
47
|
-
// With authenticated backend
|
|
48
|
-
<FlonkKYCWidget
|
|
49
|
-
publishableKey="pk_live_..."
|
|
50
|
-
serverUrl="/api/kyc/create-session"
|
|
51
|
-
requestHeaders={{ Authorization: `Bearer ${token}` }}
|
|
52
|
-
...
|
|
53
|
-
/>
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Option B: You control session creation
|
|
57
|
-
|
|
58
|
-
```tsx
|
|
59
|
-
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
60
|
-
|
|
61
|
-
// 1. Create session on your backend first
|
|
62
|
-
const { sessionId, embedToken } = await fetch('/api/kyc/create-session', {
|
|
63
|
-
method: 'POST',
|
|
64
|
-
body: JSON.stringify({ email: user.email }),
|
|
65
|
-
}).then(r => r.json());
|
|
66
|
-
|
|
67
|
-
// 2. Pass credentials to widget
|
|
68
|
-
<FlonkKYCWidget
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
|
87
|
-
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
case 'verification.
|
|
154
|
-
console.log('
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
# @flonkid/kyc
|
|
2
|
+
|
|
3
|
+
Official SDK for [Flonk](https://flonk.id) identity verification.
|
|
4
|
+
|
|
5
|
+
- **Dashboard**: [dashboard.flonk.id](https://dashboard.flonk.id)
|
|
6
|
+
- **Docs**: [docs.flonk.id](https://docs.flonk.id)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @flonkid/kyc
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Import | Use |
|
|
15
|
+
|--------|-----|
|
|
16
|
+
| `@flonkid/kyc` | Browser — widget + React component |
|
|
17
|
+
| `@flonkid/kyc/server` | Node.js — sessions API + webhook verification |
|
|
18
|
+
|
|
19
|
+
## Keys
|
|
20
|
+
|
|
21
|
+
You'll find two keys in **Dashboard → Project Settings → API Keys**:
|
|
22
|
+
|
|
23
|
+
| Key | Prefix | Where to use | Purpose |
|
|
24
|
+
|-----|--------|--------------|---------|
|
|
25
|
+
| **Publishable key** | `pk_live_*` / `pk_sandbox_*` | Frontend (browser) | Loads your project branding (logo, colors) instantly |
|
|
26
|
+
| **Secret key** | `sk_live_*` / `sk_sandbox_*` | Backend only | Creates sessions, authenticates API calls |
|
|
27
|
+
|
|
28
|
+
> **Never expose your secret key in client-side code.**
|
|
29
|
+
|
|
30
|
+
## React Component (recommended)
|
|
31
|
+
|
|
32
|
+
### Option A: SDK handles session creation
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
36
|
+
|
|
37
|
+
<FlonkKYCWidget
|
|
38
|
+
publishableKey="pk_live_..."
|
|
39
|
+
serverUrl="/api/kyc/create-session"
|
|
40
|
+
clientMetadata={{ email: 'user@example.com', userId: 'user_123' }}
|
|
41
|
+
lang="de"
|
|
42
|
+
onSuccess={(result) => console.log('Verified:', result)}
|
|
43
|
+
onError={(error) => console.error(error)}
|
|
44
|
+
onCancel={() => console.log('Cancelled')}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
// With authenticated backend
|
|
48
|
+
<FlonkKYCWidget
|
|
49
|
+
publishableKey="pk_live_..."
|
|
50
|
+
serverUrl="/api/kyc/create-session"
|
|
51
|
+
requestHeaders={{ Authorization: `Bearer ${token}` }}
|
|
52
|
+
...
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Option B: You control session creation
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { FlonkKYCWidget } from '@flonkid/kyc';
|
|
60
|
+
|
|
61
|
+
// 1. Create session on your backend first
|
|
62
|
+
const { sessionId, embedToken } = await fetch('/api/kyc/create-session', {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
body: JSON.stringify({ email: user.email }),
|
|
65
|
+
}).then(r => r.json());
|
|
66
|
+
|
|
67
|
+
// 2. Pass credentials to widget
|
|
68
|
+
<FlonkKYCWidget
|
|
69
|
+
publishableKey="pk_live_..." // optional — instant branded loader (see note)
|
|
70
|
+
sessionId={sessionId}
|
|
71
|
+
embedToken={embedToken}
|
|
72
|
+
lang="de"
|
|
73
|
+
onSuccess={(result) => console.log('Verified:', result)}
|
|
74
|
+
onError={(error) => console.error(error)}
|
|
75
|
+
onCancel={() => console.log('Cancelled')}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> `publishableKey` enables the instant branded loader in **both** flows. With it,
|
|
80
|
+
> the brand color is resolved straight from the key (in parallel with session
|
|
81
|
+
> setup) and painted on the first frame; without it, branding is resolved from
|
|
82
|
+
> the session and the loader shows the default color until that request returns.
|
|
83
|
+
|
|
84
|
+
### Props
|
|
85
|
+
|
|
86
|
+
| Prop | Type | Description |
|
|
87
|
+
|------|------|-------------|
|
|
88
|
+
| `publishableKey` | `string` | Your `pk_live_*` key — enables instant branded loader |
|
|
89
|
+
| `serverUrl` | `string` | Your backend endpoint — SDK auto-creates session |
|
|
90
|
+
| `sessionId` | `string` | Pre-created session ID (Option B) |
|
|
91
|
+
| `embedToken` | `string` | JWT token from your backend (Option B) |
|
|
92
|
+
| `requestHeaders` | `Record<string, string>` | Extra headers for serverUrl (e.g. JWT auth) |
|
|
93
|
+
| `clientMetadata` | `Record<string, unknown>` | Custom data passed to session |
|
|
94
|
+
| `lang` | `'en' \| 'de' \| 'uk'` | Widget language |
|
|
95
|
+
| `onSuccess` | `(result) => void` | Verification completed |
|
|
96
|
+
| `onError` | `(error) => void` | Error occurred |
|
|
97
|
+
| `onCancel` | `() => void` | User closed widget |
|
|
98
|
+
| `onReady` | `() => void` | Widget loaded |
|
|
99
|
+
| `autoOpen` | `boolean` | Open on mount (default: `true`) |
|
|
100
|
+
|
|
101
|
+
## Imperative API (non-React)
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { FlonkKYC } from '@flonkid/kyc';
|
|
105
|
+
|
|
106
|
+
const kyc = new FlonkKYC();
|
|
107
|
+
|
|
108
|
+
const widget = await kyc.init({
|
|
109
|
+
publishableKey: 'pk_live_...',
|
|
110
|
+
serverUrl: '/api/kyc/create-session',
|
|
111
|
+
clientMetadata: { email: 'user@example.com' },
|
|
112
|
+
lang: 'de',
|
|
113
|
+
onSuccess: (result) => console.log('Verified:', result),
|
|
114
|
+
onError: (error) => console.error(error),
|
|
115
|
+
onCancel: () => console.log('Cancelled'),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Cleanup
|
|
119
|
+
widget.destroy();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Server — Node.js
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { FlonkKYCServer } from '@flonkid/kyc/server';
|
|
126
|
+
|
|
127
|
+
const flonk = new FlonkKYCServer({ secretKey: 'sk_live_...' });
|
|
128
|
+
|
|
129
|
+
// Create session
|
|
130
|
+
const session = await flonk.createSession({
|
|
131
|
+
clientMetadata: { email: 'user@example.com', userId: 'user_123' },
|
|
132
|
+
expiryMinutes: 30,
|
|
133
|
+
language: 'de',
|
|
134
|
+
});
|
|
135
|
+
// → { id, embedToken, status, expiresAt, widgetUrl, qrCodeUrl }
|
|
136
|
+
|
|
137
|
+
// Verify webhook
|
|
138
|
+
const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Webhook Events
|
|
142
|
+
|
|
143
|
+
| Event | Description |
|
|
144
|
+
|-------|-------------|
|
|
145
|
+
| `verification.completed` | AI verification finished |
|
|
146
|
+
| `verification.status_changed` | Admin changed status (approved/rejected) |
|
|
147
|
+
| `verification.updated` | Admin edited verification data |
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
|
|
151
|
+
|
|
152
|
+
switch (event.type) {
|
|
153
|
+
case 'verification.completed':
|
|
154
|
+
console.log('Extracted:', event.data.object.extracted_data);
|
|
155
|
+
break;
|
|
156
|
+
case 'verification.status_changed':
|
|
157
|
+
console.log('New status:', event.data.object.status);
|
|
158
|
+
break;
|
|
159
|
+
case 'verification.updated':
|
|
160
|
+
console.log('Updated by:', event.data.object.updated_by);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Links
|
|
166
|
+
|
|
167
|
+
- [Full Documentation](https://docs.flonk.id)
|
|
168
|
+
- [Integration Guide](https://docs.flonk.id/docs/integration-frontend-backend)
|
|
169
|
+
- [Webhook Guide](https://docs.flonk.id/docs/webhooks)
|
|
170
|
+
- [Dashboard](https://dashboard.flonk.id)
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
Proprietary. Copyright (c) 2026 Flonk. All rights reserved.
|
|
175
|
+
See [Terms of Service](https://flonk.id/terms) for usage terms.
|