chore(): Module Internal Events (#13296)

* chore(): Ensure the product module emits all necessary events

* chore(): Ensure the product module emits all necessary events

* Update events tests

* more events and fixes

* more tests and category fixes

* more tests and category fixes

* Add todo

* update updateProduct_ event emitting and adjust test

* Adjust update products implementation to rely on already computed events

* rm unnecessary update variants events

* Fix formatting in changeset for product events

* refactor: Manage event emitting automatically (WIP)

* refactor: Manage event emitting automatically (WIP)

* chore(api-key): Add missing emit events and refactoring

* chore(cart): Add missing emit events and refactoring

* chore(customer): Add missing emit events and refactoring

* chore(fufillment, utils): Add missing emit events and refactoring

* chore(fufillment, utils): Add missing emit events and refactoring

* chore(inventory): Add missing emit events and refactoring

* chore(notification): Add missing emit events and refactoring

* chore(utils): Remove medusa service event handling legacy

* chore(product): Add missing emit events and refactoring

* chore(order): Add missing emit events and refactoring

* chore(payment): Add missing emit events and refactoring

* chore(pricing, util): Add missing emit events and refactoring, fix internal service upsertWithReplace event dispatching

* chore(promotions): Add missing emit events and refactoring

* chore(region): Add missing emit events and refactoring

* chore(sales-channel): Add missing emit events and refactoring

* chore(settings): Add missing emit events and refactoring

* chore(stock-location): Add missing emit events and refactoring

* chore(store): Add missing emit events and refactoring

* chore(taxes): Add missing emit events and refactoring

* chore(user): Add missing emit events and refactoring

* fix unit tests

* rm changeset for regeneration

* Create changeset for Medusa.js patch updates

Add a changeset for patch updates to multiple Medusa.js modules.

* rm unused product event builders

* address feedback

* remove old changeset

* fix event action for token generated

* fix user module events

* fix import

* fix promotion events

* add new module integration tests shard

* fix medusa service

* revert shard

* fix event action

* fix pipeline

* fix pipeline

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2025-09-10 14:37:38 +02:00
committed by GitHub
parent afe21741c4
commit e8822f3e69
55 changed files with 3614 additions and 2353 deletions

View File

@@ -7,6 +7,7 @@ import {
SettingsTypes,
} from "@medusajs/framework/types"
import {
EmitEvents,
InjectManager,
InjectTransactionManager,
MedusaContext,
@@ -50,7 +51,8 @@ export default class SettingsModuleService
this.userPreferenceService_ = userPreferenceService
}
@InjectTransactionManager()
@InjectManager()
@EmitEvents()
// @ts-expect-error
async createViewConfigurations(
data:
@@ -97,10 +99,14 @@ export default class SettingsModuleService
dataArray,
sharedContext
)
return isArrayInput ? result : result[0]
return await this.baseRepository_.serialize<
SettingsTypes.ViewConfigurationDTO[] | SettingsTypes.ViewConfigurationDTO
>(isArrayInput ? result : result[0])
}
@InjectTransactionManager()
@InjectManager()
@EmitEvents()
// @ts-expect-error
async updateViewConfigurations(
idOrSelector: string | SettingsTypes.FilterableViewConfigurationProps,
@@ -109,6 +115,25 @@ export default class SettingsModuleService
): Promise<
SettingsTypes.ViewConfigurationDTO | SettingsTypes.ViewConfigurationDTO[]
> {
const updated = await this.updateViewConfigurations_(
idOrSelector,
data,
sharedContext
)
const serialized = await this.baseRepository_.serialize<
SettingsTypes.ViewConfigurationDTO[] | SettingsTypes.ViewConfigurationDTO
>(updated)
return typeof idOrSelector === "string" ? serialized[0] : serialized
}
@InjectTransactionManager()
protected async updateViewConfigurations_(
idOrSelector: string | SettingsTypes.FilterableViewConfigurationProps,
data: SettingsTypes.UpdateViewConfigurationDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof ViewConfiguration>[]> {
let selector: SettingsTypes.FilterableViewConfigurationProps = {}
if (typeof idOrSelector === "string") {
@@ -164,11 +189,7 @@ export default class SettingsModuleService
sharedContext
)
const serialized = await this.baseRepository_.serialize<
SettingsTypes.ViewConfigurationDTO[]
>(updatedEntities, { populate: true })
return typeof idOrSelector === "string" ? serialized[0] : serialized
return updatedEntities
}
// For non-configuration updates, use the standard update method
@@ -177,11 +198,7 @@ export default class SettingsModuleService
sharedContext
)
const serialized = await this.baseRepository_.serialize<
SettingsTypes.ViewConfigurationDTO[]
>(updated, { populate: true })
return typeof idOrSelector === "string" ? serialized[0] : serialized
return updated as unknown as InferEntityType<typeof ViewConfiguration>[]
}
@InjectManager()
@@ -201,12 +218,12 @@ export default class SettingsModuleService
}
return await this.baseRepository_.serialize<SettingsTypes.UserPreferenceDTO>(
prefs[0],
{ populate: true }
prefs[0]
)
}
@InjectTransactionManager()
@InjectManager()
@EmitEvents()
async setUserPreference(
userId: string,
key: string,
@@ -236,8 +253,7 @@ export default class SettingsModuleService
}
return await this.baseRepository_.serialize<SettingsTypes.UserPreferenceDTO>(
result,
{ populate: true }
result
)
}
@@ -297,7 +313,8 @@ export default class SettingsModuleService
return systemDefaults.length > 0 ? systemDefaults[0] : null
}
@InjectTransactionManager()
@InjectManager()
@EmitEvents()
async setActiveViewConfiguration(
entity: string,
userId: string,
@@ -347,7 +364,8 @@ export default class SettingsModuleService
return systemDefaults.length > 0 ? systemDefaults[0] : null
}
@InjectTransactionManager()
@InjectManager()
@EmitEvents()
async clearActiveViewConfiguration(
entity: string,
userId: string,