v1.18.0
Highlights
Subscriber API + Scheduled Jobs API
This release comes with an improved Subscriber API and a new Scheduled Jobs API. These are drastic improvements of the developer experience of setting up event subscribers and cron jobs.
Subscriber API
// src/subscribers/product-update-handler.ts
import type { SubscriberConfig, SubscriberArgs, ProductService } from "@medusajs/medusa"
export default async function productUpdateHandler({ data, eventName, container, pluginOptions }: SubscriberArgs) {
const productService: ProductService = container.resolve("productService")
const { id } = data
const product = await productService.retrieve(id)
// do something with the product...
}
export const config: SubscriberConfig = {
event: ProductService.Events.UPDATE
}
Scheduled Jobs API
// src/jobs/once-a-minute.ts
import type { ProductService, ScheduledJobConfig, ScheduledJobArgs } from "@medusajs/medusa"
export default async function handler({ container, data, pluginOptions }: ScheduledJobArgs) {
const productService: ProductService = container.resolve("productService")
const count = await productService.count()
console.log(`You have ${count} products`)
}
export const config: ScheduledJobConfig = {
name: "every-minute",
schedule: "* * * * *"
}
Read more about the new APIs in the PR details.
Breaking changes
Changes to feature flags
This version significantly changes the feature flags in our core @medusajs/medusa
. We've decided to replace all module-specific feature flags with one that encapsulates all the work around modularizing Medusa further.
The following feature flags no longer exist:
Name | Flag | Environment variable |
---|---|---|
Product Module | isolate_product_domain |
MEDUSA_FF_ISOLATE_PRODUCT_DOMAIN |
Pricing Module | isolate_pricing_domain |
MEDUSA_FF_ISOLATE_PRICING_DOMAIN |
These feature flags have been replaced with one capturing all work for Medusa V2, releasing next year:
Name | Flag | Environment variable |
---|---|---|
Medusa V2 | medusa_v2 |
MEDUSA_FF_MEDUSA_V2 |
Creating a NotificationService
The introduction of the new Subscriber API changes the recommended way to define the subscribers of a NotificationService. The recommended approach is to use a loader until our Subscriber API natively supports NotificationServices or we introduce a mechanism dedicated towards it.
Read more here.
Features
- feat(pricing,types): price list API + price calculations with price lists by @riqwan in #5498
- feat(workflows,medusa,utils): add medusa v2 feature flag by @riqwan in #5603
- feat(medusa): Alternative Subscriber API and new ScheduledJobs API by @kasperkristensen in #5624
- feat(medusa): Add metadata to Product Category by @bqst in #5599
Bugs
- fix: minor fixes to IconButton and Button documentation by @kasperkristensen in #5636
- fix(admin-ui): Preserve decimal numbers when locale uses commas by @kasperkristensen in #5641
- fix(admin-ui): sort supported languages alphabetically by @VariableVic in #5479
- fix(medusa): Add missing promiseAll import by @chemicalkosek in #5635
- fix(medusa): Error handling middleware should be applied when no config is exported by @kasperkristensen in #5634
- fix(medusa): Update wrapHandler so it also passes errors in non-async route handlers to the errorHandler middleware by @kasperkristensen in #5597
- fix(ui): Fixed CodeBlock line number width by @kasperkristensen in #5640
- fix(product): when running migrations, prevent exploding on isolated case by @riqwan in #5643
Chores
- chore: add missing error responses to currency OAS by @shahednasser in #5627
- chore: change code owners of docs-util directory by @shahednasser in #5626
- chore: add TSDocs for IStockLocationService by @shahednasser in #5631
- chore(types): Add TSDoc comments to IInventoryService by @shahednasser in #5630
Documentation
- docs: update docusaurus to v3 by @shahednasser in #5625
- docs: added troubleshooting for postgres docker container by @shahednasser in #5629
- docs: add note about ttl in redis cache module by @shahednasser in #5617
- docs: generate inventory and stock location references by @shahednasser in #5645
New Contributors
- @VariableVic made their first contribution in #5479
Full Changelog: v1.17.4...v1.18.0