@flonkid/kyc 1.6.0 → 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 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
- sessionId={sessionId}
70
- embedToken={embedToken}
71
- lang="de"
72
- onSuccess={(result) => console.log('Verified:', result)}
73
- onError={(error) => console.error(error)}
74
- onCancel={() => console.log('Cancelled')}
75
- />
76
- ```
77
-
78
- ### Props
79
-
80
- | Prop | Type | Description |
81
- |------|------|-------------|
82
- | `publishableKey` | `string` | Your `pk_live_*` key enables instant branded loader |
83
- | `serverUrl` | `string` | Your backend endpoint — SDK auto-creates session |
84
- | `sessionId` | `string` | Pre-created session ID (Option B) |
85
- | `embedToken` | `string` | JWT token from your backend (Option B) |
86
- | `requestHeaders` | `Record<string, string>` | Extra headers for serverUrl (e.g. JWT auth) |
87
- | `clientMetadata` | `Record<string, unknown>` | Custom data passed to session |
88
- | `lang` | `'en' \| 'de' \| 'uk'` | Widget language |
89
- | `onSuccess` | `(result) => void` | Verification completed |
90
- | `onError` | `(error) => void` | Error occurred |
91
- | `onCancel` | `() => void` | User closed widget |
92
- | `onReady` | `() => void` | Widget loaded |
93
- | `autoOpen` | `boolean` | Open on mount (default: `true`) |
94
-
95
- ## Imperative API (non-React)
96
-
97
- ```typescript
98
- import { FlonkKYC } from '@flonkid/kyc';
99
-
100
- const kyc = new FlonkKYC();
101
-
102
- const widget = await kyc.init({
103
- publishableKey: 'pk_live_...',
104
- serverUrl: '/api/kyc/create-session',
105
- clientMetadata: { email: 'user@example.com' },
106
- lang: 'de',
107
- onSuccess: (result) => console.log('Verified:', result),
108
- onError: (error) => console.error(error),
109
- onCancel: () => console.log('Cancelled'),
110
- });
111
-
112
- // Cleanup
113
- widget.destroy();
114
- ```
115
-
116
- ## Server — Node.js
117
-
118
- ```typescript
119
- import { FlonkKYCServer } from '@flonkid/kyc/server';
120
-
121
- const flonk = new FlonkKYCServer({ secretKey: 'sk_live_...' });
122
-
123
- // Create session
124
- const session = await flonk.createSession({
125
- clientMetadata: { email: 'user@example.com', userId: 'user_123' },
126
- expiryMinutes: 30,
127
- language: 'de',
128
- });
129
- // { id, embedToken, status, expiresAt, widgetUrl, qrCodeUrl }
130
-
131
- // Verify webhook
132
- const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
133
- ```
134
-
135
- ## Webhook Events
136
-
137
- | Event | Description |
138
- |-------|-------------|
139
- | `verification.completed` | AI verification finished |
140
- | `verification.status_changed` | Admin changed status (approved/rejected) |
141
- | `verification.updated` | Admin edited verification data |
142
-
143
- ```typescript
144
- const event = flonk.webhooks.constructEvent(rawBody, signature, secret);
145
-
146
- switch (event.type) {
147
- case 'verification.completed':
148
- console.log('Extracted:', event.data.object.extracted_data);
149
- break;
150
- case 'verification.status_changed':
151
- console.log('New status:', event.data.object.status);
152
- break;
153
- case 'verification.updated':
154
- console.log('Updated by:', event.data.object.updated_by);
155
- break;
156
- }
157
- ```
158
-
159
- ## Links
160
-
161
- - [Full Documentation](https://docs.flonk.id)
162
- - [Integration Guide](https://docs.flonk.id/docs/integration-frontend-backend)
163
- - [Webhook Guide](https://docs.flonk.id/docs/webhooks)
164
- - [Dashboard](https://dashboard.flonk.id)
165
-
166
- ## License
167
-
168
- Proprietary. Copyright (c) 2026 Flonk. All rights reserved.
169
- See [Terms of Service](https://flonk.id/terms) for usage terms.
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.