@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 +65 -2
- package/dist/index.esm.js +78 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34640,6 +34640,83 @@ const getApiIndustryType = (erpIndustry) => {
|
|
|
34640
34640
|
return INDUSTRY_MAPPING[erpIndustry] || "manufacturing";
|
|
34641
34641
|
};
|
|
34642
34642
|
|
|
34643
|
+
const getItemsForUser = async (apiClient, options = {}) => {
|
|
34644
|
+
const params = new URLSearchParams();
|
|
34645
|
+
if (options.industry)
|
|
34646
|
+
params.set("industry", options.industry);
|
|
34647
|
+
const query = params.toString();
|
|
34648
|
+
const data = await apiClient
|
|
34649
|
+
.get(`erp-config/items${query ? `?${query}` : ""}`)
|
|
34650
|
+
.json();
|
|
34651
|
+
return data.items || [];
|
|
34652
|
+
};
|
|
34653
|
+
const resolveEmissionFactorsForUser = async (apiClient, options) => {
|
|
34654
|
+
const data = await apiClient
|
|
34655
|
+
.post("erp-config/items/emission-factors/resolve", {
|
|
34656
|
+
json: {
|
|
34657
|
+
industry: options.industry,
|
|
34658
|
+
scope: options.scope,
|
|
34659
|
+
category: options.category,
|
|
34660
|
+
items: options.items,
|
|
34661
|
+
},
|
|
34662
|
+
})
|
|
34663
|
+
.json();
|
|
34664
|
+
return data.items || [];
|
|
34665
|
+
};
|
|
34666
|
+
const addItemForUser = async (apiClient, options) => {
|
|
34667
|
+
const data = await apiClient
|
|
34668
|
+
.post("erp-config/items/bulk", {
|
|
34669
|
+
json: {
|
|
34670
|
+
industry: options.industry,
|
|
34671
|
+
scope: options.scope,
|
|
34672
|
+
category: options.category,
|
|
34673
|
+
source: "bulk-upload-review",
|
|
34674
|
+
items: options.items,
|
|
34675
|
+
},
|
|
34676
|
+
})
|
|
34677
|
+
.json();
|
|
34678
|
+
return data.items || [];
|
|
34679
|
+
};
|
|
34680
|
+
const updateItemEmissionFactorForUser = async (apiClient, options) => {
|
|
34681
|
+
if (!apiClient.patch) {
|
|
34682
|
+
throw new Error("apiClient.patch is required to update emission factors");
|
|
34683
|
+
}
|
|
34684
|
+
const data = await apiClient
|
|
34685
|
+
.patch(`erp-config/items/${options.itemId}/emission-factor`, { json: { emissionFactor: options.emissionFactor } })
|
|
34686
|
+
.json();
|
|
34687
|
+
return data;
|
|
34688
|
+
};
|
|
34689
|
+
const mergeUserItemsIntoIndustryConfig = (baseConfig, userItems = []) => {
|
|
34690
|
+
const config = JSON.parse(JSON.stringify(baseConfig));
|
|
34691
|
+
for (const item of userItems) {
|
|
34692
|
+
if (item.scope === "scope3") {
|
|
34693
|
+
const scope = config.scope3.find((entry) => entry.name === item.category);
|
|
34694
|
+
const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => entry.category === item.subCategory);
|
|
34695
|
+
if (group && !group.items.some((entry) => entry.item === item.itemName)) {
|
|
34696
|
+
group.items.push({
|
|
34697
|
+
item: item.itemName,
|
|
34698
|
+
unit: item.unit,
|
|
34699
|
+
emissionFactor: item.emissionFactor,
|
|
34700
|
+
requiresMassData: item.requiresMassData,
|
|
34701
|
+
});
|
|
34702
|
+
}
|
|
34703
|
+
continue;
|
|
34704
|
+
}
|
|
34705
|
+
const scopeList = item.scope === "scope2" ? config.scope2 : config.scope1;
|
|
34706
|
+
const scope = scopeList.find((entry) => entry.name === item.category);
|
|
34707
|
+
if (scope && !scope.subProducts.some((entry) => entry.name === item.itemName)) {
|
|
34708
|
+
scope.subProducts.push({
|
|
34709
|
+
name: item.itemName,
|
|
34710
|
+
type: item.subCategory,
|
|
34711
|
+
unit: item.unit,
|
|
34712
|
+
emissionFactor: item.emissionFactor,
|
|
34713
|
+
calorificValue: 0,
|
|
34714
|
+
});
|
|
34715
|
+
}
|
|
34716
|
+
}
|
|
34717
|
+
return config;
|
|
34718
|
+
};
|
|
34719
|
+
|
|
34643
34720
|
// Scope 3 categories configuration for cement industry using API data
|
|
34644
34721
|
const API_SCOPE3_CEMENT_CONFIG = [
|
|
34645
34722
|
{
|
|
@@ -40168,6 +40245,7 @@ exports.ISO_CATEGORIES_PACKAGING = ISO_CATEGORIES_PACKAGING;
|
|
|
40168
40245
|
exports.Industries = index;
|
|
40169
40246
|
exports.UI_FEATURES = UI_FEATURES;
|
|
40170
40247
|
exports.WATER_PRODUCTS = WATER_PRODUCTS$1;
|
|
40248
|
+
exports.addItemForUser = addItemForUser;
|
|
40171
40249
|
exports.calculateCCTSEmission = calculateCCTSEmission;
|
|
40172
40250
|
exports.calculateIntensityMetrics = calculateIntensityMetrics;
|
|
40173
40251
|
exports.categorizeApiItem = categorizeApiItem;
|
|
@@ -40191,6 +40269,7 @@ exports.getIndustryBackendConfig = getIndustryBackendConfig;
|
|
|
40191
40269
|
exports.getIndustryConfig = getIndustryConfig;
|
|
40192
40270
|
exports.getIndustryFieldConfig = getIndustryFieldConfig;
|
|
40193
40271
|
exports.getIntensityFormulas = getIntensityFormulas;
|
|
40272
|
+
exports.getItemsForUser = getItemsForUser;
|
|
40194
40273
|
exports.getPlantNameConfig = getPlantNameConfig;
|
|
40195
40274
|
exports.getRCOConfigByName = getRCOConfigByName;
|
|
40196
40275
|
exports.getScope3ConfigByName = getScope3ConfigByName;
|
|
@@ -40199,7 +40278,10 @@ exports.getUserNameScopeConfig = getUserNameScopeConfig;
|
|
|
40199
40278
|
exports.hasIntensities = hasIntensities;
|
|
40200
40279
|
exports.isUIFeatureEnabled = isUIFeatureEnabled;
|
|
40201
40280
|
exports.mapIndustryToApiType = mapIndustryToApiType;
|
|
40281
|
+
exports.mergeUserItemsIntoIndustryConfig = mergeUserItemsIntoIndustryConfig;
|
|
40282
|
+
exports.resolveEmissionFactorsForUser = resolveEmissionFactorsForUser;
|
|
40202
40283
|
exports.sanitizeNumber = sanitizeNumber;
|
|
40203
40284
|
exports.supportsIntensityCalculations = supportsIntensityCalculations;
|
|
40285
|
+
exports.updateItemEmissionFactorForUser = updateItemEmissionFactorForUser;
|
|
40204
40286
|
exports.validateCarbonIntensityData = validateCarbonIntensityData;
|
|
40205
40287
|
//# sourceMappingURL=index.js.map
|