I am trying to extends the existing stripe payment provider with custom logic to handle transfers through stripe connect for a marketplace.
To achieve this, I need to run a workflow that splits an order to different vendors and creates stripe payments for each of them. This requires the usage of workflows from within the payment provider service.
So when I am trying to use this.container_.resolve(ContainerRegistrationKeys.LOGGER), it crashes saying
AwilixResolutionError: Could not resolve 'resolve'
But if I do this.container_.logger even though typescript complains that MedusaContainer has no such field, I can execute this code (checked through debugging line by line).
That is because the overriding resolve method looks at the registered keys inside the MedusaContainer but if I try to use the Proxy as is, I would call MedusaContainer methods and they are not registered to this overwritten resolve method.
I could just use .logger in this instance, but I need the container down the line in a couple of workflows, and then they fail because of the same issue.
Expected behavior
this.container_.resolve(ContainerRegistrationKeys.LOGGER) should resolve into a valid instance of the logger module service.
Actual behavior
The execution crashes with the error:
AwilixResolutionError: Could not resolve 'resolve'
Thank you for reporting this issue, I have created a PR that fix the type of the container. on the other hand, we are not allowing executing a workflow from withing a service. You might need to move your logic to a separate place (a workflow for example)
Package.json file
Node.js version
v22.11.0
Database and its version
PostgreSQL 16.2
Operating system name and version
MacOS Sonoma 14.6.1
Browser name
No response
What happended?
I am trying to extends the existing stripe payment provider with custom logic to handle transfers through stripe connect for a marketplace.
To achieve this, I need to run a workflow that splits an order to different vendors and creates stripe payments for each of them. This requires the usage of workflows from within the payment provider service.
So the payment provider gets a
MedusaContainer
injected to the constructor: https://github.com/medusajs/medusa/blob/6f7467f071119871d9c35e399f85cfd939952b5d/packages/modules/providers/payment-stripe/src/core/stripe-base.tsThe problem is that
MedusaContainer
is itself an Awilix proxy object, but it overwrites the resolve method: https://github.com/medusajs/medusa/blob/9c39cf69fb0e40cd215856189d3621320dba7ad7/packages/core/types/src/common/medusa-container.ts#L14So when I am trying to use
this.container_.resolve(ContainerRegistrationKeys.LOGGER)
, it crashes sayingBut if I do
this.container_.logger
even though typescript complains thatMedusaContainer
has no such field, I can execute this code (checked through debugging line by line).That is because the overriding resolve method looks at the registered keys inside the
MedusaContainer
but if I try to use the Proxy as is, I would callMedusaContainer
methods and they are not registered to this overwritten resolve method.I could just use .logger in this instance, but I need the container down the line in a couple of workflows, and then they fail because of the same issue.
Expected behavior
this.container_.resolve(ContainerRegistrationKeys.LOGGER)
should resolve into a valid instance of the logger module service.Actual behavior
The execution crashes with the error:
Link to reproduction repo
https://github.com/damianr13/medusa-broken-container-example