Commit Graph

285 Commits

Author SHA1 Message Date
Oli Juhl
c9b8db04c1 feat: Custom line items (#10408)
* feat: Custom line items

* fix tests

* fix migration

* Allow custom items in update line item workflow

* throw if line item doesn't have a price

* minor things

* wip

* fix flows

* fix test

* add default

* add to type
2024-12-18 12:53:57 +01:00
Oli Juhl
f3eca7734e fix(medusa): Missing metadata field on order (#10651) 2024-12-18 10:09:35 +01:00
Riqwan Thamir
6367bccde8 feat(medusa,pricing): Cart pricing context with customer group (#10579)
* fix(carts): Fixes cart modifications not accounting for certain price lists (#10493)

*What*

* Fixes #10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>

* chore: update cart workflows to accept new pricing context

* chore: add transfer specs

* chore: fix specs

* chore: modify types + specs

* chore: add data migration + dashboard changes

* chore: fix update line item workflow

* chore: add changeset + unskip spec

---------

Co-authored-by: Sergio Campamá <sergiocampama@gmail.com>
2024-12-17 11:10:30 +01:00
Riqwan Thamir
9e797dc3d2 feat(core-flows, types): update shipping methods upon cart ops (#10382)
* feat(core-flows,framework,medusa): list shipping options pass in cart as pricing context

* chore: add test for shipping options returning free shipping

* feat(core-flows, types): update shipping methods upon cart ops

* chore: fix specs

* chore: fix bugs + specs

* Update update-shipping-methods.ts

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

* Update mutations.ts

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

* chore: undo refresh changes

* chore: merge with latest

* chore: address PR comments

* chore: fix conflicts

* chore: fix specs

* chore: address reviews

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-12-08 14:06:50 +01:00
Oli Juhl
ff4663713a fix(core-flows): Listing return shipping options (#10432) 2024-12-04 17:21:07 +01:00
Riqwan Thamir
11bd556133 feat(core-flows,framework,medusa): list shipping options pass in cart as pricing context (#10374)
* feat(core-flows,framework,medusa): list shipping options pass in cart as pricing context

* chore: add test for shipping options returning free shipping
2024-12-01 20:59:26 +01:00
Oli Juhl
eacd691951 fix: Ensure tax lines are generated for all items and shipping methods in cart (#10372)
* fix: Generate tax lines for all items in cart

* fix: Correct test
2024-12-01 14:50:38 +01:00
Riqwan Thamir
b7044bb3b0 feat(core-flows,medusa): Add API to update cart's customer (#10151)
what:

- adds an endpoint that updates a cart's customer

RESOLVES CMRC-718
2024-11-19 11:44:25 +00:00
Sebastian Rindom
41dc05d0c9 fix: add address and customer metadata to tax calc context (#10122)
Fixes CMRC-713

**What**
- Ensure that customer and shipping address metadata is passed in the tax calculation context when updating tax lines on a cart.

**Why**
- Gives more flexibility in criteria to evaluate tax rates. 
- https://github.com/medusajs/medusa/discussions/10121
- https://github.com/medusajs/medusa/discussions/10114

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-11-19 11:42:31 +00:00
Carlos R. L. Rodrigues
1bae311a29 fix(core-flows): keep same customer on cart update (#9977)
* fix(core-flows): keep same customer on cart update

* update guest customer email

* create guest customer for new emails

* rm log
2024-11-10 14:11:40 +01:00
Carlos R. L. Rodrigues
03f4b66b90 fix(link-modules): generate graphql type of read only links (#9955) 2024-11-08 07:54:50 -03:00
Frane Polić
af9eec73df fix(core-flows): pass metadata on order fulfillment create (#9974)
CLOSES SUP-109
CLOSES https://github.com/medusajs/medusa/issues/9964
2024-11-07 19:13:44 +00:00
Oli Juhl
505768dd9f fix: Product type tax overrides (#9951)
* fix: Make product type tax override work

* fix: Make product type tax override work
2024-11-06 20:33:40 +01:00
Oli Juhl
c1c85ef952 fix(core-flows,medusa): Include region_id in shipping option retrieval (#9929)
### What
Include `region_id` when retrieving shipping options for a cart

### Why
Otherwise, region-specific prices will never show in the Store API

Closes CMRC-655 https://github.com/medusajs/medusa/issues/9906
2024-11-06 15:59:47 +00:00
Adrien de Peretti
f295596df2 fix(orchestration): Ids wrongly processed when using operators map (#9781)
* fix(orchestration): Ids processing when using operators map

* fix(orchestration): Ids processing when using operators map

* address feedback

* address feedback
2024-10-25 11:10:35 +02:00
Carlos R. L. Rodrigues
6fa98b6a4d chore(orchestration): modules method context (#9669)
** What **
* Test to check if the MedusaContext is being injected when calling a Module's method
2024-10-18 21:08:06 +00:00
Christian
a0b747e117 feat: allow html content for notifications (#9613)
* feat: allow passing provider specific metadata to notification module

* changed providerContext to snake cased

* rename provider_context to content
2024-10-18 11:36:22 +02:00
Harminder Virk
68560787e5 breaking: rename package names to be consistent and under @medusajs scope (#9580) 2024-10-16 22:28:09 +05:30
Riqwan Thamir
537567b679 chore: add compare_at_unit_price when price list price is retrieved (#9564)
* chore: add compare_at_unit_price when price list price is retrieved

* chore: add test for update item + more fixes along the way

* chore: fix tests

* chore: add refresh spec

* Apply suggestions from code review

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>

* chore: use undefined checker

* chore: switch to map

---------

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
2024-10-15 13:05:14 +02:00
Frane Polić
48cc00e991 feat(core-flows, product): options checks on product create/update (#9171)
**What**
- validate that variants are unique with respect to options on product update/create and variant update/create
- validate that the product has options upon creation
- ensure variants have the same number of option values as the product has options
- admin error handling
- update tests

---

FIXES FRMW-2707 CC-556
2024-10-15 09:06:51 +00:00
Oli Juhl
43324b9294 fix: Add shipping method data validation (#9542)
* fix: Add shipping method data validation

* fix: return type
2024-10-14 12:55:01 +02:00
Adrien de Peretti
1d8939df3a chore(): Allow to register modules through array (#9522) 2024-10-11 15:17:00 +02:00
Adrien de Peretti
34d57870ad chore: workflow internals improvementss (#9455) 2024-10-10 09:11:56 +02:00
Harminder Virk
1560d7ed5f breaking: Standalone builds (#9496)
Fixes: FRMW-2742

In this PR, we fix the build output of the backend source code, which eliminates a lot of magic between the development and production environments.

Right now, we only compile the source files from the `src` directory and write them within the `dist` directory.

**Here's how the `src` directory with a custom module looks like**

```
src
├── modules
│   └── hello
│       ├── index.ts
```

**Here's the build output**

```
dist
├── modules
│   └── hello
│       ├── index.js
```

Let's imagine a file at the root of your project (maybe the `medusa-config.js` file) that wants to import the `modules/hello/index` file. How can we ensure that the import will work in both the development and production environments?

If we write the import targeting the `src` directory, it will break in production because it should target the `dist` directory.

## Solution
The solution is to compile everything within the project and mimic the file structure in the build output, not just the `src` directory.

**Here's how the fixed output should look like**

```
dist
├── src
│  ├── modules
│  │   └── hello
│  │       ├── index.js
├── medusa-config.js
├── yarn.lock
├── package.json
```

If you notice carefully, we also have `medusa-config.js`, `yarn.lock`, and `package.json` within the `dist` directory. We do so to create a standalone built application, something you can copy/paste to your server and run without relying on the original source code.

- This results in small containers since you are not copying unnecessary files.
- Clear distinction between the development and the production code. If you want to run the production server, then `cd` into the `dist` directory and run it from there.

## Changes in the PR

- Breaking: Remove the `dist` and `build` folders. Instead, write them production artefacts within the `.medusa` directory as `.medusa/admin` and `.medusa/server`.
- Breaking: Change the output of the `.medusa/server` folder to mimic the root project structure.
- Refactor: Remove `Symbol.for("ts-node.register.instance")]` check to find from where to load the source code.
- Refactor: Use `tsc` for creating the production build. This ensures we respect `tsconfig` settings when creating the build and also perform type-checking.

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-10-09 15:59:08 +00:00
Oli Juhl
f7472a6fa6 fix: Idempotent cart completion (#9231)
What
- Store result of cart-completion workflow for three days by default
  - This enables the built-in idempotency mechanism to kick-in, provided the same transaction ID is used on workflow executions
- Return order from cart-completion workflow if the cart has already been completed
  - In case transaction ID is not used on workflow executions, we still only want to complete a cart once
2024-10-04 12:01:09 +00:00
Oli Juhl
6055f4c9cf fix: If country on cart has no tax region, clear tax lines (#9447)
**What**

If the country on the shipping address changes to a country without an associated tax region, we clear the tax lines on shipping methods and line items.
2024-10-04 11:55:53 +00:00
Oli Juhl
a114f90358 fix: Handle region updates on cart (1/n) (#9369)
**What**

On cart creation:
- If region only has one country -> create cart with country code

On cart updates:
- If shipping address country code is provided in input ->
  - If cart region doesn't include that country -> throw
  - If cart includes the country -> update shipping address
- If region is provided in input and is different from the one currently on the cart -> 
  - If there is a shipping address on the cart -> clear the address
    - If the region only has one country -> set country code of address
  - If there is not a shipping address on the cart ->
    - If the region only has one country -> set country code of address


Closes CC-545
2024-10-04 11:33:36 +00:00
Oli Juhl
8851ae7b51 fix: Update tax lines on cart when region changes (#9367)
**What**
- Removes broken cart retrieval step `retrieveWithCartLinks` in favor of `useRemoteQueryStep` in `updateTaxLinesWorkflows`

**Why**
- Filters variables in the step were passed with an incorrect shape
  - I removed the step, since it's only used once and the behavior is identical to the generic remote query step

**Note**
- Because the filters were passed incorrectly, the, now-removed, step has always returned the first cart in the database. As a result all tax calculations so far have been based on whatever the shape of that cart has. It basically ignores all input to this workflow
2024-09-30 11:55:54 +00:00
Oli Juhl
1b4372ae71 fix: Tax region + rates clean up (#9279)
What
- Require `code` on Tax Rates
- Update dashboard to account for non-nullable code on Tax Rates

- Include `automatic_taxes` in API Route response

Closes CC-524 CC-525
2024-09-29 10:25:33 +00:00
Sebastian Rindom
0efbcd2344 fix: validate regions exist for shipping option price update (#9364)
**What**
- Adds a step to `updateShippingOptionsWorkflow` and `createShippingOptionsWorkflow` that validates if the region prices being updated have corresponding regions configured.

**Why**
- Previously, if you tried to send a region price update for a region that had been deleted the backend would throw an error when attempting to insert the region price. The error comes from a not-null constraint in the db, but it is better to validate that the regions we are trying to create prices for exist. 

Fixes CC-542
2024-09-29 09:52:16 +00:00
Sebastian Rindom
17b2868a50 feat(medusa,fulfillment): pass stock location data to fulfillment provider (#9322)
**What**
- Fetches the stock location's details when creating a fulfillment and return fulfillment.
- Passes the data to the fulfillment module, which in turn passes it to the fulfillment provider.

**Why**
- When creating a fulfillment in a multi-location setup the fulfillment provider will need to know where the package is being sent from (so the shipping service can pick it up). 
- Previously, we didn't pass anything but the location id to the fulfillment provider. Because the fulfillment provider can't have a dependency on the stock location module this was not sufficient. 
- This change ensures there is enough data passed to the fulfillment provider to build integrations properly.
2024-09-28 14:01:48 +00:00
Carlos R. L. Rodrigues
19bc8d7f61 fix(core-flows): shipping options for cart (#9343)
FIXES: CC-536

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
2024-09-27 12:32:32 +00:00
Adrien de Peretti
38778b37e2 fix: remove dist access for modules in integration tests (#9336) 2024-09-27 09:11:03 +02:00
Adrien de Peretti
a8e19faf8d chore: use framework sub paths everywhere (#9253) 2024-09-26 16:38:38 +05:30
Adrien de Peretti
802f204d31 fix(orchestration): Throw if not exists using filters (#9275) 2024-09-24 17:12:04 +02:00
Carlos R. L. Rodrigues
b4b1a48987 feat(utils): define read only link (#9254) 2024-09-24 12:00:38 -03:00
Adrien de Peretti
3084008fc9 feat(index): Provide a similar API to Query (#9193)
**What**
Align the index engine API to be similar to the Query API

## Example

```ts
        // Benefit from the same level of typing like the remote query

        const { data, metadata } = await indexEngine.query<'product'>({
          fields: [
            "product.*",
            "product.variants.*",
            "product.variants.prices.*",
          ],
          filters: {
            product: {
              variants: {
                prices: {
                  amount: { $gt: 50 },
                },
              },
            },
          },
          pagination: {
            order: {
              product: {
                variants: {
                  prices: {
                    amount: "DESC",
                  },
                },
              },
            },
          },
        })
```
2024-09-20 10:02:42 +00:00
Carlos R. L. Rodrigues
1215a7c094 chore(orchestrator): remote joiner using entitymap (#9205) 2024-09-20 05:30:08 -03:00
Adrien de Peretti
58167b5dfa feat(index): Index module foundation (#9095)
**What**
Index module foundation

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2024-09-18 19:04:04 +00:00
Adrien de Peretti
c6795dfc47 feat(modules-sdk): Parse filters based on loaded modules graph (#9158) 2024-09-17 14:20:04 -03:00
Carlos R. L. Rodrigues
ef8dc4087e feat: run nested async workflows (#9119) 2024-09-16 13:06:45 +00:00
Carlos R. L. Rodrigues
950cf9af79 chore: remove container registration name (#9137) 2024-09-16 06:22:24 -03:00
Frane Polić
9db334554f fix(core-flows): item id in reservations (#9097)
**What**
- on cart completion, when creating reservations, use line item id instead of cart item id
- NOTE: inventory reservation is now done after we create the order

---

FIXES CC-448
2024-09-16 07:33:12 +00:00
Riqwan Thamir
a729fb3fbb feat(utils,types,framework,medusa): store endpoints should require publishable key (#9068)
* feat(utils,types,framework,medusa): store endpoints should require publishable key

* chore: fix specs

* chore: fix more specs

* chore: update js-sdk

* chore: fix specs wrt to default SC

* chore: revert custom headers + change error message

* chore: fix specs

* chore: fix new store specs
2024-09-11 15:08:37 +02:00
Carlos R. L. Rodrigues
fdd0543011 chore: joiner config entity property (#9084) 2024-09-11 06:25:25 -03:00
Riqwan Thamir
d398009d3f feat(payment): Payment providers are upserted upon loading (#9090) 2024-09-11 09:01:24 +02:00
Oli Juhl
4bf42f7889 fix: Update auth app_metadata when deleting users + customers (#9041)
* wip

* more work

* working on stuff

* more

* fix test

* remove incorrect test

* fix test

* fix: Only allow deletion of yourself

* remove redundant tests
2024-09-10 19:58:16 +02:00
Riqwan Thamir
afd0921326 fix(utils,medusa,order,cart): fix totals when promotions are included (#9014)
* fix(utils): fix totals when promotions are included

* chore: update totals calc

* chore: ignore taxes when taxable amount is 0

* chore: use subtotals everywhere

* chore: fix shipping totals + tests
2024-09-10 10:59:22 +02:00
Shahed Nasser
c962283281 fix(types, medusa): request / response types clean-up (#9043)
More clean-up of request / response types
2024-09-09 06:59:43 +00:00
Adrien de Peretti
2c5e72d141 feat: Application types generation from project GQL schema's (#8995) 2024-09-06 15:15:32 +05:30