docs: changes for next release (#12098)
* docs: changes for next release * generate * generate
This commit is contained in:
@@ -76,6 +76,70 @@ The value of each module’s property is an object, whose keys are of the format
|
||||
|
||||
So, in the example above, you link a record of the `MyCustom` data model in a `hello` module to a `Product` record in the Product Module.
|
||||
|
||||
### Enforced Integrity Constraints on Link Creation
|
||||
|
||||
Medusa enforces integrity constraints on links based on the link's relation type. So, an error is thrown in the following scenarios:
|
||||
|
||||
- If the link is one-to-one and one of the linked records already has a link to another record of the same data model. For example:
|
||||
|
||||
```ts
|
||||
// no error
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
"helloModuleService": {
|
||||
my_custom_id: "mc_123",
|
||||
},
|
||||
})
|
||||
|
||||
// throws an error because `prod_123` already has a link to `mc_123`
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
"helloModuleService": {
|
||||
my_custom_id: "mc_456",
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
- If the link is one-to-many and the "one" side already has a link to another record of the same data model. For example, if a product can have many `MyCustom` records, but a `MyCustom` record can only have one product:
|
||||
|
||||
```ts
|
||||
// no error
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
"helloModuleService": {
|
||||
my_custom_id: "mc_123",
|
||||
},
|
||||
})
|
||||
|
||||
// also no error
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
"helloModuleService": {
|
||||
my_custom_id: "mc_456",
|
||||
},
|
||||
})
|
||||
|
||||
// throws an error because `mc_123` already has a link to `prod_123`
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_456",
|
||||
},
|
||||
"helloModuleService": {
|
||||
my_custom_id: "mc_123",
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
There are no integrity constraints in a many-to-many link, so you can create multiple links between the same records.
|
||||
|
||||
---
|
||||
|
||||
## Dismiss Link
|
||||
|
||||
@@ -81,7 +81,7 @@ In addition, make sure that the `keywords` field in `package.json` includes the
|
||||
|
||||
<Note>
|
||||
|
||||
Your plugin project will already have the dependencies mentioned in this section. If you haven't made any changes to the dependencies, you can skip this section.
|
||||
Your plugin project will already have the dependencies mentioned in this section. Unless you made changes to the dependencies, you can skip this section.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -113,6 +113,48 @@ For example, assuming `2.5.0` is the latest Medusa version:
|
||||
}
|
||||
```
|
||||
|
||||
### Package Exports
|
||||
|
||||
<Note>
|
||||
|
||||
Your plugin project will already have the exports mentioned in this section. Unless you made changes to the exports or you created your plugin before [Medusa v2.7.0](https://github.com/medusajs/medusa/releases/tag/v2.7.0), you can skip this section.
|
||||
|
||||
</Note>
|
||||
|
||||
In the `package.json` file, make sure your plugin has the following exports:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
"./workflows": "./.medusa/server/src/workflows/index.js",
|
||||
"./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
|
||||
"./providers/*": "./.medusa/server/src/providers/*/index.js",
|
||||
"./admin": {
|
||||
"import": "./.medusa/server/src/admin/index.mjs",
|
||||
"require": "./.medusa/server/src/admin/index.js",
|
||||
"default": "./.medusa/server/src/admin/index.js"
|
||||
},
|
||||
"./*": "./.medusa/server/src/*.js"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
Aside from the `./package.json`, `./providers`, and `./admin`, these exports are only a recommendation. You can cherry-pick the files and directories you want to export.
|
||||
|
||||
</Note>
|
||||
|
||||
The plugin exports the following files and directories:
|
||||
|
||||
- `./package.json`: The `package.json` file. Medusa needs to access the `package.json` when registering the plugin.
|
||||
- `./workflows`: The workflows exported in `./src/workflows/index.ts`.
|
||||
- `./.medusa/server/src/modules/*`: The definition file of modules. This is useful if you create links to the plugin's modules in the Medusa application.
|
||||
- `./providers/*`: The definition file of module providers. This is useful if your plugin includes a module provider, allowing you to register the plugin's providers in Medusa applications. Learn more in the [Create Module Providers](#create-module-providers) section.
|
||||
- `./admin`: The admin extensions exported in `./src/admin/index.ts`.
|
||||
- `./*`: Any other files in the plugin's `src` directory.
|
||||
|
||||
---
|
||||
|
||||
## 3. Publish Plugin Locally for Development and Testing
|
||||
@@ -325,35 +367,11 @@ The migrations in your application, including your plugin, will run and update t
|
||||
|
||||
### Importing Module Resources
|
||||
|
||||
Your plugin project should have the following exports in `package.json`:
|
||||
In the [Prepare Plugin](#2-prepare-plugin) section, you learned about [exported resources](#package-exports) in your plugin.
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
"./workflows": "./.medusa/server/src/workflows/index.js",
|
||||
"./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
|
||||
"./providers/*": "./.medusa/server/src/providers/*/index.js",
|
||||
"./*": "./.medusa/server/src/*.js"
|
||||
}
|
||||
}
|
||||
```
|
||||
These exports allow you to import your plugin resources in your Medusa application, including workflows, links and modules.
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
Aside from the `./package.json` and `./providers`, these exports are only a recommendation. You can cherry-pick the files and directories you want to export.
|
||||
|
||||
</Note>
|
||||
|
||||
The plugin exports the following files and directories:
|
||||
|
||||
- `./package.json`: The package.json file. Medusa needs to access the `package.json` when registering the plugin.
|
||||
- `./workflows`: The workflows exported in `./src/workflows/index.ts`.
|
||||
- `./.medusa/server/src/modules/*`: The definition file of modules. This is useful if you create links to the plugin's modules in the Medusa application.
|
||||
- `./providers/*`: The definition file of module providers. This allows you to register the plugin's providers in the Medusa application.
|
||||
- `./*`: Any other files in the plugin's `src` directory.
|
||||
|
||||
With these exports, you can import the plugin's resources in the Medusa application's code like this:
|
||||
For example, to import the plugin's workflow in your Medusa application:
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
@@ -368,7 +386,17 @@ import BlogModule from "@myorg/plugin-name/modules/blog"
|
||||
import BlogType from "@myorg/plugin-name/types/blog"
|
||||
```
|
||||
|
||||
And you can register a module provider in the Medusa application's `medusa-config.ts` like this:
|
||||
### Create Module Providers
|
||||
|
||||
The [exported resources](#package-exports) also allow you to import module providers in your plugin and register them in the Medusa application's configuration. A module provider is a module that provides the underlying logic or integration related to a commerce or architectural module.
|
||||
|
||||
For example, assuming your plugin has a [Notification Module Provider](!resources!/architectural-modules/notification) called `my-notification`, you can register it in your Medusa application's configuration like this:
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
`@myorg/plugin-name` is the plugin package's name.
|
||||
|
||||
</Note>
|
||||
|
||||
```ts highlights={[["9"]]} title="medusa-config.ts"
|
||||
module.exports = defineConfig({
|
||||
@@ -395,8 +423,6 @@ module.exports = defineConfig({
|
||||
|
||||
You pass to `resolve` the path to the provider relative to the plugin package. So, in this example, the `my-notification` provider is located in `./src/providers/my-notification/index.ts` of the plugin.
|
||||
|
||||
### Create Module Providers
|
||||
|
||||
To learn how to create module providers, refer to the following guides:
|
||||
|
||||
<CardList
|
||||
|
||||
@@ -101,7 +101,7 @@ export const generatedEditDates = {
|
||||
"app/learn/fundamentals/workflows/multiple-step-usage/page.mdx": "2024-11-25T16:19:32.169Z",
|
||||
"app/learn/installation/page.mdx": "2025-03-11T08:55:12.967Z",
|
||||
"app/learn/fundamentals/data-models/check-constraints/page.mdx": "2024-12-06T14:34:50.384Z",
|
||||
"app/learn/fundamentals/module-links/link/page.mdx": "2025-01-06T09:27:25.604Z",
|
||||
"app/learn/fundamentals/module-links/link/page.mdx": "2025-04-07T08:03:14.513Z",
|
||||
"app/learn/fundamentals/workflows/store-executions/page.mdx": "2025-02-11T15:56:03.835Z",
|
||||
"app/learn/fundamentals/plugins/create/page.mdx": "2025-04-07T14:50:53.866Z",
|
||||
"app/learn/fundamentals/plugins/page.mdx": "2025-01-22T10:14:10.433Z",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -105,11 +105,11 @@ To retrieve the account holder associated with a customer with [Query](!docs!/le
|
||||
const { data: customers } = await query.graph({
|
||||
entity: "customer",
|
||||
fields: [
|
||||
"account_holder.*",
|
||||
"account_holders.*",
|
||||
],
|
||||
})
|
||||
|
||||
// customers.account_holder
|
||||
// customers.account_holders
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
@@ -123,11 +123,11 @@ import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
|
||||
const { data: customers } = useQueryGraphStep({
|
||||
entity: "customer",
|
||||
fields: [
|
||||
"account_holder.*",
|
||||
"account_holders.*",
|
||||
],
|
||||
})
|
||||
|
||||
// customers.account_holder
|
||||
// customers.account_holders
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
|
||||
@@ -23,6 +23,14 @@ It holds fields retrieved from the third-party provider, such as:
|
||||
|
||||
A payment provider that supports saving payment methods for customers would create the equivalent of an account holder in the third-party provider. Then, whenever a payment method is saved, it would be saved under the account holder in the third-party provider.
|
||||
|
||||
### Relation between Account Holder and Customer
|
||||
|
||||
The Medusa application creates a link between the [Customer](/references/customer/models/Customer) data model of the [Customer Module](../../customer/page.mdx) and the `AccountHolder` data model of the Payment Module.
|
||||
|
||||
This link indicates that a customer can have more than one account holder, each representing saved payment methods in different payment providers.
|
||||
|
||||
Learn more about this link in the [Link to Other Modules](../links-to-other-modules/page.mdx) guide.
|
||||
|
||||
---
|
||||
|
||||
## Save Payment Methods
|
||||
|
||||
@@ -5725,7 +5725,7 @@ export const generatedEditDates = {
|
||||
"app/commerce-modules/tax/admin-widget-zones/page.mdx": "2024-12-24T08:47:13.176Z",
|
||||
"app/commerce-modules/user/admin-widget-zones/page.mdx": "2024-12-24T08:48:14.186Z",
|
||||
"app/commerce-modules/currency/links-to-other-modules/page.mdx": "2025-03-17T06:41:29.161Z",
|
||||
"app/commerce-modules/customer/links-to-other-modules/page.mdx": "2025-03-14T15:18:39.759Z",
|
||||
"app/commerce-modules/customer/links-to-other-modules/page.mdx": "2025-04-07T07:31:46.046Z",
|
||||
"app/commerce-modules/fulfillment/events/page.mdx": "2024-12-31T09:37:49.253Z",
|
||||
"app/commerce-modules/payment/events/page.mdx": "2024-12-31T09:41:56.582Z",
|
||||
"references/core_flows/Payment/Steps_Payment/functions/core_flows.Payment.Steps_Payment.refundPaymentsStep/page.mdx": "2025-03-04T13:33:44.866Z",
|
||||
@@ -5891,7 +5891,7 @@ export const generatedEditDates = {
|
||||
"references/types/HttpTypes/interfaces/types.HttpTypes.StoreProductTypeResponse/page.mdx": "2025-01-27T11:43:54.212Z",
|
||||
"references/types/interfaces/types.BaseProductTypeListParams/page.mdx": "2025-01-27T11:43:54.550Z",
|
||||
"references/core_flows/Order/Steps_Order/variables/core_flows.Order.Steps_Order.updateOrderChangesStepId/page.mdx": "2025-01-27T11:43:49.278Z",
|
||||
"app/commerce-modules/payment/account-holder/page.mdx": "2025-01-31T09:37:41.595Z",
|
||||
"app/commerce-modules/payment/account-holder/page.mdx": "2025-04-07T07:31:20.235Z",
|
||||
"app/troubleshooting/test-errors/page.mdx": "2025-01-31T13:08:42.639Z",
|
||||
"app/commerce-modules/product/variant-inventory/page.mdx": "2025-02-26T11:21:20.075Z",
|
||||
"app/examples/guides/custom-item-price/page.mdx": "2025-03-05T11:30:19.896Z",
|
||||
|
||||
Reference in New Issue
Block a user