Commit Graph

1530 Commits

Author SHA1 Message Date
Sebastian Rindom
e539bdc620 chore: Fix CI pipeline (#1839) 2022-07-12 20:14:34 +02:00
olivermrbl
cf167d00b1 chore(release): Publish 2022-07-12 09:38:54 +02:00
olivermrbl
fb0346f1fa fix: Merge conflicts 2022-07-12 09:29:41 +02:00
Adrien de Peretti
b402b9f159 feat(medusa): Create default sales channel associated to the store (#1830)
**What**
Add support for default sales channel

**How**
- Implement a new method in the salesChannelService `createDefault`
- call the new method above in the default loader

**Test**
- Unit tests of the sales channel service method createDefaulta
- Init default loader unit tests

Fixes CORE-316
2022-07-11 21:05:28 +00:00
Philip Korsholm
19f35ba6aa Feat(medusa, medusa-js, medusa-react): Include sales channels in related queries as an optional expand parameter (#1816)
**What**
- Add `transformQuery` to get endpoints for product, order and cart
  - ensure that the default relations (when getting a singular entity) includes sales channels when enabled
- Add `EmptyQueryParams` class in common types to prevent query parameters while using `transformQuery`
- update product-, order- and cartFactory to include sales channels if provided
- remove `packages/medusa/src/controllers/products/admin-list-products.ts`

**Testing** 
- expands sales channel for single order
- expands sales channels for orders with expand parameter 
- returns single product with sales channel 
- expands sales channels for products with expand parameter
- returns cart with sales channel for single cart

Fixes CORE-293

Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2022-07-11 16:45:01 +00:00
Kasper Fabricius Kristensen
fb4cfc3c3c fix(medusa-react): Use correct type for hook useAdminCreateDraftOrder (#1832) 2022-07-11 16:14:10 +02:00
Oliver Windall Juhl
fb82d3dd22 fix(medusa): Add migration ensuring correct state of BatchJob model (#1825) 2022-07-11 15:50:01 +02:00
Sebastian Rindom
39f2c0c15e fix(medusa): calculates correct taxes and totals on order with gift cards (#1807)
**What**
Since the release of the Tax API the line item totals calculations on orders with gift cards have been wrong. To understand the bug consider the below order:

Region:
- tax_rate: 25%
- gift_cards_taxable: true

Order:
- applied gift card: 1000
- items: 
  - A: unit_price: 1000
  - B: unit_price: 500
- Subtotal: 1500

**Previous calculation method**
1. Determine how much of the gift card is used for each item using `item_total / subtotal * gift_card_amount`:
  - Item A: 1000/1500 * 1000 = 666.67
  - Item B: 500/1500 * 1000 = 333.33
2. Calculate line item totals including taxes using `(unit_price - gift_card) * (1 + tax_rate)`
  - Item A: 1000 - 666.67 = 333.33; vat amount -> 83.33
  - Item B: 500 - 333.33 = 166.67; vat amount -> 41.67
3. Add up the line item totals: order subtotal = 500; vat amount = 125; total = 625

This is all correct at the totals level; but at the line item level we should still use the "original prices" i.e. the line item total for item a should be (1000 * 1.25) = 1250 with a tax amount of 250. 

**New calculation method**
1. Use default totals calculations
  - Item A: subtotal: 1000, tax_total: 250, total: 1250
  - Item B: subtotal: 500, tax_total: 125, total: 625
2. Add up the line item totals: subtotal: 1500, tax_total: 375, total: 1875
3. Reduce total with gift card: subtotal: 1500 - 1000 = 500, tax_total: 375 - 250 = 125, total = 625

Totals can now be forwarded correctly to accounting plugins.

Fixes CORE-310.
2022-07-11 12:18:43 +00:00
Philip Korsholm
3e197e3adf feat(medusa): Add feature flags to store response (#1819)
**What**
- Add `feature_flags` string array to store response

**Why**
- to provide conditional ui in admin corresponding to enabled features

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-07-11 09:42:58 +00:00
Oliver Windall Juhl
02967f95b1 fix(medusa): Refresh adjustments when region on cart is changed (#1827)
* fix(medusa): Refresh adjustments when region on cart is changed

* fix test

* Fix unit test

* fix: integration tests

* fix: comment
2022-07-11 10:51:55 +02:00
dependabot[bot]
6a2fd3b361 chore(deps): bump moment from 2.29.1 to 2.29.4 in /packages/gatsby-source-medusa (#1818)
Bumps [moment](https://github.com/moment/moment) from 2.29.1 to 2.29.4.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/moment/moment/blob/develop/CHANGELOG.md">moment's changelog</a>.</em></p>
<blockquote>
<h3>2.29.4</h3>
<ul>
<li>Release Jul 6, 2022
<ul>
<li><a href="https://github-redirect.dependabot.com/moment/moment/pull/6015">#6015</a> [bugfix] Fix ReDoS in preprocessRFC2822 regex</li>
</ul>
</li>
</ul>
<h3>2.29.3 <a href="https://gist.github.com/ichernev/edebd440f49adcaec72e5e77b791d8be">Full changelog</a></h3>
<ul>
<li>Release Apr 17, 2022
<ul>
<li><a href="https://github-redirect.dependabot.com/moment/moment/pull/5995">#5995</a> [bugfix] Remove const usage</li>
<li><a href="https://github-redirect.dependabot.com/moment/moment/pull/5990">#5990</a> misc: fix advisory link</li>
</ul>
</li>
</ul>
<h3>2.29.2 <a href="https://gist.github.com/ichernev/1904b564f6679d9aac1ae08ce13bc45c">See full changelog</a></h3>
<ul>
<li>Release Apr 3 2022</li>
</ul>
<p>Address <a href="https://github.com/moment/moment/security/advisories/GHSA-8hfj-j24r-96c4">https://github.com/moment/moment/security/advisories/GHSA-8hfj-j24r-96c4</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="000ac1800e"><code>000ac18</code></a> Build 2.24.4</li>
<li><a href="f2006b6479"><code>f2006b6</code></a> Bump version to 2.24.4</li>
<li><a href="536ad0c348"><code>536ad0c</code></a> Update changelog for 2.29.4</li>
<li><a href="9a3b5894f3"><code>9a3b589</code></a> [bugfix] Fix redos in preprocessRFC2822 regex (<a href="https://github-redirect.dependabot.com/moment/moment/issues/6015">#6015</a>)</li>
<li><a href="6374fd860a"><code>6374fd8</code></a> Merge branch 'master' into develop</li>
<li><a href="b4e615307e"><code>b4e6153</code></a> Revert &quot;[bugfix] Fix redos in preprocessRFC2822 regex (<a href="https://github-redirect.dependabot.com/moment/moment/issues/6015">#6015</a>)&quot;</li>
<li><a href="7aebb1617f"><code>7aebb16</code></a> [bugfix] Fix redos in preprocessRFC2822 regex (<a href="https://github-redirect.dependabot.com/moment/moment/issues/6015">#6015</a>)</li>
<li><a href="57c90622e4"><code>57c9062</code></a> Build 2.29.3</li>
<li><a href="aaf50b6bca"><code>aaf50b6</code></a> Fixup release complaints</li>
<li><a href="26f4aef9ca"><code>26f4aef</code></a> Bump version to 2.29.3</li>
<li>Additional commits viewable in <a href="https://github.com/moment/moment/compare/2.29.1...2.29.4">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=moment&package-manager=npm_and_yarn&previous-version=2.29.1&new-version=2.29.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/medusajs/medusa/network/alerts).

</details>
2022-07-10 13:41:34 +00:00
Philip Korsholm
812ba65d8f feat(medusa): Add streaming to Minio fileservice (#1619) 2022-07-10 12:34:28 +02:00
Zakaria El Asri
9fa4238ee4 chore: improve ci pipeline (#1764)
* fix: caching deps + add true parallelization to integration tests api

* fix: github action

* chore: upgrade to yarn berry (#1762)

* init migration

* remove: yarn.lock from all pkgs

* fix: build script in pkgs

* adjust yarn config

* fix: yarn.lock and yarnrc.yml

* fix: github actions

* fix: wrong type

* fix (medusa-react): use dts-cli instead of tsdx

* fix: yarn.lock

* fix: yarn v

* fix: prepare script

* add: comment on why we need to downgrade yarn before medusa-dev

* chore: move to Turborepo (#1763)

* increase number of parallel nodes

* fix (medusa-fulfillment-webshipper): build script

* fix: use new version of medusa-dev

* fix: rename cache-bootstrap to cache-deps
2022-07-10 12:11:11 +02:00
Adrien de Peretti
6715eb11de fix(medusa): Export data should always provide a file_key (#1785) 2022-07-10 11:38:27 +02:00
dependabot[bot]
65aea2fe36 chore(deps): bump moment in /packages/medusa-dev-cli (#1822)
Bumps [moment](https://github.com/moment/moment) from 2.29.1 to 2.29.4.
- [Release notes](https://github.com/moment/moment/releases)
- [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/moment/moment/compare/2.29.1...2.29.4)

---
updated-dependencies:
- dependency-name: moment
  dependency-type: indirect
2022-07-10 11:34:47 +02:00
Derek Wene
41a757a5f8 fix(medusa): Add relations to cart retrieval to correctly calculate tax context (#1823) 2022-07-10 11:18:12 +02:00
Shahed Nasser
3b28f46705 docs: added reference for JS Client (#1629)
* added reference for JS Client

* added reference for JS Client

* added reference for JS Client
2022-07-08 18:21:46 +03:00
Adrien de Peretti
2d03634cfc feat(medusa, medusa-js, medusa-react): Implement Sales Channel deletion (#1804) 2022-07-07 10:47:51 +02:00
Sebastian Rindom
4d15e01c3e fix(medusa): calculate orders correctly by adding adjustments (#1812) 2022-07-07 07:35:12 +00:00
Frane Polić
0d1624cf6a feat(medusa, medusa-js, medusa-react): Implement Sales Channel creation (#1795) 2022-07-06 22:18:05 +02:00
Philip Korsholm
428a801293 feat(medusa-js, medusa-react): Update jsdoc with experimental annotation for sales channels (#1811)
**What**
- Add tag to indicate methods are part of an experimental feature under development

**Why**
- To notify developers because we cant support featureflags in the same way from the client side libraries.
2022-07-06 15:38:26 +00:00
Philip Korsholm
9d19cc0818 feat(medusa, medusa-js, medusa-react): Implement Sales Channel update (#1797) 2022-07-06 15:44:09 +02:00
dependabot[bot]
dae2d5abe0 chore(deps): bump parse-url from 6.0.0 to 6.0.2 (#1801)
Bumps [parse-url](https://github.com/IonicaBizau/parse-url) from 6.0.0 to 6.0.2.
- [Release notes](https://github.com/IonicaBizau/parse-url/releases)
- [Commits](https://github.com/IonicaBizau/parse-url/commits)

---
updated-dependencies:
- dependency-name: parse-url
  dependency-type: indirect
2022-07-06 12:40:07 +02:00
Adrien de Peretti
263a661031 feat(medusa, medusa-js, medusa-react): Implement Sales Channel retrieval (#1793) 2022-07-06 12:17:26 +02:00
Sebastian Rindom
e115518dda fix(medusa-payment-klarna): Join adjustments for total calculation (#1791) 2022-07-05 18:00:40 +00:00
Philip Korsholm
413b2850bf feat(medusa): SC service (#1784)
* add sales channel service and empty api index

* add integration testing file

* add tyeps

* remove ts directive

* add sales channel test

* update import

* remove unused import

* fix tests
2022-07-05 14:40:10 +02:00
olivermrbl
76cc10335f Merge branch 'master' into develop 2022-07-05 10:19:13 +02:00
olivermrbl
915359d84b chore: fix yarn.lock conflicts 2022-07-05 10:17:09 +02:00
olivermrbl
6b2a43abf1 chore(release): Publish
- medusa-dev-cli@0.0.26
2022-07-05 09:59:58 +02:00
olivermrbl
f87c268913 chore(release): Publish
- @medusajs/medusa-cli@1.3.1
 - medusa-dev-cli@0.0.25
 - medusa-file-minio@1.0.7
 - medusa-file-s3@1.1.3
 - medusa-file-spaces@1.2.3
 - medusa-fulfillment-webshipper@1.3.3
 - medusa-interfaces@1.3.1
 - @medusajs/medusa-js@1.2.3
 - medusa-payment-paypal@1.2.3
 - medusa-payment-stripe@1.1.41
 - medusa-plugin-algolia@0.2.3
 - medusa-plugin-brightpearl@1.3.1
 - medusa-plugin-contentful@1.2.3
 - medusa-plugin-ip-lookup@1.2.1
 - medusa-plugin-mailchimp@1.1.42
 - medusa-plugin-meilisearch@0.2.3
 - medusa-plugin-sendgrid@1.3.3
 - medusa-plugin-slack-notification@1.3.3
 - medusa-plugin-twilio-sms@1.2.3
 - medusa-react@0.3.3
 - medusa-source-shopify@1.2.1
 - @medusajs/medusa@1.3.3
2022-07-05 09:51:23 +02:00
Sebastian Rindom
f8138afa36 feat(medusa-dev-cli): adds helpers to manage feature flags (#1770)
**Usage**

**Create a new feature flag**
```
$ medusa-dev ff create [name of flag] -d [description of what flag is for]
```
Will put a new file in `packages/medusa/src/loaders/feature-flags/[kebab-cased-flag-name].ts` and fill out the details.

**List feature flags**
```
$ medusa-dev ff list
```
Note: your Medusa repo must be built for the flags to show up

**Delete a feature flag**
```
$ medusa-dev ff delete [name of flag]
```
Will delete a file at `packages/medusa/src/loaders/feature-flags/[kebab-cased-flag-name].ts` if it exists.
2022-07-05 07:33:46 +00:00
Frane Polić
f9c3218aac feat(medusa): Sales Channels model (#1782)
**What**
- added `SalesChannel` entity
- added `SalesChannel` repository
- added `SalesChannel` relations to the order, cart and store entities
- added a migrations file

**How**
- introduced entities and relations under a new feature flag "sales-channels"

Fixes CORE-271

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
2022-07-05 07:31:11 +00:00
Sebastian Rindom
9a14b84e58 fix: introduce listAndCount for gift cards to enable pagination (#1754)
**What**
Proper `listAndCount` implementation for gift cards.
2022-07-04 14:52:55 +00:00
Sebastian Rindom
9b5c2e8c1f hotfix(medusa): add line item adjustments for correct calculation in authorizePayment (#1772) 2022-07-04 14:50:16 +00:00
Philip Korsholm
41681b45b1 Feat(medusa): implement feature flags (#1768)
* feat: add feature flag loading in projects

* fix: make feature flag consume itself

* fix: rename container registration to featureFlagRouter

* fix: refactor

* behavioral feature flags

* add environment to server

* limit "useTemplateDb" to non feature flagged migrations

* filter migrations and entities according to those which are enabled in the environment

* run only migrations that are enabled when running 'medusa migrations run'

* add logging to the featureflag loader

* initial implementation of featureFlagEntity

* column descriptors

* initial startServerWithEnv (to be refactored)

* update commands

* final touches

* update loaders to fix unit tests

* enable all batch job tests

* update seed method

* add api test capabilities

* revert batch job test

* revert formatting changes

* pr feedback

* pr feedback

* remove unused imports

* rename feature flag decorators

* pr feedback

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-07-04 15:39:30 +02:00
Oliver Windall Juhl
f0704a7e17 chore(medusa-react): Move @medusajs/medusa to peerDeps in medusa-react (#1771)
* chore: Move @medusajs/medusa to peerDeps in medusa-react

* update README
2022-07-04 11:25:35 +02:00
Sebastian Rindom
1d3032dc67 fix(webshipper): allow cancelling WS orders with error status (#1755) 2022-07-04 07:57:35 +00:00
Oliver Windall Juhl
c76e23e84d fix(medusa): Remove deps mongoose + mongodb (#1218)
* fix(medusa): Remove deps mongoose, mongodb and transaction service + base model

* chore: delete permissions+add-ons legacy plugins

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-07-04 09:10:32 +02:00
Zakaria El Asri
8fe5fb5503 make medusa-dev-cli compatible with yarn 2/3 (#1765) 2022-07-03 11:24:41 +02:00
Derek Wene
3fb74bf512 feat: add customer to fetch-draft-order payload (#1444) 2022-07-02 21:54:35 +02:00
dependabot[bot]
9b53477b64 chore(deps): bump got from 10.7.0 to 11.8.5 (#1710)
Bumps [got](https://github.com/sindresorhus/got) from 10.7.0 to 11.8.5.
- [Release notes](https://github.com/sindresorhus/got/releases)
- [Commits](https://github.com/sindresorhus/got/compare/v10.7.0...v11.8.5)

---
updated-dependencies:
- dependency-name: got
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-02 17:48:37 +02:00
Oliver Windall Juhl
7bee57f7c5 fix(medusa-js): Fix stringifyNullProperties util (#1766)
**What**
Changes the order of object type evaluation to properly handle null properties.

Previously, `stringifyNullProperties({ test: null })` would fail in the 2nd iteration due to an attempt to iterate `null` in `Object.keys(obj)`.
2022-07-02 15:29:27 +00:00
Adrien de Peretti
e53c06eab8 feat(medusa): Apply query transformers to Collection and CustomerGroups (#1667) 2022-07-02 13:01:52 +02:00
Sebastian Rindom
fee0f88a62 fix: add shipping taxes (#1759)
**What**
Adds taxes to the shipping prices when listing in admin. Allows store operators to see correct prices when processing returns.
2022-07-02 10:35:16 +00:00
Sebastian Rindom
f7e300e8ce fix(meilisearch): remove medusa-interfaces dependency (#1751)
Remove `medusa-interfaces` from dependencies. `medusa-interfaces` should only be a peer dependency
2022-07-02 09:09:48 +00:00
Sebastian Rindom
c0e18d473c fix(webshipper): only add invoices if invoice generator produces a file (#1749) 2022-07-02 09:05:20 +00:00
Philip Korsholm
198681f7d8 Feat(medusa): Convert fulfillment service to typescript (#1659)
**What**
- convert fulfillment service to typescript


I have removed the `transform` parameter from the getFulfillmentItems_ function since it was not being used with different methods, only `validateFulfillmentLineItem_`. Instead I have just reference the validateFulfillmentLineItem_ function directly. 

We have the same pattern across some different methods, is there a specific reason or just for future proofing?
2022-07-02 07:28:38 +00:00
Adrien de Peretti
fc1cbe72c7 feat(medusa-js): Create utils to stringify null values and respect object types (#1748)
### What

At the moment it is not possible to pass explicitly null on a property since the qs.stringify will transform it as `url?property=` which is then interpreted on the backend side as `""` value which is not what we expect.
The actual way to pass null value is to set the property as `{ prop: "null" }` in order to get the stringify method to send it correctly.

### How

I just created a small util that loop through the input object and transform all null values to "null" before being passed to the qs.stringify method.

The new util is only applied on the list batch job since this is for now the only place that require that behaviour.
2022-06-30 09:17:57 +00:00
Adrien de Peretti
9e0f65dee3 fix(medusa-react): Allow to not invalidate any cache (#1756)
### What
At the moment, it is not possible to not invalidate any queries>
Example, when we want to Create a new signed url, it does not require to invalidate any of the queries.
But the way it is done in the buildOptions, require to give either a key or an array of keys. 

### How
The behaviour for empty array is to invalidate all the queries and here we would like to be able to just pass undefined in order to not trigger the invalidation. The update allow the arg to be optional and check for undefined explicitly before choosing the invalidation
2022-06-30 09:01:31 +00:00
Philip Korsholm
9018d270be Feat(medusa-js, medusa-react): Upload endpoints in medusa js and react (#1716)
* export types from admin uploads

* add delete and download to medusa-js

* add upload endpoints to hooks

* remove upload from js and react

* pr feedback

* Apply suggestions from code review

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>

* rename types for admin uploads

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-06-29 11:36:19 +02:00