Commit Graph

3074 Commits

Author SHA1 Message Date
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
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
Sebastian Rindom
d03b72ecdd feat(tax): normalize country and province code (#6513)
**What**
- Ensures that country and province codes are always stored as lower case.
- Ensures that calculation context normalizes input before getting region rates.
2024-02-27 09:12:05 +00:00
Philip Korsholm
e747f9d4aa feat: Refresh invite (#6469) 2024-02-27 07:16:52 +00:00
Philip Korsholm
7bddb58542 feat: Update authentication middleware (#6447)
* authentication middleware update

* disable customer authentication

* call correct feature flag method

* fix authentication middleware for store/customers

* fix integration tests and add middleware for admin customers

* update seeders

* customer groups fix

* add authentication middleware for all admin endpoints

* Feat(medusa, user): require authentication for invite accept (#6448)

* initial invite token validation for authentication invocation

* remove invite auth

* remove unused import

* cleanup tests

* refactor to auth instead of auth_user

* pr feedback

* update authenticatedRequest type

* update store authenticated endpoints

* update routes with type

* fix build

* fix build

* fix build

* use auth middleware for api-keys
2024-02-27 13:50:18 +08:00
Sebastian Rindom
63aea44e06 feat(tax): add tax provider support (#6492)
**What**
- Adds Tax Provider model
- Adds loader to get Tax Provider from module options
- Adds System Tax provider which forwards tax rates as is
2024-02-26 19:29:26 +00:00
Oli Juhl
ce39b9b66e feat(payment, payment-stripe): Add Stripe module provider (#6311) 2024-02-26 19:48:15 +01:00
Adrien de Peretti
ac829fc67f feat(fulfillment): List shipping options filtered by context anmd rules (#6507)
**What**
Should be able to list the shipping options with or without a context, when a context is provided all the rules of the shipping options must be valid for the shipping options to be returned.

FIXES CORE-1765
2024-02-26 14:59:55 +00:00
Stevche Radevski
b13c669528 feat: Add basic CRUD functionality to store module (#6510)
Adds the core model and basic CRUD around it.

Note: The store model is not complete, but I prefer doing smaller PRs so it's easier to do a proper review. Adding currencies will be a follow-up PR.
2024-02-26 14:23:48 +00:00
Oli Juhl
7ebe885ec9 feat: Create cart with line items (#6449)
**What**
- Add support for creating a cart with items
- Add endpoint `POST /store/carts/:id/line-items`
- Add `CreateCartWorkflow`
- Add `AddToCartWorkflow`
- Add steps for both workflows

**Testing**
- Endpoints
- Workflows

I would still call this a first iteration, as we are missing a few pieces of the full flow, such as payment sessions, discounts, and taxes.

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-02-26 13:32:16 +00:00
Riqwan Thamir
ac86362e81 feat(workflows-sdk,core-flows,medusa,types): add workflow to update promotions to cart (#6474)
what:

- adds API + workflow to add/remove promotions in a cart
- minor fixes in promotions module
- minor type fixes in cart module
- typing fix in workflows-sdk (Thanks @adrien2p)
- fix step result in workflows-sdk (Thanks @adrien2p)

RESOLVES CORE-1768

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-02-26 12:43:57 +00:00
Stevche Radevski
63be07031b feat: Add skeleton for Store module (#6506) 2024-02-26 12:00:48 +00:00
Riqwan Thamir
8ea37d03c9 fix(utils): bignumber util considers nullable options when setting value (#6499)
what:

- when setting null for nullable columns, big number utils should not throw error
- remove circular soft delete depenedencies for cart module
- trims zeros on big number values
2024-02-26 11:29:36 +00:00
Adrien de Peretti
56cbf88115 chore(utils): Soft delete should allow self referencing circular deps (#6504)
**What**
Self referencing circular dep should not be an error and should be accepted
2024-02-26 09:37:46 +00:00
Sebastian Rindom
d983329481 feat(tax): soft deletes (#6486)
**What**
- Adds soft deletes
2024-02-26 08:34:46 +00:00
Sebastian Rindom
3c5b020c5e feat(tax): singular creates and deletes of regions, rates, rules (#6464)
**What**
- Adds support for creating single rates, regions, rules.
- Adds delete methods.
2024-02-25 21:38:41 +00:00
Adrien de Peretti
168f02f138 chore(util): Detect circular dependencies on soft delete (#6489) 2024-02-24 14:21:43 +01:00
Stevche Radevski
5b85c3103e feat: Update signature of region module to match latest spec (#6487) 2024-02-23 15:56:16 +00:00
Shahed Nasser
c86e27bd0d chore: generated tsdocs (#6352)
Generated TSDocs for the past release.

Note: I haven't updated examples as the examples are for modules without a public reference yet, so the examples can wait.
2024-02-23 15:21:16 +00:00
Adrien de Peretti
788c4a1e36 feat(fulfillment): Shipping options, rules CRUD + rules based context filtering (#6455)
**What**
- Update shipping options with its rules and type
- create/update rules independently
- context based validation fundation
- 🔴 list shipping options with context rules fitlering will come in a separate pr to keep this one smaller

FIXES CORE-1743
FIXES CORE-1764
2024-02-23 11:14:33 +00:00
Stevche Radevski
0582545065 feat(api-key): Add the endpoints and workflows for api key module 2024-02-23 11:01:08 +01:00
Oli Juhl
d9636f4631 chore(cart): Make all cart entities soft-deletable (#6475) 2024-02-23 08:59:02 +01:00
Philip Korsholm
3fc2aea752 feat(modules-sdk, types, user, utils):init user module events (#6431)
* init user module events

* refactor utils

* undo test script update

* fix feedback

* add eventbus service to module test-runner

* add injected dependencies

* move events to utils

* use const eventname in tests

* rm withTransaction
2024-02-23 09:31:02 +08:00
Adrien de Peretti
36a61658f9 feat(utils): Fix big number decorator and cleanup (#6473)
**What**
- Fix big number decorator and cleanup
2024-02-22 16:58:41 +00:00
Sebastian Rindom
598ee6f49c feat(tax): adds getItemTaxLines (#6440)
**What**
- Selects the correct tax line for an item given a calculation context.

**For later PR**
- Consider optimizations. Some thoughts:
  - Even with global sales the number of rates in the DB is not likely to grow beyond ~1000.
  - Can large orders with hundreds of items optimize somehow?
  - Does it make sense to write a custom SQL query to do this?
- Support combined rate.

**Test cases covered**
The selection of tax rates take the following priority:

1. specific product rules - province
2. specific product type rules - province
3. default province rules
4. specific product rules - country
5. specific product type rules - country
6. default country rules

There are test cases for each of them under the following data seed structure:

### **US** 
- **Default Rate**: 2%
- **Sub-Regions**
  - CA 
    - Default Rate: 5%
    - Overrides
      - Reduced rate (for 3 product ids): 3%
      - Reduced rate (for product type): 1%
  - NY 
    - Default rate: 6%
  - FL 
    - Default rate: 4%
- **Overrides**
  - None

### **Denmark** 
- **Default rate:** 25% 
- **Sub-Regions**
  - None
- **Overrides**
  -  None

### **Germany** 
- **Default Rate:** 19%
- **Sub-Regions**
  - None
- **Overrides:**
  - Reduced Rate (for product type) - 7%

### **Canada** 
- **Default rate**: 5%
- **Sub-Regions**
  - QC 
    - Default rate: 2%
    - Overrides:
      - Reduced rate (for same product type as country reduced rate): 1%
  - BC 
    - Default rate: 2%
- **Overrides**
  - Reduced rate (for product id) - 3%
  - Reduced rate (for product type) - 3.5%
2024-02-22 16:28:55 +00:00
invalid w
58943e83fd fix(medusa): unable to delete downloaded files (#6169)
resolve #6168
2024-02-22 12:13:42 +00:00
Adrien de Peretti
f611865553 fix(workflows-sdk): Fix StepFunction typings and custom step name (#6468)
* fix(workflows=sdk): Fix StepFunction typings and custom step name

* Create smart-nails-switch.md

* fixes

* fixes

* fixes

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-02-22 11:59:53 +01:00
Kasper Fabricius Kristensen
72a17d6cd7 feat(dashboard): Rework route modals (#6459)
**What**
- Reworks how RouteModals are setup.

**Why**
- With the current implementation it was possible to create a race-condition in the logic that handled displaying a prompt if the user tried to close a modal, while a child form was dirty. The race condition would cause a new prompt to spawn each time the user clicked the screen, making it impossible to dismiss the prompt. This only occurred in a few specific cases.

**How**
- Creates two new components: RouteFocusModal and RouteDrawer. The component shares logic for handling their own open/closed state, and now accept a form prop, that allows the modals to keep track of whether their child form is dirty. This change ensures that race conditions cannot occur, and that the prompt always only renders once when needed.
2024-02-22 09:03:40 +00:00