@medusajs/framework 0.0.2-snapshot-20240821132459 → 0.0.2-snapshot-20240821152538
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/config/__fixtures__/medusa-config-2.d.ts +3 -0
- package/dist/config/__fixtures__/medusa-config-2.d.ts.map +1 -0
- package/dist/config/__fixtures__/medusa-config-2.js +8 -0
- package/dist/config/__fixtures__/medusa-config.d.ts +3 -0
- package/dist/config/__fixtures__/medusa-config.d.ts.map +1 -0
- package/dist/config/__fixtures__/medusa-config.js +4 -0
- package/dist/config/__tests__/index.spec.d.ts +2 -0
- package/dist/config/__tests__/index.spec.d.ts.map +1 -0
- package/dist/config/__tests__/index.spec.js +28 -0
- package/dist/config/types.d.ts +120 -58
- package/dist/config/types.d.ts.map +1 -1
- package/dist/feature-flags/__tests__/feature-flags.spec.d.ts +2 -0
- package/dist/feature-flags/__tests__/feature-flags.spec.d.ts.map +1 -0
- package/dist/feature-flags/__tests__/feature-flags.spec.js +82 -0
- package/dist/http/__fixtures__/mocks/index.d.ts +7 -0
- package/dist/http/__fixtures__/mocks/index.d.ts.map +1 -0
- package/dist/http/__fixtures__/mocks/index.js +20 -0
- package/dist/http/__fixtures__/routers/_private/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers/_private/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/_private/route.js +7 -0
- package/dist/http/__fixtures__/routers/admin/orders/[id]/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers/admin/orders/[id]/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/admin/orders/[id]/route.js +21 -0
- package/dist/http/__fixtures__/routers/admin/orders/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers/admin/orders/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/admin/orders/route.js +7 -0
- package/dist/http/__fixtures__/routers/admin/products/[id]/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers/admin/products/[id]/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/admin/products/[id]/route.js +7 -0
- package/dist/http/__fixtures__/routers/admin/products/route.d.ts +9 -0
- package/dist/http/__fixtures__/routers/admin/products/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/admin/products/route.js +31 -0
- package/dist/http/__fixtures__/routers/admin/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers/admin/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/admin/route.js +11 -0
- package/dist/http/__fixtures__/routers/customers/[customer_id]/orders/[order_id]/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers/customers/[customer_id]/orders/[order_id]/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/customers/[customer_id]/orders/[order_id]/route.js +9 -0
- package/dist/http/__fixtures__/routers/customers/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers/customers/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers/customers/route.js +7 -0
- package/dist/http/__fixtures__/routers-duplicate-parameter/admin/customers/[id]/orders/[id]/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers-duplicate-parameter/admin/customers/[id]/orders/[id]/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-duplicate-parameter/admin/customers/[id]/orders/[id]/route.js +11 -0
- package/dist/http/__fixtures__/routers-error-handler/middlewares.d.ts +3 -0
- package/dist/http/__fixtures__/routers-error-handler/middlewares.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-error-handler/middlewares.js +39 -0
- package/dist/http/__fixtures__/routers-error-handler/store/route.d.ts +5 -0
- package/dist/http/__fixtures__/routers-error-handler/store/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-error-handler/store/route.js +31 -0
- package/dist/http/__fixtures__/routers-middleware/admin/protected/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/admin/protected/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/admin/protected/route.js +7 -0
- package/dist/http/__fixtures__/routers-middleware/admin/unprotected/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers-middleware/admin/unprotected/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/admin/unprotected/route.js +8 -0
- package/dist/http/__fixtures__/routers-middleware/customers/error/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/customers/error/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/customers/error/route.js +8 -0
- package/dist/http/__fixtures__/routers-middleware/customers/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers-middleware/customers/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/customers/route.js +11 -0
- package/dist/http/__fixtures__/routers-middleware/middlewares.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/middlewares.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/middlewares.js +38 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/protected/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/protected/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/protected/route.js +7 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/unprotected/route.d.ts +4 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/unprotected/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/store/customers/me/unprotected/route.js +8 -0
- package/dist/http/__fixtures__/routers-middleware/store/products/[id]/sync/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/store/products/[id]/sync/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/store/products/[id]/sync/route.js +7 -0
- package/dist/http/__fixtures__/routers-middleware/webhooks/payment/route.d.ts +3 -0
- package/dist/http/__fixtures__/routers-middleware/webhooks/payment/route.d.ts.map +1 -0
- package/dist/http/__fixtures__/routers-middleware/webhooks/payment/route.js +10 -0
- package/dist/http/__fixtures__/server/index.d.ts +9 -0
- package/dist/http/__fixtures__/server/index.d.ts.map +1 -0
- package/dist/http/__fixtures__/server/index.js +142 -0
- package/dist/http/__tests__/index.spec.d.ts +2 -0
- package/dist/http/__tests__/index.spec.d.ts.map +1 -0
- package/dist/http/__tests__/index.spec.js +182 -0
- package/dist/jobs/__fixtures__/mock-scheduler-storage.d.ts +9 -0
- package/dist/jobs/__fixtures__/mock-scheduler-storage.d.ts.map +1 -0
- package/dist/jobs/__fixtures__/mock-scheduler-storage.js +15 -0
- package/dist/jobs/__fixtures__/plugin/jobs/order-summary.d.ts +8 -0
- package/dist/jobs/__fixtures__/plugin/jobs/order-summary.d.ts.map +1 -0
- package/dist/jobs/__fixtures__/plugin/jobs/order-summary.js +12 -0
- package/dist/jobs/__tests__/register-jobs.spec.d.ts +2 -0
- package/dist/jobs/__tests__/register-jobs.spec.d.ts.map +1 -0
- package/dist/jobs/__tests__/register-jobs.spec.js +22 -0
- package/dist/links/__fixtures__/links/link.d.ts +2 -0
- package/dist/links/__fixtures__/links/link.d.ts.map +1 -0
- package/dist/links/__fixtures__/links/link.js +19 -0
- package/dist/links/__fixtures__/links/sub-links/link.d.ts +2 -0
- package/dist/links/__fixtures__/links/sub-links/link.d.ts.map +1 -0
- package/dist/links/__fixtures__/links/sub-links/link.js +19 -0
- package/dist/links/__tests__/index.spec.d.ts +2 -0
- package/dist/links/__tests__/index.spec.d.ts.map +1 -0
- package/dist/links/__tests__/index.spec.js +15 -0
- package/dist/subscribers/__fixtures__/subscribers/order-notifier.d.ts +4 -0
- package/dist/subscribers/__fixtures__/subscribers/order-notifier.d.ts.map +1 -0
- package/dist/subscribers/__fixtures__/subscribers/order-notifier.js +11 -0
- package/dist/subscribers/__fixtures__/subscribers/product-updater.d.ts +4 -0
- package/dist/subscribers/__fixtures__/subscribers/product-updater.d.ts.map +1 -0
- package/dist/subscribers/__fixtures__/subscribers/product-updater.js +13 -0
- package/dist/subscribers/__fixtures__/subscribers/variant-created.d.ts +4 -0
- package/dist/subscribers/__fixtures__/subscribers/variant-created.d.ts.map +1 -0
- package/dist/subscribers/__fixtures__/subscribers/variant-created.js +10 -0
- package/dist/subscribers/__mocks__/index.d.ts +5 -0
- package/dist/subscribers/__mocks__/index.d.ts.map +1 -0
- package/dist/subscribers/__mocks__/index.js +8 -0
- package/dist/subscribers/__tests__/index.spec.d.ts +2 -0
- package/dist/subscribers/__tests__/index.spec.d.ts.map +1 -0
- package/dist/subscribers/__tests__/index.spec.js +81 -0
- package/dist/workflows/__fixtures__/workflows/deep-workflows/product-updater.d.ts +3 -0
- package/dist/workflows/__fixtures__/workflows/deep-workflows/product-updater.d.ts.map +1 -0
- package/dist/workflows/__fixtures__/workflows/deep-workflows/product-updater.js +12 -0
- package/dist/workflows/__fixtures__/workflows/order-notifier.d.ts +3 -0
- package/dist/workflows/__fixtures__/workflows/order-notifier.d.ts.map +1 -0
- package/dist/workflows/__fixtures__/workflows/order-notifier.js +12 -0
- package/dist/workflows/__tests__/index.spec.d.ts +2 -0
- package/dist/workflows/__tests__/index.spec.d.ts.map +1 -0
- package/dist/workflows/__tests__/index.spec.js +19 -0
- package/package.json +10 -10
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"medusa-config-2.d.ts","sourceRoot":"","sources":["../../../src/config/__fixtures__/medusa-config-2.js"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"medusa-config.d.ts","sourceRoot":"","sources":["../../../src/config/__fixtures__/medusa-config.js"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../src/config/__tests__/index.spec.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const loader_1 = require("../loader");
|
4
|
+
const path_1 = require("path");
|
5
|
+
const container_1 = require("../../container");
|
6
|
+
const utils_1 = require("@medusajs/utils");
|
7
|
+
describe("configLoader", () => {
|
8
|
+
const entryDirectory = (0, path_1.join)(__dirname, "../__fixtures__");
|
9
|
+
it("should load the config properly", async () => {
|
10
|
+
let configModule = container_1.container.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
11
|
+
expect(configModule).toBeUndefined();
|
12
|
+
(0, loader_1.configLoader)(entryDirectory, "medusa-config.js");
|
13
|
+
configModule = container_1.container.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
14
|
+
expect(configModule).toBeDefined();
|
15
|
+
expect(configModule.projectConfig.databaseName).toBeUndefined();
|
16
|
+
(0, loader_1.configLoader)(entryDirectory, "medusa-config-2.js");
|
17
|
+
configModule = container_1.container.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
18
|
+
expect(configModule).toBeDefined();
|
19
|
+
expect(configModule.projectConfig.databaseName).toBe("foo");
|
20
|
+
expect(configModule.projectConfig.workerMode).toBe("shared");
|
21
|
+
process.env.MEDUSA_WORKER_MODE = "worker";
|
22
|
+
(0, loader_1.configLoader)(entryDirectory, "medusa-config-2.js");
|
23
|
+
configModule = container_1.container.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
24
|
+
expect(configModule).toBeDefined();
|
25
|
+
expect(configModule.projectConfig.databaseName).toBe("foo");
|
26
|
+
expect(configModule.projectConfig.workerMode).toBe("worker");
|
27
|
+
});
|
28
|
+
});
|
package/dist/config/types.d.ts
CHANGED
@@ -10,6 +10,17 @@ export type AdminOptions = {
|
|
10
10
|
/**
|
11
11
|
* Whether to disable the admin dashboard. If set to `true`, the admin dashboard is disabled,
|
12
12
|
* in both development and production environments. The default value is `false`.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* ```js title="medusa-config.js"
|
16
|
+
* module.exports = defineConfig({
|
17
|
+
* admin: {
|
18
|
+
* disable: process.env.ADMIN_DISABLED === "true" ||
|
19
|
+
* false
|
20
|
+
* },
|
21
|
+
* // ...
|
22
|
+
* })
|
23
|
+
* ```
|
13
24
|
*/
|
14
25
|
disable?: boolean;
|
15
26
|
/**
|
@@ -20,15 +31,46 @@ export type AdminOptions = {
|
|
20
31
|
* - `/store`
|
21
32
|
* - `/auth`
|
22
33
|
* - `/`
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* ```js title="medusa-config.js"
|
37
|
+
* module.exports = defineConfig({
|
38
|
+
* admin: {
|
39
|
+
* path: process.env.ADMIN_PATH || `/app`,
|
40
|
+
* },
|
41
|
+
* // ...
|
42
|
+
* })
|
43
|
+
* ```
|
23
44
|
*/
|
24
45
|
path?: `/${string}`;
|
25
46
|
/**
|
26
|
-
* The directory where the admin build is
|
47
|
+
* The directory where the admin build is outputted when you run the `build` command.
|
27
48
|
* The default value is `./build`.
|
49
|
+
*
|
50
|
+
* @example
|
51
|
+
* ```js title="medusa-config.js"
|
52
|
+
* module.exports = defineConfig({
|
53
|
+
* admin: {
|
54
|
+
* outDir: process.env.ADMIN_BUILD_DIR || `./build`,
|
55
|
+
* },
|
56
|
+
* // ...
|
57
|
+
* })
|
58
|
+
* ```
|
28
59
|
*/
|
29
60
|
outDir?: string;
|
30
61
|
/**
|
31
|
-
* The URL of your Medusa
|
62
|
+
* The URL of your Medusa application. This is useful to set when you deploy the Medusa application.
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* ```js title="medusa-config.js"
|
66
|
+
* module.exports = defineConfig({
|
67
|
+
* admin: {
|
68
|
+
* backendUrl: process.env.MEDUSA_BACKEND_URL ||
|
69
|
+
* "http://localhost:9000"
|
70
|
+
* },
|
71
|
+
* // ...
|
72
|
+
* })
|
73
|
+
* ```
|
32
74
|
*/
|
33
75
|
backendUrl?: string;
|
34
76
|
/**
|
@@ -105,11 +147,11 @@ export type HttpCompressionOptions = {
|
|
105
147
|
/**
|
106
148
|
* @interface
|
107
149
|
*
|
108
|
-
* Essential configurations related to the Medusa
|
150
|
+
* Essential configurations related to the Medusa application, such as database and CORS configurations.
|
109
151
|
*/
|
110
152
|
export type ProjectConfigOptions = {
|
111
153
|
/**
|
112
|
-
* The name of the database to connect to. If specified in `databaseUrl`, then
|
154
|
+
* The name of the database to connect to. If the name is specified in `databaseUrl`, then you don't have to use this configuration.
|
113
155
|
*
|
114
156
|
* Make sure to create the PostgreSQL database before using it. You can check how to create a database in
|
115
157
|
* [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html).
|
@@ -128,7 +170,7 @@ export type ProjectConfigOptions = {
|
|
128
170
|
*/
|
129
171
|
databaseName?: string;
|
130
172
|
/**
|
131
|
-
* The connection URL of the database
|
173
|
+
* The PostgreSQL connection URL of the database, which is of the following format:
|
132
174
|
*
|
133
175
|
* ```bash
|
134
176
|
* postgres://[user][:password]@[host][:port]/[dbname]
|
@@ -180,19 +222,13 @@ export type ProjectConfigOptions = {
|
|
180
222
|
*/
|
181
223
|
databaseSchema?: string;
|
182
224
|
/**
|
183
|
-
* This configuration specifies
|
184
|
-
*
|
185
|
-
* - (default) A boolean value that indicates whether any messages should be logged.
|
186
|
-
* - The string value `all` that indicates all types of messages should be logged.
|
187
|
-
* - An array of log-level strings to indicate which type of messages to show in the logs. The strings can be `query`, `schema`, `error`, `warn`, `info`, `log`, or `migration`. Refer to [Typeorm’s documentation](https://typeorm.io/logging#logging-options) for more details on what each of these values means.
|
188
|
-
*
|
189
|
-
* If this configuration isn't set, its default value is `false`, meaning no database messages are logged.
|
225
|
+
* This configuration specifies whether database messages should be logged.
|
190
226
|
*
|
191
227
|
* @example
|
192
228
|
* ```js title="medusa-config.js"
|
193
229
|
* module.exports = defineConfig({
|
194
230
|
* projectConfig: {
|
195
|
-
* databaseLogging:
|
231
|
+
* databaseLogging: false
|
196
232
|
* // ...
|
197
233
|
* },
|
198
234
|
* // ...
|
@@ -209,12 +245,18 @@ export type ProjectConfigOptions = {
|
|
209
245
|
*/
|
210
246
|
databaseType?: string;
|
211
247
|
/**
|
212
|
-
*
|
213
|
-
* `ssl`
|
248
|
+
* This configuration is used to pass additional options to the database connection. You can pass any configuration. For example, pass the
|
249
|
+
* `ssl` property that enables support for TLS/SSL connections.
|
214
250
|
*
|
215
251
|
* This is useful for production databases, which can be supported by setting the `rejectUnauthorized` attribute of `ssl` object to `false`.
|
216
252
|
* During development, it’s recommended not to pass this option.
|
217
253
|
*
|
254
|
+
* :::note
|
255
|
+
*
|
256
|
+
* Make sure to add to the end of the database URL `?ssl_mode=disable` as well when disabling `rejectUnauthorized`.
|
257
|
+
*
|
258
|
+
* :::
|
259
|
+
*
|
218
260
|
* @example
|
219
261
|
* ```js title="medusa-config.js"
|
220
262
|
* module.exports = defineConfig({
|
@@ -241,7 +283,7 @@ export type ProjectConfigOptions = {
|
|
241
283
|
};
|
242
284
|
};
|
243
285
|
/**
|
244
|
-
*
|
286
|
+
* This configuration specifies the connection URL to Redis to store the Medusa server's session.
|
245
287
|
*
|
246
288
|
* :::note
|
247
289
|
*
|
@@ -271,7 +313,7 @@ export type ProjectConfigOptions = {
|
|
271
313
|
*/
|
272
314
|
redisUrl?: string;
|
273
315
|
/**
|
274
|
-
*
|
316
|
+
* This configuration defines a prefix on all keys stored in Redis for the Medusa server's session. The default value is `sess:`.
|
275
317
|
*
|
276
318
|
* If this configuration option is provided, it is prepended to `sess:`.
|
277
319
|
*
|
@@ -288,7 +330,7 @@ export type ProjectConfigOptions = {
|
|
288
330
|
*/
|
289
331
|
redisPrefix?: string;
|
290
332
|
/**
|
291
|
-
*
|
333
|
+
* This configuration defines options to pass ioredis for the Redis connection used to store the Medusa server's session. Refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions)
|
292
334
|
* for the list of available options.
|
293
335
|
*
|
294
336
|
* @example
|
@@ -307,7 +349,7 @@ export type ProjectConfigOptions = {
|
|
307
349
|
*/
|
308
350
|
redisOptions?: RedisOptions;
|
309
351
|
/**
|
310
|
-
*
|
352
|
+
* This configuration defines additional options to pass to [express-session](https://www.npmjs.com/package/express-session), which is used to store the Medusa server's session.
|
311
353
|
*
|
312
354
|
* @example
|
313
355
|
* ```js title="medusa-config.js"
|
@@ -324,7 +366,7 @@ export type ProjectConfigOptions = {
|
|
324
366
|
*/
|
325
367
|
sessionOptions?: SessionOptions;
|
326
368
|
/**
|
327
|
-
*
|
369
|
+
* This property configures the HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
|
328
370
|
* However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.
|
329
371
|
*
|
330
372
|
* 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`.
|
@@ -348,22 +390,38 @@ export type ProjectConfigOptions = {
|
|
348
390
|
* // ...
|
349
391
|
* })
|
350
392
|
* ```
|
393
|
+
*
|
394
|
+
* @ignore
|
395
|
+
*
|
396
|
+
* @privateRemarks
|
397
|
+
* Couldn't find any use for this option.
|
351
398
|
*/
|
352
399
|
jobsBatchSize?: number;
|
353
400
|
/**
|
354
|
-
* Configure the application's worker mode.
|
401
|
+
* Configure the application's worker mode.
|
402
|
+
*
|
403
|
+
* Workers are processes running separately from the main application. They're useful for executing long-running or resource-heavy tasks in the background, such as importing products.
|
404
|
+
*
|
405
|
+
* With a worker, these tasks are offloaded to a separate process. So, they won't affect the performance of the main application.
|
406
|
+
*
|
407
|
+
* ![Diagram showcasing how the server and worker work together](https://res.cloudinary.com/dza7lstvk/image/upload/fl_lossy/f_auto/r_16/ar_16:9,c_pad/v1/Medusa%20Book/medusa-worker_klkbch.jpg?_a=BATFJtAA0)
|
408
|
+
*
|
409
|
+
* Medusa has three runtime modes:
|
355
410
|
*
|
356
411
|
* - Use `shared` to run the application in a single process.
|
357
412
|
* - Use `worker` to run the a worker process only.
|
358
413
|
* - Use `server` to run the application server only.
|
359
414
|
*
|
360
|
-
*
|
415
|
+
* In production, it's recommended to deploy two instances:
|
416
|
+
*
|
417
|
+
* 1. One having the `workerMode` configuration set to `server`.
|
418
|
+
* 2. Another having the `workerMode` configuration set to `worker`.
|
361
419
|
*
|
362
420
|
* @example
|
363
421
|
* ```js title="medusa-config.js"
|
364
422
|
* module.exports = defineConfig({
|
365
423
|
* projectConfig: {
|
366
|
-
* workerMode: "shared"
|
424
|
+
* workerMode: process.env.WORKER_MODE || "shared"
|
367
425
|
* // ...
|
368
426
|
* },
|
369
427
|
* // ...
|
@@ -372,7 +430,7 @@ export type ProjectConfigOptions = {
|
|
372
430
|
*/
|
373
431
|
workerMode?: "shared" | "worker" | "server";
|
374
432
|
/**
|
375
|
-
*
|
433
|
+
* This property configures the application's http-specific settings.
|
376
434
|
*
|
377
435
|
* @example
|
378
436
|
* ```js title="medusa-config.js"
|
@@ -394,8 +452,8 @@ export type ProjectConfigOptions = {
|
|
394
452
|
/**
|
395
453
|
* A random string used to create authentication tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.
|
396
454
|
*
|
397
|
-
* In a development environment, if this option is not set the default secret is `supersecret
|
398
|
-
* error is thrown and the
|
455
|
+
* In a development environment, if this option is not set the default secret is `supersecret`. However, in production, if this configuration is not set, an
|
456
|
+
* error is thrown and the application crashes.
|
399
457
|
*
|
400
458
|
* @example
|
401
459
|
* ```js title="medusa-config.js"
|
@@ -412,7 +470,9 @@ export type ProjectConfigOptions = {
|
|
412
470
|
*/
|
413
471
|
jwtSecret?: string;
|
414
472
|
/**
|
415
|
-
* The expiration time for the JWT token.
|
473
|
+
* The expiration time for the JWT token. Its format is based off the [ms package](https://github.com/vercel/ms).
|
474
|
+
*
|
475
|
+
* If not provided, the default value is `24h`.
|
416
476
|
*
|
417
477
|
* @example
|
418
478
|
* ```js title="medusa-config.js"
|
@@ -431,8 +491,8 @@ export type ProjectConfigOptions = {
|
|
431
491
|
/**
|
432
492
|
* A random string used to create cookie tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.
|
433
493
|
*
|
434
|
-
* In a development environment, if this option is not set, the default secret is `supersecret
|
435
|
-
* the
|
494
|
+
* In a development environment, if this option is not set, the default secret is `supersecret`. However, in production, if this configuration is not set, an error is thrown and
|
495
|
+
* the application crashes.
|
436
496
|
*
|
437
497
|
* @example
|
438
498
|
* ```js title="medusa-config.js"
|
@@ -449,14 +509,14 @@ export type ProjectConfigOptions = {
|
|
449
509
|
*/
|
450
510
|
cookieSecret?: string;
|
451
511
|
/**
|
452
|
-
* The Medusa
|
512
|
+
* The Medusa application'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.
|
453
513
|
*
|
454
514
|
* `cors` is a string used to specify the accepted URLs or patterns for API Routes starting with `/auth`. It can either be one accepted origin, or a comma-separated list of accepted origins.
|
455
515
|
*
|
456
516
|
* Every origin in that list must either be:
|
457
517
|
*
|
458
518
|
* 1. A URL. For example, `http://localhost:7001`. The URL must not end with a backslash;
|
459
|
-
* 2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that
|
519
|
+
* 2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([\/~@;%#'])(.*?)\1([gimsuy]*)$`.
|
460
520
|
*
|
461
521
|
* @example
|
462
522
|
* Some example values of common use cases:
|
@@ -506,9 +566,8 @@ export type ProjectConfigOptions = {
|
|
506
566
|
* Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
|
507
567
|
* However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.
|
508
568
|
*
|
509
|
-
* Its value is an object that has the following properties:
|
510
|
-
*
|
511
569
|
* 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`.
|
570
|
+
* Learn more in the [API Reference](https://docs.medusajs.com/v2/api/store#http-compression).
|
512
571
|
*
|
513
572
|
* @example
|
514
573
|
* ```js title="medusa-config.js"
|
@@ -530,7 +589,7 @@ export type ProjectConfigOptions = {
|
|
530
589
|
*/
|
531
590
|
compression?: HttpCompressionOptions;
|
532
591
|
/**
|
533
|
-
* The Medusa
|
592
|
+
* The Medusa application'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.
|
534
593
|
*
|
535
594
|
* `store_cors` is a string used to specify the accepted URLs or patterns for store API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.
|
536
595
|
*
|
@@ -583,7 +642,7 @@ export type ProjectConfigOptions = {
|
|
583
642
|
*/
|
584
643
|
storeCors: string;
|
585
644
|
/**
|
586
|
-
* The Medusa
|
645
|
+
* The Medusa application'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.
|
587
646
|
*
|
588
647
|
* `admin_cors` is a string used to specify the accepted URLs or patterns for admin API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.
|
589
648
|
*
|
@@ -636,11 +695,10 @@ export type ProjectConfigOptions = {
|
|
636
695
|
*/
|
637
696
|
adminCors: string;
|
638
697
|
/**
|
639
|
-
*
|
640
|
-
* For example, you only want to allow SSO logins for `users
|
641
|
-
*
|
642
|
-
* `authMethodsPerActor` is a a map where the actor type (eg. 'user') is the key, and an array of supported auth providers as the value.
|
698
|
+
* This configuration specifies the supported authentication providers per actor type (such as `user`, `customer`, or any custom actors).
|
699
|
+
* For example, you only want to allow SSO logins for `users`, while you want to allow email/password logins for `customers` to the storefront.
|
643
700
|
*
|
701
|
+
* `authMethodsPerActor` is a a map where the actor type (eg. 'user') is the key, and the value is an array of supported auth provider IDs.
|
644
702
|
*
|
645
703
|
* @example
|
646
704
|
* Some example values of common use cases:
|
@@ -653,7 +711,7 @@ export type ProjectConfigOptions = {
|
|
653
711
|
* http: {
|
654
712
|
* authMethodsPerActor: {
|
655
713
|
* user: ["email"],
|
656
|
-
* customer: ["
|
714
|
+
* customer: ["emailpass", "google"]
|
657
715
|
* }
|
658
716
|
* }
|
659
717
|
* // ...
|
@@ -668,14 +726,15 @@ export type ProjectConfigOptions = {
|
|
668
726
|
/**
|
669
727
|
* @interface
|
670
728
|
*
|
671
|
-
* The configurations for your Medusa
|
729
|
+
* The configurations for your Medusa application are in `medusa-config.js` located in the root of your Medusa project. The configurations include configurations for database, modules, and more.
|
672
730
|
*
|
673
|
-
* `medusa-config.js` exports
|
731
|
+
* `medusa-config.js` exports the value returned by the `defineConfig` utility function imported from `@medusajs/utils`.
|
674
732
|
*
|
675
|
-
*
|
733
|
+
* `defineConfig` accepts as a parameter an object with the following properties:
|
734
|
+
*
|
735
|
+
* - {@link ConfigModule.projectConfig | projectConfig} (required): An object that holds general configurations related to the Medusa application, such as database or CORS configurations.
|
676
736
|
* - {@link ConfigModule.admin | admin}: An object that holds admin-related configurations.
|
677
|
-
* - {@link ConfigModule.
|
678
|
-
* - {@link ConfigModule.modules | modules}: An object that defines what modules are installed and optionally specifies each of their configurations.
|
737
|
+
* - {@link ConfigModule.modules | modules}: An object that configures the Medusa application's modules.
|
679
738
|
* - {@link ConfigModule.featureFlags | featureFlags}: An object that enables or disables features guarded by a feature flag.
|
680
739
|
*
|
681
740
|
* For example:
|
@@ -703,18 +762,18 @@ export type ProjectConfigOptions = {
|
|
703
762
|
*
|
704
763
|
* It's highly recommended to store the values of configurations in environment variables, then reference them within `medusa-config.js`.
|
705
764
|
*
|
706
|
-
* During development, you can set your environment variables in the `.env` file at the root of your Medusa
|
765
|
+
* During development, you can set your environment variables in the `.env` file at the root of your Medusa application project. In production,
|
707
766
|
* setting the environment variables depends on the hosting provider.
|
708
767
|
*
|
709
768
|
* ---
|
710
769
|
*/
|
711
770
|
export type ConfigModule = {
|
712
771
|
/**
|
713
|
-
* This property holds essential configurations related to the Medusa
|
772
|
+
* This property holds essential configurations related to the Medusa application, such as database and CORS configurations.
|
714
773
|
*/
|
715
774
|
projectConfig: ProjectConfigOptions;
|
716
775
|
/**
|
717
|
-
* Admin dashboard
|
776
|
+
* This property holds configurations for the Medusa Admin dashboard.
|
718
777
|
*
|
719
778
|
* @example
|
720
779
|
* ```js title="medusa-config.js"
|
@@ -769,18 +828,21 @@ export type ConfigModule = {
|
|
769
828
|
options: Record<string, unknown>;
|
770
829
|
} | string)[];
|
771
830
|
/**
|
772
|
-
*
|
773
|
-
* with custom implementations.
|
831
|
+
* This property holds all custom modules installed in your Medusa application.
|
774
832
|
*
|
775
|
-
*
|
833
|
+
* :::note
|
834
|
+
*
|
835
|
+
* Medusa's commerce modules are configured by default, so only
|
836
|
+
* add them to this property if you're changing their configurations or adding providers to a module.
|
837
|
+
*
|
838
|
+
* :::
|
776
839
|
*
|
777
840
|
* The keys of the `modules` configuration object refer to the module's registration name. Its value can be one of the following:
|
778
841
|
*
|
779
842
|
* 1. A boolean value indicating whether the module type is enabled. This is only supported for Medusa's commerce and architectural modules;
|
780
843
|
* 2. Or an object having the following properties:
|
781
|
-
* 1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name.
|
844
|
+
* 1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name. For example, `./modules/my-module`.
|
782
845
|
* 2. `options`: (optional) an object indicating the options to pass to the module.
|
783
|
-
* 3. `definition`: (optional) an object of extra configurations, such as `isQueryable` used when a module has relationships.
|
784
846
|
*
|
785
847
|
* @example
|
786
848
|
* ```js title="medusa-config.js"
|
@@ -796,12 +858,12 @@ export type ConfigModule = {
|
|
796
858
|
*/
|
797
859
|
modules?: Record<string, boolean | Partial<InternalModuleDeclaration | ExternalModuleDeclaration>>;
|
798
860
|
/**
|
799
|
-
* Some features in the Medusa
|
861
|
+
* Some features in the Medusa application are guarded by a feature flag. This ensures constant shipping of new features while maintaining the engine’s stability.
|
800
862
|
*
|
801
|
-
* You can
|
802
|
-
* variables or through this configuration exported in `medusa-config.js`.
|
863
|
+
* You can enable a feature in your application by enabling its feature flag. Feature flags are enabled through either environment
|
864
|
+
* variables or through this configuration property exported in `medusa-config.js`.
|
803
865
|
*
|
804
|
-
* The `featureFlags`
|
866
|
+
* The `featureFlags`'s value is an object. Its properties are the names of the feature flags, and their value is a boolean indicating whether the feature flag is enabled.
|
805
867
|
*
|
806
868
|
* You can find available feature flags and their key name [here](https://github.com/medusajs/medusa/tree/develop/packages/medusa/src/loaders/feature-flags).
|
807
869
|
*
|
@@ -809,7 +871,7 @@ export type ConfigModule = {
|
|
809
871
|
* ```js title="medusa-config.js"
|
810
872
|
* module.exports = defineConfig({
|
811
873
|
* featureFlags: {
|
812
|
-
*
|
874
|
+
* analytics: true,
|
813
875
|
* // ...
|
814
876
|
* }
|
815
877
|
* // ...
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"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"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"feature-flags.spec.d.ts","sourceRoot":"","sources":["../../../src/feature-flags/__tests__/feature-flags.spec.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("@medusajs/utils");
|
4
|
+
const path_1 = require("path");
|
5
|
+
const feature_flag_loader_1 = require("../feature-flag-loader");
|
6
|
+
const config_1 = require("../../config");
|
7
|
+
const filesystem = new utils_1.FileSystem((0, path_1.join)(__dirname, "__ff-test__"));
|
8
|
+
const buildFeatureFlag = (key, defaultVal) => {
|
9
|
+
const snakeCaseKey = key.replace(/-/g, "_");
|
10
|
+
return `
|
11
|
+
export default {
|
12
|
+
description: "${key} descr",
|
13
|
+
key: "${snakeCaseKey}",
|
14
|
+
env_key: "MEDUSA_FF_${snakeCaseKey.toUpperCase()}",
|
15
|
+
default_val: ${defaultVal},
|
16
|
+
}
|
17
|
+
`;
|
18
|
+
};
|
19
|
+
describe("feature flags", () => {
|
20
|
+
const OLD_ENV = { ...process.env };
|
21
|
+
beforeEach(async () => {
|
22
|
+
jest.resetModules();
|
23
|
+
jest.clearAllMocks();
|
24
|
+
process.env = { ...OLD_ENV };
|
25
|
+
await filesystem.cleanup();
|
26
|
+
config_1.configManager.loadConfig({
|
27
|
+
projectConfig: {},
|
28
|
+
baseDir: filesystem.basePath,
|
29
|
+
});
|
30
|
+
});
|
31
|
+
afterAll(async () => {
|
32
|
+
process.env = OLD_ENV;
|
33
|
+
await filesystem.cleanup();
|
34
|
+
});
|
35
|
+
it("should load the flag from project", async () => {
|
36
|
+
config_1.configManager.loadConfig({
|
37
|
+
projectConfig: { featureFlags: { flag_1: false } },
|
38
|
+
baseDir: filesystem.basePath,
|
39
|
+
});
|
40
|
+
await filesystem.create("flags/flag-1.js", buildFeatureFlag("flag-1", true));
|
41
|
+
const flags = await (0, feature_flag_loader_1.featureFlagsLoader)((0, path_1.join)(filesystem.basePath, "flags"));
|
42
|
+
expect(flags.isFeatureEnabled("flag_1")).toEqual(false);
|
43
|
+
});
|
44
|
+
it("should load a nested + simple flag from project", async () => {
|
45
|
+
config_1.configManager.loadConfig({
|
46
|
+
projectConfig: {
|
47
|
+
featureFlags: { test: { nested: true }, simpletest: true },
|
48
|
+
},
|
49
|
+
baseDir: filesystem.basePath,
|
50
|
+
});
|
51
|
+
await filesystem.create("flags/test.js", buildFeatureFlag("test", false));
|
52
|
+
await filesystem.create("flags/simpletest.js", buildFeatureFlag("simpletest", false));
|
53
|
+
const flags = await (0, feature_flag_loader_1.featureFlagsLoader)((0, path_1.join)(filesystem.basePath, "flags"));
|
54
|
+
expect(flags.isFeatureEnabled({ test: "nested" })).toEqual(true);
|
55
|
+
expect(flags.isFeatureEnabled("simpletest")).toEqual(true);
|
56
|
+
});
|
57
|
+
it("should load the default feature flags", async () => {
|
58
|
+
await filesystem.create("flags/flag-1.js", buildFeatureFlag("flag-1", false));
|
59
|
+
const flags = await (0, feature_flag_loader_1.featureFlagsLoader)((0, path_1.join)(filesystem.basePath, "flags"));
|
60
|
+
expect(flags.isFeatureEnabled("flag_1")).toEqual(false);
|
61
|
+
});
|
62
|
+
it("should load the flag from env", async () => {
|
63
|
+
process.env.MEDUSA_FF_FLAG_1 = "false";
|
64
|
+
await filesystem.create("flags/flag-1.js", buildFeatureFlag("flag-1", false));
|
65
|
+
const flags = await (0, feature_flag_loader_1.featureFlagsLoader)((0, path_1.join)(filesystem.basePath, "flags"));
|
66
|
+
expect(flags.isFeatureEnabled("flag_1")).toEqual(false);
|
67
|
+
});
|
68
|
+
it("should load mix of flags", async () => {
|
69
|
+
config_1.configManager.loadConfig({
|
70
|
+
projectConfig: { featureFlags: { flag_2: false } },
|
71
|
+
baseDir: filesystem.basePath,
|
72
|
+
});
|
73
|
+
process.env.MEDUSA_FF_FLAG_3 = "true";
|
74
|
+
await filesystem.create("flags/flag-1.js", buildFeatureFlag("flag-1", false));
|
75
|
+
await filesystem.create("flags/flag-2.js", buildFeatureFlag("flag-2", false));
|
76
|
+
await filesystem.create("flags/flag-3.js", buildFeatureFlag("flag-3", false));
|
77
|
+
const flags = await (0, feature_flag_loader_1.featureFlagsLoader)((0, path_1.join)(filesystem.basePath, "flags"));
|
78
|
+
expect(flags.isFeatureEnabled("flag_1")).toEqual(false);
|
79
|
+
expect(flags.isFeatureEnabled("flag_2")).toEqual(false);
|
80
|
+
expect(flags.isFeatureEnabled("flag_3")).toEqual(true);
|
81
|
+
});
|
82
|
+
});
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="jest" />
|
2
|
+
import { ConfigModule } from "@medusajs/types";
|
3
|
+
export declare const customersGlobalMiddlewareMock: jest.Mock<any, any, any>;
|
4
|
+
export declare const customersCreateMiddlewareMock: jest.Mock<any, any, any>;
|
5
|
+
export declare const storeGlobalMiddlewareMock: jest.Mock<any, any, any>;
|
6
|
+
export declare const config: ConfigModule;
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/http/__fixtures__/mocks/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,eAAO,MAAM,6BAA6B,0BAAY,CAAA;AACtD,eAAO,MAAM,6BAA6B,0BAAY,CAAA;AACtD,eAAO,MAAM,yBAAyB,0BAAY,CAAA;AAElD,eAAO,MAAM,MAAM,EAAE,YAapB,CAAA"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.config = exports.storeGlobalMiddlewareMock = exports.customersCreateMiddlewareMock = exports.customersGlobalMiddlewareMock = void 0;
|
4
|
+
exports.customersGlobalMiddlewareMock = jest.fn();
|
5
|
+
exports.customersCreateMiddlewareMock = jest.fn();
|
6
|
+
exports.storeGlobalMiddlewareMock = jest.fn();
|
7
|
+
exports.config = {
|
8
|
+
projectConfig: {
|
9
|
+
databaseLogging: false,
|
10
|
+
http: {
|
11
|
+
authCors: "http://localhost:9000",
|
12
|
+
storeCors: "http://localhost:8000",
|
13
|
+
adminCors: "http://localhost:7001",
|
14
|
+
jwtSecret: "supersecret",
|
15
|
+
cookieSecret: "superSecret",
|
16
|
+
},
|
17
|
+
},
|
18
|
+
featureFlags: {},
|
19
|
+
plugins: [],
|
20
|
+
};
|