Files
HiveGrid-Wireframes/hivegrid-cloud/packages/plugin-runtime/src/production-gate.ts
T

26 lines
940 B
TypeScript

export type PluginRuntimeEnv = {
[key: string]: string | undefined;
NODE_ENV?: string;
PLUGIN_RUNTIME_PRODUCTION_ENABLED?: string;
};
export const PLUGIN_RUNTIME_PRODUCTION_GATE_ENV = "PLUGIN_RUNTIME_PRODUCTION_ENABLED";
export function isPluginRuntimeProductionEnabled(env: PluginRuntimeEnv = process.env): boolean {
return env.NODE_ENV !== "production" || env.PLUGIN_RUNTIME_PRODUCTION_ENABLED === "true";
}
export function describePluginRuntimeProductionGate(env: PluginRuntimeEnv = process.env): string | null {
if (isPluginRuntimeProductionEnabled(env)) {
return null;
}
return `${PLUGIN_RUNTIME_PRODUCTION_GATE_ENV}=true is required before tenant plugin runtime operations are allowed in production.`;
}
export function assertPluginRuntimeProductionEnabled(env: PluginRuntimeEnv = process.env): void {
const reason = describePluginRuntimeProductionGate(env);
if (reason) {
throw new Error(reason);
}
}