arkos 1.4.11-beta → 1.4.13-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.
Files changed (99) hide show
  1. package/dist/cjs/components/arkos-policy/index.js +38 -0
  2. package/dist/cjs/components/arkos-policy/index.js.map +1 -0
  3. package/dist/cjs/{types/arkos-prisma-input.bak.js → components/arkos-policy/types.js} +1 -1
  4. package/dist/cjs/components/arkos-policy/types.js.map +1 -0
  5. package/dist/cjs/exports/config.js +6 -0
  6. package/dist/cjs/exports/config.js.map +1 -0
  7. package/dist/cjs/modules/auth/auth.service.js +1 -1
  8. package/dist/cjs/modules/auth/auth.service.js.map +1 -1
  9. package/dist/cjs/modules/error-handler/error-handler.controller.js +1 -1
  10. package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
  11. package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js +288 -0
  12. package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js.map +1 -0
  13. package/dist/cjs/types/arkos-config/utils.js +3 -0
  14. package/dist/cjs/types/arkos-config/utils.js.map +1 -0
  15. package/dist/cjs/types/arkos-prisma-input.js.map +1 -1
  16. package/dist/cjs/types/arkos.js +3 -0
  17. package/dist/cjs/types/arkos.js.map +1 -0
  18. package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +152 -0
  19. package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -0
  20. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
  21. package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +208 -0
  22. package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
  23. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js +143 -39
  24. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
  25. package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js +51 -0
  26. package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -0
  27. package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js +169 -0
  28. package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
  29. package/dist/cjs/utils/features/api.features.js +0 -3
  30. package/dist/cjs/utils/features/api.features.js.map +1 -1
  31. package/dist/cjs/utils/helpers/api.features.helpers.js +20 -0
  32. package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
  33. package/dist/cjs/utils/helpers/exit-error.js +12 -0
  34. package/dist/cjs/utils/helpers/exit-error.js.map +1 -0
  35. package/dist/cjs/utils/helpers/prisma.helpers.js +1 -2
  36. package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
  37. package/dist/cjs/utils/initialize-app.js +52 -0
  38. package/dist/cjs/utils/initialize-app.js.map +1 -0
  39. package/dist/cjs/utils/setup-app.js +119 -0
  40. package/dist/cjs/utils/setup-app.js.map +1 -0
  41. package/dist/esm/components/arkos-policy/index.js +32 -0
  42. package/dist/esm/components/arkos-policy/index.js.map +1 -0
  43. package/dist/esm/components/arkos-policy/types.js +2 -0
  44. package/dist/esm/components/arkos-policy/types.js.map +1 -0
  45. package/dist/esm/exports/config.js +3 -0
  46. package/dist/esm/exports/config.js.map +1 -0
  47. package/dist/esm/modules/auth/auth.service.js +1 -1
  48. package/dist/esm/modules/auth/auth.service.js.map +1 -1
  49. package/dist/esm/modules/error-handler/error-handler.controller.js +1 -1
  50. package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
  51. package/dist/esm/modules/swagger/utils/get-open-api-login-html.js +285 -0
  52. package/dist/esm/modules/swagger/utils/get-open-api-login-html.js.map +1 -0
  53. package/dist/esm/types/arkos-config/utils.js +2 -0
  54. package/dist/esm/types/arkos-config/utils.js.map +1 -0
  55. package/dist/esm/types/arkos-prisma-input.js.map +1 -1
  56. package/dist/esm/types/arkos.js +2 -0
  57. package/dist/esm/types/arkos.js.map +1 -0
  58. package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +146 -0
  59. package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -0
  60. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
  61. package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +208 -0
  62. package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
  63. package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js +143 -39
  64. package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
  65. package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js +45 -0
  66. package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -0
  67. package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js +169 -0
  68. package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
  69. package/dist/esm/utils/features/api.features.js +0 -3
  70. package/dist/esm/utils/features/api.features.js.map +1 -1
  71. package/dist/esm/utils/helpers/api.features.helpers.js +20 -0
  72. package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
  73. package/dist/esm/utils/helpers/exit-error.js +6 -0
  74. package/dist/esm/utils/helpers/exit-error.js.map +1 -0
  75. package/dist/esm/utils/helpers/prisma.helpers.js +1 -2
  76. package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
  77. package/dist/esm/utils/initialize-app.js +45 -0
  78. package/dist/esm/utils/initialize-app.js.map +1 -0
  79. package/dist/esm/utils/setup-app.js +113 -0
  80. package/dist/esm/utils/setup-app.js.map +1 -0
  81. package/dist/types/components/arkos-policy/index.d.ts +31 -0
  82. package/dist/types/components/arkos-policy/types.d.ts +21 -0
  83. package/dist/types/exports/config.d.ts +2 -0
  84. package/dist/types/modules/swagger/utils/get-open-api-login-html.d.ts +1 -0
  85. package/dist/types/types/arkos-config/utils.d.ts +68 -0
  86. package/dist/types/types/arkos-prisma-input.d.ts +1 -1
  87. package/dist/types/types/arkos.d.ts +31 -0
  88. package/dist/types/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.d.ts +7 -0
  89. package/dist/types/utils/cli/utils/template-generator/templates/class-validator-dto-generator.d.ts +4 -0
  90. package/dist/types/utils/cli/utils/template-generator/templates/policy-template.d.ts +2 -0
  91. package/dist/types/utils/cli/utils/template-generator/templates/zod-schema-generator.d.ts +4 -0
  92. package/dist/types/utils/helpers/exit-error.d.ts +1 -0
  93. package/dist/types/utils/initialize-app.d.ts +3 -0
  94. package/dist/types/utils/setup-app.d.ts +2 -0
  95. package/package.json +55 -55
  96. package/dist/cjs/types/arkos-prisma-input.bak.js.map +0 -1
  97. package/dist/esm/types/arkos-prisma-input.bak.js +0 -2
  98. package/dist/esm/types/arkos-prisma-input.bak.js.map +0 -1
  99. package/dist/types/types/arkos-prisma-input.bak.d.ts +0 -237
