Commit Graph

73 Commits

Author SHA1 Message Date
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
Patrick
240d0ea7b8 fix(ci,oas) move oas ci script to a package under the oas workspace (#3391)
* feat(ci,oas) run oas ci on all PRs

* fix(ci,oas) move oas ci script to a package under the oas workspace

* chore(changeset): patch
2023-03-07 10:33:12 +01:00
Kasper Fabricius Kristensen
40de54b010 feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334) 2023-03-03 10:09:16 +01:00
Riqwan Thamir
121b42acfe chore(medusa): Typeorm upgrade to 0.3.11 (#3041) 2023-02-15 16:25:30 +01:00
Patrick
8137061908 feat(oas): medusa-oas-cli as OAS build tool (#3213)
## What

Introduce a CLI for extracting OAS from the core `medusa` package.

## Why

We need to decouple OAS tooling from documentation tooling in order to allow packages and external systems to leverage our OAS has a dependency.

## How

Introduce a new OAS workspace within packages in order to organize current and future OAS related package. Only 1 OAS package for now.

Introduce a new CLI only package to act as the main gateway for all upcoming OAS tooling. Only 1 command for now.

Update documentation tooling pertaining to OAS to use the CLI instead.

## Test

### Prerequisite
From the monorepo root:
* `yarn install`
* `yarn build`

### Documentation

#### Case - validation only - success
* Run `yarn openapi:generate --dry-run`
* Expect console output `🟢 Valid OAS` but no mention of `🔵 Exported OAS`

#### Case - validation only - invalid
* Introduce a bug by renaming `@schema Cart` to `@schema Kart` in [models/cart.ts](0adb0d9ff9/packages/medusa/src/models/cart.ts (L2))
* Run `yarn build` to update `@medusajs/medusa` package with the bug.
* Run `yarn openapi:generate --dry-run`
* Expect console output `🔴 Invalid OAS` with a stack trace of the issue.

#### Case - docs generation
* Run `yarn openapi:generate`
* Expect `docs/api/` directory to contain:
  * `admin.oas.json` (raw OAS)
  * `store.oas.json` (raw OAS)
  * `admin.oas.yaml` (sanitized OAS)
  * `store.oas.yaml` (sanitized OAS)
  * `admin/` (updated redocly split output)
  * `store/` (updated redocly split output)

### CLI

#### Case - crawl additional paths
* From a local medusa server (`medusa-starter-default`), add an `index.ts` file in `src/models/`
* In the `index.ts`, add dummy OAS JSDoc like `/** @schema Foobar */`
* From the root of the monorepo, run `yarn medusa-oas --type store --paths path-to-medusa-server/src`
* Expect a `store.oas.json` to be created at the root of the monorepo.
* The `store.oas.json` should contain an additional `Foobar` entry in `components.schemas`.
2023-02-15 14:55:58 +00:00
Patrick
53532df8d5 feat(OAS): sanitize circular reference for Redocly (#3198)
### What

Add OAS build step to patch known circular references that prevent Redocly from rendering the API documentation.

### Why

We've encountered crashing and loading issues with Redocly when the OAS contained circular references. We have been working around the limitation by omitting some known problematic $ref in our source OAS. We wish to move away from this strategy in order to always explicitly include $ref in our OAS.

### How

We are introducing a custom Redocly CLI plugin that will replace `$ref` by `type: object` base on a configurable set of instructions. These instructions can be modified in `docs-util/redocly/config.yaml`

We are adding a `redocly bundle` step in the current OAS build process in order to sanitize problematic circular references.

We updated the redocly-cli package version in order to ensure that plugins are supported.

### Test

We will use [Cart.payment](fd5c185159/packages/medusa/src/models/cart.ts (L72-L74)) to ensure that the new process is properly sanitizing.

* Run `yarn openapi:generate`
* Open `docs/api/store/components/schemas/Cart.yaml`
  * Expect the `payment` property to have been sanitized to `type: object`
* Run `yarn redocly preview-docs docs/api/store/openapi.yaml --config=docs-util/redocly/config.yaml`
* Visit http://127.0.0.1:8080/#tag/Cart/operation/GetCartsCart
  * In the response, expect cart.payment to not list the properties of the Payment schema.
2023-02-08 13:01:03 +00:00
Oliver Windall Juhl
08324355a4 chore: Patch bump all dependencies + minor bumps winston (#3185) 2023-02-07 19:15:29 +01:00
Carlos R. L. Rodrigues
f776ed234f feat(medusa): Run shared module migrations (#3109) 2023-02-01 08:10:59 -03:00
Riqwan Thamir
b280e53bd3 refactor(medusa): move repository specs into its own folder (#2952)
**What:**

Introduces a new folder under which repository specs will be placed. 

Why:

We don't currently have a good place to test ORM logic or custom queries against the database. The repository folder tests are a place for just exactly that. 

How:

Creates an internal package similar to other integration tests - api and plugins. 

CORE-965
2023-01-09 08:19:01 +00:00
Shahed Nasser
d1b4b11ff6 chore(docs): added eslint to lint documentation code blocks (#2920)
* docs: added rule for code length

* chore: fixes based on vale errors

* changed to use eslint

* fixes using eslint

* added github action for documentation eslint

* changed allowed max-length

* fixed incorrect heading level

* removed comment
2022-12-30 18:44:46 +02:00
Philip Korsholm
d8893d6b9f chore: Update release tag from staging to next (#2858) 2022-12-20 12:21:48 +01:00
Patrick
17c3f34e3d chore(turbo): flip turbo caching glob from allow-list to deny-list (#2772)
### What

Flip Turborepo cache glob pattern from an allow-list to deny-list pattern.

### Why

Packages within medusa's monorepo will output their build to a `dist` directory. 

This convention does not apply to plugins since the core plugin loader expects the content of plugin packages `src` directory to be outputted at the root of the package. 

i.e. `packages/foobar-plugin/src/utils/index.ts` -> `packages/foobar-plugin/utils/index.js`

Manually maintaining an allow-list of known plugin output directories is not scalable. When a directory exists in a plugin package but is not know to the allow-list, the directory will not be re-built on subsequent builds. Troubleshooting the issue requires intimate knowledge of Turborepo caching strategies.

### How

By using a deny-list glob pattern, plugin packages can now declare any not-known directory within their `src` folder without facing any potential omission issues during the build process.

We declare `src` and its content as the only directory for turbo cache to ignore.

### Additional scope

* Use `turbo.json` file content in cache hashing algorithm in order to break CI cache when changes are made to the Turborepo config.
* Upgraded turbo minor verion.
* Added missing dependency to medusa package.

### Test
* Delete previously built output in packages. Run `yarn build --force` (replace any existing cache)
  * Expect all src content to be outputted
* Run `yarn build` right after
  * Expect a fast build time since cache will be fresh
* Add a new directory with an index.ts file in a plugin package src folder. Run `yarn build` 
  * Expect a fast build time, except for the modified plugin package.
  * Expect the newly added directory to be outputted.
* Delete the newly outputted directory. Run `yarn build`
  * Expect the outputted directory to reappear. 

### References
* 5093b82f3a/packages/medusa/src/loaders/plugins.ts
* https://turbo.build/repo/docs/reference/configuration#outputs
* https://turbo.build/repo/docs/reference/configuration#globaldependencies

Resolves CORE-891
2022-12-13 17:59:48 +00:00
Patrick
86f9455d00 test: allow integration-tests to leverage workspaces optimizations (#2727)
### What
Leverage yarn workspaces and Turborepo for integration-tests in order to accelerate development and reduce DevX complexity.

### Why
The current solution for running integration tests requires using `medusa-dev-cli` in order to publish packages to a local npm repository. The package where the command is executed will have its package.json altered for any known medusa dependency in order to install from the local npm. The process is taxing on the host machine resources and prevents rapid iterations when working with integration tests.

For more information, see documentation: f0cc1b324c/docs/content/usage/local-development.md (run-api-integration-tests)

### How
By declaring `integeration-tests/**/*` as a workspace, Turborepo can now be leveraged to build and run integration test as if there were packages. The build process will take care of interdependency between package in order to ensure local dependency are met.

In addition, within each integration-tests "packages", we can declare local dependencies as "*" which will translate to using the one that is part of the current build, regardless of the dependency's version number. No more fiddling with version numbers.

Github actions pertaining to integration-tests have been streamlined to use the new behavior.

The integration-tests packages have been marked as `private:true` in order to avoid publishing them to the public npm registry.

### Testing
```
cd root-of-medusajs-medusa-repo/
yarn install
yarn build
yarn test:integration:api
yarn test:integration:plugins
```

After a code change, `yarn build` must be run before re-running an integration test, which is the same procedure as for unit tests.

Resolves: CORE-845
2022-12-08 14:57:16 +00:00
olivermrbl
2b2ea157a6 chore(workflows): Fix merge conflicts with master 2022-12-07 20:28:32 +01:00
Adrien de Peretti
42d9c7222b feat(medusa): Performance improvements of Carts domain (#2648)
**What**

I have created a new method on the cart service which is `addLineItems`, allowing a user to add one or multiple items in an optimized way. Also updated the `generate` method from the line item service which now also accept a object data or a collection of data which. Various places have been optimized and cache support has been added to the price selection strategy.

The overall optimization allows to reach another 9000% improvement in the response time as a median (Creating a cart with 6 items):

|   | Min (ms)  | Median (ms)  | Max (ms)  | Median Improvement (%)
|---|:-:|---|---|---|
| Before optimisation  | 1200  | 9999 | 12698  |  N/A
| After optimisation | 63  | 252  | 500  | 39x
| After re optimisation | 56 | 82  | 399  | 121x
| After including addressed feedback | 65 | 202  | 495  | 49x

FIXES CORE-722
2022-12-07 14:39:12 +00:00
Shahed Nasser
2ffeaf567f docs: delete unused doc files (#2732) 2022-12-06 18:13:38 +02:00
Philip Korsholm
5332081972 fix(medusa, medusa-plugin-discount-generator, medusa-plugin-restock-notification): Bump Medusa package versions (#2623) 2022-11-18 10:50:13 +01:00
Philip Korsholm
f60267a494 feat(medusa): Release staging version on push to develop (#2594)
* initial

* working config

* update name and add snapshot to release

* add changeset

* use correct command for action

* pr feedback
2022-11-16 20:08:18 +01:00
Carlos R. L. Rodrigues
755ba90c05 feat(medusa): Payment Collection endpoints (#2525) 2022-11-11 18:28:45 +01:00
Carlos R. L. Rodrigues
b88cef2b1f feat: Development server for core + plugins (#2448) 2022-10-21 15:53:06 +02:00
olivermrbl
8b44618e7c fix: Merge conflicts with master 2022-10-21 14:21:06 +02:00
Oliver Windall Juhl
7d77d91a3d chore: Automate staging releases with action (#2458) 2022-10-17 18:11:49 +02:00
Shahed Nasser
479ae1e257 docs: Added automated freshness check (#2428)
* docs: created freshness check script

* added github action
2022-10-17 10:01:45 +03:00
Shahed Nasser
31fb4c3d3f docs: automated announcement bar (#2231) 2022-09-20 10:21:24 +03:00
Carlos R. L. Rodrigues
a94d9816fe chore: Centralise ESLint rules (#2162)
* chore: centrilize eslint rules
2022-09-13 07:42:33 -03:00
Oliver Windall Juhl
6a62a8f1ed chore: Remove lerna (#2116)
**What**
- Removes `lerna` as we are now using `changesets` + Turborepo to handle builds and releases
2022-08-29 13:26:58 +00:00
Carlos R. L. Rodrigues
ffd6234356 chore(integration): throw errors on catch blocks (#2091)
Why:
Suppressing errors and not failing the execution will lead to misleading errors of the following tests.

Fixes CORE-461
2022-08-25 06:36:24 +00:00
Carlos R. L. Rodrigues
690ca9e89a chore(integration-tests): Normalize DB config + use single process (#2077) 2022-08-24 12:29:53 +02:00
Shahed Nasser
4a416e7fa5 docs: added entity reference (#2047)
* added entity reference

* chore: added github action

* added link to reference
2022-08-15 15:54:48 +03:00
Shahed Nasser
73383cc466 chore(docs): Refactor API Reference (#1883) 2022-08-05 14:06:12 +02:00
Shahed Nasser
02d5c1da88 docs: update Typedoc and regenerate references (#1994)
* generated new services reference

* changed from automatic push to automated pull request

* updated typedoc, regenerated JS Client reference

* regenerated the reference after updating typedoc

* added action for js client
2022-08-04 17:29:52 +03:00
Sebastian Rindom
e539bdc620 chore: Fix CI pipeline (#1839) 2022-07-12 20:14:34 +02:00
olivermrbl
fb0346f1fa fix: Merge conflicts 2022-07-12 09:29:41 +02:00
Zakaria El Asri
9fa4238ee4 chore: improve ci pipeline (#1764)
* fix: caching deps + add true parallelization to integration tests api

* fix: github action

* chore: upgrade to yarn berry (#1762)

* init migration

* remove: yarn.lock from all pkgs

* fix: build script in pkgs

* adjust yarn config

* fix: yarn.lock and yarnrc.yml

* fix: github actions

* fix: wrong type

* fix (medusa-react): use dts-cli instead of tsdx

* fix: yarn.lock

* fix: yarn v

* fix: prepare script

* add: comment on why we need to downgrade yarn before medusa-dev

* chore: move to Turborepo (#1763)

* increase number of parallel nodes

* fix (medusa-fulfillment-webshipper): build script

* fix: use new version of medusa-dev

* fix: rename cache-bootstrap to cache-deps
2022-07-10 12:11:11 +02:00
Shahed Nasser
3b28f46705 docs: added reference for JS Client (#1629)
* added reference for JS Client

* added reference for JS Client

* added reference for JS Client
2022-07-08 18:21:46 +03:00
Oliver Windall Juhl
c76e23e84d fix(medusa): Remove deps mongoose + mongodb (#1218)
* fix(medusa): Remove deps mongoose, mongodb and transaction service + base model

* chore: delete permissions+add-ons legacy plugins

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-07-04 09:10:32 +02:00
Zakaria El Asri
55978e9e81 add: changesets + snapshot-this action (#1746)
* add: changesets + snapshot-this action

* add: changeset folder

* add: action credits
2022-06-30 11:07:18 +02:00
Shahed Nasser
c87ddd73ff docs: Add Services reference (#1548) 2022-06-01 18:33:08 +02:00
Zakaria El Asri
33426ddb4c fix: make plugin tests run with integration test suites (#1101)
* fix: make plugin tests run with integration test suites"

* add: plugins to test pipeline

* add: run integration tests on different jobs + fix failing test command

* fix: typo

* fix: pipeline
2022-02-25 16:39:28 +01:00
Zakaria El Asri
2e384842d5 feat: medusa-react admin hooks (#978)
* add: medusa admin hooks + tests

* fix: remove unneeded props

* fix: deps

* fix: deps

* fix: deps

* fix: failing tests

* fix: failing tests

* fix: query key

* add: yarn workspaces

* fix: linting medusa-react

* fix: add prepare script

* fix: buildOptions

* fix: useAdminShippingOptions query

* fix: use qs instead for query params (#1019)

* fix: formatting

* debug: ci pipeline

* debug: log node_modules structure

* debug: use lerna bootstrap

* debug: update node version

* debug: print pkgs in workspace

* debug: print pkgs in workspace

* debug: print pkgs in workspace

* debug: print pkgs in workspace

* debug: add explicit build step

* fix: jsdoc

* debug: run build step

* debug: fix build errors

* debug: add build step to integration tests

* fix: failing test

* cleanup

Co-authored-by: Sebastian Rindom <seb@medusajs.com>
Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-02-02 17:10:56 +01:00
Zakaria El Asri
69620e572e chore: parallelize integration tests and use template dbs (#907) 2021-12-14 21:45:57 +01:00
Zakaria El Asri
d0d8dd7bf6 feat: add medusa-react (#913) 2021-12-14 19:09:36 +01:00
Zakaria El Asri
032fcb97ca fix: fine-tuning (#847)
fix: checkout guide markdown + punctuation
fix: remove @docusaurus/theme-search-algolia from project root package.json
fix: use 400 font-weight for paragraphs as opposed to current 450
2021-11-26 14:41:01 +01:00
Oliver Windall Juhl
373532ecbc feat: Typescript for API layer (#817)
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
2021-11-18 15:19:17 +01:00