@things-factory/integration-base 7.0.1-rc.0 → 7.0.1-rc.5

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.
Files changed (45) hide show
  1. package/dist-server/engine/connection-manager.js +7 -8
  2. package/dist-server/engine/connection-manager.js.map +1 -1
  3. package/dist-server/engine/connector/echo-back-connector.js +1 -1
  4. package/dist-server/engine/connector/echo-back-connector.js.map +1 -1
  5. package/dist-server/engine/connector/graphql-connector.js +2 -2
  6. package/dist-server/engine/connector/graphql-connector.js.map +1 -1
  7. package/dist-server/engine/connector/mqtt-connector.js +1 -1
  8. package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
  9. package/dist-server/engine/connector/mssql-connector.js +1 -1
  10. package/dist-server/engine/connector/mssql-connector.js.map +1 -1
  11. package/dist-server/engine/connector/operato-connector.js +1 -1
  12. package/dist-server/engine/connector/operato-connector.js.map +1 -1
  13. package/dist-server/engine/connector/oracle-connector.js +1 -1
  14. package/dist-server/engine/connector/oracle-connector.js.map +1 -1
  15. package/dist-server/engine/connector/postgresql-connector.js +2 -2
  16. package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
  17. package/dist-server/engine/connector/socket-server.js +1 -1
  18. package/dist-server/engine/connector/socket-server.js.map +1 -1
  19. package/dist-server/engine/connector/sqlite-connector.js +2 -2
  20. package/dist-server/engine/connector/sqlite-connector.js.map +1 -1
  21. package/dist-server/engine/task/oracle-procedure.js +1 -1
  22. package/dist-server/engine/task/oracle-procedure.js.map +1 -1
  23. package/dist-server/index.js +1 -2
  24. package/dist-server/index.js.map +1 -1
  25. package/dist-server/service/index.d.ts +1 -1
  26. package/dist-server/service/payload-log/payload-log-mutation.js +1 -1
  27. package/dist-server/service/payload-log/payload-log-mutation.js.map +1 -1
  28. package/dist-server/service/scenario-instance/scenario-instance-type.js +6 -6
  29. package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
  30. package/dist-server/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +9 -9
  32. package/server/engine/connection-manager.ts +7 -8
  33. package/server/engine/connector/echo-back-connector.ts +2 -1
  34. package/server/engine/connector/graphql-connector.ts +8 -3
  35. package/server/engine/connector/mqtt-connector.ts +2 -1
  36. package/server/engine/connector/mssql-connector.ts +1 -1
  37. package/server/engine/connector/operato-connector.ts +10 -4
  38. package/server/engine/connector/oracle-connector.ts +5 -8
  39. package/server/engine/connector/postgresql-connector.ts +3 -2
  40. package/server/engine/connector/socket-server.ts +1 -1
  41. package/server/engine/connector/sqlite-connector.ts +2 -5
  42. package/server/engine/task/oracle-procedure.ts +5 -5
  43. package/server/index.ts +1 -2
  44. package/server/service/payload-log/payload-log-mutation.ts +1 -1
  45. package/server/service/scenario-instance/scenario-instance-type.ts +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-base",
3
- "version": "7.0.1-rc.0",
3
+ "version": "7.0.1-rc.5",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -27,13 +27,13 @@
27
27
  "dependencies": {
28
28
  "@apollo/client": "^3.6.9",
29
29
  "@operato/moment-timezone-es": "^7.0.0-rc",
30
- "@things-factory/api": "^7.0.1-rc.0",
31
- "@things-factory/auth-base": "^7.0.1-rc.0",
32
- "@things-factory/cache-service": "^7.0.1-rc.0",
33
- "@things-factory/env": "^7.0.1-rc.0",
34
- "@things-factory/oauth2-client": "^7.0.1-rc.0",
35
- "@things-factory/scheduler-client": "^7.0.1-rc.0",
36
- "@things-factory/shell": "^7.0.1-rc.0",
30
+ "@things-factory/api": "^7.0.1-rc.5",
31
+ "@things-factory/auth-base": "^7.0.1-rc.5",
32
+ "@things-factory/cache-service": "^7.0.1-rc.5",
33
+ "@things-factory/env": "^7.0.1-rc.5",
34
+ "@things-factory/oauth2-client": "^7.0.1-rc.5",
35
+ "@things-factory/scheduler-client": "^7.0.1-rc.5",
36
+ "@things-factory/shell": "^7.0.1-rc.5",
37
37
  "@things-factory/utils": "^7.0.1-rc.0",
38
38
  "async-mqtt": "^2.5.0",
39
39
  "chance": "^1.1.11",
@@ -44,5 +44,5 @@
44
44
  "readline": "^1.3.0",
45
45
  "vm2": "^3.9.11"
46
46
  },
