@sparkelf/dsh-dataops-managed 0.3.30 → 0.3.32
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/lib/client.js +543 -200
- package/lib/client.js.map +1 -1
- package/lib/index.js +113 -4
- package/lib/types/client/ResourceCatalogSidebar.d.ts +17 -0
- package/lib/types/client/ResourceListPanel.d.ts +40 -0
- package/lib/types/client/ResourceTabIcon.d.ts +11 -0
- package/lib/types/client/locales.d.ts +2 -0
- package/lib/types/client/review-client.d.ts +8 -6
- package/lib/types/client/review-types.d.ts +20 -0
- package/lib/types/resource-management-api.d.ts +2 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1250,6 +1250,11 @@ var CollectApi = class {
|
|
|
1250
1250
|
};
|
|
1251
1251
|
//#endregion
|
|
1252
1252
|
//#region src/resource-management-api.ts
|
|
1253
|
+
/**
|
|
1254
|
+
* DataOps resource-management transport: pending approval tasks, existing access grants,
|
|
1255
|
+
* batch grant/revoke, and approval decisions. Disclosure is handled by tool-scope; this file
|
|
1256
|
+
* only speaks to the existing DataOps APIs.
|
|
1257
|
+
*/
|
|
1253
1258
|
const reasonOf = (body) => {
|
|
1254
1259
|
if (typeof body !== "object" || body === null || Array.isArray(body)) return "";
|
|
1255
1260
|
const record = body;
|
|
@@ -1307,6 +1312,7 @@ var ResourceManagementApi = class {
|
|
|
1307
1312
|
const action = decision.decision === "approve" ? "complete" : "reject";
|
|
1308
1313
|
return this.call("/api/tasks/" + decision.taskId.toString() + "/user-tasks/" + encodeURIComponent(decision.userTaskId) + "/" + action, {
|
|
1309
1314
|
method: "POST",
|
|
1315
|
+
headers: { "idempotency-key": decision.idempotencyKey?.trim() || "dataops-managed-" + randomUUID() },
|
|
1310
1316
|
body: JSON.stringify({
|
|
1311
1317
|
expectedVersion: decision.expectedVersion ?? 0,
|
|
1312
1318
|
comment: decision.comment?.trim() || (decision.decision === "approve" ? "同意" : "驳回")
|
|
@@ -2591,6 +2597,10 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2591
2597
|
expected_version: {
|
|
2592
2598
|
type: "number",
|
|
2593
2599
|
description: "Current taskVersion; read from task detail when omitted."
|
|
2600
|
+
},
|
|
2601
|
+
idempotency_key: {
|
|
2602
|
+
type: "string",
|
|
2603
|
+
description: "Optional replay key; reuse the original key to retry a timed-out command."
|
|
2594
2604
|
}
|
|
2595
2605
|
},
|
|
2596
2606
|
additionalProperties: false
|
|
@@ -2628,7 +2638,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2628
2638
|
userTaskId,
|
|
2629
2639
|
decision: action,
|
|
2630
2640
|
comment: decision.comment,
|
|
2631
|
-
expectedVersion
|
|
2641
|
+
expectedVersion,
|
|
2642
|
+
idempotencyKey: decision.idempotency_key
|
|
2632
2643
|
});
|
|
2633
2644
|
results.push({
|
|
2634
2645
|
taskId,
|
|
@@ -3692,6 +3703,47 @@ const COLLECT_SKILL = {
|
|
|
3692
3703
|
rank: BUNDLED_SKILL_RANK,
|
|
3693
3704
|
locator: COLLECT_SKILL_FILE
|
|
3694
3705
|
};
|
|
3706
|
+
/** Connector authoring skill: only superadmins hold `data:connector:authoring`. */
|
|
3707
|
+
const CONNECTOR_SKILL_NAME = "api-connector-authoring";
|
|
3708
|
+
const CONNECTOR_SKILL_FILE = new URL("../skills/api-connector-authoring/SKILL.md", import.meta.url);
|
|
3709
|
+
const CONNECTOR_SKILL_ROOT = fileURLToPath(new URL("../", import.meta.url));
|
|
3710
|
+
/** 该技能的门禁:只有持有 `data:connector:authoring` 的超管能看到(只对超管授权)。 */
|
|
3711
|
+
const CONNECTOR_SKILL_PERMISSION = "data:connector:authoring";
|
|
3712
|
+
const CONNECTOR_SKILL = {
|
|
3713
|
+
name: CONNECTOR_SKILL_NAME,
|
|
3714
|
+
metadata: { permissions: [CONNECTOR_SKILL_PERMISSION] },
|
|
3715
|
+
description: "从接口文档(OpenAPI / Swagger / 接口说明)创建 API Connector 并导入为接口资源时使用。包含文档解析、导入粒度判断、资源命名与目录治理、GenUI 预览和用户确认后才导入的流程。",
|
|
3716
|
+
invocation: {
|
|
3717
|
+
modelInvocable: true,
|
|
3718
|
+
userInvocable: true
|
|
3719
|
+
},
|
|
3720
|
+
provider: CONNECTOR_SKILL_NAME,
|
|
3721
|
+
source: "bundled",
|
|
3722
|
+
resourceBase: {
|
|
3723
|
+
kind: "directory",
|
|
3724
|
+
path: CONNECTOR_SKILL_ROOT
|
|
3725
|
+
},
|
|
3726
|
+
rank: BUNDLED_SKILL_RANK,
|
|
3727
|
+
locator: CONNECTOR_SKILL_FILE
|
|
3728
|
+
};
|
|
3729
|
+
/**
|
|
3730
|
+
* 当前 DataOps 身份是否允许看到连接器作者技能。
|
|
3731
|
+
*
|
|
3732
|
+
* 核心层对 provider 的列表是 fail-open 的:不认识的技能一律展示。所以门禁必须在这里做——
|
|
3733
|
+
* 没有权限时返回空列表,`get` 也拒绝,避免只靠 SKILL.md 里的 frontmatter 声明。
|
|
3734
|
+
*/
|
|
3735
|
+
let connectorSkillAllowed = () => false;
|
|
3736
|
+
const connectorSkillProvider = {
|
|
3737
|
+
name: CONNECTOR_SKILL_NAME,
|
|
3738
|
+
list: () => Promise.resolve(connectorSkillAllowed() ? [CONNECTOR_SKILL] : []),
|
|
3739
|
+
async get() {
|
|
3740
|
+
if (!connectorSkillAllowed()) throw new Error("connector skill is not available for this account");
|
|
3741
|
+
return {
|
|
3742
|
+
...CONNECTOR_SKILL,
|
|
3743
|
+
content: await readFile(CONNECTOR_SKILL_FILE, "utf8")
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
};
|
|
3695
3747
|
/** Serve the collection skill to the catalog. */
|
|
3696
3748
|
const collectSkillProvider = {
|
|
3697
3749
|
name: COLLECT_SKILL_NAME,
|
|
@@ -3715,6 +3767,7 @@ async function apply(ctx, config) {
|
|
|
3715
3767
|
let mcpFiber;
|
|
3716
3768
|
ctx.skills.registerProvider(() => querySkillProvider);
|
|
3717
3769
|
ctx.skills.registerProvider(() => collectSkillProvider);
|
|
3770
|
+
ctx.skills.registerProvider(() => connectorSkillProvider);
|
|
3718
3771
|
const ensureMcp = async () => {
|
|
3719
3772
|
if (mcpFiber !== void 0 && mcpFiber.uid !== null) return;
|
|
3720
3773
|
const fiber = ctx.plugin(McpClient, {
|
|
@@ -3844,16 +3897,54 @@ async function apply(ctx, config) {
|
|
|
3844
3897
|
ctx.effect(() => ctx.webServer.register({
|
|
3845
3898
|
kind: "exact",
|
|
3846
3899
|
path: RESOURCE_TAB_CONFIG_PATH,
|
|
3847
|
-
handler: (request, response) => {
|
|
3900
|
+
handler: async (request, response) => {
|
|
3848
3901
|
const payload = resolveResourceTabConfig(request, config.webBaseUrl);
|
|
3902
|
+
let token;
|
|
3903
|
+
try {
|
|
3904
|
+
token = (await ctx.credentials.resolve(accessRef))?.value;
|
|
3905
|
+
} catch {
|
|
3906
|
+
token = void 0;
|
|
3907
|
+
}
|
|
3849
3908
|
response.writeHead(200, {
|
|
3850
3909
|
"content-type": "application/json; charset=utf-8",
|
|
3851
3910
|
"cache-control": "no-store"
|
|
3852
3911
|
});
|
|
3853
|
-
response.end(JSON.stringify(payload
|
|
3912
|
+
response.end(JSON.stringify(token === void 0 ? payload : {
|
|
3913
|
+
...payload,
|
|
3914
|
+
token
|
|
3915
|
+
}));
|
|
3854
3916
|
}
|
|
3855
3917
|
}), "dataops-managed: resource tab config route");
|
|
3856
3918
|
/**
|
|
3919
|
+
* Same-origin resource reads for the tab's native fallback.
|
|
3920
|
+
*
|
|
3921
|
+
* A DSH page served from its own origin (for example the workspace port) cannot open the
|
|
3922
|
+
* portal's `/embed/resources` iframe with a session: that document is cross-origin and its
|
|
3923
|
+
* sessionStorage token is unreachable. The tab then renders the list in React and reads the
|
|
3924
|
+
* same DataOps resources through this route, where the Host still owns the JWT.
|
|
3925
|
+
*/
|
|
3926
|
+
ctx.effect(() => ctx.webServer.register({
|
|
3927
|
+
kind: "prefix",
|
|
3928
|
+
path: "/integrations/dataops/resources",
|
|
3929
|
+
handler: async (request, response) => {
|
|
3930
|
+
const method = (request.method ?? "GET").toUpperCase();
|
|
3931
|
+
const url = new URL(request.url ?? "/", "http://dsh.internal");
|
|
3932
|
+
const rest = url.pathname.slice(31).replace(/^\/+/u, "").replace(/\/+$/u, "");
|
|
3933
|
+
const preferenceWrite = /^\d+\/(?:favorite|pin)$/u.test(rest);
|
|
3934
|
+
if (method !== "GET" && !(preferenceWrite && (method === "PUT" || method === "DELETE"))) {
|
|
3935
|
+
response.writeHead(405, {
|
|
3936
|
+
allow: "GET, PUT, DELETE",
|
|
3937
|
+
"content-length": "0"
|
|
3938
|
+
});
|
|
3939
|
+
response.end();
|
|
3940
|
+
return;
|
|
3941
|
+
}
|
|
3942
|
+
const target = rest === "" ? "/api/resources" + (url.search || "") : "/api/resources/" + encodeURIComponent(rest) + (url.search || "");
|
|
3943
|
+
const result = await reviewApi.request(target, { method });
|
|
3944
|
+
writeJson(response, result.status, result.body);
|
|
3945
|
+
}
|
|
3946
|
+
}), "dataops-managed: resource list bridge");
|
|
3947
|
+
/**
|
|
3857
3948
|
* The managed tool list follows the workspace's DataOps scope.
|
|
3858
3949
|
*
|
|
3859
3950
|
* `AiToolManager` registers only the skill/review tools the current principal can use and
|
|
@@ -3863,6 +3954,11 @@ async function apply(ctx, config) {
|
|
|
3863
3954
|
* route's answer, because a role edit does not change the JWT but does change the scope.
|
|
3864
3955
|
*/
|
|
3865
3956
|
const aiTools = new AiToolManager(ctx, reviewApi, resourceTabHub);
|
|
3957
|
+
connectorSkillAllowed = () => {
|
|
3958
|
+
const scope = aiTools.currentScope();
|
|
3959
|
+
if (scope === void 0) return false;
|
|
3960
|
+
return (scope.permissions ?? scope.permissionKeys ?? []).includes(CONNECTOR_SKILL_PERMISSION);
|
|
3961
|
+
};
|
|
3866
3962
|
ctx.effect(() => () => aiTools.dispose(), "dataops-managed: skill and review tool disclosure");
|
|
3867
3963
|
ctx.effect(() => ctx.on("credentials/reference-updated", (ref) => {
|
|
3868
3964
|
if (String(ref) !== config.credentialRef) return;
|
|
@@ -4584,9 +4680,22 @@ async function apply(ctx, config) {
|
|
|
4584
4680
|
kind: "exact",
|
|
4585
4681
|
path: AUTH_STATE_PATH,
|
|
4586
4682
|
handler: async (request, response) => {
|
|
4683
|
+
if (request.method === "POST") {
|
|
4684
|
+
const body = await readJson(request).catch(() => null);
|
|
4685
|
+
if (body?.state === "expired") noteExpired();
|
|
4686
|
+
else if (body?.state === "valid") noteAccepted();
|
|
4687
|
+
else {
|
|
4688
|
+
response.writeHead(400, { "content-length": "0" });
|
|
4689
|
+
response.end();
|
|
4690
|
+
return;
|
|
4691
|
+
}
|
|
4692
|
+
response.writeHead(204, { "cache-control": "no-store" });
|
|
4693
|
+
response.end();
|
|
4694
|
+
return;
|
|
4695
|
+
}
|
|
4587
4696
|
if (request.method !== "GET") {
|
|
4588
4697
|
response.writeHead(405, {
|
|
4589
|
-
allow: "GET",
|
|
4698
|
+
allow: "GET, POST",
|
|
4590
4699
|
"content-length": "0"
|
|
4591
4700
|
});
|
|
4592
4701
|
response.end();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tab's own data-catalog tree (168px): 全部 / 收藏 / 置顶 + one row per catalog.
|
|
3
|
+
*
|
|
4
|
+
* The portal page inside the iframe is the product's card list and detail view; the host
|
|
5
|
+
* sidebar owns the tree and only sends the active filter to that page, so the portal never
|
|
6
|
+
* renders its own left column in embed mode.
|
|
7
|
+
*
|
|
8
|
+
* @module client/ResourceCatalogSidebar
|
|
9
|
+
*/
|
|
10
|
+
export interface ResourceFilter {
|
|
11
|
+
scope: 'all' | 'favorites' | 'pinned' | 'catalog';
|
|
12
|
+
catalog?: string;
|
|
13
|
+
ids?: number[];
|
|
14
|
+
}
|
|
15
|
+
export declare function ResourceCatalogSidebar({ onFilter }: {
|
|
16
|
+
onFilter: (filter: ResourceFilter) => void;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native resource page for the cross-origin right-sidebar tab.
|
|
3
|
+
*
|
|
4
|
+
* The card, badge and button geometry mirrors the portal's `/embed/resources` page
|
|
5
|
+
* (`DataOpsResourcesEmbedPage.vue`) so the tab keeps the product's existing look; only the
|
|
6
|
+
* data path changes (Host bridge instead of a portal iframe). The left column is the data
|
|
7
|
+
* catalog the product asks for: 全部 / 收藏 / 置顶 plus one row per catalog.
|
|
8
|
+
*
|
|
9
|
+
* @module client/ResourceListPanel
|
|
10
|
+
*/
|
|
11
|
+
/** One resource row as `/api/resources` returns it. */
|
|
12
|
+
interface ResourceRow {
|
|
13
|
+
id: number;
|
|
14
|
+
urn?: string;
|
|
15
|
+
resourceType?: string;
|
|
16
|
+
chineseName?: string;
|
|
17
|
+
sourceSystem?: string;
|
|
18
|
+
sourceTable?: string;
|
|
19
|
+
sourceDept?: string;
|
|
20
|
+
rowCount?: number | null;
|
|
21
|
+
columnCount?: number;
|
|
22
|
+
accessLevel?: string;
|
|
23
|
+
aiVisible?: boolean;
|
|
24
|
+
catalog?: string;
|
|
25
|
+
remark?: string;
|
|
26
|
+
tags?: string[];
|
|
27
|
+
columns?: Array<{
|
|
28
|
+
name?: string;
|
|
29
|
+
chineseName?: string;
|
|
30
|
+
dataType?: string;
|
|
31
|
+
type?: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/** Card grid + data catalog sidebar. */
|
|
35
|
+
export declare function ResourceListPanel({ initialResourceId, portalBaseUrl, onInsertReference, }: {
|
|
36
|
+
initialResourceId?: number;
|
|
37
|
+
portalBaseUrl: string;
|
|
38
|
+
onInsertReference?: (resource: ResourceRow) => void;
|
|
39
|
+
}): import("react").JSX.Element;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「数据资源」tab 的图标。
|
|
3
|
+
*
|
|
4
|
+
* 以**组件函数**形式提供:sidebar 的 tab 图标契约是
|
|
5
|
+
* `typeof descriptor.icon === 'function' ? descriptor.icon(14) : descriptor.icon`,
|
|
6
|
+
* 传函数可以让 sidebar 自己决定尺寸。用 JSX 而不是 createElement,是为了和同仓
|
|
7
|
+
* 其它插件走同一套 React 运行时(跨运行时创建的元素不会被渲染)。
|
|
8
|
+
*/
|
|
9
|
+
export declare function ResourceTabIcon({ size }: {
|
|
10
|
+
size?: number;
|
|
11
|
+
}): React.ReactElement;
|
|
@@ -103,6 +103,8 @@ export declare const en: {
|
|
|
103
103
|
readonly permWaiting: "The permission-centre API is waiting for the backend (task-37).";
|
|
104
104
|
readonly permResourceSkill: "Skill";
|
|
105
105
|
readonly permResourceWorkflow: "Workflow";
|
|
106
|
+
readonly permResourceBuiltin: "Built-in skill";
|
|
107
|
+
readonly permUnshared: "Not shared";
|
|
106
108
|
readonly permResourceKb: "Knowledge base";
|
|
107
109
|
readonly permType: "Type";
|
|
108
110
|
readonly permName: "Name";
|
|
@@ -69,16 +69,18 @@ export interface DepartmentRow {
|
|
|
69
69
|
enabled?: boolean;
|
|
70
70
|
updatedAt?: string;
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
72
|
+
/** A resource scope value; `unshared` only applies to a platform built-in skill. */
|
|
73
|
+
export type ResourceScopeVisibility = ResourceVisibility | 'unshared';
|
|
74
|
+
/** One plaza skill/workflow or platform built-in skill and its visibility scope. */
|
|
73
75
|
export interface ResourceScopeRow {
|
|
74
|
-
kind: 'skill' | 'workflow';
|
|
76
|
+
kind: 'skill' | 'workflow' | 'builtin';
|
|
75
77
|
id: string | number;
|
|
76
78
|
name: string;
|
|
77
|
-
ownerId?: string;
|
|
78
|
-
ownerName?: string;
|
|
79
|
+
ownerId?: string | null;
|
|
80
|
+
ownerName?: string | null;
|
|
79
81
|
departmentCode?: string | null;
|
|
80
|
-
visibility:
|
|
81
|
-
reviewStatus?: ReviewStatus;
|
|
82
|
+
visibility: ResourceScopeVisibility;
|
|
83
|
+
reviewStatus?: ReviewStatus | 'unshared';
|
|
82
84
|
updatedAt?: string;
|
|
83
85
|
}
|
|
84
86
|
/** Everything the permission centre renders in one read. */
|
|
@@ -77,6 +77,26 @@ export interface ReviewableSummary {
|
|
|
77
77
|
export declare function normalizeReviewStatus(value: unknown): ReviewStatus;
|
|
78
78
|
/** Treat a missing visibility as global: a shared row with no scope was visible to everyone. */
|
|
79
79
|
export declare function normalizeVisibility(value: unknown): ResourceVisibility;
|
|
80
|
+
/** The resource-scope facts the permission centre needs to decide button availability. */
|
|
81
|
+
export interface ResourceScopeSubject {
|
|
82
|
+
kind: 'skill' | 'workflow' | 'builtin';
|
|
83
|
+
visibility: 'global' | 'department' | 'private' | 'unshared';
|
|
84
|
+
departmentCode?: string | null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether this actor may edit one resource-scope row.
|
|
88
|
+
*
|
|
89
|
+
* Mirrors the backend policy: built-in skills are super-administrator only, global skills
|
|
90
|
+
* belong to administrators, and a department administrator edits department rows in their
|
|
91
|
+
* subtree (the list itself is already narrowed to that subtree).
|
|
92
|
+
* @param subject - the row's kind and current scope.
|
|
93
|
+
* @param actorRole - the caller's portal role.
|
|
94
|
+
* @returns the decision and, when denied, the reason shown on the disabled control.
|
|
95
|
+
*/
|
|
96
|
+
export declare function canEditResourceScopeRow(subject: ResourceScopeSubject, actorRole: PortalRole): {
|
|
97
|
+
allowed: boolean;
|
|
98
|
+
reason?: string;
|
|
99
|
+
};
|
|
80
100
|
/** Whether the caller may see and act on the review queue. */
|
|
81
101
|
export declare function canReview(context: ReviewContext | null | undefined): boolean;
|
|
82
102
|
/** Whether the caller may open the permission centre's write controls. */
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataOps resource-management transport: pending approval tasks, existing access grants,
|
|
3
|
-
* batch grant/revoke, and approval decisions. Disclosure is handled by tool-scope; this file
|
|
4
|
-
* only speaks to the existing DataOps APIs.
|
|
5
|
-
*/
|
|
6
1
|
import type { ReviewApi } from './review-api.ts';
|
|
7
2
|
export type ResourceGrantTargetType = 'USER' | 'ROLE' | 'DEPARTMENT' | 'APPLICATION';
|
|
8
3
|
export type ResourceGrantPermission = 'READ' | 'WRITE' | 'MANAGE';
|
|
@@ -20,6 +15,8 @@ export interface PendingTaskDecision {
|
|
|
20
15
|
decision: 'approve' | 'reject';
|
|
21
16
|
comment?: string;
|
|
22
17
|
expectedVersion?: number;
|
|
18
|
+
/** Optional replay key; omit for a fresh generated key. */
|
|
19
|
+
idempotencyKey?: string;
|
|
23
20
|
}
|
|
24
21
|
/** Thin typed wrapper over the existing DataOps REST endpoints. */
|
|
25
22
|
export declare class ResourceManagementApi {
|
package/package.json
CHANGED