From fe96bd39b1f82c1a07c48f69f856a18acdd06a11 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 30 May 2024 16:47:28 +0300 Subject: [PATCH] docs: change config snippets to use defineConfig (#7546) --- .../core/types/src/common/config-module.ts | 251 ++++++++---------- .../api-routes/cors/page.mdx | 11 +- .../modules/module-relationships/page.mdx | 20 +- .../modules/options/page.mdx | 19 +- .../app/basics/modules-and-services/page.mdx | 16 +- .../book/app/basics/scheduled-jobs/page.mdx | 11 +- .../feature-flags/page.mdx | 6 +- .../app/storefront-development/tips/page.mdx | 6 +- .../cache/create/page.mdx | 24 +- .../cache/in-memory/page.mdx | 13 +- .../cache/redis/page.mdx | 9 +- .../event/create/page.mdx | 22 +- .../event/local/page.mdx | 13 +- .../event/redis/page.mdx | 9 +- .../architectural-modules/file/local/page.mdx | 11 +- .../architectural-modules/file/s3/page.mdx | 4 + .../notification/local/page.mdx | 17 +- .../notification/page.mdx | 6 +- .../notification/sendgrid/page.mdx | 11 +- .../workflow-engine/in-memory/page.mdx | 13 +- .../workflow-engine/redis/page.mdx | 9 +- .../app/commerce-modules/api-key/page.mdx | 17 -- .../auth/auth-providers/page.mdx | 4 +- .../auth/module-options/page.mdx | 58 ++-- .../app/commerce-modules/auth/page.mdx | 17 +- .../app/commerce-modules/cart/page.mdx | 17 -- .../app/commerce-modules/currency/page.mdx | 17 -- .../app/commerce-modules/customer/page.mdx | 17 -- .../fulfillment/module-options/page.mdx | 40 +-- .../app/commerce-modules/fulfillment/page.mdx | 18 -- .../app/commerce-modules/inventory/page.mdx | 17 -- .../app/commerce-modules/order/page.mdx | 17 -- .../payment/module-options/page.mdx | 43 +-- .../app/commerce-modules/payment/page.mdx | 20 -- .../payment/payment-provider/stripe/page.mdx | 44 +-- .../app/commerce-modules/pricing/page.mdx | 17 -- .../app/commerce-modules/product/page.mdx | 17 -- .../app/commerce-modules/promotion/page.mdx | 17 -- .../app/commerce-modules/region/page.mdx | 17 -- .../commerce-modules/sales-channel/page.mdx | 17 -- .../commerce-modules/stock-location/page.mdx | 17 -- .../app/commerce-modules/store/page.mdx | 17 -- .../tax/module-options/page.mdx | 34 ++- .../app/commerce-modules/tax/page.mdx | 15 -- .../user/module-options/page.mdx | 20 +- .../app/commerce-modules/user/page.mdx | 20 -- .../_sections/other/cors-errors.mdx | 22 +- .../merger-custom-options/auth-provider.ts | 32 +-- .../constants/merger-custom-options/file.ts | 32 +-- .../fulfillment-provider.ts | 32 +-- .../merger-custom-options/notification.ts | 34 +-- 51 files changed, 489 insertions(+), 718 deletions(-) diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index e672be344c..3d5462fa4f 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -125,14 +125,14 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * databaseName: process.env.DATABASE_DATABASE || + * databaseName: process.env.DATABASE_NAME || * "medusa-store", * // ... * }, * // ... - * } + * }) * ``` */ databaseName?: string @@ -164,13 +164,13 @@ export type ProjectConfigOptions = { * Then, use the value in `medusa-config.js`: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * databaseUrl: process.env.DATABASE_URL, * // ... * }, * // ... - * } + * }) * ``` */ 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`. * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * databaseSchema: process.env.DATABASE_SCHEMA || * "custom", * // ... * }, * // ... - * } + * }) * ``` */ databaseSchema?: string @@ -202,15 +202,13 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * databaseLogging: [ - * "query", "error", - * ], + * databaseLogging: ["query", "error"] * // ... * }, * // ... - * } + * }) * ``` */ databaseLogging?: LoggerOptions @@ -233,16 +231,14 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * databaseExtra: - * process.env.NODE_ENV !== "development" - * ? { ssl: { rejectUnauthorized: false } } - * : {}, + * databaseExtra: process.env.NODE_ENV !== "development" ? + * { ssl: { rejectUnauthorized: false } } : {} * // ... * }, * // ... - * } + * }) * ``` */ databaseExtra?: Record & { @@ -266,16 +262,14 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * databaseDriverOptions: - * process.env.NODE_ENV !== "development" - * ? { connection: { ssl: { rejectUnauthorized: false } } } - * : {}, + * databaseDriverOptions: process.env.NODE_ENV !== "development" ? + * { ssl: { rejectUnauthorized: false } } : {} * // ... * }, * // ... - * } + * }) * ``` */ databaseDriverOptions?: Record & { @@ -311,14 +305,14 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * redisUrl: process.env.REDIS_URL || + * redisUrl: process.env.REDIS_URL || * "redis://localhost:6379", * // ... * }, * // ... - * } + * }) * ``` */ redisUrl?: string @@ -330,14 +324,13 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { - * redisPrefix: process.env.REDIS_PREFIX || - * "medusa:", + * redisPrefix: process.env.REDIS_URL || "medusa:", * // ... * }, * // ... - * } + * }) * ``` */ redisPrefix?: string @@ -348,16 +341,16 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * redisOptions: { - * connectionName: process.env.REDIS_CONNECTION_NAME || + * connectionName: process.env.REDIS_CONNECTION_NAME || * "medusa", - * }, + * } * // ... * }, * // ... - * } + * }) * ``` */ redisOptions?: RedisOptions @@ -367,16 +360,15 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * sessionOptions: { - * name: process.env.SESSION_NAME || - * "custom", - * }, + * name: process.env.SESSION_NAME || "custom", + * } * // ... * }, * // ... - * } + * }) * ``` */ 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`. * - * @example - * ```js title="medusa-config.js" - * module.exports = { - * projectConfig: { - * httpCompression: { - * enabled: true, - * level: 6, - * memLevel: 8, - * threshold: 1024, - * }, - * // ... - * }, - * // ... - * } - * ``` + * @ignore * * @deprecated use {@link http }'s `compression` property instead. * @@ -413,13 +391,13 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * jobsBatchSize: 100 * // ... * }, * // ... - * } + * }) * ``` */ jobsBatchSize?: number @@ -435,13 +413,13 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * workerMode: "shared" * // ... * }, * // ... - * } + * }) * ``` */ workerMode?: "shared" | "worker" | "server" @@ -451,16 +429,18 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { - * cookieSecret: "some-super-secret", - * compression: { ... }, + * cookieSecret: "supersecret", + * compression: { + * // ... + * } * } * // ... * }, * // ... - * } + * }) * ``` */ http: { @@ -472,14 +452,15 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { - * cookieSecret: "supersecret" + * jwtSecret: "supersecret", * } + * // ... * }, * // ... - * } + * }) * ``` */ jwtSecret?: string @@ -488,14 +469,15 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * jwtExpiresIn: "2d" * } + * // ... * }, * // ... - * } + * }) * ``` */ jwtExpiresIn?: string @@ -507,15 +489,15 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { - * cookieSecret: "supersecret" + * cookieSecret: "supersecret" * } * // ... * }, * // ... - * } + * }) * ``` */ cookieSecret?: string @@ -546,7 +528,7 @@ export type ProjectConfigOptions = { * Then, set the configuration in `medusa-config.js`: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * 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: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * authCors: "/http:\\/\\/localhost:700\\d+$/", @@ -568,7 +550,7 @@ export type ProjectConfigOptions = { * // ... * }, * // ... - * } + * }) * ``` */ authCors: string @@ -583,20 +565,20 @@ export type ProjectConfigOptions = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * compression: { * enabled: true, * level: 6, * memLevel: 8, - * threshold: 1024, + * threshold: 1024 * } - * }, + * } * // ... * }, * // ... - * } + * }) * ``` */ compression?: HttpCompressionOptions @@ -627,7 +609,7 @@ export type ProjectConfigOptions = { * Then, set the configuration in `medusa-config.js`: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * 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: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * storeCors: "/vercel\\.app$/", @@ -649,7 +631,7 @@ export type ProjectConfigOptions = { * // ... * }, * // ... - * } + * }) * ``` */ storeCors: string @@ -681,7 +663,7 @@ export type ProjectConfigOptions = { * Then, set the configuration in `medusa-config.js`: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * 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: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { - * adminCors: process.env.ADMIN_CORS, + * adminCors: "/vercel\\.app$/", * } * // ... * }, * // ... - * } + * }) * ``` */ adminCors: string @@ -721,18 +703,18 @@ export type ProjectConfigOptions = { * Then, set the configuration in `medusa-config.js`: * * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * projectConfig: { * http: { * authMethodsPerActor: { - * user: ['sso'], - * customer: ["emailpass", "google"] - * }, - * }, + * user: ["email"], + * customer: ["emailpas", "google"] + * } + * } * // ... * }, * // ... - * } + * }) * ``` */ authMethodsPerActor?: Record @@ -755,12 +737,20 @@ export type ProjectConfigOptions = { * For example: * * ```js title="medusa-config.js" - * module.exports = { - * projectConfig, - * admin, - * modules, - * featureFlags, - * } + * module.exports = defineConfig({ + * projectConfig: { + * // ... + * }, + * admin: { + * // ... + * }, + * modules: { + * // ... + * }, + * featureFlags: { + * // ... + * } + * }) * ``` * * --- @@ -785,12 +775,13 @@ export type ConfigModule = { * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * admin: { - * backendUrl: process.env.MEDUSA_BACKEND_URL || "http://localhost:9000" - * } + * backendUrl: process.env.MEDUSA_BACKEND_URL || + * "http://localhost:9000" + * }, * // ... - * } + * }) * ``` */ 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: ( | { @@ -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`. * - * 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; - * 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; - * 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 name of 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. `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. + * 1. A boolean value indicating whether the module type is enabled. This is only supported for Medusa's commerce and architectural modules; + * 2. Or an object having the following properties: + * 1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name. + * 2. `options`: (optional) an object indicating the options to pass to the module. + * 3. `definition`: (optional) an object of extra configurations, such as `isQueryable` used when a module has relationships. * * @example * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * modules: { - * eventBus: { - * resolve: "@medusajs/event-bus-local", - * }, - * cacheService: { - * resolve: "@medusajs/cache-redis", - * options: { - * redisUrl: process.env.CACHE_REDIS_URL, - * ttl: 30, - * }, - * }, - * // ... - * }, + * helloModuleService: { + * resolve: "./modules/hello" + * } + * } * // ... - * } + * }) * ``` */ 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 * 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. * - * 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 * ```js title="medusa-config.js" - * module.exports = { + * module.exports = defineConfig({ * featureFlags: { * product_categories: true, * // ... - * }, + * } * // ... - * } + * }) * ``` * * :::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. * * ::: */ diff --git a/www/apps/book/app/advanced-development/api-routes/cors/page.mdx b/www/apps/book/app/advanced-development/api-routes/cors/page.mdx index c396a1e866..2e3f78fbe2 100644 --- a/www/apps/book/app/advanced-development/api-routes/cors/page.mdx +++ b/www/apps/book/app/advanced-development/api-routes/cors/page.mdx @@ -17,16 +17,15 @@ You configure allowed origins for Store and Admin API Routes using the `storeCor For example: ```js title="medusa-config.js" -module.exports = { +module.exports = defineConfig({ projectConfig: { http: { - adminCors: "http://localhost:7001", 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. diff --git a/www/apps/book/app/advanced-development/modules/module-relationships/page.mdx b/www/apps/book/app/advanced-development/modules/module-relationships/page.mdx index ee292bb56d..81e60699ea 100644 --- a/www/apps/book/app/advanced-development/modules/module-relationships/page.mdx +++ b/www/apps/book/app/advanced-development/modules/module-relationships/page.mdx @@ -209,22 +209,24 @@ This creates a relationship to the `Product` data model of the Product Module us ### 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 = [ ["7", "isQueryable", "Enable this property to use relationships in a module."] ] ```js title="medusa-config.js" highlights={configHighlights} -const modules = { - helloModuleService: { - // ... - definition: { - isQueryable: true, - }, - }, +module.exports = defineConfig({ // ... -} + modules: { + helloModuleService: { + // ... + definition: { + isQueryable: true + } + } + } +}) ``` Enabling the `isQueryable` property is required to use relationships in a module. diff --git a/www/apps/book/app/advanced-development/modules/options/page.mdx b/www/apps/book/app/advanced-development/modules/options/page.mdx index 80bc9bea57..696c858732 100644 --- a/www/apps/book/app/advanced-development/modules/options/page.mdx +++ b/www/apps/book/app/advanced-development/modules/options/page.mdx @@ -23,15 +23,18 @@ To pass options to a module, add an `options` property to the module’s configu For example: ```js title="medusa-config.js" -const modules = { - helloModuleService: { - resolve: "./dist/modules/hello", - options: { - capitalize: true, - }, - }, +module.exports = defineConfig({ // ... -} + modules: { + helloModuleService: { + resolve: "./modules/hello", + options: { + capitalize: true, + }, + } + } +}) + ``` The `options` property’s value is an object. You can pass any properties you want. diff --git a/www/apps/book/app/basics/modules-and-services/page.mdx b/www/apps/book/app/basics/modules-and-services/page.mdx index a7bd6548ae..bb314dd414 100644 --- a/www/apps/book/app/basics/modules-and-services/page.mdx +++ b/www/apps/book/app/basics/modules-and-services/page.mdx @@ -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: -```js title="medusa-config.js" highlights={[["2", "helloModuleService", "The key of the main service to be registered in the Medusa container."]]} -const modules = { - helloModuleService: { - resolve: "./dist/modules/hello", - }, - // other modules... -} +```js title="medusa-config.js" highlights={[["4", "helloModuleService", "The key of the main service to be registered in the Medusa container."]]} +module.exports = defineConfig({ + // ... + modules: { + helloModuleService: { + resolve: "./modules/hello", + } + } +}) ``` Its key (`helloModuleService`) is the name of the module’s main service. It will be registered in the Medusa container with that name. diff --git a/www/apps/book/app/basics/scheduled-jobs/page.mdx b/www/apps/book/app/basics/scheduled-jobs/page.mdx index 0e8cbad00e..da60baf1cf 100644 --- a/www/apps/book/app/basics/scheduled-jobs/page.mdx +++ b/www/apps/book/app/basics/scheduled-jobs/page.mdx @@ -64,11 +64,12 @@ To test out your scheduled job: 1. Uncomment the following line in the `medusa-config.js` file: ```js title="medusa-config.js" -const projectConfig = { - // ... - // Uncomment the following lines to enable REDIS - redisUrl: REDIS_URL, -} +module.exports = defineConfig({ + projectConfig: { + redisUrl: REDIS_URL + // ... + } +}) ``` 2. Start the Medusa application: diff --git a/www/apps/book/app/debugging-and-testing/feature-flags/page.mdx b/www/apps/book/app/debugging-and-testing/feature-flags/page.mdx index d912da5fce..a627f3bc96 100644 --- a/www/apps/book/app/debugging-and-testing/feature-flags/page.mdx +++ b/www/apps/book/app/debugging-and-testing/feature-flags/page.mdx @@ -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. -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: ```js title="medusa-config.js" -module.exports = { +module.exports = defineConfig({ featureFlags: { tax_inclusive_pricing: true, }, // ... -} +}) ``` diff --git a/www/apps/book/app/storefront-development/tips/page.mdx b/www/apps/book/app/storefront-development/tips/page.mdx index 265665b51e..d0f4db804d 100644 --- a/www/apps/book/app/storefront-development/tips/page.mdx +++ b/www/apps/book/app/storefront-development/tips/page.mdx @@ -29,15 +29,15 @@ The Medusa application’s API routes are guarded by a CORS middleware. Make sur For example: ```js title="medusa-config.js" -module.exports = { +module.exports = defineConfig({ projectConfig: { http: { storeCors: "http://localhost:3000", // ... } - }, + } // ... -} +}) ``` --- diff --git a/www/apps/resources/app/architectural-modules/cache/create/page.mdx b/www/apps/resources/app/architectural-modules/cache/create/page.mdx index 6d93374015..7c8dd45941 100644 --- a/www/apps/resources/app/architectural-modules/cache/create/page.mdx +++ b/www/apps/resources/app/architectural-modules/cache/create/page.mdx @@ -152,14 +152,20 @@ To use your Cache Module, add it to the `modules` object exported as part of the For example: ```js title="medusa-config.js" -const modules = { - // other modules... - cacheService: { - resolve: "./dist/modules/my-cache/index.ts", - options: { - // any necessary options - ttl: 30, +const { Modules } = require("@medusajs/modules-sdk") + +// ... + +module.exports = defineConfig({ + // ... + modules: { + [Modules.CACHE]: { + resolve: "./modules/my-cache", + options: { + // any options + ttl: 30, + }, }, - }, -} + } +}) ``` diff --git a/www/apps/resources/app/architectural-modules/cache/in-memory/page.mdx b/www/apps/resources/app/architectural-modules/cache/in-memory/page.mdx index d891a038a7..db718e8670 100644 --- a/www/apps/resources/app/architectural-modules/cache/in-memory/page.mdx +++ b/www/apps/resources/app/architectural-modules/cache/in-memory/page.mdx @@ -16,6 +16,12 @@ For production, it’s recommended to use modules like [Redis Cache Module](../r ## Install the In-Memory Cache Module + + +The In-Memory Cache Module is installed by default in your application. + + + To install the In-Memory Cache Module, run the following command in the directory of your Medusa application: ```bash npm2yarn @@ -29,18 +35,17 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.CACHE]: { resolve: "@medusajs/cache-inmemory", options: { // optional options }, }, - }, -} + } +}) ``` ### In-Memory Cache Module Options diff --git a/www/apps/resources/app/architectural-modules/cache/redis/page.mdx b/www/apps/resources/app/architectural-modules/cache/redis/page.mdx index e94c01c71e..ae4bf11480 100644 --- a/www/apps/resources/app/architectural-modules/cache/redis/page.mdx +++ b/www/apps/resources/app/architectural-modules/cache/redis/page.mdx @@ -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`: export const highlights = [ - ["12", "redisUrl", "The Redis connection URL."] + ["11", "redisUrl", "The Redis connection URL."] ] ```js title="medusa-config.js" highlights={highlights} @@ -35,18 +35,17 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.CACHE]: { resolve: "@medusajs/cache-redis", options: { redisUrl: process.env.CACHE_REDIS_URL, }, }, - }, -} + } +}) ``` ### Environment Variables diff --git a/www/apps/resources/app/architectural-modules/event/create/page.mdx b/www/apps/resources/app/architectural-modules/event/create/page.mdx index 69035ac78c..841b086ee2 100644 --- a/www/apps/resources/app/architectural-modules/event/create/page.mdx +++ b/www/apps/resources/app/architectural-modules/event/create/page.mdx @@ -107,13 +107,19 @@ To use your Event Module, add it to the `modules` object exported as part of the For example: ```js title="medusa-config.js" -const modules = { - // other modules... - eventBus: { - resolve: "./dist/modules/my-event/index.ts", - options: { - // any necessary options +const { Modules } = require("@medusajs/modules-sdk") + +// ... + +module.exports = defineConfig({ + // ... + modules: { + [Modules.EVENT_BUS]: { + resolve: "./modules/my-event", + options: { + // any options + }, }, - }, -} + } +}) ``` diff --git a/www/apps/resources/app/architectural-modules/event/local/page.mdx b/www/apps/resources/app/architectural-modules/event/local/page.mdx index 90a8e94d64..292f0758dd 100644 --- a/www/apps/resources/app/architectural-modules/event/local/page.mdx +++ b/www/apps/resources/app/architectural-modules/event/local/page.mdx @@ -14,6 +14,12 @@ For production, it’s recommended to use modules like [Redis Event Bus Module]( ## Install the Local Event Bus Module + + +The Local Event Bus Module is installed by default in your application. + + + To install Local Event Bus Module, run the following command in the directory of your Medusa application: ```bash npm2yarn @@ -27,13 +33,12 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.EVENT_BUS]: true, - }, -} + } +}) ``` --- diff --git a/www/apps/resources/app/architectural-modules/event/redis/page.mdx b/www/apps/resources/app/architectural-modules/event/redis/page.mdx index 40157564ca..934b0e710b 100644 --- a/www/apps/resources/app/architectural-modules/event/redis/page.mdx +++ b/www/apps/resources/app/architectural-modules/event/redis/page.mdx @@ -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`: export const highlights = [ - ["8", "redisUrl", "The Redis connection URL."] + ["11", "redisUrl", "The Redis connection URL."] ] ```js title="medusa-config.js" @@ -39,18 +39,17 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.EVENT_BUS]: { resolve: "@medusajs/event-redis", options: { redisUrl: process.env.EVENTS_REDIS_URL, }, }, - }, -} + } +}) ``` ### Environment Variables diff --git a/www/apps/resources/app/architectural-modules/file/local/page.mdx b/www/apps/resources/app/architectural-modules/file/local/page.mdx index 37b344a1b8..71b979bfe6 100644 --- a/www/apps/resources/app/architectural-modules/file/local/page.mdx +++ b/www/apps/resources/app/architectural-modules/file/local/page.mdx @@ -12,6 +12,12 @@ The Local File Provider Module stores files uploaded to your Medusa application ## Install the Local File Module + + +The Local File Module is installed by default in your application. + + + To install the Local File Provider Module, run the following command in the directory of your Medusa application: ```bash npm2yarn @@ -27,10 +33,13 @@ The File Module accepts one provider only. ```js title="medusa-config.js" +const { Modules } = require("@medusajs/modules-sdk") + +// ... + module.exports = { // ... modules: { - // ... [Modules.FILE]: { resolve: "@medusajs/file", options: { diff --git a/www/apps/resources/app/architectural-modules/file/s3/page.mdx b/www/apps/resources/app/architectural-modules/file/s3/page.mdx index 611db727d1..1291c51732 100644 --- a/www/apps/resources/app/architectural-modules/file/s3/page.mdx +++ b/www/apps/resources/app/architectural-modules/file/s3/page.mdx @@ -85,6 +85,10 @@ The File Module accepts one provider only. ```js title="medusa-config.js" +const { Modules } = require("@medusajs/modules-sdk") + +// ... + module.exports = { // ... modules: { diff --git a/www/apps/resources/app/architectural-modules/notification/local/page.mdx b/www/apps/resources/app/architectural-modules/notification/local/page.mdx index f3260f3876..7380ffe8e4 100644 --- a/www/apps/resources/app/architectural-modules/notification/local/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/local/page.mdx @@ -12,6 +12,12 @@ The Local Notification Provider Module simulates sending a notification, but onl ## Install the Local Notification Module + + +The Local Notification Provider Module is installed by default in your application. + + + To install the Local Notification Provider Module, run the following command in the directory of your Medusa application: ```bash npm2yarn @@ -27,10 +33,13 @@ Only one provider can be defined for a channel. ```js title="medusa-config.js" -module.exports = { +const { Modules } = require("@medusajs/modules-sdk") + +// ... + +module.exports = defineConfig({ // ... modules: { - // ... [Modules.NOTIFICATION]: { resolve: "@medusajs/notification", options: { @@ -49,8 +58,8 @@ module.exports = { ], }, }, - }, -} + } +}) ``` ### Local Notification Module Options diff --git a/www/apps/resources/app/architectural-modules/notification/page.mdx b/www/apps/resources/app/architectural-modules/notification/page.mdx index ac6f5f8d37..a560d935b0 100644 --- a/www/apps/resources/app/architectural-modules/notification/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/page.mdx @@ -30,7 +30,11 @@ When you send a notification, you specify the channel to send it through, such a For example: -```js title="medusa-config.js" highlights={[["15"]]} +```js title="medusa-config.js" highlights={[["19"]]} +const { Modules } = require("@medusajs/modules-sdk") + +// ... + module.exports = { // ... modules: { diff --git a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx index 9f0f06feb9..75953065ab 100644 --- a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx @@ -35,10 +35,13 @@ Only one provider can be defined for a channel. ```js title="medusa-config.js" -module.exports = { +const { Modules } = require("@medusajs/modules-sdk") + +// ... + +module.exports = defineConfig({ // ... modules: { - // ... [Modules.NOTIFICATION]: { resolve: "@medusajs/notification", options: { @@ -59,8 +62,8 @@ module.exports = { ], }, }, - }, -} + } +}) ``` ### Environment Variables diff --git a/www/apps/resources/app/architectural-modules/workflow-engine/in-memory/page.mdx b/www/apps/resources/app/architectural-modules/workflow-engine/in-memory/page.mdx index 0ab6da7ae6..f461d294ea 100644 --- a/www/apps/resources/app/architectural-modules/workflow-engine/in-memory/page.mdx +++ b/www/apps/resources/app/architectural-modules/workflow-engine/in-memory/page.mdx @@ -16,6 +16,12 @@ For production, it’s recommended to use modules like [Redis Workflow Engine Mo ## Install the In-Memory Workflow Engine Module + + +The In-Memory Workflow Engine Module is installed by default in your application. + + + To install the In-Memory Workflow Engine Module, run the following command in the directory of your Medusa application: ```bash npm2yarn @@ -29,11 +35,10 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.WORKFLOW_ENGINE]: true, - }, -} + } +}) ``` diff --git a/www/apps/resources/app/architectural-modules/workflow-engine/redis/page.mdx b/www/apps/resources/app/architectural-modules/workflow-engine/redis/page.mdx index cc5fa4c923..f7d5e69ac2 100644 --- a/www/apps/resources/app/architectural-modules/workflow-engine/redis/page.mdx +++ b/www/apps/resources/app/architectural-modules/workflow-engine/redis/page.mdx @@ -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`: export const highlights = [ - ["8", "redisUrl", "The Redis connection URL."] + ["12", "url", "The Redis connection URL."] ] ```js title="medusa-config.js" highlights={highlights} @@ -35,10 +35,9 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -module.exports = { +module.exports = defineConfig({ // ... modules: { - // ... [Modules.WORKFLOW_ENGINE]: { resolve: "@medusajs/workflow-engine-redis", options: { @@ -47,8 +46,8 @@ module.exports = { }, }, }, - }, -} + } +}) ``` ### Environment Variables diff --git a/www/apps/resources/app/commerce-modules/api-key/page.mdx b/www/apps/resources/app/commerce-modules/api-key/page.mdx index 27c475c1cb..5e2b065a7d 100644 --- a/www/apps/resources/app/commerce-modules/api-key/page.mdx +++ b/www/apps/resources/app/commerce-modules/api-key/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/auth/auth-providers/page.mdx b/www/apps/resources/app/commerce-modules/auth/auth-providers/page.mdx index 3eb66e61a5..920c738b30 100644 --- a/www/apps/resources/app/commerce-modules/auth/auth-providers/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/auth-providers/page.mdx @@ -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 = { }, // ... } -} +}) ``` --- diff --git a/www/apps/resources/app/commerce-modules/auth/module-options/page.mdx b/www/apps/resources/app/commerce-modules/auth/module-options/page.mdx index bc7277ca21..8bf7cf033e 100644 --- a/www/apps/resources/app/commerce-modules/auth/module-options/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/module-options/page.mdx @@ -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. diff --git a/www/apps/resources/app/commerce-modules/auth/page.mdx b/www/apps/resources/app/commerce-modules/auth/page.mdx index fb1f964be0..8905afdf80 100644 --- a/www/apps/resources/app/commerce-modules/auth/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/page.mdx @@ -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. --- diff --git a/www/apps/resources/app/commerce-modules/cart/page.mdx b/www/apps/resources/app/commerce-modules/cart/page.mdx index 8cca98325c..2828124707 100644 --- a/www/apps/resources/app/commerce-modules/cart/page.mdx +++ b/www/apps/resources/app/commerce-modules/cart/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/currency/page.mdx b/www/apps/resources/app/commerce-modules/currency/page.mdx index 7c104dde5e..f587673a63 100644 --- a/www/apps/resources/app/commerce-modules/currency/page.mdx +++ b/www/apps/resources/app/commerce-modules/currency/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/customer/page.mdx b/www/apps/resources/app/commerce-modules/customer/page.mdx index e5ac249245..09c72ca297 100644 --- a/www/apps/resources/app/commerce-modules/customer/page.mdx +++ b/www/apps/resources/app/commerce-modules/customer/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/fulfillment/module-options/page.mdx b/www/apps/resources/app/commerce-modules/fulfillment/module-options/page.mdx index 77a1b9c252..e8fbdf0cfb 100644 --- a/www/apps/resources/app/commerce-modules/fulfillment/module-options/page.mdx +++ b/www/apps/resources/app/commerce-modules/fulfillment/module-options/page.mdx @@ -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. \ No newline at end of file diff --git a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx index 8116323650..89cb3f818c 100644 --- a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx +++ b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx @@ -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. --- diff --git a/www/apps/resources/app/commerce-modules/inventory/page.mdx b/www/apps/resources/app/commerce-modules/inventory/page.mdx index f4cd809183..3753a64e92 100644 --- a/www/apps/resources/app/commerce-modules/inventory/page.mdx +++ b/www/apps/resources/app/commerce-modules/inventory/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/order/page.mdx b/www/apps/resources/app/commerce-modules/order/page.mdx index 0bf8243248..aa18e06e92 100644 --- a/www/apps/resources/app/commerce-modules/order/page.mdx +++ b/www/apps/resources/app/commerce-modules/order/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/payment/module-options/page.mdx b/www/apps/resources/app/commerce-modules/payment/module-options/page.mdx index 3af778bace..c47234c301 100644 --- a/www/apps/resources/app/commerce-modules/payment/module-options/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/module-options/page.mdx @@ -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. \ No newline at end of file diff --git a/www/apps/resources/app/commerce-modules/payment/page.mdx b/www/apps/resources/app/commerce-modules/payment/page.mdx index 14be444c90..375969b385 100644 --- a/www/apps/resources/app/commerce-modules/payment/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/page.mdx @@ -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. --- diff --git a/www/apps/resources/app/commerce-modules/payment/payment-provider/stripe/page.mdx b/www/apps/resources/app/commerce-modules/payment/payment-provider/stripe/page.mdx index ebba6e499a..a4a01aaba9 100644 --- a/www/apps/resources/app/commerce-modules/payment/payment-provider/stripe/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/payment-provider/stripe/page.mdx @@ -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 diff --git a/www/apps/resources/app/commerce-modules/pricing/page.mdx b/www/apps/resources/app/commerce-modules/pricing/page.mdx index 2db768a646..11be06808f 100644 --- a/www/apps/resources/app/commerce-modules/pricing/page.mdx +++ b/www/apps/resources/app/commerce-modules/pricing/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/product/page.mdx b/www/apps/resources/app/commerce-modules/product/page.mdx index 7afc2d2f3b..0db257bb24 100644 --- a/www/apps/resources/app/commerce-modules/product/page.mdx +++ b/www/apps/resources/app/commerce-modules/product/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/promotion/page.mdx b/www/apps/resources/app/commerce-modules/promotion/page.mdx index 9355c01173..a8425c3d58 100644 --- a/www/apps/resources/app/commerce-modules/promotion/page.mdx +++ b/www/apps/resources/app/commerce-modules/promotion/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/region/page.mdx b/www/apps/resources/app/commerce-modules/region/page.mdx index 9b9550b539..ba40fa109c 100644 --- a/www/apps/resources/app/commerce-modules/region/page.mdx +++ b/www/apps/resources/app/commerce-modules/region/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx index 854c795d61..50f213ae1f 100644 --- a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx +++ b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/stock-location/page.mdx b/www/apps/resources/app/commerce-modules/stock-location/page.mdx index 3e250db814..12bcaff6c0 100644 --- a/www/apps/resources/app/commerce-modules/stock-location/page.mdx +++ b/www/apps/resources/app/commerce-modules/stock-location/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/store/page.mdx b/www/apps/resources/app/commerce-modules/store/page.mdx index 9ce75f1775..ab34694342 100644 --- a/www/apps/resources/app/commerce-modules/store/page.mdx +++ b/www/apps/resources/app/commerce-modules/store/page.mdx @@ -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`. diff --git a/www/apps/resources/app/commerce-modules/tax/module-options/page.mdx b/www/apps/resources/app/commerce-modules/tax/module-options/page.mdx index 3f26b838ae..83ee05a1d1 100644 --- a/www/apps/resources/app/commerce-modules/tax/module-options/page.mdx +++ b/www/apps/resources/app/commerce-modules/tax/module-options/page.mdx @@ -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. diff --git a/www/apps/resources/app/commerce-modules/tax/page.mdx b/www/apps/resources/app/commerce-modules/tax/page.mdx index 0389ba6774..3ec1aec2df 100644 --- a/www/apps/resources/app/commerce-modules/tax/page.mdx +++ b/www/apps/resources/app/commerce-modules/tax/page.mdx @@ -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. --- diff --git a/www/apps/resources/app/commerce-modules/user/module-options/page.mdx b/www/apps/resources/app/commerce-modules/user/module-options/page.mdx index 1188abc7c2..815426ade0 100644 --- a/www/apps/resources/app/commerce-modules/user/module-options/page.mdx +++ b/www/apps/resources/app/commerce-modules/user/module-options/page.mdx @@ -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, + }, }, - }, -} + } +}) ``` diff --git a/www/apps/resources/app/commerce-modules/user/page.mdx b/www/apps/resources/app/commerce-modules/user/page.mdx index 3af35e3af1..d1f9a09925 100644 --- a/www/apps/resources/app/commerce-modules/user/page.mdx +++ b/www/apps/resources/app/commerce-modules/user/page.mdx @@ -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. --- diff --git a/www/apps/resources/app/troubleshooting/_sections/other/cors-errors.mdx b/www/apps/resources/app/troubleshooting/_sections/other/cors-errors.mdx index 8420fd3a8a..5b3d5d0075 100644 --- a/www/apps/resources/app/troubleshooting/_sections/other/cors-errors.mdx +++ b/www/apps/resources/app/troubleshooting/_sections/other/cors-errors.mdx @@ -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) -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`. - -The default configuration uses the following CORS settings: +In your `medusa-config.js` , you should ensure that you've configured your CORS settings correctly: ```js title="medusa-config.js" -// CORS when consuming Medusa from admin -const ADMIN_CORS = process.env.ADMIN_CORS || - "http://localhost:7000,http://localhost:7001" - -// CORS to avoid issues when consuming Medusa from a client -const STORE_CORS = - process.env.STORE_CORS || "http://localhost:8000" +module.exports = defineConfig({ + projectConfig: { + http: { + storeCors: process.env.STORE_CORS, + adminCors: process.env.ADMIN_CORS, + } + // ... + } +}) ``` - -If you wish to run your storefront or Medusa Admin on other ports, you should update the above settings accordingly. diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/auth-provider.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/auth-provider.ts index 9afbb2775b..01b1be8b1c 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/auth-provider.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/auth-provider.ts @@ -55,26 +55,28 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -const modules = { +module.exports = defineConfig({ // ... - [Modules.AUTH]: { - resolve: "@medusajs/auth", - options: { - providers: [ - { - resolve: "./dist/modules/my-auth", - options: { - config: { - "my-auth": { - // provider options... + modules: { + [Modules.AUTH]: { + resolve: "@medusajs/auth", + options: { + providers: [ + { + resolve: "./modules/my-auth", + options: { + config: { + "my-auth": { + // provider options... + }, }, }, }, - }, - ], + ], + }, }, - }, -} + } +}) \`\`\` `, ], diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/file.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/file.ts index b92124a85b..6706f0abc0 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/file.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/file.ts @@ -61,26 +61,28 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -const modules = { +module.exports = defineConfig({ // ... - [Modules.FILE]: { - resolve: "@medusajs/file", - options: { - providers: [ - { - resolve: "./dist/modules/my-file", - options: { - config: { - "my-file": { - // provider options... + modules: { + [Modules.FILE]: { + resolve: "@medusajs/file", + options: { + providers: [ + { + resolve: "./modules/my-file", + options: { + config: { + "my-file": { + // provider options... + }, }, }, }, - }, - ], + ], + }, }, - }, -} + } +}) \`\`\` `, ], diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/fulfillment-provider.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/fulfillment-provider.ts index e2214614ea..e890007cb1 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/fulfillment-provider.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/fulfillment-provider.ts @@ -55,26 +55,28 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -const modules = { +module.exports = defineConfig({ // ... - [Modules.FULFILLMENT]: { - resolve: "@medusajs/fulfillment", - options: { - providers: [ - { - resolve: "./dist/modules/my-fulfillment", - options: { - config: { - "my-fulfillment": { - // provider options... + modules: { + [Modules.FULFILLMENT]: { + resolve: "@medusajs/fulfillment", + options: { + providers: [ + { + resolve: "./dist/modules/my-fulfillment", + options: { + config: { + "my-fulfillment": { + // provider options... + }, }, }, }, - }, - ], + ], + }, }, - }, -} + } +}) \`\`\` `, ], diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts index a0c0b4ec03..b1eb1119bf 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts @@ -70,27 +70,29 @@ const { Modules } = require("@medusajs/modules-sdk") // ... -const modules = { +module.exports = defineConfig({ // ... - [Modules.NOTIFICATION]: { - resolve: "@medusajs/notification", - options: { - providers: [ - { - resolve: "./dist/modules/my-notification", - options: { - config: { - "my-notification": { - channels: ["email"], - // provider options... + modules: { + [Modules.NOTIFICATION]: { + resolve: "@medusajs/notification", + options: { + providers: [ + { + resolve: "./dist/modules/my-notification", + options: { + config: { + "my-notification": { + channels: ["email"], + // provider options... + }, }, }, }, - }, - ], + ], + }, }, - }, -} + } +}) \`\`\` `, ],