@things-factory/integration-base 8.0.39 → 9.0.0-9.0.0-beta.59.0
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/dist-server/engine/connector/headless-connector.d.ts +23 -0
- package/dist-server/engine/connector/headless-connector.js +357 -0
- package/dist-server/engine/connector/headless-connector.js.map +1 -0
- package/dist-server/engine/connector/http-connector.js +1 -1
- package/dist-server/engine/connector/http-connector.js.map +1 -1
- package/dist-server/engine/connector/index.d.ts +1 -0
- package/dist-server/engine/connector/index.js +1 -0
- package/dist-server/engine/connector/index.js.map +1 -1
- package/dist-server/engine/index.d.ts +3 -2
- package/dist-server/engine/index.js +3 -2
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/resource-pool/headless-pool.d.ts +1 -0
- package/dist-server/engine/resource-pool/headless-pool.js +62 -0
- package/dist-server/engine/resource-pool/headless-pool.js.map +1 -0
- package/dist-server/engine/resource-pool/index.d.ts +1 -0
- package/dist-server/engine/resource-pool/index.js +5 -0
- package/dist-server/engine/resource-pool/index.js.map +1 -0
- package/dist-server/engine/task/headless-post.js +19 -33
- package/dist-server/engine/task/headless-post.js.map +1 -1
- package/dist-server/engine/task/headless-scrap.js +20 -13
- package/dist-server/engine/task/headless-scrap.js.map +1 -1
- package/dist-server/engine/task/mqtt-publish.js +29 -6
- package/dist-server/engine/task/mqtt-publish.js.map +1 -1
- package/dist-server/engine/task/mqtt-subscribe.js +178 -64
- package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
- package/dist-server/index.d.ts +6 -6
- package/dist-server/index.js +10 -10
- package/dist-server/index.js.map +1 -1
- package/dist-server/routes.js +6 -6
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/connection/connection-mutation.js +17 -5
- package/dist-server/service/connection/connection-mutation.js.map +1 -1
- package/dist-server/service/connection/connection-query.js +3 -0
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/translations/en.json +12 -4
- package/translations/ja.json +12 -4
- package/translations/ko.json +12 -4
- package/translations/ms.json +12 -4
- package/translations/zh.json +12 -4
- package/server/controllers/index.ts +0 -2
- package/server/controllers/publish-data.ts +0 -29
- package/server/controllers/scenario-controller.ts +0 -154
- package/server/engine/analyzer/analyze-integration.ts +0 -115
- package/server/engine/connection-manager.ts +0 -232
- package/server/engine/connector/echo-back-connector.ts +0 -51
- package/server/engine/connector/echo-back-server.ts +0 -72
- package/server/engine/connector/graphql-connector.ts +0 -126
- package/server/engine/connector/http-connector.ts +0 -65
- package/server/engine/connector/index.ts +0 -12
- package/server/engine/connector/mqtt-connector.ts +0 -78
- package/server/engine/connector/mssql-connector.ts +0 -152
- package/server/engine/connector/mysql-connector.ts +0 -94
- package/server/engine/connector/operato-connector.ts +0 -264
- package/server/engine/connector/oracle-connector.ts +0 -218
- package/server/engine/connector/postgresql-connector.ts +0 -152
- package/server/engine/connector/proxy-connector.ts +0 -53
- package/server/engine/connector/socket-server.ts +0 -86
- package/server/engine/connector/sqlite-connector.ts +0 -69
- package/server/engine/edge-client.ts +0 -45
- package/server/engine/index.ts +0 -10
- package/server/engine/pending-queue.ts +0 -97
- package/server/engine/scenario-engine.ts +0 -106
- package/server/engine/task/book-up-scenario.ts +0 -73
- package/server/engine/task/csv-readline.ts +0 -127
- package/server/engine/task/data-accessor.ts +0 -36
- package/server/engine/task/data-mapper.ts +0 -47
- package/server/engine/task/database-query.ts +0 -56
- package/server/engine/task/echo-receive.ts +0 -21
- package/server/engine/task/echo-send.ts +0 -32
- package/server/engine/task/empty-check.ts +0 -38
- package/server/engine/task/end.ts +0 -18
- package/server/engine/task/floating-point.ts +0 -71
- package/server/engine/task/goto.ts +0 -27
- package/server/engine/task/graphql-mutate.ts +0 -79
- package/server/engine/task/graphql-query.ts +0 -78
- package/server/engine/task/headless-post.ts +0 -147
- package/server/engine/task/headless-scrap.ts +0 -80
- package/server/engine/task/http-get.ts +0 -117
- package/server/engine/task/http-post.ts +0 -148
- package/server/engine/task/index.ts +0 -45
- package/server/engine/task/jsonata.ts +0 -45
- package/server/engine/task/local-graphql-mutate.ts +0 -100
- package/server/engine/task/local-graphql-query.ts +0 -100
- package/server/engine/task/log.ts +0 -78
- package/server/engine/task/mqtt-publish.ts +0 -45
- package/server/engine/task/mqtt-subscribe.ts +0 -139
- package/server/engine/task/mssql-procedure.ts +0 -128
- package/server/engine/task/oracle-procedure.ts +0 -124
- package/server/engine/task/pick-pending-scenario.ts +0 -80
- package/server/engine/task/publish.ts +0 -40
- package/server/engine/task/random.ts +0 -53
- package/server/engine/task/reset-pending-queue.ts +0 -17
- package/server/engine/task/script.ts +0 -63
- package/server/engine/task/set-domain.ts +0 -37
- package/server/engine/task/sleep.ts +0 -34
- package/server/engine/task/socket-listener.ts +0 -96
- package/server/engine/task/state-group-read.ts +0 -69
- package/server/engine/task/state-read.ts +0 -56
- package/server/engine/task/state-write.ts +0 -65
- package/server/engine/task/stop-scenario.ts +0 -44
- package/server/engine/task/sub-scenario.ts +0 -57
- package/server/engine/task/switch-goto.ts +0 -43
- package/server/engine/task/switch-range-goto.ts +0 -53
- package/server/engine/task/switch-range-scenario.ts +0 -79
- package/server/engine/task/switch-range-set.ts +0 -48
- package/server/engine/task/switch-scenario.ts +0 -67
- package/server/engine/task/switch-set.ts +0 -37
- package/server/engine/task/throw.ts +0 -27
- package/server/engine/task/utils/headless-pool-for-scenario.ts +0 -71
- package/server/engine/task/utils/substitute.ts +0 -44
- package/server/engine/task/variables.ts +0 -17
- package/server/engine/task-registry.ts +0 -23
- package/server/engine/types.ts +0 -114
- package/server/index.ts +0 -20
- package/server/migrations/index.ts +0 -9
- package/server/restful/index.ts +0 -1
- package/server/restful/unstable/index.ts +0 -7
- package/server/restful/unstable/run-scenario.ts +0 -51
- package/server/restful/unstable/scenario-instance.ts +0 -52
- package/server/restful/unstable/scenario-instances.ts +0 -80
- package/server/restful/unstable/scenario.ts +0 -41
- package/server/restful/unstable/scenarios.ts +0 -69
- package/server/restful/unstable/start-scenario.ts +0 -33
- package/server/restful/unstable/stop-scenario.ts +0 -30
- package/server/routers/scenario-schedule-callback-router.ts +0 -69
- package/server/routers/scenario-view-router.ts +0 -46
- package/server/routes.ts +0 -35
- package/server/service/analysis/analysis-query.ts +0 -13
- package/server/service/analysis/index.ts +0 -3
- package/server/service/connection/connection-mutation.ts +0 -190
- package/server/service/connection/connection-query.ts +0 -87
- package/server/service/connection/connection-subscription.ts +0 -104
- package/server/service/connection/connection-type.ts +0 -305
- package/server/service/connection/index.ts +0 -7
- package/server/service/connector/connector-query.ts +0 -62
- package/server/service/connector/connector-type.ts +0 -29
- package/server/service/connector/index.ts +0 -4
- package/server/service/index.ts +0 -52
- package/server/service/payload-log/index.ts +0 -7
- package/server/service/payload-log/payload-log-mutation.ts +0 -151
- package/server/service/payload-log/payload-log-query.ts +0 -49
- package/server/service/payload-log/payload-log-type.ts +0 -36
- package/server/service/payload-log/payload-log.ts +0 -100
- package/server/service/property-spec.ts +0 -24
- package/server/service/scenario/index.ts +0 -6
- package/server/service/scenario/scenario-mutation.ts +0 -396
- package/server/service/scenario/scenario-query.ts +0 -109
- package/server/service/scenario/scenario-type.ts +0 -78
- package/server/service/scenario/scenario.ts +0 -124
- package/server/service/scenario-flow/scenario-flow.ts +0 -17
- package/server/service/scenario-instance/index.ts +0 -6
- package/server/service/scenario-instance/scenario-instance-mutation.ts +0 -44
- package/server/service/scenario-instance/scenario-instance-query.ts +0 -42
- package/server/service/scenario-instance/scenario-instance-subscription.ts +0 -118
- package/server/service/scenario-instance/scenario-instance-type.ts +0 -557
- package/server/service/scenario-queue/index.ts +0 -4
- package/server/service/scenario-queue/scenario-queue-subscription.ts +0 -55
- package/server/service/scenario-queue/scenario-queue-type.ts +0 -27
- package/server/service/state-register/data-resolver.ts +0 -56
- package/server/service/state-register/index.ts +0 -8
- package/server/service/state-register/state-register-mutation.ts +0 -166
- package/server/service/state-register/state-register-query.ts +0 -80
- package/server/service/state-register/state-register-type.ts +0 -80
- package/server/service/state-register/state-register.ts +0 -113
- package/server/service/step/index.ts +0 -6
- package/server/service/step/step-mutation.ts +0 -52
- package/server/service/step/step-query.ts +0 -55
- package/server/service/step/step-type.ts +0 -238
- package/server/service/task-type/index.ts +0 -4
- package/server/service/task-type/task-type-query.ts +0 -95
- package/server/service/task-type/task-type-type.ts +0 -29
@@ -1,232 +0,0 @@
|
|
1
|
-
import moment from 'moment-timezone'
|
2
|
-
import { createLogger, format, transports } from 'winston'
|
3
|
-
|
4
|
-
import { Domain, getRepository, pubsub, PubSubLogTransport } from '@things-factory/shell'
|
5
|
-
|
6
|
-
import { Connection, ConnectionStatus } from '../service'
|
7
|
-
import { Connector } from './types'
|
8
|
-
import { ProxyConnector } from './connector/proxy-connector'
|
9
|
-
|
10
|
-
const { combine, splat, printf, errors } = format
|
11
|
-
const debug = require('debug')('things-factory:integration-base:connections')
|
12
|
-
|
13
|
-
function getSystemTimeZone() {
|
14
|
-
try {
|
15
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
16
|
-
if (!timeZone) {
|
17
|
-
throw new Error('Unable to resolve timeZone')
|
18
|
-
}
|
19
|
-
return timeZone
|
20
|
-
} catch (e) {
|
21
|
-
console.warn('Failed to get system timeZone, falling back to UTC.', e)
|
22
|
-
return 'UTC'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
const SYSTEM_TZ = getSystemTimeZone()
|
27
|
-
const systemTimestamp = format((info, opts: { tz?: string }) => {
|
28
|
-
if (opts.tz) info.timestamp = moment().tz(opts.tz).format()
|
29
|
-
return info
|
30
|
-
})
|
31
|
-
|
32
|
-
export class ConnectionManager {
|
33
|
-
private static connectors: { [propName: string]: Connector } = {}
|
34
|
-
private static connections: { [domainId: string]: { [name: string]: any } } = {}
|
35
|
-
private static entities = {}
|
36
|
-
private static logFormat = printf(({ level, message, timestamp, stack }) => {
|
37
|
-
return `${timestamp} ${level}: ${stack || message}`
|
38
|
-
})
|
39
|
-
|
40
|
-
public static logger = createLogger({
|
41
|
-
format: combine(errors({ stack: true }), systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),
|
42
|
-
transports: [
|
43
|
-
new (transports as any).DailyRotateFile({
|
44
|
-
filename: `logs/connections-%DATE%.log`,
|
45
|
-
datePattern: 'YYYY-MM-DD-HH',
|
46
|
-
zippedArchive: false,
|
47
|
-
maxSize: '20m',
|
48
|
-
maxFiles: '14d',
|
49
|
-
level: 'info'
|
50
|
-
}),
|
51
|
-
new PubSubLogTransport({
|
52
|
-
topic: 'connection-log'
|
53
|
-
})
|
54
|
-
]
|
55
|
-
})
|
56
|
-
|
57
|
-
static async ready() {
|
58
|
-
const CONNECTIONS = (
|
59
|
-
await getRepository(Connection).find({
|
60
|
-
where: { active: true },
|
61
|
-
relations: ['domain', 'edge', 'creator', 'updater']
|
62
|
-
})
|
63
|
-
).map(connection => {
|
64
|
-
return {
|
65
|
-
...connection,
|
66
|
-
params: connection.params || {}
|
67
|
-
}
|
68
|
-
})
|
69
|
-
|
70
|
-
ConnectionManager.logger.info('Initializing ConnectionManager...')
|
71
|
-
|
72
|
-
return await Promise.all(
|
73
|
-
[...Object.keys(ConnectionManager.connectors), 'proxy-connector'].map(type => {
|
74
|
-
const connector = type == 'proxy-connector' ? ProxyConnector.instance : ConnectionManager.getConnector(type)
|
75
|
-
|
76
|
-
ConnectionManager.logger.info(`Connector '${type}' started to ready`)
|
77
|
-
|
78
|
-
return connector
|
79
|
-
.ready(
|
80
|
-
CONNECTIONS.filter(connection => {
|
81
|
-
if (type == 'proxy-connector') {
|
82
|
-
return !!connection.edge
|
83
|
-
} else {
|
84
|
-
return !connection.edge && connection.type == type
|
85
|
-
}
|
86
|
-
}) as any
|
87
|
-
)
|
88
|
-
.catch(error => {
|
89
|
-
ConnectionManager.logger.error(error)
|
90
|
-
})
|
91
|
-
.then(() => {
|
92
|
-
ConnectionManager.logger.info(`All connector for '${type}' ready`)
|
93
|
-
})
|
94
|
-
})
|
95
|
-
).then(() => {
|
96
|
-
ConnectionManager.logger.info('ConnectionManager initialization done:')
|
97
|
-
Object.keys(ConnectionManager.connections).forEach(key => {
|
98
|
-
var connections = ConnectionManager.connections[key]
|
99
|
-
ConnectionManager.logger.info('For domain(%s) : %s', key, JSON.stringify(Object.keys(connections)))
|
100
|
-
})
|
101
|
-
})
|
102
|
-
}
|
103
|
-
|
104
|
-
static registerConnector(type: string, connector: Connector) {
|
105
|
-
ConnectionManager.connectors[type] = connector
|
106
|
-
}
|
107
|
-
|
108
|
-
static getConnector(type: string): Connector {
|
109
|
-
return ConnectionManager.connectors[type]
|
110
|
-
}
|
111
|
-
|
112
|
-
static getConnectors(): { [connectorName: string]: Connector } {
|
113
|
-
return {
|
114
|
-
...ConnectionManager.connectors
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
static unregisterConnector(type: string) {
|
119
|
-
delete ConnectionManager.connectors[type]
|
120
|
-
}
|
121
|
-
|
122
|
-
static getConnections() {
|
123
|
-
return ConnectionManager.connections
|
124
|
-
}
|
125
|
-
|
126
|
-
static getEntities() {
|
127
|
-
return ConnectionManager.entities
|
128
|
-
}
|
129
|
-
|
130
|
-
static getConnectionInstance(connection: Connection): any {
|
131
|
-
const { domain, name } = connection
|
132
|
-
return ConnectionManager.connections[domain.id]?.[name]
|
133
|
-
}
|
134
|
-
|
135
|
-
static getConnectionInstanceByName(domain: Domain, name: string) {
|
136
|
-
const connections = ConnectionManager.connections[domain.id]
|
137
|
-
const connection = connections?.[name]
|
138
|
-
|
139
|
-
if (!connection) {
|
140
|
-
throw `The connection with the given name(${name}) cannot be found`
|
141
|
-
}
|
142
|
-
|
143
|
-
return connection
|
144
|
-
}
|
145
|
-
|
146
|
-
static getConnectionInstanceEntityByName(domain: Domain, name: string): any {
|
147
|
-
const connection = ConnectionManager.entities[domain.id]?.[name]
|
148
|
-
if (connection) {
|
149
|
-
return connection
|
150
|
-
}
|
151
|
-
|
152
|
-
if (domain.parentId) {
|
153
|
-
return ConnectionManager.entities[domain.id]?.[name]
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {
|
158
|
-
const connections = ConnectionManager.connections[domain.id]
|
159
|
-
const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId]
|
160
|
-
|
161
|
-
return {
|
162
|
-
...parentConnections,
|
163
|
-
...connections
|
164
|
-
}
|
165
|
-
}
|
166
|
-
|
167
|
-
static getConnectionInstanceEntities(domain: Domain): { [connectionName: string]: any } {
|
168
|
-
const connections = ConnectionManager.entities[domain.id]
|
169
|
-
|
170
|
-
return {
|
171
|
-
...connections
|
172
|
-
}
|
173
|
-
}
|
174
|
-
|
175
|
-
static addConnectionInstance(connection: Connection, instance: any) {
|
176
|
-
const { domain, name } = connection
|
177
|
-
|
178
|
-
var connections = ConnectionManager.connections[domain.id]
|
179
|
-
if (!connections) {
|
180
|
-
connections = ConnectionManager.connections[domain.id] = {}
|
181
|
-
}
|
182
|
-
|
183
|
-
var entities = ConnectionManager.entities[domain.id]
|
184
|
-
if (!entities) {
|
185
|
-
entities = ConnectionManager.entities[domain.id] = {}
|
186
|
-
}
|
187
|
-
|
188
|
-
connections[name] = instance
|
189
|
-
entities[name] = connection
|
190
|
-
|
191
|
-
ConnectionManager.publishState(connection, ConnectionStatus.CONNECTED)
|
192
|
-
debug('add-connection', domain.subdomain, name)
|
193
|
-
}
|
194
|
-
|
195
|
-
static removeConnectionInstance(connection: Connection): any {
|
196
|
-
const { domain, name } = connection
|
197
|
-
var connections = ConnectionManager.connections[domain.id]
|
198
|
-
var entities = ConnectionManager.entities[domain.id]
|
199
|
-
|
200
|
-
var instance = connections?.[name]
|
201
|
-
|
202
|
-
if (!connections || !instance) {
|
203
|
-
debug('remove-connection', `'${name}' connection not found in domain '${domain.subdomain}'`)
|
204
|
-
return
|
205
|
-
}
|
206
|
-
|
207
|
-
delete connections[name]
|
208
|
-
delete entities[name]
|
209
|
-
|
210
|
-
ConnectionManager.publishState(connection, ConnectionStatus.DISCONNECTED)
|
211
|
-
debug('remove-connection', `'${name}' connection is removed from domain '${domain.subdomain}'`)
|
212
|
-
|
213
|
-
return instance
|
214
|
-
}
|
215
|
-
|
216
|
-
private static async publishState(connection: Connection, state) {
|
217
|
-
const { domain, id, name, description, type, edge } = connection
|
218
|
-
|
219
|
-
pubsub.publish('connection-state', {
|
220
|
-
connectionState: {
|
221
|
-
domain,
|
222
|
-
id,
|
223
|
-
name,
|
224
|
-
description,
|
225
|
-
type,
|
226
|
-
edge,
|
227
|
-
state,
|
228
|
-
timestamp: new Date()
|
229
|
-
}
|
230
|
-
})
|
231
|
-
}
|
232
|
-
}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import net from 'net'
|
2
|
-
import PromiseSocket from 'promise-socket'
|
3
|
-
|
4
|
-
import { Connector } from '../types'
|
5
|
-
import { ConnectionManager } from '../connection-manager'
|
6
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
7
|
-
|
8
|
-
export class EchoBack implements Connector {
|
9
|
-
async ready(connectionConfigs) {
|
10
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
11
|
-
|
12
|
-
ConnectionManager.logger.info('echo-back connections are ready')
|
13
|
-
}
|
14
|
-
|
15
|
-
async connect(connection: InputConnection) {
|
16
|
-
let socket = new PromiseSocket(new net.Socket())
|
17
|
-
let [host, port = 8124] = connection.endpoint.split(':')
|
18
|
-
|
19
|
-
try {
|
20
|
-
await socket.connect(Number(port), host)
|
21
|
-
ConnectionManager.addConnectionInstance(connection, socket)
|
22
|
-
|
23
|
-
ConnectionManager.logger.info(
|
24
|
-
`echo-back-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
25
|
-
)
|
26
|
-
} catch (e) {
|
27
|
-
ConnectionManager.logger.error(
|
28
|
-
`echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected.`,
|
29
|
-
e
|
30
|
-
)
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
async disconnect(connection: InputConnection) {
|
35
|
-
let socket = ConnectionManager.removeConnectionInstance(connection)
|
36
|
-
|
37
|
-
await socket.destroy()
|
38
|
-
|
39
|
-
ConnectionManager.logger.info(`echo-back-connector connection(${connection.name}) is disconnected`)
|
40
|
-
}
|
41
|
-
|
42
|
-
get parameterSpec() {
|
43
|
-
return []
|
44
|
-
}
|
45
|
-
|
46
|
-
get taskPrefixes() {
|
47
|
-
return ['echo']
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
ConnectionManager.registerConnector('echo-back', new EchoBack())
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import net from 'net'
|
2
|
-
import PromiseSocket from 'promise-socket'
|
3
|
-
|
4
|
-
import { Connector } from '../types'
|
5
|
-
import { ConnectionManager } from '../connection-manager'
|
6
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
7
|
-
|
8
|
-
export class EchoBack implements Connector {
|
9
|
-
async ready(connectionConfigs: InputConnection[]) {
|
10
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
11
|
-
|
12
|
-
ConnectionManager.logger.info('echo-back-servers are ready')
|
13
|
-
}
|
14
|
-
|
15
|
-
async connect(config: InputConnection): Promise<void> {
|
16
|
-
var [host = '0.0.0.0', port = 8124] = config.endpoint.split(':')
|
17
|
-
|
18
|
-
return new Promise((resolve, reject) => {
|
19
|
-
var server = net.createServer(socket => {
|
20
|
-
socket.on('data', function (data) {
|
21
|
-
socket.write(data.toString())
|
22
|
-
})
|
23
|
-
|
24
|
-
socket.on('error', function (err) {
|
25
|
-
ConnectionManager.logger.error(err)
|
26
|
-
reject(err)
|
27
|
-
})
|
28
|
-
})
|
29
|
-
|
30
|
-
server.listen(port, async () => {
|
31
|
-
ConnectionManager.logger.info(`Echo-back server listening on ${host}:${port}`)
|
32
|
-
|
33
|
-
/* default client connection */
|
34
|
-
let socket = new net.Socket()
|
35
|
-
socket.on('error', console.error)
|
36
|
-
|
37
|
-
try {
|
38
|
-
let promiseSocket = new PromiseSocket(socket)
|
39
|
-
await promiseSocket.connect(Number(port), 'localhost')
|
40
|
-
promiseSocket['__server__'] = server
|
41
|
-
|
42
|
-
ConnectionManager.addConnectionInstance(config, promiseSocket)
|
43
|
-
|
44
|
-
ConnectionManager.logger.info(`echo-back-server connection(${config.name}:${config.endpoint}) is connected`)
|
45
|
-
|
46
|
-
resolve()
|
47
|
-
} catch (err) {
|
48
|
-
ConnectionManager.logger.error(
|
49
|
-
`echo-back-server connection(${config.name}:${config.endpoint}) is connected.\ncause: ${err}`
|
50
|
-
)
|
51
|
-
reject(err)
|
52
|
-
}
|
53
|
-
})
|
54
|
-
})
|
55
|
-
}
|
56
|
-
|
57
|
-
async disconnect(connection: InputConnection) {
|
58
|
-
let socket = ConnectionManager.removeConnectionInstance(connection)
|
59
|
-
var server = socket['__server__']
|
60
|
-
|
61
|
-
await socket.destroy()
|
62
|
-
server && (await server.close())
|
63
|
-
|
64
|
-
ConnectionManager.logger.info(`echo-back-server connection(${connection.name}) is disconnected`)
|
65
|
-
}
|
66
|
-
|
67
|
-
get parameterSpec() {
|
68
|
-
return []
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
ConnectionManager.registerConnector('echo-back-server', new EchoBack())
|
@@ -1,126 +0,0 @@
|
|
1
|
-
import 'cross-fetch/polyfill'
|
2
|
-
|
3
|
-
import { ApolloClient, ApolloLink, from, HttpLink, InMemoryCache } from '@apollo/client/core'
|
4
|
-
import { onError } from '@apollo/client/link/error'
|
5
|
-
import { Oauth2Client } from '@things-factory/oauth2-client'
|
6
|
-
import { getRepository } from '@things-factory/shell'
|
7
|
-
|
8
|
-
import { ConnectionManager } from '../connection-manager'
|
9
|
-
import { Connector } from '../types'
|
10
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
11
|
-
|
12
|
-
const defaultOptions: any = {
|
13
|
-
watchQuery: {
|
14
|
-
fetchPolicy: 'no-cache',
|
15
|
-
errorPolicy: 'ignore'
|
16
|
-
},
|
17
|
-
query: {
|
18
|
-
fetchPolicy: 'no-cache', //'network-only'
|
19
|
-
errorPolicy: 'all'
|
20
|
-
},
|
21
|
-
mutate: {
|
22
|
-
errorPolicy: 'all'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
export class GraphqlConnector implements Connector {
|
27
|
-
async ready(connectionConfigs: InputConnection[]) {
|
28
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
29
|
-
|
30
|
-
ConnectionManager.logger.info('graphql-connector connections are ready')
|
31
|
-
}
|
32
|
-
|
33
|
-
async connect(connection: InputConnection) {
|
34
|
-
const {
|
35
|
-
endpoint: uri,
|
36
|
-
params: { authClient }
|
37
|
-
} = connection
|
38
|
-
|
39
|
-
const ERROR_HANDLER: any = ({ graphQLErrors, networkError }) => {
|
40
|
-
if (graphQLErrors)
|
41
|
-
graphQLErrors.map(({ message, locations, path }) => {
|
42
|
-
ConnectionManager.logger.error(
|
43
|
-
`[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`,
|
44
|
-
graphQLErrors
|
45
|
-
)
|
46
|
-
})
|
47
|
-
|
48
|
-
if (networkError) {
|
49
|
-
ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}]`, networkError)
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
const oauth2Client: Oauth2Client = await getRepository(Oauth2Client).findOneBy({ id: authClient })
|
54
|
-
|
55
|
-
const authMiddleware = new ApolloLink((operation, forward) => {
|
56
|
-
// add the authorization to the headers
|
57
|
-
operation.setContext(({ headers = {} }) => ({
|
58
|
-
headers: {
|
59
|
-
...headers,
|
60
|
-
...oauth2Client.getAuthHeaders()
|
61
|
-
}
|
62
|
-
}))
|
63
|
-
|
64
|
-
return forward(operation)
|
65
|
-
})
|
66
|
-
|
67
|
-
const cache = new InMemoryCache({
|
68
|
-
addTypename: false
|
69
|
-
})
|
70
|
-
|
71
|
-
ConnectionManager.addConnectionInstance(
|
72
|
-
connection,
|
73
|
-
new ApolloClient({
|
74
|
-
defaultOptions,
|
75
|
-
cache,
|
76
|
-
link: from([
|
77
|
-
authMiddleware,
|
78
|
-
onError(ERROR_HANDLER),
|
79
|
-
new HttpLink({
|
80
|
-
uri,
|
81
|
-
credentials: 'include'
|
82
|
-
})
|
83
|
-
])
|
84
|
-
})
|
85
|
-
)
|
86
|
-
|
87
|
-
ConnectionManager.logger.info(
|
88
|
-
`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
89
|
-
)
|
90
|
-
}
|
91
|
-
|
92
|
-
async disconnect(connection: InputConnection) {
|
93
|
-
const client = ConnectionManager.getConnectionInstance(connection)
|
94
|
-
client.stop()
|
95
|
-
ConnectionManager.removeConnectionInstance(connection)
|
96
|
-
|
97
|
-
ConnectionManager.logger.info(`graphql-connector connection(${connection.name}) is disconnected`)
|
98
|
-
}
|
99
|
-
|
100
|
-
get parameterSpec() {
|
101
|
-
return [
|
102
|
-
{
|
103
|
-
type: 'entity-selector',
|
104
|
-
name: 'authClient',
|
105
|
-
label: 'auth-client',
|
106
|
-
property: {
|
107
|
-
queryName: 'oauth2Clients'
|
108
|
-
}
|
109
|
-
}
|
110
|
-
]
|
111
|
-
}
|
112
|
-
|
113
|
-
get taskPrefixes() {
|
114
|
-
return ['graphql']
|
115
|
-
}
|
116
|
-
|
117
|
-
get description() {
|
118
|
-
return 'Graphql Http Connector'
|
119
|
-
}
|
120
|
-
|
121
|
-
get help() {
|
122
|
-
return 'integration/connector/graphql-connector'
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
ConnectionManager.registerConnector('graphql-connector', new GraphqlConnector())
|
@@ -1,65 +0,0 @@
|
|
1
|
-
import { Oauth2Client } from '@things-factory/oauth2-client'
|
2
|
-
import { getRepository } from '@things-factory/shell'
|
3
|
-
|
4
|
-
import { ConnectionManager } from '../connection-manager'
|
5
|
-
import { Connector } from '../types'
|
6
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
7
|
-
|
8
|
-
export class HttpConnector implements Connector {
|
9
|
-
async ready(connectionConfigs: InputConnection[]) {
|
10
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
11
|
-
|
12
|
-
ConnectionManager.logger.info('http-connector connections are ready')
|
13
|
-
}
|
14
|
-
|
15
|
-
async connect(connection: InputConnection) {
|
16
|
-
var { params } = connection
|
17
|
-
params.rejectUnauthorized = (params.rejectUnauthorized || 'Y') === 'Y'
|
18
|
-
|
19
|
-
if (params.authClient) {
|
20
|
-
const oauth2Client: Oauth2Client = await getRepository(Oauth2Client).findOneBy({ id: params.authClient })
|
21
|
-
var authHeaders = oauth2Client.getAuthHeaders()
|
22
|
-
}
|
23
|
-
|
24
|
-
ConnectionManager.addConnectionInstance(connection, {
|
25
|
-
...connection,
|
26
|
-
authHeaders: authHeaders || {},
|
27
|
-
params
|
28
|
-
})
|
29
|
-
|
30
|
-
ConnectionManager.logger.info(`http-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
31
|
-
}
|
32
|
-
|
33
|
-
async disconnect(connection: InputConnection) {
|
34
|
-
ConnectionManager.removeConnectionInstance(connection)
|
35
|
-
|
36
|
-
ConnectionManager.logger.info(`http-connector connection(${connection.name}) is disconnected`)
|
37
|
-
}
|
38
|
-
|
39
|
-
get parameterSpec() {
|
40
|
-
return [
|
41
|
-
{
|
42
|
-
type: 'entity-selector',
|
43
|
-
name: 'authClient',
|
44
|
-
label: 'auth-client',
|
45
|
-
property: {
|
46
|
-
queryName: 'oauth2Clients'
|
47
|
-
}
|
48
|
-
},
|
49
|
-
{
|
50
|
-
type: 'select',
|
51
|
-
name: 'rejectUnauthorized',
|
52
|
-
label: 'reject-unauthorized',
|
53
|
-
property: {
|
54
|
-
options: ['Y', 'N']
|
55
|
-
}
|
56
|
-
}
|
57
|
-
]
|
58
|
-
}
|
59
|
-
|
60
|
-
get taskPrefixes() {
|
61
|
-
return ['http', 'headless-post', 'headless-scrap']
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
ConnectionManager.registerConnector('http-connector', new HttpConnector())
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import './echo-back-server'
|
2
|
-
import './echo-back-connector'
|
3
|
-
import './http-connector'
|
4
|
-
import './graphql-connector'
|
5
|
-
import './sqlite-connector'
|
6
|
-
import './postgresql-connector'
|
7
|
-
import './mqtt-connector'
|
8
|
-
import './mssql-connector'
|
9
|
-
import './oracle-connector'
|
10
|
-
import './mysql-connector'
|
11
|
-
import './socket-server'
|
12
|
-
import './operato-connector'
|
@@ -1,78 +0,0 @@
|
|
1
|
-
import { Connector } from '../types'
|
2
|
-
import { ConnectionManager } from '../connection-manager'
|
3
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
4
|
-
|
5
|
-
import mqtt from 'async-mqtt'
|
6
|
-
|
7
|
-
export class MqttConnector implements Connector {
|
8
|
-
async ready(connectionConfigs: InputConnection[]) {
|
9
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
10
|
-
|
11
|
-
ConnectionManager.logger.info('mqtt-connector connections are ready')
|
12
|
-
}
|
13
|
-
|
14
|
-
async connect(connection: InputConnection) {
|
15
|
-
const {
|
16
|
-
endpoint: uri,
|
17
|
-
params: { user, password }
|
18
|
-
} = connection
|
19
|
-
|
20
|
-
try {
|
21
|
-
var client = null
|
22
|
-
if (user && password) {
|
23
|
-
client = await mqtt.connectAsync(uri, { username: user, password: password })
|
24
|
-
} else {
|
25
|
-
client = await mqtt.connectAsync(uri)
|
26
|
-
}
|
27
|
-
|
28
|
-
if (!client) {
|
29
|
-
throw new Error(
|
30
|
-
`the initialization of mqtt connector is failed. uri: ${uri}, user: ${user} password: ${password}`
|
31
|
-
)
|
32
|
-
}
|
33
|
-
|
34
|
-
ConnectionManager.addConnectionInstance(connection, {
|
35
|
-
client,
|
36
|
-
connection
|
37
|
-
})
|
38
|
-
|
39
|
-
ConnectionManager.logger.info(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
40
|
-
} catch (err) {
|
41
|
-
ConnectionManager.logger.error(
|
42
|
-
`mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed.`,
|
43
|
-
err
|
44
|
-
)
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
async disconnect(connection: InputConnection) {
|
49
|
-
const { client } = ConnectionManager.removeConnectionInstance(connection)
|
50
|
-
|
51
|
-
client && (await client.end())
|
52
|
-
}
|
53
|
-
|
54
|
-
get parameterSpec() {
|
55
|
-
return [
|
56
|
-
{
|
57
|
-
type: 'string',
|
58
|
-
name: 'user',
|
59
|
-
label: 'user'
|
60
|
-
},
|
61
|
-
{
|
62
|
-
type: 'password',
|
63
|
-
name: 'password',
|
64
|
-
label: 'password'
|
65
|
-
}
|
66
|
-
]
|
67
|
-
}
|
68
|
-
|
69
|
-
get taskPrefixes() {
|
70
|
-
return ['mqtt']
|
71
|
-
}
|
72
|
-
|
73
|
-
get help() {
|
74
|
-
return 'integration/connector/mqtt-connector'
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
ConnectionManager.registerConnector('mqtt-connector', new MqttConnector())
|