From 1d69f890ae7db9ad32724f3e5dbf9198ae82fd42 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 28 May 2024 16:39:36 +0530 Subject: [PATCH 1/3] refactor: rename config types to camelCase --- .../core/types/src/common/config-module.ts | 56 ++++++++++--------- packages/medusa/src/loaders/config.ts | 14 ++--- packages/medusa/src/loaders/express.ts | 22 ++++---- packages/medusa/src/loaders/medusa-app.ts | 20 +++---- packages/medusa/src/loaders/pg-connection.ts | 6 +- packages/medusa/src/loaders/redis.ts | 6 +- 6 files changed, 63 insertions(+), 61 deletions(-) diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index 3188096901452..7de64855f82db 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -127,7 +127,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * database_database: process.env.DATABASE_DATABASE || + * databaseName: process.env.DATABASE_DATABASE || * "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: @@ -166,21 +166,22 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * 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`. * * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * database_schema: process.env.DATABASE_SCHEMA || + * databaseSchema: process.env.DATABASE_SCHEMA || * "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: @@ -203,7 +204,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * database_logging: [ + * databaseLogging: [ * "query", "error", * ], * // ... @@ -212,7 +213,7 @@ export type ProjectConfigOptions = { * } * ``` */ - database_logging: LoggerOptions + databaseLogging: LoggerOptions /** * @ignore @@ -221,7 +222,7 @@ export type ProjectConfigOptions = { * @privateRemarks * 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 @@ -234,7 +235,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * database_extra: + * databaseExtra: * process.env.NODE_ENV !== "development" * ? { ssl: { rejectUnauthorized: false } } * : {}, @@ -244,7 +245,7 @@ export type ProjectConfigOptions = { * } * ``` */ - database_extra?: Record & { + databaseExtra?: Record & { /** * Configure support for TLS/SSL connection */ @@ -267,7 +268,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * database_driver_options: + * databaseDriverOptions: * process.env.NODE_ENV !== "development" * ? { connection: { ssl: { rejectUnauthorized: false } } } * : {}, @@ -277,7 +278,7 @@ export type ProjectConfigOptions = { * } * ``` */ - database_driver_options?: Record & { + databaseDriverOptions?: Record & { connection?: { /** * Configure support for TLS/SSL connection @@ -312,7 +313,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * redis_url: process.env.REDIS_URL || + * redisUrl: process.env.REDIS_URL || * "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:`. @@ -331,7 +332,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * redis_prefix: process.env.REDIS_PREFIX || + * redisPrefix: process.env.REDIS_PREFIX || * "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) @@ -349,7 +350,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * redis_options: { + * redisOptions: { * connectionName: process.env.REDIS_CONNECTION_NAME || * "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). @@ -368,7 +369,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * session_options: { + * sessionOptions: { * name: process.env.SESSION_NAME || * "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. @@ -390,7 +391,7 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * http_compression: { + * httpCompression: { * enabled: true, * level: 6, * memLevel: 8, @@ -405,7 +406,7 @@ export type ProjectConfigOptions = { * @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`. @@ -414,14 +415,14 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * jobs_batch_size: 100 + * jobsBatchSize: 100 * // ... * }, * // ... * } * ``` */ - jobs_batch_size?: number + jobsBatchSize?: number /** * Configure the application's worker mode. Default is `shared`. @@ -436,14 +437,14 @@ export type ProjectConfigOptions = { * ```js title="medusa-config.js" * module.exports = { * projectConfig: { - * worker_mode: "shared" + * workerMode: "shared" * // ... * }, * // ... * } * ``` */ - worker_mode?: "shared" | "worker" | "server" + workerMode?: "shared" | "worker" | "server" /** * Configure the application's http-specific settings @@ -652,6 +653,7 @@ export type ProjectConfigOptions = { * ``` */ 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. * diff --git a/packages/medusa/src/loaders/config.ts b/packages/medusa/src/loaders/config.ts index df94a80b61367..9950749df1ecd 100644 --- a/packages/medusa/src/loaders/config.ts +++ b/packages/medusa/src/loaders/config.ts @@ -57,30 +57,30 @@ const buildHttpConfig = (projectConfig: ConfigModule["projectConfig"]) => { const normalizeProjectConfig = ( projectConfig: ConfigModule["projectConfig"] ) => { - if (!projectConfig?.redis_url) { + if (!projectConfig?.redisUrl) { 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) - let worker_mode = projectConfig?.worker_mode + let workedMode = projectConfig?.workerMode - if (!isDefined(worker_mode)) { + if (!isDefined(workedMode)) { const env = process.env.MEDUSA_WORKER_MODE if (isDefined(env)) { if (env === "shared" || env === "worker" || env === "server") { - worker_mode = env + workedMode = env } } else { - worker_mode = "shared" + workedMode = "shared" } } return { ...projectConfig, - worker_mode, + workerMode: workedMode, } } diff --git a/packages/medusa/src/loaders/express.ts b/packages/medusa/src/loaders/express.ts index 3c72d80d1bc2e..d38b5ab3b3a42 100644 --- a/packages/medusa/src/loaders/express.ts +++ b/packages/medusa/src/loaders/express.ts @@ -28,33 +28,33 @@ export default async ({ sameSite = "none" } - const { http, session_options } = configModule.projectConfig + const { http, sessionOptions } = configModule.projectConfig const sessionOpts = { - name: session_options?.name ?? "connect.sid", - resave: session_options?.resave ?? true, - rolling: session_options?.rolling ?? false, - saveUninitialized: session_options?.saveUninitialized ?? true, + name: sessionOptions?.name ?? "connect.sid", + resave: sessionOptions?.resave ?? true, + rolling: sessionOptions?.rolling ?? false, + saveUninitialized: sessionOptions?.saveUninitialized ?? true, proxy: true, - secret: session_options?.secret ?? http?.cookieSecret, + secret: sessionOptions?.secret ?? http?.cookieSecret, cookie: { sameSite, secure, - maxAge: session_options?.ttl ?? 10 * 60 * 60 * 1000, + maxAge: sessionOptions?.ttl ?? 10 * 60 * 60 * 1000, }, store: null, } let redisClient - if (configModule?.projectConfig?.redis_url) { + if (configModule?.projectConfig?.redisUrl) { const RedisStore = createStore(session) redisClient = new Redis( - configModule.projectConfig.redis_url, - configModule.projectConfig.redis_options ?? {} + configModule.projectConfig.redisUrl, + configModule.projectConfig.redisOptions ?? {} ) sessionOpts.store = new RedisStore({ client: redisClient, - prefix: `${configModule?.projectConfig?.redis_prefix ?? ""}sess:`, + prefix: `${configModule?.projectConfig?.redisPrefix ?? ""}sess:`, }) } diff --git a/packages/medusa/src/loaders/medusa-app.ts b/packages/medusa/src/loaders/medusa-app.ts index 95af463adcbee..ca56a338516ec 100644 --- a/packages/medusa/src/loaders/medusa-app.ts +++ b/packages/medusa/src/loaders/medusa-app.ts @@ -85,9 +85,9 @@ async function runMedusaAppMigrations({ clientUrl: injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client ?.config?.connection?.connectionString ?? - configModule.projectConfig.database_url, - driverOptions: configModule.projectConfig.database_driver_options, - debug: !!(configModule.projectConfig.database_logging ?? false), + configModule.projectConfig.databaseUrl, + driverOptions: configModule.projectConfig.databaseDriverOptions, + debug: !!(configModule.projectConfig.databaseLogging ?? false), }, } const configModules = mergeDefaultModules(configModule.modules) @@ -175,9 +175,9 @@ export const loadMedusaApp = async ( const sharedResourcesConfig = { database: { - clientUrl: configModule.projectConfig.database_url, - driverOptions: configModule.projectConfig.database_driver_options, - debug: !!(configModule.projectConfig.database_logging ?? false), + clientUrl: configModule.projectConfig.databaseUrl, + driverOptions: configModule.projectConfig.databaseDriverOptions, + debug: !!(configModule.projectConfig.databaseLogging ?? false), }, } @@ -187,7 +187,7 @@ export const loadMedusaApp = async ( const configModules = mergeDefaultModules(configModule.modules) const medusaApp = await MedusaApp({ - workerMode: configModule.projectConfig.worker_mode, + workerMode: configModule.projectConfig.workerMode, modulesConfig: configModules, sharedContainer: container, linkModules, @@ -256,9 +256,9 @@ export async function runModulesLoader({ const sharedResourcesConfig = { database: { - clientUrl: configModule.projectConfig.database_url, - driverOptions: configModule.projectConfig.database_driver_options, - debug: !!(configModule.projectConfig.database_logging ?? false), + clientUrl: configModule.projectConfig.databaseUrl, + driverOptions: configModule.projectConfig.databaseDriverOptions, + debug: !!(configModule.projectConfig.databaseLogging ?? false), }, } diff --git a/packages/medusa/src/loaders/pg-connection.ts b/packages/medusa/src/loaders/pg-connection.ts index 6e16993faa4fb..6e112bd0040f3 100644 --- a/packages/medusa/src/loaders/pg-connection.ts +++ b/packages/medusa/src/loaders/pg-connection.ts @@ -13,10 +13,10 @@ export default async ({ container, configModule }: Options): Promise => { } // 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 = - configModule.projectConfig.database_driver_options || {} - const schema = configModule.projectConfig.database_schema || "public" + configModule.projectConfig.databaseDriverOptions || {} + const schema = configModule.projectConfig.databaseSchema || "public" const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed const poolMax = driverOptions.pool?.max diff --git a/packages/medusa/src/loaders/redis.ts b/packages/medusa/src/loaders/redis.ts index 1349786c2fcfd..bdd128ee6361a 100644 --- a/packages/medusa/src/loaders/redis.ts +++ b/packages/medusa/src/loaders/redis.ts @@ -19,11 +19,11 @@ async function redisLoader({ }: Options): Promise<{ shutdown: () => Promise }> { let client!: Redis | FakeRedis - if (configModule.projectConfig.redis_url) { - client = new Redis(configModule.projectConfig.redis_url, { + if (configModule.projectConfig.redisUrl) { + client = new Redis(configModule.projectConfig.redisUrl, { // Lazy connect to properly handle connection errors lazyConnect: true, - ...(configModule.projectConfig.redis_options ?? {}), + ...(configModule.projectConfig.redisOptions ?? {}), }) try { From 5d7697769201bec450945aab535b2692fcc6161e Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 28 May 2024 17:02:55 +0530 Subject: [PATCH 2/3] refactor: update config references to use renamed options --- integration-tests/api/medusa-config.js | 6 +- integration-tests/modules/medusa-config.js | 4 +- .../src/medusa-test-runner.ts | 4 +- .../core/types/src/common/config-module.ts | 2 +- packages/medusa/src/loaders/index.ts | 2 +- .../medusa_config.ConfigModule/page.mdx | 283 ++++++++++++++---- 6 files changed, 228 insertions(+), 73 deletions(-) diff --git a/integration-tests/api/medusa-config.js b/integration-tests/api/medusa-config.js index 0c516b1bf05f1..ec21558b0c80a 100644 --- a/integration-tests/api/medusa-config.js +++ b/integration-tests/api/medusa-config.js @@ -21,9 +21,9 @@ module.exports = { disable: true, }, projectConfig: { - redis_url: redisUrl, - database_url: DB_URL, - database_type: "postgres", + redisUrl: redisUrl, + databaseUrl: DB_URL, + databaseType: "postgres", http: { compression: { enabled: enableResponseCompression, diff --git a/integration-tests/modules/medusa-config.js b/integration-tests/modules/medusa-config.js index c6f7b7e9e9af0..36d0733ded97a 100644 --- a/integration-tests/modules/medusa-config.js +++ b/integration-tests/modules/medusa-config.js @@ -36,8 +36,8 @@ module.exports = { }, plugins: [], projectConfig: { - database_url: DB_URL, - database_type: "postgres", + databaseUrl: DB_URL, + databaseType: "postgres", http: { jwtSecret: "test", cookieSecret: "test", diff --git a/packages/core/medusa-test-utils/src/medusa-test-runner.ts b/packages/core/medusa-test-utils/src/medusa-test-runner.ts index 365116b21ccbd..ea13527a4ab1f 100644 --- a/packages/core/medusa-test-utils/src/medusa-test-runner.ts +++ b/packages/core/medusa-test-utils/src/medusa-test-runner.ts @@ -103,8 +103,8 @@ export function medusaIntegrationTestRunner({ rootDirectory: string ) => { const config = originalConfigLoader(rootDirectory) - config.projectConfig.database_url = dbConfig.clientUrl - config.projectConfig.database_driver_options = dbConfig.clientUrl.includes( + config.projectConfig.databaseUrl = dbConfig.clientUrl + config.projectConfig.databaseDriverOptions = dbConfig.clientUrl.includes( "localhost" ) ? {} diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index 7de64855f82db..c29ddba886f8a 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -118,7 +118,7 @@ export type HttpCompressionOptions = { */ 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 * [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html). diff --git a/packages/medusa/src/loaders/index.ts b/packages/medusa/src/loaders/index.ts index 9cc58d7a84166..d2ac3c4a1add5 100644 --- a/packages/medusa/src/loaders/index.ts +++ b/packages/medusa/src/loaders/index.ts @@ -27,7 +27,7 @@ type Options = { } const isWorkerMode = (configModule) => { - return configModule.projectConfig.worker_mode === "worker" + return configModule.projectConfig.workerMode === "worker" } async function subscribersLoader( diff --git a/www/apps/resources/references/medusa_config/interfaces/medusa_config.ConfigModule/page.mdx b/www/apps/resources/references/medusa_config/interfaces/medusa_config.ConfigModule/page.mdx index 6e073133824e4..b6bfd695b3e01 100644 --- a/www/apps/resources/references/medusa_config/interfaces/medusa_config.ConfigModule/page.mdx +++ b/www/apps/resources/references/medusa_config/interfaces/medusa_config.ConfigModule/page.mdx @@ -11,7 +11,7 @@ In this document, you’ll learn how to create a file service in the Medusa back ## 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. - + --- 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. -### 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. @@ -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. @@ -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. @@ -180,7 +180,7 @@ Then, set the configuration in `medusa-config.js`: ```js title="medusa-config.js" module.exports = { 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" module.exports = { 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. @@ -211,15 +211,14 @@ the backend crashes. ```js title="medusa-config.js" module.exports = { projectConfig: { - cookie_secret: process.env.COOKIE_SECRET || - "supersecret", + cookieSecret: process.env.COOKIE_SECRET || "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. @@ -231,17 +230,16 @@ error is thrown and the backend crashes. ```js title="medusa-config.js" module.exports = { projectConfig: { - jwt_secret: process.env.JWT_SECRET || - "supersecret", + jwtSecret: process.env.JWT_SECRET || "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 [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" module.exports = { projectConfig: { - database_database: process.env.DATABASE_DATABASE || - "medusa-store", + databaseName: process.env.DATABASE_DATABASE || "medusa-store", // ... }, // ... } ``` -### database\_url +### databaseUrl 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" module.exports = { 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`. ```js title="medusa-config.js" module.exports = { projectConfig: { - database_schema: process.env.DATABASE_SCHEMA || - "custom", + databaseSchema: process.env.DATABASE_SCHEMA || "custom", // ... }, // ... } ``` -### database\_logging +### databaseLogging 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" module.exports = { projectConfig: { - database_logging: [ - "query", "error", - ], + databaseLogging: ["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 `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" module.exports = { projectConfig: { - database_extra: + databaseExtra: process.env.NODE_ENV !== "development" ? { ssl: { rejectUnauthorized: false } } : {}, @@ -361,9 +355,33 @@ module.exports = { #### Properties - + -### 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 `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" module.exports = { projectConfig: { - database_driver_options: + databaseDriverOptions: process.env.NODE_ENV !== "development" ? { connection: { ssl: { rejectUnauthorized: false } } } : {}, @@ -388,9 +406,43 @@ module.exports = { #### Properties - + -### 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. @@ -413,15 +465,14 @@ For a local Redis installation, the connection URL should be `redis://localhost: ```js title="medusa-config.js" module.exports = { projectConfig: { - redis_url: process.env.REDIS_URL || - "redis://localhost:6379", + redisUrl: process.env.REDIS_URL || "redis://localhost:6379", // ... }, // ... } ``` -### redis\_prefix +### redisPrefix 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" module.exports = { projectConfig: { - redis_prefix: process.env.REDIS_PREFIX || - "medusa:", + redisPrefix: process.env.REDIS_PREFIX || "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) for the list of available options. @@ -450,9 +500,8 @@ for the list of available options. ```js title="medusa-config.js" module.exports = { projectConfig: { - redis_options: { - connectionName: process.env.REDIS_CONNECTION_NAME || - "medusa", + redisOptions: { + connectionName: process.env.REDIS_CONNECTION_NAME || "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). @@ -469,9 +518,8 @@ An object of options to pass to [express-session](https://www.npmjs.com/package/ ```js title="medusa-config.js" module.exports = { projectConfig: { - session_options: { - name: process.env.SESSION_NAME || - "custom", + sessionOptions: { + name: process.env.SESSION_NAME || "custom", }, // ... }, @@ -481,9 +529,73 @@ module.exports = { #### Properties - + -### 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. 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 - + -### jobs\_batch\_size +### jobs_batch_size 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" module.exports = { projectConfig: { - jobs_batch_size: 100 + jobs_batch_size: 100, // ... }, // ... } ``` -### worker\_mode +### worker_mode 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" module.exports = { projectConfig: { - worker_mode: "shared" + worker_mode: "shared", // ... }, // ... } ``` -___ +--- ## 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. - An object having the following properties: - - `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. + - `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. ### Example @@ -576,8 +732,7 @@ module.exports = { { resolve: `medusa-my-plugin`, options: { - apiKey: process.env.MY_API_KEY || - `test`, + apiKey: process.env.MY_API_KEY || `test`, }, }, // ... @@ -586,7 +741,7 @@ module.exports = { } ``` -___ +--- ## 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; 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. `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. ### Example @@ -627,7 +782,7 @@ module.exports = { } ``` -___ +--- ## featureFlags From abd864d9a246889167bce5bef78e661de3ebadc3 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 28 May 2024 17:26:28 +0530 Subject: [PATCH 3/3] refactor: update more references --- integration-tests/api/__tests__/database/index.js | 2 +- integration-tests/environment-helpers/use-db.js | 4 ++-- .../src/loaders/helpers/routing/__fixtures__/mocks/index.ts | 2 +- packages/modules/event-bus-redis/src/loaders/index.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-tests/api/__tests__/database/index.js b/integration-tests/api/__tests__/database/index.js index 824388021348d..1e3dcc3bffb4d 100644 --- a/integration-tests/api/__tests__/database/index.js +++ b/integration-tests/api/__tests__/database/index.js @@ -13,7 +13,7 @@ describe("Database options", () => { const cwd = path.resolve(path.join(__dirname, "..", "..")) dbConnection = await initDb({ cwd, - database_extra: { idle_in_transaction_session_timeout: 1000 }, + databaseExtra: { idle_in_transaction_session_timeout: 1000 }, }) medusaProcess = await setupServer({ cwd }) }) diff --git a/integration-tests/environment-helpers/use-db.js b/integration-tests/environment-helpers/use-db.js index 09f5e6d1e59e7..20e1f45601ded 100644 --- a/integration-tests/environment-helpers/use-db.js +++ b/integration-tests/environment-helpers/use-db.js @@ -91,7 +91,7 @@ const instance = DbTestUtil module.exports = { initDb: async function ({ cwd, - database_extra, + databaseExtra, env, force_modules_migration, }) { @@ -145,7 +145,7 @@ module.exports = { url: DB_URL, entities: enabledEntities.concat(moduleModels), migrations: enabledMigrations.concat(moduleMigrations), - extra: database_extra ?? {}, + extra: databaseExtra ?? {}, name: "integration-tests", }) diff --git a/packages/medusa/src/loaders/helpers/routing/__fixtures__/mocks/index.ts b/packages/medusa/src/loaders/helpers/routing/__fixtures__/mocks/index.ts index ddaf7beb400e0..2d48ddbce8b11 100644 --- a/packages/medusa/src/loaders/helpers/routing/__fixtures__/mocks/index.ts +++ b/packages/medusa/src/loaders/helpers/routing/__fixtures__/mocks/index.ts @@ -6,7 +6,7 @@ export const storeGlobalMiddlewareMock = jest.fn() export const config: ConfigModule = { projectConfig: { - database_logging: false, + databaseLogging: false, http: { authCors: "http://localhost:9000", storeCors: "http://localhost:8000", diff --git a/packages/modules/event-bus-redis/src/loaders/index.ts b/packages/modules/event-bus-redis/src/loaders/index.ts index 40028b57e1741..29e35ae3661c4 100644 --- a/packages/modules/event-bus-redis/src/loaders/index.ts +++ b/packages/modules/event-bus-redis/src/loaders/index.ts @@ -13,7 +13,7 @@ export default async ({ if (!redisUrl) { 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 { - await new Promise(async resolve => { + await new Promise(async (resolve) => { await connection.connect(resolve) }) logger?.info(`Connection to Redis in module 'event-bus-redis' established`)