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

chore(core-flows): [3] export types and types, add basic TSDocs #8507

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

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(
findOneOrAnyRegionStepId,
async (data: { regionId?: string }, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { CustomerDTO, ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName, validateEmail } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface FindOrCreateCustomerStepInput {
customerId?: string | null
email?: string | null
}

interface StepOutput {
export interface FindOrCreateCustomerOutputStepOutput {
customer?: CustomerDTO | null
email?: string | null
}
Expand All @@ -18,9 +18,13 @@ interface StepCompensateInput {
}

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(
findOrCreateCustomerStepId,
async (data: StepInput, { container }) => {
async (data: FindOrCreateCustomerStepInput, { container }) => {
if (
typeof data.customerId === undefined &&
typeof data.email === undefined
Expand All @@ -38,7 +42,7 @@ export const findOrCreateCustomerStep = createStep(
ModuleRegistrationName.CUSTOMER
)

const customerData: StepOutput = {
const customerData: FindOrCreateCustomerOutputStepOutput = {
customer: null,
email: null,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import {
import { MedusaError, ModuleRegistrationName, isDefined } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface FindSalesChannelStepInput {
salesChannelId?: string | null
}

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(
findSalesChannelStepId,
async (data: StepInput, { container }) => {
async (data: FindSalesChannelStepInput, { container }) => {
const salesChannelService = container.resolve<ISalesChannelModuleService>(
ModuleRegistrationName.SALES_CHANNEL
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { CartDTO, IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetActionsToComputeFromPromotionsStepInput {
cart: CartDTO
promotionCodesToApply: string[]
}

export const getActionsToComputeFromPromotionsStepId =
"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(
getActionsToComputeFromPromotionsStepId,
async (data: StepInput, { container }) => {
async (data: GetActionsToComputeFromPromotionsStepInput, { container }) => {
const { cart, promotionCodesToApply = [] } = data
const promotionService = container.resolve<IPromotionModuleService>(
ModuleRegistrationName.PROMOTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetItemTaxLinesStepInput {
cart: CartWorkflowDTO
items: CartLineItemDTO[]
shipping_methods: CartShippingMethodDTO[]
Expand Down Expand Up @@ -94,9 +94,12 @@ function normalizeLineItemsForShipping(
}

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(
getItemTaxLinesStepId,
async (data: StepInput, { container }) => {
async (data: GetItemTaxLinesStepInput, { container }) => {
const {
cart,
items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetLineItemActionsStepInput {
id: string
items: CreateLineItemForCartDTO[]
}

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(
getLineItemActionsStepId,
async (data: StepInput, { container }) => {
async (data: GetLineItemActionsStepInput, { container }) => {
const cartModule = container.resolve<ICartModuleService>(
ModuleRegistrationName.CART
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName, PromotionActions } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetPromotionCodesToApplyStepInput {
cart: {
items?: { adjustments?: { code?: string }[] }[]
shipping_methods?: { adjustments?: { code?: string }[] }[]
Expand All @@ -15,9 +15,12 @@ interface StepInput {
}

export const getPromotionCodesToApplyId = "get-promotion-codes-to-apply"
/**
* This step retrieves the promotion codes to apply on a cart.
*/
export const getPromotionCodesToApply = createStep(
getPromotionCodesToApplyId,
async (data: StepInput, { container }) => {
async (data: GetPromotionCodesToApplyStepInput, { container }) => {
const { promo_codes = [], cart, action = PromotionActions.ADD } = data
const { items = [], shipping_methods = [] } = cart
const adjustmentCodes: string[] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { IPricingModuleService } from "@medusajs/types"
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetVariantPriceSetsStepInput {
variantIds: string[]
context?: Record<string, unknown>
}

export const getVariantPriceSetsStepId = "get-variant-price-sets"
/**
* This step retrieves the calculated price sets of the specified variants.
*/
export const getVariantPriceSetsStep = createStep(
getVariantPriceSetsStepId,
async (data: StepInput, { container }) => {
async (data: GetVariantPriceSetsStepInput, { container }) => {
if (!data.variantIds.length) {
return new StepResponse({})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface GetVariantsStepInput {
filter?: FilterableProductVariantProps
config?: FindConfig<ProductVariantDTO>
}

export const getVariantsStepId = "get-variants"
/**
* This step retrieves variants matching the specified filters.
*/
export const getVariantsStep = createStep(
getVariantsStepId,
async (data: StepInput, { container }) => {
async (data: GetVariantsStepInput, { container }) => {
const productModuleService = container.resolve<IProductModuleService>(
ModuleRegistrationName.PRODUCT
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import {
import { ComputedActions, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface PrepareAdjustmentsFromPromotionActionsStepInput {
actions: ComputeActions[]
}

export const prepareAdjustmentsFromPromotionActionsStepId =
"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(
prepareAdjustmentsFromPromotionActionsStepId,
async (data: StepInput, { container }) => {
async (data: PrepareAdjustmentsFromPromotionActionsStepInput, { container }) => {
const promotionModuleService: IPromotionModuleService = container.resolve(
ModuleRegistrationName.PROMOTION
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PromotionActions } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { updateCartPromotionsWorkflow } from "../workflows"

interface StepInput {
export interface RefreshCartPromotionsStepInput {
id: string
promo_codes?: string[]
action?:
Expand All @@ -12,9 +12,12 @@ interface StepInput {
}

export const refreshCartPromotionsStepId = "refresh-cart-promotions"
/**
* This step refreshes the promotions of a cart.
*/
export const refreshCartPromotionsStep = createStep(
refreshCartPromotionsStepId,
async (data: StepInput, { container }) => {
async (data: RefreshCartPromotionsStepInput, { container }) => {
const { promo_codes = [], id, action = PromotionActions.ADD } = data

await updateCartPromotionsWorkflow(container).run({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
import { ModuleRegistrationName, arrayDifference } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RefreshCartShippingMethodsStepInput {
cart: CartDTO
}

export const refreshCartShippingMethodsStepId = "refresh-cart-shipping-methods"
/**
* This step refreshes the shipping methods of a cart.
*/
export const refreshCartShippingMethodsStep = createStep(
refreshCartShippingMethodsStepId,
async (data: StepInput, { container }) => {
async (data: RefreshCartShippingMethodsStepInput, { container }) => {
const { cart } = data
const { shipping_methods: shippingMethods = [] } = cart

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { ICartModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RemoveLineItemAdjustmentsStepInput {
lineItemAdjustmentIdsToRemove: string[]
}

export const removeLineItemAdjustmentsStepId = "remove-line-item-adjustments"
/**
* This step removes line item adjustments from a cart.
*/
export const removeLineItemAdjustmentsStep = createStep(
removeLineItemAdjustmentsStepId,
async (data: StepInput, { container }) => {
async (data: RemoveLineItemAdjustmentsStepInput, { container }) => {
const { lineItemAdjustmentIdsToRemove = [] } = data
const cartModuleService: ICartModuleService = container.resolve(
ModuleRegistrationName.CART
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { ICartModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RemoveShippingMethodAdjustmentsStepInput {
shippingMethodAdjustmentIdsToRemove: string[]
}

export const removeShippingMethodAdjustmentsStepId =
"remove-shipping-method-adjustments"
/**
* This step removes shipping method adjustments from a cart.
*/
export const removeShippingMethodAdjustmentsStep = createStep(
removeShippingMethodAdjustmentsStepId,
async (data: StepInput, { container }) => {
async (data: RemoveShippingMethodAdjustmentsStepInput, { container }) => {
const { shippingMethodAdjustmentIdsToRemove = [] } = data
const cartModuleService: ICartModuleService = container.resolve(
ModuleRegistrationName.CART
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { ICartModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RemoveShippingMethodFromCartStepInput {
shipping_method_ids: string[]
}

export const removeShippingMethodFromCartStepId =
"remove-shipping-method-to-cart-step"
/**
* This step removes shipping methods from a cart.
*/
export const removeShippingMethodFromCartStep = createStep(
removeShippingMethodFromCartStepId,
async (data: StepInput, { container }) => {
async (data: RemoveShippingMethodFromCartStepInput, { container }) => {
const cartService = container.resolve<ICartModuleService>(
ModuleRegistrationName.CART
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IInventoryService } from "@medusajs/types"
import { MathBN, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface ReserveVariantInventoryStepInput {
items: {
id?: string
inventory_item_id: string
Expand All @@ -14,9 +14,13 @@ interface StepInput {
}

export const reserveInventoryStepId = "reserve-inventory-step"
/**
* This step reserves the quantity of line items from the associated
* variant's inventory.
*/
export const reserveInventoryStep = createStep(
reserveInventoryStepId,
async (data: StepInput, { container }) => {
async (data: ReserveVariantInventoryStepInput, { container }) => {
const inventoryService = container.resolve<IInventoryService>(
ModuleRegistrationName.INVENTORY
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RetrieveCartWithLinksStepInput {
cart_or_cart_id: string | CartWorkflowDTO
fields: string[]
}

export const retrieveCartWithLinksStepId = "retrieve-cart-with-links"
/**
* This step retrieves a cart's details with its linked records.
*/
export const retrieveCartWithLinksStep = createStep(
retrieveCartWithLinksStepId,
async (data: StepInput, { container }) => {
async (data: RetrieveCartWithLinksStepInput, { container }) => {
const { cart_or_cart_id: cartOrCartId, fields } = data

if (isObject(cartOrCartId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { CartDTO, FindConfig, ICartModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface RetrieveCartStepInput {
id: string
config?: FindConfig<CartDTO>
}

export const retrieveCartStepId = "retrieve-cart"
/**
* This step retrieves a cart's details.
*/
export const retrieveCartStep = createStep(
retrieveCartStepId,
async (data: StepInput, { container }) => {
async (data: RetrieveCartStepInput, { container }) => {
const cartModuleService = container.resolve<ICartModuleService>(
ModuleRegistrationName.CART
)
Expand Down
Loading
Loading