Skip to content
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 @@ -75,6 +75,8 @@ export const addShippingMethodToCartWorkflowId = "add-shipping-method-to-cart"
* @summary
*
* Add a shipping method to a cart.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const addShippingMethodToCartWorkflow = createWorkflow(
addShippingMethodToCartWorkflowId,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/core-flows/src/cart/workflows/add-to-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const addToCartWorkflowId = "add-to-cart"
* @summary
*
* Add a line item to a cart.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const addToCartWorkflow = createWorkflow(
addToCartWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const completeCartWorkflowId = "complete-cart"
* @summary
*
* Complete a cart and place an order.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const completeCartWorkflow = createWorkflow(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const createCartWorkflowId = "create-cart"
*
* Create a cart specifying region, items, and more.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation.
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
* @property hooks.cartCreated - This hook is executed after a cart is created. You can consume this hook to perform custom actions on the created cart.
*/
export const createCartWorkflow = createWorkflow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items"
* @summary
*
* Refresh a cart's details after an update.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const refreshCartItemsWorkflow = createWorkflow(
refreshCartItemsWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const refreshCartShippingMethodsWorkflowId =
* @summary
*
* Refresh a cart's shipping methods after an update.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const refreshCartShippingMethodsWorkflow = createWorkflow(
refreshCartShippingMethodsWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const refreshPaymentCollectionForCartWorkflowId =
* @summary
*
* Refresh a cart's payment collection details.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const refreshPaymentCollectionForCartWorkflow = createWorkflow(
refreshPaymentCollectionForCartWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const transferCartCustomerWorkflowId = "transfer-cart-customer"
* @summary
*
* Refresh a cart's payment collection details.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const transferCartCustomerWorkflow = createWorkflow(
transferCartCustomerWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const updateCartPromotionsWorkflowId = "update-cart-promotions"
* @summary
*
* Update a cart's applied promotions to add, replace, or remove them.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const updateCartPromotionsWorkflow = createWorkflow(
updateCartPromotionsWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const updateCartWorkflowId = "update-cart"
*
* Update a cart's details, such as region, address, and more.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation.
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
* @property hooks.cartUpdated - This hook is executed after a cart is update. You can consume this hook to perform custom actions on the updated cart.
*/
export const updateCartWorkflow = createWorkflow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const updateLineItemInCartWorkflowId = "update-line-item-in-cart"
* @summary
*
* Update a cart's line item.
*
* @property hooks.validate - This hook is executed before all operations. You can consume this hook to perform any custom validation. If validation fails, you can throw an error to stop the workflow execution.
*/
export const updateLineItemInCartWorkflow = createWorkflow(
updateLineItemInCartWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import {
import { Modules } from "@medusajs/framework/utils"
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"

/**
* The data to create customer groups.
*/
export type CreateCustomerGroupsStepInput = CreateCustomerGroupDTO[]

export const createCustomerGroupsStepId = "create-customer-groups"
/**
* This step creates one or more customer groups.
*/
export const createCustomerGroupsStep = createStep(
createCustomerGroupsStepId,
async (data: CreateCustomerGroupDTO[], { container }) => {
async (data: CreateCustomerGroupsStepInput, { container }) => {
const service = container.resolve<ICustomerModuleService>(Modules.CUSTOMER)

const createdCustomerGroups = await service.createCustomerGroups(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { ICustomerModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"

/**
* The IDs of the customer groups to delete.
*/
export type DeleteCustomerGroupsStepInput = string[]

export const deleteCustomerGroupStepId = "delete-customer-groups"
/**
* This step deletes one or more customer groups.
*/
export const deleteCustomerGroupStep = createStep(
deleteCustomerGroupStepId,
async (ids: string[], { container }) => {
async (ids: DeleteCustomerGroupsStepInput, { container }) => {
const service = container.resolve<ICustomerModuleService>(Modules.CUSTOMER)

await service.softDeleteCustomerGroups(ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
export const linkCustomerGroupsToCustomerStepId =
"link-customers-to-customer-group"
/**
* This step creates one or more links between a customer and customer groups records.
* This step manages the customer groups of a customer.
*
* @example
* const data = linkCustomerGroupsToCustomerStep({
* id: "cus_123",
* add: ["cusgrp_123"],
* remove: ["cusgrp_456"]
* })
*/
export const linkCustomerGroupsToCustomerStep = createStep(
linkCustomerGroupsToCustomerStepId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
export const linkCustomersToCustomerGroupStepId =
"link-customers-to-customer-group"
/**
* This step creates one or more links between customer and customer group records.
* This step manages the customers in a customer group.
*
* @example
* const data = linkCustomersToCustomerGroupStep({
* id: "cusgrp_123",
* add: ["cus_123"],
* remove: ["cus_456"]
* })
*/
export const linkCustomersToCustomerGroupStep = createStep(
linkCustomersToCustomerGroupStepId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@ import {
} from "@medusajs/framework/utils"
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"

/**
* The data to update customer groups.
*/
export type UpdateCustomerGroupStepInput = {
/**
* The filters to select the customer groups to update.
*/
selector: FilterableCustomerGroupProps
/**
* The data to update in the customer groups.
*/
update: CustomerGroupUpdatableFields
}

export const updateCustomerGroupStepId = "update-customer-groups"
/**
* This step updates one or more customer groups.
*
* @example
* const data = updateCustomerGroupsStep({
* selector: {
* id: "cusgrp_123"
* },
* update: {
* name: "VIP"
* }
* })
*/
export const updateCustomerGroupsStep = createStep(
updateCustomerGroupStepId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,51 @@ import {
} from "@medusajs/framework/workflows-sdk"
import { createCustomerGroupsStep } from "../steps"

/**
* The data to create customer groups.
*/
export type CreateCustomerGroupsWorkflowInput = {
/**
* The customer groups to create.
*/
customersData: CreateCustomerGroupDTO[]
}

/**
* The created customer groups.
*/
export type CreateCustomerGroupsWorkflowOutput = CustomerGroupDTO[]

export const createCustomerGroupsWorkflowId = "create-customer-groups"
/**
* This workflow creates one or more customer groups.
* This workflow creates one or more customer groups. It's used by the
* [Create Customer Group Admin API Route](https://docs.medusajs.com/api/admin#customer-groups_postcustomergroups).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* create customer groups within your custom flows. For example, you can create customer groups to segregate
* customers by age group or purchase habits.
*
* @example
* const { result } = await createCustomerGroupsWorkflow(container)
* .run({
* input: {
* customersData: [
* {
* name: "VIP"
* }
* ]
* }
* })
*
* @summary
*
* Create one or more customer groups.
*/
export const createCustomerGroupsWorkflow = createWorkflow(
createCustomerGroupsWorkflowId,
(
input: WorkflowData<CreateCustomerGroupsWorkflowInput>
): WorkflowResponse<CustomerGroupDTO[]> => {
): WorkflowResponse<CreateCustomerGroupsWorkflowOutput> => {
return new WorkflowResponse(createCustomerGroupsStep(input.customersData))
}
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
import { deleteCustomerGroupStep } from "../steps"

export type DeleteCustomerGroupsWorkflowInput = { ids: string[] }
/**
* The data to delete customer groups.
*/
export type DeleteCustomerGroupsWorkflowInput = {
/**
* The IDs of the customer groups to delete.
*/
ids: string[]
}

export const deleteCustomerGroupsWorkflowId = "delete-customer-groups"
/**
* This workflow deletes one or more customer groups.
* This workflow deletes one or more customer groups. It's used by the
* [Delete Customer Group Admin API Route](https://docs.medusajs.com/api/admin#customer-groups_deletecustomergroupsid).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* delete customer groups within your custom flows.
*
* @example
* const { result } = await deleteCustomerGroupsWorkflow(container)
* .run({
* input: {
* ids: ["cusgrp_123"]
* }
* })
*
* @summary
*
* Delete one or more customer groups.
*/
export const deleteCustomerGroupsWorkflow = createWorkflow(
deleteCustomerGroupsWorkflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@ import { LinkWorkflowInput } from "@medusajs/framework/types"
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
import { linkCustomerGroupsToCustomerStep } from "../steps"

/**
* The data to manage the customer groups of a customer.
*
* @property id - The ID of the customer to manage its groups.
* @property add - The IDs of the customer groups to add the customer to.
* @property remove - The IDs of the customer groups to remove the customer from.
*/
export type LinkCustomerGroupsToCustomerWorkflowInput = LinkWorkflowInput

export const linkCustomerGroupsToCustomerWorkflowId =
"link-customer-groups-to-customer"
/**
* This workflow creates one or more links between a customer and customer groups.
* This workflow manages the customer groups a customer is in. It's used by the
* [Manage Groups of Customer Admin API Route](https://docs.medusajs.com/api/admin#customers_postcustomersidcustomergroups).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* manage the customer groups of a customer in your custom flow.
*
* @example
* const { result } = await linkCustomerGroupsToCustomerWorkflow(container)
* .run({
* input: {
* id: "cus_123",
* add: ["cusgrp_123"],
* remove: ["cusgrp_456"]
* }
* })
*
* @summary
*
* Manage groups of a customer.
*/
export const linkCustomerGroupsToCustomerWorkflow = createWorkflow(
linkCustomerGroupsToCustomerWorkflowId,
(input: WorkflowData<LinkWorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<LinkCustomerGroupsToCustomerWorkflowInput>): WorkflowData<void> => {
return linkCustomerGroupsToCustomerStep(input)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@ import { LinkWorkflowInput } from "@medusajs/framework/types"
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
import { linkCustomersToCustomerGroupStep } from "../steps"

/**
* The data to manage the customers of a group.
*
* @property id - The ID of the customer group to manage its customers.
* @property add - The IDs of the customers to add to the customer group.
* @property remove - The IDs of the customers to remove from the customer group.
*/
export type LinkCustomersToCustomerGroupWorkflow = LinkWorkflowInput

export const linkCustomersToCustomerGroupWorkflowId =
"link-customers-to-customer-group"
/**
* This workflow creates one or more links between customer and customer group records.
* This workflow manages the customers of a customer group. It's used by the
* [Manage Customers of Group Admin API Route](https://docs.medusajs.com/api/admin#customer-groups_postcustomergroupsidcustomers).
*
* You can use this workflow within your customizations or your own custom workflows, allowing you to
* manage the customers of a customer group within your custom flows.
*
* @example
* const { result } = await linkCustomersToCustomerGroupWorkflow(container)
* .run({
* input: {
* id: "cusgrp_123",
* add: ["cus_123"],
* remove: ["cus_456"]
* }
* })
*
* @summary
*
* Manage the customers of a customer group.
*/
export const linkCustomersToCustomerGroupWorkflow = createWorkflow(
linkCustomersToCustomerGroupWorkflowId,
(input: WorkflowData<LinkWorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<LinkCustomersToCustomerGroupWorkflow>): WorkflowData<void> => {
return linkCustomersToCustomerGroupStep(input)
}
)
Loading
Loading