@kumologica/sdk 4.0.0-beta1 → 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,35 +1,39 @@
1
- exports.command = 'save';
1
+ const path = require('path');
2
+
3
+ exports.command = 'save [key]';
2
4
  exports.desc = `Saves kumologica license in local file system.\n
3
5
 
4
6
  Documentation:
5
7
  https://docs.kumologica.com/docs/references/cli/LicenseSave.html`;
6
8
 
7
- exports.builder = {
8
- "key": {
9
- describe: "The license key received in email from kumologica.com.\n ",
10
- type: 'string',
11
- alias: 'l',
12
- nargs: 1
13
- }
14
- }
9
+ exports.builder = (yargs) => {
10
+ yargs
11
+ .positional('key', {
12
+ describe: 'The license key received in email from kumologica.com.',
13
+ type: 'string',
14
+
15
+ demandOption: true // Makes the positional argument required
16
+ });
17
+ };
15
18
 
16
19
  function display(argv) {
17
- console.log(`\nSaving license key \n`);
20
+ console.log(`\nSaving license key ${argv.key}\n`);
18
21
  }
19
22
 
20
- const { saveLicense } = require('../../../../tools/src/license/index');
21
-
22
23
  exports.handler = function (argv) {
23
24
  display(argv);
24
25
 
25
26
  try {
26
27
 
27
28
  if (argv.key) {
28
- const electron = require('electron');
29
+ const tools = require('../../../src/app/lib/utils/tools.min.js');
30
+ const utils = require("../../utils/license.js");
31
+
32
+ const userDataPath = utils.getHomeDir();
29
33
 
34
+ console.log(`User data path: ${userDataPath}`);
30
35
  // Get the userDataPath directory
31
- const userDataPath = (electron.app || electron.remote.app).getPath('userData');
32
- saveLicense(userDataPath, argv.key);
36
+ tools.license.save(userDataPath, argv.key);
33
37
  console.log('License key saved successfully.');
34
38
  } else {
35
39
  console.log('No license key provided. Use the --key option to specify the license key.');
@@ -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-beta1",
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-beta1",
88
- "@kumologica/devkit": "4.0.0-beta1",
89
- "@kumologica/runtime": "4.0.0-beta1",
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
- require("crypto");var e,o,n,r,l=require("fs"),c=require("path");function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(){return o?e:(o=1,e={display:function(e){var o,l,r,n;e&&e.sub&&e.licenseType?({sub:e,email:o,licenseType:l,iat:r,exp:n}=e,console.log("--- License Details ---"),console.log("Subscriber: "+e),console.log("Email: "+o),console.log("License Type: "+l),console.log("Issued At: "+new Date(r).toLocaleString()),console.log("Expiry: "+("perpetual"===n?"Perpetual":new Date(n).toLocaleString())),console.log("------------------------")):console.error("Invalid license data.")},verify:function(e,o,l){return!0},save:function(e,o){var r=l,n=c.join(e,"kumologica.license");try{r.writeFileSync(n,o,"utf-8"),console.log("License saved successfully at: "+n)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var o=l,r=c.join(e,"kumologica.license");try{let e=o.readFileSync(r,"utf-8");return console.log("License read successfully from: "+r),e}catch(e){return console.error("Failed to read license: "+e.message),null}}})}var i=(()=>{if(r)return n;r=1;var e=t();return n={license:e}})(),u=s(i);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;
@@ -5,11 +5,11 @@ const {
5
5
  } = require("@kumologica/runtime");
6
6
  const tcpPortUsed = require("tcp-port-used");
7
7
 
8
- const os = require("os");
8
+ const tools = require('../app/lib/utils/tools.min.js');
9
9
  /**
10
10
  * This class will encapsulate the adminApp and FlowApp into two servers.
11
11
  * It will be the one running on the development box of the user (either local or remote),
12
- * and it will serve all the functioanlity to the Kumologica Cloud Editor.
12
+ * and it will serve all the functionality to the Kumologica Cloud Editor.
13
13
  */
14
14
 
15
15
  class DesignerServer {
@@ -27,7 +27,7 @@ class DesignerServer {
27
27
  console.log(
28
28
  "[ERROR] Flow is not defined. Make sure you pass the flow file to the constructor of FlowBuilder"
29
29
  );
30
- os.exit(1);
30
+ process.exit(1);
31
31
  }
32
32
 
33
33
  this.editorApi = options.editorApi;
@@ -40,8 +40,49 @@ class DesignerServer {
40
40
  );
41
41
  }
42
42
 
43
+ readLicense() {
44
+ const electron = require('electron');
45
+ const licensePath = (electron.app || electron.remote.app).getPath('userData');
46
+
47
+ console.debug(`License path: ${licensePath}`);
48
+ console.debug(`platform: ${this.config.platform}`);
49
+
50
+ const licenseData = tools.license.read(licensePath);
51
+ return licenseData;
52
+ }
53
+
54
+ verifyLicense(licenseData) {
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;
65
+ }
66
+ }
67
+
43
68
  async start() {
44
69
  // Check if port passed by parameter is available otherwise allocate a new one
70
+
71
+ let licenseKey = process.env.KUMOLOGICA_LICENSE;
72
+
73
+ if (!licenseKey) {
74
+ licenseKey = this.readLicense();
75
+ }
76
+
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;
85
+
45
86
  this.config.port = await this.allocatePort(this.config.port);
46
87
  this.flowServer = new AbstractServerfulServer(
47
88
  this.config,
@@ -1,115 +0,0 @@
1
- exports.command = 'kumohub';
2
- exports.desc = `Deploy kumologica flow to kumohub.io account`;
3
-
4
- exports.builder = {
5
- "flow-file-name": {
6
- describe: "The name of kumologica flow file.\n Auto search if not provided.\n",
7
- type: 'string',
8
- alias: 'f',
9
- nargs: 1
10
- },
11
- "service-name": {
12
- describe: "The name of service.\n flow file name without extension if not provided.\n Service name will be sanitized to be compatible with aws lambda name restrictions.\n",
13
- type: 'string',
14
- nargs: 1
15
- },
16
- "project-directory": {
17
- describe: "The root directory of project.\n Process working directory if not provided.\n",
18
- type: 'string',
19
- alias: 'd',
20
- nargs: 1
21
- },
22
- "environment": {
23
- describe: `Environment variables, JSON Syntax: '{"Variables": {"key": "value", ...}}'\n`,
24
- type: 'string',
25
- nargs: 1
26
- },
27
- "account": {
28
- describe: "The name of kumohub.io account\n",
29
- type: 'string',
30
- required: true,
31
- alias: 'a',
32
- nargs: 1
33
- },
34
- "username": {
35
- describe: "The username to login to kumohub.io account\n",
36
- type: 'string',
37
- required: true,
38
- alias: 'u',
39
- nargs: 1
40
- },
41
- "password": {
42
- describe: "The username password to login to kumohub.io account\n",
43
- type: 'string',
44
- required: true,
45
- alias: 'p',
46
- nargs: 1
47
- },
48
- "workspace": {
49
- describe: "The name of the workspace where flow to be deployed.\n",
50
- type: 'string',
51
- required: true,
52
- alias: 'w',
53
- nargs: 1
54
- },
55
- "stage": {
56
- describe: "The name of the stage where flow to be deployed\n",
57
- type: 'string',
58
- required: true,
59
- alias: 's',
60
- nargs: 1
61
- },
62
- "policy": {
63
- describe: "The name of security policy to assign to the flow.\n",
64
- type: 'string',
65
- required: true,
66
- default: "Public",
67
- nargs: 1
68
- },
69
- "memory": {
70
- describe: "The amount of memory (MB) to be allocated to the flow. 128 MB to 10240 MB\n",
71
- type: 'string',
72
- nargs: 1,
73
- default: "512"
74
- },
75
- "timeout": {
76
- describe: "The amount of seconds flow should be run before timing out. Up to 900 seconds\n",
77
- type: 'string',
78
- nargs: 1,
79
- default: "30"
80
- },
81
- "description": {
82
- describe: "The description of function.\n",
83
- type: 'string',
84
- nargs: 1
85
- }
86
- }
87
-
88
- function display(argv) {
89
- console.log(`\nDeploying flow to kumohub.io with following parameters: \n`);
90
- console.log('project-directory: %s', argv["project-directory"] || '');
91
- console.log('flow-file-name: %s', argv["flow-file-name"] || '');
92
- console.log('service-name: %s', argv["service-name"] || '');
93
- console.log('environment vars: %s', argv["environment"] || '');
94
- console.log('username: %s', argv["username"] || '');
95
- console.log('password: %s', argv["password"]? "provided": "missing");
96
- console.log('workspace: %s', argv["workspace"] || '');
97
- console.log('stage: %s', argv["stage"] || '');
98
- console.log('policy: %s', argv["policy"] || '');
99
- console.log('memory: %s', argv["memory"] || '');
100
- console.log('timeout: %s', argv["timeout"] || '');
101
- console.log('description: %s', argv["description"] || '');
102
- }
103
-
104
- exports.handler = function (argv) {
105
- display(argv);
106
-
107
- try {
108
- const { deploy } = require('@kumologica/builder');
109
- deploy('kumohub', argv);
110
- } catch (e) {
111
- console.log(`${e.message}`);
112
- process.exit(1);
113
- }
114
- }
115
-