@m5kdev/backend 0.6.0 → 0.8.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 (553) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  2. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/api/index.d.mts +1 -0
  3. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/adapter/factory.d.mts +1 -0
  4. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/adapter/get-field-attributes.d.mts +1 -0
  5. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/adapter/get-id-field.d.mts +1 -0
  6. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/adapter/index.d.mts +1 -0
  7. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/adapter/types.d.mts +1 -0
  8. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/get-tables.d.mts +1 -0
  9. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/index.d.mts +1 -0
  10. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/account.d.mts +1 -0
  11. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/rate-limit.d.mts +1 -0
  12. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/session.d.mts +1 -0
  13. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/shared.d.mts +1 -0
  14. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/user.d.mts +1 -0
  15. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/db/schema/verification.d.mts +1 -0
  16. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/index.d.mts +1 -0
  17. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/social-providers/index.d.mts +1 -0
  18. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/types/context.d.mts +1 -0
  19. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/types/helper.d.mts +7 -0
  20. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/types/init-options.d.mts +1 -0
  21. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/types/plugin-client.d.mts +1 -0
  22. package/dist/node_modules/.pnpm/@better-auth_core@1.4.18_@better-auth_utils@0.3.0_@better-fetch_fetch@1.1.21_better-cal_347838d331444e5371f256b914727290/node_modules/@better-auth/core/dist/types/plugin.d.mts +1 -0
  23. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect-adapter-base.d.mts +1 -0
  24. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect-adapter.d.mts +1 -0
  25. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect.d.mts +1 -0
  26. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-adapter.d.mts +1 -0
  27. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-dialect.d.mts +1 -0
  28. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-introspector.d.mts +1 -0
  29. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-adapter.d.mts +1 -0
  30. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-dialect.d.mts +1 -0
  31. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-introspector.d.mts +1 -0
  32. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-adapter.d.mts +1 -0
  33. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-dialect.d.mts +1 -0
  34. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-introspector.d.mts +1 -0
  35. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-adapter.d.mts +1 -0
  36. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-dialect.d.mts +1 -0
  37. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-introspector.d.mts +1 -0
  38. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/expression/expression-builder.d.mts +1 -0
  39. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/index.d.mts +1 -0
  40. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/kysely.d.mts +38 -0
  41. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/migration/file-migration-provider.d.mts +1 -0
  42. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/migration/migrator.d.mts +1 -0
  43. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/binary-operation-parser.d.mts +1 -0
  44. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/delete-from-parser.d.mts +1 -0
  45. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/expression-parser.d.mts +1 -0
  46. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/group-by-parser.d.mts +1 -0
  47. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/insert-values-parser.d.mts +1 -0
  48. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/join-parser.d.mts +1 -0
  49. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/merge-into-parser.d.mts +1 -0
  50. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/reference-parser.d.mts +1 -0
  51. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/returning-parser.d.mts +1 -0
  52. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/select-from-parser.d.mts +1 -0
  53. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/select-parser.d.mts +1 -0
  54. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/set-operation-parser.d.mts +1 -0
  55. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/tuple-parser.d.mts +1 -0
  56. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/unary-operation-parser.d.mts +1 -0
  57. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/update-parser.d.mts +1 -0
  58. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/update-set-parser.d.mts +1 -0
  59. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/value-parser.d.mts +1 -0
  60. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/with-parser.d.mts +1 -0
  61. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/case-builder.d.mts +1 -0
  62. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/delete-query-builder.d.mts +1 -0
  63. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/having-interface.d.mts +1 -0
  64. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/insert-query-builder.d.mts +1 -0
  65. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/join-builder.d.mts +1 -0
  66. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/merge-query-builder.d.mts +1 -0
  67. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/on-conflict-builder.d.mts +1 -0
  68. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/output-interface.d.mts +1 -0
  69. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/returning-interface.d.mts +1 -0
  70. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/select-query-builder.d.mts +1 -0
  71. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/update-query-builder.d.mts +1 -0
  72. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/where-interface.d.mts +1 -0
  73. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-creator.d.mts +1 -0
  74. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/default-query-executor.d.mts +1 -0
  75. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/noop-query-executor.d.mts +1 -0
  76. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor-base.d.mts +1 -0
  77. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor-provider.d.mts +1 -0
  78. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor.d.mts +1 -0
  79. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/raw-builder/raw-builder.d.mts +1 -0
  80. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/raw-builder/sql.d.mts +1 -0
  81. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.mts +1 -0
  82. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.d.mts +1 -0
  83. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-builder.d.mts +1 -0
  84. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.d.mts +1 -0
  85. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-executor.d.mts +1 -0
  86. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-index-builder.d.mts +1 -0
  87. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-schema-builder.d.mts +1 -0
  88. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-table-builder.d.mts +1 -0
  89. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-type-builder.d.mts +1 -0
  90. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-view-builder.d.mts +1 -0
  91. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-index-builder.d.mts +1 -0
  92. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-schema-builder.d.mts +1 -0
  93. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-table-builder.d.mts +1 -0
  94. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-type-builder.d.mts +1 -0
  95. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-view-builder.d.mts +1 -0
  96. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.d.mts +1 -0
  97. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/schema.d.mts +1 -0
  98. package/dist/src/lib/posthog.d.mts +7 -0
  99. package/dist/src/lib/posthog.mjs +7 -0
  100. package/dist/src/lib/posthog.mjs.map +1 -0
  101. package/dist/src/lib/sentry.d.mts +1 -0
  102. package/dist/src/lib/sentry.mjs +10 -0
  103. package/dist/src/lib/sentry.mjs.map +1 -0
  104. package/dist/src/modules/access/access.repository.d.mts +2352 -0
  105. package/dist/src/modules/access/access.repository.mjs +24 -0
  106. package/dist/src/modules/access/access.repository.mjs.map +1 -0
  107. package/dist/src/modules/access/access.service.d.mts +25 -0
  108. package/dist/src/modules/access/access.service.mjs +40 -0
  109. package/dist/src/modules/access/access.service.mjs.map +1 -0
  110. package/dist/src/modules/access/access.utils.d.mts +19 -0
  111. package/dist/src/modules/access/access.utils.mjs +21 -0
  112. package/dist/src/modules/access/access.utils.mjs.map +1 -0
  113. package/dist/src/modules/ai/ai.db.d.mts +401 -0
  114. package/dist/src/modules/ai/ai.db.mjs +38 -0
  115. package/dist/src/modules/ai/ai.db.mjs.map +1 -0
  116. package/dist/src/modules/ai/ai.prompt.d.mts +30 -0
  117. package/dist/src/modules/ai/ai.prompt.mjs +30 -0
  118. package/dist/src/modules/ai/ai.prompt.mjs.map +1 -0
  119. package/dist/src/modules/ai/ai.prompts.d.mts +10 -0
  120. package/dist/src/modules/ai/{ai.prompts.js → ai.prompts.mjs} +17 -15
  121. package/dist/src/modules/ai/ai.prompts.mjs.map +1 -0
  122. package/dist/src/modules/ai/ai.repository.d.mts +428 -0
  123. package/dist/src/modules/ai/ai.repository.mjs +23 -0
  124. package/dist/src/modules/ai/ai.repository.mjs.map +1 -0
  125. package/dist/src/modules/ai/ai.router.d.mts +1 -0
  126. package/dist/src/modules/ai/ai.service.d.mts +128 -0
  127. package/dist/src/modules/ai/ai.service.mjs +267 -0
  128. package/dist/src/modules/ai/ai.service.mjs.map +1 -0
  129. package/dist/src/modules/ai/ai.trpc.d.mts +31 -0
  130. package/dist/src/modules/ai/ai.trpc.mjs +17 -0
  131. package/dist/src/modules/ai/ai.trpc.mjs.map +1 -0
  132. package/dist/src/modules/ai/ideogram/ideogram.constants.d.mts +11 -0
  133. package/dist/src/modules/ai/ideogram/ideogram.constants.mjs +184 -0
  134. package/dist/src/modules/ai/ideogram/ideogram.constants.mjs.map +1 -0
  135. package/dist/src/modules/ai/ideogram/ideogram.dto.d.mts +234 -0
  136. package/dist/src/modules/ai/ideogram/ideogram.dto.mjs +45 -0
  137. package/dist/src/modules/ai/ideogram/ideogram.dto.mjs.map +1 -0
  138. package/dist/src/modules/ai/ideogram/ideogram.prompt.d.mts +7 -0
  139. package/dist/src/modules/ai/ideogram/{ideogram.prompt.js → ideogram.prompt.mjs} +861 -859
  140. package/dist/src/modules/ai/ideogram/ideogram.prompt.mjs.map +1 -0
  141. package/dist/src/modules/ai/ideogram/ideogram.repository.d.mts +11 -0
  142. package/dist/src/modules/ai/ideogram/ideogram.repository.mjs +32 -0
  143. package/dist/src/modules/ai/ideogram/ideogram.repository.mjs.map +1 -0
  144. package/dist/src/modules/ai/ideogram/ideogram.service.d.mts +14 -0
  145. package/dist/src/modules/ai/ideogram/ideogram.service.mjs +11 -0
  146. package/dist/src/modules/ai/ideogram/ideogram.service.mjs.map +1 -0
  147. package/dist/src/modules/auth/auth.db.d.mts +2341 -0
  148. package/dist/src/modules/auth/auth.db.mjs +169 -0
  149. package/dist/src/modules/auth/auth.db.mjs.map +1 -0
  150. package/dist/src/modules/auth/auth.dto.d.mts +70 -0
  151. package/dist/src/modules/auth/auth.dto.mjs +43 -0
  152. package/dist/src/modules/auth/auth.dto.mjs.map +1 -0
  153. package/dist/src/modules/auth/auth.lib.d.mts +4894 -0
  154. package/dist/src/modules/auth/auth.lib.mjs +232 -0
  155. package/dist/src/modules/auth/auth.lib.mjs.map +1 -0
  156. package/dist/src/modules/auth/auth.middleware.d.mts +619 -0
  157. package/dist/src/modules/auth/auth.middleware.mjs +38 -0
  158. package/dist/src/modules/auth/auth.middleware.mjs.map +1 -0
  159. package/dist/src/modules/auth/auth.repository.d.mts +2453 -0
  160. package/dist/src/modules/auth/auth.repository.mjs +401 -0
  161. package/dist/src/modules/auth/auth.repository.mjs.map +1 -0
  162. package/dist/src/modules/auth/auth.service.d.mts +105 -0
  163. package/dist/src/modules/auth/auth.service.mjs +227 -0
  164. package/dist/src/modules/auth/auth.service.mjs.map +1 -0
  165. package/dist/src/modules/auth/auth.trpc.d.mts +303 -0
  166. package/dist/src/modules/auth/auth.trpc.mjs +108 -0
  167. package/dist/src/modules/auth/auth.trpc.mjs.map +1 -0
  168. package/dist/src/modules/auth/auth.utils.d.mts +2356 -0
  169. package/dist/src/modules/auth/auth.utils.mjs +77 -0
  170. package/dist/src/modules/auth/auth.utils.mjs.map +1 -0
  171. package/dist/src/modules/base/base.abstract.d.mts +29 -0
  172. package/dist/src/modules/base/base.abstract.mjs +60 -0
  173. package/dist/src/modules/base/base.abstract.mjs.map +1 -0
  174. package/dist/src/modules/base/base.actor.d.mts +73 -0
  175. package/dist/src/modules/base/base.actor.mjs +78 -0
  176. package/dist/src/modules/base/base.actor.mjs.map +1 -0
  177. package/dist/src/modules/base/base.dto.d.mts +67 -0
  178. package/dist/src/modules/base/base.dto.mjs +79 -0
  179. package/dist/src/modules/base/base.dto.mjs.map +1 -0
  180. package/dist/src/modules/base/base.grants.d.mts +28 -0
  181. package/dist/src/modules/base/base.grants.mjs +103 -0
  182. package/dist/src/modules/base/base.grants.mjs.map +1 -0
  183. package/dist/src/modules/base/base.procedure.d.mts +111 -0
  184. package/dist/src/modules/base/base.procedure.mjs +252 -0
  185. package/dist/src/modules/base/base.procedure.mjs.map +1 -0
  186. package/dist/src/modules/base/base.repository.d.mts +123 -0
  187. package/dist/src/modules/base/base.repository.mjs +250 -0
  188. package/dist/src/modules/base/base.repository.mjs.map +1 -0
  189. package/dist/src/modules/base/base.service.d.mts +44 -0
  190. package/dist/src/modules/base/base.service.mjs +116 -0
  191. package/dist/src/modules/base/base.service.mjs.map +1 -0
  192. package/dist/src/modules/base/base.types.d.mts +5 -0
  193. package/dist/src/modules/billing/billing.db.d.mts +371 -0
  194. package/dist/src/modules/billing/billing.db.mjs +31 -0
  195. package/dist/src/modules/billing/billing.db.mjs.map +1 -0
  196. package/dist/src/modules/billing/billing.repository.d.mts +2787 -0
  197. package/dist/src/modules/billing/billing.repository.mjs +188 -0
  198. package/dist/src/modules/billing/billing.repository.mjs.map +1 -0
  199. package/dist/src/modules/billing/billing.router.d.mts +9 -0
  200. package/dist/src/modules/billing/billing.router.mjs +40 -0
  201. package/dist/src/modules/billing/billing.router.mjs.map +1 -0
  202. package/dist/src/modules/billing/billing.service.d.mts +53 -0
  203. package/dist/src/modules/billing/billing.service.mjs +125 -0
  204. package/dist/src/modules/billing/billing.service.mjs.map +1 -0
  205. package/dist/src/modules/billing/billing.trpc.d.mts +29 -0
  206. package/dist/src/modules/billing/billing.trpc.mjs +17 -0
  207. package/dist/src/modules/billing/billing.trpc.mjs.map +1 -0
  208. package/dist/src/modules/clay/clay.repository.d.mts +10 -0
  209. package/dist/src/modules/clay/clay.repository.mjs +27 -0
  210. package/dist/src/modules/clay/clay.repository.mjs.map +1 -0
  211. package/dist/src/modules/clay/clay.service.d.mts +32 -0
  212. package/dist/src/modules/clay/clay.service.mjs +23 -0
  213. package/dist/src/modules/clay/clay.service.mjs.map +1 -0
  214. package/dist/src/modules/connect/connect.db.d.mts +362 -0
  215. package/dist/src/modules/connect/connect.db.mjs +30 -0
  216. package/dist/src/modules/connect/connect.db.mjs.map +1 -0
  217. package/dist/src/modules/connect/connect.dto.d.mts +79 -0
  218. package/dist/src/modules/connect/connect.dto.mjs +38 -0
  219. package/dist/src/modules/connect/connect.dto.mjs.map +1 -0
  220. package/dist/src/modules/connect/connect.linkedin.d.mts +7 -0
  221. package/dist/src/modules/connect/connect.linkedin.mjs +47 -0
  222. package/dist/src/modules/connect/connect.linkedin.mjs.map +1 -0
  223. package/dist/src/modules/connect/connect.oauth.d.mts +32 -0
  224. package/dist/src/modules/connect/connect.oauth.mjs +145 -0
  225. package/dist/src/modules/connect/connect.oauth.mjs.map +1 -0
  226. package/dist/src/modules/connect/connect.repository.d.mts +419 -0
  227. package/dist/src/modules/connect/connect.repository.mjs +40 -0
  228. package/dist/src/modules/connect/connect.repository.mjs.map +1 -0
  229. package/dist/src/modules/connect/connect.router.d.mts +9 -0
  230. package/dist/src/modules/connect/connect.router.mjs +46 -0
  231. package/dist/src/modules/connect/connect.router.mjs.map +1 -0
  232. package/dist/src/modules/connect/connect.service.d.mts +103 -0
  233. package/dist/src/modules/connect/connect.service.mjs +88 -0
  234. package/dist/src/modules/connect/connect.service.mjs.map +1 -0
  235. package/dist/src/modules/connect/connect.trpc.d.mts +53 -0
  236. package/dist/src/modules/connect/connect.trpc.mjs +17 -0
  237. package/dist/src/modules/connect/connect.trpc.mjs.map +1 -0
  238. package/dist/src/modules/connect/connect.types.d.mts +29 -0
  239. package/dist/src/modules/crypto/crypto.db.d.mts +157 -0
  240. package/dist/src/modules/crypto/crypto.db.mjs +19 -0
  241. package/dist/src/modules/crypto/crypto.db.mjs.map +1 -0
  242. package/dist/src/modules/crypto/crypto.repository.d.mts +163 -0
  243. package/dist/src/modules/crypto/crypto.repository.mjs +9 -0
  244. package/dist/src/modules/crypto/crypto.repository.mjs.map +1 -0
  245. package/dist/src/modules/crypto/crypto.service.d.mts +15 -0
  246. package/dist/src/modules/crypto/crypto.service.mjs +40 -0
  247. package/dist/src/modules/crypto/crypto.service.mjs.map +1 -0
  248. package/dist/src/modules/email/email.service.d.mts +62 -0
  249. package/dist/src/modules/email/email.service.mjs +105 -0
  250. package/dist/src/modules/email/email.service.mjs.map +1 -0
  251. package/dist/src/modules/file/file.repository.d.mts +17 -0
  252. package/dist/src/modules/file/file.repository.mjs +72 -0
  253. package/dist/src/modules/file/file.repository.mjs.map +1 -0
  254. package/dist/src/modules/file/{file.router.d.ts → file.router.d.mts} +4 -0
  255. package/dist/src/modules/file/file.router.mjs +88 -0
  256. package/dist/src/modules/file/file.router.mjs.map +1 -0
  257. package/dist/src/modules/file/file.service.d.mts +30 -0
  258. package/dist/src/modules/file/file.service.mjs +117 -0
  259. package/dist/src/modules/file/file.service.mjs.map +1 -0
  260. package/dist/src/modules/recurrence/recurrence.db.d.mts +568 -0
  261. package/dist/src/modules/recurrence/recurrence.db.mjs +47 -0
  262. package/dist/src/modules/recurrence/recurrence.db.mjs.map +1 -0
  263. package/dist/src/modules/recurrence/recurrence.repository.d.mts +588 -0
  264. package/dist/src/modules/recurrence/recurrence.repository.mjs +28 -0
  265. package/dist/src/modules/recurrence/recurrence.repository.mjs.map +1 -0
  266. package/dist/src/modules/recurrence/recurrence.service.d.mts +51 -0
  267. package/dist/src/modules/recurrence/recurrence.service.mjs +64 -0
  268. package/dist/src/modules/recurrence/recurrence.service.mjs.map +1 -0
  269. package/dist/src/modules/recurrence/recurrence.trpc.d.mts +65 -0
  270. package/dist/src/modules/recurrence/recurrence.trpc.mjs +44 -0
  271. package/dist/src/modules/recurrence/recurrence.trpc.mjs.map +1 -0
  272. package/dist/src/modules/social/social.dto.d.mts +39 -0
  273. package/dist/src/modules/social/social.dto.mjs +22 -0
  274. package/dist/src/modules/social/social.dto.mjs.map +1 -0
  275. package/dist/src/modules/social/{social.linkedin.d.ts → social.linkedin.d.mts} +8 -3
  276. package/dist/src/modules/social/social.linkedin.mjs +346 -0
  277. package/dist/src/modules/social/social.linkedin.mjs.map +1 -0
  278. package/dist/src/modules/social/social.service.d.mts +34 -0
  279. package/dist/src/modules/social/social.service.mjs +55 -0
  280. package/dist/src/modules/social/social.service.mjs.map +1 -0
  281. package/dist/src/modules/social/social.types.d.mts +40 -0
  282. package/dist/src/modules/tag/tag.db.d.mts +352 -0
  283. package/dist/src/modules/tag/tag.db.mjs +35 -0
  284. package/dist/src/modules/tag/tag.db.mjs.map +1 -0
  285. package/dist/src/modules/tag/tag.dto.d.mts +1025 -0
  286. package/dist/src/modules/tag/tag.dto.mjs +11 -0
  287. package/dist/src/modules/tag/tag.dto.mjs.map +1 -0
  288. package/dist/src/modules/tag/tag.repository.d.mts +394 -0
  289. package/dist/src/modules/tag/tag.repository.mjs +114 -0
  290. package/dist/src/modules/tag/tag.repository.mjs.map +1 -0
  291. package/dist/src/modules/tag/tag.service.d.mts +93 -0
  292. package/dist/src/modules/tag/tag.service.mjs +47 -0
  293. package/dist/src/modules/tag/tag.service.mjs.map +1 -0
  294. package/dist/src/modules/tag/tag.trpc.d.mts +109 -0
  295. package/dist/src/modules/tag/tag.trpc.mjs +30 -0
  296. package/dist/src/modules/tag/tag.trpc.mjs.map +1 -0
  297. package/dist/src/modules/utils/{applyPagination.d.ts → applyPagination.d.mts} +5 -1
  298. package/dist/src/modules/utils/applyPagination.mjs +15 -0
  299. package/dist/src/modules/utils/applyPagination.mjs.map +1 -0
  300. package/dist/src/modules/utils/applySorting.d.mts +13 -0
  301. package/dist/src/modules/utils/applySorting.mjs +18 -0
  302. package/dist/src/modules/utils/applySorting.mjs.map +1 -0
  303. package/dist/src/modules/utils/getConditionsFromFilters.d.mts +9 -0
  304. package/dist/src/modules/utils/getConditionsFromFilters.mjs +150 -0
  305. package/dist/src/modules/utils/getConditionsFromFilters.mjs.map +1 -0
  306. package/dist/src/modules/video/video.service.d.mts +12 -0
  307. package/dist/src/modules/video/video.service.mjs +50 -0
  308. package/dist/src/modules/video/video.service.mjs.map +1 -0
  309. package/dist/src/modules/webhook/webhook.constants.d.mts +12 -0
  310. package/dist/src/modules/webhook/webhook.constants.mjs +12 -0
  311. package/dist/src/modules/webhook/webhook.constants.mjs.map +1 -0
  312. package/dist/src/modules/webhook/webhook.db.d.mts +142 -0
  313. package/dist/src/modules/webhook/webhook.db.mjs +17 -0
  314. package/dist/src/modules/webhook/webhook.db.mjs.map +1 -0
  315. package/dist/src/modules/webhook/webhook.dto.d.mts +402 -0
  316. package/dist/src/modules/webhook/webhook.dto.mjs +9 -0
  317. package/dist/src/modules/webhook/webhook.dto.mjs.map +1 -0
  318. package/dist/src/modules/webhook/webhook.repository.d.mts +154 -0
  319. package/dist/src/modules/webhook/webhook.repository.mjs +50 -0
  320. package/dist/src/modules/webhook/webhook.repository.mjs.map +1 -0
  321. package/dist/src/modules/webhook/webhook.router.d.mts +8 -0
  322. package/dist/src/modules/webhook/webhook.router.mjs +23 -0
  323. package/dist/src/modules/webhook/webhook.router.mjs.map +1 -0
  324. package/dist/src/modules/webhook/webhook.service.d.mts +14 -0
  325. package/dist/src/modules/webhook/webhook.service.mjs +59 -0
  326. package/dist/src/modules/webhook/webhook.service.mjs.map +1 -0
  327. package/dist/src/modules/workflow/workflow.db.d.mts +302 -0
  328. package/dist/src/modules/workflow/workflow.db.mjs +28 -0
  329. package/dist/src/modules/workflow/workflow.db.mjs.map +1 -0
  330. package/dist/src/modules/workflow/workflow.repository.d.mts +371 -0
  331. package/dist/src/modules/workflow/workflow.repository.mjs +93 -0
  332. package/dist/src/modules/workflow/workflow.repository.mjs.map +1 -0
  333. package/dist/src/modules/workflow/workflow.service.d.mts +31 -0
  334. package/dist/src/modules/workflow/workflow.service.mjs +40 -0
  335. package/dist/src/modules/workflow/workflow.service.mjs.map +1 -0
  336. package/dist/src/modules/workflow/workflow.trpc.d.mts +28 -0
  337. package/dist/src/modules/workflow/workflow.trpc.mjs +17 -0
  338. package/dist/src/modules/workflow/workflow.trpc.mjs.map +1 -0
  339. package/dist/src/modules/workflow/workflow.types.d.mts +25 -0
  340. package/dist/src/modules/workflow/workflow.utils.d.mts +36 -0
  341. package/dist/src/modules/workflow/workflow.utils.mjs +181 -0
  342. package/dist/src/modules/workflow/workflow.utils.mjs.map +1 -0
  343. package/dist/src/types.d.mts +346 -0
  344. package/dist/src/types.mjs +13 -0
  345. package/dist/src/types.mjs.map +1 -0
  346. package/dist/src/utils/errors.d.mts +62 -0
  347. package/dist/src/utils/errors.mjs +96 -0
  348. package/dist/src/utils/errors.mjs.map +1 -0
  349. package/dist/src/utils/logger.d.mts +7 -0
  350. package/dist/src/utils/logger.mjs +10 -0
  351. package/dist/src/utils/logger.mjs.map +1 -0
  352. package/dist/src/utils/posthog.d.mts +17 -0
  353. package/dist/src/utils/posthog.mjs +25 -0
  354. package/dist/src/utils/posthog.mjs.map +1 -0
  355. package/dist/src/utils/trpc.d.mts +54 -0
  356. package/dist/src/utils/trpc.mjs +146 -0
  357. package/dist/src/utils/trpc.mjs.map +1 -0
  358. package/dist/src/utils/types.d.mts +9 -0
  359. package/package.json +5 -4
  360. package/dist/src/lib/posthog.d.ts +0 -2
  361. package/dist/src/lib/posthog.js +0 -7
  362. package/dist/src/lib/sentry.js +0 -9
  363. package/dist/src/modules/access/access.repository.d.ts +0 -2347
  364. package/dist/src/modules/access/access.repository.js +0 -32
  365. package/dist/src/modules/access/access.service.d.ts +0 -21
  366. package/dist/src/modules/access/access.service.js +0 -51
  367. package/dist/src/modules/access/access.test.js +0 -182
  368. package/dist/src/modules/access/access.utils.d.ts +0 -16
  369. package/dist/src/modules/access/access.utils.js +0 -20
  370. package/dist/src/modules/ai/ai.db.d.ts +0 -395
  371. package/dist/src/modules/ai/ai.db.js +0 -39
  372. package/dist/src/modules/ai/ai.prompt.d.ts +0 -26
  373. package/dist/src/modules/ai/ai.prompt.js +0 -30
  374. package/dist/src/modules/ai/ai.prompts.d.ts +0 -5
  375. package/dist/src/modules/ai/ai.repository.d.ts +0 -423
  376. package/dist/src/modules/ai/ai.repository.js +0 -26
  377. package/dist/src/modules/ai/ai.router.js +0 -132
  378. package/dist/src/modules/ai/ai.service.d.ts +0 -127
  379. package/dist/src/modules/ai/ai.service.js +0 -297
  380. package/dist/src/modules/ai/ai.trpc.d.ts +0 -22
  381. package/dist/src/modules/ai/ai.trpc.js +0 -20
  382. package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts +0 -7
  383. package/dist/src/modules/ai/ideogram/ideogram.constants.js +0 -167
  384. package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts +0 -229
  385. package/dist/src/modules/ai/ideogram/ideogram.dto.js +0 -49
  386. package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts +0 -2
  387. package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts +0 -6
  388. package/dist/src/modules/ai/ideogram/ideogram.repository.js +0 -46
  389. package/dist/src/modules/ai/ideogram/ideogram.service.d.ts +0 -9
  390. package/dist/src/modules/ai/ideogram/ideogram.service.js +0 -11
  391. package/dist/src/modules/auth/auth.db.d.ts +0 -2335
  392. package/dist/src/modules/auth/auth.db.js +0 -215
  393. package/dist/src/modules/auth/auth.dto.d.ts +0 -65
  394. package/dist/src/modules/auth/auth.dto.js +0 -38
  395. package/dist/src/modules/auth/auth.lib.d.ts +0 -4873
  396. package/dist/src/modules/auth/auth.lib.js +0 -284
  397. package/dist/src/modules/auth/auth.middleware.d.ts +0 -614
  398. package/dist/src/modules/auth/auth.middleware.js +0 -52
  399. package/dist/src/modules/auth/auth.repository.d.ts +0 -2421
  400. package/dist/src/modules/auth/auth.repository.js +0 -636
  401. package/dist/src/modules/auth/auth.service.d.ts +0 -108
  402. package/dist/src/modules/auth/auth.service.js +0 -246
  403. package/dist/src/modules/auth/auth.trpc.d.ts +0 -292
  404. package/dist/src/modules/auth/auth.trpc.js +0 -179
  405. package/dist/src/modules/auth/auth.utils.d.ts +0 -2351
  406. package/dist/src/modules/auth/auth.utils.js +0 -97
  407. package/dist/src/modules/base/base.abstract.d.ts +0 -19
  408. package/dist/src/modules/base/base.abstract.js +0 -62
  409. package/dist/src/modules/base/base.dto.d.ts +0 -69
  410. package/dist/src/modules/base/base.dto.js +0 -112
  411. package/dist/src/modules/base/base.grants.d.ts +0 -28
  412. package/dist/src/modules/base/base.grants.js +0 -123
  413. package/dist/src/modules/base/base.grants.test.js +0 -668
  414. package/dist/src/modules/base/base.procedure.d.ts +0 -112
  415. package/dist/src/modules/base/base.procedure.js +0 -289
  416. package/dist/src/modules/base/base.repository.d.ts +0 -97
  417. package/dist/src/modules/base/base.repository.js +0 -317
  418. package/dist/src/modules/base/base.service.d.ts +0 -52
  419. package/dist/src/modules/base/base.service.js +0 -116
  420. package/dist/src/modules/base/base.service.test.js +0 -415
  421. package/dist/src/modules/base/base.types.d.ts +0 -1
  422. package/dist/src/modules/base/base.types.js +0 -2
  423. package/dist/src/modules/billing/billing.db.d.ts +0 -365
  424. package/dist/src/modules/billing/billing.db.js +0 -29
  425. package/dist/src/modules/billing/billing.repository.d.ts +0 -2763
  426. package/dist/src/modules/billing/billing.repository.js +0 -235
  427. package/dist/src/modules/billing/billing.router.d.ts +0 -4
  428. package/dist/src/modules/billing/billing.router.js +0 -56
  429. package/dist/src/modules/billing/billing.service.d.ts +0 -59
  430. package/dist/src/modules/billing/billing.service.js +0 -147
  431. package/dist/src/modules/billing/billing.trpc.d.ts +0 -38
  432. package/dist/src/modules/billing/billing.trpc.js +0 -17
  433. package/dist/src/modules/clay/clay.repository.d.ts +0 -5
  434. package/dist/src/modules/clay/clay.repository.js +0 -26
  435. package/dist/src/modules/clay/clay.service.d.ts +0 -28
  436. package/dist/src/modules/clay/clay.service.js +0 -24
  437. package/dist/src/modules/connect/connect.db.d.ts +0 -356
  438. package/dist/src/modules/connect/connect.db.js +0 -30
  439. package/dist/src/modules/connect/connect.dto.d.ts +0 -74
  440. package/dist/src/modules/connect/connect.dto.js +0 -36
  441. package/dist/src/modules/connect/connect.linkedin.d.ts +0 -2
  442. package/dist/src/modules/connect/connect.linkedin.js +0 -53
  443. package/dist/src/modules/connect/connect.oauth.d.ts +0 -27
  444. package/dist/src/modules/connect/connect.oauth.js +0 -198
  445. package/dist/src/modules/connect/connect.repository.d.ts +0 -413
  446. package/dist/src/modules/connect/connect.repository.js +0 -54
  447. package/dist/src/modules/connect/connect.router.d.ts +0 -4
  448. package/dist/src/modules/connect/connect.router.js +0 -54
  449. package/dist/src/modules/connect/connect.service.d.ts +0 -88
  450. package/dist/src/modules/connect/connect.service.js +0 -114
  451. package/dist/src/modules/connect/connect.trpc.d.ts +0 -44
  452. package/dist/src/modules/connect/connect.trpc.js +0 -21
  453. package/dist/src/modules/connect/connect.types.d.ts +0 -25
  454. package/dist/src/modules/connect/connect.types.js +0 -2
  455. package/dist/src/modules/crypto/crypto.db.d.ts +0 -151
  456. package/dist/src/modules/crypto/crypto.db.js +0 -17
  457. package/dist/src/modules/crypto/crypto.repository.d.ts +0 -159
  458. package/dist/src/modules/crypto/crypto.repository.js +0 -10
  459. package/dist/src/modules/crypto/crypto.service.d.ts +0 -10
  460. package/dist/src/modules/crypto/crypto.service.js +0 -52
  461. package/dist/src/modules/email/email.service.d.ts +0 -56
  462. package/dist/src/modules/email/email.service.js +0 -106
  463. package/dist/src/modules/file/file.repository.d.ts +0 -12
  464. package/dist/src/modules/file/file.repository.js +0 -79
  465. package/dist/src/modules/file/file.router.js +0 -99
  466. package/dist/src/modules/file/file.service.d.ts +0 -24
  467. package/dist/src/modules/file/file.service.js +0 -150
  468. package/dist/src/modules/recurrence/recurrence.db.d.ts +0 -562
  469. package/dist/src/modules/recurrence/recurrence.db.js +0 -66
  470. package/dist/src/modules/recurrence/recurrence.repository.d.ts +0 -584
  471. package/dist/src/modules/recurrence/recurrence.repository.js +0 -39
  472. package/dist/src/modules/recurrence/recurrence.service.d.ts +0 -50
  473. package/dist/src/modules/recurrence/recurrence.service.js +0 -69
  474. package/dist/src/modules/recurrence/recurrence.trpc.d.ts +0 -206
  475. package/dist/src/modules/recurrence/recurrence.trpc.js +0 -65
  476. package/dist/src/modules/social/social.dto.d.ts +0 -34
  477. package/dist/src/modules/social/social.dto.js +0 -18
  478. package/dist/src/modules/social/social.linkedin.js +0 -427
  479. package/dist/src/modules/social/social.linkedin.test.js +0 -235
  480. package/dist/src/modules/social/social.service.d.ts +0 -28
  481. package/dist/src/modules/social/social.service.js +0 -76
  482. package/dist/src/modules/social/social.types.d.ts +0 -35
  483. package/dist/src/modules/social/social.types.js +0 -2
  484. package/dist/src/modules/tag/tag.db.d.ts +0 -346
  485. package/dist/src/modules/tag/tag.db.js +0 -42
  486. package/dist/src/modules/tag/tag.dto.d.ts +0 -1018
  487. package/dist/src/modules/tag/tag.dto.js +0 -9
  488. package/dist/src/modules/tag/tag.repository.d.ts +0 -383
  489. package/dist/src/modules/tag/tag.repository.js +0 -156
  490. package/dist/src/modules/tag/tag.service.d.ts +0 -109
  491. package/dist/src/modules/tag/tag.service.js +0 -42
  492. package/dist/src/modules/tag/tag.trpc.d.ts +0 -164
  493. package/dist/src/modules/tag/tag.trpc.js +0 -53
  494. package/dist/src/modules/utils/applyPagination.js +0 -16
  495. package/dist/src/modules/utils/applySorting.d.ts +0 -8
  496. package/dist/src/modules/utils/applySorting.js +0 -18
  497. package/dist/src/modules/utils/getConditionsFromFilters.d.ts +0 -4
  498. package/dist/src/modules/utils/getConditionsFromFilters.js +0 -200
  499. package/dist/src/modules/video/video.service.d.ts +0 -7
  500. package/dist/src/modules/video/video.service.js +0 -84
  501. package/dist/src/modules/webhook/webhook.constants.d.ts +0 -8
  502. package/dist/src/modules/webhook/webhook.constants.js +0 -10
  503. package/dist/src/modules/webhook/webhook.db.d.ts +0 -136
  504. package/dist/src/modules/webhook/webhook.db.js +0 -17
  505. package/dist/src/modules/webhook/webhook.dto.d.ts +0 -394
  506. package/dist/src/modules/webhook/webhook.dto.js +0 -7
  507. package/dist/src/modules/webhook/webhook.repository.d.ts +0 -148
  508. package/dist/src/modules/webhook/webhook.repository.js +0 -56
  509. package/dist/src/modules/webhook/webhook.router.d.ts +0 -3
  510. package/dist/src/modules/webhook/webhook.router.js +0 -30
  511. package/dist/src/modules/webhook/webhook.service.d.ts +0 -9
  512. package/dist/src/modules/webhook/webhook.service.js +0 -68
  513. package/dist/src/modules/workflow/workflow.db.d.ts +0 -296
  514. package/dist/src/modules/workflow/workflow.db.js +0 -30
  515. package/dist/src/modules/workflow/workflow.repository.d.ts +0 -343
  516. package/dist/src/modules/workflow/workflow.repository.js +0 -105
  517. package/dist/src/modules/workflow/workflow.service.d.ts +0 -21
  518. package/dist/src/modules/workflow/workflow.service.js +0 -37
  519. package/dist/src/modules/workflow/workflow.trpc.d.ts +0 -56
  520. package/dist/src/modules/workflow/workflow.trpc.js +0 -21
  521. package/dist/src/modules/workflow/workflow.types.d.ts +0 -20
  522. package/dist/src/modules/workflow/workflow.types.js +0 -2
  523. package/dist/src/modules/workflow/workflow.utils.d.ts +0 -21
  524. package/dist/src/modules/workflow/workflow.utils.js +0 -173
  525. package/dist/src/test/stubs/utils.d.ts +0 -2
  526. package/dist/src/test/stubs/utils.js +0 -5
  527. package/dist/src/trpc/context.d.ts +0 -41
  528. package/dist/src/trpc/context.js +0 -17
  529. package/dist/src/trpc/index.d.ts +0 -3
  530. package/dist/src/trpc/index.js +0 -6
  531. package/dist/src/trpc/procedures.d.ts +0 -233
  532. package/dist/src/trpc/procedures.js +0 -32
  533. package/dist/src/trpc/utils.d.ts +0 -4
  534. package/dist/src/trpc/utils.js +0 -20
  535. package/dist/src/types.d.ts +0 -358
  536. package/dist/src/types.js +0 -12
  537. package/dist/src/utils/errors.d.ts +0 -49
  538. package/dist/src/utils/errors.js +0 -104
  539. package/dist/src/utils/logger.d.ts +0 -1
  540. package/dist/src/utils/logger.js +0 -11
  541. package/dist/src/utils/posthog.d.ts +0 -13
  542. package/dist/src/utils/posthog.js +0 -31
  543. package/dist/src/utils/trpc.d.ts +0 -58
  544. package/dist/src/utils/trpc.js +0 -63
  545. package/dist/src/utils/types.d.ts +0 -4
  546. package/dist/src/utils/types.js +0 -2
  547. package/dist/tsconfig.tsbuildinfo +0 -1
  548. /package/dist/src/{lib/sentry.d.ts → modules/ai/ai.router.mjs} +0 -0
  549. /package/dist/src/modules/{access/access.test.d.ts → base/base.types.mjs} +0 -0
  550. /package/dist/src/modules/{ai/ai.router.d.ts → connect/connect.types.mjs} +0 -0
  551. /package/dist/src/modules/{base/base.grants.test.d.ts → social/social.types.mjs} +0 -0
  552. /package/dist/src/modules/{base/base.service.test.d.ts → workflow/workflow.types.mjs} +0 -0
  553. /package/dist/src/{modules/social/social.linkedin.test.d.ts → utils/types.mjs} +0 -0
