docs: replace ModuleRegistrationName with Modules (#9142)
This commit is contained in:
1 parent
8829f89402
commit
8584031041
55 files changed
+389
-391
No files matched your search
@@ -119,7 +119,7 @@ import type {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
@@ -129,7 +129,7 @@ export const GET = async (
|
||||
if (req.auth_context?.actor_id) {
|
||||
// retrieve customer
|
||||
const customerModuleService: ICustomerModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
Modules.CUSTOMER
|
||||
)
|
||||
|
||||
const customer = await customerModuleService.retrieveCustomer(
|
||||
@@ -154,7 +154,7 @@ import type {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
@@ -162,7 +162,7 @@ export const GET = async (
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const userModuleService: IUserModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.USER
|
||||
Modules.USER
|
||||
)
|
||||
|
||||
const user = await userModuleService.retrieveUser(
|
||||
|
||||
@@ -23,11 +23,11 @@ import {
|
||||
ExecArgs,
|
||||
IProductModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export default async function myScript({ container }: ExecArgs) {
|
||||
const productModuleService: IProductModuleService = container.resolve(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
Modules.PRODUCT
|
||||
)
|
||||
|
||||
const [, count] = await productModuleService
|
||||
|
||||
@@ -49,14 +49,14 @@ export const updateProductHighlights = [
|
||||
```ts title="src/workflows/update-product-erp/steps/update-product.ts" highlights={updateProductHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { UpdateProductAndErpWorkflowInput } from ".."
|
||||
|
||||
const updateProduct = createStep(
|
||||
"update-product",
|
||||
async (input: UpdateProductAndErpWorkflowInput, context) => {
|
||||
const productModuleService: IProductModuleService =
|
||||
context.container.resolve(ModuleRegistrationName.PRODUCT)
|
||||
context.container.resolve(Modules.PRODUCT)
|
||||
|
||||
const { id } = input
|
||||
const previousProductData =
|
||||
@@ -72,7 +72,7 @@ const updateProduct = createStep(
|
||||
// compensation function
|
||||
async ({ previousProductData }, context) => {
|
||||
const productModuleService: IProductModuleService =
|
||||
context.container.resolve(ModuleRegistrationName.PRODUCT)
|
||||
context.container.resolve(Modules.PRODUCT)
|
||||
|
||||
const { id, type, options, variants, ...previousData } = previousProductData
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ So, when you execute the `hello-world` workflow, it continues its execution in t
|
||||
|
||||
Once the workflow's execution reaches an async step, it'll wait in the background for the step to succeed or fail before it moves to the rest of the steps.
|
||||
|
||||
To change fail or succeed a step, use the workflow engine's main service that is registered in the Medusa Container under the `ModuleRegistrationName.WORKFLOW_ENGINE` (or `workflowsModuleService`) key.
|
||||
To change fail or succeed a step, use the workflow engine's main service that is registered in the Medusa Container under the `Modules.WORKFLOW_ENGINE` (or `workflowsModuleService`) key.
|
||||
|
||||
### Retrieve Transaction ID
|
||||
|
||||
@@ -103,7 +103,7 @@ export const successStatusHighlights = [
|
||||
|
||||
```ts highlights={successStatusHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
TransactionHandlerType,
|
||||
} from "@medusajs/utils";
|
||||
import {
|
||||
@@ -122,7 +122,7 @@ export const setStepSuccessStep = createStep(
|
||||
{ container }
|
||||
) {
|
||||
const workflowEngineService = container.resolve(
|
||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||
Modules.WORKFLOW_ENGINE
|
||||
);
|
||||
|
||||
await workflowEngineService.setStepSuccess({
|
||||
@@ -221,7 +221,7 @@ export const failureStatusHighlights = [
|
||||
|
||||
```ts highlights={failureStatusHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
TransactionHandlerType,
|
||||
} from "@medusajs/utils";
|
||||
import {
|
||||
@@ -240,7 +240,7 @@ export const setStepFailureStep = createStep(
|
||||
{ container }
|
||||
) {
|
||||
const workflowEngineService = container.resolve(
|
||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||
Modules.WORKFLOW_ENGINE
|
||||
);
|
||||
|
||||
await workflowEngineService.setStepFailure({
|
||||
@@ -282,7 +282,7 @@ import myWorkflow from "../../../workflows/hello-world"
|
||||
import {
|
||||
IWorkflowEngineService,
|
||||
} from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
||||
const { transaction, result } = await myWorkflow(req.scope).run()
|
||||
@@ -290,7 +290,7 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
||||
const workflowEngineService = req.scope.resolve<
|
||||
IWorkflowEngineService
|
||||
>(
|
||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||
Modules.WORKFLOW_ENGINE
|
||||
)
|
||||
|
||||
const subscriptionOptions = {
|
||||
|
||||
@@ -27,14 +27,14 @@ For example, you saw this code snippet in the [Medusa container chapter](../medu
|
||||
```ts highlights={[["10"]]}
|
||||
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const productModuleService: IProductModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
Modules.PRODUCT
|
||||
)
|
||||
|
||||
const [, count] = await productModuleService
|
||||
@@ -46,10 +46,10 @@ export const GET = async (
|
||||
}
|
||||
```
|
||||
|
||||
When you resolve the `ModuleRegistrationName.PRODUCT` (or `productModuleService`) registration name, you're actually resolving the main service of the Product Module.
|
||||
When you resolve the `Modules.PRODUCT` (or `productModuleService`) registration name, you're actually resolving the main service of the Product Module.
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
To resolve the main service of any commerce module, use the registration name defined in the `ModuleRegistrationName` enum imported from `@medusajs/utils`.
|
||||
To resolve the main service of any commerce module, use the registration name defined in the `Modules` enum imported from `@medusajs/utils`.
|
||||
|
||||
</Note>
|
||||
@@ -85,20 +85,20 @@ For example:
|
||||
export const highlights = [
|
||||
["7", "container", "Recieve the Medusa Container in the object parameter."],
|
||||
["10", "resolve", "Resolve the Product Module's main service."],
|
||||
["10", "ModuleRegistrationName.PRODUCT", "The module's registration name imported from `@medusajs/utils`."]
|
||||
["10", "Modules.PRODUCT", "The module's registration name imported from `@medusajs/utils`."]
|
||||
]
|
||||
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights}
|
||||
import { SubscriberArgs, type SubscriberConfig } from "@medusajs/medusa"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export default async function productCreateHandler({
|
||||
event: { data },
|
||||
container,
|
||||
}: SubscriberArgs<{ id: string }>) {
|
||||
const productModuleService: IProductModuleService =
|
||||
container.resolve(ModuleRegistrationName.PRODUCT)
|
||||
container.resolve(Modules.PRODUCT)
|
||||
|
||||
const productId = data.id
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export const highlights = [
|
||||
["9", "resolve", "Resolve the Product Module's main service."],
|
||||
[
|
||||
"10",
|
||||
"ModuleRegistrationName.PRODUCT",
|
||||
"Modules.PRODUCT",
|
||||
"The resource registration name imported from `@medusajs/utils`.",
|
||||
],
|
||||
]
|
||||
@@ -26,14 +26,14 @@ export const highlights = [
|
||||
```ts highlights={highlights}
|
||||
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const productModuleService: IProductModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
Modules.PRODUCT
|
||||
)
|
||||
|
||||
const [, count] = await productModuleService
|
||||
|
||||
@@ -87,7 +87,7 @@ For example:
|
||||
|
||||
export const highlights = [
|
||||
["11", "resolve", "Resolve the Product Module's main service."],
|
||||
["11", "ModuleRegistrationName.PRODUCT", "The module's registration name imported from `@medusajs/utils`."]
|
||||
["11", "Modules.PRODUCT", "The module's registration name imported from `@medusajs/utils`."]
|
||||
]
|
||||
|
||||
```ts title="src/jobs/hello-world.ts" highlights={highlights}
|
||||
@@ -95,13 +95,13 @@ import {
|
||||
IProductModuleService,
|
||||
MedusaContainer,
|
||||
} from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export default async function myCustomJob(
|
||||
container: MedusaContainer
|
||||
) {
|
||||
const productModuleService: IProductModuleService =
|
||||
container.resolve(ModuleRegistrationName.PRODUCT)
|
||||
container.resolve(Modules.PRODUCT)
|
||||
|
||||
const [, count] = await productModuleService.listAndCountProducts()
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ To execute the workflow, invoke it passing the Medusa container as a parameter.
|
||||
type SubscriberArgs,
|
||||
} from "@medusajs/medusa"
|
||||
import myWorkflow from "../workflows/hello-world"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
|
||||
export default async function handleCustomerCreate({
|
||||
@@ -136,7 +136,7 @@ To execute the workflow, invoke it passing the Medusa container as a parameter.
|
||||
}: SubscriberArgs<{ id: string }>) {
|
||||
const userId = data.id
|
||||
const userModuleService: IUserModuleService = container.resolve(
|
||||
ModuleRegistrationName.USER
|
||||
Modules.USER
|
||||
)
|
||||
|
||||
const user = await userModuleService.retrieveUser(userId)
|
||||
@@ -231,7 +231,7 @@ export const highlights = [
|
||||
["12", "resolve", "Resolve the Product Module's main service."],
|
||||
[
|
||||
"12",
|
||||
"ModuleRegistrationName.PRODUCT",
|
||||
"Modules.PRODUCT",
|
||||
"The resource registration name imported from `@medusajs/utils`.",
|
||||
],
|
||||
]
|
||||
@@ -244,11 +244,11 @@ import {
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, context) => {
|
||||
const productModuleService: IProductModuleService =
|
||||
context.container.resolve(ModuleRegistrationName.PRODUCT)
|
||||
context.container.resolve(Modules.PRODUCT)
|
||||
|
||||
const [, count] = await productModuleService.listAndCountProducts()
|
||||
|
||||
|
||||
Reference in new issue
Block a user