docs/refactor: rename getModuleMetadata and update route auth format
- Rename `getModuleMetadata` to `getModuleMetadataGenerator` in registry, index, and client exports to clarify its purpose (returns a generator function, not a metadata object) - Add new `getModuleMetadata` and `getMetadataGenerator` exports from `modules.metadata.js` for server-side metadata object retrieval - Update route auth format in docs from `requireAuth`/`requireAdmin` flags to a single `auth` field with values: `'admin'`, `'user'`, or `'public'` - Fix `isModuleEnabledInEnv` to replace hyphens with underscores in env var names (e.g. `my-module` → `ZEN_MODULE_MY_MODULE`) - Replace `useState` initializer in `ZenProvider` with `useRef` guard to avoid React strict mode double-invocation issues
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* const { getInvoiceByToken } = getModuleActions('invoice');
|
||||
*/
|
||||
|
||||
import { getModule } from '../core/modules/registry.js';
|
||||
import { getModule, getEnabledModules } from '../core/modules/registry.js';
|
||||
|
||||
// Static actions for internal modules (add entries here for new internal modules)
|
||||
export const MODULE_ACTIONS = {
|
||||
@@ -43,14 +43,15 @@ export function getModuleDashboardAction(moduleName) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all dashboard stats from all modules
|
||||
* Get all dashboard stats from all modules (internal static + external runtime).
|
||||
* @returns {Promise<Object>} Object with module names as keys and stats as values
|
||||
*/
|
||||
export async function getAllModuleDashboardStats() {
|
||||
const stats = {};
|
||||
|
||||
// Internal modules — static action map
|
||||
for (const [moduleName, getStats] of Object.entries(MODULE_DASHBOARD_ACTIONS)) {
|
||||
const envKey = `ZEN_MODULE_${moduleName.toUpperCase()}`;
|
||||
const envKey = `ZEN_MODULE_${moduleName.toUpperCase().replace(/-/g, '_')}`;
|
||||
if (process.env[envKey] !== 'true') continue;
|
||||
|
||||
try {
|
||||
@@ -63,6 +64,20 @@ export async function getAllModuleDashboardStats() {
|
||||
}
|
||||
}
|
||||
|
||||
// External modules — runtime registry
|
||||
for (const mod of getEnabledModules()) {
|
||||
if (mod.external && typeof mod.actions?.getDashboardStats === 'function') {
|
||||
try {
|
||||
const result = await mod.actions.getDashboardStats();
|
||||
if (result.success) {
|
||||
stats[mod.name] = result.stats;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error getting dashboard stats for ${mod.name}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user