Compare commits

..

51 Commits

Author SHA1 Message Date
jkunz 521628cb72 v6.1.4
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-05-01 15:54:40 +00:00
jkunz 5e31dc93a3 fix(qenv): replace smartfile-based config loading with native fs and yaml parsing for env files 2026-05-01 15:54:39 +00:00
jkunz c0d33340c3 6.1.3 2025-08-16 12:35:35 +00:00
jkunz 5a81caa7bb fix(qenv): Handle falsy environment values correctly, improve env source resolution, add tests and update test script 2025-08-16 12:35:35 +00:00
jkunz a7e3bf1223 6.1.2 2025-08-14 07:22:44 +00:00
jkunz aedbc25269 fix(readme): Correct DATABASE_CONFIG example formatting in README and add local settings configuration file 2025-08-14 07:22:44 +00:00
jkunz d5f56e6ef6 6.1.1 2025-08-14 07:20:05 +00:00
jkunz 88bed685bc fix(qenv): Improve documentation, update dependencies, and refine project configuration 2025-08-14 07:20:05 +00:00
philkunz 7b34ef8453 6.1.0 2024-11-22 18:47:51 +01:00
philkunz e25406662f feat(core): Added new method getEnvVarOnDemandStrict to throw error for unset env vars 2024-11-22 18:47:50 +01:00
philkunz 5b1e3a184b 6.0.8 2024-11-18 19:27:20 +01:00
philkunz b9677b110c fix(Qenv): Fix environment file path initialization logic. 2024-11-18 19:27:20 +01:00
philkunz df35680dea 6.0.7 2024-11-18 19:23:35 +01:00
philkunz ec68a4db92 fix(Qenv): Fix file path initialization for environment variable files 2024-11-18 19:23:35 +01:00
philkunz fdd4fc62c2 6.0.6 2024-11-18 19:19:30 +01:00
philkunz bedefd3efe fix(core): Improve handling of env.json and env.yml file checks 2024-11-18 19:19:30 +01:00
philkunz fa00f33c13 update description 2024-05-29 14:11:29 +02:00
philkunz 4a24b7df65 update tsconfig 2024-04-14 17:16:43 +02:00
philkunz 2449fc059f update npmextra.json: githost 2024-04-01 21:33:31 +02:00
philkunz c5c1e5ebe3 update npmextra.json: githost 2024-04-01 19:57:33 +02:00
philkunz 04b0f81b6f update npmextra.json: githost 2024-03-30 21:46:30 +01:00
philkunz 7655318629 6.0.5 2024-02-09 15:42:01 +01:00
philkunz 754ffa6cac fix(core): update 2024-02-09 15:42:00 +01:00
philkunz b644ca0c1a 6.0.4 2023-10-20 18:18:48 +02:00
philkunz 9f638d687b fix(core): update 2023-10-20 18:18:47 +02:00
philkunz a9bdfe9373 6.0.3 2023-10-20 17:21:52 +02:00
philkunz 2017d51f11 fix(core): update 2023-10-20 17:21:51 +02:00
philkunz 765011ad2a 6.0.2 2023-08-09 17:47:21 +02:00
philkunz d807cc6de2 fix(core): update 2023-08-09 17:47:20 +02:00
philkunz 53721a41c2 6.0.1 2023-08-09 14:50:33 +02:00
philkunz c9f79e6ea4 fix(core): update 2023-08-09 14:50:32 +02:00
philkunz 3c7e3e2589 6.0.0 2023-08-09 13:24:50 +02:00
philkunz 205d27f9a0 BREAKING CHANGE(core): update 2023-08-09 13:24:49 +02:00
philkunz 56ce78f794 5.0.5 2023-08-09 12:49:52 +02:00
philkunz 9d33054f03 fix(core): update 2023-08-09 12:49:52 +02:00
philkunz 072ca59ab0 5.0.4 2023-08-08 19:50:45 +02:00
philkunz 59e3759a3a fix(core): update 2023-08-08 19:50:44 +02:00
philkunz bc95ba3f2d 5.0.3 2023-08-08 19:08:25 +02:00
philkunz 1e6b9779b8 fix(core): update 2023-08-08 19:08:25 +02:00
philkunz 3988887a37 switch to new org scheme 2023-07-11 00:07:40 +02:00
philkunz 5a26ba7771 switch to new org scheme 2023-07-10 02:41:52 +02:00
philkunz f61c0da30a 5.0.2 2022-08-02 14:50:18 +02:00
philkunz 3dfb07e875 fix(core): update 2022-08-02 14:50:18 +02:00
philkunz fde1e90440 5.0.1 2022-07-28 10:10:40 +02:00
philkunz f06c9f186f fix(core): update 2022-07-28 10:10:39 +02:00
philkunz e539489901 5.0.0 2022-07-28 10:09:35 +02:00
philkunz a1dcfba0a2 BREAKING CHANGE(core): switch to esm 2022-07-28 10:09:34 +02:00
philkunz cff79e56c0 4.0.11 2022-07-28 10:09:01 +02:00
philkunz 44252ab0d3 fix(core): update 2022-07-28 10:09:01 +02:00
philkunz d4c3ec6c90 4.0.10 2020-06-08 19:03:18 +00:00
philkunz 42aa1c2831 fix(core): update 2020-06-08 19:03:17 +00:00
29 changed files with 10926 additions and 5591 deletions
+66
View File
@@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
+124
View File
@@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true
-127
View File
@@ -1,127 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true
-4
View File
@@ -1,4 +0,0 @@
node_modules/
coverage/
docs/
@@ -0,0 +1,38 @@
# Code Style and Conventions
## TypeScript Conventions
- Use TypeScript with ES modules (type: "module" in package.json)
- All files use `.js` extensions in imports (even for .ts files)
- Interfaces prefixed with `I` (e.g., `IUserData`)
- Types prefixed with `T` (e.g., `TEnvVarRef`)
- Filenames must be lowercase
- Avoid ENUMs when possible
## File Organization
- Source code in `ts/` directory
- Tests in `test/` directory
- Plugin imports in `ts/qenv.plugins.ts`
- Main exports in `ts/index.ts`
- Class files named as `qenv.classes.<classname>.ts`
## Import Style
- Import all dependencies in plugins file
- Reference as `plugins.moduleName.method()`
- Use full import paths with .js extension
- Group imports: external packages, then internal modules
## Testing
- Use @git.zone/tstest framework
- Import expect from tapbundle: `import { tap, expect } from '@git.zone/tstest/tapbundle'`
- Test files end with `export default tap.start()` (tstest pattern)
- Test file naming: `*.both.ts`, `*.node.ts`, or `*.browser.ts`
## Documentation
- Keep comments minimal unless specifically requested
- README should be lowercase: `readme.md`
- Documentation should be engaging and use emojis where appropriate
## Git Conventions
- Small, focused commits
- Use `git mv` for file operations
- Never commit without running tests and type checks
+37
View File
@@ -0,0 +1,37 @@
# Qenv Project Overview
## Purpose
@push.rocks/qenv is a TypeScript/Node.js module for managing environment variables in Node.js projects. It provides a unified interface for loading environment variables from multiple sources:
- Process environment variables
- YAML configuration files (.yml/.yaml)
- JSON configuration files (.json)
- Docker secrets
- Dynamic/async variable resolution via functions
## Key Features
- Support for required and optional environment variables
- Multi-source loading hierarchy (env vars > config files > Docker secrets)
- Base64-encoded object support for complex configurations
- Synchronous and asynchronous variable retrieval
- Strict mode with error throwing for unset variables
- TypeScript with full type definitions
- Logging via @push.rocks/smartlog
## Main Components
- `Qenv` class: Core class for environment variable management
- `CloudlyAdapter`: Configuration vault integration
- Support for `qenv.yml` (required vars definition) and `env.yml`/`env.json` (values)
## Tech Stack
- TypeScript
- Node.js
- pnpm package manager
- @push.rocks ecosystem libraries (smartfile, smartlog, smartpath)
- @git.zone tools for building and testing
## Dependencies
- @api.global/typedrequest
- @configvault.io/interfaces
- @push.rocks/smartfile
- @push.rocks/smartlog
- @push.rocks/smartpath
+30
View File
@@ -0,0 +1,30 @@
# Suggested Commands for Qenv Development
## Build & Test Commands
- `pnpm test` - Run tests with tstest
- `pnpm build` - Build the project with tsbuild (includes --web --allowimplicitany flags)
- `pnpm buildDocs` - Generate documentation with tsdoc
## Development Tools
- `tsx <file>` - Execute TypeScript files directly (globally available)
- `tstest test/test.some.ts --verbose` - Run specific test file with verbose output
## Package Management
- `pnpm install` - Install dependencies
- `pnpm install --save-dev <package>` - Add development dependency
- `pnpm install <package>` - Add production dependency
## Git Operations
- `git mv <old> <new>` - Move/rename files preserving history
- `git status` - Check current repository status
- `git diff` - View uncommitted changes
## Type Checking
- `tsbuild check test/**/* --skiplibcheck` - Type check test files
- `pnpm run build` - Type check and build module files
## System Commands (Linux)
- `ls` - List files
- `find . -name "pattern"` - Find files by pattern
- `rg "pattern"` - Search file contents (ripgrep)
- `curl` - Make HTTP requests for testing/debugging
@@ -0,0 +1,32 @@
# Task Completion Checklist
When completing any development task in the qenv project, follow these steps:
## Pre-Commit Checks
1. **Run Tests**: `pnpm test`
- Ensure all tests pass
- Add new tests for new functionality
2. **Type Checking**: `pnpm run build`
- Verify no TypeScript errors
- Check that build output is generated correctly
3. **Code Quality**:
- Verify code follows project conventions
- Ensure no console.log statements left in production code
- Check imports use proper .js extensions
## Documentation Updates
- Update README.md if API changes
- Update changelog.md for notable changes
- Ensure JSDoc comments for public APIs
## Final Verification
- Review changes with `git diff`
- Test the module can be imported correctly
- Verify no breaking changes to public API
## Important Notes
- NEVER commit without explicit user approval
- Always run tests and build before suggesting commit
- If lint/typecheck commands unknown, ask user and update CLAUDE.md
+68
View File
@@ -0,0 +1,68 @@
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
# * For C, use cpp
# * For JavaScript, use typescript
# Special requirements:
# * csharp: Requires the presence of a .sln file in the project folder.
language: typescript
# whether to use the project's gitignore file to ignore files
# Added on 2025-04-07
ignore_all_files_in_gitignore: true
# list of additional paths to ignore
# same syntax as gitignore, so you can use * and **
# Was previously called `ignored_dirs`, please update your config if you are using that.
# Added (renamed)on 2025-04-07
ignored_paths: []
# whether the project is in read-only mode
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
# Added on 2025-04-18
read_only: false
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
# Below is the complete list of tools for convenience.
# To make sure you have the latest list of tools, and to view their descriptions,
# execute `uv run scripts/print_tool_overview.py`.
#
# * `activate_project`: Activates a project by name.
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
# * `create_text_file`: Creates/overwrites a file in the project directory.
# * `delete_lines`: Deletes a range of lines within a file.
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
# * `execute_shell_command`: Executes a shell command.
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
# * `initial_instructions`: Gets the initial instructions for the current project.
# Should only be used in settings where the system prompt cannot be set,
# e.g. in clients you have no control over, like Claude Desktop.
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
# * `insert_at_line`: Inserts content at a given line in a file.
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
# * `list_memories`: Lists memories in Serena's project-specific memory store.
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
# * `read_file`: Reads a file within the project directory.
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
# * `remove_project`: Removes a project from the Serena configuration.
# * `replace_lines`: Replaces a range of lines within a file with new content.
# * `replace_symbol_body`: Replaces the full definition of a symbol.
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
# * `search_for_pattern`: Performs a search for a pattern in the project.
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
# * `switch_modes`: Activates modes by providing a list of their names
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
excluded_tools: []
# initial prompt for the project. It will always be given to the LLM upon activating the project
# (contrary to the memories, which are loaded on demand).
initial_prompt: ""
project_name: "qenv"
+36
View File
@@ -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"
}
}
+3 -21
View File
@@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }
+1 -1
View File
@@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }
+98
View File
@@ -0,0 +1,98 @@
# 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
- Treat 0, false and empty string as valid environment values by checking for !== undefined when resolving env vars
- Refactor source resolution to iterate over environment, env file, Docker secrets and secret.json, returning the first defined value
- Ensure env.json and Docker secret JSON return strings for scalar values and base64-encode object values
- Add tests covering falsy values and lookup behavior (test/test.falsy.ts)
- Update package.json test script to run tstest with --verbose --testlog --timeout flags
## 2025-08-14 - 6.1.2 - fix(readme)
Correct DATABASE_CONFIG example formatting in README and add local settings configuration file
- Fix YAML formatting in DATABASE_CONFIG example to reflect proper YAML syntax
- Introduce .claude/settings.local.json with updated permission settings
## 2025-08-14 - 6.1.1 - fix(qenv)
Improve documentation, update dependencies, and refine project configuration
- Revamp README with enhanced installation, configuration, and usage instructions
- Add new project documentation files including code style conventions, project overview, suggested commands, and task checklist
- Upgrade dependency versions in package.json (e.g. @git.zone/tsbuild, @git.zone/tstest, @push.rocks/smartfile, smartlog, and smartpath)
- Adjust test import to use '@git.zone/tstest/tapbundle' for improved compatibility
- Introduce new local configuration files (.claude/settings.local.json and .serena/project.yml) to standardize project settings
## 2024-11-22 - 6.1.0 - feat(core)
Added new method getEnvVarOnDemandStrict to throw error for unset env vars
- Introduced getEnvVarOnDemandStrict method in Qenv class for strict retrieval of environment variables.
- Upgraded various @git.zone and @push.rocks dependencies for improved functionality and security.
## 2024-11-18 - 6.0.8 - fix(Qenv)
Fix environment file path initialization logic.
- Corrected the logic for setting the environment file paths to prevent overwriting each other.
## 2024-11-18 - 6.0.7 - fix(Qenv)
Fix file path initialization for environment variable files
- Corrected the logic for determining the absolute path for environment files
- Added missing initialization for env.yml file paths
## 2024-11-18 - 6.0.6 - fix(core)
Improve handling of env.json and env.yml file checks
- Check for existence of both env.json and env.yml files and prioritize env.json.
- Consolidate getFromEnvJsonFile and getFromEnvYamlFile methods into getFromEnvYamlOrJsonFile.
## 2024-05-29 to 2024-02-09 - 6.0.5 - update
Updates related to configuration files and data handling.
- Updated description
- Updated tsconfig
- Updated npmextra.json for githost
## 2023-08-09 - 6.0.0 to 6.0.4 - core
Various fixes within the core functionality.
- Fixes and improvements across multiple minor versions
## 2023-08-09 - 5.0.5 - core
Breaking change that impacts core functionality.
- Significant updates leading to breaking changes
## 2023-07-11 to 2022-07-28 - 5.0.2 - organization
Transition to a new organization scheme.
- Switched to new organizational scheme
## 2022-07-28 - 4.0.11 - core
Breaking change introducing ESM modules.
- Switch to ECMAScript modules
## 2019-01-15 - 3.1.1 - environment
Breaking change in environment handling.
- Treat environment variables as immutable
## 2019-01-14 - 3.0.7 - docker
New feature for Docker secret management.
- Allow Docker secret.json to be named flexibly
## 2018-08-13 - 1.1.7 - scope
Scope update for package management.
- Change scope to @pushrocks/
+21
View File
@@ -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.
+29 -10
View File
@@ -1,17 +1,36 @@
{ {
"npmci": { "@git.zone/cli": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "qenv", "gitrepo": "qenv",
"shortDescription": "easy promised environments", "description": "A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.",
"npmPackagename": "@pushrocks/qenv", "npmPackagename": "@push.rocks/qenv",
"license": "MIT" "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"
} }
} }
-5183
View File
File diff suppressed because it is too large Load Diff
+34 -21
View File
@@ -1,41 +1,48 @@
{ {
"name": "@pushrocks/qenv", "name": "@push.rocks/qenv",
"version": "4.0.9", "version": "6.1.4",
"private": false, "private": false,
"description": "easy promised environments", "description": "A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/ --verbose --testlog --timeout 20)",
"build": "(tsbuild)" "build": "tsbuild --web",
"format": "gitzone format",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/qenv.git" "url": "https://code.foss.global/push.rocks/qenv.git"
}, },
"keywords": [ "keywords": [
"environment", "environment variables",
"git", "configuration management",
"ci" "Node.js",
"TypeScript",
"Docker secrets",
"CI/CD",
"testing"
], ],
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/qenv/issues" "url": "https://gitlab.com/pushrocks/qenv/issues"
}, },
"homepage": "https://gitlab.com/pushrocks/qenv#README", "homepage": "https://code.foss.global/push.rocks/qenv",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@git.zone/tsbuild": "^4.4.0",
"@gitzone/tsrun": "^1.2.12", "@git.zone/tsrun": "^2.0.3",
"@gitzone/tstest": "^1.0.33", "@git.zone/tstest": "^3.6.3",
"@pushrocks/tapbundle": "^3.2.1", "@types/node": "^25.6.0"
"@types/node": "^14.0.12",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartfile": "^7.0.12", "@api.global/typedrequest": "^3.3.0",
"@pushrocks/smartlog": "^2.0.26" "@configvault.io/interfaces": "^1.0.17",
"@push.rocks/smartlog": "^3.2.2",
"@push.rocks/smartpath": "^6.0.0",
"yaml": "^2.8.3"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -46,7 +53,13 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"license",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"browserslist": [
"last 1 chrome versions"
],
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
} }
+9515
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
+347 -41
View File
@@ -1,54 +1,360 @@
# @pushrocks/qenv # @push.rocks/qenv 🔐
easy promised environments **Smart Environment Variable Management for Node.js**
## Availabililty and Links > Never hardcode secrets again. Load environment variables from multiple sources with ease and confidence.
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/qenv)
* [gitlab.com (source)](https://gitlab.com/pushrocks/qenv)
* [github.com (source mirror)](https://github.com/pushrocks/qenv)
* [docs (typedoc)](https://pushrocks.gitlab.io/qenv/)
## Status for master ## 🚀 Features
Status Category | Status Badge **Multi-source Loading** - Automatically loads from environment variables, config files, and Docker secrets
-- | -- **Type-Safe** - Full TypeScript support with comprehensive type definitions
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/qenv/badges/master/pipeline.svg)](https://lossless.cloud) **Flexible Formats** - Supports `.yml`, `.yaml`, and `.json` configuration files
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/qenv/badges/master/coverage.svg)](https://lossless.cloud) **Docker Ready** - Built-in support for Docker secrets and secret.json files
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/qenv)](https://lossless.cloud) **Async & Sync** - Both synchronous and asynchronous variable retrieval
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/qenv)](https://lossless.cloud) **Strict Mode** - Optional strict mode that throws errors for missing variables
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) **Base64 Objects** - Handle complex configuration objects with automatic encoding/decoding
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) **Dynamic Resolution** - Support for async functions as environment variable sources
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/qenv)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/qenv)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/qenv)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## 📦 Installation
Use TypeScript for best in class instellisense. ```bash
# Using npm
npm install @push.rocks/qenv --save
qenv works with two files: # Using pnpm (recommended)
pnpm add @push.rocks/qenv
- **qenv.yml** - specifies which ENV vars are required. # Using yarn
- **env.yml** - specifies all env vars that are not already set in the current environment. yarn add @push.rocks/qenv
Now obviously you can set build specific env vars in many CI environments.
So there we do not need an **env.yml** since all ENV vars are in place
However when on another machine you can have a env.yml that will be added to the environment by qenv.
```javascript
import { Qenv } from 'qenv';
const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env.yml/is(');
``` ```
## Contribution ## 🎯 Quick Start
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) ```typescript
import { Qenv } from '@push.rocks/qenv';
For further information read the linked docs at the top of this readme. // Create a new Qenv instance
const qenv = new Qenv('./', './', true);
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) // Access environment variables
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) const dbHost = await qenv.getEnvVarOnDemand('DB_HOST');
const apiKey = await qenv.getEnvVarOnDemand('API_KEY');
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) // Use strict mode to ensure variables exist
const criticalVar = await qenv.getEnvVarOnDemandStrict('CRITICAL_CONFIG');
// Throws error if CRITICAL_CONFIG is not set!
```
## 📖 Configuration
### Setting Up Your Environment Files
#### 1. Define Required Variables (`qenv.yml`)
Create a `qenv.yml` file to specify which environment variables your application needs:
```yaml
required:
- DB_HOST
- DB_USER
- DB_PASSWORD
- API_KEY
- LOG_LEVEL
```
#### 2. Provide Values (`env.yml` or `env.json`)
For local development, create an `env.yml` or `env.json` file:
**env.yml:**
```yaml
DB_HOST: localhost
DB_USER: developer
DB_PASSWORD: supersecret123
API_KEY: dev-key-12345
LOG_LEVEL: debug
```
**env.json:**
```json
{
"DB_HOST": "localhost",
"DB_USER": "developer",
"DB_PASSWORD": "supersecret123",
"API_KEY": "dev-key-12345",
"LOG_LEVEL": "debug"
}
```
> 💡 **Pro Tip:** Add `env.yml` and `env.json` to your `.gitignore` to keep secrets out of version control!
## 🔥 Advanced Usage
### Loading Priority
Qenv loads variables in this order (first found wins):
1. **Process environment variables** - Already set in `process.env`
2. **Configuration files** - From `env.yml` or `env.json`
3. **Docker secrets** - From `/run/secrets/`
4. **Docker secret JSON** - From `/run/secrets/secret.json`
### Handling Complex Objects
Store and retrieve complex configuration objects:
```typescript
# In env.yml
DATABASE_CONFIG:
database:
host: localhost
port: 5432
options:
ssl: true
poolSize: 10
// Qenv automatically handles base64 encoding
const dbConfig = await qenv.getEnvVarOnDemandAsObject('DATABASE_CONFIG');
console.log(dbConfig.database.options.poolSize); // 10
```
### Dynamic Environment Variables
Load variables from external sources dynamically:
```typescript
const qenv = new Qenv();
// Define an async function to fetch configuration
const fetchFromVault = async () => {
const response = await fetch('https://vault.example.com/api/secret');
const data = await response.json();
return data.secret;
};
// Use the function as an environment variable source
const secret = await qenv.getEnvVarOnDemand(fetchFromVault);
```
### Working with Docker
Qenv seamlessly integrates with Docker secrets:
```dockerfile
# docker-compose.yml
version: '3.7'
services:
app:
image: your-app
secrets:
- db_password
- api_key
secrets:
db_password:
external: true
api_key:
external: true
```
Your application automatically reads from `/run/secrets/`:
```typescript
const qenv = new Qenv();
// Automatically loads from /run/secrets/db_password
const dbPassword = await qenv.getEnvVarOnDemand('db_password');
```
### Handling Missing Variables
Control how your application handles missing environment variables:
```typescript
// Fail fast (default behavior)
const qenvStrict = new Qenv('./', './', true);
// Application exits if required variables are missing
// Graceful handling
const qenvRelaxed = new Qenv('./', './', false);
// Application continues, you handle missing variables
// Check what's missing
if (qenvRelaxed.missingEnvVars.length > 0) {
console.warn('Missing variables:', qenvRelaxed.missingEnvVars);
// Implement fallback logic
}
```
### Strict Mode for Critical Variables
Use the new strict getter when you absolutely need a variable:
```typescript
try {
// This will throw if TOKEN is not set
const token = await qenv.getEnvVarOnDemandStrict('TOKEN');
// You can also check multiple fallback names
const db = await qenv.getEnvVarOnDemandStrict(['DATABASE_URL', 'DB_CONNECTION']);
} catch (error) {
console.error('Critical configuration missing:', error.message);
process.exit(1);
}
```
## 🏗️ CI/CD Integration
### GitHub Actions
```yaml
name: Deploy
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy with secrets
env:
API_KEY: ${{ secrets.API_KEY }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
npm install
npm run deploy
```
### GitLab CI
```yaml
deploy:
stage: deploy
script:
- npm install
- npm run deploy
variables:
API_KEY: $CI_API_KEY
DB_PASSWORD: $CI_DB_PASSWORD
```
## 🎭 Testing
For testing, create a separate `test/assets/env.yml`:
```typescript
import { Qenv } from '@push.rocks/qenv';
describe('MyApp', () => {
let qenv: Qenv;
beforeEach(() => {
qenv = new Qenv('./test/assets', './test/assets', false);
});
it('should load test configuration', async () => {
const testVar = await qenv.getEnvVarOnDemand('TEST_VAR');
expect(testVar).toBe('test-value');
});
});
```
## 🔍 Debugging
Enable detailed logging to troubleshoot environment variable loading:
```typescript
const qenv = new Qenv();
// Check what's loaded
console.log('Required vars:', qenv.requiredEnvVars);
console.log('Available vars:', qenv.availableEnvVars);
console.log('Missing vars:', qenv.missingEnvVars);
// Access the logger
qenv.logger.log('info', 'Custom log message');
```
## 📊 Real-World Example
Here's how you might use qenv in a production Node.js application:
```typescript
import { Qenv } from '@push.rocks/qenv';
import { createServer } from './server';
import { connectDatabase } from './database';
async function bootstrap() {
// Initialize environment
const qenv = new Qenv();
// Load critical configuration
const config = {
port: await qenv.getEnvVarOnDemand('PORT') || '3000',
dbUrl: await qenv.getEnvVarOnDemandStrict('DATABASE_URL'),
apiKey: await qenv.getEnvVarOnDemandStrict('API_KEY'),
logLevel: await qenv.getEnvVarOnDemand('LOG_LEVEL') || 'info',
features: await qenv.getEnvVarOnDemandAsObject('FEATURE_FLAGS')
};
// Connect to database
await connectDatabase(config.dbUrl);
// Start server
const server = createServer(config);
server.listen(config.port, () => {
console.log(`🚀 Server running on port ${config.port}`);
});
}
bootstrap().catch(error => {
console.error('Failed to start application:', error);
process.exit(1);
});
```
## 🤝 API Reference
### Class: `Qenv`
#### Constructor
```typescript
new Qenv(
qenvFileBasePathArg?: string, // Path to qenv.yml (default: process.cwd())
envFileBasePathArg?: string, // Path to env.yml/json (default: same as qenv)
failOnMissing?: boolean // Exit on missing vars (default: true)
)
```
#### Methods
| Method | Description | Returns |
|--------|-------------|---------|
| `getEnvVarOnDemand(name)` | Get environment variable value | `Promise<string \| undefined>` |
| `getEnvVarOnDemandStrict(name)` | Get variable or throw error | `Promise<string>` |
| `getEnvVarOnDemandSync(name)` | Synchronously get variable | `string \| undefined` |
| `getEnvVarOnDemandAsObject(name)` | Get variable as decoded object | `Promise<any>` |
#### Properties
| Property | Type | Description |
|----------|------|-------------|
| `requiredEnvVars` | `string[]` | List of required variable names |
| `availableEnvVars` | `string[]` | List of found variable names |
| `missingEnvVars` | `string[]` | List of missing variable names |
| `keyValueObject` | `object` | All loaded variables as key-value pairs |
## License and Legal Information
This 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.
**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.
### Trademarks
This 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.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By 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.
+120
View File
@@ -0,0 +1,120 @@
import * as path from 'path';
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as qenv from '../ts/index.js';
const testDir = path.dirname(new URL(import.meta.url).pathname);
// Test falsy values handling
tap.test('should handle falsy values correctly', async () => {
// Set up environment variables with falsy values
process.env['FALSY_FALSE'] = 'false';
process.env['FALSY_ZERO'] = '0';
process.env['FALSY_EMPTY'] = '';
const testQenv = new qenv.Qenv(testDir, testDir, false);
// Test that falsy values are returned, not undefined
expect(await testQenv.getEnvVarOnDemand('FALSY_FALSE')).toEqual('false');
expect(await testQenv.getEnvVarOnDemand('FALSY_ZERO')).toEqual('0');
expect(await testQenv.getEnvVarOnDemand('FALSY_EMPTY')).toEqual('');
// Test sync versions
expect(testQenv.getEnvVarOnDemandSync('FALSY_FALSE')).toEqual('false');
expect(testQenv.getEnvVarOnDemandSync('FALSY_ZERO')).toEqual('0');
expect(testQenv.getEnvVarOnDemandSync('FALSY_EMPTY')).toEqual('');
// Test that undefined is still returned for non-existent variables
expect(await testQenv.getEnvVarOnDemand('NON_EXISTENT')).toBeUndefined();
expect(testQenv.getEnvVarOnDemandSync('NON_EXISTENT')).toBeUndefined();
// Clean up
delete process.env['FALSY_FALSE'];
delete process.env['FALSY_ZERO'];
delete process.env['FALSY_EMPTY'];
});
tap.test('should handle falsy values in env.json file', async () => {
// Create a test env.json with falsy values
const testAssetsDir = path.join(testDir, 'assets-falsy');
const fs = await import('fs');
// Create directory if it doesn't exist
if (!fs.existsSync(testAssetsDir)) {
fs.mkdirSync(testAssetsDir, { recursive: true });
}
// Create env.json with falsy values
const envJsonContent = {
JSON_FALSE: false,
JSON_ZERO: 0,
JSON_EMPTY: ''
};
fs.writeFileSync(
path.join(testAssetsDir, 'env.json'),
JSON.stringify(envJsonContent, null, 2)
);
const testQenv = new qenv.Qenv(testAssetsDir, testAssetsDir, false);
// Test that falsy values from JSON are returned correctly
expect(await testQenv.getEnvVarOnDemand('JSON_FALSE')).toEqual('false');
expect(await testQenv.getEnvVarOnDemand('JSON_ZERO')).toEqual('0');
expect(await testQenv.getEnvVarOnDemand('JSON_EMPTY')).toEqual('');
// Clean up
fs.rmSync(testAssetsDir, { recursive: true, force: true });
});
tap.test('should throw error for undefined in strict mode', async () => {
const testQenv = new qenv.Qenv(testDir, testDir, false);
// Set a falsy value
process.env['FALSY_VALUE'] = '0';
// Should NOT throw for falsy value
let result;
try {
result = await testQenv.getEnvVarOnDemandStrict('FALSY_VALUE');
} catch (error) {
// Should not reach here
expect(true).toBeFalse();
}
expect(result).toEqual('0');
// Should throw for non-existent variable
let threwError = false;
try {
await testQenv.getEnvVarOnDemandStrict('NON_EXISTENT_VAR');
} catch (error) {
threwError = true;
const errorMessage = error instanceof Error ? error.message : String(error);
expect(errorMessage).toContain('is not set');
}
expect(threwError).toBeTrue();
// Clean up
delete process.env['FALSY_VALUE'];
});
tap.test('should handle array of env vars with falsy values', async () => {
const testQenv = new qenv.Qenv(testDir, testDir, false);
// Set up test environment
process.env['FIRST_VAR'] = '0';
process.env['SECOND_VAR'] = 'false';
// Test that it returns the first defined value, even if falsy
const result = await testQenv.getEnvVarOnDemand(['NON_EXISTENT', 'FIRST_VAR', 'SECOND_VAR']);
expect(result).toEqual('0');
// Test sync version
const resultSync = testQenv.getEnvVarOnDemandSync(['NON_EXISTENT', 'FIRST_VAR', 'SECOND_VAR']);
expect(resultSync).toEqual('0');
// Clean up
delete process.env['FIRST_VAR'];
delete process.env['SECOND_VAR'];
});
export default tap.start();
+17 -11
View File
@@ -1,29 +1,35 @@
import * as path from 'path'; import * as path from 'path';
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as qenv from '../ts/index'; import * as qenv from '../ts/index.js';
import * as smartpath from '@push.rocks/smartpath';
export { smartpath };
const testDir = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
process.env['key1'] = 'original'; process.env['key1'] = 'original';
let testQenv: qenv.Qenv; let testQenv: qenv.Qenv;
tap.test('should create a new class', async () => { tap.test('should create a new class', async () => {
testQenv = new qenv.Qenv(path.join(__dirname, 'assets'), path.join(__dirname, 'assets'), false); testQenv = new qenv.Qenv(path.join(testDir, 'assets'), path.join(testDir, 'assets'), false);
expect(testQenv).to.be.instanceof(qenv.Qenv); expect(testQenv).toBeInstanceOf(qenv.Qenv);
}); });
tap.test('key1 should be not be overwritten since it is already present', async () => { tap.test('key1 should be not be overwritten since it is already present', async () => {
expect(testQenv.getEnvVarRequired('key1')).to.equal('original'); expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
expect(testQenv.getEnvVarOnDemand('key1')).to.equal('original'); expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
}); });
tap.test('key2 should be read from Yml', async () => { tap.test('key2 should be read from Yml', async () => {
expect(testQenv.getEnvVarRequired('key2')).to.equal('fromJson'); expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
expect(testQenv.getEnvVarOnDemand('key2')).to.equal('fromJson'); expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
}); });
tap.test('keyValueObjectArray should hold all retrieved values', async () => { tap.test('keyValueObjectArray should hold all retrieved values', async () => {
expect(testQenv.keyValueObject.key1).to.equal('original'); expect(await testQenv.keyValueObject.key1).toEqual('original');
expect(testQenv.keyValueObject.key2).to.equal('fromJson'); expect(await testQenv.keyValueObject.key2).toEqual('fromJson');
}); });
tap.start(); export default tap.start();
+8
View File
@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/qenv',
version: '6.1.4',
description: 'A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.'
}
+1 -1
View File
@@ -1 +1 @@
export * from './qenv.classes.qenv'; export * from './qenv.classes.qenv.js';
+31
View File
@@ -0,0 +1,31 @@
import * as plugins from './qenv.plugins.js';
export class CloudlyAdapter {
public configVaultUrl?: string;
constructor(configVaultUrl?: string) {
this.configVaultUrl = configVaultUrl;
}
public async getConfigBundle(): Promise<plugins.configvaultInterfaces.data.IEnvBundle | null> {
if (this.configVaultUrl) {
console.log(`ConfigVault specified through constructor`)
} else if (process.env['CONFIGVAULT_URL']) {
this.configVaultUrl = process.env['CONFIGVAULT_URL'];
} else {
return null;
}
const parsedUrl = new URL(this.configVaultUrl);
const tr =
new plugins.typedrequest.TypedRequest<plugins.configvaultInterfaces.requests.IReq_GetEnvBundle>(
`${parsedUrl.host}/typedrequest`,
'getEnvBundle'
);
const response = await tr.fire({
authorization: parsedUrl.pathname.replace('/', ''),
})
return response.envBundle;
}
}
+242 -158
View File
@@ -1,44 +1,97 @@
import * as plugins from './qenv.plugins'; 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>;
/**
* class Qenv
* allows to make assertions about the environments while being more flexibel in how to meet them
*/
export class Qenv { export class Qenv {
public requiredEnvVars: string[] = []; public requiredEnvVars: string[] = [];
public availableEnvVars: string[] = []; public availableEnvVars: string[] = [];
public missingEnvVars: string[] = []; public missingEnvVars: string[] = [];
public keyValueObject: { [key: string]: any } = {}; public keyValueObject: TKeyValueObject = {};
public logger = new plugins.smartlog.ConsoleLog(); public logger = new plugins.smartlog.ConsoleLog();
// filePaths public cloudlyAdapter: CloudlyAdapter;
public qenvFilePathAbsolute: string;
public envFilePathAbsolute: string;
constructor(qenvFileBasePathArg = process.cwd(), envFileBasePathArg, failOnMissing = true) { public qenvFilePathAbsolute = '';
// lets make sure paths are absolute public envFilePathAbsolute?: string;
constructor(
qenvFileBasePathArg: string = process.cwd(),
envFileBasePathArg?: string,
failOnMissing: boolean = true
) {
this.cloudlyAdapter = new CloudlyAdapter();
this.initializeFilePaths(qenvFileBasePathArg, envFileBasePathArg);
this.loadRequiredEnvVars();
this.loadAvailableEnvVars();
this.checkForMissingEnvVars(failOnMissing);
}
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg?: string) {
this.qenvFilePathAbsolute = plugins.path.join( this.qenvFilePathAbsolute = plugins.path.join(
plugins.path.resolve(qenvFileBasePathArg), plugins.path.resolve(qenvFileBasePathArg),
'qenv.yml' 'qenv.yml'
); );
this.envFilePathAbsolute = plugins.path.join(
plugins.path.resolve(envFileBasePathArg), if (envFileBasePathArg) {
'env.json' const envFileBasePath = plugins.path.resolve(envFileBasePathArg);
const envFileJsonPath = plugins.path.join(envFileBasePath, 'env.json');
const envFileYmlPath = plugins.path.join(envFileBasePath, 'env.yml');
const envFileYamlPath = plugins.path.join(envFileBasePath, 'env.yaml');
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');
this.envFilePathAbsolute = envFileJsonPath;
} else if (envFileJsonExists) {
this.envFilePathAbsolute = envFileJsonPath;
} else if (envFileYmlExists) {
this.envFilePathAbsolute = envFileYmlPath;
} else if (envFileYamlExists) {
this.envFilePathAbsolute = envFileYamlPath;
}
}
}
private loadRequiredEnvVars() {
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!');
}
}
}
private loadAvailableEnvVars() {
for (const envVar of this.requiredEnvVars) {
const value = this.getEnvVarOnDemand(envVar);
if (value !== undefined) {
this.availableEnvVars.push(envVar);
this.keyValueObject[envVar] = value;
}
}
}
private checkForMissingEnvVars(failOnMissing: boolean) {
this.missingEnvVars = this.requiredEnvVars.filter(
(envVar) => !this.availableEnvVars.includes(envVar)
); );
this.getRequiredEnvVars();
this.getAvailableEnvVars();
this.missingEnvVars = this.getMissingEnvVars();
// handle missing variables
if (this.missingEnvVars.length > 0) { if (this.missingEnvVars.length > 0) {
console.info('Required Env Vars are:'); console.info('Required Env Vars are:', this.requiredEnvVars);
console.log(this.requiredEnvVars); console.error('Missing Env Vars:', this.missingEnvVars);
console.error('However some Env variables could not be resolved:');
console.log(this.missingEnvVars);
if (failOnMissing) { if (failOnMissing) {
this.logger.log('error', 'Exiting!'); this.logger.log('error', 'Exiting due to missing env vars!');
process.exit(1); process.exit(1);
} else { } else {
this.logger.log('warn', 'qenv is not set to fail on missing environment variables'); this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
@@ -46,150 +99,181 @@ export class Qenv {
} }
} }
/** public async getEnvVarOnDemand(
* only gets an environment variable if it is required within a read qenv.yml file envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
* @param envVarName ): Promise<string | undefined> {
*/ if (Array.isArray(envVarNameOrNames)) {
public getEnvVarRequired(envVarName): string { for (const envVarName of envVarNameOrNames) {
return this.keyValueObject[envVarName]; const value = await this.tryGetEnvVar(envVarName);
} if (value !== undefined) {
return value;
/**
* tries to get any env var even if it is not required
* @param wantedEnvVar
*/
public getEnvVarOnDemand(wantedEnvVar: string): string {
let envVarFromEnvironmentVariable: string;
let envVarFromEnvJsonFile: string;
let envVarFromDockerSecret: string;
let dockerSecretJson: string;
// env var check
if (process.env[wantedEnvVar]) {
this.availableEnvVars.push(wantedEnvVar);
envVarFromEnvironmentVariable = process.env[wantedEnvVar];
}
// env file check
// lets determine the actual env yml
let envJsonFileAsObject;
try {
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
} catch (err) {
envJsonFileAsObject = {};
}
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
}
// docker secret check
if (
plugins.smartfile.fs.isDirectory('/run') &&
plugins.smartfile.fs.isDirectory('/run/secrets') &&
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${wantedEnvVar}`)
) {
envVarFromDockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${wantedEnvVar}`);
}
// docker secret.json
if (
plugins.smartfile.fs.isDirectory('/run') &&
plugins.smartfile.fs.isDirectory('/run/secrets')
) {
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
for (const secret of availableSecrets) {
if (secret.includes('secret.json') && !envVarFromDockerSecret) {
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
envVarFromDockerSecret = secretObject[wantedEnvVar];
} }
} }
} return undefined;
// warn if there is more than one candidate
const availableCcandidates: any[] = [];
[
envVarFromEnvironmentVariable,
envVarFromEnvJsonFile,
envVarFromDockerSecret,
dockerSecretJson
].forEach(candidate => {
if (candidate) {
availableCcandidates.push(candidate);
}
});
if (availableCcandidates.length > 1) {
this.logger.log(
'warn',
`found multiple candidates for ${wantedEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
);
console.log(availableCcandidates);
}
switch (true) {
case !!envVarFromEnvironmentVariable:
this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
return envVarFromEnvironmentVariable;
case !!envVarFromEnvJsonFile:
this.logger.log('ok', `found ${wantedEnvVar} as env.json variable`);
return envVarFromEnvJsonFile;
case !!envVarFromDockerSecret:
this.logger.log('ok', `found ${wantedEnvVar} as docker secret`);
return envVarFromDockerSecret;
case !!dockerSecretJson:
this.logger.log('ok', `found ${wantedEnvVar} as docker secret.json`);
return dockerSecretJson;
default:
this.logger.log(
'warn',
`could not find the wanted environment variable ${wantedEnvVar} anywhere`
);
return;
}
}
/**
* gets the required env values
*/
private getRequiredEnvVars = () => {
let qenvFile: any = {};
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
}
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
this.logger.log(
'warn',
`qenv (promised environment): ./qenv.yml File does not contain a 'required' Array! This might be ok though.`
);
} else { } else {
for (const keyArg of Object.keys(qenvFile.required)) { return await this.tryGetEnvVar(envVarNameOrNames);
this.requiredEnvVars.push(qenvFile.required[keyArg]);
} }
} }
};
/** /**
* gets the available env vars * Like getEnvVarOnDemand, but throws an error if the env var is not set.
* @param envVarNameOrNames
* @returns
*/ */
private getAvailableEnvVars = () => { public async getEnvVarOnDemandStrict(
for (const requiredEnvVar of this.requiredEnvVars) { envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
const chosenVar = this.getEnvVarOnDemand(requiredEnvVar); ): Promise<string> {
if (chosenVar) { const value = await this.getEnvVarOnDemand(envVarNameOrNames);
this.availableEnvVars.push(requiredEnvVar); if (value === undefined) {
this.keyValueObject[requiredEnvVar] = chosenVar; throw new Error(`Env var ${envVarNameOrNames} is not set!`);
} }
return value;
} }
};
/** public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
* gets missing env vars console.warn('requesting env var sync leaves out potentially important async env sources.');
*/
private getMissingEnvVars = (): string[] => { if (Array.isArray(envVarNameOrNames)) {
const missingEnvVars: string[] = []; for (const envVarName of envVarNameOrNames) {
for (const envVar of this.requiredEnvVars) { const value = this.tryGetEnvVarSync(envVarName);
if (!this.availableEnvVars.includes(envVar)) { if (value !== undefined) {
missingEnvVars.push(envVar); return value;
} }
} }
return missingEnvVars; return undefined;
}; } else {
return this.tryGetEnvVarSync(envVarNameOrNames);
}
}
public async getEnvVarOnDemandAsObject(envVarNameOrNames: string | string[]): Promise<any> {
const rawValue = await this.getEnvVarOnDemand(envVarNameOrNames);
if (rawValue && rawValue.startsWith('base64Object:')) {
const base64Part = rawValue.split('base64Object:')[1];
return this.decodeBase64(base64Part);
}
return rawValue;
}
private async tryGetEnvVar(envVarRefArg: TEnvVarRef): Promise<string | undefined> {
if (typeof envVarRefArg === 'function') {
return await envVarRefArg();
}
const sources = [
this.getFromEnvironmentVariable(envVarRefArg),
this.getFromEnvYamlOrJsonFile(envVarRefArg),
this.getFromDockerSecret(envVarRefArg),
this.getFromDockerSecretJson(envVarRefArg)
];
for (const value of sources) {
if (value !== undefined) {
return value;
}
}
return undefined;
}
private tryGetEnvVarSync(envVarName: string): string | undefined {
const sources = [
this.getFromEnvironmentVariable(envVarName),
this.getFromEnvYamlOrJsonFile(envVarName),
this.getFromDockerSecret(envVarName),
this.getFromDockerSecretJson(envVarName)
];
for (const value of sources) {
if (value !== undefined) {
return value;
}
}
return undefined;
}
private getFromEnvironmentVariable(envVarName: string): string | undefined {
return process.env[envVarName];
}
private getFromEnvYamlOrJsonFile(envVarName: string): string | undefined {
if (!this.fileExists(this.envFilePathAbsolute)) {
return undefined;
}
try {
const envJson = this.readObjectFromFile(this.envFilePathAbsolute);
const value = envJson[envVarName];
if (value === undefined) {
return undefined;
}
if (typeof value === 'object' && value !== null) {
return 'base64Object:' + this.encodeBase64(value);
}
return String(value);
} catch (error) {
return undefined;
}
}
private getFromDockerSecret(envVarName: string): string | undefined {
const secretPath = `/run/secrets/${envVarName}`;
if (this.fileExists(secretPath)) {
return plugins.fs.readFileSync(secretPath, 'utf8');
}
return undefined;
}
private getFromDockerSecretJson(envVarName: string): string | undefined {
if (this.directoryExists('/run/secrets')) {
const availableSecrets = plugins.fs.readdirSync('/run/secrets');
for (const secret of availableSecrets) {
if (secret.includes('secret.json')) {
const secretObject = this.readObjectFromFile(`/run/secrets/${secret}`);
const value = secretObject[envVarName];
if (value === undefined) {
continue;
}
if (typeof value === 'object' && value !== null) {
return 'base64Object:' + this.encodeBase64(value);
}
return String(value);
}
}
}
return undefined;
}
private encodeBase64(data: any): string {
const jsonString = JSON.stringify(data);
return Buffer.from(jsonString).toString('base64');
}
private decodeBase64(encodedString: string): any {
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 : {};
}
} }
+21 -4
View File
@@ -1,10 +1,27 @@
// native // native
import * as fs from 'node:fs';
import * as path from 'path'; import * as path from 'path';
export { path }; export { fs, path };
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
export {
typedrequest,
}
// @pushrocks scope // @pushrocks scope
import * as smartfile from '@pushrocks/smartfile'; import * as smartlog from '@push.rocks/smartlog';
import * as smartlog from '@pushrocks/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 };
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": ["dist_*/**/*.d.ts"]
}
-17
View File
@@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}