arkos 1.2.8-beta → 1.2.9-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 (24) hide show
  1. package/dist/cjs/modules/auth/auth.service.js.map +1 -1
  2. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -12
  3. package/dist/cjs/utils/cli/utils/cli.helpers.js.map +1 -1
  4. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +33 -66
  5. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
  6. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +16 -10
  7. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
  8. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +5 -0
  9. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
  10. package/dist/cjs/utils/helpers/global.helpers.js +7 -0
  11. package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
  12. package/dist/esm/modules/auth/auth.service.js.map +1 -1
  13. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -12
  14. package/dist/esm/utils/cli/utils/cli.helpers.js.map +1 -1
  15. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js +33 -66
  16. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
  17. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +16 -10
  18. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
  19. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js +5 -0
  20. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
  21. package/dist/esm/utils/helpers/global.helpers.js +7 -0
  22. package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
  23. package/dist/types/utils/cli/utils/cli.helpers.d.ts +1 -1
  24. package/package.json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AM,IAAI,QAAQ,CAChB,iDAAiD,EACjD,GAAG,EACH,EAAE,EACF,kBAAkB,CACnB,CAAC;QAEJ,MAAM,IAAI,GAAe,MAAO,MAAc,CAAC,IAAI,CAAC,UAAU,CAAC;YAC7D,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;SAQlC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,QAAQ,CAChB,wDAAwD,EACxD,GAAG,CACJ,CAAC;QAEJ,IACE,IAAI,CAAC,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,GAAI,CAAC;YACjD,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC;YAE/B,MAAM,IAAI,QAAQ,CAChB,sDAAsD,EACtD,GAAG,EACH,EAAE,EACF,iBAAiB,CAClB,CAAC;QAEJ,OAAO,IAAI,CAAC;IACd,CAAC;IA8BD,2BAA2B,CACzB,MAAoB,EACpB,qBAA+D;QAE/D,IAAI,qBAAqB,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;YACvE,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAK,KAAK;gBAAE,OAAO,QAAQ,CAAC;iBACxD,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAK,IAAI;gBAAE,OAAO,IAAI,CAAC,YAAY,CAAC;QAC5E,CAAC;;YAAM,OAAO,IAAI,CAAC,YAAY,CAAC;QAEhC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,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} from \"../../types/auth\";\nimport { MsDuration } from \"./utils/helpers/auth.controller.helpers\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\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.NODE_ENV === \"production\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n {},\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 * 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(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.NODE_ENV === \"production\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\"Missing JWT secret!\", 500);\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 /**\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} resourceName - 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 handleAccessControl(\n action: AccessAction,\n resourceName: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n return catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (req.user) {\n const user = req.user as any;\n const prisma = getPrismaInstance();\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const matchingRole = await prisma.userRole.findFirst({\n where: {\n userId: req.user.id,\n role: {\n permissions: {\n some: {\n resource: resourceName,\n action: action,\n },\n },\n },\n },\n select: { id: true },\n });\n\n if (!matchingRole)\n return next(\n new AppError(\n \"You do not have permission to perfom this action\",\n 403\n )\n );\n } else if (configs?.authentication?.mode === \"static\") {\n let authorizedRoles: string[] = [];\n\n if (!accessControl)\n return next(\n new AppError(\n \"You do not have permission to perform this action\",\n 403\n )\n );\n\n if (Array.isArray(accessControl)) authorizedRoles = accessControl;\n else if (accessControl[action])\n authorizedRoles = accessControl[action] || [];\n\n const userRoles = Array.isArray(user?.roles)\n ? user.roles\n : [user.role];\n const hasPermission = userRoles.some((role: string) =>\n authorizedRoles.includes(role)\n );\n\n if (!hasPermission) {\n return next(\n new AppError(\n \"You do not have permission to perform this action\",\n 403\n )\n );\n }\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 const arkosConfig = getArkosConfig();\n if (!arkosConfig?.authentication) return null;\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 ) {\n token = req?.headers?.authorization.split(\" \")[1];\n } else if (req?.cookies?.arkos_access_token !== \"no-token\" && req.cookies) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token)\n throw new AppError(\n \"You are not logged in! please log in to get access\",\n 401,\n {},\n \"LoginRequired\"\n );\n\n let decoded: AuthJwtPayload | undefined;\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw new AppError(\n \"Your auth token is invalid, please login again.\",\n 401,\n {},\n \"InvalidAuthToken\"\n );\n }\n\n if (!decoded?.id)\n throw new AppError(\n \"Your auth token is invalid, please login again.\",\n 401,\n {},\n \"InvalidAuthToken\"\n );\n\n const user: any | null = await (prisma as any).user.findUnique({\n where: { id: String(decoded.id) },\n // select: {\n // id: true,\n // passwordChangedAt: true,\n // isActive: true,\n // deletedSelfAccountAt: true,\n // isSuperUser: true,\n // },\n });\n\n if (!user)\n throw new AppError(\n \"The user belonging to this token does no longer exists\",\n 401\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 {},\n \"PasswordChanged\"\n );\n\n return user;\n }\n\n /**\n * Middleware function to authenticate the user based on the JWT token.\n *\n * @param {ArkosRequest} req - The request object.\n * @param {ArkosResponse} res - The response object.\n * @param {ArkosNextFunction} next - The next middleware function to be called.\n * @returns {void}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const arkosConfig = getArkosConfig();\n if (!arkosConfig?.authentication) {\n next();\n return;\n }\n\n req.user = (await this.getAuthenticatedUser(req)) as User;\n next();\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 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/**\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,O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C;YACjD,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC;YAE/B,MAAM,IAAI,QAAQ,CAChB,sDAAsD,EACtD,GAAG,EACH,EAAE,EACF,iBAAiB,CAClB,CAAC;QAEJ,OAAO,IAAI,CAAC;IACd,CAAC;IA8BD,2BAA2B,CACzB,MAAoB,EACpB,qBAA+D;QAE/D,IAAI,qBAAqB,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;YACvE,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAK,KAAK;gBAAE,OAAO,QAAQ,CAAC;iBACxD,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAK,IAAI;gBAAE,OAAO,IAAI,CAAC,YAAY,CAAC;QAC5E,CAAC;;YAAM,OAAO,IAAI,CAAC,YAAY,CAAC;QAEhC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,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} from \"../../types/auth\";\nimport { MsDuration } from \"./utils/helpers/auth.controller.helpers\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\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.NODE_ENV === \"production\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n {},\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 * 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(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.NODE_ENV === \"production\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\"Missing JWT secret!\", 500);\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 /**\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} resourceName - 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 handleAccessControl(\n action: AccessAction,\n resourceName: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n return catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (req.user) {\n const user = req.user as any;\n const prisma = getPrismaInstance();\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const matchingRole = await prisma.userRole.findFirst({\n where: {\n userId: req.user.id,\n role: {\n permissions: {\n some: {\n resource: resourceName,\n action: action,\n },\n },\n },\n },\n select: { id: true },\n });\n\n if (!matchingRole)\n return next(\n new AppError(\n \"You do not have permission to perfom this action\",\n 403\n )\n );\n } else if (configs?.authentication?.mode === \"static\") {\n let authorizedRoles: string[] = [];\n\n if (!accessControl)\n return next(\n new AppError(\n \"You do not have permission to perform this action\",\n 403\n )\n );\n\n if (Array.isArray(accessControl)) authorizedRoles = accessControl;\n else if (accessControl[action])\n authorizedRoles = accessControl[action] || [];\n\n const userRoles = Array.isArray(user?.roles)\n ? user.roles\n : [user.role];\n const hasPermission = userRoles.some((role: string) =>\n authorizedRoles.includes(role)\n );\n\n if (!hasPermission) {\n return next(\n new AppError(\n \"You do not have permission to perform this action\",\n 403\n )\n );\n }\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 const arkosConfig = getArkosConfig();\n if (!arkosConfig?.authentication) return null;\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 ) {\n token = req?.headers?.authorization.split(\" \")[1];\n } else if (req?.cookies?.arkos_access_token !== \"no-token\" && req.cookies) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token)\n throw new AppError(\n \"You are not logged in! please log in to get access\",\n 401,\n {},\n \"LoginRequired\"\n );\n\n let decoded: AuthJwtPayload | undefined;\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw new AppError(\n \"Your auth token is invalid, please login again.\",\n 401,\n {},\n \"InvalidAuthToken\"\n );\n }\n\n if (!decoded?.id)\n throw new AppError(\n \"Your auth token is invalid, please login again.\",\n 401,\n {},\n \"InvalidAuthToken\"\n );\n\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 );\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 {},\n \"PasswordChanged\"\n );\n\n return user;\n }\n\n /**\n * Middleware function to authenticate the user based on the JWT token.\n *\n * @param {ArkosRequest} req - The request object.\n * @param {ArkosResponse} res - The response object.\n * @param {ArkosNextFunction} next - The next middleware function to be called.\n * @returns {void}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const arkosConfig = getArkosConfig();\n if (!arkosConfig?.authentication) {\n next();\n return;\n }\n\n req.user = (await this.getAuthenticatedUser(req)) as User;\n next();\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 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/**\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,9 +1,6 @@
