839 Commits

Author SHA1 Message Date
debashish
a34fcfab35 fix(): Remove redundant indexes to resolve schema warnings (#13736)
Fixes #13735

### What

This Pull Request introduces new database migrations to remove multiple redundant indexes across several core modules, including product, cart, order, customer, and inventory.

### Why

As detailed in issue #13735, a fresh Medusa installation produces numerous "Duplicate Index" warnings. These legacy indexes add unnecessary write overhead and provide no performance benefit. This PR cleans up the schema to resolve these warnings and improve database health.

### How

I have added one new, reversible migration file for each of the five affected modules:
- `@medusajs/product`
- `@medusajs/cart`
- `@medusajs/order`
- `@medusajs/customer`
- `@medusajs/inventory`

Each migration's `up()` method safely drops the older, redundant index, and its `down()` method re-creates it, ensuring the change is fully reversible and non-destructive.


### Testing

I have tested these migrations by following the local development workflow outlined in the `CONTRIBUTING.md` guide.

1.  **Setup:**
    *   Cloned my forked Medusa repository locally .
    *   Created a separate, fresh test project using `npx create-medusa-app@latest my-medusa-store`.
    *   The test project's PostgreSQL database, which already contained the schema with the duplicate indexes.

2.  **Linking Local Source Code:**
    *   In the test project's `package.json`, I modified all `@medusajs/*` dependencies and resolutions to point to the local packages in my forked repository (e.g., `"@medusajs/product": "file:../medusa/packages/modules/product"`).
    *   From the test project's directory, I ran `yarn install` to link the local, modified Medusa source code into its `node_modules`.

3.  **Build & Migration:**
    *   Inside my forked Medusa repository, I ran `yarn build` to compile the new TypeScript migration files.
    *   From the root of the **test project**, I then executed the migration command: `npx medusa migration run`.

4.  **Verification:**
    *   The command successfully identified and ran only the new migration files I had created.
    *   I also confirmed via direct SQL queries that the old, redundant indexes were correctly dropped from all affected tables (`product_collection`, `customer_group`, etc.).
2025-10-21 13:50:10 +00:00
github-actions[bot]
e47f0d0271 chore: Version Packages (#13545)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-10-21 09:24:59 +02:00
Shahed Nasser
150aa50397 feat(tax,types): Add method to retrieve a Tax Module Provider's service (#13784)
## Summary

**What** — What changes are introduced in this PR?

Add a method in the Tax Module's servie to retrieve a provider by its ID.

**Why** — Why are these changes relevant or necessary?  

The Tax Module Provider could be used for use cases other than calculating tax lines. For example, Avalara supports importing products to manage product-specific taxes. However, it's not possible right now to listen to the `product.created` event and create the product in Avalara with its provider. Instead, you'll have to create a separate module that also connects to Avalara and resolve it in the subsriber.

This also matches the pattern in the Analytics Module, which allows retrieving the underlying provider.

**How** — How have these changes been implemented?

Add a `getProvider` method to the Tax Module's service and its interface.

**Testing** — How have these changes been tested, or how can the reviewer test the feature?

Added integration test for the method.

---

## Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.  
This helps with documentation and ensures maintainers can quickly understand and verify the change.

```ts
const avalaraProvider = taxModuleService.getProvider("tp_avalara_avalara")
```

---

## Checklist

Please ensure the following before requesting a review:

- [x] I have added a **changeset** for this PR
    - Every non-breaking change should be marked as a **patch**
    - To add a changeset, run `yarn changeset` and follow the prompts
- [x] The changes are covered by relevant **tests**
- [x] I have verified the code works as intended locally
- [ ] I have linked the related issue(s) if applicable

---

## Additional Context

Add any additional context, related issues, or references that might help the reviewer understand this PR.
2025-10-20 16:18:48 +00:00
Adrien de Peretti
516f5a3896 fix: workflow async concurrency (#13769)
* executeAsync

* || 1

* wip

* stepId

* stepId

* wip

* wip

* continue versioning management changes

* fix and improve concurrency

* update in memory engine

* remove duplicated test

* fix script

* Create weak-drinks-confess.md

* fixes

* fix

* fix

* continuation

* centralize merge checkepoint

* centralize merge checkpoint

* fix locking

* rm only

* Continue improvements and fixes

* fixes

* fixes

* hasAwaiting will be recomputed

* fix orchestrator engine

* bump version on async parallel steps only

* mark as delivered fix

* changeset

* check partitions

* avoid saving when having parent step

* cart test

---------

Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-10-20 15:29:19 +02:00
Stevche Radevski
ee1c77a01f feat: Add support for multiple active keys at a time (#13754) 2025-10-16 10:07:08 +02:00
Oli Juhl
b5ecdfcd12 feat: Add allocation method type ONCE (#13700)
### What
Add a new `once` allocation strategy to promotions that limits application to a maximum number of items across the entire cart, rather than per line item.

### Why
Merchants want to create promotions that apply to a limited number of items across the entire cart. For example:
- "Get $10 off, applied to one item only"
- "20% off up to 2 items in your cart"

Current allocation strategies:
- `each`: Applies to each line item independently (respects `max_quantity` per item)
- `across`: Distributes proportionally across all items

Neither supports limiting total applications across the entire cart.

### How

Add `once` to the `ApplicationMethodAllocation` enum.

Behavior:
- Applies promotion to maximum `max_quantity` items across entire cart
- Always prioritizes lowest-priced eligible items first
- Distributes sequentially across items until quota exhausted
- Requires `max_quantity` field to be set

### Example Usage

**Scenario 1: Fixed discount**
```javascript
{
  type: "fixed",
  allocation: "once",
  value: 10,        // $10 off
  max_quantity: 2   // Apply to 2 items max across cart
}

Cart:
- Item A: 3 units @ $100/unit
- Item B: 5 units @ $50/unit (lowest price)

Result: $20 discount on Item B (2 units × $10)
```

**Scenario 2: Distribution across items**
```javascript
{
  type: "fixed",
  allocation: "once",
  value: 5,
  max_quantity: 4
}

Cart:
- Item A: 2 units @ $50/unit
- Item B: 3 units @ $60/unit

Result:
- Item A: $10 discount (2 units × $5)
- Item B: $10 discount (2 units × $5, remaining quota)
```

**Scenario 3: Percentage discount - single item**
```javascript
{
  type: "percentage",
  allocation: "once",
  value: 20,         // 20% off
  max_quantity: 3    // Apply to 3 items max
}

Cart:
- Item A: 5 units @ $100/unit
- Item B: 4 units @ $50/unit (lowest price)

Result: $30 discount on Item B (3 units × $50 × 20% = $30)
```

**Scenario 4: Percentage discount - distributed across items**
```javascript
{
  type: "percentage",
  allocation: "once",
  value: 15,         // 15% off
  max_quantity: 5
}

Cart:
- Item A: 2 units @ $40/unit (lowest price)
- Item B: 4 units @ $80/unit

Result:
- Item A: $12 discount (2 units × $40 × 15% = $12)
- Item B: $36 discount (3 units × $80 × 15% = $36, remaining quota)
Total: $48 discount
```

**Scenario 5: Percentage with max_quantity = 1**
```javascript
{
  type: "percentage",
  allocation: "once",
  value: 25,         // 25% off
  max_quantity: 1    // Only one item
}

Cart:
- Item A: 3 units @ $60/unit
- Item B: 2 units @ $30/unit (lowest price)

Result: $7.50 discount on Item B (1 unit × $30 × 25%)
```
2025-10-14 11:01:00 +00:00
Shahed Nasser
958b003a11 chore: add since tags for latest release (#13739) 2025-10-13 11:24:51 +03:00
Adrien de Peretti
c54c5ed6de chore(): improve cart operations + Mikro orm 6.4.16 (#13712)
* chore(): Mikro orm 6.4.16

* Create small-ghosts-draw.md

* update config

* update config

* fix delete

* update config

* update workflows

* order improvements

* test pricing quuery

* test pricing quuery

* configurable connection options

* configurable connection options

* configurable connection options

* Update packages/modules/pricing/src/models/price.ts

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-10-10 08:58:19 +02:00
Frane Polić
7dc3b0c5ff feat(core-flows,dashboard,js-sdk,promotion,medusa,types,utils): limit promotion usage per customer (#13451)
**What**
- implement promotion usage limits per customer/email
- fix registering spend usage over the limit
- fix type errors in promotion module tests

**How**
- introduce a new type of campaign budget that can be defined by an attribute such as customer id or email
- add `CampaignBudgetUsage` entity to keep track of the number of uses per attribute value
- update `registerUsage` and `computeActions` in the promotion module to work with the new type
- update `core-flows` to pass context needed for usage calculation to the promotion module

**Breaking**
- registering promotion usage now throws (and cart complete fails) if the budget limit is exceeded or if the cart completion would result in a breached limit

---

CLOSES CORE-1172
CLOSES CORE-1173
CLOSES CORE-1174
CLOSES CORE-1175


Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2025-10-09 12:35:54 +00:00
Adrien de Peretti
b43b285125 fix(): Workflow save to db + index integration instability (#13707)
**What**
- Fix index integration tests instability
- Fix workflow engine storage save to db
2025-10-08 08:45:15 +00:00
Adrien de Peretti
51859c38a7 chore(): Default caching configuration and gracefull redis error handling (#13663)
* chore(): Default caching configuration and gracefull redis error handling

* Create odd-moons-crash.md

* chore(): Default caching configuration and gracefull redis error handling

* fixes

* address feedback

* revert(): Test utils imit module fix

* reconnect

* reconnect

* reconnect
2025-10-06 17:57:11 +02:00
Adrien de Peretti
62d340b897 fix(): caching better identify default provider (#13675) 2025-10-03 21:04:27 +02:00
Adrien de Peretti
4165172145 chore(): Downgrade mikro orm (performance regression) (#13680)
**What**
After lot of investigation, we finally found one of our performance regerssion point (see [here](https://github.com/mikro-orm/mikro-orm/issues/6905)), this pr downgrade mikro orm and move the strategy back to select in where needed
2025-10-03 15:31:40 +00:00
Adrien de Peretti
d58462c9c9 chore(): Caching improvements (#13660)
* chore(): Caching improvements

* Create proud-windows-sleep.md

* naming

* fix tests

* address feedback
2025-10-03 10:05:44 +02:00
Adrien de Peretti
76aa4a48b3 fix(): workflows concurrency (#13645) 2025-10-02 11:11:38 -03:00
Nicolas Gorga
ca334b7cc1 fix(inventory): delete reservation item inventory level required quantity (#13633)
Fixes #13625


---

> [!NOTE]
> Ensure `reserved_quantity` is adjusted when deleting reservation items via `deleteReservationItems`, with new integration tests covering deletion and inventory updates.
> 
> - **Inventory Module Service (`packages/modules/inventory/src/services/inventory-module.ts`)**:
>   - Add `deleteReservationItems` API (and transactional `_` variant) that hard-deletes reservations, then updates related inventory levels via `adjustInventoryLevelsForReservationsDeletion`.
>   - Wire through event emission/manager decorators consistent with existing patterns.
> - **Integration Tests (`packages/modules/inventory/integration-tests/__tests__/inventory-module-service.spec.ts`)**:
>   - Add tests for `deleteReservationItems` to verify deletion by id and `reserved_quantity` adjustments on inventory levels.
>   - Minor import update to include `ReservationItemDTO`.
> - **Changeset**:
>   - Patch release note for `@medusajs/inventory` documenting the fix.
> 
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ac6641a9ec9543115504407f708f81bd427c3444. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
2025-10-02 12:59:13 +00:00
William Bouchard
bb08edd41f fix(medusa,file-local,file-s3,core-flows): fix csv parsing special characters (#13649)
* fix(): fix csv parsing special characters

* remove other tries

* tweak

* remove comments

* Create rude-mirrors-hang.md
2025-10-02 08:24:18 -04:00
Adrien de Peretti
8fb7e04be7 fix(): Fulfillment custom schema error on provider (#13656) 2025-10-02 14:01:54 +02:00
martinerko
9361f9c25a fix(index): preserve existing fields configuration (#13639) (#13640)
Co-authored-by: William Bouchard <46496014+willbouch@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
2025-10-02 11:53:56 +02:00
Adrien de Peretti
b9d6f73320 Feat(): distributed caching (#13435)
RESOLVES CORE-1153

**What**
- This pr mainly lay the foundation the caching layer. It comes with a modules (built in memory cache) and a redis provider.
- Apply caching to few touch point to test

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2025-09-30 16:19:06 +00:00
Adrien de Peretti
5b135a41fe fix(): workflow engine migration issue (#13629)
**What**
The extension creation have been pushed by mistake
2025-09-30 15:41:09 +00:00
Shahed Nasser
0c7cbfb2e7 feat(payment-stripe): Allow passing shared payment token in Stripe (#13632)
* feat(@medusajs/payment-stripe): Allow passing shared payment token in Stripe

* fix changeset
2025-09-30 18:40:36 +03:00
Adrien de Peretti
9c7c1d48c7 fix(): Pricing preference context loss (#13626)
**What**
The context reference is being mutated by the repository leading to an empty context. Also, the filter is built from the pricing context instead of pricing context -> context leading to always fetch all preferences all the time
2025-09-30 12:38:04 +00:00
William Bouchard
087887fefb feat(core-flows): support ad hoc returns (#13598)
* feat(core-flows): support ad hoc returns

* fix: missing transform

* handle edge case

* refactor

* replace gte for gt

* cleanup

* weird bug fix

* add test

* Create quick-nails-kick.md

* stop sending empty strings

* add code to refund reason

* fix build

* fix tests

* handle code in dashboard

* fix tests

* more tests failing

* add reference and reference id to credit lieng

* rework create refund form
2025-09-30 07:38:50 -04:00
William Bouchard
5346079d47 chore(): create default refund reasons (#13591)
* chore(): create default refund reasons

* Create great-donuts-swim.md

* woops

* woopsie

* woopsie

* tests

* tests

* woopsie

* fml

* fix: comment
2025-09-28 10:07:48 +02:00
Adrien de Peretti
fc67fd0b36 chore(utils): make upsert with replace more efficient (#13580)
PARTIALLY RESOLVES CORE-1156

**What**
Improve upsertWithReplace to batch as much as possible what can be batched. Performance of this method will be much greater specially for cases with maybe entities and batch (e.g we seen many cases where they bulk product with hundreds variants and options etc)
for example let take the following object:
- entity 1
  - entity 2 []
    - entity 3 []
  - entity 2 []
    - entity 3 []

here all entity 3 will be batched and all entity 2 will be batched

I ve also added a pretty detail test that check all the stage and what is batched or not with many comments so that it is less harder to consume and remember in the future


Also includes:
- mikro orm upgade (issues found and fixes)
- order module hooks fixes

**NOTE**
It was easier for now to do this instead of rewriting the different areas where it is being used, also, maybe it means that we will have closer performance to what we would expect to have natively

**NOTE 2**
Also fix the fact that integration tests of the core packages never ran 😂
2025-09-26 08:06:43 +00:00
Frane Polić
10787c865f feat(dashboard): refactor location list UI to use data table (#13571)
* wip: convert location list to a table

* chore: changeset

* fix: rm search bluring on loading change

* feat: translations and palceholders, cleanup, make content more compact

* fix: delete message

* chore: optimise use memo

* fix: update toast

* feat: make stock location address searchable

* fix: search input blur on load finish
2025-09-24 10:29:13 +02:00
Frane Polić
6e806942c7 fix:(dasboard, order): set return status on cancel (#13578) 2025-09-24 08:48:00 +02:00
William Bouchard
5e827ec95d feat(admin-shared,dashboard,js-sdk,types): refund reasons in dashboard (#13575)
CLOSES CORE-1209

This PR just adds the stuff necessary to support refund reasons in the dashboard. It adds the option in the settings tab and allows viewing, creating, editing and deleting refund reasons. I hate to open such a big PR but most of it is copy pasted from the return reasons. Major difference is only the fact that refund reasons don't have a `value` field
2025-09-23 15:51:40 +00:00
Hakim Saoudi
a501364b2d fix(product): Correctly fetch category descendants by handle (#13579)
This PR fixes the issue #13518  where product category descendants were not retrieved when
filtering by handle with the include_descendants_tree flag. The handle filter was not
being correctly removed before the descendant tree query was executed.
2025-09-23 14:40:31 +00:00
kusonsaelee
9fc32ba7c7 fix(stripe): add StripePromptPayService to Stripe module provider (#13572)
* fix(stripe): add StripePromptPayService to Stripe module provider

* Add changeset for StripePromptPayService fix
2025-09-22 15:46:56 -04:00
Adrien de Peretti
12a96a7c70 chore(): Move peer deps into a single package and re export from framework (#13439)
* chore(): Move peer deps into a single package and re export from framework

* WIP

* update core packages

* update cli and deps

* update medusa

* update exports path

* remove analyze

* update modules deps

* finalise changes

* fix yarn

* fix import

* Refactor peer dependencies into a single package

Consolidate peer dependencies into one package and re-export from the framework.

* update changeset

* Update .changeset/brown-cows-sleep.md

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* rm deps

* fix deps

* increase timeout

* upgrade version

* update versions

* update versions

* fixes

* update lock

* fix missing import

* fix missing import

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-09-22 18:36:22 +02:00
Shahed Nasser
3758303a1d fix(order): save return's location ID from input (#13567) 2025-09-22 13:59:58 +03:00
Adrien de Peretti
9633e0676e fix(workflow-engine-redis): module option queueName wrongly used (#13570)
https://github.com/medusajs/medusa/issues/13452

**What**
Wrongly used module option for redis workflow engine
2025-09-22 10:33:51 +00:00
Carlos R. L. Rodrigues
68a643bb3a fix(workflow-engine-redis): use worker connection (#13561)
What:
 * Regular redis connection does not have `maxRetriesPerRequest: null`, and the worker connection hangs.
2025-09-22 04:59:59 +00:00
Adrien de Peretti
8ece06d8ed chore(): upgrade mikro orm (#13450) 2025-09-19 21:39:18 +02:00
Adrien de Peretti
4c1c1dd4c0 chore(): Further improve promotions computation (#13556)
* chore(): Further improve promotions

* chore(): Further improve promotions

* chore(): Further improve promotions

* chore(): Further improve promotions

* chore(): Further improve promotions

* Create lazy-lemons-occur.md

* chore(): Further improve promotions

* WIP

* fix

* improve:

* fix attribute tests

* fix tests

* union
2025-09-19 21:34:35 +02:00
Adrien de Peretti
cb716856b6 fix(engine): Always create cleaner job (#13557)
RESOLVES CORE-1206

**What**
Instead of removing cleaner repeatable job and risk to remove it while other instances are still up, we always create it, since the id of a job is unique and we give one to the job, if already present it wont get added
2025-09-19 14:38:14 +00:00
William Bouchard
0695c5844f fix(auth-emailpass): better handle identity with same email error (#13537)
* fix(auth-emailpass): better handle identity with same email error

* add test

* Create blue-laws-argue.md

* check for empty object

* trueeee

* nit

* flip condition
2025-09-18 13:05:54 -04:00
github-actions[bot]
174b5b1cb7 chore: Version Packages (#13494)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-09-18 18:38:07 +02:00
Carlos R. L. Rodrigues
9563ee446f fix(utils,core-flows): subtotal calculation and returns location (#13497)
* fix(utils,core-flows): subtotal calculation and returns location

* changeset

* fix test

* var

* rm extra field from test

* fix original total

* fix partial refunds and pending difference

* fix test

* fix test

* test

* extract to util

* original total and update payment when receive return

* original_subtotal

* default fields

* test

* calculate pending difference

* revert claims test

* pending difference

* creadit line fix

* if
2025-09-18 17:50:40 +02:00
Adrien de Peretti
4736c58da5 fix: Prevent promotion filtering to exceed psql limits (#13540)
* fix(): Prevent promotion filtering to exceed psql limits

* Create sour-rockets-grin.md
2025-09-18 17:50:10 +02:00
Adrien de Peretti
57897c232e feat(): prefilter top level promotion rules in db (#13524)
* feat(): promotion pre filtering rule from db

* wip

* feat(): promotion pre filtering rule from db

* improve test readability

* resolve conflict

* fix automatic flag

* add index on attribute and operator

* add index on attribute and operator

* finalize

* cleanup

* cleanup

* cleanup

* cleanup

* Create purple-cars-design.md

* fixes

* fixes

* simplify filters

* fix filter

* fix filter

* further improvements

* fixes

* fixes

* fixes

* fix exclusion

* fix comment

* fix comment
2025-09-18 14:34:03 +02:00
Adrien de Peretti
25634b0382 test(): test dynamic max workers and improve CI (#13516)
* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* test(): test dynamic max workers

* Clarify test description and improve CI
2025-09-16 11:11:03 +02:00
Adrien de Peretti
ebf33bea43 fix(): pipeline missing suites (#13457)
* fix(): pipeline missing suites

* fix tax integration tests

* fix tax integration tests

* fix pipeline

* fix link integration tests

* remove old tests and move current one

* fix workflow execution integration tests

* fix tests and orchestrator

* Fix missing suites in pipeline

Remove integration-tests-modules from patch list.
2025-09-15 12:54:57 +02:00
github-actions[bot]
6525ac5c1c chore: Version Packages (#13354)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-09-12 15:42:43 +02:00
William Bouchard
4fded2602b fix(medusa,product): fix ordering product categories (#13487)
CLOSES CORE-1191

cc @SteelRazor47
2025-09-11 21:18:40 +00:00
Adrien de Peretti
d828005354 chore(): improve inventory module (#13463)
RESOVLES CORE-1185

**What**
Reduce higher function call to reduce overserialization
2025-09-11 10:11:49 +00:00
Adrien de Peretti
58e20fa3fc chore(): Add missing product status index (#13475)
**What**
Add missing product status index
2025-09-11 09:54:12 +00:00
Adrien de Peretti
8dd9ae3d35 chore(): Improve cart module (#13472)
* chore(): Improve cart module

* Create giant-spoons-crash.md
2025-09-11 11:50:58 +02:00