fix(core): update

This commit is contained in:
Philipp Kunz 2024-06-19 18:50:00 +02:00
parent f7f035e878
commit 5ec9124d29
2 changed files with 23 additions and 5 deletions

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/npmextra', name: '@push.rocks/npmextra',
version: '5.0.21', version: '5.0.22',
description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.' description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.'
} }

View File

@ -77,18 +77,36 @@ export class AppData<T = any> {
// Recursive function to handle nested objects, now includes key parameter // Recursive function to handle nested objects, now includes key parameter
const processEnvMapping = async (key: keyof T, mappingValue: any, parentKey: keyof T | '' = ''): Promise<any> => { const processEnvMapping = async (key: keyof T, mappingValue: any, parentKey: keyof T | '' = ''): Promise<any> => {
if (typeof mappingValue === 'string') { if (typeof mappingValue === 'string') {
let envValue: string | T[keyof T]; let envValue: string | boolean | T[keyof T];
let convert: 'none' | 'json' | 'base64' | 'boolean' = 'none'
if (mappingValue.startsWith('hard:')) { if (mappingValue.startsWith('hard:')) {
envValue = mappingValue.replace('hard:', '') as T[keyof T]; envValue = mappingValue.replace('hard:', '') as T[keyof T];
} else if (mappingValue.startsWith('boolean:')) {
envValue = await qenvInstance.getEnvVarOnDemand(mappingValue.replace('boolean:', '')) as T[keyof T];
convert = 'boolean';
} else if(mappingValue.startsWith('json')) {
envValue = await qenvInstance.getEnvVarOnDemand(mappingValue.replace('json:', '')) as T[keyof T];
convert = 'json';
} else if (mappingValue.startsWith('base64')) {
envValue = await qenvInstance.getEnvVarOnDemand(mappingValue.replace('base64:', '')) as T[keyof T];
convert = 'base64';
} else { } else {
envValue = await qenvInstance.getEnvVarOnDemand(mappingValue) as T[keyof T]; envValue = await qenvInstance.getEnvVarOnDemand(mappingValue) as T[keyof T];
} }
// lets format the env value
if (envValue) { if (envValue) {
if (typeof envValue === 'string' && mappingValue.endsWith('_JSON')) { if (convert === 'boolean') {
envValue = JSON.parse(envValue) as T[keyof T]; envValue = envValue === 'true';
}
if (typeof envValue === 'string' && (mappingValue.endsWith('_JSON') || convert === 'json')) {
envValue = JSON.parse(envValue as string) as T[keyof T];
}
if (typeof envValue === 'string' && (mappingValue.endsWith('_BASE64') || convert === 'base64')) {
envValue = Buffer.from(envValue as string, 'base64').toString();
} }
if (!parentKey) { if (!parentKey) {
await this.kvStore.writeKey(key, envValue); await this.kvStore.writeKey(key, envValue as any);
} else { } else {
return envValue; return envValue;
} }