{"_id":"@c3exchange/simple-config","_rev":"1-24cb5360ccfd5f7b763eba11e4336bcc","name":"@c3exchange/simple-config","description":"Simple application configuration library","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@c3exchange/simple-config","version":"0.1.0","author":"","license":"MIT","_id":"@c3exchange/simple-config@0.1.0","maintainers":[{"name":"alex99y","email":"alexyammine94@gmail.com"},{"name":"mxmauro","email":"mxmauro@mauroleggieri.com"}],"ava":{"typescript":{"compile":false,"rewritePaths":{"src/":"lib/"}}},"dist":{"shasum":"1af9f7b826b73179eb54cf625ed8b73e639f274f","tarball":"https://registry.npmjs.org/@c3exchange/simple-config/-/simple-config-0.1.0.tgz","fileCount":36,"integrity":"sha512-uwJYYFsmRQ58NwsJr8Dj89RfLMMH80QX8oHF15x/76OAg2bsTKW7OYFWjkpcEt89DbURY0KxaiafaaOGe4hdRw==","signatures":[{"sig":"MEUCIDxNBUxb0vblW/NVKJzxla8KFruMXBEUOH+MxtIqq815AiEA8tdF5CfQ4KKJ7zoJZAlWQIf9cPBpMxNIlAwOUbfHJk0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":80196},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"12fb410ba5329227c260af686179207c6b436f2f","scripts":{"test":"npm run clean && tsc --build tsconfig.tests.json && ava **/*.test.ts","build":"npm run clean && tsc && dts-bundle-generator -o lib/index.d.ts -no-banner src/index.ts","clean":"rimraf -I lib","prepack":"npm run build"},"_npmUser":{"name":"mxmauro","email":"mxmauro@mauroleggieri.com"},"_npmVersion":"10.3.0","description":"Simple application configuration library","directories":{},"_nodeVersion":"20.9.0","dependencies":{"axios":"^1.6.5","axios-retry":"^4.0.0","@smithy/signature-v4":"^2.0.19","@smithy/protocol-http":"^3.0.12","@aws-sdk/credential-providers":"^3.490.0"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.0.1","eslint":"^8.56.0","rimraf":"^5.0.5","cross-env":"^7.0.3","typescript":"^5.3.3","@types/node":"^20.11.2","@ava/typescript":"^4.1.0","dts-bundle-generator":"^9.2.4","@typescript-eslint/parser":"^6.18.1","@typescript-eslint/eslint-plugin":"^6.18.1"},"_npmOperationalInternal":{"tmp":"tmp/simple-config_0.1.0_1705423771021_0.6112331614736672","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-01-16T16:49:30.905Z","modified":"2024-06-13T20:53:37.835Z","0.1.0":"2024-01-16T16:49:31.174Z"},"maintainers":[{"email":"joshua.averett@gmail.com","name":"javerett"},{"email":"alexyammine94@gmail.com","name":"alex99y"},{"email":"mxmauro@mauroleggieri.com","name":"mxmauro"}],"license":"MIT","readme":"# Simple-Config\n\nA simple application configuration library.\n\n# Installation and usage\n\n## Installation\n\nRun the following command in your NodeJS project's directory.\n\n```bash\nnpm i @c3exchange/simple-config\n```\n\n## Sample code\n\n1. First define the configuration variables you expect. You can specify the type of variable and some constraints. For example:\n\n```javascript\nconst variableDefs: Variable[] = [\n\tStringVar.define('DATABASE_HOST').minLength(1).maxLength(256).validator((value: string, name: string): string => {\n\t\tif (ipV4AddressRegex.test(value) || hostnameRegex.test(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tthrow new Error('Variable \"' + name + '\" is not an IPv4 address nor a host name.');\n\t}),\n\tNumberVar.define('DATABASE_PORT').min(1).max(65535),\n\tBooleanVar.define('DATABASE_USE_SSL'),\n\tEnumVar.define('DATABASE_TYPE').allowed(['mysql', 'postgresql', 'mongodb'])\n];\n```\n\n2. At program startup, try to load them from process environment variables and/or Hashicorp Vault secrets store.\n\n```javascript\ntry {\n\tconst settings = await load({\n\t\tvars: variableDefs\n\t});\n\t// ....\n}\ncatch (err: any) {\n\t// ....\n}\n```\n\n## Variable types\n\n### StringVar\n\nDefine a string variable using `StringVar.define(\"{variable-name}\")`.\n\nThe available constraints and options are:\n\n| Name        | Description                                                                                                                      |\n|-------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `minLength` | Specifies the minimum length.                                                                                                    |\n| `maxLength` | Specifies the maximum length.                                                                                                    |\n| `validator` | Specifies a custom validator callback. After performing your desired checks, the validator function can return a modified value. |\n\n### NumberVar\n\nDefine a numeric variable using `NumberVar.define(\"{variable-name}\")`.\n\nThe available constraints and options are:\n\n| Name        | Description                                                                                                                      |\n|-------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `min`       | Specifies the minimum value.                                                                                                     |\n| `max`       | Specifies the maximum value.                                                                                                     |\n| `musBeInt`  | Indicates if the number must be an integer value or can be float.                                                                |\n| `validator` | Specifies a custom validator callback. After performing your desired checks, the validator function can return a modified value. |\n\n### EnumVar\n\nDefine a string variable that only allows one of a set of values using `EnumVar.define(\"{variable-name}\")`.\n\nThe available constraint is:\n\n| Name      | Description                                                                                         |\n|-----------|-----------------------------------------------------------------------------------------------------|\n| `allowed` | An array of allowed values, case insensitive. The value is transformed to uppercase when processed. |\n\n### BooleanVar\n\nDefine a boolean variable using `BooleanVar.define(\"{variable-name}\")`.\n\nThe case-insensitive values `1`, `Y`, `yes`, `on`, `t` and `true` resolves to `true` and the values `0`, `N`, `no`, `off`, `f` and `false` resolves to `false`.\n\n### Additional common options\n\n| Name        | Description                                                                                                                      |\n|-------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `required`  | Raises an exception if the variable is not found unless a `default`` value is assigned.                                          |\n| `default`   | Sets a default value if the variable is not defined.                                                                             |\n\n## Loader options\n\nThe `load` function accepts some configuration options that established the load behavior. By default, the library will attempt to load and merge variables in the following order:\n\n1. From Vault, if access is allowed and a the environment variable containing the url is present.\n2. From the process environment.\n\n| Name              | Description                                                                                               |\n|-------------------|-----------------------------------------------------------------------------------------------------------|\n| `vars`            | An array of `Variable`` objects that defines the configuration settings to parse.                         |\n| `envVarsOverride` | Specifies if the values readed from Vault can be overriden with values stored in the process environment. |\n| `modifyEnvVars`   | The `load` function returns an object with the parsed values.<br />By enabling this setting, it will also set/overwrite the process' environment variables with stringified versions of the those values.<br />Defaults to `true`. |\n| `vaultOpts`       | Customizes Vault access behavior. See below for details.                                                  |\n\nVault options:\n\n| Name                   | Description                                                                                                                            |\n|------------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `disable`              | Skip the attempt to load variables from Vault.                                                                                         |\n| `envVar`               | Sets what environment variable name may contain the Vault URL.<br />Defaults to `VAULT_URL`.                                           |\n| `caCertEnvVar` (1)     | Sets what environment variable name may contain the filename of the certificate autority file.<br />Defaults to `VAULT_SSL_CACERT`.    |\n| `certEnvVar`   (1) (2) | Sets what environment variable name may contain the filename of the client certificate file.<br />Defaults to `VAULT_SSL_CLIENT_CERT`. |\n| `keyEnvVar`    (1) (2) | Sets what environment variable name may contain the filename of the client private key file.<br />Defaults to `VAULT_SSL_CLIENT_KEY`.  |\n\n1. Used only when accesing Vault with HTTPS.\n2. Define both variables or none. You cannot define just one of them.\n\n# Hashicorp Vault setup and URL format\n\nThe [document folder](./docs/) contains instructions on how to configure Hashicorp Vault for different authentication methods like AppRole, [AWS](https://aws.amazon.com/) using IAM roles and [Kubernetes](https://kubernetes.io/).\n\nThe URL must have the following format: `{protocol}://{vault-host:vault-port}?{query-parameters}`\n\nWhere `protocol` can be `http` or `https`. `vault-host` and, optionally, `vault-port` indicates the location of Vault server. At last, `query-parameters` are:\n\n| Parameter             | Description                                                                                                  |\n|-----------------------|--------------------------------------------------------------------------------------------------------------|\n| `method`              | Can be `iam`, `approle` or `k8s`. The loader tries to auto-detect the authorization method if not specified. |\n| `mountPath`           | Sets the authentication mount path. Defaults to `aws`, `approle` or `kubernetes`.                            |\n| `path`                | A full path where secrets are stored. For example: `/secret/data/my-app`. See notes below.                   |\n| `roleName`            | Specifies the role name to use. Only valid for `iam` and `k8s` authentication methods.                       |\n| `roleId` & `secretId` | Specifies the role and secret ids. Only valid for the `approle` authentication method.                       |\n| `timeout`             | Establishes a query timeout. Defaults to 10 seconds.                                                         |\n| `allowUntrusted`      | If set to `true`, invalid or expired HTTPS server certificates are ignored.                                  |\n\nRemember to do escape encoding when specifying query parameters.\n\n##### NOTES for the `path` parameter\n\n* If multiple path query parameters are specified, they are read in order. If duplicated settings are found in more than one location, the lastest will be used.\n* The path route may vary depending on the secrets engine you are accessing. Check Vault documentation.\n\n# License\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}