Skip to content
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

Merged
merged 40 commits into from
Aug 8, 2023
Merged

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Aug 3, 2023

What:

  • Adds a cart workflow and injects it into medusa route

RESOLVES CORE-1461

@changeset-bot
Copy link

changeset-bot bot commented Aug 3, 2023

🦋 Changeset detected

Latest commit: d7af8e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@medusajs/workflows Patch
@medusajs/medusa Patch
@medusajs/types Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch

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

@vercel
Copy link

vercel bot commented Aug 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Aug 8, 2023 9:36am

@riqwan riqwan force-pushed the feat/create-cart-workflow branch from 1d07a6c to e69286b Compare August 3, 2023 08:54
@riqwan riqwan force-pushed the feat/create-cart-workflow branch from 0296e96 to 7233e2f Compare August 3, 2023 15:12
@riqwan riqwan force-pushed the feat/create-cart-workflow branch from a70a13b to 7fe07e9 Compare August 4, 2023 12:54
@riqwan riqwan force-pushed the feat/create-cart-workflow branch from 7fe07e9 to e06e0b9 Compare August 4, 2023 12:57
@riqwan riqwan changed the title [WIP] Create cart workflow feat(medusa,workflows) Create cart workflow Aug 4, 2023
@riqwan riqwan marked this pull request as ready for review August 7, 2023 08:41
@riqwan riqwan requested a review from a team as a code owner August 7, 2023 08:41
Copy link
Member

@adrien2p adrien2p left a 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: {
Copy link
Member

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?

Copy link
Contributor Author

@riqwan riqwan Aug 7, 2023

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 = {}
Copy link
Member

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")
Copy link
Member

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
Copy link
Member

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: {
Copy link
Member

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: {
Copy link
Member

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?

Copy link
Member

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: {
Copy link
Member

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?

Comment on lines 124 to 127
// 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.
Copy link
Contributor

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.

Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues Aug 7, 2023

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@adrien2p adrien2p left a 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) {
Copy link
Member

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) {
Copy link
Member

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",
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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")
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

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

todo: from context

Copy link
Member

@adrien2p adrien2p left a 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

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

lgtm! 🚢

@riqwan riqwan merged commit 281b074 into develop Aug 8, 2023
@github-actions github-actions bot mentioned this pull request Aug 8, 2023
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.

4 participants