Commit Graph

298 Commits

Author SHA1 Message Date
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
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
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
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
Carlos R. L. Rodrigues
d48c076b77 chore(order): big number calculations (#6651)
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-03-11 17:51:00 +00:00
Adrien de Peretti
d9d5afc3cf feat(fulfillment): Soft deletes (#6630)
**What**
- Ensure soft delete works properly according to the soft delete configuration and validate all relation of the entire data model
- Add is_enabled to the providers in order to manage new providers to enabled or disabled
- include joiner config update

FIXES CORE-1853
FIXES CORE-1830
FIXES CORE-1719
2024-03-11 15:56:08 +00:00
Oli Juhl
c51a67a421 feat: Add payment + promotion refreshing to cart workflows (#6654)
Add payment collection refreshing to:
- Add to cart
- Create cart
- Update line item in cart

Add promotion creation to:
- Create cart
2024-03-11 12:32:41 +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
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
Philip Korsholm
c19d276458 feat(inventory-next, types): inventory module conversion (#6596)
* init

* create new interface

* prep integration tests

* update denpencies

* inventory service partial tests

* finalize integration tests

* add events

* align events

* adjust inventory level reservation levels

* add test validating reserved quantity after reseration item update

* fix nits

* rename to inventory-next

* update yarn.lock

* remove changelog

* remove fixtures

* remove unused files

* ready for review

* Update packages/inventory-next/package.json

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

* pr feedback

* add tests and docs for partition-array util

* remote decorators from private method

* fix unit tests

* add migrations

* add foreign keys

* fix build

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-03-08 14:09:05 +01:00
Philip Korsholm
8406eb5a35 feat(stock-location): Convert module to use mikro-orm (#6616)
* convert module

* fix migration

* cleanup module service

* fix pr feedback
2024-03-08 13:15:15 +01:00
Stevche Radevski
056e3e9599 feat: Set withDeleted as true if filtering on deleted_at in modules (#6626)
Similar convention already existed in v1, so we are just applying this for the abstract module factory
2024-03-08 11:40:00 +00:00
Carlos R. L. Rodrigues
43399c8d0d Feat(order): order changes (#6614)
This is a PR to keep them relatively small. Very likely changes, validations and other features will be added.

What:
  Basic methods to cancel, confirm or decline order changes
  Apply order changes to modify and create a new version of an order

Things related to calculation, Order and Item totals are not covered in this PR. Properties won't match with definition, etc.

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-03-07 18:24: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
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
Adrien de Peretti
62a7bcc30c Feat(fulfillment): service provider registration + fulfillment management (#6524)
**What**
- Create the fulfillment manual package with a first iteration API 
- Create a new `AbstractFulfillmentProviderService` and `IFulfillmentProvider`
- Modify the module service interface to add new methods to manipulate the fulfillment and the communication with the external provider
  - create (no bulk)
  - cancel (no bulk)
  - update (no bulk)
  - list
  - listAndCount
  - retrieve
- Add new methods to the service provider service to include communication with the third party provider
  - get options
  - create
  - cancel
  - validate data
  - validate option
- Update/create interfaces and DTO's
- fix repository serializer to allow non entity to be passed without throwing
- split module tests into multiple files to simplify navigation
- Add integration tests to validate fulfillments manipulation and external provider loading + communication

FIXES CORE-1729
FIXES CORE-1785
FIXES CORE-1784
FIXES CORE-1766
2024-03-05 11:11:14 +00:00
Stevche Radevski
f9ef37a2f2 feat: add product admin v2 endpoints (#6579)
This implementation obviously lacks a lot of things, and there are a lot of TODOs. However, there are already a lot of questions I'd rather get answered soon, so I figured it's much easier to do the implementation in steps.

I wrote down all breaking changes, suggested changes, and new additions with comments (TODO and Note).

In a follow-up PR I will:

Add the remaining/missing models
Make the workflows handle all interactions between the different models/modules
Add integration tests
2024-03-05 10:24:33 +00: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
8dad2b51a2 feat(medusa-react,medusa,utils): add users/me endpoint + add missing specs (#6441)
**what:**

- adds /me endpoint
- adds fixes to routes
- adds specs for auth endpoint
- updates dotenv package versions


Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
2024-03-04 09:07:47 +00:00
Oli Juhl
883cb0dca7 feat: Add payment collection creation for cart (#6527) 2024-03-04 09:02:01 +01:00
Stevche Radevski
71ed21de4a feat: Add supported currencies to store model (#6562)
I ultimately went with having a flat list of settings for the store. It wouldn't be very difficult to change it if we wish to do so, but for now this keeps the codebase simpler
2024-03-01 15:43:47 +00:00
Stevche Radevski
347aba719c fix: Move default country loading for region to the loader, fix a bug with cascade (#6559) 2024-03-01 14:58:55 +01:00
nkhar
a5b51dc09b docs: Fixed typo in database_url [:post] instead of [:port] (#6505) 2024-03-01 13:15:18 +01:00
Stevche Radevski
196e821ff2 feat: Modify api key and sales channel link to use modules and add test (#6546) 2024-03-01 09:24:50 +00:00
Carlos R. L. Rodrigues
03ca5c814e feat(order): order change actions engine (#6467) 2024-02-29 16:22:14 -03:00
Stevche Radevski
dc025302a1 feat: Add currency module and remove currency models from region and pricing modules (#6536)
What:
- Creates a new currency module
- Removes currency model from the pricing module
- Removes currency model from region module
2024-02-29 15:09:59 +00:00
Sebastian Rindom
c4760dfd5f feat(tax): v2 api tax rates and regions deletes (#6541) 2024-02-29 12:06:11 +00:00
Sebastian Rindom
6279fb3c67 feat(tax): add support for updating tax rates (#6537) 2024-02-29 11:03:18 +00:00
Sebastian Rindom
2407b443f1 feat(tax): add endpoints to create tax regions and tax rates (#6533)
**What**
Adds:
- POST /admin/tax-regions
- POST /admin/tax-rates
- GET /admin/tax-rates
- `createTaxRegionsWorkflow`
- `createTaxRatesWorkflow`
2024-02-29 10:26:21 +00:00
Sebastian Rindom
adad66e13f feat(tax): migration file (#6523)
**What**
- Tax Module Migration file.
- Skeleton for API routes and integrations tests for tax API in v2
2024-02-28 14:40:35 +00:00
Riqwan Thamir
0d46abf0ff feat(types): promotion module uses big number (#6522)
what: 

- promotion modules (application method and campaign budget) uses big number fields instead of numeric fields
- refreshes the migrations to include new fields for big numbers
- adds a promotion_ prefix to promotion models
- uses `take: null` within the module to prevent the default pagination on performing actions within the module
2024-02-28 11:57:43 +00:00
Oli Juhl
c5d35ec7f2 chore(cart): Use module native soft-delete/delete methods (#6491) 2024-02-28 10:45:56 +00:00
Stevche Radevski
d60f3adc03 feat: Add basic endpoints and workflows for Store module (#6515) 2024-02-28 10:08:11 +00:00
Oli Juhl
3ee0f599c1 feat: Line Items API Routes (#6478)
**What**
- `POST /store/carts/:id/line-items`
- `POST /store/carts/:id/line-items/:id`
- `DELETE /store/carts/:id/line-items/:id`

**Outstanding**
- Integration tests
- Module integrations: Payment, Fulfillment, Promotions

Depends on #6475 and #6449.
2024-02-27 12:47:00 +00:00
Riqwan Thamir
f5c2256286 feat(core-flows,medusa,types,utils): adds update cart API with promotions (#6514)
what:

- adds update cart API
  - workflow
  - promotions
  - sales channel
  - region
  - customer
2024-02-27 12:09:30 +00:00
Stevche Radevski
690e8c2e09 feat(api-key): Allow revoking in the future, and enforce the secret key (#6484)
Since there is quite a bit of code here already, I'll do the middleware changes in a separate PR
2024-02-27 10:37:32 +00:00
Sebastian Rindom
ca463ae9a9 feat(tax): add support for updating tax rates (#6516)
**What**
- Adds update
2024-02-27 09:55:22 +00:00