@8medusa/framework 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/build-tools/compiler.d.ts +64 -0
- package/dist/build-tools/compiler.d.ts.map +1 -0
- package/dist/build-tools/compiler.js +419 -0
- package/dist/build-tools/compiler.js.map +1 -0
- package/dist/build-tools/index.d.ts +2 -0
- package/dist/build-tools/index.d.ts.map +1 -0
- package/dist/build-tools/index.js +18 -0
- package/dist/build-tools/index.js.map +1 -0
- package/dist/config/config.d.ts +34 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +134 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +35 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +3 -0
- package/dist/config/types.js.map +1 -0
- package/dist/container.d.ts +3 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +21 -0
- package/dist/container.js.map +1 -0
- package/dist/database/index.d.ts +3 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +19 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/pg-connection-loader.d.ts +6 -0
- package/dist/database/pg-connection-loader.d.ts.map +1 -0
- package/dist/database/pg-connection-loader.js +43 -0
- package/dist/database/pg-connection-loader.js.map +1 -0
- package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
- package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
- package/dist/feature-flags/feature-flag-loader.js +81 -0
- package/dist/feature-flags/feature-flag-loader.js.map +1 -0
- package/dist/feature-flags/flag-router.d.ts +32 -0
- package/dist/feature-flags/flag-router.d.ts.map +1 -0
- package/dist/feature-flags/flag-router.js +67 -0
- package/dist/feature-flags/flag-router.js.map +1 -0
- package/dist/feature-flags/index.d.ts +5 -0
- package/dist/feature-flags/index.d.ts.map +1 -0
- package/dist/feature-flags/index.js +21 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/feature-flags/types.d.ts +31 -0
- package/dist/feature-flags/types.d.ts.map +1 -0
- package/dist/feature-flags/types.js +3 -0
- package/dist/feature-flags/types.js.map +1 -0
- package/dist/http/express-loader.d.ts +8 -0
- package/dist/http/express-loader.d.ts.map +1 -0
- package/dist/http/express-loader.js +128 -0
- package/dist/http/express-loader.js.map +1 -0
- package/dist/http/index.d.ts +15 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +31 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middleware-file-loader.d.ts +33 -0
- package/dist/http/middleware-file-loader.d.ts.map +1 -0
- package/dist/http/middleware-file-loader.js +173 -0
- package/dist/http/middleware-file-loader.js.map +1 -0
- package/dist/http/middlewares/apply-default-filters.d.ts +3 -0
- package/dist/http/middlewares/apply-default-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-default-filters.js +32 -0
- package/dist/http/middlewares/apply-default-filters.js.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts +5 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.js +14 -0
- package/dist/http/middlewares/apply-params-as-filters.js.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts +13 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.js +136 -0
- package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
- package/dist/http/middlewares/bodyparser.d.ts +13 -0
- package/dist/http/middlewares/bodyparser.d.ts.map +1 -0
- package/dist/http/middlewares/bodyparser.js +62 -0
- package/dist/http/middlewares/bodyparser.js.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.js +12 -0
- package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js +45 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
- package/dist/http/middlewares/error-handler.d.ts +21 -0
- package/dist/http/middlewares/error-handler.d.ts.map +1 -0
- package/dist/http/middlewares/error-handler.js +85 -0
- package/dist/http/middlewares/error-handler.js.map +1 -0
- package/dist/http/middlewares/exception-formatter.d.ts +9 -0
- package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
- package/dist/http/middlewares/exception-formatter.js +36 -0
- package/dist/http/middlewares/exception-formatter.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +8 -0
- package/dist/http/middlewares/index.d.ts.map +1 -0
- package/dist/http/middlewares/index.js +24 -0
- package/dist/http/middlewares/index.js.map +1 -0
- package/dist/http/middlewares/set-context.d.ts +3 -0
- package/dist/http/middlewares/set-context.d.ts.map +1 -0
- package/dist/http/middlewares/set-context.js +18 -0
- package/dist/http/middlewares/set-context.js.map +1 -0
- package/dist/http/router.d.ts +28 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +252 -0
- package/dist/http/router.js.map +1 -0
- package/dist/http/routes-finder.d.ts +22 -0
- package/dist/http/routes-finder.d.ts.map +1 -0
- package/dist/http/routes-finder.js +62 -0
- package/dist/http/routes-finder.js.map +1 -0
- package/dist/http/routes-loader.d.ts +30 -0
- package/dist/http/routes-loader.d.ts.map +1 -0
- package/dist/http/routes-loader.js +203 -0
- package/dist/http/routes-loader.js.map +1 -0
- package/dist/http/routes-sorter.d.ts +105 -0
- package/dist/http/routes-sorter.d.ts.map +1 -0
- package/dist/http/routes-sorter.js +146 -0
- package/dist/http/routes-sorter.js.map +1 -0
- package/dist/http/types.d.ts +164 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +16 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/utils/define-middlewares.d.ts +22 -0
- package/dist/http/utils/define-middlewares.d.ts.map +1 -0
- package/dist/http/utils/define-middlewares.js +27 -0
- package/dist/http/utils/define-middlewares.js.map +1 -0
- package/dist/http/utils/get-query-config.d.ts +42 -0
- package/dist/http/utils/get-query-config.d.ts.map +1 -0
- package/dist/http/utils/get-query-config.js +183 -0
- package/dist/http/utils/get-query-config.js.map +1 -0
- package/dist/http/utils/http-compression.d.ts +5 -0
- package/dist/http/utils/http-compression.d.ts.map +1 -0
- package/dist/http/utils/http-compression.js +33 -0
- package/dist/http/utils/http-compression.js.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.js +68 -0
- package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
- package/dist/http/utils/refetch-entities.d.ts +5 -0
- package/dist/http/utils/refetch-entities.d.ts.map +1 -0
- package/dist/http/utils/refetch-entities.js +29 -0
- package/dist/http/utils/refetch-entities.js.map +1 -0
- package/dist/http/utils/restricted-fields.d.ts +6 -0
- package/dist/http/utils/restricted-fields.d.ts.map +1 -0
- package/dist/http/utils/restricted-fields.js +30 -0
- package/dist/http/utils/restricted-fields.js.map +1 -0
- package/dist/http/utils/unless-path.d.ts +9 -0
- package/dist/http/utils/unless-path.d.ts.map +1 -0
- package/dist/http/utils/unless-path.js +19 -0
- package/dist/http/utils/unless-path.js.map +1 -0
- package/dist/http/utils/validate-body.d.ts +5 -0
- package/dist/http/utils/validate-body.d.ts.map +1 -0
- package/dist/http/utils/validate-body.js +23 -0
- package/dist/http/utils/validate-body.js.map +1 -0
- package/dist/http/utils/validate-query.d.ts +6 -0
- package/dist/http/utils/validate-query.d.ts.map +1 -0
- package/dist/http/utils/validate-query.js +79 -0
- package/dist/http/utils/validate-query.js.map +1 -0
- package/dist/http/utils/wrap-handler.d.ts +3 -0
- package/dist/http/utils/wrap-handler.d.ts.map +1 -0
- package/dist/http/utils/wrap-handler.js +26 -0
- package/dist/http/utils/wrap-handler.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/index.d.ts +2 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +18 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/job-loader.d.ts +42 -0
- package/dist/jobs/job-loader.d.ts.map +1 -0
- package/dist/jobs/job-loader.js +78 -0
- package/dist/jobs/job-loader.js.map +1 -0
- package/dist/links/index.d.ts +2 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/index.js +18 -0
- package/dist/links/index.js.map +1 -0
- package/dist/links/link-loader.d.ts +10 -0
- package/dist/links/link-loader.d.ts.map +1 -0
- package/dist/links/link-loader.js +74 -0
- package/dist/links/link-loader.js.map +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +9 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/medusa-app-loader.d.ts +51 -0
- package/dist/medusa-app-loader.d.ts.map +1 -0
- package/dist/medusa-app-loader.js +189 -0
- package/dist/medusa-app-loader.js.map +1 -0
- package/dist/migrations/index.d.ts +3 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +19 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/migrator.d.ts +38 -0
- package/dist/migrations/migrator.d.ts.map +1 -0
- package/dist/migrations/migrator.js +129 -0
- package/dist/migrations/migrator.js.map +1 -0
- package/dist/migrations/run-migration-scripts.d.ts +17 -0
- package/dist/migrations/run-migration-scripts.d.ts.map +1 -0
- package/dist/migrations/run-migration-scripts.js +94 -0
- package/dist/migrations/run-migration-scripts.js.map +1 -0
- package/dist/mikro-orm-cli/bin.d.ts +14 -0
- package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
- package/dist/mikro-orm-cli/bin.js +54 -0
- package/dist/mikro-orm-cli/bin.js.map +1 -0
- package/dist/modules-sdk/index.d.ts +2 -0
- package/dist/modules-sdk/index.d.ts.map +1 -0
- package/dist/modules-sdk/index.js +18 -0
- package/dist/modules-sdk/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +2 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +18 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/subscribers/index.d.ts +3 -0
- package/dist/subscribers/index.d.ts.map +1 -0
- package/dist/subscribers/index.js +19 -0
- package/dist/subscribers/index.js.map +1 -0
- package/dist/subscribers/subscriber-loader.d.ts +12 -0
- package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
- package/dist/subscribers/subscriber-loader.js +147 -0
- package/dist/subscribers/subscriber-loader.js.map +1 -0
- package/dist/subscribers/types.d.ts +15 -0
- package/dist/subscribers/types.d.ts.map +1 -0
- package/dist/subscribers/types.js +3 -0
- package/dist/subscribers/types.js.map +1 -0
- package/dist/telemetry/index.d.ts +50 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +81 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/types/container.d.ts +62 -0
- package/dist/types/container.d.ts.map +1 -0
- package/dist/types/container.js +3 -0
- package/dist/types/container.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/resource-loader.d.ts +26 -0
- package/dist/utils/resource-loader.d.ts.map +1 -0
- package/dist/utils/resource-loader.js +78 -0
- package/dist/utils/resource-loader.js.map +1 -0
- package/dist/workflows/index.d.ts +3 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +19 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/workflow-loader.d.ts +12 -0
- package/dist/workflows/workflow-loader.d.ts.map +1 -0
- package/dist/workflows/workflow-loader.js +24 -0
- package/dist/workflows/workflow-loader.js.map +1 -0
- package/dist/workflows-sdk/composer.d.ts +2 -0
- package/dist/workflows-sdk/composer.d.ts.map +1 -0
- package/dist/workflows-sdk/composer.js +18 -0
- package/dist/workflows-sdk/composer.js.map +1 -0
- package/dist/workflows-sdk/index.d.ts +3 -0
- package/dist/workflows-sdk/index.d.ts.map +1 -0
- package/dist/workflows-sdk/index.js +19 -0
- package/dist/workflows-sdk/index.js.map +1 -0
- package/dist/zod/index.d.ts +2 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +18 -0
- package/dist/zod/index.js.map +1 -0
- package/dist/zod/zod-helpers.d.ts +3 -0
- package/dist/zod/zod-helpers.d.ts.map +1 -0
- package/dist/zod/zod-helpers.js +95 -0
- package/dist/zod/zod-helpers.js.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface IFlagRouter {
|
|
2
|
+
isFeatureEnabled: (key: string) => boolean;
|
|
3
|
+
listFlags: () => FeatureFlagsResponse;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @schema FeatureFlagsResponse
|
|
7
|
+
* type: array
|
|
8
|
+
* items:
|
|
9
|
+
* type: object
|
|
10
|
+
* required:
|
|
11
|
+
* - key
|
|
12
|
+
* - value
|
|
13
|
+
* properties:
|
|
14
|
+
* key:
|
|
15
|
+
* description: The key of the feature flag.
|
|
16
|
+
* type: string
|
|
17
|
+
* value:
|
|
18
|
+
* description: The value of the feature flag.
|
|
19
|
+
* type: boolean
|
|
20
|
+
*/
|
|
21
|
+
export type FeatureFlagsResponse = {
|
|
22
|
+
key: string;
|
|
23
|
+
value: boolean | Record<string, boolean>;
|
|
24
|
+
}[];
|
|
25
|
+
export type FlagSettings = {
|
|
26
|
+
key: string;
|
|
27
|
+
description: string;
|
|
28
|
+
env_key: string;
|
|
29
|
+
default_val: boolean;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/feature-flags/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IAC1C,SAAS,EAAE,MAAM,oBAAoB,CAAA;CACtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACzC,EAAE,CAAA;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/feature-flags/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express-loader.d.ts","sourceRoot":"","sources":["../../src/http/express-loader.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAA;AAc1D,wBAAsB,aAAa,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC;IACtE,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9B,CAAC,CAuID"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.expressLoader = expressLoader;
|
|
7
|
+
const connect_redis_1 = __importDefault(require("connect-redis"));
|
|
8
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
9
|
+
const express_1 = __importDefault(require("express"));
|
|
10
|
+
const express_session_1 = __importDefault(require("express-session"));
|
|
11
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
12
|
+
const morgan_1 = __importDefault(require("morgan"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const logger_1 = require("../logger");
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
const utils_1 = require("@8medusa/utils");
|
|
17
|
+
const NOISY_ENDPOINTS_CHUNKS = ["@fs", "@id", "@vite", "@react", "node_modules"];
|
|
18
|
+
const isHealthCheck = (req) => req.path === "/health";
|
|
19
|
+
async function expressLoader({ app }) {
|
|
20
|
+
const baseDir = config_1.configManager.baseDir;
|
|
21
|
+
const configModule = config_1.configManager.config;
|
|
22
|
+
const isProduction = config_1.configManager.isProduction;
|
|
23
|
+
const NODE_ENV = process.env.NODE_ENV || "development";
|
|
24
|
+
const IS_DEV = NODE_ENV.startsWith("dev");
|
|
25
|
+
const isStaging = NODE_ENV === "staging";
|
|
26
|
+
const isTest = NODE_ENV === "test";
|
|
27
|
+
let sameSite = false;
|
|
28
|
+
let secure = false;
|
|
29
|
+
if (isProduction || isStaging) {
|
|
30
|
+
secure = true;
|
|
31
|
+
sameSite = "none";
|
|
32
|
+
}
|
|
33
|
+
const { http, sessionOptions } = configModule.projectConfig;
|
|
34
|
+
const sessionOpts = {
|
|
35
|
+
name: sessionOptions?.name ?? "connect.sid",
|
|
36
|
+
resave: sessionOptions?.resave ?? true,
|
|
37
|
+
rolling: sessionOptions?.rolling ?? false,
|
|
38
|
+
saveUninitialized: sessionOptions?.saveUninitialized ?? false,
|
|
39
|
+
proxy: true,
|
|
40
|
+
secret: sessionOptions?.secret ?? http?.cookieSecret,
|
|
41
|
+
cookie: {
|
|
42
|
+
sameSite,
|
|
43
|
+
secure,
|
|
44
|
+
maxAge: sessionOptions?.ttl ?? 10 * 60 * 60 * 1000,
|
|
45
|
+
},
|
|
46
|
+
store: null,
|
|
47
|
+
};
|
|
48
|
+
let redisClient;
|
|
49
|
+
if (configModule?.projectConfig.sessionOptions?.dynamodbOptions) {
|
|
50
|
+
const storeFactory = await (0, utils_1.dynamicImport)("connect-dynamodb");
|
|
51
|
+
const client = await (0, utils_1.dynamicImport)("@aws-sdk/client-dynamodb");
|
|
52
|
+
const DynamoDBStore = storeFactory({ session: express_session_1.default });
|
|
53
|
+
sessionOpts.store = new DynamoDBStore({
|
|
54
|
+
...configModule.projectConfig.sessionOptions.dynamodbOptions,
|
|
55
|
+
client: new client.DynamoDBClient(configModule.projectConfig.sessionOptions.dynamodbOptions.clientOptions),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (configModule?.projectConfig?.redisUrl) {
|
|
59
|
+
const RedisStore = (0, connect_redis_1.default)(express_session_1.default);
|
|
60
|
+
redisClient = new ioredis_1.default(configModule.projectConfig.redisUrl, configModule.projectConfig.redisOptions ?? {});
|
|
61
|
+
sessionOpts.store = new RedisStore({
|
|
62
|
+
client: redisClient,
|
|
63
|
+
prefix: `${configModule?.projectConfig?.redisPrefix ?? ""}sess:`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
app.set("trust proxy", 1);
|
|
67
|
+
/**
|
|
68
|
+
* Method to skip logging HTTP requests. We skip in test environment
|
|
69
|
+
* and also exclude files served by vite during development
|
|
70
|
+
*/
|
|
71
|
+
function shouldSkipHttpLog(req, res) {
|
|
72
|
+
return (isTest ||
|
|
73
|
+
isHealthCheck(req) ||
|
|
74
|
+
NOISY_ENDPOINTS_CHUNKS.some((chunk) => req.url.includes(chunk)) ||
|
|
75
|
+
!logger_1.logger.shouldLog("http"));
|
|
76
|
+
}
|
|
77
|
+
let loggingMiddleware;
|
|
78
|
+
/**
|
|
79
|
+
* The middleware to use for logging. We write the log messages
|
|
80
|
+
* using winston, but rely on morgan to hook into HTTP requests
|
|
81
|
+
*/
|
|
82
|
+
if (!IS_DEV) {
|
|
83
|
+
const jsonFormat = (tokens, req, res) => {
|
|
84
|
+
const result = {
|
|
85
|
+
level: "http",
|
|
86
|
+
// client ip
|
|
87
|
+
client_ip: req.ip || "-",
|
|
88
|
+
// Request ID can be correlated with other logs (like error reports)
|
|
89
|
+
request_id: req.requestId || "-",
|
|
90
|
+
// Standard HTTP request properties
|
|
91
|
+
http_version: tokens["http-version"](req, res),
|
|
92
|
+
method: tokens.method(req, res),
|
|
93
|
+
path: tokens.url(req, res),
|
|
94
|
+
// Response details
|
|
95
|
+
status: Number(tokens.status(req, res)),
|
|
96
|
+
response_size: tokens.res(req, res, "content-length") || 0,
|
|
97
|
+
request_size: tokens.req(req, res, "content-length") || 0,
|
|
98
|
+
duration: Number(tokens["response-time"](req, res)),
|
|
99
|
+
// Useful headers that might help in debugging or tracing
|
|
100
|
+
referrer: tokens.referrer(req, res) || "-",
|
|
101
|
+
user_agent: tokens["user-agent"](req, res),
|
|
102
|
+
timestamp: new Date().toISOString(),
|
|
103
|
+
};
|
|
104
|
+
return JSON.stringify(result);
|
|
105
|
+
};
|
|
106
|
+
loggingMiddleware = (0, morgan_1.default)(jsonFormat, {
|
|
107
|
+
skip: shouldSkipHttpLog,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
loggingMiddleware = (0, morgan_1.default)(":method :url ← :referrer (:status) - :response-time ms", {
|
|
112
|
+
skip: shouldSkipHttpLog,
|
|
113
|
+
stream: {
|
|
114
|
+
write: (message) => logger_1.logger.http(message.trim()),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
app.use(loggingMiddleware);
|
|
119
|
+
app.use((0, cookie_parser_1.default)());
|
|
120
|
+
app.use((0, express_session_1.default)(sessionOpts));
|
|
121
|
+
// Currently we don't allow configuration of static files, but this can be revisited as needed.
|
|
122
|
+
app.use("/static", express_1.default.static(path_1.default.join(baseDir, "static")));
|
|
123
|
+
const shutdown = async () => {
|
|
124
|
+
redisClient?.disconnect();
|
|
125
|
+
};
|
|
126
|
+
return { app, shutdown };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=express-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express-loader.js","sourceRoot":"","sources":["../../src/http/express-loader.ts"],"names":[],"mappings":";;;;;AAgBA,sCA0IC;AA1JD,kEAAuC;AACvC,kEAAwC;AACxC,sDAA0D;AAC1D,sEAAqC;AACrC,sDAA2B;AAC3B,oDAA2B;AAC3B,gDAAuB;AACvB,sCAAkC;AAClC,sCAAyC;AAEzC,0CAA8C;AAE9C,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAA;AAEhF,MAAM,aAAa,GAAG,CAAC,GAAkB,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAA;AAE7D,KAAK,UAAU,aAAa,CAAC,EAAE,GAAG,EAAoB;IAI3D,MAAM,OAAO,GAAG,sBAAa,CAAC,OAAO,CAAA;IACrC,MAAM,YAAY,GAAG,sBAAa,CAAC,MAAM,CAAA;IACzC,MAAM,YAAY,GAAG,sBAAa,CAAC,YAAY,CAAA;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAA;IACtD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CA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C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;aACxD;SACF,CACF,CAAA;IACH,CAAC;IAED,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAC1B,GAAG,CAAC,GAAG,CAAC,IAAA,uBAAY,GAAE,CAAC,CAAA;IACvB,GAAG,CAAC,GAAG,CAAC,IAAA,yBAAO,EAAC,WAAW,CAAC,CAAC,CAAA;IAE7B,+FAA+F;IAC/F,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAO,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEhE,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,WAAW,EAAE,UAAU,EAAE,CAAA;IAC3B,CAAC,CAAA;IAED,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "../types/container";
|
|
2
|
+
export * from "./express-loader";
|
|
3
|
+
export * from "./router";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export * from "./middlewares";
|
|
6
|
+
export * from "./utils/http-compression";
|
|
7
|
+
export * from "./utils/validate-body";
|
|
8
|
+
export * from "./utils/validate-query";
|
|
9
|
+
export * from "./utils/get-query-config";
|
|
10
|
+
export * from "./utils/define-middlewares";
|
|
11
|
+
export * from "./utils/maybe-apply-link-filter";
|
|
12
|
+
export * from "./utils/refetch-entities";
|
|
13
|
+
export * from "./utils/unless-path";
|
|
14
|
+
export * from "./utils/restricted-fields";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAE3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
require("../types/container");
|
|
18
|
+
__exportStar(require("./express-loader"), exports);
|
|
19
|
+
__exportStar(require("./router"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./middlewares"), exports);
|
|
22
|
+
__exportStar(require("./utils/http-compression"), exports);
|
|
23
|
+
__exportStar(require("./utils/validate-body"), exports);
|
|
24
|
+
__exportStar(require("./utils/validate-query"), exports);
|
|
25
|
+
__exportStar(require("./utils/get-query-config"), exports);
|
|
26
|
+
__exportStar(require("./utils/define-middlewares"), exports);
|
|
27
|
+
__exportStar(require("./utils/maybe-apply-link-filter"), exports);
|
|
28
|
+
__exportStar(require("./utils/refetch-entities"), exports);
|
|
29
|
+
__exportStar(require("./utils/unless-path"), exports);
|
|
30
|
+
__exportStar(require("./utils/restricted-fields"), exports);
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAE3B,mDAAgC;AAChC,2CAAwB;AACxB,0CAAuB;AACvB,gDAA6B;AAC7B,2DAAwC;AACxC,wDAAqC;AACrC,yDAAsC;AACtC,2DAAwC;AACxC,6DAA0C;AAC1C,kEAA+C;AAC/C,2DAAwC;AACxC,sDAAmC;AACnC,4DAAyC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type BodyParserConfigRoute, type MiddlewareDescriptor, type MedusaErrorHandlerFunction, type AdditionalDataValidatorRoute } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Exposes the API to scan a directory and load the `middleware.ts` file. This file contains
|
|
4
|
+
* the configuration for certain global middlewares and core routes validators. Also, it may
|
|
5
|
+
* contain custom middlewares.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MiddlewareFileLoader {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Scans a given directory for the "middleware.ts" or "middleware.js" files and
|
|
11
|
+
* imports them for reading the registered middleware and configuration for
|
|
12
|
+
* existing routes/middleware.
|
|
13
|
+
*/
|
|
14
|
+
scanDir(sourceDir: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the globally registered error handler (if any)
|
|
17
|
+
*/
|
|
18
|
+
getErrorHandler(): MedusaErrorHandlerFunction | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Returns a collection of registered middleware
|
|
21
|
+
*/
|
|
22
|
+
getMiddlewares(): MiddlewareDescriptor[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns routes that have bodyparser config on them
|
|
25
|
+
*/
|
|
26
|
+
getBodyParserConfigRoutes(): BodyParserConfigRoute[];
|
|
27
|
+
/**
|
|
28
|
+
* Returns routes that have additional validator configured
|
|
29
|
+
* on them
|
|
30
|
+
*/
|
|
31
|
+
getAdditionalDataValidatorRoutes(): AdditionalDataValidatorRoute[];
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=middleware-file-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-file-loader.d.ts","sourceRoot":"","sources":["../../src/http/middleware-file-loader.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAElC,MAAM,SAAS,CAAA;AAOhB;;;;GAIG;AACH,qBAAa,oBAAoB;;IA8H/B;;;;OAIG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM;IAa/B;;OAEG;IACH,eAAe;IAIf;;OAEG;IACH,cAAc;IAId;;OAEG;IACH,yBAAyB;IAIzB;;;OAGG;IACH,gCAAgC;CAGjC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _MiddlewareFileLoader_instances, _MiddlewareFileLoader_errorHandler, _MiddlewareFileLoader_middleware, _MiddlewareFileLoader_additionalDataValidatorRoutes, _MiddlewareFileLoader_bodyParserConfigRoutes, _MiddlewareFileLoader_processMiddlewareFile;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.MiddlewareFileLoader = void 0;
|
|
19
|
+
const zod_1 = __importDefault(require("zod"));
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const utils_1 = require("@8medusa/utils");
|
|
22
|
+
const logger_1 = require("../logger");
|
|
23
|
+
const types_1 = require("./types");
|
|
24
|
+
/**
|
|
25
|
+
* File name that is used to indicate that the file is a middleware file
|
|
26
|
+
*/
|
|
27
|
+
const MIDDLEWARE_FILE_NAME = "middlewares";
|
|
28
|
+
/**
|
|
29
|
+
* Exposes the API to scan a directory and load the `middleware.ts` file. This file contains
|
|
30
|
+
* the configuration for certain global middlewares and core routes validators. Also, it may
|
|
31
|
+
* contain custom middlewares.
|
|
32
|
+
*/
|
|
33
|
+
class MiddlewareFileLoader {
|
|
34
|
+
constructor() {
|
|
35
|
+
_MiddlewareFileLoader_instances.add(this);
|
|
36
|
+
/**
|
|
37
|
+
* Global error handler exported from the middleware file loader
|
|
38
|
+
*/
|
|
39
|
+
_MiddlewareFileLoader_errorHandler.set(this, void 0);
|
|
40
|
+
/**
|
|
41
|
+
* Middleware collected manually or by scanning directories
|
|
42
|
+
*/
|
|
43
|
+
_MiddlewareFileLoader_middleware.set(this, []
|
|
44
|
+
/**
|
|
45
|
+
* Route matchers on which a custom additional data validator is
|
|
46
|
+
* defined
|
|
47
|
+
*/
|
|
48
|
+
);
|
|
49
|
+
/**
|
|
50
|
+
* Route matchers on which a custom additional data validator is
|
|
51
|
+
* defined
|
|
52
|
+
*/
|
|
53
|
+
_MiddlewareFileLoader_additionalDataValidatorRoutes.set(this, []
|
|
54
|
+
/**
|
|
55
|
+
* Route matchers on which a custom body parser config is used
|
|
56
|
+
*/
|
|
57
|
+
);
|
|
58
|
+
/**
|
|
59
|
+
* Route matchers on which a custom body parser config is used
|
|
60
|
+
*/
|
|
61
|
+
_MiddlewareFileLoader_bodyParserConfigRoutes.set(this, []
|
|
62
|
+
/**
|
|
63
|
+
* Processes the middleware file and returns the middleware and the
|
|
64
|
+
* routes config exported by it.
|
|
65
|
+
*/
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Scans a given directory for the "middleware.ts" or "middleware.js" files and
|
|
70
|
+
* imports them for reading the registered middleware and configuration for
|
|
71
|
+
* existing routes/middleware.
|
|
72
|
+
*/
|
|
73
|
+
async scanDir(sourceDir) {
|
|
74
|
+
const fs = new utils_1.FileSystem(sourceDir);
|
|
75
|
+
if (await fs.exists(`${MIDDLEWARE_FILE_NAME}.ts`)) {
|
|
76
|
+
await __classPrivateFieldGet(this, _MiddlewareFileLoader_instances, "m", _MiddlewareFileLoader_processMiddlewareFile).call(this, (0, path_1.join)(sourceDir, `${MIDDLEWARE_FILE_NAME}.ts`));
|
|
77
|
+
}
|
|
78
|
+
else if (await fs.exists(`${MIDDLEWARE_FILE_NAME}.js`)) {
|
|
79
|
+
await __classPrivateFieldGet(this, _MiddlewareFileLoader_instances, "m", _MiddlewareFileLoader_processMiddlewareFile).call(this, (0, path_1.join)(sourceDir, `${MIDDLEWARE_FILE_NAME}.js`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the globally registered error handler (if any)
|
|
84
|
+
*/
|
|
85
|
+
getErrorHandler() {
|
|
86
|
+
return __classPrivateFieldGet(this, _MiddlewareFileLoader_errorHandler, "f");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns a collection of registered middleware
|
|
90
|
+
*/
|
|
91
|
+
getMiddlewares() {
|
|
92
|
+
return __classPrivateFieldGet(this, _MiddlewareFileLoader_middleware, "f");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns routes that have bodyparser config on them
|
|
96
|
+
*/
|
|
97
|
+
getBodyParserConfigRoutes() {
|
|
98
|
+
return __classPrivateFieldGet(this, _MiddlewareFileLoader_bodyParserConfigRoutes, "f");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns routes that have additional validator configured
|
|
102
|
+
* on them
|
|
103
|
+
*/
|
|
104
|
+
getAdditionalDataValidatorRoutes() {
|
|
105
|
+
return __classPrivateFieldGet(this, _MiddlewareFileLoader_additionalDataValidatorRoutes, "f");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.MiddlewareFileLoader = MiddlewareFileLoader;
|
|
109
|
+
_MiddlewareFileLoader_errorHandler = new WeakMap(), _MiddlewareFileLoader_middleware = new WeakMap(), _MiddlewareFileLoader_additionalDataValidatorRoutes = new WeakMap(), _MiddlewareFileLoader_bodyParserConfigRoutes = new WeakMap(), _MiddlewareFileLoader_instances = new WeakSet(), _MiddlewareFileLoader_processMiddlewareFile =
|
|
110
|
+
/**
|
|
111
|
+
* Processes the middleware file and returns the middleware and the
|
|
112
|
+
* routes config exported by it.
|
|
113
|
+
*/
|
|
114
|
+
async function _MiddlewareFileLoader_processMiddlewareFile(absolutePath) {
|
|
115
|
+
const middlewareExports = await (0, utils_1.dynamicImport)(absolutePath);
|
|
116
|
+
const middlewareConfig = middlewareExports.default;
|
|
117
|
+
if (!middlewareConfig) {
|
|
118
|
+
logger_1.logger.warn(`No middleware configuration found in ${absolutePath}. Skipping middleware configuration.`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const routes = middlewareConfig.routes;
|
|
122
|
+
if (!routes || !Array.isArray(routes)) {
|
|
123
|
+
logger_1.logger.warn(`Invalid default export found in ${absolutePath}. Make sure to use "defineMiddlewares" function and export its output.`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const result = routes.reduce((result, route) => {
|
|
127
|
+
if (!route.matcher) {
|
|
128
|
+
throw new Error(`Middleware is missing a \`matcher\` field. The 'matcher' field is required when applying middleware. ${JSON.stringify(route, null, 2)}`);
|
|
129
|
+
}
|
|
130
|
+
const matcher = String(route.matcher);
|
|
131
|
+
if (route.bodyParser !== undefined) {
|
|
132
|
+
const methods = route.methods || [...types_1.HTTP_METHODS];
|
|
133
|
+
logger_1.logger.debug(`using custom bodyparser config on matcher ${methods}:${route.matcher}`);
|
|
134
|
+
result.bodyParserConfigRoutes.push({
|
|
135
|
+
matcher: matcher,
|
|
136
|
+
methods,
|
|
137
|
+
config: route.bodyParser,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (route.additionalDataValidator !== undefined) {
|
|
141
|
+
const methods = route.methods || [...types_1.HTTP_METHODS];
|
|
142
|
+
logger_1.logger.debug(`assigning additionalData validator on matcher ${methods}:${route.matcher}`);
|
|
143
|
+
result.additionalDataValidatorRoutes.push({
|
|
144
|
+
matcher: matcher,
|
|
145
|
+
methods,
|
|
146
|
+
schema: route.additionalDataValidator,
|
|
147
|
+
validator: zod_1.default.object(route.additionalDataValidator).nullish(),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (route.middlewares) {
|
|
151
|
+
route.middlewares.forEach((middleware) => {
|
|
152
|
+
result.middleware.push({
|
|
153
|
+
handler: middleware,
|
|
154
|
+
matcher: matcher,
|
|
155
|
+
methods: route.methods,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}, {
|
|
161
|
+
bodyParserConfigRoutes: [],
|
|
162
|
+
additionalDataValidatorRoutes: [],
|
|
163
|
+
middleware: [],
|
|
164
|
+
});
|
|
165
|
+
const errorHandler = middlewareConfig.errorHandler;
|
|
166
|
+
if (errorHandler) {
|
|
167
|
+
__classPrivateFieldSet(this, _MiddlewareFileLoader_errorHandler, errorHandler, "f");
|
|
168
|
+
}
|
|
169
|
+
__classPrivateFieldSet(this, _MiddlewareFileLoader_middleware, __classPrivateFieldGet(this, _MiddlewareFileLoader_middleware, "f").concat(result.middleware), "f");
|
|
170
|
+
__classPrivateFieldSet(this, _MiddlewareFileLoader_bodyParserConfigRoutes, __classPrivateFieldGet(this, _MiddlewareFileLoader_bodyParserConfigRoutes, "f").concat(result.bodyParserConfigRoutes), "f");
|
|
171
|
+
__classPrivateFieldSet(this, _MiddlewareFileLoader_additionalDataValidatorRoutes, __classPrivateFieldGet(this, _MiddlewareFileLoader_additionalDataValidatorRoutes, "f").concat(result.additionalDataValidatorRoutes), "f");
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=middleware-file-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-file-loader.js","sourceRoot":"","sources":["../../src/http/middleware-file-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAAqB;AACrB,+BAA2B;AAC3B,0CAA0D;AAE1D,sCAAkC;AAClC,mCAOgB;AAEhB;;GAEG;AACH,MAAM,oBAAoB,GAAG,aAAa,CAAA;AAE1C;;;;GAIG;AACH,MAAa,oBAAoB;IAAjC;;QACE;;WAEG;QACH,qDAA0C;QAE1C;;WAEG;QACH,2CAAsC,EAAE;QAExC;;;WAGG;UALqC;QAExC;;;WAGG;QACH,8DAAiE,EAAE;QAEnE;;WAEG;UAJgE;QAEnE;;WAEG;QACH,uDAAmD,EAAE;QAErD;;;WAGG;UALkD;IAwJvD,CAAC;IA9CC;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB;QAC7B,MAAM,EAAE,GAAG,IAAI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AI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;gBACvC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;oBACrB,OAAO,EAAE,UAAU;oBACnB,OAAO,EAAE,OAAO;oBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,EACD;QACE,sBAAsB,EAAE,EAAE;QAC1B,6BAA6B,EAAE,EAAE;QACjC,UAAU,EAAE,EAAE;KACf,CACF,CAAA;IAED,MAAM,YAAY,GAChB,gBAAgB,CAAC,YAAiD,CAAA;IAEpE,IAAI,YAAY,EAAE,CAAC;QACjB,uBAAA,IAAI,sCAAiB,YAAY,MAAA,CAAA;IACnC,CAAC;IACD,uBAAA,IAAI,oCAAe,uBAAA,IAAI,wCAAY,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAA,CAAA;IAC7D,uBAAA,IAAI,gDAA2B,uBAAA,IAAI,oDAAwB,CAAC,MAAM,CAChE,MAAM,CAAC,sBAAsB,CAC9B,MAAA,CAAA;IACD,uBAAA,IAAI,uDACF,uBAAA,IAAI,2DAA+B,CAAC,MAAM,CACxC,MAAM,CAAC,6BAA6B,CACrC,MAAA,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MedusaNextFunction, MedusaRequest, MedusaResponse } from "../types";
|
|
2
|
+
export declare function applyDefaultFilters<TFilter extends object>(filtersToApply: TFilter): (req: MedusaRequest, _: MedusaResponse, next: MedusaNextFunction) => Promise<void>;
|
|
3
|
+
//# sourceMappingURL=apply-default-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-default-filters.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/apply-default-filters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,cAAc,EAAE,OAAO,SAGhB,aAAa,KACf,cAAc,QACX,kBAAkB,mBA4B3B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDefaultFilters = applyDefaultFilters;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
function applyDefaultFilters(filtersToApply) {
|
|
6
|
+
return async function defaultFiltersMiddleware(req, _, next) {
|
|
7
|
+
for (const [filter, filterValue] of Object.entries(filtersToApply)) {
|
|
8
|
+
let valueToApply = filterValue;
|
|
9
|
+
// If certain manipulations need to be done on a middleware level, we can provide a simple
|
|
10
|
+
// function that mutates the data based on any custom requirement
|
|
11
|
+
if (typeof filterValue === "function") {
|
|
12
|
+
// pass the actual filterable fields so that the function can mutate the original object.
|
|
13
|
+
// Currently we only need it to delete filter keys from the request filter object, but this could
|
|
14
|
+
// be used for other purposes. If we can't find other purposes, we can refactor to accept an array
|
|
15
|
+
// of strings to delete after filters have been applied.
|
|
16
|
+
valueToApply = filterValue(req.filterableFields, req.queryConfig.fields);
|
|
17
|
+
}
|
|
18
|
+
// If the value to apply is an object, we add it to any existing filters thats already applied
|
|
19
|
+
if ((0, utils_1.isObject)(valueToApply)) {
|
|
20
|
+
req.filterableFields[filter] = {
|
|
21
|
+
...(req.filterableFields[filter] || {}),
|
|
22
|
+
...valueToApply,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if ((0, utils_1.isPresent)(valueToApply)) {
|
|
26
|
+
req.filterableFields[filter] = valueToApply;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return next();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=apply-default-filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-default-filters.js","sourceRoot":"","sources":["../../../src/http/middlewares/apply-default-filters.ts"],"names":[],"mappings":";;AAOA,kDAkCC;AAzCD,0CAAoD;AAOpD,SAAgB,mBAAmB,CACjC,cAAuB;IAEvB,OAAO,KAAK,UAAU,wBAAwB,CAC5C,GAAkB,EAClB,CAAiB,EACjB,IAAwB;QAExB,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACnE,IAAI,YAAY,GAAG,WAAW,CAAA;YAE9B,0FAA0F;YAC1F,iEAAiE;YACjE,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBACtC,yFAAyF;gBACzF,iGAAiG;gBACjG,kGAAkG;gBAClG,wDAAwD;gBACxD,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YAC1E,CAAC;YAED,8FAA8F;YAC9F,IAAI,IAAA,gBAAQ,EAAC,YAAY,CAAC,EAAE,CAAC;gBAC3B,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG;oBAC7B,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;oBACvC,GAAG,YAAY;iBAChB,CAAA;YACH,CAAC;iBAAM,IAAI,IAAA,iBAAS,EAAC,YAAY,CAAC,EAAE,CAAC;gBACnC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,YAAY,CAAA;YAC7C,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MedusaNextFunction, MedusaRequest, MedusaResponse } from "../types";
|
|
2
|
+
export declare function applyParamsAsFilters(mappings: {
|
|
3
|
+
[param: string]: string;
|
|
4
|
+
}): (req: MedusaRequest, _: MedusaResponse, next: MedusaNextFunction) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=apply-params-as-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-params-as-filters.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/apply-params-as-filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,SAEjE,aAAa,KACf,cAAc,QACX,kBAAkB,mBAU3B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyParamsAsFilters = applyParamsAsFilters;
|
|
4
|
+
function applyParamsAsFilters(mappings) {
|
|
5
|
+
return async function paramsAsFiltersMiddleware(req, _, next) {
|
|
6
|
+
for (const [param, paramValue] of Object.entries(req.params)) {
|
|
7
|
+
if (mappings[param]) {
|
|
8
|
+
req.filterableFields[mappings[param]] = paramValue;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return next();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=apply-params-as-filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-params-as-filters.js","sourceRoot":"","sources":["../../../src/http/middlewares/apply-params-as-filters.ts"],"names":[],"mappings":";;AAMA,oDAcC;AAdD,SAAgB,oBAAoB,CAAC,QAAqC;IACxE,OAAO,KAAK,UAAU,yBAAyB,CAC7C,GAAkB,EAClB,CAAiB,EACjB,IAAwB;QAExB,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7D,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,GAAG,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAA;YACpD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RequestHandler } from "express";
|
|
2
|
+
import { AuthContext } from "../types";
|
|
3
|
+
declare const SESSION_AUTH = "session";
|
|
4
|
+
declare const BEARER_AUTH = "bearer";
|
|
5
|
+
declare const API_KEY_AUTH = "api-key";
|
|
6
|
+
export type AuthType = typeof SESSION_AUTH | typeof BEARER_AUTH | typeof API_KEY_AUTH;
|
|
7
|
+
export declare const authenticate: (actorType: string | string[], authType: AuthType | AuthType[], options?: {
|
|
8
|
+
allowUnauthenticated?: boolean;
|
|
9
|
+
allowUnregistered?: boolean;
|
|
10
|
+
}) => RequestHandler;
|
|
11
|
+
export declare const getAuthContextFromJwtToken: (authHeader: string | undefined, jwtSecret: string, authTypes: AuthType[], actorTypes: string[]) => AuthContext | null;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=authenticate-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticate-middleware.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/authenticate-middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,cAAc,EAAE,MAAM,SAAS,CAAA;AAGtD,OAAO,EACL,WAAW,EAIZ,MAAM,UAAU,CAAA;AAEjB,QAAA,MAAM,YAAY,YAAY,CAAA;AAC9B,QAAA,MAAM,WAAW,WAAW,CAAA;AAC5B,QAAA,MAAM,YAAY,YAAY,CAAA;AAK9B,MAAM,MAAM,QAAQ,GAChB,OAAO,YAAY,GACnB,OAAO,WAAW,GAClB,OAAO,YAAY,CAAA;AAMvB,eAAO,MAAM,YAAY,cACZ,MAAM,GAAG,MAAM,EAAE,YAClB,QAAQ,GAAG,QAAQ,EAAE,YACtB;IAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,KACvE,cA4EF,CAAA;AAgED,eAAO,MAAM,0BAA0B,eACzB,MAAM,GAAG,SAAS,aACnB,MAAM,aACN,QAAQ,EAAE,cACT,MAAM,EAAE,KACnB,WAAW,GAAG,IA+BhB,CAAA"}
|