@zkyc/evg 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # @zkyc/sdk
2
+
3
+ zKYC SDK wrapper to generate tokens and redirect users to KYC verification.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @zkyc/sdk
package/index.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @zkyc/sdk - NPM Package Script
3
+ *
4
+ * This is the script to include in your npm package.
5
+ * Users will call ZKYCProcess() with their API key to generate a token
6
+ * and redirect to the SDK.
7
+ */
8
+
9
+ /**
10
+ * Generates a secure token from the API key and redirects to the SDK
11
+ *
12
+ * @param {Object} config - Configuration object containing API key and redirect URLs
13
+ * @param {string} config.apiKey - Your zKYC API key (with test_ or prod_ prefix)
14
+ * @param {string} config.userId - EVG users userId
15
+ * @param {string} config.callback - URL to redirect if KYC verification fails
16
+ * @param {string} [config.platformApiUrl] - Optional: Your platform API URL (defaults to production)
17
+ * @returns {Promise<void>}
18
+ * @throws {Error} if API key, failurePage, or pendingPage is missing
19
+ * @throws {Error} if token generation fails
20
+ */
21
+ async function ZKYCProcess(config) {
22
+ const { apiKey, callback, userId } = config;
23
+
24
+ // Validate required parameters
25
+ if (!apiKey || !callback || !userId) {
26
+ throw new Error("apiKey, callback, and userId are required");
27
+ }
28
+
29
+ // Default to production platform API URL if not provided
30
+ // Users should set this to their platform URL (e.g., https://api.zkyc.tech)
31
+ const platformUrl = "https://app.zkyc.tech";
32
+ const tokenEndpoint = `${platformUrl}/api/sdk-token`;
33
+
34
+ try {
35
+ // Generate token from API key (server-side call)
36
+ const response = await fetch(tokenEndpoint, {
37
+ method: "POST",
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ },
41
+ body: JSON.stringify({ apikey: apiKey }),
42
+ });
43
+
44
+ if (!response.ok) {
45
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
46
+ throw new Error(`Token generation failed: ${errorData.error || response.statusText}`);
47
+ }
48
+
49
+ const { token, expiresIn, expiresAt } = await response.json();
50
+
51
+ if (!token) {
52
+ throw new Error("Token generation failed: No token received");
53
+ }
54
+
55
+ // Build SDK URL with token
56
+ const sdkUrl = new URL("https://sdk.zkyc.tech/");
57
+ sdkUrl.searchParams.set("apikey", token); // SDK will detect it's a token
58
+ sdkUrl.searchParams.set("callback", callback);
59
+ sdkUrl.searchParams.set("userId", userId);
60
+
61
+ // Redirect to SDK
62
+ if (typeof window !== "undefined") {
63
+ window.location.assign(sdkUrl.toString());
64
+ } else {
65
+ throw new Error("ZKYCProcess can only be used in browser environment");
66
+ }
67
+ } catch (error) {
68
+ if (error instanceof Error) {
69
+ throw new Error(`ZKYC Process failed: ${error.message}`);
70
+ }
71
+ throw new Error("ZKYC Process failed: Unknown error");
72
+ }
73
+ }
74
+
75
+ // ES Module exports (for modern bundlers and browsers)
76
+ export default ZKYCProcess;
77
+ export { ZKYCProcess };
78
+
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@zkyc/evg",
3
+ "version": "1.0.0",
4
+ "description": "zKYC SDK wrapper to generate tokens and redirect to KYC",
5
+ "main": "index.js",
6
+ "module": "index.js",
7
+ "type": "module",
8
+ "scripts": {},
9
+ "keywords": ["zkc", "kyc", "sdk", "token"],
10
+ "author": "Your Name",
11
+ "license": "MIT",
12
+ "dependencies": {}
13
+ }