@kyciris/core 0.1.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 +224 -0
- package/dist/index.d.mts +197 -0
- package/dist/index.d.ts +197 -0
- package/dist/index.js +251 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +243 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# @kyciris/core
|
|
2
|
+
|
|
3
|
+
Core SDK package with UI-agnostic KYC (Know Your Customer) functions. Use this package if you want to build your own UI while leveraging Paytesy's verification services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @kyciris/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialization
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createKYCClient } from '@kyciris/core';
|
|
17
|
+
|
|
18
|
+
const kyc = createKYCClient({
|
|
19
|
+
apiKey: 'your-api-key',
|
|
20
|
+
baseUrl: 'http://localhost:3000', // Your KYC API base URL
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Creating a Verification Token
|
|
25
|
+
|
|
26
|
+
Before starting verification, create a token for secure API access:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const { token, expiresIn } = await kyc.createVerificationToken(
|
|
30
|
+
'user-123', // externalId
|
|
31
|
+
'3' // expiry in hours (optional, default: 3)
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Starting a Verification
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const session = await kyc.startVerification({
|
|
39
|
+
documentType: 'IDENTITY_CARD', // or 'DRIVING_LICENSE'
|
|
40
|
+
country: 'MZ', // Country code: MZ, AO, PT, etc.
|
|
41
|
+
identityId: 'optional-existing-identity-id', // optional
|
|
42
|
+
externalId: 'optional-external-ref', // optional
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(session.verificationId);
|
|
46
|
+
console.log(session.status); // 'PENDING'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Uploading Documents
|
|
50
|
+
|
|
51
|
+
After starting verification, upload front and back of the document:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// Upload front of document
|
|
55
|
+
const frontResult = await kyc.uploadDocument({
|
|
56
|
+
verificationId: session.verificationId,
|
|
57
|
+
type: 'front',
|
|
58
|
+
imageData: 'base64-encoded-image-data',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Upload back of document
|
|
62
|
+
const backResult = await kyc.uploadDocument({
|
|
63
|
+
verificationId: session.verificationId,
|
|
64
|
+
type: 'back',
|
|
65
|
+
imageData: 'base64-encoded-image-data',
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Uploading Selfie
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const selfieResult = await kyc.uploadSelfie({
|
|
73
|
+
verificationId: session.verificationId,
|
|
74
|
+
imageData: 'base64-encoded-selfie-image',
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Checking Status
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Get current status
|
|
82
|
+
const status = await kyc.getStatus(session.verificationId);
|
|
83
|
+
console.log(status.status); // 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED'
|
|
84
|
+
console.log(status.ocrData); // Extracted document data
|
|
85
|
+
console.log(status.faceMatchScore); // Face match similarity (0-1)
|
|
86
|
+
|
|
87
|
+
// Poll until completion
|
|
88
|
+
const finalStatus = await kyc.pollStatus(
|
|
89
|
+
session.verificationId,
|
|
90
|
+
3000, // poll interval in ms (optional, default: 3000)
|
|
91
|
+
120000 // timeout in ms (optional, default: 120000)
|
|
92
|
+
);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Listening to Events
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Subscribe to status changes
|
|
99
|
+
const unsubscribe = kyc.onEvent((event) => {
|
|
100
|
+
if (event.type === 'statusChanged') {
|
|
101
|
+
console.log('Status changed to:', event.status);
|
|
102
|
+
} else if (event.type === 'error') {
|
|
103
|
+
console.log('Error:', event.error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Unsubscribe when done
|
|
108
|
+
unsubscribe();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## API Reference
|
|
112
|
+
|
|
113
|
+
### Interfaces
|
|
114
|
+
|
|
115
|
+
#### KYCCredentials
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
{
|
|
119
|
+
apiKey: string; // Your API key for authentication
|
|
120
|
+
baseUrl: string; // Base URL of your KYC API
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### StartVerificationParams
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
{
|
|
128
|
+
documentType: 'IDENTITY_CARD' | 'DRIVING_LICENSE';
|
|
129
|
+
country: string; // Country code (e.g., 'MZ', 'AO', 'PT')
|
|
130
|
+
identityId?: string; // Optional existing identity ID
|
|
131
|
+
externalId?: string; // Optional external reference
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### VerificationStatus
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
{
|
|
139
|
+
verificationId: string;
|
|
140
|
+
status: 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED';
|
|
141
|
+
faceMatchScore?: number; // Similarity score 0-1
|
|
142
|
+
ocrData?: {
|
|
143
|
+
fullName?: string;
|
|
144
|
+
idNumber?: string;
|
|
145
|
+
birthDate?: string;
|
|
146
|
+
expiryDate?: string;
|
|
147
|
+
// ... additional country-specific fields
|
|
148
|
+
};
|
|
149
|
+
createdAt: string;
|
|
150
|
+
updatedAt: string;
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Supported Countries
|
|
155
|
+
|
|
156
|
+
- **MZ** (Mozambique)
|
|
157
|
+
- **AO** (Angola)
|
|
158
|
+
- **PT** (Portugal)
|
|
159
|
+
|
|
160
|
+
## Error Handling
|
|
161
|
+
|
|
162
|
+
All methods throw `KYCSdkError` with the following properties:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
try {
|
|
166
|
+
await kyc.startVerification({ ... });
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof KYCSdkError) {
|
|
169
|
+
console.log(error.code); // Error code
|
|
170
|
+
console.log(error.statusCode); // HTTP status code
|
|
171
|
+
console.log(error.message); // Human-readable message
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Example
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { createKYCClient } from '@kyciris/core';
|
|
180
|
+
|
|
181
|
+
async function runKYC() {
|
|
182
|
+
const kyc = createKYCClient({
|
|
183
|
+
apiKey: process.env.KYC_API_KEY,
|
|
184
|
+
baseUrl: 'http://localhost:3000',
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Start verification
|
|
188
|
+
const session = await kyc.startVerification({
|
|
189
|
+
documentType: 'IDENTITY_CARD',
|
|
190
|
+
country: 'MZ',
|
|
191
|
+
externalId: 'user-12345',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Listen for events
|
|
195
|
+
kyc.onEvent((event) => {
|
|
196
|
+
console.log('KYC Event:', event);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Upload documents (you would get imageData from your UI)
|
|
200
|
+
await kyc.uploadDocument({
|
|
201
|
+
verificationId: session.verificationId,
|
|
202
|
+
type: 'front',
|
|
203
|
+
imageData: 'base64-encoded-image...',
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await kyc.uploadDocument({
|
|
207
|
+
verificationId: session.verificationId,
|
|
208
|
+
type: 'back',
|
|
209
|
+
imageData: 'base64-encoded-image...',
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Upload selfie
|
|
213
|
+
await kyc.uploadSelfie({
|
|
214
|
+
verificationId: session.verificationId,
|
|
215
|
+
imageData: 'base64-encoded-selfie...',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Wait for completion
|
|
219
|
+
const result = await kyc.pollStatus(session.verificationId);
|
|
220
|
+
console.log('Verification result:', result.status);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
runKYC();
|
|
224
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials required to initialize the KYC SDK
|
|
3
|
+
*/
|
|
4
|
+
interface KYCCredentials {
|
|
5
|
+
/** API key for authentication */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Base URL of the KYC API */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters required to start a verification session
|
|
12
|
+
*/
|
|
13
|
+
interface StartVerificationParams {
|
|
14
|
+
/** Type of document to verify (e.g., IDENTITY_CARD, DRIVING_LICENSE) */
|
|
15
|
+
documentType: 'IDENTITY_CARD' | 'DRIVING_LICENSE';
|
|
16
|
+
/** Country code (e.g., MZ, AO, PT) */
|
|
17
|
+
country: string;
|
|
18
|
+
/** Optional existing identity ID to link verification to */
|
|
19
|
+
identityId?: string;
|
|
20
|
+
/** Optional external reference ID */
|
|
21
|
+
externalId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Response from starting a verification session
|
|
25
|
+
*/
|
|
26
|
+
interface VerificationSession {
|
|
27
|
+
/** Unique verification ID */
|
|
28
|
+
verificationId: string;
|
|
29
|
+
/** Linked identity ID (if exists) */
|
|
30
|
+
identityId?: string;
|
|
31
|
+
/** Current verification status */
|
|
32
|
+
status: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parameters for uploading a selfie image
|
|
36
|
+
*/
|
|
37
|
+
interface UploadSelfieParams {
|
|
38
|
+
/** Verification ID to attach the selfie to */
|
|
39
|
+
verificationId: string;
|
|
40
|
+
/** Base64 encoded image data, data URI, or file:// URI (React Native) */
|
|
41
|
+
imageData: string;
|
|
42
|
+
/** MIME type of the image (default: image/jpeg) */
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parameters for uploading a document image
|
|
47
|
+
*/
|
|
48
|
+
interface UploadDocumentParams {
|
|
49
|
+
/** Verification ID to attach the document to */
|
|
50
|
+
verificationId: string;
|
|
51
|
+
/** Type of document (front or back) */
|
|
52
|
+
type: 'front' | 'back';
|
|
53
|
+
/** Base64 encoded image data, data URI, or file:// URI (React Native) */
|
|
54
|
+
imageData: string;
|
|
55
|
+
/** MIME type of the image (default: image/jpeg) */
|
|
56
|
+
mimeType?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Result of an upload operation */
|
|
59
|
+
interface UploadResult {
|
|
60
|
+
/** Response message */
|
|
61
|
+
message: string;
|
|
62
|
+
/** Current status after upload */
|
|
63
|
+
status: string;
|
|
64
|
+
}
|
|
65
|
+
/** Current status of a verification session */
|
|
66
|
+
interface VerificationStatus {
|
|
67
|
+
/** Verification ID */
|
|
68
|
+
verificationId: string;
|
|
69
|
+
/** Current status: PENDING, PROCESSING, APPROVED, or REJECTED */
|
|
70
|
+
status: 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED';
|
|
71
|
+
/** Face match similarity score (0-1) */
|
|
72
|
+
faceMatchScore?: number;
|
|
73
|
+
/** OCR extracted data from document */
|
|
74
|
+
ocrData?: {
|
|
75
|
+
/** Full name extracted from document */
|
|
76
|
+
fullName?: string;
|
|
77
|
+
/** ID number extracted from document */
|
|
78
|
+
idNumber?: string;
|
|
79
|
+
/** Birth date extracted from document */
|
|
80
|
+
birthDate?: string;
|
|
81
|
+
/** Expiry date extracted from document */
|
|
82
|
+
expiryDate?: string;
|
|
83
|
+
/** Additional extracted fields */
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
};
|
|
86
|
+
/** When the verification was created */
|
|
87
|
+
createdAt: string;
|
|
88
|
+
/** When the verification was last updated */
|
|
89
|
+
updatedAt: string;
|
|
90
|
+
}
|
|
91
|
+
/** Event emitted when KYC status changes */
|
|
92
|
+
interface KYCStatusEvent {
|
|
93
|
+
/** Type of event: statusChanged or error */
|
|
94
|
+
type: 'statusChanged' | 'error';
|
|
95
|
+
/** New status (for statusChanged events) */
|
|
96
|
+
status?: string;
|
|
97
|
+
/** Error message (for error events) */
|
|
98
|
+
error?: string;
|
|
99
|
+
}
|
|
100
|
+
/** Callback function for handling KYC status events */
|
|
101
|
+
type KYCEventCallback = (event: KYCStatusEvent) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Custom error class for KYC SDK errors
|
|
104
|
+
*/
|
|
105
|
+
declare class KYCSdkError extends Error {
|
|
106
|
+
/** Error code for programmatic error handling */
|
|
107
|
+
code: string;
|
|
108
|
+
/** HTTP status code if available */
|
|
109
|
+
statusCode?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new KYC SDK error
|
|
112
|
+
* @param message Human-readable error message
|
|
113
|
+
* @param code Error code for handling
|
|
114
|
+
* @param statusCode Optional HTTP status code
|
|
115
|
+
*/
|
|
116
|
+
constructor(message: string, code: string, statusCode?: number);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Core KYC SDK client for interacting with the verification API
|
|
120
|
+
*/
|
|
121
|
+
declare class KYCCore {
|
|
122
|
+
private client;
|
|
123
|
+
private credentials;
|
|
124
|
+
private eventCallbacks;
|
|
125
|
+
/**
|
|
126
|
+
* Creates a new KYC Core instance
|
|
127
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
128
|
+
*/
|
|
129
|
+
constructor(credentials: KYCCredentials);
|
|
130
|
+
/**
|
|
131
|
+
* Registers a callback for KYC status events
|
|
132
|
+
* @param callback Function to call when status changes
|
|
133
|
+
* @returns Unsubscribe function to remove the callback
|
|
134
|
+
*/
|
|
135
|
+
onEvent(callback: KYCEventCallback): () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Emits a status event to all registered callbacks
|
|
138
|
+
* @param event The event to emit
|
|
139
|
+
*/
|
|
140
|
+
private emitEvent;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a verification token for secure API access
|
|
143
|
+
* @param externalId External reference ID
|
|
144
|
+
* @param expiry Token expiry in hours (default: 3)
|
|
145
|
+
* @returns Object containing the token and its expiration time
|
|
146
|
+
*/
|
|
147
|
+
createVerificationToken(externalId: string, expiry?: string): Promise<{
|
|
148
|
+
token: string;
|
|
149
|
+
expiresIn: string;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Starts a new verification session
|
|
153
|
+
* @param params Parameters including documentType, country, identityId, and externalId
|
|
154
|
+
* @returns Verification session with verificationId and status
|
|
155
|
+
*/
|
|
156
|
+
startVerification(params: StartVerificationParams): Promise<VerificationSession>;
|
|
157
|
+
/**
|
|
158
|
+
* Uploads a selfie image for face verification
|
|
159
|
+
* @param params Parameters including verificationId, imageData, and optional mimeType
|
|
160
|
+
* @returns Upload result with status
|
|
161
|
+
*/
|
|
162
|
+
uploadSelfie(params: UploadSelfieParams): Promise<UploadResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Uploads a document image (front or back)
|
|
165
|
+
* @param params Parameters including verificationId, type, imageData, and optional mimeType
|
|
166
|
+
* @returns Upload result with status
|
|
167
|
+
*/
|
|
168
|
+
uploadDocument(params: UploadDocumentParams): Promise<UploadResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the current status of a verification session
|
|
171
|
+
* @param verificationId The verification ID to check
|
|
172
|
+
* @returns Current verification status including OCR data and face match score
|
|
173
|
+
*/
|
|
174
|
+
getStatus(verificationId: string): Promise<VerificationStatus>;
|
|
175
|
+
/**
|
|
176
|
+
* Polls for verification status until completion or timeout
|
|
177
|
+
* @param verificationId The verification ID to check
|
|
178
|
+
* @param interval Polling interval in milliseconds (default: 3000)
|
|
179
|
+
* @param timeout Maximum time to wait in milliseconds (default: 120000)
|
|
180
|
+
* @returns Final verification status when approved or rejected
|
|
181
|
+
*/
|
|
182
|
+
pollStatus(verificationId: string, interval?: number, timeout?: number): Promise<VerificationStatus>;
|
|
183
|
+
/**
|
|
184
|
+
* Static factory method to create a KYC client instance
|
|
185
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
186
|
+
* @returns Configured KYCCore instance
|
|
187
|
+
*/
|
|
188
|
+
static createClient(credentials: KYCCredentials): KYCCore;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Factory function to create a KYC client instance
|
|
192
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
193
|
+
* @returns Configured KYCCore instance
|
|
194
|
+
*/
|
|
195
|
+
declare function createKYCClient(credentials: KYCCredentials): KYCCore;
|
|
196
|
+
|
|
197
|
+
export { KYCCore, type KYCCredentials, type KYCEventCallback, KYCSdkError, type KYCStatusEvent, type StartVerificationParams, type UploadDocumentParams, type UploadResult, type UploadSelfieParams, type VerificationSession, type VerificationStatus, createKYCClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials required to initialize the KYC SDK
|
|
3
|
+
*/
|
|
4
|
+
interface KYCCredentials {
|
|
5
|
+
/** API key for authentication */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Base URL of the KYC API */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters required to start a verification session
|
|
12
|
+
*/
|
|
13
|
+
interface StartVerificationParams {
|
|
14
|
+
/** Type of document to verify (e.g., IDENTITY_CARD, DRIVING_LICENSE) */
|
|
15
|
+
documentType: 'IDENTITY_CARD' | 'DRIVING_LICENSE';
|
|
16
|
+
/** Country code (e.g., MZ, AO, PT) */
|
|
17
|
+
country: string;
|
|
18
|
+
/** Optional existing identity ID to link verification to */
|
|
19
|
+
identityId?: string;
|
|
20
|
+
/** Optional external reference ID */
|
|
21
|
+
externalId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Response from starting a verification session
|
|
25
|
+
*/
|
|
26
|
+
interface VerificationSession {
|
|
27
|
+
/** Unique verification ID */
|
|
28
|
+
verificationId: string;
|
|
29
|
+
/** Linked identity ID (if exists) */
|
|
30
|
+
identityId?: string;
|
|
31
|
+
/** Current verification status */
|
|
32
|
+
status: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parameters for uploading a selfie image
|
|
36
|
+
*/
|
|
37
|
+
interface UploadSelfieParams {
|
|
38
|
+
/** Verification ID to attach the selfie to */
|
|
39
|
+
verificationId: string;
|
|
40
|
+
/** Base64 encoded image data, data URI, or file:// URI (React Native) */
|
|
41
|
+
imageData: string;
|
|
42
|
+
/** MIME type of the image (default: image/jpeg) */
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parameters for uploading a document image
|
|
47
|
+
*/
|
|
48
|
+
interface UploadDocumentParams {
|
|
49
|
+
/** Verification ID to attach the document to */
|
|
50
|
+
verificationId: string;
|
|
51
|
+
/** Type of document (front or back) */
|
|
52
|
+
type: 'front' | 'back';
|
|
53
|
+
/** Base64 encoded image data, data URI, or file:// URI (React Native) */
|
|
54
|
+
imageData: string;
|
|
55
|
+
/** MIME type of the image (default: image/jpeg) */
|
|
56
|
+
mimeType?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Result of an upload operation */
|
|
59
|
+
interface UploadResult {
|
|
60
|
+
/** Response message */
|
|
61
|
+
message: string;
|
|
62
|
+
/** Current status after upload */
|
|
63
|
+
status: string;
|
|
64
|
+
}
|
|
65
|
+
/** Current status of a verification session */
|
|
66
|
+
interface VerificationStatus {
|
|
67
|
+
/** Verification ID */
|
|
68
|
+
verificationId: string;
|
|
69
|
+
/** Current status: PENDING, PROCESSING, APPROVED, or REJECTED */
|
|
70
|
+
status: 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED';
|
|
71
|
+
/** Face match similarity score (0-1) */
|
|
72
|
+
faceMatchScore?: number;
|
|
73
|
+
/** OCR extracted data from document */
|
|
74
|
+
ocrData?: {
|
|
75
|
+
/** Full name extracted from document */
|
|
76
|
+
fullName?: string;
|
|
77
|
+
/** ID number extracted from document */
|
|
78
|
+
idNumber?: string;
|
|
79
|
+
/** Birth date extracted from document */
|
|
80
|
+
birthDate?: string;
|
|
81
|
+
/** Expiry date extracted from document */
|
|
82
|
+
expiryDate?: string;
|
|
83
|
+
/** Additional extracted fields */
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
};
|
|
86
|
+
/** When the verification was created */
|
|
87
|
+
createdAt: string;
|
|
88
|
+
/** When the verification was last updated */
|
|
89
|
+
updatedAt: string;
|
|
90
|
+
}
|
|
91
|
+
/** Event emitted when KYC status changes */
|
|
92
|
+
interface KYCStatusEvent {
|
|
93
|
+
/** Type of event: statusChanged or error */
|
|
94
|
+
type: 'statusChanged' | 'error';
|
|
95
|
+
/** New status (for statusChanged events) */
|
|
96
|
+
status?: string;
|
|
97
|
+
/** Error message (for error events) */
|
|
98
|
+
error?: string;
|
|
99
|
+
}
|
|
100
|
+
/** Callback function for handling KYC status events */
|
|
101
|
+
type KYCEventCallback = (event: KYCStatusEvent) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Custom error class for KYC SDK errors
|
|
104
|
+
*/
|
|
105
|
+
declare class KYCSdkError extends Error {
|
|
106
|
+
/** Error code for programmatic error handling */
|
|
107
|
+
code: string;
|
|
108
|
+
/** HTTP status code if available */
|
|
109
|
+
statusCode?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new KYC SDK error
|
|
112
|
+
* @param message Human-readable error message
|
|
113
|
+
* @param code Error code for handling
|
|
114
|
+
* @param statusCode Optional HTTP status code
|
|
115
|
+
*/
|
|
116
|
+
constructor(message: string, code: string, statusCode?: number);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Core KYC SDK client for interacting with the verification API
|
|
120
|
+
*/
|
|
121
|
+
declare class KYCCore {
|
|
122
|
+
private client;
|
|
123
|
+
private credentials;
|
|
124
|
+
private eventCallbacks;
|
|
125
|
+
/**
|
|
126
|
+
* Creates a new KYC Core instance
|
|
127
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
128
|
+
*/
|
|
129
|
+
constructor(credentials: KYCCredentials);
|
|
130
|
+
/**
|
|
131
|
+
* Registers a callback for KYC status events
|
|
132
|
+
* @param callback Function to call when status changes
|
|
133
|
+
* @returns Unsubscribe function to remove the callback
|
|
134
|
+
*/
|
|
135
|
+
onEvent(callback: KYCEventCallback): () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Emits a status event to all registered callbacks
|
|
138
|
+
* @param event The event to emit
|
|
139
|
+
*/
|
|
140
|
+
private emitEvent;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a verification token for secure API access
|
|
143
|
+
* @param externalId External reference ID
|
|
144
|
+
* @param expiry Token expiry in hours (default: 3)
|
|
145
|
+
* @returns Object containing the token and its expiration time
|
|
146
|
+
*/
|
|
147
|
+
createVerificationToken(externalId: string, expiry?: string): Promise<{
|
|
148
|
+
token: string;
|
|
149
|
+
expiresIn: string;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Starts a new verification session
|
|
153
|
+
* @param params Parameters including documentType, country, identityId, and externalId
|
|
154
|
+
* @returns Verification session with verificationId and status
|
|
155
|
+
*/
|
|
156
|
+
startVerification(params: StartVerificationParams): Promise<VerificationSession>;
|
|
157
|
+
/**
|
|
158
|
+
* Uploads a selfie image for face verification
|
|
159
|
+
* @param params Parameters including verificationId, imageData, and optional mimeType
|
|
160
|
+
* @returns Upload result with status
|
|
161
|
+
*/
|
|
162
|
+
uploadSelfie(params: UploadSelfieParams): Promise<UploadResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Uploads a document image (front or back)
|
|
165
|
+
* @param params Parameters including verificationId, type, imageData, and optional mimeType
|
|
166
|
+
* @returns Upload result with status
|
|
167
|
+
*/
|
|
168
|
+
uploadDocument(params: UploadDocumentParams): Promise<UploadResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the current status of a verification session
|
|
171
|
+
* @param verificationId The verification ID to check
|
|
172
|
+
* @returns Current verification status including OCR data and face match score
|
|
173
|
+
*/
|
|
174
|
+
getStatus(verificationId: string): Promise<VerificationStatus>;
|
|
175
|
+
/**
|
|
176
|
+
* Polls for verification status until completion or timeout
|
|
177
|
+
* @param verificationId The verification ID to check
|
|
178
|
+
* @param interval Polling interval in milliseconds (default: 3000)
|
|
179
|
+
* @param timeout Maximum time to wait in milliseconds (default: 120000)
|
|
180
|
+
* @returns Final verification status when approved or rejected
|
|
181
|
+
*/
|
|
182
|
+
pollStatus(verificationId: string, interval?: number, timeout?: number): Promise<VerificationStatus>;
|
|
183
|
+
/**
|
|
184
|
+
* Static factory method to create a KYC client instance
|
|
185
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
186
|
+
* @returns Configured KYCCore instance
|
|
187
|
+
*/
|
|
188
|
+
static createClient(credentials: KYCCredentials): KYCCore;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Factory function to create a KYC client instance
|
|
192
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
193
|
+
* @returns Configured KYCCore instance
|
|
194
|
+
*/
|
|
195
|
+
declare function createKYCClient(credentials: KYCCredentials): KYCCore;
|
|
196
|
+
|
|
197
|
+
export { KYCCore, type KYCCredentials, type KYCEventCallback, KYCSdkError, type KYCStatusEvent, type StartVerificationParams, type UploadDocumentParams, type UploadResult, type UploadSelfieParams, type VerificationSession, type VerificationStatus, createKYCClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
var KYCSdkError = class extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new KYC SDK error
|
|
13
|
+
* @param message Human-readable error message
|
|
14
|
+
* @param code Error code for handling
|
|
15
|
+
* @param statusCode Optional HTTP status code
|
|
16
|
+
*/
|
|
17
|
+
constructor(message, code, statusCode) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "KYCSdkError";
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.statusCode = statusCode;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var KYCCore = class _KYCCore {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new KYC Core instance
|
|
27
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
28
|
+
*/
|
|
29
|
+
constructor(credentials) {
|
|
30
|
+
this.eventCallbacks = [];
|
|
31
|
+
this.credentials = credentials;
|
|
32
|
+
this.client = axios__default.default.create({
|
|
33
|
+
baseURL: credentials.baseUrl,
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
Accept: "application/json"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.client.interceptors.request.use((config) => {
|
|
40
|
+
config.headers["x-api-key"] = this.credentials.apiKey;
|
|
41
|
+
return config;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Registers a callback for KYC status events
|
|
46
|
+
* @param callback Function to call when status changes
|
|
47
|
+
* @returns Unsubscribe function to remove the callback
|
|
48
|
+
*/
|
|
49
|
+
onEvent(callback) {
|
|
50
|
+
this.eventCallbacks.push(callback);
|
|
51
|
+
return () => {
|
|
52
|
+
this.eventCallbacks = this.eventCallbacks.filter((cb) => cb !== callback);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Emits a status event to all registered callbacks
|
|
57
|
+
* @param event The event to emit
|
|
58
|
+
*/
|
|
59
|
+
emitEvent(event) {
|
|
60
|
+
this.eventCallbacks.forEach((callback) => callback(event));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a verification token for secure API access
|
|
64
|
+
* @param externalId External reference ID
|
|
65
|
+
* @param expiry Token expiry in hours (default: 3)
|
|
66
|
+
* @returns Object containing the token and its expiration time
|
|
67
|
+
*/
|
|
68
|
+
async createVerificationToken(externalId, expiry = "3") {
|
|
69
|
+
try {
|
|
70
|
+
const response = await this.client.post("/verification/token", {
|
|
71
|
+
externalId,
|
|
72
|
+
expiry
|
|
73
|
+
});
|
|
74
|
+
return response.data;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
const message = error.response?.data?.message || error.message || "Failed to create verification token";
|
|
77
|
+
throw new KYCSdkError(message, "TOKEN_CREATE_FAILED", error.response?.status);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Starts a new verification session
|
|
82
|
+
* @param params Parameters including documentType, country, identityId, and externalId
|
|
83
|
+
* @returns Verification session with verificationId and status
|
|
84
|
+
*/
|
|
85
|
+
async startVerification(params) {
|
|
86
|
+
try {
|
|
87
|
+
const response = await this.client.post("/verification/start", params);
|
|
88
|
+
this.emitEvent({
|
|
89
|
+
type: "statusChanged",
|
|
90
|
+
status: "PENDING"
|
|
91
|
+
});
|
|
92
|
+
return response.data;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const message = error.response?.data?.message || error.message || "Failed to start verification";
|
|
95
|
+
throw new KYCSdkError(message, "VERIFICATION_START_FAILED", error.response?.status);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Uploads a selfie image for face verification
|
|
100
|
+
* @param params Parameters including verificationId, imageData, and optional mimeType
|
|
101
|
+
* @returns Upload result with status
|
|
102
|
+
*/
|
|
103
|
+
async uploadSelfie(params) {
|
|
104
|
+
try {
|
|
105
|
+
const formData = new FormData();
|
|
106
|
+
formData.append("verificationId", params.verificationId);
|
|
107
|
+
const mimeType = params.mimeType || "image/jpeg";
|
|
108
|
+
const imageData = params.imageData;
|
|
109
|
+
if (imageData.startsWith("file://")) {
|
|
110
|
+
formData.append("file", {
|
|
111
|
+
uri: imageData,
|
|
112
|
+
type: mimeType,
|
|
113
|
+
name: "selfie.jpg"
|
|
114
|
+
});
|
|
115
|
+
} else if (imageData.startsWith("data:")) {
|
|
116
|
+
formData.append("file", {
|
|
117
|
+
uri: imageData,
|
|
118
|
+
type: mimeType,
|
|
119
|
+
name: "selfie.jpg"
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
formData.append("file", {
|
|
123
|
+
uri: `data:${mimeType};base64,${imageData}`,
|
|
124
|
+
type: mimeType,
|
|
125
|
+
name: "selfie.jpg"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const response = await this.client.post("/verification/upload/selfie", formData, {
|
|
129
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
130
|
+
});
|
|
131
|
+
this.emitEvent({
|
|
132
|
+
type: "statusChanged",
|
|
133
|
+
status: "PROCESSING"
|
|
134
|
+
});
|
|
135
|
+
return response.data;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.log("Upload selfie error:", error.response?.data || error.message);
|
|
138
|
+
const message = error.response?.data?.message || error.message || "Failed to upload selfie";
|
|
139
|
+
throw new KYCSdkError(message, "SELFIE_UPLOAD_FAILED", error.response?.status);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Uploads a document image (front or back)
|
|
144
|
+
* @param params Parameters including verificationId, type, imageData, and optional mimeType
|
|
145
|
+
* @returns Upload result with status
|
|
146
|
+
*/
|
|
147
|
+
async uploadDocument(params) {
|
|
148
|
+
try {
|
|
149
|
+
const formData = new FormData();
|
|
150
|
+
formData.append("verificationId", params.verificationId);
|
|
151
|
+
formData.append("type", params.type);
|
|
152
|
+
const mimeType = params.mimeType || "image/jpeg";
|
|
153
|
+
const imageData = params.imageData;
|
|
154
|
+
if (imageData.startsWith("file://")) {
|
|
155
|
+
formData.append("file", {
|
|
156
|
+
uri: imageData,
|
|
157
|
+
type: mimeType,
|
|
158
|
+
name: `${params.type}.jpg`
|
|
159
|
+
});
|
|
160
|
+
} else if (imageData.startsWith("data:")) {
|
|
161
|
+
formData.append("file", {
|
|
162
|
+
uri: imageData,
|
|
163
|
+
type: mimeType,
|
|
164
|
+
name: `${params.type}.jpg`
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
formData.append("file", {
|
|
168
|
+
uri: `data:${mimeType};base64,${imageData}`,
|
|
169
|
+
type: mimeType,
|
|
170
|
+
name: `${params.type}.jpg`
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const response = await this.client.post("/verification/upload/document", formData, {
|
|
174
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
175
|
+
});
|
|
176
|
+
this.emitEvent({
|
|
177
|
+
type: "statusChanged",
|
|
178
|
+
status: "PROCESSING"
|
|
179
|
+
});
|
|
180
|
+
return response.data;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.log("Upload document error:", error.response?.data || error.message);
|
|
183
|
+
const message = error.response?.data?.message || error.message || "Failed to upload document";
|
|
184
|
+
throw new KYCSdkError(message, "DOCUMENT_UPLOAD_FAILED", error.response?.status);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Gets the current status of a verification session
|
|
189
|
+
* @param verificationId The verification ID to check
|
|
190
|
+
* @returns Current verification status including OCR data and face match score
|
|
191
|
+
*/
|
|
192
|
+
async getStatus(verificationId) {
|
|
193
|
+
try {
|
|
194
|
+
const response = await this.client.get(`/verification/status/${verificationId}`);
|
|
195
|
+
this.emitEvent({
|
|
196
|
+
type: "statusChanged",
|
|
197
|
+
status: response.data.status
|
|
198
|
+
});
|
|
199
|
+
return response.data;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
const message = error.response?.data?.message || error.message || "Failed to get verification status";
|
|
202
|
+
throw new KYCSdkError(message, "STATUS_CHECK_FAILED", error.response?.status);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Polls for verification status until completion or timeout
|
|
207
|
+
* @param verificationId The verification ID to check
|
|
208
|
+
* @param interval Polling interval in milliseconds (default: 3000)
|
|
209
|
+
* @param timeout Maximum time to wait in milliseconds (default: 120000)
|
|
210
|
+
* @returns Final verification status when approved or rejected
|
|
211
|
+
*/
|
|
212
|
+
async pollStatus(verificationId, interval = 3e3, timeout = 12e4) {
|
|
213
|
+
const startTime = Date.now();
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
const poll = async () => {
|
|
216
|
+
try {
|
|
217
|
+
const status = await this.getStatus(verificationId);
|
|
218
|
+
if (status.status === "APPROVED" || status.status === "REJECTED") {
|
|
219
|
+
resolve(status);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (Date.now() - startTime > timeout) {
|
|
223
|
+
reject(new KYCSdkError("Polling timeout", "POLLING_TIMEOUT"));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
setTimeout(poll, interval);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
reject(error);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
poll();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Static factory method to create a KYC client instance
|
|
236
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
237
|
+
* @returns Configured KYCCore instance
|
|
238
|
+
*/
|
|
239
|
+
static createClient(credentials) {
|
|
240
|
+
return new _KYCCore(credentials);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
function createKYCClient(credentials) {
|
|
244
|
+
return KYCCore.createClient(credentials);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
exports.KYCCore = KYCCore;
|
|
248
|
+
exports.KYCSdkError = KYCSdkError;
|
|
249
|
+
exports.createKYCClient = createKYCClient;
|
|
250
|
+
//# sourceMappingURL=index.js.map
|
|
251
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["axios"],"mappings":";;;;;;;;;AAmHO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYrC,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAc,UAAA,EAAqB;AAC9D,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACpB;AACF;AAKO,IAAM,OAAA,GAAN,MAAM,QAAA,CAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,EASnB,YAAY,WAAA,EAA6B;AANzC,IAAA,IAAA,CAAQ,iBAAqC,EAAC;AAO5C,IAAA,IAAA,CAAK,WAAA,GAAc,WAAA;AACnB,IAAA,IAAA,CAAK,MAAA,GAASA,uBAAM,MAAA,CAAO;AAAA,MACzB,SAAS,WAAA,CAAY,OAAA;AAAA,MACrB,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,MAAA,EAAQ;AAAA;AACV,KACD,CAAA;AAED,IAAA,IAAA,CAAK,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW;AAC/C,MAAA,MAAA,CAAO,OAAA,CAAQ,WAAW,CAAA,GAAI,IAAA,CAAK,WAAA,CAAY,MAAA;AAC/C,MAAA,OAAO,MAAA;AAAA,IACT,CAAC,CAAA;AAA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C,CAAA;AAC5D,YAAA;AAAA,UACF;AAEA,UAAA,UAAA,CAAW,MAAM,QAAQ,CAAA;AAAA,QAC3B,SAAS,KAAA,EAAO;AACd,UAAA,MAAA,CAAO,KAAK,CAAA;AAAA,QACd;AAAA,MACF,CAAA;AAEA,MAAA,IAAA,EAAK;AAAA,IACP,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,aAAa,WAAA,EAAsC;AACxD,IAAA,OAAO,IAAI,SAAQ,WAAW,CAAA;AAAA,EAChC;AACF;AAOO,SAAS,gBAAgB,WAAA,EAAsC;AACpE,EAAA,OAAO,OAAA,CAAQ,aAAa,WAAW,CAAA;AACzC","file":"index.js","sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n/**\n * Credentials required to initialize the KYC SDK\n */\nexport interface KYCCredentials {\n /** API key for authentication */\n apiKey: string;\n /** Base URL of the KYC API */\n baseUrl: string;\n}\n\n/**\n * Parameters required to start a verification session\n */\nexport interface StartVerificationParams {\n /** Type of document to verify (e.g., IDENTITY_CARD, DRIVING_LICENSE) */\n documentType: 'IDENTITY_CARD' | 'DRIVING_LICENSE';\n /** Country code (e.g., MZ, AO, PT) */\n country: string;\n /** Optional existing identity ID to link verification to */\n identityId?: string;\n /** Optional external reference ID */\n externalId?: string;\n}\n\n/**\n * Response from starting a verification session\n */\nexport interface VerificationSession {\n /** Unique verification ID */\n verificationId: string;\n /** Linked identity ID (if exists) */\n identityId?: string;\n /** Current verification status */\n status: string;\n}\n\n/**\n * Parameters for uploading a selfie image\n */\nexport interface UploadSelfieParams {\n /** Verification ID to attach the selfie to */\n verificationId: string;\n /** Base64 encoded image data, data URI, or file:// URI (React Native) */\n imageData: string;\n /** MIME type of the image (default: image/jpeg) */\n mimeType?: string;\n}\n\n/**\n * Parameters for uploading a document image\n */\nexport interface UploadDocumentParams {\n /** Verification ID to attach the document to */\n verificationId: string;\n /** Type of document (front or back) */\n type: 'front' | 'back';\n /** Base64 encoded image data, data URI, or file:// URI (React Native) */\n imageData: string;\n /** MIME type of the image (default: image/jpeg) */\n mimeType?: string;\n}\n\n/** Result of an upload operation */\nexport interface UploadResult {\n /** Response message */\n message: string;\n /** Current status after upload */\n status: string;\n}\n\n/** Current status of a verification session */\nexport interface VerificationStatus {\n /** Verification ID */\n verificationId: string;\n /** Current status: PENDING, PROCESSING, APPROVED, or REJECTED */\n status: 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED';\n /** Face match similarity score (0-1) */\n faceMatchScore?: number;\n /** OCR extracted data from document */\n ocrData?: {\n /** Full name extracted from document */\n fullName?: string;\n /** ID number extracted from document */\n idNumber?: string;\n /** Birth date extracted from document */\n birthDate?: string;\n /** Expiry date extracted from document */\n expiryDate?: string;\n /** Additional extracted fields */\n [key: string]: any;\n };\n /** When the verification was created */\n createdAt: string;\n /** When the verification was last updated */\n updatedAt: string;\n}\n\n/** Event emitted when KYC status changes */\nexport interface KYCStatusEvent {\n /** Type of event: statusChanged or error */\n type: 'statusChanged' | 'error';\n /** New status (for statusChanged events) */\n status?: string;\n /** Error message (for error events) */\n error?: string;\n}\n\n/** Callback function for handling KYC status events */\nexport type KYCEventCallback = (event: KYCStatusEvent) => void;\n\n/**\n * Custom error class for KYC SDK errors\n */\nexport class KYCSdkError extends Error {\n /** Error code for programmatic error handling */\n code: string;\n /** HTTP status code if available */\n statusCode?: number;\n\n /**\n * Creates a new KYC SDK error\n * @param message Human-readable error message\n * @param code Error code for handling\n * @param statusCode Optional HTTP status code\n */\n constructor(message: string, code: string, statusCode?: number) {\n super(message);\n this.name = 'KYCSdkError';\n this.code = code;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Core KYC SDK client for interacting with the verification API\n */\nexport class KYCCore {\n private client: AxiosInstance;\n private credentials: KYCCredentials;\n private eventCallbacks: KYCEventCallback[] = [];\n\n /**\n * Creates a new KYC Core instance\n * @param credentials API credentials (apiKey and baseUrl)\n */\n constructor(credentials: KYCCredentials) {\n this.credentials = credentials;\n this.client = axios.create({\n baseURL: credentials.baseUrl,\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n });\n\n this.client.interceptors.request.use((config) => {\n config.headers['x-api-key'] = this.credentials.apiKey;\n return config;\n });\n }\n\n /**\n * Registers a callback for KYC status events\n * @param callback Function to call when status changes\n * @returns Unsubscribe function to remove the callback\n */\n onEvent(callback: KYCEventCallback): () => void {\n this.eventCallbacks.push(callback);\n return () => {\n this.eventCallbacks = this.eventCallbacks.filter((cb) => cb !== callback);\n };\n }\n\n /**\n * Emits a status event to all registered callbacks\n * @param event The event to emit\n */\n private emitEvent(event: KYCStatusEvent): void {\n this.eventCallbacks.forEach((callback) => callback(event));\n }\n\n /**\n * Creates a verification token for secure API access\n * @param externalId External reference ID\n * @param expiry Token expiry in hours (default: 3)\n * @returns Object containing the token and its expiration time\n */\n async createVerificationToken(\n externalId: string,\n expiry: string = '3'\n ): Promise<{ token: string; expiresIn: string }> {\n try {\n const response = await this.client.post('/verification/token', {\n externalId,\n expiry,\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to create verification token';\n throw new KYCSdkError(message, 'TOKEN_CREATE_FAILED', error.response?.status);\n }\n }\n\n /**\n * Starts a new verification session\n * @param params Parameters including documentType, country, identityId, and externalId\n * @returns Verification session with verificationId and status\n */\n async startVerification(params: StartVerificationParams): Promise<VerificationSession> {\n try {\n const response = await this.client.post('/verification/start', params);\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PENDING',\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to start verification';\n throw new KYCSdkError(message, 'VERIFICATION_START_FAILED', error.response?.status);\n }\n }\n\n /**\n * Uploads a selfie image for face verification\n * @param params Parameters including verificationId, imageData, and optional mimeType\n * @returns Upload result with status\n */\n async uploadSelfie(params: UploadSelfieParams): Promise<UploadResult> {\n try {\n const formData = new FormData();\n formData.append('verificationId', params.verificationId);\n\n const mimeType = params.mimeType || 'image/jpeg';\n const imageData = params.imageData;\n\n if (imageData.startsWith('file://')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n } else if (imageData.startsWith('data:')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n } else {\n formData.append('file', {\n uri: `data:${mimeType};base64,${imageData}`,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n }\n\n const response = await this.client.post('/verification/upload/selfie', formData, {\n headers: { 'Content-Type': 'multipart/form-data' },\n });\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PROCESSING',\n });\n\n return response.data;\n } catch (error: any) {\n console.log('Upload selfie error:', error.response?.data || error.message);\n const message = error.response?.data?.message || error.message || 'Failed to upload selfie';\n throw new KYCSdkError(message, 'SELFIE_UPLOAD_FAILED', error.response?.status);\n }\n }\n\n /**\n * Uploads a document image (front or back)\n * @param params Parameters including verificationId, type, imageData, and optional mimeType\n * @returns Upload result with status\n */\n async uploadDocument(params: UploadDocumentParams): Promise<UploadResult> {\n try {\n const formData = new FormData();\n formData.append('verificationId', params.verificationId);\n formData.append('type', params.type);\n\n const mimeType = params.mimeType || 'image/jpeg';\n const imageData = params.imageData;\n\n if (imageData.startsWith('file://')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n } else if (imageData.startsWith('data:')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n } else {\n formData.append('file', {\n uri: `data:${mimeType};base64,${imageData}`,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n }\n\n const response = await this.client.post('/verification/upload/document', formData, {\n headers: { 'Content-Type': 'multipart/form-data' },\n });\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PROCESSING',\n });\n\n return response.data;\n } catch (error: any) {\n console.log('Upload document error:', error.response?.data || error.message);\n const message = error.response?.data?.message || error.message || 'Failed to upload document';\n throw new KYCSdkError(message, 'DOCUMENT_UPLOAD_FAILED', error.response?.status);\n }\n }\n\n /**\n * Gets the current status of a verification session\n * @param verificationId The verification ID to check\n * @returns Current verification status including OCR data and face match score\n */\n async getStatus(verificationId: string): Promise<VerificationStatus> {\n try {\n const response = await this.client.get(`/verification/status/${verificationId}`);\n\n this.emitEvent({\n type: 'statusChanged',\n status: response.data.status,\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to get verification status';\n throw new KYCSdkError(message, 'STATUS_CHECK_FAILED', error.response?.status);\n }\n }\n\n /**\n * Polls for verification status until completion or timeout\n * @param verificationId The verification ID to check\n * @param interval Polling interval in milliseconds (default: 3000)\n * @param timeout Maximum time to wait in milliseconds (default: 120000)\n * @returns Final verification status when approved or rejected\n */\n async pollStatus(\n verificationId: string,\n interval: number = 3000,\n timeout: number = 120000\n ): Promise<VerificationStatus> {\n const startTime = Date.now();\n\n return new Promise((resolve, reject) => {\n const poll = async () => {\n try {\n const status = await this.getStatus(verificationId);\n\n if (status.status === 'APPROVED' || status.status === 'REJECTED') {\n resolve(status);\n return;\n }\n\n if (Date.now() - startTime > timeout) {\n reject(new KYCSdkError('Polling timeout', 'POLLING_TIMEOUT'));\n return;\n }\n\n setTimeout(poll, interval);\n } catch (error) {\n reject(error);\n }\n };\n\n poll();\n });\n }\n\n /**\n * Static factory method to create a KYC client instance\n * @param credentials API credentials (apiKey and baseUrl)\n * @returns Configured KYCCore instance\n */\n static createClient(credentials: KYCCredentials): KYCCore {\n return new KYCCore(credentials);\n }\n}\n\n/**\n * Factory function to create a KYC client instance\n * @param credentials API credentials (apiKey and baseUrl)\n * @returns Configured KYCCore instance\n */\nexport function createKYCClient(credentials: KYCCredentials): KYCCore {\n return KYCCore.createClient(credentials);\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var KYCSdkError = class extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new KYC SDK error
|
|
7
|
+
* @param message Human-readable error message
|
|
8
|
+
* @param code Error code for handling
|
|
9
|
+
* @param statusCode Optional HTTP status code
|
|
10
|
+
*/
|
|
11
|
+
constructor(message, code, statusCode) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "KYCSdkError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.statusCode = statusCode;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var KYCCore = class _KYCCore {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new KYC Core instance
|
|
21
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
22
|
+
*/
|
|
23
|
+
constructor(credentials) {
|
|
24
|
+
this.eventCallbacks = [];
|
|
25
|
+
this.credentials = credentials;
|
|
26
|
+
this.client = axios.create({
|
|
27
|
+
baseURL: credentials.baseUrl,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
Accept: "application/json"
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.client.interceptors.request.use((config) => {
|
|
34
|
+
config.headers["x-api-key"] = this.credentials.apiKey;
|
|
35
|
+
return config;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Registers a callback for KYC status events
|
|
40
|
+
* @param callback Function to call when status changes
|
|
41
|
+
* @returns Unsubscribe function to remove the callback
|
|
42
|
+
*/
|
|
43
|
+
onEvent(callback) {
|
|
44
|
+
this.eventCallbacks.push(callback);
|
|
45
|
+
return () => {
|
|
46
|
+
this.eventCallbacks = this.eventCallbacks.filter((cb) => cb !== callback);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Emits a status event to all registered callbacks
|
|
51
|
+
* @param event The event to emit
|
|
52
|
+
*/
|
|
53
|
+
emitEvent(event) {
|
|
54
|
+
this.eventCallbacks.forEach((callback) => callback(event));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a verification token for secure API access
|
|
58
|
+
* @param externalId External reference ID
|
|
59
|
+
* @param expiry Token expiry in hours (default: 3)
|
|
60
|
+
* @returns Object containing the token and its expiration time
|
|
61
|
+
*/
|
|
62
|
+
async createVerificationToken(externalId, expiry = "3") {
|
|
63
|
+
try {
|
|
64
|
+
const response = await this.client.post("/verification/token", {
|
|
65
|
+
externalId,
|
|
66
|
+
expiry
|
|
67
|
+
});
|
|
68
|
+
return response.data;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const message = error.response?.data?.message || error.message || "Failed to create verification token";
|
|
71
|
+
throw new KYCSdkError(message, "TOKEN_CREATE_FAILED", error.response?.status);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Starts a new verification session
|
|
76
|
+
* @param params Parameters including documentType, country, identityId, and externalId
|
|
77
|
+
* @returns Verification session with verificationId and status
|
|
78
|
+
*/
|
|
79
|
+
async startVerification(params) {
|
|
80
|
+
try {
|
|
81
|
+
const response = await this.client.post("/verification/start", params);
|
|
82
|
+
this.emitEvent({
|
|
83
|
+
type: "statusChanged",
|
|
84
|
+
status: "PENDING"
|
|
85
|
+
});
|
|
86
|
+
return response.data;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const message = error.response?.data?.message || error.message || "Failed to start verification";
|
|
89
|
+
throw new KYCSdkError(message, "VERIFICATION_START_FAILED", error.response?.status);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Uploads a selfie image for face verification
|
|
94
|
+
* @param params Parameters including verificationId, imageData, and optional mimeType
|
|
95
|
+
* @returns Upload result with status
|
|
96
|
+
*/
|
|
97
|
+
async uploadSelfie(params) {
|
|
98
|
+
try {
|
|
99
|
+
const formData = new FormData();
|
|
100
|
+
formData.append("verificationId", params.verificationId);
|
|
101
|
+
const mimeType = params.mimeType || "image/jpeg";
|
|
102
|
+
const imageData = params.imageData;
|
|
103
|
+
if (imageData.startsWith("file://")) {
|
|
104
|
+
formData.append("file", {
|
|
105
|
+
uri: imageData,
|
|
106
|
+
type: mimeType,
|
|
107
|
+
name: "selfie.jpg"
|
|
108
|
+
});
|
|
109
|
+
} else if (imageData.startsWith("data:")) {
|
|
110
|
+
formData.append("file", {
|
|
111
|
+
uri: imageData,
|
|
112
|
+
type: mimeType,
|
|
113
|
+
name: "selfie.jpg"
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
formData.append("file", {
|
|
117
|
+
uri: `data:${mimeType};base64,${imageData}`,
|
|
118
|
+
type: mimeType,
|
|
119
|
+
name: "selfie.jpg"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const response = await this.client.post("/verification/upload/selfie", formData, {
|
|
123
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
124
|
+
});
|
|
125
|
+
this.emitEvent({
|
|
126
|
+
type: "statusChanged",
|
|
127
|
+
status: "PROCESSING"
|
|
128
|
+
});
|
|
129
|
+
return response.data;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.log("Upload selfie error:", error.response?.data || error.message);
|
|
132
|
+
const message = error.response?.data?.message || error.message || "Failed to upload selfie";
|
|
133
|
+
throw new KYCSdkError(message, "SELFIE_UPLOAD_FAILED", error.response?.status);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Uploads a document image (front or back)
|
|
138
|
+
* @param params Parameters including verificationId, type, imageData, and optional mimeType
|
|
139
|
+
* @returns Upload result with status
|
|
140
|
+
*/
|
|
141
|
+
async uploadDocument(params) {
|
|
142
|
+
try {
|
|
143
|
+
const formData = new FormData();
|
|
144
|
+
formData.append("verificationId", params.verificationId);
|
|
145
|
+
formData.append("type", params.type);
|
|
146
|
+
const mimeType = params.mimeType || "image/jpeg";
|
|
147
|
+
const imageData = params.imageData;
|
|
148
|
+
if (imageData.startsWith("file://")) {
|
|
149
|
+
formData.append("file", {
|
|
150
|
+
uri: imageData,
|
|
151
|
+
type: mimeType,
|
|
152
|
+
name: `${params.type}.jpg`
|
|
153
|
+
});
|
|
154
|
+
} else if (imageData.startsWith("data:")) {
|
|
155
|
+
formData.append("file", {
|
|
156
|
+
uri: imageData,
|
|
157
|
+
type: mimeType,
|
|
158
|
+
name: `${params.type}.jpg`
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
formData.append("file", {
|
|
162
|
+
uri: `data:${mimeType};base64,${imageData}`,
|
|
163
|
+
type: mimeType,
|
|
164
|
+
name: `${params.type}.jpg`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const response = await this.client.post("/verification/upload/document", formData, {
|
|
168
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
169
|
+
});
|
|
170
|
+
this.emitEvent({
|
|
171
|
+
type: "statusChanged",
|
|
172
|
+
status: "PROCESSING"
|
|
173
|
+
});
|
|
174
|
+
return response.data;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.log("Upload document error:", error.response?.data || error.message);
|
|
177
|
+
const message = error.response?.data?.message || error.message || "Failed to upload document";
|
|
178
|
+
throw new KYCSdkError(message, "DOCUMENT_UPLOAD_FAILED", error.response?.status);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Gets the current status of a verification session
|
|
183
|
+
* @param verificationId The verification ID to check
|
|
184
|
+
* @returns Current verification status including OCR data and face match score
|
|
185
|
+
*/
|
|
186
|
+
async getStatus(verificationId) {
|
|
187
|
+
try {
|
|
188
|
+
const response = await this.client.get(`/verification/status/${verificationId}`);
|
|
189
|
+
this.emitEvent({
|
|
190
|
+
type: "statusChanged",
|
|
191
|
+
status: response.data.status
|
|
192
|
+
});
|
|
193
|
+
return response.data;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const message = error.response?.data?.message || error.message || "Failed to get verification status";
|
|
196
|
+
throw new KYCSdkError(message, "STATUS_CHECK_FAILED", error.response?.status);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Polls for verification status until completion or timeout
|
|
201
|
+
* @param verificationId The verification ID to check
|
|
202
|
+
* @param interval Polling interval in milliseconds (default: 3000)
|
|
203
|
+
* @param timeout Maximum time to wait in milliseconds (default: 120000)
|
|
204
|
+
* @returns Final verification status when approved or rejected
|
|
205
|
+
*/
|
|
206
|
+
async pollStatus(verificationId, interval = 3e3, timeout = 12e4) {
|
|
207
|
+
const startTime = Date.now();
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
const poll = async () => {
|
|
210
|
+
try {
|
|
211
|
+
const status = await this.getStatus(verificationId);
|
|
212
|
+
if (status.status === "APPROVED" || status.status === "REJECTED") {
|
|
213
|
+
resolve(status);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (Date.now() - startTime > timeout) {
|
|
217
|
+
reject(new KYCSdkError("Polling timeout", "POLLING_TIMEOUT"));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
setTimeout(poll, interval);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
reject(error);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
poll();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Static factory method to create a KYC client instance
|
|
230
|
+
* @param credentials API credentials (apiKey and baseUrl)
|
|
231
|
+
* @returns Configured KYCCore instance
|
|
232
|
+
*/
|
|
233
|
+
static createClient(credentials) {
|
|
234
|
+
return new _KYCCore(credentials);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
function createKYCClient(credentials) {
|
|
238
|
+
return KYCCore.createClient(credentials);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { KYCCore, KYCSdkError, createKYCClient };
|
|
242
|
+
//# sourceMappingURL=index.mjs.map
|
|
243
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.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A,EAAsC;AACxD,IAAA,OAAO,IAAI,SAAQ,WAAW,CAAA;AAAA,EAChC;AACF;AAOO,SAAS,gBAAgB,WAAA,EAAsC;AACpE,EAAA,OAAO,OAAA,CAAQ,aAAa,WAAW,CAAA;AACzC","file":"index.mjs","sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n/**\n * Credentials required to initialize the KYC SDK\n */\nexport interface KYCCredentials {\n /** API key for authentication */\n apiKey: string;\n /** Base URL of the KYC API */\n baseUrl: string;\n}\n\n/**\n * Parameters required to start a verification session\n */\nexport interface StartVerificationParams {\n /** Type of document to verify (e.g., IDENTITY_CARD, DRIVING_LICENSE) */\n documentType: 'IDENTITY_CARD' | 'DRIVING_LICENSE';\n /** Country code (e.g., MZ, AO, PT) */\n country: string;\n /** Optional existing identity ID to link verification to */\n identityId?: string;\n /** Optional external reference ID */\n externalId?: string;\n}\n\n/**\n * Response from starting a verification session\n */\nexport interface VerificationSession {\n /** Unique verification ID */\n verificationId: string;\n /** Linked identity ID (if exists) */\n identityId?: string;\n /** Current verification status */\n status: string;\n}\n\n/**\n * Parameters for uploading a selfie image\n */\nexport interface UploadSelfieParams {\n /** Verification ID to attach the selfie to */\n verificationId: string;\n /** Base64 encoded image data, data URI, or file:// URI (React Native) */\n imageData: string;\n /** MIME type of the image (default: image/jpeg) */\n mimeType?: string;\n}\n\n/**\n * Parameters for uploading a document image\n */\nexport interface UploadDocumentParams {\n /** Verification ID to attach the document to */\n verificationId: string;\n /** Type of document (front or back) */\n type: 'front' | 'back';\n /** Base64 encoded image data, data URI, or file:// URI (React Native) */\n imageData: string;\n /** MIME type of the image (default: image/jpeg) */\n mimeType?: string;\n}\n\n/** Result of an upload operation */\nexport interface UploadResult {\n /** Response message */\n message: string;\n /** Current status after upload */\n status: string;\n}\n\n/** Current status of a verification session */\nexport interface VerificationStatus {\n /** Verification ID */\n verificationId: string;\n /** Current status: PENDING, PROCESSING, APPROVED, or REJECTED */\n status: 'PENDING' | 'PROCESSING' | 'APPROVED' | 'REJECTED';\n /** Face match similarity score (0-1) */\n faceMatchScore?: number;\n /** OCR extracted data from document */\n ocrData?: {\n /** Full name extracted from document */\n fullName?: string;\n /** ID number extracted from document */\n idNumber?: string;\n /** Birth date extracted from document */\n birthDate?: string;\n /** Expiry date extracted from document */\n expiryDate?: string;\n /** Additional extracted fields */\n [key: string]: any;\n };\n /** When the verification was created */\n createdAt: string;\n /** When the verification was last updated */\n updatedAt: string;\n}\n\n/** Event emitted when KYC status changes */\nexport interface KYCStatusEvent {\n /** Type of event: statusChanged or error */\n type: 'statusChanged' | 'error';\n /** New status (for statusChanged events) */\n status?: string;\n /** Error message (for error events) */\n error?: string;\n}\n\n/** Callback function for handling KYC status events */\nexport type KYCEventCallback = (event: KYCStatusEvent) => void;\n\n/**\n * Custom error class for KYC SDK errors\n */\nexport class KYCSdkError extends Error {\n /** Error code for programmatic error handling */\n code: string;\n /** HTTP status code if available */\n statusCode?: number;\n\n /**\n * Creates a new KYC SDK error\n * @param message Human-readable error message\n * @param code Error code for handling\n * @param statusCode Optional HTTP status code\n */\n constructor(message: string, code: string, statusCode?: number) {\n super(message);\n this.name = 'KYCSdkError';\n this.code = code;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Core KYC SDK client for interacting with the verification API\n */\nexport class KYCCore {\n private client: AxiosInstance;\n private credentials: KYCCredentials;\n private eventCallbacks: KYCEventCallback[] = [];\n\n /**\n * Creates a new KYC Core instance\n * @param credentials API credentials (apiKey and baseUrl)\n */\n constructor(credentials: KYCCredentials) {\n this.credentials = credentials;\n this.client = axios.create({\n baseURL: credentials.baseUrl,\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n });\n\n this.client.interceptors.request.use((config) => {\n config.headers['x-api-key'] = this.credentials.apiKey;\n return config;\n });\n }\n\n /**\n * Registers a callback for KYC status events\n * @param callback Function to call when status changes\n * @returns Unsubscribe function to remove the callback\n */\n onEvent(callback: KYCEventCallback): () => void {\n this.eventCallbacks.push(callback);\n return () => {\n this.eventCallbacks = this.eventCallbacks.filter((cb) => cb !== callback);\n };\n }\n\n /**\n * Emits a status event to all registered callbacks\n * @param event The event to emit\n */\n private emitEvent(event: KYCStatusEvent): void {\n this.eventCallbacks.forEach((callback) => callback(event));\n }\n\n /**\n * Creates a verification token for secure API access\n * @param externalId External reference ID\n * @param expiry Token expiry in hours (default: 3)\n * @returns Object containing the token and its expiration time\n */\n async createVerificationToken(\n externalId: string,\n expiry: string = '3'\n ): Promise<{ token: string; expiresIn: string }> {\n try {\n const response = await this.client.post('/verification/token', {\n externalId,\n expiry,\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to create verification token';\n throw new KYCSdkError(message, 'TOKEN_CREATE_FAILED', error.response?.status);\n }\n }\n\n /**\n * Starts a new verification session\n * @param params Parameters including documentType, country, identityId, and externalId\n * @returns Verification session with verificationId and status\n */\n async startVerification(params: StartVerificationParams): Promise<VerificationSession> {\n try {\n const response = await this.client.post('/verification/start', params);\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PENDING',\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to start verification';\n throw new KYCSdkError(message, 'VERIFICATION_START_FAILED', error.response?.status);\n }\n }\n\n /**\n * Uploads a selfie image for face verification\n * @param params Parameters including verificationId, imageData, and optional mimeType\n * @returns Upload result with status\n */\n async uploadSelfie(params: UploadSelfieParams): Promise<UploadResult> {\n try {\n const formData = new FormData();\n formData.append('verificationId', params.verificationId);\n\n const mimeType = params.mimeType || 'image/jpeg';\n const imageData = params.imageData;\n\n if (imageData.startsWith('file://')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n } else if (imageData.startsWith('data:')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n } else {\n formData.append('file', {\n uri: `data:${mimeType};base64,${imageData}`,\n type: mimeType,\n name: 'selfie.jpg',\n } as any);\n }\n\n const response = await this.client.post('/verification/upload/selfie', formData, {\n headers: { 'Content-Type': 'multipart/form-data' },\n });\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PROCESSING',\n });\n\n return response.data;\n } catch (error: any) {\n console.log('Upload selfie error:', error.response?.data || error.message);\n const message = error.response?.data?.message || error.message || 'Failed to upload selfie';\n throw new KYCSdkError(message, 'SELFIE_UPLOAD_FAILED', error.response?.status);\n }\n }\n\n /**\n * Uploads a document image (front or back)\n * @param params Parameters including verificationId, type, imageData, and optional mimeType\n * @returns Upload result with status\n */\n async uploadDocument(params: UploadDocumentParams): Promise<UploadResult> {\n try {\n const formData = new FormData();\n formData.append('verificationId', params.verificationId);\n formData.append('type', params.type);\n\n const mimeType = params.mimeType || 'image/jpeg';\n const imageData = params.imageData;\n\n if (imageData.startsWith('file://')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n } else if (imageData.startsWith('data:')) {\n formData.append('file', {\n uri: imageData,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n } else {\n formData.append('file', {\n uri: `data:${mimeType};base64,${imageData}`,\n type: mimeType,\n name: `${params.type}.jpg`,\n } as any);\n }\n\n const response = await this.client.post('/verification/upload/document', formData, {\n headers: { 'Content-Type': 'multipart/form-data' },\n });\n\n this.emitEvent({\n type: 'statusChanged',\n status: 'PROCESSING',\n });\n\n return response.data;\n } catch (error: any) {\n console.log('Upload document error:', error.response?.data || error.message);\n const message = error.response?.data?.message || error.message || 'Failed to upload document';\n throw new KYCSdkError(message, 'DOCUMENT_UPLOAD_FAILED', error.response?.status);\n }\n }\n\n /**\n * Gets the current status of a verification session\n * @param verificationId The verification ID to check\n * @returns Current verification status including OCR data and face match score\n */\n async getStatus(verificationId: string): Promise<VerificationStatus> {\n try {\n const response = await this.client.get(`/verification/status/${verificationId}`);\n\n this.emitEvent({\n type: 'statusChanged',\n status: response.data.status,\n });\n\n return response.data;\n } catch (error: any) {\n const message =\n error.response?.data?.message || error.message || 'Failed to get verification status';\n throw new KYCSdkError(message, 'STATUS_CHECK_FAILED', error.response?.status);\n }\n }\n\n /**\n * Polls for verification status until completion or timeout\n * @param verificationId The verification ID to check\n * @param interval Polling interval in milliseconds (default: 3000)\n * @param timeout Maximum time to wait in milliseconds (default: 120000)\n * @returns Final verification status when approved or rejected\n */\n async pollStatus(\n verificationId: string,\n interval: number = 3000,\n timeout: number = 120000\n ): Promise<VerificationStatus> {\n const startTime = Date.now();\n\n return new Promise((resolve, reject) => {\n const poll = async () => {\n try {\n const status = await this.getStatus(verificationId);\n\n if (status.status === 'APPROVED' || status.status === 'REJECTED') {\n resolve(status);\n return;\n }\n\n if (Date.now() - startTime > timeout) {\n reject(new KYCSdkError('Polling timeout', 'POLLING_TIMEOUT'));\n return;\n }\n\n setTimeout(poll, interval);\n } catch (error) {\n reject(error);\n }\n };\n\n poll();\n });\n }\n\n /**\n * Static factory method to create a KYC client instance\n * @param credentials API credentials (apiKey and baseUrl)\n * @returns Configured KYCCore instance\n */\n static createClient(credentials: KYCCredentials): KYCCore {\n return new KYCCore(credentials);\n }\n}\n\n/**\n * Factory function to create a KYC client instance\n * @param credentials API credentials (apiKey and baseUrl)\n * @returns Configured KYCCore instance\n */\nexport function createKYCClient(credentials: KYCCredentials): KYCCore {\n return KYCCore.createClient(credentials);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kyciris/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"axios": "^1.6.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.10.0",
|
|
17
|
+
"eslint": "^9.25.0",
|
|
18
|
+
"tsup": "^8.0.0",
|
|
19
|
+
"typescript": "~5.9.2"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"lint": "eslint src/"
|
|
26
|
+
}
|
|
27
|
+
}
|