biz-a-cli 2.3.7 → 2.3.8

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/bin/hubEvent.js CHANGED
@@ -65,7 +65,7 @@ export default async (socket, argv) => new Promise((resolve, reject) => {
65
65
 
66
66
  Axios.request({
67
67
  method: data.method,
68
- url: `${process.env.HOST || 'http://localhost'}:${argv.serverport}/cb${path}`,
68
+ url: `${process.env.HOST || 'http://localhost'}:${argv.serverport}/cb${path || ''}`,
69
69
  data: remainData
70
70
  }).subscribe(result => callback(result.data));
71
71
  });
@@ -20,10 +20,10 @@ export async function runCliScript(req, res) {
20
20
  const { data, selectedConfig } = getInputScript(req);
21
21
 
22
22
  loadCliScript(selectedConfig, req.body.query).subscribe({
23
- next: script => {
23
+ next: async script => {
24
24
  let functions = extractFunctionScript(script);
25
25
  if (functions) {
26
- res.send(functions.onInit(data));
26
+ res.send(await functions.onInit(data));
27
27
  console.log(`Run Callback Successfully!`);
28
28
  } else {
29
29
  res.send('CLI Script does not exist.');
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "biz-a-cli",
3
3
  "nameDev": "biz-a-cli-dev",
4
- "version": "2.3.7",
5
- "versionDev": "0.0.25",
4
+ "version": "2.3.8",
5
+ "versionDev": "0.0.27",
6
6
  "description": "",
7
7
  "main": "bin/index.js",
8
8
  "type": "module",
9
9
  "engines": {
10
- "node": "20.9.0",
11
- "npm": "10.1.0"
10
+ "node": "20.12.1",
11
+ "npm": "10.5.0"
12
12
  },
13
13
  "scripts": {
14
14
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch a",
15
15
  "test1": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
16
16
  "dev": "node --watch server.js",
17
- "hub": "node bin/hub.js"
17
+ "hub": "node --experimental-vm-modules bin/hub.js"
18
18
  },
19
19
  "author": "Imamatek",
20
20
  "license": "ISC",
@@ -35,6 +35,7 @@
35
35
  "nodemailer": "^6.9.12",
36
36
  "socket.io-client": "^4.7.5",
37
37
  "socket.io-stream": "^0.9.1",
38
+ "web-push": "^3.6.7",
38
39
  "yargs": "^17.7.2"
39
40
  },
40
41
  "devDependencies": {
@@ -44,4 +45,4 @@
44
45
  "jest": {
45
46
  "transform": {}
46
47
  }
47
- }
48
+ }
@@ -1,6 +1,17 @@
1
1
  import { map, tap } from "rxjs";
2
2
  import { Axios } from 'axios-observable';
3
+ import { runInThisContext, constants } from "vm";
3
4
  import { insertHistory } from "./watcherController.js";
5
+ import axios from "axios";
6
+ import * as dayjs from "dayjs";
7
+ import timezone from "dayjs/plugin/timezone.js";
8
+ import utc from "dayjs/plugin/utc.js"
9
+ import crypto from "crypto";
10
+
11
+ import customParseFormat from 'dayjs/plugin/customParseFormat.js'
12
+ dayjs.default.extend(customParseFormat)
13
+ dayjs.default.extend(timezone)
14
+ dayjs.default.extend(utc)
4
15
 
5
16
  // let BIZA_SERVER_LINK;
6
17
 
@@ -13,32 +24,32 @@ import { insertHistory } from "./watcherController.js";
13
24
 
14
25
  function mapData2Key(res, cols) {
15
26
  return res.map(e => {
16
- return cols.reduce((o, k) => {
27
+ return cols.reduce((o, k) => {
17
28
  o[k.key ? k.key : k.data] = e[k.data]
18
29
  return o;
19
30
  }, {})
20
31
  })
21
32
  }
22
33
 
23
- function hex2a(hexx) {
24
- let hex = hexx.toString();//force conversion
25
- let str = '';
26
- for (let i = 0; i < hex.length; i += 2)
27
- str += String.fromCharCode(parseInt(hex.slice(i, i + 2), 16));
28
- return str;
29
- }
34
+ // function hex2a(hexx) {
35
+ // let hex = hexx.toString();//force conversion
36
+ // let str = '';
37
+ // for (let i = 0; i < hex.length; i += 2)
38
+ // str += String.fromCharCode(parseInt(hex.slice(i, i + 2), 16));
39
+ // return str;
40
+ // }
30
41
 
31
- function deserialise(key, data) {
32
- if (data instanceof Array && data[0] == 'window.Function') {
33
- let f = Function(data[1], data[2].join("\r\n"));
34
- return f;
35
- } else {
36
- return data;
37
- }
38
- };
42
+ // function deserialise(key, data) {
43
+ // if (data instanceof Array && data[0] == 'window.Function') {
44
+ // let f = Function(data[1], data[2].join("\r\n"));
45
+ // return f;
46
+ // } else {
47
+ // return data;
48
+ // }
49
+ // };
39
50
 
40
51
  function getUrlApi(config, methodName, isPost = true) {
41
- return `${config.API_URL}/fina/rest/TOrmMethod/` +
52
+ return `${config.url}/fina/rest/TOrmMethod/` +
42
53
  `${isPost ? '%22' : ''}${methodName}${isPost ? '%22' : ''}`
43
54
  }
44
55
 
@@ -156,9 +167,16 @@ export function extractFunctionScript(data) {
156
167
  return
157
168
  }
158
169
  if (data.length == 0) return
159
- let hex = JSON.parse(hex2a(data[0].script))
160
- if (!hex.functions) return
161
- return JSON.parse(JSON.stringify(hex.functions), deserialise)
170
+
171
+ const scriptFn = runInThisContext(data[0].script, { importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER });
172
+ if (!scriptFn().functions) return
173
+ let lib = {
174
+ axios : axios.default,
175
+ dayjs : dayjs.default,
176
+ crypto: crypto
177
+ }
178
+ return scriptFn(lib).functions;
179
+ // return JSON.parse(JSON.stringify(scriptFn.functions), deserialise)
162
180
  }
163
181
 
164
182
  export function getQueryDataObsParameters(trigger) {
@@ -188,7 +206,7 @@ export function loadCliScript(selectedConfig, trigger) {
188
206
  }
189
207
 
190
208
  export function getInputData(config, trigger) {
191
- const urlAndPort = config.API_URL.split(':');
209
+ const urlAndPort = config.url.split(':');
192
210
  return {
193
211
  arguments: {
194
212
  hostname: urlAndPort[1].split('//')[1],
@@ -5,13 +5,6 @@ jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
5
5
  insertHistory: mockInsertHistory.mockResolvedValue('OK')
6
6
  }))
7
7
 
8
- // const mockModule = await import('../scheduler/datalib.js');
9
- // const mockExtractFunctionScript = jest.fn();
10
- // jest.unstable_mockModule("../scheduler/datalib.js", () => ({
11
- // ...mockModule,
12
- // extractFunctionScript: mockExtractFunctionScript
13
- // }))
14
-
15
8
  const {
16
9
  scheduleSubscription,
17
10
  getConfig,
@@ -20,14 +13,34 @@ const {
20
13
  } = await import('../scheduler/datalib.js');
21
14
 
22
15
  describe('data test', () => {
16
+ const SCRIPT = "get = function () {" +
17
+ " return {" +
18
+ " functions: {" +
19
+ " onInit: function (data) {" +
20
+ " const doit = async () => {" +
21
+ " const config = {" +
22
+ " url: `http://${data.arguments.hostname}:${data.arguments.port}`," +
23
+ " dbindex: data.arguments.dbindex," +
24
+ " subdomain: data.arguments.subdomain" +
25
+ " };" +
26
+ " };" +
27
+ " doit();" +
28
+ " return 'OK';" +
29
+ " }" +
30
+ " }" +
31
+ " }" +
32
+ "}";
33
+
23
34
  test('check schedule subscription no history', () => {
24
35
  const config = {
25
36
  _id: 'ffffffff2ae49fab9ea654e1',
26
- API_URL: 'http://localhost:212',
37
+ url: 'http://localhost:212',
27
38
  dbindex: 2,
28
39
  subdomain: 'abc'
29
40
  }
30
- const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
41
+ // const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
42
+ const data = [{ script: SCRIPT }];
43
+
31
44
  const trigger = {
32
45
  _id: 1,
33
46
  name: 'New Watcher 1',
@@ -40,12 +53,14 @@ describe('data test', () => {
40
53
  test('check schedule subscription with history', () => {
41
54
  const config = {
42
55
  _id: 'ffffffff2ae49fab9ea654e1',
43
- API_URL: 'http://localhost:212',
56
+ url: 'http://localhost:212',
44
57
  dbindex: 2,
45
58
  subdomain: 'abc'
46
59
  }
47
60
 
48
- const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
61
+ // const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
62
+ const data = [{ script: SCRIPT }];
63
+
49
64
  const trigger = {
50
65
  _id: 1,
51
66
  name: 'New Watcher 1'
@@ -58,7 +73,7 @@ describe('data test', () => {
58
73
  test('get input data', () => {
59
74
  const config = {
60
75
  _id: 'ffffffff2ae49fab9ea654e1',
61
- API_URL: 'http://localhost:212',
76
+ url: 'http://localhost:212',
62
77
  dbindex: 2,
63
78
  subdomain: 'abc'
64
79
  }
@@ -86,7 +101,7 @@ describe('data test', () => {
86
101
  test('get config', () => {
87
102
  const config = {
88
103
  _id: 'ffffffff2ae49fab9ea654e1',
89
- API_URL: 'localhost'
104
+ url: 'localhost'
90
105
  }
91
106
 
92
107
  expect(getConfig(config)).toStrictEqual(config);
@@ -95,18 +110,23 @@ describe('data test', () => {
95
110
  test('get config array', () => {
96
111
  const config = [{
97
112
  _id: 'ffffffff2ae49fab9ea654e1',
98
- API_URL: 'localhost'
113
+ url: 'localhost'
99
114
  }]
100
115
 
101
116
  expect(getConfig(config)).toStrictEqual(config[0]);
102
117
  });
103
118
 
104
- // test('get config array', () => {
105
- // const trigger = {
106
- // _id: 'abc'
107
- // }
119
+ test('get query data parameter', () => {
120
+ const trigger = {
121
+ scriptid: 12
122
+ }
123
+
124
+ expect(getQueryDataObsParameters(trigger)).toStrictEqual({
125
+ length: 1,
126
+ filter: [{ junction: '', column: 'ID', operator: '=', value1: '12' }],
127
+ columns: [{ data: "SYS$CLI_SCRIPT.SCRIPT", key: 'script' }]
128
+ });
129
+ });
108
130
 
109
- // expect(getQueryDataObsParameters(trigger)).toStrictEqual();
110
- // });
111
131
  })
112
132
 
package/tests/hub.test.js CHANGED
@@ -61,24 +61,49 @@ describe('cli req test', () => {
61
61
  })
62
62
 
63
63
  test('request to cli', async () => {
64
- jest.spyOn(Axios, 'request').mockReturnValue(of({ data: 'OK' }));
64
+ let mockedRequest = jest.spyOn(Axios, 'request').mockReturnValue(of({ data: 'OK' }));
65
65
 
66
66
  let socket;
67
67
  try {
68
68
  socket = ioc(`http://localhost:${port}`);
69
-
70
69
  await hubEvent(socket, {
71
70
  server: `http://localhost:${port}`,
72
71
  subdomain: 'scy',
73
72
  hostname: 'localhost',
74
73
  port: 212,
74
+ serverport: 3002
75
+ });
76
+
77
+ let result = await toPromise(resolve => socketsBySubdomain['scy'].emit(
78
+ 'cli-req', {
79
+ // path: '/a/b',
80
+ method: 'POST',
81
+ query: { subdomain: 'abc' }, body: { data: 'xyz' }
82
+ }, cb => resolve(cb)
83
+ ))
84
+
85
+ expect(result).toStrictEqual('OK');
86
+ expect(mockedRequest).toHaveBeenCalledWith({
87
+ data: { body: { data: "xyz" }, query: { subdomain: "abc" } },
88
+ method: "POST",
89
+ url: "http://localhost:3002/cb"
75
90
  });
76
91
 
77
- const result = await toPromise(resolve => socketsBySubdomain['scy'].emit(
78
- 'cli-req', { d: 1 }, cb => resolve(cb)
92
+ result = await toPromise(resolve => socketsBySubdomain['scy'].emit(
93
+ 'cli-req', {
94
+ path: '/a/b',
95
+ method: 'POST',
96
+ query: { subdomain: 'abc' }, body: { data: 'xyz' }
97
+ }, cb => resolve(cb)
79
98
  ))
80
99
 
81
100
  expect(result).toStrictEqual('OK');
101
+ expect(mockedRequest).toHaveBeenCalledWith({
102
+ data: { body: { data: "xyz" }, query: { subdomain: "abc" } },
103
+ method: "POST",
104
+ url: "http://localhost:3002/cb/a/b",
105
+ });
106
+
82
107
  socket.disconnect();
83
108
  } catch (error) {
84
109
  console.log(error);