@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,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthContextFromJwtToken = exports.authenticate = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
6
|
+
const SESSION_AUTH = "session";
|
|
7
|
+
const BEARER_AUTH = "bearer";
|
|
8
|
+
const API_KEY_AUTH = "api-key";
|
|
9
|
+
// This is the only hard-coded actor type, as API keys have special handling for now. We could also generalize API keys to carry the actor type with them.
|
|
10
|
+
const ADMIN_ACTOR_TYPE = "user";
|
|
11
|
+
const authenticate = (actorType, authType, options = {}) => {
|
|
12
|
+
const authenticateMiddleware = async (req, res, next) => {
|
|
13
|
+
const authTypes = Array.isArray(authType) ? authType : [authType];
|
|
14
|
+
const actorTypes = Array.isArray(actorType) ? actorType : [actorType];
|
|
15
|
+
const req_ = req;
|
|
16
|
+
// We only allow authenticating using a secret API key on the admin
|
|
17
|
+
const isExclusivelyUser = actorTypes.length === 1 && actorTypes[0] === ADMIN_ACTOR_TYPE;
|
|
18
|
+
if (authTypes.includes(API_KEY_AUTH) && isExclusivelyUser) {
|
|
19
|
+
const apiKey = await getApiKeyInfo(req);
|
|
20
|
+
if (apiKey) {
|
|
21
|
+
req_.auth_context = {
|
|
22
|
+
actor_id: apiKey.id,
|
|
23
|
+
actor_type: "api-key",
|
|
24
|
+
auth_identity_id: "",
|
|
25
|
+
app_metadata: {},
|
|
26
|
+
};
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// We try to extract the auth context either from the session or from a JWT token
|
|
31
|
+
let authContext = getAuthContextFromSession(req.session, authTypes, actorTypes);
|
|
32
|
+
if (!authContext) {
|
|
33
|
+
const { projectConfig: { http }, } = req.scope.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
|
34
|
+
authContext = (0, exports.getAuthContextFromJwtToken)(req.headers.authorization, http.jwtSecret, authTypes, actorTypes);
|
|
35
|
+
}
|
|
36
|
+
// If the entity is authenticated, and it is a registered actor we can continue
|
|
37
|
+
if (authContext?.actor_id) {
|
|
38
|
+
req_.auth_context = authContext;
|
|
39
|
+
return next();
|
|
40
|
+
}
|
|
41
|
+
// If the entity is authenticated, but there is no registered actor yet, we can continue (eg. in the case of a user invite) if allow unregistered is set
|
|
42
|
+
// We also don't want to allow creating eg. a customer with a token created for a `user` provider.
|
|
43
|
+
if (authContext?.auth_identity_id &&
|
|
44
|
+
options.allowUnregistered &&
|
|
45
|
+
isActorTypePermitted(actorTypes, authContext.actor_type)) {
|
|
46
|
+
req_.auth_context = authContext;
|
|
47
|
+
return next();
|
|
48
|
+
}
|
|
49
|
+
// If we allow unauthenticated requests (i.e public endpoints), just continue
|
|
50
|
+
if (options.allowUnauthenticated) {
|
|
51
|
+
return next();
|
|
52
|
+
}
|
|
53
|
+
res.status(401).json({ message: "Unauthorized" });
|
|
54
|
+
};
|
|
55
|
+
return authenticateMiddleware;
|
|
56
|
+
};
|
|
57
|
+
exports.authenticate = authenticate;
|
|
58
|
+
const getApiKeyInfo = async (req) => {
|
|
59
|
+
const authHeader = req.headers.authorization;
|
|
60
|
+
if (!authHeader) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const [tokenType, token] = authHeader.split(" ");
|
|
64
|
+
if (tokenType.toLowerCase() !== "basic" || !token) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
// The token could have been base64 encoded, we want to decode it first.
|
|
68
|
+
let normalizedToken = token;
|
|
69
|
+
if (!token.startsWith("sk_")) {
|
|
70
|
+
normalizedToken = Buffer.from(token, "base64").toString("utf-8");
|
|
71
|
+
}
|
|
72
|
+
// Basic auth is defined as a username:password set, and since the token is set to the username we need to trim the colon
|
|
73
|
+
if (normalizedToken.endsWith(":")) {
|
|
74
|
+
normalizedToken = normalizedToken.slice(0, -1);
|
|
75
|
+
}
|
|
76
|
+
// Secret tokens start with 'sk_', and if it doesn't it could be a user JWT or a malformed token
|
|
77
|
+
if (!normalizedToken.startsWith("sk_")) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const apiKeyModule = req.scope.resolve(utils_1.Modules.API_KEY);
|
|
81
|
+
try {
|
|
82
|
+
const apiKey = await apiKeyModule.authenticate(normalizedToken);
|
|
83
|
+
if (!apiKey) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return apiKey;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const getAuthContextFromSession = (session = {}, authTypes, actorTypes) => {
|
|
94
|
+
if (!authTypes.includes(SESSION_AUTH)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (session.auth_context &&
|
|
98
|
+
isActorTypePermitted(actorTypes, session.auth_context?.actor_type)) {
|
|
99
|
+
return session.auth_context;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
const getAuthContextFromJwtToken = (authHeader, jwtSecret, authTypes, actorTypes) => {
|
|
104
|
+
if (!authTypes.includes(BEARER_AUTH)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
if (!authHeader) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const re = /(\S+)\s+(\S+)/;
|
|
111
|
+
const matches = authHeader.match(re);
|
|
112
|
+
// TODO: figure out how to obtain token (and store correct data in token)
|
|
113
|
+
if (matches) {
|
|
114
|
+
const tokenType = matches[1];
|
|
115
|
+
const token = matches[2];
|
|
116
|
+
if (tokenType.toLowerCase() === BEARER_AUTH) {
|
|
117
|
+
// get config jwt secret
|
|
118
|
+
// verify token and set authUser
|
|
119
|
+
try {
|
|
120
|
+
const verified = (0, jsonwebtoken_1.verify)(token, jwtSecret);
|
|
121
|
+
if (isActorTypePermitted(actorTypes, verified.actor_type)) {
|
|
122
|
+
return verified;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
};
|
|
132
|
+
exports.getAuthContextFromJwtToken = getAuthContextFromJwtToken;
|
|
133
|
+
const isActorTypePermitted = (actorTypes, currentActorType) => {
|
|
134
|
+
return actorTypes.includes("*") || actorTypes.includes(currentActorType);
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=authenticate-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticate-middleware.js","sourceRoot":"","sources":["../../../src/http/middlewares/authenticate-midd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,QAAA,0BAA0B,8BAoCtC;AAED,MAAM,oBAAoB,GAAG,CAC3B,UAA6B,EAC7B,gBAAwB,EACxB,EAAE;IACF,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AAC1E,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RequestHandler } from "express";
|
|
2
|
+
import type { MiddlewareFunction, BodyParserConfigRoute } from "../types";
|
|
3
|
+
import type { RoutesFinder } from "../routes-finder";
|
|
4
|
+
/**
|
|
5
|
+
* Creates the bodyparser middlewares stack that creates custom bodyparsers
|
|
6
|
+
* during an HTTP request based upon the defined config. The bodyparser
|
|
7
|
+
* instances are cached for re-use.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createBodyParserMiddlewaresStack(route: string, routesFinder: RoutesFinder<BodyParserConfigRoute>, tracer?: (handler: RequestHandler | MiddlewareFunction, route: {
|
|
10
|
+
route: string;
|
|
11
|
+
method?: string;
|
|
12
|
+
}) => RequestHandler | MiddlewareFunction): RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>[];
|
|
13
|
+
//# sourceMappingURL=bodyparser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodyparser.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/bodyparser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,cAAc,EAAoB,MAAM,SAAS,CAAA;AAE9E,OAAO,KAAK,EAKV,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA+BpD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,YAAY,CAAC,qBAAqB,CAAC,EACjD,MAAM,CAAC,EAAE,CACP,OAAO,EAAE,cAAc,GAAG,kBAAkB,EAC5C,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KACtC,cAAc,GAAG,kBAAkB,gIAyCzC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.createBodyParserMiddlewaresStack = createBodyParserMiddlewaresStack;
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const reporter_1 = __importDefault(require("@8medusa/cli/dist/reporter"));
|
|
9
|
+
const express_1 = require("express");
|
|
10
|
+
/**
|
|
11
|
+
* Parsers to use for parsing the HTTP request body
|
|
12
|
+
*/
|
|
13
|
+
const parsers = {
|
|
14
|
+
json: (0, lodash_1.memoize)(function jsonParserMiddleware(options) {
|
|
15
|
+
return (0, express_1.json)({
|
|
16
|
+
limit: options?.sizeLimit,
|
|
17
|
+
verify: options?.preserveRawBody
|
|
18
|
+
? (req, res, buf) => {
|
|
19
|
+
req.rawBody = buf;
|
|
20
|
+
}
|
|
21
|
+
: undefined,
|
|
22
|
+
});
|
|
23
|
+
}),
|
|
24
|
+
text: (0, lodash_1.memoize)(function textParser(options) {
|
|
25
|
+
return (0, express_1.text)({
|
|
26
|
+
limit: options?.sizeLimit,
|
|
27
|
+
});
|
|
28
|
+
}),
|
|
29
|
+
urlencoded: (0, lodash_1.memoize)(function urlencodedParserMiddleware(options) {
|
|
30
|
+
return (0, express_1.urlencoded)({
|
|
31
|
+
limit: options?.sizeLimit,
|
|
32
|
+
extended: true,
|
|
33
|
+
});
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates the bodyparser middlewares stack that creates custom bodyparsers
|
|
38
|
+
* during an HTTP request based upon the defined config. The bodyparser
|
|
39
|
+
* instances are cached for re-use.
|
|
40
|
+
*/
|
|
41
|
+
function createBodyParserMiddlewaresStack(route, routesFinder, tracer) {
|
|
42
|
+
return ["json", "text", "urlencoded"].map((parser) => {
|
|
43
|
+
function bodyParser(req, res, next) {
|
|
44
|
+
const matchingRoute = routesFinder.find(req.path, req.method);
|
|
45
|
+
const parserMiddleware = parsers[parser];
|
|
46
|
+
if (!matchingRoute) {
|
|
47
|
+
return parserMiddleware()(req, res, next);
|
|
48
|
+
}
|
|
49
|
+
if (matchingRoute.config === false) {
|
|
50
|
+
reporter_1.default.debug(`skipping ${parser} bodyparser middleware ${req.method} ${req.path}`);
|
|
51
|
+
return next();
|
|
52
|
+
}
|
|
53
|
+
reporter_1.default.debug(`using custom ${parser} bodyparser config ${req.method} ${req.path}`);
|
|
54
|
+
return parserMiddleware(matchingRoute.config)(req, res, next);
|
|
55
|
+
}
|
|
56
|
+
Object.defineProperty(bodyParser, "name", {
|
|
57
|
+
value: `${parser}BodyParser`,
|
|
58
|
+
});
|
|
59
|
+
return (tracer ? tracer(bodyParser, { route }) : bodyParser);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=bodyparser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodyparser.js","sourceRoot":"","sources":["../../../src/http/middlewares/bodyparser.ts"],"names":[],"mappings":";;;;;AAgDA,4EA+CC;AA/FD,mCAAgC;AAChC,0EAA+C;AAC/C,qCAA8E;AAY9E;;GAEG;AACH,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,IAAA,gBAAO,EAAC,SAAS,oBAAoB,CAAC,OAA0B;QACpE,OAAO,IAAA,cAAI,EAAC;YACV,KAAK,EAAE,OAAO,EAAE,SAAS;YACzB,MAAM,EAAE,OAAO,EAAE,eAAe;gBAC9B,CAAC,CAAC,CAAC,GAAkB,EAAE,GAAmB,EAAE,GAAW,EAAE,EAAE;oBACvD,GAAG,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sBAAsB,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,CACrE,CAAA;YACD,OAAO,gBAAgB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAC/D,CAAC;QAED,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE;YACxC,KAAK,EAAE,GAAG,MAAM,YAAY;SAC7B,CAAC,CAAA;QAEF,OAAO,CACL,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAClC,CAAA;IACrB,CAAC,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MedusaNextFunction, MedusaRequest, MedusaResponse } from "../types";
|
|
2
|
+
export declare function clearFiltersByKey(keys: string[]): (req: MedusaRequest, _: MedusaResponse, next: MedusaNextFunction) => Promise<void>;
|
|
3
|
+
//# sourceMappingURL=clear-filters-by-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear-filters-by-key.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/clear-filters-by-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAEvC,aAAa,KACf,cAAc,QACX,kBAAkB,mBAQ3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearFiltersByKey = clearFiltersByKey;
|
|
4
|
+
function clearFiltersByKey(keys) {
|
|
5
|
+
return async function clearFiltersByKeyMiddleware(req, _, next) {
|
|
6
|
+
keys.forEach((key) => {
|
|
7
|
+
delete req.filterableFields[key];
|
|
8
|
+
});
|
|
9
|
+
return next();
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=clear-filters-by-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear-filters-by-key.js","sourceRoot":"","sources":["../../../src/http/middlewares/clear-filters-by-key.ts"],"names":[],"mappings":";;AAMA,8CAYC;AAZD,SAAgB,iBAAiB,CAAC,IAAc;IAC9C,OAAO,KAAK,UAAU,2BAA2B,CAC/C,GAAkB,EAClB,CAAiB,EACjB,IAAwB;QAExB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MedusaNextFunction, MedusaResponse, MedusaStoreRequest } from "../../http";
|
|
2
|
+
export declare function ensurePublishableApiKeyMiddleware(req: MedusaStoreRequest, _: MedusaResponse, next: MedusaNextFunction): Promise<void>;
|
|
3
|
+
//# sourceMappingURL=ensure-publishable-api-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-publishable-api-key.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/ensure-publishable-api-key.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAEnB,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,kBAAkB,EACvB,CAAC,EAAE,cAAc,EACjB,IAAI,EAAE,kBAAkB,iBAqDzB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensurePublishableApiKeyMiddleware = ensurePublishableApiKeyMiddleware;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
async function ensurePublishableApiKeyMiddleware(req, _, next) {
|
|
6
|
+
const publishableApiKey = req.get(utils_1.PUBLISHABLE_KEY_HEADER);
|
|
7
|
+
if (!(0, utils_1.isPresent)(publishableApiKey)) {
|
|
8
|
+
const error = new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_ALLOWED, `Publishable API key required in the request header: ${utils_1.PUBLISHABLE_KEY_HEADER}. You can manage your keys in settings in the dashboard.`);
|
|
9
|
+
return next(error);
|
|
10
|
+
}
|
|
11
|
+
let apiKey;
|
|
12
|
+
const query = req.scope.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
13
|
+
try {
|
|
14
|
+
const { data } = await query.graph({
|
|
15
|
+
entity: "api_key",
|
|
16
|
+
fields: ["id", "token", "sales_channels_link.sales_channel_id"],
|
|
17
|
+
filters: {
|
|
18
|
+
token: publishableApiKey,
|
|
19
|
+
type: utils_1.ApiKeyType.PUBLISHABLE,
|
|
20
|
+
$or: [
|
|
21
|
+
{ revoked_at: { $eq: null } },
|
|
22
|
+
{ revoked_at: { $gt: new Date() } },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
apiKey = data[0];
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return next(e);
|
|
30
|
+
}
|
|
31
|
+
if (!apiKey) {
|
|
32
|
+
try {
|
|
33
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_ALLOWED, `A valid publishable key is required to proceed with the request`);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
return next(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
req.publishable_key_context = {
|
|
40
|
+
key: apiKey.token,
|
|
41
|
+
sales_channel_ids: apiKey.sales_channels_link.map((link) => link.sales_channel_id),
|
|
42
|
+
};
|
|
43
|
+
return next();
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=ensure-publishable-api-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-publishable-api-key.js","sourceRoot":"","sources":["../../../src/http/middlewares/ensure-publishable-api-key.ts"],"names":[],"mappings":";;AAaA,8EAwDC;AArED,0CAMuB;AAOhB,KAAK,UAAU,iCAAiC,CACrD,GAAuB,EACvB,CAAiB,EACjB,IAAwB;IAExB,MAAM,iBAAiB,GAAG,GAAG,CAAC,GAAG,CAAC,8BAAsB,CAAC,CAAA;IAEzD,IAAI,CAAC,IAAA,iBAAS,EAAC,iBAAiB,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,IAAI,mBAAW,CAC3B,mBAAW,CAAC,KAAK,CAAC,WAAW,EAC7B,uDAAuD,8BAAsB,0DAA0D,CACxI,CAAA;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,MAAM,CAAA;IACV,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,iCAAyB,CAAC,KAAK,CAAC,CAAA;IAEhE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;YACjC,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,sCAAsC,CAAC;YAC/D,OAAO,EAAE;gBACP,KAAK,EAAE,iBAAiB;gBACxB,IAAI,EAAE,kBAAU,CAAC,WAAW;gBAC5B,GAAG,EAAE;oBACH,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;oBAC7B,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE;iBACpC;aACF;SACF,CAAC,CAAA;QAEF,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IAClB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,WAAW,EAC7B,iEAAiE,CAClE,CAAA;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED,GAAG,CAAC,uBAAuB,GAAG;QAC5B,GAAG,EAAE,MAAM,CAAC,KAAK;QACjB,iBAAiB,EAAE,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAC/C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAChC;KACF,CAAA;IAED,OAAO,IAAI,EAAE,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrorRequestHandler } from "express";
|
|
2
|
+
export declare function errorHandler(): ErrorRequestHandler;
|
|
3
|
+
/**
|
|
4
|
+
* @schema Error
|
|
5
|
+
* title: "Response Error"
|
|
6
|
+
* type: object
|
|
7
|
+
* properties:
|
|
8
|
+
* code:
|
|
9
|
+
* type: string
|
|
10
|
+
* description: A slug code to indicate the type of the error.
|
|
11
|
+
* enum: [invalid_state_error, invalid_request_error, api_error, unknown_error]
|
|
12
|
+
* message:
|
|
13
|
+
* type: string
|
|
14
|
+
* description: Description of the error that occurred.
|
|
15
|
+
* example: "first_name must be a string"
|
|
16
|
+
* type:
|
|
17
|
+
* type: string
|
|
18
|
+
* description: A slug indicating the type of the error.
|
|
19
|
+
* enum: [QueryRunnerAlreadyReleasedError, TransactionAlreadyStartedError, TransactionNotStartedError, conflict, unauthorized, payment_authorization_error, duplicate_error, not_allowed, invalid_data, not_found, database_error, unexpected_state, invalid_argument, unknown_error]
|
|
20
|
+
*/
|
|
21
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAY,MAAM,SAAS,CAAA;AAcrE,wBAAgB,YAAY,IAgEV,mBAAmB,CACpC;AAED;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = errorHandler;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
const exception_formatter_1 = require("./exception-formatter");
|
|
6
|
+
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError";
|
|
7
|
+
const TRANSACTION_STARTED = "TransactionAlreadyStartedError";
|
|
8
|
+
const TRANSACTION_NOT_STARTED = "TransactionNotStartedError";
|
|
9
|
+
const API_ERROR = "api_error";
|
|
10
|
+
const INVALID_REQUEST_ERROR = "invalid_request_error";
|
|
11
|
+
const INVALID_STATE_ERROR = "invalid_state_error";
|
|
12
|
+
function errorHandler() {
|
|
13
|
+
return function coreErrorHandler(err, req, res, _) {
|
|
14
|
+
const logger = req.scope.resolve(utils_1.ContainerRegistrationKeys.LOGGER);
|
|
15
|
+
err = (0, exception_formatter_1.formatException)(err);
|
|
16
|
+
logger.error(err);
|
|
17
|
+
const errorType = err.type || err.name;
|
|
18
|
+
const errObj = {
|
|
19
|
+
code: err.code,
|
|
20
|
+
type: err.type,
|
|
21
|
+
message: err.message,
|
|
22
|
+
};
|
|
23
|
+
let statusCode = 500;
|
|
24
|
+
switch (errorType) {
|
|
25
|
+
case QUERY_RUNNER_RELEASED:
|
|
26
|
+
case TRANSACTION_STARTED:
|
|
27
|
+
case TRANSACTION_NOT_STARTED:
|
|
28
|
+
case utils_1.MedusaError.Types.CONFLICT:
|
|
29
|
+
statusCode = 409;
|
|
30
|
+
errObj.code = INVALID_STATE_ERROR;
|
|
31
|
+
errObj.message =
|
|
32
|
+
"The request conflicted with another request. You may retry the request with the provided Idempotency-Key.";
|
|
33
|
+
break;
|
|
34
|
+
case utils_1.MedusaError.Types.UNAUTHORIZED:
|
|
35
|
+
statusCode = 401;
|
|
36
|
+
break;
|
|
37
|
+
case utils_1.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR:
|
|
38
|
+
statusCode = 422;
|
|
39
|
+
break;
|
|
40
|
+
case utils_1.MedusaError.Types.DUPLICATE_ERROR:
|
|
41
|
+
statusCode = 422;
|
|
42
|
+
errObj.code = INVALID_REQUEST_ERROR;
|
|
43
|
+
break;
|
|
44
|
+
case utils_1.MedusaError.Types.NOT_ALLOWED:
|
|
45
|
+
case utils_1.MedusaError.Types.INVALID_DATA:
|
|
46
|
+
statusCode = 400;
|
|
47
|
+
break;
|
|
48
|
+
case utils_1.MedusaError.Types.NOT_FOUND:
|
|
49
|
+
statusCode = 404;
|
|
50
|
+
break;
|
|
51
|
+
case utils_1.MedusaError.Types.DB_ERROR:
|
|
52
|
+
statusCode = 500;
|
|
53
|
+
errObj.code = API_ERROR;
|
|
54
|
+
break;
|
|
55
|
+
case utils_1.MedusaError.Types.UNEXPECTED_STATE:
|
|
56
|
+
case utils_1.MedusaError.Types.INVALID_ARGUMENT:
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
errObj.code = "unknown_error";
|
|
60
|
+
errObj.message = "An unknown error occurred.";
|
|
61
|
+
errObj.type = "unknown_error";
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
res.status(statusCode).json(errObj);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @schema Error
|
|
69
|
+
* title: "Response Error"
|
|
70
|
+
* type: object
|
|
71
|
+
* properties:
|
|
72
|
+
* code:
|
|
73
|
+
* type: string
|
|
74
|
+
* description: A slug code to indicate the type of the error.
|
|
75
|
+
* enum: [invalid_state_error, invalid_request_error, api_error, unknown_error]
|
|
76
|
+
* message:
|
|
77
|
+
* type: string
|
|
78
|
+
* description: Description of the error that occurred.
|
|
79
|
+
* example: "first_name must be a string"
|
|
80
|
+
* type:
|
|
81
|
+
* type: string
|
|
82
|
+
* description: A slug indicating the type of the error.
|
|
83
|
+
* enum: [QueryRunnerAlreadyReleasedError, TransactionAlreadyStartedError, TransactionNotStartedError, conflict, unauthorized, payment_authorization_error, duplicate_error, not_allowed, invalid_data, not_found, database_error, unexpected_state, invalid_argument, unknown_error]
|
|
84
|
+
*/
|
|
85
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/http/middlewares/error-handler.ts"],"names":[],"mappings":";;AAcA,oCAiEC;AA7ED,0CAAuE;AACvE,+DAAuD;AAGvD,MAAM,qBAAqB,GAAG,iCAAiC,CAAA;AAC/D,MAAM,mBAAmB,GAAG,gCAAgC,CAAA;AAC5D,MAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAE5D,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,qBAAqB,GAAG,uBAAuB,CAAA;AACrD,MAAM,mBAAmB,GAAG,qBAAqB,CAAA;AAEjD,SAAgB,YAAY;IAC1B,OAAO,SAAS,gBAAgB,CAC9B,GAAgB,EAChB,GAAkB,EAClB,GAAa,EACb,CAAe;QAEf,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,iCAAyB,CAAC,MAAM,CAAC,CAAA;QAElE,GAAG,GAAG,IAAA,qCAAe,EAAC,GAAG,CAAC,CAAA;QAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAEjB,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAA;QAEtC,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;SAC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AI,GAAG,eAAe,CAAA;gBAC7B,MAAK;QACT,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrC,CAAmC,CAAA;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MedusaError } from "@8medusa/utils";
|
|
2
|
+
export declare enum PostgresError {
|
|
3
|
+
DUPLICATE_ERROR = "23505",
|
|
4
|
+
FOREIGN_KEY_ERROR = "23503",
|
|
5
|
+
SERIALIZATION_FAILURE = "40001",
|
|
6
|
+
NULL_VIOLATION = "23502"
|
|
7
|
+
}
|
|
8
|
+
export declare const formatException: (err: any) => MedusaError;
|
|
9
|
+
//# sourceMappingURL=exception-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-formatter.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/exception-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,oBAAY,aAAa;IACvB,eAAe,UAAU;IACzB,iBAAiB,UAAU;IAC3B,qBAAqB,UAAU;IAC/B,cAAc,UAAU;CACzB;AAED,eAAO,MAAM,eAAe,gBAAU,WA8CrC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatException = exports.PostgresError = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
var PostgresError;
|
|
6
|
+
(function (PostgresError) {
|
|
7
|
+
PostgresError["DUPLICATE_ERROR"] = "23505";
|
|
8
|
+
PostgresError["FOREIGN_KEY_ERROR"] = "23503";
|
|
9
|
+
PostgresError["SERIALIZATION_FAILURE"] = "40001";
|
|
10
|
+
PostgresError["NULL_VIOLATION"] = "23502";
|
|
11
|
+
})(PostgresError || (exports.PostgresError = PostgresError = {}));
|
|
12
|
+
const formatException = (err) => {
|
|
13
|
+
switch (err.code) {
|
|
14
|
+
case PostgresError.DUPLICATE_ERROR:
|
|
15
|
+
return new utils_1.MedusaError(utils_1.MedusaError.Types.DUPLICATE_ERROR, `${err.table.charAt(0).toUpperCase()}${err.table.slice(1)} with ${err.detail.slice(4).replace(/[()=]/g, (s) => {
|
|
16
|
+
return s === "=" ? " " : "";
|
|
17
|
+
})}`);
|
|
18
|
+
case PostgresError.FOREIGN_KEY_ERROR: {
|
|
19
|
+
const matches = /Key \(([\w-\d]+)\)=\(([\w-\d]+)\) is not present in table "(\w+)"/g.exec(err.detail);
|
|
20
|
+
if (matches?.length !== 4) {
|
|
21
|
+
return new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, JSON.stringify(matches));
|
|
22
|
+
}
|
|
23
|
+
return new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `${matches[3]?.charAt(0).toUpperCase()}${matches[3]?.slice(1)} with ${matches[1]} ${matches[2]} does not exist.`);
|
|
24
|
+
}
|
|
25
|
+
case PostgresError.SERIALIZATION_FAILURE: {
|
|
26
|
+
return new utils_1.MedusaError(utils_1.MedusaError.Types.CONFLICT, err?.detail ?? err?.message);
|
|
27
|
+
}
|
|
28
|
+
case PostgresError.NULL_VIOLATION: {
|
|
29
|
+
return new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Can't insert null value in field ${err?.column} on insert in table ${err?.table}`);
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.formatException = formatException;
|
|
36
|
+
//# sourceMappingURL=exception-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-formatter.js","sourceRoot":"","sources":["../../../src/http/middlewares/exception-formatter.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAE5C,IAAY,aAKX;AALD,WAA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,IAAI,OAAO,CAAC,CAAC,CAAC,kBAAkB,CACjC,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACzC,OAAO,IAAI,mBAAW,CACpB,mBAAW,CAAC,KAAK,CAAC,QAAQ,EAC1B,GAAG,EAAE,MAAM,IAAI,GAAG,EAAE,OAAO,CAC5B,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;YAClC,OAAO,IAAI,mBAAW,CACpB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,oCAAoC,GAAG,EAAE,MAAM,uBAAuB,GAAG,EAAE,KAAK,EAAE,CACnF,CAAA;QACH,CAAC;QACD;YACE,OAAO,GAAG,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AA9CY,QAAA,eAAe,mBA8C3B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./authenticate-middleware";
|
|
2
|
+
export * from "./error-handler";
|
|
3
|
+
export * from "./exception-formatter";
|
|
4
|
+
export * from "./apply-default-filters";
|
|
5
|
+
export * from "./apply-params-as-filters";
|
|
6
|
+
export * from "./clear-filters-by-key";
|
|
7
|
+
export * from "./set-context";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
__exportStar(require("./authenticate-middleware"), exports);
|
|
18
|
+
__exportStar(require("./error-handler"), exports);
|
|
19
|
+
__exportStar(require("./exception-formatter"), exports);
|
|
20
|
+
__exportStar(require("./apply-default-filters"), exports);
|
|
21
|
+
__exportStar(require("./apply-params-as-filters"), exports);
|
|
22
|
+
__exportStar(require("./clear-filters-by-key"), exports);
|
|
23
|
+
__exportStar(require("./set-context"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAyC;AACzC,kDAA+B;AAC/B,wDAAqC;AACrC,0DAAuC;AACvC,4DAAyC;AACzC,yDAAsC;AACtC,gDAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-context.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/set-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE5D,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAClC,aAAa,gBAAW,kBAAkB,mBAiB9D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setContext = setContext;
|
|
4
|
+
function setContext(context) {
|
|
5
|
+
return async (req, _, next) => {
|
|
6
|
+
const ctx = { ...(req.context || {}) };
|
|
7
|
+
for (const [contextKey, contextValue] of Object.entries(context || {})) {
|
|
8
|
+
let valueToApply = contextValue;
|
|
9
|
+
if (typeof contextValue === "function") {
|
|
10
|
+
valueToApply = await contextValue(req, ctx);
|
|
11
|
+
}
|
|
12
|
+
ctx[contextKey] = valueToApply;
|
|
13
|
+
}
|
|
14
|
+
req.context = ctx;
|
|
15
|
+
return next();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=set-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-context.js","sourceRoot":"","sources":["../../../src/http/middlewares/set-context.ts"],"names":[],"mappings":";;AAEA,gCAkBC;AAlBD,SAAgB,UAAU,CAAC,OAA4B;IACrD,OAAO,KAAK,EAAE,GAAkB,EAAE,CAAC,EAAE,IAAwB,EAAE,EAAE;QAC/D,MAAM,GAAG,GAAwB,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAA;QAE3D,KAAK,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;YACvE,IAAI,YAAY,GAAG,YAAY,CAAA;YAE/B,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE,CAAC;gBACvC,YAAY,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAC7C,CAAC;YAED,GAAG,CAAC,UAAU,CAAC,GAAG,YAAY,CAAA;QAChC,CAAC;QAED,GAAG,CAAC,OAAO,GAAG,GAAG,CAAA;QAEjB,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Express, RequestHandler } from "express";
|
|
2
|
+
import type { MiddlewareFunction, RouteHandler } from "./types";
|
|
3
|
+
export declare class ApiLoader {
|
|
4
|
+
#private;
|
|
5
|
+
/**
|
|
6
|
+
* Wrap the original route handler implementation for
|
|
7
|
+
* instrumentation.
|
|
8
|
+
*/
|
|
9
|
+
static traceRoute?: (handler: RouteHandler, route: {
|
|
10
|
+
route: string;
|
|
11
|
+
method: string;
|
|
12
|
+
}) => RouteHandler;
|
|
13
|
+
/**
|
|
14
|
+
* Wrap the original middleware handler implementation for
|
|
15
|
+
* instrumentation.
|
|
16
|
+
*/
|
|
17
|
+
static traceMiddleware?: (handler: RequestHandler | MiddlewareFunction, route: {
|
|
18
|
+
route: string;
|
|
19
|
+
method?: string;
|
|
20
|
+
}) => RequestHandler | MiddlewareFunction;
|
|
21
|
+
constructor({ app, sourceDir, baseRestrictedFields, }: {
|
|
22
|
+
app: Express;
|
|
23
|
+
sourceDir: string | string[];
|
|
24
|
+
baseRestrictedFields?: string[];
|
|
25
|
+
});
|
|
26
|
+
load(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/http/router.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAuB,MAAM,SAAS,CAAA;AAC3E,OAAO,KAAK,EAKV,kBAAkB,EAIlB,YAAY,EAEb,MAAM,SAAS,CAAA;AAchB,qBAAa,SAAS;;IACpB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EAAE,CAClB,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KACrC,YAAY,CAAA;IAEjB;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,EAAE,CACvB,OAAO,EAAE,cAAc,GAAG,kBAAkB,EAC5C,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KACtC,cAAc,GAAG,kBAAkB,CAAA;gBAc5B,EACV,GAAG,EACH,SAAS,EACT,oBAAyB,GAC1B,EAAE;QACD,GAAG,EAAE,OAAO,CAAA;QACZ,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QAC5B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAChC;IAmRK,IAAI;CA6GX"}
|