import type { Context } from 'hono'; import { type RouteContext, type Store } from '../core/index.js'; import type { WorkOSStore } from './store.js'; import type { WorkOSRole, WorkOSPermission } from './entities.js'; import { type BodyRules } from './authorization-validation.js'; export declare function findEnvRole(ws: WorkOSStore, slug: string): WorkOSRole | undefined; export declare function findOrgRole(ws: WorkOSStore, orgId: string, slug: string): WorkOSRole | undefined; /** * Resolve the role a membership's role slug refers to within an organization. * An organization role shadows an environment role with the same slug. Matches * on organization_id rather than type: seeded roles can carry an organization_id * with the type defaulted to EnvironmentRole — which is also why the environment * fallback requires a null organization_id, so another organization's seeded * role can never leak across the boundary. */ export declare function resolvePrimaryRole(ws: WorkOSStore, organizationId: string, slug: string): WorkOSRole | undefined; /** * The roles that apply to an organization, the way production lists them: every environment * role plus the organization's own, an organization role shadowing an environment role with * the same slug, in priority order. Equal priorities keep environment roles ahead of the * organization's, each in insertion order, since Array.prototype.sort is stable. The * organization's roles are matched on organization_id, as resolvePrimaryRole does: a seeded * role can carry an organization_id with its type defaulted to EnvironmentRole, and it is * still that organization's override. */ export declare function rolesApplyingTo(ws: WorkOSStore, organizationId: string): WorkOSRole[]; /** Every environment role, in priority order: what `GET /authorization/roles` lists. */ export declare function environmentRoles(ws: WorkOSStore): WorkOSRole[]; export declare function requireEnvRole(ws: WorkOSStore, slug: string): WorkOSRole; export declare function requireOrgRole(ws: WorkOSStore, orgId: string, slug: string): WorkOSRole; export declare function getRolePermissions(ws: WorkOSStore, roleId: string): WorkOSPermission[]; /** * The permission slugs a membership's roles grant together: each slug resolves the way the * authorization endpoints resolve it (an organization role shadows an environment role) and * the union is deduplicated in role order. Undefined when no slug names a defined role, so a * token's `permissions` claim is omitted rather than minted empty. */ export declare function permissionsForRoles(ws: WorkOSStore, organizationId: string, slugs: readonly string[]): string[] | undefined; /** * The permission a role-permissions body names. Production resolves the slug before it * touches the role and answers an unknown one with 422 `invalid_permission_slug` (the * role-permissions controllers map PermissionSlugNotFoundException onto it), not 404. */ export declare function requirePermissionBySlug(ws: WorkOSStore, slug: string): WorkOSPermission; /** * Replace a role's permission set. Every slug is resolved before the join * table is touched, so an unknown slug answers 422 and leaves the current set * intact rather than half-applied. Returns whether the set actually changed, * which is what decides whether a role.updated event is due, as in production. */ export declare function replaceRolePermissions(ws: WorkOSStore, roleId: string, permissionSlugs: string[]): boolean; /** * Production emits `role.updated` (or `organization_role.updated`) when a * role's permission set changes through the permissions endpoints without * touching the role row, so this goes to the bus directly rather than through * the collection hooks. */ export declare function emitRolePermissionsUpdated(store: Store, ws: WorkOSStore, role: WorkOSRole): void; /** * Whether any membership still holds the role, which is what production's * `userRolesService.findAllByRoleId` answers before an organization role may be deleted: * a membership's organization-level roles (held by slug, which resolves to this role * because an organization role shadows an environment role), its resource-scoped * assignments, and the ones a native group's grant derives for each of the group's members. * The emulator materializes those derived assignments when they are read rather than * storing them, so a group grant counts while its group still has a live member: a deleted * membership leaves its group link behind, and a link to nothing derives nothing. */ export declare function roleHasAssignments(ws: WorkOSStore, role: WorkOSRole): boolean; /** * The priority a newly created role takes: production appends it to the end of the * priority order, so it sorts after every role that already exists. */ export declare function nextRolePriority(ws: WorkOSStore): number; /** * The slug production generates for an organization role created without one * (api-services/src/roles/slug-generation.ts): the name slugified, cut to fit, and the last * six characters of the role's ULID appended in lowercase. It does not carry the `org-` * prefix an explicit slug must. */ export declare function generateRoleSlug(name: string, roleId: string): string; export interface RoleRouteConfig { pathPrefix: string; roleType: 'EnvironmentRole' | 'OrganizationRole'; /** Resolves the role a write names: an organization route only ever writes its own roles. */ requireRole: (ws: WorkOSStore, c: Context) => WorkOSRole; /** * Resolves the role a GET names. Defaults to requireRole; production's organization GET * also answers the environment roles that apply to the organization. */ readRole?: (ws: WorkOSStore, c: Context) => WorkOSRole; findRole: (ws: WorkOSStore, c: Context, slug: string) => WorkOSRole | undefined; /** The body rules production's create DTO enforces for this role type. */ createRules: BodyRules; /** The slug a validated create body gives the role; `roleId` is the id the role will take. */ slugFor: (body: Record, roleId: string) => string; /** The whole list the GET answers with: the spec's RoleList is unpaged and in priority order. */ listRoles: (ws: WorkOSStore, c: Context) => WorkOSRole[]; insertDefaults: (c: Context) => Partial; duplicateMessage: string; /** Spec error code for a taken slug: `role_slug_conflict` or `organization_role_slug_conflict`. */ duplicateCode: string; validateBeforeCreate?: (ws: WorkOSStore, c: Context) => void; } export declare function registerRoleRoutes(ctx: RouteContext, config: RoleRouteConfig): void;