@zerocarbon/erp-config-sdk 1.0.21 → 1.0.23

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.d.ts CHANGED
@@ -1209,6 +1209,69 @@ declare const createEmissionSourceGenerator: (billManager: BillManager) => Emiss
1209
1209
  declare const INDUSTRY_MAPPING: Record<string, IndustryType>;
1210
1210
  declare const getApiIndustryType: (erpIndustry: string) => IndustryType;
1211
1211
 
1212
+ type JsonResponse<T> = {
1213
+ json: () => Promise<T>;
1214
+ };
1215
+ type UserConfigApiClient = {
1216
+ get: <T = any>(path: string) => JsonResponse<T>;
1217
+ post: <T = any>(path: string, options: {
1218
+ json: unknown;
1219
+ }) => JsonResponse<T>;
1220
+ patch?: <T = any>(path: string, options: {
1221
+ json: unknown;
1222
+ }) => JsonResponse<T>;
1223
+ };
1224
+ type UserConfigItem = {
1225
+ id?: string;
1226
+ industry: string;
1227
+ scope: "scope1" | "scope2" | "scope3" | string;
1228
+ category: string;
1229
+ subCategory: string;
1230
+ itemName: string;
1231
+ unit: string;
1232
+ emissionFactor: number;
1233
+ emissionFactorSource?: {
1234
+ name?: string;
1235
+ url?: string;
1236
+ unit?: string;
1237
+ confidence?: number;
1238
+ notes?: string;
1239
+ };
1240
+ requiresMassData?: boolean;
1241
+ aliases?: string[];
1242
+ source?: string;
1243
+ };
1244
+ type UserEmissionFactorResolution = Partial<UserConfigItem> & {
1245
+ clientId?: string;
1246
+ status: "found" | "missing";
1247
+ message?: string;
1248
+ };
1249
+ declare const getItemsForUser: (apiClient: UserConfigApiClient, options?: {
1250
+ industry?: string;
1251
+ }) => Promise<UserConfigItem[]>;
1252
+ declare const resolveEmissionFactorsForUser: (apiClient: UserConfigApiClient, options: {
1253
+ industry: string;
1254
+ scope: string;
1255
+ category: string;
1256
+ items: (Partial<UserConfigItem> & {
1257
+ clientId?: string;
1258
+ })[];
1259
+ }) => Promise<UserEmissionFactorResolution[]>;
1260
+ declare const addItemForUser: (apiClient: UserConfigApiClient, options: {
1261
+ industry: string;
1262
+ scope: string;
1263
+ category: string;
1264
+ items: Partial<UserConfigItem>[];
1265
+ }) => Promise<UserConfigItem[]>;
1266
+ declare const updateItemEmissionFactorForUser: (apiClient: UserConfigApiClient, options: {
1267
+ itemId: string;
1268
+ emissionFactor: number;
1269
+ }) => Promise<{
1270
+ item?: UserConfigItem;
1271
+ updatedBills?: number;
1272
+ }>;
1273
+ declare const mergeUserItemsIntoIndustryConfig: <T extends BackendIndustryConfig>(baseConfig: T, userItems?: UserConfigItem[]) => T;
1274
+
1212
1275
  interface MappingRules {
1213
1276
  includeIfCategoryContains?: string[];
1214
1277
  includeIfSubCategoryContains?: string[];
@@ -4208,5 +4271,5 @@ declare namespace index {
4208
4271
  };
4209
4272
  }
4210
4273
 