1
1
  import fs from "fs";
2
2
  import { killDevelopmentServerChildProcess } from "../dev.js";
3
3
  import { killProductionServerChildProcess } from "../start.js";
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- import { dirname } from "path";
7
4
  export function ensureDirectoryExists(dirPath) {
8
5
  if (!fs.existsSync(dirPath)) {
9
6
  fs.mkdirSync(dirPath, { recursive: true });
@@ -14,14 +11,6 @@ export function killServerChildProcess() {
14
11
  killProductionServerChildProcess();
15
12
  }
16
13
  export function getVersion() {
17
- let currentDir;
18
- if (typeof __dirname !== "undefined") {
19
- currentDir = __dirname;
20
- }
21
- else {
22
- currentDir = dirname(fileURLToPath(import.meta.url));
23
- }
24
- const packageJson = JSON.parse(fs.readFileSync(path.join(currentDir, "../../../../../package.json"), "utf8") || "{}");
25
- return packageJson?.version || "1.0.0";
14
+ return "1.2.9-beta";
26
15
  }
27
16
  //# sourceMappingURL=cli.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.helpers.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/cli.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,iCAAiC,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,iCAAiC,EAAE,CAAC;IACpC,gCAAgC,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,UAAkB,CAAC;IAEvB,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;QAErC,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;SAAM,CAAC;QAEN,UAAU,GAAG,OAAO,CAAC,aAAa,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,EAAE,CAAC,YAAY,CACb,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,6BAA6B,CAAC,EACpD,MAAM,CACP,IAAI,IAAI,CACV,CAAC;IACF,OAAO,WAAW,EAAE,OAAO,IAAI,OAAO,CAAC;AACzC,CAAC","sourcesContent":["import fs from \"fs\";\nimport { killDevelopmentServerChildProcess } from \"../dev\";\nimport { killProductionServerChildProcess } from \"../start\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { dirname } from \"path\";\n\nexport function ensureDirectoryExists(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n fs.mkdirSync(dirPath, { recursive: true });\n }\n}\n\nexport function killServerChildProcess() {\n killDevelopmentServerChildProcess();\n killProductionServerChildProcess();\n}\n\nexport function getVersion() {\n let currentDir: string;\n // @ts-ignore\n if (typeof __dirname !== \"undefined\") {\n // @ts-ignore\n currentDir = __dirname;\n } else {\n // @ts-ignore\n currentDir = dirname(fileURLToPath((import.meta as any).url));\n }\n\n const packageJson = JSON.parse(\n fs.readFileSync(\n path.join(currentDir, \"../../../../../package.json\"),\n \"utf8\"\n ) || \"{}\"\n );\n return packageJson?.version || \"1.0.0\";\n}\n"]}
1
+ {"version":3,"file":"cli.helpers.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/cli.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,iCAAiC,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAM5D,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,iCAAiC,EAAE,CAAC;IACpC,gCAAgC,EAAE,CAAC;AACrC,CAAC;AA+BD,MAAM,UAAU,UAAU;IACxB,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import fs from \"fs\";\nimport { killDevelopmentServerChildProcess } from \"../dev\";\nimport { killProductionServerChildProcess } from \"../start\";\nimport path, { dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n// import { fileURLToPath } from \"url\";\n// import { dirname } from \"path\";\n\nexport function ensureDirectoryExists(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n fs.mkdirSync(dirPath, { recursive: true });\n }\n}\n\nexport function killServerChildProcess() {\n killDevelopmentServerChildProcess();\n killProductionServerChildProcess();\n}\n\n// export function getVersion() {\n// let currentDir: string;\n// // @ts-ignore\n// if (typeof __dirname !== \"undefined\") {\n// // @ts-ignore\n// currentDir = __dirname;\n// } else {\n// // @ts-ignore\n// currentDir = dirname(fileURLToPath((import.meta as any).url));\n// }\n\n// const packageJson = JSON.parse(\n// fs.readFileSync(\n// path.join(currentDir, \"../../../../../package.json\"),\n// \"utf8\"\n// ) || \"{}\"\n// );\n// return packageJson?.version || \"1.0.0\";\n// }\n\n//export async function getVersion() {\n// //@ts-ignore\n// const pkg = await import(\"../../../../../package.json\", {\n// with: { type: \"json\" }, // Use 'with' instead of 'assert'\n// });\n// const version = \"default\" in pkg ? pkg.default.versoin : pkg.version;\n\n// return version || \"1.0.0\";\n//}\nexport function getVersion() {\n return \"{{version}}\";\n}\n"]}
@@ -20,246 +20,213 @@ import { catchAsync } from "arkos/error-handler";`
20
20
  if (isAuth) {
21
21
  return `${baseImports}
22
22
 
23
- // export const beforeGetMe = catchAsync(
23
+ // export const beforeGetMe =
24
24
  // async (${functionParams}) => {
25
25
  // // Your logic here
26
26
  // next();
27
27
  // }
28
- // );
29
28
 
30
- // export const afterGetMe = catchAsync(
29
+ // export const afterGetMe =
31
30
  // async (${functionParams}) => {
32
31
  // // Your logic here
33
32
  // next();
34
33
  // }
35
- // );
36
34
 
37
- // export const beforeLogin = catchAsync(
35
+ // export const beforeLogin =
38
36
  // async (${functionParams}) => {
39
37
  // // Your logic here
40
38
  // next();
41
39
  // }
42
- // );
43
40
 
44
- // export const afterLogin = catchAsync(
41
+ // export const afterLogin =
45
42
  // async (${functionParams}) => {
46
43
  // // Your logic here
47
44
  // next();
48
45
  // }
49
- // );
50
46
 
51
- // export const beforeLogout = catchAsync(
47
+ // export const beforeLogout =
52
48
  // async (${functionParams}) => {
53
49
  // // Your logic here
54
50
  // next();
55
51
  // }
56
- // );
57
52
 
58
- // export const afterLogout = catchAsync(
53
+ // export const afterLogout =
59
54
  // async (${functionParams}) => {
60
55
  // // Your logic here
61
56
  // next();
62
57
  // }
63
- // );
64
58
 
65
- // export const beforeSignup = catchAsync(
59
+ // export const beforeSignup =
66
60
  // async (${functionParams}) => {
67
61
  // // Your logic here
68
62
  // next();
69
63
  // }
70
- // );
71
64
 
72
- // export const afterSignup = catchAsync(
65
+ // export const afterSignup =
73
66
  // async (${functionParams}) => {
74
67
  // // Your logic here
75
68
  // next();
76
69
  // }
77
- // );
78
70
 
79
- // export const beforeUpdatePassword = catchAsync(
71
+ // export const beforeUpdatePassword =
80
72
  // async (${functionParams}) => {
81
73
  // // Your logic here
82
74
  // next();
83
75
  // }
84
- // );
85
76
 
86
- // export const afterUpdatePassword = catchAsync(
77
+ // export const afterUpdatePassword =
87
78
  // async (${functionParams}) => {
88
79
  // // Your logic here
89
80
  // next();
90
81
  // }
91
- // );
92
82
  `;
93
83
  }
94
84
  if (isFileUpload) {
95
85
  return `${baseImports}
96
86
 
97
87
 
98
- // export const beforeFindFile = catchAsync(
88
+ // export const beforeFindFile =
99
89
  // async (${functionParams}) => {
100
90
  // // Your logic here
101
91
  // next();
102
92
  // }
103
- // );
104
93
 
105
94
  // There is not afterFindFile: because the main handler is handleded by express.static()
106
95
 
107
- // export const beforeUploadFile = catchAsync(
96
+ // export const beforeUploadFile =
108
97
  // async (${functionParams}) => {
109
98
  // // Your logic here
110
99
  // next();
111
100
  // }
112
- // );
113
101
 
114
- // export const afterUploadFile = catchAsync(
102
+ // export const afterUploadFile =
115
103
  // async (${functionParams}) => {
116
104
  // // Your logic here
117
105
  // next();
118
106
  // }
119
- // );
120
107
 
121
- // export const beforeUpdateFile = catchAsync(
108
+ // export const beforeUpdateFile =
122
109
  // async (${functionParams}) => {
123
110
  // // Your logic here
124
111
  // next();
125
112
  // }
126
- // );
127
113
 
128
- // export const afterUpdateFile = catchAsync(
114
+ // export const afterUpdateFile =
129
115
  // async (${functionParams}) => {
130
116
  // // Your logic here
131
117
  // next();
132
118
  // }
133
- // );
134
119
 
135
- // export const beforeDeleteFile = catchAsync(
120
+ // export const beforeDeleteFile =
136
121
  // async (${functionParams}) => {
137
122
  // // Your logic here
138
123
  // next();
139
124
  // }
140
- // );
141
125
 
142
- // export const afterDeleteFile = catchAsync(
126
+ // export const afterDeleteFile =
143
127
  // async (${functionParams}) => {
144
128
  // // Your logic here
145
129
  // next();
146
130
  // }
147
- // );
148
131
  `;
149
132
  }
150
133
  return `${baseImports}
151
134
 
152
- // export const beforeCreateOne = catchAsync(
135
+ // export const beforeCreateOne =
153
136
  // async (${functionParams}) => {
154
137
  // // Your logic here
155
138
  // next();
156
139
  // }
157
- // );
158
140
 
159
- // export const afterCreateOne = catchAsync(
141
+ // export const afterCreateOne =
160
142
  // async (${functionParams}) => {
161
143
  // // Your logic here
162
144
  // next();
163
145
  // }
164
- // );
165
146
 
166
- // export const beforeFindOne = catchAsync(
147
+ // export const beforeFindOne =
167
148
  // async (${functionParams}) => {
168
149
  // // Your logic here
169
150
  // next();
170
151
  // }
171
- // );
172
152
 
173
- // export const afterFindOne = catchAsync(
153
+ // export const afterFindOne =
174
154
  // async (${functionParams}) => {
175
155
  // // Your logic here
176
156
  // next();
177
157
  // }
178
- // );
179
158
 
180
- // export const beforeFindMany = catchAsync(
159
+ // export const beforeFindMany =
181
160
  // async (${functionParams}) => {
182
161
  // // Your logic here
183
162
  // next();
184
163
  // }
185
- // );
186
164
 
187
- // export const afterFindMany = catchAsync(
165
+ // export const afterFindMany =
188
166
  // async (${functionParams}) => {
189
167
  // // Your logic here
190
168
  // next();
191
169
  // }
192
- // );
193
170
 
194
- // export const beforeUpdateOne = catchAsync(
171
+ // export const beforeUpdateOne =
195
172
  // async (${functionParams}) => {
196
173
  // // Your logic here
197
174
  // next();
198
175
  // }
199
- // );
200
176
 
201
- // export const afterUpdateOne = catchAsync(
177
+ // export const afterUpdateOne =
202
178
  // async (${functionParams}) => {
203
179
  // // Your logic here
204
180
  // next();
205
181
  // }
206
- // );
207
182
 
208
- // export const beforeDeleteOne = catchAsync(
183
+ // export const beforeDeleteOne =
209
184
  // async (${functionParams}) => {
210
185
  // // Your logic here
211
186
  // next();
212
187
  // }
213
- // );
214
188
 
215
- // export const afterDeleteOne = catchAsync(
189
+ // export const afterDeleteOne =
216
190
  // async (${functionParams}) => {
217
191
  // // Your logic here
218
192
  // next();
219
193
  // }
220
- // );
221
194
 
222
- // export const beforeCreateMany = catchAsync(
195
+ // export const beforeCreateMany =
223
196
  // async (${functionParams}) => {
224
197
  // // Your logic here
225
198
  // next();
226
199
  // }
227
- // );
228
200
 
229
- // export const afterCreateMany = catchAsync(
201
+ // export const afterCreateMany =
230
202
  // async (${functionParams}) => {
231
203
  // // Your logic here
232
204
  // next();
233
205
  // }
234
- // );
235
206
 
236
- // export const beforeUpdateMany = catchAsync(
207
+ // export const beforeUpdateMany =
237
208
  // async (${functionParams}) => {
238
209
  // // Your logic here
239
210
  // next();
240
211
  // }
241
- // );
242
212
 
243
- // export const afterUpdateMany = catchAsync(
213
+ // export const afterUpdateMany =
244
214
  // async (${functionParams}) => {
245
215
  // // Your logic here
246
216
  // next();
247
217
  // }
248
- // );
249
218
 
250
- // export const beforeDeleteMany = catchAsync(
219
+ // export const beforeDeleteMany =
251
220
  // async (${functionParams}) => {
252
221
  // // Your logic here
253
222
  // next();
254
223
  // }
255
- // );
256
224
 
257
- // export const afterDeleteMany = catchAsync(
225
+ // export const afterDeleteMany =
258
226
  // async (${functionParams}) => {
259
227
  // // Your logic here
260
228
  // next();
261
229
  // }
262
- // );
263
230
  `;
264
231
  }
265
232
  //# sourceMappingURL=generate-middlewares.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-middlewares.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-middlewares.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,2BAA2B,CAAC,OAAwB;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IA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;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;CAK3B,CAAC;AACF,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateMiddlewaresTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for middleware template\");\n\n const isAuth = modelName.camel === \"auth\";\n const isFileUpload =\n modelName.camel === \"fileUpload\" || modelName.camel === \"file-upload\";\n\n // Generate imports based on TypeScript/JavaScript\n const requestType = isTypeScript ? \"ArkosRequest\" : \"req\";\n const responseType = isTypeScript ? \"ArkosResponse\" : \"res\";\n const nextType = isTypeScript ? \"ArkosNextFunction\" : \"next\";\n\n const baseImports = isTypeScript\n ? `import { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"arkos\";\nimport { catchAsync } from \"arkos/error-handler\";`\n : `import { catchAsync } from \"arkos/error-handler\";`;\n\n const functionParams = isTypeScript\n ? `req: ${requestType}, res: ${responseType}, next: ${nextType}`\n : `req, res, next`;\n\n if (isAuth) {\n return `${baseImports}\n\n// export const beforeGetMe = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterGetMe = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeLogin = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterLogin = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeLogout = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterLogout = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeSignup = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterSignup = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdatePassword = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdatePassword = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n }\n\n if (isFileUpload) {\n return `${baseImports}\n\n\n// export const beforeFindFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// There is not afterFindFile: because the main handler is handleded by express.static()\n\n// export const beforeUploadFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUploadFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n }\n\n // Regular model middlewares\n return `${baseImports}\n\n// export const beforeCreateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterCreateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeFindOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterFindOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeFindMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterFindMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeCreateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterCreateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n}\n"]}
