Commit Graph

332 Commits

Author SHA1 Message Date
Harminder Virk
ecc09fd77d feat: generate modules mappings at runtime (#10791) 2025-01-03 15:49:47 +05:30
Ranjith kumar
1ef3e4b8de docs: update fulfillment provider module docs to reflect CalculatedShippingOptionPrice (#10778)
The return value below the example for the `calculatePrice` method is shown correctly as `CalculatedShippingOptionPrice` but the example is not updated in the guide "How to Create a Fulfillment Provider Module"

This PR updates the example in the guide and the TS doc
2024-12-31 11:44:17 +00:00
Harminder Virk
bbf790ea44 feat: deprecate remote link (#10768)
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-12-30 14:57:43 +05:30
Shahed Nasser
ce51c36ecf chore: improve payment provider tsdocs + generate reference (#10742) 2024-12-26 14:11:52 +02:00
olivermrbl
348f866ffe chore: Version packages 2024-12-20 11:25:36 +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
Riqwan Thamir
3f4d574748 feat(order, types): Add Credit Line to order module (#10636)
* feat(order, types): Add Credit Line to order module

* chore: add action to inject credit lines
2024-12-19 10:36:59 +01:00
Shahed Nasser
fec24aa7eb chore: improve tsdocs of fulfillment provider (#10649)
* initial changes

* small changes
2024-12-19 10:04:12 +02: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
Riqwan Thamir
632c340bf5 chore(utils): add comments + cleanup util functions (#10628)
remnants from https://github.com/medusajs/medusa/pull/10579
2024-12-17 14:22:33 +00:00
olivermrbl
a391a29aa8 chore: Version packages 2024-12-17 14:41:05 +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
Frane Polić
0c49470066 feat(core-flows): calculate SO price on cart ops (#10563)
**What**
- calculate the shipping option price when creating a shipping method
- calculate the shipping option price when refreshing cart
- add testing for calculated SO flow
- fix validation on calculated SO creation
- add manual fulfillment provider for testing
- add `from_location` to calculation context

---

RESOLVES CMRC-778
RESOLVES CMRC-602
RESOLVES SUP-136
2024-12-16 22:28:30 +00:00
Carlos R. L. Rodrigues
729eb5da7b chore(inventory): convert to dml (#10569)
Fixes: FRMW-2848

Co-authored-by: Harminder Virk <1706381+thetutlage@users.noreply.github.com>
2024-12-13 12:51:26 +00:00
Harminder Virk
ae1d875fcf fix: pluralization rule for the info word (#10599) 2024-12-13 16:09:09 +05:30
Shahed Nasser
54118941ef docs-util: support @version tag (#10591) 2024-12-13 09:40:47 +02:00
Shahed Nasser
7f669b8c5f chore: small tsdoc update to dml float property. (#10576) 2024-12-12 15:32:22 +02:00
Frane Polić
472e92e400 feat(medusa, core-flows, fulfillment): calculate SO price endpoint (#10532)
**What**
- endpoint + flow for fetching calculated price for a shipping option

---

CLOSES CMRC-777
2024-12-12 08:03:56 +00:00
Harminder Virk
885c82ded6 feat: add support for float properties (#10551) 2024-12-12 10:34:39 +05:30
Shahed Nasser
c3b2b4b438 chore: fixes to tsdocs + docs-util related to providers 2024-12-11 17:27:32 +02:00
Harminder Virk
16d27ea6e4 feat: Migrate customer module to DML (#10499) 2024-12-11 14:37:27 +05:30
Frane Polić
d8a92dbb2d feat(core-flows, dashboard, fulfillment, fulfillment-manual, utils, types): create shipping options with calculated prices (#10495)
**What**
- support creating SO with calculated price
- support updating SO for both types of pricing
- update `validateShippingOptionPricesStep` to handle both SO price_types
- add the `validateShippingOptionsForPriceCalculation` method to `FulfillementModule`
- add `canCalculate` and `calculatePrice` to fulfillment provider service service / interface / manual provider
- disable SO pricing edit on Admin if SO price type is calculated

---

CLOSES CMRC-776
2024-12-11 08:38:44 +00:00
Harminder Virk
fad85a9d29 refactor: migrate promotion module (#10410) 2024-12-11 13:12:39 +05:30
olivermrbl
0e342b491d chore: Version packages 2024-12-10 14:01:50 +01:00
Carlos R. L. Rodrigues
69f4c4f4e0 chore(index): index dml (#10482)
What:
- DML - `autoincrement` property
- Index `type` option (GIN)
- Index module - DML
2024-12-10 10:55:12 +00:00
Adrien de Peretti
0a077d48e1 chore(workflow-engine): Migrate to DML (#10477)
RESOLVES FRMW-2832
RESOLVES FRMW-2833

**What**
Migrate workflow engines to DML. Alos includes and update to the linkable generation which now takes into account id and primary keys to generate the linkable instead of only primary keys
2024-12-06 13:23:07 +00:00
Carlos R. L. Rodrigues
f65a3cc06d fix(utils): avoid optional properties on graphql generated file (#10476)
FIXES: SUP-367
2024-12-06 12:16:02 +00:00
Carlos R. L. Rodrigues
90ae187e09 fix(workflows-sdk): name for when/then step (#10459) 2024-12-05 15:47:42 -03:00
Sebastian Rindom
7ff3f15d6d fix(medusa): calculate sales channel availability correctly for variants (#10448)
* fix: calculate inventory quantities based on sales channel and locations

* Update packages/medusa/src/api/utils/middlewares/products/variant-inventory-quantity.ts

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* Update packages/medusa/src/api/utils/middlewares/products/variant-inventory-quantity.ts

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* Update packages/core/core-flows/src/product/steps/get-variant-availability.ts

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* fix: crk

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2024-12-05 19:29:47 +01:00
Adrien de Peretti
b160fd3cbf fix(utils): DML one to one definition (#10415)
RESOLVES FRMW-2819

**What**
Fix one to one definition.
2024-12-05 16:55:57 +00:00
Harminder Virk
0a16efa426 refactor: migrate cart module to DML (#10385)
FIXES: FRMW-2815

This PR has no breaking changes
2024-12-05 12:30:50 +00:00
Adrien de Peretti
90d7f4ff39 chore(utils): DML#hasOne allow mappedBy to not be defined (#10442)
RESOLVES FRMW-2826

**What**
We have many places where we define only one to one on one side of the relation. In that case it is a one to one that does not mapped by to the other side relation since it is not defined. This pr allow to create a one to one without mapped by. In order to remove breaking changes, in that case we ask the user to explicitly define the `mappedBy` as `undefined`
2024-12-05 09:31:38 +00:00
Harminder Virk
223bcff379 feat: add support for defining hasOne with FK (#10441) 2024-12-05 14:15:13 +05:30
olivermrbl
4723acd949 chore: Version packages 2024-12-04 18:36:57 +01:00
Frane Polić
ab948b7c65 feat(core-flows,medusa,order,types): update orders (#10373)
**What**
- add order update endpoint
- add workflows and steps for updating orders
- add `registerChanges` method to Order module + workflow step

---

CLOSES CMRC-633
2024-12-03 17:15:26 +00:00
Harminder Virk
3e98364bd1 feature: add support for check constraints in DML (#10391) 2024-12-02 17:59:50 +05:30
Adrien de Peretti
a1f36caaf7 chore(utils): Ensure DML name convention follow the same as the class name for simplicity (#10370)
**What**
DML class name and mikro orm entity name are different, it was ok and the idea was to accept that and do the transformation when needed. But since class name are usually upper case first we decided to re integrate that convention in the DML class name as well to simplify consumption of the dml name without having to worry about the normal case
2024-12-02 04:57:23 +00:00
Adrien de Peretti
ed11834d6e Fix(dml): DML default/nullable management (#10363)
RESOLVES FRMW-2813

**What**
Extract what we have done in the order module DML migration.
This includes all the changes we discussed around default value and nullable management

From now on, when the default is being set through the DML on a property, no default initializer will be created, this means that when a mikro orm class is being instantiated, no default will be applied at instantiation time. This fixes the issue when retrieving data and not selecting fields that have a default. The default initializer was taking the relay making you think the data was present except that it was the value of the default initializer. From now on, the default value is applied as follows
- db column default
- before flush
- on persist
The same applies for nullable properties/columns

Co-authored-by: Harminder Virk <1706381+thetutlage@users.noreply.github.com>
2024-11-29 11:46:26 +00:00
Harminder Virk
194361b95a fix: do not rely on model loading order to find an implicit owner (#10360) 2024-11-29 16:02:34 +05:30
Harminder Virk
d57c739052 fix: do not initialize FKs to null (#10337) 2024-11-28 17:15:08 +05:30
Riqwan Thamir
3b1a63eca7 feat(pricing,utils,types): add operator field to price rule (#10315)
what:

- adds an operator field to price rule with specific operator fields

RESOLVES CMRC-746
2024-11-28 09:23:26 +00:00
olivermrbl
e9c1b1127e chore: Version packages 2024-11-27 15:40:07 +01:00
Carlos R. L. Rodrigues
e9003c3124 fix(utils): read dir recursive (#10318)
What:
 - Using `Object.defineProperty) to avoid issues on Node versions that set this property as readonly.
2024-11-27 14:37:07 +00:00
Harminder Virk
9f204817b0 feat: convert MikroORM entities to DML entities (#10043)
* feat: convert MikroORM entities to DML entities

* feat: wip on repository changes

* continue repositories and types rework

* fix order repository usage

* continue to update product category repository

* Add foreign key as part of the inferred DML type

* ../../core/types/src/dml/index.ts

* ../../core/types/src/dml/index.ts

* fix: relationships mapping

* handle nullable foreign keys types

* handle nullable foreign keys types

* handle nullable foreign keys types

* continue to update product category repository

* fix all product category repositories issues

* fix product category service types

* fix product module service types

* fix product module service types

* fix repository template type

* refactor: use a singleton DMLToMikroORM factory instance

Since the MikroORM MetadataStorage is global, we will also have to turn DML
to MikroORM entities conversion use a global bucket as well

* refactor: update product module to use DML in tests

* wip: tests

* WIP product linkable fixes

* continue type fixing and start test fixing

* test: fix more tests

* fix repository

* fix pivot table computaion + fix mikro orm repository

* fix many to many management and configuration

* fix many to many management and configuration

* fix many to many management and configuration

* update product tag relation configuration

* Introduce experimental dml hooks to fix some issues with categories

* more fixes

* fix product tests

* add missing id prefixes

* fix product category handle management

* test: fix more failing tests

* test: make it all green

* test: fix breaking tests

* fix: build issues

* fix: build issues

* fix: more breaking tests

* refactor: fix issues after merge

* refactor: fix issues after merge

* refactor: surpress types error

* test: fix DML failing tests

* improve many to many inference + tests

* Wip fix columns from product entity

* remove product model before create hook and manage handle validation and transformation at the service level

* test: fix breaking unit tests

* fix: product module service to not update handle on product update

* fix define link and joiner config

* test: fix joiner config test

* test: fix joiner config test

* fix joiner config primary keys

* Fix joiner config builder

* Fix joiner config builder

* test: remove only modifier from test

* refactor: remove hooks usage from product collection

* refactor: remove hooks usage from product-option

* refactor: remove hooks usage for computing category handle

* refactor: remove hooks usage from productCategory model

* refactor: remove hooks from DML

* refactor: remove cruft

* cleanup

* re add foerign key indexes

* chore: remove unused types

* refactor: cleanup

* migration and models configuration adjustments

* cleanup

* fix random ordering

* fix

* test: fix product-category tests

* test: update breaking DML tests

* test: array assertion to not care about ordering

* fix: temporarily apply id ordering for products

* fix ordering

* fix ordering remove logs

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-11-26 20:01:02 +05:30
olivermrbl
ccf4e801f3 chore: Version packages 2024-11-25 12:14:36 +01:00
olivermrbl
4245312d8d chore: Version packages 2024-11-25 09:57:00 +01:00
Kasper Fabricius Kristensen
1659c9be5d feat(product,dashboard): Allow re-ordering images (#10187)
* migration

* fix snapshot

* primarykey

* init work on dnd

* progress

* dnd

* undo changes

* undo changes

* undo changes

* undo changes

* fix firefox issue

* lint

* lint

* lint

* add changeset

* undo changes to product module

* set activator node

* init work on service layer

* alternative

* switch to OneToMany

* add tests

* progress

* update migration

* update approach and remove all references to images in product.ts tests

* handle delete images on empty array

* fix config and order type

* update changeset

* rm flag

* export type and fix type in test

* fix type

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-11-25 09:03:10 +01:00
Adrien de Peretti
b964b45fb2 fix(stripe): Wrong container type (#10223)
RESOLVES SUP-238

**What**

wrong container type withing payment providers
2024-11-22 10:57:41 +00:00
mStenz
25d1dfdea5 Fix typo in db error message (#9612) 2024-11-21 13:48:22 +00:00
Carlos R. L. Rodrigues
42c08fa8e0 fix(framework): handle deprecated Dirent path (#10179)
What:

- `Dirent` class from `NodeJS` has different properties in different versions, causing issues in our loaders.
- Util `readDirRecursive` was introduced, avoiding old node versions to break

FIXES: https://github.com/medusajs/medusa/issues/8419
2024-11-20 20:25:48 +00:00