chore: import codes
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Module Actions Registry (Server-Side)
|
||||
*
|
||||
* Import server actions for public pages (/zen/*) and dashboard.
|
||||
* Admin pages import actions directly from modules.
|
||||
* See modules.registry.js for full module creation guide.
|
||||
*
|
||||
* Usage in consuming Next.js app:
|
||||
* ```
|
||||
* import { MODULE_ACTIONS, MODULE_DASHBOARD_ACTIONS } from '@hykocx/zen/modules/actions';
|
||||
*
|
||||
* // Access module actions
|
||||
* const { getInvoiceByTokenAction } = MODULE_ACTIONS.invoice;
|
||||
*
|
||||
* // Get dashboard stats
|
||||
* const stats = await MODULE_DASHBOARD_ACTIONS.invoice();
|
||||
* ```
|
||||
*/
|
||||
|
||||
// Import module actions (use relative paths for build compatibility)
|
||||
import {
|
||||
isStripeEnabled,
|
||||
isInteracEnabled,
|
||||
getInteracEmail,
|
||||
getPublicPageConfig,
|
||||
getInvoiceByTokenAction,
|
||||
createStripeCheckoutSessionAction,
|
||||
generateInvoicePDFAction,
|
||||
getInteracCredentialsAction,
|
||||
generateReceiptPDFAction,
|
||||
} from './invoice/actions.js';
|
||||
|
||||
import {
|
||||
getShareByTokenAction,
|
||||
verifySharePasswordAction,
|
||||
getSharedContentsAction,
|
||||
getShareFileDownloadUrlAction,
|
||||
uploadToShareAction,
|
||||
getPublicPageConfig as getNuagePublicPageConfig,
|
||||
} from './nuage/actions.js';
|
||||
|
||||
// Import dashboard stats actions
|
||||
import { getInvoiceDashboardStats } from './invoice/dashboard/statsActions.js';
|
||||
|
||||
// Register module actions (for public pages)
|
||||
export const MODULE_ACTIONS = {
|
||||
invoice: {
|
||||
isStripeEnabled,
|
||||
isInteracEnabled,
|
||||
getInteracEmail,
|
||||
getPublicPageConfig,
|
||||
getInvoiceByTokenAction,
|
||||
createStripeCheckoutSessionAction,
|
||||
generateInvoicePDFAction,
|
||||
getInteracCredentialsAction,
|
||||
generateReceiptPDFAction,
|
||||
},
|
||||
posts: {},
|
||||
nuage: {
|
||||
getPublicPageConfig: getNuagePublicPageConfig,
|
||||
getShareByTokenAction,
|
||||
verifySharePasswordAction,
|
||||
getSharedContentsAction,
|
||||
getShareFileDownloadUrlAction,
|
||||
uploadToShareAction,
|
||||
},
|
||||
};
|
||||
|
||||
// Register dashboard stats actions (for admin dashboard)
|
||||
export const MODULE_DASHBOARD_ACTIONS = {
|
||||
invoice: getInvoiceDashboardStats,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get actions for a specific module
|
||||
* @param {string} moduleName - Module name
|
||||
* @returns {Object} Module actions object or empty object
|
||||
*/
|
||||
export function getModuleActions(moduleName) {
|
||||
return MODULE_ACTIONS[moduleName] || {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dashboard stats action for a specific module
|
||||
* @param {string} moduleName - Module name
|
||||
* @returns {Function|null} Dashboard stats function or null
|
||||
*/
|
||||
export function getModuleDashboardAction(moduleName) {
|
||||
return MODULE_DASHBOARD_ACTIONS[moduleName] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all dashboard stats from all modules
|
||||
* @returns {Promise<Object>} Object with module names as keys and stats as values
|
||||
*/
|
||||
export async function getAllModuleDashboardStats() {
|
||||
const stats = {};
|
||||
|
||||
for (const [moduleName, getStats] of Object.entries(MODULE_DASHBOARD_ACTIONS)) {
|
||||
const envKey = `ZEN_MODULE_${moduleName.toUpperCase()}`;
|
||||
if (process.env[envKey] !== 'true') continue;
|
||||
|
||||
try {
|
||||
const result = await getStats();
|
||||
if (result.success) {
|
||||
stats[moduleName] = result.stats;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error getting dashboard stats for ${moduleName}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
export default MODULE_ACTIONS;
|
||||
Reference in New Issue
Block a user