4211
- export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig$1 as getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getPlantNameConfig, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, mapIndustryToApiType, sanitizeNumber, supportsIntensityCalculations, validateCarbonIntensityData };
4212
- export type { AllConfigurations, AlloyRequest, AlloyResponse, AluminiumRequest, AluminiumResponse, ApiEndpointConfig, ApiResponse, AutomobileRequest, AutomobileResponse, AviationRequest, AviationResponse, BackendAdditionalScopeItem, BackendEmissionItem, BackendEmissions, BackendEquipmentCategory, BackendIndustries, BackendIndustryConfig, BackendProduct, BackendScope, BackendScope3Item, BackendUserConfig, BackendUserConfigs, BaseRequest, BaseResponse, Bill, BillCalculationConfig, BillFilterOptions, BillMatchingConfig, BusinessTravelEmission, BusinessTravelEmissionAttributes, BusinessTravelEmissionsResponse, BillsAnalyzed$1 as CarbonIntensityBillsAnalyzed, Calculations$1 as CarbonIntensityCalculations, EmissionData$2 as CarbonIntensityEmissionData, ErrorResponse$1 as CarbonIntensityErrorResponse, CarbonIntensityRequest, CarbonIntensityResponse, ChemicalRequest, ChemicalResponse, DetailedCarbonIntensityResponse, EditableItem, EmissionData$3 as EmissionData, EmissionSource, Emissions$j as Emissions, EmissionsDataAttributes, EmissionsDataResponse, FieldConfig, FoodBeveragesRequest, FoodBeveragesResponse, FormData, FormValidationResult, FrontendIndustryConfig, HospitalityRequest, HospitalityResponse, IndustryConfig$1 as IndustryConfig, EmissionData as IndustryEmissionData, IndustryFieldConfig, IndustryFieldSection, ProductionData as IndustryProductionData, IndustryType, IntensityCalculation, IntensityValue, LogisticsRequest, LogisticsResponse, ManufacturingRequest, ManufacturingResponse, Meta, MetalEnergyRequest, MetalEnergyResponse, PackagingRequest, PackagingResponse, Pagination, PetrochemicalRequest, PetrochemicalResponse, PharmaRequest, PharmaResponse, PlantNameConfig, ProcessedEmissionCategory, ProcessedEmissionItem, ProcessedScope3Data, RealEstateRequest, RealEstateResponse, BillsAnalyzed as ResponseBillsAnalyzed, Calculations as ResponseCalculations, EmissionData$1 as ResponseEmissionData, ErrorResponse as ResponseErrorResponse, ScopeConfig, ScopeProduct, ShippingRequest, ShippingResponse, SteelRequest, SteelResponse, StrapiItem, StrapiResponse, TelecommunicationRequest, TelecommunicationResponse, TextileRequest, TextileResponse, TransportationEmission, TransportationEmissionAttributes, TransportationEmissionsResponse, UserData, UtilitiesRequest, UtilitiesResponse, ValidationError, VehicleEmission, VehicleEmissionAttributes, VehicleEmissionsResponse };
4274
+ export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS, addItemForUser, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig$1 as getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, resolveEmissionFactorsForUser, sanitizeNumber, supportsIntensityCalculations, updateItemEmissionFactorForUser, validateCarbonIntensityData };
4275
+ export type { AllConfigurations, AlloyRequest, AlloyResponse, AluminiumRequest, AluminiumResponse, ApiEndpointConfig, ApiResponse, AutomobileRequest, AutomobileResponse, AviationRequest, AviationResponse, BackendAdditionalScopeItem, BackendEmissionItem, BackendEmissions, BackendEquipmentCategory, BackendIndustries, BackendIndustryConfig, BackendProduct, BackendScope, BackendScope3Item, BackendUserConfig, BackendUserConfigs, BaseRequest, BaseResponse, Bill, BillCalculationConfig, BillFilterOptions, BillMatchingConfig, BusinessTravelEmission, BusinessTravelEmissionAttributes, BusinessTravelEmissionsResponse, BillsAnalyzed$1 as CarbonIntensityBillsAnalyzed, Calculations$1 as CarbonIntensityCalculations, EmissionData$2 as CarbonIntensityEmissionData, ErrorResponse$1 as CarbonIntensityErrorResponse, CarbonIntensityRequest, CarbonIntensityResponse, ChemicalRequest, ChemicalResponse, DetailedCarbonIntensityResponse, EditableItem, EmissionData$3 as EmissionData, EmissionSource, Emissions$j as Emissions, EmissionsDataAttributes, EmissionsDataResponse, FieldConfig, FoodBeveragesRequest, FoodBeveragesResponse, FormData, FormValidationResult, FrontendIndustryConfig, HospitalityRequest, HospitalityResponse, IndustryConfig$1 as IndustryConfig, EmissionData as IndustryEmissionData, IndustryFieldConfig, IndustryFieldSection, ProductionData as IndustryProductionData, IndustryType, IntensityCalculation, IntensityValue, LogisticsRequest, LogisticsResponse, ManufacturingRequest, ManufacturingResponse, Meta, MetalEnergyRequest, MetalEnergyResponse, PackagingRequest, PackagingResponse, Pagination, PetrochemicalRequest, PetrochemicalResponse, PharmaRequest, PharmaResponse, PlantNameConfig, ProcessedEmissionCategory, ProcessedEmissionItem, ProcessedScope3Data, RealEstateRequest, RealEstateResponse, BillsAnalyzed as ResponseBillsAnalyzed, Calculations as ResponseCalculations, EmissionData$1 as ResponseEmissionData, ErrorResponse as ResponseErrorResponse, ScopeConfig, ScopeProduct, ShippingRequest, ShippingResponse, SteelRequest, SteelResponse, StrapiItem, StrapiResponse, TelecommunicationRequest, TelecommunicationResponse, TextileRequest, TextileResponse, TransportationEmission, TransportationEmissionAttributes, TransportationEmissionsResponse, UserConfigApiClient, UserConfigItem, UserData, UserEmissionFactorResolution, UtilitiesRequest, UtilitiesResponse, ValidationError, VehicleEmission, VehicleEmissionAttributes, VehicleEmissionsResponse };
package/dist/index.esm.js CHANGED
@@ -34638,6 +34638,83 @@ const getApiIndustryType = (erpIndustry) => {
34638
34638
  return INDUSTRY_MAPPING[erpIndustry] || "manufacturing";
34639
34639
  };
