creditchek-react-sdk 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/README.md ADDED
@@ -0,0 +1,76 @@
1
+ <p align="center">
2
+ <img title="CreeditChek" height="200" src="https://docs.creditchek.africa/img/nav_logo.svg" width="50%"/>
3
+ </p>
4
+
5
+ # CreditChek React SDK
6
+
7
+ ## Introduction
8
+
9
+ The CreditChek Secured SDK Engine is a lightweight product that gives businesses access to a pool of CreditChek API services and a decision engine.
10
+
11
+ The CreditChek Secured SDK Engine uses the same technology as our main application to allow your customers to carry out assessments. The customer assessments help you determine the decisions to make when they apply to your product. With our Secured SDK, you are able to customize the functionalities according to how you see fit for your business. The assessments carried out on this secured SDK includes:
12
+
13
+ - Identity verification
14
+ - Credit Bereau History search
15
+ - Income Assessments
16
+ - Automated immediate credit decision outcome
17
+
18
+
19
+ ## Installation
20
+
21
+ Install the SDK
22
+
23
+ ```bash
24
+ $ npm install creditchek-react-sdk
25
+
26
+ # or
27
+ $ yarn add creditchek-react-sdk
28
+
29
+ ```
30
+
31
+
32
+ ## Usage
33
+
34
+ Add CreditChek SDK to your projects using the following simple guide:
35
+
36
+ ```javascript
37
+ import creditchekSDK from 'creditchek-react-sdk';
38
+
39
+ export default function App() {
40
+ const handleClick = () => {
41
+ creditchekSDK.open({
42
+ businessId: 'YOUR_BUSINESS_ID',
43
+ appId: "YOUR_APP_ID",
44
+ publicKey: "YOUR_APP_PUBLIC_KEY",
45
+ incomeForm: "XXXX", // short/long
46
+ module: ["xxxx"],
47
+ onComplete: (result) => {
48
+ console.log("Result:", result);
49
+ },
50
+ });
51
+ };
52
+
53
+ return (
54
+ <div className="App">
55
+ <h1>CreditChek SDK Test</h1>
56
+ <button onClick={handleClick}>Launch SDK</button>
57
+ </div>
58
+ );
59
+ }
60
+ ```
61
+
62
+
63
+ ## Parameters
64
+
65
+ | Parameter | Always Required ? | Description |
66
+ | ------------------- | ----------------- | ---------------------|
67
+ | businessId | True | This is your Business ID and can be found in the top right corner after logging in to the CreditChek B2B portal |
68
+ | appId | True | This is the ID of the app you want to connect for your SDK operations. It can be found on the app section on the B2B dashboard |
69
+ | publicKey | True | This is the your API public key. It can be found on the app section of the dashboard. |
70
+ | incomeForm | False | This determines whether users will need to fill additional information for income assessments. Default is "short", other option is "long". |
71
+ | module | True | This is an array of strings that determine the layout of the SDK by module selection. At least one must be included. Options - "identity", "income", "credit", "recova" |
72
+
73
+
74
+ # Support
75
+
76
+ For additional assistance using this library, please create an issue on the Github repo or contact the team via [email](mailto:support@creditchek.africa).
@@ -0,0 +1,10 @@
1
+ type TModules = "identity" | "income" | "credit" | "recova";
2
+ type CreditChekOptions = {
3
+ publicKey: string;
4
+ module: TModules[];
5
+ onComplete: () => void;
6
+ };
7
+ declare const creditchekSDK: {
8
+ open: ({ publicKey, module, onComplete }: CreditChekOptions) => void;
9
+ };
10
+ export default creditchekSDK;
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ var creditchekSDK = {
2
+ open: function (_a) {
3
+ var publicKey = _a.publicKey, module = _a.module, onComplete = _a.onComplete;
4
+ var url = "https://securedwidget.creditchek.africa/" +
5
+ "?publicKey=".concat(encodeURIComponent(publicKey || "")) +
6
+ "&module=".concat(module === null || module === void 0 ? void 0 : module.join(",")) +
7
+ "&source=react";
8
+ var win = window.open(url, '_blank');
9
+ // Simulated callback logic (for demo purposes)
10
+ var interval = setInterval(function () {
11
+ if (win === null || win === void 0 ? void 0 : win.closed) {
12
+ clearInterval(interval);
13
+ onComplete();
14
+ }
15
+ }, 500);
16
+ },
17
+ };
18
+ export default creditchekSDK;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "creditchek-react-sdk",
3
+ "version": "1.0.0",
4
+ "description": "This is a react package to run assessments on creditchek",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/Tibesti/creditchek-react-sdk#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/Tibesti/creditchek-react-sdk/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Tibesti/creditchek-react-sdk.git"
13
+ },
14
+ "license": "ISC",
15
+ "author": "Tobiloba Olugbemi",
16
+ "type": "commonjs",
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "scripts": {
20
+ "test": "echo \"Error: no test specified\" && exit 1",
21
+ "build": "tsc"
22
+ },
23
+ "dependencies": {
24
+ "react": "^19.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^19.1.3",
28
+ "typescript": "^5.8.3"
29
+ }
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1,50 @@
1
+ type TModules = "identity" | "income" | "credit" | "recova";
2
+ type CreditChekOptions = {
3
+ publicKey: string;
4
+ module: TModules[];
5
+ onComplete: (result?: any) => void;
6
+ onClose?: () => void;
7
+ postMessageParam?: string;
8
+ };
9
+
10
+ const creditchekSDK = {
11
+ open: ({ publicKey, module, onComplete, onClose, postMessageParam = "result" }: CreditChekOptions) => {
12
+ var url =
13
+ "https://securedwidget.creditchek.africa/"+
14
+ `?publicKey=${encodeURIComponent(publicKey||"")}`+
15
+ `&module=${module?.join(",")}`+
16
+ `&source=react`;
17
+ const win = window.open(url, '_blank');
18
+
19
+ // Listen for postMessage from the widget
20
+ const messageHandler = (event: MessageEvent) => {
21
+ // Verify origin for security
22
+ if (event.origin === 'https://securedwidget.creditchek.africa') {
23
+ if (event.data && typeof event.data === 'object') {
24
+ // Check if the specified parameter exists in the message
25
+ if (postMessageParam && event.data[postMessageParam] !== undefined) {
26
+ // Clean up listener
27
+ window.removeEventListener('message', messageHandler);
28
+ clearInterval(interval);
29
+
30
+ // Pass the result to onComplete
31
+ onComplete(event.data);
32
+ }
33
+ }
34
+ }
35
+ };
36
+
37
+ window.addEventListener('message', messageHandler);
38
+
39
+ // Fallback: Check if window is closed (for demo purposes)
40
+ const interval = setInterval(() => {
41
+ if (win?.closed) {
42
+ clearInterval(interval);
43
+ window.removeEventListener('message', messageHandler);
44
+ onClose?.();
45
+ }
46
+ }, 500);
47
+ },
48
+ };
49
+
50
+ export default creditchekSDK;
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "ESNext",
5
+ "lib": ["dom", "esnext"],
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "moduleResolution": "node"
13
+ },
14
+ "include": ["src"]
15
+ }