feat: Init. v2 implementation in admin (#6715)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
export const defaultAdminStoreRelations = []
|
||||
export const allowedAdminStoreRelations = []
|
||||
export const defaultAdminStoreFields = [
|
||||
"id",
|
||||
"name",
|
||||
"supported_currency_codes",
|
||||
"default_currency_code",
|
||||
"default_currency.name",
|
||||
"default_currency.symbol",
|
||||
"default_currency.symbol_native",
|
||||
"default_sales_channel_id",
|
||||
"default_region_id",
|
||||
"default_location_id",
|
||||
@@ -14,9 +15,7 @@ export const defaultAdminStoreFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminStoreFields,
|
||||
defaultRelations: defaultAdminStoreRelations,
|
||||
allowedRelations: allowedAdminStoreRelations,
|
||||
defaults: defaultAdminStoreFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import { defaultAdminStoreFields } from "./query-config"
|
||||
|
||||
@@ -6,6 +6,31 @@ import { track } from "medusa-telemetry"
|
||||
|
||||
import loaders from "../loaders"
|
||||
import Logger from "../loaders/logger"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import featureFlagLoader from "../loaders/feature-flags"
|
||||
import configModuleLoader from "../loaders/config"
|
||||
import { MedusaV2Flag } from "@medusajs/utils"
|
||||
|
||||
// TEMP: Only supporting emailpass
|
||||
const createV2User = async ({ email, password }, { container }) => {
|
||||
const authService = container.resolve(ModuleRegistrationName.AUTH)
|
||||
const userService = container.resolve(ModuleRegistrationName.USER)
|
||||
const user = await userService.create({ email })
|
||||
const { authUser } = await authService.authenticate("emailpass", {
|
||||
body: {
|
||||
email,
|
||||
password,
|
||||
},
|
||||
authScope: "admin",
|
||||
})
|
||||
|
||||
await authService.update({
|
||||
id: authUser.id,
|
||||
app_metadata: {
|
||||
user_id: user.id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default async function ({
|
||||
directory,
|
||||
@@ -33,8 +58,15 @@ export default async function ({
|
||||
Invite token: ${invite[0].token}
|
||||
Open the invite in Medusa Admin at: [your-admin-url]/invite?token=${invite[0].token}`)
|
||||
} else {
|
||||
const userService = container.resolve("userService")
|
||||
await userService.create({ id, email }, password)
|
||||
const configModule = configModuleLoader(directory)
|
||||
const featureFlagRouter = featureFlagLoader(configModule)
|
||||
|
||||
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||
await createV2User({ email, password }, { container })
|
||||
} else {
|
||||
const userService = container.resolve("userService")
|
||||
await userService.create({ id, email }, password)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
requireCustomerAuthentication,
|
||||
} from "../../../api/middlewares"
|
||||
import { ConfigModule } from "../../../types/global"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import logger from "../../logger"
|
||||
import {
|
||||
AsyncRouteHandler,
|
||||
@@ -19,12 +20,11 @@ import {
|
||||
MiddlewareRoute,
|
||||
MiddlewareVerb,
|
||||
MiddlewaresConfig,
|
||||
ParserConfigArgs,
|
||||
RouteConfig,
|
||||
RouteDescriptor,
|
||||
RouteVerb,
|
||||
ParserConfigArgs,
|
||||
} from "./types"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
|
||||
const log = ({
|
||||
activityId,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { createDefaultsWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
InternalModuleDeclaration,
|
||||
ModulesDefinition,
|
||||
ModulesDefinition
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { MODULE_RESOURCE_TYPE } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
isString,
|
||||
MedusaV2Flag,
|
||||
isString,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { Express, NextFunction, Request, Response } from "express"
|
||||
@@ -23,6 +24,7 @@ import databaseLoader, { dataSource } from "./database"
|
||||
import defaultsLoader from "./defaults"
|
||||
import expressLoader from "./express"
|
||||
import featureFlagsLoader from "./feature-flags"
|
||||
import medusaProjectApisLoader from "./load-medusa-project-apis"
|
||||
import Logger from "./logger"
|
||||
import loadMedusaApp, { mergeDefaultModules } from "./medusa-app"
|
||||
import modelsLoader from "./models"
|
||||
@@ -35,7 +37,6 @@ import searchIndexLoader from "./search-index"
|
||||
import servicesLoader from "./services"
|
||||
import strategiesLoader from "./strategies"
|
||||
import subscribersLoader from "./subscribers"
|
||||
import medusaProjectApisLoader from "./load-medusa-project-apis"
|
||||
|
||||
type Options = {
|
||||
directory: string
|
||||
@@ -130,7 +131,7 @@ async function loadMedusaV2({
|
||||
featureFlagRouter,
|
||||
})
|
||||
|
||||
medusaProjectApisLoader({
|
||||
await medusaProjectApisLoader({
|
||||
rootDirectory,
|
||||
container,
|
||||
app: expressApp,
|
||||
@@ -138,6 +139,8 @@ async function loadMedusaV2({
|
||||
activityId: "medusa-project-apis",
|
||||
})
|
||||
|
||||
await createDefaultsWorkflow(container).run()
|
||||
|
||||
return {
|
||||
container,
|
||||
app: expressApp,
|
||||
|
||||
Reference in New Issue
Block a user