chore(modules-sdk): Custom Module definition (#7315)
This commit is contained in:
@@ -96,7 +96,6 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
{
|
||||
[Modules.EVENT_BUS]: {
|
||||
key: Modules.EVENT_BUS,
|
||||
isLegacy: true,
|
||||
registrationName: ModuleRegistrationName.EVENT_BUS,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.EVENT_BUS],
|
||||
label: upperCaseFirst(ModuleRegistrationName.EVENT_BUS),
|
||||
@@ -109,7 +108,6 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
},
|
||||
[Modules.STOCK_LOCATION]: {
|
||||
key: Modules.STOCK_LOCATION,
|
||||
isLegacy: true,
|
||||
registrationName: ModuleRegistrationName.STOCK_LOCATION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.STOCK_LOCATION),
|
||||
@@ -123,7 +121,6 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
},
|
||||
[Modules.INVENTORY]: {
|
||||
key: Modules.INVENTORY,
|
||||
isLegacy: true,
|
||||
registrationName: ModuleRegistrationName.INVENTORY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.INVENTORY),
|
||||
@@ -137,7 +134,6 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
},
|
||||
[Modules.CACHE]: {
|
||||
key: Modules.CACHE,
|
||||
isLegacy: true,
|
||||
registrationName: ModuleRegistrationName.CACHE,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.CACHE],
|
||||
label: upperCaseFirst(ModuleRegistrationName.CACHE),
|
||||
|
||||
@@ -16,7 +16,6 @@ describe("module definitions loader", () => {
|
||||
registrationName: "testService",
|
||||
defaultPackage: "@medusajs/test-service",
|
||||
label: "TestService",
|
||||
isLegacy: true,
|
||||
isRequired: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
|
||||
@@ -55,6 +55,13 @@ async function loadModule(
|
||||
loaderOnly?: boolean
|
||||
): Promise<{ error?: Error } | void> {
|
||||
const modDefinition = resolution.definition
|
||||
|
||||
if (!modDefinition.key) {
|
||||
throw new Error(`Module definition is missing property "key"`)
|
||||
}
|
||||
|
||||
modDefinition.registrationName ??= modDefinition.key
|
||||
|
||||
const registrationName = modDefinition.registrationName
|
||||
|
||||
const { scope, resources } = resolution.moduleDeclaration ?? ({} as any)
|
||||
|
||||
@@ -34,11 +34,19 @@ export enum MODULE_RESOURCE_TYPE {
|
||||
ISOLATED = "isolated",
|
||||
}
|
||||
|
||||
export type CustomModuleDefinition = {
|
||||
key?: string
|
||||
registrationName?: string
|
||||
label?: string
|
||||
isQueryable?: boolean // If the module is queryable via Remote Joiner
|
||||
dependencies?: string[]
|
||||
}
|
||||
|
||||
export type InternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.INTERNAL
|
||||
resources: MODULE_RESOURCE_TYPE
|
||||
dependencies?: string[]
|
||||
definition?: Partial<ModuleDefinition> // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
definition?: CustomModuleDefinition // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
resolve?: string | ModuleExports
|
||||
options?: Record<string, unknown>
|
||||
/**
|
||||
@@ -54,7 +62,7 @@ export type InternalModuleDeclaration = {
|
||||
|
||||
export type ExternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.EXTERNAL
|
||||
definition?: Partial<ModuleDefinition> // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
definition?: CustomModuleDefinition // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
server?: {
|
||||
type: "http"
|
||||
url: string
|
||||
@@ -87,7 +95,6 @@ export type ModuleDefinition = {
|
||||
label: string
|
||||
isRequired?: boolean
|
||||
isQueryable?: boolean // If the module is queryable via Remote Joiner
|
||||
isLegacy?: boolean // If the module is a legacy module TODO: Remove once all the legacy modules are migrated
|
||||
dependencies?: string[]
|
||||
defaultModuleDeclaration:
|
||||
| InternalModuleDeclaration
|
||||
|
||||
Reference in New Issue
Block a user