From 13476988763368b3b333fa5bc3f613e8eb174fdf Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Wed, 14 Jan 2026 18:39:57 +0100 Subject: [PATCH] feat(): improve module typings in medusa config (#14478) * feat(events): Allow priority configuration * feat(events): Allow priority configuration * wip * wip * wip * fix typings * Create cold-lamps-search.md * implement priority config usage * comment out #1 * fixes * fixes --- .changeset/cold-lamps-search.md | 10 ++ packages/core/framework/package.json | 5 +- packages/core/framework/src/types/index.ts | 7 + packages/core/framework/src/utils/index.ts | 2 + .../core/types/src/common/config-module.ts | 70 +++++--- packages/core/types/src/event-bus/common.ts | 22 +++ .../core/utils/src/common/define-config.ts | 11 ++ packages/core/utils/src/core-flows/events.ts | 163 +++++++++++++++--- packages/core/utils/src/event-bus/utils.ts | 36 ++-- packages/core/utils/src/fulfillment/events.ts | 101 ++++++++++- packages/core/utils/src/inventory/events.ts | 31 ++++ .../core/utils/src/notification/events.ts | 15 ++ packages/core/utils/src/pricing/events.ts | 47 +++++ packages/core/utils/src/product/events.ts | 79 +++++++++ packages/core/utils/src/user/events.ts | 28 ++- packages/modules/event-bus-redis/package.json | 4 +- .../src/services/event-bus-redis.ts | 14 ++ .../event-bus-redis/src/types/index.ts | 9 + packages/plugins/draft-order/index.d.ts | 1 + packages/plugins/draft-order/src/index.ts | 1 + yarn.lock | 2 + 21 files changed, 593 insertions(+), 65 deletions(-) create mode 100644 .changeset/cold-lamps-search.md create mode 100644 packages/plugins/draft-order/index.d.ts create mode 100644 packages/plugins/draft-order/src/index.ts diff --git a/.changeset/cold-lamps-search.md b/.changeset/cold-lamps-search.md new file mode 100644 index 0000000000..523ab77209 --- /dev/null +++ b/.changeset/cold-lamps-search.md @@ -0,0 +1,10 @@ +--- +"@medusajs/event-bus-redis": patch +"@medusajs/draft-order": patch +"@medusajs/framework": patch +"@medusajs/types": patch +"@medusajs/utils": patch +--- + +Feat/enable event configuration in medusa config +enables event priority configuration through the Medusa config, allowing users to configure event processing options (like priority) for specific events at the module level. diff --git a/packages/core/framework/package.json b/packages/core/framework/package.json index 2e2dbccbbc..132dea937f 100644 --- a/packages/core/framework/package.json +++ b/packages/core/framework/package.json @@ -27,7 +27,10 @@ "./telemetry": "./dist/telemetry/index.js", "./feature-flags": "./dist/feature-flags/index.js", "./utils": "./dist/utils/index.js", - "./types": "./dist/types/index.js", + "./types": { + "types": "./dist/types/index.d.ts", + "default": "./dist/types/index.js" + }, "./build-tools": "./dist/build-tools/index.js", "./orchestration": "./dist/orchestration/index.js", "./workflows-sdk": "./dist/workflows-sdk/index.js", diff --git a/packages/core/framework/src/types/index.ts b/packages/core/framework/src/types/index.ts index 3ae396411a..89bac2552a 100644 --- a/packages/core/framework/src/types/index.ts +++ b/packages/core/framework/src/types/index.ts @@ -1 +1,8 @@ +import "@medusajs/utils" export * from "@medusajs/types" + +import type { ModuleOptions as ModuleOptionsType } from "@medusajs/types" + +// Re-declare ModuleOptions to enable augmentation from @medusajs/framework/types +// EventBusEventsOptions is exported via "export *" and gets augmentations from @medusajs/utils +export interface ModuleOptions extends ModuleOptionsType {} diff --git a/packages/core/framework/src/utils/index.ts b/packages/core/framework/src/utils/index.ts index 02ef2b162e..13149ef58d 100644 --- a/packages/core/framework/src/utils/index.ts +++ b/packages/core/framework/src/utils/index.ts @@ -1,3 +1,5 @@ +import "@medusajs/types" +import "@medusajs/utils" import "../types/container" export * from "@medusajs/utils" diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index 1dde30f1e1..52561e31d2 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -1139,32 +1139,30 @@ type ExternalModuleDeclarationOverride = ExternalModuleDeclaration & { disable?: boolean } -/** - * Generates a union of typed module configs for all known modules in the ModuleOptions registry. - * This enables automatic type inference when using registered module resolve strings. - */ -type KnownModuleConfigs = { - [K in keyof ModuleOptions]: Partial< - Omit & { +type ModuleConfigForResolve = R extends keyof ModuleOptions + ? { + resolve: R key?: string disable?: boolean - resolve: K - options?: ModuleOptions[K] - } - > -}[keyof ModuleOptions] + options?: ModuleOptions[R] + } & Partial> + : { + resolve?: string + key?: string + disable?: boolean + options?: object + } & Partial> + +/** + * Generates a union of typed module configs for all known modules in the ModuleOptions registry. + * This distributes over all keys in ModuleOptions to create specific config types for each. + */ +type KnownModuleConfigs = ModuleConfigForResolve /** * Generic module config for modules not registered in ModuleOptions. */ -type GenericModuleConfig = Partial< - Omit & { - key?: string - disable?: boolean - resolve?: string - options?: Record - } -> +type GenericModuleConfig = ModuleConfigForResolve /** * Modules accepted by the defineConfig function. @@ -1177,20 +1175,36 @@ export type InputConfigModules = ( )[] /** - * The configuration accepted by the "defineConfig" helper + * Base configuration type without modules */ -export type InputConfig = Partial< +type InputConfigBase = Partial< Omit & { admin?: Partial - modules: - | InputConfigModules - /** - * @deprecated use the array instead - */ - | ConfigModule["modules"] } > +/** + * Configuration with array-based modules (recommended) + */ +export type InputConfigWithArrayModules = InputConfigBase & { + modules?: InputConfigModules +} + +/** + * Configuration with object-based modules (deprecated) + * @deprecated Use array-based modules instead + */ +export type InputConfigWithObjectModules = InputConfigBase & { + modules?: ConfigModule["modules"] +} + +/** + * The configuration accepted by the "defineConfig" helper + */ +export type InputConfig = + | InputConfigWithArrayModules + | InputConfigWithObjectModules + type PluginAdminDetails = { type: "local" | "package" resolve: string diff --git a/packages/core/types/src/event-bus/common.ts b/packages/core/types/src/event-bus/common.ts index 0cc3953b6b..8fd03c1dca 100644 --- a/packages/core/types/src/event-bus/common.ts +++ b/packages/core/types/src/event-bus/common.ts @@ -1,5 +1,27 @@ import { Context } from "../shared-context" +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// /** +// * Configuration options for individual events. +// */ +// export interface EventOptions { +// /** +// * Priority level for the event processing. +// * Lower numbers indicate higher priority. +// */ +// priority?: number +// } + +// /** +// * Registry for event bus events options types. +// * Events will be added to this registry to serve as a global configuration for all events +// * as part of the event bus module service module options. +// * +// * Modules augment this interface using declaration merging to register their event configurations. +// * Custom events can be added via declaration merging in your project. +// */ +// export interface EventBusEventsOptions {} + export type Subscriber = (data: Event) => Promise export type SubscriberContext = { diff --git a/packages/core/utils/src/common/define-config.ts b/packages/core/utils/src/common/define-config.ts index 26e88f36a8..97e136589e 100644 --- a/packages/core/utils/src/common/define-config.ts +++ b/packages/core/utils/src/common/define-config.ts @@ -3,6 +3,8 @@ import { ConfigModule, InputConfig, InputConfigModules, + InputConfigWithArrayModules, + InputConfigWithObjectModules, InternalModuleDeclaration, MedusaCloudOptions, } from "@medusajs/types" @@ -43,6 +45,15 @@ export const DEFAULT_STORE_RESTRICTED_FIELDS = [ * make an application work seamlessly, but still provide you the ability * to override configuration as needed. */ +export function defineConfig( + config?: InputConfigWithArrayModules +): ConfigModule +/** + * @deprecated Use array-based modules configuration instead + */ +export function defineConfig( + config?: InputConfigWithObjectModules +): ConfigModule export function defineConfig(config: InputConfig = {}): ConfigModule { const options = { isCloud: process.env.EXECUTION_CONTEXT === MEDUSA_CLOUD_EXECUTION_CONTEXT, diff --git a/packages/core/utils/src/core-flows/events.ts b/packages/core/utils/src/core-flows/events.ts index e011982e96..152cce1314 100644 --- a/packages/core/utils/src/core-flows/events.ts +++ b/packages/core/utils/src/core-flows/events.ts @@ -1,3 +1,6 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" + /** * @category Cart * @customNamespace Cart @@ -63,7 +66,7 @@ export const CartWorkflowEvents = { * ``` */ CUSTOMER_TRANSFERRED: "cart.customer_transferred", -} +} as const /** * @category Customer @@ -103,7 +106,7 @@ export const CustomerWorkflowEvents = { * ``` */ DELETED: "customer.deleted", -} +} as const /** * @category Order @@ -259,7 +262,7 @@ export const OrderWorkflowEvents = { * ``` */ TRANSFER_REQUESTED: "order.transfer_requested", -} +} as const /** * @category Order Edit @@ -308,7 +311,7 @@ export const OrderEditWorkflowEvents = { * ``` */ CANCELED: "order-edit.canceled", -} +} as const /** * @category User @@ -348,7 +351,7 @@ export const UserWorkflowEvents = { * ``` */ DELETED: "user.deleted", -} +} as const /** * @category Auth @@ -370,7 +373,7 @@ export const AuthWorkflowEvents = { * ``` */ PASSWORD_RESET: "auth.password_reset", -} +} as const /** * @category Sales Channel @@ -410,7 +413,7 @@ export const SalesChannelWorkflowEvents = { * ``` */ DELETED: "sales-channel.deleted", -} +} as const /** * @category Product Category @@ -450,7 +453,7 @@ export const ProductCategoryWorkflowEvents = { * ``` */ DELETED: "product-category.deleted", -} +} as const /** * @category Product Collection @@ -490,7 +493,7 @@ export const ProductCollectionWorkflowEvents = { * ``` */ DELETED: "product-collection.deleted", -} +} as const /** * @category Product Variant @@ -530,7 +533,7 @@ export const ProductVariantWorkflowEvents = { * ``` */ DELETED: "product-variant.deleted", -} +} as const /** * @category Product @@ -570,7 +573,7 @@ export const ProductWorkflowEvents = { * ``` */ DELETED: "product.deleted", -} +} as const /** * @category Product Type @@ -610,7 +613,7 @@ export const ProductTypeWorkflowEvents = { * ``` */ DELETED: "product-type.deleted", -} +} as const /** * @category Product Tag @@ -650,7 +653,7 @@ export const ProductTagWorkflowEvents = { * ``` */ DELETED: "product-tag.deleted", -} +} as const /** * @category Product Option @@ -690,7 +693,7 @@ export const ProductOptionWorkflowEvents = { * ``` */ DELETED: "product-option.deleted", -} +} as const /** * @category Invite @@ -744,7 +747,7 @@ export const InviteWorkflowEvents = { * ``` */ RESENT: "invite.resent", -} +} as const /** * @category Region @@ -784,7 +787,7 @@ export const RegionWorkflowEvents = { * ``` */ DELETED: "region.deleted", -} +} as const /** * @category Fulfillment @@ -814,7 +817,7 @@ export const FulfillmentWorkflowEvents = { * ``` */ DELIVERY_CREATED: "delivery.created", -} +} as const /** * @category Shipping Option Type @@ -860,7 +863,7 @@ export const ShippingOptionTypeWorkflowEvents = { * ``` */ DELETED: "shipping-option-type.deleted", -} +} as const /** * @category Shipping Option @@ -906,7 +909,7 @@ export const ShippingOptionWorkflowEvents = { * ``` */ DELETED: "shipping-option.deleted", -} +} as const /** * @category Payment @@ -935,7 +938,7 @@ export const PaymentEvents = { * ``` */ REFUNDED: "payment.refunded", -} +} as const /** * @category Translation @@ -981,4 +984,122 @@ export const TranslationWorkflowEvents = { * ``` */ DELETED: "translation.deleted", -} +} as const + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Cart events +// [CartWorkflowEvents.CREATED]?: EventOptions +// [CartWorkflowEvents.UPDATED]?: EventOptions +// [CartWorkflowEvents.CUSTOMER_UPDATED]?: EventOptions +// [CartWorkflowEvents.REGION_UPDATED]?: EventOptions +// [CartWorkflowEvents.CUSTOMER_TRANSFERRED]?: EventOptions + +// // Customer events +// [CustomerWorkflowEvents.CREATED]?: EventOptions +// [CustomerWorkflowEvents.UPDATED]?: EventOptions +// [CustomerWorkflowEvents.DELETED]?: EventOptions + +// // Order events +// [OrderWorkflowEvents.UPDATED]?: EventOptions +// [OrderWorkflowEvents.PLACED]?: EventOptions +// [OrderWorkflowEvents.CANCELED]?: EventOptions +// [OrderWorkflowEvents.COMPLETED]?: EventOptions +// [OrderWorkflowEvents.ARCHIVED]?: EventOptions +// [OrderWorkflowEvents.FULFILLMENT_CREATED]?: EventOptions +// [OrderWorkflowEvents.FULFILLMENT_CANCELED]?: EventOptions +// [OrderWorkflowEvents.RETURN_REQUESTED]?: EventOptions +// [OrderWorkflowEvents.RETURN_RECEIVED]?: EventOptions +// [OrderWorkflowEvents.CLAIM_CREATED]?: EventOptions +// [OrderWorkflowEvents.EXCHANGE_CREATED]?: EventOptions +// [OrderWorkflowEvents.TRANSFER_REQUESTED]?: EventOptions + +// // Order Edit events +// [OrderEditWorkflowEvents.REQUESTED]?: EventOptions +// [OrderEditWorkflowEvents.CONFIRMED]?: EventOptions +// [OrderEditWorkflowEvents.CANCELED]?: EventOptions + +// // User events +// [UserWorkflowEvents.CREATED]?: EventOptions +// [UserWorkflowEvents.UPDATED]?: EventOptions +// [UserWorkflowEvents.DELETED]?: EventOptions + +// // Auth events +// [AuthWorkflowEvents.PASSWORD_RESET]?: EventOptions + +// // Sales Channel events +// [SalesChannelWorkflowEvents.CREATED]?: EventOptions +// [SalesChannelWorkflowEvents.UPDATED]?: EventOptions +// [SalesChannelWorkflowEvents.DELETED]?: EventOptions + +// // Product Category events +// [ProductCategoryWorkflowEvents.CREATED]?: EventOptions +// [ProductCategoryWorkflowEvents.UPDATED]?: EventOptions +// [ProductCategoryWorkflowEvents.DELETED]?: EventOptions + +// // Product Collection events +// [ProductCollectionWorkflowEvents.CREATED]?: EventOptions +// [ProductCollectionWorkflowEvents.UPDATED]?: EventOptions +// [ProductCollectionWorkflowEvents.DELETED]?: EventOptions + +// // Product Variant events +// [ProductVariantWorkflowEvents.CREATED]?: EventOptions +// [ProductVariantWorkflowEvents.UPDATED]?: EventOptions +// [ProductVariantWorkflowEvents.DELETED]?: EventOptions + +// // Product events +// [ProductWorkflowEvents.CREATED]?: EventOptions +// [ProductWorkflowEvents.UPDATED]?: EventOptions +// [ProductWorkflowEvents.DELETED]?: EventOptions + +// // Product Type events +// [ProductTypeWorkflowEvents.CREATED]?: EventOptions +// [ProductTypeWorkflowEvents.UPDATED]?: EventOptions +// [ProductTypeWorkflowEvents.DELETED]?: EventOptions + +// // Product Tag events +// [ProductTagWorkflowEvents.CREATED]?: EventOptions +// [ProductTagWorkflowEvents.UPDATED]?: EventOptions +// [ProductTagWorkflowEvents.DELETED]?: EventOptions + +// // Product Option events +// [ProductOptionWorkflowEvents.CREATED]?: EventOptions +// [ProductOptionWorkflowEvents.UPDATED]?: EventOptions +// [ProductOptionWorkflowEvents.DELETED]?: EventOptions + +// // Invite events +// [InviteWorkflowEvents.ACCEPTED]?: EventOptions +// [InviteWorkflowEvents.CREATED]?: EventOptions +// [InviteWorkflowEvents.DELETED]?: EventOptions +// [InviteWorkflowEvents.RESENT]?: EventOptions + +// // Region events +// [RegionWorkflowEvents.CREATED]?: EventOptions +// [RegionWorkflowEvents.UPDATED]?: EventOptions +// [RegionWorkflowEvents.DELETED]?: EventOptions + +// // Fulfillment events +// [FulfillmentWorkflowEvents.SHIPMENT_CREATED]?: EventOptions +// [FulfillmentWorkflowEvents.DELIVERY_CREATED]?: EventOptions + +// // Shipping Option Type events +// [ShippingOptionTypeWorkflowEvents.CREATED]?: EventOptions +// [ShippingOptionTypeWorkflowEvents.UPDATED]?: EventOptions +// [ShippingOptionTypeWorkflowEvents.DELETED]?: EventOptions + +// // Shipping Option events +// [ShippingOptionWorkflowEvents.CREATED]?: EventOptions +// [ShippingOptionWorkflowEvents.UPDATED]?: EventOptions +// [ShippingOptionWorkflowEvents.DELETED]?: EventOptions + +// // Payment events +// [PaymentEvents.CAPTURED]?: EventOptions +// [PaymentEvents.REFUNDED]?: EventOptions + +// // Translation events +// [TranslationWorkflowEvents.CREATED]?: EventOptions +// [TranslationWorkflowEvents.UPDATED]?: EventOptions +// [TranslationWorkflowEvents.DELETED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/event-bus/utils.ts b/packages/core/utils/src/event-bus/utils.ts index be32b232f4..f97b0da8c3 100644 --- a/packages/core/utils/src/event-bus/utils.ts +++ b/packages/core/utils/src/event-bus/utils.ts @@ -2,30 +2,42 @@ import { KebabCase, SnakeCase } from "@medusajs/types" import { camelToSnakeCase, kebabCase, lowerCaseFirst } from "../common" import { CommonEvents } from "./common-events" -type ReturnType = { +type ReturnType = { [K in TNames[number] as `${Uppercase< SnakeCase - >}_CREATED`]: `${KebabCase}.created` + >}_CREATED`]: TPrefix extends "" + ? `${KebabCase}.created` + : `${TPrefix}.${KebabCase}.created` } & { [K in TNames[number] as `${Uppercase< SnakeCase - >}_UPDATED`]: `${KebabCase}.updated` + >}_UPDATED`]: TPrefix extends "" + ? `${KebabCase}.updated` + : `${TPrefix}.${KebabCase}.updated` } & { [K in TNames[number] as `${Uppercase< SnakeCase - >}_DELETED`]: `${KebabCase}.deleted` + >}_DELETED`]: TPrefix extends "" + ? `${KebabCase}.deleted` + : `${TPrefix}.${KebabCase}.deleted` } & { [K in TNames[number] as `${Uppercase< SnakeCase - >}_RESTORED`]: `${KebabCase}.restored` + >}_RESTORED`]: TPrefix extends "" + ? `${KebabCase}.restored` + : `${TPrefix}.${KebabCase}.restored` } & { [K in TNames[number] as `${Uppercase< SnakeCase - >}_ATTACHED`]: `${KebabCase}.attached` + >}_ATTACHED`]: TPrefix extends "" + ? `${KebabCase}.attached` + : `${TPrefix}.${KebabCase}.attached` } & { [K in TNames[number] as `${Uppercase< SnakeCase - >}_DETACHED`]: `${KebabCase}.detached` + >}_DETACHED`]: TPrefix extends "" + ? `${KebabCase}.detached` + : `${TPrefix}.${KebabCase}.detached` } /** @@ -64,10 +76,10 @@ export function buildModuleResourceEventName({ * @param names * @param prefix */ -export function buildEventNamesFromEntityName( - names: TNames, - prefix?: string -): ReturnType { +export function buildEventNamesFromEntityName< + TNames extends string[], + TPrefix extends string = "" +>(names: TNames, prefix?: TPrefix): ReturnType { const events = {} for (let i = 0; i < names.length; i++) { @@ -85,7 +97,7 @@ export function buildEventNamesFromEntityName( } } - return events as ReturnType + return events as ReturnType } export const EventPriority = { diff --git a/packages/core/utils/src/fulfillment/events.ts b/packages/core/utils/src/fulfillment/events.ts index c89dd3f503..99496a9577 100644 --- a/packages/core/utils/src/fulfillment/events.ts +++ b/packages/core/utils/src/fulfillment/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -37,4 +39,101 @@ export const FulfillmentEvents = { * @deprecated use `FulfillmentWorkflowEvents.DELIVERY_CREATED` instead */ DELIVERY_CREATED: "delivery.created", -} +} as const + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Fulfillment Set events +// [FulfillmentEvents.FULFILLMENT_SET_CREATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_SET_UPDATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_SET_DELETED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_SET_RESTORED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_SET_ATTACHED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_SET_DETACHED]?: EventOptions + +// // Service Zone events +// [FulfillmentEvents.SERVICE_ZONE_CREATED]?: EventOptions +// [FulfillmentEvents.SERVICE_ZONE_UPDATED]?: EventOptions +// [FulfillmentEvents.SERVICE_ZONE_DELETED]?: EventOptions +// [FulfillmentEvents.SERVICE_ZONE_RESTORED]?: EventOptions +// [FulfillmentEvents.SERVICE_ZONE_ATTACHED]?: EventOptions +// [FulfillmentEvents.SERVICE_ZONE_DETACHED]?: EventOptions + +// // Geo Zone events +// [FulfillmentEvents.GEO_ZONE_CREATED]?: EventOptions +// [FulfillmentEvents.GEO_ZONE_UPDATED]?: EventOptions +// [FulfillmentEvents.GEO_ZONE_DELETED]?: EventOptions +// [FulfillmentEvents.GEO_ZONE_RESTORED]?: EventOptions +// [FulfillmentEvents.GEO_ZONE_ATTACHED]?: EventOptions +// [FulfillmentEvents.GEO_ZONE_DETACHED]?: EventOptions + +// // Shipping Option events +// [FulfillmentEvents.SHIPPING_OPTION_CREATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_UPDATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_DELETED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RESTORED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_ATTACHED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_DETACHED]?: EventOptions + +// // Shipping Option Type events +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_UPDATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_DELETED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_RESTORED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_ATTACHED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_TYPE_DETACHED]?: EventOptions + +// // Shipping Profile events +// [FulfillmentEvents.SHIPPING_PROFILE_CREATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_PROFILE_UPDATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_PROFILE_DELETED]?: EventOptions +// [FulfillmentEvents.SHIPPING_PROFILE_RESTORED]?: EventOptions +// [FulfillmentEvents.SHIPPING_PROFILE_ATTACHED]?: EventOptions +// [FulfillmentEvents.SHIPPING_PROFILE_DETACHED]?: EventOptions + +// // Shipping Option Rule events +// [FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RULE_UPDATED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RULE_DELETED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RULE_RESTORED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RULE_ATTACHED]?: EventOptions +// [FulfillmentEvents.SHIPPING_OPTION_RULE_DETACHED]?: EventOptions + +// // Fulfillment events +// [FulfillmentEvents.FULFILLMENT_CREATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_UPDATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_DELETED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_RESTORED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ATTACHED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_DETACHED]?: EventOptions + +// // Fulfillment Address events +// [FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ADDRESS_UPDATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ADDRESS_DELETED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ADDRESS_RESTORED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ADDRESS_ATTACHED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ADDRESS_DETACHED]?: EventOptions + +// // Fulfillment Item events +// [FulfillmentEvents.FULFILLMENT_ITEM_CREATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ITEM_UPDATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ITEM_DELETED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ITEM_RESTORED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ITEM_ATTACHED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_ITEM_DETACHED]?: EventOptions + +// // Fulfillment Label events +// [FulfillmentEvents.FULFILLMENT_LABEL_CREATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_LABEL_UPDATED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_LABEL_DELETED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_LABEL_RESTORED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_LABEL_ATTACHED]?: EventOptions +// [FulfillmentEvents.FULFILLMENT_LABEL_DETACHED]?: EventOptions + +// // Deprecated events +// [FulfillmentEvents.SHIPMENT_CREATED]?: EventOptions +// [FulfillmentEvents.DELIVERY_CREATED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/inventory/events.ts b/packages/core/utils/src/inventory/events.ts index d20a8fe586..d2de84ebae 100644 --- a/packages/core/utils/src/inventory/events.ts +++ b/packages/core/utils/src/inventory/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -11,3 +13,32 @@ export const InventoryEvents = buildEventNamesFromEntityName( eventBaseNames, Modules.INVENTORY ) + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Inventory Item events +// [InventoryEvents.INVENTORY_ITEM_CREATED]?: EventOptions +// [InventoryEvents.INVENTORY_ITEM_UPDATED]?: EventOptions +// [InventoryEvents.INVENTORY_ITEM_DELETED]?: EventOptions +// [InventoryEvents.INVENTORY_ITEM_RESTORED]?: EventOptions +// [InventoryEvents.INVENTORY_ITEM_ATTACHED]?: EventOptions +// [InventoryEvents.INVENTORY_ITEM_DETACHED]?: EventOptions + +// // Reservation Item events +// [InventoryEvents.RESERVATION_ITEM_CREATED]?: EventOptions +// [InventoryEvents.RESERVATION_ITEM_UPDATED]?: EventOptions +// [InventoryEvents.RESERVATION_ITEM_DELETED]?: EventOptions +// [InventoryEvents.RESERVATION_ITEM_RESTORED]?: EventOptions +// [InventoryEvents.RESERVATION_ITEM_ATTACHED]?: EventOptions +// [InventoryEvents.RESERVATION_ITEM_DETACHED]?: EventOptions + +// // Inventory Level events +// [InventoryEvents.INVENTORY_LEVEL_CREATED]?: EventOptions +// [InventoryEvents.INVENTORY_LEVEL_UPDATED]?: EventOptions +// [InventoryEvents.INVENTORY_LEVEL_DELETED]?: EventOptions +// [InventoryEvents.INVENTORY_LEVEL_RESTORED]?: EventOptions +// [InventoryEvents.INVENTORY_LEVEL_ATTACHED]?: EventOptions +// [InventoryEvents.INVENTORY_LEVEL_DETACHED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/notification/events.ts b/packages/core/utils/src/notification/events.ts index 836e237e33..0c72153e95 100644 --- a/packages/core/utils/src/notification/events.ts +++ b/packages/core/utils/src/notification/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -7,3 +9,16 @@ export const NotificationEvents = buildEventNamesFromEntityName( eventBaseNames, Modules.NOTIFICATION ) + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Notification events +// [NotificationEvents.NOTIFICATION_CREATED]?: EventOptions +// [NotificationEvents.NOTIFICATION_UPDATED]?: EventOptions +// [NotificationEvents.NOTIFICATION_DELETED]?: EventOptions +// [NotificationEvents.NOTIFICATION_RESTORED]?: EventOptions +// [NotificationEvents.NOTIFICATION_ATTACHED]?: EventOptions +// [NotificationEvents.NOTIFICATION_DETACHED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/pricing/events.ts b/packages/core/utils/src/pricing/events.ts index dfcfa584ec..a2a8b88fe0 100644 --- a/packages/core/utils/src/pricing/events.ts +++ b/packages/core/utils/src/pricing/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -13,3 +15,48 @@ export const PricingEvents = buildEventNamesFromEntityName( eventBaseNames, Modules.PRICING ) + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Price List Rule events +// [PricingEvents.PRICE_LIST_RULE_CREATED]?: EventOptions +// [PricingEvents.PRICE_LIST_RULE_UPDATED]?: EventOptions +// [PricingEvents.PRICE_LIST_RULE_DELETED]?: EventOptions +// [PricingEvents.PRICE_LIST_RULE_RESTORED]?: EventOptions +// [PricingEvents.PRICE_LIST_RULE_ATTACHED]?: EventOptions +// [PricingEvents.PRICE_LIST_RULE_DETACHED]?: EventOptions + +// // Price List events +// [PricingEvents.PRICE_LIST_CREATED]?: EventOptions +// [PricingEvents.PRICE_LIST_UPDATED]?: EventOptions +// [PricingEvents.PRICE_LIST_DELETED]?: EventOptions +// [PricingEvents.PRICE_LIST_RESTORED]?: EventOptions +// [PricingEvents.PRICE_LIST_ATTACHED]?: EventOptions +// [PricingEvents.PRICE_LIST_DETACHED]?: EventOptions + +// // Price Rule events +// [PricingEvents.PRICE_RULE_CREATED]?: EventOptions +// [PricingEvents.PRICE_RULE_UPDATED]?: EventOptions +// [PricingEvents.PRICE_RULE_DELETED]?: EventOptions +// [PricingEvents.PRICE_RULE_RESTORED]?: EventOptions +// [PricingEvents.PRICE_RULE_ATTACHED]?: EventOptions +// [PricingEvents.PRICE_RULE_DETACHED]?: EventOptions + +// // Price Set events +// [PricingEvents.PRICE_SET_CREATED]?: EventOptions +// [PricingEvents.PRICE_SET_UPDATED]?: EventOptions +// [PricingEvents.PRICE_SET_DELETED]?: EventOptions +// [PricingEvents.PRICE_SET_RESTORED]?: EventOptions +// [PricingEvents.PRICE_SET_ATTACHED]?: EventOptions +// [PricingEvents.PRICE_SET_DETACHED]?: EventOptions + +// // Price events +// [PricingEvents.PRICE_CREATED]?: EventOptions +// [PricingEvents.PRICE_UPDATED]?: EventOptions +// [PricingEvents.PRICE_DELETED]?: EventOptions +// [PricingEvents.PRICE_RESTORED]?: EventOptions +// [PricingEvents.PRICE_ATTACHED]?: EventOptions +// [PricingEvents.PRICE_DETACHED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/product/events.ts b/packages/core/utils/src/product/events.ts index 64c1ff2a39..08d44453e5 100644 --- a/packages/core/utils/src/product/events.ts +++ b/packages/core/utils/src/product/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -27,3 +29,80 @@ export const ProductEvents = buildEventNamesFromEntityName( eventBaseNames, Modules.PRODUCT ) + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // Product events +// [ProductEvents.PRODUCT_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_DETACHED]?: EventOptions + +// // Product Variant events +// [ProductEvents.PRODUCT_VARIANT_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_VARIANT_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_VARIANT_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_VARIANT_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_VARIANT_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_VARIANT_DETACHED]?: EventOptions + +// // Product Option events +// [ProductEvents.PRODUCT_OPTION_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_DETACHED]?: EventOptions + +// // Product Option Value events +// [ProductEvents.PRODUCT_OPTION_VALUE_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_VALUE_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_VALUE_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_VALUE_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_VALUE_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_OPTION_VALUE_DETACHED]?: EventOptions + +// // Product Type events +// [ProductEvents.PRODUCT_TYPE_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_TYPE_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_TYPE_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_TYPE_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_TYPE_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_TYPE_DETACHED]?: EventOptions + +// // Product Tag events +// [ProductEvents.PRODUCT_TAG_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_TAG_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_TAG_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_TAG_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_TAG_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_TAG_DETACHED]?: EventOptions + +// // Product Category events +// [ProductEvents.PRODUCT_CATEGORY_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_CATEGORY_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_CATEGORY_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_CATEGORY_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_CATEGORY_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_CATEGORY_DETACHED]?: EventOptions + +// // Product Collection events +// [ProductEvents.PRODUCT_COLLECTION_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_COLLECTION_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_COLLECTION_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_COLLECTION_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_COLLECTION_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_COLLECTION_DETACHED]?: EventOptions + +// // Product Image events +// [ProductEvents.PRODUCT_IMAGE_CREATED]?: EventOptions +// [ProductEvents.PRODUCT_IMAGE_UPDATED]?: EventOptions +// [ProductEvents.PRODUCT_IMAGE_DELETED]?: EventOptions +// [ProductEvents.PRODUCT_IMAGE_RESTORED]?: EventOptions +// [ProductEvents.PRODUCT_IMAGE_ATTACHED]?: EventOptions +// [ProductEvents.PRODUCT_IMAGE_DETACHED]?: EventOptions +// } +// } diff --git a/packages/core/utils/src/user/events.ts b/packages/core/utils/src/user/events.ts index 49a70d339a..7b00765696 100644 --- a/packages/core/utils/src/user/events.ts +++ b/packages/core/utils/src/user/events.ts @@ -1,3 +1,5 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import { EventOptions } from "@medusajs/types" import { buildEventNamesFromEntityName } from "../event-bus" import { Modules } from "../modules-sdk" @@ -6,4 +8,28 @@ const eventBaseNames: ["user", "invite"] = ["user", "invite"] export const UserEvents = { ...buildEventNamesFromEntityName(eventBaseNames, Modules.USER), INVITE_TOKEN_GENERATED: `${Modules.USER}.user.invite.token_generated`, -} +} as const + +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// declare module "@medusajs/types" { +// export interface EventBusEventsOptions { +// // User events +// [UserEvents.USER_CREATED]?: EventOptions +// [UserEvents.USER_UPDATED]?: EventOptions +// [UserEvents.USER_DELETED]?: EventOptions +// [UserEvents.USER_RESTORED]?: EventOptions +// [UserEvents.USER_ATTACHED]?: EventOptions +// [UserEvents.USER_DETACHED]?: EventOptions + +// // Invite events +// [UserEvents.INVITE_CREATED]?: EventOptions +// [UserEvents.INVITE_UPDATED]?: EventOptions +// [UserEvents.INVITE_DELETED]?: EventOptions +// [UserEvents.INVITE_RESTORED]?: EventOptions +// [UserEvents.INVITE_ATTACHED]?: EventOptions +// [UserEvents.INVITE_DETACHED]?: EventOptions + +// // Custom events +// [UserEvents.INVITE_TOKEN_GENERATED]?: EventOptions +// } +// } diff --git a/packages/modules/event-bus-redis/package.json b/packages/modules/event-bus-redis/package.json index 3845e6916a..d775ccce32 100644 --- a/packages/modules/event-bus-redis/package.json +++ b/packages/modules/event-bus-redis/package.json @@ -23,7 +23,9 @@ "author": "Medusa", "license": "MIT", "devDependencies": { - "@medusajs/framework": "2.12.5" + "@medusajs/framework": "2.12.5", + "@medusajs/types": "2.12.5", + "@medusajs/utils": "2.12.5" }, "scripts": { "watch": "yarn run -T tsc --build --watch", diff --git a/packages/modules/event-bus-redis/src/services/event-bus-redis.ts b/packages/modules/event-bus-redis/src/services/event-bus-redis.ts index f6a56d3dfe..880f88b6d5 100644 --- a/packages/modules/event-bus-redis/src/services/event-bus-redis.ts +++ b/packages/modules/event-bus-redis/src/services/event-bus-redis.ts @@ -1,5 +1,7 @@ import { Event, + // TODO: Comment temporarely and we will re enable it in the near future #14478 + // EventBusEventsOptions, InternalModuleDeclaration, Logger, Message, @@ -53,6 +55,8 @@ export default class RedisEventBusService extends AbstractEventBusModuleService protected readonly queueOptions_: Omit protected readonly workerOptions_: Omit protected readonly jobOptions_: EmitOptions + // TODO: Comment temporarely and we will re enable it in the near future #14478 + // private readonly eventOptions_: EventBusEventsOptions protected queue_: Queue protected bullWorker_: Worker @@ -79,6 +83,11 @@ export default class RedisEventBusService extends AbstractEventBusModuleService this.queueOptions_ = eventBusRedisQueueOptions ?? {} this.workerOptions_ = eventBusRedisWorkerOptions ?? {} this.jobOptions_ = eventBusRedisJobOptions ?? {} + // TODO: Comment temporarely and we will re enable it in the near future #14478 + // this.eventOptions_ = + // _moduleOptions.eventOptions ?? + // _moduleDeclaration.options?.eventOptions ?? + // {} this.queue_ = new Queue(this.queueName_, { prefix: `${this.constructor.name}`, @@ -153,6 +162,11 @@ export default class RedisEventBusService extends AbstractEventBusModuleService ...eventData.options, } + // TODO: Comment temporarely and we will re enable it in the near future #14478 + // finalOptions.priority = + // eventData.options?.priority ?? + // this.eventOptions_[eventData.name]?.priority + if ( finalOptions.priority != undefined && (finalOptions.priority < 1 || diff --git a/packages/modules/event-bus-redis/src/types/index.ts b/packages/modules/event-bus-redis/src/types/index.ts index 80a4d92200..2b08f761e6 100644 --- a/packages/modules/event-bus-redis/src/types/index.ts +++ b/packages/modules/event-bus-redis/src/types/index.ts @@ -1,3 +1,10 @@ +// TODO: Comment temporarely and we will re enable it in the near future #14478 +// import type { EventBusEventsOptions } from "@medusajs/types" + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import type { ModuleOptions } from "@medusajs/types" + import { BulkJobOptions, Job, @@ -68,6 +75,8 @@ export type EventBusRedisModuleOptions = { * @see https://api.docs.bullmq.io/interfaces/BaseJobOptions.html */ jobOptions?: EmitOptions + + // eventOptions?: EventBusEventsOptions } declare module "@medusajs/types" { diff --git a/packages/plugins/draft-order/index.d.ts b/packages/plugins/draft-order/index.d.ts new file mode 100644 index 0000000000..e461d0e26e --- /dev/null +++ b/packages/plugins/draft-order/index.d.ts @@ -0,0 +1 @@ +// noop for typeRoots in compiler options diff --git a/packages/plugins/draft-order/src/index.ts b/packages/plugins/draft-order/src/index.ts new file mode 100644 index 0000000000..9b8078f214 --- /dev/null +++ b/packages/plugins/draft-order/src/index.ts @@ -0,0 +1 @@ +// noop, for compiler options diff --git a/yarn.lock b/yarn.lock index 7a82e7d7c7..496fe5a9ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3575,6 +3575,8 @@ __metadata: resolution: "@medusajs/event-bus-redis@workspace:packages/modules/event-bus-redis" dependencies: "@medusajs/framework": 2.12.5 + "@medusajs/types": 2.12.5 + "@medusajs/utils": 2.12.5 bullmq: 5.13.0 ioredis: ^5.4.1 peerDependencies: