@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,171 +0,0 @@
1
- import type {
2
- WorkflowListInputSchema,
3
- WorkflowListOutputSchema,
4
- WorkflowReadOutputSchema,
5
- } from "@m5kdev/commons/modules/workflow/workflow.schema";
6
- import { and, eq, inArray } from "drizzle-orm";
7
- import type { LibSQLDatabase } from "drizzle-orm/libsql";
8
- import { ok } from "neverthrow";
9
- import type { ServerResultAsync } from "#modules/base/base.dto";
10
- import { BaseRepository } from "#modules/base/base.repository";
11
- import * as workflow from "#modules/workflow/workflow.db";
12
-
13
- const schema = { ...workflow };
14
-
15
- type Schema = typeof schema;
16
- type Orm = LibSQLDatabase<Schema>;
17
-
18
- export class WorkflowRepository extends BaseRepository<Orm, Schema, Record<string, never>> {
19
- async read({
20
- jobId,
21
- userId,
22
- }: {
23
- jobId: string;
24
- userId: string;
25
- }): ServerResultAsync<WorkflowReadOutputSchema> {
26
- return this.throwableAsync(async () => {
27
- const [wf] = await this.orm
28
- .select()
29
- .from(this.schema.workflows)
30
- .where(
31
- and(eq(this.schema.workflows.jobId, jobId), eq(this.schema.workflows.userId, userId))
32
- );
33
- if (!wf) return this.error("NOT_FOUND");
34
- return ok(wf);
35
- });
36
- }
37
-
38
- async list({
39
- userId,
40
- status,
41
- jobName,
42
- }: WorkflowListInputSchema & {
43
- userId: string;
44
- }): ServerResultAsync<WorkflowListOutputSchema> {
45
- return this.throwableAsync(async () => {
46
- const { ConditionBuilder } = this.helpers;
47
- const condition = new ConditionBuilder([eq(this.schema.workflows.userId, userId)]);
48
- if (status) condition.push(inArray(this.schema.workflows.status, status));
49
- if (jobName) condition.push(eq(this.schema.workflows.jobName, jobName));
50
-
51
- const workflows = await this.orm.select().from(this.schema.workflows).where(condition.join());
52
-
53
- return ok(workflows);
54
- });
55
- }
56
-
57
- async added({
58
- userId,
59
- jobId,
60
- jobName,
61
- queueName,
62
- timeout,
63
- tags,
64
- input,
65
- }: {
66
- userId?: string;
67
- jobId: string;
68
- jobName: string;
69
- queueName: string;
70
- timeout?: number;
71
- tags?: string[];
72
- input: unknown;
73
- }): ServerResultAsync<WorkflowReadOutputSchema> {
74
- return this.throwableAsync(async () => {
75
- const [wf] = await this.orm
76
- .insert(this.schema.workflows)
77
- .values({
78
- userId,
79
- jobId,
80
- jobName,
81
- input,
82
- status: "queued",
83
- queueName,
84
- timeout,
85
- tags,
86
- createdAt: new Date(),
87
- updatedAt: new Date(),
88
- })
89
- .returning();
90
- return ok(wf);
91
- });
92
- }
93
-
94
- async addedMany(
95
- data: {
96
- userId?: string;
97
- jobId: string;
98
- jobName: string;
99
- queueName: string;
100
- timeout?: number;
101
- tags?: string[];
102
- input: unknown;
103
- }[]
104
- ): ServerResultAsync<WorkflowReadOutputSchema[]> {
105
- return this.throwableAsync(async () => {
106
- const wfs = await this.orm
107
- .insert(this.schema.workflows)
108
- .values(
109
- data.map((d) => ({
110
- userId: d.userId,
111
- jobId: d.jobId,
112
- jobName: d.jobName,
113
- queueName: d.queueName,
114
- timeout: d.timeout,
115
- tags: d.tags,
116
- input: d.input,
117
- status: "queued" as const,
118
- createdAt: new Date(),
119
- updatedAt: new Date(),
120
- }))
121
- )
122
- .returning();
123
- return ok(wfs);
124
- });
125
- }
126
-
127
- async started({ jobId }: { jobId: string }): ServerResultAsync<WorkflowReadOutputSchema> {
128
- return this.throwableAsync(async () => {
129
- const [wf] = await this.orm
130
- .update(this.schema.workflows)
131
- .set({ status: "running", updatedAt: new Date(), processedAt: new Date() })
132
- .where(eq(this.schema.workflows.jobId, jobId))
133
- .returning();
134
- return ok(wf);
135
- });
136
- }
137
-
138
- async failed({
139
- jobId,
140
- error,
141
- }: {
142
- jobId: string;
143
- error: string;
144
- }): ServerResultAsync<WorkflowReadOutputSchema> {
145
- return this.throwableAsync(async () => {
146
- const [wf] = await this.orm
147
- .update(this.schema.workflows)
148
- .set({ status: "failed", error, updatedAt: new Date(), finishedAt: new Date() })
149
- .where(eq(this.schema.workflows.jobId, jobId))
150
- .returning();
151
- return ok(wf);
152
- });
153
- }
154
-
155
- async completed({
156
- jobId,
157
- output,
158
- }: {
159
- jobId: string;
160
- output: unknown;
161
- }): ServerResultAsync<WorkflowReadOutputSchema> {
162
- return this.throwableAsync(async () => {
163
- const [wf] = await this.orm
164
- .update(this.schema.workflows)
165
- .set({ status: "completed", updatedAt: new Date(), finishedAt: new Date(), output })
166
- .where(eq(this.schema.workflows.jobId, jobId))
167
- .returning();
168
- return ok(wf);
169
- });
170
- }
171
- }
@@ -1,56 +0,0 @@
1
- import type {
2
- WorkflowListInputSchema,
3
- WorkflowListOutputSchema,
4
- WorkflowReadInputSchema,
5
- WorkflowReadOutputSchema,
6
- } from "@m5kdev/commons/modules/workflow/workflow.schema";
7
- import type { Job } from "bullmq";
8
- import type { User } from "#modules/auth/auth.lib";
9
- import type { ServerResultAsync } from "#modules/base/base.dto";
10
- import { BaseService } from "#modules/base/base.service";
11
- import type { WorkflowRepository } from "#modules/workflow/workflow.repository";
12
- export class WorkflowService extends BaseService<{ workflow: WorkflowRepository }, never> {
13
- async read(
14
- input: WorkflowReadInputSchema,
15
- { user }: { user: User }
16
- ): ServerResultAsync<WorkflowReadOutputSchema> {
17
- return await this.repository.workflow.read({ ...input, userId: user.id });
18
- }
19
-
20
- async list(
21
- input: WorkflowListInputSchema,
22
- { user }: { user: User }
23
- ): ServerResultAsync<WorkflowListOutputSchema> {
24
- return await this.repository.workflow.list({ ...input, userId: user.id });
25
- }
26
-
27
- async added(
28
- params: Parameters<WorkflowRepository["added"]>[0]
29
- ): ServerResultAsync<WorkflowReadOutputSchema> {
30
- return this.repository.workflow.added(params);
31
- }
32
-
33
- async addedMany(
34
- params: Parameters<WorkflowRepository["addedMany"]>[0]
35
- ): ServerResultAsync<WorkflowReadOutputSchema[]> {
36
- return this.repository.workflow.addedMany(params);
37
- }
38
-
39
- async started(job: Job): ServerResultAsync<WorkflowReadOutputSchema> {
40
- if (!job.id) return this.error("INTERNAL_SERVER_ERROR");
41
- return this.repository.workflow.started({ jobId: job.id });
42
- }
43
-
44
- async failed(job?: Job, error?: Error): ServerResultAsync<WorkflowReadOutputSchema> {
45
- if (!job?.id) return this.error("INTERNAL_SERVER_ERROR");
46
- return this.repository.workflow.failed({
47
- jobId: job.id,
48
- error: error?.message || "Unknown error",
49
- });
50
- }
51
-
52
- async completed(job: Job): ServerResultAsync<WorkflowReadOutputSchema> {
53
- if (!job.id) return this.error("INTERNAL_SERVER_ERROR");
54
- return this.repository.workflow.completed({ jobId: job.id, output: job.returnvalue });
55
- }
56
- }
@@ -1,26 +0,0 @@
1
- import {
2
- workflowListInputSchema,
3
- workflowListOutputSchema,
4
- workflowReadInputSchema,
5
- workflowReadOutputSchema,
6
- } from "@m5kdev/commons/modules/workflow/workflow.schema";
7
- import type { WorkflowService } from "#modules/workflow/workflow.service";
8
- import { handleTRPCResult, procedure, router } from "#trpc";
9
-
10
- export function createWorkflowTRPC(workflowService: WorkflowService) {
11
- return router({
12
- read: procedure
13
- .input(workflowReadInputSchema)
14
- .output(workflowReadOutputSchema)
15
- .query(async ({ ctx, input }) => {
16
- return handleTRPCResult(await workflowService.read(input, ctx));
17
- }),
18
-
19
- list: procedure
20
- .input(workflowListInputSchema)
21
- .output(workflowListOutputSchema)
22
- .query(async ({ ctx, input }) => {
23
- return handleTRPCResult(await workflowService.list(input, ctx));
24
- }),
25
- });
26
- }
@@ -1,30 +0,0 @@
1
- import type { Job, JobsOptions } from "bullmq";
2
- import type { ServerResultAsync } from "#modules/base/base.dto";
3
- import type { ServerError } from "#utils/errors";
4
-
5
- export type WorkflowMeta = {
6
- queue?: string;
7
- userId?: string;
8
- tags?: string[];
9
- timeout?: number;
10
- disablePosthogCapture?: boolean;
11
- };
12
-
13
- export type WorkflowDataType<Payload> = {
14
- payload: Payload;
15
- meta: WorkflowMeta;
16
- };
17
-
18
- export type WorkflowJob<
19
- DataType extends WorkflowDataType<any>,
20
- ReturnType extends ServerResultAsync<any>,
21
- Name extends string,
22
- > = JobsOptions & {
23
- run: (job: Job<DataType, ReturnType, Name>) => ReturnType;
24
- onComplete?: (job: Job<DataType, ReturnType, Name>) => ReturnType;
25
- onSuccess?: (job: Job<DataType, ReturnType, Name>) => ServerResultAsync<any>;
26
- onFailure?: (
27
- job: Job<DataType, ReturnType, Name>,
28
- error?: ServerError | unknown
29
- ) => ServerResultAsync<any>;
30
- };
@@ -1,259 +0,0 @@
1
- import type { WorkflowReadOutputSchema } from "@m5kdev/commons/modules/workflow/workflow.schema";
2
- import { type JobsOptions, type Queue, Worker, type WorkerOptions } from "bullmq";
3
- import { err } from "neverthrow";
4
- import type { ServerErrorLayer } from "#modules/base/base.types";
5
- import { ServerError } from "#utils/errors";
6
- import { logger as rootLogger } from "#utils/logger";
7
- import { runWithPosthogRequestState } from "#utils/posthog";
8
- import type { ServerResultAsync } from "../base/base.dto";
9
- import type { WorkflowService } from "./workflow.service";
10
- import type { WorkflowDataType, WorkflowJob, WorkflowMeta } from "./workflow.types";
11
-
12
- const errorOptions = {
13
- layer: "workflow" as ServerErrorLayer,
14
- layerName: "WorkflowTrigger",
15
- };
16
-
17
- function shouldDisablePosthogFromPayload(payload: unknown): boolean {
18
- if (!payload || typeof payload !== "object") return false;
19
-
20
- const session = (
21
- payload as {
22
- ctx?: {
23
- session?: {
24
- impersonatedBy?: string | null;
25
- };
26
- };
27
- }
28
- ).ctx?.session;
29
-
30
- return Boolean(session?.impersonatedBy);
31
- }
32
-
33
- export function createWorkflowTrigger<
34
- Jobs extends Record<string, WorkflowJob<WorkflowDataType<any>, any, string>>,
35
- >(service: WorkflowService, queues: Record<string, Queue>, defaultQueue: string) {
36
- const trigger = async ({
37
- name,
38
- payload,
39
- meta,
40
- options,
41
- }: {
42
- name: string;
43
- payload: Parameters<Jobs[keyof Jobs & string]["run"]>[0]["data"]["payload"];
44
- meta?: WorkflowMeta;
45
- options?: JobsOptions;
46
- }): ServerResultAsync<WorkflowReadOutputSchema> => {
47
- const { queue: queueName, userId, tags, timeout = 60 * 60 * 1000 } = meta || {};
48
- const disablePosthogCapture =
49
- meta?.disablePosthogCapture ?? shouldDisablePosthogFromPayload(payload);
50
- const compiledQueueName = queueName || (defaultQueue as string);
51
-
52
- if (!compiledQueueName || !Object.keys(queues).includes(compiledQueueName)) {
53
- return err(new ServerError({ code: "NOT_FOUND", ...errorOptions }));
54
- }
55
-
56
- const queue = queues[compiledQueueName as string];
57
-
58
- if (!queue) {
59
- return err(new ServerError({ code: "NOT_FOUND", ...errorOptions }));
60
- }
61
- try {
62
- const job = await queue.add(
63
- name,
64
- {
65
- payload,
66
- meta: { ...meta, timeout, disablePosthogCapture },
67
- },
68
- {
69
- removeOnComplete: {
70
- age: 24 * 3600, // keep up to 24 hours
71
- },
72
- removeOnFail: {
73
- age: 7 * 24 * 3600, // keep up to week
74
- },
75
- ...options,
76
- }
77
- );
78
-
79
- if (!job || !job.id) {
80
- return err(new ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
81
- }
82
-
83
- return await service.added({
84
- userId,
85
- jobId: job.id,
86
- jobName: name,
87
- input: payload,
88
- timeout,
89
- queueName: compiledQueueName,
90
- tags,
91
- });
92
- } catch (error) {
93
- return err(new ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
94
- }
95
- };
96
-
97
- const triggerMany = async ({
98
- name,
99
- payload,
100
- meta,
101
- options,
102
- }: {
103
- name: string;
104
- payload: Parameters<Jobs[keyof Jobs & string]["run"]>[0]["data"]["payload"][];
105
- meta?: WorkflowMeta;
106
- options?: JobsOptions;
107
- }): ServerResultAsync<WorkflowReadOutputSchema[]> => {
108
- const { queue: queueName, userId, tags, timeout = 60 * 60 * 1000 } = meta || {};
109
- const compiledQueueName = queueName || (defaultQueue as string);
110
-
111
- if (!compiledQueueName || !Object.keys(queues).includes(compiledQueueName)) {
112
- return err(new ServerError({ code: "NOT_FOUND", ...errorOptions }));
113
- }
114
-
115
- const queue = queues[compiledQueueName as string];
116
-
117
- if (!queue) {
118
- return err(new ServerError({ code: "NOT_FOUND", ...errorOptions }));
119
- }
120
- try {
121
- const jobs = await queue.addBulk(
122
- payload.map((p) => {
123
- const disablePosthogCapture =
124
- meta?.disablePosthogCapture ?? shouldDisablePosthogFromPayload(p);
125
-
126
- return {
127
- name,
128
- data: { payload: p, meta: { ...meta, timeout, disablePosthogCapture } },
129
- options: {
130
- removeOnComplete: {
131
- age: 24 * 3600, // keep up to 24 hours
132
- },
133
- removeOnFail: {
134
- age: 7 * 24 * 3600, // keep up to week
135
- },
136
- ...options,
137
- },
138
- };
139
- })
140
- );
141
-
142
- if (!jobs || jobs.length === 0) {
143
- return err(new ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
144
- }
145
-
146
- return await service.addedMany(
147
- jobs.map((j) => ({
148
- userId,
149
- jobId: j.id as string,
150
- jobName: name,
151
- input: j.data.payload,
152
- timeout,
153
- queueName: compiledQueueName,
154
- tags,
155
- }))
156
- );
157
- } catch (error) {
158
- return err(new ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
159
- }
160
- };
161
-
162
- return { trigger, triggerMany };
163
- }
164
-
165
- export function createWorkflowWorker<
166
- Jobs extends Record<string, WorkflowJob<WorkflowDataType<any>, any, string>>,
167
- >(
168
- service: WorkflowService,
169
- queueName: string,
170
- workerOptions: WorkerOptions,
171
- jobs: Jobs,
172
- errorHandler?: (error: unknown) => void
173
- ) {
174
- const logger = rootLogger.child({ layer: "worker" });
175
-
176
- const worker = new Worker(
177
- queueName,
178
- async (job) => {
179
- const { meta } = job.data as { meta: WorkflowMeta; payload: any };
180
- return await runWithPosthogRequestState(
181
- { disableCapture: Boolean(meta?.disablePosthogCapture) },
182
- async () => {
183
- const timer =
184
- meta?.timeout &&
185
- setTimeout(() => {
186
- const error = new Error("Job timed out");
187
- errorHandler?.(error);
188
- throw error;
189
- }, job.data.meta.timeout);
190
- const handler = jobs[job.name as keyof Jobs];
191
- if (!handler) {
192
- const error = new Error(`Unknown job: ${job.name}`);
193
- errorHandler?.(error);
194
- throw error;
195
- }
196
- try {
197
- await service.started(job);
198
-
199
- const result = await handler.run(job);
200
- if (result.isErr()) {
201
- await handler.onFailure?.(job, result.error);
202
- const error = new Error(result.error.message);
203
- errorHandler?.(error);
204
- throw error;
205
- }
206
- await handler.onSuccess?.(job).catch((err: unknown) => {
207
- const error = new Error(`Job ${job.id}:${job.name} failed to run onSuccess: ${err}`);
208
- logger.error(error.message);
209
- errorHandler?.(error);
210
- });
211
- return result.value ?? null;
212
- } catch (err) {
213
- await handler.onFailure?.(job, err).catch((err: unknown) => {
214
- const error = new Error(`Job ${job.id}:${job.name} failed to run onFailure: ${err}`);
215
- logger.error(error.message);
216
- errorHandler?.(error);
217
- });
218
- if (err instanceof Error && err.message === "Job timed out")
219
- logger.error(`Job ${job.id}:${job.name} timed out`);
220
- throw err;
221
- } finally {
222
- await handler.onComplete?.(job).catch((err: unknown) => {
223
- const error = new Error(`Job ${job.id}:${job.name} failed to run onComplete: ${err}`);
224
- logger.error(error.message);
225
- errorHandler?.(error);
226
- });
227
- if (timer) clearTimeout(timer);
228
- }
229
- }
230
- );
231
- },
232
- workerOptions as WorkerOptions
233
- );
234
- worker.on("completed", service.completed.bind(service));
235
- worker.on("failed", service.failed.bind(service));
236
-
237
- return worker;
238
- }
239
-
240
- export function createWorkflowWorkers<
241
- Jobs extends Record<string, WorkflowJob<WorkflowDataType<any>, any, string>>,
242
- >(
243
- service: WorkflowService,
244
- workerSettings: Record<string, WorkerOptions>,
245
- jobs: Jobs,
246
- errorHandler?: (error: unknown) => void
247
- ) {
248
- const workers: Record<string, Worker> = {} as Record<string, Worker>;
249
- for (const [queueName, workerOptions] of Object.entries(workerSettings)) {
250
- workers[queueName] = createWorkflowWorker(
251
- service,
252
- queueName,
253
- workerOptions as WorkerOptions,
254
- jobs,
255
- errorHandler
256
- );
257
- }
258
- return workers;
259
- }
@@ -1,2 +0,0 @@
1
- export * from "../../utils/errors";
2
- export * from "../../utils/logger";
@@ -1,21 +0,0 @@
1
- import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
2
- import { fromNodeHeaders } from "better-auth/node";
3
- import type { BetterAuth, Session, User } from "#modules/auth/auth.lib";
4
-
5
- export type Context = Awaited<ReturnType<typeof createAuthContext>>;
6
-
7
- export function createAuthContext(auth: BetterAuth) {
8
- return async function createContext({ req }: CreateExpressContextOptions) {
9
- const data = await auth.api.getSession({
10
- headers: fromNodeHeaders(req.headers),
11
- });
12
-
13
- const user = (data?.user as User) || null;
14
- const session = (data?.session as Session) || null;
15
-
16
- return {
17
- session,
18
- user,
19
- };
20
- };
21
- }
package/src/trpc/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./context";
2
- export * from "./procedures";
3
- export * from "./utils";
@@ -1,43 +0,0 @@
1
- import { transformer } from "@m5kdev/commons/utils/trpc";
2
- import { initTRPC } from "@trpc/server";
3
- import type { OpenApiMeta } from "trpc-to-openapi";
4
- import { ServerError } from "#utils/errors";
5
- import { runWithPosthogRequestState } from "#utils/posthog";
6
- import type { Context } from "./context";
7
-
8
- const errorOptions = {
9
- layer: "controller" as const,
10
- layerName: "TRPCController",
11
- };
12
-
13
- const t = initTRPC.meta<OpenApiMeta>().context<Context>().create({ transformer });
14
-
15
- // Base router and procedure helpers
16
- const baseProcedure = t.procedure.use(({ ctx, next }) =>
17
- runWithPosthogRequestState({ disableCapture: Boolean(ctx.session?.impersonatedBy) }, () => next())
18
- );
19
-
20
- export const publicProcedure = baseProcedure;
21
-
22
- export const procedure = baseProcedure.use(({ ctx: { user, session }, next }) => {
23
- if (!user || !session) {
24
- throw new ServerError({ code: "UNAUTHORIZED", ...errorOptions }).toTRPC();
25
- }
26
-
27
- return next({ ctx: { user, session } });
28
- });
29
-
30
- export const adminProcedure = baseProcedure.use(({ ctx: { user, session }, next }) => {
31
- if (!user || !session) {
32
- throw new ServerError({ code: "UNAUTHORIZED", ...errorOptions }).toTRPC();
33
- }
34
-
35
- if (user.role !== "admin") {
36
- throw new ServerError({ code: "FORBIDDEN", ...errorOptions }).toTRPC();
37
- }
38
-
39
- return next({ ctx: { user, session } });
40
- });
41
-
42
- export const mergeRouters = t.mergeRouters;
43
- export const router = t.router;
package/src/trpc/utils.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { Result } from "neverthrow";
2
- import type { ServerError } from "#utils/errors";
3
- import { logger } from "#utils/logger";
4
-
5
- export async function handleAsyncTRPCResult<T>(result: Promise<Result<T, ServerError>>) {
6
- return handleTRPCResult(await result);
7
- }
8
-
9
- export function handleTRPCResult<T>(result: Result<T, ServerError>) {
10
- if (result.isErr()) {
11
- logger.debug("Is tRPC Error");
12
- logger.error({
13
- layer: result.error.layer,
14
- layerName: result.error.layerName,
15
- error: result.error.toJSON(),
16
- });
17
- throw result.error.toTRPC();
18
- }
19
- return result.value;
20
- }
package/src/types.ts DELETED
@@ -1,22 +0,0 @@
1
- // Create a faux router that includes the auth router for use in the web-ui types
2
- import type { Mastra } from "@mastra/core";
3
- import type { AIService } from "#modules/ai/ai.service";
4
- import { createAITRPC } from "#modules/ai/ai.trpc";
5
- import type { AuthService } from "#modules/auth/auth.service";
6
- import { createAuthTRPC } from "#modules/auth/auth.trpc";
7
- import type { BillingService } from "#modules/billing/billing.service";
8
- import { createBillingTRPC } from "#modules/billing/billing.trpc";
9
- import { router } from "#trpc";
10
-
11
- export const createAuthTRPCRouter = <MastraInstance extends Mastra>(
12
- authService: AuthService,
13
- aiService: AIService<MastraInstance>,
14
- billingService: BillingService
15
- ) =>
16
- router({
17
- auth: createAuthTRPC(authService),
18
- ai: createAITRPC(aiService),
19
- billing: createBillingTRPC(billingService),
20
- });
21
-
22
- export type BackendTRPCRouter = ReturnType<typeof createAuthTRPCRouter>;