create-easy-stack 1.0.3

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 (327) hide show
  1. package/bin/create.mjs +244 -0
  2. package/infra/email/files/src/core/config/email.env.ts +73 -0
  3. package/infra/email/files/src/core/infrastructure/email/email-dispatcher.port.ts +13 -0
  4. package/infra/email/files/src/core/infrastructure/email/email-layout.spec.ts +83 -0
  5. package/infra/email/files/src/core/infrastructure/email/email-layout.ts +88 -0
  6. package/infra/email/files/src/core/infrastructure/email/email-sender.factory.spec.ts +87 -0
  7. package/infra/email/files/src/core/infrastructure/email/email-sender.factory.ts +35 -0
  8. package/infra/email/files/src/core/infrastructure/email/email-sender.port.ts +19 -0
  9. package/infra/email/files/src/core/infrastructure/email/email.job.spec.ts +101 -0
  10. package/infra/email/files/src/core/infrastructure/email/email.job.ts +64 -0
  11. package/infra/email/files/src/core/infrastructure/email/email.module.spec.ts +60 -0
  12. package/infra/email/files/src/core/infrastructure/email/email.module.ts +34 -0
  13. package/infra/email/files/src/core/infrastructure/email/log-email-sender.spec.ts +34 -0
  14. package/infra/email/files/src/core/infrastructure/email/log-email-sender.ts +17 -0
  15. package/infra/email/files/src/core/infrastructure/email/smtp-email-sender.spec.ts +99 -0
  16. package/infra/email/files/src/core/infrastructure/email/smtp-email-sender.ts +63 -0
  17. package/infra/email/infra.json +58 -0
  18. package/infra/prisma-postgres/docker.service.yml +12 -0
  19. package/infra/prisma-postgres/files/prisma/schema.prisma +10 -0
  20. package/infra/prisma-postgres/files/prisma.config.mjs +10 -0
  21. package/infra/prisma-postgres/files/src/core/config/database.env.ts +13 -0
  22. package/infra/prisma-postgres/files/src/core/infrastructure/database/database.module.ts +9 -0
  23. package/infra/prisma-postgres/files/src/core/infrastructure/database/prisma.service.ts +26 -0
  24. package/infra/prisma-postgres/infra.json +60 -0
  25. package/infra/rabbitmq/docker.service.yml +16 -0
  26. package/infra/rabbitmq/files/src/core/config/messaging.env.ts +29 -0
  27. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/inline-job-queue.spec.ts +60 -0
  28. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/inline-job-queue.ts +33 -0
  29. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-failure.spec.ts +23 -0
  30. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-failure.ts +19 -0
  31. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-payload-cipher.spec.ts +80 -0
  32. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-payload-cipher.ts +66 -0
  33. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-queue.boundary.spec.ts +34 -0
  34. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-queue.factory.ts +21 -0
  35. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-queue.module.spec.ts +75 -0
  36. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-queue.module.ts +30 -0
  37. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/job-queue.port.ts +59 -0
  38. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/rabbitmq-job-queue.spec.ts +510 -0
  39. package/infra/rabbitmq/files/src/core/infrastructure/messaging/jobs/rabbitmq-job-queue.ts +353 -0
  40. package/infra/rabbitmq/files/src/core/infrastructure/messaging/rabbitmq/rabbitmq.module.ts +9 -0
  41. package/infra/rabbitmq/files/src/core/infrastructure/messaging/rabbitmq/rabbitmq.service.spec.ts +289 -0
  42. package/infra/rabbitmq/files/src/core/infrastructure/messaging/rabbitmq/rabbitmq.service.ts +207 -0
  43. package/infra/rabbitmq/infra.json +55 -0
  44. package/infra/redis/docker.service.yml +10 -0
  45. package/infra/redis/files/src/core/http/decorators/rate-limit.decorator.ts +26 -0
  46. package/infra/redis/files/src/core/http/interceptors/rate-limit.interceptor.spec.ts +180 -0
  47. package/infra/redis/files/src/core/http/interceptors/rate-limit.interceptor.ts +105 -0
  48. package/infra/redis/files/src/core/infrastructure/redis/cache.constants.ts +67 -0
  49. package/infra/redis/files/src/core/infrastructure/redis/idempotency/idempotency.module.ts +9 -0
  50. package/infra/redis/files/src/core/infrastructure/redis/idempotency/idempotency.service.spec.ts +146 -0
  51. package/infra/redis/files/src/core/infrastructure/redis/idempotency/idempotency.service.ts +131 -0
  52. package/infra/redis/files/src/core/infrastructure/redis/lock/lock.module.ts +9 -0
  53. package/infra/redis/files/src/core/infrastructure/redis/lock/lock.service.integration-spec.ts +111 -0
  54. package/infra/redis/files/src/core/infrastructure/redis/lock/lock.service.ts +82 -0
  55. package/infra/redis/files/src/core/infrastructure/redis/rate-limit/rate-limit.module.ts +15 -0
  56. package/infra/redis/files/src/core/infrastructure/redis/rate-limit/rate-limit.service.spec.ts +45 -0
  57. package/infra/redis/files/src/core/infrastructure/redis/rate-limit/rate-limit.service.ts +38 -0
  58. package/infra/redis/files/src/core/infrastructure/redis/redis.module.ts +9 -0
  59. package/infra/redis/files/src/core/infrastructure/redis/redis.service.ts +196 -0
  60. package/infra/redis/infra.json +53 -0
  61. package/infra/storage-cloudinary/files/src/core/config/storage.env.ts +43 -0
  62. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/cloudinary-image-storage.spec.ts +275 -0
  63. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/cloudinary-image-storage.ts +158 -0
  64. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/image-storage.factory.ts +30 -0
  65. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/image-storage.module.ts +17 -0
  66. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/image-storage.port.ts +38 -0
  67. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/image-type.spec.ts +48 -0
  68. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/image-type.ts +25 -0
  69. package/infra/storage-cloudinary/files/src/core/infrastructure/storage/unconfigured-image-storage.ts +19 -0
  70. package/infra/storage-cloudinary/infra.json +73 -0
  71. package/lib/fs-utils.mjs +115 -0
  72. package/lib/registry.mjs +50 -0
  73. package/lib/scaffold.mjs +157 -0
  74. package/package.json +37 -0
  75. package/templates/nest-ddd/files/.env.example +5 -0
  76. package/templates/nest-ddd/files/.husky/commit-msg +1 -0
  77. package/templates/nest-ddd/files/.husky/pre-commit +1 -0
  78. package/templates/nest-ddd/files/.oxlintrc.json +10 -0
  79. package/templates/nest-ddd/files/.prettierrc +4 -0
  80. package/templates/nest-ddd/files/_gitignore +40 -0
  81. package/templates/nest-ddd/files/commitlint.config.js +3 -0
  82. package/templates/nest-ddd/files/nest-cli.json +8 -0
  83. package/templates/nest-ddd/files/package.json +66 -0
  84. package/templates/nest-ddd/files/plop-templates/command/command.ts.hbs +5 -0
  85. package/templates/nest-ddd/files/plop-templates/command/handler.ts.hbs +30 -0
  86. package/templates/nest-ddd/files/plop-templates/module/application/commands/create-{{kebab}}.command.ts.hbs +5 -0
  87. package/templates/nest-ddd/files/plop-templates/module/application/commands/create-{{kebab}}.handler.spec.ts.hbs +35 -0
  88. package/templates/nest-ddd/files/plop-templates/module/application/commands/create-{{kebab}}.handler.ts.hbs +25 -0
  89. package/templates/nest-ddd/files/plop-templates/module/application/index.ts.hbs +5 -0
  90. package/templates/nest-ddd/files/plop-templates/module/application/queries/get-{{kebab}}-by-id.handler.ts.hbs +29 -0
  91. package/templates/nest-ddd/files/plop-templates/module/application/queries/get-{{kebab}}-by-id.query.ts.hbs +5 -0
  92. package/templates/nest-ddd/files/plop-templates/module/domain/entities/{{kebab}}.entity.ts.hbs +37 -0
  93. package/templates/nest-ddd/files/plop-templates/module/domain/events/{{kebab}}-created.event.ts.hbs +10 -0
  94. package/templates/nest-ddd/files/plop-templates/module/domain/exceptions/{{kebab}}.exception.ts.hbs +11 -0
  95. package/templates/nest-ddd/files/plop-templates/module/domain/index.ts.hbs +4 -0
  96. package/templates/nest-ddd/files/plop-templates/module/domain/repositories/{{kebab}}.repository.ts.hbs +7 -0
  97. package/templates/nest-ddd/files/plop-templates/module/presentation/controllers/{{kebab}}.controller.ts.hbs +53 -0
  98. package/templates/nest-ddd/files/plop-templates/module/presentation/dtos/create-{{kebab}}.dto.ts.hbs +10 -0
  99. package/templates/nest-ddd/files/plop-templates/module/presentation/dtos/{{kebab}}-response.dto.ts.hbs +15 -0
  100. package/templates/nest-ddd/files/plop-templates/module/presentation/index.ts.hbs +4 -0
  101. package/templates/nest-ddd/files/plop-templates/module/presentation/mappers/{{kebab}}.mapper.ts.hbs +13 -0
  102. package/templates/nest-ddd/files/plop-templates/module/{{kebab}}.module.ts.hbs +40 -0
  103. package/templates/nest-ddd/files/plop-templates/persistence-memory/infrastructure/database/repositories/in-memory-{{kebab}}.repository.ts.hbs +17 -0
  104. package/templates/nest-ddd/files/plop-templates/persistence-memory/infrastructure/index.ts.hbs +1 -0
  105. package/templates/nest-ddd/files/plop-templates/persistence-prisma/infrastructure/database/mappers/{{kebab}}.mapper.ts.hbs +29 -0
  106. package/templates/nest-ddd/files/plop-templates/persistence-prisma/infrastructure/database/repositories/prisma-{{kebab}}.repository.ts.hbs +28 -0
  107. package/templates/nest-ddd/files/plop-templates/persistence-prisma/infrastructure/index.ts.hbs +2 -0
  108. package/templates/nest-ddd/files/plop-templates/query/handler.ts.hbs +28 -0
  109. package/templates/nest-ddd/files/plop-templates/query/query.ts.hbs +5 -0
  110. package/templates/nest-ddd/files/plop-templates/snippets/error-codes.hbs +14 -0
  111. package/templates/nest-ddd/files/plop-templates/snippets/prisma-model.hbs +7 -0
  112. package/templates/nest-ddd/files/plopfile.mjs +186 -0
  113. package/templates/nest-ddd/files/src/app.controller.ts +13 -0
  114. package/templates/nest-ddd/files/src/app.module.ts +26 -0
  115. package/templates/nest-ddd/files/src/core/config/app.config.ts +9 -0
  116. package/templates/nest-ddd/files/src/core/config/env.validation.ts +30 -0
  117. package/templates/nest-ddd/files/src/core/domain/base/aggregate-root.base.ts +18 -0
  118. package/templates/nest-ddd/files/src/core/domain/base/domain-event.base.ts +7 -0
  119. package/templates/nest-ddd/files/src/core/domain/base/entity.base.ts +36 -0
  120. package/templates/nest-ddd/files/src/core/domain/base/value-object.base.ts +17 -0
  121. package/templates/nest-ddd/files/src/core/domain/exceptions/domain.exception.ts +16 -0
  122. package/templates/nest-ddd/files/src/core/domain/exceptions/error-codes.ts +28 -0
  123. package/templates/nest-ddd/files/src/core/domain/types/pagination.ts +9 -0
  124. package/templates/nest-ddd/files/src/core/http/decorators/client-info.decorator.ts +24 -0
  125. package/templates/nest-ddd/files/src/core/http/decorators/current-user.decorator.ts +19 -0
  126. package/templates/nest-ddd/files/src/core/http/dtos/paginated-response.dto.ts +29 -0
  127. package/templates/nest-ddd/files/src/core/http/dtos/pagination-query.dto.ts +17 -0
  128. package/templates/nest-ddd/files/src/core/http/filters/all-exceptions.filter.spec.ts +163 -0
  129. package/templates/nest-ddd/files/src/core/http/filters/all-exceptions.filter.ts +97 -0
  130. package/templates/nest-ddd/files/src/core/http/guards/max-body-size.guard.spec.ts +47 -0
  131. package/templates/nest-ddd/files/src/core/http/guards/max-body-size.guard.ts +31 -0
  132. package/templates/nest-ddd/files/src/core/http/interceptors/logging.interceptor.ts +37 -0
  133. package/templates/nest-ddd/files/src/core/http/interceptors/response.interceptor.ts +53 -0
  134. package/templates/nest-ddd/files/src/core/http/logging/app.logger.ts +34 -0
  135. package/templates/nest-ddd/files/src/core/index.ts +33 -0
  136. package/templates/nest-ddd/files/src/core/utils/correlation-id.util.spec.ts +29 -0
  137. package/templates/nest-ddd/files/src/core/utils/correlation-id.util.ts +15 -0
  138. package/templates/nest-ddd/files/src/core/utils/hash.util.spec.ts +61 -0
  139. package/templates/nest-ddd/files/src/core/utils/hash.util.ts +47 -0
  140. package/templates/nest-ddd/files/src/core/utils/snowflake.util.spec.ts +40 -0
  141. package/templates/nest-ddd/files/src/core/utils/snowflake.util.ts +99 -0
  142. package/templates/nest-ddd/files/src/core/utils/string.util.spec.ts +20 -0
  143. package/templates/nest-ddd/files/src/core/utils/string.util.ts +21 -0
  144. package/templates/nest-ddd/files/src/core/utils/time.util.spec.ts +25 -0
  145. package/templates/nest-ddd/files/src/core/utils/time.util.ts +25 -0
  146. package/templates/nest-ddd/files/src/core/utils/ttl.util.ts +22 -0
  147. package/templates/nest-ddd/files/src/main.ts +61 -0
  148. package/templates/nest-ddd/files/test/setup.ts +6 -0
  149. package/templates/nest-ddd/files/tsconfig.build.json +9 -0
  150. package/templates/nest-ddd/files/tsconfig.json +28 -0
  151. package/templates/nest-ddd/files/vitest.config.e2e.ts +15 -0
  152. package/templates/nest-ddd/files/vitest.config.ts +16 -0
  153. package/templates/nest-ddd/template.json +8 -0
  154. package/templates/node-express/files/.env.example +28 -0
  155. package/templates/node-express/files/docker-compose.yml +52 -0
  156. package/templates/node-express/files/package-lock.json +11880 -0
  157. package/templates/node-express/files/package.json +43 -0
  158. package/templates/node-express/files/server.js +13 -0
  159. package/templates/node-express/files/src/app.js +72 -0
  160. package/templates/node-express/files/src/auth/authUtils.js +116 -0
  161. package/templates/node-express/files/src/auth/checkAuth.js +61 -0
  162. package/templates/node-express/files/src/bucket_pattern/comment.model.js +27 -0
  163. package/templates/node-express/files/src/bucket_pattern/comment.service.js +50 -0
  164. package/templates/node-express/files/src/config/config.aws-s3.js +28 -0
  165. package/templates/node-express/files/src/config/config.cloudinary.js +13 -0
  166. package/templates/node-express/files/src/config/config.mongodb.js +25 -0
  167. package/templates/node-express/files/src/config/config.multer.js +25 -0
  168. package/templates/node-express/files/src/config/config.nodemailer.js +16 -0
  169. package/templates/node-express/files/src/controllers/access.controller.js +49 -0
  170. package/templates/node-express/files/src/controllers/cart.controller.js +38 -0
  171. package/templates/node-express/files/src/controllers/checkout.controller.js +15 -0
  172. package/templates/node-express/files/src/controllers/comment.controller.js +29 -0
  173. package/templates/node-express/files/src/controllers/discount.controller.js +68 -0
  174. package/templates/node-express/files/src/controllers/email.controller.js +16 -0
  175. package/templates/node-express/files/src/controllers/inventory.controller.js +15 -0
  176. package/templates/node-express/files/src/controllers/notification.controller.js +15 -0
  177. package/templates/node-express/files/src/controllers/product.controller.js +175 -0
  178. package/templates/node-express/files/src/controllers/profile.controller.js +65 -0
  179. package/templates/node-express/files/src/controllers/rbac.controller.js +41 -0
  180. package/templates/node-express/files/src/controllers/template.controller.js +20 -0
  181. package/templates/node-express/files/src/controllers/upload.controller.js +56 -0
  182. package/templates/node-express/files/src/controllers/user.controller.js +36 -0
  183. package/templates/node-express/files/src/core/error.response.js +84 -0
  184. package/templates/node-express/files/src/core/success.response.js +44 -0
  185. package/templates/node-express/files/src/database/init.mongodb.level0.js +16 -0
  186. package/templates/node-express/files/src/database/init.mongodb.level1.js +36 -0
  187. package/templates/node-express/files/src/database/init.redis.js +119 -0
  188. package/templates/node-express/files/src/helpers/asyncHandler.js +7 -0
  189. package/templates/node-express/files/src/helpers/check.connect.js +29 -0
  190. package/templates/node-express/files/src/keys/private_key.pem +28 -0
  191. package/templates/node-express/files/src/keys/public_key.pem +9 -0
  192. package/templates/node-express/files/src/logger/discord.log.js +26 -0
  193. package/templates/node-express/files/src/logger/discord.log.v2.js +56 -0
  194. package/templates/node-express/files/src/logger/mylogger.log.js +130 -0
  195. package/templates/node-express/files/src/logger/winston.log.js +27 -0
  196. package/templates/node-express/files/src/middlewares/index.js +21 -0
  197. package/templates/node-express/files/src/middlewares/rbac.js +37 -0
  198. package/templates/node-express/files/src/middlewares/role.middleware.js +12 -0
  199. package/templates/node-express/files/src/models/KeyToken.model.js +37 -0
  200. package/templates/node-express/files/src/models/apiKey.model.js +31 -0
  201. package/templates/node-express/files/src/models/cart.model.js +47 -0
  202. package/templates/node-express/files/src/models/comment.model.js +43 -0
  203. package/templates/node-express/files/src/models/discount.model.js +92 -0
  204. package/templates/node-express/files/src/models/inventory.model.js +42 -0
  205. package/templates/node-express/files/src/models/notification.model.js +52 -0
  206. package/templates/node-express/files/src/models/order.model.js +68 -0
  207. package/templates/node-express/files/src/models/otp.model.js +32 -0
  208. package/templates/node-express/files/src/models/product.model.js +144 -0
  209. package/templates/node-express/files/src/models/repository/cart.repo.js +71 -0
  210. package/templates/node-express/files/src/models/repository/discount.repo.js +63 -0
  211. package/templates/node-express/files/src/models/repository/inventory.repo.js +45 -0
  212. package/templates/node-express/files/src/models/repository/product.repo.js +145 -0
  213. package/templates/node-express/files/src/models/repository/shop.repo.js +18 -0
  214. package/templates/node-express/files/src/models/repository/spu.repo.js +18 -0
  215. package/templates/node-express/files/src/models/repository/user.repo.js +20 -0
  216. package/templates/node-express/files/src/models/resource.model.js +32 -0
  217. package/templates/node-express/files/src/models/role.model.js +57 -0
  218. package/templates/node-express/files/src/models/shop.model.js +43 -0
  219. package/templates/node-express/files/src/models/sku.model.js +81 -0
  220. package/templates/node-express/files/src/models/spu.model.js +101 -0
  221. package/templates/node-express/files/src/models/template.model.js +25 -0
  222. package/templates/node-express/files/src/models/user.model.js +82 -0
  223. package/templates/node-express/files/src/postman/access.post.http +22 -0
  224. package/templates/node-express/files/src/routes/access/index.route.js +21 -0
  225. package/templates/node-express/files/src/routes/cart/index.route.js +20 -0
  226. package/templates/node-express/files/src/routes/checkout/index.route.js +10 -0
  227. package/templates/node-express/files/src/routes/comment/index.route.js +16 -0
  228. package/templates/node-express/files/src/routes/discount/index.route.js +26 -0
  229. package/templates/node-express/files/src/routes/index.route.js +27 -0
  230. package/templates/node-express/files/src/routes/inventory/index.route.js +11 -0
  231. package/templates/node-express/files/src/routes/notification/index.route.js +14 -0
  232. package/templates/node-express/files/src/routes/product/index.route.js +38 -0
  233. package/templates/node-express/files/src/routes/profile/index.route.js +15 -0
  234. package/templates/node-express/files/src/routes/rbac/index.route.js +21 -0
  235. package/templates/node-express/files/src/routes/template/index.route.js +11 -0
  236. package/templates/node-express/files/src/routes/upload/index.route.js +28 -0
  237. package/templates/node-express/files/src/routes/user/index.route.js +13 -0
  238. package/templates/node-express/files/src/services/access.service.js +257 -0
  239. package/templates/node-express/files/src/services/apiKey.service.js +15 -0
  240. package/templates/node-express/files/src/services/cart.service.js +115 -0
  241. package/templates/node-express/files/src/services/checkout.service.js +218 -0
  242. package/templates/node-express/files/src/services/comment.service.js +185 -0
  243. package/templates/node-express/files/src/services/discount.service.js +282 -0
  244. package/templates/node-express/files/src/services/email.service.js +71 -0
  245. package/templates/node-express/files/src/services/inventory.service.js +35 -0
  246. package/templates/node-express/files/src/services/keyToken.service.js +77 -0
  247. package/templates/node-express/files/src/services/notification.service.js +58 -0
  248. package/templates/node-express/files/src/services/otp.service.js +36 -0
  249. package/templates/node-express/files/src/services/product.service.js +228 -0
  250. package/templates/node-express/files/src/services/rbac.service.js +143 -0
  251. package/templates/node-express/files/src/services/redis.service.js +57 -0
  252. package/templates/node-express/files/src/services/redisPubSub.service.js +72 -0
  253. package/templates/node-express/files/src/services/shop.service.js +21 -0
  254. package/templates/node-express/files/src/services/sku.service.js +52 -0
  255. package/templates/node-express/files/src/services/spu.service.js +89 -0
  256. package/templates/node-express/files/src/services/template.service.js +41 -0
  257. package/templates/node-express/files/src/services/upload.s3.service.js +55 -0
  258. package/templates/node-express/files/src/services/upload.service.js +74 -0
  259. package/templates/node-express/files/src/services/user.service.js +92 -0
  260. package/templates/node-express/files/src/temp/1734420604996-ci-cd.png +0 -0
  261. package/templates/node-express/files/src/temp/1734421222213-cover-fb.jpg +0 -0
  262. package/templates/node-express/files/src/temp/1734421222214-cover-fb-01.jpg +0 -0
  263. package/templates/node-express/files/src/temp/1734421293437-cover-fb-01.jpg +0 -0
  264. package/templates/node-express/files/src/temp/1734421293437-cover-fb.jpg +0 -0
  265. package/templates/node-express/files/src/tests/inventory.test.js +21 -0
  266. package/templates/node-express/files/src/tests/message_queue/kafka/consumer.js +23 -0
  267. package/templates/node-express/files/src/tests/message_queue/kafka/producer.js +21 -0
  268. package/templates/node-express/files/src/tests/message_queue/rabbitMQ/consumer.js +28 -0
  269. package/templates/node-express/files/src/tests/message_queue/rabbitMQ/ordered.consumer.js +26 -0
  270. package/templates/node-express/files/src/tests/message_queue/rabbitMQ/ordered.producer.js +31 -0
  271. package/templates/node-express/files/src/tests/message_queue/rabbitMQ/producer.js +26 -0
  272. package/templates/node-express/files/src/tests/message_queue/rabbitMQ/producerDLX.js +44 -0
  273. package/templates/node-express/files/src/tests/mysql/connect.js +59 -0
  274. package/templates/node-express/files/src/tests/product.test.js +14 -0
  275. package/templates/node-express/files/src/utils/index.js +78 -0
  276. package/templates/node-express/files/src/utils/reasonPhrases.js +344 -0
  277. package/templates/node-express/files/src/utils/statusCodes.js +344 -0
  278. package/templates/node-express/files/src/utils/template.html.js +38 -0
  279. package/templates/node-express/template.json +11 -0
  280. package/templates/react-fsd/files/index.html +13 -0
  281. package/templates/react-fsd/files/package.json +15 -0
  282. package/templates/react-fsd/files/public/favicon.svg +1 -0
  283. package/templates/react-fsd/files/public/icons.svg +24 -0
  284. package/templates/react-fsd/files/src/assets/hero.png +0 -0
  285. package/templates/react-fsd/files/src/assets/typescript.svg +1 -0
  286. package/templates/react-fsd/files/src/assets/vite.svg +1 -0
  287. package/templates/react-fsd/files/src/counter.ts +9 -0
  288. package/templates/react-fsd/files/src/main.ts +60 -0
  289. package/templates/react-fsd/files/src/style.css +296 -0
  290. package/templates/react-fsd/files/tsconfig.json +24 -0
  291. package/templates/react-fsd/template.json +11 -0
  292. package/templates/react-monolithic/files/index.html +13 -0
  293. package/templates/react-monolithic/files/package.json +15 -0
  294. package/templates/react-monolithic/files/public/favicon.svg +1 -0
  295. package/templates/react-monolithic/files/public/icons.svg +24 -0
  296. package/templates/react-monolithic/files/src/assets/hero.png +0 -0
  297. package/templates/react-monolithic/files/src/assets/typescript.svg +1 -0
  298. package/templates/react-monolithic/files/src/assets/vite.svg +1 -0
  299. package/templates/react-monolithic/files/src/counter.ts +9 -0
  300. package/templates/react-monolithic/files/src/main.ts +60 -0
  301. package/templates/react-monolithic/files/src/style.css +296 -0
  302. package/templates/react-monolithic/files/tsconfig.json +24 -0
  303. package/templates/react-monolithic/template.json +11 -0
  304. package/templates/vue-fsd/files/index.html +13 -0
  305. package/templates/vue-fsd/files/package.json +15 -0
  306. package/templates/vue-fsd/files/public/favicon.svg +1 -0
  307. package/templates/vue-fsd/files/public/icons.svg +24 -0
  308. package/templates/vue-fsd/files/src/assets/hero.png +0 -0
  309. package/templates/vue-fsd/files/src/assets/typescript.svg +1 -0
  310. package/templates/vue-fsd/files/src/assets/vite.svg +1 -0
  311. package/templates/vue-fsd/files/src/counter.ts +9 -0
  312. package/templates/vue-fsd/files/src/main.ts +60 -0
  313. package/templates/vue-fsd/files/src/style.css +296 -0
  314. package/templates/vue-fsd/files/tsconfig.json +24 -0
  315. package/templates/vue-fsd/template.json +11 -0
  316. package/templates/vue-monolithic/files/index.html +13 -0
  317. package/templates/vue-monolithic/files/package.json +15 -0
  318. package/templates/vue-monolithic/files/public/favicon.svg +1 -0
  319. package/templates/vue-monolithic/files/public/icons.svg +24 -0
  320. package/templates/vue-monolithic/files/src/assets/hero.png +0 -0
  321. package/templates/vue-monolithic/files/src/assets/typescript.svg +1 -0
  322. package/templates/vue-monolithic/files/src/assets/vite.svg +1 -0
  323. package/templates/vue-monolithic/files/src/counter.ts +9 -0
  324. package/templates/vue-monolithic/files/src/main.ts +60 -0
  325. package/templates/vue-monolithic/files/src/style.css +296 -0
  326. package/templates/vue-monolithic/files/tsconfig.json +24 -0
  327. package/templates/vue-monolithic/template.json +11 -0
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ const redis = require("redis");
4
+ const { RedisConnectionError } = require("../core/error.response");
5
+ // redisClient is used to connect to the redis server
6
+ // redis server is used to store the data in key-value pairs
7
+ // redis server is located in the same machine as the application
8
+ /** level 1: connect to redis server */
9
+ // const redisClient = redis.createClient({
10
+ // host: process.env.REDIS_HOST,
11
+ // port: process.env.REDIS_PORT,
12
+ // password: process.env.REDIS_PASSWORD,
13
+ // username: process.env.REDIS_USERNAME,
14
+ // });
15
+
16
+ // redisClient.ping((err, res) => {
17
+ // if (err) {
18
+ // console.log("err:::error connecting to redis", err);
19
+ // } else {
20
+ // console.log("res:::connected to redis", res);
21
+ // }
22
+ // });
23
+
24
+ // redisClient.on("error", (err) => {
25
+ // console.log("err:::error connecting to redis", err);
26
+ // });
27
+
28
+ // module.exports = redisClient;
29
+
30
+ /** level 2: connect to redis server using redis-cli */
31
+ // a connection is a client - an instance to a pool of connections
32
+ // we can have multiple connections to the same redis server (pool of connections)
33
+ let client = {};
34
+ const REDIS_CONNECT_TIMEOUT = 10000;
35
+ const REDIS_CONNECT_MESSAGE = {
36
+ code: -99,
37
+ message: {
38
+ vn: "Redis bị lỗi rồi",
39
+ en: "Redis is error",
40
+ },
41
+ };
42
+ let statusConnectRedis = {
43
+ CONNECT: "connect",
44
+ END: "end",
45
+ RECONNECT: "reconnect",
46
+ DISCONNECT: "disconnect",
47
+ ERROR: "error",
48
+ };
49
+ let connectionTimeoutNumber;
50
+
51
+ const handleEventConnectRedis = ({ connectionRedis }) => {
52
+ if (!connectionRedis) return;
53
+ connectionRedis.on(statusConnectRedis.CONNECT, () => {
54
+ console.log("res:::connected to redis");
55
+ });
56
+ connectionRedis.on(statusConnectRedis.END, () => {
57
+ console.log("res:::end connection to redis");
58
+ handleTimeoutConnectRedis(connectionRedis);
59
+ });
60
+ connectionRedis.on(statusConnectRedis.RECONNECT, () => {
61
+ console.log("res:::reconnect to redis");
62
+ clearTimeout(connectionTimeoutNumber);
63
+ });
64
+ connectionRedis.on(statusConnectRedis.DISCONNECT, () => {
65
+ console.log("res:::disconnect to redis");
66
+ });
67
+ connectionRedis.on(statusConnectRedis.ERROR, (err) => {
68
+ console.log("res:::error connecting to redis", err);
69
+ // retry connect to redis
70
+ handleTimeoutConnectRedis(connectionRedis);
71
+ });
72
+ };
73
+
74
+ const handleTimeoutConnectRedis = (connectionRedis) => {
75
+ if (!connectionRedis) return;
76
+ connectionTimeoutNumber = connectionRedis.setTimeout(
77
+ REDIS_CONNECT_TIMEOUT,
78
+ () => {
79
+ throw new RedisConnectionError({
80
+ message: REDIS_CONNECT_MESSAGE.message.vn,
81
+ statusCode: REDIS_CONNECT_MESSAGE.code,
82
+ });
83
+ }
84
+ );
85
+ };
86
+
87
+ const initRedis = () => {
88
+ const instanceRedis = redis.createClient();
89
+ client.instanceConnect = instanceRedis;
90
+ handleEventConnectRedis(instanceRedis);
91
+ handleTimeoutConnectRedis(instanceRedis);
92
+ };
93
+
94
+ const getRedis = () => client;
95
+
96
+ const closeRedis = () => {
97
+ if (!client.instanceConnect) return;
98
+ client.instanceConnect.quit();
99
+ client.instanceConnect = null;
100
+ };
101
+
102
+ module.exports = {
103
+ initRedis,
104
+ getRedis,
105
+ closeRedis,
106
+ };
107
+
108
+ /**
109
+ To connect to redis server, we need to supply the following information:
110
+ - host: the host of the redis server
111
+ - port: the port of the redis server
112
+ - password: the password of the redis server
113
+ - username: the username of the redis server
114
+ because redis server is a database like mysql, postgresql, etc.
115
+ we need to supply the host, port, password, username to connect to the redis server
116
+ redis server could be local or remote
117
+ if redis server is local, we can use the default host and port
118
+ if redis server is remote, we need to supply the host, port, password, username
119
+ */
@@ -0,0 +1,7 @@
1
+ const asyncHandler = (fn) => {
2
+ return (req, res, next) => {
3
+ fn(req, res, next).catch(next);
4
+ };
5
+ };
6
+
7
+ module.exports = asyncHandler;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const mongoose = require("mongoose");
4
+ const os = require("os");
5
+ const process = require("process");
6
+ const _SECONDS = 5000;
7
+
8
+ // count connection
9
+ const countConnect = () => {
10
+ const numConnection = mongoose.connections.length;
11
+ console.log(`Number of connections:::${numConnection}`);
12
+ };
13
+
14
+ // check overload
15
+ const checkOverload = () => {
16
+ setInterval(() => {
17
+ const numConnection = mongoose.connections.length;
18
+ const numCores = os.cpus().length;
19
+ const memoryUsage = process.memoryUsage().rss;
20
+ // Example maximum number of connections per core is 5
21
+ console.log(`Memory usage::${memoryUsage / 1024 / 1024} MB`);
22
+ console.log(`Active connections::::${numConnection}`);
23
+ const maxConnections = numCores * 5;
24
+ if (numConnection > maxConnections) {
25
+ console.log("Connections overload detected");
26
+ }
27
+ }, _SECONDS);
28
+ };
29
+ module.exports = { countConnect, checkOverload };
@@ -0,0 +1,28 @@
1
+ -----BEGIN PRIVATE KEY-----
2
+ MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8Zd3WVhm7vKLD
3
+ xbeWZc9kSVhYnOlLMP/1NEU1hL06pNdaf64126WIpA9/Z1DrgLkM1ktWxPKt62/c
4
+ iAWsijwBmZ3+0QNTDsg/siFGDkt9saJNS8S+ybrGD9f/DOsdm1HfHKmLQaL0U6nW
5
+ Rw4QtU7XgYSvb2TUA44p4Pi6tpFNzdA+2XR6uvWWzCsvBlzzQZ/jo93hOTiGb7YC
6
+ 3ASdElDyXs19R+0n3m/PJdla9iXEIfY7sbMdJdPIid9hao9rglB2lsseik/hXHVa
7
+ 5gZBgJrfU+07ccW7KlzSVBhopBY0NzXeIH5wEMMbgszmh4ZqffIVI69ZB7rMuv7o
8
+ Lr4OosebAgMBAAECggEAV1L8LUIBcYRxCT9W5i5Qn9JjUceBVyniKhzNS444S7tm
9
+ Wns+G5awtpIc4NfZqR8kJvAZQaHOPpEXa2fdAWmdgLxcgGUPHmuGpAeD5r3vfdZd
10
+ PWi2TByjJvTnEEBDpph8rWbSq0qEJq201i5fNZ1kav2Mq+h9Gsx/E6hEgf7ngODu
11
+ HHS76xIYLHy7o+cxsLkGOTXt1YYueF9nOAkhKGAIifcLcX+CW76fTNcIQPLjPoHk
12
+ Pmst/NGgWCPw3AJTFSaD37vplRS149PUyZpkwPxzLbk+yA8ft8LUp+e5HhplfBvo
13
+ VDrBjSBtaR9R6p5Gk5IRdWxofuVGg2BT0tTRuQTmaQKBgQDnaoa9i2qaTey+gRAm
14
+ Ws6b7RotUY9eK4G0pIAEKWGTBeC6EgLODb5QbJy0nTbu2IQhoUx4z8+JOyI53jAg
15
+ 1VHnOMF+EnadRaQdZACXzKJdoOJ0meu91F1pOhlVY5fEZngBim92AiCMio904iVr
16
+ UVXFfr3VnhJlzRmaPQAaTzaSdwKBgQDQaXB3+8t4iAdYHHr/zzrfVeBF0Mg3jtGG
17
+ KhByv7ZuXm9Q5H2T+twhNbLxWdSEd1vnoS8yMeaPGmBh0MR49PNUMjatX2v3gaO5
18
+ lYhY9p+fPrnovQxf176c67eFcSR1jHB/OGceKAZJ2hpYeyy1QQwElA5f3fwSDdLV
19
+ 1LLeqCY4/QKBgQDYxOtT7506zxWdWW4UT2lLm+yyWLzP/DbyTEjyHQUeYBoika54
20
+ 71y/Hw4nDUEguEYE7n+ghyCjLnYf+KXii4+95GczPf5H0a0qLrtzdib9Ry/5AxlU
21
+ 5vFdGSQT3UeTnFx7LP69br6ohz5bwV5FyZlrdw5BZGFdZKK/3LYU7vByfwKBgGuy
22
+ MMYvvYM5d+IWRZEvOxLxw4UQUIY1LRyRXBKP8uuxrQA2MpZniZ03rJJ/gww4yas2
23
+ Zbcghi3oyWmCgiSnH56gnBSXPKmXuk1KcjzWpMGbnmIgXuagDAX24Mz6HIcJ3ZBA
24
+ SzkQIb/EDt0uOXoodNdg0tTDV2DU9+A7m3rnlWjZAoGAE3ijGsdogIkgKrOics/K
25
+ t8v7+ug3yo3opK77yNc60nOXicE2SqyQhhTYUOcL/YYs6ptrm1ExQaJ2ErLUBUVE
26
+ akOkM0fKtxvMHBjU3dyjhMz94DfDcNeB4lH5ehV8gIriYwmXGGrneQQ61yAtj+j+
27
+ /mfWkBNrR8DHZiry8c/ZibE=
28
+ -----END PRIVATE KEY-----
@@ -0,0 +1,9 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvGXd1lYZu7yiw8W3lmXP
3
+ ZElYWJzpSzD/9TRFNYS9OqTXWn+uNduliKQPf2dQ64C5DNZLVsTyretv3IgFrIo8
4
+ AZmd/tEDUw7IP7IhRg5LfbGiTUvEvsm6xg/X/wzrHZtR3xypi0Gi9FOp1kcOELVO
5
+ 14GEr29k1AOOKeD4uraRTc3QPtl0err1lswrLwZc80Gf46Pd4Tk4hm+2AtwEnRJQ
6
+ 8l7NfUftJ95vzyXZWvYlxCH2O7GzHSXTyInfYWqPa4JQdpbLHopP4Vx1WuYGQYCa
7
+ 31PtO3HFuypc0lQYaKQWNDc13iB+cBDDG4LM5oeGan3yFSOvWQe6zLr+6C6+DqLH
8
+ mwIDAQAB
9
+ -----END PUBLIC KEY-----
@@ -0,0 +1,26 @@
1
+ // 1314221126024560650
2
+ "use strict";
3
+
4
+ const { Client, GatewayIntentBits } = require("discord.js");
5
+ const client = new Client({
6
+ intents: [
7
+ GatewayIntentBits.DirectMessages,
8
+ GatewayIntentBits.Guilds,
9
+ GatewayIntentBits.GuildMessages,
10
+ GatewayIntentBits.MessageContent,
11
+ ],
12
+ });
13
+
14
+ client.on("ready", () => {
15
+ console.log(`Logged is as ${client.user.tag}`);
16
+ });
17
+
18
+ // const token = process.env.TOKEN_DISCORD;
19
+ client.login(token);
20
+
21
+ client.on("messageCreate", (msg) => {
22
+ if (msg.author.bot) return;
23
+ if (msg.content.toLowerCase() === "hello") {
24
+ msg.reply("Hello, How can I help you!");
25
+ }
26
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ const { Client, GatewayIntentBits } = require("discord.js");
4
+ require("dotenv").config();
5
+ const { CHANNEL_ID, TOKEN_DISCORD } = process.env;
6
+
7
+ class LoggerService {
8
+ constructor() {
9
+ this.client = new Client({
10
+ intents: [
11
+ GatewayIntentBits.DirectMessages,
12
+ GatewayIntentBits.Guilds,
13
+ GatewayIntentBits.GuildMessages,
14
+ GatewayIntentBits.MessageContent,
15
+ ],
16
+ });
17
+ // add channelId
18
+ this.channelId = CHANNEL_ID;
19
+ this.client.on("ready", () => {
20
+ console.log(`Logged is as ${this.client.user.tag}`);
21
+ });
22
+ this.client.login(TOKEN_DISCORD);
23
+ }
24
+
25
+ sendToMessage(message = "message") {
26
+ const channel = this.client.channels.cache.get(this.channelId);
27
+ if (!channel) {
28
+ console.error(`Could not find the channel...`, this.channelId);
29
+ return;
30
+ }
31
+ channel.send(message).catch((e) => console.error(e));
32
+ }
33
+
34
+ sendToFormatCode(logData) {
35
+ const {
36
+ code,
37
+ message = "This is some additional information about the code",
38
+ title = "Code Example",
39
+ } = logData;
40
+ const codeMessage = {
41
+ content: message,
42
+ embeds: [
43
+ {
44
+ color: parseInt("00ff00", 16),
45
+ title,
46
+ description: "```json\n" + JSON.stringify(code, null, 2) + "\n ```",
47
+ },
48
+ ],
49
+ };
50
+ this.sendToMessage(codeMessage);
51
+ }
52
+ }
53
+
54
+ // const loggerService = new LoggerService();
55
+ module.exports = new LoggerService();
56
+ // Discord password: Thinh09122003
@@ -0,0 +1,130 @@
1
+ const winston = require("winston");
2
+ require("winston-daily-rotate-file");
3
+ const { v4: uuidv4 } = require("uuid");
4
+ // level: error, warn, info, verbose, debug
5
+
6
+ class MyLogger {
7
+ constructor() {
8
+ const formatPrint = winston.format.printf(
9
+ ({ level, message, timestamp, context, requestId, metadata }) => {
10
+ return `[${timestamp}] - [${level}] - [${context}] - [${requestId}] - [${JSON.stringify(
11
+ metadata
12
+ )}] - ${message}`;
13
+ }
14
+ );
15
+
16
+ this.logger = winston.createLogger({
17
+ level: "info",
18
+ format: winston.format.combine(
19
+ winston.format.timestamp({
20
+ format: "YYYY-MM-DD HH:mm:ss",
21
+ }),
22
+ formatPrint
23
+ ),
24
+ transports: [
25
+ new winston.transports.Console(),
26
+ new winston.transports.DailyRotateFile({
27
+ filename: "logs/application-%DATE%.info.log",
28
+ dirname: "./src/logs",
29
+ datePattern: "YYYY-MM-DD",
30
+ zippedArchive: true, // true: compress the file after maxSize before deleting (backup)
31
+ maxSize: "20m", // 20mb => create new file if over 20mb
32
+ maxFiles: "14d", // all logs in the last 14 days will be compressed and deleted
33
+ format: winston.format.combine(
34
+ winston.format.timestamp({
35
+ format: "YYYY-MM-DD HH:mm:ss",
36
+ }),
37
+ formatPrint
38
+ ),
39
+ level: "info",
40
+ }),
41
+ new winston.transports.DailyRotateFile({
42
+ filename: "logs/application-%DATE%.error.log",
43
+ dirname: "./src/logs",
44
+ datePattern: "YYYY-MM-DD",
45
+ zippedArchive: true, // true: compress the file after maxSize before deleting (backup)
46
+ maxSize: "20m", // 20mb => create new file if over 20mb
47
+ maxFiles: "14d", // all logs in the last 14 days will be compressed and deleted
48
+ format: winston.format.combine(
49
+ winston.format.timestamp({
50
+ format: "YYYY-MM-DD HH:mm:ss",
51
+ }),
52
+ formatPrint
53
+ ),
54
+ level: "error",
55
+ }),
56
+ ],
57
+ });
58
+ }
59
+
60
+ commonParams(params) {
61
+ let context, req, metadata;
62
+ if (!Array.isArray(params)) {
63
+ context = params.context;
64
+ req = params.req;
65
+ metadata = params.metadata;
66
+ } else {
67
+ [context, req, metadata] = params;
68
+ }
69
+ const requestId = req?.id || req?.headers["x-request-id"] || uuidv4();
70
+ return { context, requestId, metadata };
71
+ }
72
+ // log, error, debug, warn override this.logger => by level
73
+ log(message, params) {
74
+ const paramsLog = this.commonParams(params);
75
+ const logObject = Object.assign(
76
+ {
77
+ message,
78
+ },
79
+ paramsLog
80
+ );
81
+
82
+ this.logger.info(logObject);
83
+ }
84
+
85
+ error(message, params) {
86
+ const paramsLog = this.commonParams(params);
87
+ const logObject = Object.assign(
88
+ {
89
+ message,
90
+ },
91
+ paramsLog
92
+ );
93
+ this.logger.error(logObject);
94
+ }
95
+
96
+ debug(message, params) {
97
+ const paramsLog = this.commonParams(params);
98
+ const logObject = Object.assign(
99
+ {
100
+ message,
101
+ },
102
+ paramsLog
103
+ );
104
+ this.logger.debug(logObject);
105
+ }
106
+
107
+ warn(message, params) {
108
+ const paramsLog = this.commonParams(params);
109
+ const logObject = Object.assign(
110
+ {
111
+ message,
112
+ },
113
+ paramsLog
114
+ );
115
+ this.logger.warn(logObject);
116
+ }
117
+ }
118
+
119
+ module.exports = new MyLogger();
120
+ // traceID: x-request-id
121
+ /*
122
+ 1. Level => info, error, debug, warn
123
+ 1.1 error: serious problems => hot fix
124
+ 1.2 warn: potential problems => fix later (not urgent)
125
+ 1.3 info: normal but important information for improving performance
126
+ 1.4 debug: detailed information for developers
127
+ 2. Context
128
+ 3. RequestId => x-request-id
129
+ 4. Metadata => result (response)
130
+ */
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ const winston = require("winston");
4
+ const { combine, timestamp, printf, json, align } = winston.format;
5
+
6
+ const logger = winston.createLogger({
7
+ level: process.env.LOG_LEVEL || "debug",
8
+ format: combine(
9
+ timestamp({
10
+ format: "YYYY-MM-DD HH:mm:ss.SSS A",
11
+ }),
12
+ align(),
13
+ printf((info) => {
14
+ return `${info.timestamp} - ${info.level}: ${info.message}`;
15
+ })
16
+ // printf is a callback function that formats the custom log message
17
+ ),
18
+ transports: [
19
+ new winston.transports.Console(),
20
+ new winston.transports.File({
21
+ dirname: "./src/logs",
22
+ filename: "test.log",
23
+ }),
24
+ ],
25
+ });
26
+
27
+ module.exports = logger;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ const Logger = require("../logger/discord.log.v2");
4
+
5
+ const pushToLogDiscord = async (req, res, next) => {
6
+ try {
7
+ console.log(req.get("host"));
8
+ Logger.sendToFormatCode({
9
+ title: `Method: ${req.method}`,
10
+ code: req.method === "GET" ? req.query | req.params : req.body,
11
+ message: `${req.get("host")} ${req.originalUrl}`,
12
+ });
13
+ return next();
14
+ } catch (error) {
15
+ next(error);
16
+ }
17
+ };
18
+
19
+ module.exports = {
20
+ pushToLogDiscord,
21
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ import { roleList } from "../services/rbac.service";
4
+
5
+ const { AuthFailureError } = require("../core/error.response");
6
+ const rbac = require("./role.middleware");
7
+ /**
8
+ *
9
+ * @param {string} action // read, delete, update, create
10
+ * @param {*} resource // profile, balance
11
+ * @returns
12
+ */
13
+
14
+ export const grantAccess = (action, resource) => {
15
+ return async (req, res, next) => {
16
+ try {
17
+ rbac.setGrants(
18
+ await roleList({
19
+ userId: req.user.userId,
20
+ })
21
+ );
22
+ const role_name = req.query.role;
23
+ const permission = await rbac.can(role_name)[action](resource);
24
+ if (!permission.granted) {
25
+ throw new AuthFailureError("You are not allowed to do this action");
26
+ }
27
+ next();
28
+ } catch (error) {
29
+ next(error);
30
+ }
31
+ };
32
+ };
33
+
34
+
35
+ // FLow of rbac
36
+ // what is any, own...
37
+ // $unwind, $project, $lookup in mongoose
@@ -0,0 +1,12 @@
1
+ const AccessControl = require("accesscontrol");
2
+ // grant list fetched from DB (to be converted to a valid grants object, internally)
3
+ // let grantList = [
4
+ // {
5
+ // role: "admin",
6
+ // resource: "profile",
7
+ // action: "readAny",
8
+ // attributes: "*, !views",
9
+ // },
10
+ // { role: "shop", resource: "profile", action: "readOwn", attributes: "*" },
11
+ // ];
12
+ module.exports = new AccessControl();
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ const { default: mongoose, Types, model } = require("mongoose");
4
+ const COLLECTION_NAME = "KeyTokens";
5
+ const DOCUMENT_NAME = "KeyToken";
6
+
7
+ const keyTokenSchema = new mongoose.Schema(
8
+ {
9
+ user: {
10
+ type: Types.ObjectId,
11
+ ref: "User",
12
+ required: true,
13
+ },
14
+ publicKey: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ privateKey: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ refreshToken: {
23
+ type: String,
24
+ required: true,
25
+ },
26
+ refreshTokenUsed: {
27
+ type: Array,
28
+ default: [],
29
+ },
30
+ },
31
+ {
32
+ timestamps: true,
33
+ collection: COLLECTION_NAME,
34
+ }
35
+ );
36
+
37
+ module.exports = model(DOCUMENT_NAME, keyTokenSchema);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const { default: mongoose, model } = require("mongoose");
4
+
5
+ const DOCUMENT_NAME = "ApiKey";
6
+ const COLLECTION_NAME = "ApiKeys";
7
+
8
+ const apiKeySchema = new mongoose.Schema(
9
+ {
10
+ key: {
11
+ type: String,
12
+ required: true,
13
+ unique: true,
14
+ },
15
+ status: {
16
+ type: Boolean,
17
+ default: true,
18
+ },
19
+ permissions: {
20
+ type: [String],
21
+ required: true,
22
+ enum: ["0000", "1111", "2222"],
23
+ },
24
+ },
25
+ {
26
+ timestamps: true,
27
+ collection: COLLECTION_NAME,
28
+ }
29
+ );
30
+
31
+ module.exports = model(DOCUMENT_NAME, apiKeySchema);
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ const { default: mongoose, Schema, model, Types } = require("mongoose");
4
+ const COLLECTION_NAME = "Carts";
5
+ const DOCUMENT_NAME = "Cart";
6
+
7
+ const cartSchema = new mongoose.Schema(
8
+ {
9
+ cart_products: {
10
+ type: Array,
11
+ required: true,
12
+ default: [],
13
+ /*
14
+ [
15
+ {
16
+ product_id,
17
+ shop_id,
18
+ quantity,
19
+ price,
20
+ name
21
+ }
22
+ ]
23
+ */
24
+ },
25
+ cart_state: {
26
+ type: String,
27
+ required: true,
28
+ enum: ["ACTIVE", "COMPLETED", "FAILED", "PENDING"],
29
+ default: "ACTIVE",
30
+ },
31
+ cart_count_product: {
32
+ type: Number,
33
+ default: 0,
34
+ },
35
+ // cart cua user nao
36
+ cart_user_id: {
37
+ type: Types.ObjectId,
38
+ required: true,
39
+ },
40
+ },
41
+ {
42
+ timestamps: true,
43
+ collection: COLLECTION_NAME,
44
+ }
45
+ );
46
+
47
+ module.exports = model(DOCUMENT_NAME, cartSchema);
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const { default: mongoose, Schema, model, Types } = require("mongoose");
4
+ const COLLECTION_NAME = "Comments";
5
+ const DOCUMENT_NAME = "Comment";
6
+
7
+ const cartSchema = new mongoose.Schema(
8
+ {
9
+ comment_productId: {
10
+ type: Types.ObjectId,
11
+ ref: "Product",
12
+ },
13
+ comment_userId: {
14
+ type: Types.ObjectId,
15
+ },
16
+ comment_content: {
17
+ type: String,
18
+ default: "comment text",
19
+ },
20
+ comment_left: {
21
+ type: Number,
22
+ default: 0,
23
+ },
24
+ comment_right: {
25
+ type: Number,
26
+ default: 0,
27
+ },
28
+ comment_parentId: {
29
+ type: Types.ObjectId,
30
+ ref: DOCUMENT_NAME,
31
+ },
32
+ isDeleted: {
33
+ type: Boolean,
34
+ default: false,
35
+ },
36
+ },
37
+ {
38
+ timestamps: true,
39
+ collection: COLLECTION_NAME,
40
+ }
41
+ );
42
+
43
+ module.exports = model(DOCUMENT_NAME, cartSchema);