Repository navigation
loyalty-plugin: let the application opt out of the plugin's core workflow hooks, and export its order workflows #17476
b0dea
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
@medusajs/loyalty-pluginregisters handlers on four core workflow hooks at module load. A hook takes one handler, so once the plugin is installed the application can't register its own handler on any of them, and the plugin has no option to leave them to the application. This is a narrower, plugin-level ask than #11968 (multiple handlers per hook, closed as not planned).src/workflows/hooks/)after-order-created.tscompleteCartWorkflow.hooks.orderCreatedcloneCartGiftCardsToOrderWorkflowcomplete-cart-before-payment-authorization.tscompleteCartWorkflow.hooks.beforePaymentAuthorizationconfirmCartCreditLinesWorkflowafter-order-credit-lines-created.tscreateOrderCreditLinesWorkflow.hooks.creditLinesCreatedrefundCreditLinesWorkflowbefore-payment-collection-refresh.tsrefreshCartItemsWorkflow.hooks.beforeRefreshingPaymentCollectionrefreshCartGiftCardsWorkflowRepro (2.22.0, same on
develop): register the plugin, then add any handler on one of those hooks:medusa developfails withCannot define multiple hook handlers for the orderCreated hook.The application also can't take a hook over and call the plugin's workflow from its own handler, because two of the four workflows aren't public:
@medusajs/loyalty-plugin/workflowsexportscarts,gift-cardsandstore-credit, but notorders, which holdscloneCartGiftCardsToOrderWorkflowandrefundCreditLinesWorkflow.Ask
registerHooks: false, or moving the registrations into an exported function the application calls (default behaviour unchanged). It would help if the docs then listed which workflows the application has to run from its own handlers.packages/plugins/loyalty/src/workflows/index.ts:export * from "./orders".How plugin options should reach module-load code is your call, so I've left the opt-out shape open.
Current workaround: a package patch that empties the plugin's four hook files and adds the
ordersexport, with our own single handler per hook running the plugin's workflows next to our logic. Patching compiled output has to be redone on every release, which is why we'd rather have a supported switch.All reactions