arkos 1.6.2-beta → 1.6.3-beta
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.map +1 -1
- package/dist/cjs/components/arkos-policy/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +6 -4
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js +5 -3
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +1 -1
- package/dist/cjs/modules/email/email.service.js +1 -0
- package/dist/cjs/modules/email/email.service.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.controller.js +7 -4
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +4 -1
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/validation/validator.js +3 -0
- package/dist/cjs/types/validation/validator.js.map +1 -0
- package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +12 -3
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +11 -10
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/components/arkos-policy/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +6 -4
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/auth/utils/services/auth-action.service.js +6 -4
- package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -1
- package/dist/esm/modules/email/email.service.js +1 -0
- package/dist/esm/modules/email/email.service.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.controller.js +7 -4
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +4 -1
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/validation/validator.js +2 -0
- package/dist/esm/types/validation/validator.js.map +1 -0
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -1
- package/dist/esm/utils/cli/build.js +13 -4
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/start.js +11 -10
- package/dist/esm/utils/cli/start.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/types/modules/auth/utils/services/auth-action.service.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/validation/validator.d.ts +2 -0
- package/dist/types/utils/arkos-router/types/index.d.ts +9 -9
- package/dist/types/utils/cli/build.d.ts +1 -1
- package/dist/types/utils/cli/start.d.ts +4 -1
- package/package.json +4 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,mCAAuC;AAiVrB,6FAjVT,oBAAY,OAiVS;AAhV9B,+BAAmC;AAgVH,2FAhVvB,gBAAU,OAgVuB;AA/U1C,mCAAuC;AA+UK,6FA/UnC,oBAAY,OA+UmC;AA9UxD,yCAA6C;AA8Ua,gGA9UjD,0BAAe,OA8UiD;AA7UzE,qDAAiD;AACjD,wEAAsD;AACtD,8EAA2D;AAE3D,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAyUrB,0BAAO;AAvUhB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,I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,CAAC;QACxC,0BAAe,CAAC,kBAAkB,CAAC;YACjC,GAAG,eAAe;YAClB,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,QAAQ;KACL,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,sCAAsC,CAAC;KACnD,MAAM,CAAC,GAAG,EAAE;IACX,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7B,0BAAe,CAAC,kBAAkB,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport prismaGenerateCommand from \"./prisma-generate\";\nimport exportAuthActionCommand from \"./export-auth-action\";\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand);\n\nconst generate = program\n .command(\"generate\")\n .alias(\"g\")\n .description(\"Generate arkos components\")\n .option(\n \"-m, --module <name>\",\n \"Module name (comma-separated for bulk: post,user,auth)\"\n )\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\"-p, --path <path>\", \"Custom path for the component\")\n .option(\"-o, --overwrite\", \"Overwrites all the content on the existing file\");\n\ngenerate\n .command(\"controller\")\n .alias(\"c\")\n .description(\"Generate a new controller\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.controller({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"service\")\n .alias(\"s\")\n .description(\"Generate a new service\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.service({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"router\")\n .alias(\"r\")\n .description(\"Generate a new router\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.router({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"auth-configs\")\n .alias(\"a\")\n .description(\"Generate auth configuration\")\n .option(\"-a, --advanced\", \"Advanced code structure\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.authConfigs({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-options\")\n .alias(\"q\")\n .description(\"Generate prisma query options\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.queryOptions({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"interceptors\")\n .alias(\"i\")\n .description(\"Generate a new interceptors file\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.interceptors({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"hooks\")\n .alias(\"h\")\n .description(\"Generate a new service hooks file\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.hooks({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"create-schema\")\n .alias(\"cs\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.createSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-schema\")\n .alias(\"us\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"schema\")\n .alias(\"sc\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.baseSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-schema\")\n .alias(\"qs\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.querySchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"create-dto\")\n .alias(\"cd\")\n .description(\n \"Generate a new class-validator create dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.createDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-dto\")\n .alias(\"ud\")\n .description(\n \"Generate a new class-validator update dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"dto\")\n .alias(\"d\")\n .description(\n \"Generate a new class-validator base dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.baseDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-dto\")\n .alias(\"qd\")\n .description(\n \"Generate a new class-validator base dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.queryDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"model\")\n .alias(\"m\")\n .description(\"Generate a new prisma model\")\n .option(\"-p, --path <path>\", \"Custom path for prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.prismaModel({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"policy\")\n .alias(\"p\")\n .description(\"Generate a new policy\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.policy({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"login-schema\")\n .alias(\"ls\")\n .description(\"Generate zod login schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.loginSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"signup-schema\")\n .alias(\"ss\")\n .description(\"Generate zod signup schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.signupSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-me-schema\")\n .alias(\"ums\")\n .description(\"Generate zod update-me schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateMeSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-password-schema\")\n .alias(\"ups\")\n .description(\"Generate zod update-password schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updatePasswordSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"login-dto\")\n .alias(\"ld\")\n .description(\"Generate class-validator login dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.loginDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"signup-dto\")\n .alias(\"sd\")\n .description(\"Generate class-validator signup dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.signupDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-me-dto\")\n .alias(\"umd\")\n .description(\"Generate class-validator update-me dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateMeDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-password-dto\")\n .alias(\"upd\")\n .description(\"Generate class-validator update-password dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updatePasswordDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"components\")\n .alias(\"co\")\n .description(\n \"Generate multiple components for one or more modules. Use -m post,user,auth for multiple modules\"\n )\n .option(\"-a, --all\", \"Generate all components\")\n .option(\n \"-n, --names <names>\",\n \"Comma-separated list of components (e.g., s,sc,m or service,schema,model)\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.multipleComponents({ ...generateOptions, ...options });\n });\n\nprogram\n .command(\"prisma\")\n .command(\"generate\")\n .description(\"Generate your @prisma/client and BaseService class types\")\n .action(prismaGenerateCommand);\n\nprogram\n .command(\"export\")\n .command(\"auth-action\")\n .description(\"Export file with an array containing all auth-actions\")\n .option(\"-o, --overwrite\", \"Overwrites all the changes on the object\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for auth-actions\",\n \"src/modules/auth/utils\"\n )\n .action(exportAuthActionCommand);\n\n// To resolve arkos g r,c,service -m post\ngenerate.on(\"command:*\", ([unknownCmd]) => {\n if (unknownCmd.includes(\",\") && !unknownCmd.includes(\" \")) {\n const generateOptions = generate.opts();\n generateCommand.multipleComponents({\n ...generateOptions,\n names: unknownCmd,\n });\n } else {\n console.error(`Unknown command: ${unknownCmd}`);\n process.exit(1);\n }\n});\n\ngenerate\n .command(\"all\")\n .description(\"Generate all components for a module\")\n .action(() => {\n const opts = generate.opts();\n generateCommand.multipleComponents({ ...opts, all: true });\n });\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,mCAAuC;AAiVrB,6FAjVT,oBAAY,OAiVS;AAhV9B,+BAAmC;AAgVH,2FAhVvB,gBAAU,OAgVuB;AA/U1C,mCAAuC;AA+UK,6FA/UnC,oBAAY,OA+UmC;AA9UxD,yCAA6C;AA8Ua,gGA9UjD,0BAAe,OA8UiD;AA7UzE,qDAAiD;AACjD,wEAAsD;AACtD,8EAA2D;AAE3D,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAyUrB,0BAAO;AAvUhB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,IA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E,CAAC;QACxC,0BAAe,CAAC,kBAAkB,CAAC;YACjC,GAAG,eAAe;YAClB,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,QAAQ;KACL,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,sCAAsC,CAAC;KACnD,MAAM,CAAC,GAAG,EAAE;IACX,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7B,0BAAe,CAAC,kBAAkB,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport prismaGenerateCommand from \"./prisma-generate\";\nimport exportAuthActionCommand from \"./export-auth-action\";\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand as any);\n\nconst generate = program\n .command(\"generate\")\n .alias(\"g\")\n .description(\"Generate arkos components\")\n .option(\n \"-m, --module <name>\",\n \"Module name (comma-separated for bulk: post,user,auth)\"\n )\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\"-p, --path <path>\", \"Custom path for the component\")\n .option(\"-o, --overwrite\", \"Overwrites all the content on the existing file\");\n\ngenerate\n .command(\"controller\")\n .alias(\"c\")\n .description(\"Generate a new controller\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.controller({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"service\")\n .alias(\"s\")\n .description(\"Generate a new service\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.service({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"router\")\n .alias(\"r\")\n .description(\"Generate a new router\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.router({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"auth-configs\")\n .alias(\"a\")\n .description(\"Generate auth configuration\")\n .option(\"-a, --advanced\", \"Advanced code structure\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.authConfigs({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-options\")\n .alias(\"q\")\n .description(\"Generate prisma query options\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.queryOptions({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"interceptors\")\n .alias(\"i\")\n .description(\"Generate a new interceptors file\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.interceptors({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"hooks\")\n .alias(\"h\")\n .description(\"Generate a new service hooks file\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.hooks({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"create-schema\")\n .alias(\"cs\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.createSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-schema\")\n .alias(\"us\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"schema\")\n .alias(\"sc\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.baseSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-schema\")\n .alias(\"qs\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.querySchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"create-dto\")\n .alias(\"cd\")\n .description(\n \"Generate a new class-validator create dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.createDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-dto\")\n .alias(\"ud\")\n .description(\n \"Generate a new class-validator update dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"dto\")\n .alias(\"d\")\n .description(\n \"Generate a new class-validator base dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.baseDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"query-dto\")\n .alias(\"qd\")\n .description(\n \"Generate a new class-validator base dto file for a prisma model\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.queryDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"model\")\n .alias(\"m\")\n .description(\"Generate a new prisma model\")\n .option(\"-p, --path <path>\", \"Custom path for prisma model\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.prismaModel({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"policy\")\n .alias(\"p\")\n .description(\"Generate a new policy\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.policy({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"login-schema\")\n .alias(\"ls\")\n .description(\"Generate zod login schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.loginSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"signup-schema\")\n .alias(\"ss\")\n .description(\"Generate zod signup schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.signupSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-me-schema\")\n .alias(\"ums\")\n .description(\"Generate zod update-me schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateMeSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-password-schema\")\n .alias(\"ups\")\n .description(\"Generate zod update-password schema for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updatePasswordSchema({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"login-dto\")\n .alias(\"ld\")\n .description(\"Generate class-validator login dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.loginDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"signup-dto\")\n .alias(\"sd\")\n .description(\"Generate class-validator signup dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.signupDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-me-dto\")\n .alias(\"umd\")\n .description(\"Generate class-validator update-me dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updateMeDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"update-password-dto\")\n .alias(\"upd\")\n .description(\"Generate class-validator update-password dto for auth module\")\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.updatePasswordDto({ ...generateOptions, ...options });\n });\n\ngenerate\n .command(\"components\")\n .alias(\"co\")\n .description(\n \"Generate multiple components for one or more modules. Use -m post,user,auth for multiple modules\"\n )\n .option(\"-a, --all\", \"Generate all components\")\n .option(\n \"-n, --names <names>\",\n \"Comma-separated list of components (e.g., s,sc,m or service,schema,model)\"\n )\n .action((options) => {\n const generateOptions = generate.opts();\n generateCommand.multipleComponents({ ...generateOptions, ...options });\n });\n\nprogram\n .command(\"prisma\")\n .command(\"generate\")\n .description(\"Generate your @prisma/client and BaseService class types\")\n .action(prismaGenerateCommand);\n\nprogram\n .command(\"export\")\n .command(\"auth-action\")\n .description(\"Export file with an array containing all auth-actions\")\n .option(\"-o, --overwrite\", \"Overwrites all the changes on the object\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for auth-actions\",\n \"src/modules/auth/utils\"\n )\n .action(exportAuthActionCommand);\n\n// To resolve arkos g r,c,service -m post\ngenerate.on(\"command:*\", ([unknownCmd]) => {\n if (unknownCmd.includes(\",\") && !unknownCmd.includes(\" \")) {\n const generateOptions = generate.opts();\n generateCommand.multipleComponents({\n ...generateOptions,\n names: unknownCmd,\n });\n } else {\n console.error(`Unknown command: ${unknownCmd}`);\n process.exit(1);\n }\n});\n\ngenerate\n .command(\"all\")\n .description(\"Generate all components for a module\")\n .action(() => {\n const opts = generate.opts();\n generateCommand.multipleComponents({ ...opts, all: true });\n });\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
@@ -15,7 +15,7 @@ const sheu_1 = __importDefault(require("../sheu.js"));
|
|
|
15
15
|
const arkos_config_helpers_1 = require("../helpers/arkos-config.helpers.js");
|
|
16
16
|
let child = null;
|
|
17
17
|
let envFiles;
|
|
18
|
-
|
|
18
|
+
function startCommand(options = {}) {
|
|
19
19
|
process.env.NO_CLI = "true";
|
|
20
20
|
if (!process.env.NODE_ENV)
|
|
21
21
|
process.env.NODE_ENV = "production";
|
|
@@ -41,15 +41,13 @@ async function startCommand(options = {}) {
|
|
|
41
41
|
env?.CLI_HOST ||
|
|
42
42
|
env?.HOST ||
|
|
43
43
|
(env.ARKOS_BUILD !== "true" ? "0.0.0.0" : "127.0.0.1");
|
|
44
|
-
env.__PORT =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
host: env.__HOST,
|
|
52
|
-
});
|
|
44
|
+
env.__PORT = env?.CLI_PORT || env?.PORT || "8000";
|
|
45
|
+
if (options.stamp !== false)
|
|
46
|
+
watermark_stamper_1.default.stamp({
|
|
47
|
+
envFiles,
|
|
48
|
+
port: env.__PORT,
|
|
49
|
+
host: env.__HOST,
|
|
50
|
+
});
|
|
53
51
|
child = (0, child_process_1.spawn)("node", [entryPoint], {
|
|
54
52
|
stdio: "inherit",
|
|
55
53
|
env,
|
|
@@ -60,8 +58,11 @@ async function startCommand(options = {}) {
|
|
|
60
58
|
child.kill();
|
|
61
59
|
process.exit(0);
|
|
62
60
|
});
|
|
61
|
+
return child;
|
|
63
62
|
}
|
|
64
63
|
catch (error) {
|
|
64
|
+
if (options.shouldThrow)
|
|
65
|
+
throw error;
|
|
65
66
|
sheu_1.default.error("Production server failed to start:");
|
|
66
67
|
console.error(error);
|
|
67
68
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;AAsBA,oCAoEC;AAKD,4EAGC;AAlGD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAoD;AACpD,sDAA6D;AAC7D,sDAAqD;AACrD,kFAAyD;AACzD,mDAA2B;AAC3B,0EAAiE;AASjE,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAKnC,SAAgB,YAAY,CAAC,UAAwB,EAAE;IACrD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IAE5B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;IAC/D,OAAO,C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AAO,CAAC,KAAK,KAAK,KAAK;YACzB,2BAAgB,CAAC,KAAK,CAAC;gBACrB,QAAQ;gBACR,IAAI,EAAE,GAAG,CAAC,MAAM;gBAChB,IAAI,EAAE,GAAG,CAAC,MAAM;aACjB,CAAC,CAAC;QAEL,KAAK,GAAG,IAAA,qBAAK,EAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;YAClC,KAAK,EAAE,SAAS;YAChB,GAAG;YACH,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACxB,IAAI,KAAK;gBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YAExB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,WAAW;YAAE,MAAM,KAAK,CAAC;QACrC,cAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,gCAAgC;IAC7C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { ChildProcess, spawn } from \"child_process\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { fullCleanCwd } from \"../helpers/fs.helpers\";\nimport watermarkStamper from \"./utils/watermark-stamper\";\nimport sheu from \"../sheu\";\nimport { getArkosConfig } from \"../helpers/arkos-config.helpers\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n stamp?: false;\n shouldThrow?: true;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Production start command for the arkos CLI\n */\nexport function startCommand(options: StartOptions = {}) {\n process.env.NO_CLI = \"true\";\n\n if (!process.env.NODE_ENV) process.env.NODE_ENV = \"production\";\n process.env.ARKOS_BUILD = \"true\";\n\n envFiles = loadEnvironmentVariables();\n\n try {\n const { port, host } = options;\n\n const config = getArkosConfig();\n\n const entryPoint = path.join(\n process.cwd(),\n \".build\",\n config.source?.entryPoint!.replace(\".ts\", \".js\")!\n );\n\n if (!fs.existsSync(path.join(entryPoint))) {\n sheu.error(\n `Could not find built application entry point at ${fullCleanCwd(entryPoint).replaceAll(/^\\/+/g, \"\")}`\n );\n process.exit(1);\n }\n\n const env: { [x: string]: string } = {\n NODE_ENV: \"production\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n ARKOS_BUILD: \"true\",\n CLI: \"false\",\n };\n\n env.__HOST =\n env?.CLI_HOST ||\n env?.HOST ||\n (env.ARKOS_BUILD !== \"true\" ? \"0.0.0.0\" : \"127.0.0.1\");\n\n env.__PORT = env?.CLI_PORT || env?.PORT || \"8000\";\n\n if (options.stamp !== false)\n watermarkStamper.stamp({\n envFiles,\n port: env.__PORT,\n host: env.__HOST,\n });\n\n child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n process.on(\"SIGINT\", () => {\n if (child) child.kill();\n\n process.exit(0);\n });\n\n return child;\n } catch (error) {\n if (options.shouldThrow) throw error;\n sheu.error(\"Production server failed to start:\");\n console.error(error);\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the production server child process\n */\nexport function killProductionServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
|
package/dist/esm/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,sCAAsC,CAAC;AAC9C,OAAO,OAAO,MAAM,SAAS,CAAC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CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC;QACtE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAO,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC;QAElE,IAAK,IAAY,EAAE,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,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,MAAM,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,MAAM,UAAU,YAAY;IAC1B,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import \"./utils/helpers/arkos-config.helpers\"; // just to trigger loading of arkos config\nimport express from \"express\";\nimport setupApp from \"./utils/setup-app\";\nimport { Arkos } from \"./types/arkos\";\nimport initializeApp, { addGlobalErrorHandler } from \"./utils/initialize-app\";\nimport { Express } from \"express\";\nimport { logAppStartup } from \"./server\";\nimport { loadPrismaModule } from \"./utils/helpers/prisma.helpers\";\nimport { loadAllModuleComponents } from \"./utils/dynamic-loader\";\nimport runtimeCliCommander from \"./utils/cli/utils/runtime-cli-commander\";\nimport { IncomingMessage, Server, ServerResponse } from \"http\";\nimport ExitError from \"./utils/helpers/exit-error\";\nimport { applyArkosRouterProxy } from \"./utils/arkos-router/utils/helpers/apply-arkos-router-proxy\";\nimport {\n isProduction,\n validateArkosConfig,\n} from \"./utils/helpers/arkos-config.helpers\";\nexport const app: express.Express = express();\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 * await app.build();\n *\n * const server = http.createServer(app);\n * app.listen(server)\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/routing/setup}\n */\nexport function arkos(): Arkos {\n if (process.env.__ARKOS_CLI !== \"true\")\n throw ExitError(\n `Arkos.js application must be started the built-in cli ${isProduction() ? \"'arkos start' in production\" : `'arkos dev' in development`} see https://www.arkosjs.com/docs/getting-started/installation#7-set-up-packagejson-scripts`\n );\n\n if (instanciated)\n throw ExitError(`arkos() must be called only once, see ${docsLink}`);\n\n const app = applyArkosRouterProxy(express(), {}, \"app\") 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 async function loadApp() {\n await Promise.all([loadPrismaModule(), loadAllModuleComponents()]);\n let _app = initializeApp(app);\n _app = addGlobalErrorHandler(_app);\n\n if (process.env.CLI_COMMAND) await runtimeCliCommander.handle();\n return _app;\n }\n\n app.build = async 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 = await 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: any[]): Promise<Server> {\n process.env.__ARKOS_SERVER_LISTENER = \"arkos\";\n\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 await loadApp();\n }\n\n validateArkosConfig();\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/arkos-policy/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/arkos-policy/index.ts"],"names":[],"mappings":"AAOA,OAAO,WAAW,MAAM,iCAAiC,CAAC;AA+B1D,MAAM,UAAU,WAAW,CACzB,QAAmB;IAEnB,OAAO,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAClB,QAAmB,EACnB,KAAsC;IAEtC,MAAM,IAAI,GAAG,CACX,MAAe,EACf,MAAuB,EAC2B,EAAE;QACpD,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAChD,OAAO,WAAW,CAAgC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CACtC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE;QACjD,MAAM,SAAS,GAA8C;YAC3D,QAAQ;YACR,MAAM;YACN,IAAI,EAAE,MAAM;SACb,CAAC;QAEF,MAAM,OAAO,GAAkB,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;YACtE,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,EAAE;SACvB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAExE,OAAO;YACL,CAAC,MAAM,EAAE,SAAS,CAAC;YACnB,CAAC,MAAM,EAAE,OAAO,CAAC;SAClB,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,aAAsB;QAC9B,QAAQ;QACR,IAAI;QACJ,GAAG,aAAa;KACoC,CAAC;AACzD,CAAC","sourcesContent":["import {\n ArkosPolicyRule,\n IArkosPolicy,\n PolicyAuthEntry,\n PolicyChecker,\n PolicyWithActions,\n} from \"./types\";\nimport authService from \"../../modules/auth/auth.service\";\n\n/**\n * Creates a typed policy for a Prisma model resource.\n *\n * Each `.rule()` call registers an action and returns the policy\n * with a typed `can{Action}` permission checker and a typed `{Action}`\n * entry — both passable to the `authentication` field on `ArkosRouteHook`\n * and `ArkosRouter`, and callable for fine-grained permission checks.\n *\n * @param resource - The resource name in kebab-case (e.g. `\"user\"`, `\"blog-post\"`)\n *\n * @example\n * ```ts\n * const userPolicy = ArkosPolicy(\"user\")\n * .rule(\"Create\", [\"Admin\", \"Editor\"])\n * .rule(\"View\", \"*\")\n * .rule(\"Delete\", [\"Admin\"]);\n *\n * // Pass to authentication field\n * userRouter.post({ path: \"/users\", authentication: userPolicy.Create });\n * userRouteHook.deleteOne({ authentication: userPolicy.Delete });\n *\n * // Fine-grained check\n * if (userPolicy.canCreate(req.user)) { ... }\n *\n * export default userPolicy;\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/api-referency/arkos-policy}\n */\nexport function ArkosPolicy<TResource extends string>(\n resource: TResource\n): IArkosPolicy<TResource, never> {\n return buildPolicy(resource, {});\n}\n\nfunction buildPolicy<TResource extends string, TActions extends string>(\n resource: TResource,\n store: Record<string, ArkosPolicyRule>\n): PolicyWithActions<TResource, TActions> {\n const rule = <TAction extends string>(\n action: TAction,\n config: ArkosPolicyRule\n ): PolicyWithActions<TResource, TActions | TAction> => {\n const newStore = { ...store, [action]: config };\n return buildPolicy<TResource, TActions | TAction>(resource, newStore);\n };\n\n const actionEntries = Object.fromEntries(\n Object.entries(store).flatMap(([action, config]) => {\n const authEntry: PolicyAuthEntry<TResource, typeof action> = {\n resource,\n action,\n rule: config,\n };\n\n const checker: PolicyChecker = authService.permission(action, resource, {\n [action]: config || {},\n });\n\n const canKey = `can${action.charAt(0).toUpperCase()}${action.slice(1)}`;\n\n return [\n [action, authEntry],\n [canKey, checker],\n ];\n })\n );\n\n return {\n __type: \"ArkosPolicy\" as const,\n resource,\n rule,\n ...actionEntries,\n } as unknown as PolicyWithActions<TResource, TActions>;\n}\n"]}
|
|
@@ -259,7 +259,7 @@ export class AuthService {
|
|
|
259
259
|
if (!accessControl &&
|
|
260
260
|
appModules.some((appModule) => kebabCase(appModule) === kebabCase(resource)))
|
|
261
261
|
accessControl = getModuleComponents(resource)?.authConfigs?.accessControl;
|
|
262
|
-
authActionService.add(action, resource, accessControl);
|
|
262
|
+
const authAction = authActionService.add(action, resource, accessControl);
|
|
263
263
|
return catchAsync(async (req, _, next) => {
|
|
264
264
|
if (req.user) {
|
|
265
265
|
const user = req.user;
|
|
@@ -268,7 +268,7 @@ export class AuthService {
|
|
|
268
268
|
next();
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
|
-
const notEnoughPermissionsError = new AppError(
|
|
271
|
+
const notEnoughPermissionsError = new AppError(authAction.errorMessage, 403, "NotEnoughPermissions");
|
|
272
272
|
if (configs?.authentication?.mode === "dynamic") {
|
|
273
273
|
const hasPermission = await this.checkDynamicAccessControl(user.id, action, resource);
|
|
274
274
|
if (!hasPermission)
|
|
@@ -322,7 +322,9 @@ export class AuthService {
|
|
|
322
322
|
return user;
|
|
323
323
|
}
|
|
324
324
|
authorize(action, resource, rule) {
|
|
325
|
-
authActionService.add(action, resource, {
|
|
325
|
+
const authAction = authActionService.add(action, resource, {
|
|
326
|
+
[action]: rule,
|
|
327
|
+
});
|
|
326
328
|
return catchAsync(async (req, _, next) => {
|
|
327
329
|
const hooks = getArkosConfig()?.authentication?.hooks?.authorize;
|
|
328
330
|
const before = await this.runHooks(hooks?.before, req, {
|
|
@@ -348,7 +350,7 @@ export class AuthService {
|
|
|
348
350
|
const user = req.user;
|
|
349
351
|
const configs = getArkosConfig();
|
|
350
352
|
if (!user.isSuperUser) {
|
|
351
|
-
const notEnoughPermissionsError = new AppError(
|
|
353
|
+
const notEnoughPermissionsError = new AppError(authAction.errorMessage, 403, "NotEnoughPermissions");
|
|
352
354
|
if (configs?.authentication?.mode === "dynamic") {
|
|
353
355
|
const hasPermission = await this.checkDynamicAccessControl(user.id, action, resource);
|
|
354
356
|
if (!hasPermission)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAoB,MAAM,cAAc,CAA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C;YAC7C,IAAI,CAAC,IAAI;gBAAE,MAAM,kBAAkB,CAAC;YACpC,IAAI,IAAI,EAAE,WAAW;gBAAE,OAAO,IAAI,CAAC;YAEnC,IAAI,OAAO,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;gBAChD,OAAO,MAAM,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC1E,CAAC;iBAAM,IAAI,OAAO,EAAE,cAAc,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtD,IAAI,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBAC5D,aAAa,GAAG,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,WAAW;wBACnE,EAAE,aAAa,CAAC;gBAEpB,OAAO,CACL,CAAC,CAAC,aAAa;oBACf,IAAI,CAAC,wBAAwB,CAAC,IAAW,EAAE,MAAM,EAAE,aAAa,CAAC,CAClE,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;CACF;AAKD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,eAAe,WAAW,CAAC","sourcesContent":["import jwt, { SignOptions } from \"jsonwebtoken\";\nimport bcrypt from \"bcryptjs\";\nimport { User } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { callNext } from \"../base/base.middlewares\";\nimport { getArkosConfig } from \"../../server\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../types\";\nimport {\n AuthJwtPayload,\n AccessAction,\n AccessControlConfig,\n AuthenticationControlConfig,\n AccessControlRules,\n DetailedAccessControlRule,\n} from \"../../types/auth\";\nimport { MsDuration, toMs } from \"./utils/helpers/auth.controller.helpers\";\nimport { appModules, getModuleComponents } from \"../../utils/dynamic-loader\";\nimport { kebabCase } from \"../../exports/utils\";\nimport {\n invaliAuthTokenError,\n loginRequiredError,\n} from \"./utils/auth-error-objects\";\nimport authActionService from \"./utils/services/auth-action.service\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\nimport {\n AuthenticateHookHandler,\n AuthenticateAfterHookHandler,\n AuthenticateErrorHookHandler,\n AuthorizeHookHandler,\n AuthorizeAfterHookHandler,\n AuthorizeErrorHookHandler,\n} from \"../../types/arkos-config/utils\";\nimport { CookieOptions } from \"express\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\n /**\n * Object containing a combination of actions per resource, tracked by each set of calls of `authService.handleAccessControl`, this can be accessed through the `authService` object or through the endpoint\n */\n actionsPerResource: Record<string, Set<string>> = {};\n\n /**\n * Runs a chain of `before` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to `onError` hooks.\n * - If a hook calls `skip()` — chain stops, core logic is bypassed, jumps to `after` hooks.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ skipped, error? }`\n */\n private async runHooks(\n hooks:\n | AuthenticateHookHandler\n | AuthenticateHookHandler[]\n | AuthorizeHookHandler\n | AuthorizeHookHandler[]\n | undefined,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ skipped: boolean; error?: unknown }> {\n if (!hooks) return { skipped: false };\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n let skipCalled = false;\n\n try {\n await (hook as any)({\n req,\n skip: () => {\n skipCalled = true;\n },\n ...ctx,\n });\n } catch (err) {\n return { skipped: false, error: err };\n }\n\n if (skipCalled) return { skipped: true };\n }\n\n return { skipped: false };\n }\n\n /**\n * Runs a chain of `after` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to the global error handler.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ error? }`\n */\n private async runAfterHooks(\n hooks:\n | AuthenticateAfterHookHandler\n | AuthenticateAfterHookHandler[]\n | AuthorizeAfterHookHandler\n | AuthorizeAfterHookHandler[]\n | undefined,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ error?: unknown }> {\n if (!hooks) return {};\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n try {\n await (hook as any)({ req, ...ctx });\n } catch (err) {\n return { error: err };\n }\n }\n\n return {};\n }\n\n /**\n * Runs a chain of `onError` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to the global error handler.\n * - If a hook calls `skip()` — suppresses the error and jumps to `after` hooks.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ skipped, error? }`\n */\n private async runErrorHooks(\n hooks:\n | AuthenticateErrorHookHandler\n | AuthenticateErrorHookHandler[]\n | AuthorizeErrorHookHandler\n | AuthorizeErrorHookHandler[]\n | undefined,\n error: unknown,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ skipped: boolean; error?: unknown }> {\n if (!hooks) return { skipped: false, error };\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n let skipCalled = false;\n\n try {\n await (hook as any)({\n req,\n error,\n skip: () => {\n skipCalled = true;\n },\n ...ctx,\n });\n } catch (err) {\n return { skipped: false, error: err };\n }\n\n if (skipCalled) return { skipped: true };\n }\n\n return { skipped: false, error };\n }\n /**\n * Signs a JWT token for the user.\n *\n * @param {number | string} id - The unique identifier of the user to generate the token for.\n * @param {string | number} [expiresIn] - The expiration time for the token. Defaults to environment variable `JWT_EXPIRES_IN`.\n * @param {string} [secret] - The secret key used to sign the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {string} The signed JWT token.\n */\n signJwtToken(\n id: number | string,\n expiresIn?: MsDuration | number,\n secret?: string\n ): string {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n \"MissingJWTOnProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n expiresIn = (expiresIn ||\n configs?.jwt?.expiresIn ||\n process.env.JWT_EXPIRES_IN ||\n arkosEnv.JWT_EXPIRES_IN) as keyof SignOptions[\"expiresIn\"];\n\n return jwt.sign({ id }, secret, {\n expiresIn: expiresIn as MsDuration,\n });\n }\n\n /**\n * Retrieves cookie configuration options for JWT authentication.\n *\n * Merges configuration from multiple sources in order of precedence:\n * 1. Arkos configuration file\n * 2. Environment variables\n * 3. Request properties (for secure flag)\n * 4. Default fallback values\n *\n * @param req - ArkosRequest object used to determine if the connection is secure\n * @returns Cookie options object with expires, httpOnly, secure, and sameSite properties\n *\n * @example\n * ```typescript\n * const cookieOptions = authService.getJwtCookieOptions(req);\n * res.cookie('jwt', token, cookieOptions);\n * ```\n */\n getJwtCookieOptions(req: ArkosRequest) {\n const arkosConfig = getArkosConfig();\n const authConfigs = arkosConfig?.authentication;\n\n if (!req)\n throw new Error(\"Missing req object in order get jwt cookie options\");\n\n const sameSite =\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n \"lax\";\n\n return {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ??\n (process.env.JWT_COOKIE_HTTP_ONLY !== undefined\n ? process.env.JWT_COOKIE_HTTP_ONLY === \"true\"\n : undefined) ??\n true,\n secure: (() => {\n if (authConfigs?.jwt?.cookie?.secure !== undefined)\n return authConfigs?.jwt?.cookie?.secure;\n else if (process.env.JWT_COOKIE_SECURE !== undefined)\n return process.env.JWT_COOKIE_SECURE === \"true\";\n else return req.secure || req.headers[\"x-forwarded-proto\"] === \"https\";\n })(),\n sameSite,\n domain: authConfigs?.jwt?.cookie?.domain || process.env.JWT_COOKIE_DOMAIN,\n ...arkosConfig?.authentication?.jwt?.cookie,\n } as CookieOptions;\n }\n\n /**\n * Is used by default internally by Arkos under `BaseService` class to check if the password is already hashed.\n *\n * This was just added to prevent unwanted errors when someone just forgets that the `BaseService` class will automatically hash the password field using `authService.hashPassword` by default.\n *\n * So now before `BaseService` hashes it will test it.\n *\n *\n * @param password The password to be tested if is hashed\n * @returns\n */\n isPasswordHashed(password: string) {\n return !Number.isNaN(bcrypt.getRounds(password) * 1);\n }\n\n /**\n * Compares a candidate password with the stored user password to check if they match.\n *\n * @param {string} candidatePassword - The password provided by the user during login.\n * @param {string} userPassword - The password stored in the database.\n * @returns {Promise<boolean>} Returns true if the passwords match, otherwise false.\n */\n async isCorrectPassword(\n candidatePassword: string,\n userPassword: string\n ): Promise<boolean> {\n return await bcrypt.compare(candidatePassword, userPassword);\n }\n\n /**\n * Hashes a plain text password using bcrypt.\n *\n * @param {string} password - The password to be hashed.\n * @returns {Promise<string>} Returns the hashed password.\n */\n async hashPassword(password: string): Promise<string> {\n return await bcrypt.hash(password, 12);\n }\n\n /**\n * Checks if a password is strong, requiring uppercase, lowercase, and numeric characters as the default.\n *\n * **NB**: You must pay attention when using custom validation with zod or class-validator, try to use the same regex always.\n *\n * **Note**: You can define it when calling arkos.init()\n * ```ts\n * arkos.init({\n * authentication: {\n * passwordValidation:{ regex: /your-desired-regex/, message: 'password must contain...'}\n * }\n * })\n * ```\n *\n * @param {string} password - The password to check.\n * @returns {boolean} Returns true if the password meets the strength criteria, otherwise false.\n */\n public isPasswordStrong(password: string): boolean {\n const initAuthConfigs = getArkosConfig()?.authentication;\n\n const strongPasswordRegex =\n initAuthConfigs?.passwordValidation?.regex ||\n /^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/;\n return strongPasswordRegex.test(password);\n }\n\n /**\n * Checks if a user has changed their password after the JWT was issued.\n *\n * @param {User} user - The user object containing the passwordChangedAt field.\n * @param {number} JWTTimestamp - The timestamp when the JWT was issued.\n * @returns {boolean} Returns true if the user changed their password after the JWT was issued, otherwise false.\n */\n userChangedPasswordAfter(user: User, JWTTimestamp: number): boolean {\n if (user.passwordChangedAt) {\n const convertedTimestamp = parseInt(\n String(new Date(user.passwordChangedAt).getTime() / 1000),\n 10\n );\n\n return JWTTimestamp < convertedTimestamp;\n }\n return false;\n }\n\n /**\n * Verifies the authenticity of a JWT token.\n *\n * @param {string} token - The JWT token to verify.\n * @param {string} [secret] - The secret key used to verify the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {Promise<AuthJwtPayload>} Returns the decoded JWT payload if the token is valid.\n * @throws {Error} Throws an error if the token is invalid or expired.\n */\n async verifyJwtToken(\n token: string,\n secret?: string\n ): Promise<AuthJwtPayload> {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret in production\",\n 500,\n \"MissingJWTSecretInProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n return new Promise((resolve, reject) => {\n jwt.verify(token, secret, (err, decoded) => {\n if (err) reject(err);\n else resolve(decoded as AuthJwtPayload);\n });\n });\n }\n\n private isWildcardAccess(config: AccessControlConfig): config is \"*\" {\n return config === \"*\";\n }\n\n private isRoleList(config: AccessControlConfig): config is string[] {\n return Array.isArray(config);\n }\n\n private isAccessRules(\n config: AccessControlConfig\n ): config is Partial<AccessControlRules> {\n return (\n typeof config === \"object\" && config !== null && !Array.isArray(config)\n );\n }\n\n private normalizeRuleToRoles(\n rule: string[] | DetailedAccessControlRule | \"*\" | undefined\n ): string[] {\n if (!rule) return [];\n if (rule === \"*\") return [\"*\"];\n if (Array.isArray(rule)) return rule;\n return rule.roles === \"*\" ? [\"*\"] : (rule.roles ?? []);\n }\n\n private resolveAuthorizedRoles(\n action: AccessAction,\n accessControl: AccessControlConfig\n ): string[] {\n if (this.isWildcardAccess(accessControl)) return [\"*\"];\n if (this.isRoleList(accessControl)) return accessControl;\n if (this.isAccessRules(accessControl))\n return this.normalizeRuleToRoles(accessControl[action]);\n return [];\n }\n\n /**\n * Checks if a user has permission for a specific action using static access control rules.\n * Validates user roles against predefined access control configuration.\n *\n * @param user - The user object containing role or roles field\n * @param action - The action being performed\n * @param accessControl - Access control configuration (array of roles or object with action-role mappings)\n * @returns True if user has permission, false otherwise\n * @throws Error if user doesn't have role/roles field\n */\n protected checkStaticAccessControl(\n user: User,\n action: string,\n accessControl: AccessControlConfig\n ) {\n if (!user?.role && !user.roles)\n throw Error(\n \"Validation Error: In order to use static authentication user needs at least role field or roles for multiple roles.\"\n );\n\n let authorizedRoles = this.resolveAuthorizedRoles(action, accessControl);\n\n const userRoles = Array.isArray(user?.roles) ? user.roles : [user.role];\n\n return (\n authorizedRoles?.[0] === \"*\" ||\n !!userRoles.some((role: string) => authorizedRoles.includes(role))\n );\n }\n\n /**\n * Checks if a user has permission for a specific action and resource using dynamic access control.\n * Queries the database to verify user's role permissions.\n *\n * @param userId - The unique identifier of the user\n * @param action - The action being performed\n * @param resource - The resource being accessed\n * @returns Promise resolving to true if user has permission, false otherwise\n */\n protected async checkDynamicAccessControl(\n userId: string,\n action: string,\n resource: string\n ) {\n const prisma = getPrismaInstance();\n return !!(await prisma.userRole.findFirst({\n where: {\n userId,\n role: {\n permissions: {\n some: {\n resource,\n action,\n },\n },\n },\n },\n select: { id: true },\n }));\n }\n\n /**\n * Middleware function to handle access control based on user roles and permissions.\n *\n * @param {AccessAction} action - The action being performed (e.g., create, update, delete, view).\n * @param {string} resource - The resource name that the action is being performed on (e.g., \"User\", \"Post\").\n * @param {AccessControlConfig} accessControl - The access control configuration.\n * @returns {ArkosRequestHandler} The middleware function that checks if the user has permission to perform the action.\n *\n * @deprecated Will be removed on v2.0, use AuthService.authorize instead\n */\n handleAccessControl(\n action: AccessAction,\n resource: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n if (\n !accessControl &&\n appModules.some(\n (appModule) => kebabCase(appModule) === kebabCase(resource)\n )\n )\n accessControl = getModuleComponents(resource)?.authConfigs?.accessControl;\n\n authActionService.add(action, resource, accessControl);\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n const notEnoughPermissionsError = new AppError(\n \"You do not have permission to perfom this action\",\n 403,\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl) return next(notEnoughPermissionsError);\n\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n accessControl\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n }\n }\n\n next();\n }\n );\n }\n\n /**\n * Processes the cookies or authoriation token and returns the user.\n * @param req\n * @returns {Promise<User | null>} - if authentication is turned off in arkosConfig it returns null\n * @throws {AppError} Throws an error if the token is invalid or the user is not logged in.\n */\n async getAuthenticatedUser(req: ArkosRequest): Promise<User | null> {\n if (!isAuthenticationEnabled())\n throw Error(\n \"ValidationError: Trying to call AuthService.getAuthenticatedUser without setting up authentication\"\n );\n\n const prisma = getPrismaInstance();\n\n let token: string | undefined;\n\n if (\n req?.headers?.authorization &&\n req?.headers?.authorization.startsWith(\"Bearer\") &&\n req?.headers?.authorization.split?.(\" \")?.[1]\n )\n token = req?.headers?.authorization.split(\" \")[1];\n\n if (\n !token &&\n req?.cookies?.arkos_access_token !== \"no-token\" &&\n req.cookies\n ) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token) return null;\n\n let decoded: AuthJwtPayload | undefined;\n\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw invaliAuthTokenError;\n }\n\n if (!decoded?.id) throw invaliAuthTokenError;\n const user: any | null = await (prisma as any).user.findUnique({\n where: { id: String(decoded.id) },\n });\n\n if (!user)\n throw new AppError(\n \"The user belonging to this token does no longer exists\",\n 401,\n \"UserNoLongerExists\"\n );\n\n if (\n this.userChangedPasswordAfter(user, decoded.iat!) &&\n !req.path?.includes?.(\"logout\")\n )\n throw new AppError(\n \"User recently changed password! Please log in again.\",\n 401,\n \"PasswordChanged\"\n );\n\n req.accessToken = token;\n return user;\n }\n\n /**\n * Middleware to authenticate the request by extracting and verifying the JWT token and setting `req.user`.\n *\n * Runs `authentication.hooks.authenticate` before/after the authentication logic.\n *\n * Hook execution flow:\n * - `before` hooks run first — call `ctx.skip()` to bypass core logic and jump to `after` hooks,\n * call `ctx.next()` to stop the chain early, or return without calling anything to continue.\n * - Core logic runs — extracts and verifies the JWT token, sets `req.user`.\n * - `after` hooks run — call `ctx.next(err)` to abort or return without calling anything to continue.\n * - `onError` hooks run if core logic throws — call `ctx.skip()` to suppress the error and jump to\n * `after` hooks, or call `ctx.next(err)` to forward it to the global error handler.\n *\n * On custom routes, hooks defined in `arkosConfig` still apply since they are baked into this method.\n *\n * @example\n * ```ts\n * // custom route - hooks still run\n * router.get(\"/custom\", authService.authenticate, handler);\n * ```\n *\n * @example\n * ```ts\n * // skip built-in auth from a before hook\n * before: (ctx) => {\n * ctx.req.user = myCustomAuth(ctx.req);\n * ctx.skip();\n * }\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/authentication/hooks}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n const hooks = getArkosConfig()?.authentication?.hooks?.authenticate;\n\n const before = await this.runHooks(hooks?.before, req);\n if (before.error) {\n const onError = await this.runErrorHooks(\n hooks?.onError,\n before.error,\n req\n );\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req);\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n\n if (!before.skipped) {\n try {\n if (isAuthenticationEnabled()) {\n const user = (await this.getAuthenticatedUser(req)) as User;\n if (!user) throw loginRequiredError;\n req.user = user;\n }\n } catch (err) {\n const onError = await this.runErrorHooks(hooks?.onError, err, req);\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req);\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n }\n\n const after = await this.runAfterHooks(hooks?.after, req);\n if (after.error) return next(after.error);\n\n next();\n }\n );\n\n /**\n * Middleware to authorize the authenticated user for a given action on a resource.\n *\n * Runs `authentication.hooks.authorize` before/after the authorization logic.\n *\n * Hook execution flow:\n * - `before` hooks run first — call `ctx.skip()` to bypass core logic and jump to `after` hooks,\n * call `ctx.next()` to stop the chain early, or return without calling anything to continue.\n * - Core logic runs — checks user role/permissions against the access control rules.\n * - `after` hooks run — call `ctx.next(err)` to abort or return without calling anything to continue.\n * - `onError` hooks run if authorization fails — call `ctx.skip()` to suppress the error and jump to\n * `after` hooks, or call `ctx.next(err)` to forward it to the global error handler.\n *\n * @param resource - The resource being accessed, in kebabCase (e.g. `\"product\"`, `\"cart-item\"`)\n * @param action - The action being performed (e.g. `\"View\"`, `\"Create\"`, `\"Delete\"`)\n * @param rule - Access control rules for this action. Accepts a role list, a wildcard, or a `DetailedAccessControlRule`.\n *\n * @example\n * ```ts\n * router.delete(\"/products/:id\",\n * authService.authenticate,\n * authService.authorize(\"product\", \"Delete\", [\"admin\"]),\n * handler\n * );\n * ```\n *\n * @example\n * ```ts\n * // skip built-in authorization from a before hook\n * before: (ctx) => {\n * ctx.req.user.role = myCustomRoleResolver(ctx.req);\n * ctx.skip();\n * }\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/authentication/hooks#authorize}\n * @since v1.6.0-beta\n */\n authorize(\n action: AccessAction,\n resource: string,\n rule?: string[] | DetailedAccessControlRule | \"*\"\n ): ArkosRequestHandler {\n authActionService.add(action, resource, { [action]: rule });\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n const hooks = getArkosConfig()?.authentication?.hooks?.authorize;\n\n const before = await this.runHooks(hooks?.before, req, {\n action,\n resource,\n rule,\n });\n if (before.error) {\n const onError = await this.runErrorHooks(\n hooks?.onError,\n before.error,\n req,\n { action, resource, rule }\n );\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n\n if (!before.skipped) {\n try {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (!user.isSuperUser) {\n const notEnoughPermissionsError = new AppError(\n \"You do not have permission to perform this action\",\n 403,\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n if (!hasPermission) throw notEnoughPermissionsError;\n } else if (configs?.authentication?.mode === \"static\") {\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n { [action]: rule }\n );\n if (!hasPermission) throw notEnoughPermissionsError;\n }\n }\n }\n } catch (err) {\n const onError = await this.runErrorHooks(hooks?.onError, err, req, {\n action,\n resource,\n rule,\n });\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n }\n\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n if (after.error) return next(after.error);\n\n next();\n }\n );\n }\n\n /**\n * Handles authentication control by checking the `authenticationControl` configuration in the `authConfigs`.\n *\n * @param {ControllerActions} action - The action being performed (e.g., create, update, delete, view).\n * @param {AuthenticationControlConfig} authenticationControl - The authentication configuration object.\n * @returns {ArkosRequestHandler} The middleware function that checks if authentication is required.\n *\n * @deprecated Will be removed on v2.0, use AuthService.authenticate instead\n */\n handleAuthenticationControl(\n action: AccessAction,\n authenticationControl?: AuthenticationControlConfig | undefined\n ): ArkosRequestHandler {\n if (authenticationControl && typeof authenticationControl === \"object\") {\n if (authenticationControl[action] === false) return callNext;\n else if (authenticationControl[action] === true) return this.authenticate;\n } else return this.authenticate;\n\n return this.authenticate;\n }\n\n /**\n * Creates a permission checker function for a specific action and resource.\n *\n * PS: This method should be called during application initialization to build permission validators.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/fine-grained-access-control}\n *\n * @param action - The action to check permission for (e.g., 'View', 'Create', 'Delete')\n * @param resource - The resource being accessed, must be in kebabCase (e.g., 'user', 'cart-item', 'order')\n * @param accessControl - Access control rules (required for static authentication mode), and it is automatically loaded for known modules such as all prisma models, auth and file-upload.\n * @returns A function that takes a user object and returns a boolean indicating permission status\n *\n * @example\n * ```typescript\n * const hasViewProductPermission = await authService.permission('View', 'product');\n *\n * // Later in handler:\n * const canAccess = await hasViewProductPermission(user);\n * if (canAccess) {\n * // User has permission\n * }\n * ```\n */\n permission(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ) {\n // Check if called during request handling (deep call stack indicates handler execution)\n const stack = new Error().stack;\n\n if (stack?.includes(\"node_modules/express/lib/router/index.js\"))\n throw new Error(\n \"authService.permission() should be called during application initialization level.\"\n );\n\n authActionService.add(action, resource, accessControl);\n\n return async (user: User | undefined): Promise<boolean> => {\n // getArkosConfig must not be called the same time as arkos.init()\n const configs = getArkosConfig();\n\n if (!isUsingAuthentication())\n throw Error(\n \"Validation Error: Trying to use authService.permission without setting up authentication.\"\n );\n\n if (!isAuthenticationEnabled()) return false;\n if (!user) throw loginRequiredError;\n if (user?.isSuperUser) return true;\n\n if (configs?.authentication?.mode === \"dynamic\") {\n return await this.checkDynamicAccessControl(user?.id, action, resource);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl && appModules.includes(kebabCase(resource)))\n accessControl = getModuleComponents(kebabCase(resource))?.authConfigs\n ?.accessControl;\n\n return (\n !!accessControl &&\n this.checkStaticAccessControl(user as any, action, accessControl)\n );\n }\n return false;\n };\n }\n}\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nconst authService = new AuthService();\n\nexport default authService;\n"]}
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAoB,MAAM,cAAc,CAAC;AAChD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAevE,OAAO,EAAc,IAAI,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,iBAAiB,MAAM,sCAAsC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ACnE,EAAE,aAAa,CAAC;gBAEpB,OAAO,CACL,CAAC,CAAC,aAAa;oBACf,IAAI,CAAC,wBAAwB,CAAC,IAAW,EAAE,MAAM,EAAE,aAAa,CAAC,CAClE,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;CACF;AAKD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,eAAe,WAAW,CAAC","sourcesContent":["import jwt, { SignOptions } from \"jsonwebtoken\";\nimport bcrypt from \"bcryptjs\";\nimport { User } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { callNext } from \"../base/base.middlewares\";\nimport { getArkosConfig } from \"../../server\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../types\";\nimport {\n AuthJwtPayload,\n AccessAction,\n AccessControlConfig,\n AuthenticationControlConfig,\n AccessControlRules,\n DetailedAccessControlRule,\n} from \"../../types/auth\";\nimport { MsDuration, toMs } from \"./utils/helpers/auth.controller.helpers\";\nimport { appModules, getModuleComponents } from \"../../utils/dynamic-loader\";\nimport { kebabCase } from \"../../exports/utils\";\nimport {\n invaliAuthTokenError,\n loginRequiredError,\n} from \"./utils/auth-error-objects\";\nimport authActionService from \"./utils/services/auth-action.service\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\nimport {\n AuthenticateHookHandler,\n AuthenticateAfterHookHandler,\n AuthenticateErrorHookHandler,\n AuthorizeHookHandler,\n AuthorizeAfterHookHandler,\n AuthorizeErrorHookHandler,\n} from \"../../types/arkos-config/utils\";\nimport { CookieOptions } from \"express\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\n /**\n * Object containing a combination of actions per resource, tracked by each set of calls of `authService.handleAccessControl`, this can be accessed through the `authService` object or through the endpoint\n */\n actionsPerResource: Record<string, Set<string>> = {};\n\n /**\n * Runs a chain of `before` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to `onError` hooks.\n * - If a hook calls `skip()` — chain stops, core logic is bypassed, jumps to `after` hooks.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ skipped, error? }`\n */\n private async runHooks(\n hooks:\n | AuthenticateHookHandler\n | AuthenticateHookHandler[]\n | AuthorizeHookHandler\n | AuthorizeHookHandler[]\n | undefined,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ skipped: boolean; error?: unknown }> {\n if (!hooks) return { skipped: false };\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n let skipCalled = false;\n\n try {\n await (hook as any)({\n req,\n skip: () => {\n skipCalled = true;\n },\n ...ctx,\n });\n } catch (err) {\n return { skipped: false, error: err };\n }\n\n if (skipCalled) return { skipped: true };\n }\n\n return { skipped: false };\n }\n\n /**\n * Runs a chain of `after` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to the global error handler.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ error? }`\n */\n private async runAfterHooks(\n hooks:\n | AuthenticateAfterHookHandler\n | AuthenticateAfterHookHandler[]\n | AuthorizeAfterHookHandler\n | AuthorizeAfterHookHandler[]\n | undefined,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ error?: unknown }> {\n if (!hooks) return {};\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n try {\n await (hook as any)({ req, ...ctx });\n } catch (err) {\n return { error: err };\n }\n }\n\n return {};\n }\n\n /**\n * Runs a chain of `onError` hooks in sequence.\n *\n * - If a hook throws — chain aborts, error is forwarded to the global error handler.\n * - If a hook calls `skip()` — suppresses the error and jumps to `after` hooks.\n * - If a hook returns — next hook in chain runs.\n *\n * @returns Promise resolving to `{ skipped, error? }`\n */\n private async runErrorHooks(\n hooks:\n | AuthenticateErrorHookHandler\n | AuthenticateErrorHookHandler[]\n | AuthorizeErrorHookHandler\n | AuthorizeErrorHookHandler[]\n | undefined,\n error: unknown,\n req: ArkosRequest,\n ctx?: {\n action?: AccessAction;\n resource?: string;\n rule?: string[] | DetailedAccessControlRule | \"*\";\n }\n ): Promise<{ skipped: boolean; error?: unknown }> {\n if (!hooks) return { skipped: false, error };\n\n const hookArray = Array.isArray(hooks) ? hooks : [hooks];\n\n for (const hook of hookArray) {\n let skipCalled = false;\n\n try {\n await (hook as any)({\n req,\n error,\n skip: () => {\n skipCalled = true;\n },\n ...ctx,\n });\n } catch (err) {\n return { skipped: false, error: err };\n }\n\n if (skipCalled) return { skipped: true };\n }\n\n return { skipped: false, error };\n }\n /**\n * Signs a JWT token for the user.\n *\n * @param {number | string} id - The unique identifier of the user to generate the token for.\n * @param {string | number} [expiresIn] - The expiration time for the token. Defaults to environment variable `JWT_EXPIRES_IN`.\n * @param {string} [secret] - The secret key used to sign the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {string} The signed JWT token.\n */\n signJwtToken(\n id: number | string,\n expiresIn?: MsDuration | number,\n secret?: string\n ): string {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n \"MissingJWTOnProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n expiresIn = (expiresIn ||\n configs?.jwt?.expiresIn ||\n process.env.JWT_EXPIRES_IN ||\n arkosEnv.JWT_EXPIRES_IN) as keyof SignOptions[\"expiresIn\"];\n\n return jwt.sign({ id }, secret, {\n expiresIn: expiresIn as MsDuration,\n });\n }\n\n /**\n * Retrieves cookie configuration options for JWT authentication.\n *\n * Merges configuration from multiple sources in order of precedence:\n * 1. Arkos configuration file\n * 2. Environment variables\n * 3. Request properties (for secure flag)\n * 4. Default fallback values\n *\n * @param req - ArkosRequest object used to determine if the connection is secure\n * @returns Cookie options object with expires, httpOnly, secure, and sameSite properties\n *\n * @example\n * ```typescript\n * const cookieOptions = authService.getJwtCookieOptions(req);\n * res.cookie('jwt', token, cookieOptions);\n * ```\n */\n getJwtCookieOptions(req: ArkosRequest) {\n const arkosConfig = getArkosConfig();\n const authConfigs = arkosConfig?.authentication;\n\n if (!req)\n throw new Error(\"Missing req object in order get jwt cookie options\");\n\n const sameSite =\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n \"lax\";\n\n return {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ??\n (process.env.JWT_COOKIE_HTTP_ONLY !== undefined\n ? process.env.JWT_COOKIE_HTTP_ONLY === \"true\"\n : undefined) ??\n true,\n secure: (() => {\n if (authConfigs?.jwt?.cookie?.secure !== undefined)\n return authConfigs?.jwt?.cookie?.secure;\n else if (process.env.JWT_COOKIE_SECURE !== undefined)\n return process.env.JWT_COOKIE_SECURE === \"true\";\n else return req.secure || req.headers[\"x-forwarded-proto\"] === \"https\";\n })(),\n sameSite,\n domain: authConfigs?.jwt?.cookie?.domain || process.env.JWT_COOKIE_DOMAIN,\n ...arkosConfig?.authentication?.jwt?.cookie,\n } as CookieOptions;\n }\n\n /**\n * Is used by default internally by Arkos under `BaseService` class to check if the password is already hashed.\n *\n * This was just added to prevent unwanted errors when someone just forgets that the `BaseService` class will automatically hash the password field using `authService.hashPassword` by default.\n *\n * So now before `BaseService` hashes it will test it.\n *\n *\n * @param password The password to be tested if is hashed\n * @returns\n */\n isPasswordHashed(password: string) {\n return !Number.isNaN(bcrypt.getRounds(password) * 1);\n }\n\n /**\n * Compares a candidate password with the stored user password to check if they match.\n *\n * @param {string} candidatePassword - The password provided by the user during login.\n * @param {string} userPassword - The password stored in the database.\n * @returns {Promise<boolean>} Returns true if the passwords match, otherwise false.\n */\n async isCorrectPassword(\n candidatePassword: string,\n userPassword: string\n ): Promise<boolean> {\n return await bcrypt.compare(candidatePassword, userPassword);\n }\n\n /**\n * Hashes a plain text password using bcrypt.\n *\n * @param {string} password - The password to be hashed.\n * @returns {Promise<string>} Returns the hashed password.\n */\n async hashPassword(password: string): Promise<string> {\n return await bcrypt.hash(password, 12);\n }\n\n /**\n * Checks if a password is strong, requiring uppercase, lowercase, and numeric characters as the default.\n *\n * **NB**: You must pay attention when using custom validation with zod or class-validator, try to use the same regex always.\n *\n * **Note**: You can define it when calling arkos.init()\n * ```ts\n * arkos.init({\n * authentication: {\n * passwordValidation:{ regex: /your-desired-regex/, message: 'password must contain...'}\n * }\n * })\n * ```\n *\n * @param {string} password - The password to check.\n * @returns {boolean} Returns true if the password meets the strength criteria, otherwise false.\n */\n public isPasswordStrong(password: string): boolean {\n const initAuthConfigs = getArkosConfig()?.authentication;\n\n const strongPasswordRegex =\n initAuthConfigs?.passwordValidation?.regex ||\n /^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/;\n return strongPasswordRegex.test(password);\n }\n\n /**\n * Checks if a user has changed their password after the JWT was issued.\n *\n * @param {User} user - The user object containing the passwordChangedAt field.\n * @param {number} JWTTimestamp - The timestamp when the JWT was issued.\n * @returns {boolean} Returns true if the user changed their password after the JWT was issued, otherwise false.\n */\n userChangedPasswordAfter(user: User, JWTTimestamp: number): boolean {\n if (user.passwordChangedAt) {\n const convertedTimestamp = parseInt(\n String(new Date(user.passwordChangedAt).getTime() / 1000),\n 10\n );\n\n return JWTTimestamp < convertedTimestamp;\n }\n return false;\n }\n\n /**\n * Verifies the authenticity of a JWT token.\n *\n * @param {string} token - The JWT token to verify.\n * @param {string} [secret] - The secret key used to verify the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {Promise<AuthJwtPayload>} Returns the decoded JWT payload if the token is valid.\n * @throws {Error} Throws an error if the token is invalid or expired.\n */\n async verifyJwtToken(\n token: string,\n secret?: string\n ): Promise<AuthJwtPayload> {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret in production\",\n 500,\n \"MissingJWTSecretInProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n return new Promise((resolve, reject) => {\n jwt.verify(token, secret, (err, decoded) => {\n if (err) reject(err);\n else resolve(decoded as AuthJwtPayload);\n });\n });\n }\n\n private isWildcardAccess(config: AccessControlConfig): config is \"*\" {\n return config === \"*\";\n }\n\n private isRoleList(config: AccessControlConfig): config is string[] {\n return Array.isArray(config);\n }\n\n private isAccessRules(\n config: AccessControlConfig\n ): config is Partial<AccessControlRules> {\n return (\n typeof config === \"object\" && config !== null && !Array.isArray(config)\n );\n }\n\n private normalizeRuleToRoles(\n rule: string[] | DetailedAccessControlRule | \"*\" | undefined\n ): string[] {\n if (!rule) return [];\n if (rule === \"*\") return [\"*\"];\n if (Array.isArray(rule)) return rule;\n return rule.roles === \"*\" ? [\"*\"] : (rule.roles ?? []);\n }\n\n private resolveAuthorizedRoles(\n action: AccessAction,\n accessControl: AccessControlConfig\n ): string[] {\n if (this.isWildcardAccess(accessControl)) return [\"*\"];\n if (this.isRoleList(accessControl)) return accessControl;\n if (this.isAccessRules(accessControl))\n return this.normalizeRuleToRoles(accessControl[action]);\n return [];\n }\n\n /**\n * Checks if a user has permission for a specific action using static access control rules.\n * Validates user roles against predefined access control configuration.\n *\n * @param user - The user object containing role or roles field\n * @param action - The action being performed\n * @param accessControl - Access control configuration (array of roles or object with action-role mappings)\n * @returns True if user has permission, false otherwise\n * @throws Error if user doesn't have role/roles field\n */\n protected checkStaticAccessControl(\n user: User,\n action: string,\n accessControl: AccessControlConfig\n ) {\n if (!user?.role && !user.roles)\n throw Error(\n \"Validation Error: In order to use static authentication user needs at least role field or roles for multiple roles.\"\n );\n\n let authorizedRoles = this.resolveAuthorizedRoles(action, accessControl);\n\n const userRoles = Array.isArray(user?.roles) ? user.roles : [user.role];\n\n return (\n authorizedRoles?.[0] === \"*\" ||\n !!userRoles.some((role: string) => authorizedRoles.includes(role))\n );\n }\n\n /**\n * Checks if a user has permission for a specific action and resource using dynamic access control.\n * Queries the database to verify user's role permissions.\n *\n * @param userId - The unique identifier of the user\n * @param action - The action being performed\n * @param resource - The resource being accessed\n * @returns Promise resolving to true if user has permission, false otherwise\n */\n protected async checkDynamicAccessControl(\n userId: string,\n action: string,\n resource: string\n ) {\n const prisma = getPrismaInstance();\n return !!(await prisma.userRole.findFirst({\n where: {\n userId,\n role: {\n permissions: {\n some: {\n resource,\n action,\n },\n },\n },\n },\n select: { id: true },\n }));\n }\n\n /**\n * Middleware function to handle access control based on user roles and permissions.\n *\n * @param {AccessAction} action - The action being performed (e.g., create, update, delete, view).\n * @param {string} resource - The resource name that the action is being performed on (e.g., \"User\", \"Post\").\n * @param {AccessControlConfig} accessControl - The access control configuration.\n * @returns {ArkosRequestHandler} The middleware function that checks if the user has permission to perform the action.\n *\n * @deprecated Will be removed on v2.0, use AuthService.authorize instead\n */\n handleAccessControl(\n action: AccessAction,\n resource: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n if (\n !accessControl &&\n appModules.some(\n (appModule) => kebabCase(appModule) === kebabCase(resource)\n )\n )\n accessControl = getModuleComponents(resource)?.authConfigs?.accessControl;\n\n const authAction = authActionService.add(action, resource, accessControl);\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n const notEnoughPermissionsError = new AppError(\n authAction.errorMessage,\n 403,\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl) return next(notEnoughPermissionsError);\n\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n accessControl\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n }\n }\n\n next();\n }\n );\n }\n\n /**\n * Processes the cookies or authoriation token and returns the user.\n * @param req\n * @returns {Promise<User | null>} - if authentication is turned off in arkosConfig it returns null\n * @throws {AppError} Throws an error if the token is invalid or the user is not logged in.\n */\n async getAuthenticatedUser(req: ArkosRequest): Promise<User | null> {\n if (!isAuthenticationEnabled())\n throw Error(\n \"ValidationError: Trying to call AuthService.getAuthenticatedUser without setting up authentication\"\n );\n\n const prisma = getPrismaInstance();\n\n let token: string | undefined;\n\n if (\n req?.headers?.authorization &&\n req?.headers?.authorization.startsWith(\"Bearer\") &&\n req?.headers?.authorization.split?.(\" \")?.[1]\n )\n token = req?.headers?.authorization.split(\" \")[1];\n\n if (\n !token &&\n req?.cookies?.arkos_access_token !== \"no-token\" &&\n req.cookies\n ) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token) return null;\n\n let decoded: AuthJwtPayload | undefined;\n\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw invaliAuthTokenError;\n }\n\n if (!decoded?.id) throw invaliAuthTokenError;\n const user: any | null = await (prisma as any).user.findUnique({\n where: { id: String(decoded.id) },\n });\n\n if (!user)\n throw new AppError(\n \"The user belonging to this token does no longer exists\",\n 401,\n \"UserNoLongerExists\"\n );\n\n if (\n this.userChangedPasswordAfter(user, decoded.iat!) &&\n !req.path?.includes?.(\"logout\")\n )\n throw new AppError(\n \"User recently changed password! Please log in again.\",\n 401,\n \"PasswordChanged\"\n );\n\n req.accessToken = token;\n return user;\n }\n\n /**\n * Middleware to authenticate the request by extracting and verifying the JWT token and setting `req.user`.\n *\n * Runs `authentication.hooks.authenticate` before/after the authentication logic.\n *\n * Hook execution flow:\n * - `before` hooks run first — call `ctx.skip()` to bypass core logic and jump to `after` hooks,\n * call `ctx.next()` to stop the chain early, or return without calling anything to continue.\n * - Core logic runs — extracts and verifies the JWT token, sets `req.user`.\n * - `after` hooks run — call `ctx.next(err)` to abort or return without calling anything to continue.\n * - `onError` hooks run if core logic throws — call `ctx.skip()` to suppress the error and jump to\n * `after` hooks, or call `ctx.next(err)` to forward it to the global error handler.\n *\n * On custom routes, hooks defined in `arkosConfig` still apply since they are baked into this method.\n *\n * @example\n * ```ts\n * // custom route - hooks still run\n * router.get(\"/custom\", authService.authenticate, handler);\n * ```\n *\n * @example\n * ```ts\n * // skip built-in auth from a before hook\n * before: (ctx) => {\n * ctx.req.user = myCustomAuth(ctx.req);\n * ctx.skip();\n * }\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/authentication/hooks}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n const hooks = getArkosConfig()?.authentication?.hooks?.authenticate;\n\n const before = await this.runHooks(hooks?.before, req);\n if (before.error) {\n const onError = await this.runErrorHooks(\n hooks?.onError,\n before.error,\n req\n );\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req);\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n\n if (!before.skipped) {\n try {\n if (isAuthenticationEnabled()) {\n const user = (await this.getAuthenticatedUser(req)) as User;\n if (!user) throw loginRequiredError;\n req.user = user;\n }\n } catch (err) {\n const onError = await this.runErrorHooks(hooks?.onError, err, req);\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req);\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n }\n\n const after = await this.runAfterHooks(hooks?.after, req);\n if (after.error) return next(after.error);\n\n next();\n }\n );\n\n /**\n * Middleware to authorize the authenticated user for a given action on a resource.\n *\n * Runs `authentication.hooks.authorize` before/after the authorization logic.\n *\n * Hook execution flow:\n * - `before` hooks run first — call `ctx.skip()` to bypass core logic and jump to `after` hooks,\n * call `ctx.next()` to stop the chain early, or return without calling anything to continue.\n * - Core logic runs — checks user role/permissions against the access control rules.\n * - `after` hooks run — call `ctx.next(err)` to abort or return without calling anything to continue.\n * - `onError` hooks run if authorization fails — call `ctx.skip()` to suppress the error and jump to\n * `after` hooks, or call `ctx.next(err)` to forward it to the global error handler.\n *\n * @param resource - The resource being accessed, in kebabCase (e.g. `\"product\"`, `\"cart-item\"`)\n * @param action - The action being performed (e.g. `\"View\"`, `\"Create\"`, `\"Delete\"`)\n * @param rule - Access control rules for this action. Accepts a role list, a wildcard, or a `DetailedAccessControlRule`.\n *\n * @example\n * ```ts\n * router.delete(\"/products/:id\",\n * authService.authenticate,\n * authService.authorize(\"product\", \"Delete\", [\"admin\"]),\n * handler\n * );\n * ```\n *\n * @example\n * ```ts\n * // skip built-in authorization from a before hook\n * before: (ctx) => {\n * ctx.req.user.role = myCustomRoleResolver(ctx.req);\n * ctx.skip();\n * }\n * ```\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/authentication/hooks#authorize}\n * @since v1.6.0-beta\n */\n authorize(\n action: AccessAction,\n resource: string,\n rule?: string[] | DetailedAccessControlRule | \"*\"\n ): ArkosRequestHandler {\n const authAction = authActionService.add(action, resource, {\n [action]: rule,\n });\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n const hooks = getArkosConfig()?.authentication?.hooks?.authorize;\n\n const before = await this.runHooks(hooks?.before, req, {\n action,\n resource,\n rule,\n });\n if (before.error) {\n const onError = await this.runErrorHooks(\n hooks?.onError,\n before.error,\n req,\n { action, resource, rule }\n );\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n\n if (!before.skipped) {\n try {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (!user.isSuperUser) {\n const notEnoughPermissionsError = new AppError(\n authAction.errorMessage,\n 403,\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n if (!hasPermission) throw notEnoughPermissionsError;\n } else if (configs?.authentication?.mode === \"static\") {\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n { [action]: rule }\n );\n if (!hasPermission) throw notEnoughPermissionsError;\n }\n }\n }\n } catch (err) {\n const onError = await this.runErrorHooks(hooks?.onError, err, req, {\n action,\n resource,\n rule,\n });\n if (onError.skipped) {\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n return after.error ? next(after.error) : next();\n }\n return next(onError.error);\n }\n }\n\n const after = await this.runAfterHooks(hooks?.after, req, {\n action,\n resource,\n rule,\n });\n if (after.error) return next(after.error);\n\n next();\n }\n );\n }\n\n /**\n * Handles authentication control by checking the `authenticationControl` configuration in the `authConfigs`.\n *\n * @param {ControllerActions} action - The action being performed (e.g., create, update, delete, view).\n * @param {AuthenticationControlConfig} authenticationControl - The authentication configuration object.\n * @returns {ArkosRequestHandler} The middleware function that checks if authentication is required.\n *\n * @deprecated Will be removed on v2.0, use AuthService.authenticate instead\n */\n handleAuthenticationControl(\n action: AccessAction,\n authenticationControl?: AuthenticationControlConfig | undefined\n ): ArkosRequestHandler {\n if (authenticationControl && typeof authenticationControl === \"object\") {\n if (authenticationControl[action] === false) return callNext;\n else if (authenticationControl[action] === true) return this.authenticate;\n } else return this.authenticate;\n\n return this.authenticate;\n }\n\n /**\n * Creates a permission checker function for a specific action and resource.\n *\n * PS: This method should be called during application initialization to build permission validators.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/fine-grained-access-control}\n *\n * @param action - The action to check permission for (e.g., 'View', 'Create', 'Delete')\n * @param resource - The resource being accessed, must be in kebabCase (e.g., 'user', 'cart-item', 'order')\n * @param accessControl - Access control rules (required for static authentication mode), and it is automatically loaded for known modules such as all prisma models, auth and file-upload.\n * @returns A function that takes a user object and returns a boolean indicating permission status\n *\n * @example\n * ```typescript\n * const hasViewProductPermission = await authService.permission('View', 'product');\n *\n * // Later in handler:\n * const canAccess = await hasViewProductPermission(user);\n * if (canAccess) {\n * // User has permission\n * }\n * ```\n */\n permission(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ) {\n // Check if called during request handling (deep call stack indicates handler execution)\n const stack = new Error().stack;\n\n if (stack?.includes(\"node_modules/express/lib/router/index.js\"))\n throw new Error(\n \"authService.permission() should be called during application initialization level.\"\n );\n\n authActionService.add(action, resource, accessControl);\n\n return async (user: User | undefined): Promise<boolean> => {\n // getArkosConfig must not be called the same time as arkos.init()\n const configs = getArkosConfig();\n\n if (!isUsingAuthentication())\n throw Error(\n \"Validation Error: Trying to use authService.permission without setting up authentication.\"\n );\n\n if (!isAuthenticationEnabled()) return false;\n if (!user) throw loginRequiredError;\n if (user?.isSuperUser) return true;\n\n if (configs?.authentication?.mode === \"dynamic\") {\n return await this.checkDynamicAccessControl(user?.id, action, resource);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl && appModules.includes(kebabCase(resource)))\n accessControl = getModuleComponents(kebabCase(resource))?.authConfigs\n ?.accessControl;\n\n return (\n !!accessControl &&\n this.checkStaticAccessControl(user as any, action, accessControl)\n );\n }\n return false;\n };\n }\n}\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nconst authService = new AuthService();\n\nexport default authService;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { kebabCase } from "../../../../exports/utils/index.js";
|
|
1
|
+
import { kebabCase, sentenceCase } from "../../../../exports/utils/index.js";
|
|
2
2
|
import { getArkosConfig } from "../../../../utils/helpers/arkos-config.helpers.js";
|
|
3
3
|
import { capitalize } from "../../../../utils/helpers/text.helpers.js";
|
|
4
4
|
class AuthActionService {
|
|
@@ -10,7 +10,7 @@ class AuthActionService {
|
|
|
10
10
|
resource: "auth-action",
|
|
11
11
|
name: "View auth action",
|
|
12
12
|
description: "View an auth action",
|
|
13
|
-
errorMessage: "You
|
|
13
|
+
errorMessage: "You cannot perform view for auth action",
|
|
14
14
|
},
|
|
15
15
|
];
|
|
16
16
|
}
|
|
@@ -21,7 +21,7 @@ class AuthActionService {
|
|
|
21
21
|
const inconsistencies = [];
|
|
22
22
|
const defaultName = `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`;
|
|
23
23
|
const defaultDescription = `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`;
|
|
24
|
-
const defaultErrorMessage =
|
|
24
|
+
const defaultErrorMessage = `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`;
|
|
25
25
|
const isNonDefault = (value, defaultValue) => {
|
|
26
26
|
return value !== undefined && value !== defaultValue;
|
|
27
27
|
};
|
|
@@ -65,12 +65,14 @@ class AuthActionService {
|
|
|
65
65
|
};
|
|
66
66
|
this.remove(action, resource);
|
|
67
67
|
this.authActions.push(merged);
|
|
68
|
+
return merged;
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
70
71
|
if (transformedAction.roles) {
|
|
71
72
|
transformedAction.roles = [...transformedAction.roles].sort();
|
|
72
73
|
}
|
|
73
74
|
this.authActions.push(transformedAction);
|
|
75
|
+
return transformedAction;
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
remove(action, resource) {
|
|
@@ -98,7 +100,7 @@ class AuthActionService {
|
|
|
98
100
|
resource,
|
|
99
101
|
name: `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`,
|
|
100
102
|
description: `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`,
|
|
101
|
-
errorMessage: `You
|
|
103
|
+
errorMessage: `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`,
|
|
102
104
|
};
|
|
103
105
|
const config = getArkosConfig();
|
|
104
106
|
if (config?.authentication?.mode === "dynamic")
|