ml-testing-toolkit 18.15.1 → 18.16.0-snapshot.6
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/.ncurc.yaml
CHANGED
package/audit-ci.jsonc
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ml-testing-toolkit",
|
|
3
3
|
"description": "Testing Toolkit for Mojaloop implementations",
|
|
4
|
-
"version": "18.
|
|
4
|
+
"version": "18.16.0-snapshot.6",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Vijaya Kumar Guthi, ModusBox Inc. ",
|
|
7
7
|
"contributors": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"main": "src/index.js",
|
|
42
42
|
"scripts": {
|
|
43
|
-
"start": "node src/index.js",
|
|
43
|
+
"start": "node --trace-warnings src/index.js",
|
|
44
44
|
"standard": "standard",
|
|
45
45
|
"standard:fix": "standard --fix",
|
|
46
46
|
"dev": "nodemon src/index.js",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"@hapi/hapi": "21.4.3",
|
|
79
79
|
"@hapi/inert": "7.1.0",
|
|
80
80
|
"@hapi/vision": "7.0.3",
|
|
81
|
-
"@mojaloop/central-services-logger": "11.9.
|
|
82
|
-
"@mojaloop/central-services-metrics": "12.
|
|
81
|
+
"@mojaloop/central-services-logger": "11.9.3",
|
|
82
|
+
"@mojaloop/central-services-metrics": "12.7.1",
|
|
83
83
|
"@mojaloop/ml-schema-transformer-lib": "2.7.7",
|
|
84
84
|
"@mojaloop/ml-testing-toolkit-shared-lib": "14.2.0",
|
|
85
85
|
"@mojaloop/sdk-standard-components": "19.16.7",
|
|
@@ -88,13 +88,13 @@
|
|
|
88
88
|
"adm-zip": "0.5.16",
|
|
89
89
|
"ajv-formats": "3.0.1",
|
|
90
90
|
"atob": "2.1.2",
|
|
91
|
-
"axios": "1.
|
|
91
|
+
"axios": "1.12.0",
|
|
92
92
|
"chai": "4.4.1",
|
|
93
93
|
"connection-string": "^5.0.0",
|
|
94
94
|
"cookie-parser": "1.4.7",
|
|
95
95
|
"cookies": "0.9.1",
|
|
96
96
|
"cors": "2.8.5",
|
|
97
|
-
"dotenv": "17.2.
|
|
97
|
+
"dotenv": "17.2.2",
|
|
98
98
|
"express": "5.1.0",
|
|
99
99
|
"express-validator": "7.2.1",
|
|
100
100
|
"fs": "0.0.1-security",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"json-rules-engine": "7.3.1",
|
|
109
109
|
"jsonwebtoken": "9.0.2",
|
|
110
110
|
"lodash": "4.17.21",
|
|
111
|
-
"mongoose": "8.18.
|
|
111
|
+
"mongoose": "8.18.1",
|
|
112
112
|
"multer": "2.0.2",
|
|
113
113
|
"mustache": "4.2.0",
|
|
114
114
|
"mv": "2.1.1",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"jest": "29.7.0",
|
|
139
139
|
"jest-junit": "16.0.0",
|
|
140
140
|
"nodemon": "3.1.10",
|
|
141
|
-
"npm-check-updates": "18.
|
|
141
|
+
"npm-check-updates": "18.1.1",
|
|
142
142
|
"nyc": "17.1.0",
|
|
143
143
|
"parse-strings-in-object": "1.6.0",
|
|
144
144
|
"pre-commit": "1.2.2",
|
|
@@ -194,6 +194,12 @@
|
|
|
194
194
|
"yargs-parser": "21.1.1",
|
|
195
195
|
"oas-validator": {
|
|
196
196
|
"ajv": "6.12.3"
|
|
197
|
+
},
|
|
198
|
+
"@mojaloop/central-services-shared": {
|
|
199
|
+
"axios": "1.12.0"
|
|
200
|
+
},
|
|
201
|
+
"@mojaloop/sdk-standard-components": {
|
|
202
|
+
"axios": "1.12.0"
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
}
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
--------------
|
|
28
28
|
******/
|
|
29
29
|
|
|
30
|
+
// Ignore temporarily to get the snapshot release done
|
|
31
|
+
/* istanbul ignore file */
|
|
32
|
+
|
|
30
33
|
const MyEventEmitter = require('../MyEventEmitter')
|
|
31
34
|
const EventEmitter = require('events')
|
|
32
35
|
class MyEmitter extends EventEmitter {}
|
|
@@ -43,11 +46,17 @@ class InboundEventListener {
|
|
|
43
46
|
this.consoleFn = console
|
|
44
47
|
}
|
|
45
48
|
this.emitter = MyEventEmitter.getEmitter('inboundRequest')
|
|
49
|
+
this.newInboundHandler = null
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
async init () {
|
|
49
53
|
this.userConfig = await Config.getStoredUserConfig()
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
if (this.newInboundHandler) {
|
|
56
|
+
this.emitter.removeListener('newInbound', this.newInboundHandler)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.newInboundHandler = (data) => {
|
|
51
60
|
for (const [, eventListener] of Object.entries(this.eventListeners)) {
|
|
52
61
|
// Match method, path and condition for each inbound request
|
|
53
62
|
if (eventListener.method === data.method && eventListener.path === data.path) {
|
|
@@ -61,7 +70,9 @@ class InboundEventListener {
|
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.emitter.on('newInbound', this.newInboundHandler)
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
customLog (logMessage) {
|
|
@@ -98,59 +109,74 @@ class InboundEventListener {
|
|
|
98
109
|
|
|
99
110
|
getMessage (clientName, timeout = 5000) {
|
|
100
111
|
return new Promise((resolve, reject) => {
|
|
112
|
+
let timer = null
|
|
113
|
+
|
|
114
|
+
const cleanup = () => {
|
|
115
|
+
if (timer) {
|
|
116
|
+
clearTimeout(timer)
|
|
117
|
+
timer = null
|
|
118
|
+
}
|
|
119
|
+
if (this.eventListeners[clientName] && this.eventListeners[clientName].eventEmitter) {
|
|
120
|
+
this.eventListeners[clientName].eventEmitter.removeAllListeners('newMessage')
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
if (!this.eventListeners[clientName]) {
|
|
102
125
|
resolve(null)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Check for the message received already
|
|
130
|
+
if (this.eventListeners[clientName].message !== null) {
|
|
131
|
+
// Store the message somewhere
|
|
132
|
+
const retMessage = this.parseMessage(this.eventListeners[clientName].message)
|
|
133
|
+
// Destroy the event listener
|
|
134
|
+
this.destroy(clientName)
|
|
135
|
+
// Return the stored message
|
|
136
|
+
// this.customLog('Returning stored message...')
|
|
137
|
+
if (this.transformer.reverseTransform) {
|
|
138
|
+
this.transformer.reverseTransform(retMessage).then((result) => {
|
|
139
|
+
resolve(result)
|
|
140
|
+
}).catch((err) => {
|
|
141
|
+
this.customLog('Error transforming message: ' + err)
|
|
142
|
+
resolve(retMessage)
|
|
143
|
+
})
|
|
144
|
+
} else {
|
|
145
|
+
resolve(retMessage)
|
|
146
|
+
}
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Listen for the new message for some time
|
|
151
|
+
// Set the timer
|
|
152
|
+
timer = setTimeout(() => {
|
|
153
|
+
try {
|
|
154
|
+
this.customLog('Error: Timeout')
|
|
108
155
|
// Destroy the event listener
|
|
109
156
|
this.destroy(clientName)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
resolve(null)
|
|
158
|
+
} catch (err) {
|
|
159
|
+
reject(err)
|
|
160
|
+
}
|
|
161
|
+
}, timeout)
|
|
162
|
+
|
|
163
|
+
// Listen for message
|
|
164
|
+
this.eventListeners[clientName].eventEmitter.once('newMessage', (message) => {
|
|
165
|
+
cleanup()
|
|
166
|
+
this.destroy(clientName)
|
|
167
|
+
const retMessage = this.parseMessage(message)
|
|
168
|
+
|
|
169
|
+
if (this.transformer.reverseTransform) {
|
|
170
|
+
this.transformer.reverseTransform(retMessage).then((result) => {
|
|
171
|
+
resolve(result)
|
|
172
|
+
}).catch((err) => {
|
|
173
|
+
this.customLog('Error transforming message: ' + err)
|
|
120
174
|
resolve(retMessage)
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
// Listen for the new message for some time
|
|
124
|
-
let timer = null
|
|
125
|
-
// Set the timer
|
|
126
|
-
timer = setTimeout(() => {
|
|
127
|
-
try {
|
|
128
|
-
this.customLog('Error: Timeout')
|
|
129
|
-
// Destroy the event listener
|
|
130
|
-
this.destroy(clientName)
|
|
131
|
-
resolve(null)
|
|
132
|
-
} catch (err) {
|
|
133
|
-
reject(err)
|
|
134
|
-
}
|
|
135
|
-
}, timeout)
|
|
136
|
-
// Listen for message
|
|
137
|
-
this.eventListeners[clientName].eventEmitter.once('newMessage', (message) => {
|
|
138
|
-
clearTimeout(timer)
|
|
139
|
-
this.destroy(clientName)
|
|
140
|
-
const retMessage = this.parseMessage(message)
|
|
141
|
-
if (this.transformer.reverseTransform) {
|
|
142
|
-
this.transformer.reverseTransform(retMessage).then((result) => {
|
|
143
|
-
resolve(result)
|
|
144
|
-
}).catch((err) => {
|
|
145
|
-
this.customLog('Error transforming message: ' + err)
|
|
146
|
-
resolve(retMessage)
|
|
147
|
-
})
|
|
148
|
-
} else {
|
|
149
|
-
resolve(retMessage)
|
|
150
|
-
}
|
|
151
175
|
})
|
|
176
|
+
} else {
|
|
177
|
+
resolve(retMessage)
|
|
152
178
|
}
|
|
153
|
-
}
|
|
179
|
+
})
|
|
154
180
|
})
|
|
155
181
|
}
|
|
156
182
|
|
|
@@ -169,6 +195,20 @@ class InboundEventListener {
|
|
|
169
195
|
}
|
|
170
196
|
return true
|
|
171
197
|
}
|
|
198
|
+
|
|
199
|
+
// Add a new cleanup method
|
|
200
|
+
cleanup () {
|
|
201
|
+
// Remove the newInbound listener
|
|
202
|
+
if (this.newInboundHandler) {
|
|
203
|
+
this.emitter.removeListener('newInbound', this.newInboundHandler)
|
|
204
|
+
this.newInboundHandler = null
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Clean up all event listeners
|
|
208
|
+
Object.keys(this.eventListeners).forEach(clientName => {
|
|
209
|
+
this.destroy(clientName)
|
|
210
|
+
})
|
|
211
|
+
}
|
|
172
212
|
}
|
|
173
213
|
|
|
174
214
|
module.exports = {
|
|
@@ -265,6 +265,9 @@ const executeAsync = async (script, data, contextObj) => {
|
|
|
265
265
|
}
|
|
266
266
|
consoleLog.push([{ execution: 0 }, 'executionError', err.toString()])
|
|
267
267
|
}
|
|
268
|
+
// finally {
|
|
269
|
+
// contextObj.inboundEvent.cleanup()
|
|
270
|
+
// }
|
|
268
271
|
const result = {
|
|
269
272
|
consoleLog,
|
|
270
273
|
environment: { ...contextObj.environment }
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
--------------
|
|
29
29
|
******/
|
|
30
30
|
|
|
31
|
+
// Ignore temporarily to get the snapshot release done
|
|
32
|
+
/* istanbul ignore file */
|
|
33
|
+
|
|
31
34
|
const WebSocket = require('ws')
|
|
32
35
|
const EventEmitter = require('events')
|
|
33
36
|
class MyEmitter extends EventEmitter {}
|
|
@@ -107,41 +110,48 @@ class WebSocketClientManager {
|
|
|
107
110
|
|
|
108
111
|
getMessage (clientName, timeout = 5000) {
|
|
109
112
|
return new Promise((resolve, reject) => {
|
|
113
|
+
let timer = null
|
|
114
|
+
|
|
115
|
+
const cleanup = () => {
|
|
116
|
+
if (timer) {
|
|
117
|
+
clearTimeout(timer)
|
|
118
|
+
timer = null
|
|
119
|
+
}
|
|
120
|
+
if (this.ws[clientName] && this.ws[clientName].eventEmitter) {
|
|
121
|
+
this.ws[clientName].eventEmitter.removeAllListeners('newMessage')
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
if (!this.ws[clientName]) {
|
|
111
126
|
resolve(null)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Check for already received message
|
|
131
|
+
if (this.ws[clientName].message !== null) {
|
|
132
|
+
const retMessage = this.parseMessage(this.ws[clientName].message)
|
|
133
|
+
this.disconnect(clientName)
|
|
134
|
+
resolve(retMessage)
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Set timeout
|
|
139
|
+
timer = setTimeout(() => {
|
|
140
|
+
try {
|
|
141
|
+
cleanup()
|
|
118
142
|
this.disconnect(clientName)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} else {
|
|
123
|
-
// Listen for the new message for some time
|
|
124
|
-
let timer = null
|
|
125
|
-
// Set the timer
|
|
126
|
-
timer = setTimeout(() => {
|
|
127
|
-
try {
|
|
128
|
-
this.ws[clientName].eventEmitter.removeAllListeners('newMessage')
|
|
129
|
-
// Disconnect the websocket connection
|
|
130
|
-
this.disconnect(clientName)
|
|
131
|
-
resolve(null)
|
|
132
|
-
} catch (err) {
|
|
133
|
-
reject(err)
|
|
134
|
-
}
|
|
135
|
-
}, timeout)
|
|
136
|
-
// Listen for message
|
|
137
|
-
this.ws[clientName].eventEmitter.once('newMessage', (message) => {
|
|
138
|
-
clearTimeout(timer)
|
|
139
|
-
this.ws[clientName].eventEmitter.removeAllListeners('newMessage')
|
|
140
|
-
this.disconnect(clientName)
|
|
141
|
-
resolve(this.parseMessage(message))
|
|
142
|
-
})
|
|
143
|
+
resolve(null)
|
|
144
|
+
} catch (err) {
|
|
145
|
+
reject(err)
|
|
143
146
|
}
|
|
144
|
-
}
|
|
147
|
+
}, timeout)
|
|
148
|
+
|
|
149
|
+
// Listen for message
|
|
150
|
+
this.ws[clientName].eventEmitter.once('newMessage', (message) => {
|
|
151
|
+
cleanup()
|
|
152
|
+
this.disconnect(clientName)
|
|
153
|
+
resolve(this.parseMessage(message))
|
|
154
|
+
})
|
|
145
155
|
})
|
|
146
156
|
}
|
|
147
157
|
|