@@ -49,8 +49,8 @@ export default function errorHandler(err, req, res, _) {
49
49
  error = errorControllerHelper.handleVersionMismatchError(err);
50
50
  if (process.env.ARKOS_BUILD !== "true")
51
51
  return sendDevelopmentError({
52
- ...error,
53
52
  message: error.message,
53
+ ...error,
54
54
  stack: err.stack,
55
55
  originalError: err,
56
56
  }, req, res);
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,CAAe;IAEf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MA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AE,EAAE;aACT,CAAC,CAAC;QAEL,OAAO;IACT,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC9B,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,gDAAgD;KAC1D,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} _ - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n _: NextFunction\n): void {\n console.error(\"[\\x1b[31mError\\x1b[0m]:\", err);\n\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n let error: any = {\n ...err,\n message: err.message,\n stack: err?.stack || undefined,\n };\n\n if (process.env.ARKOS_BUILD === \"true\") delete error?.stack;\n\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n if (err.name === \"PrismaClientInitializationError\")\n error = errorControllerHelper.handlePrismaClientInitializationError(err);\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P2025\")\n error = errorControllerHelper.handleNonExistingRecord(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (process.env.ARKOS_BUILD !== \"true\")\n return sendDevelopmentError(\n {\n ...error,\n message: error.message,\n stack: err.stack,\n originalError: err,\n },\n req,\n res\n );\n\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(err: any, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message:\n err.message?.split?.(\"\\n\")[err.message?.split?.(\"\\n\").length - 1],\n stack: err?.originalError?.stack?.split?.(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"Unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Internal server error, please try again later.\",\n code: \"Unknown\",\n meta: {},\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: err.message,\n code: \"Unknown\",\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: \"Internal server error, please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (process.env.ARKOS_BUILD !== \"true\") {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
1
+ {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,CAAe;IAEf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAEnC,IAAI,KAAK,GAAQ;QACf,GAAG,GAAG;QACN,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,SAAS;KAC/B,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM;QAAE,OAAO,KAAK,EAAE,KAAK,CAAC;IAE5D,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;IACjD,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IAEnD,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B;QAC5C,KAAK,GAAG,qBAAqB,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC;IACvE,IAAI,GAAG,CAAC,IAAI,KAAK,iCAAiC;QAChD,KAAK,GAAG,q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,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} _ - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n _: NextFunction\n): void {\n console.error(\"[\\x1b[31mError\\x1b[0m]:\", err);\n\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n let error: any = {\n ...err,\n message: err.message,\n stack: err?.stack || undefined,\n };\n\n if (process.env.ARKOS_BUILD === \"true\") delete error?.stack;\n\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n if (err.name === \"PrismaClientInitializationError\")\n error = errorControllerHelper.handlePrismaClientInitializationError(err);\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P2025\")\n error = errorControllerHelper.handleNonExistingRecord(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (process.env.ARKOS_BUILD !== \"true\")\n return sendDevelopmentError(\n {\n message: error.message,\n ...error,\n stack: err.stack,\n originalError: err,\n },\n req,\n res\n );\n\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(err: any, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message:\n err.message?.split?.(\"\\n\")[err.message?.split?.(\"\\n\").length - 1],\n stack: err?.originalError?.stack?.split?.(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"Unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Internal server error, please try again later.\",\n code: \"Unknown\",\n meta: {},\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: err.message,\n code: \"Unknown\",\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: \"Internal server error, please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (process.env.ARKOS_BUILD !== \"true\") {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
@@ -0,0 +1,285 @@
1
+ import { getArkosConfig } from "../../../server.js";
2
+ function formatFieldLabel(field) {
3
+ const last = field.split(".").pop();
4
+ return last
5
+ .replace(/([A-Z])/g, " $1")
6
+ .replace(/^./, (c) => c.toUpperCase())
7
+ .trim();
8
+ }
9
+ export default function getOpenApiLoginHtml() {
10
+ const arkosConfig = getArkosConfig();
11
+ const theme = arkosConfig?.swagger?.scalarApiReferenceConfiguration?.theme || "default";
12
+ const allowedUsernames = arkosConfig?.authentication?.login?.allowedUsernames
13
+ ?.length
14
+ ? arkosConfig.authentication.login.allowedUsernames
15
+ : ["username"];
16
+ const themeColors = {
17
+ default: { bg: "#0f0f0f", surface: "#1a1a1a", border: "#2e2e2e" },
18
+ moon: { bg: "#0f1117", surface: "#1c1e26", border: "#2e3040" },
19
+ purple: { bg: "#0d0d14", surface: "#1a1a2e", border: "#2e2e4a" },
20
+ solarized: { bg: "#002b36", surface: "#073642", border: "#124652" },
21
+ bluePlanet: { bg: "#070b14", surface: "#0d1424", border: "#1a2540" },
22
+ saturn: { bg: "#0a0a0f", surface: "#16161f", border: "#28283a" },
23
+ kepler: { bg: "#0a0f0a", surface: "#141f14", border: "#253525" },
24
+ mars: { bg: "#0f0a08", surface: "#1f1410", border: "#352520" },
25
+ deepSpace: { bg: "#0a0a0a", surface: "#121212", border: "#3a3a3a" },
26
+ };
27
+ const colors = themeColors[theme] ?? themeColors["default"];
28
+ const firstLabel = formatFieldLabel(allowedUsernames[0]);
29
+ const showSelect = allowedUsernames.length > 1;
30
+ const title = arkosConfig?.swagger?.options?.definition?.info?.title ||
31
+ "Arkos.js OpenAPI Documentation";
32
+ return `<!DOCTYPE html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="UTF-8">
36
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
37
+ <title>${title}</title>
38
+ <style>
39
+ * { margin: 0; padding: 0; box-sizing: border-box; }
40
+
41
+ body {
42
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
43
+ min-height: 100vh;
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
+ background-color: ${colors.bg};
48
+ padding: 8px;
49
+ }
50
+
51
+ .login-container {
52
+ background-color: ${colors.surface};
53
+ padding: 40px;
54
+ border: 1px solid ${colors.border};
55
+ border-radius: 8px;
56
+ width: 100%;
57
+ max-width: 400px;
58
+ }
59
+
60
+ h1 {
61
+ color: #ffffff;
62
+ text-align: center;
63
+ margin-bottom: 30px;
64
+ font-size: 24px;
65
+ font-weight: 600;
66
+ }
67
+
68
+ h2 {
69
+ color: #ffffff;
70
+ text-align: center;
71
+ margin-bottom: 20px;
72
+ font-size: 16px;
73
+ font-weight: 500;
74
+ }
75
+
76
+ .form-group {
77
+ margin-bottom: 20px;
78
+ }
79
+
80
+ label {
81
+ display: block;
82
+ color: #ffffff;
83
+ margin-bottom: 8px;
84
+ font-size: 14px;
85
+ font-weight: 500;
86
+ }
87
+
88
+ input[type="text"],
89
+ input[type="password"] {
90
+ width: 100%;
91
+ padding: 12px 16px;
92
+ background-color: ${colors.bg};
93
+ border: 1px solid ${colors.border};
94
+ border-radius: 4px;
95
+ color: #ffffff;
96
+ font-size: 14px;
97
+ transition: border-color 0.3s;
98
+ }
99
+
100
+ select {
101
+ width: 100%;
102
+ padding: 12px 16px;
103
+ background-color: ${colors.bg};
104
+ border: 1px solid ${colors.border};
105
+ border-radius: 4px;
106
+ color: #ffffff;
107
+ font-size: 14px;
108
+ transition: border-color 0.3s;
109
+ appearance: none;
110
+ -webkit-appearance: none;
111
+ -moz-appearance: none;
112
+ cursor: pointer;
113
+ /* custom arrow */
114
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
115
+ background-repeat: no-repeat;
116
+ background-position: right 16px center;
117
+ }
118
+
119
+ input[type="text"]:focus,
120
+ input[type="password"]:focus,
121
+ select:focus {
122
+ outline: none;
123
+ border-color: #ffffff;
124
+ }
125
+
126
+ input[type="text"]::placeholder,
127
+ input[type="password"]::placeholder {
128
+ color: #666666;
129
+ }
130
+
131
+ select option {
132
+ background-color: ${colors.surface};
133
+ color: #ffffff;
134
+ }
135
+
136
+ .login-button {
137
+ width: 100%;
138
+ padding: 12px;
139
+ background-color: #ffffff;
140
+ color: #1a1a1a;
141
+ border: none;
142
+ border-radius: 4px;
143
+ font-size: 16px;
144
+ font-weight: 600;
145
+ cursor: pointer;
146
+ transition: background-color 0.3s;
147
+ }
148
+
149
+ .login-button:hover { background-color: #e0e0e0; }
150
+ .login-button:active { transform: translateY(1px); }
151
+ .login-button:disabled { background-color: #666666; cursor: not-allowed; }
152
+
153
+ .error-message {
154
+ color: #ff6b6b;
155
+ font-size: 14px;
156
+ margin-top: 10px;
157
+ text-align: center;
158
+ display: none;
159
+ }
160
+
161
+ .error-message.show { display: block; }
162
+ </style>
163
+ </head>
164
+ <body>
165
+ <div class="login-container">
166
+ <h1>${title}</h1>
167
+ <h2>Login</h2>
168
+ <form id="loginForm">
169
+
170
+ ${showSelect
171
+ ? `
172
+ <div class="form-group">
173
+ <label for="usernameSelect">Login With</label>
174
+ <select id="usernameSelect">
175
+ ${allowedUsernames
176
+ .map((f) => `
177
+ <option value="${f}">${formatFieldLabel(f)}</option>
178
+ `)
179
+ .join("")}
180
+ </select>
181
+ </div>
182
+ `
183
+ : ""}
184
+
185
+ <div class="form-group">
186
+ <label id="usernameLabel" for="usernameField">${firstLabel}</label>
187
+ <input
188
+ type="text"
189
+ id="usernameField"
190
+ placeholder="Enter your ${firstLabel.toLowerCase()}"
191
+ required
192
+ >
193
+ </div>
194
+
195
+ <div class="form-group">
196
+ <label for="password">Password</label>
197
+ <input
198
+ type="password"
199
+ id="password"
200
+ placeholder="Enter your password"
201
+ required
202
+ >
203
+ </div>
204
+
205
+ <button type="submit" class="login-button" id="loginButton">Login</button>
206
+ <div class="error-message" id="errorMessage"></div>
207
+
208
+ </form>
209
+ </div>
210
+
211
+ <script>
212
+ const usernameLabel = document.getElementById('usernameLabel');
213
+ const usernameField = document.getElementById('usernameField');
214
+ const usernameSelect = document.getElementById('usernameSelect');
215
+ const loginButton = document.getElementById('loginButton');
216
+ const errorMessage = document.getElementById('errorMessage');
217
+
218
+ function formatFieldLabel(field) {
219
+ const last = field.split('.').pop();
220
+ return last
221
+ .replace(/([A-Z])/g, ' $1')
222
+ .replace(/^./, c => c.toUpperCase())
223
+ .trim();
224
+ }
225
+
226
+ if (usernameSelect) {
227
+ usernameSelect.addEventListener('change', () => {
228
+ const label = formatFieldLabel(usernameSelect.value);
229
+ usernameLabel.textContent = label;
230
+ usernameField.placeholder = \`Enter your \${label.toLowerCase()}\`;
231
+ });
232
+ }
233
+
234
+ const params = new URLSearchParams(window.location.search);
235
+ const urlErrorMessage = params.get('error-message');
236
+ if (urlErrorMessage) {
237
+ errorMessage.textContent = decodeURIComponent(urlErrorMessage);
238
+ errorMessage.classList.add('show');
239
+ }
240
+
241
+ document.getElementById('loginForm').addEventListener('submit', async (e) => {
242
+ e.preventDefault();
243
+
244
+ const selectedField = usernameSelect ? usernameSelect.value : '${allowedUsernames[0]}';
245
+ const password = document.getElementById('password').value;
246
+
247
+ errorMessage.classList.remove('show');
248
+ errorMessage.textContent = '';
249
+ loginButton.disabled = true;
250
+ loginButton.textContent = '...';
251
+
252
+ try {
253
+ const selectedField = usernameSelect ? usernameSelect.value : '${allowedUsernames[0]}';
254
+ const fieldKey = selectedField.split('.').pop(); // last segment only as body key
255
+
256
+ const response = await fetch(\`/api/auth/login?usernameField=\${selectedField}\`, {
257
+ method: 'POST',
258
+ headers: { 'Content-Type': 'application/json' },
259
+ body: JSON.stringify({
260
+ [fieldKey]: usernameField.value,
261
+ password,
262
+ }),
263
+ });
264
+
265
+ const data = await response.json();
266
+
267
+ if (response.ok) {
268
+ window.location.href = '/api/docs';
269
+ } else {
270
+ errorMessage.textContent = data.message || 'Login failed';
271
+ errorMessage.classList.add('show');
272
+ }
273
+ } catch {
274
+ errorMessage.textContent = 'An error occurred. Please try again.';
275
+ errorMessage.classList.add('show');
276
+ } finally {
277
+ loginButton.disabled = false;
278
+ loginButton.textContent = 'Login';
279
+ }
280
+ });
281
+ </script>
282
+ </body>
283
+ </html>`;
284
+ }
285
+ //# sourceMappingURL=get-open-api-login-html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-open-api-login-html.js","sourceRoot":"","sources":["../../../../../src/modules/swagger/utils/get-open-api-login-html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,SAAS,gBAAgB,CAAC,KAAa;IACrC,MAAM,I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DAGkD,UAAU;;;;oCAI9B,UAAU,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uEAsDW,gBAAgB,CAAC,CAAC,CAAC;;;;;;;;;yEASjB,gBAAgB,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA8BpF,CAAC;AACT,CAAC","sourcesContent":["import { getArkosConfig } from \"../../../server\";\n\nfunction formatFieldLabel(field: string): string {\n const last = field.split(\".\").pop()!;\n return last\n .replace(/([A-Z])/g, \" $1\")\n .replace(/^./, (c) => c.toUpperCase())\n .trim();\n}\n\nexport default function getOpenApiLoginHtml() {\n const arkosConfig = getArkosConfig();\n\n const theme =\n arkosConfig?.swagger?.scalarApiReferenceConfiguration?.theme || \"default\";\n\n const allowedUsernames = arkosConfig?.authentication?.login?.allowedUsernames\n ?.length\n ? arkosConfig.authentication.login.allowedUsernames\n : [\"username\"];\n\n const themeColors: Record<\n string,\n { bg: string; surface: string; border: string }\n > = {\n default: { bg: \"#0f0f0f\", surface: \"#1a1a1a\", border: \"#2e2e2e\" },\n moon: { bg: \"#0f1117\", surface: \"#1c1e26\", border: \"#2e3040\" },\n purple: { bg: \"#0d0d14\", surface: \"#1a1a2e\", border: \"#2e2e4a\" },\n solarized: { bg: \"#002b36\", surface: \"#073642\", border: \"#124652\" },\n bluePlanet: { bg: \"#070b14\", surface: \"#0d1424\", border: \"#1a2540\" },\n saturn: { bg: \"#0a0a0f\", surface: \"#16161f\", border: \"#28283a\" },\n kepler: { bg: \"#0a0f0a\", surface: \"#141f14\", border: \"#253525\" },\n mars: { bg: \"#0f0a08\", surface: \"#1f1410\", border: \"#352520\" },\n deepSpace: { bg: \"#0a0a0a\", surface: \"#121212\", border: \"#3a3a3a\" },\n };\n\n const colors = themeColors[theme] ?? themeColors[\"default\"];\n\n const firstLabel = formatFieldLabel(allowedUsernames[0]);\n const showSelect = allowedUsernames.length > 1;\n const title =\n arkosConfig?.swagger?.options?.definition?.info?.title ||\n \"Arkos.js OpenAPI Documentation\";\n\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${title}</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n background-color: ${colors.bg};\n padding: 8px;\n }\n\n .login-container {\n background-color: ${colors.surface};\n padding: 40px;\n border: 1px solid ${colors.border};\n border-radius: 8px;\n width: 100%;\n max-width: 400px;\n }\n\n h1 {\n color: #ffffff;\n text-align: center;\n margin-bottom: 30px;\n font-size: 24px;\n font-weight: 600;\n }\n\n h2 {\n color: #ffffff;\n text-align: center;\n margin-bottom: 20px;\n font-size: 16px;\n font-weight: 500;\n }\n\n .form-group {\n margin-bottom: 20px;\n }\n\n label {\n display: block;\n color: #ffffff;\n margin-bottom: 8px;\n font-size: 14px;\n font-weight: 500;\n }\n\n input[type=\"text\"],\n input[type=\"password\"] {\n width: 100%;\n padding: 12px 16px;\n background-color: ${colors.bg};\n border: 1px solid ${colors.border};\n border-radius: 4px;\n color: #ffffff;\n font-size: 14px;\n transition: border-color 0.3s;\n }\n\n select {\n width: 100%;\n padding: 12px 16px;\n background-color: ${colors.bg};\n border: 1px solid ${colors.border};\n border-radius: 4px;\n color: #ffffff;\n font-size: 14px;\n transition: border-color 0.3s;\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n cursor: pointer;\n /* custom arrow */\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E\");\n background-repeat: no-repeat;\n background-position: right 16px center;\n }\n\n input[type=\"text\"]:focus,\n input[type=\"password\"]:focus,\n select:focus {\n outline: none;\n border-color: #ffffff;\n }\n\n input[type=\"text\"]::placeholder,\n input[type=\"password\"]::placeholder {\n color: #666666;\n }\n\n select option {\n background-color: ${colors.surface};\n color: #ffffff;\n }\n\n .login-button {\n width: 100%;\n padding: 12px;\n background-color: #ffffff;\n color: #1a1a1a;\n border: none;\n border-radius: 4px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: background-color 0.3s;\n }\n\n .login-button:hover { background-color: #e0e0e0; }\n .login-button:active { transform: translateY(1px); }\n .login-button:disabled { background-color: #666666; cursor: not-allowed; }\n\n .error-message {\n color: #ff6b6b;\n font-size: 14px;\n margin-top: 10px;\n text-align: center;\n display: none;\n }\n\n .error-message.show { display: block; }\n </style>\n</head>\n<body>\n <div class=\"login-container\">\n <h1>${title}</h1>\n <h2>Login</h2>\n <form id=\"loginForm\">\n\n ${\n showSelect\n ? `\n <div class=\"form-group\">\n <label for=\"usernameSelect\">Login With</label>\n <select id=\"usernameSelect\">\n ${allowedUsernames\n .map(\n (f) => `\n <option value=\"${f}\">${formatFieldLabel(f)}</option>\n `\n )\n .join(\"\")}\n </select>\n </div>\n `\n : \"\"\n }\n\n <div class=\"form-group\">\n <label id=\"usernameLabel\" for=\"usernameField\">${firstLabel}</label>\n <input\n type=\"text\"\n id=\"usernameField\"\n placeholder=\"Enter your ${firstLabel.toLowerCase()}\"\n required\n >\n </div>\n\n <div class=\"form-group\">\n <label for=\"password\">Password</label>\n <input\n type=\"password\"\n id=\"password\"\n placeholder=\"Enter your password\"\n required\n >\n </div>\n\n <button type=\"submit\" class=\"login-button\" id=\"loginButton\">Login</button>\n <div class=\"error-message\" id=\"errorMessage\"></div>\n\n </form>\n </div>\n\n <script>\n const usernameLabel = document.getElementById('usernameLabel');\n const usernameField = document.getElementById('usernameField');\n const usernameSelect = document.getElementById('usernameSelect');\n const loginButton = document.getElementById('loginButton');\n const errorMessage = document.getElementById('errorMessage');\n\n function formatFieldLabel(field) {\n const last = field.split('.').pop();\n return last\n .replace(/([A-Z])/g, ' $1')\n .replace(/^./, c => c.toUpperCase())\n .trim();\n }\n\n if (usernameSelect) {\n usernameSelect.addEventListener('change', () => {\n const label = formatFieldLabel(usernameSelect.value);\n usernameLabel.textContent = label;\n usernameField.placeholder = \\`Enter your \\${label.toLowerCase()}\\`;\n });\n }\n\n const params = new URLSearchParams(window.location.search);\n const urlErrorMessage = params.get('error-message');\n if (urlErrorMessage) {\n errorMessage.textContent = decodeURIComponent(urlErrorMessage);\n errorMessage.classList.add('show');\n }\n\n document.getElementById('loginForm').addEventListener('submit', async (e) => {\n e.preventDefault();\n\n const selectedField = usernameSelect ? usernameSelect.value : '${allowedUsernames[0]}';\n const password = document.getElementById('password').value;\n\n errorMessage.classList.remove('show');\n errorMessage.textContent = '';\n loginButton.disabled = true;\n loginButton.textContent = '...';\n\n try {\n const selectedField = usernameSelect ? usernameSelect.value : '${allowedUsernames[0]}';\n const fieldKey = selectedField.split('.').pop(); // last segment only as body key\n\n const response = await fetch(\\`/api/auth/login?usernameField=\\${selectedField}\\`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n [fieldKey]: usernameField.value,\n password,\n }),\n });\n\n const data = await response.json();\n\n if (response.ok) {\n window.location.href = '/api/docs';\n } else {\n errorMessage.textContent = data.message || 'Login failed';\n errorMessage.classList.add('show');\n }\n } catch {\n errorMessage.textContent = 'An error occurred. Please try again.';\n errorMessage.classList.add('show');\n } finally {\n loginButton.disabled = false;\n loginButton.textContent = 'Login';\n }\n });\n </script>\n</body>\n</html>`;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/types/arkos-config/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ArkosRequest } from \"..\";\nimport { AccessAction, DetailedAccessControlRule } from \"../auth\";\n\n/** Context passed to `before` hooks of `authenticate`. */\nexport interface AuthenticateBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authenticate`. */\nexport interface AuthenticateAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n}\n\n/** Context passed to `onError` hooks of `authenticate`. */\nexport interface AuthenticateErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authentication. */\n error: unknown;\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthenticateHookHandler = (\n ctx: AuthenticateBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateAfterHookHandler = (\n ctx: AuthenticateAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateErrorHookHandler = (\n ctx: AuthenticateErrorHookContext\n) => void | Promise<void>;\n\n/** Context passed to `before` hooks of `authorize`. */\nexport interface AuthorizeBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authorize`. */\nexport interface AuthorizeAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action that was authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource that was accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule that was applied. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n}\n\n/** Context passed to `onError` hooks of `authorize`. */\nexport interface AuthorizeErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authorization. */\n error: unknown;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthorizeHookHandler = (\n ctx: AuthorizeBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeAfterHookHandler = (\n ctx: AuthorizeAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeErrorHookHandler = (\n ctx: AuthorizeErrorHookContext\n) => void | Promise<void>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"arkos-prisma-input.js","sourceRoot":"","sources":["../../../src/types/arkos-prisma-input.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Helper type to exclude properties from T that exist in U\n * Used internally by XOR to create mutually exclusive types\n */\ntype Without<T, U> = {\n [P in Exclude<keyof T, keyof U>]?: never;\n};\n/**\n * XOR (Exclusive OR) type for mutually exclusive union types\n * Ensures that properties from T and U cannot be mixed together\n * @see https://stackoverflow.com/questions/42123407/does-typescript-support-mutually-exclusive-types\n */\ntype XOR<T, U> = T extends object\n ? U extends object\n ? (Without<T, U> & U) | (Without<U, T> & T)\n : U\n : T;\ntype Unpack<T> = T;\n/**\n * Checks if a field is an array relation (one-to-many or many-to-many)\n * Identified by the presence of createMany property\n */\nexport type IsArrayRelation<T> =\n Exclude<T, undefined> extends never\n ? false\n : Exclude<T, undefined> extends { createMany?: any }\n ? true\n : false;\n/**\n * Checks if a field is an object relation (one-to-one or many-to-one)\n * Identified by the presence of relation operations without being an array\n */\nexport type IsObjectRelation<T> =\n Exclude<T, undefined> extends Array<any>\n ? false\n : Exclude<T, undefined> extends\n | {\n create?: any;\n }\n | {\n connect?: any;\n }\n | {\n connectOrCreate?: any;\n }\n | {\n update?: any;\n }\n | {\n delete?: any;\n }\n | {\n disconnect?: any;\n }\n ? true\n : false;\ntype ExtractCreateTypeArray<T> =\n Exclude<T, undefined> extends {\n create?: infer C;\n }\n ? Extract<C, Array<any>> extends Array<infer U>\n ? U extends Array<infer I>\n ? (Omit<I, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n })[]\n : (Omit<U, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n })[]\n : never\n : never;\ntype ExtractConnectTypeArray<\n T,\n A extends\n | \"connect\"\n | \"delete\"\n | \"update\"\n | \"disconnect\"\n | \"deleteMany\"\n | \"set\",\n> =\n Exclude<T, undefined> extends {\n [k in A]?: infer C;\n }\n ? Extract<C, Array<any>> extends Array<infer U>\n ? (Omit<U, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: A;\n })[]\n : never\n : never;\ntype ExtractUpdateTypeArray<T> =\n Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n update?: infer U;\n }\n ? U extends Array<infer UpdateItem>\n ? UpdateItem extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & {\n apiAction?: \"update\";\n })[]\n : never\n : U extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & {\n apiAction?: \"update\";\n })[]\n : never\n : never\n : never;\ntype ExtractCreateTypeObject<T> =\n Exclude<T, undefined> extends {\n create?: infer C;\n }\n ? Exclude<\n Extract<Exclude<C, undefined>, object>,\n Array<any>\n > extends infer Obj\n ? Obj extends object\n ? Omit<Obj, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n }\n : never\n : never\n : never;\ntype ExtractConnectTypeObject<\n T,\n A extends \"connect\" | \"delete\" | \"update\" | \"disconnect\",\n> =\n Exclude<T, undefined> extends {\n [k in A]?: infer C;\n }\n ? Exclude<\n Extract<Exclude<C, undefined>, object>,\n Array<any>\n > extends infer Obj\n ? Obj extends object\n ? Omit<Obj, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: A;\n }\n : never\n : never\n : never;\ntype ExtractUpdateTypeObject<T> =\n Exclude<T, undefined> extends {\n update?: infer U;\n }\n ? U extends {\n where: infer W;\n data: infer D;\n }\n ? (W & D) & {\n apiAction?: \"update\";\n }\n : Exclude<Extract<U, object>, Array<any>> & {\n apiAction?: \"update\";\n }\n : never;\ntype FlattenArrayRelation<T> =\n | (ExtractCreateTypeArray<T> extends never\n ? never\n : FlattenRelations<ExtractCreateTypeArray<T>>)\n | (ExtractConnectTypeArray<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectTypeArray<T, \"connect\">>)\n | (ExtractUpdateTypeArray<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateTypeArray<T>>)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n delete?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"delete\">> & {\n apiAction: \"delete\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n disconnect?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"disconnect\">> & {\n apiAction: \"disconnect\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n deleteMany?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"deleteMany\">> & {\n apiAction: \"deleteMany\";\n }\n : never\n : never);\ntype FlattenObjectRelation<T> =\n | (ExtractCreateTypeObject<T> extends never\n ? never\n : FlattenRelations<ExtractCreateTypeObject<T>>)\n | (ExtractConnectTypeObject<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectTypeObject<T, \"connect\">>)\n | (ExtractUpdateTypeObject<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateTypeObject<T>>)\n | (Exclude<T, undefined> extends {\n delete?: any;\n }\n ? FlattenRelations<ExtractConnectTypeObject<T, \"delete\">> & {\n apiAction: \"delete\";\n }\n : never)\n | (Exclude<T, undefined> extends {\n disconnect?: any;\n }\n ? FlattenRelations<ExtractConnectTypeObject<T, \"disconnect\">> & {\n apiAction: \"disconnect\";\n }\n : never)\n | (Exclude<T, undefined> extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never);\ntype StripPrismaFilters<T> = T extends\n | {\n equals?: any;\n }\n | {\n in?: any;\n }\n | {\n notIn?: any;\n }\n | {\n lt?: any;\n }\n | {\n lte?: any;\n }\n | {\n gt?: any;\n }\n | {\n gte?: any;\n }\n | {\n AND?: any;\n }\n | {\n OR?: any;\n }\n | {\n NOT?: any;\n }\n ? never\n : T;\ntype FlattenRelations<T> = {\n [K in keyof T]: IsArrayRelation<T[K]> extends true\n ? FlattenArrayRelation<T[K]>\n : IsObjectRelation<T[K]> extends true\n ? XOR<FlattenObjectRelation<T[K]>, T[K]>\n : StripPrismaFilters<T[K]> extends never\n ? never\n : T[K] extends object\n ? T[K] extends Date | null | undefined\n ? T[K]\n : FlattenRelations<StripPrismaFilters<T[K]>>\n : StripPrismaFilters<T[K]>;\n};\n/**\n * Flattens Prisma relation inputs into a simpler, developer-friendly format\n *\n * Transforms Prisma's nested relation format:\n * ```typescript\n * { posts: { create: [...], connect: [...], update: [...] } }\n * ```\n *\n * Into a flattened format with optional apiAction discriminators:\n * ```typescript\n * { posts: [\n * { title: \"New Post\" }, // auto-detected as create\n * { id: 1 }, // auto-detected as connect\n * { id: 2, title: \"Updated\", apiAction: \"update\" }\n * ]}\n * ```\n *\n * @see {@link https://wwww.arkosjs.com/docs/api-reference/arkos-prisma-input}\n * @template T - The Prisma input type (e.g., Prisma.UserCreateInput)\n * @returns A flattened version of the input type with simplified relation handling\n */\nexport type ArkosPrismaInput<T> = FlattenRelations<T>;\n"]}
1
+ {"version":3,"file":"arkos-prisma-input.js","sourceRoot":"","sources":["../../../src/types/arkos-prisma-input.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Helper type to exclude properties from T that exist in U\n * Used internally by XOR to create mutually exclusive types\n */\ntype Without<T, U> = {\n [P in Exclude<keyof T, keyof U>]?: never;\n};\n/**\n * XOR (Exclusive OR) type for mutually exclusive union types\n * Ensures that properties from T and U cannot be mixed together\n * @see https://stackoverflow.com/questions/42123407/does-typescript-support-mutually-exclusive-types\n */\ntype XOR<T, U> = T extends object\n ? U extends object\n ? (Without<T, U> & U) | (Without<U, T> & T)\n : U\n : T;\ntype Unpack<T> = T;\n/**\n * Checks if a field is an array relation (one-to-many or many-to-many)\n * Identified by the presence of createMany property\n */\nexport type IsArrayRelation<T> =\n Exclude<T, undefined> extends never\n ? false\n : Exclude<T, undefined> extends { createMany?: any }\n ? true\n : false;\n/**\n * Checks if a field is an object relation (one-to-one or many-to-one)\n * Identified by the presence of relation operations without being an array\n */\nexport type IsObjectRelation<T> =\n Exclude<T, undefined> extends Array<any>\n ? false\n : Exclude<T, undefined> extends\n | {\n create?: any;\n }\n | {\n connect?: any;\n }\n | {\n connectOrCreate?: any;\n }\n | {\n update?: any;\n }\n | {\n delete?: any;\n }\n | {\n disconnect?: any;\n }\n ? true\n : false;\ntype ExtractCreateTypeArray<T> =\n Exclude<T, undefined> extends {\n create?: infer C;\n }\n ? Extract<C, Array<any>> extends Array<infer U>\n ? U extends Array<infer I>\n ? (Omit<I, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n })[]\n : (Omit<U, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n })[]\n : never\n : never;\ntype ExtractConnectTypeArray<\n T,\n A extends\n | \"connect\"\n | \"delete\"\n | \"update\"\n | \"disconnect\"\n | \"deleteMany\"\n | \"set\",\n> =\n Exclude<T, undefined> extends {\n [k in A]?: infer C;\n }\n ? Extract<C, Array<any>> extends Array<infer U>\n ? (Omit<U, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: A;\n })[]\n : never\n : never;\ntype ExtractUpdateTypeArray<T> =\n Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n update?: infer U;\n }\n ? U extends Array<infer UpdateItem>\n ? UpdateItem extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & {\n apiAction?: \"update\";\n })[]\n : never\n : U extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & {\n apiAction?: \"update\";\n })[]\n : never\n : never\n : never;\ntype ExtractCreateTypeObject<T> =\n Exclude<T, undefined> extends {\n create?: infer C;\n }\n ? Exclude<\n Extract<Exclude<C, undefined>, object>,\n Array<any>\n > extends infer Obj\n ? Obj extends object\n ? Omit<Obj, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: \"create\";\n }\n : never\n : never\n : never;\ntype ExtractConnectTypeObject<\n T,\n A extends \"connect\" | \"delete\" | \"update\" | \"disconnect\",\n> =\n Exclude<T, undefined> extends {\n [k in A]?: infer C;\n }\n ? Exclude<\n Extract<Exclude<C, undefined>, object>,\n Array<any>\n > extends infer Obj\n ? Obj extends object\n ? Omit<Obj, \"OR\" | \"AND\" | \"NOT\"> & {\n apiAction?: A;\n }\n : never\n : never\n : never;\ntype ExtractUpdateTypeObject<T> =\n Exclude<T, undefined> extends {\n update?: infer U;\n }\n ? U extends {\n where: infer W;\n data: infer D;\n }\n ? (W & D) & {\n apiAction?: \"update\";\n }\n : Exclude<Extract<U, object>, Array<any>> & {\n apiAction?: \"update\";\n }\n : never;\ntype FlattenArrayRelation<T> =\n | (ExtractCreateTypeArray<T> extends never\n ? never\n : FlattenRelations<ExtractCreateTypeArray<T>>)\n | (ExtractConnectTypeArray<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectTypeArray<T, \"connect\">>)\n | (ExtractUpdateTypeArray<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateTypeArray<T>>)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n delete?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"delete\">> & {\n apiAction: \"delete\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n disconnect?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"disconnect\">> & {\n apiAction: \"disconnect\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never\n : never)\n | (Exclude<T, undefined> extends Array<infer Item>\n ? Item extends {\n deleteMany?: any;\n }\n ? FlattenRelations<ExtractConnectTypeArray<T, \"deleteMany\">> & {\n apiAction: \"deleteMany\";\n }\n : never\n : never);\ntype FlattenObjectRelation<T> =\n | (ExtractCreateTypeObject<T> extends never\n ? never\n : FlattenRelations<ExtractCreateTypeObject<T>>)\n | (ExtractConnectTypeObject<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectTypeObject<T, \"connect\">>)\n | (ExtractUpdateTypeObject<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateTypeObject<T>>)\n | (Exclude<T, undefined> extends {\n delete?: any;\n }\n ? FlattenRelations<ExtractConnectTypeObject<T, \"delete\">> & {\n apiAction: \"delete\";\n }\n : never)\n | (Exclude<T, undefined> extends {\n disconnect?: any;\n }\n ? FlattenRelations<ExtractConnectTypeObject<T, \"disconnect\">> & {\n apiAction: \"disconnect\";\n }\n : never)\n | (Exclude<T, undefined> extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never);\ntype StripPrismaFilters<T> = T extends\n | {\n equals?: any;\n }\n | {\n in?: any;\n }\n | {\n notIn?: any;\n }\n | {\n lt?: any;\n }\n | {\n lte?: any;\n }\n | {\n gt?: any;\n }\n | {\n gte?: any;\n }\n | {\n AND?: any;\n }\n | {\n OR?: any;\n }\n | {\n NOT?: any;\n }\n ? never\n : T;\ntype FlattenRelations<T> = {\n [K in keyof T]: IsArrayRelation<T[K]> extends true\n ? FlattenArrayRelation<T[K]>\n : IsObjectRelation<T[K]> extends true\n ? XOR<FlattenObjectRelation<T[K]>, T[K]>\n : StripPrismaFilters<T[K]> extends never\n ? never\n : T[K] extends object\n ? T[K] extends Date | null | undefined\n ? T[K]\n : FlattenRelations<StripPrismaFilters<T[K]>>\n : StripPrismaFilters<T[K]>;\n};\n/**\n * Flattens Prisma relation inputs into a simpler, developer-friendly format\n *\n * Transforms Prisma's nested relation format:\n * ```typescript\n * { posts: { create: [...], connect: [...], update: [...] } }\n * ```\n *\n * Into a flattened format with optional apiAction discriminators:\n * ```typescript\n * { posts: [\n * { title: \"New Post\" }, // auto-detected as create\n * { id: 1 }, // auto-detected as connect\n * { id: 2, title: \"Updated\", apiAction: \"update\" }\n * ]}\n * ```\n *\n * @see {@link https://wwww.arkosjs.com/docs/reference/arkos-prisma-input}\n * @template T - The Prisma input type (e.g., Prisma.UserCreateInput)\n * @returns A flattened version of the input type with simplified relation handling\n */\nexport type ArkosPrismaInput<T> = FlattenRelations<T>;\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=arkos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arkos.js","sourceRoot":"","sources":["../../../src/types/arkos.ts"],"names":[],"mappings":"","sourcesContent":["import { Express } from \"express\";\nimport { IncomingMessage, Server, ServerResponse } from \"http\";\nimport { IArkosRouter } from \"../exports\";\n\ntype ArkosRouterMethods =\n | \"get\"\n | \"post\"\n | \"put\"\n | \"patch\"\n | \"delete\"\n | \"options\"\n | \"head\"\n | \"all\"\n | \"use\"\n | \"trace\"\n | \"route\";\n\nexport interface Arkos\n extends Omit<Express, \"listen\" | ArkosRouterMethods>,\n Pick<IArkosRouter, ArkosRouterMethods> {\n (req: IncomingMessage, res: ServerResponse): void;\n /**\n * Applies all loaded items to the app by adding them as middleware,\n * routers, or handlers at the end of the stack.\n *\n * This ensures that Arkos internals always run after user middleware/routes.\n * Automatically called before listen() if not called manually.\n */\n build(): Promise<this>;\n /**\n * Starts the server using Arkos-managed port and host configuration.\n * Automatically calls build() if not called manually.\n *\n * @param callback Optional callback invoked once server starts\n */\n listen(callback?: (error?: Error) => void): Promise<Server>;\n /**\n * Starts the server using Arkos-managed port and host configuration.\n * app.build() must be called before this.\n *\n * @param server {Server} - Optional callback invoked once server starts\n * @param callback Optional callback invoked once server starts\n */\n listen(server: Server, callback?: (error?: Error) => void): Promise<Server>;\n}\n"]}
@@ -0,0 +1,146 @@
1
+ import RouteConfigValidator from "../../route-config-validator.js";
2
+ import { applyPrefix, getMiddlewareStack } from "./index.js";
3
+ import { getUserFileExtension } from "../../../helpers/fs.helpers.js";
4
+ import { getArkosConfig } from "../../../../server.js";
5
+ import RouteConfigRegistry from "../../route-config-registry.js";
6
+ import { catchAsync } from "../../../../exports/error-handler/index.js";
7
+ import deepmerge from "../../../helpers/deepmerge.helper.js";
8
+ import ExitError from "../../../helpers/exit-error.js";
9
+ import uploadManager from "./upload-manager.js";
10
+ export function applyArkosRouterProxy(target, options, name = "ArkosRouter()") {
11
+ return new Proxy(target, {
12
+ get(target, prop, receiver) {
13
+ const originalMethod = Reflect.get(target, prop, receiver);
14
+ const httpMethods = [
15
+ "get",
16
+ "post",
17
+ "put",
18
+ "patch",
19
+ "delete",
20
+ "all",
21
+ "head",
22
+ "trace",
23
+ "options",
24
+ ];
25
+ if (prop === "use") {
26
+ return function (config, ...handlers) {
27
+ if (!config ||
28
+ typeof config !== "object" ||
29
+ Array.isArray(config) ||
30
+ typeof config === "function")
31
+ return originalMethod.call(target, config, ...handlers);
32
+ if (config.disabled)
33
+ return;
34
+ const useConfig = config;
35
+ const path = useConfig.path
36
+ ? applyPrefix(options?.prefix, useConfig.path)
37
+ : undefined;
38
+ const arkosConfig = getArkosConfig();
39
+ const authenticationConfig = arkosConfig.authentication;
40
+ if (useConfig.authentication && !authenticationConfig?.mode)
41
+ throw ExitError(`Trying to authenticate route use${path ? ` ${path}` : ""} without choosing an authentication mode under arkos.config.${getUserFileExtension()}
42
+
43
+ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`);
44
+ const middlewareStack = getMiddlewareStack(useConfig);
45
+ const allHandlers = [...middlewareStack, ...handlers];
46
+ return path
47
+ ? originalMethod.call(target, path, ...allHandlers)
48
+ : originalMethod.call(target, ...allHandlers);
49
+ };
50
+ }
51
+ if (prop === "route") {
52
+ return function (path) {
53
+ const routeChain = {};
54
+ httpMethods.forEach((method) => {
55
+ routeChain[method] = function (config, ...handlers) {
56
+ const fullConfig = {
57
+ ...config,
58
+ ...(options?.openapi
59
+ ? {
60
+ experimental: {
61
+ openapi: options.openapi,
62
+ },
63
+ }
64
+ : {}),
65
+ path,
66
+ };
67
+ receiver[method](fullConfig, ...handlers);
68
+ return routeChain;
69
+ };
70
+ });
71
+ return routeChain;
72
+ };
73
+ }
74
+ if (httpMethods.includes(prop)) {
75
+ return function (config, ...handlers) {
76
+ if (config.disabled)
77
+ return;
78
+ if (!RouteConfigValidator.isArkosRouteConfig(config))
79
+ throw Error(`First argument of ${name}.${prop}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === "object" ? JSON.stringify(config, null, 2) : config}`);
80
+ const path = applyPrefix(options?.prefix, config.path);
81
+ config = {
82
+ ...config,
83
+ ...(options?.openapi
84
+ ? {
85
+ experimental: {
86
+ ...config?.experimental,
87
+ openapi: deepmerge(options.openapi || {}, config?.experimental?.openapi || {}),
88
+ },
89
+ }
90
+ : {}),
91
+ path,
92
+ };
93
+ if ([null, undefined].includes(path))
94
+ throw Error("Please pass valid value for path field to use in your route");
95
+ const method = prop;
96
+ const UndefinedHandlerError = (handler) => Error(`Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`);
97
+ if (handlers.length > 0) {
98
+ const flattenHandlers = (arr) => {
99
+ return arr.reduce((flat, item) => {
100
+ return flat.concat(Array.isArray(item) ? flattenHandlers(item) : item);
101
+ }, []);
102
+ };
103
+ const flatHandlers = flattenHandlers(handlers);
104
+ handlers = flatHandlers.map((handler) => {
105
+ if (!handler)
106
+ throw UndefinedHandlerError(handler);
107
+ if (typeof handler !== "function") {
108
+ throw UndefinedHandlerError(handler);
109
+ }
110
+ return catchAsync(handler, {
111
+ type: handler.length > 3 ? "error" : "normal",
112
+ });
113
+ });
114
+ const finalHandler = handlers[handlers.length - 1];
115
+ RouteConfigRegistry.register(finalHandler, config, method);
116
+ }
117
+ const arkosConfig = getArkosConfig();
118
+ const validationConfig = arkosConfig.validation;
119
+ const authenticationConfig = arkosConfig.authentication;
120
+ const strictValidation = validationConfig?.strict;
121
+ const route = `${method.toUpperCase()} ${path}`;
122
+ if (strictValidation &&
123
+ (!("validation" in config) ||
124
+ ("validation" in config &&
125
+ !config.validation &&
126
+ config.validation !== undefined)))
127
+ throw Error("When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.");
128
+ if (!validationConfig?.resolver &&
129
+ Object.keys(config.validation || {}).length > 0)
130
+ throw Error(`Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`);
131
+ if (config.authentication && !authenticationConfig?.mode)
132
+ throw Error(`Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${getUserFileExtension()}
133
+
134
+ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`);
135
+ handlers = [...getMiddlewareStack(config), ...handlers];
136
+ if (config.experimental?.uploads &&
137
+ config.experimental.uploads.deleteOnError !== false)
138
+ handlers.push(catchAsync(uploadManager.handleFileCleanup(config.experimental.uploads), { type: "error" }));
139
+ return originalMethod.call(target, path, ...handlers);
140
+ };
141
+ }
142
+ return originalMethod;
143
+ },
144
+ });
145
+ }
146
+ //# sourceMappingURL=apply-arkos-router-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-arkos-router-proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.ts"],"names":[],"mappings":"AAQA,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC;AACpD,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esContent":["import { RouterOptions } from \"express\";\nimport {\n ArkosAnyRequestHandler,\n ArkosRouteConfig,\n ArkosUseConfig,\n IArkosRoute,\n PathParams,\n} from \"../../types\";\nimport RouteConfigValidator from \"../../route-config-validator\";\nimport { applyPrefix, getMiddlewareStack } from \".\";\nimport { getUserFileExtension } from \"../../../helpers/fs.helpers\";\nimport { getArkosConfig } from \"../../../../server\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { catchAsync } from \"../../../../exports/error-handler\";\nimport deepmerge from \"../../../helpers/deepmerge.helper\";\nimport ExitError from \"../../../helpers/exit-error\";\nimport uploadManager from \"./upload-manager\";\n\nexport function applyArkosRouterProxy<T extends object>(\n target: T,\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n },\n name: \"app\" | \"ArkosRouter()\" = \"ArkosRouter()\"\n): T {\n return new Proxy(target, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver) as Function;\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ] as const;\n\n if (prop === \"use\") {\n return function (\n config: ArkosUseConfig | PathParams | ArkosAnyRequestHandler,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n // if not an ArkosUseConfig object, fall through to native Express use\n if (\n !config ||\n typeof config !== \"object\" ||\n Array.isArray(config) ||\n typeof config === \"function\"\n )\n return originalMethod.call(target, config, ...handlers);\n\n if ((config as ArkosUseConfig).disabled) return;\n\n const useConfig = config as ArkosUseConfig;\n const path = useConfig.path\n ? applyPrefix(options?.prefix, useConfig.path)\n : undefined;\n\n const arkosConfig = getArkosConfig();\n const authenticationConfig = arkosConfig.authentication;\n\n if (useConfig.authentication && !authenticationConfig?.mode)\n throw ExitError(\n `Trying to authenticate route use${path ? ` ${path}` : \"\"} without choosing an authentication mode under arkos.config.${getUserFileExtension()}\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n const middlewareStack = getMiddlewareStack(useConfig);\n\n const allHandlers = [...middlewareStack, ...handlers];\n\n return path\n ? originalMethod.call(target, path, ...allHandlers)\n : originalMethod.call(target, ...allHandlers);\n };\n }\n\n if (prop === \"route\") {\n return function (path: PathParams) {\n const routeChain: any = {};\n\n httpMethods.forEach((method) => {\n routeChain[method] = function (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n const fullConfig: ArkosRouteConfig = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n openapi: options.openapi,\n },\n }\n : {}),\n path,\n };\n\n receiver[method](fullConfig, ...handlers);\n\n return routeChain as IArkosRoute;\n };\n });\n\n return routeChain;\n };\n }\n\n if (httpMethods.includes(prop as any)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ${name}.${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const path = applyPrefix(options?.prefix, config.path);\n\n config = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n ...config?.experimental,\n openapi: deepmerge(\n options.openapi || {},\n config?.experimental?.openapi || {}\n ),\n },\n }\n : {}),\n path,\n };\n\n if ([null, undefined].includes(path as any))\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n const method = prop as string;\n const UndefinedHandlerError = (handler: any) =>\n Error(\n `Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`\n );\n\n if (handlers.length > 0) {\n const flattenHandlers = (arr: any[]): ArkosAnyRequestHandler[] => {\n return arr.reduce((flat, item) => {\n return flat.concat(\n Array.isArray(item) ? flattenHandlers(item) : item\n );\n }, []);\n };\n\n const flatHandlers = flattenHandlers(handlers);\n\n handlers = flatHandlers.map((handler: ArkosAnyRequestHandler) => {\n if (!handler) throw UndefinedHandlerError(handler);\n\n if (typeof handler !== \"function\") {\n throw UndefinedHandlerError(handler);\n }\n\n return catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n });\n });\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (\n !validationConfig?.resolver &&\n Object.keys(config.validation || {}).length > 0\n )\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${getUserFileExtension()}\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n });\n}\n"]}
@@ -11,6 +11,6 @@ export function killServerChildProcess() {
11
11
  killProductionServerChildProcess();
12
12
  }
13
13
  export function getVersion() {
14
- return "1.4.11-beta";
14
+ return "1.4.13-beta";
15
15
  }
16
16
  //# sourceMappingURL=cli.helpers.js.map