@zerocarbon/erp-config-sdk 1.0.34 → 1.0.35
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 +15 -1
- package/dist/index.esm.js +26 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38646,6 +38646,7 @@ function transformIndustryConfigToBackend(config) {
|
|
|
38646
38646
|
function transformProductToBackend(product) {
|
|
38647
38647
|
return {
|
|
38648
38648
|
name: product.name,
|
|
38649
|
+
materialCode: product.materialCode,
|
|
38649
38650
|
unit: product.unit,
|
|
38650
38651
|
type: product.type,
|
|
38651
38652
|
calorificValue: product.calorificValue,
|
|
@@ -38657,6 +38658,7 @@ function transformProductToBackend(product) {
|
|
|
38657
38658
|
function transformEmissionItemToBackend(item) {
|
|
38658
38659
|
return {
|
|
38659
38660
|
item: item.item,
|
|
38661
|
+
materialCode: item.materialCode,
|
|
38660
38662
|
emissionFactor: item.emissionFactor,
|
|
38661
38663
|
unit: item.unit
|
|
38662
38664
|
};
|
|
@@ -38846,6 +38848,7 @@ class BillManager {
|
|
|
38846
38848
|
this.matchField(bill.subCategory, options.subCategory, "subCategory");
|
|
38847
38849
|
const matchesNestedSubCategory = !options.nestedSubCategory ||
|
|
38848
38850
|
this.matchField(bill.nestedSubCategory, options.nestedSubCategory, "nestedSubCategory");
|
|
38851
|
+
const matchesPlantCode = !options.plantCode || bill.plantCode === options.plantCode;
|
|
38849
38852
|
const matchesPlant = !options.plant || bill.plant === options.plant;
|
|
38850
38853
|
return (matchesCategory &&
|
|
38851
38854
|
matchesYear &&
|
|
@@ -38853,6 +38856,7 @@ class BillManager {
|
|
|
38853
38856
|
matchesType &&
|
|
38854
38857
|
matchesSubCategory &&
|
|
38855
38858
|
matchesNestedSubCategory &&
|
|
38859
|
+
matchesPlantCode &&
|
|
38856
38860
|
matchesPlant);
|
|
38857
38861
|
});
|
|
38858
38862
|
}
|
|
@@ -38886,7 +38890,7 @@ class BillManager {
|
|
|
38886
38890
|
bill.nestedSubCategory === emissionItem.item &&
|
|
38887
38891
|
bill.subCategory ===
|
|
38888
38892
|
(emissionItem.subCategory || emissionItem.category) &&
|
|
38889
|
-
(!plantId || bill.plant === plantId) // Filter by plant if provided
|
|
38893
|
+
(!plantId || bill.plant === plantId || bill.plantCode === plantId) // Filter by plant if provided
|
|
38890
38894
|
);
|
|
38891
38895
|
// NO fallback matching - each emission item should have its own unique bill
|
|
38892
38896
|
return matchingBills;
|
|
@@ -39119,6 +39123,7 @@ class EmissionSourceGenerator {
|
|
|
39119
39123
|
sources.push({
|
|
39120
39124
|
id: sourceId,
|
|
39121
39125
|
itemName: subProduct.name,
|
|
39126
|
+
materialCode: subProduct.materialCode,
|
|
39122
39127
|
category: scopeConfig.name,
|
|
39123
39128
|
subcategory: subProduct.type || "N/A",
|
|
39124
39129
|
emissionFactor: subProduct.emissionFactor || 0,
|
|
@@ -39156,6 +39161,7 @@ class EmissionSourceGenerator {
|
|
|
39156
39161
|
sources.push({
|
|
39157
39162
|
id: sourceId,
|
|
39158
39163
|
itemName: apiItem.item,
|
|
39164
|
+
materialCode: apiItem.materialCode,
|
|
39159
39165
|
category: scopeConfig.name,
|
|
39160
39166
|
subcategory: apiItem.subCategory || apiItem.category,
|
|
39161
39167
|
emissionFactor: apiItem.emissionFactor,
|
|
@@ -39200,6 +39206,7 @@ class EmissionSourceGenerator {
|
|
|
39200
39206
|
sources.push({
|
|
39201
39207
|
id: sourceId,
|
|
39202
39208
|
itemName: item.item,
|
|
39209
|
+
materialCode: item.materialCode,
|
|
39203
39210
|
category: subProduct.name || scopeConfig.name,
|
|
39204
39211
|
subcategory: item.item,
|
|
39205
39212
|
emissionFactor: item.emissionFactor,
|
|
@@ -39298,7 +39305,15 @@ const normalizeConfigKeyText = (value) => normalizeConfigText(value)
|
|
|
39298
39305
|
.toLowerCase()
|
|
39299
39306
|
.replace(/[^a-z0-9]+/g, " ")
|
|
39300
39307
|
.trim();
|
|
39301
|
-
const buildUserConfigItemKey = ({ scope, category, subCategory, itemName, }) => [
|
|
39308
|
+
const buildUserConfigItemKey = ({ scope, category, subCategory, itemName, materialCode, }) => [
|
|
39309
|
+
scope,
|
|
39310
|
+
category,
|
|
39311
|
+
subCategory,
|
|
39312
|
+
itemName,
|
|
39313
|
+
...(materialCode ? [materialCode] : []),
|
|
39314
|
+
]
|
|
39315
|
+
.map(normalizeConfigKeyText)
|
|
39316
|
+
.join("|");
|
|
39302
39317
|
const sameUserConfigText = (left, right) => normalizeConfigKeyText(left) === normalizeConfigKeyText(right);
|
|
39303
39318
|
|
|
39304
39319
|
const itemMeta = (item) => ({
|
|
@@ -39308,14 +39323,20 @@ const itemMeta = (item) => ({
|
|
|
39308
39323
|
isCompanyOverride: item.source === "sdk-override" || item.isOverride,
|
|
39309
39324
|
baseEmissionFactor: item.baseEmissionFactor,
|
|
39310
39325
|
overrideKind: item.overrideKind,
|
|
39326
|
+
materialCode: item.materialCode,
|
|
39327
|
+
sourceSystem: item.sourceSystem,
|
|
39328
|
+
sourceUnit: item.sourceUnit,
|
|
39311
39329
|
});
|
|
39330
|
+
const sameMaterialIdentity = (entry, item) => item.materialCode
|
|
39331
|
+
? sameUserConfigText(entry.materialCode, item.materialCode)
|
|
39332
|
+
: !entry.materialCode;
|
|
39312
39333
|
const applyScope3Item = (config, item) => {
|
|
39313
39334
|
var _a;
|
|
39314
39335
|
const scope = config.scope3.find((entry) => sameUserConfigText(entry.name, item.category));
|
|
39315
39336
|
const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => sameUserConfigText(entry.category, item.subCategory));
|
|
39316
39337
|
if (!group)
|
|
39317
39338
|
return;
|
|
39318
|
-
const existing = group.items.find((entry) => sameUserConfigText(entry.item, item.itemName));
|
|
39339
|
+
const existing = group.items.find((entry) => sameUserConfigText(entry.item, item.itemName) && sameMaterialIdentity(entry, item));
|
|
39319
39340
|
if (existing) {
|
|
39320
39341
|
Object.assign(existing, {
|
|
39321
39342
|
emissionFactor: item.emissionFactor,
|
|
@@ -39339,7 +39360,8 @@ const applyFlatItem = (config, item) => {
|
|
|
39339
39360
|
if (!scope)
|
|
39340
39361
|
return;
|
|
39341
39362
|
const existing = scope.subProducts.find((entry) => sameUserConfigText(entry.name, item.itemName) &&
|
|
39342
|
-
sameUserConfigText(entry.type, item.subCategory)
|
|
39363
|
+
sameUserConfigText(entry.type, item.subCategory) &&
|
|
39364
|
+
sameMaterialIdentity(entry, item));
|
|
39343
39365
|
if (existing) {
|
|
39344
39366
|
Object.assign(existing, {
|
|
39345
39367
|
emissionFactor: item.emissionFactor,
|