arkos 2.0.0-canary.9 → 2.0.0-next.2
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/cli.js +36 -20
- package/dist/cjs/app.js +3 -0
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/components/arkos-loadable-registry/index.js +4 -2
- package/dist/cjs/components/arkos-loadable-registry/index.js.map +1 -1
- package/dist/cjs/components/arkos-policy/types.js.map +1 -1
- package/dist/cjs/exports/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +11 -7
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +4 -2
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +10 -2
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +22 -6
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/types/arkos.js.map +1 -1
- package/dist/cjs/types/auth.js.map +1 -1
- package/dist/cjs/types/index.js +0 -8
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/index.js +2 -0
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +1 -0
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/export-auth-action.js +1 -0
- package/dist/cjs/utils/cli/export-auth-action.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +3 -1
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +2 -2
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js +12 -0
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js.map +1 -1
- package/dist/cjs/utils/define-config.js +0 -12
- package/dist/cjs/utils/define-config.js.map +1 -1
- package/dist/esm/app.js +3 -0
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/components/arkos-loadable-registry/index.js +4 -2
- package/dist/esm/components/arkos-loadable-registry/index.js.map +1 -1
- package/dist/esm/components/arkos-policy/types.js.map +1 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js +11 -7
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +4 -2
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/base/base.router.js +10 -2
- package/dist/esm/modules/base/base.router.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +22 -6
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/types/arkos.js.map +1 -1
- package/dist/esm/types/auth.js.map +1 -1
- package/dist/esm/types/index.js +1 -7
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +2 -0
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/cli/build.js +1 -0
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/export-auth-action.js +1 -0
- package/dist/esm/utils/cli/export-auth-action.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +3 -1
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/index.js +2 -2
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js +12 -0
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js.map +1 -1
- package/dist/esm/utils/define-config.js +0 -9
- package/dist/esm/utils/define-config.js.map +1 -1
- package/dist/types/components/arkos-policy/types.d.ts +2 -2
- package/dist/types/exports/index.d.ts +2 -1
- package/dist/types/modules/auth/auth.controller.d.ts +2 -2
- package/dist/types/types/arkos.d.ts +6 -0
- package/dist/types/types/auth.d.ts +4 -3
- package/dist/types/types/index.d.ts +5 -32
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
(async () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const { join } = await import("path");
|
|
4
|
+
const { existsSync, readFileSync } = await import("fs");
|
|
5
|
+
const { spawn } = await import("child_process");
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const pkgPath = join(process.cwd(), "package.json");
|
|
8
|
+
let useEsm = false;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
13
|
-
useEsm = pkg.type === "module";
|
|
14
|
-
}
|
|
15
|
-
} catch (err) {
|
|
16
|
-
console.error("Error checking package.json:", err);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
process.env.NO_CLI = "false";
|
|
20
|
-
if (useEsm) await import("./dist/esm/utils/cli/index.js");
|
|
21
|
-
else await import("./dist/cjs/utils/cli/index.js");
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.error("Failed to load CLI:", err);
|
|
24
|
-
process.exit(1);
|
|
10
|
+
if (existsSync(pkgPath)) {
|
|
11
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
12
|
+
useEsm = pkg.type === "module";
|
|
25
13
|
}
|
|
14
|
+
|
|
15
|
+
const tsSrc = join(process.cwd(), "tsconfig.json");
|
|
16
|
+
const entryPoint = join(
|
|
17
|
+
__dirname,
|
|
18
|
+
`dist/${useEsm ? "esm" : "cjs"}/utils/cli/index.js`
|
|
19
|
+
);
|
|
20
|
+
const useTs = existsSync(tsSrc);
|
|
21
|
+
|
|
22
|
+
const args = [
|
|
23
|
+
...(useTs ? ["--experimental-strip-types"] : []),
|
|
24
|
+
entryPoint,
|
|
25
|
+
...process.argv.slice(2),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
process.env.NO_CLI = "true";
|
|
29
|
+
const child = spawn(process.execPath, args, {
|
|
30
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
31
|
+
});
|
|
32
|
+
child.stderr.on("data", (data) => {
|
|
33
|
+
const str = data.toString();
|
|
34
|
+
if (
|
|
35
|
+
!str.includes("DeprecationWarning") &&
|
|
36
|
+
!str.includes("npm warn") &&
|
|
37
|
+
!str.includes("ExperimentalWarning")
|
|
38
|
+
)
|
|
39
|
+
process.stderr.write(data);
|
|
40
|
+
});
|
|
41
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
26
42
|
})();
|
package/dist/cjs/app.js
CHANGED
|
@@ -27,6 +27,9 @@ function arkos() {
|
|
|
27
27
|
app.load = (...items) => {
|
|
28
28
|
if (state !== "idle")
|
|
29
29
|
throw (0, exit_error_1.default)(`app.load() must be called before app.${state === "listening" ? "listen" : "build"}(), see ${docsLink}`);
|
|
30
|
+
if (Array.isArray(items[0]))
|
|
31
|
+
items = items[0];
|
|
32
|
+
items = Array.isArray(items) ? items : [items];
|
|
30
33
|
items.forEach((item) => arkos_loadable_registry_1.default.register(item));
|
|
31
34
|
return app;
|
|
32
35
|
};
|
package/dist/cjs/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;AAyDA,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;AAyDA,sBAyFC;AAED,oCAEC;AAtJD,gDAA8C;AAC9C,sDAA2C;AAC3C,kEAAyC;AAEzC,4EAAmD;AACnD,qCAAyC;AACzC,oGAA0E;AAC1E,+BAA+D;AAC/D,4EAAmD;AACnD,mGAAoE;AAEpE,IAAI,SAAgE,CAAC;AACrE,MAAM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C,CAAC,KAAK,UAAU;YAC9D,SAAS,GAAG,cAAc,CACxB,IAAI,EACJ,IAAI,EACJ,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAiB,CAAC,CAC/C,CAAC;aACC,IAAI,IAAI,CAAC,CAAC,CAAC,YAAY,aAAM,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;YAC/D,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CACxB,IAAI,EACJ,IAAI,EACJ,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAiB,CAAC,CAC/C,CAAC;QAEJ,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,YAAY;IAC1B,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import \"./utils/helpers/arkos-config.helpers\";\nimport express, { Express } from \"express\";\nimport setupApp from \"./utils/setup-app\";\nimport { Arkos, ArkosLoadable } from \"./types/arkos\";\nimport initializeApp from \"./utils/initialize-app\";\nimport { logAppStartup } from \"./server\";\nimport runtimeCliCommander from \"./utils/cli/utils/runtime-cli-commander\";\nimport { IncomingMessage, Server, ServerResponse } from \"http\";\nimport ExitError from \"./utils/helpers/exit-error\";\nimport loadableRegistry from \"./components/arkos-loadable-registry\";\n\nlet appServer: Server<typeof IncomingMessage, typeof ServerResponse>;\nconst docsLink =\n \"https://www.arkosjs.com/docs/core-concepts/routing/setup#setting-up-your-app\";\nlet instanciated = false;\n\n/**\n * Creates and configures an Arkos application instance.\n *\n * Arkos extends Express with a small set of methods for registering routers,\n * loading route/service hooks, and booting the application. All Arkos-specific\n * setup (`app.build()`) must happen before the app starts\n * accepting requests.\n *\n * @example\n * ```ts\n * // Simple setup\n * import arkos from \"arkos\";\n *\n * const app = arkos();\n *\n * app.use(reportsRouter);\n *\n * app.listen();\n * ```\n *\n * @example\n * ```ts\n * // Custom HTTP server (e.g. for WebSockets)\n * import arkos from \"arkos\";\n * import http from \"http\";\n *\n * const app = arkos();\n *\n * app.use(reportsRouter);\n *\n * async function start() {\n * await app.build();\n *\n * const server = http.createServer(app);\n * app.listen(server)\n * }\n * main()\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/routing/setup}\n */\nexport function arkos(): Arkos {\n if (instanciated)\n throw ExitError(`arkos() must be called only once, see ${docsLink}`);\n\n const app = express() as any as Arkos;\n setupApp(app);\n instanciated = true;\n\n type AppState = \"idle\" | \"building\" | \"built\" | \"listening\";\n let state: AppState = \"idle\";\n\n app.load = (...items: ArkosLoadable[]) => {\n if (state !== \"idle\")\n throw ExitError(\n `app.load() must be called before app.${state === \"listening\" ? \"listen\" : \"build\"}(), see ${docsLink}`\n );\n\n if (Array.isArray(items[0])) items = items[0];\n items = Array.isArray(items) ? items : [items];\n\n items.forEach((item) => loadableRegistry.register(item));\n return app;\n };\n\n function loadApp() {\n const _app = initializeApp(app);\n if (process.env.CLI_COMMAND) runtimeCliCommander.handle();\n return _app;\n }\n\n app.build = function () {\n if (state === \"built\" || state === \"building\")\n throw ExitError(`app.build() must only be called once, see ${docsLink}`);\n if (state === \"listening\")\n throw ExitError(\n `app.build() must be called before app.listen(), see ${docsLink}`\n );\n\n state = \"building\";\n const _app = loadApp();\n state = \"built\";\n return _app;\n };\n\n const originalListen = app.listen.bind(app) as any as Express[\"listen\"];\n type UserCallback = (err?: Error) => void;\n\n const defaultCb = (\n port: number | string,\n host: string,\n cb?: UserCallback\n ) => {\n logAppStartup(port, host);\n return cb || function () {};\n };\n\n app.listen = async function (...args): Promise<Server> {\n if (state === \"listening\")\n throw ExitError(`app.listen() must only be called once, see ${docsLink}`);\n if (state === \"building\")\n throw ExitError(\n `app.build() must be awaited before calling app.listen(), see ${docsLink}`\n );\n\n if (state === \"idle\") {\n state = \"listening\";\n loadApp();\n }\n\n const port = Number(process.env.__PORT || process.env.PORT || \"8000\");\n const host = process.env.__HOST! || process.env.HOST || \"0.0.0.0\";\n\n if ((args as any)?.length === 0 || typeof args[0] === \"function\")\n appServer = originalListen(\n port,\n host,\n defaultCb(port, host, args[0] as UserCallback)\n );\n else if (args[0] instanceof Server || typeof args[0] === \"object\")\n appServer = args[0].listen(\n port,\n host,\n defaultCb(port, host, args[1] as UserCallback)\n );\n\n return appServer;\n };\n\n return app;\n}\n\nexport function getAppServer() {\n return appServer;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArkosLoadableRegistry = void 0;
|
|
4
|
+
const LOADABLES = ["ArkosRouteHook", "ArkosServiceHook"];
|
|
4
5
|
class ArkosLoadableRegistry {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.items = new Map();
|
|
@@ -8,9 +9,10 @@ class ArkosLoadableRegistry {
|
|
|
8
9
|
register(item) {
|
|
9
10
|
const type = item.__type;
|
|
10
11
|
const moduleName = item.moduleName;
|
|
11
|
-
if (!
|
|
12
|
+
if (!LOADABLES.includes(type))
|
|
13
|
+
throw Error(`Invalid loadable component, expected on of ${LOADABLES.join(", ")} but received "${item}"`);
|
|
14
|
+
if (!this.items.has(type))
|
|
12
15
|
this.items.set(type, new Map());
|
|
13
|
-
}
|
|
14
16
|
this.items.get(type).set(moduleName, item);
|
|
15
17
|
}
|
|
16
18
|
getItem(loadableType, moduleName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/arkos-loadable-registry/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/arkos-loadable-registry/index.ts"],"names":[],"mappings":";;;AAGA,MAAM,SAAS,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;AAMzD,MAAa,qBAAqB;IAAlC;QACmB,UAAK,GAA4C,IAAI,GAAG,EAAE,CAAC;IAuC9E,CAAC;IAjCC,QAAQ,CAAC,IAAmB;QAC1B,MAAM,IAAI,GAAI,IAAY,CAAC,MAAM,CAAC;QAClC,MAAM,UAAU,GAAI,IAAY,CAAC,UAAU,CAAC;QAE5C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;YAC3B,MAAM,KAAK,CACT,8CAA8C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,IAAI,GAAG,CAC5F,CAAC;QAEJ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAKD,OAAO,CACL,YAAmD,EACnD,UAA2B;QAE3B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC;IAC/D,CAAC;IAKD,OAAO,CACL,YAAmD,EACnD,UAAkB;QAElB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC;IAChE,CAAC;CACF;AAxCD,sDAwCC;AAED,MAAM,gBAAgB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAErD,kBAAe,gBAAgB,CAAC","sourcesContent":["import { ArkosLoadable } from \"../../types/arkos\";\nimport { ArkosModuleType } from \"../arkos-route-hook/types\";\n\nconst LOADABLES = [\"ArkosRouteHook\", \"ArkosServiceHook\"];\n\n/**\n * Registry for all items loaded via `app.load()`.\n * Instantiated once at app start and passed through the entire Arkos chain.\n */\nexport class ArkosLoadableRegistry {\n private readonly items: Map<string, Map<string, ArkosLoadable>> = new Map();\n\n /**\n * Registers a loadable item into the registry.\n * Called internally by `app.load()`.\n */\n register(item: ArkosLoadable): void {\n const type = (item as any).__type;\n const moduleName = (item as any).moduleName;\n\n if (!LOADABLES.includes(type))\n throw Error(\n `Invalid loadable component, expected on of ${LOADABLES.join(\", \")} but received \"${item}\"`\n );\n\n if (!this.items.has(type)) this.items.set(type, new Map());\n\n this.items.get(type)!.set(moduleName, item);\n }\n\n /**\n * Returns the interceptor for the given module name, or `null` if not registered.\n */\n getItem(\n loadableType: \"ArkosRouteHook\" | \"ArkosServiceHook\",\n moduleName: ArkosModuleType\n ): ArkosLoadable | null {\n return this.items.get(loadableType)?.get(moduleName) ?? null;\n }\n\n /**\n * Returns true if an interceptor is registered for the given module name.\n */\n hasItem(\n loadableType: \"ArkosRouteHook\" | \"ArkosServiceHook\",\n moduleName: string\n ): boolean {\n return this.items.get(loadableType)?.has(moduleName) ?? false;\n }\n}\n\nconst loadableRegistry = new ArkosLoadableRegistry();\n\nexport default loadableRegistry;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/arkos-policy/types.ts"],"names":[],"mappings":"","sourcesContent":["import { User } from \"../../types\";\nimport { DetailedAccessControlRule } from \"../../types/auth\";\n\nexport type ArkosPolicyRule =
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/arkos-policy/types.ts"],"names":[],"mappings":"","sourcesContent":["import { User, UserRole } from \"../../types\";\nimport { DetailedAccessControlRule } from \"../../types/auth\";\n\nexport type ArkosPolicyRule = UserRole[] | DetailedAccessControlRule | \"*\";\n\nexport type PolicyAuthEntry<\n TResource extends string,\n TAction extends string,\n> = {\n readonly resource: TResource;\n readonly action: TAction;\n readonly rule: ArkosPolicyRule;\n};\n\nexport type PolicyChecker = (user?: User) => Promise<boolean>;\n\ntype CanKey<TAction extends string> = `can${Capitalize<TAction>}`;\n\nexport type PolicyWithActions<\n TResource extends string,\n TActions extends string,\n> = IArkosPolicy<TResource, TActions> & {\n [K in TActions]: PolicyAuthEntry<TResource, K>;\n} & {\n [K in CanKey<TActions>]: PolicyChecker;\n};\n\nexport interface IArkosPolicy<\n TResource extends string,\n TActions extends string = never,\n> {\n readonly __type: \"ArkosPolicy\";\n readonly resource: TResource;\n\n rule<TAction extends string>(\n action: TAction,\n config?: ArkosPolicyRule\n ): PolicyWithActions<TResource, TActions | TAction>;\n}\n"]}
|
|
@@ -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;AA4BjE,+FA5BO,gCAAc,OA4BP;AA3BhB,sCAA2C;AA+BzC,+FA/BO,uBAAc,OA+BP;AA9BhB,yEAAgD;AAiC9C,sBAjCK,sBAAW,CAiCL;AAvBb,4DAAmE;AAmBjE,yGAnBO,yCAAwB,OAmBP;AAlB1B,gCAA+B;AAC/B,qEAAgE;AAmB9D,+FAnBO,iCAAc,OAmBP;AAlBhB,yEAAoE;AAmBlE,iGAnBO,qCAAgB,OAmBP;AAjBlB,6DAAyD;AAqBvD,4FArBO,0BAAW,OAqBP;AAIb,kBAAe,WAAK,CAAC","sourcesContent":["import { RouterConfig } from \"../types/router-config\";\nimport { BaseController } from \"./../modules/base/base.controller\";\nimport { getArkosConfig } from \"../server\";\nimport ArkosRouter from \"../utils/arkos-router\";\nimport { IArkosRouter } from \"../utils/arkos-router/types\";\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 { loadEnvironmentVariables } from \"../utils/dotenv.helpers\";\nimport { arkos } from \"../app\";\nimport { ArkosRouteHook } from \"../components/arkos-route-hook\";\nimport { ArkosServiceHook } from \"../components/arkos-service-hook\";\nimport { ArkosRouteHookInstance } from \"../components/arkos-route-hook/types\";\nimport { ArkosPolicy } from \"../components/arkos-policy\";\nimport { IArkosPolicy } from \"../components/arkos-policy/types\";\nimport type { ArkosLoadable } from \"../types/arkos\";\n\nexport {\n ArkosLoadable,\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n IArkosRouter,\n BaseController,\n ArkosConfig,\n RouterConfig,\n loadEnvironmentVariables,\n getArkosConfig,\n ArkosRouteHook,\n ArkosServiceHook,\n ArkosRouter,\n ArkosRouteConfig,\n ArkosRouteHookInstance,\n ArkosPolicy,\n IArkosPolicy,\n};\n\nexport default arkos;\n"]}
|
|
@@ -18,7 +18,7 @@ exports.defaultExcludedUserFields = {
|
|
|
18
18
|
class AuthController {
|
|
19
19
|
constructor() {
|
|
20
20
|
this.getMe = (0, catch_async_1.default)(async (req, res, next) => {
|
|
21
|
-
const user = (await this.
|
|
21
|
+
const user = (await this.getUserService().findOne({ id: req.user.id }, req.prismaQueryOptions || {}));
|
|
22
22
|
Object.keys(exports.defaultExcludedUserFields).forEach((key) => {
|
|
23
23
|
if (user)
|
|
24
24
|
delete user[key];
|
|
@@ -37,7 +37,7 @@ class AuthController {
|
|
|
37
37
|
this.updateMe = (0, catch_async_1.default)(async (req, res, next) => {
|
|
38
38
|
if ("password" in req.body)
|
|
39
39
|
throw new app_error_1.default("In order to update password use the update-password endpoint.", 400, "InvalidFieldPassword");
|
|
40
|
-
const user = (await this.
|
|
40
|
+
const user = (await this.getUserService().updateOne({ id: req.user.id }, req.body, req.prismaQueryOptions || {}));
|
|
41
41
|
Object.keys(exports.defaultExcludedUserFields).forEach((key) => {
|
|
42
42
|
if (user)
|
|
43
43
|
delete user[key];
|
|
@@ -88,7 +88,7 @@ class AuthController {
|
|
|
88
88
|
else {
|
|
89
89
|
whereClause = { [usernameField]: usernameValue };
|
|
90
90
|
}
|
|
91
|
-
const user = (await this.
|
|
91
|
+
const user = (await this.getUserService().findOne(whereClause, req.prismaQueryOptions || {}));
|
|
92
92
|
if (!user ||
|
|
93
93
|
!(await auth_service_1.default.isCorrectPassword(password, user.password))) {
|
|
94
94
|
return next(new app_error_1.default(`Incorrect ${lastField} or password`, 401, `IncorrectCredentials`));
|
|
@@ -126,7 +126,7 @@ class AuthController {
|
|
|
126
126
|
res.status(200).send();
|
|
127
127
|
});
|
|
128
128
|
this.signup = (0, catch_async_1.default)(async (req, res, next) => {
|
|
129
|
-
const user = (await this.
|
|
129
|
+
const user = (await this.getUserService().createOne(req.body, req.prismaQueryOptions || {}));
|
|
130
130
|
if (reader_1.routeHookReader.getHooks("auth", "signup")?.after) {
|
|
131
131
|
res.originalData = { data: user };
|
|
132
132
|
req.responseData = { data: user };
|
|
@@ -143,7 +143,7 @@ class AuthController {
|
|
|
143
143
|
});
|
|
144
144
|
this.deleteMe = (0, catch_async_1.default)(async (req, res, next) => {
|
|
145
145
|
const userId = req.user.id;
|
|
146
|
-
const updatedUser = (await this.
|
|
146
|
+
const updatedUser = (await this.getUserService().updateOne({ id: userId }, { deletedSelfAccountAt: new Date().toISOString() }, req.prismaQueryOptions || {}));
|
|
147
147
|
if (reader_1.routeHookReader.getHooks("auth", "deleteMe")?.after) {
|
|
148
148
|
res.originalData = { data: updatedUser };
|
|
149
149
|
req.responseData = { data: updatedUser };
|
|
@@ -175,7 +175,7 @@ class AuthController {
|
|
|
175
175
|
return next(new app_error_1.default(initAuthConfigs?.passwordValidation?.message ||
|
|
176
176
|
"The new password must contain at least one uppercase letter, one lowercase letter, and one number", 400, "PasswordDoesNotMeetRequirements"));
|
|
177
177
|
}
|
|
178
|
-
await this.
|
|
178
|
+
await this.getUserService().updateOne({ id: user.id }, {
|
|
179
179
|
password: await auth_service_1.default.hashPassword(newPassword),
|
|
180
180
|
passwordChangedAt: new Date(Date.now()).toISOString(),
|
|
181
181
|
});
|
|
@@ -241,7 +241,11 @@ class AuthController {
|
|
|
241
241
|
data: authActions,
|
|
242
242
|
});
|
|
243
243
|
});
|
|
244
|
-
|
|
244
|
+
}
|
|
245
|
+
getUserService() {
|
|
246
|
+
if (!this.userService)
|
|
247
|
+
this.userService = new base_service_1.BaseService("user");
|
|
248
|
+
return this.userService;
|
|
245
249
|
}
|
|
246
250
|
}
|
|
247
251
|
exports.AuthController = AuthController;
|
|
@@ -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;AACrE,qEAA2E;AAK9D,QAAA,yBAAyB,GAAG;IACvC,QAAQ,EAAE,KAAK;CAChB,CAAC;AAKF,MAAa,cAAc;IAGzB;QAOA,UAAK,GAAG,IAAA,qBAAU,EAChB,KAAK,EAAE,GAAiB,EAAE,GAAkB,EAAE,IAAuB,EAAE,EAAE;YACvE,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAC1C,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,CAAC,GAAiB,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;YAEH,IAAI,wBAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;gBACpD,GAAW,CAAC,YAAY,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;gBAC3C,GAAG,CAAC,YAAY,GAAG,EAAE,IAAI,EAA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,CAAC,MAAM;gBAC3B,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC,CACF,CAAC;QAEF,sBAAiB,GAAG,IAAA,qBAAU,EAC5B,KAAK,EAAE,GAAiB,EAAE,GAAkB,EAAE,EAAE;YAC9C,MAAM,WAAW,GAAG,IAAA,uBAAc,GAAE,CAAC;YACrC,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;YAE9C,IAAI,CAAC,YAAY;gBACf,MAAM,IAAI,mBAAQ,CAChB,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,CAAC;QAjZA,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;CAiZF;AAtZD,wCAsZC;AAEY,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AAEnD,kBAAe,sBAAc,CAAC","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\";\nimport { routeHookReader } from \"../../components/arkos-route-hook/reader\";\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 * Authentication controller class handling all auth-related operations\n */\nexport class AuthController {\n private userService: BaseService<\"user\">;\n\n constructor() {\n this.userService = new BaseService(\"user\");\n }\n\n /**\n * Retrieves the current authenticated user's information\n */\n getMe = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const user = (await this.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 (routeHookReader.getHooks(\"auth\", \"getMe\")?.after) {\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 (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n \"InvalidFieldPassword\"\n );\n\n const user = (await this.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 (routeHookReader.getHooks(\"auth\", \"updateMe\")?.after) {\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 (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (routeHookReader.getHooks(\"auth\", \"logout\")?.after) {\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 */\n login = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\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 this.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 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 (routeHookReader.getHooks(\"auth\", \"login\")?.after) {\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\n */\n signup = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const user = (await this.userService.createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (routeHookReader.getHooks(\"auth\", \"signup\")?.after) {\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 /**\n * Marks user account as self-deleted\n */\n deleteMe = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const userId = req.user!.id;\n\n const updatedUser = (await this.userService.updateOne(\n { id: userId },\n { deletedSelfAccountAt: new Date().toISOString() },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (routeHookReader.getHooks(\"auth\", \"deleteMe\")?.after) {\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({ message: \"Account deleted successfully\" });\n }\n );\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\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 this.userService.updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()).toISOString(),\n }\n );\n\n const token = authService.signJwtToken(user.id!);\n const cookieOptions = authService.getJwtCookieOptions(req);\n const authConfigs = getArkosConfig()?.authentication;\n\n const responseData: Record<string, string> = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n responseData.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 (routeHookReader.getHooks(\"auth\", \"updatePassword\")?.after) {\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\nexport const authController = new AuthController();\n\nexport default authController;\n"]}
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.controller.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MAAM,IAAI,mBAAQ,CAChB,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,CAAC;IACJ,CAAC;IApZS,cAAc;QACpB,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,MAAM,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CAiZF;AAvZD,wCAuZC;AAEY,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AAEnD,kBAAe,sBAAc,CAAC","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\";\nimport { routeHookReader } from \"../../components/arkos-route-hook/reader\";\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 * Authentication controller class handling all auth-related operations\n */\nexport class AuthController {\n private userService?: BaseService<\"user\">;\n\n private getUserService() {\n if (!this.userService) this.userService = new BaseService(\"user\");\n return this.userService;\n }\n\n /**\n * Retrieves the current authenticated user's information\n */\n getMe = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const user = (await this.getUserService().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 (routeHookReader.getHooks(\"auth\", \"getMe\")?.after) {\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 (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n \"InvalidFieldPassword\"\n );\n\n const user = (await this.getUserService().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 (routeHookReader.getHooks(\"auth\", \"updateMe\")?.after) {\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 (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (routeHookReader.getHooks(\"auth\", \"logout\")?.after) {\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 */\n login = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\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 this.getUserService().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 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 (routeHookReader.getHooks(\"auth\", \"login\")?.after) {\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\n */\n signup = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const user = (await this.getUserService().createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (routeHookReader.getHooks(\"auth\", \"signup\")?.after) {\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 /**\n * Marks user account as self-deleted\n */\n deleteMe = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const userId = req.user!.id;\n\n const updatedUser = (await this.getUserService().updateOne(\n { id: userId },\n { deletedSelfAccountAt: new Date().toISOString() },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (routeHookReader.getHooks(\"auth\", \"deleteMe\")?.after) {\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({ message: \"Account deleted successfully\" });\n }\n );\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\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 this.getUserService().updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()).toISOString(),\n }\n );\n\n const token = authService.signJwtToken(user.id!);\n const cookieOptions = authService.getJwtCookieOptions(req);\n const authConfigs = getArkosConfig()?.authentication;\n\n const responseData: Record<string, string> = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n responseData.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 (routeHookReader.getHooks(\"auth\", \"updatePassword\")?.after) {\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\nexport const authController = new AuthController();\n\nexport default authController;\n"]}
|
|
@@ -12,8 +12,8 @@ const reader_1 = require("../../components/arkos-route-hook/reader.js");
|
|
|
12
12
|
const auth_controller_1 = __importDefault(require("./auth.controller.js"));
|
|
13
13
|
function getAuthRouter() {
|
|
14
14
|
const router = (0, arkos_router_1.default)();
|
|
15
|
-
const
|
|
16
|
-
const op = (operation) =>
|
|
15
|
+
const routeHook = arkos_loadable_registry_1.default.getItem("ArkosRouteHook", "auth");
|
|
16
|
+
const op = (operation) => routeHook
|
|
17
17
|
? reader_1.routeHookReader.forOperation("auth", operation)
|
|
18
18
|
: {
|
|
19
19
|
before: [],
|
|
@@ -57,6 +57,7 @@ function getAuthRouter() {
|
|
|
57
57
|
{
|
|
58
58
|
const { before, after, onError, prismaArgs, routeConfig } = op("login");
|
|
59
59
|
router.post({
|
|
60
|
+
authentication: false,
|
|
60
61
|
rateLimit: rateLimitConfig,
|
|
61
62
|
...routeConfig,
|
|
62
63
|
path: "/auth/login",
|
|
@@ -73,6 +74,7 @@ function getAuthRouter() {
|
|
|
73
74
|
{
|
|
74
75
|
const { before, after, onError, prismaArgs, routeConfig } = op("signup");
|
|
75
76
|
router.post({
|
|
77
|
+
authentication: false,
|
|
76
78
|
rateLimit: rateLimitConfig,
|
|
77
79
|
...routeConfig,
|
|
78
80
|
path: "/auth/signup",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAaA,sCA0NC;AAtOD,+DAGkC;AAElC,yEAAwE;AACxE,4EAAmD;AACnD,uGAAwE;AACxE,qEAA2E;AAE3E,wEAA+C;AAE/C,SAAgB,aAAa;IAC3B,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,iCAAgB,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAEvE,MAAM,EAAE,GAAG,CACT,SAA0E,EAC1E,EAAE,CACF,WAAW;QACT,CAAC,CAAC,wBAAe,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;QACjD,CAAC,CAAC;YACE,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,EAAE;SAChB,CAAC;IAGR,CAAC;QACC,MAAM,EAAE,MAAM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c,EAC7B,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAGD,CAAC;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC;QAEzE,MAAM,CAAC,GAAG,CACR;YACE,GAAG,WAAW;YACd,IAAI,EAAE,eAAe;SACtB,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,yBAAc,CAAC,kBAAkB,EACjC,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAGD,CAAC;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;QAExE,MAAM,CAAC,GAAG,CACR;YACE,GAAG,WAAW;YACd,IAAI,EAAE,6BAA6B;SACpC,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,yBAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Options as RateLimitOptions } from \"express-rate-limit\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport loadableRegistry from \"../../components/arkos-loadable-registry\";\nimport { routeHookReader } from \"../../components/arkos-route-hook/reader\";\nimport { ArkosAuthRouteHookInstance } from \"../../components/arkos-route-hook/types\";\nimport authController from \"./auth.controller\";\n\nexport function getAuthRouter() {\n const router = ArkosRouter();\n const interceptor = loadableRegistry.getItem(\"ArkosRouteHook\", \"auth\");\n\n const op = (\n operation: keyof Omit<ArkosAuthRouteHookInstance, \"__type\" | \"moduleName\">\n ) =>\n interceptor\n ? routeHookReader.forOperation(\"auth\", operation)\n : {\n before: [],\n after: [],\n onError: [],\n prismaArgs: {},\n routeConfig: {},\n };\n\n // GET /users/me - Get current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"getMe\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { getMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(before),\n authController.getMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"updateMe\");\n\n router.patch(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { updateMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(before),\n authController.updateMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"deleteMe\");\n\n router.delete(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { deleteMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(before),\n authController.deleteMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n const rateLimitConfig: Partial<RateLimitOptions> = {\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\n // POST /auth/login - Login\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"login\");\n\n router.post(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/login\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { login: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(before),\n authController.login,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n {\n const { before, after, onError, routeConfig } = op(\"logout\");\n\n router.delete(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/logout\",\n },\n ...processMiddleware(before),\n authController.logout,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"signup\");\n\n router.post(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/signup\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { signup: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(before),\n authController.signup,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"updatePassword\");\n\n router.post(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/update-password\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { updatePassword: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(before),\n authController.updatePassword,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n {\n const { before, after, onError, routeConfig } = op(\"findManyAuthAction\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/auth-actions\",\n },\n ...processMiddleware(before),\n authController.findManyAuthAction,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n {\n const { before, after, onError, routeConfig } = op(\"findOneAuthAction\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/auth-actions/:resourceName\",\n },\n ...processMiddleware(before),\n authController.findOneAuthAction,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAaA,sCA4NC;AAxOD,+DAGkC;AAElC,yEAAwE;AACxE,4EAAmD;AACnD,uGAAwE;AACxE,qEAA2E;AAE3E,wEAA+C;AAE/C,SAAgB,aAAa;IAC3B,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,iCAAgB,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAErE,MAAM,EAAE,GAAG,CACT,SAA0E,EAC1E,EAAE,CACF,SAAS;QACP,CAAC,CAAC,wBAAe,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;QACjD,CAAC,CAAC;YACE,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,EAAE;SAChB,CAAC;IAGR,CAAC;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC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AAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAGD,CAAC;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC;QAEzE,MAAM,CAAC,GAAG,CACR;YACE,GAAG,WAAW;YACd,IAAI,EAAE,eAAe;SACtB,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,yBAAc,CAAC,kBAAkB,EACjC,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAGD,CAAC;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;QAExE,MAAM,CAAC,GAAG,CACR;YACE,GAAG,WAAW;YACd,IAAI,EAAE,6BAA6B;SACpC,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,yBAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE;YAC5B,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Options as RateLimitOptions } from \"express-rate-limit\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport loadableRegistry from \"../../components/arkos-loadable-registry\";\nimport { routeHookReader } from \"../../components/arkos-route-hook/reader\";\nimport { ArkosAuthRouteHookInstance } from \"../../components/arkos-route-hook/types\";\nimport authController from \"./auth.controller\";\n\nexport function getAuthRouter() {\n const router = ArkosRouter();\n const routeHook = loadableRegistry.getItem(\"ArkosRouteHook\", \"auth\");\n\n const op = (\n operation: keyof Omit<ArkosAuthRouteHookInstance, \"__type\" | \"moduleName\">\n ) =>\n routeHook\n ? routeHookReader.forOperation(\"auth\", operation)\n : {\n before: [],\n after: [],\n onError: [],\n prismaArgs: {},\n routeConfig: {},\n };\n\n // GET /users/me - Get current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"getMe\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { getMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(before),\n authController.getMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"updateMe\");\n\n router.patch(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { updateMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(before),\n authController.updateMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"deleteMe\");\n\n router.delete(\n {\n ...routeConfig,\n path: \"/users/me\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { deleteMe: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(before),\n authController.deleteMe,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n const rateLimitConfig: Partial<RateLimitOptions> = {\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\n // POST /auth/login - Login\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"login\");\n\n router.post(\n {\n authentication: false,\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/login\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { login: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(before),\n authController.login,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n {\n const { before, after, onError, routeConfig } = op(\"logout\");\n\n router.delete(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/logout\",\n },\n ...processMiddleware(before),\n authController.logout,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"signup\");\n\n router.post(\n {\n authentication: false,\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/signup\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { signup: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(before),\n authController.signup,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"updatePassword\");\n\n router.post(\n {\n rateLimit: rateLimitConfig,\n ...routeConfig,\n path: \"/auth/update-password\",\n },\n addPrismaQueryOptionsToRequest<any>(\n { updatePassword: prismaArgs } as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(before),\n authController.updatePassword,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n {\n const { before, after, onError, routeConfig } = op(\"findManyAuthAction\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/auth-actions\",\n },\n ...processMiddleware(before),\n authController.findManyAuthAction,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n {\n const { before, after, onError, routeConfig } = op(\"findOneAuthAction\");\n\n router.get(\n {\n ...routeConfig,\n path: \"/auth-actions/:resourceName\",\n },\n ...processMiddleware(before),\n authController.findOneAuthAction,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, {\n type: \"error\",\n })\n );\n }\n\n return router;\n}\n"]}
|
|
@@ -18,8 +18,8 @@ function getPrismaModelsRouter() {
|
|
|
18
18
|
const modelNameInKebab = (0, utils_1.kebabCase)(model);
|
|
19
19
|
const routeName = pluralize_1.default.plural(modelNameInKebab);
|
|
20
20
|
const controller = new exports_1.BaseController(model);
|
|
21
|
-
const
|
|
22
|
-
const op = (operation) =>
|
|
21
|
+
const routeHook = arkos_loadable_registry_1.default.getItem("ArkosRouteHook", modelNameInKebab);
|
|
22
|
+
const op = (operation) => routeHook
|
|
23
23
|
? reader_1.routeHookReader.forOperation(modelNameInKebab, operation)
|
|
24
24
|
: {
|
|
25
25
|
before: [],
|
|
@@ -31,6 +31,7 @@ function getPrismaModelsRouter() {
|
|
|
31
31
|
{
|
|
32
32
|
const { before, after, onError, prismaArgs, routeConfig } = op("createOne");
|
|
33
33
|
router.post({
|
|
34
|
+
authentication: { action: "Create", resource: modelNameInKebab },
|
|
34
35
|
...routeConfig,
|
|
35
36
|
path: `/${routeName}`,
|
|
36
37
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -40,6 +41,7 @@ function getPrismaModelsRouter() {
|
|
|
40
41
|
{
|
|
41
42
|
const { before, after, onError, prismaArgs, routeConfig } = op("findMany");
|
|
42
43
|
router.get({
|
|
44
|
+
authentication: { action: "View", resource: modelNameInKebab },
|
|
43
45
|
...routeConfig,
|
|
44
46
|
path: `/${routeName}`,
|
|
45
47
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -49,6 +51,7 @@ function getPrismaModelsRouter() {
|
|
|
49
51
|
{
|
|
50
52
|
const { before, after, onError, prismaArgs, routeConfig } = op("createMany");
|
|
51
53
|
router.post({
|
|
54
|
+
authentication: { action: "Create", resource: modelNameInKebab },
|
|
52
55
|
...routeConfig,
|
|
53
56
|
path: `/${routeName}/many`,
|
|
54
57
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -58,6 +61,7 @@ function getPrismaModelsRouter() {
|
|
|
58
61
|
{
|
|
59
62
|
const { before, after, onError, prismaArgs, routeConfig } = op("updateMany");
|
|
60
63
|
router.patch({
|
|
64
|
+
authentication: { action: "Update", resource: modelNameInKebab },
|
|
61
65
|
...routeConfig,
|
|
62
66
|
path: `/${routeName}/many`,
|
|
63
67
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -67,6 +71,7 @@ function getPrismaModelsRouter() {
|
|
|
67
71
|
{
|
|
68
72
|
const { before, after, onError, prismaArgs, routeConfig } = op("deleteMany");
|
|
69
73
|
router.delete({
|
|
74
|
+
authentication: { action: "Delete", resource: modelNameInKebab },
|
|
70
75
|
...routeConfig,
|
|
71
76
|
path: `/${routeName}/many`,
|
|
72
77
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -76,6 +81,7 @@ function getPrismaModelsRouter() {
|
|
|
76
81
|
{
|
|
77
82
|
const { before, after, onError, prismaArgs, routeConfig } = op("findOne");
|
|
78
83
|
router.get({
|
|
84
|
+
authentication: { action: "View", resource: modelNameInKebab },
|
|
79
85
|
...routeConfig,
|
|
80
86
|
path: `/${routeName}/:id`,
|
|
81
87
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -84,6 +90,7 @@ function getPrismaModelsRouter() {
|
|
|
84
90
|
}
|
|
85
91
|
const { before, after, onError, prismaArgs, routeConfig } = op("updateOne");
|
|
86
92
|
router.patch({
|
|
93
|
+
authentication: { action: "Update", resource: modelNameInKebab },
|
|
87
94
|
...routeConfig,
|
|
88
95
|
path: `/${routeName}/:id`,
|
|
89
96
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -92,6 +99,7 @@ function getPrismaModelsRouter() {
|
|
|
92
99
|
{
|
|
93
100
|
const { before, after, onError, prismaArgs, routeConfig } = op("deleteOne");
|
|
94
101
|
router.delete({
|
|
102
|
+
authentication: { action: "Delete", resource: modelNameInKebab },
|
|
95
103
|
...routeConfig,
|
|
96
104
|
path: `/${routeName}/:id`,
|
|
97
105
|
}, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.router.js","sourceRoot":"","sources":["../../../../src/modules/base/base.router.ts"],"names":[],"mappings":";;;;;AAeA,sDAgNC;AA/ND,2CAA4D;AAC5D,uGAAwE;AACxE,+CAAgD;AAChD,0DAAkC;AAClC,qEAGkD;AAClD,yDAG4B;AAC5B,yEAAwE;AACxE,mGAAyE;AAEzE,SAAgB,qBAAqB;IACnC,MAAM,MAAM,GAAG,IAAA,qBAAW,GAAE,CAAC;IAE7B,8BAAkB,CAAC,yBAAyB,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACjE,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC;QAE1C,MAAM,SAAS,GAAG,mBAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,IAAI,wBAAc,CAAC,KAAK,CAAC,CAAC;QAE7C,MAAM,WAAW,GAAG,iCAAgB,CAAC,OAAO,CAC1C,gBAAg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WAAW,CACZ,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,SAAS,EACpB,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACjD,CAAC;QAGF,CAAC;YACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GACvD,EAAE,CAAC,WAAW,CAAC,CAAC;YAClB,MAAM,CAAC,MAAM,CACX;gBACE,GAAG,WAAW;gBACd,IAAI,EAAE,IAAI,SAAS,MAAM;aAC1B,EACD,IAAA,iDAA8B,EAC5B;gBACE,SAAS,EAAE,UAAU;aACtB,EACD,WAAW,CACZ,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,SAAS,EACpB,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACjD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ArkosRouter, BaseController } from \"../../exports\";\nimport loadableRegistry from \"../../components/arkos-loadable-registry\";\nimport { kebabCase } from \"../../exports/utils\";\nimport pluralize from \"pluralize\";\nimport {\n OperationByModule,\n routeHookReader,\n} from \"../../components/arkos-route-hook/reader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"./base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport prismaSchemaParser from \"../../utils/prisma/prisma-schema-parser\";\n\nexport function getPrismaModelsRouter() {\n const router = ArkosRouter();\n\n prismaSchemaParser.getModelsAsArrayOfStrings().map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const interceptor = loadableRegistry.getItem(\n \"ArkosRouteHook\",\n modelNameInKebab\n );\n\n const op = (operation: OperationByModule<\"\">) =>\n interceptor\n ? routeHookReader.forOperation(modelNameInKebab, operation)\n : {\n before: [],\n after: [],\n onError: [],\n prismaArgs: {},\n routeConfig: {},\n };\n\n // CREATE ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"createOne\");\n\n router.post(\n {\n ...routeConfig,\n path: `/${routeName}`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n createOne: prismaArgs,\n },\n \"createOne\"\n ),\n ...processMiddleware(before),\n controller.createOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // FIND MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"findMany\");\n router.get(\n {\n ...routeConfig,\n path: `/${routeName}`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n findMany: prismaArgs,\n },\n \"findMany\"\n ),\n ...processMiddleware(before),\n controller.findMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // CREATE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"createMany\");\n router.post(\n {\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n createMany: prismaArgs,\n },\n \"createMany\"\n ),\n ...processMiddleware(before),\n controller.createMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPDATE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"updateMany\");\n router.patch(\n {\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n updateMany: prismaArgs,\n },\n \"updateMany\"\n ),\n ...processMiddleware(before),\n controller.updateMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"deleteMany\");\n router.delete(\n {\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n deleteMany: prismaArgs,\n },\n \"deleteMany\"\n ),\n ...processMiddleware(before),\n controller.deleteMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // FIND ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"findOne\");\n router.get(\n {\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n findOne: prismaArgs,\n },\n \"findOne\"\n ),\n ...processMiddleware(before),\n controller.findOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPDATE ONE\n const { before, after, onError, prismaArgs, routeConfig } = op(\"updateOne\");\n router.patch(\n {\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n updateOne: prismaArgs,\n },\n \"updateOne\"\n ),\n ...processMiddleware(before),\n controller.updateOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n\n // DELETE ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"deleteOne\");\n router.delete(\n {\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n deleteOne: prismaArgs,\n },\n \"deleteOne\"\n ),\n ...processMiddleware(before),\n controller.deleteOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n });\n\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.router.js","sourceRoot":"","sources":["../../../../src/modules/base/base.router.ts"],"names":[],"mappings":";;;;;AAeA,sDAwNC;AAvOD,2CAA4D;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OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACjD,CAAC;QAGF,CAAC;YACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GACvD,EAAE,CAAC,WAAW,CAAC,CAAC;YAClB,MAAM,CAAC,MAAM,CACX;gBACE,cAAc,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE;gBAChE,GAAG,WAAW;gBACd,IAAI,EAAE,IAAI,SAAS,MAAM;aAC1B,EACD,IAAA,iDAA8B,EAC5B;gBACE,SAAS,EAAE,UAAU;aACtB,EACD,WAAW,CACZ,EACD,GAAG,IAAA,mCAAiB,EAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,SAAS,EACpB,GAAG,IAAA,mCAAiB,EAAC,KAAK,CAAC,EAC3B,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACjD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ArkosRouter, BaseController } from \"../../exports\";\nimport loadableRegistry from \"../../components/arkos-loadable-registry\";\nimport { kebabCase } from \"../../exports/utils\";\nimport pluralize from \"pluralize\";\nimport {\n OperationByModule,\n routeHookReader,\n} from \"../../components/arkos-route-hook/reader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"./base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport prismaSchemaParser from \"../../utils/prisma/prisma-schema-parser\";\n\nexport function getPrismaModelsRouter() {\n const router = ArkosRouter();\n\n prismaSchemaParser.getModelsAsArrayOfStrings().map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routeHook = loadableRegistry.getItem(\n \"ArkosRouteHook\",\n modelNameInKebab\n );\n\n const op = (operation: OperationByModule<\"\">) =>\n routeHook\n ? routeHookReader.forOperation(modelNameInKebab, operation)\n : {\n before: [],\n after: [],\n onError: [],\n prismaArgs: {},\n routeConfig: {},\n };\n\n // CREATE ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"createOne\");\n\n router.post(\n {\n authentication: { action: \"Create\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n createOne: prismaArgs,\n },\n \"createOne\"\n ),\n ...processMiddleware(before),\n controller.createOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // FIND MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"findMany\");\n router.get(\n {\n authentication: { action: \"View\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n findMany: prismaArgs,\n },\n \"findMany\"\n ),\n ...processMiddleware(before),\n controller.findMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // CREATE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"createMany\");\n router.post(\n {\n authentication: { action: \"Create\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n createMany: prismaArgs,\n },\n \"createMany\"\n ),\n ...processMiddleware(before),\n controller.createMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPDATE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"updateMany\");\n router.patch(\n {\n authentication: { action: \"Update\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n updateMany: prismaArgs,\n },\n \"updateMany\"\n ),\n ...processMiddleware(before),\n controller.updateMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE MANY\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"deleteMany\");\n router.delete(\n {\n authentication: { action: \"Delete\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/many`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n deleteMany: prismaArgs,\n },\n \"deleteMany\"\n ),\n ...processMiddleware(before),\n controller.deleteMany,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // FIND ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } = op(\"findOne\");\n router.get(\n {\n authentication: { action: \"View\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n findOne: prismaArgs,\n },\n \"findOne\"\n ),\n ...processMiddleware(before),\n controller.findOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPDATE ONE\n const { before, after, onError, prismaArgs, routeConfig } = op(\"updateOne\");\n router.patch(\n {\n authentication: { action: \"Update\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n updateOne: prismaArgs,\n },\n \"updateOne\"\n ),\n ...processMiddleware(before),\n controller.updateOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n\n // DELETE ONE\n {\n const { before, after, onError, prismaArgs, routeConfig } =\n op(\"deleteOne\");\n router.delete(\n {\n authentication: { action: \"Delete\", resource: modelNameInKebab },\n ...routeConfig,\n path: `/${routeName}/:id`,\n },\n addPrismaQueryOptionsToRequest<any>(\n {\n deleteOne: prismaArgs,\n },\n \"deleteOne\"\n ),\n ...processMiddleware(before),\n controller.deleteOne,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n });\n\n return router;\n}\n"]}
|