@sprout-idws/sprout-config-loader 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +64 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @sprout-idws/sprout-config-loader
2
+
3
+ NestJS module that **loads configuration and secret files from directories** into `process.env` before (and alongside) `ConfigModule`, matching how Sprout deploys apps with Docker configs and secrets mounted as files.
4
+
5
+ ## Purpose
6
+
7
+ - In **Swarm / Sprout** deployments, values often arrive as files under `/run/configs` and `/run/secrets`, not only as a single `.env` file.
8
+ - This package reads those directories once at startup and exposes the same values through Nest `ConfigService` by merging them into the config layer loaded by `ConfigModule.forRoot`.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @sprout-idws/sprout-config-loader @nestjs/config
14
+ ```
15
+
16
+ Peer dependencies: `@nestjs/common`, `@nestjs/config` (v10+ / v3+ respectively).
17
+
18
+ ## Environment variables
19
+
20
+ | Variable | Default | Meaning |
21
+ |----------|---------|---------|
22
+ | `CONFIGS_BASE_PATH` | `/run/configs` | Directory of non-secret files (one file per key) |
23
+ | `SECRETS_BASE_PATH` | `/run/secrets` | Directory of secret files (one file per key) |
24
+
25
+ Each **file name** is normalized to an env key: non-alphanumeric characters become `_`, then the key is uppercased (for example `DATABASE_HOST` from a file named `DATABASE_HOST`).
26
+
27
+ If a key **already exists** in `process.env`, the file value is **not** applied (env wins).
28
+
29
+ ## Usage
30
+
31
+ Register early in your root module (typically global):
32
+
33
+ ```typescript
34
+ import { Module } from '@nestjs/common';
35
+ import { ConfigLoaderModule } from '@sprout-idws/sprout-config-loader';
36
+
37
+ @Module({
38
+ imports: [
39
+ ConfigLoaderModule.forRoot({
40
+ envFilePath: '.env', // optional; passed to ConfigModule.forRoot
41
+ isGlobal: true, // default true
42
+ }),
43
+ ],
44
+ })
45
+ export class AppModule {}
46
+ ```
47
+
48
+ `ConfigLoaderModule.forRoot`:
49
+
50
+ - Imports `ConfigModule.forRoot` with `load: [() => ConfigLoaderService.loadConfigFiles()]`.
51
+ - Exports `ConfigModule` so `ConfigService` sees file-backed values where not overridden.
52
+
53
+ ### Local development
54
+
55
+ Point `CONFIGS_BASE_PATH` / `SECRETS_BASE_PATH` at local folders with plain files named like production keys (same layout as in containers).
56
+
57
+ ## Exports
58
+
59
+ - `ConfigLoaderModule`, `ConfigLoaderModuleOptions`
60
+ - `ConfigLoaderService` (static `loadConfigFiles()` used by the module loader)
61
+
62
+ ## Repository
63
+
64
+ [`sprout-typescript-backend`](https://github.com/sprout-libs/sprout-typescript-backend) — `packages/sprout-config-loader`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprout-idws/sprout-config-loader",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Reusable NestJS config loader: loads config and secret files from directories into process.env",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "format:check": "biome format .",
16
16
  "check": "biome check .",
17
17
  "check:fix": "biome check --write .",
18
- "publish:npm": "npm publish"
18
+ "publish:npm": "bash ../../scripts/publish-npm.sh"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "@nestjs/common": ">=10.0.0",