mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
38 lines
972 B
TypeScript
38 lines
972 B
TypeScript
import { type App, ModuleManagerEvents, type AppPlugin } from "bknd";
|
|
|
|
export type SyncSecretsOptions = {
|
|
enabled?: boolean;
|
|
includeFirstBoot?: boolean;
|
|
write: (secrets: Record<string, any>) => Promise<void>;
|
|
};
|
|
|
|
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;
|
|
|
|
app.emgr.onEvent(
|
|
ModuleManagerEvents.ModuleManagerSecretsExtractedEvent,
|
|
async ({ params: { secrets } }) => {
|
|
await write?.(secrets);
|
|
},
|
|
{
|
|
id: "sync-secrets",
|
|
},
|
|
);
|
|
|
|
if (firstBoot && includeFirstBoot) {
|
|
firstBoot = false;
|
|
await write?.(manager.extractSecrets().secrets);
|
|
}
|
|
},
|
|
});
|
|
}
|