@jini-ai/user-management 0.7.2 → 0.7.3-next.2
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/CHANGELOG.md +1 -1
- package/README.md +9 -5
- package/dist/admin/adapters/http.js +25 -20
- package/dist/admin/adapters/memory.js +164 -82
- package/dist/admin/auth.module.d.ts +2 -2
- package/dist/admin/auth.module.js +1 -1
- package/dist/admin/conformance/index.js +40 -18
- package/dist/admin/controllers/auth.controller.js +3 -1
- package/dist/admin/controllers/members.controller.js +56 -31
- package/dist/admin/controllers/roles.controller.d.ts +3 -3
- package/dist/admin/controllers/roles.controller.js +188 -122
- package/dist/admin/controllers/users.controller.js +151 -72
- package/dist/admin/members.module.d.ts +2 -2
- package/dist/admin/members.module.js +1 -1
- package/dist/admin/models.d.ts +1 -0
- package/dist/admin/ports.d.ts +3 -0
- package/dist/admin/react/components/DestructiveDialog.d.ts +1 -1
- package/dist/admin/react/components/DestructiveDialog.js +1 -1
- package/dist/admin/react/components/MemberRow.d.ts +3 -1
- package/dist/admin/react/components/MemberRow.js +2 -2
- package/dist/admin/react/components/MembersConfirmation.d.ts +4 -1
- package/dist/admin/react/components/MembersConfirmation.js +2 -2
- package/dist/admin/react/components/PermissionPanel.d.ts +4 -2
- package/dist/admin/react/components/PermissionPanel.js +2 -2
- package/dist/admin/react/components/PolicyRow.d.ts +4 -2
- package/dist/admin/react/components/PolicyRow.js +2 -2
- package/dist/admin/react/components/RoleRow.d.ts +4 -2
- package/dist/admin/react/components/RoleRow.js +2 -2
- package/dist/admin/react/components/UserRow.d.ts +3 -1
- package/dist/admin/react/components/UserRow.js +2 -2
- package/dist/admin/react/components/UsersConfirmation.d.ts +4 -1
- package/dist/admin/react/components/UsersConfirmation.js +2 -2
- package/dist/admin/react/hooks/AuthBinding.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/AuthScope.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/MembersBinding.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/MembersScope.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/PeopleController.hooks.js +6 -4
- package/dist/admin/react/hooks/RolesBinding.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/RolesController.hooks.d.ts +4 -4
- package/dist/admin/react/hooks/RolesController.hooks.js +4 -3
- package/dist/admin/react/hooks/RolesPage.hooks.d.ts +8 -8
- package/dist/admin/react/hooks/RolesScope.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/UsersBinding.hooks.d.ts +1 -1
- package/dist/admin/react/hooks/UsersScope.hooks.d.ts +1 -1
- package/dist/admin/react/index.d.ts +9 -9
- package/dist/admin/react/pages/LoginPage.d.ts +4 -1
- package/dist/admin/react/pages/LoginPage.js +2 -2
- package/dist/admin/react/pages/MembersPage.d.ts +4 -1
- package/dist/admin/react/pages/MembersPage.js +2 -2
- package/dist/admin/react/pages/RolesPage.d.ts +4 -1
- package/dist/admin/react/pages/RolesPage.js +2 -2
- package/dist/admin/react/pages/UsersPage.d.ts +4 -1
- package/dist/admin/react/pages/UsersPage.js +2 -2
- package/dist/admin/react/tabs/AuthTab.d.ts +4 -2
- package/dist/admin/react/tabs/AuthTab.js +2 -2
- package/dist/admin/react/tabs/MembersTab.d.ts +4 -2
- package/dist/admin/react/tabs/MembersTab.js +2 -2
- package/dist/admin/react/tabs/PoliciesTab.d.ts +4 -2
- package/dist/admin/react/tabs/PoliciesTab.js +2 -2
- package/dist/admin/react/tabs/RolesTab.d.ts +4 -2
- package/dist/admin/react/tabs/RolesTab.js +2 -2
- package/dist/admin/react/tabs/UsersTab.d.ts +3 -1
- package/dist/admin/react/tabs/UsersTab.js +2 -2
- package/dist/admin/roles.module.d.ts +2 -2
- package/dist/admin/roles.module.js +1 -1
- package/dist/admin/users.module.d.ts +4 -4
- package/dist/admin/users.module.js +1 -1
- package/dist/react/auth/Login.js +1 -1
- package/dist/react/auth/OwnerRecovery.hooks.d.ts +93 -0
- package/dist/react/auth/OwnerRecovery.hooks.js +105 -0
- package/dist/react/auth/Passkeys.d.ts +8 -3
- package/dist/react/auth/Passkeys.hooks.d.ts +38 -0
- package/dist/react/auth/Passkeys.hooks.js +72 -0
- package/dist/react/auth/Passkeys.js +6 -64
- package/dist/react/auth/TotpSettings.d.ts +5 -2
- package/dist/react/auth/TotpSettings.hooks.d.ts +41 -0
- package/dist/react/auth/TotpSettings.hooks.js +82 -0
- package/dist/react/auth/TotpSettings.js +10 -77
- package/dist/react/auth/hooks/use-login.hooks.d.ts +1 -1
- package/dist/react/auth/hooks/use-login.hooks.js +1 -0
- package/dist/react/errors.d.ts +1 -1
- package/dist/react/errors.js +1 -0
- package/dist/react/index.d.ts +6 -2
- package/dist/react/index.js +3 -1
- package/dist/react/kit.d.ts +91 -0
- package/dist/react/kit.js +63 -0
- package/dist/react/members/Members.d.ts +1 -1
- package/dist/react/members/Members.js +19 -5
- package/dist/react/members/hooks/use-members.hooks.d.ts +1 -1
- package/dist/react/members/hooks/use-members.hooks.js +49 -27
- package/dist/react/members/rules.d.ts +2 -2
- package/dist/react/members/rules.js +1 -0
- package/dist/react/ports.d.ts +2 -0
- package/dist/react/testing.js +47 -22
- package/dist/react/users/ChangeUsernameDialog.d.ts +2 -2
- package/dist/react/users/ChangeUsernameDialog.js +4 -3
- package/dist/react/users/UserRowParts.d.ts +3 -3
- package/dist/react/users/UserRowParts.js +2 -1
- package/dist/react/users/Users.d.ts +3 -3
- package/dist/react/users/Users.js +14 -27
- package/dist/react/users/UsersDialogs.d.ts +7 -0
- package/dist/react/users/UsersDialogs.js +64 -0
- package/dist/react/users/UsersTable.d.ts +118 -0
- package/dist/react/users/UsersTable.js +55 -0
- package/dist/react/users/hooks/use-change-username.hooks.d.ts +1 -1
- package/dist/react/users/hooks/use-change-username.hooks.js +2 -1
- package/dist/react/users/hooks/use-reset-password-fields.hooks.d.ts +8 -0
- package/dist/react/users/hooks/use-reset-password-fields.hooks.js +11 -0
- package/dist/react/users/hooks/use-users-form-state.hooks.d.ts +81 -0
- package/dist/react/users/hooks/use-users-form-state.hooks.js +68 -0
- package/dist/react/users/hooks/use-users-password.hooks.d.ts +24 -0
- package/dist/react/users/hooks/use-users-password.hooks.js +85 -0
- package/dist/react/users/hooks/use-users-roster.hooks.d.ts +42 -0
- package/dist/react/users/hooks/use-users-roster.hooks.js +133 -0
- package/dist/react/users/hooks/use-users-state.hooks.d.ts +102 -0
- package/dist/react/users/hooks/use-users-state.hooks.js +19 -0
- package/dist/react/users/hooks/use-users-status.hooks.d.ts +26 -0
- package/dist/react/users/hooks/use-users-status.hooks.js +97 -0
- package/dist/react/users/hooks/use-users.hooks.d.ts +13 -5
- package/dist/react/users/hooks/use-users.hooks.js +23 -503
- package/dist/react/users/hooks/users-controller.d.ts +14 -0
- package/dist/react/users/hooks/users-controller.js +29 -0
- package/dist/react/users/hooks/users-grant-actions.d.ts +26 -0
- package/dist/react/users/hooks/users-grant-actions.js +124 -0
- package/dist/react/users/rules.d.ts +5 -4
- package/dist/react/users/rules.js +3 -2
- package/dist/server/admin-crud-service.d.ts +2 -2
- package/dist/server/admin-crud-service.js +38 -71
- package/dist/server/agent-tool-input.d.ts +7 -3
- package/dist/server/agent-tool-input.js +47 -14
- package/dist/server/agent-tool-registrations.d.ts +5 -2
- package/dist/server/agent-tool-registrations.js +250 -199
- package/dist/server/agent-tools.d.ts +1 -1
- package/dist/server/auth-service.js +1 -1
- package/dist/server/grant-service.d.ts +8 -0
- package/dist/server/grant-service.js +24 -22
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/link-policy.d.ts +23 -0
- package/dist/server/link-policy.js +30 -0
- package/dist/server/permission-migrations.d.ts +3 -3
- package/dist/server/repo.memory-transactions.js +24 -20
- package/dist/server/repo.memory.d.ts +21 -33
- package/dist/server/repo.memory.js +13 -34
- package/dist/server/seed.d.ts +3 -3
- package/dist/server/seed.js +10 -10
- package/dist/session-bootstrap/ensure.d.ts +13 -0
- package/dist/session-bootstrap/ensure.js +11 -0
- package/dist/session-bootstrap/index.d.ts +5 -0
- package/dist/session-bootstrap/index.js +4 -0
- package/dist/session-bootstrap/loopback.d.ts +14 -0
- package/dist/session-bootstrap/loopback.js +25 -0
- package/dist/session-bootstrap/read-initial.d.ts +25 -0
- package/dist/session-bootstrap/read-initial.js +27 -0
- package/package.json +21 -25
|
@@ -20,7 +20,7 @@ const MUTATES_DURABLE_STATE = "mutates-durable-state";
|
|
|
20
20
|
const CATALOG_BY_ID = indexCatalogById({ catalog: identityAgentToolCatalog });
|
|
21
21
|
/**
|
|
22
22
|
* Assembles `auth-service.ts`'s `IdentityRepos` bag from {@link IdentityToolDeps}'s flat fields — a
|
|
23
|
-
* local duplicate of `server/
|
|
23
|
+
* local duplicate of the host app's `src/server/inbound/admin-http/routes/users/deps.ts`'s `identityReposFrom` rather than an import
|
|
24
24
|
* of it, for the same reason `features/settings/tool-registrations.ts`'s header gives for
|
|
25
25
|
* duplicating `toWriteServiceDeps`: importing from the HTTP admin layer would invert this codebase's
|
|
26
26
|
* ports/adapters direction. It is a field mapping, not an authorization decision. Host route bags must bind the same
|
|
@@ -95,7 +95,7 @@ export const identityDerivedRisk = new Map([
|
|
|
95
95
|
/**
|
|
96
96
|
* Upper bound on the roster `identity_user_list` will fan out over.
|
|
97
97
|
*
|
|
98
|
-
* `
|
|
98
|
+
* the host app's `src/server/inbound/admin-http/routes/users/list.ts` does the same O(n) per-user fan-out uncapped, on the documented
|
|
99
99
|
* "operator-managed roster, not member/content scale" assumption. That assumption is fine for a
|
|
100
100
|
* human screen and NOT fine here for a different reason than scale: this result is spent as model
|
|
101
101
|
* context, so an unexpectedly large roster would silently consume the run's context window. The
|
|
@@ -124,7 +124,7 @@ export function identityInput({ toolId, input }) {
|
|
|
124
124
|
const recovery = "Fix the input and retry — this will not resolve on retry without an input change.";
|
|
125
125
|
throw new Error(`${parsed.error.message}. ${recovery} Schema for '${toolId}': ${JSON.stringify(entry.inputSchema)}`);
|
|
126
126
|
}
|
|
127
|
-
const value = parsed
|
|
127
|
+
const { value, integers } = parsed;
|
|
128
128
|
return {
|
|
129
129
|
req(field) {
|
|
130
130
|
const found = value[field];
|
|
@@ -136,6 +136,9 @@ export function identityInput({ toolId, input }) {
|
|
|
136
136
|
opt(field) {
|
|
137
137
|
return value[field];
|
|
138
138
|
},
|
|
139
|
+
int(field) {
|
|
140
|
+
return integers[field];
|
|
141
|
+
},
|
|
139
142
|
};
|
|
140
143
|
}
|
|
141
144
|
/** The permission set a tool's catalog entry declares — both halves when the gate is an OR. */
|
|
@@ -149,7 +152,7 @@ function identityPermissionsFor(toolId) {
|
|
|
149
152
|
* The mutating tools need no equivalent: their domain function opens with this same
|
|
150
153
|
* `assertCallerHasAnyPermission` call itself. Reads have no service-layer function to inherit it
|
|
151
154
|
* from — `identity` exports grant-writing transitions, not read wrappers, which is why
|
|
152
|
-
* `
|
|
155
|
+
* the host app's `src/server/inbound/admin-http/routes/users/list.ts` also gates in the route and then reads the repo ports directly.
|
|
153
156
|
* This calls the domain's own exported helper rather than re-deriving an OR gate (and rather than
|
|
154
157
|
* the kit's generic `requireToolPermission`, which cannot express an OR), so the single
|
|
155
158
|
* evaluator is reached by an identical path from both tool kinds.
|
|
@@ -233,201 +236,22 @@ export function buildIdentityRegistrations(routeDeps) {
|
|
|
233
236
|
/** Assembled per call, not per handler, because every mutating handler needs the identical bag. */
|
|
234
237
|
const serviceDeps = () => identityServiceDepsFrom(routeDeps);
|
|
235
238
|
const handlers = {
|
|
236
|
-
identity_user_list:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
? { users: listed, truncated: true, totalCount: humans.length }
|
|
253
|
-
: { users: listed };
|
|
254
|
-
},
|
|
255
|
-
identity_role_list: async (ctx) => {
|
|
256
|
-
identityInput({ toolId: "identity_role_list", input: ctx.input });
|
|
257
|
-
await assertIdentityReadAllowed(routeDeps, "identity_role_list", ctx.principal.id);
|
|
258
|
-
const roles = await routeDeps.roleRepo.list({ workspaceId: routeDeps.workspaceId });
|
|
259
|
-
return { roles: roles.map(toIdentityRoleView) };
|
|
260
|
-
},
|
|
261
|
-
identity_policy_list: async (ctx) => {
|
|
262
|
-
identityInput({ toolId: "identity_policy_list", input: ctx.input });
|
|
263
|
-
await assertIdentityReadAllowed(routeDeps, "identity_policy_list", ctx.principal.id);
|
|
264
|
-
const policies = await routeDeps.policyRepo.list({ workspaceId: routeDeps.workspaceId });
|
|
265
|
-
return { policies: policies.map(toIdentityPolicyView) };
|
|
266
|
-
},
|
|
267
|
-
identity_user_create: async (ctx) => {
|
|
268
|
-
const input = identityInput({ toolId: "identity_user_create", input: ctx.input });
|
|
269
|
-
const { principal, user } = await createUser({
|
|
270
|
-
deps: serviceDeps(),
|
|
271
|
-
input: {
|
|
272
|
-
workspaceId: routeDeps.workspaceId,
|
|
273
|
-
callerPrincipalId: ctx.principal.id,
|
|
274
|
-
username: input.req("username"),
|
|
275
|
-
password: input.req("password"),
|
|
276
|
-
},
|
|
277
|
-
}, { email: input.opt("email") });
|
|
278
|
-
// A brand-new principal has no assignments yet, so this is [] by construction, not a read.
|
|
279
|
-
return { user: toIdentityUserView({ principal, user, roleIds: [] }) };
|
|
280
|
-
},
|
|
281
|
-
identity_user_update_email: async (ctx) => {
|
|
282
|
-
const input = identityInput({ toolId: "identity_user_update_email", input: ctx.input });
|
|
283
|
-
const { user } = await updateUser({
|
|
284
|
-
deps: serviceDeps(),
|
|
285
|
-
input: {
|
|
286
|
-
workspaceId: routeDeps.workspaceId,
|
|
287
|
-
callerPrincipalId: ctx.principal.id,
|
|
288
|
-
principalId: input.req("principalId"),
|
|
289
|
-
// Absent stays absent: `updateUser` treats a falsy email as "clear", which is exactly
|
|
290
|
-
// what this tool's description tells the model omitting it does.
|
|
291
|
-
},
|
|
292
|
-
}, { email: input.opt("email") });
|
|
293
|
-
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: input.req("principalId") });
|
|
294
|
-
if (!principal)
|
|
295
|
-
throw new Error(`principal '${input.req("principalId")}' was not found`);
|
|
296
|
-
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
297
|
-
},
|
|
298
|
-
identity_user_change_username: async (ctx) => {
|
|
299
|
-
const input = identityInput({ toolId: "identity_user_change_username", input: ctx.input });
|
|
300
|
-
const principalId = input.req("principalId");
|
|
301
|
-
const { user } = await updateUser({
|
|
302
|
-
deps: serviceDeps(), input: {
|
|
303
|
-
workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, principalId,
|
|
304
|
-
}
|
|
305
|
-
}, { username: input.req("username") });
|
|
306
|
-
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: principalId });
|
|
307
|
-
if (!principal)
|
|
308
|
-
throw new Error(`principal '${principalId}' was not found`);
|
|
309
|
-
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principalId) }) };
|
|
310
|
-
},
|
|
311
|
-
identity_user_disable: async (ctx) => {
|
|
312
|
-
const input = identityInput({ toolId: "identity_user_disable", input: ctx.input });
|
|
313
|
-
const { principal } = await disablePrincipal({
|
|
314
|
-
deps: serviceDeps(),
|
|
315
|
-
input: {
|
|
316
|
-
workspaceId: routeDeps.workspaceId,
|
|
317
|
-
callerPrincipalId: ctx.principal.id,
|
|
318
|
-
principalId: input.req("principalId"),
|
|
319
|
-
// Resolved by the caller, per `disablePrincipal`'s own contract — the same
|
|
320
|
-
// `await deps.ownerPrincipalId` the human disable route performs.
|
|
321
|
-
seededOwnerPrincipalId: await routeDeps.ownerPrincipalId,
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
const user = await requireUserRecord(routeDeps, principal.id);
|
|
325
|
-
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
326
|
-
},
|
|
327
|
-
identity_user_enable: async (ctx) => {
|
|
328
|
-
const input = identityInput({ toolId: "identity_user_enable", input: ctx.input });
|
|
329
|
-
const { principal } = await enablePrincipal({
|
|
330
|
-
deps: serviceDeps(),
|
|
331
|
-
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, principalId: input.req("principalId") },
|
|
332
|
-
});
|
|
333
|
-
const user = await requireUserRecord(routeDeps, principal.id);
|
|
334
|
-
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
335
|
-
},
|
|
336
|
-
identity_role_create: async (ctx) => {
|
|
337
|
-
const input = identityInput({ toolId: "identity_role_create", input: ctx.input });
|
|
338
|
-
const { role } = await createRole({
|
|
339
|
-
deps: serviceDeps(),
|
|
340
|
-
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, name: input.req("name") },
|
|
341
|
-
});
|
|
342
|
-
return { role: toIdentityRoleView(role) };
|
|
343
|
-
},
|
|
344
|
-
identity_role_assign: async (ctx) => {
|
|
345
|
-
const input = identityInput({ toolId: "identity_role_assign", input: ctx.input });
|
|
346
|
-
const { assignment } = await assignRole({
|
|
347
|
-
deps: serviceDeps(),
|
|
348
|
-
input: {
|
|
349
|
-
workspaceId: routeDeps.workspaceId,
|
|
350
|
-
callerPrincipalId: ctx.principal.id,
|
|
351
|
-
principalId: input.req("principalId"),
|
|
352
|
-
roleId: input.req("roleId"),
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
// The join row's own id is not addressable by any other tool, so it is dropped; what the
|
|
356
|
-
// model needs back is confirmation of WHICH pair is now linked.
|
|
357
|
-
return { assigned: { principalId: assignment.principalId, roleId: assignment.roleId } };
|
|
358
|
-
},
|
|
359
|
-
identity_role_rename: async (ctx) => {
|
|
360
|
-
const input = identityInput({ toolId: "identity_role_rename", input: ctx.input });
|
|
361
|
-
const { role } = await updateRole({
|
|
362
|
-
deps: serviceDeps(),
|
|
363
|
-
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, roleId: input.req("roleId"), name: input.req("name") },
|
|
364
|
-
});
|
|
365
|
-
return { role: toIdentityRoleView(role) };
|
|
366
|
-
},
|
|
367
|
-
identity_role_delete: async (ctx) => {
|
|
368
|
-
const input = identityInput({ toolId: "identity_role_delete", input: ctx.input });
|
|
369
|
-
await deleteRole({
|
|
370
|
-
deps: serviceDeps(),
|
|
371
|
-
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, roleId: input.req("roleId") },
|
|
372
|
-
});
|
|
373
|
-
// `deleteRole` resolves void; an empty tool result would read to the model as "nothing
|
|
374
|
-
// happened", so the deleted id is echoed as the acknowledgement.
|
|
375
|
-
return { deleted: { roleId: input.req("roleId") } };
|
|
376
|
-
},
|
|
377
|
-
identity_policy_create: async (ctx) => {
|
|
378
|
-
const input = identityInput({ toolId: "identity_policy_create", input: ctx.input });
|
|
379
|
-
const { policy } = await createPolicy({
|
|
380
|
-
deps: serviceDeps(),
|
|
381
|
-
input: {
|
|
382
|
-
workspaceId: routeDeps.workspaceId,
|
|
383
|
-
callerPrincipalId: ctx.principal.id,
|
|
384
|
-
name: input.req("name"),
|
|
385
|
-
// Absent stays absent: `input.description` is only present when the caller supplied it
|
|
386
|
-
// (`parseIdentityToolInput` omits absent optional keys entirely), so this passes through
|
|
387
|
-
// unchanged rather than coercing a caller-supplied empty string to "no description".
|
|
388
|
-
},
|
|
389
|
-
}, { description: input.opt("description") });
|
|
390
|
-
return { policy: toIdentityPolicyView(policy) };
|
|
391
|
-
},
|
|
392
|
-
identity_policy_update: async (ctx) => {
|
|
393
|
-
const input = identityInput({ toolId: "identity_policy_update", input: ctx.input });
|
|
394
|
-
const { policy } = await updatePolicy({
|
|
395
|
-
deps: serviceDeps(),
|
|
396
|
-
input: {
|
|
397
|
-
workspaceId: routeDeps.workspaceId,
|
|
398
|
-
callerPrincipalId: ctx.principal.id,
|
|
399
|
-
policyId: input.req("policyId"),
|
|
400
|
-
// Same absent-stays-absent reasoning as identity_policy_create — `updatePolicy` itself
|
|
401
|
-
// distinguishes undefined ("leave unchanged") from an explicit empty string.
|
|
402
|
-
},
|
|
403
|
-
}, { name: input.opt("name"), description: input.opt("description") });
|
|
404
|
-
return { policy: toIdentityPolicyView(policy) };
|
|
405
|
-
},
|
|
406
|
-
identity_policy_delete: async (ctx) => {
|
|
407
|
-
const input = identityInput({ toolId: "identity_policy_delete", input: ctx.input });
|
|
408
|
-
await deletePolicy({
|
|
409
|
-
deps: serviceDeps(),
|
|
410
|
-
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, policyId: input.req("policyId") },
|
|
411
|
-
});
|
|
412
|
-
// `deletePolicy` resolves void; an empty tool result would read to the model as "nothing
|
|
413
|
-
// happened", so the deleted id is echoed as the acknowledgement (mirrors identity_role_delete).
|
|
414
|
-
return { deleted: { policyId: input.req("policyId") } };
|
|
415
|
-
},
|
|
416
|
-
identity_policy_attach: async (ctx) => {
|
|
417
|
-
const input = identityInput({ toolId: "identity_policy_attach", input: ctx.input });
|
|
418
|
-
const { attachment } = await attachPolicy({
|
|
419
|
-
deps: serviceDeps(),
|
|
420
|
-
input: {
|
|
421
|
-
workspaceId: routeDeps.workspaceId,
|
|
422
|
-
callerPrincipalId: ctx.principal.id,
|
|
423
|
-
principalId: input.req("principalId"),
|
|
424
|
-
policyId: input.req("policyId"),
|
|
425
|
-
},
|
|
426
|
-
});
|
|
427
|
-
// The join row's own id is not addressable by any other tool, so it is dropped; what the
|
|
428
|
-
// model needs back is confirmation of WHICH pair is now linked (mirrors identity_role_assign).
|
|
429
|
-
return { attached: { principalId: attachment.principalId, policyId: attachment.policyId } };
|
|
430
|
-
},
|
|
239
|
+
identity_user_list: createIdentityUserListHandler(routeDeps),
|
|
240
|
+
identity_role_list: createIdentityRoleListHandler(routeDeps),
|
|
241
|
+
identity_policy_list: createIdentityPolicyListHandler(routeDeps),
|
|
242
|
+
identity_user_create: createIdentityUserCreateHandler(routeDeps, serviceDeps),
|
|
243
|
+
identity_user_update_email: createIdentityUserUpdateEmailHandler(routeDeps, serviceDeps),
|
|
244
|
+
identity_user_change_username: createIdentityUserChangeUsernameHandler(routeDeps, serviceDeps),
|
|
245
|
+
identity_user_disable: createIdentityUserDisableHandler(routeDeps, serviceDeps),
|
|
246
|
+
identity_user_enable: createIdentityUserEnableHandler(routeDeps, serviceDeps),
|
|
247
|
+
identity_role_create: createIdentityRoleCreateHandler(routeDeps, serviceDeps),
|
|
248
|
+
identity_role_assign: createIdentityRoleAssignHandler(routeDeps, serviceDeps),
|
|
249
|
+
identity_role_rename: createIdentityRoleRenameHandler(routeDeps, serviceDeps),
|
|
250
|
+
identity_role_delete: createIdentityRoleDeleteHandler(routeDeps, serviceDeps),
|
|
251
|
+
identity_policy_create: createIdentityPolicyCreateHandler(routeDeps, serviceDeps),
|
|
252
|
+
identity_policy_update: createIdentityPolicyUpdateHandler(routeDeps, serviceDeps),
|
|
253
|
+
identity_policy_delete: createIdentityPolicyDeleteHandler(routeDeps, serviceDeps),
|
|
254
|
+
identity_policy_attach: createIdentityPolicyAttachHandler(routeDeps, serviceDeps),
|
|
431
255
|
};
|
|
432
256
|
// No `unwiredToolIds`: identity wires its ENTIRE catalog (which is why its own
|
|
433
257
|
// `AgentToolDefinition` makes `inputSchema` required rather than optional).
|
|
@@ -439,4 +263,231 @@ export function buildIdentityRegistrations(routeDeps) {
|
|
|
439
263
|
derivedRisk: identityDerivedRisk,
|
|
440
264
|
});
|
|
441
265
|
}
|
|
266
|
+
function createIdentityUserListHandler(routeDeps) {
|
|
267
|
+
return async (ctx) => {
|
|
268
|
+
identityInput({ toolId: "identity_user_list", input: ctx.input });
|
|
269
|
+
await assertIdentityReadAllowed(routeDeps, "identity_user_list", ctx.principal.id);
|
|
270
|
+
const principals = await routeDeps.principalRepo.list({ workspaceId: routeDeps.workspaceId });
|
|
271
|
+
// Humans only — `system`/`agent`/`api_key` principals (including the disabled `user-local`
|
|
272
|
+
// seed row) are not what "users" means on this surface, matching `routes/.../list.ts`.
|
|
273
|
+
const humans = principals.filter((principal) => principal.kind === "user");
|
|
274
|
+
const page = humans.slice(0, IDENTITY_USER_LIST_MAX);
|
|
275
|
+
const users = await Promise.all(page.map(async (principal) => {
|
|
276
|
+
const user = await routeDeps.userRepo.findByPrincipalId({ workspaceId: routeDeps.workspaceId, principalId: principal.id });
|
|
277
|
+
if (!user)
|
|
278
|
+
return null;
|
|
279
|
+
return toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) });
|
|
280
|
+
}));
|
|
281
|
+
const listed = users.filter((user) => user !== null);
|
|
282
|
+
return humans.length > page.length
|
|
283
|
+
? { users: listed, truncated: true, totalCount: humans.length }
|
|
284
|
+
: { users: listed };
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function createIdentityRoleListHandler(routeDeps) {
|
|
288
|
+
return async (ctx) => {
|
|
289
|
+
identityInput({ toolId: "identity_role_list", input: ctx.input });
|
|
290
|
+
await assertIdentityReadAllowed(routeDeps, "identity_role_list", ctx.principal.id);
|
|
291
|
+
const roles = await routeDeps.roleRepo.list({ workspaceId: routeDeps.workspaceId });
|
|
292
|
+
return { roles: roles.map(toIdentityRoleView) };
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function createIdentityPolicyListHandler(routeDeps) {
|
|
296
|
+
return async (ctx) => {
|
|
297
|
+
identityInput({ toolId: "identity_policy_list", input: ctx.input });
|
|
298
|
+
await assertIdentityReadAllowed(routeDeps, "identity_policy_list", ctx.principal.id);
|
|
299
|
+
const policies = await routeDeps.policyRepo.list({ workspaceId: routeDeps.workspaceId });
|
|
300
|
+
return { policies: policies.map(toIdentityPolicyView) };
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function createIdentityUserCreateHandler(routeDeps, serviceDeps) {
|
|
304
|
+
return async (ctx) => {
|
|
305
|
+
const input = identityInput({ toolId: "identity_user_create", input: ctx.input });
|
|
306
|
+
const { principal, user } = await createUser({
|
|
307
|
+
deps: serviceDeps(),
|
|
308
|
+
input: {
|
|
309
|
+
workspaceId: routeDeps.workspaceId,
|
|
310
|
+
callerPrincipalId: ctx.principal.id,
|
|
311
|
+
username: input.req("username"),
|
|
312
|
+
password: input.req("password"),
|
|
313
|
+
},
|
|
314
|
+
}, { email: input.opt("email") });
|
|
315
|
+
// A brand-new principal has no assignments yet, so this is [] by construction, not a read.
|
|
316
|
+
return { user: toIdentityUserView({ principal, user, roleIds: [] }) };
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function createIdentityUserUpdateEmailHandler(routeDeps, serviceDeps) {
|
|
320
|
+
return async (ctx) => {
|
|
321
|
+
const input = identityInput({ toolId: "identity_user_update_email", input: ctx.input });
|
|
322
|
+
const { user } = await updateUser({
|
|
323
|
+
deps: serviceDeps(),
|
|
324
|
+
input: {
|
|
325
|
+
workspaceId: routeDeps.workspaceId,
|
|
326
|
+
callerPrincipalId: ctx.principal.id,
|
|
327
|
+
principalId: input.req("principalId"),
|
|
328
|
+
// Absent stays absent: `updateUser` treats a falsy email as "clear", which is exactly
|
|
329
|
+
// what this tool's description tells the model omitting it does.
|
|
330
|
+
},
|
|
331
|
+
}, { email: input.opt("email") });
|
|
332
|
+
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: input.req("principalId") });
|
|
333
|
+
if (!principal)
|
|
334
|
+
throw new Error(`principal '${input.req("principalId")}' was not found`);
|
|
335
|
+
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function createIdentityUserChangeUsernameHandler(routeDeps, serviceDeps) {
|
|
339
|
+
return async (ctx) => {
|
|
340
|
+
const input = identityInput({ toolId: "identity_user_change_username", input: ctx.input });
|
|
341
|
+
const principalId = input.req("principalId");
|
|
342
|
+
const { user } = await updateUser({
|
|
343
|
+
deps: serviceDeps(), input: {
|
|
344
|
+
workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, principalId,
|
|
345
|
+
}
|
|
346
|
+
}, { username: input.req("username") });
|
|
347
|
+
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: principalId });
|
|
348
|
+
if (!principal)
|
|
349
|
+
throw new Error(`principal '${principalId}' was not found`);
|
|
350
|
+
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principalId) }) };
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function createIdentityUserDisableHandler(routeDeps, serviceDeps) {
|
|
354
|
+
return async (ctx) => {
|
|
355
|
+
const input = identityInput({ toolId: "identity_user_disable", input: ctx.input });
|
|
356
|
+
const { principal } = await disablePrincipal({
|
|
357
|
+
deps: serviceDeps(),
|
|
358
|
+
input: {
|
|
359
|
+
workspaceId: routeDeps.workspaceId,
|
|
360
|
+
callerPrincipalId: ctx.principal.id,
|
|
361
|
+
principalId: input.req("principalId"),
|
|
362
|
+
// Resolved by the caller, per `disablePrincipal`'s own contract — the same
|
|
363
|
+
// `await deps.ownerPrincipalId` the human disable route performs.
|
|
364
|
+
seededOwnerPrincipalId: await routeDeps.ownerPrincipalId,
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
const user = await requireUserRecord(routeDeps, principal.id);
|
|
368
|
+
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function createIdentityUserEnableHandler(routeDeps, serviceDeps) {
|
|
372
|
+
return async (ctx) => {
|
|
373
|
+
const input = identityInput({ toolId: "identity_user_enable", input: ctx.input });
|
|
374
|
+
const { principal } = await enablePrincipal({
|
|
375
|
+
deps: serviceDeps(),
|
|
376
|
+
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, principalId: input.req("principalId") },
|
|
377
|
+
});
|
|
378
|
+
const user = await requireUserRecord(routeDeps, principal.id);
|
|
379
|
+
return { user: toIdentityUserView({ principal, user, roleIds: await roleIdsFor(routeDeps, principal.id) }) };
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function createIdentityRoleCreateHandler(routeDeps, serviceDeps) {
|
|
383
|
+
return async (ctx) => {
|
|
384
|
+
const input = identityInput({ toolId: "identity_role_create", input: ctx.input });
|
|
385
|
+
const { role } = await createRole({
|
|
386
|
+
deps: serviceDeps(),
|
|
387
|
+
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, name: input.req("name") },
|
|
388
|
+
});
|
|
389
|
+
return { role: toIdentityRoleView(role) };
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function createIdentityRoleAssignHandler(routeDeps, serviceDeps) {
|
|
393
|
+
return async (ctx) => {
|
|
394
|
+
const input = identityInput({ toolId: "identity_role_assign", input: ctx.input });
|
|
395
|
+
const { assignment } = await assignRole({
|
|
396
|
+
deps: serviceDeps(),
|
|
397
|
+
input: {
|
|
398
|
+
workspaceId: routeDeps.workspaceId,
|
|
399
|
+
callerPrincipalId: ctx.principal.id,
|
|
400
|
+
principalId: input.req("principalId"),
|
|
401
|
+
roleId: input.req("roleId"),
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
// The join row's own id is not addressable by any other tool, so it is dropped; what the
|
|
405
|
+
// model needs back is confirmation of WHICH pair is now linked.
|
|
406
|
+
return { assigned: { principalId: assignment.principalId, roleId: assignment.roleId } };
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function createIdentityRoleRenameHandler(routeDeps, serviceDeps) {
|
|
410
|
+
return async (ctx) => {
|
|
411
|
+
const input = identityInput({ toolId: "identity_role_rename", input: ctx.input });
|
|
412
|
+
const { role } = await updateRole({
|
|
413
|
+
deps: serviceDeps(),
|
|
414
|
+
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, roleId: input.req("roleId"), name: input.req("name") },
|
|
415
|
+
});
|
|
416
|
+
return { role: toIdentityRoleView(role) };
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function createIdentityRoleDeleteHandler(routeDeps, serviceDeps) {
|
|
420
|
+
return async (ctx) => {
|
|
421
|
+
const input = identityInput({ toolId: "identity_role_delete", input: ctx.input });
|
|
422
|
+
await deleteRole({
|
|
423
|
+
deps: serviceDeps(),
|
|
424
|
+
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, roleId: input.req("roleId") },
|
|
425
|
+
});
|
|
426
|
+
// `deleteRole` resolves void; an empty tool result would read to the model as "nothing
|
|
427
|
+
// happened", so the deleted id is echoed as the acknowledgement.
|
|
428
|
+
return { deleted: { roleId: input.req("roleId") } };
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
function createIdentityPolicyCreateHandler(routeDeps, serviceDeps) {
|
|
432
|
+
return async (ctx) => {
|
|
433
|
+
const input = identityInput({ toolId: "identity_policy_create", input: ctx.input });
|
|
434
|
+
const { policy } = await createPolicy({
|
|
435
|
+
deps: serviceDeps(),
|
|
436
|
+
input: {
|
|
437
|
+
workspaceId: routeDeps.workspaceId,
|
|
438
|
+
callerPrincipalId: ctx.principal.id,
|
|
439
|
+
name: input.req("name"),
|
|
440
|
+
// Absent stays absent: `input.description` is only present when the caller supplied it
|
|
441
|
+
// (`parseIdentityToolInput` omits absent optional keys entirely), so this passes through
|
|
442
|
+
// unchanged rather than coercing a caller-supplied empty string to "no description".
|
|
443
|
+
},
|
|
444
|
+
}, { description: input.opt("description") });
|
|
445
|
+
return { policy: toIdentityPolicyView(policy) };
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function createIdentityPolicyUpdateHandler(routeDeps, serviceDeps) {
|
|
449
|
+
return async (ctx) => {
|
|
450
|
+
const input = identityInput({ toolId: "identity_policy_update", input: ctx.input });
|
|
451
|
+
const { policy } = await updatePolicy({
|
|
452
|
+
deps: serviceDeps(),
|
|
453
|
+
input: {
|
|
454
|
+
workspaceId: routeDeps.workspaceId,
|
|
455
|
+
callerPrincipalId: ctx.principal.id,
|
|
456
|
+
policyId: input.req("policyId"),
|
|
457
|
+
// Same absent-stays-absent reasoning as identity_policy_create — `updatePolicy` itself
|
|
458
|
+
// distinguishes undefined ("leave unchanged") from an explicit empty string.
|
|
459
|
+
},
|
|
460
|
+
}, { name: input.opt("name"), description: input.opt("description") });
|
|
461
|
+
return { policy: toIdentityPolicyView(policy) };
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function createIdentityPolicyDeleteHandler(routeDeps, serviceDeps) {
|
|
465
|
+
return async (ctx) => {
|
|
466
|
+
const input = identityInput({ toolId: "identity_policy_delete", input: ctx.input });
|
|
467
|
+
await deletePolicy({
|
|
468
|
+
deps: serviceDeps(),
|
|
469
|
+
input: { workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, policyId: input.req("policyId") },
|
|
470
|
+
});
|
|
471
|
+
// `deletePolicy` resolves void; an empty tool result would read to the model as "nothing
|
|
472
|
+
// happened", so the deleted id is echoed as the acknowledgement (mirrors identity_role_delete).
|
|
473
|
+
return { deleted: { policyId: input.req("policyId") } };
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function createIdentityPolicyAttachHandler(routeDeps, serviceDeps) {
|
|
477
|
+
return async (ctx) => {
|
|
478
|
+
const input = identityInput({ toolId: "identity_policy_attach", input: ctx.input });
|
|
479
|
+
const { attachment } = await attachPolicy({
|
|
480
|
+
deps: serviceDeps(),
|
|
481
|
+
input: {
|
|
482
|
+
workspaceId: routeDeps.workspaceId,
|
|
483
|
+
callerPrincipalId: ctx.principal.id,
|
|
484
|
+
principalId: input.req("principalId"),
|
|
485
|
+
policyId: input.req("policyId"),
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
// The join row's own id is not addressable by any other tool, so it is dropped; what the
|
|
489
|
+
// model needs back is confirmation of WHICH pair is now linked (mirrors identity_role_assign).
|
|
490
|
+
return { attached: { principalId: attachment.principalId, policyId: attachment.policyId } };
|
|
491
|
+
};
|
|
492
|
+
}
|
|
442
493
|
//# sourceMappingURL=agent-tool-registrations.js.map
|
|
@@ -20,7 +20,7 @@ import type { AgentToolDefinition as KernelAgentToolDefinition } from "@jini-ai/
|
|
|
20
20
|
* then authenticate as owner, so it is a full account-takeover primitive rather than a
|
|
21
21
|
* permission grant. An assistant is reachable by prompt injection through ordinary operator
|
|
22
22
|
* content (a form submission, a comment) in a way a human clicking the admin button is not.
|
|
23
|
-
* Left human-UI-only, mirroring `
|
|
23
|
+
* Left human-UI-only, mirroring `packages/cms/src/content-types/agent-tools.ts`'s reasoning for never
|
|
24
24
|
* exposing the destructive-cleanup confirm step to an agent.
|
|
25
25
|
* - `writePolicyPermission`. This is the one policy transition still
|
|
26
26
|
* deliberately excluded, and on different grounds than the five wired below: unlike
|
|
@@ -8,7 +8,7 @@ import { normalizeUsername } from "./username.js";
|
|
|
8
8
|
* @file Login / logout / session validation (state.spec `LOGIN`/`LOGOUT`).
|
|
9
9
|
*
|
|
10
10
|
* Purpose:
|
|
11
|
-
* The credential-verification + session-lifecycle surface `
|
|
11
|
+
* The credential-verification + session-lifecycle surface the host app's `src/server/inbound/admin-http/dev-auth.ts`
|
|
12
12
|
* wires into HTTP. Session tokens are hashed with SHA-256 before storage — the
|
|
13
13
|
* same technique `members/write-service.ts` uses for magic-link/member-session
|
|
14
14
|
* tokens (: the raw token is never persisted). Password verification is
|
|
@@ -66,6 +66,14 @@ export declare function assertCallerHasAnyPermission(required: {
|
|
|
66
66
|
callerPrincipalId: UUID;
|
|
67
67
|
permissions: readonly string[];
|
|
68
68
|
}): Promise<void>;
|
|
69
|
+
/** Runs `execute` in one identity transaction after the caller passes `assertCallerHasAnyPermission`, so the check and the write see the same snapshot. */
|
|
70
|
+
export declare function inAuthorizedIdentityTransaction<T>({ deps, workspaceId, callerPrincipalId, permissions, execute }: {
|
|
71
|
+
deps: AuthServiceDeps;
|
|
72
|
+
workspaceId: UUID;
|
|
73
|
+
callerPrincipalId: UUID;
|
|
74
|
+
permissions: readonly string[];
|
|
75
|
+
execute: () => Promise<T>;
|
|
76
|
+
}, _optional?: Record<string, never>): Promise<T>;
|
|
69
77
|
/**
|
|
70
78
|
* The grant-authority clamp (feature.spec.md, state.spec §3
|
|
71
79
|
* `ASSIGN_ROLE`/`ATTACH_POLICY` rows): every permission in `conferredPermissions`
|
|
@@ -92,6 +92,13 @@ export async function assertCallerHasAnyPermission(required) {
|
|
|
92
92
|
}
|
|
93
93
|
throw new IdentityForbiddenError({ message: `principal '${callerPrincipalId}' is not authorized for any of [${permissions.join(", ")}]`, permission: permissions.join("|"), reason: lastReason });
|
|
94
94
|
}
|
|
95
|
+
/** Runs `execute` in one identity transaction after the caller passes `assertCallerHasAnyPermission`, so the check and the write see the same snapshot. */
|
|
96
|
+
export function inAuthorizedIdentityTransaction({ deps, workspaceId, callerPrincipalId, permissions, execute }, _optional = {}) {
|
|
97
|
+
return inIdentityTransaction({ transactions: deps.repos.transactions, workspaceId, execute: async () => {
|
|
98
|
+
await assertCallerHasAnyPermission({ deps, workspaceId, callerPrincipalId, permissions });
|
|
99
|
+
return execute();
|
|
100
|
+
} });
|
|
101
|
+
}
|
|
95
102
|
/** True iff `effectiveRows` contains an unconstrained hold of `permission` — an exact match with
|
|
96
103
|
* `resourceType`/`constraintJson` both null, or the owner wildcard `*` (which counts as an
|
|
97
104
|
* unconstrained hold of every permission).
|
|
@@ -305,16 +312,12 @@ export async function createPolicy(required, optional = {}) {
|
|
|
305
312
|
*/
|
|
306
313
|
export async function assignRole(required) {
|
|
307
314
|
const { deps, input } = required;
|
|
308
|
-
return
|
|
309
|
-
|
|
315
|
+
return inAuthorizedIdentityTransaction({
|
|
316
|
+
deps,
|
|
310
317
|
workspaceId: input.workspaceId,
|
|
318
|
+
callerPrincipalId: input.callerPrincipalId,
|
|
319
|
+
permissions: ["role.manage"],
|
|
311
320
|
execute: async () => {
|
|
312
|
-
await assertCallerHasAnyPermission({
|
|
313
|
-
deps,
|
|
314
|
-
workspaceId: input.workspaceId,
|
|
315
|
-
callerPrincipalId: input.callerPrincipalId,
|
|
316
|
-
permissions: ["role.manage"],
|
|
317
|
-
});
|
|
318
321
|
await findAssignableTargetOrThrow({
|
|
319
322
|
deps,
|
|
320
323
|
workspaceId: input.workspaceId,
|
|
@@ -331,12 +334,7 @@ export async function assignRole(required) {
|
|
|
331
334
|
if (!role) {
|
|
332
335
|
throw new IdentityNotFoundError({ message: `role '${input.roleId}' was not found` });
|
|
333
336
|
}
|
|
334
|
-
const
|
|
335
|
-
workspaceId: input.workspaceId,
|
|
336
|
-
roleId: input.roleId,
|
|
337
|
-
});
|
|
338
|
-
const policyPermissionGroups = await Promise.all(rolePolicyLinks.map((link) => deps.repos.policyPermissions.listByPolicyId({ workspaceId: input.workspaceId, policyId: link.policyId })));
|
|
339
|
-
const conferredPermissions = policyPermissionGroups.flat().map((row) => row.permission);
|
|
337
|
+
const conferredPermissions = await rolePermissionsForAssignment({ deps, input });
|
|
340
338
|
await assertGrantClamp({
|
|
341
339
|
deps,
|
|
342
340
|
workspaceId: input.workspaceId,
|
|
@@ -354,6 +352,14 @@ export async function assignRole(required) {
|
|
|
354
352
|
},
|
|
355
353
|
});
|
|
356
354
|
}
|
|
355
|
+
async function rolePermissionsForAssignment({ deps, input }) {
|
|
356
|
+
const rolePolicyLinks = await deps.repos.rolePolicies.listByRoleId({
|
|
357
|
+
workspaceId: input.workspaceId,
|
|
358
|
+
roleId: input.roleId,
|
|
359
|
+
});
|
|
360
|
+
const policyPermissionGroups = await Promise.all(rolePolicyLinks.map((link) => deps.repos.policyPermissions.listByPolicyId({ workspaceId: input.workspaceId, policyId: link.policyId })));
|
|
361
|
+
return policyPermissionGroups.flat().map((row) => row.permission);
|
|
362
|
+
}
|
|
357
363
|
/**
|
|
358
364
|
* `ATTACH_POLICY` (state.spec §3). Gated by
|
|
359
365
|
* `role.manage`; target must be a `kind='user'` principal; the
|
|
@@ -368,16 +374,12 @@ export async function assignRole(required) {
|
|
|
368
374
|
*/
|
|
369
375
|
export async function attachPolicy(required) {
|
|
370
376
|
const { deps, input } = required;
|
|
371
|
-
return
|
|
372
|
-
|
|
377
|
+
return inAuthorizedIdentityTransaction({
|
|
378
|
+
deps,
|
|
373
379
|
workspaceId: input.workspaceId,
|
|
380
|
+
callerPrincipalId: input.callerPrincipalId,
|
|
381
|
+
permissions: ["role.manage"],
|
|
374
382
|
execute: async () => {
|
|
375
|
-
await assertCallerHasAnyPermission({
|
|
376
|
-
deps,
|
|
377
|
-
workspaceId: input.workspaceId,
|
|
378
|
-
callerPrincipalId: input.callerPrincipalId,
|
|
379
|
-
permissions: ["role.manage"],
|
|
380
|
-
});
|
|
381
383
|
await findAssignableTargetOrThrow({
|
|
382
384
|
deps,
|
|
383
385
|
workspaceId: input.workspaceId,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -27,4 +27,5 @@ export * from './mfa/passkey-service.js';
|
|
|
27
27
|
export * from './mfa/passkey-adapter.js';
|
|
28
28
|
export { parseLoginProviders } from './login-providers.js';
|
|
29
29
|
export { MemberLoginError, type LoginProvider, type LoginProviderPreset, type MemberLoginOutcomeCode, type VerifiedLoginIdentity, } from './login-types.js';
|
|
30
|
+
export { decideMemberLogin, type LinkDecision, type LoginLinkMember } from './link-policy.js';
|
|
30
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/server/index.js
CHANGED
|
@@ -29,4 +29,5 @@ export * from './mfa/passkey-service.js';
|
|
|
29
29
|
export * from './mfa/passkey-adapter.js';
|
|
30
30
|
export { parseLoginProviders } from './login-providers.js';
|
|
31
31
|
export { MemberLoginError, } from './login-types.js';
|
|
32
|
+
export { decideMemberLogin } from './link-policy.js';
|
|
32
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Pure member-login link decision: which of sign-in, link, create, inbox proof, block or conflict applies. */
|
|
2
|
+
import type { VerifiedLoginIdentity } from "./login-types.js";
|
|
3
|
+
/** The two member fields the decision reads; a host's member record is assignable. */
|
|
4
|
+
export interface LoginLinkMember {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly status: string;
|
|
7
|
+
}
|
|
8
|
+
export type LinkDecision = "sign_in" | "link" | "create" | "email_verification_required" | "blocked" | "conflict";
|
|
9
|
+
/** Pure policy: persisted issuer/subject wins over a changed email; unlink markers prevent auto-link.
|
|
10
|
+
* Inbox proof is required once before auto-linking a non-authoritative address (owner 10-24). A
|
|
11
|
+
* signed-in connect is the member's own deliberate act, so it needs no extra emailed code.
|
|
12
|
+
* @returns A fixed decision; no persistence, credentials or session effects.
|
|
13
|
+
* @complexity O(1), independent of workspace/member counts.
|
|
14
|
+
*/
|
|
15
|
+
export declare function decideMemberLogin(required: {
|
|
16
|
+
identity: VerifiedLoginIdentity;
|
|
17
|
+
member: LoginLinkMember | null;
|
|
18
|
+
subjectLinked: boolean;
|
|
19
|
+
unlinked: boolean;
|
|
20
|
+
connectMemberId?: string;
|
|
21
|
+
emailProofVerified?: boolean;
|
|
22
|
+
}, _options?: Record<string, never>): LinkDecision;
|
|
23
|
+
//# sourceMappingURL=link-policy.d.ts.map
|