@m5kdev/backend 0.1.4 → 0.2.0

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 (319) hide show
  1. package/dist/src/lib/posthog.d.ts +0 -1
  2. package/dist/src/lib/sentry.d.ts +0 -1
  3. package/dist/src/modules/access/access.repository.d.ts +0 -1
  4. package/dist/src/modules/access/access.service.d.ts +0 -1
  5. package/dist/src/modules/access/access.test.d.ts +0 -1
  6. package/dist/src/modules/access/access.utils.d.ts +0 -1
  7. package/dist/src/modules/ai/ai.db.d.ts +0 -1
  8. package/dist/src/modules/ai/ai.prompt.d.ts +0 -1
  9. package/dist/src/modules/ai/ai.repository.d.ts +0 -1
  10. package/dist/src/modules/ai/ai.router.d.ts +0 -1
  11. package/dist/src/modules/ai/ai.service.d.ts +0 -1
  12. package/dist/src/modules/ai/ai.trpc.d.ts +5 -42
  13. package/dist/src/modules/ai/ai.trpc.js +5 -5
  14. package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts +0 -1
  15. package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts +0 -1
  16. package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts +0 -1
  17. package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts +0 -1
  18. package/dist/src/modules/ai/ideogram/ideogram.service.d.ts +0 -1
  19. package/dist/src/modules/auth/auth.db.d.ts +0 -1
  20. package/dist/src/modules/auth/auth.dto.d.ts +7 -8
  21. package/dist/src/modules/auth/auth.lib.d.ts +8 -9
  22. package/dist/src/modules/auth/auth.middleware.d.ts +0 -1
  23. package/dist/src/modules/auth/auth.repository.d.ts +0 -1
  24. package/dist/src/modules/auth/auth.service.d.ts +0 -1
  25. package/dist/src/modules/auth/auth.trpc.d.ts +52 -89
  26. package/dist/src/modules/auth/auth.trpc.js +55 -53
  27. package/dist/src/modules/auth/auth.utils.d.ts +0 -1
  28. package/dist/src/modules/base/base.abstract.d.ts +0 -1
  29. package/dist/src/modules/base/base.dto.d.ts +2 -3
  30. package/dist/src/modules/base/base.grants.d.ts +0 -1
  31. package/dist/src/modules/base/base.grants.test.d.ts +0 -1
  32. package/dist/src/modules/base/base.repository.d.ts +0 -1
  33. package/dist/src/modules/base/base.service.d.ts +2 -4
  34. package/dist/src/modules/base/base.types.d.ts +0 -1
  35. package/dist/src/modules/billing/billing.db.d.ts +0 -1
  36. package/dist/src/modules/billing/billing.repository.d.ts +0 -1
  37. package/dist/src/modules/billing/billing.router.d.ts +0 -1
  38. package/dist/src/modules/billing/billing.service.d.ts +0 -1
  39. package/dist/src/modules/billing/billing.trpc.d.ts +6 -43
  40. package/dist/src/modules/billing/billing.trpc.js +7 -7
  41. package/dist/src/modules/clay/clay.repository.d.ts +0 -1
  42. package/dist/src/modules/clay/clay.service.d.ts +0 -1
  43. package/dist/src/modules/connect/connect.db.d.ts +0 -1
  44. package/dist/src/modules/connect/connect.dto.d.ts +8 -9
  45. package/dist/src/modules/connect/connect.linkedin.d.ts +0 -1
  46. package/dist/src/modules/connect/connect.oauth.d.ts +0 -1
  47. package/dist/src/modules/connect/connect.repository.d.ts +3 -4
  48. package/dist/src/modules/connect/connect.router.d.ts +0 -1
  49. package/dist/src/modules/connect/connect.service.d.ts +6 -7
  50. package/dist/src/modules/connect/connect.trpc.d.ts +9 -46
  51. package/dist/src/modules/connect/connect.trpc.js +7 -7
  52. package/dist/src/modules/connect/connect.types.d.ts +0 -1
  53. package/dist/src/modules/crypto/crypto.db.d.ts +0 -1
  54. package/dist/src/modules/crypto/crypto.repository.d.ts +0 -1
  55. package/dist/src/modules/crypto/crypto.service.d.ts +0 -1
  56. package/dist/src/modules/email/email.service.d.ts +0 -1
  57. package/dist/src/modules/file/file.repository.d.ts +0 -1
  58. package/dist/src/modules/file/file.router.d.ts +0 -1
  59. package/dist/src/modules/file/file.service.d.ts +0 -1
  60. package/dist/src/modules/recurrence/recurrence.db.d.ts +0 -1
  61. package/dist/src/modules/recurrence/recurrence.repository.d.ts +0 -1
  62. package/dist/src/modules/recurrence/recurrence.service.d.ts +0 -1
  63. package/dist/src/modules/recurrence/recurrence.trpc.d.ts +11 -48
  64. package/dist/src/modules/recurrence/recurrence.trpc.js +17 -17
  65. package/dist/src/modules/social/social.dto.d.ts +0 -1
  66. package/dist/src/modules/social/social.linkedin.d.ts +0 -1
  67. package/dist/src/modules/social/social.linkedin.test.d.ts +0 -1
  68. package/dist/src/modules/social/social.service.d.ts +0 -1
  69. package/dist/src/modules/social/social.types.d.ts +0 -1
  70. package/dist/src/modules/tag/tag.db.d.ts +0 -1
  71. package/dist/src/modules/tag/tag.dto.d.ts +0 -1
  72. package/dist/src/modules/tag/tag.repository.d.ts +0 -1
  73. package/dist/src/modules/tag/tag.service.d.ts +0 -1
  74. package/dist/src/modules/tag/tag.trpc.d.ts +10 -47
  75. package/dist/src/modules/tag/tag.trpc.js +15 -15
  76. package/dist/src/modules/utils/applyPagination.d.ts +0 -1
  77. package/dist/src/modules/utils/applySorting.d.ts +0 -1
  78. package/dist/src/modules/utils/getConditionsFromFilters.d.ts +0 -1
  79. package/dist/src/modules/video/video.service.d.ts +0 -1
  80. package/dist/src/modules/webhook/webhook.constants.d.ts +0 -1
  81. package/dist/src/modules/webhook/webhook.db.d.ts +0 -1
  82. package/dist/src/modules/webhook/webhook.dto.d.ts +0 -1
  83. package/dist/src/modules/webhook/webhook.repository.d.ts +0 -1
  84. package/dist/src/modules/webhook/webhook.router.d.ts +0 -1
  85. package/dist/src/modules/webhook/webhook.service.d.ts +0 -1
  86. package/dist/src/modules/workflow/workflow.db.d.ts +0 -1
  87. package/dist/src/modules/workflow/workflow.repository.d.ts +0 -1
  88. package/dist/src/modules/workflow/workflow.service.d.ts +0 -1
  89. package/dist/src/modules/workflow/workflow.trpc.d.ts +6 -43
  90. package/dist/src/modules/workflow/workflow.trpc.js +7 -7
  91. package/dist/src/modules/workflow/workflow.types.d.ts +0 -1
  92. package/dist/src/modules/workflow/workflow.utils.d.ts +0 -1
  93. package/dist/src/test/stubs/utils.d.ts +0 -1
  94. package/dist/src/trpc/context.d.ts +4 -5
  95. package/dist/src/trpc/index.d.ts +0 -1
  96. package/dist/src/trpc/procedures.d.ts +24 -25
  97. package/dist/src/trpc/utils.d.ts +0 -1
  98. package/dist/src/types.d.ts +61 -209
  99. package/dist/src/types.js +4 -5
  100. package/dist/src/utils/errors.d.ts +0 -1
  101. package/dist/src/utils/logger.d.ts +0 -1
  102. package/dist/src/utils/posthog.d.ts +0 -1
  103. package/dist/src/utils/trpc.d.ts +58 -0
  104. package/dist/src/utils/trpc.js +63 -0
  105. package/dist/src/utils/types.d.ts +0 -1
  106. package/dist/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +6 -8
  108. package/.cursor/rules/backend.mdc +0 -70
  109. package/.turbo/turbo-build.log +0 -5
  110. package/.turbo/turbo-check-types.log +0 -5
  111. package/.turbo/turbo-lint$colon$fix.log +0 -255
  112. package/CHANGELOG.md +0 -37
  113. package/dist/src/lib/posthog.d.ts.map +0 -1
  114. package/dist/src/lib/sentry.d.ts.map +0 -1
  115. package/dist/src/modules/access/access.repository.d.ts.map +0 -1
  116. package/dist/src/modules/access/access.service.d.ts.map +0 -1
  117. package/dist/src/modules/access/access.test.d.ts.map +0 -1
  118. package/dist/src/modules/access/access.utils.d.ts.map +0 -1
  119. package/dist/src/modules/ai/ai.db.d.ts.map +0 -1
  120. package/dist/src/modules/ai/ai.prompt.d.ts.map +0 -1
  121. package/dist/src/modules/ai/ai.repository.d.ts.map +0 -1
  122. package/dist/src/modules/ai/ai.router.d.ts.map +0 -1
  123. package/dist/src/modules/ai/ai.service.d.ts.map +0 -1
  124. package/dist/src/modules/ai/ai.trpc.d.ts.map +0 -1
  125. package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts.map +0 -1
  126. package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts.map +0 -1
  127. package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts.map +0 -1
  128. package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts.map +0 -1
  129. package/dist/src/modules/ai/ideogram/ideogram.service.d.ts.map +0 -1
  130. package/dist/src/modules/auth/auth.db.d.ts.map +0 -1
  131. package/dist/src/modules/auth/auth.dto.d.ts.map +0 -1
  132. package/dist/src/modules/auth/auth.lib.d.ts.map +0 -1
  133. package/dist/src/modules/auth/auth.middleware.d.ts.map +0 -1
  134. package/dist/src/modules/auth/auth.repository.d.ts.map +0 -1
  135. package/dist/src/modules/auth/auth.service.d.ts.map +0 -1
  136. package/dist/src/modules/auth/auth.trpc.d.ts.map +0 -1
  137. package/dist/src/modules/auth/auth.utils.d.ts.map +0 -1
  138. package/dist/src/modules/base/base.abstract.d.ts.map +0 -1
  139. package/dist/src/modules/base/base.dto.d.ts.map +0 -1
  140. package/dist/src/modules/base/base.grants.d.ts.map +0 -1
  141. package/dist/src/modules/base/base.grants.test.d.ts.map +0 -1
  142. package/dist/src/modules/base/base.repository.d.ts.map +0 -1
  143. package/dist/src/modules/base/base.service.d.ts.map +0 -1
  144. package/dist/src/modules/base/base.types.d.ts.map +0 -1
  145. package/dist/src/modules/billing/billing.db.d.ts.map +0 -1
  146. package/dist/src/modules/billing/billing.repository.d.ts.map +0 -1
  147. package/dist/src/modules/billing/billing.router.d.ts.map +0 -1
  148. package/dist/src/modules/billing/billing.service.d.ts.map +0 -1
  149. package/dist/src/modules/billing/billing.trpc.d.ts.map +0 -1
  150. package/dist/src/modules/clay/clay.repository.d.ts.map +0 -1
  151. package/dist/src/modules/clay/clay.service.d.ts.map +0 -1
  152. package/dist/src/modules/connect/connect.db.d.ts.map +0 -1
  153. package/dist/src/modules/connect/connect.dto.d.ts.map +0 -1
  154. package/dist/src/modules/connect/connect.linkedin.d.ts.map +0 -1
  155. package/dist/src/modules/connect/connect.oauth.d.ts.map +0 -1
  156. package/dist/src/modules/connect/connect.repository.d.ts.map +0 -1
  157. package/dist/src/modules/connect/connect.router.d.ts.map +0 -1
  158. package/dist/src/modules/connect/connect.service.d.ts.map +0 -1
  159. package/dist/src/modules/connect/connect.trpc.d.ts.map +0 -1
  160. package/dist/src/modules/connect/connect.types.d.ts.map +0 -1
  161. package/dist/src/modules/crypto/crypto.db.d.ts.map +0 -1
  162. package/dist/src/modules/crypto/crypto.repository.d.ts.map +0 -1
  163. package/dist/src/modules/crypto/crypto.service.d.ts.map +0 -1
  164. package/dist/src/modules/email/email.service.d.ts.map +0 -1
  165. package/dist/src/modules/file/file.repository.d.ts.map +0 -1
  166. package/dist/src/modules/file/file.router.d.ts.map +0 -1
  167. package/dist/src/modules/file/file.service.d.ts.map +0 -1
  168. package/dist/src/modules/recurrence/recurrence.db.d.ts.map +0 -1
  169. package/dist/src/modules/recurrence/recurrence.repository.d.ts.map +0 -1
  170. package/dist/src/modules/recurrence/recurrence.service.d.ts.map +0 -1
  171. package/dist/src/modules/recurrence/recurrence.trpc.d.ts.map +0 -1
  172. package/dist/src/modules/social/social.dto.d.ts.map +0 -1
  173. package/dist/src/modules/social/social.linkedin.d.ts.map +0 -1
  174. package/dist/src/modules/social/social.linkedin.test.d.ts.map +0 -1
  175. package/dist/src/modules/social/social.service.d.ts.map +0 -1
  176. package/dist/src/modules/social/social.types.d.ts.map +0 -1
  177. package/dist/src/modules/tag/tag.db.d.ts.map +0 -1
  178. package/dist/src/modules/tag/tag.dto.d.ts.map +0 -1
  179. package/dist/src/modules/tag/tag.repository.d.ts.map +0 -1
  180. package/dist/src/modules/tag/tag.service.d.ts.map +0 -1
  181. package/dist/src/modules/tag/tag.trpc.d.ts.map +0 -1
  182. package/dist/src/modules/utils/applyPagination.d.ts.map +0 -1
  183. package/dist/src/modules/utils/applySorting.d.ts.map +0 -1
  184. package/dist/src/modules/utils/getConditionsFromFilters.d.ts.map +0 -1
  185. package/dist/src/modules/video/video.service.d.ts.map +0 -1
  186. package/dist/src/modules/webhook/webhook.constants.d.ts.map +0 -1
  187. package/dist/src/modules/webhook/webhook.db.d.ts.map +0 -1
  188. package/dist/src/modules/webhook/webhook.dto.d.ts.map +0 -1
  189. package/dist/src/modules/webhook/webhook.repository.d.ts.map +0 -1
  190. package/dist/src/modules/webhook/webhook.router.d.ts.map +0 -1
  191. package/dist/src/modules/webhook/webhook.service.d.ts.map +0 -1
  192. package/dist/src/modules/workflow/workflow.db.d.ts.map +0 -1
  193. package/dist/src/modules/workflow/workflow.repository.d.ts.map +0 -1
  194. package/dist/src/modules/workflow/workflow.service.d.ts.map +0 -1
  195. package/dist/src/modules/workflow/workflow.trpc.d.ts.map +0 -1
  196. package/dist/src/modules/workflow/workflow.types.d.ts.map +0 -1
  197. package/dist/src/modules/workflow/workflow.utils.d.ts.map +0 -1
  198. package/dist/src/test/stubs/utils.d.ts.map +0 -1
  199. package/dist/src/trpc/context.d.ts.map +0 -1
  200. package/dist/src/trpc/index.d.ts.map +0 -1
  201. package/dist/src/trpc/procedures.d.ts.map +0 -1
  202. package/dist/src/trpc/utils.d.ts.map +0 -1
  203. package/dist/src/types.d.ts.map +0 -1
  204. package/dist/src/utils/errors.d.ts.map +0 -1
  205. package/dist/src/utils/logger.d.ts.map +0 -1
  206. package/dist/src/utils/posthog.d.ts.map +0 -1
  207. package/dist/src/utils/types.d.ts.map +0 -1
  208. package/jest.config.ts +0 -19
  209. package/src/lib/posthog.ts +0 -5
  210. package/src/lib/sentry.ts +0 -8
  211. package/src/modules/access/access.repository.ts +0 -36
  212. package/src/modules/access/access.service.ts +0 -81
  213. package/src/modules/access/access.test.ts +0 -216
  214. package/src/modules/access/access.utils.ts +0 -46
  215. package/src/modules/ai/ai.db.ts +0 -38
  216. package/src/modules/ai/ai.prompt.ts +0 -47
  217. package/src/modules/ai/ai.repository.ts +0 -53
  218. package/src/modules/ai/ai.router.ts +0 -148
  219. package/src/modules/ai/ai.service.ts +0 -310
  220. package/src/modules/ai/ai.trpc.ts +0 -22
  221. package/src/modules/ai/ideogram/ideogram.constants.ts +0 -170
  222. package/src/modules/ai/ideogram/ideogram.dto.ts +0 -64
  223. package/src/modules/ai/ideogram/ideogram.prompt.ts +0 -858
  224. package/src/modules/ai/ideogram/ideogram.repository.ts +0 -39
  225. package/src/modules/ai/ideogram/ideogram.service.ts +0 -14
  226. package/src/modules/auth/auth.db.ts +0 -224
  227. package/src/modules/auth/auth.dto.ts +0 -47
  228. package/src/modules/auth/auth.lib.ts +0 -349
  229. package/src/modules/auth/auth.middleware.ts +0 -62
  230. package/src/modules/auth/auth.repository.ts +0 -672
  231. package/src/modules/auth/auth.service.ts +0 -261
  232. package/src/modules/auth/auth.trpc.ts +0 -208
  233. package/src/modules/auth/auth.utils.ts +0 -117
  234. package/src/modules/base/base.abstract.ts +0 -62
  235. package/src/modules/base/base.dto.ts +0 -206
  236. package/src/modules/base/base.grants.test.ts +0 -861
  237. package/src/modules/base/base.grants.ts +0 -199
  238. package/src/modules/base/base.repository.ts +0 -433
  239. package/src/modules/base/base.service.ts +0 -154
  240. package/src/modules/base/base.types.ts +0 -7
  241. package/src/modules/billing/billing.db.ts +0 -27
  242. package/src/modules/billing/billing.repository.ts +0 -328
  243. package/src/modules/billing/billing.router.ts +0 -77
  244. package/src/modules/billing/billing.service.ts +0 -177
  245. package/src/modules/billing/billing.trpc.ts +0 -17
  246. package/src/modules/clay/clay.repository.ts +0 -29
  247. package/src/modules/clay/clay.service.ts +0 -61
  248. package/src/modules/connect/connect.db.ts +0 -32
  249. package/src/modules/connect/connect.dto.ts +0 -44
  250. package/src/modules/connect/connect.linkedin.ts +0 -70
  251. package/src/modules/connect/connect.oauth.ts +0 -288
  252. package/src/modules/connect/connect.repository.ts +0 -65
  253. package/src/modules/connect/connect.router.ts +0 -76
  254. package/src/modules/connect/connect.service.ts +0 -171
  255. package/src/modules/connect/connect.trpc.ts +0 -26
  256. package/src/modules/connect/connect.types.ts +0 -27
  257. package/src/modules/crypto/crypto.db.ts +0 -15
  258. package/src/modules/crypto/crypto.repository.ts +0 -13
  259. package/src/modules/crypto/crypto.service.ts +0 -57
  260. package/src/modules/email/email.service.ts +0 -222
  261. package/src/modules/file/file.repository.ts +0 -95
  262. package/src/modules/file/file.router.ts +0 -108
  263. package/src/modules/file/file.service.ts +0 -186
  264. package/src/modules/recurrence/recurrence.db.ts +0 -79
  265. package/src/modules/recurrence/recurrence.repository.ts +0 -70
  266. package/src/modules/recurrence/recurrence.service.ts +0 -105
  267. package/src/modules/recurrence/recurrence.trpc.ts +0 -82
  268. package/src/modules/social/social.dto.ts +0 -22
  269. package/src/modules/social/social.linkedin.test.ts +0 -277
  270. package/src/modules/social/social.linkedin.ts +0 -593
  271. package/src/modules/social/social.service.ts +0 -112
  272. package/src/modules/social/social.types.ts +0 -43
  273. package/src/modules/tag/tag.db.ts +0 -41
  274. package/src/modules/tag/tag.dto.ts +0 -18
  275. package/src/modules/tag/tag.repository.ts +0 -222
  276. package/src/modules/tag/tag.service.ts +0 -48
  277. package/src/modules/tag/tag.trpc.ts +0 -62
  278. package/src/modules/uploads/0581796b-8845-420d-bd95-cd7de79f6d37.webm +0 -0
  279. package/src/modules/uploads/33b1e649-6727-4bd0-94d0-a0b363646865.webm +0 -0
  280. package/src/modules/uploads/49a8c4c0-54d7-4c94-bef4-c93c029f9ed0.webm +0 -0
  281. package/src/modules/uploads/50e31e38-a2f0-47ca-8b7d-2d7fcad9267d.webm +0 -0
  282. package/src/modules/uploads/72ac8cf9-c3a7-4cd8-8a78-6d8e137a4c7e.webm +0 -0
  283. package/src/modules/uploads/75293649-d966-46cd-a675-67518958ae9c.png +0 -0
  284. package/src/modules/uploads/88b7b867-ce15-4891-bf73-81305a7de1f7.wav +0 -0
  285. package/src/modules/uploads/a5d6fee8-6a59-42c6-9d4a-ac8a3c5e7245.webm +0 -0
  286. package/src/modules/uploads/c13a9785-ca5a-4983-af30-b338ed76d370.webm +0 -0
  287. package/src/modules/uploads/caa1a5a7-71ba-4381-902d-7e2cafdf6dcb.webm +0 -0
  288. package/src/modules/uploads/cbeb0b81-374d-445b-914b-40ace7c8e031.webm +0 -0
  289. package/src/modules/uploads/d626aa82-b10f-493f-aee7-87bfb3361dfc.webm +0 -0
  290. package/src/modules/uploads/d7de4c16-de0c-495d-9612-e72260a6ecca.png +0 -0
  291. package/src/modules/uploads/e532e38a-6421-400e-8a5f-8e7bc8ce411b.wav +0 -0
  292. package/src/modules/uploads/e86ec867-6adf-4c51-84e0-00b0836625e8.webm +0 -0
  293. package/src/modules/utils/applyPagination.ts +0 -13
  294. package/src/modules/utils/applySorting.ts +0 -21
  295. package/src/modules/utils/getConditionsFromFilters.ts +0 -216
  296. package/src/modules/video/video.service.ts +0 -89
  297. package/src/modules/webhook/webhook.constants.ts +0 -9
  298. package/src/modules/webhook/webhook.db.ts +0 -15
  299. package/src/modules/webhook/webhook.dto.ts +0 -9
  300. package/src/modules/webhook/webhook.repository.ts +0 -68
  301. package/src/modules/webhook/webhook.router.ts +0 -29
  302. package/src/modules/webhook/webhook.service.ts +0 -78
  303. package/src/modules/workflow/workflow.db.ts +0 -29
  304. package/src/modules/workflow/workflow.repository.ts +0 -171
  305. package/src/modules/workflow/workflow.service.ts +0 -56
  306. package/src/modules/workflow/workflow.trpc.ts +0 -26
  307. package/src/modules/workflow/workflow.types.ts +0 -30
  308. package/src/modules/workflow/workflow.utils.ts +0 -259
  309. package/src/test/stubs/utils.ts +0 -2
  310. package/src/trpc/context.ts +0 -21
  311. package/src/trpc/index.ts +0 -3
  312. package/src/trpc/procedures.ts +0 -43
  313. package/src/trpc/utils.ts +0 -20
  314. package/src/types.ts +0 -22
  315. package/src/utils/errors.ts +0 -148
  316. package/src/utils/logger.ts +0 -8
  317. package/src/utils/posthog.ts +0 -43
  318. package/src/utils/types.ts +0 -5
  319. package/tsconfig.json +0 -21
