Skip to content

Conversation

@JoelFickson
Copy link
Contributor

@JoelFickson JoelFickson commented Feb 13, 2025

This pull request includes several changes to the processor package to enhance environment variable management, update dependencies, and refactor code for better maintainability. The most important changes include replacing dotenv with @fastify/env, updating the IngridApiClient constructor, and removing the config module.

Environment Variable Management:

  • Replaced dotenv with @fastify/env for loading environment variables and added a new Env.ts file to configure environment variables using a schema. (processor/package-lock.json [1] [2] [3] [4] processor/package.json [5] processor/src/server/Env.ts [6]

Dependency Updates:

  • Added @fastify/env and removed dotenv from the dependencies. (processor/package-lock.json [1] [2] processor/package.json [3]

Code Refactoring:

  • Refactored the IngridApiClient to use a new IngridClientOptions type for the constructor parameters and updated the createClient function accordingly. (processor/src/clients/ingrid/ingrid.client.ts [1] [2] [3] [4] processor/src/clients/ingrid/types/ingrid.client.type.ts [5]
  • Removed the config module and updated all references to use environment variables directly. (processor/src/config/index.ts [1] processor/src/libs/logger/index.ts [2] [3] processor/src/main.ts [4] processor/src/server/plugins/ingrid-shipping.plugin.ts [5] [6] processor/src/server/server.ts [7] [8]

@JoelFickson JoelFickson self-assigned this Feb 13, 2025
@JoelFickson JoelFickson requested a review from a team as a code owner February 13, 2025 12:11
@JoelFickson JoelFickson requested review from harm-meijer and prateek-ct and removed request for a team February 13, 2025 12:11
Copy link

@dario-commercetools dario-commercetools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if removing dotenv and using fastify.env add more/less complexity for testing.

I'm not sure what the rest of the team think about removing dotenv. has it been discussed and I just missed the meeting?

I like this change! 🎉

@leungkinghin-ct
Copy link
Collaborator

leungkinghin-ct commented Feb 14, 2025

I wonder if removing dotenv and using fastify.env add more/less complexity for testing.

I'm not sure what the rest of the team think about removing dotenv. has it been discussed and I just missed the meeting?

I like this change! 🎉

i would say so far so good.
We maintain dummy variables in our testing and not relying on config.ts, so it brings no impact to unit test when we use fastify.env
https://github.com/commercetools/connect-shipping-integration-ingrid/blob/main/processor/test/services/ingrid-shipping.service.spec.ts#L22

Copy link
Collaborator

@leungkinghin-ct leungkinghin-ct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JoelFickson. I almost forgot one thing.
We have post-deploy script and pre-undeploy script, which makes use of env-var and also are executed once after deployment / before undeployment. Therefore they are outside Fastify scope. I guess we still have to keep dotenv in our package.json for this purpose, or at least move dotenv to devDependencies.

@JoelFickson
Copy link
Contributor Author

Sorry @JoelFickson. I almost forgot one thing. We have post-deploy script and pre-undeploy script, which makes use of env-var and also are executed once after deployment / before undeployment. Therefore they are outside Fastify scope. I guess we still have to keep dotenv in our package.json for this purpose, or at least move dotenv to devDependencies.

I think there should be a way to do a pre and post deploy env var binding with fastify/env. I will take a look and if I cant find a work around I will revert the dotenv package

# Conflicts:
#	processor/src/clients/ingrid/ingrid.client.ts
#	processor/src/clients/ingrid/types/ingrid.client.type.ts
#	processor/src/config/index.ts
#	processor/src/server/plugins/ingrid-shipping.plugin.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants