diff --git a/src/lib/e-mem/index.ts b/src/lib/e-mem/index.ts index a021f6d..594cdbd 100644 --- a/src/lib/e-mem/index.ts +++ b/src/lib/e-mem/index.ts @@ -51,7 +51,8 @@ export const EMem = (globalConfig: ConfigParams): PluginInterface => { }); //Manually add default value from CCF: https://www.cloudcarbonfootprint.org/docs/methodology/#memory - const energyPerGB = globalConfig['energy-per-gb'] ?? 0.000392; + const energyPerGB = + (globalConfig && globalConfig['energy-per-gb']) ?? 0.000392; return validate>(schema, { ...globalConfig, diff --git a/src/lib/e-net/index.ts b/src/lib/e-net/index.ts index 292aede..f1af7e0 100644 --- a/src/lib/e-net/index.ts +++ b/src/lib/e-net/index.ts @@ -38,12 +38,18 @@ export const ENet = (globalConfig: ConfigParams): PluginInterface => { 'energy-per-gb': z.number(), }); - // Manually add default value - if (!globalConfig['energy-per-gb'] || globalConfig['energy-per-gb'] === 0) { - globalConfig['energy-per-gb'] = 0.001; - } + // Manually add default value from CCF: https://www.cloudcarbonfootprint.org/docs/methodology/#chosen-coefficient + const energyPerGB = + !globalConfig || + !globalConfig['energy-per-gb'] || + globalConfig['energy-per-gb'] === 0 + ? 0.001 + : globalConfig['energy-per-gb']; - return validate>(schema, globalConfig); + return validate>(schema, { + ...globalConfig, + 'energy-per-gb': energyPerGB, + }); }; /**