docs: docs for next release (#13621)
* docs: docs for next release * changes to opentelemetry dependencies * document plugin env variables * document admin changes * fix vale error * add version notes * document campaign budget updates * document campaign changes in user guide * document chages in cluster mode cli * documented once promotion allocation * document multiple API keys support
This commit is contained in:
1 parent
f38f0f9aca
commit
ed715813a5
54 files changed
+1621
-252
No files matched your search
@@ -98,9 +98,48 @@ For example, the `VITE_MY_API_KEY` environment variable in the example above wil
|
||||
|
||||
## Environment Variables in Plugins
|
||||
|
||||
As explained in the [previous section](#environment-variables-in-production), environment variables are inlined into the build. This presents a limitation for plugins, where you can't use environment variables.
|
||||
<Note>
|
||||
|
||||
Instead, only the following global variable is available in plugins:
|
||||
Environment variable support in plugins is available starting [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0). Refer to the [Medusa versions prior to v2.11.0](#for-medusa-versions-prior-to-v2110) section for more details if you're using an earlier version.
|
||||
|
||||
</Note>
|
||||
|
||||
For plugins, you can use environment variables without a prefix. Then, Medusa applications that use the plugin can set the environment variable with the `PLUGIN_` prefix.
|
||||
|
||||
For example, you can create a widget in your plugin that uses the `MY_API_KEY` environment variable:
|
||||
|
||||
```tsx highlights={[["8"]]}
|
||||
import { defineWidgetConfig } from "@medusajs/admin-sdk"
|
||||
import { Container, Heading } from "@medusajs/ui"
|
||||
|
||||
const ProductWidget = () => {
|
||||
return (
|
||||
<Container className="divide-y p-0">
|
||||
<div className="flex items-center justify-between px-6 py-4">
|
||||
<Heading level="h2">API Key: {import.meta.env.MY_API_KEY}</Heading>
|
||||
</div>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export const config = defineWidgetConfig({
|
||||
zone: "product.details.before",
|
||||
})
|
||||
|
||||
export default ProductWidget
|
||||
```
|
||||
|
||||
Then, in the Medusa application that uses the plugin, set the environment variable with the `PLUGIN_` prefix:
|
||||
|
||||
```bash
|
||||
PLUGIN_MY_API_KEY=sk_123
|
||||
```
|
||||
|
||||
The `MY_API_KEY` environment variable in the plugin will be replaced with the value of `PLUGIN_MY_API_KEY` during the build process of the Medusa application.
|
||||
|
||||
### Global Variables in Plugins
|
||||
|
||||
Plugins also have the following global variables available:
|
||||
|
||||
- `__BACKEND_URL__`: The URL of the Medusa backend, as set in the [Medusa configurations](../../../configurations/medusa-config/page.mdx#backendurl).
|
||||
- `__BASE__`: The base path of the Medusa Admin. (For example, `/app`).
|
||||
@@ -137,4 +176,14 @@ To fix possible type errors, create the file `src/admin/vite-env.d.ts` and add t
|
||||
declare const __BACKEND_URL__: string
|
||||
declare const __BASE__: string
|
||||
declare const __STOREFRONT_URL__: string
|
||||
```
|
||||
```
|
||||
|
||||
### For Medusa versions prior to v2.11.0
|
||||
|
||||
<Details summaryContent="Instructions for Medusa versions prior to v2.11.0">
|
||||
|
||||
As explained in the [Environment Variables in Production section](#environment-variables-in-production), environment variables are inlined into the build. This presents a limitation for plugins, where you can't use environment variables.
|
||||
|
||||
Instead, you can use the [Plugin Global Variables](#global-variables-in-plugins) described above to access the backend URL, base path, and storefront URL.
|
||||
|
||||
</Details>
|
||||
@@ -63,8 +63,14 @@ npx medusa db:generate blog
|
||||
|
||||
The `db:generate` command of the Medusa CLI accepts one or more module names to generate the migration for. It will create a migration file for the Blog Module in the directory `src/modules/blog/migrations` similar to the following:
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0), MikroORM dependencies are included in the `@medusajs/framework` package. If you're using an older version of Medusa, change the import statement to `@mikro-orm/migrations`.
|
||||
|
||||
</Note>
|
||||
|
||||
```ts
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
import { Migration } from "@medusajs/framework/@mikro-orm/migrations"
|
||||
|
||||
export class Migration20241121103722 extends Migration {
|
||||
|
||||
|
||||
@@ -37,8 +37,14 @@ You can also write migrations manually. To do that, create a file in the `migrat
|
||||
|
||||
For example:
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0), MikroORM dependencies are included in the `@medusajs/framework` package. If you're using an older version of Medusa, change the import statement to `@mikro-orm/migrations`.
|
||||
|
||||
</Note>
|
||||
|
||||
```ts title="src/modules/blog/migrations/Migration202507021059_create_author.ts"
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
import { Migration } from "@medusajs/framework/@mikro-orm/migrations"
|
||||
|
||||
export class Migration202507021059 extends Migration {
|
||||
|
||||
@@ -53,7 +59,7 @@ export class Migration202507021059 extends Migration {
|
||||
}
|
||||
```
|
||||
|
||||
The migration class in the file extends the `Migration` class imported from `@mikro-orm/migrations`. In the `up` and `down` method of the migration class, you use the `addSql` method provided by MikroORM's `Migration` class to run PostgreSQL syntax.
|
||||
The migration class in the file extends the `Migration` class imported from `@medusajs/framework/@mikro-orm/migrations`. In the `up` and `down` method of the migration class, you use the `addSql` method provided by MikroORM's `Migration` class to run PostgreSQL syntax.
|
||||
|
||||
In the example above, the `up` method creates the table `author`, and the `down` method drops the table if the migration is reverted.
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ So, to run database queries in a service:
|
||||
|
||||
For example, in your service, add the following methods:
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0), MikroORM dependencies are included in the `@medusajs/framework` package. If you're using an older version of Medusa, change the import statement to `@mikro-orm/knex`.
|
||||
|
||||
</Note>
|
||||
|
||||
export const methodsHighlight = [
|
||||
["13", "getCount", "Retrieves the number of records in `my_custom` using the `count` method."],
|
||||
["20", "getCountSql", "Retrieves the number of records in `my_custom` using the `execute` method."]
|
||||
@@ -39,7 +45,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -66,7 +72,7 @@ class BlogModuleService {
|
||||
|
||||
You add two methods `getCount` and `getCountSql` that have the `InjectManager` decorator. Each of the methods also accept the `sharedContext` parameter which has the `MedusaContext` decorator.
|
||||
|
||||
The entity manager is injected to the `sharedContext.manager` property, which is an instance of [EntityManager from the @mikro-orm/knex package](https://mikro-orm.io/api/knex/class/EntityManager).
|
||||
The entity manager is injected to the `sharedContext.manager` property, which is an instance of [EntityManager from the `@medusajs/framework/@mikro-orm/knex` package](https://mikro-orm.io/api/knex/class/EntityManager).
|
||||
|
||||
You use the manager in the `getCount` method to retrieve the number of records in a table, and in the `getCountSql` to run a PostgreSQL query that retrieves the count.
|
||||
|
||||
@@ -113,7 +119,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -174,7 +180,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -221,7 +227,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -380,7 +386,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -512,7 +518,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -582,7 +588,7 @@ The second parameter of the `baseRepository_.transaction` method is an object of
|
||||
|
||||
```ts highlights={[["24"]]}
|
||||
// other imports...
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
import {
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
@@ -625,8 +631,8 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { IsolationLevel } from "@mikro-orm/core"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
import { IsolationLevel } from "@medusajs/framework/@mikro-orm/core"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
@@ -660,7 +666,7 @@ import {
|
||||
MedusaContext,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Context } from "@medusajs/framework/types"
|
||||
import { EntityManager } from "@mikro-orm/knex"
|
||||
import { EntityManager } from "@medusajs/framework/@mikro-orm/knex"
|
||||
|
||||
class BlogModuleService {
|
||||
// ...
|
||||
|
||||
@@ -152,6 +152,12 @@ Consider your have a MongoDB module that allows you to perform operations on a M
|
||||
|
||||
To connect to the database, you create the following loader in your module:
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0), Awilix dependencies are included in the `@medusajs/framework` package. If you're using an older version of Medusa, change the import statement to `awilix`.
|
||||
|
||||
</Note>
|
||||
|
||||
export const loaderHighlights = [
|
||||
["5", "ModuleOptions", "Define a type for expected options."],
|
||||
["13", "ModuleOptions", "Pass the option type as a type argument to `LoaderOptions`."],
|
||||
@@ -163,7 +169,7 @@ export const loaderHighlights = [
|
||||
|
||||
```ts title="src/modules/mongo/loaders/connection.ts" highlights={loaderHighlights}
|
||||
import { LoaderOptions } from "@medusajs/framework/types"
|
||||
import { asValue } from "awilix"
|
||||
import { asValue } from "@medusajs/framework/awilix"
|
||||
import { MongoClient } from "mongodb"
|
||||
|
||||
type ModuleOptions = {
|
||||
@@ -233,7 +239,7 @@ In the loader, you check first that these options are set before proceeding. The
|
||||
After creating the client, you register it in the module's container using the container's `register` method. The method accepts two parameters:
|
||||
|
||||
1. The key to register the resource under, which in this case is `mongoClient`. You'll use this name later to resolve the client.
|
||||
2. The resource to register in the container, which is the MongoDB client you created. However, you don't pass the resource as-is. Instead, you need to use an `asValue` function imported from the [awilix package](https://github.com/jeffijoe/awilix), which is the package used to implement the container functionality in Medusa.
|
||||
2. The resource to register in the container, which is the MongoDB client you created. However, you don't pass the resource as-is. Instead, you need to use an `asValue` function imported from the [`@medusajs/framework/awilix` package](https://github.com/jeffijoe/awilix), which is the package used to implement the container functionality in Medusa.
|
||||
|
||||
### Use Custom Registered Resource in Module's Service
|
||||
|
||||
|
||||
@@ -195,8 +195,14 @@ npx medusa db:generate blog
|
||||
|
||||
The `db:generate` command of the Medusa CLI accepts one or more module names to generate the migration for. It will create a migration file for the Blog Module in the directory `src/modules/blog/migrations` similar to the following:
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0), MikroORM dependencies are included in the `@medusajs/framework` package. If you're using an older version of Medusa, change the import statement to `@mikro-orm/migrations`.
|
||||
|
||||
</Note>
|
||||
|
||||
```ts
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
import { Migration } from "@medusajs/framework/@mikro-orm/migrations"
|
||||
|
||||
export class Migration20241121103722 extends Migration {
|
||||
|
||||
|
||||
Reference in new issue
Block a user