Commit Graph

3030 Commits

Author SHA1 Message Date
olivermrbl
e1b92e9b04 fix: Merge conflicts with master 2023-02-22 17:38:49 +01:00
Patrick
935870e010 fix(oas): add missing x-codegen + fix schema naming and $ref (#3312)
## What

Add missing x-codegen + fix schema naming and $ref 

## Why

OAS code generator was missing information to be able to match current JS client.

## How

Ensure OAS matches JS client methods.
2023-02-22 16:25:48 +00:00
Patrick
287c829c9c feat(oas): include /admin and /store in paths URLs (#3314)
## What

Include `/admin` and `/store` in OAS paths URLs

## Why

Allow for generating a combined OAS that include routes for both "admin" and "store" endpoint.

Fix potential issues with code generator where routes are not prefixed with "admin" and "store" leading to 404 errors.

## Test

* Run `yarn build`
* Run `yarn openapi:generate`
* Run `yarn redocly preview-docs docs/api/admin/openapi.yaml --config=./docs-util/redocly/config.yaml`
* Expect paths to be prefixed with /admin.
* Run `yarn redocly preview-docs docs/api/store/openapi.yaml --config=./docs-util/redocly/config.yaml`
* Expect paths to be prefixed with /store.
2023-02-22 15:43:41 +00:00
Riqwan Thamir
68496ffe60 fix(medusa): fixes bug for mpath incorrectly updated for nested categories (#3311)
* chore: fix issue with mpath being incorrectly set

* chore: address review changes
2023-02-22 15:43:58 +01:00
github-actions[bot]
8e5ebc9a1d chore(docs): Generated Docs Announcement Bar (automated) (#3310)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-22 14:45:49 +02:00
github-actions[bot]
e3305188bd chore(docs): Generated API Reference (#3308)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-22 14:45:23 +02:00
github-actions[bot]
3f5b7fbe7e chore(docs): Generated Services Reference (automated) (#3309)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-22 14:44:52 +02:00
olivermrbl
fefc248a41 chore(release): v1.7.8 2023-02-22 13:13:48 +01:00
Adrien de Peretti
5301a1e9d6 chore(medusa): Revert AbstractPaymentService deprecation (#3298) 2023-02-21 20:40:40 +01:00
Patrick
e8e7d7bb53 fix(medusa-dev): include packages/ subdirectories in discovery (#3293)
## What

Include packages/ subdirectories in medusa-dev packages discovery.

## Why

We started to use subdirectories in the monorepo `packages/` directory in order to better organize packages.

Packages in subdirectories were invisible to `medusa-dev` and could not be copied.

## How

Rely on monorepo package.json workspace glob patterns to discover packages that can be published to the local npm registry.
2023-02-21 16:12:02 +00:00
Shahed Nasser
3084de0c02 chore: changed trigger for docs generation actions (#3304) 2023-02-21 18:11:32 +02:00
Adrien de Peretti
d11ab924b8 feat(medusa): Configurable returnable_items on order decorate totals (#3276) 2023-02-21 14:48:49 +01:00
Adrien de Peretti
f43e9f0f20 feat(medusa): Load PaymentProcessors + integrate in PaymentProviderService (#2978)
* feat: Add payment process support into the loader and payment provider

* WIP

* feat: continue payment provider alignment

* fix tests and defer payment service resolution

* continue to add support to payment provider

* continue to add support to payment provider

* fix fixtures

* chore: add updateSessionData unsupported error

* chore: Adress feedback

* chore: Adress feedback

* chore: fix default loader

* cleanup

* cleanup

* fix unit tests

* Create purple-sloths-confess.md

* address feedback

* minor changes

* fix unit test

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-21 09:48:32 +01:00
Patrick
1c40346e9e feat(codegen): openapi-typescript-codegen fork (#3272)
## What

Allow `medusa-oas` CLI to generate API client code from an OAS json file.

## Why

Manually maintaining API clients is time consuming and error prone. We wish to automate the process by using code generation strategies.

We also wish to eliminate direct import from `@medusajs/medusa` in clients which can lead to unwanted side effects like importing unnecessary dependencies.

## How

Fork and customize an OAS code generator library that is TypeScript friendly.

Attempt to match the interface and signature of our current client packages: `@medusajs/medusa-js`, `medusa-react`

Add a new `client` command to the `medusa-oas` CLI as the main interface to interact with the code generation tooling.

## Test

### Prerequisites 
* From the root of the monorepo:
* `yarn install`
* `yarn build`

### Case - all in one build
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-store --type store`
* Expect `~/tmp/client-store` to contain the following files and directories:
```
core/
hooks/
models/
services/
index.ts
MedusaStore.ts
useMedusaStore.tsx
```

### Case - types only
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-types --type store --component types`
* Expect `~/tmp/client-types` to contain the following files and directories:
```
models/
index.ts
```

### Case - client only
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-only --type store --component client --types-package @medusajs/client-types`
* Expect `~/tmp/client-only` to contain the following files and directories:
```
core/
services/
index.ts
MedusaStore.ts
```
2023-02-20 20:50:39 +00:00
Frane Polić
6c04624727 chore(medusa): remove PublishableAPIKeys feature flag (#3087) 2023-02-20 21:16:08 +01:00
Adrien de Peretti
46547f29c7 chore(medusa): Improve store list products (#3252)
* chore(medusa): Improve list products by 46.5 percents

* fix handler

* todo's

* Create tricky-terms-wash.md

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-20 12:45:05 +01:00
github-actions[bot]
b393d74a10 chore(docs): Removed Docs Announcement Bar (automated) (#3292)
Co-authored-by: shahednasser <shahednasser@users.noreply.github.com>
2023-02-20 09:54:13 +02:00
Pevey
13c200ad2f feat(medusa-file-s3): S3 file service reusing a single AWS client (#3260) 2023-02-19 19:17:35 +01:00
Patrick
7d585f5f84 fix(oas): fix paths and fix schema names to match convention (#3288) 2023-02-19 18:11:02 +01:00
Patrick
38503fff56 feat(oas): identify required fields in responses - store (#3282)
## Scope

Store routes

## What

Add OAS `required` to response schemas.

## Why

Code generator can use the `required` property of a schema to mark fields as optional or not when generating TS types.

## Test

* Run `yarn build`
* Run `yarn openapi:generate`
* Run `yarn redocly preview-docs docs/api/store/openapi.yaml --config=docs-util/redocly/config.yaml`
* Open the documentation preview URL in a browser (http://127.0.0.1:8080)
* Expect responses to have their fields declared as `required`
2023-02-17 15:28:01 +00:00
Shahed Nasser
7e6f15d4a9 docs: added details about expand, fields, and filtering (#3287) 2023-02-17 16:53:22 +02:00
Patrick
48ad2426aa feat(oas): identify required fields in responses - admin (#3278)
## Scope

Admin routes

## What

Add OAS `required` to response schemas.

## Why

Code generator can use the `required` property of a schema to mark fields as optional or not when generating TS types.

## Test

* Run `yarn build`
* Run `yarn openapi:generate`
* Run `yarn redocly preview-docs docs/api/admin/openapi.yaml --config=docs-util/redocly/config.yaml`
* Open the documentation preview URL in a browser (http://127.0.0.1:8080)
* Expect responses to have their fields declared as `required`
2023-02-17 14:19:13 +00:00
Shahed Nasser
d8dcc4ce9a docs: added CORS common examples (#3284)
* docs: added CORS common examples

* fix lint errors
2023-02-17 15:42:46 +02:00
Shahed Nasser
d1abe7cd85 chore(docs): manually generated API reference to fix load issue (#3286) 2023-02-17 15:23:20 +02:00
Patrick
9690f07bc0 fix(oas): patch circular references in docs (#3285)
## What

Patch OAS circular references that causes the documentation to crash

## Test

* Run `yarn openapi:generate`
* Run `yarn redocly preview-docs docs/api/admin/openapi.yaml --config=./docs-util/redocly/config.yaml`
* Open preview docs url in a browser
* Expect the page to not crash

* Repeat with `yarn redocly preview-docs docs/api/store/openapi.yaml --config=./docs-util/redocly/config.yaml`
2023-02-17 12:42:11 +00:00
Patrick
3e274edb9e feat(docs): OAS circular reference check shall fail openapi:generate (#3269)
### What

Unhandled OAS circular references shall fail `openapi:generate` until they have been patched in `docs-util/redocly/config.yaml`

### Why

Prevent developers to commit new OAS changes that would cause to API documentation to crash.

Our API documentation rendering library will crash and not load if our OAS contains circular references. We have an automated mechanism to patch offending references but they must be identified and configured by hand.

### How

Let the `openapi:generate --dry-run` command reach OAS sanitization and circular reference check operations. 

Fail the build script if unhandled circular references are detected. 

Output the offending references to the stdout in order to help the developers identify and configure the required patch.

Since some the tooling involved only work with files, use the host system's temporary directory mechanism when using the `--dry-run` flag.

### Test

* Introduce a bug by removing an entry in `docs-util/redocly/config.yaml`
* Run `yarn openapi:generate --dry-run`
* Expect the script to exit before completing
* Expect the logs to contain `🔴 Unhandled circular references.`
* Expect the logs to contain an array of the offending references
2023-02-17 12:11:27 +00:00
Oliver Windall Juhl
f88af0c28d fix(medusa): Received quantity on return lines (#3267) 2023-02-17 10:13:50 +00:00
Adrien de Peretti
aefe5aa133 feat(medusa): Expose an activeManager_ getter in TransactionBaseService (#3256) 2023-02-16 10:26:23 +00:00
Riqwan Thamir
75924b682f feat(medusa-react): add product category queries and mutations (#3218) 2023-02-16 10:22:23 +01:00
Rares Stefan
12d304307a feat(medusa-js, medusa-react, medusa): Prepare API for admin implementations (#3110)
********What********
Add `joinSalesChannels util to stock locations

Add the following endpoints to medusa-react
- inventory items
    - mutations
        - update
        - delete
        - update location level
        - delete location level
        - create location level
    - queries
        - list inventory items
        - get inventory item
        - list location levels
- Stock locations
    - mutations
        - create stock location
        - update stock location
        - delete stock location
    - queries
        - list stock locations
        - get stock locatoin
- Variants
    - queries
        - get inventory
- Reservations
    - mutations
        - create reservation
        - update reservation
        - delete reservation
    - queries
        - list reservations
        - get reservation
- sales channels 
  - mutations
    - associate location with sc
    - remove location association

**Why**
- Update clients to reflect new api endpoints in the core with inventory modules

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
2023-02-16 08:49:48 +00:00
Kasper Fabricius Kristensen
3a911091f1 hotfix(medusa-js): Export resources classes and make client public (#3271)
* export all ressource classes and make client public

* add changeset
2023-02-16 09:03:49 +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
github-actions[bot]
ef148cb9f4 chore(docs): Generated Services Reference (automated) (#3261)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-14 20:32:42 +02:00
github-actions[bot]
4fb22e8ba5 chore(docs): Generated API Reference (#3262)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-14 20:32:28 +02:00
github-actions[bot]
67f9429293 chore(docs): Generated Docs Announcement Bar (automated) (#3263) 2023-02-14 17:38:21 +01:00
olivermrbl
1bfbe27b9b chore(release): Publish 2023-02-14 17:30:40 +01:00
olivermrbl
da9fb4aaa8 chore: Lint package.json 2023-02-14 17:27:43 +01:00
Oliver Windall Juhl
968eb8fc6b fix(medusa): Refund amount on returns in claim flow (#3237) 2023-02-14 12:47:06 +01:00
olivermrbl
d48606d5dd Merge branch 'master' into develop 2023-02-14 11:28:02 +01:00
Adrien de Peretti
5e0273a370 chore(medusa): New totals calc. in Swap creation (#3191)
* feat(medusa): Cleanup swap creation flow

* revert test and package

* fix unit tests

* fix swap seeder that does not include the tax lines on the return line item

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-14 10:52:45 +01:00
Carlos R. L. Rodrigues
80452332d8 fix(medusa): Default sales channel on product create (#3249)
What:
Assign the default sales channel if none is provided while creating a new product.


FIXES: CORE-1114

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-14 08:46:14 +00:00
josetr
10ff72c30a fix(medusa): Add missing scoped transaction on update currency endpoint (#3254) 2023-02-14 09:24:39 +01:00
github-actions[bot]
a2c3ba2c2c chore(docs): Removed Docs Announcement Bar (automated) (#3255)
Co-authored-by: shahednasser <shahednasser@users.noreply.github.com>
2023-02-14 09:55:40 +02:00
olivermrbl
66e7a384e3 Merge branch 'master' into develop 2023-02-13 18:53:54 +01:00
Patrick
cac13a88da feat(oas) - accurate model OAS representation - R to U (#3250)
### Scope

Models R to U

### What

Refactor OAS for models to accurately represent their shape in API responses.

### Why

About 33% of model fields are not accurately represented in the OAS. Most of the issues are:
- fields that can not be omitted in the response are not declared as `required`
- fields that could return `null` as their value are not declared as `nullable: true`

When using a code generator, these OAS issues would lead to inaccurate response shapes in the generated client.

### How

#### nullable
Fields meeting at least one of the following condition will be represented as `nullable: true` in OAS:
* The field is decorated with `@Column({ nullable: true })`
* The field is decorated with `@OneToOne`, `@ManyToOne`
* The field is decorated with `@DeleteDateColumn`

#### optional
Fields meeting at least one of the following conditions will never be listed as `required` in OAS and will be considered optional and could be omitted in the response:
* The field is decorated with `@OneToOne`, `@ManyToOne`, `@OneToMany`, `@ManyToMany`
* The field is decorated with `@FeatureFlagColumn`
* The field is decorated with `@Column({select: false})`
* The field is representing dynamic values not persisted in the database

Fields not meeting any of the conditions above will be declared as `required` and are expected to be present in the response.

### Test
* Ran OAS validator.
* Ran docs build script.

Expect OAS changes to be reflected in the API documentation.
2023-02-13 16:59:36 +00:00
Adrien de Peretti
4cb44a3a2e fix(medusa): Discount allocation precision issues (#3244) 2023-02-13 17:22:18 +01:00
Adrien de Peretti
bbbb3d8882 fix(medusa): Missing withTransaction on update in get-cart.ts (#3246) 2023-02-13 16:30:46 +01:00
Adrien de Peretti
a2cc084db8 fix(medusa): Missing withTransaction on calculateDiscountForLineItem (#3247) 2023-02-13 16:29:11 +01:00
github-actions[bot]
312b05ea5a chore(docs): Generated Services Reference (automated) (#3242)
Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
2023-02-13 09:56:49 +02:00