chore: Rename config properties to camelCase (#7498)

* refactor: rename config types to camelCase

* refactor: update config references to use renamed options

* refactor: update more references

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Harminder VirkandOli Juhl authored and GitHub committed 2024-05-28 14:49:29 +02:00
1 parent e60b4bafe1
commit 82be054a1a
15 files changed
+297 -140

No files matched your search

@@ -13,7 +13,7 @@ describe("Database options", () => {
const cwd = path.resolve(path.join(__dirname, "..", "..")) const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ dbConnection = await initDb({
cwd, cwd,
database_extra: { idle_in_transaction_session_timeout: 1000 }, databaseExtra: { idle_in_transaction_session_timeout: 1000 },
}) })
medusaProcess = await setupServer({ cwd }) medusaProcess = await setupServer({ cwd })
}) })
+3 -3
View File
@@ -21,9 +21,9 @@ module.exports = {
disable: true, disable: true,
}, },
projectConfig: { projectConfig: {
redis_url: redisUrl, redisUrl: redisUrl,
database_url: DB_URL, databaseUrl: DB_URL,
database_type: "postgres", databaseType: "postgres",
http: { http: {
compression: { compression: {
enabled: enableResponseCompression, enabled: enableResponseCompression,
@@ -91,7 +91,7 @@ const instance = DbTestUtil
module.exports = { module.exports = {
initDb: async function ({ initDb: async function ({
cwd, cwd,
database_extra, databaseExtra,
env, env,
force_modules_migration, force_modules_migration,
}) { }) {
@@ -145,7 +145,7 @@ module.exports = {
url: DB_URL, url: DB_URL,
entities: enabledEntities.concat(moduleModels), entities: enabledEntities.concat(moduleModels),
migrations: enabledMigrations.concat(moduleMigrations), migrations: enabledMigrations.concat(moduleMigrations),
extra: database_extra ?? {}, extra: databaseExtra ?? {},
name: "integration-tests", name: "integration-tests",
}) })
+2 -2
View File
@@ -36,8 +36,8 @@ module.exports = {
}, },
plugins: [], plugins: [],
projectConfig: { projectConfig: {
database_url: DB_URL, databaseUrl: DB_URL,
database_type: "postgres", databaseType: "postgres",
http: { http: {
jwtSecret: "test", jwtSecret: "test",
cookieSecret: "test", cookieSecret: "test",
@@ -103,8 +103,8 @@ export function medusaIntegrationTestRunner({
rootDirectory: string rootDirectory: string
) => { ) => {
const config = originalConfigLoader(rootDirectory) const config = originalConfigLoader(rootDirectory)
config.projectConfig.database_url = dbConfig.clientUrl config.projectConfig.databaseUrl = dbConfig.clientUrl
config.projectConfig.database_driver_options = dbConfig.clientUrl.includes( config.projectConfig.databaseDriverOptions = dbConfig.clientUrl.includes(
"localhost" "localhost"
) )
? {} ? {}
+30 -28
View File
@@ -118,7 +118,7 @@ export type HttpCompressionOptions = {
*/ */
export type ProjectConfigOptions = { export type ProjectConfigOptions = {
/** /**
* The name of the database to connect to. If specified in `database_url`, then it’s not required to include it. * The name of the database to connect to. If specified in `databaseUrl`, then it’s not required to include it.
* *
* Make sure to create the PostgreSQL database before using it. You can check how to create a database in * Make sure to create the PostgreSQL database before using it. You can check how to create a database in
* [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html). * [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html).
@@ -127,7 +127,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* database_database: process.env.DATABASE_DATABASE || * databaseName: process.env.DATABASE_DATABASE ||
* "medusa-store", * "medusa-store",
* // ... * // ...
* }, * },
@@ -135,7 +135,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
database_database?: string databaseName?: string
/** /**
* The connection URL of the database. The format of the connection URL for PostgreSQL is: * The connection URL of the database. The format of the connection URL for PostgreSQL is:
@@ -166,21 +166,22 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* database_url: process.env.DATABASE_URL, * databaseUrl: process.env.DATABASE_URL,
* // ... * // ...
* }, * },
* // ... * // ...
* } * }
* ``` * ```
*/ */
database_url?: string databaseUrl?: string
/** /**
* 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 = {
* projectConfig: { * projectConfig: {
* database_schema: process.env.DATABASE_SCHEMA || * databaseSchema: process.env.DATABASE_SCHEMA ||
* "custom", * "custom",
* // ... * // ...
* }, * },
@@ -188,7 +189,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
database_schema?: string databaseSchema?: string
/** /**
* This configuration specifies what database messages to log. Its value can be one of the following: * This configuration specifies what database messages to log. Its value can be one of the following:
@@ -203,7 +204,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* database_logging: [ * databaseLogging: [
* "query", "error", * "query", "error",
* ], * ],
* // ... * // ...
@@ -212,7 +213,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
database_logging: LoggerOptions databaseLogging: LoggerOptions
/** /**
* @ignore * @ignore
@@ -221,7 +222,7 @@ export type ProjectConfigOptions = {
* @privateRemarks * @privateRemarks
* only postgres is supported, so this config has no effect * only postgres is supported, so this config has no effect
*/ */
database_type?: string databaseType?: string
/** /**
* An object that includes additional configurations to pass to the database connection. You can pass any configuration. One defined configuration to pass is * An object that includes additional configurations to pass to the database connection. You can pass any configuration. One defined configuration to pass is
@@ -234,7 +235,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* database_extra: * databaseExtra:
* process.env.NODE_ENV !== "development" * process.env.NODE_ENV !== "development"
* ? { ssl: { rejectUnauthorized: false } } * ? { ssl: { rejectUnauthorized: false } }
* : {}, * : {},
@@ -244,7 +245,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
database_extra?: Record<string, unknown> & { databaseExtra?: Record<string, unknown> & {
/** /**
* Configure support for TLS/SSL connection * Configure support for TLS/SSL connection
*/ */
@@ -267,7 +268,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* database_driver_options: * databaseDriverOptions:
* process.env.NODE_ENV !== "development" * process.env.NODE_ENV !== "development"
* ? { connection: { ssl: { rejectUnauthorized: false } } } * ? { connection: { ssl: { rejectUnauthorized: false } } }
* : {}, * : {},
@@ -277,7 +278,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
database_driver_options?: Record<string, unknown> & { databaseDriverOptions?: Record<string, unknown> & {
connection?: { connection?: {
/** /**
* Configure support for TLS/SSL connection * Configure support for TLS/SSL connection
@@ -312,7 +313,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* redis_url: process.env.REDIS_URL || * redisUrl: process.env.REDIS_URL ||
* "redis://localhost:6379", * "redis://localhost:6379",
* // ... * // ...
* }, * },
@@ -320,7 +321,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
redis_url?: string redisUrl?: string
/** /**
* The prefix set on all keys stored in Redis. The default value is `sess:`. * The prefix set on all keys stored in Redis. The default value is `sess:`.
@@ -331,7 +332,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* redis_prefix: process.env.REDIS_PREFIX || * redisPrefix: process.env.REDIS_PREFIX ||
* "medusa:", * "medusa:",
* // ... * // ...
* }, * },
@@ -339,7 +340,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
redis_prefix?: string redisPrefix?: string
/** /**
* An object of options to pass ioredis. You can refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions) * An object of options to pass ioredis. You can refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions)
@@ -349,7 +350,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* redis_options: { * redisOptions: {
* connectionName: process.env.REDIS_CONNECTION_NAME || * connectionName: process.env.REDIS_CONNECTION_NAME ||
* "medusa", * "medusa",
* }, * },
@@ -359,7 +360,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
redis_options?: RedisOptions redisOptions?: RedisOptions
/** /**
* An object of options to pass to [express-session](https://www.npmjs.com/package/express-session). * An object of options to pass to [express-session](https://www.npmjs.com/package/express-session).
@@ -368,7 +369,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* session_options: { * sessionOptions: {
* name: process.env.SESSION_NAME || * name: process.env.SESSION_NAME ||
* "custom", * "custom",
* }, * },
@@ -378,7 +379,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
session_options?: SessionOptions sessionOptions?: SessionOptions
/** /**
* Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there. * Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
@@ -390,7 +391,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* http_compression: { * httpCompression: {
* enabled: true, * enabled: true,
* level: 6, * level: 6,
* memLevel: 8, * memLevel: 8,
@@ -405,7 +406,7 @@ export type ProjectConfigOptions = {
* @deprecated use {@link http }'s `compression` property instead. * @deprecated use {@link http }'s `compression` property instead.
* *
*/ */
http_compression?: HttpCompressionOptions httpCompression?: HttpCompressionOptions
/** /**
* Configure the number of staged jobs that are polled from the database. Default is `1000`. * Configure the number of staged jobs that are polled from the database. Default is `1000`.
@@ -414,14 +415,14 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* jobs_batch_size: 100 * jobsBatchSize: 100
* // ... * // ...
* }, * },
* // ... * // ...
* } * }
* ``` * ```
*/ */
jobs_batch_size?: number jobsBatchSize?: number
/** /**
* Configure the application's worker mode. Default is `shared`. * Configure the application's worker mode. Default is `shared`.
@@ -436,14 +437,14 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js" * ```js title="medusa-config.js"
* module.exports = { * module.exports = {
* projectConfig: { * projectConfig: {
* worker_mode: "shared" * workerMode: "shared"
* // ... * // ...
* }, * },
* // ... * // ...
* } * }
* ``` * ```
*/ */
worker_mode?: "shared" | "worker" | "server" workerMode?: "shared" | "worker" | "server"
/** /**
* Configure the application's http-specific settings * Configure the application's http-specific settings
@@ -652,6 +653,7 @@ export type ProjectConfigOptions = {
* ``` * ```
*/ */
storeCors: string storeCors: string
/** /**
* The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes. * The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.
* *
+7 -7
View File
@@ -57,30 +57,30 @@ const buildHttpConfig = (projectConfig: ConfigModule["projectConfig"]) => {
const normalizeProjectConfig = ( const normalizeProjectConfig = (
projectConfig: ConfigModule["projectConfig"] projectConfig: ConfigModule["projectConfig"]
) => { ) => {
if (!projectConfig?.redis_url) { if (!projectConfig?.redisUrl) {
console.log( console.log(
`[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.` `[medusa-config] ⚠️ redisUrl not found. A fake redis instance will be used.`
) )
} }
projectConfig.http = buildHttpConfig(projectConfig) projectConfig.http = buildHttpConfig(projectConfig)
let worker_mode = projectConfig?.worker_mode let workedMode = projectConfig?.workerMode
if (!isDefined(worker_mode)) { if (!isDefined(workedMode)) {
const env = process.env.MEDUSA_WORKER_MODE const env = process.env.MEDUSA_WORKER_MODE
if (isDefined(env)) { if (isDefined(env)) {
if (env === "shared" || env === "worker" || env === "server") { if (env === "shared" || env === "worker" || env === "server") {
worker_mode = env workedMode = env
} }
} else { } else {
worker_mode = "shared" workedMode = "shared"
} }
} }
return { return {
...projectConfig, ...projectConfig,
worker_mode, workerMode: workedMode,
} }
} }
+11 -11
View File
@@ -28,33 +28,33 @@ export default async ({
sameSite = "none" sameSite = "none"
} }
const { http, session_options } = configModule.projectConfig const { http, sessionOptions } = configModule.projectConfig
const sessionOpts = { const sessionOpts = {
name: session_options?.name ?? "connect.sid", name: sessionOptions?.name ?? "connect.sid",
resave: session_options?.resave ?? true, resave: sessionOptions?.resave ?? true,
rolling: session_options?.rolling ?? false, rolling: sessionOptions?.rolling ?? false,
saveUninitialized: session_options?.saveUninitialized ?? true, saveUninitialized: sessionOptions?.saveUninitialized ?? true,
proxy: true, proxy: true,
secret: session_options?.secret ?? http?.cookieSecret, secret: sessionOptions?.secret ?? http?.cookieSecret,
cookie: { cookie: {
sameSite, sameSite,
secure, secure,
maxAge: session_options?.ttl ?? 10 * 60 * 60 * 1000, maxAge: sessionOptions?.ttl ?? 10 * 60 * 60 * 1000,
}, },
store: null, store: null,
} }
let redisClient let redisClient
if (configModule?.projectConfig?.redis_url) { if (configModule?.projectConfig?.redisUrl) {
const RedisStore = createStore(session) const RedisStore = createStore(session)
redisClient = new Redis( redisClient = new Redis(
configModule.projectConfig.redis_url, configModule.projectConfig.redisUrl,
configModule.projectConfig.redis_options ?? {} configModule.projectConfig.redisOptions ?? {}
) )
sessionOpts.store = new RedisStore({ sessionOpts.store = new RedisStore({
client: redisClient, client: redisClient,
prefix: `${configModule?.projectConfig?.redis_prefix ?? ""}sess:`, prefix: `${configModule?.projectConfig?.redisPrefix ?? ""}sess:`,
}) })
} }
@@ -6,7 +6,7 @@ export const storeGlobalMiddlewareMock = jest.fn()
export const config: ConfigModule = { export const config: ConfigModule = {
projectConfig: { projectConfig: {
database_logging: false, databaseLogging: false,
http: { http: {
authCors: "http://localhost:9000", authCors: "http://localhost:9000",
storeCors: "http://localhost:8000", storeCors: "http://localhost:8000",
+1 -1
View File
@@ -27,7 +27,7 @@ type Options = {
} }
const isWorkerMode = (configModule) => { const isWorkerMode = (configModule) => {
return configModule.projectConfig.worker_mode === "worker" return configModule.projectConfig.workerMode === "worker"
} }
async function subscribersLoader( async function subscribersLoader(
+10 -10
View File
@@ -85,9 +85,9 @@ async function runMedusaAppMigrations({
clientUrl: clientUrl:
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client
?.config?.connection?.connectionString ?? ?.config?.connection?.connectionString ??
configModule.projectConfig.database_url, configModule.projectConfig.databaseUrl,
driverOptions: configModule.projectConfig.database_driver_options, driverOptions: configModule.projectConfig.databaseDriverOptions,
debug: !!(configModule.projectConfig.database_logging ?? false), debug: !!(configModule.projectConfig.databaseLogging ?? false),
}, },
} }
const configModules = mergeDefaultModules(configModule.modules) const configModules = mergeDefaultModules(configModule.modules)
@@ -175,9 +175,9 @@ export const loadMedusaApp = async (
const sharedResourcesConfig = { const sharedResourcesConfig = {
database: { database: {
clientUrl: configModule.projectConfig.database_url, clientUrl: configModule.projectConfig.databaseUrl,
driverOptions: configModule.projectConfig.database_driver_options, driverOptions: configModule.projectConfig.databaseDriverOptions,
debug: !!(configModule.projectConfig.database_logging ?? false), debug: !!(configModule.projectConfig.databaseLogging ?? false),
}, },
} }
@@ -187,7 +187,7 @@ export const loadMedusaApp = async (
const configModules = mergeDefaultModules(configModule.modules) const configModules = mergeDefaultModules(configModule.modules)
const medusaApp = await MedusaApp({ const medusaApp = await MedusaApp({
workerMode: configModule.projectConfig.worker_mode, workerMode: configModule.projectConfig.workerMode,
modulesConfig: configModules, modulesConfig: configModules,
sharedContainer: container, sharedContainer: container,
linkModules, linkModules,
@@ -256,9 +256,9 @@ export async function runModulesLoader({
const sharedResourcesConfig = { const sharedResourcesConfig = {
database: { database: {
clientUrl: configModule.projectConfig.database_url, clientUrl: configModule.projectConfig.databaseUrl,
driverOptions: configModule.projectConfig.database_driver_options, driverOptions: configModule.projectConfig.databaseDriverOptions,
debug: !!(configModule.projectConfig.database_logging ?? false), debug: !!(configModule.projectConfig.databaseLogging ?? false),
}, },
} }
+3 -3
View File
@@ -13,10 +13,10 @@ export default async ({ container, configModule }: Options): Promise<any> => {
} }
// Share a knex connection to be consumed by the shared modules // Share a knex connection to be consumed by the shared modules
const connectionString = configModule.projectConfig.database_url const connectionString = configModule.projectConfig.databaseUrl
const driverOptions: any = const driverOptions: any =
configModule.projectConfig.database_driver_options || {} configModule.projectConfig.databaseDriverOptions || {}
const schema = configModule.projectConfig.database_schema || "public" const schema = configModule.projectConfig.databaseSchema || "public"
const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed
const poolMax = driverOptions.pool?.max const poolMax = driverOptions.pool?.max
+3 -3
View File
@@ -19,11 +19,11 @@ async function redisLoader({
}: Options): Promise<{ shutdown: () => Promise<void> }> { }: Options): Promise<{ shutdown: () => Promise<void> }> {
let client!: Redis | FakeRedis let client!: Redis | FakeRedis
if (configModule.projectConfig.redis_url) { if (configModule.projectConfig.redisUrl) {
client = new Redis(configModule.projectConfig.redis_url, { client = new Redis(configModule.projectConfig.redisUrl, {
// Lazy connect to properly handle connection errors // Lazy connect to properly handle connection errors
lazyConnect: true, lazyConnect: true,
...(configModule.projectConfig.redis_options ?? {}), ...(configModule.projectConfig.redisOptions ?? {}),
}) })
try { try {
@@ -13,7 +13,7 @@ export default async ({
if (!redisUrl) { if (!redisUrl) {
throw Error( throw Error(
"No `redis_url` provided in project config. It is required for the Redis Event Bus." "No `redisUrl` provided in project config. It is required for the Redis Event Bus."
) )
} }
@@ -27,7 +27,7 @@ export default async ({
}) })
try { try {
await new Promise(async resolve => { await new Promise(async (resolve) => {
await connection.connect(resolve) await connection.connect(resolve)
}) })
logger?.info(`Connection to Redis in module 'event-bus-redis' established`) logger?.info(`Connection to Redis in module 'event-bus-redis' established`)
@@ -11,7 +11,7 @@ In this document, you’ll learn how to create a file service in the Medusa back
## Prerequisites ## Prerequisites
This document assumes you already followed along with the [Prepare Environment documentation](https://docs.medusajs.com/development/backend/prepare-environment) and have a Medusa backend installed. This document assumes you already followed along with the [Prepare Environment documentation](https://docs.medusajs.com/development/backend/prepare-environment) and have a Medusa backend installed.
--- ---
The configurations for your Medusa backend are in `medusa-config.js` located in the root of your Medusa project. The configurations include database, modules, and plugin configurations, among other configurations. The configurations for your Medusa backend are in `medusa-config.js` located in the root of your Medusa project. The configurations include database, modules, and plugin configurations, among other configurations.
@@ -49,7 +49,7 @@ setting the environment variables depends on the hosting provider.
This property holds essential configurations related to the Medusa backend, such as database and CORS configurations. This property holds essential configurations related to the Medusa backend, such as database and CORS configurations.
### store\_cors ### store_cors
The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes. The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.
@@ -99,7 +99,7 @@ module.exports = {
} }
``` ```
### admin\_cors ### admin_cors
The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes. The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.
@@ -149,7 +149,7 @@ module.exports = {
} }
``` ```
### auth\_cors ### authCors
The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes. The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.
@@ -180,7 +180,7 @@ Then, set the configuration in `medusa-config.js`:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
auth_cors: process.env.AUTH_CORS, authCors: process.env.AUTH_CORS,
// ... // ...
}, },
// ... // ...
@@ -192,14 +192,14 @@ If you’re adding the value directly within `medusa-config.js`, make sure to ad
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
auth_cors: "/http:\\/\\/localhost:700\\d+$/", authCors: "/http:\\/\\/localhost:700\\d+$/",
// ... // ...
}, },
// ... // ...
} }
``` ```
### cookie\_secret ### cookieSecret
A random string used to create cookie tokens. Although this configuration option is not required, it’s highly recommended to set it for better security. A random string used to create cookie tokens. Although this configuration option is not required, it’s highly recommended to set it for better security.
@@ -211,15 +211,14 @@ the backend crashes.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
cookie_secret: process.env.COOKIE_SECRET || cookieSecret: process.env.COOKIE_SECRET || "supersecret",
"supersecret",
// ... // ...
}, },
// ... // ...
} }
``` ```
### jwt\_secret ### jwtSecret
A random string used to create authentication tokens. Although this configuration option is not required, it’s highly recommended to set it for better security. A random string used to create authentication tokens. Although this configuration option is not required, it’s highly recommended to set it for better security.
@@ -231,17 +230,16 @@ error is thrown and the backend crashes.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
jwt_secret: process.env.JWT_SECRET || jwtSecret: process.env.JWT_SECRET || "supersecret",
"supersecret",
// ... // ...
}, },
// ... // ...
} }
``` ```
### database\_database ### databaseName
The name of the database to connect to. If specified in `database_url`, then it’s not required to include it. The name of the database to connect to. If specified in `databaseUrl`, then it’s not required to include it.
Make sure to create the PostgreSQL database before using it. You can check how to create a database in Make sure to create the PostgreSQL database before using it. You can check how to create a database in
[PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html). [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html).
@@ -251,15 +249,14 @@ Make sure to create the PostgreSQL database before using it. You can check how t
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
database_database: process.env.DATABASE_DATABASE || databaseName: process.env.DATABASE_DATABASE || "medusa-store",
"medusa-store",
// ... // ...
}, },
// ... // ...
} }
``` ```
### database\_url ### databaseUrl
The connection URL of the database. The format of the connection URL for PostgreSQL is: The connection URL of the database. The format of the connection URL for PostgreSQL is:
@@ -290,29 +287,28 @@ Then, use the value in `medusa-config.js`:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
database_url: process.env.DATABASE_URL, databaseUrl: process.env.DATABASE_URL,
// ... // ...
}, },
// ... // ...
} }
``` ```
### database\_schema ### databaseSchema
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 = {
projectConfig: { projectConfig: {
database_schema: process.env.DATABASE_SCHEMA || databaseSchema: process.env.DATABASE_SCHEMA || "custom",
"custom",
// ... // ...
}, },
// ... // ...
} }
``` ```
### database\_logging ### databaseLogging
This configuration specifies what database messages to log. Its value can be one of the following: This configuration specifies what database messages to log. Its value can be one of the following:
@@ -327,16 +323,14 @@ If this configuration isn't set, its default value is `false`, meaning no databa
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
database_logging: [ databaseLogging: ["query", "error"],
"query", "error",
],
// ... // ...
}, },
// ... // ...
} }
``` ```
### database\_extra ### databaseExtra
An object that includes additional configurations to pass to the database connection. You can pass any configuration. One defined configuration to pass is An object that includes additional configurations to pass to the database connection. You can pass any configuration. One defined configuration to pass is
`ssl` which enables support for TLS/SSL connections. `ssl` which enables support for TLS/SSL connections.
@@ -349,7 +343,7 @@ During development, it’s recommended not to pass this option.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
database_extra: databaseExtra:
process.env.NODE_ENV !== "development" process.env.NODE_ENV !== "development"
? { ssl: { rejectUnauthorized: false } } ? { ssl: { rejectUnauthorized: false } }
: {}, : {},
@@ -361,9 +355,33 @@ module.exports = {
#### Properties #### Properties
<TypeList types={[{"name":"ssl","type":"`object`","description":"Configure support for TLS/SSL connection","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"rejectUnauthorized","type":"`false`","description":"Whether to fail connection if the server certificate is verified against the list of supplied CAs and the hostname and no match is found.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} sectionTitle="database_extra"/> <TypeList
types={[
{
name: "ssl",
type: "`object`",
description: "Configure support for TLS/SSL connection",
optional: false,
defaultValue: "",
expandable: false,
children: [
{
name: "rejectUnauthorized",
type: "`false`",
description:
"Whether to fail connection if the server certificate is verified against the list of supplied CAs and the hostname and no match is found.",
optional: false,
defaultValue: "",
expandable: false,
children: [],
},
],
},
]}
sectionTitle="database_extra"
/>
### database\_driver\_options ### databaseDriverOptions
An object that includes additional configurations to pass to the database connection for v2. You can pass any configuration. One defined configuration to pass is An object that includes additional configurations to pass to the database connection for v2. You can pass any configuration. One defined configuration to pass is
`ssl` which enables support for TLS/SSL connections. `ssl` which enables support for TLS/SSL connections.
@@ -376,7 +394,7 @@ During development, it’s recommended not to pass this option.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
database_driver_options: databaseDriverOptions:
process.env.NODE_ENV !== "development" process.env.NODE_ENV !== "development"
? { connection: { ssl: { rejectUnauthorized: false } } } ? { connection: { ssl: { rejectUnauthorized: false } } }
: {}, : {},
@@ -388,9 +406,43 @@ module.exports = {
#### Properties #### Properties
<TypeList types={[{"name":"connection","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"ssl","type":"`object`","description":"Configure support for TLS/SSL connection","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"rejectUnauthorized","type":"`false`","description":"Whether to fail connection if the server certificate is verified against the list of supplied CAs and the hostname and no match is found.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} sectionTitle="database_driver_options"/> <TypeList
types={[
{
name: "connection",
type: "`object`",
description: "",
optional: true,
defaultValue: "",
expandable: false,
children: [
{
name: "ssl",
type: "`object`",
description: "Configure support for TLS/SSL connection",
optional: true,
defaultValue: "",
expandable: false,
children: [
{
name: "rejectUnauthorized",
type: "`false`",
description:
"Whether to fail connection if the server certificate is verified against the list of supplied CAs and the hostname and no match is found.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
],
},
],
},
]}
sectionTitle="database_driver_options"
/>
### redis\_url ### redisUrl
Used to specify the URL to connect to Redis. This is only used for scheduled jobs. If you omit this configuration, scheduled jobs won't work. Used to specify the URL to connect to Redis. This is only used for scheduled jobs. If you omit this configuration, scheduled jobs won't work.
@@ -413,15 +465,14 @@ For a local Redis installation, the connection URL should be `redis://localhost:
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
redis_url: process.env.REDIS_URL || redisUrl: process.env.REDIS_URL || "redis://localhost:6379",
"redis://localhost:6379",
// ... // ...
}, },
// ... // ...
} }
``` ```
### redis\_prefix ### redisPrefix
The prefix set on all keys stored in Redis. The default value is `sess:`. The prefix set on all keys stored in Redis. The default value is `sess:`.
@@ -432,15 +483,14 @@ If this configuration option is provided, it is prepended to `sess:`.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
redis_prefix: process.env.REDIS_PREFIX || redisPrefix: process.env.REDIS_PREFIX || "medusa:",
"medusa:",
// ... // ...
}, },
// ... // ...
} }
``` ```
### redis\_options ### redisOptions
An object of options to pass ioredis. You can refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions) An object of options to pass ioredis. You can refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions)
for the list of available options. for the list of available options.
@@ -450,9 +500,8 @@ for the list of available options.
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
redis_options: { redisOptions: {
connectionName: process.env.REDIS_CONNECTION_NAME || connectionName: process.env.REDIS_CONNECTION_NAME || "medusa",
"medusa",
}, },
// ... // ...
}, },
@@ -460,7 +509,7 @@ module.exports = {
} }
``` ```
### session\_options ### sessionOptions
An object of options to pass to [express-session](https://www.npmjs.com/package/express-session). An object of options to pass to [express-session](https://www.npmjs.com/package/express-session).
@@ -469,9 +518,8 @@ An object of options to pass to [express-session](https://www.npmjs.com/package/
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
session_options: { sessionOptions: {
name: process.env.SESSION_NAME || name: process.env.SESSION_NAME || "custom",
"custom",
}, },
// ... // ...
}, },
@@ -481,9 +529,73 @@ module.exports = {
#### Properties #### Properties
<TypeList types={[{"name":"name","type":"`string`","description":"The name of the session ID cookie to set in the response (and read from in the request). The default value is `connect.sid`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#name) for more details.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"resave","type":"`boolean`","description":"Whether the session should be saved back to the session store, even if the session was never modified during the request. The default value is `true`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#resave) for more details.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rolling","type":"`boolean`","description":"Whether the session identifier cookie should be force-set on every response. The default value is `false`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#rolling) for more details.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"saveUninitialized","type":"`boolean`","description":"Whether a session that is \"uninitialized\" is forced to be saved to the store. The default value is `true`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#saveUninitialized) for more details.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"secret","type":"`string`","description":"The secret to sign the session ID cookie. By default, the value of `cookie_secret` is used.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#secret) for details.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ttl","type":"`number`","description":"Used when calculating the `Expires` `Set-Cookie` attribute of cookies. By default, its value is `10 * 60 * 60 * 1000`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#cookiemaxage) for details.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="session_options"/> <TypeList
types={[
{
name: "name",
type: "`string`",
description:
"The name of the session ID cookie to set in the response (and read from in the request). The default value is `connect.sid`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#name) for more details.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "resave",
type: "`boolean`",
description:
"Whether the session should be saved back to the session store, even if the session was never modified during the request. The default value is `true`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#resave) for more details.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "rolling",
type: "`boolean`",
description:
"Whether the session identifier cookie should be force-set on every response. The default value is `false`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#rolling) for more details.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "saveUninitialized",
type: "`boolean`",
description:
'Whether a session that is "uninitialized" is forced to be saved to the store. The default value is `true`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#saveUninitialized) for more details.',
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "secret",
type: "`string`",
description:
"The secret to sign the session ID cookie. By default, the value of `cookie_secret` is used.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#secret) for details.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "ttl",
type: "`number`",
description:
"Used when calculating the `Expires` `Set-Cookie` attribute of cookies. By default, its value is `10 * 60 * 60 * 1000`.\nRefer to [express-session’s documentation](https://www.npmjs.com/package/express-session#cookiemaxage) for details.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
]}
sectionTitle="session_options"
/>
### http\_compression ### http_compression
Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there. Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative. However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.
@@ -511,9 +623,53 @@ module.exports = {
#### Properties #### Properties
<TypeList types={[{"name":"enabled","type":"`boolean`","description":"Whether HTTP compression is enabled. By default, it's `false`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"level","type":"`number`","description":"The level of zlib compression to apply to responses. A higher level will result in better compression but will take longer to complete.\nA lower level will result in less compression but will be much faster. The default value is `6`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"memLevel","type":"`number`","description":"How much memory should be allocated to the internal compression state. It's an integer in the range of 1 (minimum level) and 9 (maximum level).\nThe default value is `8`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"threshold","type":"`string` \\| `number`","description":"The minimum response body size that compression is applied on. Its value can be the number of bytes or any string accepted by the\n[bytes](https://www.npmjs.com/package/bytes) module. The default value is `1024`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="http_compression"/> <TypeList
types={[
{
name: "enabled",
type: "`boolean`",
description:
"Whether HTTP compression is enabled. By default, it's `false`.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "level",
type: "`number`",
description:
"The level of zlib compression to apply to responses. A higher level will result in better compression but will take longer to complete.\nA lower level will result in less compression but will be much faster. The default value is `6`.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "memLevel",
type: "`number`",
description:
"How much memory should be allocated to the internal compression state. It's an integer in the range of 1 (minimum level) and 9 (maximum level).\nThe default value is `8`.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
{
name: "threshold",
type: "`string` \\| `number`",
description:
"The minimum response body size that compression is applied on. Its value can be the number of bytes or any string accepted by the\n[bytes](https://www.npmjs.com/package/bytes) module. The default value is `1024`.",
optional: true,
defaultValue: "",
expandable: false,
children: [],
},
]}
sectionTitle="http_compression"
/>
### jobs\_batch\_size ### jobs_batch_size
Configure the number of staged jobs that are polled from the database. Default is `1000`. Configure the number of staged jobs that are polled from the database. Default is `1000`.
@@ -522,14 +678,14 @@ Configure the number of staged jobs that are polled from the database. Default i
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
jobs_batch_size: 100 jobs_batch_size: 100,
// ... // ...
}, },
// ... // ...
} }
``` ```
### worker\_mode ### worker_mode
Configure the application's worker mode. Default is `shared`. Configure the application's worker mode. Default is `shared`.
@@ -544,14 +700,14 @@ Learn more in [this guide](https://docs.medusajs.com/development/medusa-worker).
```js title="medusa-config.js" ```js title="medusa-config.js"
module.exports = { module.exports = {
projectConfig: { projectConfig: {
worker_mode: "shared" worker_mode: "shared",
// ... // ...
}, },
// ... // ...
} }
``` ```
___ ---
## plugins ## plugins
@@ -564,8 +720,8 @@ The items in the array can either be:
- A string, which is the name of the plugin to add. You can pass a plugin as a string if it doesn’t require any configurations. - A string, which is the name of the plugin to add. You can pass a plugin as a string if it doesn’t require any configurations.
- An object having the following properties: - An object having the following properties:
- `resolve`: The name of the plugin. - `resolve`: The name of the plugin.
- `options`: An object that includes the plugin’s options. These options vary for each plugin, and you should refer to the plugin’s documentation for available options. - `options`: An object that includes the plugin’s options. These options vary for each plugin, and you should refer to the plugin’s documentation for available options.
### Example ### Example
@@ -576,8 +732,7 @@ module.exports = {
{ {
resolve: `medusa-my-plugin`, resolve: `medusa-my-plugin`,
options: { options: {
apiKey: process.env.MY_API_KEY || apiKey: process.env.MY_API_KEY || `test`,
`test`,
}, },
}, },
// ... // ...
@@ -586,7 +741,7 @@ module.exports = {
} }
``` ```
___ ---
## modules ## modules
@@ -600,11 +755,11 @@ The keys of the `modules` configuration object refer to the type of module. Its
1. A boolean value indicating whether the module type is enabled; 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; 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: 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. 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. 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. 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. 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. 5. `main`: a boolean value indicating whether this module is the main registered module. This is useful when an alias is used.
### Example ### Example
@@ -627,7 +782,7 @@ module.exports = {
} }
``` ```
___ ---
## featureFlags ## featureFlags