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
+327 -556

No files matched your search

+119 -136
View File
@@ -125,14 +125,14 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseName: process.env.DATABASE_DATABASE || * databaseName: process.env.DATABASE_NAME ||
* "medusa-store", * "medusa-store",
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseName?: string databaseName?: string
@@ -164,13 +164,13 @@ export type ProjectConfigOptions = {
* Then, use the value in `medusa-config.js`: * Then, use the value in `medusa-config.js`:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseUrl: process.env.DATABASE_URL, * databaseUrl: process.env.DATABASE_URL,
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseUrl?: string databaseUrl?: string
@@ -179,14 +179,14 @@ export type ProjectConfigOptions = {
* The database schema to connect to. This is not required to provide if you’re using the default schema, which is `public`. * The database schema to connect to. This is not required to provide if you’re using the default schema, which is `public`.
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseSchema: process.env.DATABASE_SCHEMA || * databaseSchema: process.env.DATABASE_SCHEMA ||
* "custom", * "custom",
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseSchema?: string databaseSchema?: string
@@ -202,15 +202,13 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseLogging: [ * databaseLogging: ["query", "error"]
* "query", "error",
* ],
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseLogging?: LoggerOptions databaseLogging?: LoggerOptions
@@ -233,16 +231,14 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseExtra: * databaseExtra: process.env.NODE_ENV !== "development" ?
* process.env.NODE_ENV !== "development" * { ssl: { rejectUnauthorized: false } } : {}
* ? { ssl: { rejectUnauthorized: false } }
* : {},
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseExtra?: Record<string, unknown> & { databaseExtra?: Record<string, unknown> & {
@@ -266,16 +262,14 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* databaseDriverOptions: * databaseDriverOptions: process.env.NODE_ENV !== "development" ?
* process.env.NODE_ENV !== "development" * { ssl: { rejectUnauthorized: false } } : {}
* ? { connection: { ssl: { rejectUnauthorized: false } } }
* : {},
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
databaseDriverOptions?: Record<string, unknown> & { databaseDriverOptions?: Record<string, unknown> & {
@@ -311,14 +305,14 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* redisUrl: process.env.REDIS_URL || * redisUrl: process.env.REDIS_URL ||
* "redis://localhost:6379", * "redis://localhost:6379",
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
redisUrl?: string redisUrl?: string
@@ -330,14 +324,13 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* redisPrefix: process.env.REDIS_PREFIX || * redisPrefix: process.env.REDIS_URL || "medusa:",
* "medusa:",
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
redisPrefix?: string redisPrefix?: string
@@ -348,16 +341,16 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* redisOptions: { * redisOptions: {
* connectionName: process.env.REDIS_CONNECTION_NAME || * connectionName: process.env.REDIS_CONNECTION_NAME ||
* "medusa", * "medusa",
* },
* // ...
* },
* // ...
* } * }
* // ...
* },
* // ...
* })
* ``` * ```
*/ */
redisOptions?: RedisOptions redisOptions?: RedisOptions
@@ -367,16 +360,15 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* sessionOptions: { * sessionOptions: {
* name: process.env.SESSION_NAME || * name: process.env.SESSION_NAME || "custom",
* "custom",
* },
* // ...
* },
* // ...
* } * }
* // ...
* },
* // ...
* })
* ``` * ```
*/ */
sessionOptions?: SessionOptions sessionOptions?: SessionOptions
@@ -387,21 +379,7 @@ export type ProjectConfigOptions = {
* *
* If you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `"x-no-compression": true`. * If you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `"x-no-compression": true`.
* *
* @example * @ignore
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* httpCompression: {
* enabled: true,
* level: 6,
* memLevel: 8,
* threshold: 1024,
* },
* // ...
* },
* // ...
* }
* ```
* *
* @deprecated use {@link http }'s `compression` property instead. * @deprecated use {@link http }'s `compression` property instead.
* *
@@ -413,13 +391,13 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* jobsBatchSize: 100 * jobsBatchSize: 100
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
jobsBatchSize?: number jobsBatchSize?: number
@@ -435,13 +413,13 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* workerMode: "shared" * workerMode: "shared"
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
workerMode?: "shared" | "worker" | "server" workerMode?: "shared" | "worker" | "server"
@@ -451,16 +429,18 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* cookieSecret: "some-super-secret", * cookieSecret: "supersecret",
* compression: { ... }, * compression: {
* // ...
* }
* } * }
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
http: { http: {
@@ -472,14 +452,15 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* cookieSecret: "supersecret" * jwtSecret: "supersecret",
* } * }
* // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
jwtSecret?: string jwtSecret?: string
@@ -488,14 +469,15 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* jwtExpiresIn: "2d" * jwtExpiresIn: "2d"
* } * }
* // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
jwtExpiresIn?: string jwtExpiresIn?: string
@@ -507,7 +489,7 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* cookieSecret: "supersecret" * cookieSecret: "supersecret"
@@ -515,7 +497,7 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
cookieSecret?: string cookieSecret?: string
@@ -546,7 +528,7 @@ export type ProjectConfigOptions = {
* Then, set the configuration in `medusa-config.js`: * Then, set the configuration in `medusa-config.js`:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* authCors: process.env.AUTH_CORS * authCors: process.env.AUTH_CORS
@@ -554,13 +536,13 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
* *
* If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example: * If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* authCors: "/http:\\/\\/localhost:700\\d+$/", * authCors: "/http:\\/\\/localhost:700\\d+$/",
@@ -568,7 +550,7 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
authCors: string authCors: string
@@ -583,20 +565,20 @@ export type ProjectConfigOptions = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* compression: { * compression: {
* enabled: true, * enabled: true,
* level: 6, * level: 6,
* memLevel: 8, * memLevel: 8,
* threshold: 1024, * threshold: 1024
* }
* } * }
* },
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
compression?: HttpCompressionOptions compression?: HttpCompressionOptions
@@ -627,7 +609,7 @@ export type ProjectConfigOptions = {
* Then, set the configuration in `medusa-config.js`: * Then, set the configuration in `medusa-config.js`:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* storeCors: process.env.STORE_CORS, * storeCors: process.env.STORE_CORS,
@@ -635,13 +617,13 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
* *
* If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example: * If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* storeCors: "/vercel\\.app$/", * storeCors: "/vercel\\.app$/",
@@ -649,7 +631,7 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
storeCors: string storeCors: string
@@ -681,7 +663,7 @@ export type ProjectConfigOptions = {
* Then, set the configuration in `medusa-config.js`: * Then, set the configuration in `medusa-config.js`:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* adminCors: process.env.ADMIN_CORS, * adminCors: process.env.ADMIN_CORS,
@@ -689,21 +671,21 @@ export type ProjectConfigOptions = {
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
* *
* If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example: * If you’re adding the value directly within `medusa-config.js`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* adminCors: process.env.ADMIN_CORS, * adminCors: "/vercel\\.app$/",
* } * }
* // ... * // ...
* }, * },
* // ... * // ...
* } * })
* ``` * ```
*/ */
adminCors: string adminCors: string
@@ -721,18 +703,18 @@ export type ProjectConfigOptions = {
* Then, set the configuration in `medusa-config.js`: * Then, set the configuration in `medusa-config.js`:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig: { * projectConfig: {
* http: { * http: {
* authMethodsPerActor: { * authMethodsPerActor: {
* user: ['sso'], * user: ["email"],
* customer: ["emailpass", "google"] * customer: ["emailpas", "google"]
* },
* },
* // ...
* },
* // ...
* } * }
* }
* // ...
* },
* // ...
* })
* ``` * ```
*/ */
authMethodsPerActor?: Record<string, string[]> authMethodsPerActor?: Record<string, string[]>
@@ -755,12 +737,20 @@ export type ProjectConfigOptions = {
* For example: * For example:
* *
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* projectConfig, * projectConfig: {
* admin, * // ...
* modules, * },
* featureFlags, * admin: {
* // ...
* },
* modules: {
* // ...
* },
* featureFlags: {
* // ...
* } * }
* })
* ``` * ```
* *
* --- * ---
@@ -785,12 +775,13 @@ export type ConfigModule = {
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* admin: { * admin: {
* backendUrl: process.env.MEDUSA_BACKEND_URL || "http://localhost:9000" * backendUrl: process.env.MEDUSA_BACKEND_URL ||
* } * "http://localhost:9000"
* },
* // ... * // ...
* } * })
* ``` * ```
*/ */
admin?: AdminOptions admin?: AdminOptions
@@ -825,6 +816,11 @@ export type ConfigModule = {
* // ... * // ...
* } * }
* ``` * ```
*
* @ignore
*
* @privateRemarks
* Added the `@\ignore` tag for now so it's not generated in the main docs until we figure out what to do with plugins
*/ */
plugins: ( plugins: (
| { | {
@@ -840,35 +836,24 @@ export type ConfigModule = {
* *
* Aside from installing the module with NPM, you must add it to the exported object in `medusa-config.js`. * Aside from installing the module with NPM, you must add it to the exported object in `medusa-config.js`.
* *
* The keys of the `modules` configuration object refer to the type of module. Its value can be one of the following: * The keys of the `modules` configuration object refer to the module's registration name. Its value can be one of the following:
* *
* 1. A boolean value indicating whether the module type is enabled; * 1. A boolean value indicating whether the module type is enabled. This is only supported for Medusa's commerce and architectural modules;
* 2. Or a string value indicating the name of the module to be used for the module type. This can be used if the module does not require any options; * 2. Or an object having the following properties:
* 3. Or an object having the following properties, but typically you would mainly use the `resolve` and `options` properties only: * 1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name.
* 1. `resolve`: a string indicating the name of the module. * 2. `options`: (optional) an object indicating the options to pass to the module.
* 2. `options`: an object indicating the options to pass to the module. These options vary for each module, and you should refer to the module’s documentation for details on them. * 3. `definition`: (optional) an object of extra configurations, such as `isQueryable` used when a module has relationships.
* 3. `resources`: a string indicating whether the module shares the dependency container with the Medusa core. Its value can either be `shared` or `isolated`. Refer to the [Modules documentation](https://docs.medusajs.com/development/modules/create#module-scope) for more details.
* 4. `alias`: a string indicating a unique alias to register the module under. Other modules can’t use the same alias.
* 5. `main`: a boolean value indicating whether this module is the main registered module. This is useful when an alias is used.
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* modules: { * modules: {
* eventBus: { * helloModuleService: {
* resolve: "@medusajs/event-bus-local", * resolve: "./modules/hello"
* },
* cacheService: {
* resolve: "@medusajs/cache-redis",
* options: {
* redisUrl: process.env.CACHE_REDIS_URL,
* ttl: 30,
* },
* },
* // ...
* },
* // ...
* } * }
* }
* // ...
* })
* ``` * ```
*/ */
modules?: Record< modules?: Record<
@@ -882,26 +867,24 @@ export type ConfigModule = {
* You can specify whether a feature should or shouldn’t be used in your backend by enabling its feature flag. Feature flags can be enabled through either environment * You can specify whether a feature should or shouldn’t be used in your backend by enabling its feature flag. Feature flags can be enabled through either environment
* variables or through this configuration exported in `medusa-config.js`. * variables or through this configuration exported in `medusa-config.js`.
* *
* If you want to use the environment variables method, learn more about it in the [Feature Flags documentation](https://docs.medusajs.com/development/feature-flags/toggle#method-one-using-environment-variables).
*
* The `featureFlags` configuration is an object. Its properties are the names of the feature flags. Each property’s value is a boolean indicating whether the feature flag is enabled. * The `featureFlags` configuration is an object. Its properties are the names of the feature flags. Each property’s value is a boolean indicating whether the feature flag is enabled.
* *
* You can find available feature flags and their key name [here](https://github.com/medusajs/medusa/tree/master/packages/medusa/src/loaders/feature-flags). * You can find available feature flags and their key name [here](https://github.com/medusajs/medusa/tree/develop/packages/medusa/src/loaders/feature-flags).
* *
* @example * @example
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = defineConfig({
* featureFlags: { * featureFlags: {
* product_categories: true, * product_categories: true,
* // ... * // ...
* },
* // ...
* } * }
* // ...
* })
* ``` * ```
* *
* :::note * :::note
* *
* After enabling a feature flag, make sure to [run migrations](https://docs.medusajs.com/development/entities/migrations/overview#migrate-command) as it may require making changes to the database. * After enabling a feature flag, make sure to run migrations as it may require making changes to the database.
* *
* ::: * :::
*/ */
@@ -17,16 +17,15 @@ You configure allowed origins for Store and Admin API Routes using the `storeCor
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = defineConfig({
projectConfig: { projectConfig: {
http: { http: {
adminCors: "http://localhost:7001",
storeCors: "http://localhost:8000", storeCors: "http://localhost:8000",
adminCors: "http://localhost:7001",
// ... // ...
}
}, },
// ...
} }
})
``` ```
This allows the `http://localhost:7001` origin to access the Admin API Routes, and the `http://localhost:8000` origin to access Store API Routes. This allows the `http://localhost:7001` origin to access the Admin API Routes, and the `http://localhost:8000` origin to access Store API Routes.
@@ -209,22 +209,24 @@ This creates a relationship to the `Product` data model of the Product Module us
### 2. Adjust Module Configuration ### 2. Adjust Module Configuration
To use relationships in a module, adjust its configuration object passed to the `modules` object in `medusa-config.js`: To use relationships in a module, adjust its configuration object passed to `modules` in `medusa-config.js`:
export const configHighlights = [ export const configHighlights = [
["7", "isQueryable", "Enable this property to use relationships in a module."] ["7", "isQueryable", "Enable this property to use relationships in a module."]
] ]
```js title="medusa-config.js" highlights={configHighlights} ```js title="medusa-config.js" highlights={configHighlights}
const modules = { module.exports = defineConfig({
// ...
modules: {
helloModuleService: { helloModuleService: {
// ... // ...
definition: { definition: {
isQueryable: true, isQueryable: true
},
},
// ...
} }
}
}
})
``` ```
Enabling the `isQueryable` property is required to use relationships in a module. Enabling the `isQueryable` property is required to use relationships in a module.
@@ -23,15 +23,18 @@ To pass options to a module, add an `options` property to the module’s configu
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { module.exports = defineConfig({
// ...
modules: {
helloModuleService: { helloModuleService: {
resolve: "./dist/modules/hello", resolve: "./modules/hello",
options: { options: {
capitalize: true, capitalize: true,
}, },
},
// ...
} }
}
})
``` ```
The `options` property’s value is an object. You can pass any properties you want. The `options` property’s value is an object. You can pass any properties you want.
@@ -62,13 +62,15 @@ The last step is to add the module in Medusa’s configurations.
In `medusa-config.js`, add the module to the `modules` object: In `medusa-config.js`, add the module to the `modules` object:
```js title="medusa-config.js" highlights={[["2", "helloModuleService", "The key of the main service to be registered in the Medusa container."]]} ```js title="medusa-config.js" highlights={[["4", "helloModuleService", "The key of the main service to be registered in the Medusa container."]]}
const modules = { module.exports = defineConfig({
// ...
modules: {
helloModuleService: { helloModuleService: {
resolve: "./dist/modules/hello", resolve: "./modules/hello",
},
// other modules...
} }
}
})
``` ```
Its key (`helloModuleService`) is the name of the module’s main service. It will be registered in the Medusa container with that name. Its key (`helloModuleService`) is the name of the module’s main service. It will be registered in the Medusa container with that name.
@@ -64,11 +64,12 @@ To test out your scheduled job:
1. Uncomment the following line in the `medusa-config.js` file: 1. Uncomment the following line in the `medusa-config.js` file:
```js title="medusa-config.js" ```js title="medusa-config.js"
const projectConfig = { module.exports = defineConfig({
projectConfig: {
redisUrl: REDIS_URL
// ... // ...
// Uncomment the following lines to enable REDIS
redisUrl: REDIS_URL,
} }
})
``` ```
2. Start the Medusa application: 2. Start the Medusa application:
@@ -46,17 +46,17 @@ MEDUSA_FF_TAX_INCLUSIVE_PRICING=true
A feature flag also has an associated key that can be used to toggle its value in Medusa’s configurations. A feature flag also has an associated key that can be used to toggle its value in Medusa’s configurations.
The configuration object 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. 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: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = defineConfig({
featureFlags: { featureFlags: {
tax_inclusive_pricing: true, tax_inclusive_pricing: true,
}, },
// ... // ...
} })
``` ```
<Note title="Tip"> <Note title="Tip">
@@ -29,15 +29,15 @@ The Medusa application’s API routes are guarded by a CORS middleware. Make sur
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = defineConfig({
projectConfig: { projectConfig: {
http: { http: {
storeCors: "http://localhost:3000", storeCors: "http://localhost:3000",
// ... // ...
} }
},
// ...
} }
// ...
})
``` ```
--- ---
@@ -152,14 +152,20 @@ To use your Cache Module, add it to the `modules` object exported as part of the
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// other modules...
cacheService: { // ...
resolve: "./dist/modules/my-cache/index.ts",
module.exports = defineConfig({
// ...
modules: {
[Modules.CACHE]: {
resolve: "./modules/my-cache",
options: { options: {
// any necessary options // any options
ttl: 30, ttl: 30,
}, },
}, },
} }
})
``` ```
@@ -16,6 +16,12 @@ For production, it’s recommended to use modules like [Redis Cache Module](../r
## Install the In-Memory Cache Module ## Install the In-Memory Cache Module
<Note>
The In-Memory Cache Module is installed by default in your application.
</Note>
To install the In-Memory Cache Module, run the following command in the directory of your Medusa application: To install the In-Memory Cache Module, run the following command in the directory of your Medusa application:
```bash npm2yarn ```bash npm2yarn
@@ -29,18 +35,17 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.CACHE]: { [Modules.CACHE]: {
resolve: "@medusajs/cache-inmemory", resolve: "@medusajs/cache-inmemory",
options: { options: {
// optional options // optional options
}, },
}, },
},
} }
})
``` ```
### In-Memory Cache Module Options ### In-Memory Cache Module Options
@@ -27,7 +27,7 @@ npm install @medusajs/cache-redis
Next, add the module into the `modules` property of the exported object in `medusa-config.js`: Next, add the module into the `modules` property of the exported object in `medusa-config.js`:
export const highlights = [ export const highlights = [
["12", "redisUrl", "The Redis connection URL."] ["11", "redisUrl", "The Redis connection URL."]
] ]
```js title="medusa-config.js" highlights={highlights} ```js title="medusa-config.js" highlights={highlights}
@@ -35,18 +35,17 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.CACHE]: { [Modules.CACHE]: {
resolve: "@medusajs/cache-redis", resolve: "@medusajs/cache-redis",
options: { options: {
redisUrl: process.env.CACHE_REDIS_URL, redisUrl: process.env.CACHE_REDIS_URL,
}, },
}, },
},
} }
})
``` ```
### Environment Variables ### Environment Variables
@@ -107,13 +107,19 @@ To use your Event Module, add it to the `modules` object exported as part of the
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// other modules...
eventBus: { // ...
resolve: "./dist/modules/my-event/index.ts",
module.exports = defineConfig({
// ...
modules: {
[Modules.EVENT_BUS]: {
resolve: "./modules/my-event",
options: { options: {
// any necessary options // any options
}, },
}, },
} }
})
``` ```
@@ -14,6 +14,12 @@ For production, it’s recommended to use modules like [Redis Event Bus Module](
## Install the Local Event Bus Module ## Install the Local Event Bus Module
<Note>
The Local Event Bus Module is installed by default in your application.
</Note>
To install Local Event Bus Module, run the following command in the directory of your Medusa application: To install Local Event Bus Module, run the following command in the directory of your Medusa application:
```bash npm2yarn ```bash npm2yarn
@@ -27,13 +33,12 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.EVENT_BUS]: true, [Modules.EVENT_BUS]: true,
},
} }
})
``` ```
--- ---
@@ -31,7 +31,7 @@ npm install @medusajs/event-redis
Next, add the module into the `modules` property of the exported object in `medusa-config.js`: Next, add the module into the `modules` property of the exported object in `medusa-config.js`:
export const highlights = [ export const highlights = [
["8", "redisUrl", "The Redis connection URL."] ["11", "redisUrl", "The Redis connection URL."]
] ]
```js title="medusa-config.js" ```js title="medusa-config.js"
@@ -39,18 +39,17 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.EVENT_BUS]: { [Modules.EVENT_BUS]: {
resolve: "@medusajs/event-redis", resolve: "@medusajs/event-redis",
options: { options: {
redisUrl: process.env.EVENTS_REDIS_URL, redisUrl: process.env.EVENTS_REDIS_URL,
}, },
}, },
},
} }
})
``` ```
### Environment Variables ### Environment Variables
@@ -12,6 +12,12 @@ The Local File Provider Module stores files uploaded to your Medusa application
## Install the Local File Module ## Install the Local File Module
<Note>
The Local File Module is installed by default in your application.
</Note>
To install the Local File Provider Module, run the following command in the directory of your Medusa application: To install the Local File Provider Module, run the following command in the directory of your Medusa application:
```bash npm2yarn ```bash npm2yarn
@@ -27,10 +33,13 @@ The File Module accepts one provider only.
</Note> </Note>
```js title="medusa-config.js" ```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = { module.exports = {
// ... // ...
modules: { modules: {
// ...
[Modules.FILE]: { [Modules.FILE]: {
resolve: "@medusajs/file", resolve: "@medusajs/file",
options: { options: {
@@ -85,6 +85,10 @@ The File Module accepts one provider only.
</Note> </Note>
```js title="medusa-config.js" ```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = { module.exports = {
// ... // ...
modules: { modules: {
@@ -12,6 +12,12 @@ The Local Notification Provider Module simulates sending a notification, but onl
## Install the Local Notification Module ## Install the Local Notification Module
<Note>
The Local Notification Provider Module is installed by default in your application.
</Note>
To install the Local Notification Provider Module, run the following command in the directory of your Medusa application: To install the Local Notification Provider Module, run the following command in the directory of your Medusa application:
```bash npm2yarn ```bash npm2yarn
@@ -27,10 +33,13 @@ Only one provider can be defined for a channel.
</Note> </Note>
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.NOTIFICATION]: { [Modules.NOTIFICATION]: {
resolve: "@medusajs/notification", resolve: "@medusajs/notification",
options: { options: {
@@ -49,8 +58,8 @@ module.exports = {
], ],
}, },
}, },
},
} }
})
``` ```
### Local Notification Module Options ### Local Notification Module Options
@@ -30,7 +30,11 @@ When you send a notification, you specify the channel to send it through, such a
For example: For example:
```js title="medusa-config.js" highlights={[["15"]]} ```js title="medusa-config.js" highlights={[["19"]]}
const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = { module.exports = {
// ... // ...
modules: { modules: {
@@ -35,10 +35,13 @@ Only one provider can be defined for a channel.
</Note> </Note>
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { const { Modules } = require("@medusajs/modules-sdk")
// ...
module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.NOTIFICATION]: { [Modules.NOTIFICATION]: {
resolve: "@medusajs/notification", resolve: "@medusajs/notification",
options: { options: {
@@ -59,8 +62,8 @@ module.exports = {
], ],
}, },
}, },
},
} }
})
``` ```
### Environment Variables ### Environment Variables
@@ -16,6 +16,12 @@ For production, it’s recommended to use modules like [Redis Workflow Engine Mo
## Install the In-Memory Workflow Engine Module ## Install the In-Memory Workflow Engine Module
<Note>
The In-Memory Workflow Engine Module is installed by default in your application.
</Note>
To install the In-Memory Workflow Engine Module, run the following command in the directory of your Medusa application: To install the In-Memory Workflow Engine Module, run the following command in the directory of your Medusa application:
```bash npm2yarn ```bash npm2yarn
@@ -29,11 +35,10 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.WORKFLOW_ENGINE]: true, [Modules.WORKFLOW_ENGINE]: true,
},
} }
})
``` ```
@@ -27,7 +27,7 @@ npm install @medusajs/workflow-engine-redis
Next, add the module into the `modules` property of the exported object in `medusa-config.js`: Next, add the module into the `modules` property of the exported object in `medusa-config.js`:
export const highlights = [ export const highlights = [
["8", "redisUrl", "The Redis connection URL."] ["12", "url", "The Redis connection URL."]
] ]
```js title="medusa-config.js" highlights={highlights} ```js title="medusa-config.js" highlights={highlights}
@@ -35,10 +35,9 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
module.exports = { module.exports = defineConfig({
// ... // ...
modules: { modules: {
// ...
[Modules.WORKFLOW_ENGINE]: { [Modules.WORKFLOW_ENGINE]: {
resolve: "@medusajs/workflow-engine-redis", resolve: "@medusajs/workflow-engine-redis",
options: { options: {
@@ -47,8 +46,8 @@ module.exports = {
}, },
}, },
}, },
},
} }
})
``` ```
### Environment Variables ### Environment Variables
@@ -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 ## 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`. 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: 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" ```js title="medusa-config.js"
module.exports = { module.exports = defineConfig({
projectConfig: { projectConfig: {
http: { http: {
authMethodsPerActor: { authMethodsPerActor: {
@@ -38,7 +38,7 @@ module.exports = {
}, },
// ... // ...
} }
} })
``` ```
--- ---
@@ -15,9 +15,14 @@ In this document, you'll learn about the options of the Auth Module.
## providers ## providers
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
auth: {
module.exports = defineConfig({
// ...
modules: {
[Modules.AUTH]: {
resolve: "@medusajs/auth", resolve: "@medusajs/auth",
options: { options: {
providers: [ providers: [
@@ -42,8 +47,9 @@ const modules = {
}, },
], ],
}, },
},
} }
}
})
``` ```
The `providers` option is an array of objects indicating the auth providers to register, their scopes, and configurations. 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 ## Configure Auth Module
To use the Auth Module, enable it in the `modules` object in `medusa-config.js`: Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
```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. */}
--- ---
@@ -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 ## 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`. 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 ## 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`. 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 ## 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`. 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,9 +21,14 @@ When the Medusa application starts, these providers are registered and can be us
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
fulfillment: {
module.exports = defineConfig({
// ...
modules: {
[Modules.FULFILLMENT]: {
resolve: "@medusajs/fulfillment", resolve: "@medusajs/fulfillment",
options: { options: {
providers: [ providers: [
@@ -41,10 +46,11 @@ const modules = {
}, },
}, },
} }
})
``` ```
The `providers` option is an array of objects that accept the following properties: 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: - `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. - `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 ## 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. 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 ## 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`. 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 ## 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`. 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,9 +104,14 @@ When the Medusa application starts, these providers are registered and can be us
For example: For example:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
payment: {
module.exports = defineConfig({
// ...
modules: {
[Modules.PAYMENT]: {
resolve: "@medusajs/payment", resolve: "@medusajs/payment",
options: { options: {
providers: [ providers: [
@@ -116,19 +121,15 @@ const modules = {
// ... // ...
}, },
}, },
{
resolve: "medusa-payment-paypal",
options: {
// ...
},
},
], ],
}, },
}, },
} }
})
``` ```
The `providers` option is an array of objects that accept the following properties: 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. - `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 options to pass to the payment provider. - `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 ## 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. Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
--- ---
@@ -39,9 +39,14 @@ npm install @medusajs/payment-stripe
Next, add the module to the array of providers passed to the Payment Module: Next, add the module to the array of providers passed to the Payment Module:
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
payment: {
module.exports = defineConfig({
// ...
modules: {
[Modules.PAYMENT]: {
resolve: "@medusajs/payment", resolve: "@medusajs/payment",
options: { options: {
providers: [ providers: [
@@ -63,6 +68,7 @@ const modules = {
}, },
}, },
} }
})
``` ```
### Environment Variables ### 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 ## 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`. 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 ## 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`. 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 ## 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`. 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 ## 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`. 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 ## 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`. 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 ## 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`. 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 ## 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`. 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,9 +19,14 @@ 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. When the Medusa application starts, these providers are registered and can be used to retrieve tax lines.
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
tax: {
module.exports = defineConfig({
// ...
modules: {
[Modules.TAX]: {
resolve: "@medusajs/tax", resolve: "@medusajs/tax",
options: { options: {
providers: [ providers: [
@@ -35,9 +40,10 @@ const modules = {
}, },
}, },
} }
})
``` ```
The objects in the array accept the following properties: 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. - `options`: An object of options to pass to the tax provider.
@@ -78,21 +78,6 @@ const taxLines = await taxModuleService.getTaxLines(
## Configure Tax Module ## 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. 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 ## Module Options
```js title="medusa-config.js" ```js title="medusa-config.js"
const modules = { const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
user: {
module.exports = defineConfig({
// ...
modules: {
[Modules.USER]: {
resolve: "@medusajs/user", resolve: "@medusajs/user",
options: { options: {
jwt_secret: process.env.JWT_SECRET, jwt_secret: process.env.JWT_SECRET,
}, },
}, },
} }
})
``` ```
<Table> <Table>
@@ -39,26 +39,6 @@ await userModuleService.refreshInviteTokens([invite.id])
## Configure User Module ## 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. Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
--- ---
@@ -4,18 +4,16 @@ You might see a log in your browser console, that looks like this:
![CORS error log](https://res.cloudinary.com/dza7lstvk/image/upload/v1668003322/Medusa%20Docs/Other/jnHK115_udgf2n.png) ![CORS error log](https://res.cloudinary.com/dza7lstvk/image/upload/v1668003322/Medusa%20Docs/Other/jnHK115_udgf2n.png)
In your `medusa-config.js` , you should ensure that you've configured your CORS settings correctly. By default, the Medusa starter runs on port `9000`, Medusa Admin runs on port `7001`, and the storefront starters run on port `8000`. In your `medusa-config.js` , you should ensure that you've configured your CORS settings correctly:
The default configuration uses the following CORS settings:
```js title="medusa-config.js" ```js title="medusa-config.js"
// CORS when consuming Medusa from admin module.exports = defineConfig({
const ADMIN_CORS = process.env.ADMIN_CORS || projectConfig: {
"http://localhost:7000,http://localhost:7001" http: {
storeCors: process.env.STORE_CORS,
// CORS to avoid issues when consuming Medusa from a client adminCors: process.env.ADMIN_CORS,
const STORE_CORS = }
process.env.STORE_CORS || "http://localhost:8000" // ...
}
})
``` ```
If you wish to run your storefront or Medusa Admin on other ports, you should update the above settings accordingly.
@@ -55,14 +55,15 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
const modules = { module.exports = defineConfig({
// ... // ...
modules: {
[Modules.AUTH]: { [Modules.AUTH]: {
resolve: "@medusajs/auth", resolve: "@medusajs/auth",
options: { options: {
providers: [ providers: [
{ {
resolve: "./dist/modules/my-auth", resolve: "./modules/my-auth",
options: { options: {
config: { config: {
"my-auth": { "my-auth": {
@@ -75,6 +76,7 @@ const modules = {
}, },
}, },
} }
})
\`\`\` \`\`\`
`, `,
], ],
@@ -61,14 +61,15 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
const modules = { module.exports = defineConfig({
// ... // ...
modules: {
[Modules.FILE]: { [Modules.FILE]: {
resolve: "@medusajs/file", resolve: "@medusajs/file",
options: { options: {
providers: [ providers: [
{ {
resolve: "./dist/modules/my-file", resolve: "./modules/my-file",
options: { options: {
config: { config: {
"my-file": { "my-file": {
@@ -81,6 +82,7 @@ const modules = {
}, },
}, },
} }
})
\`\`\` \`\`\`
`, `,
], ],
@@ -55,8 +55,9 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
const modules = { module.exports = defineConfig({
// ... // ...
modules: {
[Modules.FULFILLMENT]: { [Modules.FULFILLMENT]: {
resolve: "@medusajs/fulfillment", resolve: "@medusajs/fulfillment",
options: { options: {
@@ -75,6 +76,7 @@ const modules = {
}, },
}, },
} }
})
\`\`\` \`\`\`
`, `,
], ],
@@ -70,8 +70,9 @@ const { Modules } = require("@medusajs/modules-sdk")
// ... // ...
const modules = { module.exports = defineConfig({
// ... // ...
modules: {
[Modules.NOTIFICATION]: { [Modules.NOTIFICATION]: {
resolve: "@medusajs/notification", resolve: "@medusajs/notification",
options: { options: {
@@ -91,6 +92,7 @@ const modules = {
}, },
}, },
} }
})
\`\`\` \`\`\`
`, `,
], ],