Commit Graph

4711 Commits

Author SHA1 Message Date
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
Leonardo Cabeza
be8122bc0d Update redis.md (#6519)
Fix ioredis options url
2024-02-27 08:45:34 +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
Shahed Nasser
3b18f399c1 docs(ui): show icon tooltip on small devices (#6407) 2024-02-26 08:31:36 +01: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
78b6d46584 Merge pull request #6471 from medusajs/feat/add-api-endpoints-api-key
feat(api-key): Add the endpoints and workflows for api key module
2024-02-23 11:35:31 +01: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
Shahed Nasser
52afc619b3 docs: typo fix in create event module reference (#6470) 2024-02-22 12:16:18 +01: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
Stevche Radevski
add861d205 chore(utils): Move generic utils from region module to utils (#6466)
Moves some generic utilities from the region module to the top-level utils package
2024-02-22 08:06:46 +00:00
Stevche Radevski
5a15e039ec Merge pull request #6463 from medusajs/feat/implement-crud-api-key-module
feat(api-key): Add CRUD functionalities to the api key module
2024-02-21 16:36:31 +01:00
Stevche Radevski
ec6351b363 chore: Updates based on PR feedback 2024-02-21 16:05:51 +01:00
Stevche Radevski
c99ca5cc22 feat(api-key): Add CRUD functionalities to the api key module 2024-02-21 15:45:40 +01:00
Adrien de Peretti
e0750bae40 chore(medusa-test-utils): Add debug option to the module test runner (#6462)
**What**
Add a debug options to the test runner, for now it will only switch the db to log the query but it could evolve to do more debug.
2024-02-21 13:01:03 +00:00
Frane Polić
8ff838970e fix(medusa): register logger when running migrations (#6415) 2024-02-21 13:28:58 +01:00
Kasper Fabricius Kristensen
44d43e8155 feat(dashboard, medusa, medusa-js, medusa-react, icons): DataGrid, partial Product domain, and ProductVariant hook (#6428)
The PR for the Products section is growing quite large, so I would like to merge this PR that contains a lot of the ground work before moving onto finalizing the rest of the domain.

**Note**
Since the PR contains changes to the core, that the dashboard depends on, the staging env will not work. To preview this PR, you will need to run it locally. 

## `@medusajs/medusa`

**What**
- Adds missing query params to `GET /admin/products/:id/variants`
- `options.values` has been added to the default relations of admin product endpoints.

## `medusa-react`

**What**
- Adds missing hook for `GET /admin/products/:id/variants`

## `@medusajs/dashboard`
- Adds base implementation for `DataGrid` component (formerly `BulkEditor`) (WIP)
- Adds `/products` overview page
- Adds partial `/products/create` page for creating new products (WIP - need to go over design w/ Ludvig before continuing)
- Adds `/products/:id` details page
- Adds `/products/:id/gallery` page for inspecting a products images in fullscreen.
- Adds `/products/:id/edit` page for editing the general information of a product
- Adds `/products/:id/attributes` page for editing the attributes information of a product
- Adds `/products/:id/sales-channels` page for editing which sales channels a product is available in
- Fixes a bug in `DataTable` where a table with two fixed columns would not display correctly

For the review its not important to test the DataGrid, as it is still WIP, and I need to go through some minor changes to the behaviour with Ludvig, as virtualizing it adds some constraints.

## `@medusajs/icons`

**What**
- Pulls latest icons from Figma

## TODO in next PR
- [ ] Fix the typing of POST /admin/products/:id as it is currently not possible to delete any of the nullable fields once they have been added. Be aware of this when reviewing this PR.
- [ ] Wrap up `/products/create` page
- [ ] Add `/products/:id/media` page for managing media associated with the product.
- [ ] Add `/products/id/options` for managing product options (need Ludvig to rethink this as the current API is very limited and we can implement the current design as is.)
- [ ] Add `/products/:id/variants/:id` page for editing a variant. (Possibly concat all of these into one BulkEditor page?)
2024-02-21 11:29:35 +00:00
Shahed Nasser
c3e30224c7 docs: add missing widget props for collections injection zones (#6452)
* docs: add missing widget props for collections injection zones

Adds missing widget props for the `product_collection.details.before` and `product_collection.details.after` injection zones.

* fix lint error
2024-02-21 07:49:30 +01:00