feat(core-flows): Emit cart trasnferred customer (#12425)

**What**
When a cart is transferred emit an event notifying of the action with the cart id and the customer id
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2025-05-11 15:17:19 +00:00
1 parent 47700899ed
commit fff285f8d2
3 files changed
+92 -64

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"@medusajs/core-flows": patch
"@medusajs/utils": patch
---
feat(core-flows): Emit cart trasnferred customer
@@ -6,9 +6,10 @@ import {
WorkflowData, WorkflowData,
WorkflowResponse, WorkflowResponse,
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "../../common" import { emitEventStep, useQueryGraphStep } from "../../common"
import { updateCartsStep } from "../steps" import { updateCartsStep } from "../steps"
import { refreshCartItemsWorkflow } from "./refresh-cart-items" import { refreshCartItemsWorkflow } from "./refresh-cart-items"
import { CartWorkflowEvents } from "@medusajs/framework/utils"
/** /**
* The cart ownership transfer details. * The cart ownership transfer details.
@@ -110,6 +111,14 @@ export const transferCartCustomerWorkflow = createWorkflow(
refreshCartItemsWorkflow.runAsStep({ refreshCartItemsWorkflow.runAsStep({
input: { cart_id: input.id, force_refresh: true }, input: { cart_id: input.id, force_refresh: true },
}) })
emitEventStep({
eventName: CartWorkflowEvents.CUSTOMER_TRANSFERRED,
data: {
id: input.id,
customer_id: customer.customer_id,
},
})
} }
) )
+76 -63
View File
@@ -5,7 +5,7 @@
export const CartWorkflowEvents = { export const CartWorkflowEvents = {
/** /**
* Emitted when a cart is created. * Emitted when a cart is created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -16,7 +16,7 @@ export const CartWorkflowEvents = {
CREATED: "cart.created", CREATED: "cart.created",
/** /**
* Emitted when a cart's details are updated. * Emitted when a cart's details are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -27,7 +27,7 @@ export const CartWorkflowEvents = {
UPDATED: "cart.updated", UPDATED: "cart.updated",
/** /**
* Emitted when the customer in the cart is updated. * Emitted when the customer in the cart is updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -39,7 +39,7 @@ export const CartWorkflowEvents = {
/** /**
* Emitted when the cart's region is updated. This * Emitted when the cart's region is updated. This
* event is emitted alongside the `cart.updated` event. * event is emitted alongside the `cart.updated` event.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -48,6 +48,19 @@ export const CartWorkflowEvents = {
* ``` * ```
*/ */
REGION_UPDATED: "cart.region_updated", REGION_UPDATED: "cart.region_updated",
/**
* Emitted when the customer in the cart is transferred.
*
* @eventPayload
* ```ts
* {
* id, // The ID of the cart
* customer_id, // The ID of the customer
* }
* ```
*/
CUSTOMER_TRANSFERRED: "cart.customer_transferred",
} }
/** /**
@@ -57,7 +70,7 @@ export const CartWorkflowEvents = {
export const CustomerWorkflowEvents = { export const CustomerWorkflowEvents = {
/** /**
* Emitted when a customer is created. * Emitted when a customer is created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -68,7 +81,7 @@ export const CustomerWorkflowEvents = {
CREATED: "customer.created", CREATED: "customer.created",
/** /**
* Emitted when a customer is updated. * Emitted when a customer is updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -79,7 +92,7 @@ export const CustomerWorkflowEvents = {
UPDATED: "customer.updated", UPDATED: "customer.updated",
/** /**
* Emitted when a customer is deleted. * Emitted when a customer is deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -98,7 +111,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when the details of an order or draft order is updated. This * Emitted when the details of an order or draft order is updated. This
* doesn't include updates made by an edit. * doesn't include updates made by an edit.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -111,7 +124,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when an order is placed, or when a draft order is converted to an * Emitted when an order is placed, or when a draft order is converted to an
* order. * order.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -122,7 +135,7 @@ export const OrderWorkflowEvents = {
PLACED: "order.placed", PLACED: "order.placed",
/** /**
* Emitted when an order is canceld. * Emitted when an order is canceld.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -133,7 +146,7 @@ export const OrderWorkflowEvents = {
CANCELED: "order.canceled", CANCELED: "order.canceled",
/** /**
* Emitted when orders are completed. * Emitted when orders are completed.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -144,7 +157,7 @@ export const OrderWorkflowEvents = {
COMPLETED: "order.completed", COMPLETED: "order.completed",
/** /**
* Emitted when an order is archived. * Emitted when an order is archived.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -156,7 +169,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when a fulfillment is created for an order. * Emitted when a fulfillment is created for an order.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -169,7 +182,7 @@ export const OrderWorkflowEvents = {
FULFILLMENT_CREATED: "order.fulfillment_created", FULFILLMENT_CREATED: "order.fulfillment_created",
/** /**
* Emitted when an order's fulfillment is canceled. * Emitted when an order's fulfillment is canceled.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -183,7 +196,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when a return request is confirmed. * Emitted when a return request is confirmed.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -195,7 +208,7 @@ export const OrderWorkflowEvents = {
RETURN_REQUESTED: "order.return_requested", RETURN_REQUESTED: "order.return_requested",
/** /**
* Emitted when a return is marked as received. * Emitted when a return is marked as received.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -208,7 +221,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when a claim is created for an order. * Emitted when a claim is created for an order.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -220,7 +233,7 @@ export const OrderWorkflowEvents = {
CLAIM_CREATED: "order.claim_created", CLAIM_CREATED: "order.claim_created",
/** /**
* Emitted when an exchange is created for an order. * Emitted when an exchange is created for an order.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -234,7 +247,7 @@ export const OrderWorkflowEvents = {
/** /**
* Emitted when an order is requested to be transferred to * Emitted when an order is requested to be transferred to
* another customer. * another customer.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -253,9 +266,9 @@ export const OrderWorkflowEvents = {
export const OrderEditWorkflowEvents = { export const OrderEditWorkflowEvents = {
/** /**
* Emitted when an order edit is requested. * Emitted when an order edit is requested.
* *
* @version 2.8.0 * @version 2.8.0
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -267,9 +280,9 @@ export const OrderEditWorkflowEvents = {
REQUESTED: "order-edit.requested", REQUESTED: "order-edit.requested",
/** /**
* Emitted when an order edit request is confirmed. * Emitted when an order edit request is confirmed.
* *
* @version 2.8.0 * @version 2.8.0
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -281,9 +294,9 @@ export const OrderEditWorkflowEvents = {
CONFIRMED: "order-edit.confirmed", CONFIRMED: "order-edit.confirmed",
/** /**
* Emitted when an order edit request is canceled. * Emitted when an order edit request is canceled.
* *
* @version 2.8.0 * @version 2.8.0
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -302,7 +315,7 @@ export const OrderEditWorkflowEvents = {
export const UserWorkflowEvents = { export const UserWorkflowEvents = {
/** /**
* Emitted when users are created. * Emitted when users are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -313,7 +326,7 @@ export const UserWorkflowEvents = {
CREATED: "user.created", CREATED: "user.created",
/** /**
* Emitted when users are updated. * Emitted when users are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -324,7 +337,7 @@ export const UserWorkflowEvents = {
UPDATED: "user.updated", UPDATED: "user.updated",
/** /**
* Emitted when users are deleted. * Emitted when users are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -343,7 +356,7 @@ export const AuthWorkflowEvents = {
/** /**
* Emitted when a reset password token is generated. You can listen to this event * Emitted when a reset password token is generated. You can listen to this event
* to send a reset password email to the user or customer, for example. * to send a reset password email to the user or customer, for example.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -363,7 +376,7 @@ export const AuthWorkflowEvents = {
export const SalesChannelWorkflowEvents = { export const SalesChannelWorkflowEvents = {
/** /**
* Emitted when sales channels are created. * Emitted when sales channels are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -374,7 +387,7 @@ export const SalesChannelWorkflowEvents = {
CREATED: "sales-channel.created", CREATED: "sales-channel.created",
/** /**
* Emitted when sales channels are updated. * Emitted when sales channels are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -385,7 +398,7 @@ export const SalesChannelWorkflowEvents = {
UPDATED: "sales-channel.updated", UPDATED: "sales-channel.updated",
/** /**
* Emitted when sales channels are deleted. * Emitted when sales channels are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -403,7 +416,7 @@ export const SalesChannelWorkflowEvents = {
export const ProductCategoryWorkflowEvents = { export const ProductCategoryWorkflowEvents = {
/** /**
* Emitted when product categories are created. * Emitted when product categories are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -414,7 +427,7 @@ export const ProductCategoryWorkflowEvents = {
CREATED: "product-category.created", CREATED: "product-category.created",
/** /**
* Emitted when product categories are updated. * Emitted when product categories are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -425,7 +438,7 @@ export const ProductCategoryWorkflowEvents = {
UPDATED: "product-category.updated", UPDATED: "product-category.updated",
/** /**
* Emitted when product categories are deleted. * Emitted when product categories are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -443,7 +456,7 @@ export const ProductCategoryWorkflowEvents = {
export const ProductCollectionWorkflowEvents = { export const ProductCollectionWorkflowEvents = {
/** /**
* Emitted when product collections are created. * Emitted when product collections are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -454,7 +467,7 @@ export const ProductCollectionWorkflowEvents = {
CREATED: "product-collection.created", CREATED: "product-collection.created",
/** /**
* Emitted when product collections are updated. * Emitted when product collections are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -465,7 +478,7 @@ export const ProductCollectionWorkflowEvents = {
UPDATED: "product-collection.updated", UPDATED: "product-collection.updated",
/** /**
* Emitted when product collections are deleted. * Emitted when product collections are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -483,7 +496,7 @@ export const ProductCollectionWorkflowEvents = {
export const ProductVariantWorkflowEvents = { export const ProductVariantWorkflowEvents = {
/** /**
* Emitted when product variants are updated. * Emitted when product variants are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -494,7 +507,7 @@ export const ProductVariantWorkflowEvents = {
UPDATED: "product-variant.updated", UPDATED: "product-variant.updated",
/** /**
* Emitted when product variants are created. * Emitted when product variants are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -505,7 +518,7 @@ export const ProductVariantWorkflowEvents = {
CREATED: "product-variant.created", CREATED: "product-variant.created",
/** /**
* Emitted when product variants are deleted. * Emitted when product variants are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -523,7 +536,7 @@ export const ProductVariantWorkflowEvents = {
export const ProductWorkflowEvents = { export const ProductWorkflowEvents = {
/** /**
* Emitted when products are updated. * Emitted when products are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -534,7 +547,7 @@ export const ProductWorkflowEvents = {
UPDATED: "product.updated", UPDATED: "product.updated",
/** /**
* Emitted when products are created. * Emitted when products are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -545,7 +558,7 @@ export const ProductWorkflowEvents = {
CREATED: "product.created", CREATED: "product.created",
/** /**
* Emitted when products are deleted. * Emitted when products are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -563,7 +576,7 @@ export const ProductWorkflowEvents = {
export const ProductTypeWorkflowEvents = { export const ProductTypeWorkflowEvents = {
/** /**
* Emitted when product types are updated. * Emitted when product types are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -574,7 +587,7 @@ export const ProductTypeWorkflowEvents = {
UPDATED: "product-type.updated", UPDATED: "product-type.updated",
/** /**
* Emitted when product types are created. * Emitted when product types are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -585,7 +598,7 @@ export const ProductTypeWorkflowEvents = {
CREATED: "product-type.created", CREATED: "product-type.created",
/** /**
* Emitted when product types are deleted. * Emitted when product types are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -603,7 +616,7 @@ export const ProductTypeWorkflowEvents = {
export const ProductTagWorkflowEvents = { export const ProductTagWorkflowEvents = {
/** /**
* Emitted when product tags are updated. * Emitted when product tags are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -614,7 +627,7 @@ export const ProductTagWorkflowEvents = {
UPDATED: "product-tag.updated", UPDATED: "product-tag.updated",
/** /**
* Emitted when product tags are created. * Emitted when product tags are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -625,7 +638,7 @@ export const ProductTagWorkflowEvents = {
CREATED: "product-tag.created", CREATED: "product-tag.created",
/** /**
* Emitted when product tags are deleted. * Emitted when product tags are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -643,7 +656,7 @@ export const ProductTagWorkflowEvents = {
export const ProductOptionWorkflowEvents = { export const ProductOptionWorkflowEvents = {
/** /**
* Emitted when product options are updated. * Emitted when product options are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -654,7 +667,7 @@ export const ProductOptionWorkflowEvents = {
UPDATED: "product-option.updated", UPDATED: "product-option.updated",
/** /**
* Emitted when product options are created. * Emitted when product options are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -665,7 +678,7 @@ export const ProductOptionWorkflowEvents = {
CREATED: "product-option.created", CREATED: "product-option.created",
/** /**
* Emitted when product options are deleted. * Emitted when product options are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -683,7 +696,7 @@ export const ProductOptionWorkflowEvents = {
export const InviteWorkflowEvents = { export const InviteWorkflowEvents = {
/** /**
* Emitted when an invite is accepted. * Emitted when an invite is accepted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -695,7 +708,7 @@ export const InviteWorkflowEvents = {
/** /**
* Emitted when invites are created. You can listen to this event * Emitted when invites are created. You can listen to this event
* to send an email to the invited users, for example. * to send an email to the invited users, for example.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -706,7 +719,7 @@ export const InviteWorkflowEvents = {
CREATED: "invite.created", CREATED: "invite.created",
/** /**
* Emitted when invites are deleted. * Emitted when invites are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -719,7 +732,7 @@ export const InviteWorkflowEvents = {
* Emitted when invites should be resent because their token was * Emitted when invites should be resent because their token was
* refreshed. You can listen to this event to send an email to the invited users, * refreshed. You can listen to this event to send an email to the invited users,
* for example. * for example.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -737,7 +750,7 @@ export const InviteWorkflowEvents = {
export const RegionWorkflowEvents = { export const RegionWorkflowEvents = {
/** /**
* Emitted when regions are updated. * Emitted when regions are updated.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -748,7 +761,7 @@ export const RegionWorkflowEvents = {
UPDATED: "region.updated", UPDATED: "region.updated",
/** /**
* Emitted when regions are created. * Emitted when regions are created.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -759,7 +772,7 @@ export const RegionWorkflowEvents = {
CREATED: "region.created", CREATED: "region.created",
/** /**
* Emitted when regions are deleted. * Emitted when regions are deleted.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* [{ * [{
@@ -777,7 +790,7 @@ export const RegionWorkflowEvents = {
export const FulfillmentWorkflowEvents = { export const FulfillmentWorkflowEvents = {
/** /**
* Emitted when a shipment is created for an order. * Emitted when a shipment is created for an order.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -789,7 +802,7 @@ export const FulfillmentWorkflowEvents = {
SHIPMENT_CREATED: "shipment.created", SHIPMENT_CREATED: "shipment.created",
/** /**
* Emitted when a fulfillment is marked as delivered. * Emitted when a fulfillment is marked as delivered.
* *
* @eventPayload * @eventPayload
* ```ts * ```ts
* { * {
@@ -798,4 +811,4 @@ export const FulfillmentWorkflowEvents = {
* ``` * ```
*/ */
DELIVERY_CREATED: "delivery.created", DELIVERY_CREATED: "delivery.created",
} }