Commit Graph

120 Commits

Author SHA1 Message Date
github-actions[bot]
628e8d22ee chore: Version Packages (#12691)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-06-25 11:41:13 +02:00
Riqwan Thamir
820a936b98 feat: add cookie options (#12720)
* feat: add cookie options

* feat: allow configuring hmr server port via the HMR_PORT env var

* support configuring HMR host and proto

* allow configuring the hmr client_port

* cleanup

* cleanup

---------

Co-authored-by: Harminder Virk <virk.officials@gmail.com>
Co-authored-by: Salvador Gironès <salvadorgirones@gmail.com>
Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
2025-06-25 11:18:28 +02:00
Adrien de Peretti
d517dbd66a feat(): Add support for jwt asymetric keys (#12813)
* feat(): Add support for jwt asymetric keys

* Create early-chefs-chew.md

* fix unit tests

* Add verify options support

* feedback

* fix unit tests
2025-06-25 10:29:32 +02:00
Adrien de Peretti
a833c3c98c fix(utils): build query withDeleted remove auto detection (#12788)
**What**
Currently, filtering data providing a `deleted_at` value will automatically apply the `withDeleted` flag which in turns remove the default constraint apply to all queries `deleted_at: null`. The problem is that it does not account for the value assign to `deleted_at` leading to inconsistent behaviour depending on the value. e.g filtering with `deleted_at: { $eq: null }` where the expectation is to only filter the non deleted record will end up returning deleted record as well by applying the `withDeleted` filters.

This pr revert this auto detection if favor of the user providing `withDeleted` explicitly, as it is already supported , plus the filters.

Further more, some integration tests demonstrate how to filter deleted records (e.g product) from the api. While the api did not properly support it, this pr adds support to pass with_deleted flags to the query and being handled accordingly to our api support. Validators have been updated and product list end point benefit from it. Also, the list config type was already accepting such value which I have translated to the remote query config.

Also, since the previous pr was adjusting the product types, I ve adjusted them to match the expectation
2025-06-25 07:51:37 +00:00
juanzgc
3826bde591 fix(medusa): Query Config update Order By filter (#12781)
**What**
Fixed a bug in the prepareListQuery function where nested field ordering was not properly building the expected nested object structure. The function was returning flat objects like { "employee.first_name": "ASC" } instead of the correct nested structure { "employee": { "first_name": "ASC" } }.

**Why**
The buildOrder function is designed to create nested objects from dot-notation field paths, which is essential for proper query building in the Medusa framework. When this functionality was broken, it prevented correct ordering of related fields and caused queries to fail or return unexpected results.

**How**
- Root cause: The `prepareListQuery` function was not properly utilizing the `buildOrder` utility function to transform dot-notation field paths into nested objects
- Before: order = "employee.first_name" → { "employee.first_name": "ASC" }
- After: order = "employee.first_name" → { "employee": { "first_name": "ASC" } }
- Added comprehensive tests: Created detailed unit tests for the prepareListQuery function focusing on buildOrder functionality, covering various scenarios including:
  - Simple ascending/descending order
  - Nested field ordering (e.g., product.title)
  - Deeply nested ordering (e.g., product.variants.prices.amount)
  - Multiple nesting levels (up to 5 levels deep)
- Added integration tests: Created integration tests in `product.spec.ts` to verify the full end-to-end functionality of nested ordering with variant titles

The fix ensures that the buildOrder function properly transforms dot-notation field paths into the expected nested object structure, enabling correct query building for related field ordering throughout the Medusa framework.

Resolves SUP-1868
2025-06-24 15:45:54 +00:00
Harminder Virk
94b62c6724 fix: initiate request container before other express middleware (#12761) 2025-06-19 07:23:15 +00:00
Adrien de Peretti
9bdd5429af fix(core, medusa-test-utils): Fix medusa test runner plugin modules loading (#12753) 2025-06-17 19:43:31 +02:00
Harminder Virk
00505b4f8e chore: upgrade to use glob 10 (#12754)
Glob 7 uses the `inflight` module, which leaks memory. Also, all other Medusa packages are using glob 10+. So upgraded the one used by the framework too.

Fixes: FRMW-2972
2025-06-17 12:52:27 +00:00
Adrien de Peretti
cbf3644eb7 chore(): Add retry strategy to database connection (#12713)
RESOLVES FRMW-2978

**What**
Add retry mechanism to database connection management to prevent failing when the server start faster than what makes the connection available
2025-06-13 07:18:49 +00:00
github-actions[bot]
68a796d300 chore: Version Packages (#12583)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-06-05 20:33:53 +02:00
Harminder Virk
cf0297f74a feat: implement stream based processing of the files (#12574)
Fixes: FRMW-2960

This PR adds support for processing large CSV files by breaking them into chunks and processing one chunk at a time. This is how it works in nutshell.

- The CSV file is read as a stream and each chunk of the stream is one CSV row.
- We read upto 1000 rows (plus a few more to ensure product variants of a product are not split into multiple chunks).
- Each chunk is then normalized using the `CSVNormalizer` and validated using zod schemas. If there is an error, the entire process will be aborted and the existing chunks will be deleted.
- Each chunk is written to a JSON file, so that we can process them later (after user confirms) without re-processing or validating the CSV file.
- The confirmation process will start consuming one chunk at a time and create/update products using the `batchProducts` workflow.

## Resume or not to resume processing of chunks

Let's imagine during processing of chunks, we find that chunk 3 leads to a database error. However, till this time we have processed the first two chunks already. How do we deal with this situation? Options are:

- We store at which chunk we failed and then during the re-upload we ignore chunks before the failed one. In my conversation with @olivermrbl we discovered that resuming will have to work with certain assumptions if we decide to implement it.
   - What if a user updates the CSV rows which are part of the already processed chunks? These changes will be ignored and they will never notice it.
   - Resuming works if the file name is still the same. What if they made changes and saved the file with "Save as - New name". In that case we will anyways process the entire file.
   - We will have to fetch the old workflow from the workflow engine using some `ilike` search, so that we can see at which chunk the last run failed for the given file.

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2025-05-29 05:42:16 +00:00
Harminder Virk
1f5f50010a fix: expand method ALL for bodyparser config and additional validator (#12612)
Fixes: FRMW-2969
2025-05-26 10:22:26 +00:00
Adrien de Peretti
7685d66c07 fix(framework): Fix compiler to create the dist after clean-up (#12582)
* fix(framework): Fix compiler to create the dist after clean-up

* Create angry-stingrays-fetch.md
2025-05-22 15:30:39 +02:00
github-actions[bot]
5ad3615830 chore: Version Packages (#12576)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-05-22 14:04:27 +02:00
Stevche Radevski
b9a51e217d feat: Add an analytics module and local and posthog providers (#12505)
* feat: Add an analytics module and local and posthog providers

* fix: Add tests and wire up in missing places

* fix: Address feedback and add missing module typing

* fix: Address feedback and add missing module typing

---------

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-05-19 19:57:13 +02:00
olivermrbl
8c0b49fed4 chore: Version packages 2025-05-16 11:04:39 +02:00
olivermrbl
d2dd2e7c72 chore: Version packages 2025-05-15 09:49:09 +02:00
olivermrbl
d3a5868e8b chore: Version packages 2025-05-13 12:56:07 +02:00
Carlos R. L. Rodrigues
b868a4ef4d feat(index): add filterable fields to link definition (#11898)
* feat(index): add filterable fields to link definition

* rm comment

* break recursion

* validate read only links

* validate filterable

* gql schema array

* link parents

* isInverse

* push id when not present

* Fix ciruclar relationships and add tests to ensure proper behaviour (part 1)

* log and fallback to entity.alias

* cleanup and fixes

* cleanup and fixes

* cleanup and fixes

* fix get attributes

* gql type

* unit test

* array inference

* rm only

* package.json

* pacvkage.json

* fix link retrieval on duplicated entity type and aliases + tests

* link parents as array

* Match only parent entity

* rm comment

* remove hard coded schema

* extend types

* unit test

* test

* types

* pagination type

* type

* fix integration tests

* Improve performance of in selection

* use @@ to filter property

* escape jsonPath

* add Event Bus by default

* changeset

* rm postgres analyze

* estimate count

* new query

* parent aliases

* inner query w/ filter and sort relations

* address comments

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-04-29 12:10:31 +02:00
olivermrbl
2fec5f4aa0 chore: Version packages 2025-04-23 09:27:02 +02:00
Harminder Virk
ee35f3ce90 fix: apply additional data validator using a global middleware (#12194) 2025-04-16 16:26:44 +05:30
Harminder Virk
b890263725 feature: add support for dynamoDB for storing sessions and some types cleanup (#12140) 2025-04-16 14:55:14 +05:30
Adrien de Peretti
2f6963a5fb fix(): Event group id propagation and event managements (#12157) 2025-04-14 15:57:52 -03:00
olivermrbl
d61694385d chore: Version packages 2025-04-11 10:25:36 +02:00
Adrien de Peretti
2a18a75353 chore(framework): slightly improve maybe apply link filter middleware (#12113)
**What**
- Use the resource id filtering when possible instead of relying on programmatic intersection checks over potential hundreds thousands of resources from the link when in fact it is not necessary to fetch everything to check in memory but instead check in the db 
- Also fix normalizeDataForContext middlewares
2025-04-09 04:03:10 +00:00
Adrien de Peretti
fc652ea51e fix(workflow-engine-*): scheduled jobs interval (#11800)
**What**
Currently only cron pattern are supported by scheduled jobs, this can lead to issue. for example you set the pattern to execute every hours at minute 0 and second 0 (as it is expected to execute at exactly this constraint) but due to the moment it gets executed we our out of the second 0 then the job wont get executed until the next scheduled cron table execution.

With this pr we introduce the `interval` configuration which allows you the specify a delay between execution in ms (e.g every minute -> 60 * 1000 ms) which ensure that once a job is executed another one is scheduled for a minute later.

**Usage**
```ts
// jobs/job-1.ts
const thirtySeconds = 30 * 1000

export const config = {
  name: "job-1",
  schedule: {
    interval: thirtySeconds
  },
}
```
2025-03-13 15:05:13 +00:00
Kasper Fabricius Kristensen
ec56a8bc85 fix(medusa,utils,test-utils,types,framework,dashboard,admin-vite-plugin,admin-bundler): Fix broken plugin dependencies in development server (#11720)
**What**
- Reworks how admin extensions are loaded from plugins.
- Reworks how extensions are managed internally in the dashboard project.

**Why**
- Previously we loaded extensions from plugins the same way we do for extension found in a users application. This being scanning the source code for possible extensions in `.medusa/server/src/admin`, and including any extensions that were discovered in the final virtual modules.
- This was causing issues with how Vite optimizes dependencies, and would lead to CJS/ESM issues. Not sure of the exact cause of this, but the issue was pinpointed to Vite not being able to register correctly which dependencies to optimize when they were loaded through the virtual module from a plugin in `node_modules`.

**What changed**
- To circumvent the above issue we have changed to a different strategy for loading extensions from plugins. The changes are the following:
  - We now build plugins slightly different, if a plugin has admin extensions we now build those to `.medusa/server/src/admin/index.mjs` and `.medusa/server/src/admin/index.js` for a ESM and CJS build.
  - When determining how to load extensions from a source we follow these rules:
    - If the source has a `medusa-plugin-options.json` or is the root application we determine that it is a `local` extension source, and load extensions as previously through a virtual module.
    - If it has neither of the above, but has a `./admin` export in its package.json then we determine that it is a `package` extension, and we update the entry point for the dashboard to import the package and pass its extensions a long to the dashboard manager.

**Changes required by plugin authors**
- The change has no breaking changes, but requires plugin authors to update the `package.json` of their plugins to also include a `./admin` export. It should look like this:

```json
{
  "name": "@medusajs/plugin",
  "version": "0.0.1",
  "description": "A starter for Medusa plugins.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "files": [
    ".medusa/server"
  ],
  "exports": {
    "./package.json": "./package.json",
    "./workflows": "./.medusa/server/src/workflows/index.js",
    "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
    "./modules/*": "./.medusa/server/src/modules/*/index.js",
    "./providers/*": "./.medusa/server/src/providers/*/index.js",
    "./*": "./.medusa/server/src/*.js",
    "./admin": {
      "import": "./.medusa/server/src/admin/index.mjs",
      "require": "./.medusa/server/src/admin/index.js",
      "default": "./.medusa/server/src/admin/index.js"
    }
  },
}
```
2025-03-11 11:28:33 +00:00
olivermrbl
f1cac99316 chore: Version packages 2025-03-10 15:44:09 +01:00
Adrien de Peretti
20cd59e622 Fix(framework): http cors middleware order and options (#11765)
FIXES SUP-1101
also fixes https://github.com/medusajs/medusa/issues/11743

**What**
The store cors is currently applied after the ensure publishable API key middleware, in this pr the order is fixed and the cors will be applied first.
2025-03-07 10:45:00 +00:00
Oli Juhl
3b470f4142 chore: remove ranges on medusa packages (#11738) 2025-03-06 14:17:05 +01:00
Adrien de Peretti
cc1309d370 chore(product): Improve product normalization and fix http router with tracing (#11724)
**What**
- Improve product normalization and prevent over fetching data
- Fix HTTP router wrap handler with tracing enabled
2025-03-05 13:04:25 +00:00
olivermrbl
5d74ac3cc3 chore: Version packages 2025-03-04 14:11:37 +01:00
Adrien de Peretti
5d184ba0c8 chore(framework): Unified resource loading and exclude non js/ts files (#11707)
* chore(framework): Unified resource loading and exclude non js/ts files

* chore(framework): Unified resource loading and exclude non js/ts files

* chore(framework): Unified resource loading and exclude non js/ts files

* chore(framework): Unified resource loading and exclude non js/ts files

* chore(framework): Unified resource loading and exclude non js/ts files

* Create six-parrots-shave.md
2025-03-04 13:21:37 +01:00
Harminder Virk
aabbbb7292 feat: Replace existing router with the new implementation (#11646) 2025-03-04 17:22:20 +05:30
Stevche Radevski
93dc10332d fix: Exclude the health endpoint from being logged (#11650) 2025-02-27 16:22:50 +01:00
Adrien de Peretti
ca6a15717d chore(): Add support for extra pool configuration (#11636)
**What**
Support more pool configuration
2025-02-27 10:33:08 +00:00
Harminder Virk
b0a16488e0 feat: add middleware-file-loader (#11638)
Fixes: FRMW-2920

The feature is called `middleware-file-loader`, because it does more than just collecting middlewares. It also collects the bodyParser config for routes
2025-02-27 09:42:29 +00:00
Oli Juhl
54a6ef91ac chore: Move token from params to headers (#11281)
* chore: Move token from params to body

* chore: Add type

* wip

* chore: clean up

* clean ip
2025-02-26 17:41:16 +01:00
Harminder Virk
9e2af4801d feat: add routes loader (#11592)
Fixes: FRMW-2919

This PR adds a new routes loader with a single responsibility of scanning the filesystem and collecting routes. Sorting of routes, merging middleware and registering them with express are going to separate implementations.

The new `RoutesLoader` class allows overriding routes as-well (not recommended though) and this is how routes are de-duplicated.

- When two routes for the exact route pattern/matcher are discovered, the routes loader will only keep the last one.

- Routes files can also override handlers for specific HTTP methods. For example, the original route file exported handlers for `GET` and `POST`, but the overriding one only defines `GET`. In that case, we will continue using the original implementation for the `POST` handler.

- If an overriding route file exports additional configuration like `export const AUTHENTICATION=false`, then this will only impact the handlers exported from this file and not the original handlers.

Routes sorting has been already been implemented in a separate PR and you can visualize it using this URL. https://routes-visualizer.fly.dev/
2025-02-26 07:24:10 +00:00
olivermrbl
3f7470022c chore: Version packages 2025-02-24 11:36:46 +01:00
Harminder Virk
feec0243ab feat: add middleware and routes sorter (#11526)
Fixes: FRMW-2918
2025-02-24 10:17:15 +00:00
Shahed Nasser
b60e1c855e fix(framework): add missing storefrontUrl from configuration type (#11511)
The `storefrontUrl` is defined in the `packages/core/types/src/common/config-module.ts` file, but for many purposes, including the documentation, we use the types defined in `packages/core/framework/src/config/types.ts`. This PR adds the `storefrontUrl` to the framework type
2025-02-18 17:29:59 +00:00
Adrien de Peretti
3b7856e8f5 feat(framework): Improve production structured logging with more valuable information as well (#11489)
* feat(framework): Improve production structured logging with more valuable information as well

* feat(framework): Improve production structured logging with more valuable information as well

* feat(framework): Improve production structured logging with more valuable information as well

* feat(framework): Improve production structured logging with more valuable information as well

* fix typo

* update trust proxy

* Create new-ligers-heal.md

* revert trust proxy
2025-02-17 18:16:33 +01:00
Kasper Fabricius Kristensen
47edd01dee fix(admin-vite-plugin,admin-bundler,ui,icons,dashboard,framework,types): Update Vite dependencies (#11414)
**What**
- Bumps the versions of Vite across the entire stack, to prevent an issue similar to what is described here: https://github.com/vitejs/vite/discussions/18271

Not entirely sure what was happening as I couldn't reproduce the issue, but Adrien faced the issue yesterday when working with local versions of our packages. It does appear as if the range we had before could lead to a version of Vite to be installed with said bug.
2025-02-12 10:09:39 +00:00
olivermrbl
682dcf6507 chore: Version packages 2025-02-11 12:00:43 +01:00
Oli Juhl
db03738b5f chore: Revert version range to ^ (#11390) 2025-02-11 11:35:25 +01:00
Riqwan Thamir
cf788ec49e chore(types,framework): pick ssl types from tls lib (#11381)
* chore(types,framework): pick ssl types from tls lib

* chore: call from node:tls directly
2025-02-11 09:52:33 +01:00
Shahed Nasser
c366ae3b61 chore(framework): add example of admin's vite configurations (#11283) 2025-02-03 16:30:06 +02:00
Carlos R. L. Rodrigues
e98d3c615e chore(orchestration): validate PK when throwIfKeyNotFound (#11190)
CLOSES: FRMW-2895
2025-01-29 19:17:36 +00:00
Harminder Virk
716de2cb3a fix: exit process with a status code when build fails (#11206)
Fixes: FRMW-2897
CLOSES CLO-434

Still need the frontend Admin bundler to provide some way to know if the build has failed or not.
2025-01-29 08:34:47 +00:00