@tacoreai/web-sdk 1.24.0 → 1.24.1-beta.3
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/README.md +39 -0
- package/TacoreActionSDK.js +206 -0
- package/database/core/apps/AppServerRuntime.js +80 -46
- package/database/core/apps/AppsClient.AppServer.js +49 -7
- package/database/core/apps/AppsClient.IAM.js +0 -32
- package/database/core/apps/AppsClient.js +1 -8
- package/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,45 @@ npm install @tacoreai/web-sdk
|
|
|
17
17
|
### AppsClient (Data & AI)
|
|
18
18
|
示例略(保持原有章节)
|
|
19
19
|
|
|
20
|
+
### TacoreActionSDK (Headless Capability)
|
|
21
|
+
|
|
22
|
+
组织通用 Agent、外部 Agent 或 CLI 壳应通过 `TacoreActionSDK` 调用云应用暴露的 `/.tacore/capabilities.json`,而不是依赖应用 UI、DOM、按钮或页面路径。应用 GUI 只是 capability 的一个使用者,必须和 SDK 执行共享同一 Action Registry / service 层。
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { TacoreActionSDK } from '@tacoreai/web-sdk'
|
|
26
|
+
|
|
27
|
+
const actionSdk = new TacoreActionSDK({
|
|
28
|
+
accessToken: 'PLATFORM_ACCESS_TOKEN',
|
|
29
|
+
organizationId: 'org_xxx',
|
|
30
|
+
appId: 'crm_app_xxx',
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const manifest = await actionSdk.listCapabilities()
|
|
34
|
+
const schema = await actionSdk.getCapabilitySchema('crm.lead.create')
|
|
35
|
+
const draft = await actionSdk.draft('crm.lead.create', {
|
|
36
|
+
name: 'Acme',
|
|
37
|
+
phone: '13800000000',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// 写入类能力应先展示 preview/dry-run,再经用户确认后执行。
|
|
41
|
+
await actionSdk.execute('crm.lead.create', {
|
|
42
|
+
draftId: draft.draftId,
|
|
43
|
+
action: {
|
|
44
|
+
name: 'crm.lead.create',
|
|
45
|
+
idempotencyKey: 'lead:13800000000',
|
|
46
|
+
steps: [
|
|
47
|
+
{
|
|
48
|
+
op: 'create',
|
|
49
|
+
modelName: 'lead',
|
|
50
|
+
data: { name: 'Acme', phone: '13800000000' },
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
SDK 封装平台 `/plat/agent/capabilities` 的发现、dry-run 与 execute 请求;核心执行仍落到 manifest 声明的 `actions/run` 事务契约,CLI 只是同一接口的一层命令行包装。
|
|
58
|
+
|
|
20
59
|
### AppsClient (Events)
|
|
21
60
|
|
|
22
61
|
应用自定义埋点应使用事件日志接口,不要把高频事件写入通用数据模型。
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { getAppsApiBaseUrl, getGlobalOptions, isBrowser } from "./utils/index.js";
|
|
2
|
+
|
|
3
|
+
const PLATFORM_ACCESS_TOKEN_STORAGE_KEY = "tacoreai_access_token";
|
|
4
|
+
|
|
5
|
+
function normalizeString(value) {
|
|
6
|
+
return String(value || "").trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function normalizeAccessToken(value) {
|
|
10
|
+
const token = normalizeString(value);
|
|
11
|
+
return token.replace(/^Bearer\s+/i, "").trim();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function readPlatformAccessToken() {
|
|
15
|
+
if (!isBrowser) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return normalizeAccessToken(localStorage.getItem(PLATFORM_ACCESS_TOKEN_STORAGE_KEY));
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("[TacoreActionSDK] Failed to read platform access token:", error);
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildQuery(params = {}) {
|
|
27
|
+
const searchParams = new URLSearchParams();
|
|
28
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
29
|
+
if (value === undefined || value === null || value === "") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
searchParams.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
33
|
+
});
|
|
34
|
+
const query = searchParams.toString();
|
|
35
|
+
return query ? `?${query}` : "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveDraftCapabilityId(draft) {
|
|
39
|
+
return normalizeString(draft?.capabilityId || draft?.capability?.capabilityId);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class TacoreActionSDK {
|
|
43
|
+
constructor(config = {}) {
|
|
44
|
+
const globalOptions = getGlobalOptions();
|
|
45
|
+
this.config = {
|
|
46
|
+
...globalOptions.clientDefaultConfig,
|
|
47
|
+
apiBaseUrl: getAppsApiBaseUrl(),
|
|
48
|
+
organizationId: "",
|
|
49
|
+
projectId: "",
|
|
50
|
+
appId: "",
|
|
51
|
+
...config,
|
|
52
|
+
};
|
|
53
|
+
this.accessToken = normalizeAccessToken(config.accessToken || "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
updateConfig(nextConfig = {}) {
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(nextConfig, "accessToken")) {
|
|
58
|
+
this.setAccessToken(nextConfig.accessToken);
|
|
59
|
+
}
|
|
60
|
+
this.config = {
|
|
61
|
+
...this.config,
|
|
62
|
+
...nextConfig,
|
|
63
|
+
accessToken: this.accessToken,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setAccessToken(token) {
|
|
68
|
+
this.accessToken = normalizeAccessToken(token);
|
|
69
|
+
this.config.accessToken = this.accessToken;
|
|
70
|
+
return this.accessToken;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getAccessToken() {
|
|
74
|
+
return this.accessToken || readPlatformAccessToken();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getHeaders(options = {}) {
|
|
78
|
+
const headers = {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
...(options.headers || {}),
|
|
81
|
+
};
|
|
82
|
+
const organizationId = normalizeString(options.organizationId || this.config.organizationId);
|
|
83
|
+
const projectId = normalizeString(options.projectId || this.config.projectId);
|
|
84
|
+
const appId = normalizeString(options.appId || this.config.appId);
|
|
85
|
+
const token = this.getAccessToken();
|
|
86
|
+
|
|
87
|
+
if (organizationId) {
|
|
88
|
+
headers["x-org-id"] = organizationId;
|
|
89
|
+
}
|
|
90
|
+
if (projectId) {
|
|
91
|
+
headers["x-project-id"] = projectId;
|
|
92
|
+
}
|
|
93
|
+
if (appId) {
|
|
94
|
+
headers["x-app-id"] = appId;
|
|
95
|
+
}
|
|
96
|
+
if (token) {
|
|
97
|
+
headers.Authorization = `Bearer ${token}`;
|
|
98
|
+
}
|
|
99
|
+
return headers;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async request(endpoint, options = {}) {
|
|
103
|
+
const response = await fetch(`${this.config.apiBaseUrl}${endpoint}`, {
|
|
104
|
+
...options,
|
|
105
|
+
headers: this.getHeaders(options),
|
|
106
|
+
});
|
|
107
|
+
const result = await response.json().catch(() => ({}));
|
|
108
|
+
if (!response.ok || result?.success === false) {
|
|
109
|
+
const error = new Error(result?.message || result?.error || `HTTP ${response.status}: ${response.statusText}`);
|
|
110
|
+
error.status = response.status;
|
|
111
|
+
error.code = result?.code;
|
|
112
|
+
error.details = result?.details;
|
|
113
|
+
error.responseData = result;
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
return result?.data ?? result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
get(endpoint, params = {}, options = {}) {
|
|
120
|
+
return this.request(`${endpoint}${buildQuery(params)}`, {
|
|
121
|
+
...options,
|
|
122
|
+
method: "GET",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
post(endpoint, body = {}, options = {}) {
|
|
127
|
+
return this.request(endpoint, {
|
|
128
|
+
...options,
|
|
129
|
+
method: "POST",
|
|
130
|
+
body: JSON.stringify(body),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
listCapabilities(options = {}) {
|
|
135
|
+
const appId = normalizeString(options.appId || this.config.appId);
|
|
136
|
+
return this.get("/plat/agent/capabilities", { appId }, { appId, ...options });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getCapabilitySchema(capabilityId, options = {}) {
|
|
140
|
+
const appId = normalizeString(options.appId || this.config.appId);
|
|
141
|
+
const normalizedCapabilityId = encodeURIComponent(normalizeString(capabilityId));
|
|
142
|
+
return this.get(`/plat/agent/capabilities/${normalizedCapabilityId}`, { appId }, { appId, ...options });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
dryRun(capabilityId, options = {}) {
|
|
146
|
+
const appId = normalizeString(options.appId || this.config.appId);
|
|
147
|
+
return this.post("/plat/agent/capabilities/dry-run", {
|
|
148
|
+
appId,
|
|
149
|
+
capabilityId: normalizeString(capabilityId),
|
|
150
|
+
input: options.input || {},
|
|
151
|
+
action: options.action || null,
|
|
152
|
+
options: options.options || {},
|
|
153
|
+
}, { appId, ...options });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
draft(capabilityId, inputOrOptions = {}, maybeOptions = {}) {
|
|
157
|
+
const isOptionsObject = inputOrOptions && typeof inputOrOptions === "object" && (
|
|
158
|
+
Object.prototype.hasOwnProperty.call(inputOrOptions, "input") ||
|
|
159
|
+
Object.prototype.hasOwnProperty.call(inputOrOptions, "appId") ||
|
|
160
|
+
Object.prototype.hasOwnProperty.call(inputOrOptions, "options")
|
|
161
|
+
);
|
|
162
|
+
const options = isOptionsObject
|
|
163
|
+
? inputOrOptions
|
|
164
|
+
: {
|
|
165
|
+
...maybeOptions,
|
|
166
|
+
input: inputOrOptions || {},
|
|
167
|
+
};
|
|
168
|
+
return this.dryRun(capabilityId, options);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
preview(draftOrCapabilityId, options = {}) {
|
|
172
|
+
if (draftOrCapabilityId && typeof draftOrCapabilityId === "object") {
|
|
173
|
+
if (draftOrCapabilityId.dryRun === true) {
|
|
174
|
+
return Promise.resolve(draftOrCapabilityId);
|
|
175
|
+
}
|
|
176
|
+
return this.dryRun(resolveDraftCapabilityId(draftOrCapabilityId), {
|
|
177
|
+
...draftOrCapabilityId,
|
|
178
|
+
...options,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return this.dryRun(draftOrCapabilityId, options);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
execute(draftOrCapabilityId, options = {}) {
|
|
185
|
+
const draft = draftOrCapabilityId && typeof draftOrCapabilityId === "object" ? draftOrCapabilityId : null;
|
|
186
|
+
const capabilityId = draft ? resolveDraftCapabilityId(draft) : normalizeString(draftOrCapabilityId);
|
|
187
|
+
const appId = normalizeString(options.appId || draft?.appId || this.config.appId);
|
|
188
|
+
return this.post("/plat/agent/capabilities/execute", {
|
|
189
|
+
appId,
|
|
190
|
+
capabilityId,
|
|
191
|
+
draftId: normalizeString(options.draftId || draft?.draftId),
|
|
192
|
+
input: options.input || draft?.input || {},
|
|
193
|
+
action: options.action || draft?.action || null,
|
|
194
|
+
options: options.options || {},
|
|
195
|
+
}, { appId, ...options });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
runTransactionAction({ appId, capabilityId, input = {}, action, options = {} } = {}) {
|
|
199
|
+
return this.execute(capabilityId, {
|
|
200
|
+
appId,
|
|
201
|
+
input,
|
|
202
|
+
action,
|
|
203
|
+
options,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -7,6 +7,11 @@ const DEFAULT_FILE_SIZE_LIMIT = 100 * 1024 * 1024;
|
|
|
7
7
|
const DEFAULT_MAX_FILES = 20;
|
|
8
8
|
|
|
9
9
|
const isPreviewMode = () => process.env.TACORE_APPSERVER_PREVIEW_MODE === "true";
|
|
10
|
+
const isLocalDeploymentMode = (env = {}) =>
|
|
11
|
+
env.localDeployment === true ||
|
|
12
|
+
env.localAppServer === true ||
|
|
13
|
+
env.appServerDeploymentMode === "local" ||
|
|
14
|
+
process.env.TACORE_APPSERVER_LOCAL_DEPLOYMENT_MODE === "true";
|
|
10
15
|
|
|
11
16
|
const isValidInternalToken = (incomingValue, expectedValue) => {
|
|
12
17
|
return Boolean(expectedValue) && Boolean(incomingValue) && incomingValue === expectedValue;
|
|
@@ -78,6 +83,15 @@ const validateExternalApiKey = async (appsClient, appId, apiKey) => {
|
|
|
78
83
|
return Boolean(result?.success && result?.data?.valid);
|
|
79
84
|
};
|
|
80
85
|
|
|
86
|
+
const validateLocalDeploymentAccessToken = async (env, accessToken) => {
|
|
87
|
+
const authClient = createRequestScopedAppsClient(env, {
|
|
88
|
+
accessToken,
|
|
89
|
+
clientAppId: env.appId,
|
|
90
|
+
});
|
|
91
|
+
const result = await authClient.getIamContext({});
|
|
92
|
+
return Boolean(result?.success);
|
|
93
|
+
};
|
|
94
|
+
|
|
81
95
|
const getPreviewGuidePayload = (req) => {
|
|
82
96
|
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
83
97
|
const invokeUrl = `${baseUrl}/invokeAppServerAPI?apiName=YOUR_API_NAME`;
|
|
@@ -300,51 +314,71 @@ export const createAppServerRuntime = async (options = {}) => {
|
|
|
300
314
|
|
|
301
315
|
if (!isPlatformProxyRequest && !isSchedulerRequest) {
|
|
302
316
|
if (!requestApiKey) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
317
|
+
if (isLocalDeploymentMode(env) && requestAccessToken) {
|
|
318
|
+
try {
|
|
319
|
+
const isValidAccessToken = await validateLocalDeploymentAccessToken(env, requestAccessToken);
|
|
320
|
+
if (!isValidAccessToken) {
|
|
321
|
+
return res.status(401).json({
|
|
322
|
+
success: false,
|
|
323
|
+
code: "INVALID_ACCESS_TOKEN",
|
|
324
|
+
error: "Invalid Authorization token",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
} catch (error) {
|
|
328
|
+
console.error("[AppServer] Failed to validate local deployment access token:", error);
|
|
329
|
+
return res.status(error.status || 401).json({
|
|
330
|
+
success: false,
|
|
331
|
+
code: "ACCESS_TOKEN_VALIDATION_FAILED",
|
|
332
|
+
error: error.message,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
console.warn("[AppServer Auth] Missing X-API-Key. This request is treated as external call.");
|
|
337
|
+
return res.status(401).json({
|
|
338
|
+
success: false,
|
|
339
|
+
code: "MISSING_API_KEY",
|
|
340
|
+
error: "X-API-Key header is required",
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
if (!isPreviewApiKeyShapeValid(requestApiKey)) {
|
|
345
|
+
return res.status(400).json({
|
|
346
|
+
success: false,
|
|
347
|
+
code: "INVALID_API_KEY_FORMAT",
|
|
348
|
+
error: "X-API-Key format is invalid. Expected 8-128 chars: [A-Za-z0-9._-]",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
let isValidApiKey = false;
|
|
353
|
+
try {
|
|
354
|
+
const authClient = createRequestScopedAppsClient(env, {
|
|
355
|
+
accessToken: requestAccessToken || null,
|
|
356
|
+
clientAppId: env.appId,
|
|
357
|
+
});
|
|
358
|
+
isValidApiKey = await validateExternalApiKey(authClient, env.appId, requestApiKey);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error("[AppServer] Failed to validate external API key:", error);
|
|
361
|
+
return res.status(500).json({
|
|
362
|
+
success: false,
|
|
363
|
+
code: "API_KEY_VALIDATION_FAILED",
|
|
364
|
+
error: error.message,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (!isValidApiKey) {
|
|
369
|
+
return res.status(401).json({
|
|
370
|
+
success: false,
|
|
371
|
+
code: "INVALID_API_KEY",
|
|
372
|
+
error: "Invalid X-API-Key",
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
isExternalApiKeyRequest = true;
|
|
377
|
+
appServerApiKey = requestApiKey;
|
|
378
|
+
|
|
379
|
+
if (isPreviewMode() && !requestAccessToken) {
|
|
380
|
+
previewAppServerApiKey = requestApiKey;
|
|
381
|
+
}
|
|
348
382
|
}
|
|
349
383
|
}
|
|
350
384
|
|
|
@@ -398,7 +432,7 @@ export const createAppServerRuntime = async (options = {}) => {
|
|
|
398
432
|
|
|
399
433
|
const listen = (listenOptions = {}) => {
|
|
400
434
|
const port = listenOptions.port || process.env.PORT || 9000;
|
|
401
|
-
const host = listenOptions.host;
|
|
435
|
+
const host = listenOptions.host || process.env.HOST || "";
|
|
402
436
|
const callback = typeof listenOptions.onListen === "function"
|
|
403
437
|
? listenOptions.onListen
|
|
404
438
|
: () => {
|
|
@@ -121,6 +121,27 @@ const clearPreviewSessionToken = (appId) => {
|
|
|
121
121
|
previewSessionPromiseCache.delete(appId);
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
+
const getBrowserPreviewBridgeBaseUrl = () => {
|
|
125
|
+
if (typeof window === "undefined") {
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
return String(window.__TACORE_APPSERVER_PREVIEW_BRIDGE_BASE_URL__ || "").trim().replace(/\/$/, "");
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const getBrowserPreviewBridgeInvokeUrl = () => {
|
|
132
|
+
if (typeof window === "undefined") {
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
return String(window.__TACORE_APPSERVER_PREVIEW_BRIDGE_URL__ || "").trim();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const appendPreviewInvokeParams = (rawUrl, appId, apiName) => {
|
|
139
|
+
const url = new URL(rawUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
140
|
+
url.searchParams.set("appId", appId);
|
|
141
|
+
url.searchParams.set("apiName", apiName);
|
|
142
|
+
return url.toString();
|
|
143
|
+
};
|
|
144
|
+
|
|
124
145
|
const getPreviewSessionToken = async function(options = {}) {
|
|
125
146
|
const { forceRefresh = false } = options;
|
|
126
147
|
const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
|
|
@@ -139,7 +160,10 @@ const getPreviewSessionToken = async function(options = {}) {
|
|
|
139
160
|
}
|
|
140
161
|
|
|
141
162
|
const requestPromise = (async () => {
|
|
142
|
-
const
|
|
163
|
+
const bridgeBaseUrl = getBrowserPreviewBridgeBaseUrl();
|
|
164
|
+
const endpoint = bridgeBaseUrl
|
|
165
|
+
? `${bridgeBaseUrl}/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`
|
|
166
|
+
: `/appserver-preview/session?appId=${encodeURIComponent(appServerOwnerAppId)}`;
|
|
143
167
|
const response = await fetch(endpoint, {
|
|
144
168
|
method: "GET",
|
|
145
169
|
headers: {
|
|
@@ -404,7 +428,13 @@ const invokeByPlatformProxy = async function(appServerAPIName, payload, options
|
|
|
404
428
|
|
|
405
429
|
const invokeByPreviewProxyOnce = async function(appServerAPIName, payload, options = {}, previewToken) {
|
|
406
430
|
const appServerOwnerAppId = getAppServerOwnerAppId.call(this);
|
|
407
|
-
const
|
|
431
|
+
const bridgeInvokeUrl = getBrowserPreviewBridgeInvokeUrl();
|
|
432
|
+
const bridgeBaseUrl = getBrowserPreviewBridgeBaseUrl();
|
|
433
|
+
const endpoint = bridgeInvokeUrl
|
|
434
|
+
? appendPreviewInvokeParams(bridgeInvokeUrl, appServerOwnerAppId, appServerAPIName)
|
|
435
|
+
: bridgeBaseUrl
|
|
436
|
+
? `${bridgeBaseUrl}/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`
|
|
437
|
+
: `/appserver-preview/invokeAppServerAPI?appId=${encodeURIComponent(appServerOwnerAppId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
|
|
408
438
|
const response = await fetch(
|
|
409
439
|
endpoint,
|
|
410
440
|
buildRemoteRequestInit.call(this, payload, options, {
|
|
@@ -432,17 +462,26 @@ const invokeByPreviewProxy = async function(appServerAPIName, payload, options =
|
|
|
432
462
|
|
|
433
463
|
const invokeByCrossAppDirect = async function(appServerAPIName, payload, options = {}) {
|
|
434
464
|
const endpoint = `${this.config.appServerBaseUrl}/invokeAppServerAPI?apiName=${encodeURIComponent(appServerAPIName)}`;
|
|
435
|
-
const
|
|
436
|
-
"X-API-Key": this.config.appServerApiKey
|
|
437
|
-
|
|
465
|
+
const extraHeaders = this.config.appServerApiKey
|
|
466
|
+
? { "X-API-Key": this.config.appServerApiKey }
|
|
467
|
+
: {};
|
|
468
|
+
const requestInit = buildRemoteRequestInit.call(this, payload, options, extraHeaders);
|
|
438
469
|
const response = await fetch(endpoint, requestInit);
|
|
439
470
|
return await unwrapAppServerResponse(response, "[AppServer-CrossApp]");
|
|
440
471
|
};
|
|
441
472
|
|
|
473
|
+
const canUseBackendDirectAppServer = function() {
|
|
474
|
+
return Boolean(this.config.appServerBaseUrl && this.config.appServerApiKey);
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
const canUseProductionBrowserDirectAppServer = function() {
|
|
478
|
+
return Boolean(this.config.appServerBaseUrl);
|
|
479
|
+
};
|
|
480
|
+
|
|
442
481
|
/**
|
|
443
482
|
* 调用一个 App Server API。
|
|
444
483
|
* - 开发态浏览器:预览页走 CLI preview bridge,其他页面走平台转发。
|
|
445
|
-
* -
|
|
484
|
+
* - 生产态浏览器:配置了 appServerBaseUrl 时直连,使用当前用户 Authorization 鉴权。
|
|
446
485
|
* - 后端跨应用:允许使用 appServerBaseUrl + appServerApiKey 直连目标 AppServer。
|
|
447
486
|
* - 后端当前应用:从本地注册表执行。
|
|
448
487
|
*
|
|
@@ -456,7 +495,10 @@ const invokeAppServerAPI = async function(appServerAPIName, payload, options = {
|
|
|
456
495
|
throw new Error("appServerAPIName is required");
|
|
457
496
|
}
|
|
458
497
|
|
|
459
|
-
if (
|
|
498
|
+
if (
|
|
499
|
+
(isBackend && canUseBackendDirectAppServer.call(this)) ||
|
|
500
|
+
(isProductionBrowser && canUseProductionBrowserDirectAppServer.call(this))
|
|
501
|
+
) {
|
|
460
502
|
return await invokeByCrossAppDirect.call(this, appServerAPIName, payload, options);
|
|
461
503
|
}
|
|
462
504
|
|
|
@@ -7,22 +7,6 @@ export const appsClientIamMethods = {
|
|
|
7
7
|
return this._post("/apps/iam/bootstrap", params);
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
async listIamOrgUnits(params = {}) {
|
|
11
|
-
return this._post("/apps/iam/org-units/list", params);
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
async createIamOrgUnit(params = {}) {
|
|
15
|
-
return this._post("/apps/iam/org-units", params);
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
async updateIamOrgUnit(params = {}) {
|
|
19
|
-
return this._post("/apps/iam/org-units/update", params);
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
async deleteIamOrgUnit(params = {}) {
|
|
23
|
-
return this._post("/apps/iam/org-units/delete", params);
|
|
24
|
-
},
|
|
25
|
-
|
|
26
10
|
async listIamRoles(params = {}) {
|
|
27
11
|
return this._post("/apps/iam/roles/list", params);
|
|
28
12
|
},
|
|
@@ -39,22 +23,6 @@ export const appsClientIamMethods = {
|
|
|
39
23
|
return this._post("/apps/iam/roles/delete", params);
|
|
40
24
|
},
|
|
41
25
|
|
|
42
|
-
async listIamStaff(params = {}) {
|
|
43
|
-
return this._post("/apps/iam/staff/list", params);
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
async createIamStaff(params = {}) {
|
|
47
|
-
return this._post("/apps/iam/staff", params);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
async updateIamStaff(params = {}) {
|
|
51
|
-
return this._post("/apps/iam/staff/update", params);
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
async deleteIamStaff(params = {}) {
|
|
55
|
-
return this._post("/apps/iam/staff/delete", params);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
26
|
async listModelPolicies(params = {}) {
|
|
59
27
|
return this._post("/apps/data/model-policies/list", params);
|
|
60
28
|
},
|
|
@@ -56,6 +56,7 @@ class AppsClient extends BaseAppsClient {
|
|
|
56
56
|
/**
|
|
57
57
|
* 定义策略适配器映射
|
|
58
58
|
* 将 invoke 的对象参数转换为老方法的位置参数
|
|
59
|
+
* stone手动: 注意!!! 无需前端特殊逻辑的新方法,仅需直接在后端新增 xxx/yyy 这种接口即可,websdk 不需要发版,应用层直接 client.invoke('xxx/yyy', params) 即可调用;需要前端特殊逻辑适配的方法,才需要在这里新增适配器
|
|
59
60
|
*/
|
|
60
61
|
get adapters() {
|
|
61
62
|
return {
|
|
@@ -113,18 +114,10 @@ class AppsClient extends BaseAppsClient {
|
|
|
113
114
|
// === 企业 IAM / 审计 / 文件鉴权 ===
|
|
114
115
|
"iam/me": params => this.getIamContext(params),
|
|
115
116
|
"iam/bootstrap": params => this.bootstrapIam(params),
|
|
116
|
-
"iam/org-units/list": params => this.listIamOrgUnits(params),
|
|
117
|
-
"iam/org-units": params => this.createIamOrgUnit(params),
|
|
118
|
-
"iam/org-units/update": params => this.updateIamOrgUnit(params),
|
|
119
|
-
"iam/org-units/delete": params => this.deleteIamOrgUnit(params),
|
|
120
117
|
"iam/roles/list": params => this.listIamRoles(params),
|
|
121
118
|
"iam/roles": params => this.createIamRole(params),
|
|
122
119
|
"iam/roles/update": params => this.updateIamRole(params),
|
|
123
120
|
"iam/roles/delete": params => this.deleteIamRole(params),
|
|
124
|
-
"iam/staff/list": params => this.listIamStaff(params),
|
|
125
|
-
"iam/staff": params => this.createIamStaff(params),
|
|
126
|
-
"iam/staff/update": params => this.updateIamStaff(params),
|
|
127
|
-
"iam/staff/delete": params => this.deleteIamStaff(params),
|
|
128
121
|
"data/model-policies/list": params => this.listModelPolicies(params),
|
|
129
122
|
"data/model-policies/declare": params => this.declareModelPolicy(params),
|
|
130
123
|
"audit/write": params => this.writeAuditLog(params),
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as utils from "./utils/index.js"
|
|
|
4
4
|
export { AppsClient } from "./database/core/apps/AppsClient.js"
|
|
5
5
|
export { AppsAuthManager } from "./database/core/apps/AppsAuthManager.js"
|
|
6
6
|
export { AppsPublicClient } from "./database/core/apps/AppsPublicClient.js"
|
|
7
|
+
export { TacoreActionSDK } from "./TacoreActionSDK.js"
|
|
7
8
|
|
|
8
9
|
// 导出工具函数
|
|
9
10
|
export { utils }
|