47
- "gitHead": "45476b164b69aef2c211d9a5257897f42d8e2f5f"
47
+ "gitHead": "7d5d340e80a8efde9be08bb7b1e019d944bc3628"
48
48
  }
@@ -7,7 +7,7 @@ import { Connection, ConnectionStatus } from '../service'
7
7
  import { Connector } from './types'
8
8
  import { ProxyConnector } from './connector/proxy-connector'
9
9
 
10
- const { combine, timestamp, splat, printf } = format
10
+ const { combine, splat, printf, errors } = format
11
11
  const debug = require('debug')('things-factory:integration-base:connections')
12
12
 
13
13
  const SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone
@@ -20,12 +20,12 @@ export class ConnectionManager {
20
20
  private static connectors: { [propName: string]: Connector } = {}
21
21
  private static connections: { [domainId: string]: { [name: string]: any } } = {}
22
22
  private static entities = {}
23
- private static logFormat = printf(({ level, message, timestamp }) => {
24
- return `${timestamp} ${level}: ${message}`
23
+ private static logFormat = printf(({ level, message, timestamp, stack }) => {
24
+ return `${timestamp} ${level}: ${stack || message}`
25
25
  })
26
26
 
27
27
  public static logger = createLogger({
28
- format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),
28
+ format: combine(errors({ stack: true }), systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),
29
29
  transports: [
30
30
  new (transports as any).DailyRotateFile({
31
31
  filename: `logs/connections-%DATE%.log`,
@@ -52,8 +52,7 @@ export class ConnectionManager {
52
52
  try {
53
53
  params = JSON.parse(connection.params || '{}')
54
54
  } catch (ex) {
55
- ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`)
56
- ConnectionManager.logger.error(ex)
55
+ ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`, ex)
57
56
  }
58
57
 
59
58
  return {
@@ -66,7 +65,7 @@ export class ConnectionManager {
66
65
 
67
66
  return await Promise.all(
68
67
  [...Object.keys(ConnectionManager.connectors), 'proxy-connector'].map(type => {
69
- const connector = 'proxy-connector' ? ProxyConnector.instance : ConnectionManager.getConnector(type)
68
+ const connector = type == 'proxy-connector' ? ProxyConnector.instance : ConnectionManager.getConnector(type)
70
69
 
71
70
  ConnectionManager.logger.info(`Connector '${type}' started to ready`)
72
71
 
@@ -81,7 +80,7 @@ export class ConnectionManager {
81
80
  }) as any
82
81
  )
83
82
  .catch(error => {
84
- ConnectionManager.logger.error(error.message)
83
+ ConnectionManager.logger.error(error)
85
84
  })
86
85
  .then(() => {
87
86
  ConnectionManager.logger.info(`All connector for '${type}' ready`)
@@ -25,7 +25,8 @@ export class EchoBack implements Connector {
25
25
  )
26
26
  } catch (e) {
27
27
  ConnectionManager.logger.error(
28
- `echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected.\ncause: ${e}`
28
+ `echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected.`,
29
+ e
29
30
  )
30
31
  }
31
32
  }
@@ -39,11 +39,14 @@ export class GraphqlConnector implements Connector {
39
39
  const ERROR_HANDLER: any = ({ graphQLErrors, networkError }) => {
40
40
  if (graphQLErrors)
41
41
  graphQLErrors.map(({ message, locations, path }) => {
42
- ConnectionManager.logger.error(`[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`)
42
+ ConnectionManager.logger.error(
43
+ `[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`,
44
+ graphQLErrors
45
+ )
43
46
  })
44
47
 
45
48
  if (networkError) {
46
- ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}] ${networkError}`)
49
+ ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}]`, networkError)
47
50
  }
48
51
  }
49
52
 
@@ -81,7 +84,9 @@ export class GraphqlConnector implements Connector {
81
84
  })
82
85
  )
83
86
 
84
- ConnectionManager.logger.info(`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`)
87
+ ConnectionManager.logger.info(
88
+ `graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`
89
+ )
85
90
  }
86
91
 
87
92
  async disconnect(connection: InputConnection) {
@@ -39,7 +39,8 @@ export class MqttConnector implements Connector {
39
39
  ConnectionManager.logger.info(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is connected`)
40
40
  } catch (err) {
41
41
  ConnectionManager.logger.error(
42
- `mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed.\ncause: ${err}`
42
+ `mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed.`,
43
+ err
43
44
  )
44
45
  }
45
46
  }
@@ -7,7 +7,7 @@ import { InputConnection } from '../../service/connection/connection-type'
7
7
  try {
8
8
  var Client = require('mssql')
9
9
  } catch (err) {
10
- logger.error('mssql module loading failed')
10
+ logger.error('mssql module loading failed', err)
11
11
  }
12
12
 
13
13
  export class MssqlConnector implements Connector {
@@ -160,14 +160,16 @@ export class OperatoConnector implements Connector {
160
160
  await this.runScenario(subscriptions, data?.data?.data)
161
161
  },
162
162
  error: error => {
163
- ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error: ${error}`)
163
+ ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)
164
164
  },
165
165
  complete: () => {
166
166
  ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)
167
167
  }
168
168
  })
169
169
 
170
- ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`)
170
+ ConnectionManager.logger.info(
171
+ `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`
172
+ )
171
173
 
172
174
  subscriptions.push({
173
175
  tag,
@@ -180,7 +182,9 @@ export class OperatoConnector implements Connector {
180
182
  client['subscriptions'] = subscriptions
181
183
  ConnectionManager.addConnectionInstance(connection, client)
182
184
 
183
- ConnectionManager.logger.info(`operato-connector connection(${connection.name}:${connection.endpoint}) is connected`)
185
+ ConnectionManager.logger.info(
186
+ `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`
187
+ )
184
188
  }
185
189
 
186
190
  async disconnect(connection: InputConnection) {
@@ -208,7 +212,9 @@ export class OperatoConnector implements Connector {
208
212
 
209
213
  if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {
210
214
  const { category, privilege } = scenario.privilege || {}
211
- throw new Error(`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`)
215
+ throw new Error(
216
+ `Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`
217
+ )
212
218
  }
213
219
 
214
220
  /* create a scenario instance */
@@ -7,7 +7,7 @@ import { InputConnection } from '../../service/connection/connection-type'
7
7
  try {
8
8
  var oracledb = require('oracledb')
9
9
  } catch (err) {
10
- logger.error('oracledb module loading failed')
10
+ logger.error('oracledb module loading failed', err)
11
11
  }
12
12
 
13
13
  export class OracleConnector implements Connector {
@@ -71,7 +71,7 @@ export class OracleConnector implements Connector {
71
71
  poolAlias,
72
72
  enableStatistics
73
73
  })
74
-
74
+
75
75
  ConnectionManager.addConnectionInstance(connection, {
76
76
  query: async (query, params) => {
77
77
  let dbConnection: any = {}
@@ -89,12 +89,10 @@ export class OracleConnector implements Connector {
89
89
  await this.recreatePool(connection)
90
90
  }
91
91
  throw e
92
- }
93
- finally {
92
+ } finally {
94
93
  await dbConnection.close()
95
94
  }
96
95
  return taskResult
97
-
98
96
  },
99
97
  execute: async (procedure, params) => {
100
98
  let dbConnection: any = {}
@@ -105,7 +103,7 @@ export class OracleConnector implements Connector {
105
103
  ${procedure}
106
104
  END;`
107
105
  dbConnection = await oracledb.getConnection(poolAlias)
108
-
106
+
109
107
  // console.log('\n************* stat after get ****************')
110
108
  // await oracledb.getPool(poolAlias).logStatistics()
111
109
 
@@ -131,8 +129,7 @@ export class OracleConnector implements Connector {
131
129
  await this.recreatePool(connection)
132
130
  }
133
131
  throw e
134
- }
135
- finally {
132
+ } finally {
136
133
  await dbConnection.close()
137
134
 
138
135
  // console.log('\n************* stat after close ****************')
@@ -7,7 +7,7 @@ import { InputConnection } from '../../service/connection/connection-type'
7
7
  try {
8
8
  var { Client } = require('pg')
9
9
  } catch (err) {
10
- logger.error('postgresql module loading failed')
10
+ logger.error('postgresql module loading failed', err)
11
11
  }
12
12
 
13
13
  export class PostgresqlConnector implements Connector {
@@ -55,7 +55,8 @@ export class PostgresqlConnector implements Connector {
55
55
  ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} connected.`)
56
56
  } catch (e) {
57
57
  ConnectionManager.logger.error(
58
- `PostgresSQL Database(${connection.name}:${database}) at ${endpoint} not connected.\ncause: ${e}`
58
+ `PostgresSQL Database(${connection.name}:${database}) at ${endpoint} not connected.`,
59
+ e
59
60
  )
60
61
  }
61
62
  }
@@ -40,7 +40,7 @@ export class SocketServer implements Connector {
40
40
  var logger = ConnectionManager.logger
41
41
  let message = ex.stack ? ex.stack : ex
42
42
  let msg = typeof message == 'object' ? JSON.stringify(message, null, 2) : message
43
- logger.error(msg)
43
+ logger.error(msg, ex)
44
44
  reject(ex)
45
45
  })
46
46
  })
@@ -6,11 +6,10 @@ import { ConnectionManager } from '../connection-manager'
6
6
  import { Connector } from '../types'
7
7
  import { InputConnection } from '../../service/connection/connection-type'
8
8
 
9
-
10
9
  try {
11
10
  var sqlite3 = require('sqlite3').verbose()
12
11
  } catch (err) {
13
- logger.error('sqlite3 module loading failed')
12
+ logger.error('sqlite3 module loading failed', err)
14
13
  }
15
14
 
16
15
  export class SqliteConnector implements Connector {
@@ -29,9 +28,7 @@ export class SqliteConnector implements Connector {
29
28
 
30
29
  var database = new sqlite3.Database(endpoint, sqlite3.OPEN_READWRITE, err => {
31
30
  if (err) {
32
- ConnectionManager.logger.error(
33
- `SQLite Database(${connection.name}) at ${endpoint} not connected.\ncause: ${err}`
34
- )
31
+ ConnectionManager.logger.error(`SQLite Database(${connection.name}) at ${endpoint} not connected.`, err)
35
32
  return
36
33
  }
37
34
 
@@ -9,7 +9,7 @@ import { Context } from '../types'
9
9
  try {
10
10
  var oracledb = require('oracledb')
11
11
  } catch (err) {
12
- logger.error('oracledb module loading failed')
12
+ logger.error('oracledb module loading failed', err)
13
13
  }
14
14
 
15
15
  type ProcedureParameterType = {
@@ -82,10 +82,10 @@ async function OracleProcedure(step: InputStep, context: Context) {
82
82
  type == 'Date'
83
83
  ? new Date(calculated)
84
84
  : type == 'Number'
85
- ? Number(calculated)
86
- : type == 'String'
87
- ? String(calculated)
88
- : calculated
85
+ ? Number(calculated)
86
+ : type == 'String'
87
+ ? String(calculated)
88
+ : calculated
89
89
  }
90
90
 
91
91
  if (maxSize) {
package/server/index.ts CHANGED
@@ -15,7 +15,6 @@ process.on('bootstrap-module-start' as any, async ({ app, config, client }: any)
15
15
 
16
16
  console.log('Scenario Engine has just started.')
17
17
  } catch (ex) {
18
- ConnectionManager.logger.error(ex)
19
- console.log('Just has failed to start Scenario Engine.')
18
+ ConnectionManager.logger.error('Just has failed to start Scenario Engine.', ex)
20
19
  }
21
20
  })
@@ -146,6 +146,6 @@ export async function createPayloadLog(
146
146
  updatedAt: new Date()
147
147
  })
148
148
  } catch (error) {
149
- logger.error(`PayloadLog Error: ${error}`)
149
+ logger.error(`PayloadLog Error`, error)
150
150
  }
151
151
  }
@@ -18,10 +18,10 @@ import { Step } from '../step/step-type'
18
18
  import { handler as edgeHandler } from '../../engine/edge-client'
19
19
 
20
20
  const debug = require('debug')('things-factory:integration-base:scenario-instance')
21
- const { combine, timestamp, splat, printf } = format
21
+ const { combine, errors, splat, printf } = format
22
22
 
23
- const LOGFORMAT = printf(({ level, message, timestamp }) => {
24
- return `${timestamp} ${level}: ${message}`
23
+ const LOGFORMAT = printf(({ level, message, timestamp, stack }) => {
24
+ return `${timestamp} ${level}: ${stack || message}`
25
25
  })
26
26
 
27
27
  const SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone
@@ -228,7 +228,7 @@ export class ScenarioInstance {
228
228
  logger:
229
229
  context?.logger ||
230
230
  createLogger({
231
- format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), LOGFORMAT),
231
+ format: combine(errors({ stack: true }), systemTimestamp({ tz: SYSTEM_TZ }), splat(), LOGFORMAT),
232
232
  transports: [
233
233
  new (transports as any).DailyRotateFile({
234
234
  filename: `logs/${domain.subdomain}/scenario-${scenarioName}-%DATE%.log`,
@@ -320,7 +320,7 @@ export class ScenarioInstance {
320
320
  const message = ex.stack ? ex.stack : ex
321
321
  const { scenarioName, domain } = this
322
322
 
323
- this.context.logger.error(ex.message ? ex.message : ex)
323
+ this.context.logger.error(ex)
324
324
 
325
325
  debug('failed to run ', `[ Domain: ${domain.name}, Scenario: ${scenarioName} ]\n`, ex)
326
326
  this.setState(
@@ -515,7 +515,7 @@ export class ScenarioInstance {
515
515
  try {
516
516
  step.params = JSON.parse(step.params)
517
517
  } catch (ex) {
518
- this.context.logger.error(`params(${step.params}) parsing error. params must be a JSON.`)
518
+ this.context.logger.error(`params(${step.params}) parsing error. params must be a JSON.`, ex)
519
519
  }
520
520
  step.params = step.params || {}
521
521