-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(medusa,workflows) Create cart workflow #4685
Conversation
🦋 Changeset detectedLatest commit: d7af8e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
1d07a6c
to
e69286b
Compare
0296e96
to
7233e2f
Compare
a70a13b
to
7fe07e9
Compare
7fe07e9
to
e06e0b9
Compare
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.
LGTM, few suggestions, I ve didn't put them all but just to give an idea of the overall suggestions
} | ||
|
||
type HandlerInputData = { | ||
cart: { |
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.
suggestion: should we just expect id, email and this handler becomes just a createOrRetrieve customer? to be mre reusable?
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 still think we should scope it, that would make it easier for the handler to accept from other handlers and for each of those to not clash. Maybe not for this, but it would be good to have a generic structure for these handlers.
We could still make it more reusable.
{
customer: {
id?: string
email?: string
}
}
context, | ||
data, | ||
}: WorkflowArguments<HandlerInputData>): Promise<AttachCustomerDetailsDTO> { | ||
const customerDTO: AttachCustomerDetailsDTO = {} |
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.
suggestion: CreateCustomerDTO?
}: WorkflowArguments<HandlerInputData>): Promise<AttachCustomerDetailsDTO> { | ||
const customerDTO: AttachCustomerDetailsDTO = {} | ||
const customerService = container.resolve("customerService") | ||
const entityManager = container.resolve("manager") |
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.
suggestion: context.manager
const customerDTO: AttachCustomerDetailsDTO = {} | ||
const customerService = container.resolve("customerService") | ||
const entityManager = container.resolve("manager") | ||
const customerId = data[Aliases.Cart].customer_id |
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.
question: do you think we should use the alias here? in theory it is more for the consumer since here we know what we have access to with the typings as well. data.cart
} | ||
|
||
type HandlerInputData = { | ||
cart: { |
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.
suggestion: should we expect cart
only with all the data such as
type HandlerInputData = {
metadata,
address,
customer,
region
}
and on the workflow you have another middleware wich takes just care of creating this object from any other objects? The idea is that this method should be reusable, so if the user already have a prepared cart object with all the required data, he shouldn't have to then split those data in different objects right?
} | ||
|
||
type HandlerInputData = { | ||
cart: { |
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.
suggestion: could we just expect region_id instead? my idea is that you can use that handler to use the region id or retrieve the default, but not necessarely in the context of a cart only, wdyt?
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 think it is about the same suggestion I will have for every handler, except attach-(sales-channel/region) which looks more like a preparation and does attach the data to the cart but in fact retrieve the data. I think you should have preparation middleware instead of handlers wdyt?
} | ||
|
||
type HandlerInputData = { | ||
createdCart: { |
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.
suggestion: should we just expect a cart: { id }
instead?
// thought: if an error occurs on the invoke level, it'll stop the invoke flow | ||
// and begin the compensation flow. If another error shows up on the compensate level, | ||
// it doesn't make sense to throw that error since the user won't be able to do anything about it. | ||
// In these cases, we probably need to silently issue a notification to the developers that this has happened. |
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 can remove this comment. This will likely be handled at a centralized place like the Workflow manager listening to Transaction Orchestrator events to handle what has failed.
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.
But feel free to change that on the exportWorkflow
helper to filter out errors from the compensate stage.
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.
Yes, that would be a good addition. Will remove the comment, it was just there to remind
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.
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.
LGTM, some todo's and suggestions
workflows: Workflows.CreateCart, | ||
}) | ||
|
||
if (isWorkflowEnabled && !productModuleService) { |
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.
todo: rm productModuleService and warning
) | ||
} | ||
|
||
if (productModuleService) { |
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.
todo: use the isEnabled instead
}, | ||
}, | ||
}, | ||
resultFrom: "retrieveCart", |
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.
todo: add to the workflowExport
noCompensation: true, | ||
}, | ||
{ | ||
action: CreateCartActions.attachSalesChannel, |
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.
suggestion: findSalesChannel?
noCompensation: true, | ||
}, | ||
{ | ||
action: CreateCartActions.attachRegion, |
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.
suggestion: same as previous
|
||
export async function findOrCreateAddresses({ | ||
container, | ||
context, |
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.
suggestion: rm context
}: WorkflowArguments<HandlerInputData>): Promise<CustomerDTO> { | ||
const customerDTO: CustomerDTO = {} | ||
const customerService = container.resolve("customerService") | ||
const entityManager = container.resolve("manager") |
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.
todo: from context
data, | ||
}: WorkflowArguments<HandlerInputData>): Promise<void> { | ||
const cartService = container.resolve("cartService") | ||
const entityManager = container.resolve("manager") |
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.
todo: from context
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.
LGTLM with one todo
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.
lgtm! 🚢
What:
RESOLVES CORE-1461