@@ -0,0 +1,188 @@
1
+ import { posthogCapture } from "../../utils/posthog.mjs";
2
+ import { auth_db_exports } from "../auth/auth.db.mjs";
3
+ import { BaseTableRepository } from "../base/base.repository.mjs";
4
+ import { billing_db_exports } from "./billing.db.mjs";
5
+ import { and, desc, eq, inArray } from "drizzle-orm";
6
+ import { err, ok } from "neverthrow";
7
+ //#region src/modules/billing/billing.repository.ts
8
+ ({
9
+ ...auth_db_exports,
10
+ ...billing_db_exports
11
+ });
12
+ var BillingRepository = class extends BaseTableRepository {
13
+ stripe;
14
+ plans;
15
+ trial;
16
+ constructor(options) {
17
+ const { libs, config, ...rest } = options;
18
+ super(rest);
19
+ this.stripe = libs.stripe;
20
+ this.plans = config.plans;
21
+ this.trial = config.trial;
22
+ }
23
+ hasTrial() {
24
+ return !!this.trial;
25
+ }
26
+ getPlanByPriceId(priceId) {
27
+ return this.plans.find((plan) => plan.priceId === priceId || plan.annualDiscountPriceId === priceId);
28
+ }
29
+ getCustomerByEmail(email) {
30
+ return this.throwableAsync(async () => {
31
+ return ok((await this.stripe.customers.list({
32
+ email,
33
+ limit: 1
34
+ })).data[0] ?? null);
35
+ });
36
+ }
37
+ getUserByCustomerId(customerId) {
38
+ return this.throwableAsync(async () => {
39
+ const [user] = await this.orm.select().from(this.schema.users).where(eq(this.schema.users.stripeCustomerId, customerId)).limit(1);
40
+ return ok(user ?? null);
41
+ });
42
+ }
43
+ createCustomer({ email, name, userId }) {
44
+ return this.throwableAsync(async () => {
45
+ return ok(await this.stripe.customers.create({
46
+ email,
47
+ name,
48
+ metadata: { userId }
49
+ }));
50
+ });
51
+ }
52
+ async createTrialSubscription(customerId) {
53
+ if (!this.trial) return this.error("NOT_FOUND", "Trial plan not found");
54
+ const stripeSubscription = await this.createSubscription({
55
+ customerId,
56
+ priceId: this.trial.priceId,
57
+ trialDays: this.trial.freeTrial?.days ?? 7
58
+ });
59
+ if (stripeSubscription.isErr()) return err(stripeSubscription.error);
60
+ if (!stripeSubscription.value) return this.error("INTERNAL_SERVER_ERROR", "Failed to create trial subscription");
61
+ return ok(stripeSubscription.value);
62
+ }
63
+ createSubscription({ customerId, priceId, quantity = 1, trialDays }) {
64
+ return this.throwableAsync(async () => {
65
+ return ok(await this.stripe.subscriptions.create({
66
+ customer: customerId,
67
+ items: [{
68
+ price: priceId,
69
+ quantity
70
+ }],
71
+ ...trialDays ? {
72
+ trial_period_days: trialDays,
73
+ trial_settings: { end_behavior: { missing_payment_method: "cancel" } }
74
+ } : {}
75
+ }));
76
+ });
77
+ }
78
+ updateUserCustomerId({ userId, customerId }) {
79
+ return this.throwableAsync(async () => {
80
+ const [user] = await this.orm.update(this.schema.users).set({ stripeCustomerId: customerId }).where(eq(this.schema.users.id, userId)).returning();
81
+ if (!user) return this.error("NOT_FOUND", "User not found");
82
+ return ok(user);
83
+ });
84
+ }
85
+ getLatestSubscription(referenceId) {
86
+ return this.throwableAsync(async () => {
87
+ return ok((await this.orm.select().from(this.schema.subscriptions).where(eq(this.schema.subscriptions.referenceId, referenceId)).orderBy(desc(this.schema.subscriptions.createdAt)).limit(1))[0] ?? null);
88
+ });
89
+ }
90
+ getActiveSubscription(referenceId) {
91
+ return this.throwableAsync(async () => {
92
+ const [subscription] = await this.orm.select().from(this.schema.subscriptions).where(and(eq(this.schema.subscriptions.referenceId, referenceId), inArray(this.schema.subscriptions.status, ["active", "trialing"]))).orderBy(desc(this.schema.subscriptions.createdAt)).limit(1);
93
+ return ok(subscription ?? null);
94
+ });
95
+ }
96
+ listInvoices(customerId) {
97
+ return this.throwableAsync(async () => {
98
+ return ok((await this.stripe.invoices.list({ customer: customerId })).data);
99
+ });
100
+ }
101
+ createCheckoutSession({ customerId, priceId, userId }) {
102
+ return this.throwableAsync(async () => {
103
+ return ok(await this.stripe.checkout.sessions.create({
104
+ client_reference_id: userId,
105
+ customer: customerId,
106
+ success_url: `${process.env.VITE_SERVER_URL}/stripe/success`,
107
+ cancel_url: `${process.env.VITE_APP_URL}/billing`,
108
+ mode: "subscription",
109
+ line_items: [{
110
+ price: priceId,
111
+ quantity: 1
112
+ }]
113
+ }));
114
+ });
115
+ }
116
+ createBillingPortalSession(customerId) {
117
+ return this.throwableAsync(async () => {
118
+ return ok(await this.stripe.billingPortal.sessions.create({
119
+ customer: customerId,
120
+ return_url: `${process.env.VITE_SERVER_URL}/stripe/success`
121
+ }));
122
+ });
123
+ }
124
+ async syncStripeData({ customerId, userId }) {
125
+ return this.throwableAsync(async () => {
126
+ const [stripeSubscription] = (await this.stripe.subscriptions.list({
127
+ customer: customerId,
128
+ limit: 1,
129
+ status: "all",
130
+ expand: ["data.default_payment_method"]
131
+ })).data;
132
+ if (!stripeSubscription) return this.error("NOT_FOUND", "Subscription not found");
133
+ const plan = this.getPlanByPriceId(stripeSubscription.items.data[0]?.price.id);
134
+ if (!plan) return this.error("NOT_FOUND", `Plan not found for price ID: ${stripeSubscription.items.data[0]?.price.id}`);
135
+ const values = {
136
+ stripeCustomerId: customerId,
137
+ referenceId: userId,
138
+ plan: plan.name,
139
+ status: stripeSubscription.status,
140
+ seats: stripeSubscription.items.data[0]?.quantity || 1,
141
+ periodEnd: /* @__PURE__ */ new Date(stripeSubscription.items.data[0]?.current_period_end * 1e3),
142
+ periodStart: /* @__PURE__ */ new Date(stripeSubscription.items.data[0]?.current_period_start * 1e3),
143
+ priceId: stripeSubscription.items.data[0]?.price.id,
144
+ interval: stripeSubscription.items.data[0]?.price.recurring?.interval,
145
+ unitAmount: stripeSubscription.items.data[0]?.price.unit_amount,
146
+ discounts: stripeSubscription.discounts.map((discount) => typeof discount === "string" ? discount : discount.id),
147
+ stripeSubscriptionId: stripeSubscription.id,
148
+ cancelAtPeriodEnd: stripeSubscription.cancel_at_period_end,
149
+ cancelAt: stripeSubscription.cancel_at ? /* @__PURE__ */ new Date(stripeSubscription.cancel_at * 1e3) : null,
150
+ canceledAt: stripeSubscription.canceled_at ? /* @__PURE__ */ new Date(stripeSubscription.canceled_at * 1e3) : null,
151
+ ...stripeSubscription.trial_start && stripeSubscription.trial_end ? {
152
+ trialStart: /* @__PURE__ */ new Date(stripeSubscription.trial_start * 1e3),
153
+ trialEnd: /* @__PURE__ */ new Date(stripeSubscription.trial_end * 1e3)
154
+ } : {}
155
+ };
156
+ const existingSubscription = await this.getActiveSubscription(userId);
157
+ if (existingSubscription.isErr()) return err(existingSubscription.error);
158
+ if (!existingSubscription.value) {
159
+ await this.orm.insert(this.schema.subscriptions).values(values);
160
+ posthogCapture({
161
+ distinctId: userId,
162
+ event: "stripe.subscription_created",
163
+ properties: values
164
+ });
165
+ return ok(true);
166
+ }
167
+ await this.orm.update(this.schema.subscriptions).set({
168
+ ...values,
169
+ updatedAt: /* @__PURE__ */ new Date()
170
+ }).where(eq(this.schema.subscriptions.id, existingSubscription.value.id));
171
+ posthogCapture({
172
+ distinctId: userId,
173
+ event: "stripe.subscription_updated",
174
+ properties: values
175
+ });
176
+ return ok(false);
177
+ });
178
+ }
179
+ constructEvent(body, signature, secret) {
180
+ return this.throwable(() => {
181
+ return ok(this.stripe.webhooks.constructEvent(body, signature, secret));
182
+ });
183
+ }
184
+ };
185
+ //#endregion
186
+ export { BillingRepository };
187
+
188
+ //# sourceMappingURL=billing.repository.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.repository.mjs","names":["auth","billing"],"sources":["../../../../src/modules/billing/billing.repository.ts"],"sourcesContent":["import type { BillingSchema } from \"@m5kdev/commons/modules/billing/billing.schema\";\r\nimport type { StripePlan } from \"@m5kdev/commons/modules/billing/billing.types\";\r\nimport { and, desc, eq, type InferSelectModel, inArray } from \"drizzle-orm\";\r\nimport type { LibSQLDatabase } from \"drizzle-orm/libsql\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport type { Stripe } from \"stripe\";\r\nimport * as auth from \"../auth/auth.db\";\r\nimport type { ServerResult, ServerResultAsync } from \"../base/base.dto\";\r\nimport { BaseTableRepository } from \"../base/base.repository\";\r\nimport * as billing from \"./billing.db\";\r\nimport { posthogCapture } from \"../../utils/posthog\";\r\n\r\nconst schema = { ...auth, ...billing };\r\ntype Schema = typeof schema;\r\ntype Orm = LibSQLDatabase<Schema>;\r\n\r\nexport class BillingRepository extends BaseTableRepository<\r\n Orm,\r\n Schema,\r\n Record<string, never>,\r\n Schema[\"subscriptions\"]\r\n> {\r\n public stripe: Stripe;\r\n public plans: StripePlan[];\r\n public trial?: StripePlan;\r\n\r\n constructor(options: {\r\n orm: Orm;\r\n schema: Schema;\r\n table: Schema[\"subscriptions\"];\r\n libs: { stripe: Stripe };\r\n config: {\r\n trial?: StripePlan;\r\n plans: StripePlan[];\r\n };\r\n }) {\r\n const { libs, config, ...rest } = options;\r\n super(rest);\r\n this.stripe = libs.stripe;\r\n this.plans = config.plans;\r\n this.trial = config.trial;\r\n }\r\n hasTrial(): boolean {\r\n return !!this.trial;\r\n }\r\n\r\n getPlanByPriceId(priceId: string): StripePlan | undefined {\r\n return this.plans.find(\r\n (plan) => plan.priceId === priceId || plan.annualDiscountPriceId === priceId\r\n );\r\n }\r\n\r\n getCustomerByEmail(email: string): ServerResultAsync<Stripe.Customer | null> {\r\n return this.throwableAsync(async () => {\r\n const customers = await this.stripe.customers.list({\r\n email,\r\n limit: 1,\r\n });\r\n return ok(customers.data[0] ?? null);\r\n });\r\n }\r\n\r\n getUserByCustomerId(\r\n customerId: string\r\n ): ServerResultAsync<InferSelectModel<Schema[\"users\"]> | null> {\r\n return this.throwableAsync(async () => {\r\n const [user] = await this.orm\r\n .select()\r\n .from(this.schema.users)\r\n .where(eq(this.schema.users.stripeCustomerId, customerId))\r\n .limit(1);\r\n return ok(user ?? null);\r\n });\r\n }\r\n\r\n createCustomer({\r\n email,\r\n name,\r\n userId,\r\n }: {\r\n email: string;\r\n name?: string;\r\n userId: string;\r\n }): ServerResultAsync<Stripe.Customer> {\r\n return this.throwableAsync(async () => {\r\n const customer = await this.stripe.customers.create({\r\n email,\r\n name,\r\n metadata: {\r\n userId,\r\n },\r\n });\r\n return ok(customer);\r\n });\r\n }\r\n\r\n async createTrialSubscription(customerId: string): ServerResultAsync<Stripe.Subscription> {\r\n if (!this.trial) return this.error(\"NOT_FOUND\", \"Trial plan not found\");\r\n const stripeSubscription = await this.createSubscription({\r\n customerId,\r\n priceId: this.trial.priceId,\r\n trialDays: this.trial.freeTrial?.days ?? 7,\r\n });\r\n if (stripeSubscription.isErr()) return err(stripeSubscription.error);\r\n if (!stripeSubscription.value)\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to create trial subscription\");\r\n return ok(stripeSubscription.value);\r\n }\r\n\r\n createSubscription({\r\n customerId,\r\n priceId,\r\n quantity = 1,\r\n trialDays,\r\n }: {\r\n customerId: string;\r\n priceId: string;\r\n quantity?: number;\r\n trialDays?: number;\r\n }): ServerResultAsync<Stripe.Subscription> {\r\n return this.throwableAsync(async () => {\r\n const stripeSubscription = await this.stripe.subscriptions.create({\r\n customer: customerId,\r\n items: [{ price: priceId, quantity }], // quantity = seats if you want\r\n ...(trialDays\r\n ? {\r\n trial_period_days: trialDays,\r\n trial_settings: {\r\n end_behavior: {\r\n missing_payment_method: \"cancel\",\r\n },\r\n },\r\n }\r\n : {}),\r\n });\r\n return ok(stripeSubscription);\r\n });\r\n }\r\n\r\n updateUserCustomerId({\r\n userId,\r\n customerId,\r\n }: {\r\n userId: string;\r\n customerId: string;\r\n }): ServerResultAsync<InferSelectModel<Schema[\"users\"]>> {\r\n return this.throwableAsync(async () => {\r\n const [user] = await this.orm\r\n .update(this.schema.users)\r\n .set({ stripeCustomerId: customerId })\r\n .where(eq(this.schema.users.id, userId))\r\n .returning();\r\n if (!user) return this.error(\"NOT_FOUND\", \"User not found\");\r\n return ok(user);\r\n });\r\n }\r\n\r\n getLatestSubscription(referenceId: string): ServerResultAsync<BillingSchema | null> {\r\n return this.throwableAsync(async () => {\r\n const subscriptions = await this.orm\r\n .select()\r\n .from(this.schema.subscriptions)\r\n .where(eq(this.schema.subscriptions.referenceId, referenceId))\r\n .orderBy(desc(this.schema.subscriptions.createdAt))\r\n .limit(1);\r\n\r\n return ok(subscriptions[0] ?? null);\r\n });\r\n }\r\n\r\n getActiveSubscription(referenceId: string): ServerResultAsync<BillingSchema | null> {\r\n return this.throwableAsync(async () => {\r\n const [subscription] = await this.orm\r\n .select()\r\n .from(this.schema.subscriptions)\r\n .where(\r\n and(\r\n eq(this.schema.subscriptions.referenceId, referenceId),\r\n inArray(this.schema.subscriptions.status, [\"active\", \"trialing\"])\r\n )\r\n )\r\n .orderBy(desc(this.schema.subscriptions.createdAt))\r\n .limit(1);\r\n\r\n return ok(subscription ?? null);\r\n });\r\n }\r\n\r\n listInvoices(customerId: string): ServerResultAsync<Stripe.Invoice[]> {\r\n return this.throwableAsync(async () => {\r\n const invoices = await this.stripe.invoices.list({\r\n customer: customerId,\r\n });\r\n return ok(invoices.data);\r\n });\r\n }\r\n\r\n createCheckoutSession({\r\n customerId,\r\n priceId,\r\n userId,\r\n }: {\r\n customerId: string;\r\n priceId: string;\r\n userId: string;\r\n }): ServerResultAsync<Stripe.Checkout.Session> {\r\n return this.throwableAsync(async () => {\r\n const session = await this.stripe.checkout.sessions.create({\r\n client_reference_id: userId,\r\n customer: customerId,\r\n success_url: `${process.env.VITE_SERVER_URL}/stripe/success`,\r\n cancel_url: `${process.env.VITE_APP_URL}/billing`,\r\n mode: \"subscription\",\r\n line_items: [\r\n {\r\n price: priceId,\r\n quantity: 1,\r\n },\r\n ],\r\n });\r\n return ok(session);\r\n });\r\n }\r\n\r\n createBillingPortalSession(customerId: string): ServerResultAsync<Stripe.BillingPortal.Session> {\r\n return this.throwableAsync(async () => {\r\n const session = await this.stripe.billingPortal.sessions.create({\r\n customer: customerId,\r\n return_url: `${process.env.VITE_SERVER_URL}/stripe/success`,\r\n });\r\n return ok(session);\r\n });\r\n }\r\n\r\n async syncStripeData({\r\n customerId,\r\n userId,\r\n }: {\r\n customerId: string;\r\n userId: string;\r\n }): ServerResultAsync<boolean> {\r\n return this.throwableAsync(async () => {\r\n // Fetch latest subscription data from Stripe\r\n\r\n const stripeSubscriptions = await this.stripe.subscriptions.list({\r\n customer: customerId,\r\n limit: 1,\r\n status: \"all\",\r\n expand: [\"data.default_payment_method\"],\r\n });\r\n const [stripeSubscription] = stripeSubscriptions.data;\r\n if (!stripeSubscription) return this.error(\"NOT_FOUND\", \"Subscription not found\");\r\n\r\n const plan = this.getPlanByPriceId(stripeSubscription.items.data[0]?.price.id!);\r\n if (!plan)\r\n return this.error(\r\n \"NOT_FOUND\",\r\n `Plan not found for price ID: ${stripeSubscription.items.data[0]?.price.id}`\r\n );\r\n\r\n const values = {\r\n stripeCustomerId: customerId,\r\n referenceId: userId,\r\n plan: plan.name,\r\n status: stripeSubscription.status,\r\n seats: stripeSubscription.items.data[0]?.quantity || 1,\r\n periodEnd: new Date(stripeSubscription.items.data[0]?.current_period_end! * 1000),\r\n periodStart: new Date(stripeSubscription.items.data[0]?.current_period_start! * 1000),\r\n priceId: stripeSubscription.items.data[0]?.price.id!,\r\n interval: stripeSubscription.items.data[0]?.price.recurring?.interval,\r\n unitAmount: stripeSubscription.items.data[0]?.price.unit_amount,\r\n discounts: stripeSubscription.discounts.map((discount) =>\r\n typeof discount === \"string\" ? discount : discount.id\r\n ),\r\n stripeSubscriptionId: stripeSubscription.id,\r\n cancelAtPeriodEnd: stripeSubscription.cancel_at_period_end,\r\n cancelAt: stripeSubscription.cancel_at\r\n ? new Date(stripeSubscription.cancel_at * 1000)\r\n : null,\r\n canceledAt: stripeSubscription.canceled_at\r\n ? new Date(stripeSubscription.canceled_at * 1000)\r\n : null,\r\n ...(stripeSubscription.trial_start && stripeSubscription.trial_end\r\n ? {\r\n trialStart: new Date(stripeSubscription.trial_start * 1000),\r\n trialEnd: new Date(stripeSubscription.trial_end * 1000),\r\n }\r\n : {}),\r\n };\r\n\r\n const existingSubscription = await this.getActiveSubscription(userId);\r\n if (existingSubscription.isErr()) return err(existingSubscription.error);\r\n\r\n if (!existingSubscription.value) {\r\n await this.orm.insert(this.schema.subscriptions).values(values);\r\n posthogCapture({\r\n distinctId: userId,\r\n event: \"stripe.subscription_created\",\r\n properties: values,\r\n });\r\n return ok(true);\r\n }\r\n\r\n await this.orm\r\n .update(this.schema.subscriptions)\r\n .set({ ...values, updatedAt: new Date() })\r\n .where(eq(this.schema.subscriptions.id, existingSubscription.value.id));\r\n posthogCapture({\r\n distinctId: userId,\r\n event: \"stripe.subscription_updated\",\r\n properties: values,\r\n });\r\n\r\n return ok(false);\r\n });\r\n }\r\n\r\n constructEvent(\r\n body: Buffer | string,\r\n signature: string,\r\n secret: string\r\n ): ServerResult<Stripe.Event> {\r\n return this.throwable(() => {\r\n const event = this.stripe.webhooks.constructEvent(body, signature, secret);\r\n return ok(event);\r\n });\r\n }\r\n}\r\n"],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ import { BillingService } from "./billing.service.mjs";
2
+ import { AuthMiddleware } from "../auth/auth.middleware.mjs";
3
+ import { Router } from "express";
4
+
5
+ //#region src/modules/billing/billing.router.d.ts
6
+ declare function createBillingRouter(authMiddleware: AuthMiddleware, service: BillingService): Router;
7
+ //#endregion
8
+ export { createBillingRouter };
9
+ //# sourceMappingURL=billing.router.d.mts.map
@@ -0,0 +1,40 @@
1
+ import bodyParser from "body-parser";
2
+ import { Router } from "express";
3
+ //#region src/modules/billing/billing.router.ts
4
+ function createBillingRouter(authMiddleware, service) {
5
+ const billingRouter = Router();
6
+ billingRouter.get("/checkout/:priceId", authMiddleware, async (req, res) => {
7
+ const user = req.user;
8
+ const session = await service.createCheckoutSession({ priceId: req.params.priceId }, { user });
9
+ if (session.isErr()) return res.status(500).json({ message: session.error.message });
10
+ if (!session.value.url) return res.status(500).json({ message: "Failed to create checkout session" });
11
+ return res.redirect(session.value.url);
12
+ });
13
+ billingRouter.get("/portal", authMiddleware, async (req, res) => {
14
+ const user = req.user;
15
+ const session = await service.createBillingPortalSession({ user });
16
+ if (session.isErr()) return res.status(500).json({ message: session.error.message });
17
+ return res.redirect(session.value.url);
18
+ });
19
+ billingRouter.get("/success", authMiddleware, async (req, res) => {
20
+ const user = req.user;
21
+ if (!user.stripeCustomerId) return res.redirect(`${process.env.VITE_APP_URL}/billing`);
22
+ if ((await service.syncStripeData(user.stripeCustomerId)).isErr()) return res.redirect(`${process.env.VITE_APP_URL}/billing?error=SYNC_FAILED`);
23
+ return res.redirect(`${process.env.VITE_APP_URL}/billing`);
24
+ });
25
+ billingRouter.post("/webhook", bodyParser.raw({ type: "application/json" }), async (req, res) => {
26
+ const signature = req.headers["stripe-signature"];
27
+ if (!signature) return res.status(400).json({ message: "No signature" });
28
+ if (typeof signature !== "string") return res.status(500).json({ message: "Signature is not a string" });
29
+ const event = service.constructEvent(req.body, signature);
30
+ if (event.isErr()) return res.status(500).json({ message: event.error.message });
31
+ const result = await service.processEvent(event.value);
32
+ if (result.isErr()) return res.status(500).json({ message: result.error.message });
33
+ return res.status(200).json({ received: true });
34
+ });
35
+ return billingRouter;
36
+ }
37
+ //#endregion
38
+ export { createBillingRouter };
39
+
40
+ //# sourceMappingURL=billing.router.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.router.mjs","names":[],"sources":["../../../../src/modules/billing/billing.router.ts"],"sourcesContent":["import bodyParser from \"body-parser\";\r\nimport { Router } from \"express\";\r\nimport type { AuthMiddleware, AuthRequest } from \"../auth/auth.middleware\";\r\nimport type { BillingService } from \"./billing.service\";\r\n\r\nexport function createBillingRouter(\r\n authMiddleware: AuthMiddleware,\r\n service: BillingService\r\n): Router {\r\n const billingRouter = Router();\r\n\r\n billingRouter.get(\"/checkout/:priceId\", authMiddleware, async (req: AuthRequest, res) => {\r\n const user = req.user!;\r\n\r\n const session = await service.createCheckoutSession({ priceId: req.params.priceId }, { user });\r\n if (session.isErr()) {\r\n return res.status(500).json({ message: session.error.message });\r\n }\r\n\r\n if (!session.value.url) {\r\n return res.status(500).json({ message: \"Failed to create checkout session\" });\r\n }\r\n\r\n return res.redirect(session.value.url);\r\n });\r\n\r\n billingRouter.get(\"/portal\", authMiddleware, async (req: AuthRequest, res) => {\r\n const user = req.user!;\r\n\r\n const session = await service.createBillingPortalSession({ user });\r\n\r\n if (session.isErr()) {\r\n return res.status(500).json({ message: session.error.message });\r\n }\r\n\r\n return res.redirect(session.value.url);\r\n });\r\n\r\n billingRouter.get(\"/success\", authMiddleware, async (req: AuthRequest, res) => {\r\n const user = req.user!;\r\n\r\n if (!user.stripeCustomerId) {\r\n return res.redirect(`${process.env.VITE_APP_URL}/billing`);\r\n }\r\n\r\n const result = await service.syncStripeData(user.stripeCustomerId);\r\n\r\n if (result.isErr()) {\r\n return res.redirect(`${process.env.VITE_APP_URL}/billing?error=SYNC_FAILED`);\r\n }\r\n\r\n return res.redirect(`${process.env.VITE_APP_URL}/billing`);\r\n });\r\n\r\n billingRouter.post(\"/webhook\", bodyParser.raw({ type: \"application/json\" }), async (req, res) => {\r\n const signature = req.headers[\"stripe-signature\"];\r\n\r\n if (!signature) return res.status(400).json({ message: \"No signature\" });\r\n\r\n if (typeof signature !== \"string\")\r\n return res.status(500).json({ message: \"Signature is not a string\" });\r\n\r\n const event = service.constructEvent(req.body, signature);\r\n if (event.isErr()) {\r\n return res.status(500).json({ message: event.error.message });\r\n }\r\n\r\n const result = await service.processEvent(event.value);\r\n if (result.isErr()) {\r\n return res.status(500).json({ message: result.error.message });\r\n }\r\n\r\n return res.status(200).json({ received: true });\r\n });\r\n\r\n return billingRouter;\r\n}\r\n"],"mappings":";;;AAKA,SAAgB,oBACd,gBACA,SACQ;CACR,MAAM,gBAAgB,QAAQ;AAE9B,eAAc,IAAI,sBAAsB,gBAAgB,OAAO,KAAkB,QAAQ;EACvF,MAAM,OAAO,IAAI;EAEjB,MAAM,UAAU,MAAM,QAAQ,sBAAsB,EAAE,SAAS,IAAI,OAAO,SAAS,EAAE,EAAE,MAAM,CAAC;AAC9F,MAAI,QAAQ,OAAO,CACjB,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,QAAQ,MAAM,SAAS,CAAC;AAGjE,MAAI,CAAC,QAAQ,MAAM,IACjB,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,qCAAqC,CAAC;AAG/E,SAAO,IAAI,SAAS,QAAQ,MAAM,IAAI;GACtC;AAEF,eAAc,IAAI,WAAW,gBAAgB,OAAO,KAAkB,QAAQ;EAC5E,MAAM,OAAO,IAAI;EAEjB,MAAM,UAAU,MAAM,QAAQ,2BAA2B,EAAE,MAAM,CAAC;AAElE,MAAI,QAAQ,OAAO,CACjB,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,QAAQ,MAAM,SAAS,CAAC;AAGjE,SAAO,IAAI,SAAS,QAAQ,MAAM,IAAI;GACtC;AAEF,eAAc,IAAI,YAAY,gBAAgB,OAAO,KAAkB,QAAQ;EAC7E,MAAM,OAAO,IAAI;AAEjB,MAAI,CAAC,KAAK,iBACR,QAAO,IAAI,SAAS,GAAG,QAAQ,IAAI,aAAa,UAAU;AAK5D,OAFe,MAAM,QAAQ,eAAe,KAAK,iBAAiB,EAEvD,OAAO,CAChB,QAAO,IAAI,SAAS,GAAG,QAAQ,IAAI,aAAa,4BAA4B;AAG9E,SAAO,IAAI,SAAS,GAAG,QAAQ,IAAI,aAAa,UAAU;GAC1D;AAEF,eAAc,KAAK,YAAY,WAAW,IAAI,EAAE,MAAM,oBAAoB,CAAC,EAAE,OAAO,KAAK,QAAQ;EAC/F,MAAM,YAAY,IAAI,QAAQ;AAE9B,MAAI,CAAC,UAAW,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,gBAAgB,CAAC;AAExE,MAAI,OAAO,cAAc,SACvB,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,6BAA6B,CAAC;EAEvE,MAAM,QAAQ,QAAQ,eAAe,IAAI,MAAM,UAAU;AACzD,MAAI,MAAM,OAAO,CACf,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,MAAM,MAAM,SAAS,CAAC;EAG/D,MAAM,SAAS,MAAM,QAAQ,aAAa,MAAM,MAAM;AACtD,MAAI,OAAO,OAAO,CAChB,QAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,OAAO,MAAM,SAAS,CAAC;AAGhE,SAAO,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,UAAU,MAAM,CAAC;GAC/C;AAEF,QAAO"}
@@ -0,0 +1,53 @@
1
+ import { ServerResult, ServerResultAsync } from "../base/base.dto.mjs";
2
+ import { Context } from "../../utils/trpc.mjs";
3
+ import { BillingRepository } from "./billing.repository.mjs";
4
+ import { User } from "../auth/auth.lib.mjs";
5
+ import { BaseService } from "../base/base.service.mjs";
6
+ import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
7
+ import Stripe$1 from "stripe";
8
+
9
+ //#region src/modules/billing/billing.service.d.ts
10
+ declare class BillingService extends BaseService<{
11
+ billing: BillingRepository;
12
+ }, never> {
13
+ createUserCustomer({
14
+ user
15
+ }: {
16
+ user: {
17
+ id: string;
18
+ email: string;
19
+ name?: string;
20
+ };
21
+ }): ServerResultAsync<Stripe$1.Customer>;
22
+ createUserHook({
23
+ user
24
+ }: {
25
+ user: {
26
+ id: string;
27
+ email: string;
28
+ name?: string;
29
+ };
30
+ }): ServerResultAsync<boolean>;
31
+ getActiveSubscription(ctx: Context): ServerResultAsync<BillingSchema | null>;
32
+ listInvoices(ctx: Context): ServerResultAsync<Stripe$1.Invoice[]>;
33
+ createCheckoutSession({
34
+ priceId
35
+ }: {
36
+ priceId: string;
37
+ }, {
38
+ user
39
+ }: {
40
+ user: User;
41
+ }): ServerResultAsync<Stripe$1.Checkout.Session>;
42
+ createBillingPortalSession({
43
+ user
44
+ }: {
45
+ user: User;
46
+ }): ServerResultAsync<Stripe$1.BillingPortal.Session>;
47
+ constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe$1.Event>;
48
+ syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean>;
49
+ processEvent(event: Stripe$1.Event): ServerResultAsync<boolean>;
50
+ }
51
+ //#endregion
52
+ export { BillingService };
53
+ //# sourceMappingURL=billing.service.d.mts.map
@@ -0,0 +1,125 @@
1
+ import { posthogCapture } from "../../utils/posthog.mjs";
2
+ import { BaseService } from "../base/base.service.mjs";
3
+ import { err, ok } from "neverthrow";
4
+ //#region src/modules/billing/billing.service.ts
5
+ const allowedEvents = [
6
+ "checkout.session.completed",
7
+ "customer.subscription.created",
8
+ "customer.subscription.updated",
9
+ "customer.subscription.deleted",
10
+ "customer.subscription.paused",
11
+ "customer.subscription.resumed",
12
+ "customer.subscription.pending_update_applied",
13
+ "customer.subscription.pending_update_expired",
14
+ "customer.subscription.trial_will_end",
15
+ "invoice.paid",
16
+ "invoice.payment_failed",
17
+ "invoice.payment_action_required",
18
+ "invoice.upcoming",
19
+ "invoice.marked_uncollectible",
20
+ "invoice.payment_succeeded",
21
+ "payment_intent.succeeded",
22
+ "payment_intent.payment_failed",
23
+ "payment_intent.canceled"
24
+ ];
25
+ var BillingService = class extends BaseService {
26
+ async createUserCustomer({ user }) {
27
+ let stripeCustomer = null;
28
+ const existingCustomer = await this.repository.billing.getCustomerByEmail(user.email);
29
+ if (existingCustomer.isErr()) return err(existingCustomer.error);
30
+ stripeCustomer = existingCustomer.value;
31
+ if (!stripeCustomer) {
32
+ const newCustomer = await this.repository.billing.createCustomer({
33
+ email: user.email,
34
+ name: user.name,
35
+ userId: user.id
36
+ });
37
+ if (newCustomer.isErr()) return err(newCustomer.error);
38
+ stripeCustomer = newCustomer.value;
39
+ }
40
+ if (!stripeCustomer) return this.error("INTERNAL_SERVER_ERROR", "Failed to create or get stripe customer");
41
+ const updatedUser = await this.repository.billing.updateUserCustomerId({
42
+ userId: user.id,
43
+ customerId: stripeCustomer.id
44
+ });
45
+ if (updatedUser.isErr()) return err(updatedUser.error);
46
+ return ok(stripeCustomer);
47
+ }
48
+ async createUserHook({ user }) {
49
+ const stripeCustomer = await this.createUserCustomer({ user });
50
+ if (stripeCustomer.isErr()) return err(stripeCustomer.error);
51
+ if (this.repository.billing.hasTrial()) {
52
+ const existingSubscription = await this.repository.billing.getLatestSubscription(user.id);
53
+ if (existingSubscription.isErr()) return err(existingSubscription.error);
54
+ if (!existingSubscription.value) {
55
+ const subscription = await this.repository.billing.createTrialSubscription(stripeCustomer.value.id);
56
+ if (subscription.isErr()) return err(subscription.error);
57
+ }
58
+ const syncResult = await this.syncStripeData(stripeCustomer.value.id);
59
+ if (syncResult.isErr()) return err(syncResult.error);
60
+ if (syncResult.value === false) return this.error("INTERNAL_SERVER_ERROR", "Sync did not create new subscription");
61
+ }
62
+ return ok(true);
63
+ }
64
+ async getActiveSubscription(ctx) {
65
+ return this.repository.billing.getActiveSubscription(ctx.actor.userId);
66
+ }
67
+ async listInvoices(ctx) {
68
+ if (!ctx.user.stripeCustomerId) return this.error("NOT_FOUND", "User has no stripe customer id");
69
+ return this.repository.billing.listInvoices(ctx.user.stripeCustomerId);
70
+ }
71
+ async createCheckoutSession({ priceId }, { user }) {
72
+ let stripeCustomerId = user.stripeCustomerId;
73
+ if (!stripeCustomerId) {
74
+ const stripeCustomer = await this.createUserCustomer({ user });
75
+ if (stripeCustomer.isErr()) return err(stripeCustomer.error);
76
+ stripeCustomerId = stripeCustomer.value.id;
77
+ }
78
+ return this.repository.billing.createCheckoutSession({
79
+ customerId: stripeCustomerId,
80
+ priceId,
81
+ userId: user.id
82
+ });
83
+ }
84
+ async createBillingPortalSession({ user }) {
85
+ let stripeCustomerId = user.stripeCustomerId;
86
+ if (!stripeCustomerId) {
87
+ const stripeCustomer = await this.createUserCustomer({ user });
88
+ if (stripeCustomer.isErr()) return err(stripeCustomer.error);
89
+ stripeCustomerId = stripeCustomer.value.id;
90
+ }
91
+ return this.repository.billing.createBillingPortalSession(stripeCustomerId);
92
+ }
93
+ constructEvent(body, signature) {
94
+ if (!process.env.STRIPE_WEBHOOK_SECRET) return this.error("INTERNAL_SERVER_ERROR", "Stripe webhook secret is not set");
95
+ return this.repository.billing.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET);
96
+ }
97
+ async syncStripeData(customerId, eventType) {
98
+ const user = await this.repository.billing.getUserByCustomerId(customerId);
99
+ if (user.isErr()) return err(user.error);
100
+ if (!user.value) return this.error("NOT_FOUND", "User not found");
101
+ if (eventType) posthogCapture({
102
+ distinctId: user.value.id,
103
+ event: `stripe.${eventType}`,
104
+ properties: { customerId }
105
+ });
106
+ return this.repository.billing.syncStripeData({
107
+ customerId,
108
+ userId: user.value.id
109
+ });
110
+ }
111
+ async processEvent(event) {
112
+ return this.throwableAsync(async () => {
113
+ if (!allowedEvents.includes(event.type)) return ok(false);
114
+ const { customer: customerId } = event?.data?.object;
115
+ if (typeof customerId !== "string") return this.error("INTERNAL_SERVER_ERROR", `[STRIPE HOOK] Unexpected event structure: customer ID is not a string. Event type: ${event.type}`);
116
+ const result = await this.syncStripeData(customerId, event.type);
117
+ if (result.isErr()) return err(result.error);
118
+ return ok(true);
119
+ });
120
+ }
121
+ };
122
+ //#endregion
123
+ export { BillingService };
124
+
125
+ //# sourceMappingURL=billing.service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.service.mjs","names":[],"sources":["../../../../src/modules/billing/billing.service.ts"],"sourcesContent":["import type { BillingSchema } from \"@m5kdev/commons/modules/billing/billing.schema\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport type Stripe from \"stripe\";\r\nimport { posthogCapture } from \"../../utils/posthog\";\r\nimport type { User } from \"../auth/auth.lib\";\r\nimport type { ServerResult, ServerResultAsync } from \"../base/base.dto\";\r\nimport type { Context } from \"../../utils/trpc\";\r\nimport { BaseService } from \"../base/base.service\";\r\nimport type { BillingRepository } from \"./billing.repository\";\r\n\r\nconst allowedEvents: Stripe.Event.Type[] = [\r\n \"checkout.session.completed\",\r\n \"customer.subscription.created\",\r\n \"customer.subscription.updated\",\r\n \"customer.subscription.deleted\",\r\n \"customer.subscription.paused\",\r\n \"customer.subscription.resumed\",\r\n \"customer.subscription.pending_update_applied\",\r\n \"customer.subscription.pending_update_expired\",\r\n \"customer.subscription.trial_will_end\",\r\n \"invoice.paid\",\r\n \"invoice.payment_failed\",\r\n \"invoice.payment_action_required\",\r\n \"invoice.upcoming\",\r\n \"invoice.marked_uncollectible\",\r\n \"invoice.payment_succeeded\",\r\n \"payment_intent.succeeded\",\r\n \"payment_intent.payment_failed\",\r\n \"payment_intent.canceled\",\r\n];\r\n\r\nexport class BillingService extends BaseService<{ billing: BillingRepository }, never> {\r\n async createUserCustomer({\r\n user,\r\n }: {\r\n user: { id: string; email: string; name?: string };\r\n }): ServerResultAsync<Stripe.Customer> {\r\n let stripeCustomer: Stripe.Customer | null = null;\r\n const existingCustomer = await this.repository.billing.getCustomerByEmail(user.email);\r\n if (existingCustomer.isErr()) return err(existingCustomer.error);\r\n stripeCustomer = existingCustomer.value;\r\n if (!stripeCustomer) {\r\n const newCustomer = await this.repository.billing.createCustomer({\r\n email: user.email,\r\n name: user.name,\r\n userId: user.id,\r\n });\r\n if (newCustomer.isErr()) return err(newCustomer.error);\r\n stripeCustomer = newCustomer.value;\r\n }\r\n\r\n if (!stripeCustomer)\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to create or get stripe customer\");\r\n const updatedUser = await this.repository.billing.updateUserCustomerId({\r\n userId: user.id,\r\n customerId: stripeCustomer.id,\r\n });\r\n if (updatedUser.isErr()) return err(updatedUser.error);\r\n return ok(stripeCustomer);\r\n }\r\n\r\n async createUserHook({\r\n user,\r\n }: {\r\n user: { id: string; email: string; name?: string };\r\n }): ServerResultAsync<boolean> {\r\n const stripeCustomer = await this.createUserCustomer({ user });\r\n if (stripeCustomer.isErr()) return err(stripeCustomer.error);\r\n\r\n if (this.repository.billing.hasTrial()) {\r\n const existingSubscription = await this.repository.billing.getLatestSubscription(user.id);\r\n if (existingSubscription.isErr()) return err(existingSubscription.error);\r\n if (!existingSubscription.value) {\r\n const subscription = await this.repository.billing.createTrialSubscription(\r\n stripeCustomer.value.id\r\n );\r\n if (subscription.isErr()) return err(subscription.error);\r\n }\r\n const syncResult = await this.syncStripeData(stripeCustomer.value.id);\r\n if (syncResult.isErr()) return err(syncResult.error);\r\n if (syncResult.value === false)\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Sync did not create new subscription\");\r\n }\r\n\r\n return ok(true);\r\n }\r\n\r\n async getActiveSubscription(ctx: Context): ServerResultAsync<BillingSchema | null> {\r\n return this.repository.billing.getActiveSubscription(ctx.actor.userId);\r\n }\r\n\r\n async listInvoices(ctx: Context): ServerResultAsync<Stripe.Invoice[]> {\r\n if (!ctx.user.stripeCustomerId)\r\n return this.error(\"NOT_FOUND\", \"User has no stripe customer id\");\r\n return this.repository.billing.listInvoices(ctx.user.stripeCustomerId);\r\n }\r\n\r\n async createCheckoutSession(\r\n { priceId }: { priceId: string },\r\n { user }: { user: User }\r\n ): ServerResultAsync<Stripe.Checkout.Session> {\r\n let stripeCustomerId = user.stripeCustomerId;\r\n if (!stripeCustomerId) {\r\n const stripeCustomer = await this.createUserCustomer({ user });\r\n if (stripeCustomer.isErr()) return err(stripeCustomer.error);\r\n stripeCustomerId = stripeCustomer.value.id;\r\n }\r\n return this.repository.billing.createCheckoutSession({\r\n customerId: stripeCustomerId,\r\n priceId,\r\n userId: user.id,\r\n });\r\n }\r\n\r\n async createBillingPortalSession({\r\n user,\r\n }: {\r\n user: User;\r\n }): ServerResultAsync<Stripe.BillingPortal.Session> {\r\n let stripeCustomerId = user.stripeCustomerId;\r\n if (!stripeCustomerId) {\r\n const stripeCustomer = await this.createUserCustomer({ user });\r\n if (stripeCustomer.isErr()) return err(stripeCustomer.error);\r\n stripeCustomerId = stripeCustomer.value.id;\r\n }\r\n return this.repository.billing.createBillingPortalSession(stripeCustomerId);\r\n }\r\n\r\n constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe.Event> {\r\n if (!process.env.STRIPE_WEBHOOK_SECRET)\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Stripe webhook secret is not set\");\r\n return this.repository.billing.constructEvent(\r\n body,\r\n signature,\r\n process.env.STRIPE_WEBHOOK_SECRET!\r\n );\r\n }\r\n\r\n async syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean> {\r\n const user = await this.repository.billing.getUserByCustomerId(customerId);\r\n if (user.isErr()) return err(user.error);\r\n if (!user.value) return this.error(\"NOT_FOUND\", \"User not found\");\r\n\r\n if (eventType) {\r\n posthogCapture({\r\n distinctId: user.value.id,\r\n event: `stripe.${eventType}`,\r\n properties: {\r\n customerId,\r\n },\r\n });\r\n }\r\n return this.repository.billing.syncStripeData({ customerId, userId: user.value.id });\r\n }\r\n\r\n async processEvent(event: Stripe.Event): ServerResultAsync<boolean> {\r\n return this.throwableAsync(async () => {\r\n // Skip processing if the event isn't one I'm tracking (list of all events below)\r\n if (!allowedEvents.includes(event.type)) return ok(false);\r\n\r\n // All the events I track have a customerId\r\n const { customer: customerId } = event?.data?.object as {\r\n customer: string; // Sadly TypeScript does not know this\r\n };\r\n\r\n // This helps make it typesafe and also lets me know if my assumption is wrong\r\n if (typeof customerId !== \"string\") {\r\n return this.error(\r\n \"INTERNAL_SERVER_ERROR\",\r\n `[STRIPE HOOK] Unexpected event structure: customer ID is not a string. Event type: ${event.type}`\r\n );\r\n }\r\n\r\n const result = await this.syncStripeData(customerId, event.type);\r\n if (result.isErr()) return err(result.error);\r\n return ok(true);\r\n });\r\n }\r\n}\r\n"],"mappings":"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"}
@@ -0,0 +1,29 @@
1
+ import { Context, TRPCMethods } from "../../utils/trpc.mjs";
2
+ import { BillingService } from "./billing.service.mjs";
3
+ import * as _$_trpc_server0 from "@trpc/server";
4
+ import * as _$stripe from "stripe";
5
+
6
+ //#region src/modules/billing/billing.trpc.d.ts
7
+ declare function createBillingTRPC({
8
+ router,
9
+ privateProcedure: procedure
10
+ }: TRPCMethods, billingService: BillingService): _$_trpc_server0.TRPCBuiltRouter<{
11
+ ctx: Context;
12
+ meta: any;
13
+ errorShape: _$_trpc_server0.TRPCDefaultErrorShape;
14
+ transformer: any;
15
+ }, _$_trpc_server0.TRPCDecorateCreateRouterOptions<{
16
+ getActiveSubscription: _$_trpc_server0.TRPCQueryProcedure<{
17
+ input: void;
18
+ output: any;
19
+ meta: any;
20
+ }>;
21
+ listInvoices: _$_trpc_server0.TRPCQueryProcedure<{
22
+ input: void;
23
+ output: _$stripe.Stripe.Invoice[];
24
+ meta: any;
25
+ }>;
26
+ }>>;
27
+ //#endregion
28
+ export { createBillingTRPC };
29
+ //# sourceMappingURL=billing.trpc.d.mts.map
@@ -0,0 +1,17 @@
1
+ import { handleTRPCResult } from "../../utils/trpc.mjs";
2
+ import { billingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
3
+ //#region src/modules/billing/billing.trpc.ts
4
+ function createBillingTRPC({ router, privateProcedure: procedure }, billingService) {
5
+ return router({
6
+ getActiveSubscription: procedure.output(billingSchema.nullable()).query(async ({ ctx }) => {
7
+ return handleTRPCResult(await billingService.getActiveSubscription(ctx));
8
+ }),
9
+ listInvoices: procedure.query(async ({ ctx }) => {
10
+ return handleTRPCResult(await billingService.listInvoices(ctx));
11
+ })
12
+ });
13
+ }
14
+ //#endregion
15
+ export { createBillingTRPC };
16
+
17
+ //# sourceMappingURL=billing.trpc.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.trpc.mjs","names":[],"sources":["../../../../src/modules/billing/billing.trpc.ts"],"sourcesContent":["import { billingSchema } from \"@m5kdev/commons/modules/billing/billing.schema\";\r\nimport { handleTRPCResult, type TRPCMethods } from \"../../utils/trpc\";\r\nimport type { BillingService } from \"./billing.service\";\r\n\r\nexport function createBillingTRPC(\r\n { router, privateProcedure: procedure }: TRPCMethods,\r\n billingService: BillingService\r\n) {\r\n return router({\r\n getActiveSubscription: procedure.output(billingSchema.nullable()).query(async ({ ctx }) => {\r\n return handleTRPCResult(await billingService.getActiveSubscription(ctx));\r\n }),\r\n\r\n listInvoices: procedure.query(async ({ ctx }) => {\r\n return handleTRPCResult(await billingService.listInvoices(ctx));\r\n }),\r\n });\r\n}\r\n"],"mappings":";;;AAIA,SAAgB,kBACd,EAAE,QAAQ,kBAAkB,aAC5B,gBACA;AACA,QAAO,OAAO;EACZ,uBAAuB,UAAU,OAAO,cAAc,UAAU,CAAC,CAAC,MAAM,OAAO,EAAE,UAAU;AACzF,UAAO,iBAAiB,MAAM,eAAe,sBAAsB,IAAI,CAAC;IACxE;EAEF,cAAc,UAAU,MAAM,OAAO,EAAE,UAAU;AAC/C,UAAO,iBAAiB,MAAM,eAAe,aAAa,IAAI,CAAC;IAC/D;EACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ServerResultAsync } from "../base/base.dto.mjs";
2
+ import { BaseExternaRepository } from "../base/base.repository.mjs";
3
+
4
+ //#region src/modules/clay/clay.repository.d.ts
5
+ declare class ClayRepository extends BaseExternaRepository {
6
+ sendToWebhook(webhookUrl: string, row: Record<string, unknown>, callbackUrl: string): ServerResultAsync<void>;
7
+ }
8
+ //#endregion
9
+ export { ClayRepository };
10
+ //# sourceMappingURL=clay.repository.d.mts.map
@@ -0,0 +1,27 @@
1
+ import { BaseExternaRepository } from "../base/base.repository.mjs";
2
+ import { ok } from "neverthrow";
3
+ //#region src/modules/clay/clay.repository.ts
4
+ const { CLAY_WEBHOOK_AUTH_TOKEN } = process.env;
5
+ var ClayRepository = class extends BaseExternaRepository {
6
+ async sendToWebhook(webhookUrl, row, callbackUrl) {
7
+ return this.throwableAsync(async () => {
8
+ const response = await fetch(webhookUrl, {
9
+ method: "POST",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ ...CLAY_WEBHOOK_AUTH_TOKEN ? { "x-clay-webhook-auth": CLAY_WEBHOOK_AUTH_TOKEN } : {}
13
+ },
14
+ body: JSON.stringify({
15
+ ...row,
16
+ callback: callbackUrl
17
+ })
18
+ });
19
+ if (!response.ok) return this.error("BAD_REQUEST", `HTTP error! status: ${response.status}`, { cause: response });
20
+ return ok();
21
+ });
22
+ }
23
+ };
24
+ //#endregion
25
+ export { ClayRepository };
26
+
27
+ //# sourceMappingURL=clay.repository.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clay.repository.mjs","names":[],"sources":["../../../../src/modules/clay/clay.repository.ts"],"sourcesContent":["import { ok } from \"neverthrow\";\r\nimport type { ServerResultAsync } from \"../base/base.dto\";\r\nimport { BaseExternaRepository } from \"../base/base.repository\";\r\n\r\nconst { CLAY_WEBHOOK_AUTH_TOKEN } = process.env;\r\n\r\nexport class ClayRepository extends BaseExternaRepository {\r\n async sendToWebhook(\r\n webhookUrl: string,\r\n row: Record<string, unknown>,\r\n callbackUrl: string\r\n ): ServerResultAsync<void> {\r\n return this.throwableAsync(async () => {\r\n const response = await fetch(webhookUrl, {\r\n method: \"POST\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n ...(CLAY_WEBHOOK_AUTH_TOKEN ? { \"x-clay-webhook-auth\": CLAY_WEBHOOK_AUTH_TOKEN } : {}),\r\n },\r\n body: JSON.stringify({ ...row, callback: callbackUrl }),\r\n });\r\n if (!response.ok)\r\n return this.error(\"BAD_REQUEST\", `HTTP error! status: ${response.status}`, {\r\n cause: response,\r\n });\r\n return ok();\r\n });\r\n }\r\n}\r\n"],"mappings":";;;AAIA,MAAM,EAAE,4BAA4B,QAAQ;AAE5C,IAAa,iBAAb,cAAoC,sBAAsB;CACxD,MAAM,cACJ,YACA,KACA,aACyB;AACzB,SAAO,KAAK,eAAe,YAAY;GACrC,MAAM,WAAW,MAAM,MAAM,YAAY;IACvC,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,GAAI,0BAA0B,EAAE,uBAAuB,yBAAyB,GAAG,EAAE;KACtF;IACD,MAAM,KAAK,UAAU;KAAE,GAAG;KAAK,UAAU;KAAa,CAAC;IACxD,CAAC;AACF,OAAI,CAAC,SAAS,GACZ,QAAO,KAAK,MAAM,eAAe,uBAAuB,SAAS,UAAU,EACzE,OAAO,UACR,CAAC;AACJ,UAAO,IAAI;IACX"}
@@ -0,0 +1,32 @@
1
+ import { ServerResultAsync } from "../base/base.dto.mjs";
2
+ import { BaseService } from "../base/base.service.mjs";
3
+ import { ClayRepository } from "./clay.repository.mjs";
4
+ import { WebhookService } from "../webhook/webhook.service.mjs";
5
+ import { z } from "zod";
6
+
7
+ //#region src/modules/clay/clay.service.d.ts
8
+ type ClayTable = {
9
+ name?: string;
10
+ tableId?: string;
11
+ viewId?: string;
12
+ webhookUrl: string;
13
+ schema?: z.ZodAny;
14
+ timeoutInSeconds?: number;
15
+ };
16
+ declare class ClayService<K extends string> extends BaseService<{
17
+ clay: ClayRepository;
18
+ }, {
19
+ webhook: WebhookService;
20
+ }> {
21
+ private tables;
22
+ constructor(repositories: {
23
+ clay: ClayRepository;
24
+ }, services: {
25
+ webhook: WebhookService;
26
+ }, tables: Record<K, ClayTable>);
27
+ waitForResponse<T>(webhookUrl: string, row: Record<string, unknown>, timeoutInSeconds?: number): ServerResultAsync<T>;
28
+ sendToTable(table: K, row: Record<string, unknown>, timeoutInSeconds?: number): ServerResultAsync<z.infer<(typeof this.tables)[K]["schema"] extends z.ZodAny ? z.infer<(typeof this.tables)[K]["schema"]> : unknown>>;
29
+ }
30
+ //#endregion
31
+ export { ClayService };
32
+ //# sourceMappingURL=clay.service.d.mts.map
@@ -0,0 +1,23 @@
1
+ import { BaseService } from "../base/base.service.mjs";
2
+ //#region src/modules/clay/clay.service.ts
3
+ var ClayService = class extends BaseService {
4
+ tables;
5
+ constructor(repositories, services, tables) {
6
+ super(repositories, services);
7
+ this.tables = tables;
8
+ }
9
+ async waitForResponse(webhookUrl, row, timeoutInSeconds) {
10
+ return await this.service.webhook.waitForRequest((url) => {
11
+ return this.repository.clay.sendToWebhook(webhookUrl, row, url);
12
+ }, timeoutInSeconds);
13
+ }
14
+ async sendToTable(table, row, timeoutInSeconds) {
15
+ const tableData = this.tables[table];
16
+ if (!tableData) return this.error("NOT_FOUND", `Table ${table} not found`);
17
+ return await this.waitForResponse(tableData.webhookUrl, row, tableData.timeoutInSeconds || timeoutInSeconds);
18
+ }
19
+ };
20
+ //#endregion
21
+ export { ClayService };
22
+
23
+ //# sourceMappingURL=clay.service.mjs.map