@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 CHANGED
@@ -110,6 +110,7 @@ type VehicleEmissionsResponse = StrapiResponse<VehicleEmissionAttributes>;
110
110
  interface ProcessedEmissionItem {
111
111
  id: string;
112
112
  item: string;
113
+ materialCode?: string;
113
114
  category: string;
114
115
  subCategory?: string;
115
116
  mode?: string;
@@ -153,6 +154,7 @@ interface Bill {
153
154
  _id?: string;
154
155
  user?: string;
155
156
  plant?: string;
157
+ plantCode?: string;
156
158
  category: string;
157
159
  year: number;
158
160
  month: number;
@@ -1050,6 +1052,7 @@ type IndustryConfigWithRCO = IndustryConfig & {
1050
1052
  declare const getIndustryConfig$1: (industry: string, username?: string) => IndustryConfigWithRCO;
1051
1053
  type Product = {
1052
1054
  name: string;
1055
+ materialCode?: string;
1053
1056
  unit: string;
1054
1057
  type: string;
1055
1058
  calorificValue: number;
@@ -1068,6 +1071,7 @@ type Scope = {
1068
1071
  };
1069
1072
  type EmissionItem$k = {
1070
1073
  item: string;
1074
+ materialCode?: string;
1071
1075
  emissionFactor: number;
1072
1076
  unit: string;
1073
1077
  };
@@ -1087,6 +1091,7 @@ type Scope3Item$2 = {
1087
1091
  };
1088
1092
  type BackendProduct = {
1089
1093
  name: string;
1094
+ materialCode?: string;
1090
1095
  unit: string;
1091
1096
  type: string;
1092
1097
  calorificValue: number;
@@ -1095,6 +1100,7 @@ type BackendProduct = {
1095
1100
  };
1096
1101
  type BackendEmissionItem = {
1097
1102
  item: string;
1103
+ materialCode?: string;
1098
1104
  emissionFactor: number;
1099
1105
  unit: string;
1100
1106
  };
@@ -1188,6 +1194,7 @@ interface BillFilterOptions {
1188
1194
  subCategory?: string;
1189
1195
  nestedSubCategory?: string;
1190
1196
  plant?: string;
1197
+ plantCode?: string;
1191
1198
  }
1192
1199
  interface BillCalculationConfig {
1193
1200
  industry: string;
@@ -1256,6 +1263,7 @@ declare const formatKPIEmission: (value: number) => string;
1256
1263
  interface EmissionSource {
1257
1264
  id: string;
1258
1265
  itemName: string;
1266
+ materialCode?: string;
1259
1267
  category: string;
1260
1268
  subcategory: string;
1261
1269
  emissionFactor: number;
@@ -1273,6 +1281,7 @@ interface EmissionSource {
1273
1281
  }
1274
1282
  interface ScopeProduct {
1275
1283
  name: string;
1284
+ materialCode?: string;
1276
1285
  displayName?: string;
1277
1286
  type?: string;
1278
1287
  unit?: string;
@@ -1280,6 +1289,7 @@ interface ScopeProduct {
1280
1289
  emissionFactor?: number;
1281
1290
  items?: Array<{
1282
1291
  item: string;
1292
+ materialCode?: string;
1283
1293
  emissionFactor: number;
1284
1294
  unit: string;
1285
1295
  requiresMassData?: boolean;
@@ -1320,11 +1330,12 @@ declare const getApiIndustryType: (erpIndustry: string) => IndustryType;
1320
1330
 
1321
1331
  declare const normalizeConfigText: (value: unknown) => string;
1322
1332
  declare const normalizeConfigKeyText: (value: unknown) => string;
1323
- declare const buildUserConfigItemKey: ({ scope, category, subCategory, itemName, }: {
1333
+ declare const buildUserConfigItemKey: ({ scope, category, subCategory, itemName, materialCode, }: {
1324
1334
  scope?: unknown;
1325
1335
  category?: unknown;
1326
1336
  subCategory?: unknown;
1327
1337
  itemName?: unknown;
1338
+ materialCode?: unknown;
1328
1339
  }) => string;
1329
1340
  declare const sameUserConfigText: (left: unknown, right: unknown) => boolean;
1330
1341
 
@@ -1352,6 +1363,7 @@ type UserConfigItem = {
1352
1363
  category: string;
1353
1364
  subCategory: string;
1354
1365
  itemName: string;
1366
+ materialCode?: string;
1355
1367
  unit: string;
1356
1368
  emissionFactor: number;
1357
1369
  emissionFactorSource?: {
@@ -1368,6 +1380,8 @@ type UserConfigItem = {
1368
1380
  baseEmissionFactor?: number;
1369
1381
  overrideKind?: "custom-item" | "sdk-emission-factor" | string;
1370
1382
  isOverride?: boolean;
1383
+ sourceSystem?: string;
1384
+ sourceUnit?: string;
1371
1385
  source?: string;
1372
1386
  };
1373
1387
  type UserEmissionFactorResolution = Partial<UserConfigItem> & {
package/dist/index.esm.js CHANGED
@@ -38644,6 +38644,7 @@ function transformIndustryConfigToBackend(config) {
38644
38644
  function transformProductToBackend(product) {
38645
38645
  return {
38646
38646
  name: product.name,
38647
+ materialCode: product.materialCode,
38647
38648
  unit: product.unit,
38648
38649
  type: product.type,
38649
38650
  calorificValue: product.calorificValue,
@@ -38655,6 +38656,7 @@ function transformProductToBackend(product) {
38655
38656
  function transformEmissionItemToBackend(item) {
38656
38657
  return {
38657
38658
  item: item.item,
38659
+ materialCode: item.materialCode,
38658
38660
  emissionFactor: item.emissionFactor,
38659
38661
  unit: item.unit
38660
38662
  };
@@ -38844,6 +38846,7 @@ class BillManager {
38844
38846
  this.matchField(bill.subCategory, options.subCategory, "subCategory");
38845
38847
  const matchesNestedSubCategory = !options.nestedSubCategory ||
38846
38848
  this.matchField(bill.nestedSubCategory, options.nestedSubCategory, "nestedSubCategory");
38849
+ const matchesPlantCode = !options.plantCode || bill.plantCode === options.plantCode;
38847
38850
  const matchesPlant = !options.plant || bill.plant === options.plant;
38848
38851
  return (matchesCategory &&
38849
38852
  matchesYear &&
@@ -38851,6 +38854,7 @@ class BillManager {
38851
38854
  matchesType &&
38852
38855
  matchesSubCategory &&
38853
38856
  matchesNestedSubCategory &&
38857
+ matchesPlantCode &&
38854
38858
  matchesPlant);
38855
38859
  });
38856
38860
  }
@@ -38884,7 +38888,7 @@ class BillManager {
38884
38888
  bill.nestedSubCategory === emissionItem.item &&
38885
38889
  bill.subCategory ===
38886
38890
  (emissionItem.subCategory || emissionItem.category) &&
38887
- (!plantId || bill.plant === plantId) // Filter by plant if provided
38891
+ (!plantId || bill.plant === plantId || bill.plantCode === plantId) // Filter by plant if provided
38888
38892
  );
38889
38893
  // NO fallback matching - each emission item should have its own unique bill
38890
38894
  return matchingBills;
@@ -39117,6 +39121,7 @@ class EmissionSourceGenerator {
39117
39121
  sources.push({
39118
39122
  id: sourceId,
39119
39123
  itemName: subProduct.name,
39124
+ materialCode: subProduct.materialCode,
39120
39125
  category: scopeConfig.name,
39121
39126
  subcategory: subProduct.type || "N/A",
39122
39127
  emissionFactor: subProduct.emissionFactor || 0,
@@ -39154,6 +39159,7 @@ class EmissionSourceGenerator {
39154
39159
  sources.push({
39155
39160
  id: sourceId,
39156
39161
  itemName: apiItem.item,
39162
+ materialCode: apiItem.materialCode,
39157
39163
  category: scopeConfig.name,
39158
39164
  subcategory: apiItem.subCategory || apiItem.category,
39159
39165
  emissionFactor: apiItem.emissionFactor,
@@ -39198,6 +39204,7 @@ class EmissionSourceGenerator {
39198
39204
  sources.push({
39199
39205
  id: sourceId,
39200
39206
  itemName: item.item,
39207
+ materialCode: item.materialCode,
39201
39208
  category: subProduct.name || scopeConfig.name,
39202
39209
  subcategory: item.item,
39203
39210
  emissionFactor: item.emissionFactor,
@@ -39296,7 +39303,15 @@ const normalizeConfigKeyText = (value) => normalizeConfigText(value)
39296
39303
  .toLowerCase()
39297
39304
  .replace(/[^a-z0-9]+/g, " ")
39298
39305
  .trim();
39299
- const buildUserConfigItemKey = ({ scope, category, subCategory, itemName, }) => [scope, category, subCategory, itemName].map(normalizeConfigKeyText).join("|");
39306
+ const buildUserConfigItemKey = ({ scope, category, subCategory, itemName, materialCode, }) => [
39307
+ scope,
39308
+ category,
39309
+ subCategory,
39310
+ itemName,
39311
+ ...(materialCode ? [materialCode] : []),
39312
+ ]
39313
+ .map(normalizeConfigKeyText)
39314
+ .join("|");
39300
39315
  const sameUserConfigText = (left, right) => normalizeConfigKeyText(left) === normalizeConfigKeyText(right);
39301
39316
 
39302
39317
  const itemMeta = (item) => ({
@@ -39306,14 +39321,20 @@ const itemMeta = (item) => ({
39306
39321
  isCompanyOverride: item.source === "sdk-override" || item.isOverride,
39307
39322
  baseEmissionFactor: item.baseEmissionFactor,
39308
39323
  overrideKind: item.overrideKind,
39324
+ materialCode: item.materialCode,
39325
+ sourceSystem: item.sourceSystem,
39326
+ sourceUnit: item.sourceUnit,
39309
39327
  });
39328
+ const sameMaterialIdentity = (entry, item) => item.materialCode
39329
+ ? sameUserConfigText(entry.materialCode, item.materialCode)
39330
+ : !entry.materialCode;
39310
39331
  const applyScope3Item = (config, item) => {
39311
39332
  var _a;
39312
39333
  const scope = config.scope3.find((entry) => sameUserConfigText(entry.name, item.category));
39313
39334
  const group = scope === null || scope === void 0 ? void 0 : scope.subProducts.find((entry) => sameUserConfigText(entry.category, item.subCategory));
39314
39335
  if (!group)
39315
39336
  return;
39316
- const existing = group.items.find((entry) => sameUserConfigText(entry.item, item.itemName));
39337
+ const existing = group.items.find((entry) => sameUserConfigText(entry.item, item.itemName) && sameMaterialIdentity(entry, item));
39317
39338
  if (existing) {
39318
39339
  Object.assign(existing, {
39319
39340
  emissionFactor: item.emissionFactor,
@@ -39337,7 +39358,8 @@ const applyFlatItem = (config, item) => {
39337
39358
  if (!scope)
39338
39359
  return;
39339
39360
  const existing = scope.subProducts.find((entry) => sameUserConfigText(entry.name, item.itemName) &&
39340
- sameUserConfigText(entry.type, item.subCategory));
39361
+ sameUserConfigText(entry.type, item.subCategory) &&
39362
+ sameMaterialIdentity(entry, item));
39341
39363
  if (existing) {
39342
39364
  Object.assign(existing, {
39343
39365
  emissionFactor: item.emissionFactor,