@zerocarbon/erp-config-sdk 1.0.22 → 1.0.24
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 +59 -3
- package/dist/index.esm.js +105 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +111 -28
- 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)
|
|
@@ -34650,6 +34725,19 @@ const getItemsForUser = async (apiClient, options = {}) => {
|
|
|
34650
34725
|
.json();
|
|
34651
34726
|
return data.items || [];
|
|
34652
34727
|
};
|
|
34728
|
+
const resolveEmissionFactorsForUser = async (apiClient, options) => {
|
|
34729
|
+
const data = await apiClient
|
|
34730
|
+
.post("erp-config/items/emission-factors/resolve", {
|
|
34731
|
+
json: {
|
|
34732
|
+
industry: options.industry,
|
|
34733
|
+
scope: options.scope,
|
|
34734
|
+
category: options.category,
|
|
34735
|
+
items: options.items,
|
|
34736
|
+
},
|
|
34737
|
+
})
|
|
34738
|
+
.json();
|
|
34739
|
+
return data.items || [];
|
|
34740
|
+
};
|
|
34653
34741
|
const addItemForUser = async (apiClient, options) => {
|
|
34654
34742
|
const data = await apiClient
|
|
34655
34743
|
.post("erp-config/items/bulk", {
|
|
@@ -34664,35 +34752,23 @@ const addItemForUser = async (apiClient, options) => {
|
|
|
34664
34752
|
.json();
|
|
34665
34753
|
return data.items || [];
|
|
34666
34754
|
};
|
|
34667
|
-
const
|
|
34668
|
-
|
|
34669
|
-
|
|
34670
|
-
if (item.scope === "scope3") {
|
|
34671
|
-
const scope = config.scope3.find((entry) => entry.name === item.category);
|
|
34672
|
-
const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => entry.category === item.subCategory);
|
|
34673
|
-
if (group && !group.items.some((entry) => entry.item === item.itemName)) {
|
|
34674
|
-
group.items.push({
|
|
34675
|
-
item: item.itemName,
|
|
34676
|
-
unit: item.unit,
|
|
34677
|
-
emissionFactor: item.emissionFactor,
|
|
34678
|
-
requiresMassData: item.requiresMassData,
|
|
34679
|
-
});
|
|
34680
|
-
}
|
|
34681
|
-
continue;
|
|
34682
|
-
}
|
|
34683
|
-
const scopeList = item.scope === "scope2" ? config.scope2 : config.scope1;
|
|
34684
|
-
const scope = scopeList.find((entry) => entry.name === item.category);
|
|
34685
|
-
if (scope && !scope.subProducts.some((entry) => entry.name === item.itemName)) {
|
|
34686
|
-
scope.subProducts.push({
|
|
34687
|
-
name: item.itemName,
|
|
34688
|
-
type: item.subCategory,
|
|
34689
|
-
unit: item.unit,
|
|
34690
|
-
emissionFactor: item.emissionFactor,
|
|
34691
|
-
calorificValue: 0,
|
|
34692
|
-
});
|
|
34693
|
-
}
|
|
34755
|
+
const updateItemEmissionFactorForUser = async (apiClient, options) => {
|
|
34756
|
+
if (!apiClient.patch) {
|
|
34757
|
+
throw new Error("apiClient.patch is required to update emission factors");
|
|
34694
34758
|
}
|
|
34695
|
-
|
|
34759
|
+
const data = await apiClient
|
|
34760
|
+
.patch(`erp-config/items/${options.itemId}/emission-factor`, { json: { emissionFactor: options.emissionFactor } })
|
|
34761
|
+
.json();
|
|
34762
|
+
return data;
|
|
34763
|
+
};
|
|
34764
|
+
const updateSdkItemEmissionFactorForUser = async (apiClient, options) => {
|
|
34765
|
+
if (!apiClient.put) {
|
|
34766
|
+
throw new Error("apiClient.put is required to override SDK item emission factors");
|
|
34767
|
+
}
|
|
34768
|
+
const data = await apiClient
|
|
34769
|
+
.put("erp-config/items/emission-factor-override", { json: options })
|
|
34770
|
+
.json();
|
|
34771
|
+
return data;
|
|
34696
34772
|
};
|
|
34697
34773
|
|
|
34698
34774
|
// Scope 3 categories configuration for cement industry using API data
|
|
@@ -40224,6 +40300,7 @@ exports.Industries = index;
|
|
|
40224
40300
|
exports.UI_FEATURES = UI_FEATURES;
|
|
40225
40301
|
exports.WATER_PRODUCTS = WATER_PRODUCTS$1;
|
|
40226
40302
|
exports.addItemForUser = addItemForUser;
|
|
40303
|
+
exports.buildUserConfigItemKey = buildUserConfigItemKey;
|
|
40227
40304
|
exports.calculateCCTSEmission = calculateCCTSEmission;
|
|
40228
40305
|
exports.calculateIntensityMetrics = calculateIntensityMetrics;
|
|
40229
40306
|
exports.categorizeApiItem = categorizeApiItem;
|
|
@@ -40257,7 +40334,13 @@ exports.hasIntensities = hasIntensities;
|
|
|
40257
40334
|
exports.isUIFeatureEnabled = isUIFeatureEnabled;
|
|
40258
40335
|
exports.mapIndustryToApiType = mapIndustryToApiType;
|
|
40259
40336
|
exports.mergeUserItemsIntoIndustryConfig = mergeUserItemsIntoIndustryConfig;
|
|
40337
|
+
exports.normalizeConfigKeyText = normalizeConfigKeyText;
|
|
40338
|
+
exports.normalizeConfigText = normalizeConfigText;
|
|
40339
|
+
exports.resolveEmissionFactorsForUser = resolveEmissionFactorsForUser;
|
|
40340
|
+
exports.sameUserConfigText = sameUserConfigText;
|
|
40260
40341
|
exports.sanitizeNumber = sanitizeNumber;
|
|
40261
40342
|
exports.supportsIntensityCalculations = supportsIntensityCalculations;
|
|
40343
|
+
exports.updateItemEmissionFactorForUser = updateItemEmissionFactorForUser;
|
|
40344
|
+
exports.updateSdkItemEmissionFactorForUser = updateSdkItemEmissionFactorForUser;
|
|
40262
40345
|
exports.validateCarbonIntensityData = validateCarbonIntensityData;
|
|
40263
40346
|
//# sourceMappingURL=index.js.map
|