Declare permissions on the plugin declaration

Clusterio #988 added a permissions array to PluginDeclaration and a
type level Permissions registry, and made checkPermission and the web
UI hasPermission helpers take PermissionName. Move the definePermission
calls of exp_groups and exp_scenario into the declaration and add the
names to the registry so the web pages type check. The browser
tsconfigs include index.ts so the augmentation is visible to the web
bundle, matching the in-repo plugins.

The exp_scenario table keeps its tuple form and derives the name union
from it, so a new row is still one line. Seed role permissions are typed
as PermissionName, so a typo in seed.ts is now a compile error rather
than a warning at seed time. The tests register the declared
permissions through registerPluginPermissions instead of importing
permissions.ts for its side effect.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-09-11 23:27:17 +00:00
co-authored by Claude Fable 5.1
parent 24d2f76a35
commit 30f1b5ea75
8 changed files with 192 additions and 153 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
import type * as lib from "@clusterio/lib";
import { RoleColor } from "@expcluster/roles";
/**
@@ -19,7 +20,7 @@ export interface SeedRole {
isAdmin?: boolean;
/** Name of the role whose permissions are also granted, applied recursively. */
parent?: string;
permissions: string[];
permissions: lib.PermissionName[];
/**
* Name of the seed group holders are placed in by their highest role.
* Without one the holders stay in Factorio's Default group.
@@ -329,7 +330,7 @@ export const seedGroups: SeedGroup[] = [
/** The permissions a seed role grants, including those of its parents. */
export function flattenSeedPermissions(role: SeedRole, roles = seedRoles) {
const permissions = new Set<string>();
const permissions = new Set<lib.PermissionName>();
const seen = new Set<string>();
let current: SeedRole | undefined = role;
while (current && !seen.has(current.name)) {