@laboratory-one/api-components 0.0.23 → 0.0.25

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 (296) hide show
  1. package/dist/src/ability/ability.factory.d.ts +5 -0
  2. package/dist/src/ability/ability.factory.d.ts.map +1 -0
  3. package/dist/src/ability/ability.factory.js +22 -0
  4. package/dist/src/ability/ability.factory.js.map +1 -0
  5. package/dist/src/ability/ability.module.d.ts +3 -0
  6. package/dist/src/ability/ability.module.d.ts.map +1 -0
  7. package/dist/src/ability/ability.module.js +16 -0
  8. package/dist/src/ability/ability.module.js.map +1 -0
  9. package/dist/src/ability/ability.util.d.ts +7 -0
  10. package/dist/src/ability/ability.util.d.ts.map +1 -0
  11. package/dist/src/ability/ability.util.js +30 -0
  12. package/dist/src/ability/ability.util.js.map +1 -0
  13. package/dist/src/ability/action.enum.d.ts +9 -0
  14. package/dist/src/ability/action.enum.d.ts.map +1 -0
  15. package/dist/src/ability/action.enum.js +11 -0
  16. package/dist/src/ability/action.enum.js.map +1 -0
  17. package/dist/src/ability/app-ability.type.d.ts +7 -0
  18. package/dist/src/ability/app-ability.type.d.ts.map +1 -0
  19. package/dist/src/ability/app-ability.type.js +3 -0
  20. package/dist/src/ability/app-ability.type.js.map +1 -0
  21. package/dist/src/ability/index.d.ts +7 -0
  22. package/dist/src/ability/index.d.ts.map +1 -0
  23. package/dist/src/ability/index.js +10 -0
  24. package/dist/src/ability/index.js.map +1 -0
  25. package/dist/src/ability/services.enum.d.ts +7 -0
  26. package/dist/src/ability/services.enum.d.ts.map +1 -0
  27. package/dist/src/ability/services.enum.js +9 -0
  28. package/dist/src/ability/services.enum.js.map +1 -0
  29. package/dist/src/cron/cron.module.d.ts.map +1 -0
  30. package/dist/src/cron/cron.module.js.map +1 -0
  31. package/dist/src/cron/cron.service.d.ts.map +1 -0
  32. package/dist/src/cron/cron.service.js.map +1 -0
  33. package/dist/src/cron/cron.util.d.ts.map +1 -0
  34. package/dist/src/cron/cron.util.js.map +1 -0
  35. package/dist/src/cron/index.d.ts.map +1 -0
  36. package/dist/src/cron/index.js.map +1 -0
  37. package/dist/src/decorator/index.d.ts +3 -0
  38. package/dist/src/decorator/index.d.ts.map +1 -0
  39. package/dist/src/decorator/index.js +6 -0
  40. package/dist/src/decorator/index.js.map +1 -0
  41. package/dist/src/decorator/policies.decorator.d.ts +4 -0
  42. package/dist/src/decorator/policies.decorator.d.ts.map +1 -0
  43. package/dist/src/decorator/policies.decorator.js +8 -0
  44. package/dist/src/decorator/policies.decorator.js.map +1 -0
  45. package/dist/src/decorator/policies.handler.d.ts +9 -0
  46. package/dist/src/decorator/policies.handler.d.ts.map +1 -0
  47. package/dist/src/decorator/policies.handler.js +14 -0
  48. package/dist/src/decorator/policies.handler.js.map +1 -0
  49. package/dist/src/enums/humanDay.enum.d.ts.map +1 -0
  50. package/dist/src/enums/humanDay.enum.js.map +1 -0
  51. package/dist/src/enums/index.d.ts.map +1 -0
  52. package/dist/src/enums/index.js.map +1 -0
  53. package/dist/src/enums/serverDay.enum.d.ts.map +1 -0
  54. package/dist/src/enums/serverDay.enum.js.map +1 -0
  55. package/dist/src/guard/auth.guard.d.ts.map +1 -0
  56. package/dist/src/guard/auth.guard.js.map +1 -0
  57. package/dist/src/guard/index.d.ts +3 -0
  58. package/dist/src/guard/index.d.ts.map +1 -0
  59. package/{src → dist/src}/guard/index.js +1 -0
  60. package/dist/src/guard/index.js.map +1 -0
  61. package/dist/src/guard/policies.guard.d.ts +11 -0
  62. package/dist/src/guard/policies.guard.d.ts.map +1 -0
  63. package/dist/src/guard/policies.guard.js +44 -0
  64. package/dist/src/guard/policies.guard.js.map +1 -0
  65. package/dist/src/health/dtos/health.response.dto.d.ts.map +1 -0
  66. package/dist/src/health/dtos/health.response.dto.js.map +1 -0
  67. package/dist/src/health/dtos/index.d.ts.map +1 -0
  68. package/dist/src/health/dtos/index.js.map +1 -0
  69. package/dist/src/health/health.controller.d.ts.map +1 -0
  70. package/dist/src/health/health.controller.js.map +1 -0
  71. package/dist/src/health/health.module.d.ts.map +1 -0
  72. package/dist/src/health/health.module.js.map +1 -0
  73. package/dist/src/health/health.service.d.ts.map +1 -0
  74. package/dist/src/health/health.service.js.map +1 -0
  75. package/dist/src/health/index.d.ts.map +1 -0
  76. package/dist/src/health/index.js.map +1 -0
  77. package/dist/src/middleware/index.d.ts.map +1 -0
  78. package/dist/src/middleware/index.js.map +1 -0
  79. package/dist/src/middleware/logger.middleware.d.ts.map +1 -0
  80. package/dist/src/middleware/logger.middleware.js.map +1 -0
  81. package/dist/src/prisma/index.d.ts.map +1 -0
  82. package/dist/src/prisma/index.js.map +1 -0
  83. package/dist/src/prisma/prisma.module.d.ts.map +1 -0
  84. package/dist/src/prisma/prisma.module.js.map +1 -0
  85. package/dist/src/prisma/prisma.service.d.ts.map +1 -0
  86. package/dist/src/prisma/prisma.service.js.map +1 -0
  87. package/dist/src/push/index.d.ts.map +1 -0
  88. package/dist/src/push/index.js.map +1 -0
  89. package/dist/src/push/push.module.d.ts.map +1 -0
  90. package/dist/src/push/push.module.js.map +1 -0
  91. package/dist/src/push/push.service.d.ts.map +1 -0
  92. package/dist/src/push/push.service.js.map +1 -0
  93. package/dist/src/search/index.d.ts.map +1 -0
  94. package/dist/src/search/index.js.map +1 -0
  95. package/dist/src/search/search.module.d.ts.map +1 -0
  96. package/dist/src/search/search.module.js.map +1 -0
  97. package/dist/src/search/search.service.d.ts.map +1 -0
  98. package/dist/src/search/search.service.js.map +1 -0
  99. package/dist/src/services/index.d.ts.map +1 -0
  100. package/dist/src/services/index.js.map +1 -0
  101. package/dist/src/services/instrument-sentry.d.ts.map +1 -0
  102. package/dist/src/services/instrument-sentry.js.map +1 -0
  103. package/dist/src/types/index.d.ts +5 -0
  104. package/dist/src/types/index.d.ts.map +1 -0
  105. package/{src → dist/src}/types/index.js +2 -0
  106. package/dist/src/types/index.js.map +1 -0
  107. package/dist/src/types/policy.type.d.ts +8 -0
  108. package/dist/src/types/policy.type.d.ts.map +1 -0
  109. package/dist/src/types/policy.type.js +3 -0
  110. package/dist/src/types/policy.type.js.map +1 -0
  111. package/dist/src/types/req.type.d.ts.map +1 -0
  112. package/dist/src/types/req.type.js.map +1 -0
  113. package/dist/src/types/reqWithUser.type.d.ts +4 -0
  114. package/dist/src/types/reqWithUser.type.d.ts.map +1 -0
  115. package/dist/src/types/reqWithUser.type.js +3 -0
  116. package/dist/src/types/reqWithUser.type.js.map +1 -0
  117. package/dist/src/types/success.response.dto.d.ts.map +1 -0
  118. package/dist/src/types/success.response.dto.js.map +1 -0
  119. package/dist/src/utils/datetime.util.d.ts.map +1 -0
  120. package/dist/src/utils/datetime.util.js.map +1 -0
  121. package/dist/src/utils/error.util.d.ts.map +1 -0
  122. package/dist/src/utils/error.util.js.map +1 -0
  123. package/{src → dist/src}/utils/index.d.ts +0 -1
  124. package/dist/src/utils/index.d.ts.map +1 -0
  125. package/{src → dist/src}/utils/index.js +0 -1
  126. package/dist/src/utils/index.js.map +1 -0
  127. package/dist/src/utils/input.util.d.ts.map +1 -0
  128. package/dist/src/utils/input.util.js.map +1 -0
  129. package/dist/src/utils/noop.util.d.ts.map +1 -0
  130. package/dist/src/utils/noop.util.js.map +1 -0
  131. package/dist/src/utils/string.util.d.ts.map +1 -0
  132. package/dist/src/utils/string.util.js.map +1 -0
  133. package/dist/src/utils/version.util.d.ts.map +1 -0
  134. package/dist/src/utils/version.util.js.map +1 -0
  135. package/dist/tsconfig.tsbuildinfo +1 -0
  136. package/package.json +12 -100
  137. package/src/ability/ability.factory.ts +19 -0
  138. package/src/ability/ability.module.ts +8 -0
  139. package/src/ability/ability.util.ts +37 -0
  140. package/src/ability/action.enum.ts +9 -0
  141. package/src/ability/app-ability.type.ts +7 -0
  142. package/src/ability/index.ts +6 -0
  143. package/src/ability/services.enum.ts +7 -0
  144. package/src/decorator/index.ts +2 -0
  145. package/src/decorator/policies.decorator.ts +7 -0
  146. package/src/decorator/policies.handler.ts +16 -0
  147. package/src/guard/index.ts +1 -0
  148. package/src/guard/policies.guard.ts +65 -0
  149. package/src/types/index.ts +2 -0
  150. package/src/types/policy.type.ts +9 -0
  151. package/src/types/reqWithUser.type.ts +3 -0
  152. package/src/utils/index.ts +0 -1
  153. package/src/auth/auth.module.d.ts +0 -3
  154. package/src/auth/auth.module.js +0 -18
  155. package/src/auth/auth.module.ts +0 -10
  156. package/src/auth/auth.service.d.ts +0 -18
  157. package/src/auth/auth.service.js +0 -65
  158. package/src/auth/auth.service.ts +0 -80
  159. package/src/auth/index.d.ts +0 -3
  160. package/src/auth/index.js +0 -6
  161. package/src/auth/index.ts +0 -2
  162. package/src/guard/index.d.ts +0 -2
  163. package/src/types/index.d.ts +0 -3
  164. package/src/user/dtos/delete-user.request.dto.d.ts +0 -4
  165. package/src/user/dtos/delete-user.request.dto.js +0 -15
  166. package/src/user/dtos/delete-user.request.dto.ts +0 -8
  167. package/src/user/dtos/get-user.response.dto.d.ts +0 -7
  168. package/src/user/dtos/get-user.response.dto.js +0 -32
  169. package/src/user/dtos/get-user.response.dto.ts +0 -22
  170. package/src/user/dtos/index.d.ts +0 -9
  171. package/src/user/dtos/index.js +0 -12
  172. package/src/user/dtos/index.ts +0 -8
  173. package/src/user/dtos/phone-login-verify.request.dto.d.ts +0 -6
  174. package/src/user/dtos/phone-login-verify.request.dto.js +0 -25
  175. package/src/user/dtos/phone-login-verify.request.dto.ts +0 -16
  176. package/src/user/dtos/phone-login.request.dto.d.ts +0 -4
  177. package/src/user/dtos/phone-login.request.dto.js +0 -15
  178. package/src/user/dtos/phone-login.request.dto.ts +0 -8
  179. package/src/user/dtos/phone-login.response.dto.d.ts +0 -5
  180. package/src/user/dtos/phone-login.response.dto.js +0 -20
  181. package/src/user/dtos/phone-login.response.dto.ts +0 -12
  182. package/src/user/dtos/register.request.dto.d.ts +0 -5
  183. package/src/user/dtos/register.request.dto.js +0 -20
  184. package/src/user/dtos/register.request.dto.ts +0 -12
  185. package/src/user/dtos/register.response.dto.d.ts +0 -5
  186. package/src/user/dtos/register.response.dto.js +0 -16
  187. package/src/user/dtos/register.response.dto.ts +0 -10
  188. package/src/user/dtos/update-user.request.dto.d.ts +0 -8
  189. package/src/user/dtos/update-user.request.dto.js +0 -40
  190. package/src/user/dtos/update-user.request.dto.ts +0 -29
  191. package/src/user/index.d.ts +0 -7
  192. package/src/user/index.js +0 -10
  193. package/src/user/index.ts +0 -6
  194. package/src/user/schemas/delete-user.schema.d.ts +0 -5
  195. package/src/user/schemas/delete-user.schema.js +0 -9
  196. package/src/user/schemas/delete-user.schema.ts +0 -7
  197. package/src/user/schemas/index.d.ts +0 -6
  198. package/src/user/schemas/index.js +0 -9
  199. package/src/user/schemas/index.ts +0 -5
  200. package/src/user/schemas/phone-login-verify.schema.d.ts +0 -7
  201. package/src/user/schemas/phone-login-verify.schema.js +0 -11
  202. package/src/user/schemas/phone-login-verify.schema.ts +0 -9
  203. package/src/user/schemas/phone-login.schema.d.ts +0 -5
  204. package/src/user/schemas/phone-login.schema.js +0 -9
  205. package/src/user/schemas/phone-login.schema.ts +0 -7
  206. package/src/user/schemas/signup.schema.d.ts +0 -6
  207. package/src/user/schemas/signup.schema.js +0 -10
  208. package/src/user/schemas/signup.schema.ts +0 -8
  209. package/src/user/schemas/update-user.schema.d.ts +0 -9
  210. package/src/user/schemas/update-user.schema.js +0 -15
  211. package/src/user/schemas/update-user.schema.ts +0 -13
  212. package/src/user/user.controller.d.ts +0 -22
  213. package/src/user/user.controller.js +0 -279
  214. package/src/user/user.controller.ts +0 -321
  215. package/src/user/user.module.d.ts +0 -3
  216. package/src/user/user.module.js +0 -22
  217. package/src/user/user.module.ts +0 -16
  218. package/src/user/user.service.d.ts +0 -15
  219. package/src/user/user.service.js +0 -62
  220. package/src/user/user.service.ts +0 -68
  221. package/src/user/user.util.d.ts +0 -3
  222. package/src/user/user.util.js +0 -8
  223. package/src/user/user.util.ts +0 -5
  224. package/src/utils/schema.util.d.ts +0 -13
  225. package/src/utils/schema.util.js +0 -16
  226. package/src/utils/schema.util.ts +0 -13
  227. /package/{src → dist/src}/cron/cron.module.d.ts +0 -0
  228. /package/{src → dist/src}/cron/cron.module.js +0 -0
  229. /package/{src → dist/src}/cron/cron.service.d.ts +0 -0
  230. /package/{src → dist/src}/cron/cron.service.js +0 -0
  231. /package/{src → dist/src}/cron/cron.util.d.ts +0 -0
  232. /package/{src → dist/src}/cron/cron.util.js +0 -0
  233. /package/{src → dist/src}/cron/index.d.ts +0 -0
  234. /package/{src → dist/src}/cron/index.js +0 -0
  235. /package/{src → dist/src}/enums/humanDay.enum.d.ts +0 -0
  236. /package/{src → dist/src}/enums/humanDay.enum.js +0 -0
  237. /package/{src → dist/src}/enums/index.d.ts +0 -0
  238. /package/{src → dist/src}/enums/index.js +0 -0
  239. /package/{src → dist/src}/enums/serverDay.enum.d.ts +0 -0
  240. /package/{src → dist/src}/enums/serverDay.enum.js +0 -0
  241. /package/{src → dist/src}/guard/auth.guard.d.ts +0 -0
  242. /package/{src → dist/src}/guard/auth.guard.js +0 -0
  243. /package/{src → dist/src}/health/dtos/health.response.dto.d.ts +0 -0
  244. /package/{src → dist/src}/health/dtos/health.response.dto.js +0 -0
  245. /package/{src → dist/src}/health/dtos/index.d.ts +0 -0
  246. /package/{src → dist/src}/health/dtos/index.js +0 -0
  247. /package/{src → dist/src}/health/health.controller.d.ts +0 -0
  248. /package/{src → dist/src}/health/health.controller.js +0 -0
  249. /package/{src → dist/src}/health/health.module.d.ts +0 -0
  250. /package/{src → dist/src}/health/health.module.js +0 -0
  251. /package/{src → dist/src}/health/health.service.d.ts +0 -0
  252. /package/{src → dist/src}/health/health.service.js +0 -0
  253. /package/{src → dist/src}/health/index.d.ts +0 -0
  254. /package/{src → dist/src}/health/index.js +0 -0
  255. /package/{src → dist/src}/middleware/index.d.ts +0 -0
  256. /package/{src → dist/src}/middleware/index.js +0 -0
  257. /package/{src → dist/src}/middleware/logger.middleware.d.ts +0 -0
  258. /package/{src → dist/src}/middleware/logger.middleware.js +0 -0
  259. /package/{src → dist/src}/prisma/index.d.ts +0 -0
  260. /package/{src → dist/src}/prisma/index.js +0 -0
  261. /package/{src → dist/src}/prisma/prisma.module.d.ts +0 -0
  262. /package/{src → dist/src}/prisma/prisma.module.js +0 -0
  263. /package/{src → dist/src}/prisma/prisma.service.d.ts +0 -0
  264. /package/{src → dist/src}/prisma/prisma.service.js +0 -0
  265. /package/{src → dist/src}/push/index.d.ts +0 -0
  266. /package/{src → dist/src}/push/index.js +0 -0
  267. /package/{src → dist/src}/push/push.module.d.ts +0 -0
  268. /package/{src → dist/src}/push/push.module.js +0 -0
  269. /package/{src → dist/src}/push/push.service.d.ts +0 -0
  270. /package/{src → dist/src}/push/push.service.js +0 -0
  271. /package/{src → dist/src}/search/index.d.ts +0 -0
  272. /package/{src → dist/src}/search/index.js +0 -0
  273. /package/{src → dist/src}/search/search.module.d.ts +0 -0
  274. /package/{src → dist/src}/search/search.module.js +0 -0
  275. /package/{src → dist/src}/search/search.service.d.ts +0 -0
  276. /package/{src → dist/src}/search/search.service.js +0 -0
  277. /package/{src → dist/src}/services/index.d.ts +0 -0
  278. /package/{src → dist/src}/services/index.js +0 -0
  279. /package/{src → dist/src}/services/instrument-sentry.d.ts +0 -0
  280. /package/{src → dist/src}/services/instrument-sentry.js +0 -0
  281. /package/{src → dist/src}/types/req.type.d.ts +0 -0
  282. /package/{src → dist/src}/types/req.type.js +0 -0
  283. /package/{src → dist/src}/types/success.response.dto.d.ts +0 -0
  284. /package/{src → dist/src}/types/success.response.dto.js +0 -0
  285. /package/{src → dist/src}/utils/datetime.util.d.ts +0 -0
  286. /package/{src → dist/src}/utils/datetime.util.js +0 -0
  287. /package/{src → dist/src}/utils/error.util.d.ts +0 -0
  288. /package/{src → dist/src}/utils/error.util.js +0 -0
  289. /package/{src → dist/src}/utils/input.util.d.ts +0 -0
  290. /package/{src → dist/src}/utils/input.util.js +0 -0
  291. /package/{src → dist/src}/utils/noop.util.d.ts +0 -0
  292. /package/{src → dist/src}/utils/noop.util.js +0 -0
  293. /package/{src → dist/src}/utils/string.util.d.ts +0 -0
  294. /package/{src → dist/src}/utils/string.util.js +0 -0
  295. /package/{src → dist/src}/utils/version.util.d.ts +0 -0
  296. /package/{src → dist/src}/utils/version.util.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laboratory-one/api-components",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "API components for Laboratory One",
