@zerocarbon/erp-config-sdk 1.0.14 β 1.0.16
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/README.md +528 -74
- package/dist/index.d.ts +120 -40
- package/dist/index.esm.js +914 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +915 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Zero Carbon ERP Config SDK
|
|
2
2
|
|
|
3
|
-
A comprehensive TypeScript SDK providing emission configurations and calculation utilities for carbon footprint tracking across 24+ industries.
|
|
3
|
+
A comprehensive TypeScript SDK providing emission configurations and calculation utilities for carbon footprint tracking across 24+ industries. **Now with full backend compatibility** - use the same SDK on both frontend (React) and backend (Node.js) applications.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,13 +10,60 @@ npm install erp-config-sdk
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
- 24+ Industry-specific emission configurations
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
13
|
+
- **π 24+ Industry-specific emission configurations**
|
|
14
|
+
- **π RCO module configuration** parsed from the ERP template sheets
|
|
15
|
+
- **π Type-safe emission data structures with deep type safety**
|
|
16
|
+
- **π₯οΈ Full backend compatibility** - No React dependencies in data output
|
|
17
|
+
- **π Carbon intensity calculations**
|
|
18
|
+
- **β‘ Emission source generators**
|
|
19
|
+
- **πΊοΈ Industry mapping utilities**
|
|
20
|
+
- **π¨ React Icons integration** (frontend only)
|
|
21
|
+
- **βοΈ UI feature configurations**
|
|
22
|
+
- **π§ Granular configuration functions** for precise data access
|
|
23
|
+
|
|
24
|
+
## Backend vs Frontend Usage
|
|
25
|
+
|
|
26
|
+
### π₯οΈ Backend Usage (Node.js, API servers)
|
|
27
|
+
Perfect for backend applications, APIs, and server-side processing:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import {
|
|
31
|
+
getAllConfig,
|
|
32
|
+
getUserNameBackendConfig,
|
|
33
|
+
getIndustryBackendConfig,
|
|
34
|
+
getCombinedBackendConfig,
|
|
35
|
+
type BackendIndustryConfig,
|
|
36
|
+
type BackendUserConfig
|
|
37
|
+
} from 'erp-config-sdk';
|
|
38
|
+
|
|
39
|
+
// Get all configurations (no React components)
|
|
40
|
+
const allConfigs = getAllConfig();
|
|
41
|
+
|
|
42
|
+
// Get specific industry configuration
|
|
43
|
+
const cementConfig = getIndustryBackendConfig('Cement');
|
|
44
|
+
|
|
45
|
+
// Get user-specific configuration
|
|
46
|
+
const gasLabConfig = getUserNameBackendConfig('gas lab');
|
|
47
|
+
|
|
48
|
+
// Get combined configuration (user overrides + industry)
|
|
49
|
+
const combinedConfig = getCombinedBackendConfig('Cement', 'gas lab');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### βοΈ Frontend Usage (React applications)
|
|
53
|
+
Full React integration with icons and UI components:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import {
|
|
57
|
+
getIndustryConfig,
|
|
58
|
+
getUIFeatures,
|
|
59
|
+
type IndustryConfig
|
|
60
|
+
} from 'erp-config-sdk';
|
|
61
|
+
|
|
62
|
+
// Get configuration with React icons
|
|
63
|
+
const config = getIndustryConfig('Cement');
|
|
64
|
+
const uiFeatures = getUIFeatures('manufacturing');
|
|
65
|
+
const rcoSheets = config.rco;
|
|
66
|
+
```
|
|
20
67
|
|
|
21
68
|
## Industries Supported
|
|
22
69
|
|
|
@@ -45,7 +92,138 @@ npm install erp-config-sdk
|
|
|
45
92
|
- Textile Manufacturing
|
|
46
93
|
- Utilities & Energy
|
|
47
94
|
|
|
48
|
-
##
|
|
95
|
+
## Backend Functions
|
|
96
|
+
|
|
97
|
+
### Core Backend Functions
|
|
98
|
+
|
|
99
|
+
#### `getAllConfig(): AllConfigurations`
|
|
100
|
+
Returns all industry and user configurations in backend-compatible format.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const allConfigs = getAllConfig();
|
|
104
|
+
console.log(allConfigs.industries.Cement.scope1); // Array of backend scopes
|
|
105
|
+
console.log(allConfigs.userConfigs['gas lab']); // User-specific config
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### `getIndustryBackendConfig(industryName: string): BackendIndustryConfig | undefined`
|
|
109
|
+
Get complete configuration for a specific industry.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const cementConfig = getIndustryBackendConfig('Cement');
|
|
113
|
+
if (cementConfig) {
|
|
114
|
+
console.log(`Scope1 items: ${cementConfig.scope1.length}`);
|
|
115
|
+
console.log(`Scope2 items: ${cementConfig.scope2.length}`);
|
|
116
|
+
console.log(`Scope3 items: ${cementConfig.scope3.length}`);
|
|
117
|
+
console.log(`RCO sheets: ${cementConfig.rco.length}`);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### `getUserNameBackendConfig(username: string): BackendUserConfig | undefined`
|
|
122
|
+
Get user-specific configurations by username.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const gasLabUser = getUserNameBackendConfig('gas lab');
|
|
126
|
+
if (gasLabUser) {
|
|
127
|
+
console.log('User has custom scope1:', gasLabUser.scope1?.length || 0);
|
|
128
|
+
console.log('User has water management:', !!gasLabUser.waterManagement);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### `getCombinedBackendConfig(industryName: string, username?: string): BackendIndustryConfig | undefined`
|
|
133
|
+
Get combined configuration where user settings override industry defaults.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Industry config only
|
|
137
|
+
const industry = getCombinedBackendConfig('Cement');
|
|
138
|
+
|
|
139
|
+
// Combined with user overrides
|
|
140
|
+
const combined = getCombinedBackendConfig('Cement', 'gas lab');
|
|
141
|
+
|
|
142
|
+
// User-specific configurations will override industry defaults
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Deep Type Safety
|
|
146
|
+
|
|
147
|
+
All backend functions provide **complete type safety from root to leaf properties**:
|
|
148
|
+
|
|
149
|
+
### Core Backend Types
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Product-level typing
|
|
153
|
+
type BackendProduct = {
|
|
154
|
+
name: string;
|
|
155
|
+
unit: string;
|
|
156
|
+
type: string;
|
|
157
|
+
calorificValue: number;
|
|
158
|
+
emissionFactor: number;
|
|
159
|
+
energyConversionFactor?: number;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Emission item typing
|
|
163
|
+
type BackendEmissionItem = {
|
|
164
|
+
item: string;
|
|
165
|
+
emissionFactor: number;
|
|
166
|
+
unit: string;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Equipment category typing
|
|
170
|
+
type BackendEquipmentCategory = {
|
|
171
|
+
category: string;
|
|
172
|
+
items: BackendEmissionItem[];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// Scope configuration typing (no React components)
|
|
176
|
+
type BackendScope = {
|
|
177
|
+
name: string;
|
|
178
|
+
icon?: string; // String instead of React component
|
|
179
|
+
scope: string;
|
|
180
|
+
unit: string;
|
|
181
|
+
subProducts: BackendProduct[]; // Fully typed products
|
|
182
|
+
desc: string;
|
|
183
|
+
group?: string;
|
|
184
|
+
className?: string;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Complete industry configuration
|
|
188
|
+
type BackendIndustryConfig = {
|
|
189
|
+
scope1: BackendScope[];
|
|
190
|
+
scope2: BackendScope[];
|
|
191
|
+
scope3: BackendScope3Item[];
|
|
192
|
+
rco: BackendScope3Item[];
|
|
193
|
+
additionalScopes?: {
|
|
194
|
+
[key: string]: BackendAdditionalScopeItem[];
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Data Access Examples
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Access emission factors with full type safety
|
|
203
|
+
const config = getIndustryBackendConfig('Cement');
|
|
204
|
+
if (config?.scope1[0]?.subProducts[0]) {
|
|
205
|
+
const product = config.scope1[0].subProducts[0];
|
|
206
|
+
|
|
207
|
+
// All properties are typed and accessible
|
|
208
|
+
const factor: number = product.emissionFactor;
|
|
209
|
+
const unit: string = product.unit;
|
|
210
|
+
const name: string = product.name;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Access scope3 emission data
|
|
214
|
+
if (config?.scope3[0]?.subProducts[0]?.items[0]) {
|
|
215
|
+
const emissionItem = config.scope3[0].subProducts[0].items[0];
|
|
216
|
+
|
|
217
|
+
// Fully typed emission data
|
|
218
|
+
const itemName: string = emissionItem.item;
|
|
219
|
+
const factor: number = emissionItem.emissionFactor;
|
|
220
|
+
const unit: string = emissionItem.unit;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Frontend Integration (React)
|
|
225
|
+
|
|
226
|
+
When using in React applications, you get the same data plus React components:
|
|
49
227
|
|
|
50
228
|
```typescript
|
|
51
229
|
import {
|
|
@@ -54,9 +232,9 @@ import {
|
|
|
54
232
|
IndustryConfig,
|
|
55
233
|
calculateEmissionFootprint,
|
|
56
234
|
getIndustryFromCompanyName
|
|
57
|
-
} from '
|
|
235
|
+
} from 'erp-config-sdk';
|
|
58
236
|
|
|
59
|
-
// Get configuration for a specific industry
|
|
237
|
+
// Get configuration for a specific industry (includes React icons)
|
|
60
238
|
const automobileConfig = getIndustryConfig('automobile');
|
|
61
239
|
|
|
62
240
|
// Get industry mapping from company name
|
|
@@ -71,60 +249,207 @@ const emissionData: EmissionData = {
|
|
|
71
249
|
};
|
|
72
250
|
```
|
|
73
251
|
|
|
74
|
-
|
|
252
|
+
### React Components with Icons
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { FaIndustry } from 'react-icons/fa';
|
|
256
|
+
import { getUIFeatures, getIndustryConfig } from 'erp-config-sdk';
|
|
257
|
+
|
|
258
|
+
const features = getUIFeatures('manufacturing');
|
|
259
|
+
const config = getIndustryConfig('Manufacturing');
|
|
260
|
+
|
|
261
|
+
function IndustryCard() {
|
|
262
|
+
const IconComponent = config.scope1[0]?.icon || FaIndustry;
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<div>
|
|
266
|
+
<IconComponent size={24} />
|
|
267
|
+
<span>{config.scope1[0]?.name}</span>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
```
|
|
75
272
|
|
|
76
|
-
|
|
273
|
+
## Configuration Structure
|
|
274
|
+
|
|
275
|
+
Each industry provides comprehensive emission configurations:
|
|
77
276
|
|
|
78
277
|
- **Scope 1 Emissions**: Direct emissions from company operations
|
|
79
|
-
- **Scope 2 Emissions**: Indirect emissions from purchased energy
|
|
278
|
+
- **Scope 2 Emissions**: Indirect emissions from purchased energy
|
|
80
279
|
- **Scope 3 Emissions**: Indirect emissions from value chain activities
|
|
81
|
-
- **
|
|
82
|
-
- **
|
|
280
|
+
- **Additional Scopes**: Water management and other custom scopes
|
|
281
|
+
- **UI Features**: Icon mappings and display configurations (frontend)
|
|
282
|
+
- **Deep Type Safety**: Complete typing from root to all nested properties
|
|
83
283
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
### Custom Emission Calculations
|
|
284
|
+
### Data Structure Overview
|
|
87
285
|
|
|
88
286
|
```typescript
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
287
|
+
// Complete configuration structure
|
|
288
|
+
interface AllConfigurations {
|
|
289
|
+
industries: {
|
|
290
|
+
[industryName: string]: {
|
|
291
|
+
scope1: BackendScope[]; // Direct emissions
|
|
292
|
+
scope2: BackendScope[]; // Energy emissions
|
|
293
|
+
scope3: BackendScope3Item[]; // Value chain emissions
|
|
294
|
+
additionalScopes?: { // Custom scopes
|
|
295
|
+
waterManagement: BackendAdditionalScopeItem[];
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
userConfigs: {
|
|
300
|
+
[username: string]: {
|
|
301
|
+
scope1?: BackendScope[];
|
|
302
|
+
scope2?: BackendScope[];
|
|
303
|
+
scope3?: BackendScope3Item[];
|
|
304
|
+
waterManagement?: BackendScope;
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Real-World Usage Examples
|
|
95
311
|
|
|
96
|
-
|
|
97
|
-
const formatted = formatEmissions(1234.567); // "1,234.57"
|
|
312
|
+
### Backend API Example
|
|
98
313
|
|
|
99
|
-
|
|
100
|
-
|
|
314
|
+
```typescript
|
|
315
|
+
// Express.js API endpoint
|
|
316
|
+
app.get('/api/emissions/:industry', (req, res) => {
|
|
317
|
+
const { industry } = req.params;
|
|
318
|
+
const { username } = req.query;
|
|
319
|
+
|
|
320
|
+
// Get appropriate configuration
|
|
321
|
+
const config = username
|
|
322
|
+
? getCombinedBackendConfig(industry, username)
|
|
323
|
+
: getIndustryBackendConfig(industry);
|
|
324
|
+
|
|
325
|
+
if (!config) {
|
|
326
|
+
return res.status(404).json({ error: 'Industry not found' });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Return JSON-serialized configuration
|
|
330
|
+
res.json({
|
|
331
|
+
industry,
|
|
332
|
+
username,
|
|
333
|
+
configuration: config,
|
|
334
|
+
scope1Count: config.scope1.length,
|
|
335
|
+
scope2Count: config.scope2.length,
|
|
336
|
+
scope3Count: config.scope3.length
|
|
337
|
+
});
|
|
338
|
+
});
|
|
101
339
|
```
|
|
102
340
|
|
|
103
|
-
###
|
|
341
|
+
### Database Integration Example
|
|
104
342
|
|
|
105
343
|
```typescript
|
|
106
|
-
|
|
107
|
-
import {
|
|
344
|
+
// Store configurations in database
|
|
345
|
+
import { getAllConfig } from 'erp-config-sdk';
|
|
346
|
+
|
|
347
|
+
async function seedEmissionDatabase() {
|
|
348
|
+
const allConfigs = getAllConfig();
|
|
349
|
+
|
|
350
|
+
for (const [industryName, config] of Object.entries(allConfigs.industries)) {
|
|
351
|
+
// Store industry configuration
|
|
352
|
+
await db.collection('industries').doc(industryName).set({
|
|
353
|
+
...config,
|
|
354
|
+
lastUpdated: new Date(),
|
|
355
|
+
version: '1.0'
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// Store individual emission factors for fast lookup
|
|
359
|
+
config.scope1.forEach(async (scope, index) => {
|
|
360
|
+
scope.subProducts.forEach(async (product, pIndex) => {
|
|
361
|
+
await db.collection('emission_factors').add({
|
|
362
|
+
industry: industryName,
|
|
363
|
+
scope: 'scope1',
|
|
364
|
+
scopeIndex: index,
|
|
365
|
+
productIndex: pIndex,
|
|
366
|
+
productName: product.name,
|
|
367
|
+
emissionFactor: product.emissionFactor,
|
|
368
|
+
unit: product.unit,
|
|
369
|
+
type: product.type
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
108
376
|
|
|
109
|
-
|
|
110
|
-
const Icon = features.icon || FaIndustry;
|
|
377
|
+
### Carbon Footprint Calculation Example
|
|
111
378
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
379
|
+
```typescript
|
|
380
|
+
// Calculate emissions using SDK data
|
|
381
|
+
function calculateCarbonFootprint(
|
|
382
|
+
industry: string,
|
|
383
|
+
consumptionData: { [productName: string]: number },
|
|
384
|
+
username?: string
|
|
385
|
+
) {
|
|
386
|
+
const config = getCombinedBackendConfig(industry, username);
|
|
387
|
+
if (!config) throw new Error('Industry not found');
|
|
388
|
+
|
|
389
|
+
let totalEmissions = 0;
|
|
390
|
+
|
|
391
|
+
// Calculate scope 1 emissions
|
|
392
|
+
config.scope1.forEach(scope => {
|
|
393
|
+
scope.subProducts.forEach(product => {
|
|
394
|
+
const consumption = consumptionData[product.name] || 0;
|
|
395
|
+
const emissions = consumption * product.emissionFactor;
|
|
396
|
+
totalEmissions += emissions;
|
|
397
|
+
|
|
398
|
+
console.log(`${product.name}: ${consumption} ${product.unit} Γ ${product.emissionFactor} = ${emissions} kg CO2e`);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
return totalEmissions;
|
|
119
403
|
}
|
|
404
|
+
|
|
405
|
+
// Usage
|
|
406
|
+
const emissions = calculateCarbonFootprint('Cement', {
|
|
407
|
+
'Coal': 1000, // 1000 tonnes
|
|
408
|
+
'Natural Gas': 500 // 500 cubic meters
|
|
409
|
+
}, 'gas lab');
|
|
410
|
+
|
|
411
|
+
console.log(`Total emissions: ${emissions} kg CO2e`);
|
|
120
412
|
```
|
|
121
413
|
|
|
122
414
|
## Types
|
|
123
415
|
|
|
124
|
-
The SDK exports comprehensive TypeScript types:
|
|
416
|
+
The SDK exports comprehensive TypeScript types for both backend and frontend usage:
|
|
417
|
+
|
|
418
|
+
### Backend Types (No React Dependencies)
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
// Import backend-compatible types
|
|
422
|
+
import type {
|
|
423
|
+
AllConfigurations,
|
|
424
|
+
BackendIndustryConfig,
|
|
425
|
+
BackendUserConfig,
|
|
426
|
+
BackendScope,
|
|
427
|
+
BackendScope3Item,
|
|
428
|
+
BackendProduct,
|
|
429
|
+
BackendEmissionItem,
|
|
430
|
+
BackendEquipmentCategory,
|
|
431
|
+
BackendEmissions,
|
|
432
|
+
BackendAdditionalScopeItem,
|
|
433
|
+
BackendUserConfigs,
|
|
434
|
+
BackendIndustries
|
|
435
|
+
} from 'erp-config-sdk';
|
|
436
|
+
|
|
437
|
+
// Usage example with full type safety
|
|
438
|
+
const handleIndustryConfig = (config: BackendIndustryConfig) => {
|
|
439
|
+
config.scope1.forEach((scope: BackendScope) => {
|
|
440
|
+
scope.subProducts.forEach((product: BackendProduct) => {
|
|
441
|
+
const factor: number = product.emissionFactor;
|
|
442
|
+
const unit: string = product.unit;
|
|
443
|
+
// Full IntelliSense support
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Frontend Types (With React Components)
|
|
125
450
|
|
|
126
451
|
```typescript
|
|
127
|
-
//
|
|
452
|
+
// Import frontend types (includes React components)
|
|
128
453
|
import type {
|
|
129
454
|
EmissionData,
|
|
130
455
|
EmissionSource,
|
|
@@ -132,66 +457,195 @@ import type {
|
|
|
132
457
|
IndustryConfig,
|
|
133
458
|
CarbonIntensityData,
|
|
134
459
|
BillsAnalyzed,
|
|
135
|
-
Calculations
|
|
136
|
-
|
|
460
|
+
Calculations,
|
|
461
|
+
Scope,
|
|
462
|
+
Scope3Item
|
|
463
|
+
} from 'erp-config-sdk';
|
|
137
464
|
```
|
|
138
465
|
|
|
139
|
-
|
|
466
|
+
### Universal Types
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
// These types work in both backend and frontend
|
|
470
|
+
import type {
|
|
471
|
+
FormData,
|
|
472
|
+
ValidationError,
|
|
473
|
+
FormValidationResult,
|
|
474
|
+
BaseRequest,
|
|
475
|
+
ApiResponse,
|
|
476
|
+
IndustryType,
|
|
477
|
+
FieldConfig,
|
|
478
|
+
PlantNameConfig
|
|
479
|
+
} from 'erp-config-sdk';
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## API Reference
|
|
483
|
+
|
|
484
|
+
### Backend Functions
|
|
485
|
+
|
|
486
|
+
| Function | Parameters | Return Type | Description |
|
|
487
|
+
|----------|------------|-------------|-------------|
|
|
488
|
+
| `getAllConfig()` | None | `AllConfigurations` | Get all industry and user configurations |
|
|
489
|
+
| `getIndustryBackendConfig()` | `industryName: string` | `BackendIndustryConfig \| undefined` | Get specific industry configuration |
|
|
490
|
+
| `getUserNameBackendConfig()` | `username: string` | `BackendUserConfig \| undefined` | Get user-specific configuration |
|
|
491
|
+
| `getCombinedBackendConfig()` | `industryName: string, username?: string` | `BackendIndustryConfig \| undefined` | Get combined configuration with user overrides |
|
|
140
492
|
|
|
141
|
-
###
|
|
493
|
+
### Frontend Functions
|
|
142
494
|
|
|
143
|
-
|
|
144
|
-
|
|
495
|
+
| Function | Parameters | Return Type | Description |
|
|
496
|
+
|----------|------------|-------------|-------------|
|
|
497
|
+
| `getIndustryConfig()` | `industry: string, username?: string` | `IndustryConfig` | Get industry config with React components |
|
|
498
|
+
| `getUserNameScopeConfig()` | `scopeKey, username?, defaultScope?` | `T` | Get user-specific scope configuration |
|
|
145
499
|
|
|
146
|
-
###
|
|
500
|
+
### Utility Functions
|
|
147
501
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
502
|
+
| Function | Parameters | Return Type | Description |
|
|
503
|
+
|----------|------------|-------------|-------------|
|
|
504
|
+
| `formatEmissions()` | `value: number` | `string` | Format emission values for display |
|
|
505
|
+
| `generateEmissionSources()` | `scope: string` | `EmissionSource[]` | Generate emission sources |
|
|
506
|
+
| `getUIFeatures()` | `industry: string` | `UIFeature` | Get UI configurations |
|
|
507
|
+
| `getIndustryFromCompanyName()` | `name: string` | `string` | Map company name to industry |
|
|
151
508
|
|
|
152
|
-
|
|
509
|
+
## Advanced Usage
|
|
510
|
+
|
|
511
|
+
### Custom Emission Calculations
|
|
153
512
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
513
|
+
```typescript
|
|
514
|
+
import {
|
|
515
|
+
formatEmissions,
|
|
516
|
+
generateEmissionSources,
|
|
517
|
+
getIndustryBackendConfig
|
|
518
|
+
} from 'erp-config-sdk';
|
|
519
|
+
|
|
520
|
+
// Get configuration and calculate emissions
|
|
521
|
+
const config = getIndustryBackendConfig('Steel');
|
|
522
|
+
if (config) {
|
|
523
|
+
const coalProduct = config.scope1[0]?.subProducts.find(p => p.name === 'Coal');
|
|
524
|
+
if (coalProduct) {
|
|
525
|
+
const emissions = 1000 * coalProduct.emissionFactor; // 1000 tonnes of coal
|
|
526
|
+
const formatted = formatEmissions(emissions); // "1,234.57"
|
|
527
|
+
console.log(`Coal emissions: ${formatted} kg CO2e`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
```
|
|
157
531
|
|
|
158
532
|
## Dependencies
|
|
159
533
|
|
|
160
|
-
|
|
534
|
+
### Production Dependencies
|
|
161
535
|
- **TypeScript**: Full type safety and IntelliSense support
|
|
536
|
+
- **Emission Factor Data**: Comprehensive emission factors for 24+ industries
|
|
162
537
|
|
|
163
|
-
|
|
164
|
-
|
|
538
|
+
### Peer Dependencies (Frontend Only)
|
|
165
539
|
```json
|
|
166
540
|
{
|
|
167
541
|
"react-icons": "^4.0.0"
|
|
168
542
|
}
|
|
169
543
|
```
|
|
170
544
|
|
|
171
|
-
|
|
545
|
+
**Note**: React Icons are only required for frontend usage. Backend applications do not need React dependencies.
|
|
172
546
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
547
|
+
## Backend vs Frontend Compatibility
|
|
548
|
+
|
|
549
|
+
| Feature | Backend | Frontend |
|
|
550
|
+
|---------|---------|----------|
|
|
551
|
+
| **Configuration Data** | β
Full access | β
Full access |
|
|
552
|
+
| **Type Safety** | β
Complete | β
Complete |
|
|
553
|
+
| **JSON Serialization** | β
Native | β
Native |
|
|
554
|
+
| **React Icons** | β Not included | β
Included |
|
|
555
|
+
| **Bundle Size** | π₯ Minimal | π¦ Standard |
|
|
556
|
+
| **Node.js Compatible** | β
Yes | β No |
|
|
557
|
+
| **Browser Compatible** | β No | β
Yes |
|
|
558
|
+
|
|
559
|
+
## Migration Guide
|
|
176
560
|
|
|
177
|
-
|
|
178
|
-
npm run build
|
|
561
|
+
### Upgrading from Frontend-Only Usage
|
|
179
562
|
|
|
180
|
-
|
|
181
|
-
npm run lint
|
|
563
|
+
If you were previously using the SDK only in frontend applications:
|
|
182
564
|
|
|
183
|
-
|
|
184
|
-
|
|
565
|
+
```typescript
|
|
566
|
+
// Before (frontend only)
|
|
567
|
+
import { getIndustryConfig } from 'erp-config-sdk';
|
|
568
|
+
const config = getIndustryConfig('Cement');
|
|
569
|
+
|
|
570
|
+
// After (backend compatible)
|
|
571
|
+
import { getIndustryBackendConfig } from 'erp-config-sdk';
|
|
572
|
+
const config = getIndustryBackendConfig('Cement');
|
|
573
|
+
// Note: Icons will be strings instead of React components
|
|
185
574
|
```
|
|
186
575
|
|
|
187
|
-
|
|
576
|
+
### New Backend-First Applications
|
|
188
577
|
|
|
189
|
-
|
|
578
|
+
For new backend applications, use the backend functions from the start:
|
|
579
|
+
|
|
580
|
+
```typescript
|
|
581
|
+
import {
|
|
582
|
+
getAllConfig,
|
|
583
|
+
getIndustryBackendConfig,
|
|
584
|
+
getUserNameBackendConfig,
|
|
585
|
+
getCombinedBackendConfig
|
|
586
|
+
} from 'erp-config-sdk';
|
|
587
|
+
|
|
588
|
+
// All functions return data without React dependencies
|
|
589
|
+
```
|
|
190
590
|
|
|
191
591
|
## Contributing
|
|
192
592
|
|
|
193
|
-
Contributions are welcome! Please ensure all changes
|
|
593
|
+
Contributions are welcome! Please ensure all changes:
|
|
594
|
+
|
|
595
|
+
- Include appropriate TypeScript types
|
|
596
|
+
- Maintain backward compatibility
|
|
597
|
+
- Support both backend and frontend usage
|
|
598
|
+
- Include tests for new functionality
|
|
599
|
+
- Follow the existing code style
|
|
600
|
+
|
|
601
|
+
### Adding New Industries
|
|
602
|
+
|
|
603
|
+
To add a new industry configuration:
|
|
604
|
+
|
|
605
|
+
1. Create a new file in `src/config/industries/`
|
|
606
|
+
2. Define scope1, scope2, and scope3 configurations
|
|
607
|
+
3. Export the configuration from `src/config/industries/index.ts`
|
|
608
|
+
4. Add the industry to `INDUSTRIES_CONFIG` in `src/config/index.ts`
|
|
609
|
+
5. Update the README with the new industry
|
|
610
|
+
|
|
611
|
+
### Adding Backend Functions
|
|
612
|
+
|
|
613
|
+
When adding new backend functions:
|
|
614
|
+
|
|
615
|
+
1. Ensure no React dependencies in output
|
|
616
|
+
2. Provide complete TypeScript definitions
|
|
617
|
+
3. Transform all nested data to backend-compatible format
|
|
618
|
+
4. Export from both config and main index files
|
|
619
|
+
5. Add comprehensive JSDoc documentation
|
|
194
620
|
|
|
195
621
|
## Support
|
|
196
622
|
|
|
197
|
-
For questions
|
|
623
|
+
For questions, issues, or feature requests:
|
|
624
|
+
|
|
625
|
+
- π§ Email: support@zerocarbon-erp.com
|
|
626
|
+
- π Issues: [GitHub Issues](https://github.com/your-org/erp-config-sdk/issues)
|
|
627
|
+
- π Documentation: [Full API Documentation](https://docs.zerocarbon-erp.com)
|
|
628
|
+
- π¬ Community: [Discord Support Server](https://discord.gg/zerocarbon)
|
|
629
|
+
|
|
630
|
+
## Changelog
|
|
631
|
+
|
|
632
|
+
### Latest Updates
|
|
633
|
+
|
|
634
|
+
**v2.0.0** - Backend Compatibility Release
|
|
635
|
+
- β¨ Added `getAllConfig()` for complete backend access
|
|
636
|
+
- β¨ Added `getUserNameBackendConfig()` for user-specific configs
|
|
637
|
+
- β¨ Added `getIndustryBackendConfig()` for industry-specific configs
|
|
638
|
+
- β¨ Added `getCombinedBackendConfig()` for merged configurations
|
|
639
|
+
- π Complete type safety from root to leaf properties
|
|
640
|
+
- π₯οΈ Full backend compatibility without React dependencies
|
|
641
|
+
- π¦ Deep transformation of all nested data structures
|
|
642
|
+
- π― Granular access to specific configurations
|
|
643
|
+
|
|
644
|
+
**v1.x** - Frontend-focused releases
|
|
645
|
+
- React Icons integration
|
|
646
|
+
- Industry-specific configurations
|
|
647
|
+
- Carbon intensity calculations
|
|
648
|
+
|
|
649
|
+
## License
|
|
650
|
+
|
|
651
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|