biz-a-cli 2.3.3 → 2.3.4
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/hub.js +13 -4
- package/callbackController.js +25 -10
- package/envs/env.dev.js +1 -1
- package/envs/env.js +0 -1
- package/package.json +2 -2
- package/scheduler/configController.js +9 -9
- package/scheduler/datalib.js +21 -4
- package/scheduler/timer.js +1 -2
- package/tests/callback.test.js +40 -0
- package/tests/data.test.js +36 -4
- package/tests/hub.test.js +1 -1
package/bin/hub.js
CHANGED
|
@@ -22,21 +22,28 @@ const argv = yargs(process.argv.slice(2))
|
|
|
22
22
|
.options('h', {
|
|
23
23
|
alias: 'hostname',
|
|
24
24
|
default: '127.0.0.1',
|
|
25
|
-
describe: 'Address of local server for forwarding over socket-tunnel',
|
|
25
|
+
describe: '(Required) Address of local server for forwarding over socket-tunnel',
|
|
26
26
|
type: 'string',
|
|
27
27
|
demandOption: true
|
|
28
28
|
})
|
|
29
|
+
.options('d', {
|
|
30
|
+
alias: 'dbindex',
|
|
31
|
+
default: 2,
|
|
32
|
+
describe: '(Required) Biz-A Database Index (Callback Feature)',
|
|
33
|
+
type: 'number',
|
|
34
|
+
demandOption: false
|
|
35
|
+
})
|
|
29
36
|
.options('p', {
|
|
30
37
|
alias: 'port',
|
|
31
38
|
default: 212,
|
|
32
|
-
describe: '
|
|
39
|
+
describe: 'Port of local server for forwarding over socket-tunnel',
|
|
33
40
|
type: 'number',
|
|
34
|
-
demandOption:
|
|
41
|
+
demandOption: false
|
|
35
42
|
})
|
|
36
43
|
.options('sp', {
|
|
37
44
|
alias: 'serverport',
|
|
38
45
|
default: 3002,
|
|
39
|
-
describe: '
|
|
46
|
+
describe: 'Express Port (Callback Feature)',
|
|
40
47
|
type: 'number',
|
|
41
48
|
demandOption: false
|
|
42
49
|
})
|
|
@@ -67,6 +74,8 @@ import { runCliScript } from '../callbackController.js'
|
|
|
67
74
|
app.use(cors());
|
|
68
75
|
app.use(express.json());
|
|
69
76
|
|
|
77
|
+
app.set('args', argv);
|
|
78
|
+
|
|
70
79
|
app.use('/cb', runCliScript);
|
|
71
80
|
const port = 3002;
|
|
72
81
|
|
package/callbackController.js
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import { loadCliScript, extractFunctionScript } from "./scheduler/datalib.js";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function getInputScript(req) {//
|
|
5
|
+
const args = req.app.settings.args;
|
|
6
|
+
return {
|
|
7
|
+
data: {
|
|
8
|
+
arguments: args,
|
|
9
|
+
body: req.body.body
|
|
10
|
+
},
|
|
11
|
+
selectedConfig: {
|
|
12
|
+
API_URL: `http://${args.hostname}:${args.port}`,
|
|
13
|
+
dbindex: args.dbindex,
|
|
14
|
+
subdomain: args.subdomain
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
3
18
|
|
|
4
19
|
export async function runCliScript(req, res) {
|
|
5
|
-
const data = req
|
|
6
|
-
const company = await getCompanyObjectId(data.query.companyId);
|
|
7
|
-
const config = await getSelectedConfig(company._id);
|
|
8
|
-
const selectedConfig = config[0];
|
|
20
|
+
const { data, selectedConfig } = getInputScript(req);
|
|
9
21
|
|
|
10
|
-
loadCliScript(selectedConfig,
|
|
11
|
-
next:
|
|
12
|
-
let functions = extractFunctionScript(
|
|
13
|
-
res.send(functions.onInit(
|
|
22
|
+
loadCliScript(selectedConfig, req.body.query).subscribe({
|
|
23
|
+
next: script => {
|
|
24
|
+
let functions = extractFunctionScript(script);
|
|
25
|
+
res.send(functions.onInit(data));
|
|
14
26
|
|
|
15
27
|
console.log(`Run Callback Successfully!`);
|
|
16
28
|
},
|
|
17
|
-
error: error =>
|
|
29
|
+
error: error => {
|
|
30
|
+
console.error(error);
|
|
31
|
+
throw new Error(error);
|
|
32
|
+
}
|
|
18
33
|
})
|
|
19
34
|
}
|
package/envs/env.dev.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const envDev = {
|
|
2
2
|
production: false,
|
|
3
|
-
cdmUrl: 'https://imm-cdm-dev.herokuapp.com',
|
|
4
3
|
BIZA_MONGO_LINK: 'mongodb+srv://imm_biza:' +
|
|
5
4
|
encodeURIComponent('imm@2023') + '@cluster0.z2yr8kp.mongodb.net/?retryWrites=true&w=majority',
|
|
6
5
|
CDM_MONGO_LINK: 'mongodb+srv://imm_cdm:' +
|
|
7
6
|
encodeURIComponent('imm@2019') + '@imm-cdm-dev.rf6wr.mongodb.net/?retryWrites=true&w=majority',
|
|
8
7
|
COMPANY_REGISTER: 'companyregister-dev',
|
|
9
8
|
BIZA_SERVER_LINK: 'https://biz-a-dev-41e7c93a25e5.herokuapp.com'
|
|
9
|
+
// BIZA_SERVER_LINK: 'http://localhost:3000'
|
|
10
10
|
};
|
package/envs/env.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const env = {
|
|
2
2
|
production: true,
|
|
3
|
-
cdmUrl: 'https://imm-cdm.herokuapp.com',
|
|
4
3
|
BIZA_MONGO_LINK: 'mongodb+srv://imm_biza:' +
|
|
5
4
|
encodeURIComponent('imm@2023') + '@cluster0.lezywmk.mongodb.net/?retryWrites=true&w=majority',
|
|
6
5
|
CDM_MONGO_LINK: 'mongodb+srv://imm_cdm:' +
|
package/package.json
CHANGED
|
@@ -7,17 +7,17 @@ let CDM_MONGO_LINK;
|
|
|
7
7
|
let COMPANY_REGISTER;
|
|
8
8
|
|
|
9
9
|
// if ((process.env.NODE_ENV == undefined) || (process.env.NODE_ENV == 'development')) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// BIZA_MONGO_LINK = envDev.BIZA_MONGO_LINK;
|
|
11
|
+
// CDM_MONGO_LINK = envDev.CDM_MONGO_LINK;
|
|
12
|
+
// COMPANY_REGISTER = envDev.COMPANY_REGISTER;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// console.log('BIZA_MONGO_LINK =>', BIZA_MONGO_LINK);
|
|
15
|
+
// console.log('CDM_MONGO_LINK =>', CDM_MONGO_LINK);
|
|
16
|
+
// console.log('COMPANY_REGISTER =>', COMPANY_REGISTER);
|
|
17
17
|
// } else {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
BIZA_MONGO_LINK = env.BIZA_MONGO_LINK;
|
|
19
|
+
CDM_MONGO_LINK = env.CDM_MONGO_LINK;
|
|
20
|
+
COMPANY_REGISTER = env.COMPANY_REGISTER;
|
|
21
21
|
// }
|
|
22
22
|
|
|
23
23
|
async function fetchSelectedConfig(aggregateField) {
|
package/scheduler/datalib.js
CHANGED
|
@@ -134,6 +134,7 @@ export function extractFunctionScript(data) {
|
|
|
134
134
|
return
|
|
135
135
|
}
|
|
136
136
|
if (data.length == 0) return
|
|
137
|
+
|
|
137
138
|
let hex = JSON.parse(hex2a(data[0].template))
|
|
138
139
|
//sementara ke template dahulu
|
|
139
140
|
// let hex = JSON.parse(hex2a(data[0].script))
|
|
@@ -145,8 +146,8 @@ export function extractFunctionScript(data) {
|
|
|
145
146
|
export function getQueryDataObsParameters(trigger) {
|
|
146
147
|
return {
|
|
147
148
|
length: 1,
|
|
148
|
-
|
|
149
|
-
filter: [{ junction: '', column: 'FILENAME', operator: '=', value1: `'
|
|
149
|
+
|
|
150
|
+
filter: [{ junction: '', column: 'FILENAME', operator: '=', value1: `'${trigger.filename}'` }],
|
|
150
151
|
columns: [{ data: "TEMPLATE.TEMPLATE", key: 'template' }]
|
|
151
152
|
|
|
152
153
|
//sementara ke template dahulu
|
|
@@ -173,11 +174,24 @@ export function loadCliScript(selectedConfig, trigger) {
|
|
|
173
174
|
)
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
export function getInputData(config, trigger) {
|
|
178
|
+
const urlAndPort = config.API_URL.split(':');
|
|
179
|
+
return {
|
|
180
|
+
arguments: {
|
|
181
|
+
hostname: urlAndPort[1].split('//')[1],
|
|
182
|
+
port: +urlAndPort[2],
|
|
183
|
+
dbindex: config.dbindex,
|
|
184
|
+
subdomain: config.subdomain
|
|
185
|
+
},
|
|
186
|
+
body: trigger.data
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
176
190
|
export function scheduleSubscription(config, data, trigger, needSetHistory, isTest = false) {
|
|
177
191
|
try {
|
|
178
192
|
let functions = extractFunctionScript(data);
|
|
179
193
|
if (!isTest) { // next, change isTest to test better
|
|
180
|
-
functions.onInit(config, trigger
|
|
194
|
+
functions.onInit(getInputData(config, trigger));
|
|
181
195
|
}
|
|
182
196
|
|
|
183
197
|
if (needSetHistory) {
|
|
@@ -195,6 +209,9 @@ export function scheduleSubscription(config, data, trigger, needSetHistory, isTe
|
|
|
195
209
|
export function checkSchedule(selectedConfig, trigger, needSetHistory) {
|
|
196
210
|
loadCliScript(selectedConfig, trigger).subscribe({
|
|
197
211
|
next: data => scheduleSubscription(selectedConfig, data, trigger, needSetHistory),
|
|
198
|
-
error: error =>
|
|
212
|
+
error: error => {
|
|
213
|
+
console.error(error);
|
|
214
|
+
throw new Error(error);
|
|
215
|
+
}
|
|
199
216
|
})
|
|
200
217
|
}
|
package/scheduler/timer.js
CHANGED
|
@@ -50,14 +50,13 @@ export async function runHistory(histories, config, watchers, now) {
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
export const runScheduler = async (companyName) => {
|
|
53
|
-
await delay(30000);
|
|
53
|
+
// await delay(30000);
|
|
54
54
|
|
|
55
55
|
const company = await getCompanyObjectId(companyName);
|
|
56
56
|
const config = await getSelectedConfig(company._id);
|
|
57
57
|
|
|
58
58
|
forkJoin([getHistories(config[0]), getWatchers(config[0])]).subscribe({
|
|
59
59
|
next: ([historyResult, watcherResult]) => {
|
|
60
|
-
|
|
61
60
|
const histories = historyRecordToJson(historyResult);
|
|
62
61
|
const watchers = watcherRecordToJson(watcherResult);
|
|
63
62
|
runHistory(histories, config[0], watchers, new Date());
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// import { jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
// const mockInsertHistory = jest.fn();
|
|
4
|
+
// jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
|
|
5
|
+
// insertHistory: mockInsertHistory.mockResolvedValue('OK')
|
|
6
|
+
// }))
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
getInputScript
|
|
10
|
+
} = await import('../callbackController.js');
|
|
11
|
+
|
|
12
|
+
describe('callback test', () => {
|
|
13
|
+
test('get input script', () => {
|
|
14
|
+
const args = {
|
|
15
|
+
hostname: 'localhost',
|
|
16
|
+
port: 212,
|
|
17
|
+
dbindex: 2,
|
|
18
|
+
subdomain: 'abc'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const request = {
|
|
22
|
+
app: { settings: { args: args } },
|
|
23
|
+
body: { body: { body1: 'value1' } }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
expect(getInputScript(request)).toStrictEqual({
|
|
27
|
+
data: {
|
|
28
|
+
arguments: args,
|
|
29
|
+
body: { body1: 'value1' }
|
|
30
|
+
},
|
|
31
|
+
selectedConfig: {
|
|
32
|
+
API_URL: 'http://localhost:212',
|
|
33
|
+
dbindex: 2,
|
|
34
|
+
subdomain: 'abc'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
})
|
|
40
|
+
|
package/tests/data.test.js
CHANGED
|
@@ -15,6 +15,7 @@ jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
|
|
|
15
15
|
const {
|
|
16
16
|
scheduleSubscription,
|
|
17
17
|
getConfig,
|
|
18
|
+
getInputData,
|
|
18
19
|
getQueryDataObsParameters,
|
|
19
20
|
} = await import('../scheduler/datalib.js');
|
|
20
21
|
|
|
@@ -22,9 +23,10 @@ describe('data test', () => {
|
|
|
22
23
|
test('check schedule subscription no history', () => {
|
|
23
24
|
const config = {
|
|
24
25
|
_id: 'ffffffff2ae49fab9ea654e1',
|
|
25
|
-
API_URL: 'localhost'
|
|
26
|
+
API_URL: 'http://localhost:212',
|
|
27
|
+
dbindex: 2,
|
|
28
|
+
subdomain: 'abc'
|
|
26
29
|
}
|
|
27
|
-
|
|
28
30
|
const data = [{ template: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
|
|
29
31
|
const trigger = {
|
|
30
32
|
_id: 1,
|
|
@@ -38,19 +40,49 @@ describe('data test', () => {
|
|
|
38
40
|
test('check schedule subscription with history', () => {
|
|
39
41
|
const config = {
|
|
40
42
|
_id: 'ffffffff2ae49fab9ea654e1',
|
|
41
|
-
API_URL: 'localhost'
|
|
43
|
+
API_URL: 'http://localhost:212',
|
|
44
|
+
dbindex: 2,
|
|
45
|
+
subdomain: 'abc'
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
const data = [{ template: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
|
|
45
49
|
const trigger = {
|
|
46
50
|
_id: 1,
|
|
47
|
-
name: 'New Watcher 1'
|
|
51
|
+
name: 'New Watcher 1'
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
scheduleSubscription(config, data, trigger, true, true);
|
|
51
55
|
expect(mockInsertHistory).toBeCalledTimes(1);
|
|
52
56
|
});
|
|
53
57
|
|
|
58
|
+
test('get input data', () => {
|
|
59
|
+
const config = {
|
|
60
|
+
_id: 'ffffffff2ae49fab9ea654e1',
|
|
61
|
+
API_URL: 'http://localhost:212',
|
|
62
|
+
dbindex: 2,
|
|
63
|
+
subdomain: 'abc'
|
|
64
|
+
}
|
|
65
|
+
const trigger = {
|
|
66
|
+
data: {
|
|
67
|
+
_id: 1,
|
|
68
|
+
name: 'New Watcher 1'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
expect(getInputData(config, trigger)).toStrictEqual({
|
|
73
|
+
arguments: {
|
|
74
|
+
hostname: 'localhost',
|
|
75
|
+
port: 212,
|
|
76
|
+
dbindex: 2,
|
|
77
|
+
subdomain: 'abc'
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
_id: 1,
|
|
81
|
+
name: 'New Watcher 1'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
54
86
|
test('get config', () => {
|
|
55
87
|
const config = {
|
|
56
88
|
_id: 'ffffffff2ae49fab9ea654e1',
|
package/tests/hub.test.js
CHANGED