Commit Graph

57 Commits

Author SHA1 Message Date
Riqwan Thamir
4c98545ab3 feat: shard modules and API integration tests (#6775)
what:

- runs module and api integration tests in matrix strategy
  - v28 of jest comes with sharding support, which we can utilize when we upgrade
- splits the tests by number of matrix jobs and run them in parallel
  - This introduced some flakiness in some specs, but couldn't reproduce locally. Those have been skipped for now.
- uses swc/jest for added performance
  - Locally, a chunk took 90 seconds with babel and 30 seconds with swc. 
  - This translated to 2 mins saved per shard in CI, but haven't tested this enough.
2024-03-22 11:15:01 +00:00
Riqwan Thamir
b792c4cab5 chore: merge money amounts and price set money amounts (#6768)
what: 

- merges price set money amounts and money amount
2024-03-21 16:10:13 +00:00
Riqwan Thamir
cf8b5ce85b chore: pricing models uses standardized relationships attributes (#6767)
what:

- all relationships under all models are standardized
2024-03-21 10:01:52 +00:00
Carlos R. L. Rodrigues
60070fb65f fix(link-modules): recreate dismissed link (#6764)
* fix(link-modules): recreate dismissed link

* rm type

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-03-20 19:12:48 +01:00
Riqwan Thamir
20243e22ee feat(pricing): pricing models are made soft deletable (#6732)
what:

- pricing models are made soft deletable
- adds missing timestamp attributes
- removes unwanted relationships + cascade cleanup
2024-03-20 16:03:17 +00:00
Philip Korsholm
64c2731e46 feat(medusa, core-flows): add ppdate inventory item endpoint (#6735)
* init update inventory item

* prep for pr
2024-03-20 14:45:06 +01:00
Oli Juhl
8155e2cfad feat: Init. v2 implementation in admin (#6715) 2024-03-20 14:28:28 +01:00
Philip Korsholm
62d5803b20 Feat(core-flows, medusa): delete inventory item (#6708)
* initial get-inventory-item

* add exception throw test

* remove console log

* add changeset

* remove inventory item

* add changeset

* fix pr feedback

* use links

* use modules instead of property names
2024-03-19 10:40:18 +01:00
Philip Korsholm
c20eb15cd9 Feat(core-flows, medusa, types): Add delete location level api-v2 endpoint (#6727)
* add delete inventory level endpoint

* add changeset

* rename step

* rename step
2024-03-19 10:06:37 +01:00
Philip Korsholm
390bc3e72f Feat(core-flows, inventory-next, medusa, types): Add create inventory item endpoint (#6693)
* init create inventory item

* fix integration tests

* pr feedback

* rename to validate

* pr feedback

* bulk delete

* undo change w/ naming

* update dto body

* move integration test

* pr fixes

* fix for pr review

* revert medusa-config changes

* pr feedback

* fix build
2024-03-19 09:20:30 +01:00
Riqwan Thamir
0c705d7bd4 feat(core-flows,medusa,types): create/update workflows to create and update PriceList prices (#6711)
what:

- create and update workflows for price list prices
- update price list endpoint does a "set"
2024-03-18 14:14:28 +00:00
Philip Korsholm
84b8836cbf Feat(core-flows, inventory-next, medusa, types): Add create location level endpoint (#6695)
* initialize create location levels

* add enough from pr to make code build and test

* fix integration tests

* pr feedback

* fix errors

* rm dto

* Update packages/core-flows/src/inventory/steps/validate-inventory-locations.ts

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

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-03-18 10:28:57 +01:00
Philip Korsholm
56a6ec0227 feat(medusa): Add get inventory item endpoint (#6704)
* initial get-inventory-item

* add exception throw test

* remove console log

* add changeset

* remove unused import
2024-03-15 16:00:27 +01:00
Adrien de Peretti
3188e703b3 feat(fulfillment): Separate list and context rules validation (#6674)
**What**

- Add method to validate fulfillment option from the provider
- Separate list/list and count from context rules validation and add listShippingOptionsForContext

FIXES CORE-1861
2024-03-15 13:25:51 +00:00
Stevche Radevski
1956dce80a feat: Update the product options model and refactor the product module (#6685)
The changes in this PR are:
1. Change how product options are created and stored. The relationship changed from
`options --> option values <-- variants`
to
`options --> option values --> variant options <-- variants`

Now we can enforce non-duplicate option values, easier creation and updates of options, and more.

2. Refactors the product module. The product module did a lot of things in a non-ideal approach, and this is a step towards a more consistent usage of the base repository and methods exposed by a module. There is still work left to improve the module, but a large chunk of the changes are included in this PR


Things to do as a follow-up:
1. Remove many-to-many relationships  if an empty list is passed in the base repository.
2. Improve the typings of the module
3. Further cleanup and improvements (there are few questions that I need answered before I can improve the API)
2024-03-15 12:35:46 +00:00
Riqwan Thamir
9288f53327 feat(core-flows,medusa,pricing,types,utils): added price list workflows + endpoints (#6648)
Apologies for the giant PR in advance, but most of these are removing of files and migrations from old workflows and routes to new.

What:

- Adds CRUD endpoints for price lists
- Migrate workflows from old sdk to new
- Added missing updatePriceListPrices method to pricing module
2024-03-15 11:09:02 +00:00
Riqwan Thamir
e5945479e0 feat(medusa,core-flows,types): adds update promotion rule endpoint + workflow (#6702)
what:

- adds endpoint + workflow to update promotion rule
- adds method in promotion to update promotion rules
2024-03-14 20:04:53 +00:00
Riqwan Thamir
7be0a2cf6d chore(medusa): use batch/add and batch/remove endpoints for promotion rules (#6701) 2024-03-14 19:07:48 +01:00
Riqwan Thamir
cc1b66842c feat(core-flows,medusa,types,utils): add/remove fulfillment shipping option rules (#6698)
what:

- adds fulfillment shipping option rules batch endpoint
- remove fulfillment shipping option rules batch endpoint
- breaks my British based education to not call it fulfilment with a single "l"
2024-03-14 16:02:50 +00:00
Riqwan Thamir
1a661adf3e feat(medusa,types): GET admin promotion endpoint to fetch by code (#6697)
what:

- GET admin promotion endpoint will search for a promotion either through ID or code
2024-03-14 15:13:53 +00:00
Philip Korsholm
c3f8c30ba6 Feat(inventory-next, medusa): Add List inventory items endpoint (#6694)
* code for list inventory items

* fix integration tests

* move integration test

* calculate reserved and stocked quantities in db

* update lockfile
2024-03-14 14:48:34 +01:00
Riqwan Thamir
04a532e5ef feat(core-flows,medusa,types): remove rules from promotion endpoints + workflows (#6696) 2024-03-14 09:19:05 +01:00
Riqwan Thamir
640eccd5dd feat(core-flows,medusa,types,utils): add rules to promotion endpoints + workflow (#6692)
* feat(core-flows,medusa,types,utils): add rules to promotion endpoints + workflow

* chore: fix specs

* chore: move input type to types package
2024-03-13 21:19:24 +01:00
Oli Juhl
02e784ce78 feat: Confirm inventory in create cart workflow (#6635) 2024-03-13 18:24:08 +01:00
Riqwan Thamir
b78f863d80 feat(core-flows,medusa): added api + workflows for rule types CRUD (#6684) 2024-03-13 16:43:30 +01:00
Oli Juhl
25d176b851 feat: List shipping options for cart (#6677) 2024-03-13 09:08:47 +00:00
Riqwan Thamir
d4b921f3db feat(medusa,pricing,types): added get endpoints for pricing rule types (#6678)
what:

- adds list endpoint for rule types
- adds get endpoint for rule types
2024-03-12 17:35:24 +00:00
Oli Juhl
f0c8142635 feat: Add shipping method to cart (#6661) 2024-03-12 17:52:48 +01:00
Riqwan Thamir
c3c4f49fc2 feat(core-flows,medusa,types): add automatic-taxes to region + generate tax lines endpoint (#6667)
what:

- endpoint to generate tax lines
- update workflows to force calculate tax lines with a flag
- added automatic_taxes to region
2024-03-12 14:36:22 +00:00
Adrien de Peretti
87e63c024e feat(fulfillment): Migration backward compatibility (#6672)
**What**
- Update migration for backward compatibility. This does not take into account data migration and table cleanup (@olivermrbl do we have a general tasks for the modules on that subject)?
- Rename fulfillment provider id to provider id
- add integration tests to ensure the migration backward compatibility
- add new module type for the options to be used in the medusa config for example

FIXES CORE-1724
2024-03-12 13:53:33 +00:00
Riqwan Thamir
7c46b0f88b feat(medusa): added list price list products endpoint (#6617)
what:

- adds an endpoint to list price list products
2024-03-11 17:00:16 +00:00
Stevche Radevski
ff4bd62f71 feat: Implement missing methods in product module and make more tests pass (#6650)
The 2 bigger remaining tasks are:
1. handling prices for variants
2. Handling options (breaking change)

After that all tests should pass on both v1 and v2
2024-03-11 11:03:24 +00:00
Oli Juhl
4136b9da5f feat: Add Sales Channel Stock Location link (#6634) 2024-03-08 15:26:26 +01:00
Stevche Radevski
a92cdeb01d chore: Adjusting the v2 product module to follow the v1 specs (#6618)
In this PR:
1. I added upsert support for the product
2. I updated the create and update signatures to match the latest interface standards
3. Small changes to make the v1 and v2 APIs compatible (WIP)
2024-03-08 14:03:59 +00:00
Oli Juhl
272fb6d328 fix(tests): Cart links (#6628)
Not sure how this test snuck past our CI check, but this fixes it :)
2024-03-08 11:12:05 +00:00
Riqwan Thamir
e4acde1aa2 feat(medusa,core-flows,types): add cart <> tax integration workflows + steps (#6580)
what:

- adds tax lines to cart when item operations take place

RESOLVES CORE-1821
RESOLVES CORE-1822
RESOLVES CORE-1823
RESOLVES CORE-1824
2024-03-07 16:17:43 +00:00
Oli Juhl
8c57e61cb8 feat: Refresh payment collection + delete session (#6594)
### What
Add workflow for refreshing a payment collection. 

The idea is that on all cart updates, we want two things to happen (in the context of payments) 1. the currently active payment sessions should be destroyed, and 2. the payment collection should be updated with the new cart total.

We do this to ensure that we always collect the correct payment amount. 

From a customer perspective, this would mean that every time something on the cart is updated, the customer would need to enter their payment details anew. 

To me, this is a good tradeoff to avoid inconsistencies with payment collection.

Additionally, I updated the Payment Module interface with `upsert` and `updated` following our established convention.

### Note
This PR depends on a fix to the `remoteJoiner` that @carlos-r-l-rodrigues is working on.

Update: Fix merged in #6602 

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-03-07 13:32:20 +00:00
Oli Juhl
e5cbe28d54 feat: Refund payment (#6610)
Essentially the same as #6601 but for refunds
2024-03-07 12:34:36 +00:00
Oli Juhl
3d0da980cf feat: Capture payment (#6601)
* feat: Capture payment

* add amount to workflow input
2024-03-07 11:02:26 +01:00
Stevche Radevski
12b035cb18 chore(tests): Try to use the api integration tests for v2 (#6588)
Few things to keep in mind:
1. You need to set MEDUSA_FF_MEDUSA_V2 to true before running the tests to run with the v2 API
2. You can use the `breaking` function to differentiate between v1 and v2 differences. This can help us identify what was breaking pretty quickly afterwards
3. You will need to run specific tests for now instead of all if you want to target v2. I think that's fine though, as we don't really need these to run on every PR until we have feature parity (and by then, all tests would be both v1 and v2 compatible)


**note: Adrien** 
- add a new way to load modules only to run their loaders comparable to the way to run the migrations only
- improve tests runner to cleanup the data properly as well as re running all loaders and core defaults

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-03-07 08:05:43 +00:00
Riqwan Thamir
000eb61e33 feat(pricing,medusa,utils): added list + get endpoints for price lists (#6592)
what:

- brings back price list GET endpoints to v2 endpoints
2024-03-06 23:22:31 +00:00
Carlos R. L. Rodrigues
8a946beb75 Fix(orchestrator): Joiner field alias (#6602) 2024-03-06 15:17:11 -03:00
Adrien de Peretti
0c9018eddc fix: integration tests modules 2 (#6599)
Currently, if the v2 flag is not enabled it can lead to issues if the modules are part of the medusa config as they will get loaded anyway leading to issues if the migrations did not ran
2024-03-06 13:26:42 +00:00
Adrien de Peretti
f0ef0a8784 fix: integration-tests/modules (#6595) 2024-03-06 11:45:34 +00:00
Adrien de Peretti
51bb6f1e89 Chore/integration tests modules utils (#6581)
new wrapper for medusa integration tests.
for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. 

It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
2024-03-06 10:03:07 +00:00
Stevche Radevski
a6736c7ee0 fix: Add some tests and test cleanup for product module (#6586) 2024-03-05 17:18:46 +01:00
Oli Juhl
7d69e6068e feat: Region PaymentProvider link (#6577)
**What**

- Introduce link between Region and PaymentProvider
- Introduce API endpoint `GET /store/regions/:id/payment-providers` for retrieving providers by region
- Add tests for both
2024-03-05 09:40:25 +00:00
Oli Juhl
84208aafc1 feat: Create payment sessions (#6549)
~~Opening a draft PR to discuss a couple of implementation details that we should align on~~

**What**

Add workflow and API endpoint for creating payment sessions for a payment collection. Endpoint is currently `POST /store/payment-collection/:id/payment-sessions`. I suggested an alternative in a comment below.

Please note, we intentionally do not want to support creating payment sessions in bulk, as this would become a mess when having to manage multiple calls to third-party providers.
2024-03-05 08:40:47 +00:00
Sebastian Rindom
555eb41fca feat(tax): add endpoints to manage tax rate rules (#6557)
**What**
Adds endpoints to manage tax rules on a tax rate:
- Create a tax rule: POST /admin/tax-rates/:id/rules 
- Delete a tax rule: DELETE /admin/tax-rates/:id/rules/:rule_id
- Replace tax rules: POST /admin/tax-rates/:id -- with { rules: [...] } in body.

### Noteworthy things I bumped into

**Updating nested relationships**
A TaxRate can have multiple TaxRules and in this PR we enable users to replace all TaxRules associated with a TaxRate in one operation. If working with the module directly this can be done with:

```javascript
taxModuleService.update(rateId, { rules: [{ ... }] })
```

Internally in the `update` function the TaxModule first soft deletes any TaxRules that exist on the TaxRate and then creates new TaxRules for the passed rules ([see test](https://github.com/medusajs/medusa/pull/6557/files#diff-cdcbab80ac7928b80648088ec57a3ab09dddd4409d6afce034f2caff08ee022bR78)).

A challenge arises when doing this in a compensatable way in a workflow. To see this imagine the following:
1. `updateTaxRatesWorkflow` gets the current data for the tax rates to update. This includes the tax rates' rules.
2. `updateTaxRatesWorkflow` calls `taxModuleService.update` with new rules. 
3. Internally, the tax module deletes the rules in 1. and creates new rules.
4. Imagine an error happens in a following step and the workflow has to compensate.
5. The workflow uses the data from 1. and calls upsert. The tax module may correctly update the previous tax rules so they are no longer soft deleted. However, upsert (at least not by default) doesn't delete the new rules that were created in 2.

As illustrated by 5. compensating the update is not pretty. To get around this I instead opted to let the workflow handle setting the rules for a rate that makes the compensation more straightforward to handle. [See workflow here](https://github.com/medusajs/medusa/pull/6557/files#diff-ff19e1f2fa32289aefff90d33c05c154f9605a3c5da6a62683071a1fcaedfd7bR89).

**Using nested workflows**
Initially, I wanted to use the `setTaxRateRulesWorkflow` within the `updateTaxRatesWorkflow`. And this worked great for the invoke phase. However, when I needed to compensate the update workflow (and hence also had to compensate the set rules workflow), I found that the workflow engine no longer had the set rules transaction in memory and therefore could not roll it back. ([This is where I try to rollback](https://github.com/medusajs/medusa/pull/6557/files#diff-ff19e1f2fa32289aefff90d33c05c154f9605a3c5da6a62683071a1fcaedfd7bR62), but the transaction id can't be found).

I therefore opted to copy the steps from the set tax rate rules workflow into the update tax rates workflow; however, once we figure out a good way to ensure we can compensate nested workflows we should move to the nested workflow instead. 

This also made me realize that the current implementation of workflows that use `refreshCartPromotions` may create inconsistencies in case of failures (cc: @riqwan).
2024-03-04 10:30:54 +00:00
Riqwan Thamir
d550be3685 feat(core-flows,link-modules,modules-sdk): add cart <> promotion link as source of truth (#6561)
what:

- adds promotion cart link
- update steps to create and remove links
2024-03-04 09:50:49 +00:00