@southwind-ai/shared 0.2.8 → 0.3.0

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
@@ -23,7 +23,6 @@ export * from "./src/platform-settings.js";
23
23
  export * from "./src/profile.js";
24
24
  export * from "./src/primitives.js";
25
25
  export * from "./src/rbac.js";
26
- export * from "./src/ruoyi.js";
27
26
  export * from "./src/scheduler.js";
28
27
  export * from "./src/search-provider.js";
29
28
  // @windy-module system.agent begin
@@ -31,3 +30,5 @@ export * from "./src/screenshot-context-digest.js";
31
30
  // @windy-module system.agent end
32
31
  export * from "./src/stable-key.js";
33
32
  export * from "./src/workflow.js";
33
+
34
+ export * from "./src/license-console-capabilities.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@southwind-ai/shared",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -0,0 +1,163 @@
1
+ import type { LicenseOperatorPermission } from "./license.js";
2
+
3
+ /** 厂商签发中心独立认证域;不装配到客户 system.license。 */
4
+ export const LICENSE_CONSOLE_CAPABILITIES = {
5
+ records: {
6
+ feature: "license.record",
7
+ permission: "license.record.read",
8
+ entry: "records",
9
+ apis: [
10
+ "GET /api/licenses",
11
+ "GET /api/licenses/:id",
12
+ "GET /api/licenses/:id/download",
13
+ "GET /api/licenses/:id/activation-code",
14
+ "GET /api/licenses/:id/events",
15
+ "GET /api/events",
16
+ "GET /api/customers",
17
+ "GET /api/customers/:id",
18
+ "GET /api/projects",
19
+ "GET /api/projects/:id",
20
+ "GET /api/contracts",
21
+ "GET /api/contracts/:id",
22
+ "GET /api/license-versions",
23
+ "GET /api/license-versions/:id",
24
+ "GET /api/nodes",
25
+ "GET /api/nodes/:id",
26
+ "GET /api/keys/active",
27
+ "GET /api/projects/:projectId/contracts",
28
+ "GET /api/projects/:projectId/nodes",
29
+ "GET /api/projects/:projectId/license-versions",
30
+ "GET /api/projects/:projectId/licenses",
31
+ "GET /api/keys",
32
+ "GET /api/signing/diagnostics",
33
+ ],
34
+ auditActions: ["license.downloaded"],
35
+ },
36
+ projects: {
37
+ feature: "license.project",
38
+ permission: "license.project.manage",
39
+ entry: "maintenance",
40
+ apis: [
41
+ "POST /api/customers",
42
+ "POST /api/projects",
43
+ "POST /api/contracts",
44
+ "POST /api/license-versions",
45
+ "POST /api/nodes",
46
+ "PATCH /api/customers/:id",
47
+ "PATCH /api/projects/:id",
48
+ "PATCH /api/contracts/:id",
49
+ "PATCH /api/license-versions/:id",
50
+ "PATCH /api/nodes/:id",
51
+ "PATCH /api/customers/:id/archive",
52
+ "PATCH /api/projects/:id/archive",
53
+ "PATCH /api/contracts/:id/archive",
54
+ "PATCH /api/license-versions/:id/archive",
55
+ "PATCH /api/nodes/:id/archive",
56
+ ],
57
+ auditActions: ["crud.create", "crud.update"],
58
+ },
59
+ issuance: {
60
+ feature: "license.issue",
61
+ permission: "license.issue",
62
+ entry: "project-issuance",
63
+ apis: [
64
+ "POST /api/projects/:projectId/licenses",
65
+ "POST /api/projects/:projectId/license-review",
66
+ "GET /api/projects/:projectId/issuance-requests/:key",
67
+ "POST /api/licenses",
68
+ "POST /api/licenses/:id/revocation-marks",
69
+ "POST /api/licenses/:id/note-corrections",
70
+ ],
71
+ auditActions: [
72
+ "license.issued",
73
+ "license.replaced",
74
+ "license.superseded",
75
+ "license.revocation-marked",
76
+ "license.note-corrected",
77
+ ],
78
+ },
79
+ keys: {
80
+ feature: "license.key",
81
+ permission: "license.key.rotate",
82
+ entry: "operations",
83
+ apis: ["POST /api/keys/rotate", "POST /api/keys/:keyId/compatibility"],
84
+ auditActions: ["license.key.rotated", "license.key.compatibility-declared"],
85
+ },
86
+ operators: {
87
+ feature: "license.operator",
88
+ permission: "license.operator.manage",
89
+ entry: "administration",
90
+ apis: [
91
+ "GET /api/operators",
92
+ "POST /api/operators",
93
+ "PATCH /api/operators/:id",
94
+ ],
95
+ auditActions: ["license.operator.created", "license.operator.updated"],
96
+ },
97
+ sessions: {
98
+ feature: "license.session",
99
+ permission: "license.session.revoke",
100
+ entry: "administration",
101
+ apis: ["POST /api/auth/sessions/:id/revoke"],
102
+ auditActions: ["auth.session.revoke"],
103
+ },
104
+ audit: {
105
+ feature: "license.audit",
106
+ permission: "license.audit.read",
107
+ entry: "administration",
108
+ apis: ["GET /api/audit-logs"],
109
+ auditActions: [],
110
+ },
111
+ } as const satisfies Record<
112
+ string,
113
+ {
114
+ feature: string;
115
+ permission: LicenseOperatorPermission;
116
+ entry: string;
117
+ apis: readonly string[];
118
+ auditActions: readonly string[];
119
+ }
120
+ >;
121
+
122
+ export interface LicenseConsoleCapability {
123
+ feature: string;
124
+ permission: LicenseOperatorPermission;
125
+ entry: string;
126
+ apis: readonly string[];
127
+ auditActions: readonly string[];
128
+ }
129
+ export function validateLicenseConsoleCapabilities(
130
+ items: readonly LicenseConsoleCapability[] = Object.values(
131
+ LICENSE_CONSOLE_CAPABILITIES,
132
+ ),
133
+ ): void {
134
+ const features = new Set<string>();
135
+ const permissions = new Set<string>();
136
+ const apis = new Set<string>();
137
+ for (const item of items) {
138
+ if (features.has(item.feature) || permissions.has(item.permission))
139
+ throw new Error("签发中心能力声明重复");
140
+ if (
141
+ item.permission !== item.feature &&
142
+ !item.permission.startsWith(`${item.feature}.`)
143
+ )
144
+ throw new Error("签发中心权限基础 Key 不匹配");
145
+ features.add(item.feature);
146
+ permissions.add(item.permission);
147
+ for (const api of item.apis) {
148
+ if (apis.has(api)) throw new Error("签发中心 API 声明重复");
149
+ apis.add(api);
150
+ }
151
+ }
152
+ }
153
+
154
+ export function hasLicenseConsolePermission(
155
+ permissions: readonly string[],
156
+ permission: string,
157
+ ): boolean {
158
+ return (
159
+ Object.values(LICENSE_CONSOLE_CAPABILITIES).some(
160
+ (item) => item.permission === permission,
161
+ ) && permissions.includes(permission)
162
+ );
163
+ }
@@ -0,0 +1,94 @@
1
+ import type {
2
+ LicenseContractVersion,
3
+ LicenseCustomer,
4
+ LicenseIssueRecord,
5
+ LicenseNode,
6
+ LicenseProject,
7
+ LicenseReplacement,
8
+ LicenseV1Claims,
9
+ LicenseVersion,
10
+ } from "./license.js";
11
+
12
+ export interface LicenseIssueSummary {
13
+ id: string;
14
+ customerId: string;
15
+ projectId: string;
16
+ contractVersionId: string;
17
+ nodeId: string;
18
+ operatorId: string;
19
+ claims: LicenseV1Claims;
20
+ targetSoftwareVersion?: string;
21
+ predecessor?: LicenseReplacement;
22
+ successor?: LicenseReplacement;
23
+ revocationMarked: boolean;
24
+ }
25
+ export interface LicenseConsoleCollections {
26
+ customers: LicenseCustomer;
27
+ projects: LicenseProject;
28
+ contracts: LicenseContractVersion;
29
+ nodes: LicenseNode;
30
+ "license-versions": LicenseVersion;
31
+ licenses: LicenseIssueSummary;
32
+ }
33
+ export interface LicenseListQuery {
34
+ page: number;
35
+ pageSize: number;
36
+ q?: string;
37
+ customerId?: string;
38
+ projectId?: string;
39
+ status?: string;
40
+ contractVersionId?: string;
41
+ nodeId?: string;
42
+ machineCode?: string;
43
+ licenseVersionKey?: string;
44
+ issuedFrom?: string;
45
+ issuedTo?: string;
46
+ expiresFrom?: string;
47
+ expiresTo?: string;
48
+ expiresWithinDays?: 7 | 30 | 60;
49
+ }
50
+ export interface LicensePage<T> {
51
+ items: T[];
52
+ total: number;
53
+ page: number;
54
+ pageSize: number;
55
+ }
56
+ export interface LicenseNewNode {
57
+ code: string;
58
+ name: string;
59
+ purpose?: string;
60
+ machineCode: string;
61
+ }
62
+ export interface LicenseReviewCommand {
63
+ contractVersionId: string;
64
+ nodeId?: string;
65
+ newNode?: LicenseNewNode;
66
+ expiresAt: string;
67
+ softwareVersion: string;
68
+ replacementOfLicenseId?: string;
69
+ replacementReason?: string;
70
+ }
71
+ export interface LicenseReviewConfirmation {
72
+ customer: LicenseCustomer;
73
+ project: LicenseProject;
74
+ contract: LicenseContractVersion;
75
+ licenseVersion: LicenseVersion;
76
+ node: LicenseNewNode;
77
+ keyId: string;
78
+ expiresAt: string;
79
+ softwareVersion: string;
80
+ replacementOfLicenseId?: string;
81
+ replacementReason?: string;
82
+ }
83
+ export interface LicenseReviewResult {
84
+ reviewDigest: string;
85
+ confirmation: LicenseReviewConfirmation;
86
+ blockingReasons: string[];
87
+ }
88
+ export interface LicenseRequestStatus {
89
+ status: "processing" | "failed" | "completed";
90
+ licenseId: string;
91
+ result?: LicenseIssueRecord;
92
+ error?: { code: string; reason: string };
93
+ retryAfterSeconds?: number;
94
+ }
package/src/license.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { EntityId, ISODateTime } from "./primitives.js";
2
2
 
