UNPKG

@gsb-core/core

Version:

GSB core services and classes for platform-independent web applications

59 lines 2.31 kB
"use strict"; /** * Tenant Configuration * Simplified version that uses consolidated functions from gsb-config.ts */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentTenantCode = void 0; exports.setupTenant = setupTenant; exports.shouldInitTenant = shouldInitTenant; exports.getTenantFromToken = getTenantFromToken; exports.getCurrentTenant = getCurrentTenant; const gsb_config_1 = require("./gsb-config"); Object.defineProperty(exports, "getCurrentTenantCode", { enumerable: true, get: function () { return gsb_config_1.getGsbTenantCode; } }); /** * Set up tenant based on the current environment * @param hostname Current hostname * @param isDevMode Whether we're in development mode * @returns The current tenant code */ function setupTenant(hostname, isDevMode = (0, gsb_config_1.getEnvVar)('NODE_ENV', 'production') === 'development') { const tenantFromHostname = (0, gsb_config_1.getTenantFromHostname)(hostname); const currentTenant = tenantFromHostname || (0, gsb_config_1.getDefaultTenant)(); // Set as active tenant (0, gsb_config_1.setGsbTenantCode)(currentTenant); // In development mode, try to set up token from environment variables if (isDevMode) { const token = (0, gsb_config_1.getEnvToken)(); if (token) { console.log(`[DEV] Set up tenant: ${currentTenant} using environment token`); } else { console.log(`[DEV] No token found for tenant: ${currentTenant}. Authentication will be required.`); } } return currentTenant; } /** * Check if we should initialize a specific tenant * @param desiredTenant The desired tenant to check * @returns True if we should initialize the desired tenant */ function shouldInitTenant(desiredTenant) { return desiredTenant === (0, gsb_config_1.getGsbTenantCode)(); } /** * Parse tenant from JWT token - alias for extractTenantCodeFromToken * @param token JWT token * @returns Tenant code or null if can't parse */ function getTenantFromToken(token) { return (0, gsb_config_1.extractTenantCodeFromToken)(token) || null; } /** * Get the current tenant - alias for getGsbTenantCode */ function getCurrentTenant() { return (0, gsb_config_1.getGsbTenantCode)(); } //# sourceMappingURL=tenant-config.js.map