feat(medusa): integrate pricing module to core (#5304)
* add pricing integraiton feature flag * init * first endpoint * cleanup * remove console.logs * refactor to util and implement across endpoints * add changeset * rename variables * remove mistype * feat(medusa): move price module integration to pricing service (#5322) * initial changes * chore: make product service always internal for pricing module * add notes --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * nit * cleanup * update to object querying * update cart integration test * remove uppercase currency_code * nit * Feat/admin product pricing module reads (#5354) * initial changes to list prices for admin * working price module implementation of list prices * nit * variant pricing * redo integration test changes * cleanup * cleanup * fix unit tests * [wip] Core <> Pricing - price updates (#5364) * chore: update medusa-app * wip * get links and modules working with migration * wip * chore: make test pass * Feat/rule type utils (#5371) * initial rule type utils * update migration script * chore: cleanup * ensure prices are always decorated * chore: use seed instead * chore: fix oas conflict * region id add to admin price read! --------- Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> * pr feedback * create remoteQueryFunction type * fix merge * fix loaders issue * Feat(medusa, types, pricing): pricing module migration script (#5409) * add migration script for money amounts in pricing module * add changeset * rename file * cleanup imports * update changeset * add check for pricing module and ff * feat(medusa,workflows,types): update prices on product and variant update (#5412) * wip * chore: update product prices through workflow * chore: cleanup * chore: update product handler updates prices for variants * chore: handle reverts * chore: address pr comments * chore: scope workflow handlers to flag handlers * chore: update return * chore: update db url * chore: remove migration * chore: increase jest timeout * Feat(medusa): update migration and initDb to run link-migrations (#5437) * initial * loader update * more progress on loaders * update integration tests and remote-query loader * remove helper * migrate isolated modules * fix test * fix integration test * update with pr feedback * unregister medusa-app * re-register medusaApp * fix featureflag * set timeout * set timeout * conditionally run link-module migrations * pr feedback 1 * add driver options for db * throw if link is not defined in migration script * pass config module directly * include container in migrate command * chore: increase timeout * rm redis from api integration tests to test * chore: temporarily skip tests * chore: undo skips + add timeout for workflow tests * chore: increase timeout for order edits * re-add redis * include final resolution * add sharedcontainer to medusaapp loader * chore: move migration under run command * try removing redis_url from api tests * chore: cleanup server on process exit * chore: clear container on exit * chore: adjustments * chore: remove consoles * chore: close express app on finish * chore: destroy pg connection on shutdown * chore: skip * chore: unskip test * chore: cleanup container pg connection * chore: skip --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
@@ -139,7 +139,8 @@ export async function loadModuleMigrations(
|
||||
): Promise<[Function | undefined, Function | undefined]> {
|
||||
let loadedModule: ModuleExports
|
||||
try {
|
||||
loadedModule = (await import(resolution.resolutionPath as string)).default
|
||||
loadedModule = await import(resolution.resolutionPath as string)
|
||||
|
||||
return [loadedModule.runMigrations, loadedModule.revertMigration]
|
||||
} catch {
|
||||
return [undefined, undefined]
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { mergeTypeDefs } from "@graphql-tools/merge"
|
||||
import { makeExecutableSchema } from "@graphql-tools/schema"
|
||||
import { RemoteFetchDataCallback } from "@medusajs/orchestration"
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
@@ -26,15 +23,18 @@ import {
|
||||
Modules,
|
||||
} from "./definitions"
|
||||
import { MedusaModule } from "./medusa-module"
|
||||
import { RemoteFetchDataCallback } from "@medusajs/orchestration"
|
||||
import { RemoteLink } from "./remote-link"
|
||||
import { RemoteQuery } from "./remote-query"
|
||||
import { cleanGraphQLSchema } from "./utils"
|
||||
import { asValue } from "awilix"
|
||||
import { makeExecutableSchema } from "@graphql-tools/schema"
|
||||
import { mergeTypeDefs } from "@graphql-tools/merge"
|
||||
|
||||
const LinkModulePackage = "@medusajs/link-modules"
|
||||
|
||||
export type RunMigrationFn = (
|
||||
options: Omit<LoaderOptions<ModuleServiceInitializeOptions>, "container">,
|
||||
options?: ModuleServiceInitializeOptions,
|
||||
injectedDependencies?: Record<any, any>
|
||||
) => Promise<void>
|
||||
|
||||
@@ -162,6 +162,18 @@ function registerCustomJoinerConfigs(servicesConfig: ModuleJoinerConfig[]) {
|
||||
}
|
||||
}
|
||||
|
||||
export type MedusaAppOutput = {
|
||||
modules: Record<string, LoadedModule | LoadedModule[]>
|
||||
link: RemoteLink | undefined
|
||||
query: (
|
||||
query: string | RemoteJoinerQuery | object,
|
||||
variables?: Record<string, unknown>
|
||||
) => Promise<any>
|
||||
entitiesMap?: Record<string, any>
|
||||
notFound?: Record<string, Record<string, string>>
|
||||
runMigrations: RunMigrationFn
|
||||
}
|
||||
|
||||
export async function MedusaApp(
|
||||
{
|
||||
sharedContainer,
|
||||
@@ -276,19 +288,24 @@ export async function MedusaApp(
|
||||
return await remoteQuery.query(query, variables)
|
||||
}
|
||||
|
||||
const runMigrations: RunMigrationFn = async (): Promise<void> => {
|
||||
const runMigrations: RunMigrationFn = async (
|
||||
linkModuleOptions
|
||||
): Promise<void> => {
|
||||
for (const moduleName of Object.keys(allModules)) {
|
||||
const loadedModule = allModules[moduleName]
|
||||
const moduleResolution = MedusaModule.getModuleResolutions(moduleName)
|
||||
|
||||
await MedusaModule.migrateUp(
|
||||
loadedModule.definition.key,
|
||||
loadedModule.resolutionPath,
|
||||
loadedModule.options
|
||||
moduleResolution.definition.key,
|
||||
moduleResolution.resolutionPath as string,
|
||||
moduleResolution.options
|
||||
)
|
||||
}
|
||||
|
||||
linkModuleMigration &&
|
||||
(await linkModuleMigration(linkResolution.options, injectedDependencies))
|
||||
(await linkModuleMigration({
|
||||
options: linkModuleOptions,
|
||||
injectedDependencies,
|
||||
}))
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -71,6 +71,7 @@ export class MedusaModule {
|
||||
private static modules_: Map<string, ModuleAlias[]> = new Map()
|
||||
private static loading_: Map<string, Promise<any>> = new Map()
|
||||
private static joinerConfig_: Map<string, ModuleJoinerConfig> = new Map()
|
||||
private static moduleResolutions_: Map<string, ModuleResolution> = new Map()
|
||||
|
||||
public static getLoadedModules(
|
||||
aliases?: Map<string, string>
|
||||
@@ -88,6 +89,7 @@ export class MedusaModule {
|
||||
MedusaModule.instances_.clear()
|
||||
MedusaModule.modules_.clear()
|
||||
MedusaModule.joinerConfig_.clear()
|
||||
MedusaModule.moduleResolutions_.clear()
|
||||
}
|
||||
|
||||
public static isInstalled(moduleKey: string, alias?: string): boolean {
|
||||
@@ -109,11 +111,29 @@ export class MedusaModule {
|
||||
return [...MedusaModule.joinerConfig_.values()]
|
||||
}
|
||||
|
||||
public static getModuleResolutions(moduleKey: string): ModuleResolution {
|
||||
return MedusaModule.moduleResolutions_.get(moduleKey)!
|
||||
}
|
||||
|
||||
public static getAllModuleResolutions(): ModuleResolution[] {
|
||||
return [...MedusaModule.moduleResolutions_.values()]
|
||||
}
|
||||
|
||||
public static setModuleResolution(
|
||||
moduleKey: string,
|
||||
resolution: ModuleResolution
|
||||
): ModuleResolution {
|
||||
MedusaModule.moduleResolutions_.set(moduleKey, resolution)
|
||||
|
||||
return resolution
|
||||
}
|
||||
|
||||
public static setJoinerConfig(
|
||||
moduleKey: string,
|
||||
config: ModuleJoinerConfig
|
||||
): ModuleJoinerConfig {
|
||||
MedusaModule.joinerConfig_.set(moduleKey, config)
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -261,6 +281,8 @@ export class MedusaModule {
|
||||
MedusaModule.setJoinerConfig(keyName, joinerConfig)
|
||||
}
|
||||
|
||||
MedusaModule.setModuleResolution(keyName, resolution)
|
||||
|
||||
MedusaModule.registerModule(keyName, {
|
||||
key: keyName,
|
||||
hash: hashKey,
|
||||
@@ -379,6 +401,7 @@ export class MedusaModule {
|
||||
}
|
||||
}
|
||||
|
||||
MedusaModule.setModuleResolution(keyName, resolution)
|
||||
MedusaModule.registerModule(keyName, {
|
||||
key: keyName,
|
||||
hash: hashKey,
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
import {
|
||||
RemoteFetchDataCallback,
|
||||
RemoteJoiner,
|
||||
toRemoteJoinerQuery,
|
||||
} from "@medusajs/orchestration"
|
||||
import {
|
||||
JoinerRelationship,
|
||||
JoinerServiceConfig,
|
||||
@@ -11,7 +6,13 @@ import {
|
||||
RemoteExpandProperty,
|
||||
RemoteJoinerQuery,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
RemoteFetchDataCallback,
|
||||
RemoteJoiner,
|
||||
toRemoteJoinerQuery,
|
||||
} from "@medusajs/orchestration"
|
||||
import { isString, toPascalCase } from "@medusajs/utils"
|
||||
|
||||
import { MedusaModule } from "./medusa-module"
|
||||
|
||||
export class RemoteQuery {
|
||||
@@ -28,14 +29,14 @@ export class RemoteQuery {
|
||||
customRemoteFetchData?: RemoteFetchDataCallback
|
||||
servicesConfig?: ModuleJoinerConfig[]
|
||||
}) {
|
||||
const servicesConfig_ = [...servicesConfig]
|
||||
|
||||
if (!modulesLoaded?.length) {
|
||||
modulesLoaded = MedusaModule.getLoadedModules().map(
|
||||
(mod) => Object.values(mod)[0]
|
||||
)
|
||||
}
|
||||
|
||||
const servicesConfig_ = [...servicesConfig]
|
||||
|
||||
for (const mod of modulesLoaded) {
|
||||
if (!mod.__definition.isQueryable) {
|
||||
continue
|
||||
@@ -54,6 +55,7 @@ export class RemoteQuery {
|
||||
}
|
||||
|
||||
this.customRemoteFetchData = customRemoteFetchData
|
||||
|
||||
this.remoteJoiner = new RemoteJoiner(
|
||||
servicesConfig_ as JoinerServiceConfig[],
|
||||
this.remoteFetchData.bind(this)
|
||||
|
||||
Reference in New Issue
Block a user