5
5
  "author": "Laboratory One",
6
6
  "private": false,
@@ -8,41 +8,8 @@
8
8
  "type": "commonjs",
9
9
  "typesVersions": {
10
10
  "*": {
11
- "auth": [
12
- "src/auth/index.d.ts"
13
- ],
14
- "cron": [
15
- "src/cron/index.d.ts"
16
- ],
17
- "enums": [
18
- "src/enums/index.d.ts"
19
- ],
20
- "guard": [
21
- "src/guard/index.d.ts"
22
- ],
23
- "health": [
24
- "src/health/index.d.ts"
25
- ],
26
- "middleware": [
27
- "src/middleware/index.d.ts"
28
- ],
29
- "prisma": [
30
- "src/prisma/index.d.ts"
31
- ],
32
- "push": [
33
- "src/push/index.d.ts"
34
- ],
35
- "services": [
36
- "src/services/index.d.ts"
37
- ],
38
- "types": [
39
- "src/types/index.d.ts"
40
- ],
41
- "user": [
42
- "src/user/index.d.ts"
43
- ],
44
- "utils": [
45
- "src/utils/index.d.ts"
11
+ "*": [
12
+ "dist/src/*/index.d.ts"
46
13
  ]
47
14
  }
48
15
  },
@@ -59,81 +26,27 @@
59
26
  "dist"
60
27
  ],
