Commit Graph

1832 Commits

Author SHA1 Message Date
olivermrbl
233d6904f8 chore(release): Publish 2022-12-22 15:54:20 +01:00
Philip Korsholm
3f097b7987 allow module definitions to have no default package (#2878)
* allow module definitions to have no default package

* remove duplicated test

* update modulesresponse type
2022-12-22 14:51:24 +01:00
Philip Korsholm
37aaca0da4 feat(medusa): Extend Module Resolution configuration (#2864)
**What**
update module definitions in `ConfigModule` to support the following module configuration methods:
- none: defaults are loaded
- boolean `inventoryService: true|false`, if true the defaults are loaded, false throws if it's a required module, if the module is not required it's not loaded 
- string: `inventoryService: "..."`, treats the string as a path to the overriding module, (we dont handle the case where a string is given but the module is not overridable, we just load the default in that case)
- `ConfigurableModuleDeclaration = { resolve?: string, options?: Record } `, like plugins, options can be used to pass configs to the main service of the module, if not defined no options are passed. Resolve is like string, if defined it's used to look for a custom module, otherwise the default is loaded.

Testing: 
- Added unit tests for: 
  - `loaders/modules.ts`
  - `loaders/module-definitions/index.ts`

Fixes CORE-932
2022-12-22 12:20:57 +00:00
Adrien de Peretti
463f83ffdd feat(medusa): Ordering products on retrieval (#2815)
**What**

Move to transformQuery which adds a default ordering and also allows to order the product list from the store API

**How**
Among other things, fix the product repo to allow ordering by either a key from the product or a key from a relation

FIXES CORE-911
FIXES CORE-901
2022-12-22 10:33:53 +00:00
Adrien de Peretti
e27b1940c7 fix(medusa): Include items.variant relation in order calculation (#2869)
**What**

When an order require to decorate the totals, the variant relation should be added

FIXES CORE-930
2022-12-22 09:32:49 +00:00
Patrick
b700c6ba5b chore(oas): replace requestBody with $ref to req class JSDoc OAS (#2867)
### What

Move inline OAS requestBody schema declaration under their respective class-validator classes in order to expose them through  `#/components/schemas`. Replace inline OAS requestBody schema with a `$ref` reference pointing to the newly declared schema.

### Why

Having requestBody declared as its own "named" schema will allow OAS code generators to output typed entities/DTO that can be manipulate without having to reference the route/operation.

### How

Declare a new @schema JSDoc for each class-validator used to parse and validate request body. Move the current inline requestBody to the new @schema.

### Test

- Ran OAS validator.
- Ran docs build script.

Expect no visible changes to the documentation.

### Out-of-scope

requestBody of type `multipart/form-data` used for file uploads. These will be address as part of CORE-934
- [create-upload.ts](58d23a7b45/packages/medusa/src/api/routes/admin/uploads/create-upload.ts (L87-L90))
- [create-protected-upload.ts](58d23a7b45/packages/medusa/src/api/routes/admin/uploads/create-protected-upload.ts (L87-L90))

Path Parameter and Query Parameter. These will need more research and experimentation, part of CORE-931

---

Resolves CORE-853
2022-12-21 14:08:16 +00:00
Riqwan Thamir
8a60a73389 fix(medusa): gift card values & taxes are calculated correctly (#2777)
* chore: tax_rate is added to giftcards

* chore: minor

* chore: update gift card tax calculations to look at giftCard.tax_rate

* chore: gift card transactions use tax rate from gift card for legacy

* fix: gift cart total check for transaction should check the length

* chore: use tax exclusive cost + use giftcard tax rate for gctransactions + refactor

* chore: fix integration test

* chore: address issues brought up in comments

* chore: move gift card creation as a part of order service on order placed

* chore: add type handling for gift card creation

* chore: fix specs

* chore: use taxLines to calculate tax of a gift card

* chore: specs for line items containing gift cards and without

* chore: add integration specs + fix tax rate bug

* chore: round totaling + add GC application specs

* chore: cleanup trialables

* chore: write migration script to backfill gift cards with null tax_rate

* chore: update legacy totals service for gift cards

* chore: add changeset

* chore: address PR review changes

* chore: fix tests based on new totals calc

* chore: address review comments

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-12-20 22:24:25 +01:00
josetr
3113d8024f feat(medusa): Allow creating DraftOrders without items (#2719) 2022-12-20 18:37:42 +01:00
Patrick
a027d5ff9e chore(oas): PascalCase for schemas + remove x-resourceId (#2847)
### What

Rename all JSDoc OAS `@schema` and `$ref: #/components/schemas/` from snake_case to PascalCase, `foo_bar -> FooBar`

Extra scope: Remove `x-resourceId` from JSDoc OAS.

### Why

Classes use PascalCase as a convention but the OAS @schemas describing them were using snake_case. OAS code generators tend to use the schema name when generating typed models.

In order to avoid mismatch between source code, the OAS, and the generated client code, it is advised to align OAS @schemas formatting to the classes they represent.

Extra scope: x-resourceId is not a widely used OAS property. It's current usage in our OAS does not provide additional value. Therefore, we recommend to remove it in order to have one less item to maintain.

### How

Good old search & replace. Regex search to further make sure we didn't miss any.

The scope is limited to `@schema` definition and their usage in `$ref: #/components/schemas/`.

### Test

* Ran OAS validator.
* Ran docs build script.

Expect no visible changes to the documentation.

Resolves: CORE-852, CORE-859
2022-12-20 10:58:57 +00:00
josetr
2e5ceb7950 feat(medusa): Allow custom database schema (#2819) 2022-12-20 10:04:47 +01:00
Philip Korsholm
79cddc23da feat(medusa-file-s3): Allow all AWS options in config (#2809) 2022-12-20 10:01:30 +01:00
Oliver Windall Juhl
ba6bb3e54b feat(medusa): Extract cron job logic to its own service (#2821)
**What**
Extract cron job logic from the `EventBusService` to its own service `JobSchedulerService`

**Why**
Preliminary step to extracting the event bus into a module

**Tests**
Tested with a local installation of Medusa

Resolved CORE-918
2022-12-19 19:04:46 +00:00
Adrien de Peretti
c8724da503 feat(medusa,medusa-payment-stripe): Move database mutation from plugin to core (#2743)
**what**
The goal of that PR is to first refactor the payment provider and payment plugin to support the new API that removes the data mutation from within the plugin to be done by the core instead. In any case, this pr does not include the steps of the deeper refactoring. The last part will come in later pr.

**How**
- The payment plugin is now capable to handle both the deprecated and new API and the plugin works the same as it use to works.
- The mutation made by the plugin have been moved into the core as well as the subscriber
- The tests have been updated to reflect the changed
- Remove all new methods introduced by the payment collections
  - Mutualise types
  - Update provider and payment collection services
  - cleanup around all those refactoring including cleanup of the payment collection
  - refactor stripe payment plugin

FIXES CORE-887
2022-12-19 14:37:35 +00:00
Carlos R. L. Rodrigues
8dcc805ccf feat(medusa): Validate required id before retrieving (#2738) 2022-12-19 09:49:18 +01:00
Kasper Fabricius Kristensen
9e05fef4b9 fix(medusa): Fix q param on /admin/price-lists/:id/products (#2813) 2022-12-18 20:11:38 +01:00
Adrien de Peretti
5e4decbc1c fix(medusa): Batch job not saving the errors properly (#2812) 2022-12-16 20:13:53 +01:00
Philip Korsholm
c16522d6ce feat(medusa): Add has_account to list-customers query params (#2811) 2022-12-16 12:16:34 +01:00
Philip Korsholm
6283010fd6 Fix(medusa): Totals on draft orders (#2785)
* test subtotals on draft order operations

* fetch cart with subtotals when doing draft order operations

* write test for updating discounts seeing changes in totals

* formatting

* udpate test

* force taxes

* missing select

* add import

* rm force_taxes
2022-12-16 10:21:53 +01:00
Frane Polić
ea460b4e0b feat(medusa): add q param to PKs sales channels retrieval (#2810)
**What**
- enable to filter sales channels of a Publishable API Key with a free text search param

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-12-15 19:12:44 +00:00
Adrien de Peretti
0fa5042e35 feat(medusa): CSV formatter accounts for comma and semicolon (#2789)
Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-12-15 14:06:49 +01:00
Frane Polić
2d22b17b49 feat(medusa): Allow all relations on /admin/* endpoints (#2763) 2022-12-15 09:07:07 +01:00
Patrick
0a9c891853 chore: explicitly add devDependencies for monorepo peerDependencies (#2808) 2022-12-15 08:46:52 +01:00
Aaron Finocchiaro
b06794b08b feat(medusa-plugin-sendgrid) Add refund created event to sendgrid (#2740) 2022-12-14 19:37:01 +01:00
Adrien de Peretti
7cced6006a fix(medusa-core-utils): getConfigFile typings (#2783)
* fix: getConfigFile typeings

* Create brave-apes-carry.md

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-12-14 19:35:16 +01:00
Adrien de Peretti
71b536e01e chore(medusa): Replace inline Redis cache in favour of the CacheService (#2802)
* chore: Replace all usage of redis for the cache in favour of the cache service

* Create four-bugs-mate.md

* chore: missing new line
2022-12-14 18:11:10 +01:00
Patrick
7bb9cd6aff fix(medusa-js): missing devDependency was failing repo build task (#2804)
### What

Explicitly declare `@medusajs/medusa` as a devDependency for `@medusajs/medusa-js` client package.

### Why

With our latest version upgrade of `turbo`, peerDependencies aren't taken into account in the build graph. The recommendation is to also explicitly declare them in devDependencies.

### Test

* Run `yarn build --graph`
* Expect to see medusa-js having a dependency on medusa
```
"[root] @medusajs/medusa-js#build" -> "[root] @medusajs/medusa#build"
```
2022-12-14 16:46:08 +00:00
olivermrbl
8edf6a06ee Merge branch 'master' into develop 2022-12-14 14:47:23 +01:00
Jürgen
6531eb52ed docs: fixed typo in carts resource (#2798)
Co-authored-by: j.untch <j.untch@outlook.de>
2022-12-14 13:31:13 +02:00
Shahed Nasser
49383c0cbd docs: fix OAS comments in publishable api keys (#2796) 2022-12-14 11:29:39 +01:00
Philip Korsholm
e79794ea92 chore(medusa): Remove unused event from order service (#2793)
**What**
- remove unused event (legacy from claiming orders)
2022-12-14 09:43:47 +00:00
olivermrbl
01d521ed40 chore(medusa-js): Version package + add missing changeset 2022-12-14 09:37:20 +01:00
Patrick
17c3f34e3d chore(turbo): flip turbo caching glob from allow-list to deny-list (#2772)
### What

Flip Turborepo cache glob pattern from an allow-list to deny-list pattern.

### Why

Packages within medusa's monorepo will output their build to a `dist` directory. 

This convention does not apply to plugins since the core plugin loader expects the content of plugin packages `src` directory to be outputted at the root of the package. 

i.e. `packages/foobar-plugin/src/utils/index.ts` -> `packages/foobar-plugin/utils/index.js`

Manually maintaining an allow-list of known plugin output directories is not scalable. When a directory exists in a plugin package but is not know to the allow-list, the directory will not be re-built on subsequent builds. Troubleshooting the issue requires intimate knowledge of Turborepo caching strategies.

### How

By using a deny-list glob pattern, plugin packages can now declare any not-known directory within their `src` folder without facing any potential omission issues during the build process.

We declare `src` and its content as the only directory for turbo cache to ignore.

### Additional scope

* Use `turbo.json` file content in cache hashing algorithm in order to break CI cache when changes are made to the Turborepo config.
* Upgraded turbo minor verion.
* Added missing dependency to medusa package.

### Test
* Delete previously built output in packages. Run `yarn build --force` (replace any existing cache)
  * Expect all src content to be outputted
* Run `yarn build` right after
  * Expect a fast build time since cache will be fresh
* Add a new directory with an index.ts file in a plugin package src folder. Run `yarn build` 
  * Expect a fast build time, except for the modified plugin package.
  * Expect the newly added directory to be outputted.
* Delete the newly outputted directory. Run `yarn build`
  * Expect the outputted directory to reappear. 

### References
* 5093b82f3a/packages/medusa/src/loaders/plugins.ts
* https://turbo.build/repo/docs/reference/configuration#outputs
* https://turbo.build/repo/docs/reference/configuration#globaldependencies

Resolves CORE-891
2022-12-13 17:59:48 +00:00
olivermrbl
29135c0519 chore(release): Publish 2022-12-13 10:34:07 +01:00
Adrien de Peretti
b5d6682db6 feat(medusa): Allow regexp in CORS configuration (#1935) 2022-12-12 19:24:37 +01:00
Kasper Fabricius Kristensen
c2c38dd091 fix(medusa, medusa-react): Typing of optional fields on multiple product endpoints (#2771) 2022-12-12 19:10:06 +01:00
Frane Polić
3464617553 fix(medusa): Payment status on refunds (#2770) 2022-12-12 19:04:36 +01:00
Oliver Windall Juhl
b2ea8b7d45 fix(medusa): Throw on flat rate shipping options with no amount (#2628) 2022-12-12 18:34:30 +01:00
Adrien de Peretti
e63777e3c5 fix(medusa): Creating tax lines in cart completion strategy (#2761) 2022-12-12 18:28:41 +01:00
Adrien de Peretti
424efff919 feat(medusa): Allow to assign a Collection to a Product on import (#2764) 2022-12-12 17:10:03 +01:00
Kasper Fabricius Kristensen
33aa3edb80 fix(medusa): keep country_code when partially updating cart addresses (#2683)
**What**
- Fixes a bug where `country_code` was dropped when partially updating a shipping or billing address on a cart.
2022-12-12 14:03:54 +00:00
Adrien de Peretti
d68e81fb3d fix(medusa): Update line item adjustments upon cart discount removal (#2751)
**What**

When a discount is deleted from a cart, the line item adjustments must be refreshed. Now, the cart service `removeDiscount` includes updating the adjustments.

**Tests**

**Add a new integration test which:**
- create a cart with a discount 
- add a line item
- validate the adjustments
- remove the discount
- check that the adjustments are not present anymore

**Update unit tests**
The actual tests cases now check that the adjustments repository is called when needed

FIXES CORE-890
2022-12-12 09:53:40 +00:00
Kasper Fabricius Kristensen
72f70bc789 fix(medusa): Decorate order with totals in store domain (#2747) 2022-12-09 09:42:53 +01:00
Philip Korsholm
a6243618fe feat(medusa): Claim customer orders (#2710) 2022-12-08 17:48:49 +01:00
Riqwan Thamir
dbe25245b5 Merge branch 'develop' into fix/discount-regions-validation 2022-12-08 10:50:20 +01:00
olivermrbl
2b2ea157a6 chore(workflows): Fix merge conflicts with master 2022-12-07 20:28:32 +01:00
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