feat(core-flows,utils): Shipping options workflow events emission (#14388)
* Shipping options workflow events type * Emit shipping options workflow events * add changeset
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(core-flows,utils): Shipping options workflow events emission
|
||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
import { setShippingOptionsPriceSetsStep } from "../steps/set-shipping-options-price-sets"
|
import { setShippingOptionsPriceSetsStep } from "../steps/set-shipping-options-price-sets"
|
||||||
import { validateFulfillmentProvidersStep } from "../steps/validate-fulfillment-providers"
|
import { validateFulfillmentProvidersStep } from "../steps/validate-fulfillment-providers"
|
||||||
import { validateShippingOptionPricesStep } from "../steps/validate-shipping-option-prices"
|
import { validateShippingOptionPricesStep } from "../steps/validate-shipping-option-prices"
|
||||||
|
import { emitEventStep } from "../../common"
|
||||||
|
import { ShippingOptionWorkflowEvents } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data to create the shipping options.
|
* The data to create the shipping options.
|
||||||
@@ -132,6 +134,12 @@ export const createShippingOptionsWorkflow = createWorkflow(
|
|||||||
data.shippingOptions
|
data.shippingOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const eventData = transform(createdShippingOptions, (data) => {
|
||||||
|
return data.map((option) => {
|
||||||
|
return { id: option.id }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const normalizedShippingOptionsPrices = transform(
|
const normalizedShippingOptionsPrices = transform(
|
||||||
{
|
{
|
||||||
shippingOptions: createdShippingOptions,
|
shippingOptions: createdShippingOptions,
|
||||||
@@ -171,7 +179,13 @@ export const createShippingOptionsWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
setShippingOptionsPriceSetsStep(normalizedLinkData)
|
parallelize(
|
||||||
|
setShippingOptionsPriceSetsStep(normalizedLinkData),
|
||||||
|
emitEventStep({
|
||||||
|
eventName: ShippingOptionWorkflowEvents.CREATED,
|
||||||
|
data: eventData,
|
||||||
|
})
|
||||||
|
)
|
||||||
return new WorkflowResponse(createdShippingOptions)
|
return new WorkflowResponse(createdShippingOptions)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||||
import { createWorkflow, WorkflowData } from "@medusajs/framework/workflows-sdk"
|
import {
|
||||||
|
createWorkflow,
|
||||||
|
parallelize,
|
||||||
|
WorkflowData,
|
||||||
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { deleteShippingOptionsStep } from "../steps"
|
import { deleteShippingOptionsStep } from "../steps"
|
||||||
import { removeRemoteLinkStep } from "../../common"
|
import { emitEventStep, removeRemoteLinkStep } from "../../common"
|
||||||
|
import { ShippingOptionWorkflowEvents } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
export const deleteShippingOptionsWorkflowId =
|
export const deleteShippingOptionsWorkflowId =
|
||||||
"delete-shipping-options-workflow"
|
"delete-shipping-options-workflow"
|
||||||
@@ -31,6 +36,12 @@ export const deleteShippingOptionsWorkflow = createWorkflow(
|
|||||||
) => {
|
) => {
|
||||||
const softDeletedEntities = deleteShippingOptionsStep(input.ids)
|
const softDeletedEntities = deleteShippingOptionsStep(input.ids)
|
||||||
|
|
||||||
removeRemoteLinkStep(softDeletedEntities)
|
parallelize(
|
||||||
|
removeRemoteLinkStep(softDeletedEntities),
|
||||||
|
emitEventStep({
|
||||||
|
eventName: ShippingOptionWorkflowEvents.DELETED,
|
||||||
|
data: input.ids,
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ import {
|
|||||||
} from "../steps"
|
} from "../steps"
|
||||||
import { validateFulfillmentProvidersStep } from "../steps/validate-fulfillment-providers"
|
import { validateFulfillmentProvidersStep } from "../steps/validate-fulfillment-providers"
|
||||||
import { validateShippingOptionPricesStep } from "../steps/validate-shipping-option-prices"
|
import { validateShippingOptionPricesStep } from "../steps/validate-shipping-option-prices"
|
||||||
import { ShippingOptionPriceType } from "@medusajs/framework/utils"
|
import {
|
||||||
|
ShippingOptionPriceType,
|
||||||
|
ShippingOptionWorkflowEvents,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
import { emitEventStep } from "../../common"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data to update the shipping options.
|
* The data to update the shipping options.
|
||||||
@@ -92,6 +96,10 @@ export const updateShippingOptionsWorkflow = createWorkflow(
|
|||||||
data.shippingOptions
|
data.shippingOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const eventData = transform(updatedShippingOptions, (data) => {
|
||||||
|
return data.map((option) => option.id)
|
||||||
|
})
|
||||||
|
|
||||||
const normalizedShippingOptionsPrices = transform(
|
const normalizedShippingOptionsPrices = transform(
|
||||||
{
|
{
|
||||||
shippingOptions: updatedShippingOptions,
|
shippingOptions: updatedShippingOptions,
|
||||||
@@ -115,8 +123,14 @@ export const updateShippingOptionsWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
setShippingOptionsPricesStep(
|
parallelize(
|
||||||
normalizedShippingOptionsPrices.shippingOptionsPrices
|
setShippingOptionsPricesStep(
|
||||||
|
normalizedShippingOptionsPrices.shippingOptionsPrices
|
||||||
|
),
|
||||||
|
emitEventStep({
|
||||||
|
eventName: ShippingOptionWorkflowEvents.UPDATED,
|
||||||
|
data: eventData,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
return new WorkflowResponse(updatedShippingOptions)
|
return new WorkflowResponse(updatedShippingOptions)
|
||||||
|
|||||||
@@ -861,6 +861,46 @@ export const ShippingOptionTypeWorkflowEvents = {
|
|||||||
DELETED: "shipping-option-type.deleted",
|
DELETED: "shipping-option-type.deleted",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Shipping Option
|
||||||
|
* @customNamespace Fulfillment
|
||||||
|
*/
|
||||||
|
export const ShippingOptionWorkflowEvents = {
|
||||||
|
/**
|
||||||
|
* Emitted when shipping options are created.
|
||||||
|
*
|
||||||
|
* @eventPayload
|
||||||
|
* ```ts
|
||||||
|
* {
|
||||||
|
* id, // The ID of the shipping option
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
CREATED: "shipping-option.created",
|
||||||
|
/**
|
||||||
|
* Emitted when shipping options are updated.
|
||||||
|
*
|
||||||
|
* @eventPayload
|
||||||
|
* ```ts
|
||||||
|
* {
|
||||||
|
* id, // The ID of the shipping option
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
UPDATED: "shipping-option.updated",
|
||||||
|
/**
|
||||||
|
* Emitted when shipping options are deleted.
|
||||||
|
*
|
||||||
|
* @eventPayload
|
||||||
|
* ```ts
|
||||||
|
* {
|
||||||
|
* id, // The ID of the shipping option
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
DELETED: "shipping-option.deleted",
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category Payment
|
* @category Payment
|
||||||
* @customNamespace Payment
|
* @customNamespace Payment
|
||||||
|
|||||||
Reference in New Issue
Block a user