arkos 1.4.0-canary.50 → 1.4.0-canary.53
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/dist/cjs/app.js +101 -62
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/index.js +3 -1
- package/dist/cjs/exports/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +1 -1
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +2 -2
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +3 -7
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +2 -2
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +3 -3
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +4 -4
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +10 -10
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +4 -4
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +9 -9
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +9 -9
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +4 -4
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +7 -7
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/cjs/server.js +32 -30
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/new-arkos-config.js +3 -0
- package/dist/cjs/types/new-arkos-config.js.map +1 -0
- package/dist/cjs/utils/arkos-router/index.js +10 -8
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/route-config-validator.js +3 -2
- package/dist/cjs/utils/arkos-router/route-config-validator.js.map +1 -1
- package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js +3 -0
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +16 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js.map +1 -1
- package/dist/cjs/utils/define-config.js +7 -0
- package/dist/cjs/utils/define-config.js.map +1 -0
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +19 -19
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/app.js +101 -62
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/exports/index.js +2 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js +1 -1
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +2 -2
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js +3 -7
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/base/base.router.js +2 -2
- package/dist/esm/modules/base/base.router.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +1 -1
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +3 -3
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +4 -4
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +10 -10
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +4 -4
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +9 -9
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +9 -9
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +4 -4
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +7 -7
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/esm/server.js +32 -28
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/types/arkos-config.js.map +1 -1
- package/dist/esm/types/new-arkos-config.js +2 -0
- package/dist/esm/types/new-arkos-config.js.map +1 -0
- package/dist/esm/utils/arkos-router/index.js +10 -8
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/route-config-validator.js +3 -2
- package/dist/esm/utils/arkos-router/route-config-validator.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/index.js +3 -0
- package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +15 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js.map +1 -1
- package/dist/esm/utils/define-config.js +4 -0
- package/dist/esm/utils/define-config.js.map +1 -0
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +19 -19
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/types/app.d.ts +2 -2
- package/dist/types/exports/index.d.ts +4 -2
- package/dist/types/modules/auth/auth.controller.d.ts +2 -2
- package/dist/types/modules/auth/auth.router.d.ts +2 -2
- package/dist/types/modules/auth/auth.service.d.ts +1 -1
- package/dist/types/modules/base/base.router.d.ts +2 -2
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +1 -1
- package/dist/types/modules/file-upload/file-upload.router.d.ts +2 -2
- package/dist/types/modules/swagger/swagger.router.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +2 -2
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +3 -3
- package/dist/types/server.d.ts +6 -5
- package/dist/types/types/arkos-config.d.ts +3 -181
- package/dist/types/types/new-arkos-config.d.ts +166 -0
- package/dist/types/utils/arkos-router/index.d.ts +2 -2
- package/dist/types/utils/arkos-router/types/index.d.ts +25 -1
- package/dist/types/utils/cli/utils/cli.helpers.d.ts +2 -0
- package/dist/types/utils/define-config.d.ts +2 -0
- package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/app.js
CHANGED
|
@@ -55,23 +55,31 @@ const swagger_router_1 = require("./modules/swagger/swagger.router");
|
|
|
55
55
|
const dynamic_loader_1 = require("./utils/dynamic-loader");
|
|
56
56
|
const error_handler_1 = require("./exports/error-handler");
|
|
57
57
|
const debugger_service_1 = __importDefault(require("./modules/debugger/debugger.service"));
|
|
58
|
+
const exports_1 = require("./exports");
|
|
58
59
|
exports.app = (0, express_1.default)();
|
|
59
60
|
const knowModulesRouter = (0, express_1.Router)();
|
|
60
|
-
async function bootstrap(
|
|
61
|
+
async function bootstrap(initConfig) {
|
|
62
|
+
const arkosConfig = (0, exports_1.getArkosConfig)();
|
|
61
63
|
await Promise.all([
|
|
62
64
|
(0, prisma_helpers_1.loadPrismaModule)(),
|
|
63
65
|
(0, dynamic_loader_1.loadAllModuleComponents)(arkosConfig),
|
|
64
|
-
|
|
66
|
+
initConfig?.configureApp && (await initConfig?.configureApp(exports.app)),
|
|
65
67
|
]);
|
|
66
68
|
const middlewaresConfig = arkosConfig?.middlewares;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (middlewaresConfig?.compression !== false) {
|
|
70
|
+
if (typeof middlewaresConfig?.compression === "function") {
|
|
71
|
+
exports.app.use(middlewaresConfig.compression);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
exports.app.use((0, compression_1.default)(middlewaresConfig?.compression || {}));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (middlewaresConfig?.rateLimit !== false) {
|
|
78
|
+
if (typeof middlewaresConfig?.rateLimit === "function") {
|
|
79
|
+
exports.app.use(middlewaresConfig.rateLimit);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
exports.app.use((0, express_rate_limit_1.rateLimit)((0, deepmerge_helper_1.default)({
|
|
75
83
|
windowMs: 60 * 1000,
|
|
76
84
|
limit: 300,
|
|
77
85
|
standardHeaders: "draft-7",
|
|
@@ -81,14 +89,20 @@ async function bootstrap(arkosConfig) {
|
|
|
81
89
|
message: "Too many requests, please try again later",
|
|
82
90
|
});
|
|
83
91
|
},
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
}, middlewaresConfig?.rateLimit || {})));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (middlewaresConfig?.cors !== false) {
|
|
96
|
+
if (typeof middlewaresConfig?.cors === "function") {
|
|
97
|
+
exports.app.use(middlewaresConfig.cors);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
exports.app.use((0, cors_1.default)(middlewaresConfig?.cors?.customHandler
|
|
101
|
+
? middlewaresConfig.cors.customHandler
|
|
89
102
|
: (0, deepmerge_helper_1.default)({
|
|
90
103
|
origin: (origin, cb) => {
|
|
91
|
-
const allowed =
|
|
104
|
+
const allowed = middlewaresConfig?.cors
|
|
105
|
+
?.allowedOrigins;
|
|
92
106
|
if (allowed === "*")
|
|
93
107
|
cb(null, true);
|
|
94
108
|
else if (Array.isArray(allowed))
|
|
@@ -105,61 +119,80 @@ async function bootstrap(arkosConfig) {
|
|
|
105
119
|
"Connection",
|
|
106
120
|
],
|
|
107
121
|
credentials: true,
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
}, middlewaresConfig?.cors?.options || {})));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (middlewaresConfig?.expressJson !== false) {
|
|
126
|
+
if (typeof middlewaresConfig?.expressJson === "function") {
|
|
127
|
+
exports.app.use(middlewaresConfig.expressJson);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
exports.app.use(express_1.default.json(middlewaresConfig?.expressJson || {}));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (middlewaresConfig?.cookieParser !== false) {
|
|
134
|
+
if (typeof middlewaresConfig?.cookieParser === "function") {
|
|
135
|
+
exports.app.use(middlewaresConfig.cookieParser);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const params = Array.isArray(middlewaresConfig?.cookieParser)
|
|
139
|
+
? middlewaresConfig.cookieParser
|
|
140
|
+
: [];
|
|
141
|
+
exports.app.use((0, cookie_parser_1.default)(...params));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (middlewaresConfig?.queryParser !== false) {
|
|
145
|
+
if (typeof middlewaresConfig?.queryParser === "function") {
|
|
146
|
+
exports.app.use(middlewaresConfig.queryParser);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
exports.app.use((0, query_parser_helpers_1.queryParser)((0, deepmerge_helper_1.default)({
|
|
118
150
|
parseNull: true,
|
|
119
151
|
parseUndefined: true,
|
|
120
152
|
parseBoolean: true,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
153
|
+
parseNumber: true,
|
|
154
|
+
}, middlewaresConfig?.queryParser || {})));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (middlewaresConfig?.requestLogger !== false) {
|
|
158
|
+
if (typeof middlewaresConfig?.requestLogger === "function") {
|
|
159
|
+
exports.app.use(middlewaresConfig.requestLogger);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
exports.app.use(base_middlewares_1.handleRequestLogs);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
128
165
|
exports.app.use(debugger_service_1.default.logRequestInfo);
|
|
129
166
|
const routersConfig = arkosConfig?.routers;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
167
|
+
if (routersConfig?.welcomeRoute !== false) {
|
|
168
|
+
if (typeof routersConfig?.welcomeRoute === "function") {
|
|
169
|
+
exports.app.get("/api", routersConfig.welcomeRoute);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
exports.app.get("/api", (_, res) => {
|
|
135
173
|
res.status(200).json({ message: arkosConfig.welcomeMessage });
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
if (!disabledRouters?.includes?.("file-upload")) {
|
|
139
|
-
const fileUploadRouter = replacedRouters.fileUpload
|
|
140
|
-
? await replacedRouters.fileUpload(arkosConfig)
|
|
141
|
-
: await (0, file_upload_router_1.getFileUploadRouter)(arkosConfig);
|
|
142
|
-
knowModulesRouter.use(fileUploadRouter);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
143
176
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
exports.app.use(debugger_service_1.default.logRequestInfo);
|
|
178
|
+
if (initConfig?.middlewares)
|
|
179
|
+
for (const mw of initConfig.middlewares) {
|
|
180
|
+
exports.app.use(mw);
|
|
181
|
+
}
|
|
182
|
+
if (initConfig?.routers)
|
|
183
|
+
for (const router of initConfig.routers) {
|
|
184
|
+
exports.app.use(router);
|
|
185
|
+
}
|
|
186
|
+
const fileUploadRouter = (0, file_upload_router_1.getFileUploadRouter)(arkosConfig);
|
|
187
|
+
knowModulesRouter.use(fileUploadRouter);
|
|
188
|
+
if (arkosConfig.authentication) {
|
|
189
|
+
const authRouter = (0, auth_router_1.getAuthRouter)(arkosConfig);
|
|
149
190
|
knowModulesRouter.use("/api", authRouter);
|
|
150
191
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
? await replacedRouters.prismaModelsRouter(arkosConfig)
|
|
154
|
-
: await (0, base_router_1.getPrismaModelsRouter)(arkosConfig);
|
|
155
|
-
knowModulesRouter.use("/api", modelsRouter);
|
|
156
|
-
}
|
|
192
|
+
const modelsRouter = (0, base_router_1.getPrismaModelsRouter)(arkosConfig);
|
|
193
|
+
knowModulesRouter.use("/api", modelsRouter);
|
|
157
194
|
exports.app.use(knowModulesRouter);
|
|
158
195
|
exports.app.use("/api", (0, base_router_1.getAvailableResourcesAndRoutesRouter)());
|
|
159
|
-
if (routersConfig?.additional)
|
|
160
|
-
routersConfig.additional.forEach((router) => {
|
|
161
|
-
exports.app.use(router);
|
|
162
|
-
});
|
|
163
196
|
if (arkosConfig.swagger &&
|
|
164
197
|
(process.env.ARKOS_BUILD !== "true" ||
|
|
165
198
|
arkosConfig.swagger.enableAfterBuild === true))
|
|
@@ -167,8 +200,14 @@ async function bootstrap(arkosConfig) {
|
|
|
167
200
|
exports.app.use("*", (req) => {
|
|
168
201
|
throw new error_handler_1.AppError("Route not found", 404, { route: req.path }, "RouteNotFound");
|
|
169
202
|
});
|
|
170
|
-
if (
|
|
171
|
-
|
|
203
|
+
if (middlewaresConfig?.errorHandler !== false) {
|
|
204
|
+
if (typeof middlewaresConfig?.errorHandler === "function") {
|
|
205
|
+
exports.app.use(middlewaresConfig.errorHandler);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
exports.app.use(error_handler_controller_1.default);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
172
211
|
return exports.app;
|
|
173
212
|
}
|
|
174
213
|
//# sourceMappingURL=app.js.map
|
package/dist/cjs/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,8BAuLC;AAhND,mDAA0C;AAC1C,gDAAwB;AACxB,kEAAyC;AACzC,4DAA2D;AAC3D,4DAGoC;AACpC,gHAA4E;AAC5E,2DAA+C;AAC/C,8DAAsC;AACtC,sEAAoE;AACpE,mEAAkE;AAClE,iFAA+E;AAE/E,+EAAmE;AACnE,wFAAyD;AACzD,qEAAoE;AACpE,2DAAiE;AACjE,2DAAmD;AACnD,2FAAkE;AAErD,QAAA,GAAG,GAAoB,IAAA,iBAAO,GAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAA,gBAAM,GAAE,CAAC;AAE5B,KAAK,UAAU,SAAS,CAC7B,WAAwB;IAExB,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,IAAA,iCAAgB,GAAE;QAClB,IAAA,wCAAuB,EAAC,WAAW,CAAC;QACpC,WAAW,EAAE,YAAY,IAAI,CAAC,MAAM,WAAW,EAAE,YAAY,CAAC,WAAG,CAAC,CAAC;KACpE,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,WAAW,EAAE,WAAW,CAAC;IACnD,MAAM,mBAAmB,GAAG,iBAAiB,EAAE,OAAO,IAAI,EAAE,CAAC;IAC7D,MAAM,mBAAmB,GAAG,iBAAiB,EAAE,OAAO,IAAI,EAAE,CAAC;IAE7D,IAAI,CAAC,mBAAmB,EAAE,QAAQ,EAAE,CAAC,aAAa,CAAC;QACjD,WAAG,CAAC,GAAG,CACL,mBAAmB,CAAC,WAAW;YAC7B,IAAA,qBAAW,EAAC,WAAW,EAAE,kBAAkB,CAAC,CAC/C,CAAC;IAEJ,IAAI,CAAC,m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AAI,CAAC,mBAAmB,EAAE,QAAQ,EAAE,CAAC,sBAAsB,CAAC;QAC1D,WAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,kBAAkB,IAAI,kCAAY,CAAC,CAAC;IAElE,OAAO,WAAG,CAAC;AACb,CAAC","sourcesContent":["import express, { Router } from \"express\";\nimport cors from \"cors\";\nimport cookieParser from \"cookie-parser\";\nimport { getAuthRouter } from \"./modules/auth/auth.router\";\nimport {\n getPrismaModelsRouter,\n getAvailableResourcesAndRoutesRouter,\n} from \"./modules/base/base.router\";\nimport errorHandler from \"./modules/error-handler/error-handler.controller\";\nimport { rateLimit } from \"express-rate-limit\";\nimport compression from \"compression\";\nimport { handleRequestLogs } from \"./modules/base/base.middlewares\";\nimport { loadPrismaModule } from \"./utils/helpers/prisma.helpers\";\nimport { getFileUploadRouter } from \"./modules/file-upload/file-upload.router\";\nimport { ArkosConfig } from \"./types/arkos-config\";\nimport { queryParser } from \"./utils/helpers/query-parser.helpers\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\nimport { getSwaggerRouter } from \"./modules/swagger/swagger.router\";\nimport { loadAllModuleComponents } from \"./utils/dynamic-loader\";\nimport { AppError } from \"./exports/error-handler\";\nimport debuggerService from \"./modules/debugger/debugger.service\";\n\nexport const app: express.Express = express();\nconst knowModulesRouter = Router();\n\nexport async function bootstrap(\n arkosConfig: ArkosConfig\n): Promise<express.Express> {\n await Promise.all([\n loadPrismaModule(),\n loadAllModuleComponents(arkosConfig),\n arkosConfig?.configureApp && (await arkosConfig?.configureApp(app)),\n ]);\n\n const middlewaresConfig = arkosConfig?.middlewares;\n const disabledMiddlewares = middlewaresConfig?.disable || [];\n const replacedMiddlewares = middlewaresConfig?.replace || {};\n\n if (!disabledMiddlewares?.includes?.(\"compression\"))\n app.use(\n replacedMiddlewares.compression ||\n compression(arkosConfig?.compressionOptions)\n );\n\n if (!disabledMiddlewares?.includes?.(\"global-rate-limit\"))\n app.use(\n replacedMiddlewares.globalRateLimit ||\n rateLimit(\n deepmerge(\n {\n windowMs: 60 * 1000,\n limit: 300,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfig?.globalRequestRateLimitOptions || {}\n )\n )\n );\n\n if (!disabledMiddlewares?.includes?.(\"cors\"))\n app.use(\n replacedMiddlewares.cors ||\n cors(\n arkosConfig?.cors?.customHandler\n ? arkosConfig.cors.customHandler\n : deepmerge(\n {\n origin: (\n origin: string,\n cb: (err: Error | null, allow?: boolean) => void\n ) => {\n const allowed = arkosConfig?.cors?.allowedOrigins;\n\n if (allowed === \"*\") cb(null, true);\n else if (Array.isArray(allowed))\n cb(null, !origin || allowed?.includes?.(origin));\n else if (typeof allowed === \"string\")\n cb(null, !origin || allowed === origin);\n else cb(null, false);\n },\n\n methods: [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"],\n allowedHeaders: [\n \"Content-Type\",\n \"Authorization\",\n \"Connection\",\n ],\n credentials: true,\n },\n arkosConfig?.cors?.options || {}\n )\n )\n );\n\n if (!disabledMiddlewares?.includes?.(\"express-json\"))\n app.use(\n replacedMiddlewares.expressJson ||\n express.json(arkosConfig?.jsonBodyParserOptions)\n );\n\n if (!disabledMiddlewares?.includes?.(\"cookie-parser\"))\n app.use(\n replacedMiddlewares.cookieParser ||\n cookieParser(...[...(arkosConfig?.cookieParserParameters || [])])\n );\n\n if (!disabledMiddlewares?.includes?.(\"query-parser\"))\n app.use(\n replacedMiddlewares.queryParser ||\n queryParser(\n deepmerge(\n {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n },\n arkosConfig?.queryParserOptions || {}\n )\n )\n );\n\n if (!disabledMiddlewares?.includes?.(\"request-logger\"))\n app.use(replacedMiddlewares.requestLogger || handleRequestLogs);\n\n if (arkosConfig?.middlewares?.additional)\n arkosConfig.middlewares.additional.forEach((middleware) => {\n app.use(middleware);\n });\n\n app.use(debuggerService.logRequestInfo);\n\n const routersConfig = arkosConfig?.routers;\n const disabledRouters = routersConfig?.disable || [];\n const replacedRouters = routersConfig?.replace || {};\n\n if (!disabledRouters?.includes?.(\"welcome-endpoint\"))\n app.get(\n \"/api\",\n replacedRouters.welcomeEndpoint ||\n ((_, res) => {\n res.status(200).json({ message: arkosConfig.welcomeMessage });\n })\n );\n\n app.use(debuggerService.logRequestInfo);\n\n if (!disabledRouters?.includes?.(\"file-upload\")) {\n const fileUploadRouter = replacedRouters.fileUpload\n ? await replacedRouters.fileUpload(arkosConfig)\n : await getFileUploadRouter(arkosConfig);\n knowModulesRouter.use(fileUploadRouter);\n }\n\n if (\n !disabledRouters?.includes?.(\"auth-router\") &&\n arkosConfig.authentication\n ) {\n const authRouter = replacedRouters.authRouter\n ? await replacedRouters.authRouter(arkosConfig)\n : await getAuthRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", authRouter);\n }\n\n if (!disabledRouters?.includes?.(\"prisma-models-router\")) {\n const modelsRouter = replacedRouters.prismaModelsRouter\n ? await replacedRouters.prismaModelsRouter(arkosConfig)\n : await getPrismaModelsRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", modelsRouter);\n }\n\n app.use(knowModulesRouter);\n app.use(\"/api\", getAvailableResourcesAndRoutesRouter());\n\n if (routersConfig?.additional)\n routersConfig.additional.forEach((router) => {\n app.use(router as any);\n });\n\n /**\n * Must be last called in order to be able to get all\n * routes built using ArkosRouter\n */\n if (\n arkosConfig.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n arkosConfig.swagger.enableAfterBuild === true)\n )\n app.use(\"/api\", await getSwaggerRouter(arkosConfig, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n \"Route not found\",\n 404,\n { route: req.path },\n \"RouteNotFound\"\n );\n });\n\n if (!disabledMiddlewares?.includes?.(\"global-error-handler\"))\n app.use(replacedMiddlewares.globalErrorHandler || errorHandler);\n\n return app;\n}\n"]}
|
|
1
|
+
{"version":3,"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AC,GAAG,CAAC,MAAM,EAAE,MAAM,IAAA,iCAAgB,EAAC,WAAW,EAAE,WAAG,CAAC,CAAC,CAAC;IAE5D,WAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACnB,MAAM,IAAI,wBAAQ,CAChB,iBAAiB,EACjB,GAAG,EACH,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACnB,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,iBAAiB,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC9C,IAAI,OAAO,iBAAiB,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YAC1D,WAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,WAAG,CAAC,GAAG,CAAC,kCAAY,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,WAAG,CAAC;AACb,CAAC","sourcesContent":["import express, { IRouter, Router } from \"express\";\nimport cors from \"cors\";\nimport cookieParser from \"cookie-parser\";\nimport { getAuthRouter } from \"./modules/auth/auth.router\";\nimport {\n getPrismaModelsRouter,\n getAvailableResourcesAndRoutesRouter,\n} from \"./modules/base/base.router\";\nimport errorHandler from \"./modules/error-handler/error-handler.controller\";\nimport { rateLimit } from \"express-rate-limit\";\nimport compression from \"compression\";\nimport { handleRequestLogs } from \"./modules/base/base.middlewares\";\nimport { loadPrismaModule } from \"./utils/helpers/prisma.helpers\";\nimport { getFileUploadRouter } from \"./modules/file-upload/file-upload.router\";\nimport { queryParser } from \"./utils/helpers/query-parser.helpers\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\nimport { getSwaggerRouter } from \"./modules/swagger/swagger.router\";\nimport { loadAllModuleComponents } from \"./utils/dynamic-loader\";\nimport { AppError } from \"./exports/error-handler\";\nimport debuggerService from \"./modules/debugger/debugger.service\";\nimport { getArkosConfig } from \"./exports\";\nimport { ArkosInitConfig } from \"./types/arkos-config\";\nexport const app: express.Express = express();\nconst knowModulesRouter = Router();\n\nexport async function bootstrap(\n initConfig: ArkosInitConfig\n): Promise<express.Express> {\n const arkosConfig = getArkosConfig();\n\n await Promise.all([\n loadPrismaModule(),\n loadAllModuleComponents(arkosConfig),\n initConfig?.configureApp && (await initConfig?.configureApp(app)),\n ]);\n\n const middlewaresConfig = arkosConfig?.middlewares;\n\n if (middlewaresConfig?.compression !== false) {\n if (typeof middlewaresConfig?.compression === \"function\") {\n app.use(middlewaresConfig.compression);\n } else {\n app.use(compression(middlewaresConfig?.compression || {}));\n }\n }\n\n if (middlewaresConfig?.rateLimit !== false) {\n if (typeof middlewaresConfig?.rateLimit === \"function\") {\n app.use(middlewaresConfig.rateLimit);\n } else {\n app.use(\n rateLimit(\n deepmerge(\n {\n windowMs: 60 * 1000,\n limit: 300,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n middlewaresConfig?.rateLimit || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.cors !== false) {\n if (typeof middlewaresConfig?.cors === \"function\") {\n app.use(middlewaresConfig.cors);\n } else {\n app.use(\n cors(\n middlewaresConfig?.cors?.customHandler\n ? middlewaresConfig.cors.customHandler\n : deepmerge(\n {\n origin: (\n origin: string,\n cb: (err: Error | null, allow?: boolean) => void\n ) => {\n const allowed = (middlewaresConfig?.cors as any)\n ?.allowedOrigins;\n\n if (allowed === \"*\") cb(null, true);\n else if (Array.isArray(allowed))\n cb(null, !origin || allowed?.includes?.(origin));\n else if (typeof allowed === \"string\")\n cb(null, !origin || allowed === origin);\n else cb(null, false);\n },\n\n methods: [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"],\n allowedHeaders: [\n \"Content-Type\",\n \"Authorization\",\n \"Connection\",\n ],\n credentials: true,\n },\n middlewaresConfig?.cors?.options || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.expressJson !== false) {\n if (typeof middlewaresConfig?.expressJson === \"function\") {\n app.use(middlewaresConfig.expressJson);\n } else {\n app.use(express.json(middlewaresConfig?.expressJson || {}));\n }\n }\n\n if (middlewaresConfig?.cookieParser !== false) {\n if (typeof middlewaresConfig?.cookieParser === \"function\") {\n app.use(middlewaresConfig.cookieParser);\n } else {\n const params = Array.isArray(middlewaresConfig?.cookieParser)\n ? middlewaresConfig.cookieParser\n : [];\n app.use(cookieParser(...(params as any))); // FIXME: check types correctly\n }\n }\n\n if (middlewaresConfig?.queryParser !== false) {\n if (typeof middlewaresConfig?.queryParser === \"function\") {\n app.use(middlewaresConfig.queryParser);\n } else {\n app.use(\n queryParser(\n deepmerge(\n {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n parseNumber: true,\n },\n middlewaresConfig?.queryParser || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.requestLogger !== false) {\n if (typeof middlewaresConfig?.requestLogger === \"function\") {\n app.use(middlewaresConfig.requestLogger);\n } else {\n app.use(handleRequestLogs);\n }\n }\n\n app.use(debuggerService.logRequestInfo);\n\n const routersConfig = arkosConfig?.routers;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get(\"/api\", routersConfig.welcomeRoute);\n } else {\n app.get(\"/api\", (_, res) => {\n res.status(200).json({ message: arkosConfig.welcomeMessage });\n });\n }\n }\n\n app.use(debuggerService.logRequestInfo);\n\n if (initConfig?.middlewares)\n for (const mw of initConfig.middlewares) {\n app.use(mw);\n }\n\n if (initConfig?.routers)\n for (const router of initConfig.routers) {\n app.use(router as IRouter);\n }\n\n const fileUploadRouter = getFileUploadRouter(arkosConfig);\n knowModulesRouter.use(fileUploadRouter);\n\n if (arkosConfig.authentication) {\n const authRouter = getAuthRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", modelsRouter);\n\n app.use(knowModulesRouter);\n app.use(\"/api\", getAvailableResourcesAndRoutesRouter());\n\n if (\n arkosConfig.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n arkosConfig.swagger.enableAfterBuild === true)\n )\n app.use(\"/api\", await getSwaggerRouter(arkosConfig, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n \"Route not found\",\n 404,\n { route: req.path },\n \"RouteNotFound\"\n );\n });\n\n if (middlewaresConfig?.errorHandler !== false) {\n if (typeof middlewaresConfig?.errorHandler === \"function\") {\n app.use(middlewaresConfig.errorHandler);\n } else {\n app.use(errorHandler);\n }\n }\n\n return app;\n}\n"]}
|
|
@@ -3,13 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ArkosRouter = exports.getArkosConfig = exports.BaseController = void 0;
|
|
6
|
+
exports.defineConfig = exports.ArkosRouter = exports.getArkosConfig = exports.BaseController = void 0;
|
|
7
7
|
const base_controller_1 = require("./../modules/base/base.controller");
|
|
8
8
|
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return base_controller_1.BaseController; } });
|
|
9
9
|
const server_1 = require("../server");
|
|
10
10
|
Object.defineProperty(exports, "getArkosConfig", { enumerable: true, get: function () { return server_1.getArkosConfig; } });
|
|
11
11
|
const arkos_router_1 = __importDefault(require("../utils/arkos-router"));
|
|
12
12
|
exports.ArkosRouter = arkos_router_1.default;
|
|
13
|
+
const define_config_1 = __importDefault(require("../utils/define-config"));
|
|
14
|
+
exports.defineConfig = define_config_1.default;
|
|
13
15
|
const arkos = {
|
|
14
16
|
init: server_1.initApp,
|
|
15
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":";;;;;;AACA,uEAAmE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":";;;;;;AACA,uEAAmE;AA6BjE,+FA7BO,gCAAc,OA6BP;AA5BhB,sCAAoD;AAgClD,+FAhCgB,uBAAc,OAgChB;AA/BhB,yEAAgD;AAwD9C,sBAxDK,sBAAW,CAwDL;AA9Cb,2EAAkD;AAgDhD,uBAhDK,uBAAY,CAgDL;AAxCd,MAAM,KAAK,GAAG;IACZ,IAAI,EAAE,gBAAO;CACd,CAAC;AA8CF,kBAAe,KAAK,CAAC","sourcesContent":["import { RouterConfig } from \"../types/router-config\";\nimport { BaseController } from \"./../modules/base/base.controller\";\nimport { initApp, getArkosConfig } from \"../server\";\nimport ArkosRouter from \"../utils/arkos-router\";\nimport { ArkosRouteConfig } from \"../utils/arkos-router/types\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../types\";\nimport { ArkosConfig } from \"../types/new-arkos-config\";\nimport { ArkosInitConfig } from \"../types/arkos-config\";\nimport defineConfig from \"../utils/define-config\";\n\n/**\n * Initializes the Arkos application.\n *\n * @module arkos\n * @property {Function} init - Function to initialize the app.\n */\nconst arkos = {\n init: initApp,\n};\n\nexport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n BaseController,\n ArkosConfig,\n ArkosInitConfig,\n RouterConfig,\n getArkosConfig,\n /**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * route: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\n ArkosRouter,\n ArkosRouteConfig,\n defineConfig,\n};\n\n/**\n * Main entry point for the Arkos module.\n *\n * @module arkos\n */\nexport default arkos;\n"]}
|
|
@@ -14,7 +14,7 @@ const auth_action_service_1 = __importDefault(require("./utils/services/auth-act
|
|
|
14
14
|
exports.defaultExcludedUserFields = {
|
|
15
15
|
password: false,
|
|
16
16
|
};
|
|
17
|
-
const authControllerFactory =
|
|
17
|
+
const authControllerFactory = (interceptors = {}) => {
|
|
18
18
|
const userService = new base_service_1.BaseService("user");
|
|
19
19
|
return {
|
|
20
20
|
getMe: (0, catch_async_1.default)(async (req, res, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;AAAA,qFAA4D;AAC5D,iFAAwD;AAExD,kEAAyC;AACzC,uDAAmD;AAEnD,yCAA8C;AAC9C,qFAIiD;AACjD,+FAAqE;AAKxD,QAAA,yBAAyB,GAAG;IACvC,QAAQ,EAAE,KAAK;CAChB,CAAC;AAQK,MAAM,qBAAqB,GAAG,KAAK,EAAE,eAAoB,EAAE,EAAE,EAAE;IACpE,MAAM,WAAW,GAAG,IAAI,0BAAW,CAAC,MAAM,CAAC,CAAC;IAE5C,OAAO;QAIL,KAAK,EAAE,IAAA,qBAAU,EACf,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACvB,EAAE;YACF,MAAM,IAAI,GAAG,CAAC,MAAM,WAAW,CAAC,OAAO,CACrC,EAAE,EAAE,EAAE,GAAG,CAAC,IAAK,CAAC,EAAE,EAAE,EACpB,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAC7B,CAAwB,CAAC;YAE1B,MAAM,CAAC,IAAI,CAAC,iCAAyB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACrD,IAAI,IAAI;oBAAE,OAAO,IAAI,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,WAAW;aAClB,CAAC,CAAC;QACL,CAAC,CACF;KACF,CAAC;AACJ,CAAC,CAAC;AAraW,QAAA,qBAAqB,yBAqahC","sourcesContent":["import catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"../../types\";\nimport authService from \"./auth.service\";\nimport { BaseService } from \"../base/base.service\";\nimport { User } from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n createPrismaWhereClause,\n determineUsernameField,\n getNestedValue,\n} from \"./utils/helpers/auth.controller.helpers\";\nimport authActionService from \"./utils/services/auth-action.service\";\n\n/**\n * Default fields to exclude from user object when returning to client\n */\nexport const defaultExcludedUserFields = {\n password: false,\n};\n\n/**\n * Factory function to create authentication controller with configurable interceptors\n *\n * @param interceptors - Optional middleware functions to execute after controller actions\n * @returns An object containing all authentication controller methods\n */\nexport const authControllerFactory = async (interceptors: any = {}) => {\n const userService = new BaseService(\"user\");\n\n return {\n /**\n * Retrieves the current authenticated user's information\n */\n getMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.findOne(\n { id: req.user!.id },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterGetMe) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Updates the current authenticated user's information\n */\n updateMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n {},\n \"InvalidFieldPassword\"\n );\n\n const user = (await userService.updateOne(\n { id: req.user!.id },\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterUpdateMe) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Logs out the current user by invalidating their access token cookie\n */\n logout: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (interceptors?.afterLogout) {\n (res as any).originalData = null;\n req.responseData = null;\n res.locals.data = null;\n (res as any).originalStatus = 204;\n req.responseStatus = 204;\n res.locals.status = 204;\n return next();\n }\n\n res.status(204).json();\n }\n ),\n\n /**\n * Authenticates a user using configurable username field and password\n * Username field can be specified in query parameter or config\n *\n * Supports nested fields and array queries (e.g., \"profile.nickname\", \"phones.some.number\")\n */\n login: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n // For the error message, we only care about the top-level field name\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\n\n const { password } = req.body;\n\n if (!usernameValue || !password)\n return next(\n new AppError(\n `Please provide both ${lastField} and password`,\n 400,\n `MissingCredentialFields`\n )\n );\n\n let whereClause: Record<string, any>;\n\n if (usernameField?.includes?.(\".\")) {\n const valueToFind = getNestedValue(req.body, usernameField);\n if (valueToFind === undefined) {\n return next(new AppError(`Invalid ${usernameField} provided`, 400));\n }\n whereClause = createPrismaWhereClause(usernameField, valueToFind);\n } else {\n whereClause = { [usernameField]: usernameValue };\n }\n\n const user = (await userService.findOne(\n whereClause,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (\n !user ||\n !(await authService.isCorrectPassword(password, user.password))\n ) {\n return next(\n new AppError(\n `Incorrect ${lastField} or password`,\n 401,\n `IncorrectCredentials`\n )\n );\n }\n\n const token = authService.signJwtToken(user.id!);\n\n const cookieOptions = authService.getJwtCookieOptions(req);\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n req.responseData = { accessToken: token };\n res.locals.data = { accessToken: token };\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.cookie(\"arkos_access_token\", token, cookieOptions);\n\n req.accessToken = token;\n\n if (interceptors?.afterLogin) {\n (res as any).originalData = req.responseData;\n req.additionalData = { user };\n res.locals.additional = { user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n res.status(200).json(req.responseData);\n } else if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.status(200).send();\n }\n ),\n\n /**\n * Creates a new user account using the userService\n */\n signup: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterSignup) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 201;\n req.responseStatus = 201;\n res.locals.status = 201;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete user[key as keyof User];\n });\n\n res.status(201).json({ data: user });\n }\n ),\n /**\n * Marks user account as self-deleted by setting deletedSelfAccountAt timestamp\n */\n deleteMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const userId = req.user!.id;\n\n const updatedUser = (await userService.updateOne(\n { id: userId },\n {\n deletedSelfAccountAt: new Date().toISOString(),\n },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterDeleteMe) {\n (res as any).originalData = { data: updatedUser };\n req.responseData = { data: updatedUser };\n res.locals.data = { data: updatedUser };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete updatedUser[key as keyof User];\n });\n\n res.status(200).json({\n message: \"Account deleted successfully\",\n });\n }\n ),\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const { currentPassword, newPassword } = req.body;\n\n if (!currentPassword || !newPassword)\n return next(\n new AppError(\n \"currentPassword and newPassword are required\",\n 400,\n \"SameCurrentAndNewPassword\"\n )\n );\n\n const user = req.user;\n\n if (!user || user?.isActive === false || user?.deletedSelfAccountAt)\n return next(new AppError(\"User not found!\", 404));\n\n const isPasswordCorrect = await authService.isCorrectPassword(\n String(currentPassword),\n String(user.password)\n );\n\n const configs = getArkosConfig();\n const initAuthConfigs = configs?.authentication;\n\n if (!isPasswordCorrect)\n return next(\n new AppError(\n \"Current password is incorrect\",\n 400,\n \"IncorrentCurrentPassword\"\n )\n );\n\n if (\n !authService.isPasswordStrong(String(newPassword)) &&\n !configs?.validation\n ) {\n return next(\n new AppError(\n initAuthConfigs?.passwordValidation?.message ||\n \"The new password must contain at least one uppercase letter, one lowercase letter, and one number\",\n 400,\n \"PasswordDoesNotMeetRequirements\"\n )\n );\n }\n\n await userService.updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()),\n }\n );\n\n const responseData = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n\n if (interceptors?.afterUpdatePassword) {\n (res as any).originalData = responseData;\n req.additionalData = { user };\n req.responseData = responseData;\n res.locals.data = responseData;\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json(responseData);\n }\n ),\n\n findManyAuthAction: catchAsync(\n async (_: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const authActions = authActionService.getAll()?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n\n findOneAuthAction: catchAsync(\n async (req: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const resourceName = req.params?.resourceName;\n\n if (!resourceName)\n throw new AppError(\n `Please provide a resoureName`,\n 400,\n \"MissiongResourseName\"\n );\n\n const authActions = authActionService\n .getByResource(req.params?.resourceName)\n ?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n if (!authActions)\n throw new AppError(\n `No auth action with resource name ${resourceName}`,\n 404,\n \"AuthActionNotFound\"\n );\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;AAAA,qFAA4D;AAC5D,iFAAwD;AAExD,kEAAyC;AACzC,uDAAmD;AAEnD,yCAA8C;AAC9C,qFAIiD;AACjD,+FAAqE;AAKxD,QAAA,yBAAy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B,8BAA8B,EAC9B,GAAG,EACH,sBAAsB,CACvB,CAAC;YAEJ,MAAM,WAAW,GAAG,6BAAiB;iBAClC,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;gBACxC,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;gBACnB,IAAI,WAAW,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS;oBACjD,OAAQ,UAAkB,EAAE,KAAK,CAAC;gBACpC,OAAO,UAAU,CAAC;YACpB,CAAC,CAAC,CAAC;YAEL,IAAI,CAAC,WAAW;gBACd,MAAM,IAAI,mBAAQ,CAChB,qCAAqC,YAAY,EAAE,EACnD,GAAG,EACH,oBAAoB,CACrB,CAAC;YAEJ,GAAG,CAAC,IAAI,CAAC;gBACP,KAAK,EAAE,WAAW,CAAC,MAAM;gBACzB,OAAO,EAAE,WAAW,CAAC,MAAM;gBAC3B,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC,CACF;KACF,CAAC;AACJ,CAAC,CAAC;AAraW,QAAA,qBAAqB,yBAqahC","sourcesContent":["import catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"../../types\";\nimport authService from \"./auth.service\";\nimport { BaseService } from \"../base/base.service\";\nimport { User } from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n createPrismaWhereClause,\n determineUsernameField,\n getNestedValue,\n} from \"./utils/helpers/auth.controller.helpers\";\nimport authActionService from \"./utils/services/auth-action.service\";\n\n/**\n * Default fields to exclude from user object when returning to client\n */\nexport const defaultExcludedUserFields = {\n password: false,\n};\n\n/**\n * Factory function to create authentication controller with configurable interceptors\n *\n * @param interceptors - Optional middleware functions to execute after controller actions\n * @returns An object containing all authentication controller methods\n */\nexport const authControllerFactory = (interceptors: any = {}) => {\n const userService = new BaseService(\"user\");\n\n return {\n /**\n * Retrieves the current authenticated user's information\n */\n getMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.findOne(\n { id: req.user!.id },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterGetMe) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Updates the current authenticated user's information\n */\n updateMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n {},\n \"InvalidFieldPassword\"\n );\n\n const user = (await userService.updateOne(\n { id: req.user!.id },\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterUpdateMe) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Logs out the current user by invalidating their access token cookie\n */\n logout: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (interceptors?.afterLogout) {\n (res as any).originalData = null;\n req.responseData = null;\n res.locals.data = null;\n (res as any).originalStatus = 204;\n req.responseStatus = 204;\n res.locals.status = 204;\n return next();\n }\n\n res.status(204).json();\n }\n ),\n\n /**\n * Authenticates a user using configurable username field and password\n * Username field can be specified in query parameter or config\n *\n * Supports nested fields and array queries (e.g., \"profile.nickname\", \"phones.some.number\")\n */\n login: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n // For the error message, we only care about the top-level field name\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\n\n const { password } = req.body;\n\n if (!usernameValue || !password)\n return next(\n new AppError(\n `Please provide both ${lastField} and password`,\n 400,\n `MissingCredentialFields`\n )\n );\n\n let whereClause: Record<string, any>;\n\n if (usernameField?.includes?.(\".\")) {\n const valueToFind = getNestedValue(req.body, usernameField);\n if (valueToFind === undefined) {\n return next(new AppError(`Invalid ${usernameField} provided`, 400));\n }\n whereClause = createPrismaWhereClause(usernameField, valueToFind);\n } else {\n whereClause = { [usernameField]: usernameValue };\n }\n\n const user = (await userService.findOne(\n whereClause,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (\n !user ||\n !(await authService.isCorrectPassword(password, user.password))\n ) {\n return next(\n new AppError(\n `Incorrect ${lastField} or password`,\n 401,\n `IncorrectCredentials`\n )\n );\n }\n\n const token = authService.signJwtToken(user.id!);\n\n const cookieOptions = authService.getJwtCookieOptions(req);\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n req.responseData = { accessToken: token };\n res.locals.data = { accessToken: token };\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.cookie(\"arkos_access_token\", token, cookieOptions);\n\n req.accessToken = token;\n\n if (interceptors?.afterLogin) {\n (res as any).originalData = req.responseData;\n req.additionalData = { user };\n res.locals.additional = { user };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n res.status(200).json(req.responseData);\n } else if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.status(200).send();\n }\n ),\n\n /**\n * Creates a new user account using the userService\n */\n signup: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterSignup) {\n (res as any).originalData = { data: user };\n req.responseData = { data: user };\n res.locals.data = { data: user };\n (res as any).originalStatus = 201;\n req.responseStatus = 201;\n res.locals.status = 201;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete user[key as keyof User];\n });\n\n res.status(201).json({ data: user });\n }\n ),\n /**\n * Marks user account as self-deleted by setting deletedSelfAccountAt timestamp\n */\n deleteMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const userId = req.user!.id;\n\n const updatedUser = (await userService.updateOne(\n { id: userId },\n {\n deletedSelfAccountAt: new Date().toISOString(),\n },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterDeleteMe) {\n (res as any).originalData = { data: updatedUser };\n req.responseData = { data: updatedUser };\n res.locals.data = { data: updatedUser };\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete updatedUser[key as keyof User];\n });\n\n res.status(200).json({\n message: \"Account deleted successfully\",\n });\n }\n ),\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const { currentPassword, newPassword } = req.body;\n\n if (!currentPassword || !newPassword)\n return next(\n new AppError(\n \"currentPassword and newPassword are required\",\n 400,\n \"SameCurrentAndNewPassword\"\n )\n );\n\n const user = req.user;\n\n if (!user || user?.isActive === false || user?.deletedSelfAccountAt)\n return next(new AppError(\"User not found!\", 404));\n\n const isPasswordCorrect = await authService.isCorrectPassword(\n String(currentPassword),\n String(user.password)\n );\n\n const configs = getArkosConfig();\n const initAuthConfigs = configs?.authentication;\n\n if (!isPasswordCorrect)\n return next(\n new AppError(\n \"Current password is incorrect\",\n 400,\n \"IncorrentCurrentPassword\"\n )\n );\n\n if (\n !authService.isPasswordStrong(String(newPassword)) &&\n !configs?.validation\n ) {\n return next(\n new AppError(\n initAuthConfigs?.passwordValidation?.message ||\n \"The new password must contain at least one uppercase letter, one lowercase letter, and one number\",\n 400,\n \"PasswordDoesNotMeetRequirements\"\n )\n );\n }\n\n await userService.updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()),\n }\n );\n\n const responseData = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n\n if (interceptors?.afterUpdatePassword) {\n (res as any).originalData = responseData;\n req.additionalData = { user };\n req.responseData = responseData;\n res.locals.data = responseData;\n (res as any).originalStatus = 200;\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json(responseData);\n }\n ),\n\n findManyAuthAction: catchAsync(\n async (_: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const authActions = authActionService.getAll()?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n\n findOneAuthAction: catchAsync(\n async (req: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const resourceName = req.params?.resourceName;\n\n if (!resourceName)\n throw new AppError(\n `Please provide a resoureName`,\n 400,\n \"MissiongResourseName\"\n );\n\n const authActions = authActionService\n .getByResource(req.params?.resourceName)\n ?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n if (!authActions)\n throw new AppError(\n `No auth action with resource name ${resourceName}`,\n 404,\n \"AuthActionNotFound\"\n );\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n };\n};\n"]}
|
|
@@ -17,7 +17,7 @@ const debugger_service_1 = __importDefault(require("../debugger/debugger.service
|
|
|
17
17
|
const router_validator_1 = __importDefault(require("../base/utils/router-validator"));
|
|
18
18
|
const fs_helpers_1 = require("../../utils/helpers/fs.helpers");
|
|
19
19
|
const router = (0, express_1.Router)();
|
|
20
|
-
|
|
20
|
+
function getAuthRouter(arkosConfigs) {
|
|
21
21
|
const { interceptors, dtos, schemas, prismaQueryOptions, router: customRouterModule, } = (0, dynamic_loader_1.getModuleComponents)("auth") || {};
|
|
22
22
|
const routerConfig = customRouterModule?.config || {};
|
|
23
23
|
const customRouter = customRouterModule?.default;
|
|
@@ -27,7 +27,7 @@ async function getAuthRouter(arkosConfigs) {
|
|
|
27
27
|
else
|
|
28
28
|
throw Error(`ValidationError: The exported router from auth.router.${(0, fs_helpers_1.getUserFileExtension)()} is not a valid express or arkos Router.`);
|
|
29
29
|
}
|
|
30
|
-
const authController =
|
|
30
|
+
const authController = (0, auth_controller_1.authControllerFactory)(interceptors);
|
|
31
31
|
if (routerConfig?.disable === true)
|
|
32
32
|
return router;
|
|
33
33
|
const getValidationSchemaOrDto = (key) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAqBA,sCAsNC;AA3OD,qCAAiC;AACjC,uDAA0D;AAC1D,kEAAyC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AC;IAEJ,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\n\nconst router: Router = Router();\n\nexport async function getAuthRouter(arkosConfigs: ArkosConfig) {\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig = customRouterModule?.config || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/auth`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = await authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\n ) {\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\"))\n router.get(\n \"/auth-actions\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\"))\n router.get(\n \"/auth-actions/:resourceName\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n\n debuggerService.logModuleFinalRouter(\"auth\", router);\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAqBA,sCAsNC;AA3OD,qCAAiC;AACjC,uDAA0D;AAC1D,kEAAyC;AACzC,4EAA2C;AAC3C,+DAAiE;AACjE,+DAIkC;AAElC,4FAA6D;AAE7D,yEAAwE;AACxE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEhC,SAAgB,aAAa,CAAC,YAAyB;IACrD,MAAM,EACJ,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,GAC3B,GAAG,IAAA,oCAAmB,EAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAEtC,MAAM,YAAY,GAAG,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;IACtD,MAAM,YAAY,GAAG,kBAAkB,EAAE,OAAiB,CAAC;IAE3D,IAAI,YAAY,IAAI,kBAAkB,EAAE,CAAC;QACvC,IAAI,0BAAe,CAAC,eAAe,CAAC,YAAY,CAAC;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BAAkB,EACjC,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAC3D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,yBAAyB,EAAE;YAC5D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IAEJ,IAAI,CAAC,IAAA,wCAAkB,EAAC,YAAY,EAAE,mBAAmB,CAAC;QACxD,MAAM,CAAC,GAAG,CACR,6BAA6B,EAC7B,sBAAW,CAAC,YAAY,EACxB,sBAAW,CAAC,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,EACtD,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAC3D,cAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,sBAAsB,CAAC,EAC1D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,wBAAwB,EAAE;YAC3D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IAEJ,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/new-arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\n\nconst router: Router = Router();\n\nexport function getAuthRouter(arkosConfigs: ArkosConfig) {\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig = customRouterModule?.config || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/auth`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\n ) {\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\"))\n router.get(\n \"/auth-actions\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\"))\n router.get(\n \"/auth-actions/:resourceName\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n\n debuggerService.logModuleFinalRouter(\"auth\", router);\n return router;\n}\n"]}
|
|
@@ -155,7 +155,7 @@ function validateRequestInputs(routeConfig) {
|
|
|
155
155
|
const validationConfig = arkosConfig.validation;
|
|
156
156
|
const strictValidation = validationConfig?.strict;
|
|
157
157
|
const validators = routeConfig?.validation;
|
|
158
|
-
const openapi = routeConfig?.openapi;
|
|
158
|
+
const openapi = routeConfig?.experimental?.openapi;
|
|
159
159
|
if (!validationConfig?.resolver && validators)
|
|
160
160
|
throw Error("Trying to pass validators into route config validation option without choosing a validation resolver under arkos.init({ validation: {} }).");
|
|
161
161
|
if (validators === true)
|
|
@@ -169,14 +169,10 @@ function validateRequestInputs(routeConfig) {
|
|
|
169
169
|
const isValidValidator = validationConfig?.resolver == "zod" ? dynamic_loader_1.isZodSchema : dynamic_loader_1.isClass;
|
|
170
170
|
const validatorName = validationConfig?.resolver == "zod" ? "zod schema" : "class-validator dto";
|
|
171
171
|
const validatorNameType = validationConfig?.resolver == "zod" ? "Schema" : "Dto";
|
|
172
|
+
if (openapi?.parameters)
|
|
173
|
+
throw Error("Invalid field openapi.parameters, if you would like to define documenation parameters define them under validation.body, validation.query or validation.params fields and they will be transformed to openapi json schemas.");
|
|
172
174
|
if (typeof validators === "object")
|
|
173
175
|
validatorsKey.forEach((key) => {
|
|
174
|
-
if (openapi &&
|
|
175
|
-
typeof openapi === "object" &&
|
|
176
|
-
openapi.parameters?.some((parameter) => parameter.in === key) &&
|
|
177
|
-
validators[key]) {
|
|
178
|
-
throw Error(`When usign validation.${key} you must not define parameters unde openapi.parameters as documentation of req.${key} because the ${validatorName} you passed under validation.${key} will be added as jsonSchema into the api documenation, if you wish to define documenation by yourself do not define validation.${key}.`);
|
|
179
|
-
}
|
|
180
176
|
if (openapi &&
|
|
181
177
|
typeof openapi === "object" &&
|
|
182
178
|
openapi.requestBody &&
|