biz-a-cli 2.3.55 → 2.3.56
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/app.js +1 -1
- package/bin/deleteApp.js +2 -1
- package/bin/hub.js +3 -2
- package/bin/hubEvent.js +25 -12
- package/bin/index.js +2 -1
- package/bin/uploadApp.js +1 -4
- package/envs/env.dev.js +1 -1
- package/envs/env.js +2 -1
- package/package.json +1 -1
- package/readme.md +6 -6
- package/scheduler/datalib.js +0 -11
- package/tests/hub.test.js +70 -22
package/bin/app.js
CHANGED
|
@@ -16,7 +16,7 @@ const keyFolderPath = process.argv[1].substring(0, process.argv[1].lastIndexOf("
|
|
|
16
16
|
yargs(process.argv.slice(2))
|
|
17
17
|
.option("s", {
|
|
18
18
|
alias: "server",
|
|
19
|
-
describe:
|
|
19
|
+
describe: `Server URL (ex: ${env.BIZA_SERVER_LINK} or http://192.168.1.1 or https://finaapi.imamatek.com)`,
|
|
20
20
|
type: "string",
|
|
21
21
|
demandOption: true
|
|
22
22
|
})
|
package/bin/deleteApp.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import yargs from "yargs";
|
|
4
4
|
import axios from "axios";
|
|
5
|
+
import { env } from "../envs/env.js"
|
|
5
6
|
|
|
6
7
|
const options = yargs(process.argv.slice(2))
|
|
7
8
|
.option("s", {
|
|
8
9
|
alias: "server",
|
|
9
|
-
describe:
|
|
10
|
+
describe: `Server URL (ex: ${env.BIZA_SERVER_LINK} or http://192.168.1.1 or https://finaapi.imamatek.com)`,
|
|
10
11
|
type: "string",
|
|
11
12
|
demandOption: true
|
|
12
13
|
})
|
package/bin/hub.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createLogger, transports, format } from "winston";
|
|
|
7
7
|
import { Server as ioServer } from 'socket.io'
|
|
8
8
|
import os from 'node:os'
|
|
9
9
|
import { directHubEvent, localhostTunnel }from './directHubEvent.js'
|
|
10
|
+
import { env } from "../envs/env.js"
|
|
10
11
|
|
|
11
12
|
const logger = createLogger({
|
|
12
13
|
level: 'info',
|
|
@@ -35,7 +36,7 @@ const argv = yargs(process.argv.slice(2))
|
|
|
35
36
|
.usage('Usage: $0 [options]')
|
|
36
37
|
.options('s', {
|
|
37
38
|
alias: 'server',
|
|
38
|
-
default:
|
|
39
|
+
default: env.BIZA_SERVER_LINK,
|
|
39
40
|
describe: '(Required) Tunnel server endpoint',
|
|
40
41
|
type: 'string',
|
|
41
42
|
demandOption: false
|
|
@@ -87,7 +88,7 @@ const argv = yargs(process.argv.slice(2))
|
|
|
87
88
|
demandOption: false
|
|
88
89
|
})
|
|
89
90
|
.options('hub', {
|
|
90
|
-
default:
|
|
91
|
+
default: `${env.BIZA_HUB_SERVER_LINK}`,
|
|
91
92
|
describe: 'BizA hub',
|
|
92
93
|
type: 'string',
|
|
93
94
|
demandOption: false
|
package/bin/hubEvent.js
CHANGED
|
@@ -136,24 +136,37 @@ export const hubEvent = (socket, argv, notifier)=>{
|
|
|
136
136
|
|
|
137
137
|
export const apiRequestListener = (socket, argv)=>{
|
|
138
138
|
socket.on('apiRequest', (reqData, resCB)=>{
|
|
139
|
+
|
|
140
|
+
let apiAddress = `${argv['secure']==true ? 'https://' : 'http://'}${argv['hostname']}:${argv['port']}`
|
|
141
|
+
let reqBody = reqData.body
|
|
142
|
+
try{
|
|
143
|
+
let parsedBody = (typeof reqData.body==='object') ? reqBody : JSON.parse(reqBody)
|
|
144
|
+
if (parsedBody.apiAddress){
|
|
145
|
+
apiAddress = parsedBody.apiAddress
|
|
146
|
+
delete parsedBody.apiAddress
|
|
147
|
+
reqBody = (typeof reqData.body==='string') ? JSON.stringify(parsedBody) : parsedBody
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {}
|
|
150
|
+
|
|
139
151
|
const socketResponse = (resp)=>{return {
|
|
140
152
|
status: resp.status,
|
|
141
153
|
statusText: resp.statusText,
|
|
142
154
|
headers: resp.headers,
|
|
143
|
-
body: resp.data,
|
|
155
|
+
body: resp.data,
|
|
156
|
+
url: apiAddress + resp.config.url
|
|
144
157
|
}}
|
|
158
|
+
|
|
145
159
|
if (argv['subdomain'].localeCompare(reqData.subDomain)==0) {
|
|
146
|
-
const apiAddress = `${argv['secure']==true ? 'https://' : 'http://'}${argv['hostname']}:${argv['port']}`
|
|
147
160
|
axios.request({
|
|
148
|
-
timeout: (reqData.timeout || IDLE_SOCKET_TIMEOUT_MILLISECONDS),
|
|
149
|
-
baseURL: apiAddress,
|
|
150
|
-
url: reqData.path,
|
|
151
|
-
method: reqData.method,
|
|
152
|
-
headers: reqData.headers,
|
|
153
|
-
data:
|
|
154
|
-
// decompress: false, // if we need to interfered default Agent compression
|
|
155
|
-
responseType: reqData.responseType,
|
|
156
|
-
maxContentLength: Infinity,
|
|
161
|
+
timeout : (reqData.timeout || IDLE_SOCKET_TIMEOUT_MILLISECONDS),
|
|
162
|
+
baseURL : apiAddress,
|
|
163
|
+
url : reqData.path,
|
|
164
|
+
method : reqData.method,
|
|
165
|
+
headers : reqData.headers,
|
|
166
|
+
data : reqBody,
|
|
167
|
+
// decompress : false, // if we need to interfered default Agent compression
|
|
168
|
+
responseType : reqData.responseType,
|
|
169
|
+
maxContentLength : Infinity,
|
|
157
170
|
})
|
|
158
171
|
.then(response=>{
|
|
159
172
|
resCB(null, socketResponse(response))
|
|
@@ -163,7 +176,7 @@ export const apiRequestListener = (socket, argv)=>{
|
|
|
163
176
|
})
|
|
164
177
|
}
|
|
165
178
|
else {
|
|
166
|
-
resCB({status: 401, statusText: 'bad subdomain', url:
|
|
179
|
+
resCB({status: 401, statusText: 'bad subdomain', url: apiAddress + reqData.path}, null)
|
|
167
180
|
}
|
|
168
181
|
})
|
|
169
182
|
}
|
package/bin/index.js
CHANGED
|
@@ -4,11 +4,12 @@ import yargs from "yargs";
|
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
import { promises as fs } from "fs";
|
|
6
6
|
import { runInThisContext } from "vm";
|
|
7
|
+
import { env } from "../envs/env.js"
|
|
7
8
|
|
|
8
9
|
const options = yargs(process.argv.slice(2))
|
|
9
10
|
.option("s", {
|
|
10
11
|
alias: "server",
|
|
11
|
-
describe:
|
|
12
|
+
describe: `Server URL (ex: ${env.BIZA_SERVER_LINK} or http://192.168.1.1 or https://finaapi.imamatek.com)`,
|
|
12
13
|
type: "string",
|
|
13
14
|
demandOption: true
|
|
14
15
|
})
|
package/bin/uploadApp.js
CHANGED
|
@@ -10,14 +10,13 @@ import {statSync, readFileSync} from 'fs';
|
|
|
10
10
|
import { verify, sign, privateDecrypt, constants as cryptoConstants, randomBytes, createCipheriv } from 'node:crypto';
|
|
11
11
|
import { basename } from "node:path"
|
|
12
12
|
import { env } from '../envs/env.js';
|
|
13
|
-
import { stringify } from "querystring";
|
|
14
13
|
|
|
15
14
|
const keyFolderPath = process.argv[1].substring(0, process.argv[1].lastIndexOf("\\bin")) + "\\key"
|
|
16
15
|
|
|
17
16
|
const options = yargs(process.argv.slice(2))
|
|
18
17
|
.option("s", {
|
|
19
18
|
alias: "server",
|
|
20
|
-
describe:
|
|
19
|
+
describe: `Server URL (ex: ${env.BIZA_SERVER_LINK} or http://192.168.1.1 or https://finaapi.imamatek.com)`,
|
|
21
20
|
type: "string",
|
|
22
21
|
demandOption: true
|
|
23
22
|
})
|
|
@@ -124,7 +123,6 @@ const getFileMinifiedData = async (fileName) => {
|
|
|
124
123
|
stringifyData = JSON.stringify((typeof lib.default=='function') ? lib.default() : lib.default, replacer)
|
|
125
124
|
stringifyData = stringifyData.replace(/ /g,'') // remove trailing whitespace
|
|
126
125
|
// stringifyData = stringifyData.replace(/\\r\\n/g,'') // remove line break. We don't do this because "inline css" still requires line breaks
|
|
127
|
-
// console.log('RESULT =>', stringifyData)
|
|
128
126
|
printInfo(['Stringify : \n', stringifyData].join(''))
|
|
129
127
|
} catch (error){
|
|
130
128
|
throw(error)
|
|
@@ -138,7 +136,6 @@ const prepareKeys = async ()=>{
|
|
|
138
136
|
const data = Buffer.from(JSON.stringify({issuer: 'CLI', acquirer: 'Client'})).toString('base64')
|
|
139
137
|
const privateKey = readFileSync(`${keyFolderPath}\\cliPrivate.pem`)
|
|
140
138
|
const signature = sign('sha256', data, {key: privateKey, passphrase: 'Biz-A@cli', padding: cryptoConstants.RSA_PKCS1_PSS_PADDING}).toString('base64')
|
|
141
|
-
// const res = await axios.get('https://biz-a.herokuapp.com/api/issuerKey', {data, signature})
|
|
142
139
|
const res = await axios.get(env.BIZA_SERVER_LINK+'/api/issuerKey', {params: {data, signature}})
|
|
143
140
|
if ((res.data.data!=null) && verify('sha256', res.data.data, {key: readFileSync(`${keyFolderPath}\\serverPublic.pem`), padding: cryptoConstants.RSA_PKCS1_PSS_PADDING}, Buffer.from(res.data.signature, 'base64'))) {
|
|
144
141
|
const resData = JSON.parse(Buffer.from(res.data.data, 'base64').toString())
|
package/envs/env.dev.js
CHANGED
|
@@ -6,5 +6,5 @@ export const envDev = {
|
|
|
6
6
|
encodeURIComponent('imm@2019') + '@imm-cdm-dev.rf6wr.mongodb.net/?retryWrites=true&w=majority',
|
|
7
7
|
COMPANY_REGISTER: 'companyregister-dev',
|
|
8
8
|
BIZA_SERVER_LINK: 'https://biz-a-dev-41e7c93a25e5.herokuapp.com',
|
|
9
|
-
|
|
9
|
+
BIZA_HUB_SERVER_LINK: 'https://hub.biz-a.id'
|
|
10
10
|
};
|
package/envs/env.js
CHANGED
|
@@ -5,5 +5,6 @@ export const env = {
|
|
|
5
5
|
CDM_MONGO_LINK: 'mongodb+srv://imm_cdm:' +
|
|
6
6
|
encodeURIComponent('imm@2019') + '@imm-cdm.ohcqt.mongodb.net/?retryWrites=true&w=majority',
|
|
7
7
|
COMPANY_REGISTER: 'companyregister',
|
|
8
|
-
BIZA_SERVER_LINK: 'https://biz-a.
|
|
8
|
+
BIZA_SERVER_LINK: 'https://server.biz-a.id',
|
|
9
|
+
BIZA_HUB_SERVER_LINK: 'https://hub.biz-a.id'
|
|
9
10
|
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
## I. Add BizA App
|
|
5
5
|
|
|
6
|
-
### a. Using
|
|
6
|
+
### a. Using IP Address
|
|
7
7
|
|
|
8
8
|
BizA add -s [IP of FINA API] -p [default: 212] -i [dbindex] -d [full or relative path to app folder]
|
|
9
9
|
|
|
10
10
|
Example :
|
|
11
11
|
BizA add -s http://192.168.1.1 -i 2 -d “c:\biza templates\imamatek”
|
|
12
|
-
BizA add -s
|
|
12
|
+
BizA add -s localhost -p 1205 -i 2 -d “c:\biza templates\imamatek”
|
|
13
13
|
|
|
14
14
|
### b. Using BizA Hub
|
|
15
15
|
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
hub --server [BizA Hub Server] --sub [subdomain] --hostname [ip_API] --port [port_API]
|
|
71
71
|
|
|
72
72
|
Example :
|
|
73
|
-
hub --server https://biz-a.
|
|
73
|
+
hub --server https://server.biz-a.id --sub imamatek --hostname localhost --port 212
|
|
74
74
|
|
|
75
75
|
### b. Using HTTPs (SSL)
|
|
76
76
|
hub --server [BizA Hub Server] --sub [subdomain] --hostname [ip_API] --port [port_API] --secure
|
|
77
77
|
|
|
78
78
|
Example :
|
|
79
|
-
hub --server https://biz-a.
|
|
80
|
-
|
|
79
|
+
hub --server https://server.biz-a.id --sub imamatek --hostname localhost --port 212 --secure
|
|
80
|
+
|
|
81
81
|
### c. Publish Hub
|
|
82
82
|
hub --server [BizA Hub Server] --sub [subdomain] --hostname [ip_API] --port [port_API] --publish [true]
|
|
83
83
|
|
|
84
84
|
Example :
|
|
85
|
-
hub --server https://biz-a.
|
|
85
|
+
hub --server https://server.biz-a.id --sub imamatek --hostname localhost --port 212 --publish
|
package/scheduler/datalib.js
CHANGED
|
@@ -25,17 +25,6 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
25
25
|
logger.add(new transports.Console({ format: format.simple(), level: 'info' }))
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// let BIZA_SERVER_LINK;
|
|
31
|
-
|
|
32
|
-
// // if ((process.env.NODE_ENV == undefined) || (process.env.NODE_ENV == 'development')) {
|
|
33
|
-
// if ((MODE == undefined) || (MODE == 'development')) {
|
|
34
|
-
// BIZA_SERVER_LINK = envDev.BIZA_SERVER_LINK;
|
|
35
|
-
// } else {
|
|
36
|
-
// BIZA_SERVER_LINK = env.BIZA_SERVER_LINK;
|
|
37
|
-
// };
|
|
38
|
-
|
|
39
28
|
export function mapData2Key(res, cols) {
|
|
40
29
|
return res.map(e => {
|
|
41
30
|
return cols.reduce((o, k) => {
|
package/tests/hub.test.js
CHANGED
|
@@ -268,7 +268,7 @@ describe('Hub event tests', () => {
|
|
|
268
268
|
statusText: 'Success',
|
|
269
269
|
headers: {'res-header': 'aa'},
|
|
270
270
|
body: 'body of response',
|
|
271
|
-
url:
|
|
271
|
+
url: `http://${apiAddress}:${port}/test`
|
|
272
272
|
})
|
|
273
273
|
|
|
274
274
|
expect(error).toBe(null)
|
|
@@ -335,7 +335,7 @@ describe('Hub event tests', () => {
|
|
|
335
335
|
expect(error).toStrictEqual({
|
|
336
336
|
status: 401,
|
|
337
337
|
statusText: 'bad subdomain',
|
|
338
|
-
url:
|
|
338
|
+
url: `http://${apiAddress}:${port}/test`
|
|
339
339
|
})
|
|
340
340
|
|
|
341
341
|
expect(mockedRequest).not.toHaveBeenCalledWith()
|
|
@@ -349,16 +349,6 @@ describe('Hub event tests', () => {
|
|
|
349
349
|
let hubServer
|
|
350
350
|
|
|
351
351
|
try {
|
|
352
|
-
mockedRequest = jest.spyOn(axios, 'request')
|
|
353
|
-
mockedRequest.mockClear()
|
|
354
|
-
mockedRequest.mockResolvedValueOnce({
|
|
355
|
-
status: 200,
|
|
356
|
-
statusText: 'Success',
|
|
357
|
-
headers: {'res-header': 'aa'},
|
|
358
|
-
data: 'body of response',
|
|
359
|
-
config: {baseURL: 'localhost', url: '/test'}
|
|
360
|
-
})
|
|
361
|
-
|
|
362
352
|
hubServer = new ioServer(9998)
|
|
363
353
|
hubServer.on('connection', (sock)=>hubToCLISocket = sock)
|
|
364
354
|
|
|
@@ -381,24 +371,37 @@ describe('Hub event tests', () => {
|
|
|
381
371
|
|
|
382
372
|
await toPromise(resolve => cliToHubSocket.once('connect', ()=>resolve()))
|
|
383
373
|
|
|
384
|
-
const
|
|
374
|
+
const emitApiRequest = async (reqData)=>{
|
|
375
|
+
const [error, response] = await toPromise(resolve => {
|
|
385
376
|
hubToCLISocket.emit(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
377
|
+
'apiRequest'
|
|
378
|
+
, {subDomain: subdomain, method: 'POST', path: '/test', headers: {'req-header': 'aa'}, body: reqData, responseType: 'json'}
|
|
379
|
+
, (res, err)=>{resolve([res, err])}
|
|
380
|
+
)
|
|
381
|
+
})
|
|
382
|
+
return {error, response}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
mockedRequest = jest.spyOn(axios, 'request')
|
|
386
|
+
mockedRequest.mockResolvedValue({
|
|
387
|
+
status: 200,
|
|
388
|
+
statusText: 'Success',
|
|
389
|
+
headers: {'res-header': 'aa'},
|
|
390
|
+
data: 'body of response',
|
|
391
|
+
config: {baseURL: 'localhost', url: '/test'}
|
|
390
392
|
})
|
|
391
393
|
|
|
392
|
-
|
|
394
|
+
// without parameterize apiAddress
|
|
395
|
+
mockedRequest.mockClear()
|
|
396
|
+
let result = await emitApiRequest('body of request')
|
|
397
|
+
expect(result.response).toStrictEqual({
|
|
393
398
|
status: 200,
|
|
394
399
|
statusText: 'Success',
|
|
395
400
|
headers: {'res-header': 'aa'},
|
|
396
401
|
body: 'body of response',
|
|
397
|
-
url: `127.0.0.1:${port}/test`
|
|
402
|
+
url: `http://127.0.0.1:${port}/test`
|
|
398
403
|
})
|
|
399
|
-
|
|
400
|
-
expect(error).toBe(null)
|
|
401
|
-
|
|
404
|
+
expect(result.error).toBe(null)
|
|
402
405
|
expect(mockedRequest).toHaveBeenCalledWith({
|
|
403
406
|
timeout: 30*1000,
|
|
404
407
|
baseURL: `http://127.0.0.1:${port}`,
|
|
@@ -409,6 +412,51 @@ describe('Hub event tests', () => {
|
|
|
409
412
|
responseType: 'json',
|
|
410
413
|
maxContentLength: Infinity,
|
|
411
414
|
})
|
|
415
|
+
|
|
416
|
+
// parameterize API address as String
|
|
417
|
+
mockedRequest.mockClear()
|
|
418
|
+
result = await emitApiRequest(JSON.stringify({other: 'data', apiAddress: 'http://apiHost:apiPort'}))
|
|
419
|
+
expect(result.response).toStrictEqual({
|
|
420
|
+
status: 200,
|
|
421
|
+
statusText: 'Success',
|
|
422
|
+
headers: {'res-header': 'aa'},
|
|
423
|
+
body: 'body of response',
|
|
424
|
+
url: 'http://apiHost:apiPort/test'
|
|
425
|
+
})
|
|
426
|
+
expect(result.error).toBe(null)
|
|
427
|
+
expect(mockedRequest).toHaveBeenCalledWith({
|
|
428
|
+
timeout: 30*1000,
|
|
429
|
+
baseURL: 'http://apiHost:apiPort',
|
|
430
|
+
url: '/test',
|
|
431
|
+
method: "POST",
|
|
432
|
+
headers: {'req-header': 'aa'},
|
|
433
|
+
data: JSON.stringify({other: 'data'}),
|
|
434
|
+
responseType: 'json',
|
|
435
|
+
maxContentLength: Infinity,
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
// parameterize API address as Object
|
|
439
|
+
mockedRequest.mockClear()
|
|
440
|
+
result = await emitApiRequest({other: 'data', apiAddress: 'http://apiHost:apiPort'})
|
|
441
|
+
expect(result.response).toStrictEqual({
|
|
442
|
+
status: 200,
|
|
443
|
+
statusText: 'Success',
|
|
444
|
+
headers: {'res-header': 'aa'},
|
|
445
|
+
body: 'body of response',
|
|
446
|
+
url: 'http://apiHost:apiPort/test'
|
|
447
|
+
})
|
|
448
|
+
expect(result.error).toBe(null)
|
|
449
|
+
expect(mockedRequest).toHaveBeenCalledWith({
|
|
450
|
+
timeout: 30*1000,
|
|
451
|
+
baseURL: 'http://apiHost:apiPort',
|
|
452
|
+
url: '/test',
|
|
453
|
+
method: "POST",
|
|
454
|
+
headers: {'req-header': 'aa'},
|
|
455
|
+
data: {other: 'data'},
|
|
456
|
+
responseType: 'json',
|
|
457
|
+
maxContentLength: Infinity,
|
|
458
|
+
})
|
|
459
|
+
|
|
412
460
|
}
|
|
413
461
|
finally {
|
|
414
462
|
freeSocketClient(cliToHubSocket)
|