**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
|
import jwt from "jsonwebtoken"
|
|
import { getContainer } from "../environment-helpers/use-container"
|
|
|
|
export const adminHeaders = {
|
|
headers: { "x-medusa-access-token": "test_token" },
|
|
}
|
|
|
|
export const createAdminUser = async (
|
|
dbConnection,
|
|
adminHeaders,
|
|
container?
|
|
) => {
|
|
const appContainer = container ?? getContainer()!
|
|
|
|
const userModule: IUserModuleService = appContainer.resolve(
|
|
ModuleRegistrationName.USER
|
|
)
|
|
const authModule: IAuthModuleService = appContainer.resolve(
|
|
ModuleRegistrationName.AUTH
|
|
)
|
|
const user = await userModule.createUsers({
|
|
first_name: "Admin",
|
|
last_name: "User",
|
|
email: "admin@medusa.js",
|
|
})
|
|
|
|
const authIdentity = await authModule.createAuthIdentities({
|
|
provider_identities: [
|
|
{
|
|
provider: "emailpass",
|
|
entity_id: "admin@medusa.js",
|
|
provider_metadata: {
|
|
password: "somepassword",
|
|
},
|
|
},
|
|
],
|
|
app_metadata: {
|
|
user_id: user.id,
|
|
},
|
|
})
|
|
|
|
const token = jwt.sign(
|
|
{
|
|
actor_id: user.id,
|
|
actor_type: "user",
|
|
auth_identity_id: authIdentity.id,
|
|
},
|
|
"test"
|
|
)
|
|
|
|
adminHeaders.headers["authorization"] = `Bearer ${token}`
|
|
|
|
return { user }
|
|
}
|