61
28
  "exports": {
62
- "./auth": {
63
- "import": "./src/auth/index.js",
64
- "require": "./src/auth/index.js",
65
- "types": "./src/auth/index.d.ts"
66
- },
67
- "./cron": {
68
- "import": "./src/cron/index.js",
69
- "require": "./src/cron/index.js",
70
- "types": "./src/cron/index.d.ts"
71
- },
72
- "./enums": {
73
- "import": "./src/enums/index.js",
74
- "require": "./src/enums/index.js",
75
- "types": "./src/enums/index.d.ts"
76
- },
77
- "./guard": {
78
- "import": "./src/guard/index.js",
79
- "require": "./src/guard/index.js",
80
- "types": "./src/guard/index.d.ts"
81
- },
82
- "./health": {
83
- "import": "./src/health/index.js",
84
- "require": "./src/health/index.js",
85
- "types": "./src/health/index.d.ts"
86
- },
87
- "./middleware": {
88
- "import": "./src/middleware/index.js",
89
- "require": "./src/middleware/index.js",
90
- "types": "./src/middleware/index.d.ts"
91
- },
92
- "./prisma": {
93
- "import": "./src/prisma/index.js",
94
- "require": "./src/prisma/index.js",
95
- "types": "./src/prisma/index.d.ts"
96
- },
97
- "./push": {
98
- "import": "./src/push/index.js",
99
- "require": "./src/push/index.js",
100
- "types": "./src/push/index.d.ts"
101
- },
102
- "./services": {
103
- "import": "./src/services/index.js",
104
- "require": "./src/services/index.js",
105
- "types": "./src/services/index.d.ts"
106
- },
107
- "./types": {
108
- "import": "./src/types/index.js",
109
- "require": "./src/types/index.js",
110
- "types": "./src/types/index.d.ts"
111
- },
112
- "./user": {
113
- "import": "./src/user/index.js",
114
- "require": "./src/user/index.js",
115
- "types": "./src/user/index.d.ts"
116
- },
117
- "./utils": {
118
- "import": "./src/utils/index.js",
119
- "require": "./src/utils/index.js",
120
- "types": "./src/utils/index.d.ts"
29
+ "./*": {
30
+ "import": "./dist/src/*/index.js",
31
+ "require": "./dist/src/*/index.js",
32
+ "types": "./dist/src/*/index.d.ts"
121
33
  }
122
34
  },
123
35
  "scripts": {
124
- "build": "tsc --build tsconfig.build.json",
36
+ "build": "tsc",
125
37
  "format": "prettier --write 'src/**/*.{js,ts}'",
126
- "generate": "prisma generate",
38
+ "types:generate": "npx prisma generate",
127
39
  "lint": "eslint 'src/**/*.{js,ts}'",
128
40
  "lint:fix": "yarn format && yarn lint --fix",
129
41
  "publish:local": "yalc publish",
130
42
  "push": "yarn build && yalc push --replace",
131
- "typecheck": "tsc -p tsconfig.json",
43
+ "typecheck": "tsc --noEmit",
132
44
  "version:minor": "./scripts/version.sh minor",
133
45
  "version:patch": "./scripts/version.sh patch",
134
46
  "start:dev": "watchman watch . && watchman -- trigger . yalc-push-trigger \"**/*\" -- ./scripts/yalc-push-trigger.sh"
135
47
  },
136
48
  "dependencies": {
49
+ "@casl/ability": "6.7.3",
137
50
  "@nestjs/axios": "4.0.1",
138
51
  "@nestjs/common": "11.1.6",
139
52
  "@nestjs/config": "4.0.2",
@@ -160,8 +73,7 @@
160
73
  "prisma": "6.16.2",
161
74
  "reflect-metadata": "0.2.2",
162
75
  "rxjs": "7.8.2",
163
- "stytch": "12.35.0",
164
- "zod": "4.1.11"
76
+ "stytch": "12.35.0"
165
77
  },
166
78
  "devDependencies": {
167
79
  "@babel/core": "7.28.4",
@@ -0,0 +1,19 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { AbilityBuilder, createMongoAbility } from '@casl/ability';
3
+ import { AppAbility } from './app-ability.type';
4
+ import { mapPermissionToAbility } from './ability.util';
5
+
6
+ @Injectable()
7
+ export class AbilityFactory {
8
+ createForUser(permissions: string[]): AppAbility {
9
+ const { can, build } = new AbilityBuilder<AppAbility>(createMongoAbility);
10
+
11
+ const abilities = mapPermissionToAbility(permissions);
12
+
13
+ abilities.forEach(({ action, subject }) => {
14
+ can(action, subject);
15
+ });
16
+
17
+ return build();
18
+ }
19
+ }
@@ -0,0 +1,8 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { AbilityFactory } from './ability.factory';
3
+
4
+ @Module({
5
+ providers: [AbilityFactory],
6
+ exports: [AbilityFactory],
7
+ })
8
+ export class AbilityModule {}
@@ -0,0 +1,37 @@
1
+ import { Action, ACTIONS } from './action.enum';
2
+ import { Subject } from './services.enum';
3
+
4
+ export const mapPermissionToAbility = (
5
+ permissions: string[],
6
+ ): { action: Action; subject: Subject }[] => {
7
+ return permissions.map((permission: string) => {
8
+ const split: string[] = permission.split(':');
9
+
10
+ if (split.length !== 2) {
11
+ throw new Error(`Invalid permission format: ${permission}`);
12
+ }
13
+
14
+ const action: Action = split[0] as Action;
15
+ const subject: Subject = split[1] as Subject;
16
+
17
+ switch (action) {
18
+ case ACTIONS.MANAGE:
19
+ return { action: ACTIONS.MANAGE, subject };
20
+
21
+ case ACTIONS.CREATE:
22
+ return { action: ACTIONS.CREATE, subject };
23
+
24
+ case ACTIONS.READ:
25
+ return { action: ACTIONS.READ, subject };
26
+
27
+ case ACTIONS.UPDATE:
28
+ return { action: ACTIONS.UPDATE, subject };
29
+
30
+ case ACTIONS.DELETE:
31
+ return { action: ACTIONS.DELETE, subject };
32
+
33
+ default:
34
+ throw new Error(`Invalid permission: ${permission}`);
35
+ }
36
+ });
37
+ };
@@ -0,0 +1,9 @@
1
+ export const ACTIONS = {
2
+ MANAGE: 'manage',
3
+ CREATE: 'create',
4
+ READ: 'read',
5
+ UPDATE: 'update',
6
+ DELETE: 'delete',
7
+ } as const;
8
+
9
+ export type Action = (typeof ACTIONS)[keyof typeof ACTIONS];
@@ -0,0 +1,7 @@
1
+ import { MongoAbility, InferSubjects } from '@casl/ability';
2
+ import { Subject } from './services.enum';
3
+ import { Action } from './action.enum';
4
+
5
+ type SubjectTypes = InferSubjects<Subject>;
6
+
7
+ export type AppAbility = MongoAbility<[Action, SubjectTypes]>;
@@ -0,0 +1,6 @@
1
+ export * from './ability.factory';
2
+ export * from './ability.module';
3
+ export * from './action.enum';
4
+ export * from './app-ability.type';
5
+ export * from './services.enum';
6
+ export * from './ability.util';
@@ -0,0 +1,7 @@
1
+ export const SUBJECTS = {
2
+ SUNG_JINWOO: 'sung-jinwoo',
3
+ AUTH: 'auth',
4
+ ALL: 'all',
5
+ } as const;
6
+
7
+ export type Subject = (typeof SUBJECTS)[keyof typeof SUBJECTS];
@@ -0,0 +1,2 @@
1
+ export * from './policies.decorator';
2
+ export * from './policies.handler';
@@ -0,0 +1,7 @@
1
+ import { SetMetadata } from '@nestjs/common';
2
+ import { PolicyHandler } from '../types/policy.type';
3
+
4
+ export const CHECK_POLICIES_KEY = 'check_policy';
5
+
6
+ export const CheckPolicies = (...handlers: PolicyHandler[]) =>
7
+ SetMetadata(CHECK_POLICIES_KEY, handlers);
@@ -0,0 +1,16 @@
1
+ import { AppAbility, Action, Subject } from '../ability';
2
+ import { IPolicyHandler } from '../types';
3
+
4
+ export class AuthPolicyHandler implements IPolicyHandler {
5
+ action: Action;
6
+ subject: Subject;
7
+
8
+ constructor(action: Action, subject: Subject) {
9
+ this.action = action;
10
+ this.subject = subject;
11
+ }
12
+
13
+ handle(ability: AppAbility) {
14
+ return ability.can(this.action, this.subject);
15
+ }
16
+ }
@@ -1 +1,2 @@
1
1
  export * from './auth.guard';
2
+ export * from './policies.guard';
@@ -0,0 +1,65 @@
1
+ import {
2
+ BadRequestException,
3
+ CanActivate,
4
+ ExecutionContext,
5
+ Injectable,
6
+ UnauthorizedException,
7
+ } from '@nestjs/common';
8
+ import { Reflector } from '@nestjs/core';
9
+ import { AbilityFactory, AppAbility } from '../ability';
10
+ import { CHECK_POLICIES_KEY } from '../decorator';
11
+ import { Request, Headers } from 'node-fetch';
12
+ import { PolicyHandler } from '../types';
13
+
14
+ @Injectable()
15
+ export class PoliciesGuard implements CanActivate {
16
+ constructor(
17
+ private reflector: Reflector,
18
+ private abilityFactory: AbilityFactory,
19
+ ) {}
20
+
21
+ canActivate(context: ExecutionContext): boolean {
22
+ const policyHandlers =
23
+ this.reflector.get<PolicyHandler[]>(
24
+ CHECK_POLICIES_KEY,
25
+ context.getHandler(),
26
+ ) || [];
27
+
28
+ const request: Request & { headers: Headers & { permissions: string } } =
29
+ context.switchToHttp().getRequest();
30
+
31
+ if (!request.headers.permissions) {
32
+ throw new UnauthorizedException('No permissions provided');
33
+ }
34
+
35
+ if (!request.headers['user-id']) {
36
+ throw new UnauthorizedException('No user provided');
37
+ }
38
+
39
+ request['userId'] = request.headers['user-id'];
40
+
41
+ const userPermissions: string[] = JSON.parse(
42
+ request.headers.permissions,
43
+ ) as string[];
44
+
45
+ if (!Array.isArray(userPermissions)) {
46
+ throw new BadRequestException('Permissions must be an array of strings');
47
+ }
48
+
49
+ const ability = this.abilityFactory.createForUser(userPermissions);
50
+
51
+ return policyHandlers.every((handler) =>
52
+ this.execPolicyHandler(handler, ability),
53
+ );
54
+ }
55
+
56
+ private execPolicyHandler(
57
+ handler: PolicyHandler,
58
+ ability: AppAbility,
59
+ ): boolean {
60
+ if (typeof handler === 'function') {
61
+ return handler(ability);
62
+ }
63
+ return handler.handle(ability);
64
+ }
65
+ }
@@ -1,2 +1,4 @@
1
1
  export * from './success.response.dto';
2
2
  export * from './req.type';
3
+ export * from './policy.type';
4
+ export * from './reqWithUser.type';
@@ -0,0 +1,9 @@
1
+ import { AppAbility } from '../ability';
2
+
3
+ export interface IPolicyHandler {
4
+ handle(ability: AppAbility): boolean;
5
+ }
6
+
7
+ type PolicyHandlerCallback = (ability: AppAbility) => boolean;
8
+
9
+ export type PolicyHandler = IPolicyHandler | PolicyHandlerCallback;
@@ -0,0 +1,3 @@
1
+ export type reqWithUser = {
2
+ userId: string;
3
+ };
@@ -3,5 +3,4 @@ export * from './error.util';
3
3
  export * from './input.util';
4
4
  export * from './string.util';
5
5
  export * from './noop.util';
6
- export * from './schema.util';
7
6
  export * from './version.util';
@@ -1,3 +0,0 @@
1
- export declare class AuthModule {
2
- }
3
- //# sourceMappingURL=auth.module.d.ts.map
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const auth_service_1 = require("./auth.service");
7
- const config_1 = require("@nestjs/config");
8
- let AuthModule = class AuthModule {
9
- };
10
- exports.AuthModule = AuthModule;
11
- exports.AuthModule = AuthModule = tslib_1.__decorate([
12
- (0, common_1.Module)({
13
- imports: [config_1.ConfigModule],
14
- providers: [auth_service_1.AuthService],
15
- exports: [auth_service_1.AuthService],
16
- })
17
- ], AuthModule);
18
- //# sourceMappingURL=auth.module.js.map
@@ -1,10 +0,0 @@
1
- import { Module } from '@nestjs/common';
2
- import { AuthService } from './auth.service';
3
- import { ConfigModule } from '@nestjs/config';
4
-
5
- @Module({
6
- imports: [ConfigModule],
7
- providers: [AuthService],
8
- exports: [AuthService],
9
- })
10
- export class AuthModule {}
@@ -1,18 +0,0 @@
1
- import * as stytch from 'stytch';
2
- import { ConfigService } from '@nestjs/config';
3
- import { RegisterRequestDto } from '../user';
4
- export declare class AuthService {
5
- private configService;
6
- private readonly logger;
7
- private authClient;
8
- constructor(configService: ConfigService);
9
- signup(data: RegisterRequestDto): Promise<stytch.PasswordsCreateResponse>;
10
- login(data: RegisterRequestDto): Promise<boolean>;
11
- phoneLoginOrCreate(phoneNumber: string): Promise<stytch.OTPsSmsLoginOrCreateResponse>;
12
- phoneAuthenticate({ methodId, code, }: {
13
- methodId: string;
14
- code: string;
15
- }): Promise<stytch.OTPsAuthenticateResponse>;
16
- delete(externalId: string): Promise<void>;
17
- }
18
- //# sourceMappingURL=auth.service.d.ts.map
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var AuthService_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AuthService = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const stytch = tslib_1.__importStar(require("stytch"));
8
- const config_1 = require("@nestjs/config");
9
- const utils_1 = require("../utils");
10
- let AuthService = AuthService_1 = class AuthService {
11
- constructor(configService) {
12
- this.configService = configService;
13
- this.logger = new common_1.Logger(AuthService_1.name);
14
- this.authClient = new stytch.Client({
15
- project_id: this.configService.get('STYTCH_PROJECT_ID'),
16
- secret: this.configService.get('STYTCH_SECRET'),
17
- env: this.configService.get('STYTCH_ENV') === 'test'
18
- ? stytch.envs.test
19
- : stytch.envs.live,
20
- });
21
- }
22
- async signup(data) {
23
- this.logger.debug('signup');
24
- return await this.authClient.passwords.create(data);
25
- }
26
- async login(data) {
27
- this.logger.debug('login');
28
- try {
29
- const res = await this.authClient.passwords.authenticate(data);
30
- return res['status_code'] === 200;
31
- }
32
- catch (error) {
33
- if (error.error_type === 'email_not_found') {
34
- (0, utils_1.handleError)('Email or password is wrong');
35
- }
36
- if (error.error_type === 'unauthorized_credentials') {
37
- (0, utils_1.handleError)('Email or password is wrong');
38
- }
39
- }
40
- }
41
- async phoneLoginOrCreate(phoneNumber) {
42
- this.logger.debug('phoneLoginOrCreate');
43
- return await this.authClient.otps.sms.loginOrCreate({
44
- phone_number: phoneNumber,
45
- expiration_minutes: 5,
46
- });
47
- }
48
- async phoneAuthenticate({ methodId, code, }) {
49
- this.logger.debug('phoneAuthenticate');
50
- return await this.authClient.otps.authenticate({
51
- method_id: methodId,
52
- code,
53
- });
54
- }
55
- async delete(externalId) {
56
- this.logger.debug('delete');
57
- await this.authClient.users.delete({ user_id: externalId });
58
- }
59
- };
60
- exports.AuthService = AuthService;
61
- exports.AuthService = AuthService = AuthService_1 = tslib_1.__decorate([
62
- (0, common_1.Injectable)(),
63
- tslib_1.__metadata("design:paramtypes", [config_1.ConfigService])
64
- ], AuthService);
65
- //# sourceMappingURL=auth.service.js.map
@@ -1,80 +0,0 @@
1
- import { Injectable, Logger } from '@nestjs/common';
2
- import * as stytch from 'stytch';
3
- import { ConfigService } from '@nestjs/config';
4
-
5
- import { RegisterRequestDto } from '../user';
6
- import { handleError } from '../utils';
7
-
8
- @Injectable()
9
- export class AuthService {
10
- private readonly logger: Logger = new Logger(AuthService.name);
11
- private authClient: stytch.Client;
12
-
13
- constructor(private configService: ConfigService) {
14
- this.authClient = new stytch.Client({
15
- project_id: this.configService.get<string>('STYTCH_PROJECT_ID'),
16
- secret: this.configService.get<string>('STYTCH_SECRET'),
17
- env:
18
- this.configService.get<string>('STYTCH_ENV') === 'test'
19
- ? stytch.envs.test
20
- : stytch.envs.live,
21
- });
22
- }
23
-
24
- async signup(
25
- data: RegisterRequestDto,
26
- ): Promise<stytch.PasswordsCreateResponse> {
27
- this.logger.debug('signup');
28
-
29
- return await this.authClient.passwords.create(data);
30
- }
31
-
32
- async login(data: RegisterRequestDto): Promise<boolean> {
33
- this.logger.debug('login');
34
-
35
- try {
36
- const res = await this.authClient.passwords.authenticate(data);
37
- return res['status_code'] === 200;
38
- } catch (error: any) {
39
- if (error.error_type === 'email_not_found') {
40
- handleError('Email or password is wrong');
41
- }
42
-
43
- if (error.error_type === 'unauthorized_credentials') {
44
- handleError('Email or password is wrong');
45
- }
46
- }
47
- }
48
-
49
- async phoneLoginOrCreate(
50
- phoneNumber: string,
51
- ): Promise<stytch.OTPsSmsLoginOrCreateResponse> {
52
- this.logger.debug('phoneLoginOrCreate');
53
-
54
- return await this.authClient.otps.sms.loginOrCreate({
55
- phone_number: phoneNumber,
56
- expiration_minutes: 5,
57
- });
58
- }
59
-
60
- async phoneAuthenticate({
61
- methodId,
62
- code,
63
- }: {
64
- methodId: string;
65
- code: string;
66
- }): Promise<stytch.OTPsAuthenticateResponse> {
67
- this.logger.debug('phoneAuthenticate');
68
-
69
- return await this.authClient.otps.authenticate({
70
- method_id: methodId,
71
- code,
72
- });
73
- }
74
-
75
- async delete(externalId: string): Promise<void> {
76
- this.logger.debug('delete');
77
-
78
- await this.authClient.users.delete({ user_id: externalId });
79
- }
80
- }
@@ -1,3 +0,0 @@
1
- export * from './auth.module';
2
- export * from './auth.service';
3
- //# sourceMappingURL=index.d.ts.map
package/src/auth/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./auth.module"), exports);
5
- tslib_1.__exportStar(require("./auth.service"), exports);
6
- //# sourceMappingURL=index.js.map
package/src/auth/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './auth.module';
2
- export * from './auth.service';
@@ -1,2 +0,0 @@
1
- export * from './auth.guard';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from './success.response.dto';
2
- export * from './req.type';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export declare class DeleteUserRequestDto {
2
- phoneNumber: string;
3
- }
4
- //# sourceMappingURL=delete-user.request.dto.d.ts.map
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeleteUserRequestDto = void 0;
4
- const tslib_1 = require("tslib");
5
- const class_validator_1 = require("class-validator");
6
- const swagger_1 = require("@nestjs/swagger");
7
- class DeleteUserRequestDto {
8
- }
9
- exports.DeleteUserRequestDto = DeleteUserRequestDto;
10
- tslib_1.__decorate([
11
- (0, class_validator_1.IsString)(),
12
- (0, swagger_1.ApiProperty)(),
13
- tslib_1.__metadata("design:type", String)
14
- ], DeleteUserRequestDto.prototype, "phoneNumber", void 0);
15
- //# sourceMappingURL=delete-user.request.dto.js.map
@@ -1,8 +0,0 @@
1
- import { IsString } from 'class-validator';
2
- import { ApiProperty } from '@nestjs/swagger';
3
-
4
- export class DeleteUserRequestDto {
5
- @IsString()
6
- @ApiProperty()
7
- phoneNumber: string;
8
- }
@@ -1,7 +0,0 @@
1
- export declare class GetUserResponseDto {
2
- id: string;
3
- email: string;
4
- phoneNumber?: string | undefined;
5
- fullName?: string | undefined;
6
- }
7
- //# sourceMappingURL=get-user.response.dto.d.ts.map