@haneinfo/state-machine 0.9.0 → 0.11.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/README.md +58 -0
- package/agent-guide.md +58 -0
- package/dist/access.d.ts +28 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +21 -0
- package/dist/access.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/instance-access.controller.d.ts +25 -0
- package/dist/instance-access.controller.d.ts.map +1 -0
- package/dist/instance-access.controller.js +67 -0
- package/dist/instance-access.controller.js.map +1 -0
- package/dist/instance-access.service.d.ts +54 -0
- package/dist/instance-access.service.d.ts.map +1 -0
- package/dist/instance-access.service.js +210 -0
- package/dist/instance-access.service.js.map +1 -0
- package/dist/mcp-tools.d.ts +3 -1
- package/dist/mcp-tools.d.ts.map +1 -1
- package/dist/mcp-tools.js +37 -2
- package/dist/mcp-tools.js.map +1 -1
- package/dist/plugin.d.ts +2 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +5 -2
- package/dist/plugin.js.map +1 -1
- package/dist/prisma-store.d.ts.map +1 -1
- package/dist/prisma-store.js +52 -11
- package/dist/prisma-store.js.map +1 -1
- package/dist/reader-grants.d.ts +1 -1
- package/dist/reader-grants.d.ts.map +1 -1
- package/dist/reader-grants.js +4 -2
- package/dist/reader-grants.js.map +1 -1
- package/dist/runtime.service.d.ts +1 -0
- package/dist/runtime.service.d.ts.map +1 -1
- package/dist/runtime.service.js +26 -25
- package/dist/runtime.service.js.map +1 -1
- package/dist/state-machine.module.d.ts.map +1 -1
- package/dist/state-machine.module.js +5 -1
- package/dist/state-machine.module.js.map +1 -1
- package/dist/store.d.ts +9 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +42 -8
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/haneinfo.plugin.json +8 -3
- package/package.json +7 -7
- package/prisma/instance-access.sql +50 -0
- package/prisma/state-machine.prisma +13 -9
package/README.md
CHANGED
|
@@ -56,3 +56,61 @@ exclusive lock on the same key. Normal instance transactions remain concurrent;
|
|
|
56
56
|
briefly blocks new instance writers until its backfill/cancellation commits. This closes the race
|
|
57
57
|
where creation and state entry could otherwise miss each other's uncommitted rows. The advisory lock always precedes instance locks; task CAS and delegation-row shared locks
|
|
58
58
|
remain inside that transaction. No extra table or worker is added.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Instance access lists (draft implementation)
|
|
62
|
+
|
|
63
|
+
Implemented against draft decision 202610-c8e3; the decision remains draft. This section supersedes
|
|
64
|
+
the earlier reader-only model and human transition eligibility. Upgrade the affected
|
|
65
|
+
mechanisms together and apply the App migration before starting the new runtime. The maintainer
|
|
66
|
+
selected source-specific uniqueness: `(instanceId, principalType, principalId, source)`. Existing
|
|
67
|
+
model/table names are retained. `principalType` is USER or ROLE; `principalId` is a user id or role
|
|
68
|
+
machine name; `level` is READ or WRITE; `source` is ASSIGNED, DELEGATED or GRANTED. Each row also
|
|
69
|
+
has nullable grantedBy and createdAt. Indexes cover instanceId and (principalType, principalId).
|
|
70
|
+
Permanent ASSIGNED/DELEGATED entries are READ and survive every task/delegation status. Manual
|
|
71
|
+
GRANTED entries coexist with them; removing GRANTED never removes permanent readership.
|
|
72
|
+
|
|
73
|
+
All instance reads use submitter, effective state-machine:instance:read, or a matching USER/ROLE
|
|
74
|
+
entry. Roles come from RBAC authorizationOfUser once per query, passed into persistence; no direct
|
|
75
|
+
RBAC-table joins. WRITE also requires an existing readable instance, then submitter, effective
|
|
76
|
+
state-machine:instance:write, or matching WRITE. Human transitions still check their declared
|
|
77
|
+
business permission. Assignment/Timer transition authorization is unchanged. Unreadable instances
|
|
78
|
+
return INSTANCE_NOT_FOUND/404; readable callers without write/manage eligibility receive 403.
|
|
79
|
+
|
|
80
|
+
Only the submitter or state-machine:instance:admin can manage access; instance administrators can
|
|
81
|
+
manage any instance list. Grantees cannot regrant. InteractiveAuthGuard protects GET/PUT
|
|
82
|
+
/state-machine-instances/:id/access and DELETE /state-machine-instances/:id/access/:principalType/:principalId.
|
|
83
|
+
PUT targets GRANTED only, never changes permanent rows. DELETE removes GRANTED if present; a
|
|
84
|
+
permanent-only target returns ACCESS_NOT_MANAGEABLE/409. Missing manual targets are idempotent.
|
|
85
|
+
GET returns sources, levels, principalName and grantedByName; user names share one authorized
|
|
86
|
+
findActiveNamesByIds batch, role display labels share one RBAC lookup, unavailable names are null.
|
|
87
|
+
Names are plain text. maxGrantedAccess defaults to 100. Only active users or existing roles can be
|
|
88
|
+
granted; the submitter cannot receive a USER grant. Errors include ACCESS_PRINCIPAL_INVALID/400,
|
|
89
|
+
ACCESS_LIMIT_EXCEEDED/409 and ACCESS_NOT_MANAGEABLE/409. Repeated equal grants have no effects.
|
|
90
|
+
|
|
91
|
+
StateMachineMcpTools.registerInto now also registers list_instance_access using <namespace>:instance:read.
|
|
92
|
+
It returns items in $userContent and offers no grant/remove tools. Changed individual grants notify
|
|
93
|
+
with state-machine-access:<historyId>; equal retries do not notify again. Role grants and removals
|
|
94
|
+
never notify. Missing inbox capability skips delivery. Actual inbox failures roll back the mutation.
|
|
95
|
+
ACCESS history uses the existing decision JSON and emits state-machine.access.recorded in the
|
|
96
|
+
same transaction; collaboration adds ACCESS to its existing SQL timeline union. State, revision and
|
|
97
|
+
transition events do not change for access mutations. List/export counts and pagination include
|
|
98
|
+
personal and role access in one parameterized EXISTS; snapshot exports abort on role-name changes.
|
|
99
|
+
|
|
100
|
+
Migration SQL ships at @haneinfo/state-machine/prisma/instance-access.sql. It renames user_id to
|
|
101
|
+
principal_id and reason to source, preserves created_at, adds principal_type/level/granted_by,
|
|
102
|
+
converts legacy rows to USER/READ and ASSIGNED (recognized delegation becomes DELEGATED), and
|
|
103
|
+
backfills every assignment task regardless of status. It expects the Assignment delegation columns;
|
|
104
|
+
Apps without Assignment/Delegation must omit the corresponding task queries/backfill. Do not reset
|
|
105
|
+
an existing database. See the package repository validation/equipment-loan/instance-access/report.md
|
|
106
|
+
for adoption evidence and the explicitly selected uniqueness adjustment; no decision text is changed.
|
|
107
|
+
|
|
108
|
+
Configure runtime.stateMachine.maxGrantedAccess (positive integer, default 100). Apply prisma/instance-access.sql in your App migration before upgrading. Custom StateMachineStore implementations must implement listAccess, putGranted and deleteGranted and accept optional roles/source/level in reader methods. The new optional RBAC role-label lookup requires plugin API 1.14.0.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## Access management eligibility (draft 202610-e2a9)
|
|
112
|
+
|
|
113
|
+
GET /state-machine-instances/:id/access adds canManage: boolean alongside the unchanged items.
|
|
114
|
+
The service shares its submitter/instance-admin eligibility calculation with PUT/DELETE; readers
|
|
115
|
+
can inspect but cannot regrant access. list_instance_access adds the same canManage next to its
|
|
116
|
+
existing wrapped items. It remains read-only. No database or plugin-api contract changes apply.
|
package/agent-guide.md
CHANGED
|
@@ -296,3 +296,61 @@ exclusive lock on the same key. Normal instance transactions remain concurrent;
|
|
|
296
296
|
briefly blocks new instance writers until its backfill/cancellation commits. This closes the race
|
|
297
297
|
where creation and state entry could otherwise miss each other's uncommitted rows. The advisory lock always precedes instance locks; task CAS and delegation-row shared locks
|
|
298
298
|
remain inside that transaction. No extra table or worker is added.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
## Instance access lists (draft implementation)
|
|
302
|
+
|
|
303
|
+
Implemented against draft decision 202610-c8e3; the decision remains draft. This section supersedes
|
|
304
|
+
the earlier reader-only model and human transition eligibility. Upgrade the affected
|
|
305
|
+
mechanisms together and apply the App migration before starting the new runtime. The maintainer
|
|
306
|
+
selected source-specific uniqueness: `(instanceId, principalType, principalId, source)`. Existing
|
|
307
|
+
model/table names are retained. `principalType` is USER or ROLE; `principalId` is a user id or role
|
|
308
|
+
machine name; `level` is READ or WRITE; `source` is ASSIGNED, DELEGATED or GRANTED. Each row also
|
|
309
|
+
has nullable grantedBy and createdAt. Indexes cover instanceId and (principalType, principalId).
|
|
310
|
+
Permanent ASSIGNED/DELEGATED entries are READ and survive every task/delegation status. Manual
|
|
311
|
+
GRANTED entries coexist with them; removing GRANTED never removes permanent readership.
|
|
312
|
+
|
|
313
|
+
All instance reads use submitter, effective state-machine:instance:read, or a matching USER/ROLE
|
|
314
|
+
entry. Roles come from RBAC authorizationOfUser once per query, passed into persistence; no direct
|
|
315
|
+
RBAC-table joins. WRITE also requires an existing readable instance, then submitter, effective
|
|
316
|
+
state-machine:instance:write, or matching WRITE. Human transitions still check their declared
|
|
317
|
+
business permission. Assignment/Timer transition authorization is unchanged. Unreadable instances
|
|
318
|
+
return INSTANCE_NOT_FOUND/404; readable callers without write/manage eligibility receive 403.
|
|
319
|
+
|
|
320
|
+
Only the submitter or state-machine:instance:admin can manage access; instance administrators can
|
|
321
|
+
manage any instance list. Grantees cannot regrant. InteractiveAuthGuard protects GET/PUT
|
|
322
|
+
/state-machine-instances/:id/access and DELETE /state-machine-instances/:id/access/:principalType/:principalId.
|
|
323
|
+
PUT targets GRANTED only, never changes permanent rows. DELETE removes GRANTED if present; a
|
|
324
|
+
permanent-only target returns ACCESS_NOT_MANAGEABLE/409. Missing manual targets are idempotent.
|
|
325
|
+
GET returns sources, levels, principalName and grantedByName; user names share one authorized
|
|
326
|
+
findActiveNamesByIds batch, role display labels share one RBAC lookup, unavailable names are null.
|
|
327
|
+
Names are plain text. maxGrantedAccess defaults to 100. Only active users or existing roles can be
|
|
328
|
+
granted; the submitter cannot receive a USER grant. Errors include ACCESS_PRINCIPAL_INVALID/400,
|
|
329
|
+
ACCESS_LIMIT_EXCEEDED/409 and ACCESS_NOT_MANAGEABLE/409. Repeated equal grants have no effects.
|
|
330
|
+
|
|
331
|
+
StateMachineMcpTools.registerInto now also registers list_instance_access using <namespace>:instance:read.
|
|
332
|
+
It returns items in $userContent and offers no grant/remove tools. Changed individual grants notify
|
|
333
|
+
with state-machine-access:<historyId>; equal retries do not notify again. Role grants and removals
|
|
334
|
+
never notify. Missing inbox capability skips delivery. Actual inbox failures roll back the mutation.
|
|
335
|
+
ACCESS history uses the existing decision JSON and emits state-machine.access.recorded in the
|
|
336
|
+
same transaction; collaboration adds ACCESS to its existing SQL timeline union. State, revision and
|
|
337
|
+
transition events do not change for access mutations. List/export counts and pagination include
|
|
338
|
+
personal and role access in one parameterized EXISTS; snapshot exports abort on role-name changes.
|
|
339
|
+
|
|
340
|
+
Migration SQL ships at @haneinfo/state-machine/prisma/instance-access.sql. It renames user_id to
|
|
341
|
+
principal_id and reason to source, preserves created_at, adds principal_type/level/granted_by,
|
|
342
|
+
converts legacy rows to USER/READ and ASSIGNED (recognized delegation becomes DELEGATED), and
|
|
343
|
+
backfills every assignment task regardless of status. It expects the Assignment delegation columns;
|
|
344
|
+
Apps without Assignment/Delegation must omit the corresponding task queries/backfill. Do not reset
|
|
345
|
+
an existing database. See the package repository validation/equipment-loan/instance-access/report.md
|
|
346
|
+
for adoption evidence and the explicitly selected uniqueness adjustment; no decision text is changed.
|
|
347
|
+
|
|
348
|
+
Configure runtime.stateMachine.maxGrantedAccess (positive integer, default 100). Apply prisma/instance-access.sql in your App migration before upgrading. Custom StateMachineStore implementations must implement listAccess, putGranted and deleteGranted and accept optional roles/source/level in reader methods. The new optional RBAC role-label lookup requires plugin API 1.14.0.
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
## Access panel eligibility (draft 202610-e2a9)
|
|
352
|
+
|
|
353
|
+
The access GET result now includes canManage, using the same submitter or effective instance:admin
|
|
354
|
+
calculation as mutations. Inaccessible instances still return INSTANCE_NOT_FOUND. The read-only
|
|
355
|
+
list_instance_access MCP result carries canManage outside the existing $userContent-wrapped items.
|
|
356
|
+
No new route, permission, table or MCP mutation is introduced.
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PrincipalAuthorization } from '@haneinfo/plugin-api';
|
|
2
|
+
import type { InstanceRecord, StateMachineStoreTx } from './store';
|
|
3
|
+
export type AccessPrincipalType = 'USER' | 'ROLE';
|
|
4
|
+
export type AccessLevel = 'READ' | 'WRITE';
|
|
5
|
+
export type AccessSource = 'ASSIGNED' | 'DELEGATED' | 'GRANTED';
|
|
6
|
+
export interface InstanceAccessRecord {
|
|
7
|
+
instanceId: string;
|
|
8
|
+
principalType: AccessPrincipalType;
|
|
9
|
+
principalId: string;
|
|
10
|
+
level: AccessLevel;
|
|
11
|
+
source: AccessSource;
|
|
12
|
+
grantedBy: string | null;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
}
|
|
15
|
+
/** Roles are resolved once by the caller, never by the persistence layer. */
|
|
16
|
+
export declare function instanceAccessAllowed(userId: string, record: InstanceRecord, authorization: PrincipalAuthorization, store: StateMachineStoreTx, level?: AccessLevel): Promise<boolean>;
|
|
17
|
+
export declare function accessPrincipalWhere(userId: string, roleNames?: readonly string[]): {
|
|
18
|
+
OR: ({
|
|
19
|
+
principalType: string;
|
|
20
|
+
principalId: string;
|
|
21
|
+
} | {
|
|
22
|
+
principalType: string;
|
|
23
|
+
principalId: {
|
|
24
|
+
in: string[];
|
|
25
|
+
};
|
|
26
|
+
})[];
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3C,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;AAChE,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,mBAAmB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,6EAA6E;AAC7E,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,EACtB,aAAa,EAAE,sBAAsB,EACrC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,GAAE,WAAoB,oBAQ5B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAS,MAAM,EAAO;;;;;;;;;;EAOrF"}
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instanceAccessAllowed = instanceAccessAllowed;
|
|
4
|
+
exports.accessPrincipalWhere = accessPrincipalWhere;
|
|
5
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
6
|
+
/** Roles are resolved once by the caller, never by the persistence layer. */
|
|
7
|
+
async function instanceAccessAllowed(userId, record, authorization, store, level = 'READ') {
|
|
8
|
+
return Boolean(userId &&
|
|
9
|
+
(record.submitterId === userId ||
|
|
10
|
+
(0, plugin_api_1.hasPermission)(authorization, `state-machine:instance:${level.toLowerCase()}`) ||
|
|
11
|
+
(await store.isReader(record.id, userId, authorization.roleNames, level))));
|
|
12
|
+
}
|
|
13
|
+
function accessPrincipalWhere(userId, roleNames = []) {
|
|
14
|
+
return {
|
|
15
|
+
OR: [
|
|
16
|
+
{ principalType: 'USER', principalId: userId },
|
|
17
|
+
{ principalType: 'ROLE', principalId: { in: [...roleNames] } },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":";;AAiBA,sDAaC;AAED,oDAOC;AAvCD,qDAAkF;AAgBlF,6EAA6E;AACtE,KAAK,UAAU,qBAAqB,CACzC,MAAc,EACd,MAAsB,EACtB,aAAqC,EACrC,KAA0B,EAC1B,QAAqB,MAAM;IAE3B,OAAO,OAAO,CACZ,MAAM;QACJ,CAAC,MAAM,CAAC,WAAW,KAAK,MAAM;YAC5B,IAAA,0BAAa,EAAC,aAAa,EAAE,0BAA0B,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YAC7E,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAC/E,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAc,EAAE,YAA+B,EAAE;IACpF,OAAO;QACL,EAAE,EAAE;YACF,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE;YAC9C,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE;SAC/D;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export * from './access';
|
|
2
|
+
export * from './instance-access.controller';
|
|
3
|
+
export * from './instance-access.service';
|
|
1
4
|
export { STATE_MACHINE_KIND, STATE_MACHINE_SCHEMA_VERSION, stateMachineDefinitionKind, stateMachineExample, stateMachineSpecSchema, } from './kind';
|
|
2
5
|
export * from './list-view-fields';
|
|
3
6
|
export { SIMULATE_TOOL_NAME, StateMachineMcpTools, } from './mcp-tools';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,QAAQ,CAAC;AAChB,cAAc,oBAAoB,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EACL,KAAK,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EACL,KAAK,aAAa,EAClB,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,oBAAoB,GAC1B,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,QAAQ,CAAC;AAChB,cAAc,oBAAoB,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EACL,KAAK,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EACL,KAAK,aAAa,EAClB,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,oBAAoB,GAC1B,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.initialStateOf = exports.STATE_MACHINE_STORE = exports.InMemoryStateMachineStore = exports.StateMachineModule = exports.StateMachineKindRegistration = exports.StateMachineController = exports.runHttp = exports.simulateStateMachine = exports.validateStateMachineSpec = exports.StateMachineRuntime = exports.STATE_MACHINE_CLOCK = exports.INSTANCE_WRITE_PERMISSION = exports.INSTANCE_READ_PERMISSION = exports.StateMachineReaderGrants = exports.PrismaStateMachineStore = exports.StateMachineMcpTools = exports.SIMULATE_TOOL_NAME = exports.stateMachineSpecSchema = exports.stateMachineExample = exports.stateMachineDefinitionKind = exports.STATE_MACHINE_SCHEMA_VERSION = exports.STATE_MACHINE_KIND = void 0;
|
|
18
|
+
__exportStar(require("./access"), exports);
|
|
19
|
+
__exportStar(require("./instance-access.controller"), exports);
|
|
20
|
+
__exportStar(require("./instance-access.service"), exports);
|
|
18
21
|
var kind_1 = require("./kind");
|
|
19
22
|
Object.defineProperty(exports, "STATE_MACHINE_KIND", { enumerable: true, get: function () { return kind_1.STATE_MACHINE_KIND; } });
|
|
20
23
|
Object.defineProperty(exports, "STATE_MACHINE_SCHEMA_VERSION", { enumerable: true, get: function () { return kind_1.STATE_MACHINE_SCHEMA_VERSION; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAMgB;AALd,0GAAA,kBAAkB,OAAA;AAClB,oHAAA,4BAA4B,OAAA;AAC5B,kHAAA,0BAA0B,OAAA;AAC1B,2GAAA,mBAAmB,OAAA;AACnB,8GAAA,sBAAsB,OAAA;AAExB,qDAAmC;AACnC,yCAGqB;AAFnB,+GAAA,kBAAkB,OAAA;AAClB,iHAAA,oBAAoB,OAAA;AAEtB,wDAAsC;AACtC,+CAAyD;AAAhD,uHAAA,uBAAuB,OAAA;AAChC,iDAA2D;AAAlD,yHAAA,wBAAwB,OAAA;AACjC,qDAM2B;AAJzB,2HAAA,wBAAwB,OAAA;AACxB,4HAAA,yBAAyB,OAAA;AACzB,sHAAA,mBAAmB,OAAA;AACnB,sHAAA,mBAAm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mB,OAAA;AAIrB,iCAMiB;AALf,uGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InteractivePrincipal } from '@haneinfo/plugin-api';
|
|
2
|
+
import { InstanceAccessService } from './instance-access.service';
|
|
3
|
+
export declare class InstanceAccessController {
|
|
4
|
+
private readonly access;
|
|
5
|
+
constructor(access: InstanceAccessService);
|
|
6
|
+
list(user: InteractivePrincipal, id: string): Promise<{
|
|
7
|
+
canManage: boolean;
|
|
8
|
+
items: {
|
|
9
|
+
principalName: string | null;
|
|
10
|
+
grantedByName: string | null;
|
|
11
|
+
instanceId: string;
|
|
12
|
+
principalType: import("./access").AccessPrincipalType;
|
|
13
|
+
principalId: string;
|
|
14
|
+
level: import("./access").AccessLevel;
|
|
15
|
+
source: import("./access").AccessSource;
|
|
16
|
+
grantedBy: string | null;
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
grant(user: InteractivePrincipal, id: string, body: unknown): Promise<import("./access").InstanceAccessRecord>;
|
|
21
|
+
remove(user: InteractivePrincipal, id: string, principalType: string, principalId: string): Promise<{
|
|
22
|
+
removed: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=instance-access.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-access.controller.d.ts","sourceRoot":"","sources":["../src/instance-access.controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,qBAEa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,qBAAqB;IAG1D,IAAI,CAAgB,IAAI,EAAE,oBAAoB,EAAe,EAAE,EAAE,MAAM;;;;;;;;;;;;;;IAKvE,KAAK,CAAgB,IAAI,EAAE,oBAAoB,EAAe,EAAE,EAAE,MAAM,EAAU,IAAI,EAAE,OAAO;IAK/F,MAAM,CACW,IAAI,EAAE,oBAAoB,EAC5B,EAAE,EAAE,MAAM,EACC,aAAa,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM;;;CAI5C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.InstanceAccessController = void 0;
|
|
16
|
+
const plugin_host_nest_1 = require("@haneinfo/plugin-host-nest");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const instance_access_service_1 = require("./instance-access.service");
|
|
19
|
+
const state_machine_controller_1 = require("./state-machine.controller");
|
|
20
|
+
let InstanceAccessController = class InstanceAccessController {
|
|
21
|
+
constructor(access) {
|
|
22
|
+
this.access = access;
|
|
23
|
+
}
|
|
24
|
+
list(user, id) {
|
|
25
|
+
return (0, state_machine_controller_1.runHttp)(() => this.access.listFor(user.sub, id));
|
|
26
|
+
}
|
|
27
|
+
grant(user, id, body) {
|
|
28
|
+
return (0, state_machine_controller_1.runHttp)(() => this.access.grantFor(user.sub, id, body));
|
|
29
|
+
}
|
|
30
|
+
remove(user, id, principalType, principalId) {
|
|
31
|
+
return (0, state_machine_controller_1.runHttp)(() => this.access.removeFor(user.sub, id, { principalType, principalId }));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.InstanceAccessController = InstanceAccessController;
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, common_1.Get)(),
|
|
37
|
+
__param(0, (0, plugin_host_nest_1.CurrentUser)()),
|
|
38
|
+
__param(1, (0, common_1.Param)('id')),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
41
|
+
__metadata("design:returntype", void 0)
|
|
42
|
+
], InstanceAccessController.prototype, "list", null);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, common_1.Put)(),
|
|
45
|
+
__param(0, (0, plugin_host_nest_1.CurrentUser)()),
|
|
46
|
+
__param(1, (0, common_1.Param)('id')),
|
|
47
|
+
__param(2, (0, common_1.Body)()),
|
|
48
|
+
__metadata("design:type", Function),
|
|
49
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
|
50
|
+
__metadata("design:returntype", void 0)
|
|
51
|
+
], InstanceAccessController.prototype, "grant", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, common_1.Delete)(':principalType/:principalId'),
|
|
54
|
+
__param(0, (0, plugin_host_nest_1.CurrentUser)()),
|
|
55
|
+
__param(1, (0, common_1.Param)('id')),
|
|
56
|
+
__param(2, (0, common_1.Param)('principalType')),
|
|
57
|
+
__param(3, (0, common_1.Param)('principalId')),
|
|
58
|
+
__metadata("design:type", Function),
|
|
59
|
+
__metadata("design:paramtypes", [Object, String, String, String]),
|
|
60
|
+
__metadata("design:returntype", void 0)
|
|
61
|
+
], InstanceAccessController.prototype, "remove", null);
|
|
62
|
+
exports.InstanceAccessController = InstanceAccessController = __decorate([
|
|
63
|
+
(0, common_1.Controller)('state-machine-instances/:id/access'),
|
|
64
|
+
(0, common_1.UseGuards)(plugin_host_nest_1.InteractiveAuthGuard),
|
|
65
|
+
__metadata("design:paramtypes", [instance_access_service_1.InstanceAccessService])
|
|
66
|
+
], InstanceAccessController);
|
|
67
|
+
//# sourceMappingURL=instance-access.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-access.controller.js","sourceRoot":"","sources":["../src/instance-access.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iEAA+E;AAC/E,2CAAsF;AACtF,uEAAkE;AAClE,yEAAqD;AAI9C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAA6B,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAG9D,IAAI,CAAgB,IAA0B,EAAe,EAAU;QACrE,OAAO,IAAA,kCAAO,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAGD,KAAK,CAAgB,IAA0B,EAAe,EAAU,EAAU,IAAa;QAC7F,OAAO,IAAA,kCAAO,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAGD,MAAM,CACW,IAA0B,EAC5B,EAAU,EACC,aAAqB,EACvB,WAAmB;QAEzC,OAAO,IAAA,kCAAO,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IAC5F,CAAC;CACF,CAAA;AAtBY,4DAAwB;AAInC;IADC,IAAA,YAAG,GAAE;IACA,WAAA,IAAA,8BAAW,GAAE,CAAA;IAA8B,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;oDAE3D;AAGD;IADC,IAAA,YAAG,GAAE;IACC,WAAA,IAAA,8BAAW,GAAE,CAAA;IAA8B,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;;;qDAEhF;AAGD;IADC,IAAA,eAAM,EAAC,6BAA6B,CAAC;IAEnC,WAAA,IAAA,8BAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,cAAK,EAAC,eAAe,CAAC,CAAA;IACtB,WAAA,IAAA,cAAK,EAAC,aAAa,CAAC,CAAA;;;;sDAGtB;mCArBU,wBAAwB;IAFpC,IAAA,mBAAU,EAAC,oCAAoC,CAAC;IAChD,IAAA,kBAAS,EAAC,uCAAoB,CAAC;qCAEO,+CAAqB;GAD/C,wBAAwB,CAsBpC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type IdentityStorePort, type NotificationInboxPort, type RbacPolicyPort } from '@haneinfo/plugin-api';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type Clock, StateMachineRuntime } from './runtime.service';
|
|
4
|
+
import { type StateMachineStore } from './store';
|
|
5
|
+
import type { StateMachineConfig } from './types';
|
|
6
|
+
export declare const INSTANCE_ADMIN_PERMISSION = "state-machine:instance:admin";
|
|
7
|
+
export declare const accessPrincipalSchema: z.ZodObject<{
|
|
8
|
+
principalType: z.ZodEnum<{
|
|
9
|
+
USER: "USER";
|
|
10
|
+
ROLE: "ROLE";
|
|
11
|
+
}>;
|
|
12
|
+
principalId: z.ZodString;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export declare const accessGrantSchema: z.ZodObject<{
|
|
15
|
+
principalType: z.ZodEnum<{
|
|
16
|
+
USER: "USER";
|
|
17
|
+
ROLE: "ROLE";
|
|
18
|
+
}>;
|
|
19
|
+
principalId: z.ZodString;
|
|
20
|
+
level: z.ZodEnum<{
|
|
21
|
+
READ: "READ";
|
|
22
|
+
WRITE: "WRITE";
|
|
23
|
+
}>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export declare class InstanceAccessService {
|
|
26
|
+
private readonly store;
|
|
27
|
+
private readonly runtime;
|
|
28
|
+
private readonly rbac?;
|
|
29
|
+
private readonly identity?;
|
|
30
|
+
private readonly inbox?;
|
|
31
|
+
private readonly config;
|
|
32
|
+
private readonly now;
|
|
33
|
+
constructor(store: StateMachineStore, runtime: StateMachineRuntime, rbac?: RbacPolicyPort | undefined, identity?: IdentityStorePort | undefined, inbox?: NotificationInboxPort | undefined, config?: StateMachineConfig, now?: Clock);
|
|
34
|
+
private authorized;
|
|
35
|
+
listFor(userId: string, id: string): Promise<{
|
|
36
|
+
canManage: boolean;
|
|
37
|
+
items: {
|
|
38
|
+
principalName: string | null;
|
|
39
|
+
grantedByName: string | null;
|
|
40
|
+
instanceId: string;
|
|
41
|
+
principalType: import("./access").AccessPrincipalType;
|
|
42
|
+
principalId: string;
|
|
43
|
+
level: import("./access").AccessLevel;
|
|
44
|
+
source: import("./access").AccessSource;
|
|
45
|
+
grantedBy: string | null;
|
|
46
|
+
createdAt: Date;
|
|
47
|
+
}[];
|
|
48
|
+
}>;
|
|
49
|
+
grantFor(userId: string, id: string, input: unknown): Promise<import("./access").InstanceAccessRecord>;
|
|
50
|
+
removeFor(userId: string, id: string, input: unknown): Promise<{
|
|
51
|
+
removed: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=instance-access.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-access.service.d.ts","sourceRoot":"","sources":["../src/instance-access.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EAGtB,KAAK,qBAAqB,EAE1B,KAAK,cAAc,EACpB,MAAM,sB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|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.InstanceAccessService = exports.accessGrantSchema = exports.accessPrincipalSchema = exports.INSTANCE_ADMIN_PERMISSION = void 0;
|
|
16
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const access_1 = require("./access");
|
|
20
|
+
const runtime_service_1 = require("./runtime.service");
|
|
21
|
+
const store_1 = require("./store");
|
|
22
|
+
exports.INSTANCE_ADMIN_PERMISSION = 'state-machine:instance:admin';
|
|
23
|
+
exports.accessPrincipalSchema = zod_1.z
|
|
24
|
+
.object({
|
|
25
|
+
principalType: zod_1.z.enum(['USER', 'ROLE']),
|
|
26
|
+
principalId: zod_1.z.string().min(1).max(128),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
exports.accessGrantSchema = exports.accessPrincipalSchema.extend({ level: zod_1.z.enum(['READ', 'WRITE']) });
|
|
30
|
+
let InstanceAccessService = class InstanceAccessService {
|
|
31
|
+
constructor(store, runtime, rbac, identity, inbox, config = {}, now = () => new Date()) {
|
|
32
|
+
this.store = store;
|
|
33
|
+
this.runtime = runtime;
|
|
34
|
+
this.rbac = rbac;
|
|
35
|
+
this.identity = identity;
|
|
36
|
+
this.inbox = inbox;
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.now = now;
|
|
39
|
+
}
|
|
40
|
+
async authorized(store, userId, id, manage) {
|
|
41
|
+
const instance = await store.find(id, manage);
|
|
42
|
+
const auth = await (0, plugin_api_1.authorizationOfUser)(this.rbac, userId);
|
|
43
|
+
const admin = Boolean(userId) && (0, plugin_api_1.hasPermission)(auth, exports.INSTANCE_ADMIN_PERMISSION);
|
|
44
|
+
// Instance administrators can manage any list (decision 4); ordinary readers cannot regrant.
|
|
45
|
+
if (!instance || (!admin && !(await (0, access_1.instanceAccessAllowed)(userId, instance, auth, store))))
|
|
46
|
+
throw new plugin_api_1.MechanismError('INSTANCE_NOT_FOUND', 'Instance not found', 404);
|
|
47
|
+
const canManage = admin || instance.submitterId === userId;
|
|
48
|
+
if (manage && !canManage)
|
|
49
|
+
throw new plugin_api_1.MechanismError('FORBIDDEN', 'Only the submitter or an instance administrator may manage access', 403);
|
|
50
|
+
return { instance, canManage };
|
|
51
|
+
}
|
|
52
|
+
async listFor(userId, id) {
|
|
53
|
+
return this.store.run(undefined, async (store, tx) => {
|
|
54
|
+
const { canManage } = await this.authorized(store, userId, id, false);
|
|
55
|
+
const items = await store.listAccess(id);
|
|
56
|
+
const ids = [
|
|
57
|
+
...new Set(items.flatMap((r) => [
|
|
58
|
+
...(r.principalType === 'USER' ? [r.principalId] : []),
|
|
59
|
+
...(r.grantedBy ? [r.grantedBy] : []),
|
|
60
|
+
])),
|
|
61
|
+
];
|
|
62
|
+
const names = new Map(ids.length && this.identity?.findActiveNamesByIds
|
|
63
|
+
? (await this.identity.findActiveNamesByIds(ids, tx)).map((r) => [r.id, r.name])
|
|
64
|
+
: []);
|
|
65
|
+
const roleIds = [
|
|
66
|
+
...new Set(items.filter((r) => r.principalType === 'ROLE').map((r) => r.principalId)),
|
|
67
|
+
];
|
|
68
|
+
const roles = new Map(roleIds.length && this.rbac?.findRolesByNames
|
|
69
|
+
? (await this.rbac.findRolesByNames(roleIds, tx)).map((r) => [r.name, r.displayName])
|
|
70
|
+
: []);
|
|
71
|
+
return {
|
|
72
|
+
canManage,
|
|
73
|
+
items: items.map((r) => ({
|
|
74
|
+
...r,
|
|
75
|
+
principalName: (r.principalType === 'USER' ? names : roles).get(r.principalId) ?? null,
|
|
76
|
+
grantedByName: names.get(r.grantedBy ?? '') ?? null,
|
|
77
|
+
})),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async grantFor(userId, id, input) {
|
|
82
|
+
return this.store.run(undefined, async (store, tx) => {
|
|
83
|
+
await this.runtime.get(id, tx, { lock: true });
|
|
84
|
+
const { instance } = await this.authorized(store, userId, id, true);
|
|
85
|
+
const parsed = exports.accessGrantSchema.safeParse(input);
|
|
86
|
+
if (!parsed.success)
|
|
87
|
+
throw new plugin_api_1.MechanismError('ACCESS_PRINCIPAL_INVALID', 'Invalid access principal or level');
|
|
88
|
+
const grant = parsed.data;
|
|
89
|
+
if (grant.principalType === 'USER') {
|
|
90
|
+
const principal = await this.identity?.findById(grant.principalId);
|
|
91
|
+
if (!principal?.isActive || grant.principalId === instance.submitterId)
|
|
92
|
+
throw new plugin_api_1.MechanismError('ACCESS_PRINCIPAL_INVALID', 'An active user other than the submitter is required');
|
|
93
|
+
}
|
|
94
|
+
else if (!(await this.rbac?.findRolesByNames?.([grant.principalId], tx))?.some((r) => r.name === grant.principalId)) {
|
|
95
|
+
throw new plugin_api_1.MechanismError('ACCESS_PRINCIPAL_INVALID', 'An existing role is required');
|
|
96
|
+
}
|
|
97
|
+
const entries = await store.listAccess(id);
|
|
98
|
+
const previous = entries.find((r) => r.source === 'GRANTED' &&
|
|
99
|
+
r.principalType === grant.principalType &&
|
|
100
|
+
r.principalId === grant.principalId);
|
|
101
|
+
if (previous?.level === grant.level)
|
|
102
|
+
return previous;
|
|
103
|
+
const limit = this.config.maxGrantedAccess ?? 100;
|
|
104
|
+
if (!previous && entries.filter((r) => r.source === 'GRANTED').length >= limit)
|
|
105
|
+
throw new plugin_api_1.MechanismError('ACCESS_LIMIT_EXCEEDED', 'The instance access limit has been reached', 409);
|
|
106
|
+
const entry = await store.putGranted({
|
|
107
|
+
...grant,
|
|
108
|
+
instanceId: id,
|
|
109
|
+
source: 'GRANTED',
|
|
110
|
+
grantedBy: userId,
|
|
111
|
+
createdAt: previous?.createdAt ?? this.now(),
|
|
112
|
+
});
|
|
113
|
+
const at = this.now();
|
|
114
|
+
const historyId = await store.appendHistory({
|
|
115
|
+
instanceId: id,
|
|
116
|
+
transition: null,
|
|
117
|
+
fromState: instance.state,
|
|
118
|
+
toState: instance.state,
|
|
119
|
+
triggerType: 'ACCESS',
|
|
120
|
+
triggerUserId: userId,
|
|
121
|
+
triggerRef: null,
|
|
122
|
+
at,
|
|
123
|
+
decision: {
|
|
124
|
+
access: {
|
|
125
|
+
action: previous ? 'ADJUSTED' : 'GRANTED',
|
|
126
|
+
...grant,
|
|
127
|
+
previousLevel: previous?.level ?? null,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
if (grant.principalType === 'USER')
|
|
132
|
+
await this.inbox?.notify({
|
|
133
|
+
recipientUserId: grant.principalId,
|
|
134
|
+
idempotencyKey: `state-machine-access:${historyId}`,
|
|
135
|
+
type: 'state-machine.access.granted',
|
|
136
|
+
title: 'Instance access granted',
|
|
137
|
+
body: `Access level: ${grant.level}`,
|
|
138
|
+
sourceApp: this.config.appName ?? 'app',
|
|
139
|
+
sourceEntityType: 'StateMachineInstance',
|
|
140
|
+
sourceEntityId: id,
|
|
141
|
+
targetPath: `/instances/${id}`,
|
|
142
|
+
}, { tx });
|
|
143
|
+
await this.runtime.emit({
|
|
144
|
+
name: 'state-machine.access.recorded',
|
|
145
|
+
instanceId: id,
|
|
146
|
+
payload: {
|
|
147
|
+
historyId,
|
|
148
|
+
action: previous ? 'ADJUSTED' : 'GRANTED',
|
|
149
|
+
...grant,
|
|
150
|
+
at: at.toISOString(),
|
|
151
|
+
},
|
|
152
|
+
}, tx);
|
|
153
|
+
return entry;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async removeFor(userId, id, input) {
|
|
157
|
+
return this.store.run(undefined, async (store, tx) => {
|
|
158
|
+
await this.runtime.get(id, tx, { lock: true });
|
|
159
|
+
const { instance } = await this.authorized(store, userId, id, true);
|
|
160
|
+
const parsed = exports.accessPrincipalSchema.safeParse(input);
|
|
161
|
+
if (!parsed.success)
|
|
162
|
+
throw new plugin_api_1.MechanismError('ACCESS_PRINCIPAL_INVALID', 'Invalid access principal');
|
|
163
|
+
const principal = parsed.data;
|
|
164
|
+
const entries = (await store.listAccess(id)).filter((r) => r.principalType === principal.principalType && r.principalId === principal.principalId);
|
|
165
|
+
const previous = entries.find((r) => r.source === 'GRANTED');
|
|
166
|
+
if (!previous) {
|
|
167
|
+
if (entries.length)
|
|
168
|
+
throw new plugin_api_1.MechanismError('ACCESS_NOT_MANAGEABLE', 'Permanent access cannot be removed or adjusted', 409);
|
|
169
|
+
return { removed: false };
|
|
170
|
+
}
|
|
171
|
+
await store.deleteGranted(id, principal.principalType, principal.principalId);
|
|
172
|
+
const at = this.now();
|
|
173
|
+
const historyId = await store.appendHistory({
|
|
174
|
+
instanceId: id,
|
|
175
|
+
transition: null,
|
|
176
|
+
fromState: instance.state,
|
|
177
|
+
toState: instance.state,
|
|
178
|
+
triggerType: 'ACCESS',
|
|
179
|
+
triggerUserId: userId,
|
|
180
|
+
triggerRef: null,
|
|
181
|
+
at,
|
|
182
|
+
decision: { access: { action: 'REMOVED', ...principal, previousLevel: previous.level } },
|
|
183
|
+
});
|
|
184
|
+
await this.runtime.emit({
|
|
185
|
+
name: 'state-machine.access.recorded',
|
|
186
|
+
instanceId: id,
|
|
187
|
+
payload: { historyId, action: 'REMOVED', ...principal, at: at.toISOString() },
|
|
188
|
+
}, tx);
|
|
189
|
+
return { removed: true };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
exports.InstanceAccessService = InstanceAccessService;
|
|
194
|
+
exports.InstanceAccessService = InstanceAccessService = __decorate([
|
|
195
|
+
(0, common_1.Injectable)(),
|
|
196
|
+
__param(0, (0, common_1.Inject)(store_1.STATE_MACHINE_STORE)),
|
|
197
|
+
__param(1, (0, common_1.Inject)(runtime_service_1.StateMachineRuntime)),
|
|
198
|
+
__param(2, (0, common_1.Optional)()),
|
|
199
|
+
__param(2, (0, common_1.Inject)(plugin_api_1.RBAC_POLICY)),
|
|
200
|
+
__param(3, (0, common_1.Optional)()),
|
|
201
|
+
__param(3, (0, common_1.Inject)(plugin_api_1.IDENTITY_STORE)),
|
|
202
|
+
__param(4, (0, common_1.Optional)()),
|
|
203
|
+
__param(4, (0, common_1.Inject)(plugin_api_1.NOTIFICATION_INBOX)),
|
|
204
|
+
__param(5, (0, common_1.Optional)()),
|
|
205
|
+
__param(5, (0, common_1.Inject)(runtime_service_1.STATE_MACHINE_CONFIG)),
|
|
206
|
+
__param(6, (0, common_1.Optional)()),
|
|
207
|
+
__param(6, (0, common_1.Inject)(runtime_service_1.STATE_MACHINE_CLOCK)),
|
|
208
|
+
__metadata("design:paramtypes", [Object, runtime_service_1.StateMachineRuntime, Object, Object, Object, Object, Function])
|
|
209
|
+
], InstanceAccessService);
|
|
210
|
+
//# sourceMappingURL=instance-access.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-access.service.js","sourceRoot":"","sources":["../src/instance-access.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAU8B;AAC9B,2CAA8D;AAC9D,6BAAwB;AACxB,qCAAiD;AACjD,uDAK2B;AAC3B,mCAAgG;AAGnF,QAAA,yBAAy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IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,sCAAoB,CAAC,CAAA;IACxC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,qCAAmB,CAAC,CAAA;6CALe,qCAAmB;GAHjE,qBAAqB,CAiNjC"}
|
package/dist/mcp-tools.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { type DefinitionRegistryPort, type McpToolsPort, type RbacPolicyPort } from '@haneinfo/plugin-api';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
+
import { InstanceAccessService } from './instance-access.service';
|
|
8
9
|
export declare const SIMULATE_TOOL_NAME = "simulate_state_machine";
|
|
9
10
|
declare const inputSchema: z.ZodObject<{
|
|
10
11
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
@@ -19,7 +20,8 @@ interface CallContext {
|
|
|
19
20
|
export declare class StateMachineMcpTools {
|
|
20
21
|
private readonly registry?;
|
|
21
22
|
private readonly rbac?;
|
|
22
|
-
|
|
23
|
+
private readonly access?;
|
|
24
|
+
constructor(registry?: DefinitionRegistryPort | undefined, rbac?: RbacPolicyPort | undefined, access?: InstanceAccessService | undefined);
|
|
23
25
|
registerInto(target: McpToolsPort, options: {
|
|
24
26
|
scopeNamespace: string;
|
|
25
27
|
}): void;
|