Commit Graph

4749 Commits

Author SHA1 Message Date
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
Kasper Fabricius Kristensen
e5dc918be5 feat(dashboard): Order details page (#6538)
**What**
- Adds the different display cards to the order details page. This does not include any of the different forms for editing various aspects of an order.
2024-03-05 13:06:50 +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
Shahed Nasser
82db53c99e docs: fix search in api reference (#6578)
* docs: fix search in api reference

* remove log messages
2024-03-05 10:02:56 +01: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
908b1dc3a2 fix(tax): improve error handling (#6563) 2024-03-04 17:02:11 +00:00
Adrien de Peretti
e501e9effa chore: Run packages integration tests concurrently and not in band (#6576) 2024-03-04 14:17:07 +01: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
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
Adrien de Peretti
56d97ebef9 chore(medusa-test-utils): Add logger by default (#6558)
**What**
Add the logger dependency using the console by default if not provided
2024-03-01 13:02:45 +00:00
nkhar
a5b51dc09b docs: Fixed typo in database_url [:post] instead of [:port] (#6505) 2024-03-01 13:15:18 +01:00
xyzones
45cf692f5e fix(medusa-cli): Logger arguments (#6526) 2024-03-01 13:03:01 +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
Oli Juhl
55275f0eba chore(actions): Use PG pass secret (#6548) 2024-02-29 22:10:56 +01:00
Carlos R. L. Rodrigues
03ca5c814e feat(order): order change actions engine (#6467) 2024-02-29 16:22:14 -03:00
Oli Juhl
cdb01e073b feat(link-modules): Cart, Payment Collection link definition (#6508)
* Add cart payment collection joiner confg

* fix migration

* chore: Exclude inventory tests

* remove jest ignore

* add back payment module
2024-02-29 19:33:16 +01:00
Stevche Radevski
4d38eb3bf8 chore: Use default countries and currencies from utils (#6543) 2024-02-29 17:01:18 +01:00
Oli Juhl
296d7faad4 chore: V2 core loader + modules integration-tests (#6544) 2024-02-29 16:46:30 +01: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
chemicalkosek
06f706a51a Fix logger log level (#6512) 2024-02-29 15:34:31 +01:00
Kasper Fabricius Kristensen
44a5567d0d feat(dashboard): Regions domain (#6534)
**What**
- Implements new Region domain design
- Adds new SplitView component for managing adding nested relations in FocusModals, eg. adding countries to a region.
- Adds new Combobox component for multi select fields in forms

**medusajs/ui**
- Fix styling of RadioGroup.Choicebox component

CLOSES CORE-1650, CORE-1671
2024-02-29 13:16:14 +00:00
Riqwan Thamir
0b9fcb6324 feat(utils): consolidate promotion utils + refactor + fixes (#6531) 2024-02-29 12:52:46 +00:00
Shahed Nasser
860d56041a docs: fixes to CLI reference (#6530) 2024-02-29 13:37:36 +01: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
Kasper Fabricius Kristensen
e076590ff2 feat(dashboard,medusa): Update Pub. API key table and add query params to endpoint (#6483)
**What**
- Updates table to use DataTable
- Adds some query params to sort/filter the returned pub. keys
2024-02-28 23:27:49 +00:00
Riqwan Thamir
557d86afbf feat(medusa,core-flows): update cart adjustments on item updates (#6539) 2024-02-28 19:35:24 +01: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
Riqwan Thamir
a6d7070dd6 feat(types): add util to transform get response to an update request (#6289)
what:

- add util to transform get response to an update request 

RESOLVES CORE-1687


Given an update data object, we can infer the `fields` and `selects` of a data object using a util we already have - `getSelectsAndRelationsFromObjectArray`. Using the `fields` and `selects`, we can call either the module `retrieve` or `list` method to get a snapshot of the data down to its exact attributes. We can pass this data into the revert step.

In the revert step, we just need to convert the snapshot received from `retrieve` or `list` to a shape that the `update` methods will accept. The util that is introduced in this PR aims to do exactly that, so that the revert step looks as simple as:

```
const { snapshotData, selects, relations } = revertInput

await promotionModule.updateCampaigns(
  convertItemResponseToUpdateRequest(snapshotData, selects, relations)
)
```

entity before update:
```
Campaign: {
  id: "campaign-test-1",
  name: "test campaign",
  budget: {
    total: 2000
  },
  promotions: [{ id: "promotion-1" }],
  rules: [
    { id: "rule-1", operator: "gt", value: "10" }
  ]
}
```

This is how the util will transform the data for different types of attributes in the object:

simple attributes:
```
invoke:
{
  id: "campaign-test-1",
  name: "change name",
}

compensate:
{
  id: "test-1",
  name: "test campaign"
}
```

one to one relationship:
```
invoke:
{
  id: "campaign-test-1",
  budget: { total: 4000 }
}

compensate:
{
  id: "campaign-test-1",
  budget: { total: 2000 }
}
```

one to many / many to many relationship:
```
invoke:
{
  id: "campaign-test-1",
  promotions: [{ id: "promotion-2" }]
  rules: [
    { id: "rule-1", operator: "gt", value: "20" },
    { operator: "gt", value: "20" }
  ]
}

compensate:
{
  id: "campaign-test-1",
  promotions: [{ id: "promotion-1" }]
  rules: [{ id: "rule-1", operator: "gt", value: "20" }]
}
```

all together:
```
invoke:
{
  id: "campaign-test-1",
  name: "change name",
  promotions: [{ id: "promotion-2" }],
  budget: { total: 4000 },
  rules: [
    { id: "rule-1", operator: "gt", value: "20" },
    { operator: "gt", value: "20" }
  ]
}

compensate:
{
  id: "test-1",
  name: "test campaign",
  promotions: [{ id: "promotion-1" }],
  budget: { total: 2000 },
  rules: [{ id: "rule-1", operator: "gt", value: "20" }],
}
```
2024-02-28 11:25:50 +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
70aeb602c9 feat(payment): Add migration (#6509) 2024-02-27 19:05:52 +01:00
Adrien de Peretti
b3d826497b chore(utils): Improve big number decorator (#6525)
**What**
- Re add the ability to use the original column name as part of a select in both select in and joined strategy
- The undefined error message will now display the original column name instead of the underscored one
2024-02-27 15:48:45 +00:00
Stevche Radevski
753bd93ba1 feat(api-key): Add api-key authentication to middleware (#6521)
Also did a bit of a cleanup on the auth middleware. There should be no behavioral changes, just moved code around.
2024-02-27 13:44:37 +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
Frane Polić
608c10383a feat(admin-next) discounts list page (#6490) 2024-02-27 12:33:19 +01:00
Philip Korsholm
a223566d96 feat(user): standardize events emitted for token generation (#6520) 2024-02-27 12:32:27 +01: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