mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
improved module manager's secrets extraction, updated plugins
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user