1// Initialize the Cornex SDK with configuration
2 let cornexSDK = new Cornex.init({
3 target: "New Garg Trading Co", // Name of the target entity
4 targetGST: "03AALCB4378C1ZV", // GSTIN of the target
5 url: "https://api.cornex.io/v1/partner", // Example API endpoint for the SDK
6 colorScheme: "dark", // Theme for the SDK's UI
7 mode: "sandbox" // Optional: specify environment (e.g., "sandbox" or "production")
8 });
9
10 // Opens the SDK's user interface or starts its process
11 cornexSDK.open();
12
13 // Listen for general messages or updates from the SDK
14 cornexSDK.onMessage((message) => {
15 console.log("SDK Message:", message); // e.g., { type: "status_update", content: "Processing..." }
16 });
17
18 // Listen for successful completion of the SDK's primary task
19 cornexSDK.onSuccess((result) => {
20 console.log("SDK Success:", result); // e.g., { transactionId: "xyz123", status: "completed" }
21 alert("Operation successful!");
22 });
23
24 // Listen for any errors that occur within the SDK
25 cornexSDK.onError((error) => {
26 console.error("SDK Error:", error); // e.g., { code: "auth_failed", description: "Invalid credentials" }
27 alert("An error occurred: " + error.description);
28 });
29
30 // Listen for when the SDK's UI is closed or dismissed by the user
31 cornexSDK.onClose(() => {
32 console.log("SDK Closed by user.");
33 // You might want to perform cleanup or update UI state here
34 });
35
36 // Example: Programmatically close the SDK if needed after some condition
37 // setTimeout(() => {
38 // if (cornexSDK.isOpen()) { // Assuming an isOpen() method exists
39 // console.log("Programmatically closing SDK...");
40 // cornexSDK.close(); // Assuming a close() method exists
41 // }
42 // }, 30000); // Close after 30 seconds if still open