1
+ {"version":3,"file":"generate-middlewares.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-middlewares.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,2BAA2B,CAAC,OAAwB;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,I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AMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;;;cAMd,cAAc;;;;CAI3B,CAAC;AACF,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateMiddlewaresTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for middleware template\");\n\n const isAuth = modelName.camel === \"auth\";\n const isFileUpload =\n modelName.camel === \"fileUpload\" || modelName.camel === \"file-upload\";\n\n // Generate imports based on TypeScript/JavaScript\n const requestType = isTypeScript ? \"ArkosRequest\" : \"req\";\n const responseType = isTypeScript ? \"ArkosResponse\" : \"res\";\n const nextType = isTypeScript ? \"ArkosNextFunction\" : \"next\";\n\n const baseImports = isTypeScript\n ? `import { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"arkos\";\nimport { catchAsync } from \"arkos/error-handler\";`\n : `import { catchAsync } from \"arkos/error-handler\";`;\n\n const functionParams = isTypeScript\n ? `req: ${requestType}, res: ${responseType}, next: ${nextType}`\n : `req, res, next`;\n\n if (isAuth) {\n return `${baseImports}\n\n// export const beforeGetMe = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterGetMe = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeLogin = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterLogin = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeLogout = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterLogout = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeSignup = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterSignup = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeUpdatePassword = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterUpdatePassword = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n`;\n }\n\n if (isFileUpload) {\n return `${baseImports}\n\n\n// export const beforeFindFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// There is not afterFindFile: because the main handler is handleded by express.static()\n\n// export const beforeUploadFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterUploadFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeUpdateFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterUpdateFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeDeleteFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterDeleteFile = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n`;\n }\n\n // Regular model middlewares\n return `${baseImports}\n\n// export const beforeCreateOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterCreateOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeFindOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterFindOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeFindMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterFindMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeUpdateOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterUpdateOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeDeleteOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterDeleteOne = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeCreateMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterCreateMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeUpdateMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterUpdateMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const beforeDeleteMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n\n// export const afterDeleteMany = \n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n`;\n}\n"]}
@@ -36,16 +36,22 @@ export default ${modelName.camel}QueryOptions;
36
36
  return `${prismaImport}${imports};
37
37
 
38
38
  const ${modelName.camel}QueryOptions${typeAnnotation} = {
39
- // for all queries
40
- queryOptions: {},
41
- findOne: {},
42
- findMany: {},
43
- deleteMany: {},
44
- updateMany: {},
45
- createMany: {},
46
- createOne: {},
47
- updateOne: {},
48
- deleteOne: {},
39
+ global: {},
40
+ find: {},
41
+ findOne: {},
42
+ findMany: {},
43
+ udpate: {},
44
+ updateMany: {},
45
+ updateOne: {},
46
+ create: {},
47
+ createMany: {},
48
+ createOne: {},
49
+ save: {},
50
+ saveMany: {},
51
+ saveOne: {},
52
+ delete: {},
53
+ deleteMany: {},
54
+ deleteOne: {},
49
55
  }
50
56
 
51
57
  export default ${modelName.camel}QueryOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"generate-prisma-query-options.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-prisma-query-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,4BAA4B,CAAC,OAAwB;IACnE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAC3C,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAGtE,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC,uDAAuD;QACzD,CAAC,CAAC,mDAAmD,CAAC;IAGxD,MAAM,cAAc,GAAG,YAAY;QACjC,CAAC,CAAC,MAAM;YACN,CAAC,CAAC,0CAA0C,SAAS,CAAC,KAAK,GAAG;YAC9D,CAAC,CAAC,sCAAsC,SAAS,CAAC,KAAK,GAAG;QAC5D,CAAC,CAAC,EAAE,CAAC;IAGP,MAAM,YAAY,GAAG,YAAY;QAC/B,CAAC,CAAC,gDAAgD;QAClD,CAAC,CAAC,EAAE,CAAC;IAEP,IAAI,MAAM,EAAE,CAAC;QAEX,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;iBASnC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;SAAM,CAAC;QAEN,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;;;;;iBAanC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;AACH,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateQueryOptionsTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const isAuth = modelName?.camel === \"auth\";\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for query config template\");\n\n // Generate imports\n const imports = isAuth\n ? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`\n : `import { PrismaQueryOptions } from 'arkos/prisma'`;\n\n // Generate type annotation for TypeScript\n const typeAnnotation = isTypeScript\n ? isAuth\n ? `: AuthPrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : \"\";\n\n // Generate prisma import if TypeScript\n const prismaImport = isTypeScript\n ? `import { prisma } from \"../../utils/prisma\";\\n`\n : \"\";\n\n if (isAuth) {\n // Auth template\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n getMe: {},\n updateMe: {},\n deleteMe: {},\n login: {},\n signup: {},\n updatePassword: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n } else {\n // Regular template\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n // for all queries\n queryOptions: {},\n findOne: {},\n findMany: {},\n deleteMany: {},\n updateMany: {},\n createMany: {},\n createOne: {},\n updateOne: {},\n deleteOne: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n }\n}\n"]}
