@zerocarbon/erp-config-sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -35010,17 +35010,23 @@ const UI_FEATURES = {
35010
35010
  INTEGRATION_FEATURES: "advanced.integrationFeatures",
35011
35011
  },
35012
35012
  };
35013
+ // ==================== DEFAULT CONFIGURATION ====================
35014
+ // All features are enabled by default
35015
+ const DEFAULT_FEATURES = {};
35013
35016
  // Auto-populate all features as true by default
35014
35017
  const populateDefaults = (obj, prefix = "") => {
35015
35018
  for (const [key, value] of Object.entries(obj)) {
35016
35019
  if (typeof value === "object" && value !== null) {
35017
35020
  populateDefaults(value, prefix ? `${prefix}.${key}` : key);
35018
35021
  }
35022
+ else if (typeof value === "string") {
35023
+ DEFAULT_FEATURES[value] = true;
35024
+ }
35019
35025
  }
35020
35026
  };
35021
35027
  populateDefaults(UI_FEATURES);
35022
35028
  // ==================== USER-SPECIFIC OVERRIDES ====================
35023
- ({
35029
+ const USER_OVERRIDES = {
35024
35030
  // Example: Gas Lab user with specific features disabled
35025
35031
  "gas lab": {
35026
35032
  [UI_FEATURES.DASHBOARD_CARDS.GHG_INTENSITY]: false,
@@ -35045,7 +35051,40 @@ populateDefaults(UI_FEATURES);
35045
35051
  [UI_FEATURES.ADVANCED.CUSTOM_REPORTS]: false,
35046
35052
  [UI_FEATURES.ADVANCED.API_ACCESS]: false,
35047
35053
  [UI_FEATURES.GRI.BLOCKCHAIN_PUBLISHING]: false,
35048
- }});
35054
+ },
35055
+ // Example: Admin user with all features enabled (explicitly showing override pattern)
35056
+ admin: {
35057
+ // All features remain true (default), but you could override specific ones to false if needed
35058
+ },
35059
+ };
35060
+ // ==================== UTILITY FUNCTIONS ====================
35061
+ /**
35062
+ * Check if a specific feature is enabled for a user
35063
+ * @param featurePath - The dot notation path to the feature (e.g., 'dashboard.cards.ghgIntensity')
35064
+ * @param username - The username to check (case-insensitive)
35065
+ * @returns boolean - true if feature is enabled, false if disabled
35066
+ */
35067
+ const isFeatureEnabled = (featurePath, username) => {
35068
+ var _a, _b, _c;
35069
+ if (!username) {
35070
+ return (_a = DEFAULT_FEATURES[featurePath]) !== null && _a !== void 0 ? _a : true;
35071
+ }
35072
+ const normalizedUsername = username.toLowerCase().trim();
35073
+ const userOverrides = USER_OVERRIDES[normalizedUsername];
35074
+ if (userOverrides && userOverrides.hasOwnProperty(featurePath)) {
35075
+ return (_b = userOverrides[featurePath]) !== null && _b !== void 0 ? _b : true;
35076
+ }
35077
+ return (_c = DEFAULT_FEATURES[featurePath]) !== null && _c !== void 0 ? _c : true;
35078
+ };
35079
+ /**
35080
+ * Helper function to get feature value using the constant paths
35081
+ * @param featureConstant - Use UI_FEATURES constants (e.g., UI_FEATURES.DASHBOARD_CARDS.GHG_INTENSITY)
35082
+ * @param username - The username to check
35083
+ * @returns boolean - true if feature is enabled, false if disabled
35084
+ */
35085
+ const isUIFeatureEnabled = (featureConstant, username) => {
35086
+ return isFeatureEnabled(featureConstant, username);
35087
+ };
35049
35088
  // ==================== FEATURE GROUPS FOR EASY ACCESS ====================
35050
35089
  ({
35051
35090
  DASHBOARD: [
@@ -40312,6 +40351,7 @@ exports.getPlantNameConfig = getPlantNameConfig;
40312
40351
  exports.getScope3ConfigByName = getScope3ConfigByName;
40313
40352
  exports.getUserNameWaterManagementConfig = getUserNameWaterManagementConfig;
40314
40353
  exports.hasIntensities = hasIntensities;
40354
+ exports.isUIFeatureEnabled = isUIFeatureEnabled;
40315
40355
  exports.mapIndustryToApiType = mapIndustryToApiType;
40316
40356
  exports.supportsIntensityCalculations = supportsIntensityCalculations;
40317
40357
  exports.validateCarbonIntensityData = validateCarbonIntensityData;