on GitHub" data-tooltip-id=":Rblcldb:">v2.5.1·
In this section of the documentation, you will find resources to learn more about the Region Module and how to use it in your application.
Medusa has region related features available out-of-the-box through the Region Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Region Module.
In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows
package.
For example:
1import { 2 createWorkflow, 3 WorkflowResponse,4 createStep,5 StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8 9const createRegionStep = createStep(10 "create-region",11 async ({}, { container }) => {12 const regionModuleService = container.resolve(Modules.REGION)13 14 const region = await regionModuleService.createRegions({15 name: "Europe",16 currency_code: "eur",17 })18 19 return new StepResponse({ region }, region.id)20 },21 async (regionId, { container }) => {22 if (!regionId) {23 return24 }25 const regionModuleService = container.resolve(Modules.REGION)26 27 await regionModuleService.deleteRegions([regionId])28 }29)30 31export const createRegionWorkflow = createWorkflow(32 "create-region",33 () => {34 const { region } = createRegionStep()35 36 return new WorkflowResponse({37 region,38 })39 }40)
You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
Learn more about workflows in this documentation.