Commit Graph

315 Commits

Author SHA1 Message Date
Riqwan Thamir
5eab9e7399 feat(promotion,dashboard,types,utils,medusa): Add statuses to promotions (#10950)
what:

- adds a status column to promotion table
- introduce active promotion query
- scope revert, register and compute actions to active promotions
- admin to create and update promotion with statuses

RESOLVES CMRC-845
RESOLVES CMRC-846
RESOLVES CMRC-847
RESOLVES CMRC-848
RESOLVES CMRC-849
RESOLVES CMRC-850
2025-01-16 19:17:22 +00:00
Stevche Radevski
da8e173974 feat: Remove fields from payment models that were leftovers from v1 (#10987) 2025-01-16 10:10:03 +01:00
Carlos R. L. Rodrigues
11f98f374c feat(core-flows): validate hook in cart workflows (#10967)
* feat(core-flows): validate hook

* rm only
2025-01-15 18:49:46 -05:00
Anuchit
79c87c09de fix(core-flow): invalid update quantity in update line item in cart workflow (#10405)
* fix: invalid update quantity in update line item in cart workflow

* test: update cart workflow test

* fix: rm shallow copy in transform
2025-01-05 14:39:29 +01:00
Frane Polić
fc321e96ce fix(core-flows): select stock locations for reservation from correct SC (#10661)
* fix: add stock location for reservations only if related to correct SC

* fix: update spec

* fix: wrong SC id get in OE flow

* fix: ensure test case has multiple SC and SLs
2024-12-20 09:25:19 +01:00
Adrien de Peretti
100da64242 chore(fulfillment, utils): Migrate module to DML (#10617)
**What**
- Allow to provide `foreignKeyName` option for hasOne and belongsTo relationships
  - `model.hasOne(() => OtherEntity, { foreignKey: true, foreignKeyName: 'other_entity_something_id' })`
  - The above will also output a generated type that takes into consideration the custom fk name 🔽 
- Update types to account for defined custom foreign key name
- Fix joiner config linkable generation to account for custom linkable keys that provide a public API for their model but are not part of the list of the models included in the MedusaService
  - This was supposed to be handled correctly but the implementation was not considering that custom linkable keys could reference models not part of the one provided to medusa service
- Migrate fulfillment module to DML
- Fix has one with fk behaviour and hooks (the relation should be assigned but not the fk)
- Fix has one belongsTo hooks (the relation should be assigned but not the fk)
- Fix hasOneWithFk and belongsTo non persisted fk to be selectable
- Allow to define `belongsTo` without other side definition for `ManyToOne` with no counter part defined
  - Meaning that if a user defined `belongsTo` on one side andnot mapped by and no counter part on the other entity it will be considered as a `ManyToOne`
- `orphanRemoval` on `OneToOne` have been removed, this means that when assigning a new object relation to an entity, the previous one gets deconected but not deleted automatically. This prevent removing data un volountarely

**NOTE**
As per our convention here are some information to keep in mind

**HasOne <> BelongsTo**
Define `OneToOne`, The foreign key is owned by the belongs to and the relation needs to be provided to cascade if wanted

**HasMany <> BelongsTo**
Define `OneToMane` <> `ManyToOne`, the foreign key is owned by the many to one and for those relation no cascade will be performed, the foreign key must be provided. For the `HasMany` the cascade is available

**HasOne (with FK)**
Will act similarly to belongs to with **HasOne <> BelongsTo**

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2024-12-19 16:40:11 +00:00
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
Riqwan Thamir
d1ce6d4321 Revert "feat(core-flows,medusa): Add customer validation on cart update" (#9724) 2024-10-22 18:26:01 +00:00
Riqwan Thamir
0d803b3f2d feat(core-flows,medusa): Add customer validation on cart update (#9662) 2024-10-22 12:19:12 +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
Carlos R. L. Rodrigues
902ac12f73 chore: remove internal module resources option (#9582)
What:
* removes resouces type "shared" or "isolated" from internal modules.
* modules can have an isolated database connection by providing a database config as part of their options on `medusa-config`

CLOSES: FRMW-2593
2024-10-17 21:31:46 +00:00
Harminder Virk
68560787e5 breaking: rename package names to be consistent and under @medusajs scope (#9580) 2024-10-16 22:28:09 +05:30
Carlos R. L. Rodrigues
4a03bdbb86 feat(providers): locking redis (#9544) 2024-10-15 12:40:24 -03:00
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
Adrien de Peretti
7e73fe4794 chore: Improve jest config and deps (#9318) 2024-09-30 10:50:59 +02:00
Harminder Virk
a578313db9 feature: bundle all modules (#9324) 2024-09-30 09:04:03 +02: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
ae320ac73f fix: base tsconfig (#9309)
* fix: base tsconfig

* WIP

* wi[]

* update integration typescript version

* update lock file

* fix deps

* fix medusa tests runner
2024-09-25 16:31:57 +02:00
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