@artisan-cloud/plugin-framework-admin 0.0.12 → 0.0.14
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/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRuntimeConfig } from '#imports'
|
|
2
2
|
import { ofetch, type OFetch, type FetchResponse } from 'ofetch'
|
|
3
|
+
import { createPowerXApiFetchClient, isPowerXEmbedded } from '@artisan-cloud/plugin-framework-client'
|
|
3
4
|
|
|
4
5
|
const DEFAULT_ENDPOINT = '/integration/capabilities/invoke'
|
|
5
6
|
|
|
@@ -48,6 +49,8 @@ interface PowerXCapabilityBridge {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
interface BridgeOptions {
|
|
52
|
+
pluginId?: string
|
|
53
|
+
insidePowerX?: boolean
|
|
51
54
|
apiBase?: string
|
|
52
55
|
endpoint?: string
|
|
53
56
|
fetcher?: OFetch
|
|
@@ -106,8 +109,12 @@ const pickData = (payload: Record<string, any>) => {
|
|
|
106
109
|
return null
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
const
|
|
110
|
-
const
|
|
112
|
+
export const createPowerXCapabilityBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
113
|
+
const transport = options.fetcher ?? ofetch
|
|
114
|
+
const embedded = isPowerXEmbedded(options.insidePowerX)
|
|
115
|
+
if (embedded && !options.pluginId) throw new Error('PLUGIN_ID_REQUIRED')
|
|
116
|
+
const apiBase = options.apiBase || (embedded ? `/_p/${options.pluginId}/api/v1` : '')
|
|
117
|
+
const fetcher = embedded ? createPowerXApiFetchClient({ pluginId: options.pluginId!, insidePowerX: true, baseURL: apiBase, fetcher: transport }).client : transport
|
|
111
118
|
const endpoint = options.endpoint || DEFAULT_ENDPOINT
|
|
112
119
|
return {
|
|
113
120
|
async invoke(request) {
|
|
@@ -119,7 +126,8 @@ const createBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
|
119
126
|
if (!action) {
|
|
120
127
|
throw createCapabilityBridgeError('action is required')
|
|
121
128
|
}
|
|
122
|
-
const
|
|
129
|
+
const target = combineURL(request.apiBase ?? apiBase, request.endpoint ?? endpoint)
|
|
130
|
+
const url = embedded ? new URL(target, window.location.origin).toString() : target
|
|
123
131
|
const headers: Record<string, string> = {
|
|
124
132
|
'Content-Type': 'application/json',
|
|
125
133
|
...request.headers
|
|
@@ -127,30 +135,23 @@ const createBridge = (options: BridgeOptions): PowerXCapabilityBridge => {
|
|
|
127
135
|
if (request.requestId && !headers['X-Request-ID']) {
|
|
128
136
|
headers['X-Request-ID'] = request.requestId
|
|
129
137
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (request.metadata) {
|
|
141
|
-
body.metadata = request.metadata
|
|
142
|
-
}
|
|
143
|
-
response = await fetcher.raw(url, {
|
|
144
|
-
method: 'POST',
|
|
145
|
-
headers,
|
|
146
|
-
body,
|
|
147
|
-
signal: request.signal
|
|
148
|
-
})
|
|
149
|
-
} catch (error) {
|
|
150
|
-
throw createCapabilityBridgeError(
|
|
151
|
-
error instanceof Error ? error.message : 'capability invoke failed'
|
|
152
|
-
)
|
|
138
|
+
const body: Record<string, any> = {
|
|
139
|
+
capabilityId,
|
|
140
|
+
action,
|
|
141
|
+
payload: request.payload ?? {}
|
|
142
|
+
}
|
|
143
|
+
if (request.preferredProtocol) {
|
|
144
|
+
body.preferredProtocol = request.preferredProtocol
|
|
145
|
+
}
|
|
146
|
+
if (request.metadata) {
|
|
147
|
+
body.metadata = request.metadata
|
|
153
148
|
}
|
|
149
|
+
const response: FetchResponse<Record<string, any>> = await fetcher.raw(url, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers,
|
|
152
|
+
body,
|
|
153
|
+
signal: request.signal
|
|
154
|
+
})
|
|
154
155
|
|
|
155
156
|
const payload = response._data ?? {}
|
|
156
157
|
const traceId = payload.traceId || response.headers.get('x-trace-id') || undefined
|
|
@@ -181,7 +182,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
181
182
|
const publicConfig = runtimeConfig?.public as Record<string, any> | undefined
|
|
182
183
|
const powerxConfig = (publicConfig?.powerx ?? {}) as Record<string, any>
|
|
183
184
|
|
|
184
|
-
const bridge =
|
|
185
|
+
const bridge = createPowerXCapabilityBridge({
|
|
186
|
+
pluginId: publicConfig?.powerxPluginId || powerxConfig.pluginId,
|
|
187
|
+
insidePowerX: publicConfig?.insidePowerX,
|
|
185
188
|
apiBase: (powerxConfig.apiBase as string | undefined) ?? '',
|
|
186
189
|
endpoint: (powerxConfig.capabilityEndpoint as string | undefined) ?? DEFAULT_ENDPOINT,
|
|
187
190
|
fetcher: nuxtApp.$fetch
|
package/layer/nuxt.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artisan-cloud/plugin-framework-admin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts",
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"nuxt": "^4.2.0",
|
|
17
|
-
"@artisan-cloud/plugin-framework-client": "
|
|
18
|
-
"valibot": "^1.2.0"
|
|
17
|
+
"@artisan-cloud/plugin-framework-client": "0.0.15",
|
|
18
|
+
"valibot": "^1.2.0",
|
|
19
|
+
"@types/node": "^22.18.0"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"nuxt": "^4.2.0"
|