@zerocarbon/erp-config-sdk 1.0.23 → 1.0.25
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 +45 -7
- package/dist/index.esm.js +84 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +88 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34640,6 +34640,81 @@ const getApiIndustryType = (erpIndustry) => {
|
|
|
34640
34640
|
return INDUSTRY_MAPPING[erpIndustry] || "manufacturing";
|
|
34641
34641
|
};
|
|
34642
34642
|
|
|
34643
|
+
const normalizeConfigText = (value) => String(value !== null && value !== void 0 ? value : "").replace(/\s+/g, " ").trim();
|
|
34644
|
+
const normalizeConfigKeyText = (value) => normalizeConfigText(value)
|
|
34645
|
+
.toLowerCase()
|
|
34646
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
34647
|
+
.trim();
|
|
34648
|
+
const buildUserConfigItemKey = ({ scope, category, subCategory, itemName, }) => [scope, category, subCategory, itemName].map(normalizeConfigKeyText).join("|");
|
|
34649
|
+
const sameUserConfigText = (left, right) => normalizeConfigKeyText(left) === normalizeConfigKeyText(right);
|
|
34650
|
+
|
|
34651
|
+
const itemMeta = (item) => ({
|
|
34652
|
+
customItemId: item.id,
|
|
34653
|
+
source: item.source === "sdk-override" ? "sdk-override" : "company-custom",
|
|
34654
|
+
isCompanyCustom: item.source !== "sdk-override",
|
|
34655
|
+
isCompanyOverride: item.source === "sdk-override" || item.isOverride,
|
|
34656
|
+
baseEmissionFactor: item.baseEmissionFactor,
|
|
34657
|
+
overrideKind: item.overrideKind,
|
|
34658
|
+
});
|
|
34659
|
+
const applyScope3Item = (config, item) => {
|
|
34660
|
+
var _a;
|
|
34661
|
+
const scope = config.scope3.find((entry) => sameUserConfigText(entry.name, item.category));
|
|
34662
|
+
const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => sameUserConfigText(entry.category, item.subCategory));
|
|
34663
|
+
if (!group)
|
|
34664
|
+
return;
|
|
34665
|
+
const existing = group.items.find((entry) => sameUserConfigText(entry.item, item.itemName));
|
|
34666
|
+
if (existing) {
|
|
34667
|
+
Object.assign(existing, {
|
|
34668
|
+
emissionFactor: item.emissionFactor,
|
|
34669
|
+
unit: item.unit || existing.unit,
|
|
34670
|
+
requiresMassData: (_a = item.requiresMassData) !== null && _a !== void 0 ? _a : existing.requiresMassData,
|
|
34671
|
+
...itemMeta(item),
|
|
34672
|
+
});
|
|
34673
|
+
return;
|
|
34674
|
+
}
|
|
34675
|
+
group.items = [{
|
|
34676
|
+
item: item.itemName,
|
|
34677
|
+
unit: item.unit,
|
|
34678
|
+
emissionFactor: item.emissionFactor,
|
|
34679
|
+
requiresMassData: item.requiresMassData,
|
|
34680
|
+
...itemMeta(item),
|
|
34681
|
+
}, ...group.items];
|
|
34682
|
+
};
|
|
34683
|
+
const applyFlatItem = (config, item) => {
|
|
34684
|
+
const scopeList = item.scope === "scope2" ? config.scope2 : config.scope1;
|
|
34685
|
+
const scope = scopeList.find((entry) => sameUserConfigText(entry.name, item.category));
|
|
34686
|
+
if (!scope)
|
|
34687
|
+
return;
|
|
34688
|
+
const existing = scope.subProducts.find((entry) => sameUserConfigText(entry.name, item.itemName) &&
|
|
34689
|
+
sameUserConfigText(entry.type, item.subCategory));
|
|
34690
|
+
if (existing) {
|
|
34691
|
+
Object.assign(existing, {
|
|
34692
|
+
emissionFactor: item.emissionFactor,
|
|
34693
|
+
unit: item.unit || existing.unit,
|
|
34694
|
+
...itemMeta(item),
|
|
34695
|
+
});
|
|
34696
|
+
return;
|
|
34697
|
+
}
|
|
34698
|
+
scope.subProducts = [{
|
|
34699
|
+
name: item.itemName,
|
|
34700
|
+
type: item.subCategory,
|
|
34701
|
+
unit: item.unit,
|
|
34702
|
+
emissionFactor: item.emissionFactor,
|
|
34703
|
+
calorificValue: 0,
|
|
34704
|
+
...itemMeta(item),
|
|
34705
|
+
}, ...scope.subProducts];
|
|
34706
|
+
};
|
|
34707
|
+
const mergeUserItemsIntoIndustryConfig = (baseConfig, userItems = []) => {
|
|
34708
|
+
const config = JSON.parse(JSON.stringify(baseConfig));
|
|
34709
|
+
for (const item of userItems.slice().reverse()) {
|
|
34710
|
+
if (item.scope === "scope3")
|
|
34711
|
+
applyScope3Item(config, item);
|
|
34712
|
+
else
|
|
34713
|
+
applyFlatItem(config, item);
|
|
34714
|
+
}
|
|
34715
|
+
return config;
|
|
34716
|
+
};
|
|
34717
|
+
|
|
34643
34718
|
const getItemsForUser = async (apiClient, options = {}) => {
|
|
34644
34719
|
const params = new URLSearchParams();
|
|
34645
34720
|
if (options.industry)
|
|
@@ -34682,39 +34757,18 @@ const updateItemEmissionFactorForUser = async (apiClient, options) => {
|
|
|
34682
34757
|
throw new Error("apiClient.patch is required to update emission factors");
|
|
34683
34758
|
}
|
|
34684
34759
|
const data = await apiClient
|
|
34685
|
-
.patch(`erp-config/items/${options.itemId}/emission-factor`, { json: { emissionFactor: options.emissionFactor } })
|
|
34760
|
+
.patch(`erp-config/items/${options.itemId}/emission-factor`, { json: { emissionFactor: options.emissionFactor, plant: options.plant } })
|
|
34686
34761
|
.json();
|
|
34687
34762
|
return data;
|
|
34688
34763
|
};
|
|
34689
|
-
const
|
|
34690
|
-
|
|
34691
|
-
|
|
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
|
-
}
|
|
34764
|
+
const updateSdkItemEmissionFactorForUser = async (apiClient, options) => {
|
|
34765
|
+
if (!apiClient.put) {
|
|
34766
|
+
throw new Error("apiClient.put is required to override SDK item emission factors");
|
|
34716
34767
|
}
|
|
34717
|
-
|
|
34768
|
+
const data = await apiClient
|
|
34769
|
+
.put("erp-config/items/emission-factor-override", { json: options })
|
|
34770
|
+
.json();
|
|
34771
|
+
return data;
|
|
34718
34772
|
};
|
|
34719
34773
|
|
|
34720
34774
|
// Scope 3 categories configuration for cement industry using API data
|
|
@@ -40246,6 +40300,7 @@ exports.Industries = index;
|
|
|
40246
40300
|
exports.UI_FEATURES = UI_FEATURES;
|
|
40247
40301
|
exports.WATER_PRODUCTS = WATER_PRODUCTS$1;
|
|
40248
40302
|
exports.addItemForUser = addItemForUser;
|
|
40303
|
+
exports.buildUserConfigItemKey = buildUserConfigItemKey;
|
|
40249
40304
|
exports.calculateCCTSEmission = calculateCCTSEmission;
|
|
40250
40305
|
exports.calculateIntensityMetrics = calculateIntensityMetrics;
|
|
40251
40306
|
exports.categorizeApiItem = categorizeApiItem;
|
|
@@ -40279,9 +40334,13 @@ exports.hasIntensities = hasIntensities;
|
|
|
40279
40334
|
exports.isUIFeatureEnabled = isUIFeatureEnabled;
|
|
40280
40335
|
exports.mapIndustryToApiType = mapIndustryToApiType;
|
|
40281
40336
|
exports.mergeUserItemsIntoIndustryConfig = mergeUserItemsIntoIndustryConfig;
|
|
40337
|
+
exports.normalizeConfigKeyText = normalizeConfigKeyText;
|
|
40338
|
+
exports.normalizeConfigText = normalizeConfigText;
|
|
40282
40339
|
exports.resolveEmissionFactorsForUser = resolveEmissionFactorsForUser;
|
|
40340
|
+
exports.sameUserConfigText = sameUserConfigText;
|
|
40283
40341
|
exports.sanitizeNumber = sanitizeNumber;
|
|
40284
40342
|
exports.supportsIntensityCalculations = supportsIntensityCalculations;
|
|
40285
40343
|
exports.updateItemEmissionFactorForUser = updateItemEmissionFactorForUser;
|
|
40344
|
+
exports.updateSdkItemEmissionFactorForUser = updateSdkItemEmissionFactorForUser;
|
|
40286
40345
|
exports.validateCarbonIntensityData = validateCarbonIntensityData;
|
|
40287
40346
|
//# sourceMappingURL=index.js.map
|