@things-factory/integration-base 6.1.100 → 6.1.103
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/analyzer/analyze-integration.js +88 -0
- package/dist-server/engine/analyzer/analyze-integration.js.map +1 -0
- package/dist-server/engine/task/http-get.js +4 -7
- package/dist-server/engine/task/http-get.js.map +1 -1
- package/dist-server/engine/task/http-post.js +1 -0
- package/dist-server/engine/task/http-post.js.map +1 -1
- package/dist-server/engine/task/log.js +23 -9
- package/dist-server/engine/task/log.js.map +1 -1
- package/dist-server/service/analysis/analysis-query.js +25 -0
- package/dist-server/service/analysis/analysis-query.js.map +1 -0
- package/dist-server/service/analysis/index.js +6 -0
- package/dist-server/service/analysis/index.js.map +1 -0
- package/dist-server/service/index.js +3 -1
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/scenario/scenario-query.js +32 -1
- package/dist-server/service/scenario/scenario-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/integration/concept/template-literal.ja.md +31 -0
- package/helps/integration/concept/template-literal.ko.md +31 -0
- package/helps/integration/concept/template-literal.md +31 -0
- package/helps/integration/concept/template-literal.zh.md +31 -0
- package/helps/integration/task/book-up-scenario.md +5 -2
- package/helps/integration/task/http-get.ja.md +31 -0
- package/helps/integration/task/http-get.ko.md +28 -0
- package/helps/integration/task/http-get.md +28 -0
- package/helps/integration/task/http-get.ms.md +28 -0
- package/helps/integration/task/http-get.zh.md +28 -0
- package/helps/integration/task/http-post.ja.md +35 -0
- package/helps/integration/task/http-post.ko.md +34 -0
- package/helps/integration/task/http-post.md +35 -0
- package/helps/integration/task/http-post.ms.md +37 -0
- package/helps/integration/task/http-post.zh.md +35 -0
- package/helps/integration/task/log.ja.md +11 -0
- package/helps/integration/task/log.ko.md +16 -0
- package/helps/integration/task/log.md +12 -11
- package/helps/integration/task/log.ms.md +15 -0
- package/helps/integration/task/log.zh.md +11 -0
- package/package.json +7 -7
- package/server/engine/analyzer/analyze-integration.ts +106 -0
- package/server/engine/task/http-get.ts +6 -10
- package/server/engine/task/http-post.ts +2 -0
- package/server/engine/task/log.ts +27 -10
- package/server/service/analysis/analysis-query.ts +13 -0
- package/server/service/analysis/index.ts +3 -0
- package/server/service/index.ts +4 -2
- package/server/service/scenario/scenario-query.ts +23 -1
@@ -0,0 +1,106 @@
|
|
1
|
+
import uniq from 'lodash/uniq'
|
2
|
+
|
3
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
4
|
+
import { Scenario } from '../../service/scenario/scenario-type'
|
5
|
+
import { Connection } from '../../service/connection/connection-type'
|
6
|
+
|
7
|
+
export async function analyzeIntegration(domain: Domain) {
|
8
|
+
const tagNames = []
|
9
|
+
|
10
|
+
const model = {
|
11
|
+
nodes: [],
|
12
|
+
relationships: []
|
13
|
+
}
|
14
|
+
|
15
|
+
var id = 0
|
16
|
+
|
17
|
+
const scenarios = await getRepository(Scenario).find({
|
18
|
+
where: { domain: { id: domain.id } },
|
19
|
+
relations: ['steps']
|
20
|
+
})
|
21
|
+
|
22
|
+
const connections = await getRepository(Connection).find({
|
23
|
+
where: { domain: { id: domain.id } }
|
24
|
+
})
|
25
|
+
|
26
|
+
model.nodes = model.nodes.concat(
|
27
|
+
scenarios.map(scenario => {
|
28
|
+
return {
|
29
|
+
id: scenario.id,
|
30
|
+
labels: ['Scenario'],
|
31
|
+
properties: {
|
32
|
+
scenarioId: scenario.id
|
33
|
+
}
|
34
|
+
}
|
35
|
+
})
|
36
|
+
)
|
37
|
+
|
38
|
+
model.nodes = model.nodes.concat(
|
39
|
+
connections.map(connection => {
|
40
|
+
return {
|
41
|
+
id: ++id,
|
42
|
+
labels: ['Connection'],
|
43
|
+
properties: {
|
44
|
+
connectionId: connection.id
|
45
|
+
}
|
46
|
+
}
|
47
|
+
})
|
48
|
+
)
|
49
|
+
|
50
|
+
scenarios.forEach(scenario => {
|
51
|
+
const connectionNames = uniq(scenario.steps.map(step => step.connection).filter(Boolean))
|
52
|
+
const connectionList = connectionNames
|
53
|
+
.map(connectionName => connections.find(connection => connection.name == connectionName))
|
54
|
+
.filter(Boolean)
|
55
|
+
|
56
|
+
const relationships = connectionList.map(connection => {
|
57
|
+
return {
|
58
|
+
id: ++id,
|
59
|
+
type: 'using',
|
60
|
+
sourceNode: scenario.id,
|
61
|
+
targetNode: connection.id
|
62
|
+
}
|
63
|
+
})
|
64
|
+
|
65
|
+
model.relationships = model.relationships.concat(relationships)
|
66
|
+
})
|
67
|
+
|
68
|
+
scenarios.forEach(scenario => {
|
69
|
+
const tags = uniq(
|
70
|
+
scenario.steps
|
71
|
+
.filter(step => !step.connection && step.task == 'publish')
|
72
|
+
.map(step => JSON.parse(step.params)?.tag)
|
73
|
+
.filter(Boolean)
|
74
|
+
)
|
75
|
+
|
76
|
+
for (const tag of tags) {
|
77
|
+
if (tagNames.includes(tag)) {
|
78
|
+
continue
|
79
|
+
}
|
80
|
+
|
81
|
+
model.nodes.push({
|
82
|
+
id: `tag-${tag}`,
|
83
|
+
labels: ['Tag'],
|
84
|
+
properties: {
|
85
|
+
tag
|
86
|
+
}
|
87
|
+
})
|
88
|
+
|
89
|
+
tagNames.push(tag)
|
90
|
+
}
|
91
|
+
|
92
|
+
const relationships = tags.map(tag => {
|
93
|
+
return {
|
94
|
+
id: ++id,
|
95
|
+
type: 'publish',
|
96
|
+
sourceNode: scenario.id,
|
97
|
+
targetNode: `tag-${tag}`,
|
98
|
+
properties: {}
|
99
|
+
}
|
100
|
+
})
|
101
|
+
|
102
|
+
model.relationships = model.relationships.concat(relationships)
|
103
|
+
})
|
104
|
+
|
105
|
+
return model
|
106
|
+
}
|
@@ -68,17 +68,11 @@ async function HttpGet(step, { logger, data, domain, variables }) {
|
|
68
68
|
|
69
69
|
var response = await fetch(url, fetchOptions)
|
70
70
|
|
71
|
-
var responseData = await response.text()
|
72
|
-
|
73
|
-
const responseContentType = response.headers.get('content-type')
|
74
|
-
if (responseContentType && responseContentType.indexOf('application/json') !== -1) {
|
75
|
-
responseData = JSON.parse(responseData)
|
76
|
-
}
|
77
|
-
|
78
|
-
logger.info(`http-get : \n${JSON.stringify(responseData, null, 2)}`)
|
79
|
-
|
80
71
|
return {
|
81
|
-
data:
|
72
|
+
data:
|
73
|
+
response.ok && response.headers.get('content-type').includes('application/json')
|
74
|
+
? await response.json()
|
75
|
+
: await response.text()
|
82
76
|
}
|
83
77
|
}
|
84
78
|
|
@@ -100,4 +94,6 @@ HttpGet.parameterSpec = [
|
|
100
94
|
}
|
101
95
|
]
|
102
96
|
|
97
|
+
HttpGet.help = 'integration/task/http-get'
|
98
|
+
|
103
99
|
TaskRegistry.registerTaskHandler('http-get', HttpGet)
|
@@ -1,14 +1,31 @@
|
|
1
|
-
import { access } from '@things-factory/utils'
|
1
|
+
import { access, hasTemplateExpression } from '@things-factory/utils'
|
2
|
+
import { VM } from 'vm2'
|
2
3
|
import { TaskRegistry } from '../task-registry'
|
3
4
|
|
4
|
-
async function Log(step, { logger, data }) {
|
5
|
+
async function Log(step, { logger, data, variables, domain }) {
|
5
6
|
var {
|
6
7
|
params: { message, accessor, level = 'info' }
|
7
8
|
} = step
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
if (hasTemplateExpression(message)) {
|
11
|
+
const vm = new VM({
|
12
|
+
sandbox: {
|
13
|
+
domain,
|
14
|
+
data,
|
15
|
+
variables
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
message = vm.run('`' + message + '`')
|
20
|
+
}
|
21
|
+
|
22
|
+
accessor = access(accessor, data)
|
23
|
+
|
24
|
+
if (accessor) {
|
25
|
+
if (accessor !== 'string') {
|
26
|
+
accessor = JSON.stringify(accessor, null, 2)
|
27
|
+
}
|
28
|
+
message += ': ' + accessor
|
12
29
|
}
|
13
30
|
|
14
31
|
switch (level) {
|
@@ -28,16 +45,16 @@ async function Log(step, { logger, data }) {
|
|
28
45
|
}
|
29
46
|
|
30
47
|
Log.parameterSpec = [
|
31
|
-
{
|
32
|
-
type: 'scenario-step-input',
|
33
|
-
name: 'accessor',
|
34
|
-
label: 'accessor'
|
35
|
-
},
|
36
48
|
{
|
37
49
|
type: 'string',
|
38
50
|
name: 'message',
|
39
51
|
label: 'message'
|
40
52
|
},
|
53
|
+
{
|
54
|
+
type: 'scenario-step-input',
|
55
|
+
name: 'accessor',
|
56
|
+
label: 'accessor'
|
57
|
+
},
|
41
58
|
{
|
42
59
|
type: 'select',
|
43
60
|
name: 'level',
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Resolver, Query, Ctx } from 'type-graphql'
|
2
|
+
import { ScalarObject } from '@things-factory/shell'
|
3
|
+
import { analyzeIntegration } from '../../engine/analyzer/analyze-integration'
|
4
|
+
|
5
|
+
@Resolver()
|
6
|
+
export class IntegrationAnalysisQuery {
|
7
|
+
@Query(returns => ScalarObject, { description: 'To fetch integration Analyses' })
|
8
|
+
async integrationAnalysis(@Ctx() context: ResolverContext): Promise<any> {
|
9
|
+
const { domain } = context.state
|
10
|
+
|
11
|
+
return await analyzeIntegration(domain)
|
12
|
+
}
|
13
|
+
}
|
package/server/service/index.ts
CHANGED
@@ -6,6 +6,7 @@ import { entities as ScenarioQueueEntities, resolvers as ScenarioQueueResolvers
|
|
6
6
|
import { entities as StepEntities, resolvers as StepResolvers } from './step'
|
7
7
|
import { entities as TaskTypeEntities, resolvers as TaskTypeResolvers } from './task-type'
|
8
8
|
import { entities as PayloadLogEntities, resolvers as PayloadLogResolvers } from './payload-log'
|
9
|
+
import { resolvers as IntegrationAnalysisQuery } from './analysis'
|
9
10
|
|
10
11
|
export * from './property-spec'
|
11
12
|
export * from './task-type/task-type-type'
|
@@ -38,9 +39,10 @@ export const schema = {
|
|
38
39
|
...ScenarioInstanceResolvers,
|
39
40
|
...ScenarioQueueResolvers,
|
40
41
|
...StepResolvers,
|
41
|
-
...PayloadLogResolvers
|
42
|
+
...PayloadLogResolvers,
|
43
|
+
...IntegrationAnalysisQuery
|
42
44
|
]
|
43
45
|
}
|
44
46
|
|
45
47
|
export { PayloadType } from './payload-log/payload-log'
|
46
|
-
export { createPayloadLog } from './payload-log/payload-log-mutation'
|
48
|
+
export { createPayloadLog } from './payload-log/payload-log-mutation'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
2
|
+
import { Not, IsNull } from 'typeorm'
|
2
3
|
|
3
4
|
import { User } from '@things-factory/auth-base'
|
4
5
|
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
@@ -7,6 +8,7 @@ import { ScenarioEngine } from '../../engine'
|
|
7
8
|
import { ScenarioInstance, ScenarioInstanceStatus } from '../scenario-instance/scenario-instance-type'
|
8
9
|
import { Step } from '../step/step-type'
|
9
10
|
import { Scenario, ScenarioList } from './scenario-type'
|
11
|
+
import { Connection } from '../connection/connection-type'
|
10
12
|
|
11
13
|
@Resolver(Scenario)
|
12
14
|
export class ScenarioQuery {
|
@@ -62,7 +64,27 @@ export class ScenarioQuery {
|
|
62
64
|
})
|
63
65
|
}
|
64
66
|
|
65
|
-
|
67
|
+
@FieldResolver(type => [Connection])
|
68
|
+
async connectionNames(@Root() scenario: Scenario, @Ctx() context: ResolverContext) {
|
69
|
+
const { domain } = context.state
|
70
|
+
|
71
|
+
const steps = await getRepository(Step).find({
|
72
|
+
where: { domain: { id: domain.id }, scenario: { id: scenario.id }, connection: Not(IsNull()) }
|
73
|
+
})
|
74
|
+
|
75
|
+
return steps.map(step => step.connection).filter(Boolean)
|
76
|
+
}
|
77
|
+
|
78
|
+
@FieldResolver(type => [Connection])
|
79
|
+
async publishTags(@Root() scenario: Scenario, @Ctx() context: ResolverContext) {
|
80
|
+
const { domain } = context.state
|
81
|
+
|
82
|
+
const steps = await getRepository(Step).find({
|
83
|
+
where: { domain: { id: domain.id }, scenario: { id: scenario.id }, task: 'publish' }
|
84
|
+
})
|
85
|
+
|
86
|
+
return steps.map(step => JSON.parse(step.params)?.tag).filter(Boolean)
|
87
|
+
}
|
66
88
|
|
67
89
|
@FieldResolver(type => String, { nullable: true })
|
68
90
|
async state(@Root() scenario: Scenario, @Ctx() context: ResolverContext): Promise<string> {
|