refactor: centralized the iam seeder

This commit is contained in:
Nathnael
2026-07-27 08:28:57 +00:00
parent 1fe10ee3c2
commit 03b8ca0ce7
19 changed files with 1339 additions and 592 deletions

View File

@@ -12,6 +12,7 @@ import {
ensurePostgresSchemas,
APPLICATION_SEARCH_PATH,
} from "./config/ensure-postgres-schemas";
import { IamBaselineSeeder, IamSeedModule } from "@edr/iam-seed";
import { IamModule } from "@tria-plc/iamapi-common";
import { SharedAuthModule } from "@tria-plc/api-common/modules/auth/shared-auth.module";
@@ -55,7 +56,6 @@ import {
EDR_FREIGHT_PERMISSIONS,
} from "./seed/edr-freight.seed";
import { EdrOrgSeeder } from "./seed/edr-org.seeder";
import { IamBaselineSeeder } from "./seed/iam-baseline.seeder";
import { FreightPositionsSeeder } from "./seed/freight-positions.seeder";
// Disabled seeds — imports commented out with their provider/injection/run below.
// import { DemoUsersSeeder } from "./seed/demo-users.seeder";
@@ -154,6 +154,18 @@ import { LoggerMiddleware } from "./logger.middleware";
applications: [EDR_FREIGHT_APPLICATION],
permissions: EDR_FREIGHT_PERMISSIONS,
}),
// Replaces the package's DataSeeder. Shared with edr-passenger-api, which
// seeds the same `iam` schema — see packages/iam-seed.
IamSeedModule.forRoot({
superAdmin: {
username: "superadmin",
name: { am: "ሱፐር አድሚን", en: "Super Admin" },
roleKey: "super_admin",
organizationKey: "edr_freight",
unitKey: "edr_freight_app",
fallbackEmail: "superadmin@tria.com",
},
}),
BookingsModule,
ContractsModule,
SignaturesModule,
@@ -207,7 +219,6 @@ import { LoggerMiddleware } from "./logger.middleware";
AiModule,
],
providers: [
IamBaselineSeeder,
EdrOrgSeeder,
FreightPositionsSeeder,
FileUploadSettingsSeeder,
@@ -264,16 +275,15 @@ export class AppModule implements OnApplicationBootstrap {
// Permissions foundation — keep enabled:
// freightPermissionKeyMigration → renames legacy permission keys
// edrOrgSeeder → seeds org/unit + the Permission catalog
// iamBaselineSeeder → seeds the IAM app, roles, permissions,
// position types, org/unit settings and the
// super-admin account. Local replacement for
// the package's DataSeeder (still exported as
// `DataSeeder` from @tria-plc/iamapi-common
// and runnable via `pnpm iam:seed:run`) —
// see src/seed/iam-baseline.seed.ts for
// what it seeds and what it drops. Runs after
// edrOrgSeeder because the super admin is
// attached to the edr_freight org/unit.
// iamBaselineSeeder → @edr/iam-seed: IAM app, roles, permissions,
// position types, organization types +
// default units, org/unit settings and the
// super-admin account. Replaces the package's
// DataSeeder, and is shared with
// edr-passenger-api so one writer owns the
// `iam` schema. Runs after edrOrgSeeder
// because the super admin attaches to the
// edr_freight org/unit.
// Writes nothing unless SEED_IAM_BASELINE=true.
// freightPositionsSeeder → seeds Position + PositionPermission rows
// (depends on edrOrgSeeder, must run after)