Commit Graph

159 Commits

Author SHA1 Message Date
Shahed Nasser
eebae37287 chore: add generated OAS and Typedoc output to automated PRs (#8054)
* chore: add generated OAS output to automated PR

* add typedoc json output
2024-07-11 18:17:37 +02:00
Shahed Nasser
964927b597 docs: general fixes and improvements (#7918)
* docs improvements and changes

* updated module definition

* modules + dml changes

* fix build

* fix vale error

* fix lint errors

* fixes to stripe docs

* fix condition

* fix condition

* fix module defintion

* fix checkout

* disable UI action

* change oas preview action

* flatten provider module options

* fix lint errors

* add module link docs

* pr comments fixes

* fix vale error

* change node engine version

* links -> linkable

* add note about database name

* small fixes

* link fixes

* fix response code in api reference

* added migrations step
2024-07-04 17:26:03 +03:00
Shahed Nasser
5aa62e59e4 chore: fix generate preview references action (#7901) 2024-07-03 14:10:19 +03:00
Shahed Nasser
9b5f26adab chore: action to generate documentation references (#7888)
Added an action that triggers documentation actions generating references
2024-07-01 13:54:17 +00:00
Shahed Nasser
7e7e6e3311 chore: fix OAS circular dependencies (#7693) 2024-06-12 19:42:03 +02:00
Shahed Nasser
e472aed00f docs: new + improved auth documentation pages (#7529)
* added and improved auth docs

* add prep to generates resources action

* add module options to sidebar

* fix broken link
2024-06-09 15:18:29 +02:00
Shahed Nasser
1a1ef4f208 chore: fix generate docs pipelines (#7595) 2024-06-04 14:51:05 +03:00
Stevche Radevski
6698f3ab7b feat: Add http integration tests and enable them in pipeline (#7532) 2024-05-30 10:51:31 +02:00
Shahed Nasser
c46c643fda chore: fix generate resources reference action (#7503) 2024-05-29 17:30:12 +03:00
Harminder Virk
6fa364d728 ci: remove unsupported scripts-prepend-node-path command (#7499) 2024-05-28 13:36:49 +02:00
Harminder Virk
ef6d748784 feat: add Filesystem util and load env util (#7487) 2024-05-28 15:31:13 +05:30
Shahed Nasser
1f43290cec feat(medusa-cli): added branch option (#7384) 2024-05-21 21:17:01 +02:00
Riqwan Thamir
442b0b2038 chore: rename route from api-v2 to api (#7379)
* chore: rename route from api-v2 to api

* chore: change oas references

* chore: remove v2 ref
2024-05-21 10:44:02 +02:00
Oli Juhl
2e42e053d4 chore: Publish preview release + deploy staging every 3 hours (#7341)
* wip

* Wrap up

* Update .github/workflows/trigger-staging-deployment.yml

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>

* enable schedule

---------

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2024-05-16 12:36:30 +02:00
Kasper Fabricius Kristensen
490586f566 feat(medusa,dashboard,admin-sdk): Run admin dashboard from Medusa instance (#7330) 2024-05-15 19:52:09 +02:00
Shahed Nasser
8958214350 chore: fix docs PR label removing team label (#7308)
* chore: fix docs PR labeler to only run with PR is opened

* add team labeler action

* move docs labeler to team labeler
2024-05-13 18:55:31 +03: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
3e3b8a483f chore: add action to automatically label docs (#7284)
* chore: add action to automatically label docs

* removes the paths param
2024-05-13 09:36:47 +03:00
Oli Juhl
948458a43d chore: Re-introduce CLI test (#7268) 2024-05-08 11:11:06 +02:00
Adrien de Peretti
71f4f46cb9 chore(medusa): cleanup medusa package (#7206) 2024-05-07 12:48:49 +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
Oli Juhl
16528c57b0 chore: Introduce release notes formatting + preview release action (#7247)
### What
- Add changelog formatting file to automate pull request categorization in release notes*
- Add action to trigger preview releases
- Remove unused staging deployment action

**Add changelog formatting file to automate pull request categorization in release notes**

In order for this work, we need to be more strict about our labels usage. More specifically, we need to add one of the four different labels noted in the `release.yml` file. The labels should be self-explanatory. If your PR introduces both features and bugs, you should choose the label based on importance of the changes.
2024-05-06 12:59:37 +00:00
Shahed Nasser
b39de05535 chore: move docs-util to www (#7232)
* reorganize docs apps

* add README

* fix directory

* add condition for old docs

* move docs-util to www

* remove remaining docs-util

* fixes of paths

* fix scripts

* path fixes

* fix github actions

* add build packages script
2024-05-06 09:13:50 +03:00
Shahed Nasser
4fe28f5a95 chore: reorganize docs apps (#7228)
* reorganize docs apps

* add README

* fix directory

* add condition for old docs
2024-05-03 17:36:38 +03:00
Adrien de Peretti
bbccd6481d chore(): start moving some packages to the core directory (#7215) 2024-05-03 13:37:41 +02:00
Oli Juhl
b8a0a459a8 chore: Update CI to trigger for v1.x (#7207) 2024-05-02 15:11:26 +02:00
Shahed Nasser
14748755ee chore: remove team from generate docblock actions (#6953) 2024-04-23 12:22:36 +02:00
Shahed Nasser
14a7378375 chore: add action to generate v2 oas (#7040) 2024-04-23 11:10:37 +03: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
Oli Juhl
94146e4bfe chore: Trigger pipeline on merge to develop (#6954) 2024-04-06 11:02:47 +02:00
Shahed Nasser
412111e1ea chore: fix doc announcement actions (#6856)
- Fix error in doc announcement actions due to missing build step.
- Update the announcement in the docs to the latest version
2024-03-28 17:23:25 +00: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
Oli Juhl
a5a2395622 chore: Revert #6548 (#6598)
Until a more elegant solution for allowing contributor forks to run workflows, we need to revert to using a plain text pg password
2024-03-06 13:41:53 +00:00
Oli Juhl
55275f0eba chore(actions): Use PG pass secret (#6548) 2024-02-29 22:10:56 +01:00
Oli Juhl
296d7faad4 chore: V2 core loader + modules integration-tests (#6544) 2024-02-29 16:46:30 +01:00
Shahed Nasser
5ddae7ecd1 chore(docs): add empty changeset step to actions (#6377)
- Creates a script that runs the `yarn changeset --empty` command if there are file changes. This is important to not create PRs of just empty changesets if there are no file changes.
- Run script in all docs-generation PRs
- Fix to condition in `generate-docblock` action
2024-02-13 08:58:48 +00:00
Shahed Nasser
374a3f4dab docs-util: support generating OAS in docblock generator (#6338)
## What

This PR adds support for generating OAS in the docblock generator tool.

## How

As OAS are generated in a different manner/location than regular TSDocs, it requires a new type of generator within the tool. As such, the existing docblock generator now only handles files that aren't under the `packages/medusa/src/api` and `packages/medusa/src/api-v2` directories. The new generator handles files under these directories. However, it only considers a node to be an API route if it's a function having two parameters of types `MedusaRequest` and `MedusaResponse` respectively. So, only new API Routes are considered.

The new generator runs the same way as the existing docblock generator with the same method. The generators will detect whether they can run on the file or not and the docblocks/oas are generated based on that. I've also added a `--type` option to the CLI commands of the docblock generator tool to further filter and choose which generator to use.

When the OAS generator finds an API route, it will generate its OAS under the `docs-util/oas-output/operations` directory in a TypeScript file. I chose to generate in TS files rather than YAML files to maintain the functionality of `medusa-oas` without major changes.

Schemas detected in the OAS operation, such as the request and response schemas, are generated as OAS schemas under the `docs-util/oas-output/schemas` directory and referenced in operations and other resources.

The OAS generator also handles updating OAS. When you run the same command on a file/directory and an API route already has OAS associated with it, its information and associated schemas are updated instead of generating new schemas/operations. However, summaries and descriptions aren't updated unless they're not available or their values are the default value SUMMARY.

## API Route Handling

### Request and Response Types

The tool extracts the type of request/response schemas from the type arguments passed to the `MedusaRequest` and `MedusaResponse` respectively. For example:

```ts
export const POST = async (
  req: MedusaRequest<{
    id: string
  }>,
  res: MedusaResponse<ResponseType>
) => {
  // ...
}
```

If these types aren't provided, the request/response is considered empty.

### Path Parameters

Path parameters are extracted from the file's path name. For example, for `packages/medusa/src/api-v2/admin/campaigns/[id]/route.ts` the `id` path parameter is extracted.

### Query Parameters

The tool extracts the query parameters of an API route based on the type of `request.validatedQuery`. Once we narrow down how we're typing query parameters, we can revisit this implementation.

## Changes to Medusa Oas CLI

I added a `--v2` option to the Medusa OAS CLI to support loading OAS from `docs-util/oas-output` directory rather than the `medusa` package. This will output the OAS in `www/apps/api-reference/specs`, wiping out old OAS. This is only helpful for testing purposes to check how the new OAS looks like in the API reference. It also allows us to slowly start adapting the new OAS.

## Other Notes and Changes

- I've added a GitHub action that creates a PR for generated OAS when Version Packages is merged (similar to regular TSDocs). However, this will only generate the OAS in the `docs-util/oas-output` directory and will not affect the existing OAS in the API reference. Once we're ready to include it those OAS, we can talk about next steps.
- I've moved the base YAML from the `medusa` package to the `docs-util/oas-output/base` directory and changed the `medusa-oas` tool to load them from there.
- I added a `clean:oas` command to the docblock generator CLI tool that removes unused OAS operations, schemas, and tags from `docs-util/oas-output`. The tool also supports updating OAS operations and their associated schemas. However, I didn't add a specific mechanism to update schemas on their own as that's a bit tricky and would require the help of typedoc. I believe with the process of running the tool on the `api-v2` directory whenever there's a new release should be enough to update associated schemas, but if we find that not enough, we can revisit updating schemas individually.
- Because of the `clean:oas` command which makes changes to tags (removing the existing ones, more details on this one later), I've added new base YAML under `docs-util/oas-output/base-v2`. This is used by the tool when generating/cleaning OAS, and the Medusa OAS CLI when the `--v2` option is used.

## Testing

### Prerequisites

To test with request/response types, I recommend minimally modifying `packages/medusa/src/types/routing.ts` to allow type arguments of `MedusaRequest` and `MedusaResponse`:

```ts
import type { NextFunction, Request, Response } from "express"

import type { Customer, User } from "../models"
import type { MedusaContainer } from "./global"

export interface MedusaRequest<T = unknown> extends Request {
  user?: (User | Customer) & { customer_id?: string; userId?: string }
  scope: MedusaContainer
}

export type MedusaResponse<T = unknown> = Response

export type MedusaNextFunction = NextFunction

export type MedusaRequestHandler = (
  req: MedusaRequest,
  res: MedusaResponse,
  next: MedusaNextFunction
) => Promise<void> | void
```

You can then add type arguments to the routes in `packages/medusa/src/api-v2/admin/campaigns/[id]/route.ts`. For example:

```ts
import {
  deleteCampaignsWorkflow,
  updateCampaignsWorkflow,
} from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { CampaignDTO, IPromotionModuleService } from "@medusajs/types"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"

interface ResponseType {
  campaign: CampaignDTO
}

export const GET = async (
  req: MedusaRequest,
  res: MedusaResponse<ResponseType>
) => {
  const promotionModuleService: IPromotionModuleService = req.scope.resolve(
    ModuleRegistrationName.PROMOTION
  )
  const campaign = await promotionModuleService.retrieveCampaign(
    req.params.id,
    {
      select: req.retrieveConfig.select,
      relations: req.retrieveConfig.relations,
    }
  )
  res.status(200).json({ campaign })
}

export const POST = async (
  req: MedusaRequest<{
    id: string
  }>,
  res: MedusaResponse<ResponseType>
) => {
  const updateCampaigns = updateCampaignsWorkflow(req.scope)
  const campaignsData = [
    {
      id: req.params.id,
      ...(req.validatedBody || {}),
    },
  ]
  const { result, errors } = await updateCampaigns.run({
    input: { campaignsData },
    throwOnError: false,
  })
  if (Array.isArray(errors) && errors[0]) {
    throw errors[0].error
  }
  res.status(200).json({ campaign: result[0] })
}

export const DELETE = async (
  req: MedusaRequest,
  res: MedusaResponse<{
    id: string
    object: string
    deleted: boolean
  }>
) => {
  const id = req.params.id
  const manager = req.scope.resolve("manager")
  const deleteCampaigns = deleteCampaignsWorkflow(req.scope)
  const { errors } = await deleteCampaigns.run({
    input: { ids: [id] },
    context: { manager },
    throwOnError: false,
  })
  if (Array.isArray(errors) && errors[0]) {
    throw errors[0].error
  }
  res.status(200).json({
    id,
    object: "campaign",
    deleted: true,
  })
}
```

### Generate OAS

- Install dependencies in the `docs-util` directory
- Run the following command in the `docs-util/packages/docblock-generator` directory:

```bash
yarn dev run "../../../packages/medusa/src/api-v2/admin/campaigns/[id]/route.ts"
```

This will generate the OAS operation and schemas and necessary and update the base YAML to include the new tags.

### Generate OAS with Examples

By default, the tool will only generate cURL examples for OAS operations. To generate templated JS Client and (placeholder) Medusa React examples, add the `--generate-examples` option to the command:

```bash
yarn dev run "../../../packages/medusa/src/api-v2/admin/campaigns/[id]/route.ts" --generate-examples
```

> Note: the command will update the existing OAS you generated in the previous test.

### Testing Updates

To test updating OAS, you can try updating request/response types, then running the command, and the associated OAS/schemas will be updated.

### Clean OAS

The `clean:oas` command will remove any unused operation, tags, or schemas. To test it out you can try:

- Remove an API Route => this removes its associated operation and schemas (if not referenced anywhere else).
- Remove all references to a schema => this removes the schema.
- Remove all operations in `docs-util/oas-output/operations` associated with a tag => this removes the tag from the base YAML.

```bash
yarn dev clean:oas
```

> Note: when running this command, existing tags in the base YAML (such as Products) will be removed since there are no operations using it. As it's running on the base YAML under `base-v2`, this doesn't affect base YAML used for the API reference.

### Medusa Oas CLI

- Install and build dependencies in the root of the monorepo
- Run the following command to generate reference OAS for v2 API Routes (must have generated OAS previously using the docblock generator tool):

```bash
yarn openapi:generate --v2
```

- This wipes out existing OAS in `www/apps/api-reference/specs` and replaces them with the new ones. At this point, you can view the new API routes in the API reference by running the `yarn dev` command in `www/apps/api-reference` (although not necessary for testing here).
- Run the command again without the `--v2` option:

```bash
yarn openapi:generate
```

The specs in `www/apps/api-reference/specs` are reverted back to the old routes.
2024-02-13 08:40:04 +00:00
Shahed Nasser
66e8f4e0d2 docs-util: fix release scripts (#6353)
- Fix GitHub action to run on push and check if the commit message is "chore: Release". Only then are TSDocs generated and a PR is opened.
- Add an option to pass to the `run:release` method of the docblock generator a release tag. This is helpful in cases when the GitHub action fails for any reason.
- Add scripts that checks the message of a commit.
2024-02-08 20:36:27 +00:00
Shahed Nasser
96629f1916 docs: change process for generating docblocks through actions (#6237)
This PR changes the original process of generating docblocks through actions. The process now is:

1. When a PR is merged for the branch `changeset-release/develop`, the docblock generator tool us used to generate docblocks for the changed files. The changed files are determined by retrieving all comments since the last release and the files in each of those commits.
2. If there are changes after using the docblock generator tool, a PR is opened in the branch `chore/generate-tsdocs`.
3. Once the `chore/generate-tsdocs` is merged, it triggers an action that generates the references for the docs. This changes the previous behaviour of generating references on a new release.

Both actions (that runs the docblock generator tool and that generates references for the docs) can also be triggered manually.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-01-29 08:05:14 +00:00
Oli Juhl
8f9a12c895 chore: PR team labeler (#6249) 2024-01-29 08:11:39 +01:00
Shahed Nasser
a1b561e4a6 docs(docblock-generator): fix action Node version (#6207) 2024-01-25 08:38:15 +01:00
Shahed Nasser
f29948a6a8 docs-util: created docblock-generator tool (#6096) 2024-01-24 11:13:40 +01:00
Oli Juhl
1468646b99 chore(workflows): Use Node 16.14 in CLI workflow (#5993)
* make packages private

* add changeset

* Update test-cli-with-database.yml

* revert
2024-01-04 08:40:45 +01:00
Shahed Nasser
245e5c9a69 docs: generate documentation for UI components (#5849)
* added tool to generate spec files for React components

* use typedoc for missing descriptions and types

* improvements and fixes

* improvements

* added doc comments for half of the components

* add custom resolver + more doc comments

* added all tsdocs

* general improvements

* add specs to UI docs

* added github action

* remove unnecessary api route

* Added readme for react-docs-generator

* remove comment

* Update packages/design-system/ui/src/components/currency-input/currency-input.tsx

Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>

* remove description of aria fields + add generate script

---------

Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
2023-12-13 16:02:41 +02:00
Philip Korsholm
a39ce125cc fix(product, types, workflows): Update product variant workflow (#5668)
**What**
- Fix issues with update-variant workflow: 
  - other variants than the updated variant are no longer removed 
  - options are updated properly


Co-authored-by: Riqwan Thamir <5105988+riqwan@users.noreply.github.com>
2023-11-23 14:35:01 +00:00
Shahed Nasser
c6dff873de docs: update docusaurus to v3 (#5625)
* update dependencies

* update onboarding mdx

* fixes for mdx issues

* fixes for mdx compatibility

* resolve mdx errors

* fixes in reference

* fix check errors

* revert change in vale action

* fix node version in action

* fix summary in markdown
2023-11-13 20:11:50 +02:00
Riqwan Thamir
cedab58339 feat(workflows,medusa,utils): add medusa v2 feature flag (#5603)
* chore: add medusa v2 feature flag

* chore: cleanup more FF

* chore: cleanup workflows FF

* chore: add comments on broken specs

* chore: added check for package registration

* chore: reenable workflows FF for create order workflow

* chore: disable FF on test cli db

* chore: hide loader validation behind FF

* chore: use medusa v2 enabled

* chore: register feature flag router in use-db

* chore: change to minro
2023-11-13 16:18:05 +01:00
Shahed Nasser
4f91263588 chore: fix generate automated reference action (#5589)
* chore: fix generate automated reference action

* fix dependencies

* add depends in turbo

* add install step for www workspace
2023-11-09 17:14:28 +02:00
Adrien de Peretti
f88d75b0a7 feat(product, pricing, utils): Transaction issues and reference issues (#5533)
* feat(product, pricing, utils): Transaction issues and reference issues

* fixes decorators

* cleanup

* fix product module upsert

* fix missing active manager

* increase timeout

* revert package.json

* WIP

* try another node version based on findings with memory issues with jest introduced after 16.11 but fixed in 21

* re add bail

* fix variant options

* chore: bulk create pricing

* chore: workflow bulk

* Create big-chefs-dream.md

* fix missing update for upserty

* Add integration tests for product options upsert

* rm unnecessary return

* fix product prices workflow issue

* cleanup

* fix flag

* fix model

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
2023-11-06 12:24:29 +01:00