Commit Graph

1785 Commits

Author SHA1 Message Date
Riqwan Thamir
c1cdb80436 chore: use splat instead of lodash to clone, remove unnecessary expectations 2022-12-07 16:42:32 +01:00
Riqwan Thamir
40694bd5d1 chore: add a validation in the service layer to conform to 1 region rule 2022-12-07 16:42:32 +01:00
Riqwan Thamir
7fcf2b86a9 chore: prevent adminSession variable from being mutated in the helpers 2022-12-07 16:42:32 +01:00
Riqwan Thamir
bcc1edbf2b chore: addressing review - move repeated strings and objects to constants 2022-12-07 16:42:32 +01:00
Riqwan Thamir
d4e565b0b9 fix: regions are changed from an optional to required field
A discount should always be associated to atleast 1 region - we validate it against the region in the cart service.

Adding a request parameter validation to pass in atleast one regionID in an array of regions will ensure that regionID will be validated as a part of the discount service and fail if its not a valid region ID.
2022-12-07 16:42:32 +01:00
Carlos R. L. Rodrigues
15c667fbd3 feat(medusa,medusa-react): PaymentCollection support (#2659)
* chore: medusa react, order edit complete fix and single payment session
2022-12-07 12:39:35 -03:00
Adrien de Peretti
42d9c7222b feat(medusa): Performance improvements of Carts domain (#2648)
**What**

I have created a new method on the cart service which is `addLineItems`, allowing a user to add one or multiple items in an optimized way. Also updated the `generate` method from the line item service which now also accept a object data or a collection of data which. Various places have been optimized and cache support has been added to the price selection strategy.

The overall optimization allows to reach another 9000% improvement in the response time as a median (Creating a cart with 6 items):

|   | Min (ms)  | Median (ms)  | Max (ms)  | Median Improvement (%)
|---|:-:|---|---|---|
| Before optimisation  | 1200  | 9999 | 12698  |  N/A
| After optimisation | 63  | 252  | 500  | 39x
| After re optimisation | 56 | 82  | 399  | 121x
| After including addressed feedback | 65 | 202  | 495  | 49x

FIXES CORE-722
2022-12-07 14:39:12 +00:00
Frane Polić
3b2c929408 feat(medusa-js, medusa-react): PublishableKeys SC management (#2734) 2022-12-07 12:16:48 +01:00
Frane Polić
322d462311 feat(medusa): PublishableApiKeys SC scopes (#2590)
**What**
-  add/ remove sales channels to/from PublishableApiKey in batch
- associate created cart with SC defined by PK
- filter products if PK with SC association is present
- retrieve a list of sales channels for a PK
- implement 3 new middleware
  - `extendRequestParams`
    -  _extend req object with PK scopes (a list of sales channels) if a publishable key is present in the header of the request_
  - `validateProductSalesChannelAssociation`
    -  _validate if the passed product id belongs to a SC from the PK's scope_
  - `validateSalesChannelParam`
    -  _validate that passed SC ids in the req body/query are within the scope of the PK_

**How**
- The general idea was to reuse existing logic in the controller layer which expects `sales_channel_id` array to be passed. The middleware sets associated SC ids in the request context if a PK is present. These ids are then merged in the controller and passed to the service layer.

**TODO**
- filter response from the search endpoint (CORE-824)

**Testing**
- _integration tests_
  - add sales channels to the publishable API key scope
  - remove sales channels from the publishable API key scope
  - returns products from a specific channel associated with a publishable key
  - returns products from multiples sales channels associated with a publishable key
  - returns all products if PK is not passed
  - returns all products if passed PK doesn't have associated channels
  - should assign sales channel to order on cart completion if PK is present in the header
  - list sales channels from the publishable api key
  -  throws because sales channel in query/body is not in the scope of passed PK 

---

**Discussion**
- what about the other endpoints (e.g. GET /store/product/:id - do we return 404 if the product is not in the SC associated with passed PK)
- what about products search route
- what about `/admin/products` & `/admin/orders` routes (do we add the middleware there as well)

---

RESOLVES CORE-792
RESOLVES CORE-793
RESOLVES CORE-816
2022-12-07 07:50:20 +00:00
Adrien de Peretti
1b21af87ab chore(medusa-core-utils): Migrate to TS (#2670) 2022-12-05 10:21:04 +01:00
Patrick
1dc816039c chore(oas): explicitly declare type:object on schemas with properties (#2712)
### What

OAS: Explicitly declare type:object on schemas with properties.

### Why

While not officially required, schemas with properties should have their type explicitly declared as "object". Omitting the type translates to type: any with properties XYZ. The ambiguity can lead to issues when using code generators.

### How

Multiple regex searches to identify schemas missing type: object. Manually edit each schema. Spot check generated OAS.

### Testing
- Ran OAS validator.
- Ran docs build script

### Proof
![Screen Shot 2022-12-01 at 1 46 13 PM](https://user-images.githubusercontent.com/116003638/205137671-7a6770dd-4f9b-456c-99a6-ac654f6d0f59.png)


RESOLVES CORE-847
2022-12-02 13:51:16 +00:00
Sebastian Rindom
198fe78c13 fix: allow passing idempotency key to service layer create (#2701)
**What**

Allow DraftOrders to be created with an IdempotencyKey. 

Note this doesn't implement idempotency for the DraftOrder create endpoint but allows the service layer to ingest the key and store it in the database. This is a preliminary step to being able to support an idempotent API request.
2022-11-30 09:23:59 +00:00
Philip Korsholm
70a8d3450f fix(medusa): Use correct auth middleware in GET /store/auth (#2687)
* use correct authentication middleware

* remove guard from get-session since it's guarded by middleware doing the same check

* Add integration tests

* Create lazy-swans-agree.md

Co-authored-by: olivermrbl <oliver@mrbltech.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-11-29 15:46:55 +01:00
Adrien de Peretti
e18b59de66 chore: Update Awilix to v8 (#2668) 2022-11-25 13:56:22 +01:00
Adrien de Peretti
ed121922b0 fix(medusa): Order service legacy decorate totals should add totals to items (#2667)
For some reason, probably a conflict, the legacy decorate totals does not attach the totals to the line items
https://github.com/medusajs/medusa/pull/2546/files

FIXES CORE-832

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-11-24 18:31:45 +00:00
Adrien de Peretti
63d2a0eb1b fix(strip): Hooks import was wrong (#2666)
* fix(strip): Hooks import was wrong

* Create nervous-insects-switch.md
2022-11-24 16:16:35 +01:00
olivermrbl
105c689298 chore(release): Publish 2022-11-24 11:42:04 +01:00
olivermrbl
a4d75f4a40 fix: merge conflicts with develop 2022-11-22 13:39:27 +01:00
olivermrbl
ade898d434 chore(release): Publish 2022-11-22 13:35:50 +01:00
Philip Korsholm
e7c4cc3751 fix(medusa): Separate JWT auth strategies per domain (#2646)
**What**
Separate JWT auth strategies per domain

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2022-11-22 12:30:05 +00:00
Adrien de Peretti
5d977a8f57 perf(medusa): Shipping options + TransactionBaseService initialization (#2632) 2022-11-21 08:09:18 +01:00
Oliver Windall Juhl
d7997ef256 feat(medusa): Module Resolution API (#2597) 2022-11-20 22:01:46 +01:00
Adrien de Peretti
e09f6e8a1e fix(medusa-payment-stripe): handle webhook sirialization failure (#2607) 2022-11-20 20:47:15 +01:00
Carlos R. L. Rodrigues
01a879ac94 chore: markAsAuthorized and payment collection tests (#2620)
* chore: markAsAuthorized and payment collection tests
2022-11-18 11:23:35 -03:00
Adrien de Peretti
a77780671a fix(medusa): Transaction lock issues on create/update cart items (#2612)
* fix(medusa): Transaction lock issues on create/update cart items

* fix add missing trans

* cleanup

* cleanup

* Create perfect-bears-invent.md

* cleanup

* revert draft order to no take it in that pr

* cleanup handler

* cleanup steps

* fix reference issue

* cleanup + fix tests and mock

* cleanup type

* rename file

* cleanup

* fix missing transaction

* wip

* Address pr feedback

* cleanup and fix unit tests

* fix handler

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-11-18 12:15:53 +01:00
Philip Korsholm
5332081972 fix(medusa, medusa-plugin-discount-generator, medusa-plugin-restock-notification): Bump Medusa package versions (#2623) 2022-11-18 10:50:13 +01:00
Frane Polić
9eafde07fe feat(medusa-js): Register PublishableApiKey (#2616)
**What**
- register a publishable API key through `medusa-js` i.e. define the key that will be sent with each request

**How**
- introduce KeyManager class which is used to share keys between medusa-js objects.

**Usage**
1. Set the key through the `Medusa` config
2. Set the key through `KeyManager` dynamically:
```ts
import { KeyManager } from "medusa-js"

KeyManager.registerPublishableApiKey("pk_123")
```

---

RESOLVES CORE-794
2022-11-17 12:19:18 +00:00
Patrick
022a84691e fix(draft-order): create tax-inclusive with discount (#2579)
**What**
Fix system error (500) with DraftOrder create operation when payload includes discount in a tax-inclusive context.

**How**
* Ensure newly created cart contains all required relation in order to calculate line item tax-inclusive pricing with discounts.
* Add resilience to TotalsService.getLineDiscounts()
* Ensure newly generate line items have variant relation loaded.
* fix TotalsService.getLineItemTotals to use the passed lineItem instead of relying on cartOrOrder.items.

**Test**
* Unit:
  *  TotalsService.getLineDiscounts - coverage
* Integration:
  * Admin API draft-order - coverage
  * Admin API draft-order create w/ discount in tax-inclusive

Resolves: CORE-771

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2022-11-16 15:34:18 +00:00
Frane Polić
03fc9e18e9 feat(medusa, medusa-js, medusa-react): PublishableApiKey "update" endpoint & add "title" property (#2609)
**What**
- update PK endpoint
  - medusa-js/react implementation
- add a title property to the entity
  - update the migration file
  - pass a title on create
  - list PKs by title
  - update the client libs with new param signatures
- change id prefix to: "pk_"
2022-11-16 04:35:22 +00:00
Carlos R. L. Rodrigues
ccfc5f666d feat(medusa-js): Add payment and payment collections clients (#2608) 2022-11-15 21:27:00 +01:00
Frane Polić
3de553c27f feat(medusa-js, medusa-react): PublishableApiKeys clients (#2582)
**What**
- add `PublishableApiKeys` endpoints to the `medusa-js` and `medusa-react` clients

--- 

RESOLVES CORE-791
DEPENDS ON https://github.com/medusajs/medusa/pull/2567
2022-11-15 15:41:58 +00:00
Carlos R. L. Rodrigues
4baa2e0149 docs: payment and payment collection OAS (#2604) 2022-11-15 14:30:47 +00:00
Adrien de Peretti
9e91a50df1 fix(medusa-payment-stripe): Missing transactions in Stripe provider (#2603) 2022-11-14 20:03:06 +01:00
Frane Polić
d0809bdf25 feat(medusa): PublishableApiKeys CRUD (#2567) 2022-11-14 19:30:24 +01:00
Adrien de Peretti
d2b1848e52 feat(medusa): Cart and totals computational optimizations (#2475) 2022-11-14 15:45:47 +01:00
Carlos R. L. Rodrigues
755ba90c05 feat(medusa): Payment Collection endpoints (#2525) 2022-11-11 18:28:45 +01:00
olivermrbl
27184f3878 Merge branch 'master' into develop 2022-11-10 19:35:57 +01:00
olivermrbl
5dcbec3788 chore(release): Publish 2022-11-10 19:31:03 +01:00
Oliver Windall Juhl
04e894ec39 hotfix(medusa-payment-stripe): Support provider specific intent options (#2581) 2022-11-10 19:28:35 +01:00
Shahed Nasser
208809b635 docs: update readme (#2587)
* docs: added features list

* docs: update readme
2022-11-10 17:52:03 +02:00
Adrien de Peretti
699bb1d57b hotfix(medusa): Deleted region are missing on order retrieval (#2583) 2022-11-10 14:44:35 +01:00
Frane Polić
aa8eba38e9 feat(medusa): PublishableAPI keys model (#2543) 2022-11-10 10:14:06 +01:00
olivermrbl
7914f2a82a chore: Version medusa-payment-stripe 2022-11-09 20:36:31 +01:00
olivermrbl
a4dd26e137 chore(release): Publish 2022-11-09 19:34:59 +01:00
olivermrbl
41fc095a3d Merge branch 'master' into develop 2022-11-09 19:32:30 +01:00
Oliver Windall Juhl
cfb24d72fa fix(medusa-telemetry): Fix incorrect import (#2574)
Duplicate of #2126
2022-11-09 16:51:37 +00:00
Shahed Nasser
884322447e docs: fixes to the API reference (#2570) 2022-11-09 18:24:48 +02:00
Patrick
7b0ceeffb4 feat: /store api product types (#2552)
## What
Allow users to fetch ProductTypes from the storefront API.

## Why
This endpoint will allow developers to implement better faceted product search in Medusa without the need for search plugin. Developers will be able to use this to render refinement lists based on types, like this:
![image](https://user-images.githubusercontent.com/116003638/200417828-863065de-3607-49db-bd72-62a6815129fa.png)

## How
Endpoint `GET /store/products/types` and `GET /store/product-types` (use [product types listing in admin](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/api/routes/admin/products/list-types.ts) as reference)

Support added in @medusajs/medusa-js
Support added in medusa-react

## Testing
Similar automated tests as `GET /admin/products/types` and `GET /admin/product-types`

---

Resolves CORE-699
2022-11-09 16:10:17 +00:00
Adrien de Peretti
2d095a0ce1 fix(medusa): fix missing throw in the store cart create-payment-sessions (#2568) 2022-11-09 16:47:17 +01:00
Sebastian Rindom
8069ed5e99 fix(medusa): add support for retrying failed event bus jobs (#2566)
Closes CORE-770
2022-11-09 12:24:26 +00:00