docs: change config snippets to use defineConfig (#7546)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-30 16:47:28 +03:00
1 parent ddfd757277
commit fe96bd39b1
51 files changed
+489 -718

No files matched your search

@@ -75,23 +75,6 @@ const newKey = await apiKeyModuleService.create({
---
## Configure API Key Module
To use the API Key Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.API_KEY]: true,
}
```
---
## How to Use API Key Module's Service
You can use the API Key Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.API_KEY` imported from `@medusajs/modules-sdk`.
@@ -27,7 +27,7 @@ By default, admin users and customers can login with all installed auth provider
To limit the auth providers that used for admin users and customers, use the [authMethodsPerActor option](/references/medusa-config#http-authMethodsPerActor-1-3) in Medusa's configurations:
```js title="medusa-config.js"
module.exports = {
module.exports = defineConfig({
projectConfig: {
http: {
authMethodsPerActor: {
@@ -38,7 +38,7 @@ module.exports = {
},
// ...
}
}
})
```
---
@@ -15,35 +15,41 @@ In this document, you'll learn about the options of the Auth Module.
## providers
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
auth: {
resolve: "@medusajs/auth",
options: {
providers: [
{
name: "emailpass",
scopes: {
store: {},
admin: {},
},
},
{
name: "google",
scopes: {
admin: {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
successRedirectUrl:
process.env.GOOGLE_SUCCESS_REDIRECT_URL,
modules: {
[Modules.AUTH]: {
resolve: "@medusajs/auth",
options: {
providers: [
{
name: "emailpass",
scopes: {
store: {},
admin: {},
},
},
},
],
},
},
}
{
name: "google",
scopes: {
admin: {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
successRedirectUrl:
process.env.GOOGLE_SUCCESS_REDIRECT_URL,
},
},
},
],
},
}
}
})
```
The `providers` option is an array of objects indicating the auth providers to register, their scopes, and configurations.
@@ -69,22 +69,7 @@ const { success, authIdentity } =
## Configure Auth Module
To use the Auth Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.AUTH]: true,
}
```
{/* ### Module Options
Refer to [this documentation](./module-options/page.mdx) for details on the module's options. */}
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---
@@ -63,23 +63,6 @@ When used with their respective modules and other commerce modules, you benefit
---
## Configure Cart Module
To use the Cart Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.CART]: true,
}
```
---
## How to Use Cart Module's Service
You can use the Cart Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CART` imported from `@medusajs/modules-sdk`.
@@ -33,23 +33,6 @@ const currency = await currencyModuleService.retrieve(
---
## Configure Currency Module
To use the Currency Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.CURRENCY]: true,
}
```
---
## How to Use Currency Module's Service
You can use the Currency Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CURRENCY` imported from `@medusajs/modules-sdk`.
@@ -40,23 +40,6 @@ await customerModuleService.addCustomerToGroup({
---
## Configure Customer Module
To use the Customer Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.CUSTOMER]: true,
}
```
---
## How to Use Customer Module's Service
You can use the Customer Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CUSTOMER` imported from `@medusajs/modules-sdk`.
@@ -21,30 +21,36 @@ When the Medusa application starts, these providers are registered and can be us
For example:
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
fulfillment: {
resolve: "@medusajs/fulfillment",
options: {
providers: [
{
resolve: `@medusajs/fulfillment-manual`,
options: {
config: {
manual: {
// provider options...
modules: {
[Modules.FULFILLMENT]: {
resolve: "@medusajs/fulfillment",
options: {
providers: [
{
resolve: `@medusajs/fulfillment-manual`,
options: {
config: {
manual: {
// provider options...
}
}
}
}
},
],
},
],
},
},
},
}
}
})
```
The `providers` option is an array of objects that accept the following properties:
- `resolve`: A string indicating either the package name of the fulfillment provider module or the path to it.
- `resolve`: A string indicating either the package name of the fulfillment provider module or the path to it relative to the `src` directory.
- `options`: An optional object of the fulfillment provider module's options. The object must have the following property:
- `config`: An object whose key is the ID of the fulfillment provider, and its value is an object of options to pass to the provider module.
@@ -106,24 +106,6 @@ const fulfillmentSets = await fulfillmentModuleService.create(
## Configure Fulfillment Module
To use the Fulfillment Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
const modules = {
// ...
[Modules.FULFILLMENT]: {
resolve: "@medusajs/fulfillment",
providers: [
// ...
],
},
}
```
### Module Options
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---
@@ -66,23 +66,6 @@ const isAvailable =
---
## Configure Inventory Module
To use the Inventory Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.INVENTORY]: true,
}
```
---
## How to Use Inventory Module's Service
You can use the Inventory Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.INVENTORY` imported from `@medusajs/modules-sdk`.
@@ -100,23 +100,6 @@ await orderModuleService.confirmOrderChange("ord_123")
---
## Configure Order Module
To use the Order Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.ORDER]: true,
}
```
---
## How to Use Order Module's Service
You can use the Order Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.ORDER` imported from `@medusajs/modules-sdk`.
@@ -104,31 +104,32 @@ When the Medusa application starts, these providers are registered and can be us
For example:
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
payment: {
resolve: "@medusajs/payment",
options: {
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
// ...
modules: {
[Modules.PAYMENT]: {
resolve: "@medusajs/payment",
options: {
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
// ...
},
},
},
{
resolve: "medusa-payment-paypal",
options: {
// ...
},
},
],
],
},
},
},
}
}
})
```
The `providers` option is an array of objects that accept the following properties:
- `resolve`: A string indicating the package name of the payment provider module or the payment plugin, or the path to the file defining the payment provider.
- `options`: An optional object of options to pass to the payment provider.
- `resolve`: A string indicating the package name of the payment provider module or the path to it relative to the `src` directory.
- `options`: An optional object of the payment provider module's options. The object must have the following property:
- `config`: An object whose key is the ID of the payment provider, and its value is an object of options to pass to the provider module.
@@ -72,26 +72,6 @@ await paymentModuleService.processEvent({
## Configure Payment Module
To use the Payment Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.PAYMENT]: {
resolve: "@medusajs/payment",
options: {
// ...
},
},
}
```
### Module Options
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---
@@ -39,30 +39,36 @@ npm install @medusajs/payment-stripe
Next, add the module to the array of providers passed to the Payment Module:
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
payment: {
resolve: "@medusajs/payment",
options: {
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
config: {
stripe: {
credentials: {
usd: {
apiKey: process.env.STRIPE_USD_API_KEY,
modules: {
[Modules.PAYMENT]: {
resolve: "@medusajs/payment",
options: {
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
config: {
stripe: {
credentials: {
usd: {
apiKey: process.env.STRIPE_USD_API_KEY,
},
},
},
}
}
}
},
},
},
],
],
},
},
},
}
}
})
```
### Environment Variables
@@ -102,23 +102,6 @@ const price = await pricingModuleService.calculatePrices(
---
## Configure Pricing Module
To use the Pricing Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.PRICING]: true,
}
```
---
## How to Use Pricing Module's Service
You can use the Pricing Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PRICING` imported from `@medusajs/modules-sdk`.
@@ -60,23 +60,6 @@ const products = await productService.update([
---
## Configure Product Module
To use the Product Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.PRODUCT]: true,
}
```
---
## How to Use Product Module's Service
You can use the Product Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PRODUCT` imported from `@medusajs/modules-sdk`.
@@ -72,23 +72,6 @@ const campaign = await promotionModuleService.createCampaigns(
---
## Configure Promotion Module
To use the Promotion Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.PROMOTION]: true,
}
```
---
## How to Use the Promotion Module's Service
You can use the Promotion Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PROMOTION` imported from `@medusajs/modules-sdk`.
@@ -67,23 +67,6 @@ const regions = await regionModuleService.create([
---
## Configure Region Module
To use the Region Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.REGION]: true,
}
```
---
## How to Use Region Module's Service
You can use the Region Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.REGION` imported from `@medusajs/modules-sdk`.
@@ -51,23 +51,6 @@ Orders are also scoped to a sales channel due to the relation between the Sales
---
## Configure Sales Channel Module
To use the Sales Channel Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.SALES_CHANNEL]: true,
}
```
---
## How to Use Sales Channel Module's Service
You can use the Sales Channel Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.SALES_CHANNEL` imported from `@medusajs/modules-sdk`.
@@ -42,23 +42,6 @@ const stockLocation = await stockLocationModuleService.update(
---
## Configure Stock Location Module
To use the Stock Location Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.STOCK_LOCATION]: true,
}
```
---
## How to Use Stock Location Module's Service
You can use the Stock Location Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STOCK_LOCATION` imported from `@medusajs/modules-sdk`.
@@ -40,23 +40,6 @@ const stores = await storeModuleService.create([
---
## Configure Store Module
To use the Store Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.STORE]: true,
}
```
---
## How to Use Store Module's Service
You can use the Store Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STORE` imported from `@medusajs/modules-sdk`.
@@ -19,25 +19,31 @@ The `providers` option is an array of either tax provider modules, tax plugins,
When the Medusa application starts, these providers are registered and can be used to retrieve tax lines.
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
tax: {
resolve: "@medusajs/tax",
options: {
providers: [
{
resolve: "my-provider",
options: {
// ...
modules: {
[Modules.TAX]: {
resolve: "@medusajs/tax",
options: {
providers: [
{
resolve: "my-provider",
options: {
// ...
},
},
},
],
],
},
},
},
}
}
})
```
The objects in the array accept the following properties:
- `resolve`: A string indicating the package name of the tax provider module or the tax plugin, or the path to the file defining the tax provider.
- `resolve`: A string indicating the package name of the tax provider module or the path to it relative to the `src` directory.
- `options`: An object of options to pass to the tax provider.
@@ -78,21 +78,6 @@ const taxLines = await taxModuleService.getTaxLines(
## Configure Tax Module
To use the Tax Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.TAX]: true,
}
```
### Module Options
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---
@@ -15,15 +15,21 @@ In this document, you'll learn about the options of the User Module.
## Module Options
```js title="medusa-config.js"
const modules = {
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ...
user: {
resolve: "@medusajs/user",
options: {
jwt_secret: process.env.JWT_SECRET,
modules: {
[Modules.USER]: {
resolve: "@medusajs/user",
options: {
jwt_secret: process.env.JWT_SECRET,
},
},
},
}
}
})
```
<Table>
@@ -39,26 +39,6 @@ await userModuleService.refreshInviteTokens([invite.id])
## Configure User Module
To use the User Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
[Modules.USER]: {
resolve: "@medusajs/user",
options: {
jwt_secret: process.env.JWT_SECRET ?? "supersecret",
},
},
}
```
### Module Options
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---