@@ -1,81 +0,0 @@
1
- import type { Statements } from "better-auth/plugins/access";
2
- import { err, ok } from "neverthrow";
3
- import type { AccessRepository } from "#modules/access/access.repository";
4
- import type { AccessControlRoles } from "#modules/access/access.utils";
5
- import type { ServerResultAsync } from "#modules/base/base.dto";
6
- import { BaseService } from "#modules/base/base.service";
7
-
8
- type User = {
9
- id: string;
10
- role: string;
11
- };
12
-
13
- export class AccessService<T extends Statements> extends BaseService<
14
- { access: AccessRepository },
15
- never
16
- > {
17
- acr: AccessControlRoles<T>;
18
-
19
- constructor(repositories: { access: AccessRepository }, acr: AccessControlRoles<T>) {
20
- super(repositories);
21
- this.acr = acr;
22
- }
23
-
24
- authorize(
25
- level: "user" | "team" | "organization",
26
- role: string,
27
- request: any,
28
- connector: "OR" | "AND" = "AND"
29
- ) {
30
- try {
31
- return !!this.acr[level][role].authorize(request, connector).success;
32
- } catch (error) {
33
- console.error(error);
34
- return false;
35
- }
36
- }
37
-
38
- async checkAccess(
39
- user: User,
40
- level: "team" | "organization",
41
- levelId: string,
42
- request: any,
43
- connector: "OR" | "AND" = "AND"
44
- ): ServerResultAsync<boolean> {
45
- const role =
46
- level === "organization"
47
- ? await this.repository.access.getOrganizationRole(user.id, levelId)
48
- : await this.repository.access.getTeamRole(user.id, levelId);
49
- if (role.isErr()) return err(role.error);
50
- return ok(this.authorize(level, role.value, request, connector));
51
- }
52
-
53
- async hasAccess(
54
- user: User,
55
- level: "user" | "team" | "organization",
56
- levelId: string,
57
- request: any,
58
- connector: "OR" | "AND" = "AND"
59
- ): ServerResultAsync<boolean> {
60
- // FIXME: catch all admin user access for now
61
- if (user.role === "admin") return ok(true);
62
- const userAccess = this.authorize("user", user.role, request, connector);
63
- if (level === "user") return ok(userAccess && user.id === levelId);
64
- if (userAccess) return ok(true);
65
-
66
- const organizationAccess = await this.checkAccess(
67
- user,
68
- "organization",
69
- levelId,
70
- request,
71
- connector
72
- );
73
- if (organizationAccess.isErr()) return err(organizationAccess.error);
74
- if (level === "organization") return organizationAccess;
75
- if (organizationAccess.value) return ok(true);
76
-
77
- const teamAccess = await this.checkAccess(user, "team", levelId, request, connector);
78
- if (teamAccess.isErr()) return err(teamAccess.error);
79
- return teamAccess;
80
- }
81
- }
@@ -1,216 +0,0 @@
1
- import { createClient } from "@libsql/client";
2
- import type { LibSQLDatabase } from "drizzle-orm/libsql";
3
- import { drizzle } from "drizzle-orm/libsql";
4
- import fs from "fs";
5
- import path from "path";
6
- import { AccessRepository } from "#modules/access/access.repository";
7
- import { AccessService } from "#modules/access/access.service";
8
- import { createAccessRoles } from "#modules/access/access.utils";
9
- import * as authSchema from "#modules/auth/auth.db";
10
-
11
- describe("AccessService", () => {
12
- const statements = {
13
- project: ["create", "share", "update", "delete"],
14
- } as const;
15
-
16
- const roleDefinitions = {
17
- user: {
18
- admin: { project: ["create", "share", "update"] },
19
- },
20
- team: {
21
- admin: { project: ["create", "share", "update"] },
22
- },
23
- organization: {
24
- admin: { project: ["create", "share", "update"] },
25
- },
26
- } as const;
27
-
28
- const acr = createAccessRoles(statements, roleDefinitions);
29
- // Minimal repository stub; not used by authorize() unit tests
30
- const accessService = new AccessService({ access: {} as unknown as AccessRepository }, acr);
31
-
32
- describe("user level", () => {
33
- it("allows defined action", () => {
34
- expect(accessService.authorize("user", "admin", { project: ["create"] })).toBe(true);
35
- });
36
-
37
- it("denies undefined action", () => {
38
- expect(accessService.authorize("user", "admin", { project: ["delete"] })).toBe(false);
39
- });
40
-
41
- it("handles AND vs OR connectors for multiple actions", () => {
42
- // admin has create but not delete
43
- expect(
44
- accessService.authorize("user", "admin", { project: ["create", "delete"] }, "AND")
45
- ).toBe(false);
46
- expect(
47
- accessService.authorize(
48
- "user",
49
- "admin",
50
- { project: { actions: ["create", "delete"], connector: "OR" } },
51
- "OR"
52
- )
53
- ).toBe(true);
54
- });
55
- });
56
-
57
- describe("team level", () => {
58
- it("allows defined action", () => {
59
- expect(accessService.authorize("team", "admin", { project: ["share"] })).toBe(true);
60
- });
61
-
62
- it("denies undefined action", () => {
63
- expect(accessService.authorize("team", "admin", { project: ["delete"] })).toBe(false);
64
- });
65
- });
66
-
67
- describe("organization level", () => {
68
- it("allows defined action", () => {
69
- expect(accessService.authorize("organization", "admin", { project: ["update"] })).toBe(true);
70
- });
71
-
72
- it("denies undefined action", () => {
73
- expect(accessService.authorize("organization", "admin", { project: ["delete"] })).toBe(false);
74
- });
75
- });
76
- });
77
-
78
- describe("AccessRepository (libsql local)", () => {
79
- const dbFile = path.join(__dirname, "access.test.sqlite");
80
- const url = `file:${dbFile}`;
81
- const client = createClient({ url });
82
- type Schema = typeof authSchema;
83
- type Orm = LibSQLDatabase<Schema>;
84
- const orm = drizzle(client, { schema: authSchema }) as Orm;
85
- const repo = new AccessRepository({ orm, schema: authSchema as Schema }, {});
86
-
87
- beforeAll(async () => {
88
- // Create minimal tables required for tests
89
- await client.execute(`
90
- CREATE TABLE IF NOT EXISTS members (
91
- id TEXT PRIMARY KEY,
92
- organization_id TEXT NOT NULL,
93
- user_id TEXT NOT NULL,
94
- role TEXT NOT NULL
95
- );
96
- `);
97
- await client.execute(`
98
- CREATE TABLE IF NOT EXISTS teammembers (
99
- id TEXT PRIMARY KEY,
100
- team_id TEXT NOT NULL,
101
- user_id TEXT NOT NULL,
102
- role TEXT NOT NULL
103
- );
104
- `);
105
- });
106
-
107
- beforeEach(async () => {
108
- await client.execute({
109
- sql: "INSERT INTO members (id, organization_id, user_id, role) VALUES (?, ?, ?, ?)",
110
- args: ["m1", "org1", "user1", "admin"],
111
- });
112
- await client.execute({
113
- sql: "INSERT INTO teammembers (id, team_id, user_id, role) VALUES (?, ?, ?, ?)",
114
- args: ["tm1", "team1", "user1", "admin"],
115
- });
116
- });
117
-
118
- afterEach(async () => {
119
- await client.execute("DELETE FROM members;");
120
- await client.execute("DELETE FROM teammembers;");
121
- });
122
-
123
- afterAll(async () => {
124
- try {
125
- await client.close();
126
- } catch {}
127
- try {
128
- if (fs.existsSync(dbFile)) fs.unlinkSync(dbFile);
129
- } catch {}
130
- });
131
-
132
- it("returns organization role for user", async () => {
133
- const res = await repo.getOrganizationRole("user1", "org1");
134
- expect(res.isOk()).toBe(true);
135
- if (res.isOk()) expect(res.value).toBe("admin");
136
- });
137
-
138
- it("returns team role for user", async () => {
139
- const res = await repo.getTeamRole("user1", "team1");
140
- expect(res.isOk()).toBe(true);
141
- if (res.isOk()) expect(res.value).toBe("admin");
142
- });
143
-
144
- describe("AccessService.hasAccess (with repo)", () => {
145
- const hasAccessStatements = {
146
- project: ["create", "share", "update", "delete"],
147
- } as const;
148
-
149
- const hasAccessRoles = {
150
- user: {
151
- member: { project: ["create"] },
152
- },
153
- team: {
154
- manager: { project: ["share"] },
155
- },
156
- organization: {
157
- manager: { project: ["update"] },
158
- },
159
- } as const;
160
-
161
- const acr2 = createAccessRoles(hasAccessStatements, hasAccessRoles);
162
- const service = new AccessService({ access: repo }, acr2);
163
-
164
- it("admin override grants access", async () => {
165
- const result = await service.hasAccess(
166
- { id: "any", role: "admin" },
167
- "organization",
168
- "whatever",
169
- { project: ["delete"] }
170
- );
171
- expect(result.isOk()).toBe(true);
172
- if (result.isOk()) expect(result.value).toBe(true);
173
- });
174
-
175
- it("user level access only for self and allowed action", async () => {
176
- const allowSelf = await service.hasAccess({ id: "user2", role: "member" }, "user", "user2", {
177
- project: ["create"],
178
- });
179
- expect(allowSelf.isOk()).toBe(true);
180
- if (allowSelf.isOk()) expect(allowSelf.value).toBe(true);
181
-
182
- const denyOther = await service.hasAccess({ id: "user2", role: "member" }, "user", "other", {
183
- project: ["create"],
184
- });
185
- expect(denyOther.isOk()).toBe(true);
186
- if (denyOther.isOk()) expect(denyOther.value).toBe(false);
187
- });
188
-
189
- it("organization membership grants access based on repo role", async () => {
190
- await client.execute({
191
- sql: "INSERT INTO members (id, organization_id, user_id, role) VALUES (?, ?, ?, ?)",
192
- args: ["m2", "org2", "user2", "manager"],
193
- });
194
- const result = await service.hasAccess(
195
- { id: "user2", role: "member" },
196
- "organization",
197
- "org2",
198
- { project: ["update"] }
199
- );
200
- expect(result.isOk()).toBe(true);
201
- if (result.isOk()) expect(result.value).toBe(true);
202
- });
203
-
204
- it("team membership grants access based on repo role", async () => {
205
- await client.execute({
206
- sql: "INSERT INTO teammembers (id, team_id, user_id, role) VALUES (?, ?, ?, ?)",
207
- args: ["tm2", "team2", "user2", "manager"],
208
- });
209
- const result = await service.hasAccess({ id: "user2", role: "member" }, "team", "team2", {
210
- project: ["share"],
211
- });
212
- expect(result.isOk()).toBe(true);
213
- if (result.isOk()) expect(result.value).toBe(true);
214
- });
215
- });
216
- });
@@ -1,46 +0,0 @@
1
- import {
2
- type AccessControl,
3
- createAccessControl,
4
- type Role,
5
- type Statements,
6
- type Subset,
7
- } from "better-auth/plugins/access";
8
-
9
- export type AccessControlRoles<T extends Statements> = {
10
- ac: AccessControl<T>;
11
- user: Record<string, Role<Subset<keyof T, T>>>;
12
- team: Record<string, Role<Subset<keyof T, T>>>;
13
- organization: Record<string, Role<Subset<keyof T, T>>>;
14
- };
15
-
16
- // Allow defining role statements with any subset of resources from T
17
- // and only actions permitted by each resource definition in T
18
- export type RoleDefinition<T extends Statements> = {
19
- [K in keyof T]?: T[K] extends readonly (infer A)[] ? readonly A[] : never;
20
- };
21
-
22
- export type RoleDefinitions<T extends Statements> = {
23
- user: Record<string, RoleDefinition<T>>;
24
- team: Record<string, RoleDefinition<T>>;
25
- organization: Record<string, RoleDefinition<T>>;
26
- };
27
-
28
- export function createAccessRoles<T extends Statements>(
29
- statements: T,
30
- roleDefinitions: RoleDefinitions<T>
31
- ): AccessControlRoles<T> {
32
- const ac = createAccessControl(statements);
33
- const user: Record<string, Role<Subset<keyof T, T>>> = {};
34
- const team: Record<string, Role<Subset<keyof T, T>>> = {};
35
- const organization: Record<string, Role<Subset<keyof T, T>>> = {};
36
- for (const [roleName, roleStatements] of Object.entries(roleDefinitions.user)) {
37
- user[roleName] = ac.newRole(roleStatements as unknown as Subset<keyof T, T>);
38
- }
39
- for (const [roleName, roleStatements] of Object.entries(roleDefinitions.team)) {
40
- team[roleName] = ac.newRole(roleStatements as unknown as Subset<keyof T, T>);
41
- }
42
- for (const [roleName, roleStatements] of Object.entries(roleDefinitions.organization)) {
43
- organization[roleName] = ac.newRole(roleStatements as unknown as Subset<keyof T, T>);
44
- }
45
- return { ac, user, team, organization };
46
- }
@@ -1,38 +0,0 @@
1
- import { integer, real, sqliteTable as table, text } from "drizzle-orm/sqlite-core";
2
- import { v4 as uuidv4 } from "uuid";
3
- import { organizations, teams, users } from "#modules/auth/auth.db";
4
-
5
- export const chats = table("chats", {
6
- id: text("id").primaryKey().$default(uuidv4),
7
- userId: text("user_id")
8
- .notNull()
9
- .references(() => users.id, { onDelete: "cascade" }),
10
- title: text("title"),
11
- type: text("type"),
12
- conversation: text("conversation", { mode: "json" }),
13
- createdAt: integer("created_at", { mode: "timestamp" }).$default(() => new Date()),
14
- updatedAt: integer("updated_at", { mode: "timestamp" })
15
- .notNull()
16
- .$default(() => new Date()),
17
- });
18
-
19
- export const aiUsage = table("ai_usage", {
20
- id: text("id").primaryKey().$default(uuidv4),
21
- userId: text("user_id").references(() => users.id, { onDelete: "cascade" }),
22
- teamId: text("team_id").references(() => teams.id, { onDelete: "cascade" }),
23
- organizationId: text("organization_id").references(() => organizations.id, {
24
- onDelete: "cascade",
25
- }),
26
- feature: text("feature").notNull(),
27
- provider: text("provider").notNull(),
28
- model: text("model").notNull(),
29
- inputTokens: integer("input_tokens"),
30
- outputTokens: integer("output_tokens"),
31
- totalTokens: integer("total_tokens"),
32
- cost: real("cost"),
33
- traceId: text("trace_id"),
34
- createdAt: integer("created_at", { mode: "timestamp" })
35
- .notNull()
36
- .$default(() => new Date()),
37
- metadata: text("metadata", { mode: "json" }),
38
- });
@@ -1,47 +0,0 @@
1
- import type { AiModel } from "@m5kdev/commons/modules/ai/ai.constants";
2
- import mustache from "mustache";
3
- import { logger } from "#utils/logger";
4
-
5
- export class Prompt<C extends Record<string, string>> {
6
- public prompt: string;
7
- public name?: string;
8
- public type: "text" | "chat";
9
- public config?: {
10
- model?: AiModel;
11
- temperature?: number;
12
- supported_languages?: string[];
13
- };
14
- public version?: number;
15
- public labels?: string[];
16
- public tags?: string[];
17
-
18
- constructor(
19
- prompt: string,
20
- settings?: {
21
- name?: string;
22
- type?: "text" | "chat";
23
- config?: {
24
- model?: AiModel;
25
- temperature?: number;
26
- supported_languages?: string[];
27
- };
28
- version?: number;
29
- labels?: string[];
30
- tags?: string[];
31
- }
32
- ) {
33
- this.prompt = prompt;
34
- this.name = settings?.name;
35
- this.type = settings?.type ?? "text";
36
- this.config = settings?.config;
37
- this.version = settings?.version;
38
- this.labels = settings?.labels;
39
- this.tags = settings?.tags;
40
- }
41
-
42
- compile(context: C): string {
43
- const result = mustache.render(this.prompt.trim(), context);
44
- logger.debug(`[PROMPT]: ${result.trim()}`);
45
- return result.trim();
46
- }
47
- }
@@ -1,53 +0,0 @@
1
- import type { InferInsertModel, InferSelectModel } from "drizzle-orm";
2
- import { eq, sql } from "drizzle-orm";
3
- import type { LibSQLDatabase } from "drizzle-orm/libsql";
4
- import { ok } from "neverthrow";
5
- import * as ai from "#modules/ai/ai.db";
6
- import type { ServerResultAsync } from "#modules/base/base.dto";
7
- import { BaseTableRepository } from "#modules/base/base.repository";
8
-
9
- const schema = { ...ai };
10
- type Schema = typeof schema;
11
- type Orm = LibSQLDatabase<Schema>;
12
-
13
- export type AiUsageRow = InferSelectModel<Schema["aiUsage"]>;
14
- export type AiUsageInsert = InferInsertModel<Schema["aiUsage"]>;
15
-
16
- export interface CreateAiUsageInput {
17
- userId?: string;
18
- teamId?: string;
19
- organizationId?: string;
20
- feature: string;
21
- provider: string;
22
- model: string;
23
- inputTokens?: number;
24
- outputTokens?: number;
25
- totalTokens?: number;
26
- cost?: number;
27
- traceId?: string;
28
- metadata?: unknown;
29
- }
30
-
31
- export class AiUsageRepository extends BaseTableRepository<
32
- Orm,
33
- Schema,
34
- Record<string, never>,
35
- Schema["aiUsage"]
36
- > {
37
- getUsage(
38
- userId: string
39
- ): ServerResultAsync<Pick<AiUsageRow, "inputTokens" | "outputTokens" | "totalTokens" | "cost">> {
40
- return this.throwableAsync(async () => {
41
- const [usage] = await this.orm
42
- .select({
43
- inputTokens: sql<number>`SUM(${this.table.inputTokens})`,
44
- outputTokens: sql<number>`SUM(${this.table.outputTokens})`,
45
- totalTokens: sql<number>`SUM(${this.table.totalTokens})`,
46
- cost: sql<number>`SUM(${this.table.cost})`,
47
- })
48
- .from(this.table)
49
- .where(eq(this.table.userId, userId));
50
- return ok(usage);
51
- });
52
- }
53
- }
@@ -1,148 +0,0 @@
1
- // import { openai } from "@ai-sdk/openai";
2
- // import { open}
3
- // import { withTracing } from "@posthog/ai";
4
- // import {
5
- // appendClientMessage,
6
- // appendResponseMessages,
7
- // type Message,
8
- // streamText,
9
- // type Tool,
10
- // } from "ai";
11
- // import bodyParser from "body-parser";
12
- // import { and, eq } from "drizzle-orm";
13
- // import express, { type Response, type Router } from "express";
14
- // import { v4 as uuidv4 } from "uuid";
15
- // import type { AuthRequest, createAuthMiddleware } from "../auth/auth.middleware";
16
- // import { type Orm, schema } from "../db";
17
- // import { logger } from "../logger";
18
- // import { posthogClient } from "../posthog";
19
-
20
- // export type Tooling = Record<
21
- // string,
22
- // {
23
- // getMesseges: (chatId: string) => Promise<Message[]>;
24
- // getTools: (chatId: string) => Promise<
25
- // Record<
26
- // string,
27
- // {
28
- // tool: Tool;
29
- // handler?: (
30
- // chatId: string,
31
- // args: unknown,
32
- // user: NonNullable<AuthRequest["user"]>
33
- // ) => Promise<void>;
34
- // }
35
- // >
36
- // >;
37
- // }
38
- // >;
39
-
40
- // export function tracedOpenAiModel(
41
- // model: Parameters<typeof openai>[0],
42
- // clientOptions: Parameters<typeof withTracing>[2]
43
- // ) {
44
- // return withTracing(openai(model), posthogClient, clientOptions);
45
- // }
46
-
47
- // async function getRouteSettings(id: string, name: string, settings: Tooling) {
48
- // const entity = settings[name as keyof typeof settings];
49
- // if (!entity) return { tools: {}, entityMesseges: [], entityTools: {} };
50
-
51
- // const entityTools = await entity.getTools(id);
52
- // const entityMesseges = await entity.getMesseges(id);
53
-
54
- // const tools = Object.entries(entityTools).reduce<
55
- // Record<string, (typeof entityTools)[keyof typeof entityTools]["tool"]>
56
- // >((acc, [key, value]) => {
57
- // acc[key] = value.tool as (typeof entityTools)[keyof typeof entityTools]["tool"];
58
- // return acc;
59
- // }, {});
60
-
61
- // return { tools, entityMesseges, entityTools };
62
- // }
63
-
64
- // export function createAiRouter(
65
- // orm: Orm,
66
- // authMiddleware: ReturnType<typeof createAuthMiddleware>,
67
- // settings: Tooling
68
- // ) {
69
- // const aiRouter: Router = express.Router();
70
-
71
- // aiRouter.use(bodyParser.json());
72
-
73
- // aiRouter.post("/completion/:name", authMiddleware, async (req: AuthRequest, res: Response) => {
74
- // try {
75
- // const { id, message } = req.body as {
76
- // id: string;
77
- // message: Message;
78
- // };
79
- // logger.info(req.body, "body");
80
- // const { name } = req.params;
81
- // const user = req.user!;
82
- // logger.info(message, "Received message:");
83
-
84
- // const { tools, entityMesseges, entityTools } = await getRouteSettings(id, name, settings);
85
-
86
- // const [chat] = await orm
87
- // .select()
88
- // .from(schema.chats)
89
- // .where(and(eq(schema.chats.id, id), eq(schema.chats.userId, user.id)));
90
- // if (!chat) throw new Error("Chat not found");
91
-
92
- // const messages = appendClientMessage({
93
- // messages: (chat.conversation || []) as Message[],
94
- // message,
95
- // });
96
-
97
- // // Process any tool invocations in the message
98
- // const toolInvocation = message?.parts?.find((p) => p.type === "tool-invocation");
99
-
100
- // if (toolInvocation) {
101
- // logger.info(toolInvocation, "Processing tool invocation:");
102
- // const tool =
103
- // entityTools[toolInvocation.toolInvocation.toolName as keyof typeof entityTools];
104
- // if (tool?.handler) {
105
- // const result = await tool.handler(id, toolInvocation.toolInvocation.args, user);
106
- // logger.info({ result }, "Tool handler result:");
107
- // }
108
- // }
109
-
110
- // logger.info([...entityMesseges, ...messages], "Processed messages");
111
-
112
- // const result = streamText({
113
- // model: tracedOpenAiModel("gpt-4o", {
114
- // posthogDistinctId: user.id,
115
- // posthogProperties: { conversation_id: id, paid: true },
116
- // posthogPrivacyMode: false,
117
- // }),
118
- // experimental_generateMessageId: uuidv4,
119
- // messages: [...entityMesseges, ...messages],
120
- // async onFinish({ response }) {
121
- // logger.info(response, "Final response:");
122
- // try {
123
- // await orm
124
- // .update(schema.chats)
125
- // .set({
126
- // conversation: appendResponseMessages({
127
- // messages,
128
- // responseMessages: response.messages,
129
- // }),
130
- // })
131
- // .where(eq(schema.chats.id, id));
132
- // } catch (error) {
133
- // logger.error("Error in onFinish handler:", error);
134
- // }
135
- // },
136
- // tools,
137
- // });
138
-
139
- // result.consumeStream();
140
- // result.pipeDataStreamToResponse(res);
141
- // } catch (error) {
142
- // logger.error(error, "Error in ai handler");
143
- // res.status(500).send({ error: "Internal Server Error" });
144
- // }
145
- // });
146
-
147
- // return aiRouter;
148
- // }