@artisan-cloud/plugin-framework-admin 0.0.4 → 0.0.6
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.
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { useNuxtApp } from '#app'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
interface PowerXCapabilityRequest {
|
|
4
|
+
capabilityId: string
|
|
5
|
+
action: string
|
|
6
|
+
payload?: Record<string, any> | null
|
|
7
|
+
headers?: Record<string, string>
|
|
8
|
+
requestId?: string
|
|
9
|
+
signal?: AbortSignal
|
|
10
|
+
apiBase?: string
|
|
11
|
+
endpoint?: string
|
|
12
|
+
preferredProtocol?: string
|
|
13
|
+
metadata?: Record<string, any>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PowerXCapabilityResponse {
|
|
17
|
+
traceId?: string
|
|
18
|
+
status?: string
|
|
19
|
+
data?: Record<string, any> | null
|
|
20
|
+
errors?: Record<string, any> | Record<string, any>[] | null
|
|
21
|
+
warnings?: string[] | null
|
|
22
|
+
raw?: Record<string, any> | Record<string, any>[] | string | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface PowerXCapabilityBridge {
|
|
26
|
+
invoke(request: PowerXCapabilityRequest): Promise<PowerXCapabilityResponse>
|
|
27
|
+
}
|
|
7
28
|
|
|
8
29
|
export interface UsePowerXCapabilityOptions extends Partial<Omit<PowerXCapabilityRequest, 'capabilityId' | 'action' | 'payload'>> {
|
|
9
30
|
payload?: Record<string, any> | null
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { computed, ref } from 'vue'
|
|
2
|
+
import { usePluginApi } from '../../../../framework-client/api'
|
|
3
|
+
import {
|
|
4
|
+
createSchedulerClient,
|
|
5
|
+
type ListSchedulerJobsInput,
|
|
6
|
+
type SchedulerClient,
|
|
7
|
+
type SchedulerJob,
|
|
8
|
+
type SchedulerJobSpec
|
|
9
|
+
} from '../../../../framework-client/scheduler'
|
|
10
|
+
|
|
11
|
+
export interface UsePowerXSchedulerOptions {
|
|
12
|
+
pluginId: string
|
|
13
|
+
baseURL?: string
|
|
14
|
+
tenantUuid?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const usePowerXScheduler = (options: UsePowerXSchedulerOptions) => {
|
|
18
|
+
const api = usePluginApi({
|
|
19
|
+
pluginId: options.pluginId,
|
|
20
|
+
baseURL: options.baseURL,
|
|
21
|
+
tenantUuid: options.tenantUuid
|
|
22
|
+
})
|
|
23
|
+
const client: SchedulerClient = createSchedulerClient(api)
|
|
24
|
+
const jobs = ref<SchedulerJob[]>([])
|
|
25
|
+
const loading = ref(false)
|
|
26
|
+
const error = ref<Error | null>(null)
|
|
27
|
+
|
|
28
|
+
const total = computed(() => jobs.value.length)
|
|
29
|
+
|
|
30
|
+
const listJobs = async (input?: ListSchedulerJobsInput) => {
|
|
31
|
+
loading.value = true
|
|
32
|
+
error.value = null
|
|
33
|
+
try {
|
|
34
|
+
const result = await client.listJobs({
|
|
35
|
+
tenant_uuid: options.tenantUuid,
|
|
36
|
+
...input
|
|
37
|
+
})
|
|
38
|
+
jobs.value = result.items || []
|
|
39
|
+
return result
|
|
40
|
+
} catch (err: any) {
|
|
41
|
+
error.value = err
|
|
42
|
+
throw err
|
|
43
|
+
} finally {
|
|
44
|
+
loading.value = false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const createJob = async (job: SchedulerJobSpec) => {
|
|
49
|
+
const created = await client.createJob(job)
|
|
50
|
+
await listJobs()
|
|
51
|
+
return created
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const updateJob = async (jobId: string, job: SchedulerJobSpec) => {
|
|
55
|
+
const updated = await client.updateJob(jobId, job)
|
|
56
|
+
await listJobs()
|
|
57
|
+
return updated
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const pauseJob = async (jobId: string) => {
|
|
61
|
+
const result = await client.pauseJob(jobId, options.tenantUuid)
|
|
62
|
+
await listJobs()
|
|
63
|
+
return result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const resumeJob = async (jobId: string) => {
|
|
67
|
+
const result = await client.resumeJob(jobId, options.tenantUuid)
|
|
68
|
+
await listJobs()
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const triggerJob = async (jobId: string) => {
|
|
73
|
+
return client.triggerJob(jobId, options.tenantUuid)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
client,
|
|
78
|
+
jobs,
|
|
79
|
+
total,
|
|
80
|
+
loading,
|
|
81
|
+
error,
|
|
82
|
+
listJobs,
|
|
83
|
+
createJob,
|
|
84
|
+
updateJob,
|
|
85
|
+
pauseJob,
|
|
86
|
+
resumeJob,
|
|
87
|
+
triggerJob
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
@@ -3,7 +3,7 @@ import { ofetch, type OFetch, type FetchResponse } from 'ofetch'
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_ENDPOINT = '/integration/capabilities/invoke'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface PowerXCapabilityRequest {
|
|
7
7
|
capabilityId: string
|
|
8
8
|
action: string
|
|
9
9
|
payload?: Record<string, any> | null
|
|
@@ -16,7 +16,7 @@ export interface PowerXCapabilityRequest {
|
|
|
16
16
|
metadata?: Record<string, any>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface PowerXCapabilityResponse {
|
|
20
20
|
traceId?: string
|
|
21
21
|
status?: string
|
|
22
22
|
data?: Record<string, any> | null
|
|
@@ -25,26 +25,25 @@ export interface PowerXCapabilityResponse {
|
|
|
25
25
|
raw?: Record<string, any> | Record<string, any>[] | string | null
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
traceId?: string
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
) {
|
|
38
|
-
super(message)
|
|
39
|
-
this.name = 'PowerXCapabilityBridgeError'
|
|
40
|
-
this.status = opts.status
|
|
41
|
-
this.traceId = opts.traceId
|
|
42
|
-
this.details = opts.details
|
|
43
|
-
this.warnings = opts.warnings
|
|
28
|
+
const createCapabilityBridgeError = (
|
|
29
|
+
message: string,
|
|
30
|
+
opts: { status?: number; traceId?: string; details?: any; warnings?: string[] } = {}
|
|
31
|
+
) => {
|
|
32
|
+
const error = new Error(message) as Error & {
|
|
33
|
+
status?: number
|
|
34
|
+
traceId?: string
|
|
35
|
+
details?: any
|
|
36
|
+
warnings?: string[]
|
|
44
37
|
}
|
|
38
|
+
error.name = 'PowerXCapabilityBridgeError'
|
|
39
|
+
error.status = opts.status
|
|
40
|
+
error.traceId = opts.traceId
|
|
41
|
+
error.details = opts.details
|
|
42
|
+
error.warnings = opts.warnings
|
|
43
|
+
return error
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
interface PowerXCapabilityBridge {
|
|
48
47
|
invoke(request: PowerXCapabilityRequest): Promise<PowerXCapabilityResponse>
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -114,11 +113,11 @@ const createBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
|
114
113
|
async invoke(request) {
|
|
115
114
|
const capabilityId = request.capabilityId?.trim()
|
|
116
115
|
if (!capabilityId) {
|
|
117
|
-
throw
|
|
116
|
+
throw createCapabilityBridgeError('capabilityId is required')
|
|
118
117
|
}
|
|
119
118
|
const action = request.action?.trim()
|
|
120
119
|
if (!action) {
|
|
121
|
-
throw
|
|
120
|
+
throw createCapabilityBridgeError('action is required')
|
|
122
121
|
}
|
|
123
122
|
const url = combineURL(request.apiBase ?? options.apiBase, request.endpoint ?? endpoint)
|
|
124
123
|
const headers: Record<string, string> = {
|
|
@@ -148,7 +147,7 @@ const createBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
|
148
147
|
signal: request.signal
|
|
149
148
|
})
|
|
150
149
|
} catch (error) {
|
|
151
|
-
throw
|
|
150
|
+
throw createCapabilityBridgeError(
|
|
152
151
|
error instanceof Error ? error.message : 'capability invoke failed'
|
|
153
152
|
)
|
|
154
153
|
}
|
|
@@ -157,7 +156,7 @@ const createBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
|
157
156
|
const traceId = payload.traceId || response.headers.get('x-trace-id') || undefined
|
|
158
157
|
const warnings = Array.isArray(payload.warnings) ? payload.warnings : undefined
|
|
159
158
|
if (response.status >= 400 || payload.error) {
|
|
160
|
-
throw
|
|
159
|
+
throw createCapabilityBridgeError(payload.error?.message || 'capability invoke failed', {
|
|
161
160
|
status: response.status,
|
|
162
161
|
traceId,
|
|
163
162
|
details: payload.error || payload.errors,
|