Commit Graph

116 Commits

Author SHA1 Message Date
Adrien de Peretti
a095245d71 chore(): Upgrade mikro orm (#13390)
* chore(): Upgrade mikro orm

* handle 'null' value for big number props

* 6.5.2

* remove only

* fix pricing module rule value

* switch select in strategy for balances

* revert to select in strategy for order module

* fix defining DML ManyToOne

* fix define relationship

* test fix

* more fixes

* change order strategy to balanced

* change order strategy to balanced

* prevent unnecessary manager fork

* revert generated www changes

* remove unnecessary changes

* Create real-cobras-deny.md

* address feedback

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2025-09-08 21:10:44 +02:00
Oli Juhl
a0fca16570 feat: Add Draft Order plugin (#13291)
* feat: Add draft order plugin

* version draft order plugin

* update readme

* chore: Update scripts

* Create purple-dolls-cheer.md

* port over latest changes

* chore: Make package public
2025-08-27 10:14:17 +02:00
Harminder Virk
552dc52228 test: use shared as integration-tests level (#12278) 2025-04-28 18:41:19 +05:30
Oli Juhl
40b08f7325 chore: Patch changesets to avoid major bumps (#12151) 2025-04-11 10:18:31 +02:00
Harminder Virk
3704700a49 chore: remove husky (#9967)
Fixes: FRMW-2765, FRMW-2760

Since no one is using it for a very long time we can get rid of it

Closes: #9867
2024-11-07 07:54:30 +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
Carlos R. L. Rodrigues
d6ff526820 fix(link-modules): table name (#9151)
FIXES: FRMW-2706
2024-09-16 19:08:42 +00:00
Kasper Fabricius Kristensen
0fe1201435 feat(admin-sdk,admin-bundler,admin-shared,medusa): Restructure admin packages (#8988)
**What**
- Renames /admin-next -> /admin
- Renames @medusajs/admin-sdk -> @medusajs/admin-bundler
- Creates a new package called @medusajs/admin-sdk that will hold all tooling relevant to creating admin extensions. This is currently `defineRouteConfig` and `defineWidgetConfig`, but will eventually also export methods for adding custom fields, register translation, etc. 
  - cc: @shahednasser we should update the examples in the docs so these functions are imported from `@medusajs/admin-sdk`. People will also need to install the package in their project, as it's no longer a transient dependency.
  - cc: @olivermrbl we might want to publish a changelog when this is merged, as it is a breaking change, and will require people to import the `defineXConfig` from the new package instead of `@medusajs/admin-shared`.
- Updates CODEOWNERS so /admin packages does not require a review from the UI team.
2024-09-04 19:00:25 +00:00
Carlos R. L. Rodrigues
c9c1a5b41c chore: rm pg dependency (#8526) 2024-08-08 17:22:57 +00:00
Carlos R. L. Rodrigues
3f5ddc5bce chore: normalize packages version (#8492) 2024-08-08 13:52:05 +00:00
Adrien de Peretti
47dde05517 chore(framework): Initial commit (#8221)
**What**
- Initiate the framework package (which is just a place to move things around for now)
- move the config loader and related resources as well as the `ConfigModule` type
- Create a ConfigManager singleton which prepare and store the config (later can be stored entirely in the container) and allow for easier test override
- re export the logger from the framework
- replace medusa config loader with the framework one
- `build` run type check on tests as well but `prepublishOnly` will not fail on build if tests are typed broken

FIXES FRMW-2607
FIXES FRMW-2609
FIXES FRMW-2614
FIXES FRMW-2618
2024-07-23 15:46:28 +00:00
Riqwan Thamir
03924a4ff6 chore: move to swc/jest (#7739)
* chore: move to swc

* chore: fix tax rate tests

* chore: undo failed test

* chore: fix unit tests script

* chore: use node 20

* Update scripts/run-workspace-unit-tests-in-chunks.sh
2024-06-20 12:59:33 +02:00
Carlos R. L. Rodrigues
cfa983001b feat(order): create claim and exchange (#7734) 2024-06-18 08:08:16 -03:00
Riqwan Thamir
3d33f06e77 chore: upgrade jest everywhere (#7703) 2024-06-14 07:35:30 +02:00
Stevche Radevski
6698f3ab7b feat: Add http integration tests and enable them in pipeline (#7532) 2024-05-30 10:51:31 +02:00
Adrien de Peretti
f585b13c96 chore: remove babel usage (#7452) 2024-05-24 20:51:12 +02:00
Shahed Nasser
8b2429d24f chore(medusa-oas-cli,oas-github-ci): remove v2 option + generate v2 by default (#7304)
* chore(medusa-oas-cli,oas-github-ci): remove v2 option + generate v2 by default

* fixes to changeset

* fix public url path
2024-05-13 17:01:38 +03:00
Shahed Nasser
1a68f4602c feat(api-ref): show schema of a tag (#7297) 2024-05-10 21:07:35 +03:00
Adrien de Peretti
71f4f46cb9 chore(medusa): cleanup medusa package (#7206) 2024-05-07 12:48:49 +02:00
Adrien de Peretti
a736e728b8 fix: package.json run test integration in packages (#7249) 2024-05-06 19:25:37 +02:00
Shahed Nasser
651b953db7 fix(medusa-oas-cli, oas-github-ci): updated paths to docs directories following monorepo reorganization (#7245)
* fix(medusa-oas-cli, oas-github-ci): updated paths to docs directories following monorepo reorganization

* revert change to workspaces

* change oas in workspaces

* revert change in test script
2024-05-06 16:15:38 +03:00
Riqwan Thamir
e97b0125b5 chore: add build step to pipeline (#7219) 2024-05-05 10:08:31 +02:00
Adrien de Peretti
93f6e60c17 chore(): Modules providers reorganization (#7234)
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
2024-05-05 10:08:07 +02:00
Adrien de Peretti
bbccd6481d chore(): start moving some packages to the core directory (#7215) 2024-05-03 13:37:41 +02:00
Adrien de Peretti
4eae25e1ef chore(): Reorganize modules (#7210)
**What**
Move all modules to the modules directory
2024-05-02 15:33:34 +00:00
Riqwan Thamir
8eb2a4156d chore: disable turbo and jest cache (#7024)
* chore: disable turbo cache

* chore: remove cache for build

* chore: disable jest cache
2024-04-09 14:04:31 +02:00
Riqwan Thamir
bacfa3e17b feat(medusa-payment-paypal,medusa-payment-stripe): speed up unit tests in CI (#6806)
* chore: shard unit tests

* chore: move paypal and stripe to swc

* chore: update actions

* chore: refactor http paypal client

* chore: added changeset

* chore: remove medusa changes
2024-03-25 15:27:40 +01:00
Riqwan Thamir
4c98545ab3 feat: shard modules and API integration tests (#6775)
what:

- runs module and api integration tests in matrix strategy
  - v28 of jest comes with sharding support, which we can utilize when we upgrade
- splits the tests by number of matrix jobs and run them in parallel
  - This introduced some flakiness in some specs, but couldn't reproduce locally. Those have been skipped for now.
- uses swc/jest for added performance
  - Locally, a chunk took 90 seconds with babel and 30 seconds with swc. 
  - This translated to 2 mins saved per shard in CI, but haven't tested this enough.
2024-03-22 11:15:01 +00:00
Adrien de Peretti
e501e9effa chore: Run packages integration tests concurrently and not in band (#6576) 2024-03-04 14:17:07 +01:00
Oli Juhl
296d7faad4 chore: V2 core loader + modules integration-tests (#6544) 2024-02-29 16:46:30 +01:00
Shahed Nasser
f29948a6a8 docs-util: created docblock-generator tool (#6096) 2024-01-24 11:13:40 +01:00
Carlos R. L. Rodrigues
302323916b feat: Workflow engine modules (#6128) 2024-01-23 10:08:08 -03:00
Kasper Fabricius Kristensen
f868775861 chore: move next admin packages to core repo (#5983)
**What**
- Move packages for `next` version of admin to core repo

**Other**
- Since this PR introduces packages that depend on Vite 5, it also introduces @types/node@^20. We have never had a direct dependency on the types package for Node, and as far as I can see that has resulted in us using the types from Node.js@8, as those are a dependency of one of our dependencies. With the introduction of @types/node@^20, two of our packages had TS errors because they were using the NodeJS.Timer type, which was deprecated in Node.js@14. We should add specific @types/node packages to all our packages, but I haven't done so in this PR to keep it as clean as possible.
- Q: @olivermrbl I've added the new packages to the ignore list for changeset, is this enough to prevent them from being published?
2024-01-08 09:26:46 +00:00
Kasper Fabricius Kristensen
591ba2388d fix(ui): Bump cva and minor type fixes (#5818)
**What**
- Bumps `class-variance-authority` to new beta version - `cva@beta`.
- Updates all usages of `cva` to new API.
- Clear up the naming of types in `usePrompt`

**Why**
- A bug in how `class-variance-authority` exported its types mean that we were relying on patching the package to ensure that the correct types made it into the build of our UI package. This was important to ensure intellisense for component variants, such as `<Button size="large" />`. Previously in the UI monorepo, having the patch was enough to ensure that the correct types made it into the build, but that was not the case after we moved the design system to the core repo. The issue with types is fixed in the `@1` version of `cva` which is currently in beta. I have pinpointed the version to the current beta version to ensure stability despite the package currently being in beta.
2023-12-07 20:13:44 +00:00
Kasper Fabricius Kristensen
e4ce2f4e07 chore(ui,icons,ui-preset,toolbox): Move design system packages to monorepo (#5470) 2023-11-07 22:17:44 +01:00
Shahed Nasser
c1b97050ab feat(medusa-oas-cli,oas-github-ci): new options + added download of OAS in api reference (#5453) 2023-10-31 08:05:48 +01:00
Shahed Nasser
0350eeb0a1 docs: create typedoc theme and plugins for references (#5297)
* update typedoc and its plugins

* refactor existing typedoc configurations

* added new typedoc plugin and themes

* added more customization options

* added more customization options

* refactored doc-utils to a workspace

* fix tsconfig

* update README files

* remove comments

* revert type changes

* remove dependencies no longer needed

* removed modules action
2023-10-05 12:09:42 +03:00
Shahed Nasser
914d773d3a api-ref: custom API reference (#4770)
* initialized next.js project

* finished markdown sections

* added operation schema component

* change page metadata

* eslint fixes

* fixes related to deployment

* added response schema

* resolve max stack issue

* support for different property types

* added support for property types

* added loading for components

* added more loading

* type fixes

* added oneOf type

* removed console

* fix replace with push

* refactored everything

* use static content for description

* fixes and improvements

* added code examples section

* fix path name

* optimizations

* fixed tag navigation

* add support for admin and store references

* general enhancements

* optimizations and fixes

* fixes and enhancements

* added search bar

* loading enhancements

* added loading

* added code blocks

* added margin top

* add empty response text

* fixed oneOf parameters

* added path and query parameters

* general fixes

* added base path env variable

* small fix for arrays

* enhancements

* design enhancements

* general enhancements

* fix isRequired

* added enum values

* enhancements

* general fixes

* general fixes

* changed oas generation script

* additions to the introduction section

* added copy button for code + other enhancements

* fix response code block

* fix metadata

* formatted store introduction

* move sidebar logic to Tags component

* added test env variables

* fix code block bug

* added loading animation

* added expand param + loading

* enhance operation loading

* made responsive + improvements

* added loading provider

* fixed loading

* adjustments for small devices

* added sidebar label for endpoints

* added feedback component

* fixed analytics

* general fixes

* listen to scroll for other headings

* added sample env file

* update api ref files + support new fields

* fix for external docs link

* added new sections

* fix last item in sidebar not showing

* move docs content to www/docs

* change redirect url

* revert change

* resolve build errors

* configure rewrites

* changed to environment variable url

* revert changing environment variable name

* add environment variable for API path

* fix links

* fix tailwind settings

* remove vercel file

* reconfigured api route

* move api page under api

* fix page metadata

* fix external link in navigation bar

* update api spec

* updated api specs

* fixed google lint error

* add max-height on request samples

* add padding before loading

* fix for one of name

* fix undefined types

* general fixes

* remove response schema example

* redesigned navigation bar

* redesigned sidebar

* fixed up paddings

* added feedback component + report issue

* fixed up typography, padding, and general styling

* redesigned code blocks

* optimization

* added error timeout

* fixes

* added indexing with algolia + fixes

* fix errors with algolia script

* redesign operation sections

* fix heading scroll

* design fixes

* fix padding

* fix padding + scroll issues

* fix scroll issues

* improve scroll performance

* fixes for safari

* optimization and fixes

* fixes to docs + details animation

* padding fixes for code block

* added tab animation

* fixed incorrect link

* added selection styling

* fix lint errors

* redesigned details component

* added detailed feedback form

* api reference fixes

* fix tabs

* upgrade + fixes

* updated documentation links

* optimizations to sidebar items

* fix spacing in sidebar item

* optimizations and fixes

* fix endpoint path styling

* remove margin

* final fixes

* change margin on small devices

* generated OAS

* fixes for mobile

* added feedback modal

* optimize dark mode button

* fixed color mode useeffect

* minimize dom size

* use new style system

* radius and spacing design system

* design fixes

* fix eslint errors

* added meta files

* change cron schedule

* fix docusaurus configurations

* added operating system to feedback data

* change content directory name

* fixes to contribution guidelines

* revert renaming content

* added api-reference to documentation workflow

* fixes for search

* added dark mode + fixes

* oas fixes

* handle bugs

* added code examples for clients

* changed tooltip text

* change authentication to card

* change page title based on selected section

* redesigned mobile navbar

* fix icon colors

* fix key colors

* fix medusa-js installation command

* change external regex in algolia

* change changeset

* fix padding on mobile

* fix hydration error

* update depedencies
2023-08-15 18:07:54 +03:00
Adrien de Peretti
befc2f1c80 feat(product): Create (+ workflow), delete, restore (#4459)
* Feat: create product with product module

* feat: create product wip

* feat: create product wip

* feat: update product relation and generate image migration

* lint

* conitnue implementation

* continue implementation and add integration tests for produceService.create

* Add integration tests for product creation at the module level for the complete flow

* only use persist since write operations are always wrapped in a transaction which will be committed and flushed

* simplify the transaction wrapper to make future changes easier

* feat: move some utils to the utils package to simplify its usage

* tests: fix unit tests

* feat: create variants along side the product

* Add more integration tests an update migrations

* chore: Update actions workflow to include packages integration tests

* small types and utils cleanup

* chore: Add support for database debug option

* chore: Add missing types in package.json from types and util, validate that all the models are sync with medusa

* expose retrieve method

* fix types issues

* fix unit tests and move integration tests workflow with the plugins integration tests

* chore: remove migration function export from the definition to prevent them to be ran by the medusa cli just in case

* fix package.json script

* chore: workflows

* feat: start creating the create product workflow

* feat: add empty step for prices and sales channel

* tests: update scripts and action envs

* fix imports

* feat: Add proper soft deleted support + add product deletion service public api

* chore: update migrations

* chore: update migrations

* chore: update todo

* feat: Add product deletion to the create-product workflow as compensation

* chore: cleanup product utils

* feat: Add support for cascade soft-remove

* feat: refactor repository to take into account withDeleted

* fix integration tests

* Add support for force delete -> delete, cleanup repositories and improvements

* Add support for restoring a product and add integration tests

* cleaup + tests

* types

* fix integration tests

* remove unnecessary comments

* move specific mikro orm usage to the DAL

* Cleanup workflow functions

* Make deleted_at optional at the property level and add url index for the images

* address feedback + cleanup

* fix export

* merge migrations into one

* feat(product, types): added missing product variant methods (#4475)

* chore: added missing product variant methods

* chore: address PR feedback

* chore: catch undefined case for retrieve + specs for variant service

* chore: align TEntity + add changeset

* chore: revert changeset, TEntity to ProductVariant

* chore: write tests for pagination, unskip the test

* Create chilled-mice-deliver.md

* update integration fixtuers

* update pipeline node version

* rename github action

* fix pipeline

* feat(medusa, types): added missing category tests and service methods (#4499)

* chore: added missing category tests and service methods

* chore: added type changes to module service

* chore: address pr feedback

* update repositories manager usage and serialisation from the write public API

* move serializisation to the DAL

* rename template args

* chore: added collection methods for module and collection service (#4505)

* chore: added collection methods for module and collection service

* Create fresh-islands-teach.md

* chore: move retrieve entity to utils package

* chore: make products optional in DTO type

---------

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

* feat(product): Apply transaction decorators to the services (#4512)

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2023-07-16 20:19:23 +02:00
Oliver Windall Juhl
9b42387fd3 chore: Add missing deps (#4317) 2023-06-15 18:27:31 +02:00
Oliver Windall Juhl
afd1b67f1c chore: Clean up deps, devDeps, and peerDeps across all packages (#4276)
* chore: Use caret for all Medusa deps

* Create wild-balloons-push.md

* Address PR feedback

* force build order

* add missing dep

* add missing dev deps

* addresses last comments
2023-06-14 15:18:11 +02:00
Adrien de Peretti
14c0f62f84 feat: Product Module (#4161)
* chore: boilerplate setup

* wip: add Product, ProductTag, ProductType, ProductCollection models

* wip: `IProductService` definition

* wip: test function in index, build passing

* fix: where condition

* chore: get boilerplate working with modules sdk, create a boilerplate test, create product variant model, register services properly

* chore: added variant to model

* chore: changed definition details + add migrator

* cleanup and update product entity

* Update product unique index to include soft deleted

* Migrations tests

* generated migration

* update dev orm config

* add path aliases

* WIP

* chore: added boilerplate integration test + database helper + product variant migraiton + model

* chore: remove old test utils

* update ts and jest config to include path aliases

* tweak config

* WIP migrations variant

* Migrations round

* integration tests migrations polishing

* chore: fixed issues with test db

* fix path aliases when published

* use ts-alias

* fix connection loader

* fixes

* wip: product list

* (WIP): Data access layer

* (WIP): DAL cleanup services

* wip: `ProductTag` DAL

* wip: `ProductTag` expose list in product service

* (WIP): Continue DAL and test list product filtering/populate

* WIP: unit tests

* chore: added tests for service - productvariant

* chore: WIP finding issues with orm manager fork

* WIP fix fields selection

* chore: make text fixes work

* (WIP) product integration

* (WIP) product integration

* chore: create a product in variant test

* list product with relations

* wip: `ProductTag` service + integrations

* chore: added with and without serialization example

* chore: remove only in spec

* wip: `ProductCollection` service + integrations

* uncomment product.variants

* Update type IProductService

* (WIP) type work

* (WIP) Product variants relation

* WIP: replacable data layer

* (WIP): Use bundle types

* WIP: update type

* WIP upadte tests

* WIP

* wip: options/option values entites

* (WIP): cleanup

* wip: add option value to variant, fix collection

* Integration tests for custom data access layer

* update tests

* chore: merge with latest branch

* chore: scope tests to relations and add category to models/index

* chore: ignore dist folders for jest

* chore: modularize spec data file

* improve DX

* module fixture naming

* chore: added category tests + fix model

* chore: use kebab case

* chore: allow scoping products by category id

* chore: replace `kebabCase` import

* feat: add `deleted_at` to options

* improve typings

* chore: wip

* fix query util

* revert webpack

* fix: update option models, create option DTOs, tests wip, fix `deduplicateIfNecessary` returning `undefined`

* fix: merge conflict

* WIP connection

* rm unsues deps

* fix migrations

* fix query util

* chore: adds mpath on creation

* WIP update types

* improve typings

* WIP typeings improvement

* WIP

* deps

* chore: package medusa/product ot medusa-commerce/product

* chore: added product categories service + descendants filter

* add missing index

* Add support for strict categories not in

* Add support for strict categories not in

* lint

* rename module

* rename module

* Create small-ducks-doubt.md

* yarn lock

* update initialise

* chore: fix/finalise DTOs

* fix: wrong types in `IProductService`

* fix type

* Load database config from env if present (#4175)

* Load database config from env if present

* Load database config from env if present

* options optionnal

* update util

* add defaults

* improve filterable interfaces

* fix import

* fix types

* remove medusa-telemetry from modules-sdk

* WIP fixing webpack issues when bootstraping module

* cleanup

* improve loading driver options

* cleanup

* yarn lock

* fix import

* improve sdk types and naming

* align orther modules initialise method

* fix module tests with singleton module

* fix module tests with singleton module

* add up/down migration scripts

* update types

* scripts

* cleanup migrations and scripts

* hash module singleton

* cleanup migration

* cleanup

* fix stringifyCircular usage

* improvements

* fix deps

* fix deps

* improve load config utils

* improve load config utils

* fix deps

* add declaration to the build

* update yarn

* Do not resolve a module path if the exports are explicitly given

* fix module registration resolution path when exports are provided. Explicitly check for false and assign an empty string in this scenario for segregation purpose

* add comment

* fix migration options to prevent set replica errors

* chore: update types to a proper depedency

* chore: update type package

* add seed scripts

* Add descriptive error during database config loading

* use MedusaError

* chore: added lodash to package

* add more test to the database config loader util

* create bin scripts

* add bin

* update argv retrieval

* update package.json

* chore: add product category to injected deps

* chore: replace with product category service

* move dotenv usage to the functions

* do not load db if there is custom manager

* chore: fix some tests on products repo

* chore: fixed product spec

* chore: skip products module on modules register

* stringifyCircular update

* chore: fix incorrect module resolution

* fix: circular stringify and non required module loading

* yarn lock

* target es5

* chore: mikro-orm back to 5.7.4

* revert module registry

* skip external modules

* es2020

* update indexes, migration and integration tests

* rm only

* unit test script should only run unit tests

* Exclude product integration from the unit tests and make use of the global integration script to run all packages integration tests

* fix integration tests

* improve setup

* cleanup

* log error on setup fail

* Create enum like for package names

* chore: remove EOL

* chore: review part 2

* renamve gateway to productModuleService

* chore: added filters and collections to productmoduleservice

* chore: add collection to the singleton instance

* chore: remove skipped test + add todo

* fix indexes on fields and relations + update migration

* update yarn lock

* update idx

* add foreign key

* rename interface and add listCategories

* rename product module definition

---------

Co-authored-by: fPolic <frane@medusajs.com>
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
2023-06-09 20:47:24 +02:00
Oliver Windall Juhl
6511959e23 chore: Revert to official Typeorm package (#4072) 2023-05-11 13:08:38 +02:00
Oliver Windall Juhl
d539c6feeb chore: Bump Typeorm to Medusa fork (#3981)
* chore: Bump typeorm to medusa fork

* Update types + utils

* Bump integration test suites

* Create good-parents-prove.md
2023-05-02 14:37:19 +02:00
Oliver Windall Juhl
654a546223 chore: Bump Typeorm (#3778) 2023-04-11 18:43:40 +02:00
Oliver Windall Juhl
5280e1bdad chore: Automate releases (#3736)
* chore: Automate releases

* Update release.yml
2023-04-10 09:51:14 +02:00
Patrick
089f1eb19e feat(tests): harmonize and clean-up yarn test commands convention (#3695)
## What

Harmonize and clean-up yarn test commands convention.

## Why

Current strategy to filter integration tests from unit tests was cumbersome to maintain. Also, some packages declared `test:unit` which ended up being an alias to `test`.

## How

* Remove all occurrences of `test:unit`
* Rename all `test` commands under `/integration-tests/**/package.json` to `test:integration`
* In the root `package.json`, rewrite `test:integration` command to run `turbo run test:integration`
* In the root `package.json`, remove filtering on the `test` command
* Introduce a new `test:integration` task in the Turborepo config.
2023-04-04 13:47:54 +00:00
Patrick
7b57695e00 feat(codegen): x-expanded-relations (#3442)
## What

Alter generated types base on `x-expanded-relations` OAS extension declared on schemaObjects.

## Why

Often, API endpoints will automatically expand a model relations by default. They can also decorate a model with calculated totals. In order to more accurately represent the API, we wish to alter the generated types based on the expanded relations information.

## How

- Follow the relation declaration signature as the backend controllers and the `expand` query param, i.e.: `items.variant.product`.
- Introduce a custom `x-expended-relations` OAS extension.
- Allow for organizing declared relations to help their maintenance.
- Use traversal algorithms in codegen to support deeply nested relationships.
- Use [type-fest](https://www.npmjs.com/package/type-fest)'s `Merge` and `SetRequired` to efficiently alter the types while enabling great intellisense for IDEs.

Extra scope: 
* Added convenience yarn script to interact with the `medisa-oas` CLI within the monorepo. 

## Test

Include in the PR are two implementations of the x-expanded-relations on OAS schema, a simple and a complex one.

### Step 1
* Run `yarn install`
* Run `yarn build`
* Run `yarn medusa-oas oas --type combined --out-dir ~/tmp/oas`
* Run `yarn medusa-oas client --type combined --component types --src-file ~/tmp/oas/combined.osa.json --out-dir ~/tmp/types`
* Open `~/tmp/types/models/StoreRegionsRes`
* Expect relations to be declared as required

### Step 2
* Open `~/tmp/types/models/StoreCartsRes`
* Expect relations to be declared as required
* Expect nested relations to have relations as required.

### Step 3 (optional)
* Open `~/tmp/types` in an intellisense capable IDE
* Within the `index.ts` file, attempt to declare a `const storeRegionRes: StoreRegionRes = {}`
* Expect IDE to highlight that `countries` is a required field of `StoreRegionRes`
2023-03-13 14:21:56 +00:00
Patrick
55febef7f1 feat(types): package scaffolding for generated types (#3452)
## What

Generated client types package based on the API's OpenApi Spec.

## Why

This package aims at replacing the need to import types directly from the core `@medusajs/medusa` package which can lead to side effects like importing backend dependencies into the client's realm.

## How

* The package contains a script that is invoked during the build step. 
* The script will use the `medusa-oas oas --type=combined` cli to generate a combined oas file. 
* Then, `medusa-oas client --component=types` uses the oas file to generate the types based on the OAS schema definitions. The result is outputted into `/src/lib`
* `prettier` is run on the `/src/lib` directory to ensure that the generated code follows the monorepo coding style.
* Finally, with `"emitDeclarationOnly": true`,  `tsc` compiles the src directory to only output types.

Until we update our CI pipeline, we will not commit the content `/src/lib`.

## Test

* Run `yarn install`
* Run `yarn build`
* Expect `packages/generated/client-types/dist/` to contain types generated from the OAS defined by `@medusajs/medusa`
2023-03-13 12:23:26 +00:00