UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 1.16 kB
//!src/gateway/server-methods/device-management-authz.ts function resolveDeviceSessionAuthz(e){const t=e?.connect.scopes??[];return{callerDeviceId:e?.isDeviceTokenAuth?e.connect.device?.id.trim()||null:null,callerScopes:t,isAdminCaller:t.includes(`operator.admin`)}}function resolveDeviceManagementAuthz(e,t){return{...resolveDeviceSessionAuthz(e),normalizedTargetDeviceId:t.trim()}}function deniesCrossDeviceManagement(e){return Boolean(e.callerDeviceId&&e.callerDeviceId!==e.normalizedTargetDeviceId&&!e.isAdminCaller)}function deniesDeviceTokenRoleManagement(e,t){return!e.isAdminCaller&&requestsNonOperatorDeviceRole({role:t})}function requestsNonOperatorDeviceRole(e){return[e.role,...e.roles??[]].some(e=>{const t=e?.trim();return Boolean(t&&t!==`operator`)})}function pairedDeviceHasNonOperatorRole(e){return requestsNonOperatorDeviceRole(e)||Object.values(e.tokens??{}).some(e=>{const t=e.role.trim();return Boolean(t&&t!==`operator`)})}export{resolveDeviceManagementAuthz as a,requestsNonOperatorDeviceRole as i,deniesDeviceTokenRoleManagement as n,resolveDeviceSessionAuthz as o,pairedDeviceHasNonOperatorRole as r,deniesCrossDeviceManagement as t};