@things-factory/integration-base 8.0.0-beta.1 → 8.0.0-beta.4
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/package.json +10 -10
- package/server/controllers/index.ts +0 -2
- package/server/controllers/publish-data.ts +0 -29
- package/server/controllers/scenario-controller.ts +0 -156
- package/server/engine/analyzer/analyze-integration.ts +0 -115
- package/server/engine/connection-manager.ts +0 -239
- 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/headless-connector.ts +0 -341
- package/server/engine/connector/http-connector.ts +0 -65
- package/server/engine/connector/index.ts +0 -13
- 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 -11
- package/server/engine/pending-queue.ts +0 -97
- package/server/engine/resource-pool/headless-pool.ts +0 -136
- package/server/engine/resource-pool/index.ts +0 -1
- 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 -128
- package/server/engine/task/headless-scrap.ts +0 -83
- 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 -30
- 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 -288
- 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 -563
- 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 -215
- 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,148 +0,0 @@
|
|
1
|
-
import fetch from 'node-fetch'
|
2
|
-
import { URL } from 'url'
|
3
|
-
import 'ses'
|
4
|
-
import { access } from '@things-factory/utils'
|
5
|
-
import { TaskRegistry } from '../task-registry'
|
6
|
-
import { ConnectionManager } from '../connection-manager'
|
7
|
-
import https from 'https'
|
8
|
-
import { InputStep } from '../../service/step/step-type'
|
9
|
-
import { Context } from '../types'
|
10
|
-
|
11
|
-
async function HttpPost(step: InputStep, { logger, data, domain, user, variables, lng }: Context) {
|
12
|
-
var { connection: connectionName, params: stepOptions } = step
|
13
|
-
var { headers: requestHeaders, contentType, path, accessor } = stepOptions || {}
|
14
|
-
|
15
|
-
var connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
|
16
|
-
|
17
|
-
if (!connection) {
|
18
|
-
throw new Error(`connection '${connectionName}' is not established.`)
|
19
|
-
}
|
20
|
-
|
21
|
-
var { endpoint, params: connectionParams, authHeaders = {} } = connection
|
22
|
-
|
23
|
-
const compartment = new Compartment({
|
24
|
-
domain,
|
25
|
-
user,
|
26
|
-
lng,
|
27
|
-
data,
|
28
|
-
variables,
|
29
|
-
console
|
30
|
-
})
|
31
|
-
|
32
|
-
let evalPath
|
33
|
-
try {
|
34
|
-
evalPath = compartment.evaluate('`' + path + '`')
|
35
|
-
} catch (err) {
|
36
|
-
throw new Error(`Failed to evaluate path: ${err.message}`)
|
37
|
-
}
|
38
|
-
|
39
|
-
path = evalPath
|
40
|
-
|
41
|
-
requestHeaders =
|
42
|
-
requestHeaders &&
|
43
|
-
Object.entries(requestHeaders as { [key: string]: string }).reduce((sum, [key, value]) => {
|
44
|
-
try {
|
45
|
-
sum[key] = compartment.evaluate('`' + value + '`')
|
46
|
-
} catch (err) {
|
47
|
-
throw new Error(`Failed to evaluate header value: ${err.message}`)
|
48
|
-
}
|
49
|
-
return sum
|
50
|
-
}, {})
|
51
|
-
|
52
|
-
var url = new URL(path, endpoint)
|
53
|
-
var headers = {
|
54
|
-
...authHeaders,
|
55
|
-
...requestHeaders
|
56
|
-
}
|
57
|
-
|
58
|
-
var body = access(accessor, data)
|
59
|
-
if (contentType && body) {
|
60
|
-
headers['content-type'] = contentType
|
61
|
-
switch (contentType) {
|
62
|
-
case 'text/plain':
|
63
|
-
body = JSON.stringify(body)
|
64
|
-
break
|
65
|
-
case 'application/json':
|
66
|
-
body = JSON.stringify(body)
|
67
|
-
break
|
68
|
-
case 'application/x-www-form-urlencoded':
|
69
|
-
const searchParams = new URLSearchParams()
|
70
|
-
for (const prop in body) {
|
71
|
-
searchParams.set(prop, body[prop])
|
72
|
-
}
|
73
|
-
body = searchParams
|
74
|
-
break
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
var fetchOptions: any = {
|
79
|
-
method: 'POST',
|
80
|
-
headers,
|
81
|
-
body
|
82
|
-
}
|
83
|
-
|
84
|
-
var { rejectUnauthorized } = connectionParams
|
85
|
-
|
86
|
-
if (!rejectUnauthorized) {
|
87
|
-
const httpsAgent = new https.Agent({
|
88
|
-
rejectUnauthorized
|
89
|
-
})
|
90
|
-
fetchOptions.agent = httpsAgent
|
91
|
-
}
|
92
|
-
|
93
|
-
var response = await fetch(url, fetchOptions)
|
94
|
-
|
95
|
-
return {
|
96
|
-
data:
|
97
|
-
response.ok && response.headers.get('content-type').includes('application/json')
|
98
|
-
? await response.json()
|
99
|
-
: await response.text()
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
HttpPost.parameterSpec = [
|
104
|
-
{
|
105
|
-
type: 'string',
|
106
|
-
name: 'path',
|
107
|
-
label: 'path'
|
108
|
-
},
|
109
|
-
{
|
110
|
-
type: 'http-headers',
|
111
|
-
name: 'headers',
|
112
|
-
label: 'headers'
|
113
|
-
},
|
114
|
-
{
|
115
|
-
type: 'select',
|
116
|
-
name: 'contentType',
|
117
|
-
label: 'content-type',
|
118
|
-
property: {
|
119
|
-
options: [
|
120
|
-
{
|
121
|
-
display: '',
|
122
|
-
value: ''
|
123
|
-
},
|
124
|
-
{
|
125
|
-
display: 'application/json',
|
126
|
-
value: 'application/json'
|
127
|
-
},
|
128
|
-
{
|
129
|
-
display: 'text/plain',
|
130
|
-
value: 'text/plain'
|
131
|
-
},
|
132
|
-
{
|
133
|
-
display: 'application/x-www-form-urlencoded',
|
134
|
-
value: 'application/x-www-form-urlencoded'
|
135
|
-
}
|
136
|
-
]
|
137
|
-
}
|
138
|
-
},
|
139
|
-
{
|
140
|
-
type: 'scenario-step-input',
|
141
|
-
name: 'accessor',
|
142
|
-
label: 'accessor'
|
143
|
-
}
|
144
|
-
]
|
145
|
-
|
146
|
-
HttpPost.help = 'integration/task/http-post'
|
147
|
-
|
148
|
-
TaskRegistry.registerTaskHandler('http-post', HttpPost)
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import './echo-send'
|
2
|
-
import './echo-receive'
|
3
|
-
import './sleep'
|
4
|
-
import './log'
|
5
|
-
import './publish'
|
6
|
-
import './http-get'
|
7
|
-
import './http-post'
|
8
|
-
import './graphql-query'
|
9
|
-
import './graphql-mutate'
|
10
|
-
import './local-graphql-query'
|
11
|
-
import './local-graphql-mutate'
|
12
|
-
import './sub-scenario'
|
13
|
-
import './stop-scenario'
|
14
|
-
import './book-up-scenario'
|
15
|
-
import './pick-pending-scenario'
|
16
|
-
import './reset-pending-queue'
|
17
|
-
import './empty-check'
|
18
|
-
import './goto'
|
19
|
-
import './end'
|
20
|
-
import './switch-goto'
|
21
|
-
import './switch-range-goto'
|
22
|
-
import './switch-scenario'
|
23
|
-
import './switch-range-scenario'
|
24
|
-
import './switch-set'
|
25
|
-
import './switch-range-set'
|
26
|
-
import './script'
|
27
|
-
import './database-query'
|
28
|
-
import './mqtt-subscribe'
|
29
|
-
import './mqtt-publish'
|
30
|
-
import './throw'
|
31
|
-
import './variables'
|
32
|
-
import './floating-point'
|
33
|
-
import './socket-listener'
|
34
|
-
import './random'
|
35
|
-
import './csv-readline'
|
36
|
-
import './data-mapper'
|
37
|
-
import './headless-post'
|
38
|
-
import './headless-scrap'
|
39
|
-
import './set-domain'
|
40
|
-
import './mssql-procedure'
|
41
|
-
import './oracle-procedure'
|
42
|
-
import './jsonata'
|
43
|
-
import './state-read'
|
44
|
-
import './state-write'
|
45
|
-
import './state-group-read'
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import jsonata from 'jsonata'
|
2
|
-
|
3
|
-
import { TaskRegistry } from '../task-registry'
|
4
|
-
import { InputStep } from '../../service/step/step-type'
|
5
|
-
import { Context } from '../types'
|
6
|
-
|
7
|
-
async function JSonata(step: InputStep, context: Context) {
|
8
|
-
var {
|
9
|
-
params: { expression }
|
10
|
-
} = step
|
11
|
-
|
12
|
-
const { domain, user, data, variables, lng, logger } = context
|
13
|
-
|
14
|
-
var result = jsonata(expression).evaluate({
|
15
|
-
domain,
|
16
|
-
user,
|
17
|
-
lng,
|
18
|
-
data,
|
19
|
-
variables
|
20
|
-
})
|
21
|
-
|
22
|
-
return {
|
23
|
-
data: result
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
JSonata.parameterSpec = [
|
28
|
-
{
|
29
|
-
type: 'textarea',
|
30
|
-
name: 'expression',
|
31
|
-
label: 'jsonata-expression',
|
32
|
-
property: {
|
33
|
-
language: 'javascript',
|
34
|
-
showLineNumbers: true
|
35
|
-
},
|
36
|
-
styles: {
|
37
|
-
flex: '1'
|
38
|
-
}
|
39
|
-
}
|
40
|
-
]
|
41
|
-
|
42
|
-
JSonata.connectorFree = true
|
43
|
-
JSonata.help = 'integration/task/jsonata'
|
44
|
-
|
45
|
-
TaskRegistry.registerTaskHandler('jsonata', JSonata)
|
@@ -1,100 +0,0 @@
|
|
1
|
-
import gql from 'graphql-tag'
|
2
|
-
import 'ses'
|
3
|
-
|
4
|
-
import { User } from '@things-factory/auth-base'
|
5
|
-
import { getRepository } from '@things-factory/shell'
|
6
|
-
import { access } from '@things-factory/utils'
|
7
|
-
|
8
|
-
import { TaskRegistry } from '../task-registry'
|
9
|
-
import { InputStep } from '../../service/step/step-type'
|
10
|
-
import { Context } from '../types'
|
11
|
-
|
12
|
-
async function LocalGraphqlMutate(step: InputStep, context: Context) {
|
13
|
-
var { params, updaterId } = step
|
14
|
-
var { mutation, variables: variablesAccessorMap, headers } = params || {}
|
15
|
-
var { logger, client, domain, user, data, variables, lng } = context
|
16
|
-
|
17
|
-
user =
|
18
|
-
user ||
|
19
|
-
(await getRepository(User).findOne({
|
20
|
-
where: { id: updaterId },
|
21
|
-
relations: ['domains']
|
22
|
-
}))
|
23
|
-
|
24
|
-
const compartment = new Compartment({
|
25
|
-
domain,
|
26
|
-
user,
|
27
|
-
lng,
|
28
|
-
data,
|
29
|
-
variables,
|
30
|
-
console
|
31
|
-
})
|
32
|
-
|
33
|
-
let evalMutation
|
34
|
-
try {
|
35
|
-
evalMutation = compartment.evaluate('`' + mutation + '`')
|
36
|
-
} catch (err) {
|
37
|
-
throw new Error(`Failed to evaluate mutation: ${err.message}`)
|
38
|
-
}
|
39
|
-
|
40
|
-
mutation = evalMutation
|
41
|
-
|
42
|
-
const queryVariables = Object.keys(variablesAccessorMap || {}).reduce((variables, key) => {
|
43
|
-
const accessor = variablesAccessorMap[key]
|
44
|
-
variables[key] = access(accessor, data)
|
45
|
-
return variables
|
46
|
-
}, {})
|
47
|
-
|
48
|
-
var { data: mutateResult, errors } = await client.mutate({
|
49
|
-
mutation: gql`
|
50
|
-
${mutation}
|
51
|
-
`,
|
52
|
-
variables: queryVariables,
|
53
|
-
headers,
|
54
|
-
context: {
|
55
|
-
state: {
|
56
|
-
domain,
|
57
|
-
user
|
58
|
-
}
|
59
|
-
}
|
60
|
-
})
|
61
|
-
|
62
|
-
if (errors) {
|
63
|
-
errors.forEach(error => {
|
64
|
-
logger.error('GraphQL Error: %s', error)
|
65
|
-
})
|
66
|
-
}
|
67
|
-
|
68
|
-
return {
|
69
|
-
data: mutateResult
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
LocalGraphqlMutate.parameterSpec = [
|
74
|
-
{
|
75
|
-
type: 'graphql',
|
76
|
-
name: 'mutation',
|
77
|
-
label: 'mutation',
|
78
|
-
property: {
|
79
|
-
showLineNumbers: true
|
80
|
-
},
|
81
|
-
styles: {
|
82
|
-
flex: 1
|
83
|
-
}
|
84
|
-
},
|
85
|
-
{
|
86
|
-
type: 'key-values',
|
87
|
-
name: 'variables',
|
88
|
-
label: 'variables'
|
89
|
-
},
|
90
|
-
{
|
91
|
-
type: 'key-values',
|
92
|
-
name: 'headers',
|
93
|
-
label: 'headers'
|
94
|
-
}
|
95
|
-
]
|
96
|
-
|
97
|
-
LocalGraphqlMutate.connectorFree = true
|
98
|
-
LocalGraphqlMutate.help = 'integration/task/local-graphql-mutate'
|
99
|
-
|
100
|
-
TaskRegistry.registerTaskHandler('local-graphql-mutate', LocalGraphqlMutate)
|
@@ -1,100 +0,0 @@
|
|
1
|
-
import gql from 'graphql-tag'
|
2
|
-
import 'ses'
|
3
|
-
|
4
|
-
import { User } from '@things-factory/auth-base'
|
5
|
-
import { getRepository } from '@things-factory/shell'
|
6
|
-
import { access } from '@things-factory/utils'
|
7
|
-
|
8
|
-
import { TaskRegistry } from '../task-registry'
|
9
|
-
import { InputStep } from '../../service/step/step-type'
|
10
|
-
import { Context } from '../types'
|
11
|
-
|
12
|
-
async function LocalGraphqlQuery(step: InputStep, context: Context) {
|
13
|
-
var { params, updaterId } = step
|
14
|
-
var { query, variables: variablesAccessorMap, headers } = params || {}
|
15
|
-
var { logger, client, domain, user, data, variables, lng } = context
|
16
|
-
|
17
|
-
user =
|
18
|
-
user ||
|
19
|
-
(await getRepository(User).findOne({
|
20
|
-
where: { id: updaterId },
|
21
|
-
relations: ['domains']
|
22
|
-
}))
|
23
|
-
|
24
|
-
const compartment = new Compartment({
|
25
|
-
domain,
|
26
|
-
user,
|
27
|
-
lng,
|
28
|
-
data,
|
29
|
-
variables,
|
30
|
-
console
|
31
|
-
})
|
32
|
-
|
33
|
-
let evalQuery
|
34
|
-
try {
|
35
|
-
evalQuery = compartment.evaluate('`' + query + '`')
|
36
|
-
} catch (err) {
|
37
|
-
throw new Error(`Failed to evaluate query: ${err.message}`)
|
38
|
-
}
|
39
|
-
|
40
|
-
query = evalQuery
|
41
|
-
|
42
|
-
const queryVariables = Object.keys(variablesAccessorMap || {}).reduce((variables, key) => {
|
43
|
-
const accessor = variablesAccessorMap[key]
|
44
|
-
variables[key] = access(accessor, data)
|
45
|
-
return variables
|
46
|
-
}, {})
|
47
|
-
|
48
|
-
var { data: queryResult, errors } = await client.query({
|
49
|
-
query: gql`
|
50
|
-
${query}
|
51
|
-
`,
|
52
|
-
variables: queryVariables,
|
53
|
-
headers,
|
54
|
-
context: {
|
55
|
-
state: {
|
56
|
-
domain,
|
57
|
-
user
|
58
|
-
}
|
59
|
-
}
|
60
|
-
})
|
61
|
-
|
62
|
-
if (errors) {
|
63
|
-
errors.forEach(error => {
|
64
|
-
logger.error('GraphQL Error: %s', error)
|
65
|
-
})
|
66
|
-
}
|
67
|
-
|
68
|
-
return {
|
69
|
-
data: queryResult
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
LocalGraphqlQuery.parameterSpec = [
|
74
|
-
{
|
75
|
-
type: 'graphql',
|
76
|
-
name: 'query',
|
77
|
-
label: 'query',
|
78
|
-
property: {
|
79
|
-
showLineNumbers: true
|
80
|
-
},
|
81
|
-
styles: {
|
82
|
-
flex: 1
|
83
|
-
}
|
84
|
-
},
|
85
|
-
{
|
86
|
-
type: 'key-values',
|
87
|
-
name: 'variables',
|
88
|
-
label: 'variables'
|
89
|
-
},
|
90
|
-
{
|
91
|
-
type: 'key-values',
|
92
|
-
name: 'headers',
|
93
|
-
label: 'headers'
|
94
|
-
}
|
95
|
-
]
|
96
|
-
|
97
|
-
LocalGraphqlQuery.connectorFree = true
|
98
|
-
LocalGraphqlQuery.help = 'integration/task/local-graphql-query'
|
99
|
-
|
100
|
-
TaskRegistry.registerTaskHandler('local-graphql-query', LocalGraphqlQuery)
|
@@ -1,78 +0,0 @@
|
|
1
|
-
import { access, hasTemplateExpression } from '@things-factory/utils'
|
2
|
-
import 'ses'
|
3
|
-
import { TaskRegistry } from '../task-registry'
|
4
|
-
import { InputStep } from '../../service/step/step-type'
|
5
|
-
import { Context } from '../types'
|
6
|
-
|
7
|
-
async function Log(step: InputStep, { logger, data, variables, domain, user, lng }: Context) {
|
8
|
-
var {
|
9
|
-
params: { message, accessor, level = 'info' }
|
10
|
-
} = step
|
11
|
-
|
12
|
-
if (hasTemplateExpression(message)) {
|
13
|
-
const compartment = new Compartment({
|
14
|
-
domain,
|
15
|
-
user,
|
16
|
-
lng,
|
17
|
-
data,
|
18
|
-
variables,
|
19
|
-
console
|
20
|
-
})
|
21
|
-
|
22
|
-
try {
|
23
|
-
message = compartment.evaluate('`' + message + '`')
|
24
|
-
} catch (err) {
|
25
|
-
throw new Error(`Failed to evaluate message: ${err.message}`)
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
accessor = access(accessor, data)
|
30
|
-
|
31
|
-
if (accessor) {
|
32
|
-
if (typeof accessor !== 'string') {
|
33
|
-
accessor = JSON.stringify(accessor, null, 2)
|
34
|
-
}
|
35
|
-
message += ': ' + accessor
|
36
|
-
}
|
37
|
-
|
38
|
-
switch (level) {
|
39
|
-
case 'error':
|
40
|
-
logger.error(message)
|
41
|
-
return
|
42
|
-
case 'warn':
|
43
|
-
logger.warn(message)
|
44
|
-
return
|
45
|
-
default:
|
46
|
-
logger.info(message)
|
47
|
-
}
|
48
|
-
|
49
|
-
return {
|
50
|
-
data: message
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
Log.parameterSpec = [
|
55
|
-
{
|
56
|
-
type: 'string',
|
57
|
-
name: 'message',
|
58
|
-
label: 'message'
|
59
|
-
},
|
60
|
-
{
|
61
|
-
type: 'scenario-step-input',
|
62
|
-
name: 'accessor',
|
63
|
-
label: 'accessor'
|
64
|
-
},
|
65
|
-
{
|
66
|
-
type: 'select',
|
67
|
-
name: 'level',
|
68
|
-
label: 'level',
|
69
|
-
property: {
|
70
|
-
options: ['info', 'warn', 'error']
|
71
|
-
}
|
72
|
-
}
|
73
|
-
]
|
74
|
-
|
75
|
-
Log.connectorFree = true
|
76
|
-
Log.help = 'integration/task/log'
|
77
|
-
|
78
|
-
TaskRegistry.registerTaskHandler('log', Log)
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import { access } from '@things-factory/utils'
|
2
|
-
import { TaskRegistry } from '../task-registry'
|
3
|
-
import { ConnectionManager } from '../connection-manager'
|
4
|
-
import { InputStep } from '../../service/step/step-type'
|
5
|
-
import { Context } from '../types'
|
6
|
-
|
7
|
-
async function MqttPublish(step: InputStep, { logger, data, domain }: Context) {
|
8
|
-
var {
|
9
|
-
connection: connectionName,
|
10
|
-
params: { topic, accessor }
|
11
|
-
} = step
|
12
|
-
|
13
|
-
const { client } = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
|
14
|
-
if (!client) {
|
15
|
-
throw Error(`connection is not found : ${connectionName}`)
|
16
|
-
}
|
17
|
-
|
18
|
-
if (!topic || !accessor) {
|
19
|
-
throw Error(`topic and accessor should be defined: : topic - '${topic}', accessor - '${accessor}'`)
|
20
|
-
}
|
21
|
-
|
22
|
-
var message = JSON.stringify(access(accessor, data))
|
23
|
-
await client.publish(topic, message)
|
24
|
-
|
25
|
-
return {
|
26
|
-
data: message
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
MqttPublish.parameterSpec = [
|
31
|
-
{
|
32
|
-
type: 'string',
|
33
|
-
name: 'topic',
|
34
|
-
label: 'topic'
|
35
|
-
},
|
36
|
-
{
|
37
|
-
type: 'scenario-step-input',
|
38
|
-
name: 'accessor',
|
39
|
-
label: 'accessor'
|
40
|
-
}
|
41
|
-
]
|
42
|
-
|
43
|
-
MqttPublish.help = 'integration/task/mqtt-publish'
|
44
|
-
|
45
|
-
TaskRegistry.registerTaskHandler('mqtt-publish', MqttPublish)
|
@@ -1,139 +0,0 @@
|
|
1
|
-
import mqtt from 'async-mqtt'
|
2
|
-
|
3
|
-
import { TaskRegistry } from '../task-registry'
|
4
|
-
import { ConnectionManager } from '../connection-manager'
|
5
|
-
import { sleep } from '@things-factory/utils'
|
6
|
-
import { InputStep } from '../../service/step/step-type'
|
7
|
-
import { Context } from '../types'
|
8
|
-
|
9
|
-
function convertDataFormat(data, format) {
|
10
|
-
if (format == 'json') {
|
11
|
-
return JSON.parse(data)
|
12
|
-
} else {
|
13
|
-
return data.toString()
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
async function MqttSubscribe(step: InputStep, context: Context) {
|
18
|
-
const {
|
19
|
-
connection: connectionName,
|
20
|
-
params: { topic, dataFormat },
|
21
|
-
name
|
22
|
-
} = step
|
23
|
-
|
24
|
-
const { domain, logger, closures, __mqtt_subscriber } = context
|
25
|
-
if (!__mqtt_subscriber) {
|
26
|
-
context.__mqtt_subscriber = {}
|
27
|
-
}
|
28
|
-
|
29
|
-
const {
|
30
|
-
connection: {
|
31
|
-
endpoint: uri,
|
32
|
-
params: { user, password }
|
33
|
-
}
|
34
|
-
} = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
|
35
|
-
|
36
|
-
if (!topic) {
|
37
|
-
throw Error(`topic is not found for ${connectionName}`)
|
38
|
-
}
|
39
|
-
|
40
|
-
/*
|
41
|
-
* 1. subscriber list에서 subscriber를 찾는다. 없으면, 생성한다.
|
42
|
-
* 2. client.once(...)로 메시지를 취한다.
|
43
|
-
*
|
44
|
-
* TODO 동일 브로커의 다중 subscribe 태스크에 대해서 완벽한 지원을 해야한다.
|
45
|
-
* - 현재는 여러 태스크가 동일 topic을 subscribe 하는 경우에 정상동작하지 않을 것이다.
|
46
|
-
*/
|
47
|
-
if (!context.__mqtt_subscriber[name]) {
|
48
|
-
try {
|
49
|
-
var broker = null
|
50
|
-
if (user && password) {
|
51
|
-
broker = await mqtt.connectAsync(uri, { username: user, password: password })
|
52
|
-
} else {
|
53
|
-
broker = await mqtt.connectAsync(uri)
|
54
|
-
}
|
55
|
-
|
56
|
-
logger.info(`mqtt-connector connection(${connectionName}:${uri}) is connected`)
|
57
|
-
|
58
|
-
await broker.subscribe(topic)
|
59
|
-
logger.info(`success subscribing topic '${topic}'`)
|
60
|
-
|
61
|
-
var TOPIC
|
62
|
-
var MESSAGE
|
63
|
-
|
64
|
-
context.__mqtt_subscriber[name] = async () => {
|
65
|
-
while (!MESSAGE) {
|
66
|
-
await sleep(100)
|
67
|
-
}
|
68
|
-
|
69
|
-
var topic = TOPIC
|
70
|
-
var message = MESSAGE
|
71
|
-
|
72
|
-
TOPIC = null
|
73
|
-
MESSAGE = null
|
74
|
-
|
75
|
-
return {
|
76
|
-
topic,
|
77
|
-
message
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
broker.on('message', async (messageTopic, message) => {
|
82
|
-
if (topic !== messageTopic) {
|
83
|
-
return
|
84
|
-
}
|
85
|
-
|
86
|
-
TOPIC = topic
|
87
|
-
MESSAGE = convertDataFormat(message, dataFormat)
|
88
|
-
|
89
|
-
// logger.info(`mqtt-subscribe :\n'${message.toString()}'`)
|
90
|
-
})
|
91
|
-
|
92
|
-
closures.push(async () => {
|
93
|
-
try {
|
94
|
-
broker && (await broker.end())
|
95
|
-
logger.info(`mqtt-connector connection(${connectionName}:${uri}) is disconnected`)
|
96
|
-
} catch (e) {
|
97
|
-
logger.error(e)
|
98
|
-
}
|
99
|
-
})
|
100
|
-
} catch (e) {
|
101
|
-
logger.error(e)
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
var { message } = await context.__mqtt_subscriber[name]()
|
106
|
-
|
107
|
-
return {
|
108
|
-
data: message
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
MqttSubscribe.parameterSpec = [
|
113
|
-
{
|
114
|
-
type: 'string',
|
115
|
-
name: 'topic',
|
116
|
-
label: 'topic'
|
117
|
-
},
|
118
|
-
{
|
119
|
-
type: 'select',
|
120
|
-
label: 'data-format',
|
121
|
-
name: 'dataFormat',
|
122
|
-
property: {
|
123
|
-
options: [
|
124
|
-
{
|
125
|
-
display: 'Plain Text',
|
126
|
-
value: 'text'
|
127
|
-
},
|
128
|
-
{
|
129
|
-
display: 'JSON',
|
130
|
-
value: 'json'
|
131
|
-
}
|
132
|
-
]
|
133
|
-
}
|
134
|
-
}
|
135
|
-
]
|
136
|
-
|
137
|
-
MqttSubscribe.help = 'integration/task/mqtt-subscribe'
|
138
|
-
|
139
|
-
TaskRegistry.registerTaskHandler('mqtt-subscribe', MqttSubscribe)
|