-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: di and config mgmt #38
fix: di and config mgmt #38
Conversation
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
@TimoGlastra This runs fine. I still need to fix the style errors. Wanted to put it up for early review since I kinda went rogue in fixing #34. Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally ok, but could use some cleanup.
Haven't used nconf before but i like the config file based approach.
package.json
Outdated
"dotenv": "^16.4.7", | ||
"express": "^4.21.2", | ||
"nconf": "^0.12.1", | ||
"node-fetch": "^2.6.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally try to keep dependencies to a minimum. Makes maintenance easier. Node 18 has fetch built in. Node 20+ i think (we can keep that as a minimum i think?) has env file support built in.
I just removed node fetch before migration.
@@ -48,14 +50,14 @@ export async function createAgent() { | |||
const app = express() | |||
const socketServer = new Server({ noServer: true }) | |||
|
|||
const logger = new Logger(LOG_LEVEL) | |||
const logger = new Logger(config.get('agent:logLevel')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have typing support for config.get?
Otherwise i'd rather export these from a config file so we have correct typing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No typing unfortunately. A bit more on this in my latest comment. I can go either way.
src/agent.ts
Outdated
@@ -104,6 +106,7 @@ export async function createAgent() { | |||
res.status(200).send('Ok') | |||
}) | |||
|
|||
// eslint-disable-next-line @typescript-eslint/no-misused-promises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use eslint
src/config.ts
Outdated
import dotenv from 'dotenv'; | ||
import nconf from 'nconf'; | ||
import path from 'path'; | ||
// import { fileURLToPath } from 'url'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the commented code?
src/index.ts
Outdated
|
||
console.log(`AGENT_PORT: ${config.get('agent:port')}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the console logs? It should only log if the logger is enabled
src/storage/StorageMessageQueue.ts
Outdated
import type { MessageRepository } from './MessageRepository' | ||
import { MessageRepository } from './MessageRepository' | ||
import { PushNotificationsFcmRepository } from '../push-notifications/fcm/repository' | ||
import fetch from 'node-fetch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for node fetch
src/storage/StorageMessageQueue.ts
Outdated
@@ -137,8 +144,9 @@ export class StorageServiceMessageQueue implements MessagePickupRepository { | |||
private async processNotification(message: NotificationMessage) { | |||
try { | |||
const body = { | |||
fcmToken: message.token, | |||
fcmToken: message.token || 'abc', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
src/storage/StorageMessageQueue.ts
Outdated
messageType: message.messageType, | ||
clientCode: message.clientCode || '5b4d6bc6-362e-4f53-bdad-ee2742bc0de3', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
src/storage/StorageMessageQueue.ts
Outdated
token: pushNotificationFcmRecord?.deviceToken || '', | ||
clientCode: pushNotificationFcmRecord?.clientCode || '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
token: pushNotificationFcmRecord?.deviceToken || '', | |
clientCode: pushNotificationFcmRecord?.clientCode || '', | |
token: pushNotificationFcmRecord?.deviceToken, | |
clientCode: pushNotificationFcmRecord?.clientCode, |
src/config.ts
Outdated
// nconf.defaults({}); | ||
|
||
if (env === 'development') { | ||
console.log('Configuration:', nconf.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Console.log
@jleach You can remove the |
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
Signed-off-by: Jason C. Leach <[email protected]>
@TimoGlastra For sure. That was just a draft for early feedback. I wen't through and diffed the two repos. Looks like #34 was caused by some This PR is mostly the
The up-side to {
"db": {
"host": "foo.example.ca",
...
},
"agent": {
"port": 8888,
...
},
"wallet": {
"name": "my-cool-wallet",
...
}
} Also, I couldn't find the option
|
Signed-off-by: Jason C. Leach <[email protected]>
22bff80
to
f7803d1
Compare
Signed-off-by: Jason C. Leach <[email protected]>
This is the env feature in node 20.6+ https://dev.to/usulpro/nodejs-a-guide-to-native-env-support-and-local-development-300g Edit: seems it only works if you can node and register ts-node: TypeStrong/ts-node#2058 (comment) |
Re the biome rule, somehow it doesn't recognize the service is being used for dependency injection. It shouldn't be type import there. Disabling the rule makes sense for now |
@@ -18,7 +18,7 @@ | |||
"test": "jest", | |||
"build": "tsc -p tsconfig.build.json", | |||
"prepublishOnly": "pnpm build", | |||
"dev": "ts-node --env-file=.env.development --env-file .env.local dev", | |||
"dev": "ts-node src/index.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jleach Do you want to add the config related changes to dev.ts
as well ? As it helps if we want to run locally using ngrok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need dev.ts
any more. Just change the AGENT_ENDPOINTS='https://mediator.example.ca,wss://mediator.example.ca'
in your .env
file and pnpm dev
and you're good to go. To me there shouldn't me any more of a change between dev and test. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dev script connected to ngrok and changed the urls. Now you have to run it manually in another terminal and set the env variables.
It's ok, but does require more setup work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimoGlastra I don't mind. I can create create a pnpm dev:standalone
or something for ppl that don't use ngrok. Will create a new ticket for tracking since I merged this one already.
This PR makes the following changes:
type
. I've removed all the ones causing problems and left the others.dotenv
support: I added support fordotenv
so that developers can use environment variables in development environments. In production, the library will load fromprocess.env.*
.