chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions
@@ -13,54 +13,50 @@ In this guide, youll find common examples of how you can use the Customer Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
export async function POST(request: MedusaRequest, res: MedusaResponse) {
const customerModuleService: ICustomerModuleService = request.scope.resolve(
ModuleRegistrationName.CUSTOMER
)
const customer = await customerModuleService.createCustomers({
first_name: "Peter",
last_name: "Hayes",
email: "peter.hayes@example.com",
})
const customer = await customerModuleService.createCustomers({
first_name: "Peter",
last_name: "Hayes",
email: "peter.hayes@example.com",
})
res.json({
customer,
})
}
```
res.json({
customer,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeCustomerModule,
} from "@medusajs/customer"
import { initialize as initializeCustomerModule } from "@medusajs/customer"
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
const customer = await customerModuleService.createCustomers({
first_name: "Peter",
last_name: "Hayes",
email: "peter.hayes@example.com",
})
const customer = await customerModuleService.createCustomers({
first_name: "Peter",
last_name: "Hayes",
email: "peter.hayes@example.com",
})
return NextResponse.json({
customer,
})
}
```
return NextResponse.json({
customer,
})
}
```
</CodeTab>
</CodeTabs>
@@ -72,52 +68,46 @@ In this guide, youll find common examples of how you can use the Customer Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
export async function POST(request: MedusaRequest, res: MedusaResponse) {
const customerModuleService: ICustomerModuleService = request.scope.resolve(
ModuleRegistrationName.CUSTOMER
)
const customerGroup =
await customerModuleService.createCustomerGroups({
name: "VIP",
})
const customerGroup = await customerModuleService.createCustomerGroups({
name: "VIP",
})
res.json({
customer_group: customerGroup,
})
}
```
res.json({
customer_group: customerGroup,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeCustomerModule,
} from "@medusajs/customer"
import { initialize as initializeCustomerModule } from "@medusajs/customer"
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
const customerGroup =
await customerModuleService.createCustomerGroups({
name: "VIP",
})
const customerGroup = await customerModuleService.createCustomerGroups({
name: "VIP",
})
return NextResponse.json({
customer_group: customerGroup,
})
}
```
return NextResponse.json({
customer_group: customerGroup,
})
}
```
</CodeTab>
</CodeTabs>
@@ -129,48 +119,44 @@ In this guide, youll find common examples of how you can use the Customer Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
export async function POST(request: MedusaRequest, res: MedusaResponse) {
const customerModuleService: ICustomerModuleService = request.scope.resolve(
ModuleRegistrationName.CUSTOMER
)
await customerModuleService.addCustomerToGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
await customerModuleService.addCustomerToGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
res.status(200)
}
```
res.status(200)
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeCustomerModule,
} from "@medusajs/customer"
import { initialize as initializeCustomerModule } from "@medusajs/customer"
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
await customerModuleService.addCustomerToGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
await customerModuleService.addCustomerToGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
return NextResponse.json({}, { status: 200 })
}
```
return NextResponse.json({}, { status: 200 })
}
```
</CodeTab>
</CodeTabs>
@@ -182,49 +168,45 @@ In this guide, youll find common examples of how you can use the Customer Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
export async function POST(request: MedusaRequest, res: MedusaResponse) {
const customerModuleService: ICustomerModuleService = request.scope.resolve(
ModuleRegistrationName.CUSTOMER
)
await customerModuleService.removeCustomerFromGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
await customerModuleService.removeCustomerFromGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
res.status(200)
}
```
res.status(200)
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
// eslint-disable-next-line prettier/prettier
import {
initialize as initializeCustomerModule,
} from "@medusajs/customer"
// eslint-disable-next-line prettier/prettier
import { initialize as initializeCustomerModule } from "@medusajs/customer"
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
export async function POST(request: Request) {
const customerModuleService = await initializeCustomerModule()
await customerModuleService.removeCustomerFromGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
await customerModuleService.removeCustomerFromGroup({
customer_id: "cus_123",
customer_group_id: "cusgroup_123",
})
return NextResponse.json({}, { status: 200 })
}
```
return NextResponse.json({}, { status: 200 })
}
```
</CodeTab>
</CodeTabs>
@@ -27,10 +27,9 @@ const customer = await customerModuleService.createCustomers({
You can organize customers into groups. This has a lot of benefits and supports more use cases, such as provide discounts for specific customer groups using the Promotion Module.
```ts
const customerGroup =
await customerModuleService.createCustomerGroups({
name: "VIP",
})
const customerGroup = await customerModuleService.createCustomerGroups({
name: "VIP",
})
await customerModuleService.addCustomerToGroup({
customer_id: "cus_123",
@@ -49,59 +48,55 @@ For example:
<CodeTabs groupId="resource-type">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
export async function GET(request: MedusaRequest, res: MedusaResponse) {
const customerModuleService: ICustomerModuleService = request.scope.resolve(
ModuleRegistrationName.CUSTOMER
)
res.json({
customers: await customerModuleService.listCustomers(),
})
}
```
res.json({
customers: await customerModuleService.listCustomers(),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const customerModuleService: ICustomerModuleService =
container.resolve(ModuleRegistrationName.CUSTOMER)
export default async function subscriberHandler({ container }: SubscriberArgs) {
const customerModuleService: ICustomerModuleService = container.resolve(
ModuleRegistrationName.CUSTOMER
)
const customers = await customerModuleService.listCustomers()
}
```
const customers = await customerModuleService.listCustomers()
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
const step1 = createStep(
"step-1",
async (_, { container }) => {
const customerModuleService: ICustomerModuleService =
container.resolve(ModuleRegistrationName.CUSTOMER)
const step1 = createStep("step-1", async (_, { container }) => {
const customerModuleService: ICustomerModuleService = container.resolve(
ModuleRegistrationName.CUSTOMER
)
const customers = await customerModuleService.listCustomers()
})
```
const customers = await customerModuleService.listCustomers()
})
```
</CodeTab>
</CodeTabs>