happy2 0.0.11 → 0.0.13
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 +10 -0
- package/package.json +2 -2
- package/packages/happy2-server/PLUGINS.md +205 -45
- package/packages/happy2-server/README.md +19 -7
- package/packages/happy2-server/dist/daemon.d.ts +39 -0
- package/packages/happy2-server/dist/daemon.d.ts.map +1 -0
- package/packages/happy2-server/dist/daemon.js +302 -0
- package/packages/happy2-server/dist/daemon.js.map +1 -0
- package/packages/happy2-server/dist/daemon.test.d.ts +2 -0
- package/packages/happy2-server/dist/daemon.test.d.ts.map +1 -0
- package/packages/happy2-server/dist/daemon.test.js +245 -0
- package/packages/happy2-server/dist/daemon.test.js.map +1 -0
- package/packages/happy2-server/dist/index.d.ts +3 -2
- package/packages/happy2-server/dist/index.d.ts.map +1 -1
- package/packages/happy2-server/dist/index.js +2 -1
- package/packages/happy2-server/dist/index.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatBind.d.ts +1 -0
- package/packages/happy2-server/dist/modules/agent/agentChatBind.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatBind.js +4 -0
- package/packages/happy2-server/dist/modules/agent/agentChatBind.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.js +3 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.d.ts +7 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.js +15 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentCreate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentCreate.js +1 -0
- package/packages/happy2-server/dist/modules/agent/agentCreate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.d.ts +4 -2
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.js +8 -8
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.d.ts +3 -3
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.js +4 -4
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.d.ts +4 -4
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.js +57 -41
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGet.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGet.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageGet.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.d.ts +2 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.js +11 -4
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageList.d.ts +2 -2
- package/packages/happy2-server/dist/modules/agent/agentImageList.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageList.js +8 -4
- package/packages/happy2-server/dist/modules/agent/agentImageList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.d.ts +4 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.js +5 -5
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.d.ts +2 -2
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.js +4 -4
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.d.ts +4 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.js +207 -9
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.d.ts +8 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.js +86 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.d.ts +19 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.js +87 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/impl/agentChatContext.d.ts +2 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentChatContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContext.d.ts +4 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.d.ts +3 -3
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.js +26 -40
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.js +63 -2
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/types.d.ts +53 -0
- package/packages/happy2-server/dist/modules/agent/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/daemon.d.ts +31 -2
- package/packages/happy2-server/dist/modules/agents/daemon.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/daemon.js +12 -2
- package/packages/happy2-server/dist/modules/agents/daemon.js.map +1 -1
- package/packages/happy2-server/dist/modules/agents/service.d.ts +13 -6
- package/packages/happy2-server/dist/modules/agents/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/service.js +497 -49
- package/packages/happy2-server/dist/modules/agents/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.d.ts +12 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.js +27 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.js.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.d.ts +8 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.js +22 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.js.map +1 -0
- package/packages/happy2-server/dist/modules/auth/methods.d.ts +1 -0
- package/packages/happy2-server/dist/modules/auth/methods.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/methods.js +10 -6
- package/packages/happy2-server/dist/modules/auth/methods.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/service.d.ts +2 -0
- package/packages/happy2-server/dist/modules/auth/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/service.js +26 -0
- package/packages/happy2-server/dist/modules/auth/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.d.ts +13 -0
- package/packages/happy2-server/dist/modules/auth/tokens.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.js +59 -0
- package/packages/happy2-server/dist/modules/auth/tokens.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.test.d.ts +2 -0
- package/packages/happy2-server/dist/modules/auth/tokens.test.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/auth/tokens.test.js +48 -0
- package/packages/happy2-server/dist/modules/auth/tokens.test.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.d.ts +17 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.js +98 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.js +13 -5
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.js.map +1 -1
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.d.ts +20 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.js +38 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/types.d.ts +6 -0
- package/packages/happy2-server/dist/modules/chat/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/types.js.map +1 -1
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.d.ts +7 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.js +19 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.d.ts +2 -2
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.js +8 -5
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.js +3 -0
- package/packages/happy2-server/dist/modules/config/defaults.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.test.js +1 -0
- package/packages/happy2-server/dist/modules/config/defaults.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.js +9 -0
- package/packages/happy2-server/dist/modules/config/loader.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.test.js +27 -0
- package/packages/happy2-server/dist/modules/config/loader.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/type.d.ts +5 -0
- package/packages/happy2-server/dist/modules/config/type.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/message/messageGetProjection.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/message/messageGetProjection.js +28 -0
- package/packages/happy2-server/dist/modules/message/messageGetProjection.js.map +1 -1
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.d.ts +4 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.js +39 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.d.ts +10 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.js +31 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.js +13 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.d.ts +16 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.js +70 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.d.ts +11 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.js +41 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleList.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/roleList.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleList.js +36 -0
- package/packages/happy2-server/dist/modules/permission/roleList.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.d.ts +14 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.js +78 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/types.d.ts +24 -0
- package/packages/happy2-server/dist/modules/permission/types.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/types.js +10 -0
- package/packages/happy2-server/dist/modules/permission/types.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.d.ts +16 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.js +33 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.js +44 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.js +12 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.js +12 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.js +46 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.js +53 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/archive.d.ts +7 -0
- package/packages/happy2-server/dist/modules/plugin/archive.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/archive.js +222 -0
- package/packages/happy2-server/dist/modules/plugin/archive.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/catalog.d.ts +5 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.js +75 -15
- package/packages/happy2-server/dist/modules/plugin/catalog.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.test.js +37 -0
- package/packages/happy2-server/dist/modules/plugin/catalog.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/httpBridge.d.ts +1 -0
- package/packages/happy2-server/dist/modules/plugin/httpBridge.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/httpBridge.js +7 -0
- package/packages/happy2-server/dist/modules/plugin/httpBridge.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.js +3 -2
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.js +17 -3
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/effectiveContainer.d.ts +3 -0
- package/packages/happy2-server/dist/modules/plugin/impl/effectiveContainer.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/impl/effectiveContainer.js +12 -0
- package/packages/happy2-server/dist/modules/plugin/impl/effectiveContainer.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/impl/installedManifest.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/installedManifest.js +11 -0
- package/packages/happy2-server/dist/modules/plugin/impl/installedManifest.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.d.ts +11 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.js +2 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/packageStore.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/packageStore.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/packageStore.js +122 -14
- package/packages/happy2-server/dist/modules/plugin/packageStore.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginCatalogList.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginCatalogList.js +15 -1
- package/packages/happy2-server/dist/modules/plugin/pluginCatalogList.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceAuthorize.d.ts +10 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceAuthorize.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceAuthorize.js +20 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceAuthorize.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceInvalidate.d.ts +12 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceInvalidate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceInvalidate.js +44 -0
- package/packages/happy2-server/dist/modules/plugin/pluginContainerInstanceInvalidate.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.d.ts +3 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.js +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.js +37 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.js +28 -9
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationGetRuntimeConfiguration.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationGetRuntimeConfiguration.js +18 -7
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationGetRuntimeConfiguration.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationListForHost.d.ts +14 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationListForHost.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationListForHost.js +20 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationListForHost.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationUpdateStatus.d.ts +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationUpdateStatus.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationUpdateStatus.js +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationUpdateStatus.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginList.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginList.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsList.d.ts +11 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsList.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsList.js +43 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsList.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsListReady.d.ts +15 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsListReady.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsListReady.js +37 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsListReady.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsReplace.d.ts +16 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsReplace.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsReplace.js +71 -0
- package/packages/happy2-server/dist/modules/plugin/pluginMcpToolsReplace.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.d.ts +8 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.js +24 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.d.ts +8 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.js +25 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.js +63 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/runtime.d.ts +20 -0
- package/packages/happy2-server/dist/modules/plugin/runtime.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/runtime.js +88 -2
- package/packages/happy2-server/dist/modules/plugin/runtime.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/service.d.ts +64 -5
- package/packages/happy2-server/dist/modules/plugin/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/service.js +552 -173
- package/packages/happy2-server/dist/modules/plugin/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/source.d.ts +35 -0
- package/packages/happy2-server/dist/modules/plugin/source.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/source.js +189 -0
- package/packages/happy2-server/dist/modules/plugin/source.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/types.d.ts +87 -11
- package/packages/happy2-server/dist/modules/plugin/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/types.js +1 -0
- package/packages/happy2-server/dist/modules/plugin/types.js.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/events.d.ts +3 -0
- package/packages/happy2-server/dist/modules/realtime/events.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/events.js +37 -5
- package/packages/happy2-server/dist/modules/realtime/events.js.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/local.test.js +2 -0
- package/packages/happy2-server/dist/modules/realtime/local.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/index.d.ts +1 -1
- package/packages/happy2-server/dist/modules/sandbox/index.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.d.ts +8 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.js +105 -3
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.test.js +82 -3
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/types.d.ts +17 -0
- package/packages/happy2-server/dist/modules/sandbox/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/schema.d.ts +2245 -233
- package/packages/happy2-server/dist/modules/schema.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/schema.js +120 -0
- package/packages/happy2-server/dist/modules/schema.js.map +1 -1
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.js +2 -0
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationList.js +2 -2
- package/packages/happy2-server/dist/modules/user/userAdministrationList.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.js +49 -6
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userCreateProfile.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/user/userCreateProfile.js +17 -2
- package/packages/happy2-server/dist/modules/user/userCreateProfile.js.map +1 -1
- package/packages/happy2-server/dist/routes/agents.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/agents.js +4 -2
- package/packages/happy2-server/dist/routes/agents.js.map +1 -1
- package/packages/happy2-server/dist/routes/auth.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/auth.js +12 -0
- package/packages/happy2-server/dist/routes/auth.js.map +1 -1
- package/packages/happy2-server/dist/routes/collaboration.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/collaboration.js +7 -0
- package/packages/happy2-server/dist/routes/collaboration.js.map +1 -1
- package/packages/happy2-server/dist/routes/files.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/files.js +2 -0
- package/packages/happy2-server/dist/routes/files.js.map +1 -1
- package/packages/happy2-server/dist/routes/permissions.d.ts +6 -0
- package/packages/happy2-server/dist/routes/permissions.d.ts.map +1 -0
- package/packages/happy2-server/dist/routes/permissions.js +207 -0
- package/packages/happy2-server/dist/routes/permissions.js.map +1 -0
- package/packages/happy2-server/dist/routes/pluginHost.d.ts +6 -0
- package/packages/happy2-server/dist/routes/pluginHost.d.ts.map +1 -0
- package/packages/happy2-server/dist/routes/pluginHost.js +106 -0
- package/packages/happy2-server/dist/routes/pluginHost.js.map +1 -0
- package/packages/happy2-server/dist/routes/plugins.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/plugins.js +159 -5
- package/packages/happy2-server/dist/routes/plugins.js.map +1 -1
- package/packages/happy2-server/dist/runner.js +20 -1
- package/packages/happy2-server/dist/runner.js.map +1 -1
- package/packages/happy2-server/dist/server.d.ts +4 -0
- package/packages/happy2-server/dist/server.d.ts.map +1 -1
- package/packages/happy2-server/dist/server.js +23 -1
- package/packages/happy2-server/dist/server.js.map +1 -1
- package/packages/happy2-server/dist/systemService.d.ts.map +1 -1
- package/packages/happy2-server/dist/systemService.js +16 -1
- package/packages/happy2-server/dist/systemService.js.map +1 -1
- package/packages/happy2-server/dist/systemService.test.js +15 -1
- package/packages/happy2-server/dist/systemService.test.js.map +1 -1
- package/packages/happy2-server/dist/web/assets/index-BaPUPGPe.css +2 -0
- package/packages/happy2-server/dist/web/assets/index-BnhFxR3U.js +39 -0
- package/packages/happy2-server/dist/web/index.html +2 -2
- package/packages/happy2-server/drizzle/0022_plugin_container_runtime_tools.sql +16 -0
- package/packages/happy2-server/drizzle/0023_roles_and_permissions.sql +82 -0
- package/packages/happy2-server/drizzle/0024_session_bound_dev_tokens.sql +11 -0
- package/packages/happy2-server/drizzle/0025_plugin_skills.sql +8 -0
- package/packages/happy2-server/drizzle/0026_agent_turn_traces.sql +35 -0
- package/packages/happy2-server/drizzle/0027_chat_agent_effort.sql +9 -0
- package/packages/happy2-server/drizzle/meta/_journal.json +42 -0
- package/packages/happy2-server/happy2.example.toml +14 -0
- package/packages/happy2-server/plugins/README.md +3 -1
- package/packages/happy2-server/plugins/chat-management/container/Dockerfile +6 -0
- package/packages/happy2-server/plugins/chat-management/plugin.json +17 -0
- package/packages/happy2-server/plugins/chat-management/plugin.png +0 -0
- package/packages/happy2-server/plugins/chat-management/server.mjs +113 -0
- package/packages/happy2-server/dist/web/assets/index-9SGCQLg7.js +0 -46
- package/packages/happy2-server/dist/web/assets/index-DWXBQDJB.css +0 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
import { CollaborationError } from "../chat/types.js";
|
|
4
|
+
import { isUniqueConstraint } from "../chat/isUniqueConstraint.js";
|
|
5
|
+
import { chatAppendAudit } from "../chat/chatAppendAudit.js";
|
|
6
|
+
import { withTransaction } from "../drizzle.js";
|
|
7
|
+
import { rolePermissions, roles } from "../schema.js";
|
|
8
|
+
import { permissionMutationRecord } from "./impl/permissionMutationRecord.js";
|
|
9
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a custom roles row and its complete rolePermissions allow-list in one transaction, recording audit and sync evidence for management clients.
|
|
12
|
+
* The action owns role-name uniqueness and grant persistence so no partially configured role can become assignable.
|
|
13
|
+
*/
|
|
14
|
+
export async function roleCreate(executor, input) {
|
|
15
|
+
return withTransaction(executor, async (tx) => {
|
|
16
|
+
await userRequirePermission(tx, input.actorUserId, "manageAdminRoles");
|
|
17
|
+
const [existing] = await tx
|
|
18
|
+
.select({ id: roles.id })
|
|
19
|
+
.from(roles)
|
|
20
|
+
.where(sql `lower(${roles.name}) = lower(${input.name})`)
|
|
21
|
+
.limit(1);
|
|
22
|
+
if (existing)
|
|
23
|
+
throw new CollaborationError("conflict", "A role with this name exists");
|
|
24
|
+
const id = createId();
|
|
25
|
+
try {
|
|
26
|
+
await tx.insert(roles).values({
|
|
27
|
+
id,
|
|
28
|
+
name: input.name,
|
|
29
|
+
description: input.description ?? null,
|
|
30
|
+
createdByUserId: input.actorUserId,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (isUniqueConstraint(error))
|
|
35
|
+
throw new CollaborationError("conflict", "A role with this name exists");
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
if (input.permissions.length)
|
|
39
|
+
await tx.insert(rolePermissions).values(input.permissions.map((permission) => ({
|
|
40
|
+
roleId: id,
|
|
41
|
+
permission,
|
|
42
|
+
})));
|
|
43
|
+
await chatAppendAudit(tx, {
|
|
44
|
+
actorUserId: input.actorUserId,
|
|
45
|
+
action: "role.created",
|
|
46
|
+
targetType: "role",
|
|
47
|
+
targetId: id,
|
|
48
|
+
after: { name: input.name, permissions: input.permissions },
|
|
49
|
+
});
|
|
50
|
+
const mutation = await permissionMutationRecord(tx, {
|
|
51
|
+
actorUserId: input.actorUserId,
|
|
52
|
+
affectedUserIds: [],
|
|
53
|
+
broadcast: true,
|
|
54
|
+
entityId: id,
|
|
55
|
+
kind: "role.created",
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
role: {
|
|
59
|
+
id,
|
|
60
|
+
name: input.name,
|
|
61
|
+
...(input.description ? { description: input.description } : {}),
|
|
62
|
+
builtin: null,
|
|
63
|
+
permissions: input.permissions,
|
|
64
|
+
userIds: [],
|
|
65
|
+
},
|
|
66
|
+
mutation,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=roleCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleCreate.js","sourceRoot":"","sources":["../../../sources/modules/permission/roleCreate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAwB,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC5B,QAAyB,EACzB,KAKC;IAED,OAAO,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QAC1C,MAAM,qBAAqB,CAAC,EAAE,EAAE,KAAK,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACvE,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,EAAE;aACtB,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;aACxB,IAAI,CAAC,KAAK,CAAC;aACX,KAAK,CAAC,GAAG,CAAA,SAAS,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,IAAI,GAAG,CAAC;aACvD,KAAK,CAAC,CAAC,CAAC,CAAC;QACd,IAAI,QAAQ;YAAE,MAAM,IAAI,kBAAkB,CAAC,UAAU,EAAE,8BAA8B,CAAC,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I,EAAE,KAAK,CAAC,IAAI;gBAChB,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChE,OAAO,EAAE,IAAI;gBACb,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,OAAO,EAAE,EAAE;aACd;YACD,QAAQ;SACX,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { PermissionMutation } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Deletes one custom roles row and its cascading grants and assignments while refusing either durable built-in marker.
|
|
5
|
+
* Capturing affected users before deletion allows the same commit to notify every client whose effective permissions changed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function roleDelete(executor: DrizzleExecutor, input: {
|
|
8
|
+
actorUserId: string;
|
|
9
|
+
roleId: string;
|
|
10
|
+
}): Promise<PermissionMutation>;
|
|
11
|
+
//# sourceMappingURL=roleDelete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleDelete.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/roleDelete.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGrD;;;GAGG;AACH,wBAAsB,UAAU,CAC5B,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/C,OAAO,CAAC,kBAAkB,CAAC,CA6B7B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { chatAppendAudit } from "../chat/chatAppendAudit.js";
|
|
3
|
+
import { CollaborationError } from "../chat/types.js";
|
|
4
|
+
import { withTransaction } from "../drizzle.js";
|
|
5
|
+
import { roles, userRoles } from "../schema.js";
|
|
6
|
+
import { permissionMutationRecord } from "./impl/permissionMutationRecord.js";
|
|
7
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
8
|
+
/**
|
|
9
|
+
* Deletes one custom roles row and its cascading grants and assignments while refusing either durable built-in marker.
|
|
10
|
+
* Capturing affected users before deletion allows the same commit to notify every client whose effective permissions changed.
|
|
11
|
+
*/
|
|
12
|
+
export async function roleDelete(executor, input) {
|
|
13
|
+
return withTransaction(executor, async (tx) => {
|
|
14
|
+
await userRequirePermission(tx, input.actorUserId, "manageAdminRoles");
|
|
15
|
+
const [role] = await tx.select().from(roles).where(eq(roles.id, input.roleId)).limit(1);
|
|
16
|
+
if (!role)
|
|
17
|
+
throw new CollaborationError("not_found", "Role was not found");
|
|
18
|
+
if (role.builtinKind)
|
|
19
|
+
throw new CollaborationError("invalid", "Built-in roles cannot be deleted");
|
|
20
|
+
const affectedUserIds = (await tx
|
|
21
|
+
.select({ userId: userRoles.userId })
|
|
22
|
+
.from(userRoles)
|
|
23
|
+
.where(eq(userRoles.roleId, input.roleId))).map(({ userId }) => userId);
|
|
24
|
+
await tx.delete(roles).where(eq(roles.id, input.roleId));
|
|
25
|
+
await chatAppendAudit(tx, {
|
|
26
|
+
actorUserId: input.actorUserId,
|
|
27
|
+
action: "role.deleted",
|
|
28
|
+
targetType: "role",
|
|
29
|
+
targetId: input.roleId,
|
|
30
|
+
before: { name: role.name },
|
|
31
|
+
});
|
|
32
|
+
return permissionMutationRecord(tx, {
|
|
33
|
+
actorUserId: input.actorUserId,
|
|
34
|
+
affectedUserIds,
|
|
35
|
+
broadcast: true,
|
|
36
|
+
entityId: input.roleId,
|
|
37
|
+
kind: "permissions.changed",
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=roleDelete.js.map
|
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CAAC,SAAS,CAAC;aACf,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CACjD,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACzD,MAAM,eAAe,CAAC,EAAE,EAAE;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;SAC9B,CAAC,CAAC;QACH,OAAO,wBAAwB,CAAC,EAAE,EAAE;YAChC,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,eAAe;YACf,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,IAAI,EAAE,qBAAqB;SAC9B,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import { type RoleSummary } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Lists every custom and built-in role with its grants and assigned users for an actor allowed to administer role membership.
|
|
5
|
+
* Returning built-in markers from durable rows lets clients preserve the undeletable admin/member identities after either role is renamed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function roleList(executor: DrizzleExecutor, actorUserId: string): Promise<RoleSummary[]>;
|
|
8
|
+
//# sourceMappingURL=roleList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleList.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/roleList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,QAAQ,CAC1B,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,WAAW,EAAE,CAAC,CA6BxB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { rolePermissions, roles, userRoles } from "../schema.js";
|
|
2
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
3
|
+
import { permissions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lists every custom and built-in role with its grants and assigned users for an actor allowed to administer role membership.
|
|
6
|
+
* Returning built-in markers from durable rows lets clients preserve the undeletable admin/member identities after either role is renamed.
|
|
7
|
+
*/
|
|
8
|
+
export async function roleList(executor, actorUserId) {
|
|
9
|
+
await userRequirePermission(executor, actorUserId, "manageAdminRoles");
|
|
10
|
+
const [roleRows, permissionRows, assignmentRows] = await Promise.all([
|
|
11
|
+
executor.select().from(roles).orderBy(roles.createdAt, roles.id),
|
|
12
|
+
executor
|
|
13
|
+
.select({ roleId: rolePermissions.roleId, permission: rolePermissions.permission })
|
|
14
|
+
.from(rolePermissions),
|
|
15
|
+
executor
|
|
16
|
+
.select({ roleId: userRoles.roleId, userId: userRoles.userId })
|
|
17
|
+
.from(userRoles)
|
|
18
|
+
.orderBy(userRoles.createdAt, userRoles.userId),
|
|
19
|
+
]);
|
|
20
|
+
return roleRows.map((role) => {
|
|
21
|
+
const granted = new Set(permissionRows
|
|
22
|
+
.filter(({ roleId }) => roleId === role.id)
|
|
23
|
+
.map(({ permission }) => permission));
|
|
24
|
+
return {
|
|
25
|
+
id: role.id,
|
|
26
|
+
name: role.name,
|
|
27
|
+
...(role.description ? { description: role.description } : {}),
|
|
28
|
+
builtin: role.builtinKind,
|
|
29
|
+
permissions: permissions.filter((permission) => granted.has(permission)),
|
|
30
|
+
userIds: assignmentRows
|
|
31
|
+
.filter(({ roleId }) => roleId === role.id)
|
|
32
|
+
.map(({ userId }) => userId),
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=roleList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleList.js","sourceRoot":"","sources":["../../../sources/modules/permission/roleList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAqC,MAAM,YAAY,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC1B,QAAyB,EACzB,WAAmB;IAEnB,MAAM,qBAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACjE,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC;QAChE,QAAQ;aACH,MAAM,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,eAAe,CAAC,UAAU,EAAE,CAAC;aAClF,IAAI,CAAC,eAAe,CAAC;QAC1B,QAAQ;aACH,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;aAC9D,IAAI,CAAC,SAAS,CAAC;aACf,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC;KACtD,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,IAAI,GAAG,CACnB,cAAc;aACT,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;aAC1C,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAwB,CAAC,CACzD,CAAC;QACF,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9D,OAAO,EAAE,IAAI,CAAC,WAAqC;YACnD,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACxE,OAAO,EAAE,cAAc;iBAClB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;iBAC1C,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC;SACnC,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { Permission, PermissionMutation } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Updates a roles row's editable metadata and optional complete rolePermissions allow-list while preserving its immutable built-in marker.
|
|
5
|
+
* Permission changes notify every assigned user in the same transaction so their clients can immediately refetch `/v0/me`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function roleUpdate(executor: DrizzleExecutor, input: {
|
|
8
|
+
actorUserId: string;
|
|
9
|
+
roleId: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
description?: string | null;
|
|
12
|
+
permissions?: Permission[];
|
|
13
|
+
}): Promise<PermissionMutation>;
|
|
14
|
+
//# sourceMappingURL=roleUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleUpdate.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/roleUpdate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGjE;;;GAGG;AACH,wBAAsB,UAAU,CAC5B,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC9B,GACF,OAAO,CAAC,kBAAkB,CAAC,CAoE7B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { eq, sql } from "drizzle-orm";
|
|
2
|
+
import { chatAppendAudit } from "../chat/chatAppendAudit.js";
|
|
3
|
+
import { CollaborationError } from "../chat/types.js";
|
|
4
|
+
import { isUniqueConstraint } from "../chat/isUniqueConstraint.js";
|
|
5
|
+
import { withTransaction } from "../drizzle.js";
|
|
6
|
+
import { rolePermissions, roles, userRoles } from "../schema.js";
|
|
7
|
+
import { permissionMutationRecord } from "./impl/permissionMutationRecord.js";
|
|
8
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
9
|
+
/**
|
|
10
|
+
* Updates a roles row's editable metadata and optional complete rolePermissions allow-list while preserving its immutable built-in marker.
|
|
11
|
+
* Permission changes notify every assigned user in the same transaction so their clients can immediately refetch `/v0/me`.
|
|
12
|
+
*/
|
|
13
|
+
export async function roleUpdate(executor, input) {
|
|
14
|
+
return withTransaction(executor, async (tx) => {
|
|
15
|
+
await userRequirePermission(tx, input.actorUserId, "manageAdminRoles");
|
|
16
|
+
const [role] = await tx.select().from(roles).where(eq(roles.id, input.roleId)).limit(1);
|
|
17
|
+
if (!role)
|
|
18
|
+
throw new CollaborationError("not_found", "Role was not found");
|
|
19
|
+
if (input.name !== undefined) {
|
|
20
|
+
const [duplicate] = await tx
|
|
21
|
+
.select({ id: roles.id })
|
|
22
|
+
.from(roles)
|
|
23
|
+
.where(sql `${roles.id} <> ${input.roleId} AND lower(${roles.name}) = lower(${input.name})`)
|
|
24
|
+
.limit(1);
|
|
25
|
+
if (duplicate)
|
|
26
|
+
throw new CollaborationError("conflict", "A role with this name exists");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await tx
|
|
30
|
+
.update(roles)
|
|
31
|
+
.set({
|
|
32
|
+
...(input.name === undefined ? {} : { name: input.name }),
|
|
33
|
+
...(input.description === undefined ? {} : { description: input.description }),
|
|
34
|
+
updatedAt: new Date().toISOString(),
|
|
35
|
+
})
|
|
36
|
+
.where(eq(roles.id, input.roleId));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (isUniqueConstraint(error))
|
|
40
|
+
throw new CollaborationError("conflict", "A role with this name exists");
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
if (input.permissions !== undefined) {
|
|
44
|
+
await tx.delete(rolePermissions).where(eq(rolePermissions.roleId, input.roleId));
|
|
45
|
+
if (input.permissions.length)
|
|
46
|
+
await tx.insert(rolePermissions).values(input.permissions.map((permission) => ({
|
|
47
|
+
roleId: input.roleId,
|
|
48
|
+
permission,
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
const affectedUserIds = input.permissions === undefined
|
|
52
|
+
? []
|
|
53
|
+
: (await tx
|
|
54
|
+
.select({ userId: userRoles.userId })
|
|
55
|
+
.from(userRoles)
|
|
56
|
+
.where(eq(userRoles.roleId, input.roleId))).map(({ userId }) => userId);
|
|
57
|
+
await chatAppendAudit(tx, {
|
|
58
|
+
actorUserId: input.actorUserId,
|
|
59
|
+
action: "role.updated",
|
|
60
|
+
targetType: "role",
|
|
61
|
+
targetId: input.roleId,
|
|
62
|
+
before: { name: role.name, description: role.description },
|
|
63
|
+
after: {
|
|
64
|
+
name: input.name,
|
|
65
|
+
description: input.description,
|
|
66
|
+
permissions: input.permissions,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return permissionMutationRecord(tx, {
|
|
70
|
+
actorUserId: input.actorUserId,
|
|
71
|
+
affectedUserIds,
|
|
72
|
+
broadcast: true,
|
|
73
|
+
entityId: input.roleId,
|
|
74
|
+
kind: input.permissions === undefined ? "role.updated" : "permissions.changed",
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=roleUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleUpdate.js","sourceRoot":"","sources":["../../../sources/modules/permission/roleUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAwB,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC5B,QAAyB,EACzB,KAMC;IAED,OAAO,eAAe,CAAC,QAAQ,EAAE,K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E,EAAE;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;YAC1D,KAAK,EAAE;gBACH,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;aACjC;SACJ,CAAC,CAAC;QACH,OAAO,wBAAwB,CAAC,EAAE,EAAE;YAChC,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,eAAe;YACf,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,IAAI,EAAE,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,qBAAqB;SACjF,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const permissions: readonly ["manageSecrets", "assignSecrets", "manageImages", "assignImagesToChats", "managePlugins", "viewAllMembers", "manageAdminRoles"];
|
|
2
|
+
export type Permission = (typeof permissions)[number];
|
|
3
|
+
export interface EffectivePermissions {
|
|
4
|
+
allowed: Permission[];
|
|
5
|
+
owner: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface RoleSummary {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
builtin: "admin" | "member" | null;
|
|
12
|
+
permissions: Permission[];
|
|
13
|
+
userIds: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface PermissionMutation {
|
|
16
|
+
affectedUserIds: string[];
|
|
17
|
+
broadcast: boolean;
|
|
18
|
+
sync: {
|
|
19
|
+
sequence: string;
|
|
20
|
+
chats: [];
|
|
21
|
+
areas: ["permissions"];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,YACpB,eAAe,EACf,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,CACZ,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE;QACF,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,EAAE,CAAC;QACV,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC;KAC1B,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../sources/modules/permission/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,eAAe;IACf,eAAe;IACf,cAAc;IACd,qBAAqB;IACrB,eAAe;IACf,gBAAgB;IAChB,kBAAkB;CACZ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import { permissionGetEffective } from "./permissionGetEffective.js";
|
|
3
|
+
import { type Permission } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns one active user's direct grants, assigned role identifiers, and effective permission projection to an authorized role administrator.
|
|
6
|
+
* Keeping direct and inherited state distinct lets management clients edit explicit grants without accidentally flattening role membership.
|
|
7
|
+
*/
|
|
8
|
+
export declare function userPermissionGet(executor: DrizzleExecutor, input: {
|
|
9
|
+
actorUserId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
direct: Permission[];
|
|
13
|
+
roleIds: string[];
|
|
14
|
+
effective: Awaited<ReturnType<typeof permissionGetEffective>>;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=userPermissionGet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userPermissionGet.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/userPermissionGet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;GAGG;AACH,wBAAsB,iBAAiB,CACnC,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/C,OAAO,CAAC;IACP,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC;CACjE,CAAC,CAuBD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { userRequireActiveHuman } from "../chat/userRequireActiveHuman.js";
|
|
3
|
+
import { userPermissions, userRoles } from "../schema.js";
|
|
4
|
+
import { permissionGetEffective } from "./permissionGetEffective.js";
|
|
5
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
6
|
+
import { permissions } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Returns one active user's direct grants, assigned role identifiers, and effective permission projection to an authorized role administrator.
|
|
9
|
+
* Keeping direct and inherited state distinct lets management clients edit explicit grants without accidentally flattening role membership.
|
|
10
|
+
*/
|
|
11
|
+
export async function userPermissionGet(executor, input) {
|
|
12
|
+
await userRequirePermission(executor, input.actorUserId, "manageAdminRoles");
|
|
13
|
+
await userRequireActiveHuman(executor, input.userId);
|
|
14
|
+
const [directRows, roleRows, effective] = await Promise.all([
|
|
15
|
+
executor
|
|
16
|
+
.select({ permission: userPermissions.permission })
|
|
17
|
+
.from(userPermissions)
|
|
18
|
+
.where(eq(userPermissions.userId, input.userId)),
|
|
19
|
+
executor
|
|
20
|
+
.select({ roleId: userRoles.roleId })
|
|
21
|
+
.from(userRoles)
|
|
22
|
+
.where(eq(userRoles.userId, input.userId))
|
|
23
|
+
.orderBy(userRoles.createdAt, userRoles.roleId),
|
|
24
|
+
permissionGetEffective(executor, input.userId),
|
|
25
|
+
]);
|
|
26
|
+
const directSet = new Set(directRows.map(({ permission }) => permission));
|
|
27
|
+
return {
|
|
28
|
+
direct: permissions.filter((permission) => directSet.has(permission)),
|
|
29
|
+
roleIds: roleRows.map(({ roleId }) => roleId),
|
|
30
|
+
effective,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=userPermissionGet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userPermissionGet.js","sourceRoot":"","sources":["../../../sources/modules/permission/userPermissionGet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,s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CAAC;IACF,OAAO;QACH,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrE,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC;QAC7C,SAAS;KACZ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { Permission, PermissionMutation } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Replaces an active user's complete userPermissions allow-list without altering grants inherited from assigned roles.
|
|
5
|
+
* The replacement and targeted invalidation share one transaction so `/v0/me` can be safely refetched as soon as clients receive the hint.
|
|
6
|
+
*/
|
|
7
|
+
export declare function userPermissionUpdate(executor: DrizzleExecutor, input: {
|
|
8
|
+
actorUserId: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
permissions: Permission[];
|
|
11
|
+
}): Promise<PermissionMutation>;
|
|
12
|
+
//# sourceMappingURL=userPermissionUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userPermissionUpdate.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/userPermissionUpdate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGjE;;;GAGG;AACH,wBAAsB,oBAAoB,CACtC,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,GAC1E,OAAO,CAAC,kBAAkB,CAAC,CAiC7B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { chatAppendAudit } from "../chat/chatAppendAudit.js";
|
|
3
|
+
import { userRequireActiveHuman } from "../chat/userRequireActiveHuman.js";
|
|
4
|
+
import { withTransaction } from "../drizzle.js";
|
|
5
|
+
import { userPermissions } from "../schema.js";
|
|
6
|
+
import { permissionMutationRecord } from "./impl/permissionMutationRecord.js";
|
|
7
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
8
|
+
/**
|
|
9
|
+
* Replaces an active user's complete userPermissions allow-list without altering grants inherited from assigned roles.
|
|
10
|
+
* The replacement and targeted invalidation share one transaction so `/v0/me` can be safely refetched as soon as clients receive the hint.
|
|
11
|
+
*/
|
|
12
|
+
export async function userPermissionUpdate(executor, input) {
|
|
13
|
+
return withTransaction(executor, async (tx) => {
|
|
14
|
+
await userRequirePermission(tx, input.actorUserId, "manageAdminRoles");
|
|
15
|
+
await userRequireActiveHuman(tx, input.userId);
|
|
16
|
+
const before = await tx
|
|
17
|
+
.select({ permission: userPermissions.permission })
|
|
18
|
+
.from(userPermissions)
|
|
19
|
+
.where(eq(userPermissions.userId, input.userId));
|
|
20
|
+
await tx.delete(userPermissions).where(eq(userPermissions.userId, input.userId));
|
|
21
|
+
if (input.permissions.length)
|
|
22
|
+
await tx.insert(userPermissions).values(input.permissions.map((permission) => ({
|
|
23
|
+
userId: input.userId,
|
|
24
|
+
permission,
|
|
25
|
+
grantedByUserId: input.actorUserId,
|
|
26
|
+
})));
|
|
27
|
+
await chatAppendAudit(tx, {
|
|
28
|
+
actorUserId: input.actorUserId,
|
|
29
|
+
action: "user.permissions_updated",
|
|
30
|
+
targetType: "user",
|
|
31
|
+
targetId: input.userId,
|
|
32
|
+
before: { permissions: before.map(({ permission }) => permission) },
|
|
33
|
+
after: { permissions: input.permissions },
|
|
34
|
+
});
|
|
35
|
+
return permissionMutationRecord(tx, {
|
|
36
|
+
actorUserId: input.actorUserId,
|
|
37
|
+
affectedUserIds: [input.userId],
|
|
38
|
+
broadcast: false,
|
|
39
|
+
entityId: input.userId,
|
|
40
|
+
kind: "permissions.changed",
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=userPermissionUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userPermissionUpdate.js","sourceRoot":"","sources":["../../../sources/modules/permission/userPermissionUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAwB,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,QAAyB,EACzB,KAAyE;IAEzE,OAAO,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QAC1C,MAAM,qBAAqB,CAAC,EAAE,EAAE,KAAK,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACvE,MAAM,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,MAAM,EAAE;aAClB,MAAM,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,UAAU,EAAE,CAAC;aAClD,IAAI,CAAC,eAAe,CAAC;aACrB,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACjF,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM;YACxB,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CACnC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;gBACnC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,UAAU;gBACV,eAAe,EAAE,KAAK,CAAC,WAAW;aACrC,CAAC,CAAC,CACN,CAAC;QACN,MAAM,eAAe,CAAC,EAAE,EAAE;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,0BAA0B;YAClC,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE;YACnE,KAAK,EAAE,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE;SAC5C,CAAC,CAAC;QACH,OAAO,wBAAwB,CAAC,EAAE,EAAE;YAChC,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,eAAe,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;YAC/B,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,IAAI,EAAE,qBAAqB;SAC9B,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { Permission } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Requires at least one permission from an explicit set for shared read surfaces used by adjacent management capabilities.
|
|
5
|
+
* The owner remains allow-all, while ordinary users must receive one listed grant directly or through a role.
|
|
6
|
+
*/
|
|
7
|
+
export declare function userRequireAnyPermission(executor: DrizzleExecutor, userId: string, required: readonly Permission[]): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=userRequireAnyPermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRequireAnyPermission.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/userRequireAnyPermission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,wBAAwB,CAC1C,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,UAAU,EAAE,GAChC,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CollaborationError } from "../chat/types.js";
|
|
2
|
+
import { permissionEffectiveDb } from "./impl/permissionEffectiveDb.js";
|
|
3
|
+
/**
|
|
4
|
+
* Requires at least one permission from an explicit set for shared read surfaces used by adjacent management capabilities.
|
|
5
|
+
* The owner remains allow-all, while ordinary users must receive one listed grant directly or through a role.
|
|
6
|
+
*/
|
|
7
|
+
export async function userRequireAnyPermission(executor, userId, required) {
|
|
8
|
+
const effective = await permissionEffectiveDb(executor, userId);
|
|
9
|
+
if (!effective || !required.some((permission) => effective.allowed.includes(permission)))
|
|
10
|
+
throw new CollaborationError("forbidden", `${required.join(" or ")} permission is required`);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=userRequireAnyPermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRequireAnyPermission.js","sourceRoot":"","sources":["../../../sources/modules/permission/userRequireAnyPermission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC1C,QAAyB,EACzB,MAAc,EACd,QAA+B;IAE/B,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChE,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpF,MAAM,IAAI,kBAAkB,CACxB,WAAW,EACX,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CACpD,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { Permission } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Requires one effective permission from an active human user, treating the durable server owner as an explicit allow-all principal.
|
|
5
|
+
* Centralizing this check prevents feature routes from confusing legacy administrator labels with narrowly delegated authority.
|
|
6
|
+
*/
|
|
7
|
+
export declare function userRequirePermission(executor: DrizzleExecutor, userId: string, permission: Permission): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=userRequirePermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRequirePermission.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/userRequirePermission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,qBAAqB,CACvC,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GACvB,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CollaborationError } from "../chat/types.js";
|
|
2
|
+
import { permissionEffectiveDb } from "./impl/permissionEffectiveDb.js";
|
|
3
|
+
/**
|
|
4
|
+
* Requires one effective permission from an active human user, treating the durable server owner as an explicit allow-all principal.
|
|
5
|
+
* Centralizing this check prevents feature routes from confusing legacy administrator labels with narrowly delegated authority.
|
|
6
|
+
*/
|
|
7
|
+
export async function userRequirePermission(executor, userId, permission) {
|
|
8
|
+
const effective = await permissionEffectiveDb(executor, userId);
|
|
9
|
+
if (!effective?.allowed.includes(permission))
|
|
10
|
+
throw new CollaborationError("forbidden", `${permission} permission is required`);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=userRequirePermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRequirePermission.js","sourceRoot":"","sources":["../../../sources/modules/permission/userRequirePermission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACvC,QAAyB,EACzB,MAAc,EACd,UAAsB;IAEtB,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;QACxC,MAAM,IAAI,kBAAkB,CAAC,WAAW,EAAE,GAAG,UAAU,yBAAyB,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DrizzleExecutor } from "../drizzle.js";
|
|
2
|
+
import type { PermissionMutation } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Inserts one userRoles assignment for an active human user, synchronizing users when the durable admin marker is assigned.
|
|
5
|
+
* The grant, audit record, and targeted permission invalidation commit atomically so authorization never changes silently.
|
|
6
|
+
*/
|
|
7
|
+
export declare function userRoleAssign(executor: DrizzleExecutor, input: {
|
|
8
|
+
actorUserId: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
roleId: string;
|
|
11
|
+
}): Promise<PermissionMutation>;
|
|
12
|
+
//# sourceMappingURL=userRoleAssign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRoleAssign.d.ts","sourceRoot":"","sources":["../../../sources/modules/permission/userRoleAssign.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGrD;;;GAGG;AACH,wBAAsB,cAAc,CAChC,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAAC,kBAAkB,CAAC,CA+B7B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { chatAppendAudit } from "../chat/chatAppendAudit.js";
|
|
3
|
+
import { CollaborationError } from "../chat/types.js";
|
|
4
|
+
import { userRequireActiveHuman } from "../chat/userRequireActiveHuman.js";
|
|
5
|
+
import { withTransaction } from "../drizzle.js";
|
|
6
|
+
import { roles, userRoles, users } from "../schema.js";
|
|
7
|
+
import { permissionMutationRecord } from "./impl/permissionMutationRecord.js";
|
|
8
|
+
import { userRequirePermission } from "./userRequirePermission.js";
|
|
9
|
+
/**
|
|
10
|
+
* Inserts one userRoles assignment for an active human user, synchronizing users when the durable admin marker is assigned.
|
|
11
|
+
* The grant, audit record, and targeted permission invalidation commit atomically so authorization never changes silently.
|
|
12
|
+
*/
|
|
13
|
+
export async function userRoleAssign(executor, input) {
|
|
14
|
+
return withTransaction(executor, async (tx) => {
|
|
15
|
+
await userRequirePermission(tx, input.actorUserId, "manageAdminRoles");
|
|
16
|
+
await userRequireActiveHuman(tx, input.userId);
|
|
17
|
+
const [role] = await tx.select().from(roles).where(eq(roles.id, input.roleId)).limit(1);
|
|
18
|
+
if (!role)
|
|
19
|
+
throw new CollaborationError("not_found", "Role was not found");
|
|
20
|
+
await tx
|
|
21
|
+
.insert(userRoles)
|
|
22
|
+
.values({
|
|
23
|
+
userId: input.userId,
|
|
24
|
+
roleId: input.roleId,
|
|
25
|
+
assignedByUserId: input.actorUserId,
|
|
26
|
+
})
|
|
27
|
+
.onConflictDoNothing();
|
|
28
|
+
if (role.builtinKind === "admin")
|
|
29
|
+
await tx.update(users).set({ role: "admin" }).where(eq(users.id, input.userId));
|
|
30
|
+
await chatAppendAudit(tx, {
|
|
31
|
+
actorUserId: input.actorUserId,
|
|
32
|
+
action: "user.role_assigned",
|
|
33
|
+
targetType: "user",
|
|
34
|
+
targetId: input.userId,
|
|
35
|
+
after: { roleId: input.roleId },
|
|
36
|
+
});
|
|
37
|
+
return permissionMutationRecord(tx, {
|
|
38
|
+
actorUserId: input.actorUserId,
|
|
39
|
+
affectedUserIds: [input.userId],
|
|
40
|
+
broadcast: false,
|
|
41
|
+
entityId: input.userId,
|
|
42
|
+
kind: "permissions.changed",
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=userRoleAssign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userRoleAssign.js","sourceRoot":"","sources":["../../../sources/modules/permission/userRoleAssign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAwB,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,KAAK,E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