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
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
export const metadata = {
|
||||
title: `${pageNumber} Feature Flags`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you’ll learn about feature flags and how Medusa uses them.
|
||||
|
||||
## What is a Feature Flag?
|
||||
|
||||
A feature flag is a configuration that toggles beta features in Medusa.
|
||||
|
||||
A beta feature may be disabled but is still part of the published `@medusajs/medusa` package. This allows our team to release new features rapidly and continuously without impacting Medusa applications used in production.
|
||||
|
||||
Developers interested in testing a new feature can enable its flag through Medusa’s configurations.
|
||||
|
||||
<Note type="warning">
|
||||
|
||||
Enabling a feature flag isn’t recommended for Medusa applications in a production environment, as it can cause unexpected errors and issues.
|
||||
|
||||
</Note>
|
||||
|
||||
{/* TODO re-add this based on whether we have feature flags (after V2). */}
|
||||
|
||||
{/* ---
|
||||
|
||||
## List of Feature Flags
|
||||
|
||||
Refer to this reference for a full list of feature flags. */}
|
||||
|
||||
---
|
||||
|
||||
## How to Toggle a Feature Flag
|
||||
|
||||
### Option 1: Using an Environment Variable
|
||||
|
||||
A feature flag has an associated environment variable that, if you set it, it toggles the feature flag.
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
MEDUSA_FF_TAX_INCLUSIVE_PRICING=true
|
||||
```
|
||||
|
||||
### Option 2: Using Medusa Configurations
|
||||
|
||||
A feature flag also has an associated key that can be used to toggle its value in Medusa’s configurations.
|
||||
|
||||
The configurations exported in `medusa-config.js` has a `featureFlags` property. Its value is an object where each key is the key of a feature flag, and its value is a boolean indicating whether to enable or disable the flag.
|
||||
|
||||
For example:
|
||||
|
||||
```js title="medusa-config.js"
|
||||
module.exports = defineConfig({
|
||||
featureFlags: {
|
||||
tax_inclusive_pricing: true,
|
||||
},
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
If you’ve set both the environment variable and the feature flag key in the configurations, the environment variable’s value has a higher precedence.
|
||||
|
||||
</Note>
|
||||
|
||||
### Run Migrations
|
||||
|
||||
A feature guarded by a flag may require changes in the database.
|
||||
|
||||
So, after enabling a feature flag, it’s recommended to run migrations in your Medusa application:
|
||||
|
||||
```bash
|
||||
npx medusa migrations run
|
||||
```
|
||||
|
||||
If you disable the feature flag, run the following command to revert migrations:
|
||||
|
||||
```bash
|
||||
npx medusa migrations revert
|
||||
```
|
||||
|
||||
<Note>
|
||||
|
||||
This reverts the last migrations, so if you ran other migrations since you toggled the feature flag, it’ll revert them instead. You can run it multiple times to revert the last migrations.
|
||||
|
||||
</Note>
|
||||
@@ -8,7 +8,7 @@ In this chapter, you’ll learn how to use Medusa’s logging utility.
|
||||
|
||||
## Logger Class
|
||||
|
||||
Medusa provides a `Logger` class that provides advanced logging functionalities. This includes configuring logging levels or saving logs to a file.
|
||||
Medusa provides a `Logger` class with advanced logging functionalities. This includes configuring logging levels or saving logs to a file.
|
||||
|
||||
The Medusa application registers the `Logger` class in the Medusa container and each module's container as `logger`.
|
||||
|
||||
@@ -18,34 +18,43 @@ The Medusa application registers the `Logger` class in the Medusa container and
|
||||
|
||||
Resolve the `logger` using the Medusa container to log a message in your resource.
|
||||
|
||||
For example, create the file `src/loaders/log-message.ts` with the following content:
|
||||
For example, create the file `src/jobs/log-message.ts` with the following content:
|
||||
|
||||
export const highlights = [
|
||||
["4", "resolve", "Resolve the `Logger` class."],
|
||||
["6", "info", "Log a message of level `info`."]
|
||||
["7", "resolve", "Resolve the `Logger` class."],
|
||||
["9", "info", "Log a message of level `info`."]
|
||||
]
|
||||
|
||||
```ts title="src/loaders/log-message.ts" highlights={highlights}
|
||||
import { Logger, MedusaContainer } from "@medusajs/medusa"
|
||||
```ts title="src/jobs/log-message.ts" highlights={highlights}
|
||||
import { Logger } from "@medusajs/medusa"
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
|
||||
export default async (container: MedusaContainer) => {
|
||||
export default async function myCustomJob(
|
||||
container: MedusaContainer
|
||||
) {
|
||||
const logger: Logger = container.resolve("logger")
|
||||
|
||||
logger.info("I'm using the logger!")
|
||||
}
|
||||
|
||||
export const config = {
|
||||
name: "test-logger",
|
||||
// execute every minute
|
||||
schedule: "* * * * *",
|
||||
}
|
||||
```
|
||||
|
||||
This creates a loader that resolves the `logger` from the Medusa container and uses it to log a message.
|
||||
This creates a scheduled job that resolves the `logger` from the Medusa container and uses it to log a message.
|
||||
|
||||
### Test the Loader
|
||||
### Test the Scheduled Job
|
||||
|
||||
To test out the above loader, start the Medusa application:
|
||||
To test out the above scheduled job, start the Medusa application:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run dev
|
||||
```
|
||||
|
||||
You’ll see the following message as part of the logged messages:
|
||||
After a minute, you'll see the following message as part of the logged messages:
|
||||
|
||||
```text
|
||||
info: I'm using the logger!
|
||||
@@ -116,7 +125,7 @@ The environment variable must be set as a system environment variable and not in
|
||||
|
||||
## Show Log with Progress
|
||||
|
||||
The `Logger` class has an `activity` method used to log a message of level `info`. If the Medusa application is running in a development environment, a spinner starts that can be used to show progress and succeed or fail the progress.
|
||||
The `Logger` class has an `activity` method used to log a message of level `info`. If the Medusa application is running in a development environment, a spinner starts to show the activity's progress.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -16,46 +16,39 @@ Since the Medusa server is a Node.js server, you can use any Node.js testing too
|
||||
|
||||
[Jest](https://jestjs.io/) is a JavaScript testing framework. Your Medusa project is already configured with Jest; you can use it out-of-the-box.
|
||||
|
||||
<Note>
|
||||
|
||||
Refer to [Jest's documentation](https://jestjs.io/docs/getting-started) to learn how to install and configure it.
|
||||
|
||||
</Note>
|
||||
|
||||
For example, consider the following service created at `src/modules/hello/service.ts`:
|
||||
|
||||
```ts title="src/modules/hello/service.ts"
|
||||
import { TransactionBaseService } from "@medusajs/medusa"
|
||||
|
||||
class HelloWorldService extends TransactionBaseService {
|
||||
constructor(container) {
|
||||
super(arguments[0])
|
||||
}
|
||||
class HelloModuleService {
|
||||
getMessage(): string {
|
||||
return "Hello, world!"
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloWorldService
|
||||
export default HelloModuleService
|
||||
|
||||
```
|
||||
|
||||
You can write a test for it in the file `src/modules/hello/__tests__/hello-world.ts`:
|
||||
You can write a test for it in the file `src/modules/hello/__tests__/hello-world.spec.ts`:
|
||||
|
||||
```ts title="src/modules/hello/__tests__/hello-world.ts"
|
||||
import HelloWorldService from "../hello-world"
|
||||
```ts title="src/modules/hello/__tests__/hello-world.spec.ts"
|
||||
import HelloModuleService from "../service"
|
||||
|
||||
describe("HelloWorldService", () => {
|
||||
const helloWorldService = new HelloWorldService()
|
||||
describe("HelloModuleService", () => {
|
||||
const helloModuleService = new HelloModuleService()
|
||||
|
||||
it("should return hello world message", () => {
|
||||
expect(helloWorldService.getMessage()).toBe("Hello, world!")
|
||||
expect(helloModuleService.getMessage()).toBe("Hello, world!")
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
Then, run the following command in the root of your Medusa project to run the test:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run test
|
||||
```
|
||||
|
||||
This command looks for TypeScript and JavaScript files under any directory named `__tests__` and runs them.
|
||||
|
||||
---
|
||||
|
||||
## IDE Debugging Tools
|
||||
|
||||
Reference in New Issue
Block a user