1
+ {"version":3,"file":"generate-prisma-query-options.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-prisma-query-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,4BAA4B,CAAC,OAAwB;IACnE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAC3C,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAGtE,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC,uDAAuD;QACzD,CAAC,CAAC,mDAAmD,CAAC;IAGxD,MAAM,cAAc,GAAG,YAAY;QACjC,CAAC,CAAC,MAAM;YACN,CAAC,CAAC,0CAA0C,SAAS,CAAC,KAAK,GAAG;YAC9D,CAAC,CAAC,sCAAsC,SAAS,CAAC,KAAK,GAAG;QAC5D,CAAC,CAAC,EAAE,CAAC;IAGP,MAAM,YAAY,GAAG,YAAY;QAC/B,CAAC,CAAC,gDAAgD;QAClD,CAAC,CAAC,EAAE,CAAC;IAEP,IAAI,MAAM,EAAE,CAAC;QAEX,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;iBASnC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;SAAM,CAAC;QAEN,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;;;;;;;;;;;iBAmBnC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;AACH,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateQueryOptionsTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const isAuth = modelName?.camel === \"auth\";\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for query config template\");\n\n // Generate imports\n const imports = isAuth\n ? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`\n : `import { PrismaQueryOptions } from 'arkos/prisma'`;\n\n // Generate type annotation for TypeScript\n const typeAnnotation = isTypeScript\n ? isAuth\n ? `: AuthPrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : \"\";\n\n // Generate prisma import if TypeScript\n const prismaImport = isTypeScript\n ? `import { prisma } from \"../../utils/prisma\";\\n`\n : \"\";\n\n if (isAuth) {\n // Auth template\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n getMe: {},\n updateMe: {},\n deleteMe: {},\n login: {},\n signup: {},\n updatePassword: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n } else {\n // Regular template\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n global: {},\n find: {},\n findOne: {},\n findMany: {},\n udpate: {},\n updateMany: {},\n updateOne: {},\n create: {},\n createMany: {},\n createOne: {},\n save: {},\n saveMany: {},\n saveOne: {},\n delete: {},\n deleteMany: {},\n deleteOne: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n }\n}\n"]}
@@ -6,6 +6,8 @@ export function generateRouterTemplate(options) {
6
6
  throw new Error("Model name is required for router template");
7
7
  const ext = getUserFileExtension();
8
8
  const controllerPath = imports?.controller || `./${modelName.kebab}.controller.${ext}`;
9
+ const routerConfigTsType = ext === "ts" ? ": RouterConfig" : "";
10
+ const routerConfigTsTypeImport = ext === "ts" ? "import { RouterConfig } from 'arkos'" : "";
9
11
  const controllerExists = checkFileExists(controllerPath);
10
12
  const controllerImportLine = controllerExists
11
13
  ? `import ${modelName.camel}Controller from "${imports?.controller || `./${modelName.kebab}.controller`}"`
@@ -16,6 +18,9 @@ export function generateRouterTemplate(options) {
16
18
  return `import { Router } from 'express'
17
19
  import { authService } from 'arkos/services'
18
20
  ${controllerImportLine}
21
+ ${routerConfigTsTypeImport}
22
+
23
+ export const config${routerConfigTsType} = { }
19
24
 
20
25
  const ${modelName.camel}Router = Router()
21
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"generate-router-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-router-template.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AAGxC,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC7D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAG9E,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,cAAc,GAClB,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,eAAe,GAAG,EAAE,CAAC;IAElE,MAAM,gBAAgB,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;IAEzD,MAAM,oBAAoB,GAAG,gBAAgB;QAC3C,CAAC,CAAC,UAAU,SAAS,CAAC,KAAK,oBACvB,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,aAC7C,GAAG;QACL,CAAC,CAAC,aAAa,SAAS,CAAC,KAAK,oBAC1B,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,aAC7C,GAAG,CAAC;IAER,MAAM,qBAAqB,GAAG,gBAAgB;QAC5C,CAAC,CAAC,KAAK,SAAS,CAAC,KAAK,wBAAwB;QAC9C,CAAC,CAAC,QAAQ,SAAS,CAAC,KAAK,wBAAwB,CAAC;IAEpD,OAAO;;EAEP,oBAAoB;;QAEd,SAAS,CAAC,KAAK;;EAErB,SAAS,CAAC,KAAK;4CAC2B,SAAS,CACjD,SAAS,CAAC,KAAK,CAChB;;qDAEkD,SAAS,CAAC,KAAK;EAClE,qBAAqB;;;iBAGN,SAAS,CAAC,KAAK;CAC/B,CAAC;AACF,CAAC","sourcesContent":["import pluralize from \"pluralize\";\nimport {\n checkFileExists,\n getUserFileExtension,\n} from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateRouterTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName) throw new Error(\"Model name is required for router template\");\n\n // Check if controller file exists\n const ext = getUserFileExtension();\n const controllerPath =\n imports?.controller || `./${modelName.kebab}.controller.${ext}`;\n\n const controllerExists = checkFileExists(controllerPath);\n\n const controllerImportLine = controllerExists\n ? `import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\"`\n : `// import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\"`;\n\n const controllerHandlerLine = controllerExists\n ? ` ${modelName.camel}Controller.someHandler`\n : ` // ${modelName.camel}Controller.someHandler`;\n\n return `import { Router } from 'express'\nimport { authService } from 'arkos/services'\n${controllerImportLine}\n\nconst ${modelName.camel}Router = Router()\n\n${modelName.camel}Router.post(\n '/custom-endpoint', // resolves to /api/${pluralize(\n modelName.kebab\n )}/custom-endpoint\n authService.authenticate,\n authService.handleAccessControl('CustomAction', '${modelName.kebab}'),\n${controllerHandlerLine}\n)\n\nexport default ${modelName.camel}Router\n`;\n}\n"]}
1
+ {"version":3,"file":"generate-router-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/generate-router-template.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AAGxC,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC7D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAG9E,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,cAAc,GAClB,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,eAAe,GAAG,EAAE,CAAC;IAElE,MAAM,kBAAkB,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,MAAM,wBAAwB,GAC5B,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,sCAAsC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE7D,MAAM,gBAAgB,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;IAEzD,MAAM,oBAAoB,GAAG,gBAAgB;QAC3C,CAAC,CAAC,UAAU,SAAS,CAAC,KAAK,oBACvB,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,aAC7C,GAAG;QACL,CAAC,CAAC,aAAa,SAAS,CAAC,KAAK,oBAC1B,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,aAC7C,GAAG,CAAC;IAER,MAAM,qBAAqB,GAAG,gBAAgB;QAC5C,CAAC,CAAC,KAAK,SAAS,CAAC,KAAK,wBAAwB;QAC9C,CAAC,CAAC,QAAQ,SAAS,CAAC,KAAK,wBAAwB,CAAC;IAEpD,OAAO;;EAEP,oBAAoB;EACpB,wBAAwB;;qBAEL,kBAAkB;;QAE/B,SAAS,CAAC,KAAK;;EAErB,SAAS,CAAC,KAAK;4CAC2B,SAAS,CACjD,SAAS,CAAC,KAAK,CAChB;;qDAEkD,SAAS,CAAC,KAAK;EAClE,qBAAqB;;;iBAGN,SAAS,CAAC,KAAK;CAC/B,CAAC;AACF,CAAC","sourcesContent":["import pluralize from \"pluralize\";\nimport {\n checkFileExists,\n getUserFileExtension,\n} from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateRouterTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName) throw new Error(\"Model name is required for router template\");\n\n // Check if controller file exists\n const ext = getUserFileExtension();\n const controllerPath =\n imports?.controller || `./${modelName.kebab}.controller.${ext}`;\n\n const routerConfigTsType = ext === \"ts\" ? \": RouterConfig\" : \"\";\n const routerConfigTsTypeImport =\n ext === \"ts\" ? \"import { RouterConfig } from 'arkos'\" : \"\";\n\n const controllerExists = checkFileExists(controllerPath);\n\n const controllerImportLine = controllerExists\n ? `import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\"`\n : `// import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\"`;\n\n const controllerHandlerLine = controllerExists\n ? ` ${modelName.camel}Controller.someHandler`\n : ` // ${modelName.camel}Controller.someHandler`;\n\n return `import { Router } from 'express'\nimport { authService } from 'arkos/services'\n${controllerImportLine}\n${routerConfigTsTypeImport}\n\nexport const config${routerConfigTsType} = { }\n\nconst ${modelName.camel}Router = Router()\n\n${modelName.camel}Router.post(\n '/custom-endpoint', // resolves to /api/${pluralize(\n modelName.kebab\n )}/custom-endpoint\n authService.authenticate,\n authService.handleAccessControl('CustomAction', '${modelName.kebab}'),\n${controllerHandlerLine}\n)\n\nexport default ${modelName.camel}Router\n`;\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { createRequire } from "module";
4
+ import { pathToFileURL } from "url";
3
5
  export function getPackageJson() {
4
6
  try {
5
7
  const pkgPath = path.join(process.cwd(), "package.json");
@@ -30,6 +32,11 @@ export async function importModule(modulePath, options = { fixExtension: true })
30
32
  correctedPath = modulePath + ".js";
31
33
  }
32
34
  }
35
+ if (!options.fixExtension)
36
+ return await import(modulePath);
37
+ const userRequire = createRequire(pathToFileURL(process.cwd() + "/package.json"));
38
+ const resolved = userRequire.resolve(modulePath);
39
+ return await import(pathToFileURL(resolved));
33
40
  return await import(correctedPath);
34
41
  }
35
42
  export function detectPackageManagerFromUserAgent() {
@@ -1 +1 @@
1
- {"version":3,"file":"global.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/global.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACzD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAA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C,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nexport function getPackageJson() {\n try {\n const pkgPath = path.join(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgPath)) {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n }\n } catch (err) {\n console.error(\"Error checking package.json:\", err);\n }\n}\n\nexport function isEsm() {\n const pkg = getPackageJson();\n return pkg.type === \"module\";\n}\n\nexport async function importModule(\n modulePath: string,\n options: { fixExtension: boolean } = { fixExtension: true }\n) {\n // Add .js extension if it's a relative path without extension\n let correctedPath = modulePath;\n\n if (\n options?.fixExtension &&\n isEsm() &&\n modulePath.startsWith(\".\") &&\n !modulePath.endsWith(\".js\")\n ) {\n const fullImportPath = path.resolve(process.cwd(), modulePath);\n const indexPath = fullImportPath + \"/index.js\";\n\n // Check if it's a directory with index.js or a direct file\n if (fs.existsSync(indexPath)) {\n correctedPath = modulePath + \"/index.js\";\n } else {\n correctedPath = modulePath + \".js\";\n }\n }\n\n return await import(correctedPath);\n}\n\n/**\n * Helps getting the current package manager from user agent\n *\n * @returns {string} the package manager\n * @default \"npm\"\n */\nexport function detectPackageManagerFromUserAgent(): string {\n const userAgent = process.env.npm_config_user_agent || \"\";\n\n if (!userAgent) return \"npm\";\n if (userAgent.includes(\"pnpm\")) return \"pnpm\";\n if (userAgent.includes(\"yarn\")) return \"yarn\";\n if (userAgent.includes(\"npm\")) return \"npm\";\n if (userAgent.includes(\"bun\")) return \"bun\";\n if (userAgent.includes(\"cnpm\")) return \"cnpm\";\n if (userAgent.includes(\"corepack\")) return \"corepack\";\n if (userAgent.includes(\"deno\")) return \"deno\";\n\n return \"npm\";\n}\n"]}
1
+ {"version":3,"file":"global.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/global.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACzD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;IAC7B,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAkB,EAClB,UAAqC,EAAE,YAAY,EAAE,IAAI,EAAE;IAG3D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,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { createRequire } from \"module\";\nimport { pathToFileURL } from \"url\";\n\nexport function getPackageJson() {\n try {\n const pkgPath = path.join(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgPath)) {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n }\n } catch (err) {\n console.error(\"Error checking package.json:\", err);\n }\n}\n\nexport function isEsm() {\n const pkg = getPackageJson();\n return pkg.type === \"module\";\n}\n\nexport async function importModule(\n modulePath: string,\n options: { fixExtension: boolean } = { fixExtension: true }\n) {\n // Add .js extension if it's a relative path without extension\n let correctedPath = modulePath;\n\n if (\n options?.fixExtension &&\n isEsm() &&\n modulePath.startsWith(\".\") &&\n !modulePath.endsWith(\".js\")\n ) {\n const fullImportPath = path.resolve(process.cwd(), modulePath);\n const indexPath = fullImportPath + \"/index.js\";\n\n // Check if it's a directory with index.js or a direct file\n if (fs.existsSync(indexPath)) {\n correctedPath = modulePath + \"/index.js\";\n } else {\n correctedPath = modulePath + \".js\";\n }\n }\n\n if (!options.fixExtension) return await import(modulePath);\n\n // When importing user modules:\n const userRequire = createRequire(\n pathToFileURL(process.cwd() + \"/package.json\")\n );\n const resolved = userRequire.resolve(modulePath);\n return await import(pathToFileURL(resolved) as any);\n\n return await import(correctedPath);\n}\n\n/**\n * Helps getting the current package manager from user agent\n *\n * @returns {string} the package manager\n * @default \"npm\"\n */\nexport function detectPackageManagerFromUserAgent(): string {\n const userAgent = process.env.npm_config_user_agent || \"\";\n\n if (!userAgent) return \"npm\";\n if (userAgent.includes(\"pnpm\")) return \"pnpm\";\n if (userAgent.includes(\"yarn\")) return \"yarn\";\n if (userAgent.includes(\"npm\")) return \"npm\";\n if (userAgent.includes(\"bun\")) return \"bun\";\n if (userAgent.includes(\"cnpm\")) return \"cnpm\";\n if (userAgent.includes(\"corepack\")) return \"corepack\";\n if (userAgent.includes(\"deno\")) return \"deno\";\n\n return \"npm\";\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  export declare function ensureDirectoryExists(dirPath: string): void;
2
2
  export declare function killServerChildProcess(): void;
3
- export declare function getVersion(): any;
3
+ export declare function getVersion(): string;