chore(core-flows): [3] export types and types, add basic TSDocs (#8507)
This PR exports types and steps from the core-flows package, and adds simple TSDocs for workflows / steps. This is essential for the workflows reference. PR 3/n
This commit is contained in:
1 parent
9ea0783494
commit
1bb4e764d1
26 files changed
+135
-50
No files matched your search
@@ -3,6 +3,9 @@ import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
|||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
export const findOneOrAnyRegionStepId = "find-one-or-any-region"
|
export const findOneOrAnyRegionStepId = "find-one-or-any-region"
|
||||||
|
/**
|
||||||
|
* This step retrieves a region either by the provided ID or the first region in the first store.
|
||||||
|
*/
|
||||||
export const findOneOrAnyRegionStep = createStep(
|
export const findOneOrAnyRegionStep = createStep(
|
||||||
findOneOrAnyRegionStepId,
|
findOneOrAnyRegionStepId,
|
||||||
async (data: { regionId?: string }, { container }) => {
|
async (data: { regionId?: string }, { container }) => {
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import { CustomerDTO, ICustomerModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName, validateEmail } from "@medusajs/utils"
|
import { ModuleRegistrationName, validateEmail } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface FindOrCreateCustomerStepInput {
|
||||||
customerId?: string | null
|
customerId?: string | null
|
||||||
email?: string | null
|
email?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StepOutput {
|
export interface FindOrCreateCustomerOutputStepOutput {
|
||||||
customer?: CustomerDTO | null
|
customer?: CustomerDTO | null
|
||||||
email?: string | null
|
email?: string | null
|
||||||
}
|
}
|
||||||
@@ -18,9 +18,13 @@ interface StepCompensateInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const findOrCreateCustomerStepId = "find-or-create-customer"
|
export const findOrCreateCustomerStepId = "find-or-create-customer"
|
||||||
|
/**
|
||||||
|
* This step either finds a customer matching the specified ID, or finds / create a customer
|
||||||
|
* matching the specified email. If both ID and email are provided, ID takes precedence.
|
||||||
|
*/
|
||||||
export const findOrCreateCustomerStep = createStep(
|
export const findOrCreateCustomerStep = createStep(
|
||||||
findOrCreateCustomerStepId,
|
findOrCreateCustomerStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: FindOrCreateCustomerStepInput, { container }) => {
|
||||||
if (
|
if (
|
||||||
typeof data.customerId === undefined &&
|
typeof data.customerId === undefined &&
|
||||||
typeof data.email === undefined
|
typeof data.email === undefined
|
||||||
@@ -38,7 +42,7 @@ export const findOrCreateCustomerStep = createStep(
|
|||||||
ModuleRegistrationName.CUSTOMER
|
ModuleRegistrationName.CUSTOMER
|
||||||
)
|
)
|
||||||
|
|
||||||
const customerData: StepOutput = {
|
const customerData: FindOrCreateCustomerOutputStepOutput = {
|
||||||
customer: null,
|
customer: null,
|
||||||
email: null,
|
email: null,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,18 @@ import {
|
|||||||
import { MedusaError, ModuleRegistrationName, isDefined } from "@medusajs/utils"
|
import { MedusaError, ModuleRegistrationName, isDefined } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface FindSalesChannelStepInput {
|
||||||
salesChannelId?: string | null
|
salesChannelId?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findSalesChannelStepId = "find-sales-channel"
|
export const findSalesChannelStepId = "find-sales-channel"
|
||||||
|
/**
|
||||||
|
* This step either retrieves a sales channel either using the ID provided as an input, or, if no ID
|
||||||
|
* is provided, the default sales channel of the first store.
|
||||||
|
*/
|
||||||
export const findSalesChannelStep = createStep(
|
export const findSalesChannelStep = createStep(
|
||||||
findSalesChannelStepId,
|
findSalesChannelStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: FindSalesChannelStepInput, { container }) => {
|
||||||
const salesChannelService = container.resolve<ISalesChannelModuleService>(
|
const salesChannelService = container.resolve<ISalesChannelModuleService>(
|
||||||
ModuleRegistrationName.SALES_CHANNEL
|
ModuleRegistrationName.SALES_CHANNEL
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-2
@@ -2,16 +2,20 @@ import { CartDTO, IPromotionModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetActionsToComputeFromPromotionsStepInput {
|
||||||
cart: CartDTO
|
cart: CartDTO
|
||||||
promotionCodesToApply: string[]
|
promotionCodesToApply: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getActionsToComputeFromPromotionsStepId =
|
export const getActionsToComputeFromPromotionsStepId =
|
||||||
"get-actions-to-compute-from-promotions"
|
"get-actions-to-compute-from-promotions"
|
||||||
|
/**
|
||||||
|
* This step retrieves the actions to compute based on the promotions
|
||||||
|
* applied on a cart.
|
||||||
|
*/
|
||||||
export const getActionsToComputeFromPromotionsStep = createStep(
|
export const getActionsToComputeFromPromotionsStep = createStep(
|
||||||
getActionsToComputeFromPromotionsStepId,
|
getActionsToComputeFromPromotionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetActionsToComputeFromPromotionsStepInput, { container }) => {
|
||||||
const { cart, promotionCodesToApply = [] } = data
|
const { cart, promotionCodesToApply = [] } = data
|
||||||
const promotionService = container.resolve<IPromotionModuleService>(
|
const promotionService = container.resolve<IPromotionModuleService>(
|
||||||
ModuleRegistrationName.PROMOTION
|
ModuleRegistrationName.PROMOTION
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetItemTaxLinesStepInput {
|
||||||
cart: CartWorkflowDTO
|
cart: CartWorkflowDTO
|
||||||
items: CartLineItemDTO[]
|
items: CartLineItemDTO[]
|
||||||
shipping_methods: CartShippingMethodDTO[]
|
shipping_methods: CartShippingMethodDTO[]
|
||||||
@@ -94,9 +94,12 @@ function normalizeLineItemsForShipping(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getItemTaxLinesStepId = "get-item-tax-lines"
|
export const getItemTaxLinesStepId = "get-item-tax-lines"
|
||||||
|
/**
|
||||||
|
* This step retrieves the tax lines of the specified line items in a cart.
|
||||||
|
*/
|
||||||
export const getItemTaxLinesStep = createStep(
|
export const getItemTaxLinesStep = createStep(
|
||||||
getItemTaxLinesStepId,
|
getItemTaxLinesStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetItemTaxLinesStepInput, { container }) => {
|
||||||
const {
|
const {
|
||||||
cart,
|
cart,
|
||||||
items,
|
items,
|
||||||
|
|||||||
@@ -12,15 +12,19 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetLineItemActionsStepInput {
|
||||||
id: string
|
id: string
|
||||||
items: CreateLineItemForCartDTO[]
|
items: CreateLineItemForCartDTO[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getLineItemActionsStepId = "get-line-item-actions-step"
|
export const getLineItemActionsStepId = "get-line-item-actions-step"
|
||||||
|
/**
|
||||||
|
* This step returns lists of cart line items to create or update based on the
|
||||||
|
* provided input.
|
||||||
|
*/
|
||||||
export const getLineItemActionsStep = createStep(
|
export const getLineItemActionsStep = createStep(
|
||||||
getLineItemActionsStepId,
|
getLineItemActionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetLineItemActionsStepInput, { container }) => {
|
||||||
const cartModule = container.resolve<ICartModuleService>(
|
const cartModule = container.resolve<ICartModuleService>(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { IPromotionModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName, PromotionActions } from "@medusajs/utils"
|
import { ModuleRegistrationName, PromotionActions } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetPromotionCodesToApplyStepInput {
|
||||||
cart: {
|
cart: {
|
||||||
items?: { adjustments?: { code?: string }[] }[]
|
items?: { adjustments?: { code?: string }[] }[]
|
||||||
shipping_methods?: { adjustments?: { code?: string }[] }[]
|
shipping_methods?: { adjustments?: { code?: string }[] }[]
|
||||||
@@ -15,9 +15,12 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getPromotionCodesToApplyId = "get-promotion-codes-to-apply"
|
export const getPromotionCodesToApplyId = "get-promotion-codes-to-apply"
|
||||||
|
/**
|
||||||
|
* This step retrieves the promotion codes to apply on a cart.
|
||||||
|
*/
|
||||||
export const getPromotionCodesToApply = createStep(
|
export const getPromotionCodesToApply = createStep(
|
||||||
getPromotionCodesToApplyId,
|
getPromotionCodesToApplyId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetPromotionCodesToApplyStepInput, { container }) => {
|
||||||
const { promo_codes = [], cart, action = PromotionActions.ADD } = data
|
const { promo_codes = [], cart, action = PromotionActions.ADD } = data
|
||||||
const { items = [], shipping_methods = [] } = cart
|
const { items = [], shipping_methods = [] } = cart
|
||||||
const adjustmentCodes: string[] = []
|
const adjustmentCodes: string[] = []
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ import { IPricingModuleService } from "@medusajs/types"
|
|||||||
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetVariantPriceSetsStepInput {
|
||||||
variantIds: string[]
|
variantIds: string[]
|
||||||
context?: Record<string, unknown>
|
context?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getVariantPriceSetsStepId = "get-variant-price-sets"
|
export const getVariantPriceSetsStepId = "get-variant-price-sets"
|
||||||
|
/**
|
||||||
|
* This step retrieves the calculated price sets of the specified variants.
|
||||||
|
*/
|
||||||
export const getVariantPriceSetsStep = createStep(
|
export const getVariantPriceSetsStep = createStep(
|
||||||
getVariantPriceSetsStepId,
|
getVariantPriceSetsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetVariantPriceSetsStepInput, { container }) => {
|
||||||
if (!data.variantIds.length) {
|
if (!data.variantIds.length) {
|
||||||
return new StepResponse({})
|
return new StepResponse({})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import {
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface GetVariantsStepInput {
|
||||||
filter?: FilterableProductVariantProps
|
filter?: FilterableProductVariantProps
|
||||||
config?: FindConfig<ProductVariantDTO>
|
config?: FindConfig<ProductVariantDTO>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getVariantsStepId = "get-variants"
|
export const getVariantsStepId = "get-variants"
|
||||||
|
/**
|
||||||
|
* This step retrieves variants matching the specified filters.
|
||||||
|
*/
|
||||||
export const getVariantsStep = createStep(
|
export const getVariantsStep = createStep(
|
||||||
getVariantsStepId,
|
getVariantsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: GetVariantsStepInput, { container }) => {
|
||||||
const productModuleService = container.resolve<IProductModuleService>(
|
const productModuleService = container.resolve<IProductModuleService>(
|
||||||
ModuleRegistrationName.PRODUCT
|
ModuleRegistrationName.PRODUCT
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-2
@@ -10,15 +10,19 @@ import {
|
|||||||
import { ComputedActions, ModuleRegistrationName } from "@medusajs/utils"
|
import { ComputedActions, ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface PrepareAdjustmentsFromPromotionActionsStepInput {
|
||||||
actions: ComputeActions[]
|
actions: ComputeActions[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const prepareAdjustmentsFromPromotionActionsStepId =
|
export const prepareAdjustmentsFromPromotionActionsStepId =
|
||||||
"prepare-adjustments-from-promotion-actions"
|
"prepare-adjustments-from-promotion-actions"
|
||||||
|
/**
|
||||||
|
* This step prepares the line item or shipping method adjustments using
|
||||||
|
* actions computed by the Promotion Module.
|
||||||
|
*/
|
||||||
export const prepareAdjustmentsFromPromotionActionsStep = createStep(
|
export const prepareAdjustmentsFromPromotionActionsStep = createStep(
|
||||||
prepareAdjustmentsFromPromotionActionsStepId,
|
prepareAdjustmentsFromPromotionActionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: PrepareAdjustmentsFromPromotionActionsStepInput, { container }) => {
|
||||||
const promotionModuleService: IPromotionModuleService = container.resolve(
|
const promotionModuleService: IPromotionModuleService = container.resolve(
|
||||||
ModuleRegistrationName.PROMOTION
|
ModuleRegistrationName.PROMOTION
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { PromotionActions } from "@medusajs/utils"
|
|||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
import { updateCartPromotionsWorkflow } from "../workflows"
|
import { updateCartPromotionsWorkflow } from "../workflows"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RefreshCartPromotionsStepInput {
|
||||||
id: string
|
id: string
|
||||||
promo_codes?: string[]
|
promo_codes?: string[]
|
||||||
action?:
|
action?:
|
||||||
@@ -12,9 +12,12 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const refreshCartPromotionsStepId = "refresh-cart-promotions"
|
export const refreshCartPromotionsStepId = "refresh-cart-promotions"
|
||||||
|
/**
|
||||||
|
* This step refreshes the promotions of a cart.
|
||||||
|
*/
|
||||||
export const refreshCartPromotionsStep = createStep(
|
export const refreshCartPromotionsStep = createStep(
|
||||||
refreshCartPromotionsStepId,
|
refreshCartPromotionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RefreshCartPromotionsStepInput, { container }) => {
|
||||||
const { promo_codes = [], id, action = PromotionActions.ADD } = data
|
const { promo_codes = [], id, action = PromotionActions.ADD } = data
|
||||||
|
|
||||||
await updateCartPromotionsWorkflow(container).run({
|
await updateCartPromotionsWorkflow(container).run({
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ import {
|
|||||||
import { ModuleRegistrationName, arrayDifference } from "@medusajs/utils"
|
import { ModuleRegistrationName, arrayDifference } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RefreshCartShippingMethodsStepInput {
|
||||||
cart: CartDTO
|
cart: CartDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
export const refreshCartShippingMethodsStepId = "refresh-cart-shipping-methods"
|
export const refreshCartShippingMethodsStepId = "refresh-cart-shipping-methods"
|
||||||
|
/**
|
||||||
|
* This step refreshes the shipping methods of a cart.
|
||||||
|
*/
|
||||||
export const refreshCartShippingMethodsStep = createStep(
|
export const refreshCartShippingMethodsStep = createStep(
|
||||||
refreshCartShippingMethodsStepId,
|
refreshCartShippingMethodsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RefreshCartShippingMethodsStepInput, { container }) => {
|
||||||
const { cart } = data
|
const { cart } = data
|
||||||
const { shipping_methods: shippingMethods = [] } = cart
|
const { shipping_methods: shippingMethods = [] } = cart
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,17 @@ import { ICartModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RemoveLineItemAdjustmentsStepInput {
|
||||||
lineItemAdjustmentIdsToRemove: string[]
|
lineItemAdjustmentIdsToRemove: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeLineItemAdjustmentsStepId = "remove-line-item-adjustments"
|
export const removeLineItemAdjustmentsStepId = "remove-line-item-adjustments"
|
||||||
|
/**
|
||||||
|
* This step removes line item adjustments from a cart.
|
||||||
|
*/
|
||||||
export const removeLineItemAdjustmentsStep = createStep(
|
export const removeLineItemAdjustmentsStep = createStep(
|
||||||
removeLineItemAdjustmentsStepId,
|
removeLineItemAdjustmentsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RemoveLineItemAdjustmentsStepInput, { container }) => {
|
||||||
const { lineItemAdjustmentIdsToRemove = [] } = data
|
const { lineItemAdjustmentIdsToRemove = [] } = data
|
||||||
const cartModuleService: ICartModuleService = container.resolve(
|
const cartModuleService: ICartModuleService = container.resolve(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
|
|||||||
+5
-2
@@ -2,15 +2,18 @@ import { ICartModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RemoveShippingMethodAdjustmentsStepInput {
|
||||||
shippingMethodAdjustmentIdsToRemove: string[]
|
shippingMethodAdjustmentIdsToRemove: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeShippingMethodAdjustmentsStepId =
|
export const removeShippingMethodAdjustmentsStepId =
|
||||||
"remove-shipping-method-adjustments"
|
"remove-shipping-method-adjustments"
|
||||||
|
/**
|
||||||
|
* This step removes shipping method adjustments from a cart.
|
||||||
|
*/
|
||||||
export const removeShippingMethodAdjustmentsStep = createStep(
|
export const removeShippingMethodAdjustmentsStep = createStep(
|
||||||
removeShippingMethodAdjustmentsStepId,
|
removeShippingMethodAdjustmentsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RemoveShippingMethodAdjustmentsStepInput, { container }) => {
|
||||||
const { shippingMethodAdjustmentIdsToRemove = [] } = data
|
const { shippingMethodAdjustmentIdsToRemove = [] } = data
|
||||||
const cartModuleService: ICartModuleService = container.resolve(
|
const cartModuleService: ICartModuleService = container.resolve(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
|
|||||||
+5
-2
@@ -2,15 +2,18 @@ import { ICartModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RemoveShippingMethodFromCartStepInput {
|
||||||
shipping_method_ids: string[]
|
shipping_method_ids: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeShippingMethodFromCartStepId =
|
export const removeShippingMethodFromCartStepId =
|
||||||
"remove-shipping-method-to-cart-step"
|
"remove-shipping-method-to-cart-step"
|
||||||
|
/**
|
||||||
|
* This step removes shipping methods from a cart.
|
||||||
|
*/
|
||||||
export const removeShippingMethodFromCartStep = createStep(
|
export const removeShippingMethodFromCartStep = createStep(
|
||||||
removeShippingMethodFromCartStepId,
|
removeShippingMethodFromCartStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RemoveShippingMethodFromCartStepInput, { container }) => {
|
||||||
const cartService = container.resolve<ICartModuleService>(
|
const cartService = container.resolve<ICartModuleService>(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { IInventoryService } from "@medusajs/types"
|
|||||||
import { MathBN, ModuleRegistrationName } from "@medusajs/utils"
|
import { MathBN, ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface ReserveVariantInventoryStepInput {
|
||||||
items: {
|
items: {
|
||||||
id?: string
|
id?: string
|
||||||
inventory_item_id: string
|
inventory_item_id: string
|
||||||
@@ -14,9 +14,13 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const reserveInventoryStepId = "reserve-inventory-step"
|
export const reserveInventoryStepId = "reserve-inventory-step"
|
||||||
|
/**
|
||||||
|
* This step reserves the quantity of line items from the associated
|
||||||
|
* variant's inventory.
|
||||||
|
*/
|
||||||
export const reserveInventoryStep = createStep(
|
export const reserveInventoryStep = createStep(
|
||||||
reserveInventoryStepId,
|
reserveInventoryStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: ReserveVariantInventoryStepInput, { container }) => {
|
||||||
const inventoryService = container.resolve<IInventoryService>(
|
const inventoryService = container.resolve<IInventoryService>(
|
||||||
ModuleRegistrationName.INVENTORY
|
ModuleRegistrationName.INVENTORY
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RetrieveCartWithLinksStepInput {
|
||||||
cart_or_cart_id: string | CartWorkflowDTO
|
cart_or_cart_id: string | CartWorkflowDTO
|
||||||
fields: string[]
|
fields: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const retrieveCartWithLinksStepId = "retrieve-cart-with-links"
|
export const retrieveCartWithLinksStepId = "retrieve-cart-with-links"
|
||||||
|
/**
|
||||||
|
* This step retrieves a cart's details with its linked records.
|
||||||
|
*/
|
||||||
export const retrieveCartWithLinksStep = createStep(
|
export const retrieveCartWithLinksStep = createStep(
|
||||||
retrieveCartWithLinksStepId,
|
retrieveCartWithLinksStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RetrieveCartWithLinksStepInput, { container }) => {
|
||||||
const { cart_or_cart_id: cartOrCartId, fields } = data
|
const { cart_or_cart_id: cartOrCartId, fields } = data
|
||||||
|
|
||||||
if (isObject(cartOrCartId)) {
|
if (isObject(cartOrCartId)) {
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ import { CartDTO, FindConfig, ICartModuleService } from "@medusajs/types"
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface RetrieveCartStepInput {
|
||||||
id: string
|
id: string
|
||||||
config?: FindConfig<CartDTO>
|
config?: FindConfig<CartDTO>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const retrieveCartStepId = "retrieve-cart"
|
export const retrieveCartStepId = "retrieve-cart"
|
||||||
|
/**
|
||||||
|
* This step retrieves a cart's details.
|
||||||
|
*/
|
||||||
export const retrieveCartStep = createStep(
|
export const retrieveCartStep = createStep(
|
||||||
retrieveCartStepId,
|
retrieveCartStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: RetrieveCartStepInput, { container }) => {
|
||||||
const cartModuleService = container.resolve<ICartModuleService>(
|
const cartModuleService = container.resolve<ICartModuleService>(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,16 +9,19 @@ import {
|
|||||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface SetTaxLinesForItemsStepInput {
|
||||||
cart: CartWorkflowDTO
|
cart: CartWorkflowDTO
|
||||||
item_tax_lines: ItemTaxLineDTO[]
|
item_tax_lines: ItemTaxLineDTO[]
|
||||||
shipping_tax_lines: ShippingTaxLineDTO[]
|
shipping_tax_lines: ShippingTaxLineDTO[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setTaxLinesForItemsStepId = "set-tax-lines-for-items"
|
export const setTaxLinesForItemsStepId = "set-tax-lines-for-items"
|
||||||
|
/**
|
||||||
|
* This step sets the tax lines of shipping methods and line items in a cart.
|
||||||
|
*/
|
||||||
export const setTaxLinesForItemsStep = createStep(
|
export const setTaxLinesForItemsStep = createStep(
|
||||||
setTaxLinesForItemsStepId,
|
setTaxLinesForItemsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: SetTaxLinesForItemsStepInput, { container }) => {
|
||||||
const { cart, item_tax_lines, shipping_tax_lines } = data
|
const { cart, item_tax_lines, shipping_tax_lines } = data
|
||||||
const cartService = container.resolve<ICartModuleService>(
|
const cartService = container.resolve<ICartModuleService>(
|
||||||
ModuleRegistrationName.CART
|
ModuleRegistrationName.CART
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface UpdateCartPromotionStepInput {
|
||||||
id: string
|
id: string
|
||||||
promo_codes?: string[]
|
promo_codes?: string[]
|
||||||
action?:
|
action?:
|
||||||
@@ -17,9 +17,12 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const updateCartPromotionsStepId = "update-cart-promotions"
|
export const updateCartPromotionsStepId = "update-cart-promotions"
|
||||||
|
/**
|
||||||
|
* This step updates the promotions applied on a cart.
|
||||||
|
*/
|
||||||
export const updateCartPromotionsStep = createStep(
|
export const updateCartPromotionsStep = createStep(
|
||||||
updateCartPromotionsStepId,
|
updateCartPromotionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: UpdateCartPromotionStepInput, { container }) => {
|
||||||
const { promo_codes = [], id, action = PromotionActions.ADD } = data
|
const { promo_codes = [], id, action = PromotionActions.ADD } = data
|
||||||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||||
const remoteQuery = container.resolve(
|
const remoteQuery = container.resolve(
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import {
|
|||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
export const updateCartsStepId = "update-carts"
|
export const updateCartsStepId = "update-carts"
|
||||||
|
/**
|
||||||
|
* This step updates a cart.
|
||||||
|
*/
|
||||||
export const updateCartsStep = createStep(
|
export const updateCartsStep = createStep(
|
||||||
updateCartsStepId,
|
updateCartsStepId,
|
||||||
async (data: UpdateCartWorkflowInputDTO[], { container }) => {
|
async (data: UpdateCartWorkflowInputDTO[], { container }) => {
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface UpdateLineItemsStepInput {
|
||||||
id: string
|
id: string
|
||||||
items: UpdateLineItemWithSelectorDTO[]
|
items: UpdateLineItemWithSelectorDTO[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateLineItemsStepId = "update-line-items-step"
|
export const updateLineItemsStepId = "update-line-items-step"
|
||||||
|
/**
|
||||||
|
* This step updates a cart's line items.
|
||||||
|
*/
|
||||||
export const updateLineItemsStep = createStep(
|
export const updateLineItemsStep = createStep(
|
||||||
updateLineItemsStepId,
|
updateLineItemsStepId,
|
||||||
async (input: StepInput, { container }) => {
|
async (input: UpdateLineItemsStepInput, { container }) => {
|
||||||
const { id, items = [] } = input
|
const { id, items = [] } = input
|
||||||
|
|
||||||
if (!items?.length) {
|
if (!items?.length) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
import { updateTaxLinesWorkflow } from "../workflows"
|
import { updateTaxLinesWorkflow } from "../workflows"
|
||||||
|
|
||||||
interface StepInput {
|
export interface UpdateTaxLinesStepInput {
|
||||||
cart_or_cart_id: CartWorkflowDTO | string
|
cart_or_cart_id: CartWorkflowDTO | string
|
||||||
items?: CartLineItemDTO[]
|
items?: CartLineItemDTO[]
|
||||||
shipping_methods?: CartShippingMethodDTO[]
|
shipping_methods?: CartShippingMethodDTO[]
|
||||||
@@ -14,9 +14,12 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const updateTaxLinesStepId = "update-tax-lines-step"
|
export const updateTaxLinesStepId = "update-tax-lines-step"
|
||||||
|
/**
|
||||||
|
* This step updates tax lines of line items and shipping methods.
|
||||||
|
*/
|
||||||
export const updateTaxLinesStep = createStep(
|
export const updateTaxLinesStep = createStep(
|
||||||
updateTaxLinesStepId,
|
updateTaxLinesStepId,
|
||||||
async (input: StepInput, { container }) => {
|
async (input: UpdateTaxLinesStepInput, { container }) => {
|
||||||
const { transaction } = await updateTaxLinesWorkflow(container).run({
|
const { transaction } = await updateTaxLinesWorkflow(container).run({
|
||||||
input,
|
input,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,14 +2,18 @@ import { CartWorkflowDTO } from "@medusajs/types"
|
|||||||
import { isPresent, MedusaError, PaymentSessionStatus } from "@medusajs/utils"
|
import { isPresent, MedusaError, PaymentSessionStatus } from "@medusajs/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface ValidateCartPaymentsStepInput {
|
||||||
cart: CartWorkflowDTO
|
cart: CartWorkflowDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validateCartPaymentsStepId = "validate-cart-payments"
|
export const validateCartPaymentsStepId = "validate-cart-payments"
|
||||||
|
/**
|
||||||
|
* This step validates a cart's payment sessions. Their status must
|
||||||
|
* be `pending` or `requires_more`.
|
||||||
|
*/
|
||||||
export const validateCartPaymentsStep = createStep(
|
export const validateCartPaymentsStep = createStep(
|
||||||
validateCartPaymentsStepId,
|
validateCartPaymentsStepId,
|
||||||
async (data: StepInput) => {
|
async (data: ValidateCartPaymentsStepInput) => {
|
||||||
const {
|
const {
|
||||||
cart: { payment_collection: paymentCollection },
|
cart: { payment_collection: paymentCollection },
|
||||||
} = data
|
} = data
|
||||||
|
|||||||
+5
-2
@@ -6,7 +6,7 @@ import {
|
|||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface ValidateCartShippingOptionsStepInput {
|
||||||
cart: CartDTO
|
cart: CartDTO
|
||||||
shippingOptionsContext: {
|
shippingOptionsContext: {
|
||||||
enabled_in_store?: "true" | "false"
|
enabled_in_store?: "true" | "false"
|
||||||
@@ -17,9 +17,12 @@ interface StepInput {
|
|||||||
|
|
||||||
export const validateCartShippingOptionsStepId =
|
export const validateCartShippingOptionsStepId =
|
||||||
"validate-cart-shipping-options"
|
"validate-cart-shipping-options"
|
||||||
|
/**
|
||||||
|
* This step validates shipping options to ensure they can be applied on a cart.
|
||||||
|
*/
|
||||||
export const validateCartShippingOptionsStep = createStep(
|
export const validateCartShippingOptionsStep = createStep(
|
||||||
validateCartShippingOptionsStepId,
|
validateCartShippingOptionsStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: ValidateCartShippingOptionsStepInput, { container }) => {
|
||||||
const { option_ids: optionIds = [], cart, shippingOptionsContext } = data
|
const { option_ids: optionIds = [], cart, shippingOptionsContext } = data
|
||||||
|
|
||||||
if (!optionIds.length) {
|
if (!optionIds.length) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { BigNumberInput } from "@medusajs/types"
|
|||||||
import { MedusaError, isPresent } from "@medusajs/utils"
|
import { MedusaError, isPresent } from "@medusajs/utils"
|
||||||
import { createStep } from "@medusajs/workflows-sdk"
|
import { createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
interface StepInput {
|
export interface ValidateVariantPricesStepInput {
|
||||||
variants: {
|
variants: {
|
||||||
id: string
|
id: string
|
||||||
calculated_price?: {
|
calculated_price?: {
|
||||||
@@ -12,9 +12,12 @@ interface StepInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const validateVariantPricesStepId = "validate-variant-prices"
|
export const validateVariantPricesStepId = "validate-variant-prices"
|
||||||
|
/**
|
||||||
|
* This step validates the specified variant objects to ensure they have prices.
|
||||||
|
*/
|
||||||
export const validateVariantPricesStep = createStep(
|
export const validateVariantPricesStep = createStep(
|
||||||
validateVariantPricesStepId,
|
validateVariantPricesStepId,
|
||||||
async (data: StepInput, { container }) => {
|
async (data: ValidateVariantPricesStepInput, { container }) => {
|
||||||
const priceNotFound: string[] = []
|
const priceNotFound: string[] = []
|
||||||
for (const variant of data.variants) {
|
for (const variant of data.variants) {
|
||||||
if (!isPresent(variant?.calculated_price?.calculated_amount)) {
|
if (!isPresent(variant?.calculated_price?.calculated_amount)) {
|
||||||
|
|||||||
Reference in new issue
Block a user