improved module manager's secrets extraction, updated plugins

This commit is contained in:
dswbx
2025-09-05 13:31:20 +02:00
parent 94e168589d
commit bdcc81b2f1
10 changed files with 154 additions and 47 deletions

View File

@@ -3,12 +3,14 @@ import { App, type AppConfig, type AppPlugin } from "bknd";
export type SyncConfigOptions = {
enabled?: boolean;
includeSecrets?: boolean;
includeFirstBoot?: boolean;
write: (config: AppConfig) => Promise<void>;
};
export function syncConfig({
enabled = true,
includeSecrets = false,
includeFirstBoot = false,
write,
}: SyncConfigOptions): AppPlugin {
let firstBoot = true;
@@ -26,7 +28,7 @@ export function syncConfig({
},
);
if (firstBoot) {
if (firstBoot && includeFirstBoot) {
firstBoot = false;
await write?.(app.toJSON(includeSecrets));
}

View File

@@ -1,22 +1,22 @@
import { type App, ModuleManagerEvents, type AppPlugin } from "bknd";
import type { DbModuleManager } from "modules/db/DbModuleManager";
export type SyncSecretsOptions = {
enabled?: boolean;
includeFirstBoot?: boolean;
write: (secrets: Record<string, any>) => Promise<void>;
};
export function syncSecrets({ enabled = true, write }: SyncSecretsOptions): AppPlugin {
export function syncSecrets({
enabled = true,
includeFirstBoot = false,
write,
}: SyncSecretsOptions): AppPlugin {
let firstBoot = true;
return (app: App) => ({
name: "bknd-sync-secrets",
onBuilt: async () => {
if (!enabled) return;
const manager = app.modules as DbModuleManager;
if (!("extractSecrets" in manager)) {
throw new Error("ModuleManager does not support secrets");
}
const manager = app.modules;
app.emgr.onEvent(
ModuleManagerEvents.ModuleManagerSecretsExtractedEvent,
@@ -28,7 +28,7 @@ export function syncSecrets({ enabled = true, write }: SyncSecretsOptions): AppP
},
);
if (firstBoot) {
if (firstBoot && includeFirstBoot) {
firstBoot = false;
await write?.(manager.extractSecrets().secrets);
}

View File

@@ -2,10 +2,15 @@ import { App, type AppPlugin, EntityTypescript } from "bknd";
export type SyncTypesOptions = {
enabled?: boolean;
includeFirstBoot?: boolean;
write: (et: EntityTypescript) => Promise<void>;
};
export function syncTypes({ enabled = true, write }: SyncTypesOptions): AppPlugin {
export function syncTypes({
enabled = true,
includeFirstBoot = false,
write,
}: SyncTypesOptions): AppPlugin {
let firstBoot = true;
return (app: App) => ({
name: "bknd-sync-types",
@@ -21,7 +26,7 @@ export function syncTypes({ enabled = true, write }: SyncTypesOptions): AppPlugi
},
);
if (firstBoot) {
if (firstBoot && includeFirstBoot) {
firstBoot = false;
await write?.(new EntityTypescript(app.em));
}