Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 521628cb72 | |||
| 5e31dc93a3 |
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "qenv",
|
||||
"description": "A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.",
|
||||
"npmPackagename": "@push.rocks/qenv",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"environment variables",
|
||||
"configuration management",
|
||||
"Node.js",
|
||||
"TypeScript",
|
||||
"Docker secrets",
|
||||
"CI/CD",
|
||||
"testing"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
],
|
||||
"accessLevel": "public"
|
||||
}
|
||||
},
|
||||
"@git.zone/tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
},
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmRegistryUrl": "registry.npmjs.org"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-05-01 - 6.1.4 - fix(qenv)
|
||||
replace smartfile-based config loading with native fs and yaml parsing for env files
|
||||
|
||||
- switch env and qenv file parsing to native fs with explicit JSON/YAML handling
|
||||
- tighten TypeScript typings and optional path handling to avoid undefined and non-Error access issues
|
||||
- update ConfigVault adapter to return the env bundle shape expected by consumers
|
||||
- refresh build tooling and add yaml as a runtime dependency
|
||||
|
||||
## 2025-08-16 - 6.1.3 - fix(qenv)
|
||||
Handle falsy environment values correctly, improve env source resolution, add tests and update test script
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2026 Task Venture Capital GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+14
-7
@@ -1,9 +1,5 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
@@ -21,9 +17,20 @@
|
||||
"CI/CD",
|
||||
"testing"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
],
|
||||
"accessLevel": "public"
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"@git.zone/tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
},
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmRegistryUrl": "registry.npmjs.org"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-11
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/qenv",
|
||||
"version": "6.1.3",
|
||||
"version": "6.1.4",
|
||||
"private": false,
|
||||
"description": "A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -8,7 +8,8 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --verbose --testlog --timeout 20)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"build": "tsbuild --web",
|
||||
"format": "gitzone format",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
@@ -24,24 +25,24 @@
|
||||
"CI/CD",
|
||||
"testing"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"author": "Task Venture Capital GmbH <hello@task.vc>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/qenv/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/qenv",
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.6.4",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.2",
|
||||
"@types/node": "^22.13.13"
|
||||
"@git.zone/tsbuild": "^4.4.0",
|
||||
"@git.zone/tsrun": "^2.0.3",
|
||||
"@git.zone/tstest": "^3.6.3",
|
||||
"@types/node": "^25.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest": "^3.1.10",
|
||||
"@api.global/typedrequest": "^3.3.0",
|
||||
"@configvault.io/interfaces": "^1.0.17",
|
||||
"@push.rocks/smartfile": "^11.2.5",
|
||||
"@push.rocks/smartlog": "^3.1.8",
|
||||
"@push.rocks/smartpath": "^6.0.0"
|
||||
"@push.rocks/smartlog": "^3.2.2",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"yaml": "^2.8.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@@ -52,6 +53,8 @@
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
".smartconfig.json",
|
||||
"license",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
|
||||
Generated
+3618
-3754
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -88,7 +88,8 @@ tap.test('should throw error for undefined in strict mode', async () => {
|
||||
await testQenv.getEnvVarOnDemandStrict('NON_EXISTENT_VAR');
|
||||
} catch (error) {
|
||||
threwError = true;
|
||||
expect(error.message).toContain('is not set');
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
expect(errorMessage).toContain('is not set');
|
||||
}
|
||||
expect(threwError).toBeTrue();
|
||||
|
||||
@@ -116,4 +117,4 @@ tap.test('should handle array of env vars with falsy values', async () => {
|
||||
delete process.env['SECOND_VAR'];
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
+1
-1
@@ -32,4 +32,4 @@ tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
||||
expect(await testQenv.keyValueObject.key2).toEqual('fromJson');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/qenv',
|
||||
version: '6.1.3',
|
||||
version: '6.1.4',
|
||||
description: 'A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.'
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import * as plugins from './qenv.plugins.js';
|
||||
|
||||
export class CloudlyAdapter {
|
||||
public configVaultUrl: string;
|
||||
public configVaultUrl?: string;
|
||||
|
||||
constructor(configVaultUrl?: string) {
|
||||
this.configVaultUrl = configVaultUrl;
|
||||
}
|
||||
|
||||
public async getConfigBundle(): Promise<plugins.configvaultInterfaces.data.IConfigBundle> {
|
||||
public async getConfigBundle(): Promise<plugins.configvaultInterfaces.data.IEnvBundle | null> {
|
||||
if (this.configVaultUrl) {
|
||||
console.log(`ConfigVault specified through constructor`)
|
||||
} else if (process.env['CONFIGVAULT_URL']) {
|
||||
@@ -26,5 +26,6 @@ export class CloudlyAdapter {
|
||||
const response = await tr.fire({
|
||||
authorization: parsedUrl.pathname.replace('/', ''),
|
||||
})
|
||||
return response.envBundle;
|
||||
}
|
||||
}
|
||||
|
||||
+47
-20
@@ -2,18 +2,19 @@ import { CloudlyAdapter } from './qenv.classes.configvaultadapter.js';
|
||||
import * as plugins from './qenv.plugins.js';
|
||||
|
||||
export type TEnvVarRef = string | (() => Promise<string>);
|
||||
type TKeyValueObject = Record<string, any>;
|
||||
|
||||
export class Qenv {
|
||||
public requiredEnvVars: string[] = [];
|
||||
public availableEnvVars: string[] = [];
|
||||
public missingEnvVars: string[] = [];
|
||||
public keyValueObject: { [key: string]: any } = {};
|
||||
public keyValueObject: TKeyValueObject = {};
|
||||
public logger = new plugins.smartlog.ConsoleLog();
|
||||
|
||||
public cloudlyAdapter: CloudlyAdapter;
|
||||
|
||||
public qenvFilePathAbsolute: string;
|
||||
public envFilePathAbsolute: string;
|
||||
public qenvFilePathAbsolute = '';
|
||||
public envFilePathAbsolute?: string;
|
||||
|
||||
constructor(
|
||||
qenvFileBasePathArg: string = process.cwd(),
|
||||
@@ -27,7 +28,7 @@ export class Qenv {
|
||||
this.checkForMissingEnvVars(failOnMissing);
|
||||
}
|
||||
|
||||
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
|
||||
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg?: string) {
|
||||
this.qenvFilePathAbsolute = plugins.path.join(
|
||||
plugins.path.resolve(qenvFileBasePathArg),
|
||||
'qenv.yml'
|
||||
@@ -40,9 +41,9 @@ export class Qenv {
|
||||
const envFileYmlPath = plugins.path.join(envFileBasePath, 'env.yml');
|
||||
const envFileYamlPath = plugins.path.join(envFileBasePath, 'env.yaml');
|
||||
|
||||
const envFileJsonExists = plugins.smartfile.fs.fileExistsSync(envFileJsonPath);
|
||||
const envFileYmlExists = plugins.smartfile.fs.fileExistsSync(envFileYmlPath);
|
||||
const envFileYamlExists = plugins.smartfile.fs.fileExistsSync(envFileYamlPath);
|
||||
const envFileJsonExists = this.fileExists(envFileJsonPath);
|
||||
const envFileYmlExists = this.fileExists(envFileYmlPath);
|
||||
const envFileYamlExists = this.fileExists(envFileYamlPath);
|
||||
|
||||
if (envFileJsonExists && (envFileYmlExists || envFileYamlExists)) {
|
||||
this.logger.log('warn', 'Both env.json and env.yml files exist! Using env.json');
|
||||
@@ -58,10 +59,13 @@ export class Qenv {
|
||||
}
|
||||
|
||||
private loadRequiredEnvVars() {
|
||||
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
|
||||
const qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
||||
if (qenvFile?.required && Array.isArray(qenvFile.required)) {
|
||||
this.requiredEnvVars.push(...qenvFile.required);
|
||||
if (this.fileExists(this.qenvFilePathAbsolute)) {
|
||||
const qenvFile = this.readObjectFromFile(this.qenvFilePathAbsolute);
|
||||
const requiredEnvVars = qenvFile.required;
|
||||
if (Array.isArray(requiredEnvVars)) {
|
||||
this.requiredEnvVars.push(
|
||||
...requiredEnvVars.filter((envVar): envVar is string => typeof envVar === 'string')
|
||||
);
|
||||
} else {
|
||||
this.logger.log('warn', 'qenv.yml does not contain a "required" Array!');
|
||||
}
|
||||
@@ -194,16 +198,16 @@ export class Qenv {
|
||||
}
|
||||
|
||||
private getFromEnvYamlOrJsonFile(envVarName: string): string | undefined {
|
||||
if (!plugins.smartfile.fs.fileExistsSync(this.envFilePathAbsolute)) {
|
||||
if (!this.fileExists(this.envFilePathAbsolute)) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const envJson = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||
const envJson = this.readObjectFromFile(this.envFilePathAbsolute);
|
||||
const value = envJson[envVarName];
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return 'base64Object:' + this.encodeBase64(value);
|
||||
}
|
||||
return String(value);
|
||||
@@ -214,23 +218,23 @@ export class Qenv {
|
||||
|
||||
private getFromDockerSecret(envVarName: string): string | undefined {
|
||||
const secretPath = `/run/secrets/${envVarName}`;
|
||||
if (plugins.smartfile.fs.fileExistsSync(secretPath)) {
|
||||
return plugins.smartfile.fs.toStringSync(secretPath);
|
||||
if (this.fileExists(secretPath)) {
|
||||
return plugins.fs.readFileSync(secretPath, 'utf8');
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private getFromDockerSecretJson(envVarName: string): string | undefined {
|
||||
if (plugins.smartfile.fs.isDirectory('/run/secrets')) {
|
||||
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
||||
if (this.directoryExists('/run/secrets')) {
|
||||
const availableSecrets = plugins.fs.readdirSync('/run/secrets');
|
||||
for (const secret of availableSecrets) {
|
||||
if (secret.includes('secret.json')) {
|
||||
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
||||
const secretObject = this.readObjectFromFile(`/run/secrets/${secret}`);
|
||||
const value = secretObject[envVarName];
|
||||
if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return 'base64Object:' + this.encodeBase64(value);
|
||||
}
|
||||
return String(value);
|
||||
@@ -249,4 +253,27 @@ export class Qenv {
|
||||
const decodedString = Buffer.from(encodedString, 'base64').toString('utf-8');
|
||||
return JSON.parse(decodedString);
|
||||
}
|
||||
|
||||
private fileExists(filePath: string | undefined): filePath is string {
|
||||
if (!filePath) {
|
||||
return false;
|
||||
}
|
||||
return plugins.fs.existsSync(filePath);
|
||||
}
|
||||
|
||||
private directoryExists(directoryPath: string): boolean {
|
||||
try {
|
||||
return plugins.fs.statSync(directoryPath).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private readObjectFromFile(filePath: string): TKeyValueObject {
|
||||
const fileString = plugins.fs.readFileSync(filePath, 'utf8');
|
||||
const parsedObject = filePath.endsWith('.json')
|
||||
? JSON.parse(fileString)
|
||||
: plugins.yaml.parse(fileString);
|
||||
return typeof parsedObject === 'object' && parsedObject !== null ? parsedObject : {};
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,7 +1,8 @@
|
||||
// native
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
export { fs, path };
|
||||
|
||||
// @api.global scope
|
||||
import * as typedrequest from '@api.global/typedrequest';
|
||||
@@ -11,12 +12,16 @@ export {
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
|
||||
export { smartfile, smartlog };
|
||||
export { smartlog };
|
||||
|
||||
// @configvault.io scope
|
||||
import * as configvaultInterfaces from '@configvault.io/interfaces';
|
||||
|
||||
export { configvaultInterfaces };
|
||||
|
||||
// third party scope
|
||||
import * as yaml from 'yaml';
|
||||
|
||||
export { yaml };
|
||||
|
||||
+4
-4
@@ -5,10 +5,10 @@
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
"exclude": ["dist_*/**/*.d.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user