@things-factory/integration-base 7.1.27 → 7.1.33
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/controllers/scenario-controller.d.ts +2 -0
- package/dist-server/controllers/scenario-controller.js +16 -19
- package/dist-server/controllers/scenario-controller.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +3 -4
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/task/utils/headless-pool-for-scenario.js +1 -1
- package/dist-server/engine/task/utils/headless-pool-for-scenario.js.map +1 -1
- package/dist-server/service/scenario/scenario-query.d.ts +2 -1
- package/dist-server/service/scenario/scenario-query.js +10 -0
- package/dist-server/service/scenario/scenario-query.js.map +1 -1
- package/dist-server/service/scenario/scenario-type.d.ts +3 -3
- package/dist-server/service/scenario/scenario-type.js +7 -7
- package/dist-server/service/scenario/scenario-type.js.map +1 -1
- package/dist-server/service/scenario/scenario.d.ts +3 -1
- package/dist-server/service/scenario/scenario.js +9 -0
- package/dist-server/service/scenario/scenario.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/server/controllers/scenario-controller.ts +27 -36
- package/server/engine/connector/operato-connector.ts +4 -7
- package/server/engine/task/utils/headless-pool-for-scenario.ts +1 -1
- package/server/service/scenario/scenario-query.ts +6 -1
- package/server/service/scenario/scenario-type.ts +5 -5
- package/server/service/scenario/scenario.ts +15 -19
- package/translations/en.json +1 -1
- package/translations/ja.json +1 -1
- package/translations/ko.json +1 -1
- package/translations/ms.json +1 -1
- package/translations/zh.json +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/integration-base",
|
3
|
-
"version": "7.1.
|
3
|
+
"version": "7.1.33",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -27,12 +27,12 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"@apollo/client": "^3.6.9",
|
29
29
|
"@operato/moment-timezone-es": "^7.0.0",
|
30
|
-
"@things-factory/api": "^7.1.
|
31
|
-
"@things-factory/auth-base": "^7.1.
|
32
|
-
"@things-factory/cache-service": "^7.1.
|
30
|
+
"@things-factory/api": "^7.1.33",
|
31
|
+
"@things-factory/auth-base": "^7.1.33",
|
32
|
+
"@things-factory/cache-service": "^7.1.33",
|
33
33
|
"@things-factory/env": "^7.1.16",
|
34
|
-
"@things-factory/oauth2-client": "^7.1.
|
35
|
-
"@things-factory/scheduler-client": "^7.1.
|
34
|
+
"@things-factory/oauth2-client": "^7.1.33",
|
35
|
+
"@things-factory/scheduler-client": "^7.1.33",
|
36
36
|
"@things-factory/shell": "^7.1.24",
|
37
37
|
"@things-factory/utils": "^7.1.24",
|
38
38
|
"async-mqtt": "^2.5.0",
|
@@ -44,5 +44,5 @@
|
|
44
44
|
"readline": "^1.3.0",
|
45
45
|
"ses": "^1.5.0"
|
46
46
|
},
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "da463a7d7851cf47c7d4b8136e7be6690b55969e"
|
48
48
|
}
|
@@ -1,14 +1,10 @@
|
|
1
1
|
import { getRepository, Domain, GraphqlLocalClient } from '@things-factory/shell'
|
2
|
-
import {
|
2
|
+
import { checkUserHasRole } from '@things-factory/auth-base'
|
3
3
|
import { cacheService } from '@things-factory/cache-service'
|
4
4
|
|
5
5
|
import { ScenarioEngine } from '../engine/scenario-engine'
|
6
6
|
import { Scenario } from '../service/scenario/scenario'
|
7
|
-
import {
|
8
|
-
ScenarioInstance,
|
9
|
-
ScenarioInstanceRunResult,
|
10
|
-
ScenarioInstanceStatus
|
11
|
-
} from '../service/scenario-instance/scenario-instance-type'
|
7
|
+
import { ScenarioInstance, ScenarioInstanceRunResult } from '../service/scenario-instance/scenario-instance-type'
|
12
8
|
import { Step } from '../service/step/step-type'
|
13
9
|
|
14
10
|
const debug = require('debug')('things-factory:integration-base:controller:run-scenario')
|
@@ -16,31 +12,48 @@ const debug = require('debug')('things-factory:integration-base:controller:run-s
|
|
16
12
|
async function findScenario(
|
17
13
|
scenarioName: string,
|
18
14
|
domain: Domain
|
19
|
-
): Promise<{
|
15
|
+
): Promise<{
|
16
|
+
id: string
|
17
|
+
ttl: number
|
18
|
+
name: string
|
19
|
+
steps: Step[]
|
20
|
+
domain: Domain
|
21
|
+
}> {
|
20
22
|
var repository = getRepository(Scenario)
|
21
23
|
|
22
24
|
var scenario = await repository.findOne({
|
23
25
|
where: { domain: { id: domain.id }, name: scenarioName },
|
24
|
-
relations: ['domain', 'steps', 'creator', 'updater']
|
26
|
+
relations: ['domain', 'steps', 'role', 'creator', 'updater']
|
25
27
|
})
|
26
28
|
|
27
29
|
if (!scenario && domain.parentId) {
|
28
30
|
scenario = await repository.findOne({
|
29
31
|
where: { domain: { id: domain.parentId }, name: scenarioName },
|
30
|
-
relations: ['domain', 'steps', 'creator', 'updater']
|
32
|
+
relations: ['domain', 'steps', 'role', 'creator', 'updater']
|
31
33
|
})
|
32
34
|
}
|
33
35
|
|
34
36
|
return scenario as any
|
35
37
|
}
|
36
38
|
|
39
|
+
export async function checkHasRole(scenario: Partial<Scenario>, context: ResolverContext): Promise<void> {
|
40
|
+
const { domain, user } = context.state
|
41
|
+
if (!(await checkUserHasRole(scenario.roleId, domain, user))) {
|
42
|
+
throw new Error(
|
43
|
+
context.t('error.scenario run unauthorized', {
|
44
|
+
scenario: scenario.name
|
45
|
+
})
|
46
|
+
)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
37
50
|
export async function runScenario(
|
38
51
|
instanceName: string,
|
39
52
|
scenarioName: string,
|
40
53
|
variables: any,
|
41
54
|
context: ResolverContext
|
42
55
|
): Promise<ScenarioInstanceRunResult> {
|
43
|
-
const { domain, user, lng
|
56
|
+
const { domain, user, lng } = context.state
|
44
57
|
|
45
58
|
debug('runScenario', scenarioName, instanceName, variables)
|
46
59
|
|
@@ -54,19 +67,7 @@ export async function runScenario(
|
|
54
67
|
)
|
55
68
|
}
|
56
69
|
|
57
|
-
|
58
|
-
const { category, privilege } = scenario.privilege || {}
|
59
|
-
|
60
|
-
console.error(
|
61
|
-
`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`
|
62
|
-
)
|
63
|
-
|
64
|
-
throw new Error(
|
65
|
-
context.t('error.scenario run unauthorized', {
|
66
|
-
scenario: scenarioName
|
67
|
-
})
|
68
|
-
)
|
69
|
-
}
|
70
|
+
await checkHasRole(scenario, context)
|
70
71
|
|
71
72
|
if (scenario.ttl > 0) {
|
72
73
|
const cachedValue = await cacheService.getFromCache(scenario.id, { domain: domain.id, variables: variables || {} })
|
@@ -104,7 +105,7 @@ export async function startScenario(
|
|
104
105
|
variables: any,
|
105
106
|
context: ResolverContext
|
106
107
|
): Promise<ScenarioInstance> {
|
107
|
-
const { domain, user, lng
|
108
|
+
const { domain, user, lng } = context.state
|
108
109
|
|
109
110
|
debug('startScenario', instanceName, scenarioName, variables)
|
110
111
|
|
@@ -118,12 +119,7 @@ export async function startScenario(
|
|
118
119
|
)
|
119
120
|
}
|
120
121
|
|
121
|
-
|
122
|
-
const { category, privilege } = scenario.privilege || {}
|
123
|
-
throw new Error(
|
124
|
-
`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`
|
125
|
-
)
|
126
|
-
}
|
122
|
+
await checkHasRole(scenario, context)
|
127
123
|
|
128
124
|
instanceName = instanceName || scenarioName
|
129
125
|
return await ScenarioEngine.load(instanceName, scenario, { domain, user, lng, variables })
|
@@ -152,12 +148,7 @@ export async function stopScenario(
|
|
152
148
|
|
153
149
|
var scenario = await findScenario(scenarioInstance.scenarioName, domain)
|
154
150
|
|
155
|
-
|
156
|
-
const { category, privilege } = scenario.privilege || {}
|
157
|
-
throw new Error(
|
158
|
-
`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`
|
159
|
-
)
|
160
|
-
}
|
151
|
+
await checkHasRole(scenario, context)
|
161
152
|
|
162
153
|
await ScenarioEngine.unload(domain, instanceName)
|
163
154
|
|
@@ -17,7 +17,7 @@ import { Scenario } from '../../service/scenario/scenario'
|
|
17
17
|
import { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'
|
18
18
|
|
19
19
|
import { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'
|
20
|
-
import { User,
|
20
|
+
import { User, checkUserHasRole } from '@things-factory/auth-base'
|
21
21
|
|
22
22
|
const debug = require('debug')('things-factory:integration-base:operato-connector')
|
23
23
|
|
@@ -198,7 +198,7 @@ export class OperatoConnector implements Connector {
|
|
198
198
|
}
|
199
199
|
|
200
200
|
async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {
|
201
|
-
const { domain, user
|
201
|
+
const { domain, user } = this.context
|
202
202
|
const { tag } = variables
|
203
203
|
|
204
204
|
if (!tag) {
|
@@ -210,11 +210,8 @@ export class OperatoConnector implements Connector {
|
|
210
210
|
throw new Error(`scenario is not found - ${tag}`)
|
211
211
|
}
|
212
212
|
|
213
|
-
if (!(await
|
214
|
-
|
215
|
-
throw new Error(
|
216
|
-
`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`
|
217
|
-
)
|
213
|
+
if (!(await checkUserHasRole(scenario.roleId, domain, user))) {
|
214
|
+
throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)
|
218
215
|
}
|
219
216
|
|
220
217
|
/* create a scenario instance */
|
@@ -15,7 +15,7 @@ export function getHeadlessPool() {
|
|
15
15
|
headlessPool = genericPool.createPool(
|
16
16
|
{
|
17
17
|
create() {
|
18
|
-
console.log('headless-pool-for-scensrio about to create')
|
18
|
+
console.log('headless instance in headless-pool-for-scensrio about to create')
|
19
19
|
return initializeChromium()
|
20
20
|
},
|
21
21
|
validate(browser) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
2
2
|
import { Not, IsNull } from 'typeorm'
|
3
3
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
4
|
+
import { User, Role } from '@things-factory/auth-base'
|
5
5
|
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
6
6
|
|
7
7
|
import { ScenarioEngine } from '../../engine'
|
@@ -101,4 +101,9 @@ export class ScenarioQuery {
|
|
101
101
|
|
102
102
|
return ScenarioEngine.getScenarioInstances(domain, scenario.name)
|
103
103
|
}
|
104
|
+
|
105
|
+
@FieldResolver(type => Role)
|
106
|
+
async role(@Root() scenario: Scenario) {
|
107
|
+
return scenario.roleId && (await getRepository(Role).findOneBy({ id: scenario.roleId }))
|
108
|
+
}
|
104
109
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
4
4
|
|
5
5
|
import { Scenario } from './scenario'
|
6
6
|
import { StepPatch } from '../step/step-type'
|
@@ -28,8 +28,8 @@ export class NewScenario {
|
|
28
28
|
@Field({ nullable: true })
|
29
29
|
active?: boolean
|
30
30
|
|
31
|
-
@Field({ nullable: true })
|
32
|
-
|
31
|
+
@Field(type => ObjectRef, { nullable: true })
|
32
|
+
role?: ObjectRef
|
33
33
|
}
|
34
34
|
|
35
35
|
@InputType()
|
@@ -61,8 +61,8 @@ export class ScenarioPatch {
|
|
61
61
|
@Field(type => [StepPatch], { nullable: true })
|
62
62
|
steps?: StepPatch[]
|
63
63
|
|
64
|
-
@Field({ nullable: true })
|
65
|
-
|
64
|
+
@Field(type => ObjectRef, { nullable: true })
|
65
|
+
role?: ObjectRef
|
66
66
|
|
67
67
|
@Field({ nullable: true })
|
68
68
|
cuFlag?: string
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
UpdateDateColumn
|
12
12
|
} from 'typeorm'
|
13
13
|
|
14
|
-
import { PrivilegeObject,
|
14
|
+
import { PrivilegeObject, Role, User } from '@things-factory/auth-base'
|
15
15
|
import { Domain } from '@things-factory/shell'
|
16
16
|
|
17
17
|
import { ScenarioEngine } from '../../engine'
|
@@ -76,6 +76,13 @@ export class Scenario {
|
|
76
76
|
@Field(type => PrivilegeObject, { nullable: true })
|
77
77
|
privilege?: PrivilegeObject
|
78
78
|
|
79
|
+
@ManyToOne(type => Role)
|
80
|
+
@Field(type => Role, { nullable: true })
|
81
|
+
role?: Role
|
82
|
+
|
83
|
+
@RelationId((scenario: Scenario) => scenario.role)
|
84
|
+
roleId?: string
|
85
|
+
|
79
86
|
@CreateDateColumn()
|
80
87
|
@Field({ nullable: true })
|
81
88
|
createdAt?: Date
|
@@ -98,28 +105,17 @@ export class Scenario {
|
|
98
105
|
@RelationId((scenario: Scenario) => scenario.updater)
|
99
106
|
updaterId?: string
|
100
107
|
|
101
|
-
async start(options?: {
|
102
|
-
instanceName?: string;
|
103
|
-
domain?: Domain;
|
104
|
-
user?: User;
|
105
|
-
variables?: any;
|
106
|
-
}) {
|
108
|
+
async start(options?: { instanceName?: string; domain?: Domain; user?: User; variables?: any }) {
|
107
109
|
try {
|
108
|
-
await ScenarioEngine.load(options?.instanceName || this.name,
|
109
|
-
this,
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
variables: options?.variables
|
114
|
-
})
|
110
|
+
await ScenarioEngine.load(options?.instanceName || this.name, this, {
|
111
|
+
domain: options?.domain || this.domain,
|
112
|
+
user: options?.user || this.updater,
|
113
|
+
variables: options?.variables
|
114
|
+
})
|
115
115
|
} catch (ex) {}
|
116
116
|
}
|
117
117
|
|
118
|
-
async stop(options?: {
|
119
|
-
instanceName?: string;
|
120
|
-
domain?: Domain,
|
121
|
-
user?: User
|
122
|
-
}) {
|
118
|
+
async stop(options?: { instanceName?: string; domain?: Domain; user?: User }) {
|
123
119
|
try {
|
124
120
|
await ScenarioEngine.unload(options?.domain || this.domain, options?.instanceName || this.name)
|
125
121
|
} finally {
|
package/translations/en.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"error.scenario not found": "scenario '{scenario}' not found.",
|
3
3
|
"error.scenario run error": "an error occurred while processing the '{scenario}' request. please contact the administrator.",
|
4
|
-
"error.scenario run unauthorized": "you do not have permission to run the {scenario} scenario. please contact the administrator.",
|
4
|
+
"error.scenario run unauthorized": "you do not have permission to run the '{scenario}' scenario. please contact the administrator.",
|
5
5
|
"error.schedule is not set": "schedule should be set for the scenario '{scenario}' in order to register as a schedule",
|
6
6
|
"error.timezone is not set": "timezone should be set for the scenario '{scenario}' in order to register as a schedule",
|
7
7
|
"error.scenario instance not found": "scenario instance '{instance}' not found.",
|
package/translations/ja.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"error.scenario not found": "シナリオ'{scenario}'が見つかりません.",
|
3
3
|
"error.scenario run error": "シナリオ '{scenario}' のリクエストを処理中にエラーが発生しました。管理者に連絡してください。",
|
4
|
-
"error.scenario run unauthorized": "シナリオ {scenario} を実行する権限がありません。管理者に連絡してください。",
|
4
|
+
"error.scenario run unauthorized": "シナリオ '{scenario}' を実行する権限がありません。管理者に連絡してください。",
|
5
5
|
"error.schedule is not set": "スケジュールとして登録するためにはシナリオ'{scenario}'にスケジュール情報が設定される必要があります.",
|
6
6
|
"error.timezone is not set": "スケジュールとして登録するためにはシナリオ'{scenario}'にタイム ゾーン情報が設定される必要があります.",
|
7
7
|
"error.scenario instance not found": "シナリオ インスタンス'{instance}'が見つかりません. 既に終了している可能性があります.",
|
package/translations/ko.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"error.scenario not found": "시나리오 '{scenario}'를 찾을 수 없습니다.",
|
3
3
|
"error.scenario run error": "시나리오 '{scenario}' 요청을 처리하는 중 오류가 발생했습니다. 관리자에게 문의하십시오.",
|
4
|
-
"error.scenario run unauthorized": "시나리오 {scenario}를 실행할 권한이 없습니다. 관리자에게 문의하십히오.",
|
4
|
+
"error.scenario run unauthorized": "시나리오 '{scenario}'를 실행할 권한이 없습니다. 관리자에게 문의하십히오.",
|
5
5
|
"error.schedule is not set": "스케쥴로 등록하기 위해서는 시나리오 '{scenario}'에 스케쥴 정보가 설정되어야 합니다.",
|
6
6
|
"error.timezone is not set": "스케쥴로 등록하기 위해서는 시나리오 '{scenario}'에 타임존 정보가 설정되어야 합니다.",
|
7
7
|
"error.scenario instance not found": "시나리오 인스턴스 '{instance}'를 찾을 수 없습니다. 이미 종료되었을 수 있습니다.",
|
package/translations/ms.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"error.scenario not found": "Tidak dapat mencari senario '{scenario}'.",
|
3
3
|
"error.scenario run error": "Ralat berlaku semasa memproses permintaan senario '{scenario}'. Sila hubungi pentadbir.",
|
4
|
-
"error.scenario run unauthorized": "Anda tidak mempunyai kebenaran untuk menjalankan senario {scenario}. Sila hubungi pentadbir.",
|
4
|
+
"error.scenario run unauthorized": "Anda tidak mempunyai kebenaran untuk menjalankan senario '{scenario}'. Sila hubungi pentadbir.",
|
5
5
|
"error.schedule is not set": "Untuk mendaftarkan sebagai jadual, maklumat jadual mesti diset dalam senario '{scenario}'.",
|
6
6
|
"error.timezone is not set": "Untuk mendaftarkan sebagai jadual, maklumat zon masa mesti diset dalam senario '{scenario}'.",
|
7
7
|
"error.scenario instance not found": "Tidak dapat mencari instans senario '{instance}'. Mungkin telah berakhir.",
|
package/translations/zh.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"error.scenario not found": "无法找到场景 '{scenario}'。",
|
3
3
|
"error.scenario run error": "处理场景 '{scenario}' 请求时发生错误。请联系管理员。",
|
4
|
-
"error.scenario run unauthorized": "没有执行场景 {scenario} 的权限。请联系管理员。",
|
4
|
+
"error.scenario run unauthorized": "没有执行场景 '{scenario}' 的权限。请联系管理员。",
|
5
5
|
"error.schedule is not set": "要注册为计划,场景 '{scenario}' 需要设置计划信息。",
|
6
6
|
"error.timezone is not set": "要注册为计划,场景 '{scenario}' 需要设置时区信息。",
|
7
7
|
"error.scenario instance not found": "无法找到场景实例 '{instance}'。它可能已经结束。",
|