3
3
  export * from "./license-legacy.js";
4
+ export * from "./license-console.js";
4
5
 
5
6
  declare const entitlementKeyBrand: unique symbol;
6
7
  declare const licenseVersionKeyBrand: unique symbol;
@@ -132,6 +133,8 @@ export interface LicenseProject {
132
133
  }
133
134
 
134
135
  export interface LicenseContractVersion {
136
+ predecessorId?: EntityId;
137
+ issuedCount?: number;
135
138
  id: EntityId;
136
139
  projectId: EntityId;
137
140
  contractNumber: string;
@@ -147,6 +150,7 @@ export interface LicenseContractVersion {
147
150
  }
148
151
 
149
152
  export interface LicenseNode {
153
+ issuedCount?: number;
150
154
  id: EntityId;
151
155
  projectId: EntityId;
152
156
  code: string;
@@ -200,6 +204,7 @@ export type LicenseOperatorRole =
200
204
 
201
205
  export type LicenseOperatorPermission =
202
206
  | "license.record.read"
207
+ | "license.audit.read"
203
208
  | "license.issue"
204
209
  | "license.project.manage"
205
210
  | "license.key.rotate"
package/src/ruoyi.ts DELETED
@@ -1,98 +0,0 @@
1
- import type { AuditEvent, AuditLogWriter } from "./audit.js";
2
- import type { LegacyTableMapping } from "./database.js";
3
- import type { EntityId, ISODateTime } from "./primitives.js";
4
- import type {
5
- MenuNode,
6
- PermissionDefinition,
7
- RoleDefinition,
8
- UserAccount,
9
- } from "./rbac.js";
10
-
11
- export type RuoYiCoreTable =
12
- | "sys_user"
13
- | "sys_role"
14
- | "sys_user_role"
15
- | "sys_dept"
16
- | "sys_post"
17
- | "sys_user_post"
18
- | "sys_menu"
19
- | "sys_role_menu"
20
- | "sys_role_dept"
21
- | "sys_dict_type"
22
- | "sys_dict_data"
23
- | "sys_config"
24
- | "sys_notice"
25
- | "sys_logininfor"
26
- | "sys_oper_log"
27
- | "sys_job"
28
- | "sys_job_log";
29
-
30
- export interface RuoYiConnectionConfig {
31
- mysqlDsn: string;
32
- redisDsn?: string;
33
- readonly: boolean;
34
- }
35
-
36
- export interface RuoYiMigrationPlan {
37
- id: EntityId;
38
- createdAt: ISODateTime;
39
- tables: RuoYiCoreTable[];
40
- dryRun: boolean;
41
- resetPasswords: boolean;
42
- }
43
-
44
- export interface RuoYiMigrationReport {
45
- planId: EntityId;
46
- startedAt: ISODateTime;
47
- finishedAt?: ISODateTime;
48
- importedRows: Record<RuoYiCoreTable, number>;
49
- failedRows: Record<RuoYiCoreTable, number>;
50
- warnings: string[];
51
- auditEvents: AuditEvent[];
52
- }
53
-
54
- export interface RuoYiPermissionSnapshot {
55
- user: UserAccount;
56
- roles: RoleDefinition[];
57
- menus: MenuNode[];
58
- permissions: PermissionDefinition[];
59
- }
60
-
61
- export interface RuoYiImportAdapter {
62
- dryRun(plan: RuoYiMigrationPlan): Promise<RuoYiMigrationReport>;
63
- import(
64
- plan: RuoYiMigrationPlan,
65
- audit: AuditLogWriter,
66
- ): Promise<RuoYiMigrationReport>;
67
- }
68
-
69
- export interface RuoYiLegacyRuntimeAdapter {
70
- connect(config: RuoYiConnectionConfig): Promise<void>;
71
- disconnect(): Promise<void>;
72
- readPermissionSnapshot(userId: EntityId): Promise<RuoYiPermissionSnapshot>;
73
- }
74
-
75
- export interface RuoYiReportAdapter {
76
- compareUserPermissions(userId: EntityId): Promise<RuoYiMigrationReport>;
77
- tableMappings(): LegacyTableMapping[];
78
- }
79
-
80
- export const ruoyiCoreTables: RuoYiCoreTable[] = [
81
- "sys_user",
82
- "sys_role",
83
- "sys_user_role",
84
- "sys_dept",
85
- "sys_post",
86
- "sys_user_post",
87
- "sys_menu",
88
- "sys_role_menu",
89
- "sys_role_dept",
90
- "sys_dict_type",
91
- "sys_dict_data",
92
- "sys_config",
93
- "sys_notice",
94
- "sys_logininfor",
95
- "sys_oper_log",
96
- "sys_job",
97
- "sys_job_log",
98
- ];