34640
34640
 
34641
+ const getItemsForUser = async (apiClient, options = {}) => {
34642
+ const params = new URLSearchParams();
34643
+ if (options.industry)
34644
+ params.set("industry", options.industry);
34645
+ const query = params.toString();
34646
+ const data = await apiClient
34647
+ .get(`erp-config/items${query ? `?${query}` : ""}`)
34648
+ .json();
34649
+ return data.items || [];
34650
+ };
34651
+ const resolveEmissionFactorsForUser = async (apiClient, options) => {
34652
+ const data = await apiClient
34653
+ .post("erp-config/items/emission-factors/resolve", {
34654
+ json: {
34655
+ industry: options.industry,
34656
+ scope: options.scope,
34657
+ category: options.category,
34658
+ items: options.items,
34659
+ },
34660
+ })
34661
+ .json();
34662
+ return data.items || [];
34663
+ };
34664
+ const addItemForUser = async (apiClient, options) => {
34665
+ const data = await apiClient
34666
+ .post("erp-config/items/bulk", {
34667
+ json: {
34668
+ industry: options.industry,
34669
+ scope: options.scope,
34670
+ category: options.category,
34671
+ source: "bulk-upload-review",
34672
+ items: options.items,
34673
+ },
34674
+ })
34675
+ .json();
34676
+ return data.items || [];
34677
+ };
34678
+ const updateItemEmissionFactorForUser = async (apiClient, options) => {
34679
+ if (!apiClient.patch) {
34680
+ throw new Error("apiClient.patch is required to update emission factors");
34681
+ }
34682
+ const data = await apiClient
34683
+ .patch(`erp-config/items/${options.itemId}/emission-factor`, { json: { emissionFactor: options.emissionFactor } })
34684
+ .json();
34685
+ return data;
34686
+ };
34687
+ const mergeUserItemsIntoIndustryConfig = (baseConfig, userItems = []) => {
34688
+ const config = JSON.parse(JSON.stringify(baseConfig));
34689
+ for (const item of userItems) {
34690
+ if (item.scope === "scope3") {
34691
+ const scope = config.scope3.find((entry) => entry.name === item.category);
34692
+ const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => entry.category === item.subCategory);
34693
+ if (group && !group.items.some((entry) => entry.item === item.itemName)) {
34694
+ group.items.push({
34695
+ item: item.itemName,
34696
+ unit: item.unit,
34697
+ emissionFactor: item.emissionFactor,
34698
+ requiresMassData: item.requiresMassData,
34699
+ });
34700
+ }
34701
+ continue;
34702
+ }
34703
+ const scopeList = item.scope === "scope2" ? config.scope2 : config.scope1;
34704
+ const scope = scopeList.find((entry) => entry.name === item.category);
34705
+ if (scope && !scope.subProducts.some((entry) => entry.name === item.itemName)) {
34706
+ scope.subProducts.push({
34707
+ name: item.itemName,
34708
+ type: item.subCategory,
34709
+ unit: item.unit,
34710
+ emissionFactor: item.emissionFactor,
34711
+ calorificValue: 0,
34712
+ });
34713
+ }
34714
+ }
34715
+ return config;
34716
+ };
34717
+
34641
34718
  // Scope 3 categories configuration for cement industry using API data
34642
34719
  const API_SCOPE3_CEMENT_CONFIG = [
34643
34720
  {
@@ -40135,5 +40212,5 @@ var index = /*#__PURE__*/Object.freeze({
40135
40212
  getRCOConfigByName: getRCOConfigByName
40136
40213
  });
40137
40214
 
40138
- export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$1 as WATER_PRODUCTS, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getPlantNameConfig, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, mapIndustryToApiType, sanitizeNumber, supportsIntensityCalculations, validateCarbonIntensityData };
40215
+ export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$1 as WATER_PRODUCTS, addItemForUser, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, resolveEmissionFactorsForUser, sanitizeNumber, supportsIntensityCalculations, updateItemEmissionFactorForUser, validateCarbonIntensityData };
40139
40216
  //# sourceMappingURL=index.esm.js.map