{"_id":"@codemaniac-technologies/codemaniac-config","name":"@codemaniac-technologies/codemaniac-config","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@codemaniac-technologies/codemaniac-config","version":"1.0.0","description":"> CODEMANIAC Microservice Configuration module used to configure API services and > load environment specific configuration files.","main":"lib/config.js","scripts":{"test":"nyc --cache --reporter=html --reporter=text ./node_modules/.bin/mocha --colors --recursive --timeout 10000 --reporter spec --exit","test-only":"mocha --colors --recursive --timeout 10000 --reporter spec --exit","security":"npm audit"},"repository":{"type":"git","url":"git+https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config.git"},"author":{"name":"Codemaniac Technologies"},"license":"ISC","type":"commonjs","nyc":{"exclude":["**/index.js","**/deploy/**","**/test/**"]},"prettier":{"printWidth":90,"tabWidth":2,"useTabs":false,"semi":true,"singleQuote":true,"trailingComma":"none","bracketSpacing":true,"jsxBracketSameLine":false,"arrowParens":"avoid","proseWrap":"preserve"},"husky":{"hooks":{"pre-commit":"lint-staged","pre-push":"npm run test"}},"lint-staged":{"*.{js,jsx,ts,tsx,md,html,css}":"prettier --write"},"dependencies":{"@codemaniac-technologies/codemaniac-logger":"^1.0.1","app-root-path":"^3.1.0","aws-sdk":"^2.1692.0","dotenv":"^16.5.0","nconf":"^0.13.0","traverse":"^0.6.11"},"devDependencies":{"chai":"^5.2.0","husky":"^9.1.7","lint-staged":"^16.0.0","mocha":"^11.4.0","nyc":"^17.1.0","prettier":"^3.5.3"},"_id":"@codemaniac-technologies/codemaniac-config@1.0.0","gitHead":"4cab5f2b688230ea04ce7b4ae8dd60663b2fc27d","bugs":{"url":"https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config/issues"},"homepage":"https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config#readme","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-vy854eOH11ns+s6YpxBjQKoxolU17uU/wN3C9HLLH+I2KXr+NOS6ngaW1VRRPkSj8TLyO8N/EOrlxlaFfQ8f9Q==","shasum":"2093905e9e8ec055308311350c09fe0360ccfe93","tarball":"https://registry.npmjs.org/@codemaniac-technologies/codemaniac-config/-/codemaniac-config-1.0.0.tgz","fileCount":17,"unpackedSize":31691,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGR+bUj60gIoYQqd0waRMqBZSus8ltU4db5RHb4wQdpfAiEA1XMZ7g124p29Jz1azeExZzujwgQ2vd9fs46oIFeTfvk="}]},"_npmUser":{"name":"codemaniac","email":"codemaniactechnologies@gmail.com"},"directories":{},"maintainers":[{"name":"codemaniac","email":"codemaniactechnologies@gmail.com"},{"name":"dtanaji75","email":"dtanaji75@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/codemaniac-config_1.0.0_1753537702208_0.7532388969832431"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-26T13:48:22.147Z","1.0.0":"2025-07-26T13:48:22.531Z","modified":"2025-07-26T13:48:22.761Z"},"maintainers":[{"name":"codemaniac","email":"codemaniactechnologies@gmail.com"},{"name":"dtanaji75","email":"dtanaji75@gmail.com"}],"description":"> CODEMANIAC Microservice Configuration module used to configure API services and > load environment specific configuration files.","homepage":"https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config#readme","repository":{"type":"git","url":"git+https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config.git"},"author":{"name":"Codemaniac Technologies"},"bugs":{"url":"https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config/issues"},"license":"ISC","readme":"# codemaniac-config\n\n> CODEMANIAC Microservice Configuration module used to configure API services and\n> load environment specific configuration files.\n\n## Installation\n\n1. Install as an NPM package from its git repository:\n   ```bash\n   npm install https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-config.git\n   ```\n\n## Dependencies\n\n1. `codemaniac-server` module:\n\n   Thie `codemaniac-config` modules works hand in hand with the [codemaniac-server](https://github.com/CodeManiac-Technologies-Pvt-Ltd/codemaniac-server.git) module. Though it can be imported independently, the `codemaniac-server` module automatically handles loading configurations for you.\n\n1. Config files:\n   In the context of this module, there are two classes of config files being used in our projects:\n\n   - **Environment** (dotenv) configs:\n     These configuration files are used to build a set of process environment variables scoped to the\n     environment the application is running in. An environment is denoted by the combination of the NODE_ENV\n     variable (eg. dev, devgate, sqa, prod, etc.) and the client. In essence, the environment identifies the\n     cluster the application is deployed to. The content of these config files generally includes usernames and\n     secrets. And may also include other environment scoped information such as api urls.\n\n- **Application** (json) configs:\n  These configuration files are specific to an application or service. These configs focus on the different\n  configuration options scoped to the application itself. It includes the bulk of the options that are\n  instantiated by the `codemaniac-server` module, including:\n  - Which services/modules to load\n  - Logging capabilities\n  - General config data for use throughout the application\n\nSpecific config keys are shown below and full examples of the configuration files are included in the\n`config` folder.\n\nMost configuration options are provided and maintained in the modules we utilize for development. For simplicity,\ninclude below is an amalgamation of serveral options currently provided in our modules and how the may be used.\nThe options shown only serve as an example of what's available and should not be considered the official source\ndocumentation for module configurations. To obtain the actual documentation for a given option, please see the\ncorresponding module.\n\n### codemaniac-server\n\n#### Configuration Options:\n\n- `host`:\n  Host object; encapsulates details occurred with the node.js server.\n\n  ##### Properties\n\n    <style type = \"text/css\">\n      tr {\n        text-align: left;\n        vertial-align: top;\n      }\n    </style>\n    <table border = \"2\">\n      <tr>\n        <th>Name</th>\n        <th>Type</th>\n        <th>Description</th>\n        <th>Example</th>\n      </tr>\n      <tr>\n        <td>port</td>\n        <td>integer<td>\n        <td>Application port the service will listen on. If not passed, defaults to 443</td>\n        <td>3000</td>\n      </tr>\n    </table>\n\n  ##### Example\n\n  ```.js\n  \"host\": {\n    \"port\": 3000\n  }\n  ```\n\n  - `services`:\n\n    The services object encapsulates configuration deatils for a module. Properties are module specific. As it\n    pertains to the `codemaniac-server`, the object is iterated through and each service/module is imported and\n    instantiated through either an `init` or `initialize` method as defined on the imported object. The config\n    element/object is passed to the `initialize` method, which creates and returns a corresponding instance of\n    itself with the configuration details as passed.\n\n    **NOTE: GENERATED module instances are often expected to be shared as singletons across the application (e.g\n    we use a single logger instance across all of our modules). If this functionality is need, ensure the module\n    initializing the singleton is only added as dependency (`package.json`) in the `aria-server` module so it's\n    not otherwise loaded locally in the module that depends upon it.**\n\n    ##### Properties\n\n      <style type='text/css'>\n        tr {\n          text-align: left;\n          vertical-align: top;\n        }\n      </style>\n       <table border = \"2\">\n      <tr>\n        <th>Name</th>\n        <th>Type</th>\n        <th>Description</th>\n        <th>Example</th>\n      </tr>\n      <tr>\n        <td><\"user_defined\"></td>\n        <td>object<td>\n        <td>Codemaniac module/services config object containing details used to instantiate the corresponding module\n        instance. The module instance returned on instantiation will be stored under the object name as passed.</td>\n        <td>\n          <pre><code>\"helpearn\": {\n            \"module: \"codemaniac-ds-mysql\",\n            \"poolAlias\": \"helpearn\",\n            \"modelPaths\": \"helpearn\",\n            \"user\": \"process.env.MYSQLDB_USER\",\n            \"password\": \"process.env.MYSQLDB_PASSWORD\",\n            \"connectionString\": \"process.env.MYSQLDB_CONNECTIONSTRING\",\n            \"poolIncrement\": 5,\n            \"poolMin\": 10,\n            \"poolMax\": 40,\n            \"poolTimeout\": 10,\n            \"queueTimeout\": 0,\n            \"queueRequests\": true,\n            \"_enableStats\": true \n          }\n          </code>\n          </pre>\n        </td>\n      </tr>\n    </table>\n\n    ##### Example\n\n    ```.js\n    \"services\":{\n      \"helpearn\": {\n            \"module: \"codemaniac-ds-mysql\",\n            \"poolAlias\": \"helpearn\",\n            \"modelPaths\": \"helpearn\",\n            \"user\": \"process.env.MYSQLDB_USER\",\n            \"password\": \"process.env.MYSQLDB_PASSWORD\",\n            \"connectionString\": \"process.env.MYSQLDB_CONNECTIONSTRING\",\n            \"poolIncrement\": 5,\n            \"poolMin\": 10,\n            \"poolMax\": 40,\n            \"poolTimeout\": 10,\n            \"queueTimeout\": 0,\n            \"queueRequests\": true,\n            \"_enableStats\": true\n          }\n    }\n    ```\n\n  ```\n\n  ```\n\n  - `features`\n\n    The `features` object includes additional details used to configure the server instance.\n\n    ##### Properties\n\n      <style type=\"text/css\">\n        tr {\n          text-align: left;\n          vertical-align: top;\n        }\n      </style>\n      <table border=\"2\">\n        <tr>\n          <th>Name</th>\n          <th>Type</th>\n          <th>Descriptions</th>\n          <th>Example</th>\n        </tr>\n        <tr>\n          <td>logRequests</td>\n          <td>boolean</td>\n          <td>When true, sets up the apiLogger middleware to log requests and response as configured.</td>\n          <td>true</td>\n        </tr>\n        <tr>\n          <td>logErrors</td>\n          <td>boolean</td>\n          <td>When true, sets up the apiLogger middleware to log API errors.</td>\n          <td>true</td>\n        </tr>\n        <tr>\n          <td>healthCheck</td>\n          <td>boolean</td>\n          <td>When true, creates a '/healthcheck' route on the server which provides details about the health of\n          the service.</td>\n          <td>true</td>\n        </tr>\n        <tr>\n          <td>healthCheckDiagnostics</td>\n          <td>boolean</td>\n          <td>When true, returns additional health check information about the server on the '/healthcheck' route.\n          Only used when feature.healthCheck = true.</td>\n          <td>true</td>\n        </tr>\n        <tr>\n          <td>errorDiagnostics</td>\n          <td>boolean</td>\n          <td>When true, additional error details are returned in the Error response object.</td>\n          <td>true</td>\n        </tr>\n      </table>\n    ##### Example\n\n    ```.js\n    \"features\": {\n      \"logRequests\": true,\n      \"logErrors\": true,\n      \"healthCheck\": true,\n      \"healthCheckDiagnostics\": true,\n      \"errorDiagnostics\": true\n    }\n    ```\n\n### codemaniac-logger:\n\n#### Configuration Options:\n\n- `logger`:\n  Logger configuration object.\n\n## **API**\n\n### Object: codemaniacConfig\n\n`codemaniacConfig` object is exported when requiring/importing the module.\n\n```js\nconst codemaniacConfig = require('codemaniac-config');\n```\n\n- Returns: {codemaniacConfig}\n\n### Methods/Functions\n\nmodule.exports.loadLocalEnvironment = loadLocalEnvironment;\nmodule.exports.loadLocalAppConfig = loadLocalAppConfig;\n\n#### codemaniacConfig.get(key)\n\nRetreives a configuration value from memory by key\n\n- `key` {string} - the key to retrevice, colon delimitted to denote nested object (e.g. `'services:helpearn:module'`\n  gets the `services.helpearn.module` value)\n- Returns: {Object/string}\n\n#### codemaniacConfig.set(key, value)\n\n- `key` {string} - the key for which to set the value to, colon delimitted to denote nested object (e.g.\n  `'services:helpearn:module'` sets the `services.helpearn.module` value)\n- `value` {string} - the value to set the key to\n- Returns: void\n\n#### codemaniacConfig.add(name, configObject)\n\nAdds an additional object to the in-memory config object store. Overrides key if already defined.\n\n- `name` {String} - Name identifier for the configuration object in the store.\n- `configObject` {object} - The configuration object\n- Returns: void\n\n#### codemaniacConfig.load([localFileConfig] = {})\n\n- `localFileConfig` {Object} - Configuration object providing local file paths to configs\n- `localFileConfig.tls` {Object} - Tls configuration object providing local file paths to tls files\n- `localFileConfig.tls.certPath` {string} - Path to tls cert file\n- `localFileConfig.tls.keyPath` {string} - Path to tls key file\n\nLoads base configuration along with additional configurations files and data (e.g. from s3 or SSM) based on the\nbase options passed. NOTE: Local env and application config files will be loaded if the following environment\nvariables are set:\n\n- `process.env.LOCAL_ENV_CONFIG_PATH` {string} - Path to environment (.env) file\n- `process.env.CODEMANIAC_LOCAL_APP_CONFIG_PATH` {string} - Path to application config\n\n#### codemaniacConfig.loadEnvConfig()\n\nLoads .env file into memory or from SSM.\n\n- Returns: void\n\n#### codemaniacConfig.loadEnvConfig.exposeEnvConfig()\n\nLoads .env file key/value pairs into memory as process environment variables.\n\n- Returns: void\n\n#### codemaniacConfig.loadAppConfig.subConfigEnvVariables(configObject)\n\nSubstitutes harcoded process environment variable strings with their in-meory values\n\n- `configObject` {Object} - The configuration object\n- Returns: {object} - The updated configObject with variables substituted.\n\n#### codemaniacConfig.loadLocalAppConfig([configFilePath])\n\nLoads application config.json file as specified by `configFilePath` into memory as a configuration object.\n\n- `configFilePath` {string} - path to the application config.json file -optional\n- Returns: void\n\n#### codemaniacConfig.getSSMParameters(parameters, [withDecryption])\n\nRetreives SSM parameteres as requested.\n\n- `parameters` {Array} - the configuration object\n- `withDecryption` {boolean} - Option to decrypt secure string parameters. Defaults to false.\n\n- Returns: {Promise<Object>} - The parameters object. See [AWS documentation](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetParameters.html) for specific details.\n\n## **Usage**\n\n1. Include the following in your code files:\n\n```js\nconst codemaniacConfig = require('codemaniac-config');\nconst configObject = {\n\tservices: {\n\t\tdataprotect: {\n\t\t\tclientKeySpecs: {\n\t\t\t\tdefault: {\n\t\t\t\t\tcurrentSpec: 'key-spec-value',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n};\n\n// add the configObject\nariaConfig.config.add('local-config', configObject);\n\n//get a key value (\"key-spec-value\")\n\nconst keySpec = codemaniacConfig.config.get(\n\t'services:dataprotect:clientKeySpecs:default:currentSpec'\n);\n\n//set a value\n\nconst newKeySpec = codemaniacConfig.config.set(\n\t'services:dataprotect:clientKeySpecs:default:currentSpec',\n\t'new-key-spec-value'\n);\n```\n\n## Tests\n\n1. To run the test suite, first install the dependencies the run `npm test`\n\n```bash\nnpm install\nnpm test\n```\n\nAn HTML copy of the coverage report will be written to the `./coverage` directory.\n\n2. Execute tests without code coverage reports:\n\n```bash\nnpm run test-only\n```\n\n3. Check adherance to style guidelines and detect potential problems:\n\n```bash\nnpm run lint\n```\n\n4. Check for known security exploits of dependent packages:\n\n```bash\nnpm run security\n```\n","readmeFilename":"README.md","_rev":"1-4cef6f520c23f6476b7cbe54e41cac0b"}