@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,152 +0,0 @@
|
|
1
|
-
import { logger } from '@things-factory/env'
|
2
|
-
|
3
|
-
import { ConnectionManager } from '../connection-manager'
|
4
|
-
import { Connector } from '../types'
|
5
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
6
|
-
|
7
|
-
try {
|
8
|
-
var mssql = require('mssql')
|
9
|
-
} catch (err) {
|
10
|
-
logger.error('mssql module loading failed', err)
|
11
|
-
}
|
12
|
-
|
13
|
-
export class MssqlConnector implements Connector {
|
14
|
-
async ready(connectionConfigs: InputConnection[]) {
|
15
|
-
await Promise.all(connectionConfigs.map(this.connect))
|
16
|
-
|
17
|
-
ConnectionManager.logger.info('mssql-connector connections are ready')
|
18
|
-
}
|
19
|
-
|
20
|
-
async connect(connection: InputConnection) {
|
21
|
-
const {
|
22
|
-
endpoint,
|
23
|
-
params: { user, password, database, poolMin = 0, poolMax = 4, encrypt = 'Y', trustServerCertificate }
|
24
|
-
} = connection
|
25
|
-
|
26
|
-
const [host, port = 1433] = endpoint.split(':')
|
27
|
-
|
28
|
-
if (!mssql) {
|
29
|
-
throw new Error('mssql module loading failed')
|
30
|
-
}
|
31
|
-
|
32
|
-
const pool = await mssql.connect({
|
33
|
-
user,
|
34
|
-
password,
|
35
|
-
server: host,
|
36
|
-
port: Number(port),
|
37
|
-
database,
|
38
|
-
pool: {
|
39
|
-
max: Math.max(2, poolMax),
|
40
|
-
min: Math.max(0, poolMin),
|
41
|
-
idleTimeoutMillis: 30000
|
42
|
-
},
|
43
|
-
options: {
|
44
|
-
encrypt: encrypt === 'Y',
|
45
|
-
trustServerCertificate: trustServerCertificate === 'Y'
|
46
|
-
}
|
47
|
-
})
|
48
|
-
|
49
|
-
ConnectionManager.addConnectionInstance(connection, {
|
50
|
-
query: async (query, params) => {
|
51
|
-
var result = await pool.request().query(query)
|
52
|
-
return result.recordset
|
53
|
-
},
|
54
|
-
execute: async (procedure, params) => {
|
55
|
-
let request = pool.request()
|
56
|
-
|
57
|
-
Object.keys(params).forEach(key => {
|
58
|
-
let { dir, type, val } = params[key]
|
59
|
-
|
60
|
-
if (dir === 'in' || dir === 'inout') {
|
61
|
-
request.input(key, type, val)
|
62
|
-
} else if (dir === 'out') {
|
63
|
-
request.output(key, type)
|
64
|
-
} else {
|
65
|
-
console.error(`Invalid parameter direction(${dir}) for mssql stored procedure`)
|
66
|
-
}
|
67
|
-
})
|
68
|
-
|
69
|
-
var result = await request.execute(procedure)
|
70
|
-
return result
|
71
|
-
},
|
72
|
-
close: () => {
|
73
|
-
pool.close()
|
74
|
-
}
|
75
|
-
})
|
76
|
-
|
77
|
-
ConnectionManager.logger.info(`MSSql Database(${connection.name}:${database}) at ${endpoint} connected.`)
|
78
|
-
}
|
79
|
-
|
80
|
-
async disconnect(connection: InputConnection) {
|
81
|
-
var client = ConnectionManager.getConnectionInstance(connection)
|
82
|
-
try {
|
83
|
-
await client.close()
|
84
|
-
ConnectionManager.logger.info(`MSSql Database(${connection.name}) closed.`)
|
85
|
-
} catch (e) {
|
86
|
-
ConnectionManager.logger.error(e)
|
87
|
-
}
|
88
|
-
|
89
|
-
ConnectionManager.removeConnectionInstance(connection)
|
90
|
-
}
|
91
|
-
|
92
|
-
get parameterSpec() {
|
93
|
-
return [
|
94
|
-
{
|
95
|
-
type: 'string',
|
96
|
-
name: 'user',
|
97
|
-
label: 'user'
|
98
|
-
},
|
99
|
-
{
|
100
|
-
type: 'password',
|
101
|
-
name: 'password',
|
102
|
-
label: 'password'
|
103
|
-
},
|
104
|
-
{
|
105
|
-
type: 'string',
|
106
|
-
name: 'database',
|
107
|
-
placeholder: 'SID',
|
108
|
-
label: 'database'
|
109
|
-
},
|
110
|
-
{
|
111
|
-
type: 'select',
|
112
|
-
name: 'encrypt',
|
113
|
-
label: 'encrypt',
|
114
|
-
property: {
|
115
|
-
options: ['Y', 'N']
|
116
|
-
}
|
117
|
-
},
|
118
|
-
{
|
119
|
-
type: 'number',
|
120
|
-
name: 'poolMin',
|
121
|
-
placeholder: 'minimum connection-pool size',
|
122
|
-
label: 'pool-min',
|
123
|
-
value: 0
|
124
|
-
},
|
125
|
-
{
|
126
|
-
type: 'number',
|
127
|
-
name: 'poolMax',
|
128
|
-
placeholder: 'maximum connection-pool size',
|
129
|
-
label: 'pool-max',
|
130
|
-
value: 4
|
131
|
-
},
|
132
|
-
{
|
133
|
-
type: 'select',
|
134
|
-
name: 'trustServerCertificate',
|
135
|
-
label: 'trust-server-certificate',
|
136
|
-
property: {
|
137
|
-
options: ['Y', 'N']
|
138
|
-
}
|
139
|
-
}
|
140
|
-
]
|
141
|
-
}
|
142
|
-
|
143
|
-
get taskPrefixes() {
|
144
|
-
return ['database', 'mssql']
|
145
|
-
}
|
146
|
-
|
147
|
-
get help() {
|
148
|
-
return 'integration/connector/mssql-connector'
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
ConnectionManager.registerConnector('mssql-connector', new MssqlConnector())
|
@@ -1,94 +0,0 @@
|
|
1
|
-
import Mysql from "mysql2/promise";
|
2
|
-
|
3
|
-
import { Connector } from '../types'
|
4
|
-
import { ConnectionManager } from '../connection-manager'
|
5
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
6
|
-
|
7
|
-
export class mysqlConnector implements Connector {
|
8
|
-
async ready(connectionConfigs: InputConnection[]) {
|
9
|
-
await Promise.all(connectionConfigs.map(this.connect));
|
10
|
-
ConnectionManager.logger.info("mysql-connector connections are ready");
|
11
|
-
}
|
12
|
-
|
13
|
-
async connect(connection: InputConnection) {
|
14
|
-
const {
|
15
|
-
endpoint,
|
16
|
-
params: { user, password, database },
|
17
|
-
} = connection;
|
18
|
-
|
19
|
-
let [host, port = '3306'] = endpoint.split(":");
|
20
|
-
|
21
|
-
if (!Mysql) {
|
22
|
-
throw new Error("mysql module loading failed");
|
23
|
-
}
|
24
|
-
|
25
|
-
let pool = await Mysql.createPool({
|
26
|
-
user,
|
27
|
-
password,
|
28
|
-
host,
|
29
|
-
port: Number(port),
|
30
|
-
database,
|
31
|
-
});
|
32
|
-
|
33
|
-
const client = await pool.getConnection();
|
34
|
-
ConnectionManager.addConnectionInstance(connection, {
|
35
|
-
query: async (query, params) => {
|
36
|
-
var result;
|
37
|
-
try {
|
38
|
-
const results = await client.query(query);
|
39
|
-
if (results && results.length > 0) {
|
40
|
-
result = results[0];
|
41
|
-
}
|
42
|
-
} catch (e) {
|
43
|
-
ConnectionManager.logger.error(e);
|
44
|
-
}
|
45
|
-
return result;
|
46
|
-
},
|
47
|
-
close: client.end(),
|
48
|
-
});
|
49
|
-
|
50
|
-
ConnectionManager.logger.info(
|
51
|
-
`mysql Database(${connection.name}:${database}) at ${endpoint} connected.`
|
52
|
-
);
|
53
|
-
}
|
54
|
-
|
55
|
-
async disconnect(connection: InputConnection) {
|
56
|
-
var client = ConnectionManager.getConnectionInstance(connection);
|
57
|
-
try {
|
58
|
-
await client.close();
|
59
|
-
ConnectionManager.logger.info(
|
60
|
-
`mysql Database(${connection.name}) closed.`
|
61
|
-
);
|
62
|
-
} catch (e) {
|
63
|
-
ConnectionManager.logger.error(e);
|
64
|
-
}
|
65
|
-
|
66
|
-
ConnectionManager.removeConnectionInstance(connection);
|
67
|
-
}
|
68
|
-
|
69
|
-
get parameterSpec() {
|
70
|
-
return [
|
71
|
-
{
|
72
|
-
type: "string",
|
73
|
-
name: "user",
|
74
|
-
label: "user",
|
75
|
-
},
|
76
|
-
{
|
77
|
-
type: "password",
|
78
|
-
name: "password",
|
79
|
-
label: "password",
|
80
|
-
},
|
81
|
-
{
|
82
|
-
type: "string",
|
83
|
-
name: "database",
|
84
|
-
label: "database",
|
85
|
-
},
|
86
|
-
];
|
87
|
-
}
|
88
|
-
|
89
|
-
get taskPrefixes() {
|
90
|
-
return ["database"];
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
ConnectionManager.registerConnector("mysql-connector", new mysqlConnector());
|
@@ -1,264 +0,0 @@
|
|
1
|
-
import 'cross-fetch/polyfill'
|
2
|
-
|
3
|
-
import { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'
|
4
|
-
import { setContext } from '@apollo/client/link/context'
|
5
|
-
|
6
|
-
import WebSocket from 'ws'
|
7
|
-
import { createClient } from 'graphql-ws'
|
8
|
-
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
|
9
|
-
import { getMainDefinition } from '@apollo/client/utilities'
|
10
|
-
import gql from 'graphql-tag'
|
11
|
-
|
12
|
-
import { ConnectionManager } from '../connection-manager'
|
13
|
-
import { Connector } from '../types'
|
14
|
-
import { InputConnection } from '../../service/connection/connection-type'
|
15
|
-
|
16
|
-
import { Scenario } from '../../service/scenario/scenario'
|
17
|
-
import { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'
|
18
|
-
|
19
|
-
import { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'
|
20
|
-
import { User, checkUserHasRole } from '@things-factory/auth-base'
|
21
|
-
|
22
|
-
const debug = require('debug')('things-factory:integration-base:operato-connector')
|
23
|
-
|
24
|
-
const defaultOptions: any = {
|
25
|
-
watchQuery: {
|
26
|
-
fetchPolicy: 'no-cache',
|
27
|
-
errorPolicy: 'ignore'
|
28
|
-
},
|
29
|
-
query: {
|
30
|
-
fetchPolicy: 'no-cache', //'network-only'
|
31
|
-
errorPolicy: 'all'
|
32
|
-
},
|
33
|
-
mutate: {
|
34
|
-
errorPolicy: 'all'
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
export const GRAPHQL_URI = '/graphql'
|
39
|
-
export const SUBSCRIPTION_URI = GRAPHQL_URI
|
40
|
-
|
41
|
-
interface SubscriberData {
|
42
|
-
tag: string
|
43
|
-
scenario: any
|
44
|
-
subscriptionObserver: any
|
45
|
-
}
|
46
|
-
|
47
|
-
export class OperatoConnector implements Connector {
|
48
|
-
private context: any
|
49
|
-
|
50
|
-
async ready(connectionConfigs: InputConnection[]) {
|
51
|
-
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
52
|
-
|
53
|
-
ConnectionManager.logger.info('operato-connector connections are ready')
|
54
|
-
}
|
55
|
-
|
56
|
-
async connect(connection: InputConnection) {
|
57
|
-
const {
|
58
|
-
endpoint: uri,
|
59
|
-
params: { authKey, domain, subscriptionHandlers = {} }
|
60
|
-
} = connection
|
61
|
-
|
62
|
-
if (!authKey || !domain) {
|
63
|
-
throw new Error('some connection paramter missing.')
|
64
|
-
}
|
65
|
-
|
66
|
-
const domainOwner = await getRepository(User).findOne({
|
67
|
-
where: {
|
68
|
-
id: connection.domain.owner
|
69
|
-
}
|
70
|
-
})
|
71
|
-
|
72
|
-
this.context = {
|
73
|
-
domain: connection.domain,
|
74
|
-
user: domainOwner
|
75
|
-
/* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */
|
76
|
-
}
|
77
|
-
|
78
|
-
const httpLink = createHttpLink({
|
79
|
-
uri: uri
|
80
|
-
})
|
81
|
-
|
82
|
-
/*
|
83
|
-
CHECKPOINT:
|
84
|
-
1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.
|
85
|
-
따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.
|
86
|
-
|
87
|
-
2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.
|
88
|
-
*/
|
89
|
-
const wsLink = new GraphQLWsLink(
|
90
|
-
createClient({
|
91
|
-
url: uri.replace(/^http/, 'ws'),
|
92
|
-
keepAlive: 10_000,
|
93
|
-
retryAttempts: 1_000_000,
|
94
|
-
shouldRetry: e => true,
|
95
|
-
webSocketImpl: WebSocket,
|
96
|
-
connectionParams: {
|
97
|
-
headers: {
|
98
|
-
'x-things-factory-domain': domain,
|
99
|
-
authorization: authKey ? `Bearer ${authKey}` : ''
|
100
|
-
}
|
101
|
-
}
|
102
|
-
})
|
103
|
-
)
|
104
|
-
|
105
|
-
const splitLink = split(
|
106
|
-
({ query }) => {
|
107
|
-
const def = getMainDefinition(query)
|
108
|
-
return def.kind === 'OperationDefinition' && def.operation === 'subscription'
|
109
|
-
},
|
110
|
-
wsLink,
|
111
|
-
setContext((_, { headers }) => {
|
112
|
-
return {
|
113
|
-
headers: {
|
114
|
-
...headers,
|
115
|
-
'x-things-factory-domain': domain,
|
116
|
-
authorization: authKey ? `Bearer ${authKey}` : ''
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}).concat(httpLink)
|
120
|
-
)
|
121
|
-
|
122
|
-
const cache = new InMemoryCache({
|
123
|
-
addTypename: false
|
124
|
-
})
|
125
|
-
|
126
|
-
const client = new ApolloClient({
|
127
|
-
defaultOptions,
|
128
|
-
cache,
|
129
|
-
link: splitLink
|
130
|
-
})
|
131
|
-
|
132
|
-
const subscriptions: SubscriberData[] = []
|
133
|
-
Object.keys(subscriptionHandlers).forEach(async tag => {
|
134
|
-
if (!tag || !subscriptionHandlers[tag]) return
|
135
|
-
|
136
|
-
const scenarioName = subscriptionHandlers[tag]
|
137
|
-
|
138
|
-
// fetch a scenario
|
139
|
-
const selectedScenario = await getRepository(Scenario).findOne({
|
140
|
-
where: {
|
141
|
-
name: scenarioName
|
142
|
-
},
|
143
|
-
relations: ['steps', 'domain']
|
144
|
-
})
|
145
|
-
|
146
|
-
const subscription = client.subscribe({
|
147
|
-
query: gql`
|
148
|
-
subscription {
|
149
|
-
data(tag: "${tag}") {
|
150
|
-
tag
|
151
|
-
data
|
152
|
-
}
|
153
|
-
}
|
154
|
-
`
|
155
|
-
})
|
156
|
-
|
157
|
-
const subscriptionObserver = subscription.subscribe({
|
158
|
-
next: async data => {
|
159
|
-
debug('received pubsub msg.:', data?.data)
|
160
|
-
await this.runScenario(subscriptions, data?.data?.data)
|
161
|
-
},
|
162
|
-
error: error => {
|
163
|
-
ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)
|
164
|
-
},
|
165
|
-
complete: () => {
|
166
|
-
ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)
|
167
|
-
}
|
168
|
-
})
|
169
|
-
|
170
|
-
ConnectionManager.logger.info(
|
171
|
-
`(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`
|
172
|
-
)
|
173
|
-
|
174
|
-
subscriptions.push({
|
175
|
-
tag,
|
176
|
-
scenario: selectedScenario,
|
177
|
-
subscriptionObserver
|
178
|
-
})
|
179
|
-
ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)
|
180
|
-
})
|
181
|
-
|
182
|
-
client['subscriptions'] = subscriptions
|
183
|
-
ConnectionManager.addConnectionInstance(connection, client)
|
184
|
-
|
185
|
-
ConnectionManager.logger.info(
|
186
|
-
`operato-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
187
|
-
)
|
188
|
-
}
|
189
|
-
|
190
|
-
async disconnect(connection: InputConnection) {
|
191
|
-
const client = ConnectionManager.getConnectionInstance(connection)
|
192
|
-
const subscriptions: SubscriberData[] = client['subscriptions']
|
193
|
-
subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())
|
194
|
-
client.stop()
|
195
|
-
ConnectionManager.removeConnectionInstance(connection)
|
196
|
-
|
197
|
-
ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)
|
198
|
-
}
|
199
|
-
|
200
|
-
async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {
|
201
|
-
const { domain, user } = this.context
|
202
|
-
const { tag } = variables
|
203
|
-
|
204
|
-
if (!tag) {
|
205
|
-
throw new Error(`tag is invalid - ${tag}`)
|
206
|
-
}
|
207
|
-
|
208
|
-
const scenario = subscriptions.find(subscription => subscription.tag === tag)?.scenario
|
209
|
-
if (!scenario) {
|
210
|
-
throw new Error(`scenario is not found - ${tag}`)
|
211
|
-
}
|
212
|
-
|
213
|
-
if (!(await checkUserHasRole(scenario.roleId, domain, user))) {
|
214
|
-
throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)
|
215
|
-
}
|
216
|
-
|
217
|
-
/* create a scenario instance */
|
218
|
-
const instanceName = scenario.name + '-' + String(Date.now())
|
219
|
-
const instance = new ScenarioInstance(instanceName, scenario, {
|
220
|
-
user,
|
221
|
-
domain,
|
222
|
-
variables,
|
223
|
-
client: GraphqlLocalClient.client
|
224
|
-
})
|
225
|
-
|
226
|
-
// run scenario
|
227
|
-
await instance.run()
|
228
|
-
return instance
|
229
|
-
}
|
230
|
-
|
231
|
-
get parameterSpec() {
|
232
|
-
return [
|
233
|
-
{
|
234
|
-
type: 'string',
|
235
|
-
name: 'authKey',
|
236
|
-
label: 'auth-key'
|
237
|
-
},
|
238
|
-
{
|
239
|
-
type: 'string',
|
240
|
-
name: 'domain',
|
241
|
-
label: 'domain'
|
242
|
-
},
|
243
|
-
{
|
244
|
-
type: 'tag-scenarios',
|
245
|
-
name: 'subscriptionHandlers',
|
246
|
-
label: 'subscription-handlers'
|
247
|
-
}
|
248
|
-
]
|
249
|
-
}
|
250
|
-
|
251
|
-
get taskPrefixes() {
|
252
|
-
return ['graphql']
|
253
|
-
}
|
254
|
-
|
255
|
-
get help() {
|
256
|
-
return 'integration/connector/operato-connector'
|
257
|
-
}
|
258
|
-
|
259
|
-
get description() {
|
260
|
-
return 'Operato Graphql Connector'
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
ConnectionManager.registerConnector('operato-connector', new OperatoConnector())
|