@kumologica/sdk 4.0.0-beta2 → 4.0.0-beta4

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.
@@ -1,5 +1,4 @@
1
1
  const path = require('path');
2
- const os = require('os');
3
2
 
4
3
  exports.command = 'save [key]';
5
4
  exports.desc = `Saves kumologica license in local file system.\n
@@ -16,18 +15,6 @@ exports.builder = (yargs) => {
16
15
  demandOption: true // Makes the positional argument required
17
16
  });
18
17
  };
19
-
20
- function getHomeDir() {
21
- const platform = process.platform;
22
- switch (platform) {
23
- case 'win32':
24
- return process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
25
- case 'darwin':
26
- return path.join(os.homedir(), 'Library', 'Application Support');
27
- default:
28
- return path.join(os.homedir(), '.config');
29
- }
30
- }
31
18
 
32
19
  function display(argv) {
33
20
  console.log(`\nSaving license key ${argv.key}\n`);
@@ -39,14 +26,13 @@ exports.handler = function (argv) {
39
26
  try {
40
27
 
41
28
  if (argv.key) {
42
- const electron = require('electron');
43
29
  const tools = require('../../../src/app/lib/utils/tools.min.js');
44
-
45
- const userDataPath = path.join(getHomeDir(), "Kumologica Designer");
30
+ const utils = require("../../utils/license.js");
31
+
32
+ const userDataPath = utils.getHomeDir();
46
33
 
47
34
  console.log(`User data path: ${userDataPath}`);
48
35
  // Get the userDataPath directory
49
- //const userDataPath = (electron.app || electron.remote.app).getPath('userData');
50
36
  tools.license.save(userDataPath, argv.key);
51
37
  console.log('License key saved successfully.');
52
38
  } else {
@@ -165,6 +165,12 @@ async function runUpdater(projectDir) {
165
165
  await updater.update(updates);
166
166
  }
167
167
 
168
+ async function licenseCheck() {
169
+
170
+ const license = require("../utils/license.js");
171
+ return await license.licenseCheck();
172
+ }
173
+
168
174
  exports.command = "open [project_directory]";
169
175
  exports.builder = (yargs) => {
170
176
  yargs.positional(`project_directory`, {
@@ -176,9 +182,15 @@ exports.builder = (yargs) => {
176
182
  exports.desc = "Open Kumologica Designer";
177
183
 
178
184
  exports.handler = async ({ project_directory }) => {
185
+
179
186
  const projectDir = project_directory
180
187
  ? path.resolve(project_directory)
181
188
  : undefined;
189
+
190
+ if (!await licenseCheck(project_directory)) {
191
+ process.exit(1);
192
+ }
193
+
182
194
  await runUpdater(projectDir);
183
195
 
184
196
  startElectron(projectDir);
@@ -0,0 +1,110 @@
1
+ const path = require("path");
2
+ const os = require("os");
3
+ const { Confirm, Input } = require('enquirer');
4
+ const tools = require('../../src/app/lib/utils/tools.min.js');
5
+
6
+ function getHomeDir() {
7
+ const platform = process.platform;
8
+ let homeDir;
9
+ switch (platform) {
10
+ case 'win32':
11
+ homeDir = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
12
+ break
13
+ case 'darwin':
14
+ homeDir = path.join(os.homedir(), 'Library', 'Application Support');
15
+ break;
16
+ default:
17
+ homeDir = path.join(os.homedir(), '.config');
18
+ }
19
+ return path.join(homeDir, "Kumologica Designer");
20
+ }
21
+
22
+
23
+ async function promptForLicenseKey() {
24
+ try {
25
+ // Step 1: Ask if user has a license key
26
+ const hasKey = await new Confirm({
27
+ name: 'hasLicense',
28
+ message: 'Do you have a license key?',
29
+ initial: true
30
+ }).run();
31
+
32
+ if (hasKey) {
33
+ // Step 2: Prompt for license key
34
+ const licenseKey = await new Input({
35
+ name: 'licenseKey',
36
+ message: 'Enter your license key:',
37
+ }).run();
38
+
39
+ try {
40
+ console.log(`Validating license key`);
41
+ tools.license.verify(licenseKey);
42
+ console.log(`License key is valid`);
43
+
44
+ } catch (e) {
45
+ console.error(`Invalid license key: ${e.message}`);
46
+ process.exit(1);
47
+
48
+ }
49
+
50
+ console.log(`✅ License key entered: ${licenseKey}`);
51
+
52
+ tools.license.save(getHomeDir(), licenseKey);
53
+ return true;
54
+ } else {
55
+ // Step 3: Ask if user wants to request a developer license
56
+ const requestDev = await new Confirm({
57
+ name: 'requestDevLicense',
58
+ message: 'Do you want to request a developer license key?',
59
+ initial: true
60
+ }).run();
61
+
62
+ if (requestDev) {
63
+ // Step 4: Ask for email address
64
+ const email = await new Input({
65
+ name: 'email',
66
+ message: 'Enter your email address:',
67
+ validate: value =>
68
+ /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? true : 'Please enter a valid email address'
69
+ }).run();
70
+
71
+ console.log(`📧 Developer license will be requested for: ${email}`);
72
+
73
+ await tools.license.subscribe(email);
74
+ console.log(`Follow the instructions in your email to complete the process.`);
75
+
76
+ return false;
77
+ } else {
78
+ console.log('❌ License key is required to continue. Exiting...');
79
+ return false;
80
+ }
81
+ }
82
+ } catch (err) {
83
+ console.error('❌ Prompt error:', err.message || err);
84
+ return false;
85
+ }
86
+ }
87
+
88
+ async function licenseCheck() {
89
+
90
+ console.log("Checking for valid license...");
91
+
92
+ console.log("Reading license data...");
93
+ try {
94
+ const licenseData = tools.license.read(getHomeDir());
95
+ return true;
96
+ } catch (e) {
97
+ console.error("Error reading license data:", e.message);
98
+ }
99
+
100
+ console.log("No license data...");
101
+ await promptForLicenseKey();
102
+
103
+ return false;
104
+ }
105
+
106
+
107
+ module.exports = {
108
+ licenseCheck,
109
+ getHomeDir
110
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumologica/sdk",
3
- "version": "4.0.0-beta2",
3
+ "version": "4.0.0-beta4",
4
4
  "productName": "Kumologica Designer",
5
5
  "copyright": "Copyright 2020 Kumologica Pty Ltd, All Rights Reserved.",
6
6
  "author": "Kumologica Pty Ltd <contact@kumologica.com>",
@@ -84,9 +84,9 @@
84
84
  "@aws-sdk/credential-providers": "^3.556.0",
85
85
  "@aws-sdk/lib-dynamodb": "^3.549.0",
86
86
  "@electron/remote": "^2.0.8",
87
- "@kumologica/builder": "4.0.0-beta2",
88
- "@kumologica/devkit": "4.0.0-beta2",
89
- "@kumologica/runtime": "4.0.0-beta2",
87
+ "@kumologica/builder": "4.0.0-beta4",
88
+ "@kumologica/devkit": "4.0.0-beta4",
89
+ "@kumologica/runtime": "4.0.0-beta4",
90
90
  "adm-zip": "0.4.13",
91
91
  "ajv": "8.10.0",
92
92
  "archive-type": "^4.0.0",
@@ -1 +1 @@
1
- var e,o,n,l,r=require("crypto"),s=require("fs"),t=require("path");function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function i(){if(!o){o=1;let i="base64";e={display:function(e){e?(console.log("--- License Details ---"),console.log("Subscriber: "+e.sub),console.log("Email: "+e.email),console.log("License Type: "+e.licenseType),console.log("Issued By: "+e.iss),console.log("Issued At: "+new Date(e.iat).toLocaleString()),console.log("Expiry: "+("perpetual"===e.exp?"Perpetual":new Date(e.exp).toLocaleString())),console.log("------------------------")):console.error("Invalid license data.")},verify:function(e){console.log("Verifying license..."),publicKeyPem=(()=>{var l=Buffer.from("XkI1bxBWOXhHBztkdXIuEXlKLBcSIWstZlEzOEADPyFCCVkUeQNIIxwWDU4QEiEyLHpfOjwHCVNlL3tTFiIvMGkcZCkOBnNgIjtybUckA3x7BRARDElXRxECPlB4OgF4aWIRDQAGLBI2Jns3eTINDkx+XSN9bAAFDHllInIdCEg8SzICC2JJJyl4CGk5JAB/EBQcLW4+dzcuMGxhLglhbHUZF2ZwFQMJEl08cAVfWGd5ADtje34SDUJCHxUlWh83aghXDnJXXwxxCFsUNANhCzJ0MHoiVyEvLlh2OC5gf2UwdGZhDxAvMllUcCgSWl1w",i).toString().split("").reverse().join("");let r="";for(let o=0;o<l.length;o++){let e="34jfd#d-cDFG23@W096ml".charCodeAt(o%21);r+=String.fromCharCode(l.charCodeAt(o)^e)}return Buffer.from(r,i).toString()})();var o=r,[e,l]=e.split(".");if(!e||!l)throw new Error("Invalid license format. Expected payload.signature");var e=Buffer.from(e,"base64url").toString("utf-8"),n=JSON.parse(e),e=Buffer.from(e,"utf-8"),l=Buffer.from(l,"base64url"),o=o.createVerify("SHA256");if(o.update(e),o.end(),o.verify(publicKeyPem,l))return console.log(" License is valid."),console.log("Issued To (sub):",n.sub),console.log("License Type:",n.licenseType),console.log("Expiry (exp):",n.exp),n;throw new Error("Invalid license signature. License may have been tampered.")},save:function(e,o){var l=s,r=t,r=(console.log("saving key to: "+e),r.join(e,"kumologica.license"));try{l.writeFileSync(r,o,"utf-8"),console.log("License saved successfully at: "+r)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var o=s,l=t.join(e,"kumologica.license");try{let e=o.readFileSync(l,"utf-8");return console.log("License read successfully from: "+l),e}catch(e){return console.error("Failed to read license: "+e.message),null}}}}return e}var a=(()=>{if(l)return n;l=1;var e=i();return n={license:e}})(),u=c(a);module.exports=u;
1
+ var e,o,n,t,r=require("crypto"),i=require("fs"),s=require("path");function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(){if(!o){o=1;let l="base64";e={subscribe:async function(e){console.log("Requesting developer license for email: "+e);var r=await fetch("https://api.infra.kumologica.com/p/signup?x-api-key=RjibYF3qZb2AzmTrPOnV35LfRV798e3Z87vp4izo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e})});if(r.ok)return!0;{let e=await r.text();return console.error(`License request failed: ${r.status} `+e),!1}},display:function(e){e?(console.log("--- License Details ---"),console.log("Subscriber: "+e.sub),console.log("Email: "+e.email),console.log("License Type: "+e.licenseType),console.log("Issued By: "+e.iss),console.log("Issued At: "+new Date(e.iat).toLocaleString()),console.log("Expiry: "+("perpetual"===e.exp?"Perpetual":new Date(e.exp).toLocaleString())),console.log("------------------------")):console.error("Invalid license data.")},verify:function(e){publicKeyPem=(()=>{var o=Buffer.from("XkI1bxBWOXhHBztkdXIuEXlKLBcSIWstZlEzOEADPyFCCVkUeQNIIxwWDU4QEiEyLHpfOjwHCVNlL3tTFiIvMGkcZCkOBnNgIjtybUckA3x7BRARDElXRxECPlB4OgF4aWIRDQAGLBI2Jns3eTINDkx+XSN9bAAFDHllInIdCEg8SzICC2JJJyl4CGk5JAB/EBQcLW4+dzcuMGxhLglhbHUZF2ZwFQMJEl08cAVfWGd5ADtje34SDUJCHxUlWh83aghXDnJXXwxxCFsUNANhCzJ0MHoiVyEvLlh2OC5gf2UwdGZhDxAvMllUcCgSWl1w",l).toString().split("").reverse().join("");let t="";for(let r=0;r<o.length;r++){let e="34jfd#d-cDFG23@W096ml".charCodeAt(r%21);t+=String.fromCharCode(o.charCodeAt(r)^e)}return Buffer.from(t,l).toString()})();var o=r,[e,t]=e.split(".");if(!e||!t)throw new Error("Invalid license format. License may have been tampered.");var e=Buffer.from(e,"base64url").toString("utf-8"),n=JSON.parse(e),e=Buffer.from(e,"utf-8"),t=Buffer.from(t,l),o=o.createVerify("SHA256");if(o.update(e),o.end(),!o.verify(publicKeyPem,t))throw new Error("Invalid license signature. License may have been tampered.");if(!(n&&n.sub&&n.email&&n.iss&&n.iat))throw new Error("Invalid license data. License may have been tampered.");if(n.exp&&Date.now()>n.exp)throw new Error("License has expired. Please renew your license, contact Kumologica support at contact@kumologica.com.");return n},save:function(e,r){var o=i,t=s,t=(console.log("saving key to: "+e),t.join(e,"kumologica.license"));try{o.writeFileSync(t,r,"utf-8"),console.log("License saved successfully at: "+t)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var r=i,o=s.join(e,"kumologica.license");try{let e=r.readFileSync(o,"utf-8");return console.log("License read successfully from: "+o),e}catch(e){return null}}}}return e}var a=(()=>{if(t)return n;t=1;var e=l();return n={license:e}})(),u=c(a);module.exports=u;
@@ -4,7 +4,6 @@ const {
4
4
  PLATFORMS,
5
5
  } = require("@kumologica/runtime");
6
6
  const tcpPortUsed = require("tcp-port-used");
7
- const os = require("os");
8
7
 
9
8
  const tools = require('../app/lib/utils/tools.min.js');
10
9
  /**
@@ -28,7 +27,7 @@ class DesignerServer {
28
27
  console.log(
29
28
  "[ERROR] Flow is not defined. Make sure you pass the flow file to the constructor of FlowBuilder"
30
29
  );
31
- os.exit(1);
30
+ process.exit(1);
32
31
  }
33
32
 
34
33
  this.editorApi = options.editorApi;
@@ -45,31 +44,44 @@ class DesignerServer {
45
44
  const electron = require('electron');
46
45
  const licensePath = (electron.app || electron.remote.app).getPath('userData');
47
46
 
48
- console.log(`License path: ${licensePath}`);
49
- console.log(`platform: ${this.config.platform}`);
47
+ console.debug(`License path: ${licensePath}`);
48
+ console.debug(`platform: ${this.config.platform}`);
50
49
 
51
50
  const licenseData = tools.license.read(licensePath);
52
- console.log(`License read from: ${licensePath}`);
53
-
54
51
  return licenseData;
55
52
  }
56
53
 
57
54
  verifyLicense(licenseData) {
58
- const lData = tools.license.verify(licenseData);
59
- if (lData) {
60
- tools.license.display(lData);
55
+
56
+ if (licenseData) {
57
+ const lData = tools.license.verify(licenseData);
58
+ if (lData) {
59
+ tools.license.display(lData);
60
+ }
61
+ return lData;
62
+ } else {
63
+ console.error("[ERROR] License data is not available. Please provide a valid license key.");
64
+ return null;
61
65
  }
62
- return lData;
63
66
  }
64
67
 
65
68
  async start() {
66
69
  // Check if port passed by parameter is available otherwise allocate a new one
67
70
 
68
- if (!process.env.KUMOLOGICA_LICENSE) {
69
- process.env.KUMOLOGICA_LICENSE = this.readLicense();
71
+ let licenseKey = process.env.KUMOLOGICA_LICENSE;
72
+
73
+ if (!licenseKey) {
74
+ licenseKey = this.readLicense();
70
75
  }
71
76
 
72
- this.verifyLicense(process.env.KUMOLOGICA_LICENSE);
77
+ if (!licenseKey) {
78
+ console.error("[ERROR] Missing license key. Please provide a valid license key.");
79
+ process.exit(1);
80
+ }
81
+
82
+ this.verifyLicense(licenseKey);
83
+
84
+ process.env.KUMOLOGICA_LICENSE = licenseKey;
73
85
 
74
86
  this.config.port = await this.allocatePort(this.config.port);
75
87
  this.flowServer = new AbstractServerfulServer(