Skip to content

Commit

Permalink
add codr settings; update node module config
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanBulmer committed Apr 10, 2023
1 parent 725f5c5 commit 43fffda
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ Location of environment variable is postfixed to `Config.{location}` (e.g. `Conf
| --------------------------- | ------------------------------- | --------------------------------------------------------------------------------------- |
| `ENV` | `env` | Deployment envionment - `dev`, `qa`, `stage`, `prod` |
| `HOSTNAME` | `hostname` | Deployment docker hostname |
| `npm_package_name` | `name` | Deployment service name - example: codr-user-user |
| `npm_package_version` | `version` | Deployment version - example: `1.0.0` |
| Provided via npm | `name` | Deployment service name - example: codr-user-user |
| Provided via npm | `version` | Deployment version - example: `1.0.0` |
| `AWS_REGION` | `aws.region` | AWS - deployment region |
| `AWS_SES_API_VERSION` | `aws.ses.api.version` | AWS SES - api version |
| `AWS_SES_ACCESS_KEY` | `aws.ses.access.key` | AWS SES - IAM access key id |
| `AWS_SES_ACCESS_SECRET` | `aws.ses.access.secret` | AWS SES - IAM access key secret |
| `CODR_USER_AUTH_SVC_URL` | `codr.svc.user.auth` | Codr - user authentication service |
| `CODR_USER_PROFILE_SVC_URL` | `codr.svc.user.profile` | Codr - user profile entity service |
| `CODR_USER_SESSION_SVC_URL` | `codr.svc.user.session` | Codr - user session entity service |
| `CODR_USER_USER_SVC_URL` | `codr.svc.user.user` | Codr - user entity service |
| `EMAIL_FROM` | `email.from` | Email - from address |
| `EMAIL_REPLY_TO` | `email.replyto` | Email - reply to address(es) |
| `EXPRESS_HOST` | `express.host` | Express server - listener host |
Expand All @@ -61,10 +65,10 @@ Location of environment variable is postfixed to `Config.{location}` (e.g. `Conf
| `KAFKA_CLIENT_ID` | `kafka.clientId` | Kafka server - name of the kafka cluster |
| `KAFKA_CONSUMER_GROUP` | `kafka.consumer.group` | Kafka server - consumer group |
| `MONGO_URI` | `mongo.uri` | MongoDB - server URL, please include username and password to this string |
| `NODE_ENV` | `node.env` | Node environment - `development`,`production`, `testing` |
| `NODE_VERSION` | `node.verison` | Node version - example: `16.19.1` |
| N/A | `node.modules` | Node modules - string array of all dependencies |
| `YARN_VERSION` | `node.yarnVersion` | Node - package manager version |
| `NODE_ENV` | `node.env` | Node environment - `development`, `production`, `testing` |
| Provided via npm | `node.verison` | Node version - example: `16.19.1` |
| Provided via npm | `node.modules` | Node modules - string array of all dependencies |
| Provided via yarn | `node.yarnVersion` | Node - package manager version |
| `OPENAPI_INFO_TITLE` | `openapi.info.title` | OpenAPI - documentation title |
| `OPENAPI_INFO_DESC` | `openapi.info.description` | OpenAPI - documentation description |
| `OPENAPI_SERVER_ONE_URL` | `openapi.server[0].url` | OpenAPI - server one url |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codrjs/config",
"version": "1.0.4",
"version": "1.0.5",
"description": "Codr configuration, unified",
"main": "./cjs/index.js",
"module": "./esm/index.js",
Expand Down
19 changes: 19 additions & 0 deletions src/config/CodrConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const CodrConfig: {
svc: {
user: {
user: string;
profile: string;
session: string;
auth: string;
};
};
} = {
svc: {
user: {
auth: process.env.CODR_USER_AUTH_SVC_URL as string,
profile: process.env.CODR_USER_PROFILE_SVC_URL as string,
session: process.env.CODR_USER_SESSION_SVC_URL as string,
user: process.env.CODR_USER_USER_SVC_URL as string,
},
},
};
29 changes: 16 additions & 13 deletions src/config/NodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ export const NodeConfig: {
version: process.env.NODE_VERSION as string,
modules: Object.keys(process.env)
.filter(m => /npm_package_dependencies_/g.test(m))
.map(m => [m, process.env[m]] as [string, string])
.map(m => [m[0].replace(/npm_package_dependencies_/g, ""), m[1]])
.sort()
.map(
m =>
[m.replace(/npm_package_dependencies_/g, ""), process.env[m]] as [
string,
string,
],
)
.map(
m =>
[
m[0]
.split("_")
.map((p, idx) =>
p === ""
? "@"
: idx === m[0].split("_").length - 1 &&
m[0].split("_").length !== 1
? `/${p}`
: p,
)
.join(""),
m[0].split("_").reduce((acc, curr, idx) => {
if (curr === "") acc += "@";
else if (idx === 0) acc += curr;
else if (idx === 1 && acc === "@") acc += `${curr}/`;
else if (idx >= 1 && !/@\w+\//g.test(acc)) acc += `-${curr}`;
else acc += curr;
return acc;
}, ""),
m[1],
] as string[],
)
Expand Down
3 changes: 3 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dotenv from "dotenv";
dotenv.config();

import { AWSConfig } from "./AWSConfig";
import { CodrConfig } from "./CodrConfig";
import { EmailConfig } from "./EmailConfig";
import { ExpressConfig } from "./ExpressConfig";
import { GitConfig } from "./GitConfig";
Expand All @@ -20,6 +21,7 @@ const GeneralConfig = {

const Config = {
aws: AWSConfig,
codr: CodrConfig,
email: EmailConfig,
express: ExpressConfig,
jwt: JWTConfig,
Expand All @@ -33,6 +35,7 @@ const Config = {

export {
AWSConfig,
CodrConfig,
EmailConfig,
ExpressConfig,
GitConfig,
Expand Down

0 comments on commit 43fffda

Please sign in to comment.