docs: updates to use DML and other changes (#7834)

- Change existing data model guides and add new ones for DML
- Change module's docs around service factory + remove guides that are now necessary
- Hide/remove all mentions of module relationships, or label them as coming soon.
- Change all data model creation snippets to use DML
- use `property` instead of `field` when referring to a data model's properties.
- Fix all snippets in commerce module guides to use new method suffix (no more main model methods)
- Rework recipes, removing/hiding a lot of sections as a lot of recipes are incomplete with the current state of DML.


### Other changes

- Highlight fixes in some guides
- Remove feature flags guide
- Fix code block styles when there are no line numbers.

### Upcoming changes in other PRs

- Re-generate commerce module references (for the updates in the method names)
- Ensure that the data model references are generated correctly for models using DML.
- (probably at a very later point) revisit recipes
This commit is contained in:
Shahed Nasser
2024-06-26 07:55:59 +00:00
committed by GitHub
parent 62dacdda75
commit 0462cc5acf
126 changed files with 1808 additions and 14242 deletions
@@ -45,7 +45,7 @@ Then, the user is authenticated successfully, and their authentication details a
<Note>
Check out the [AuthIdentity](/references/auth/models/AuthIdentity) reference for the expected fields in `authIdentity`.
Check out the [AuthIdentity](/references/auth/models/AuthIdentity) reference for the expected properties in `authIdentity`.
</Note>
@@ -13,31 +13,18 @@ Before creating an actor type, you must define a data model the actor type belon
The rest of this guide uses this `Manager` data model as an example:
```ts title="src/modules/manager/models/manager.ts"
import { BaseEntity } from "@medusajs/utils"
import {
Entity,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { model } from "@medusajs/utils"
@Entity()
export class Manager extends BaseEntity {
@PrimaryKey({ columnType: "text" })
id!: string
const Manager = model.define("manager", {
id: model.id(),
firstName: model.text(),
lastName: model.text(),
email: model.text(),
})
@Property({ columnType: "text" })
first_name: string
@Property({ columnType: "text" })
last_name: string
@Property({ columnType: "text" })
email: string
}
export default Manager
```
The modules main service must also have a `create` method to create a record of the `Manager` data model.
---
## 1. Create Workflow
@@ -45,7 +32,7 @@ The modules main service must also have a `create` method to create a record
Start by creating a workflow that does two things:
- Create a record of the `Manager` data model.
- Sets the `app_metadata` field of the associated `AuthIdentity` record based on the new actor type.
- Sets the `app_metadata` property of the associated `AuthIdentity` record based on the new actor type.
For example, create the file `src/workflows/create-manager.ts`. with the following content:
@@ -92,7 +79,7 @@ const createManagerStep = createStep(
const managerModuleService: ManagerModuleService =
container.resolve("managerModuleService")
const manager = await managerModuleService.create(
const manager = await managerModuleService.createManager(
managerData
)
@@ -127,7 +114,7 @@ This workflow accepts the managers data and the associated auth identitys
The workflow has two steps:
1. Create the manager using the `createManagerStep`.
2. Set the `app_metadata` field of the associated auth identity using the `setAuthAppMetadataStep` step imported from `@medusajs/core-flows`. You specify the actor type `manager` in the `actorType` property of the steps input.
2. Set the `app_metadata` property of the associated auth identity using the `setAuthAppMetadataStep` step imported from `@medusajs/core-flows`. You specify the actor type `manager` in the `actorType` property of the steps input.
---
@@ -250,13 +237,12 @@ export async function GET(
const managerModuleService: ManagerModuleService =
req.scope.resolve("managerModuleService")
const manager = await managerModuleService.retrieve(
const manager = await managerModuleService.retrieveManager(
req.auth_context.actor_id
)
res.json({ manager })
}
```
This route is only accessible by authenticated managers. You access the managers ID using `req.auth_context.actor_id`.
@@ -235,11 +235,12 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
const authModuleService: IAuthModuleService =
req.scope.resolve(ModuleRegistrationName.AUTH)
const authIdentity = await authModuleService.create({
provider: "emailpass",
entity_id: "user@example.com",
scope: "admin",
})
const authIdentity = await authModuleService
.createAuthIdentities({
provider: "emailpass",
entity_id: "user@example.com",
scope: "admin",
})
res.json({ auth_identity: authIdentity })
}
@@ -258,11 +259,12 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
export async function POST(request: Request) {
const authModuleService = await initializeAuthModule()
const authIdentity = await authModuleService.create({
provider: "emailpass",
entity_id: "user@example.com",
scope: "admin",
})
const authIdentity = await authModuleService
.createAuthIdentities({
provider: "emailpass",
entity_id: "user@example.com",
scope: "admin",
})
return NextResponse.json({
auth_identity: authIdentity,
@@ -293,7 +295,8 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
req.scope.resolve(ModuleRegistrationName.AUTH)
res.json({
auth_identitys: await authModuleService.list(),
auth_identitys:
await authModuleService.listAuthIdentities(),
})
}
```
@@ -312,7 +315,8 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
const authModuleService = await initializeAuthModule()
return NextResponse.json({
auth_identities: await authModuleService.list(),
auth_identities:
await authModuleService.listAuthIdentities(),
})
}
```
@@ -339,12 +343,13 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
const authModuleService: IAuthModuleService =
req.scope.resolve(ModuleRegistrationName.AUTH)
const authIdentity = await authModuleService.update({
id: "authusr_123",
provider_metadata: {
test: true,
},
})
const authIdentity = await authModuleService
.updateAuthIdentites({
id: "authusr_123",
provider_metadata: {
test: true,
},
})
res.json({
auth_identity: authIdentity,
@@ -374,15 +379,16 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
) {
const authModuleService = await initializeAuthModule()
const authIdentity = await authModuleService.update({
id: "authusr_123",
provider_metadata: {
test: true,
},
})
const authIdentity = await authModuleService
.updateAuthIdentites({
id: "authusr_123",
provider_metadata: {
test: true,
},
})
return NextResponse.json({
auth_identitys: await authModuleService.list(),
auth_identity: authIdentity,
})
}
```
@@ -409,7 +415,9 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
const authModuleService: IAuthModuleService =
req.scope.resolve(ModuleRegistrationName.AUTH)
await authModuleService.delete(["authusr_123"])
await authModuleService.deleteAuthIdentities([
"authusr_123",
])
res.status(200)
}
@@ -437,7 +445,9 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
) {
const authModuleService = await initializeAuthModule()
await authModuleService.delete(["authusr_123"])
await authModuleService.deleteAuthIdentities([
"authusr_123",
])
}
```
@@ -99,7 +99,8 @@ For example:
req.scope.resolve(ModuleRegistrationName.AUTH)
res.json({
authIdentitys: authModuleService.list(),
authIdentitys:
await authModuleService.listAuthIdentities(),
})
}
```
@@ -120,7 +121,8 @@ For example:
const authModuleService: IAuthModuleService =
container.resolve(ModuleRegistrationName.AUTH)
const authIdentitys = await authModuleService.list()
const authIdentitys = await authModuleService
.listAuthIdentities()
}
```
@@ -141,7 +143,8 @@ For example:
container.resolve(
ModuleRegistrationName.AUTH
)
const authIdentitys = await authModuleService.list()
const authIdentitys = await authModuleService
.listAuthIdentities()
})
```