@m5kdev/backend 0.8.7 → 0.8.8

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 (386) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +33 -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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +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.cts +1 -0
  23. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect-adapter-base.d.cts +1 -0
  24. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect-adapter.d.cts +1 -0
  25. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/dialect.d.cts +1 -0
  26. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-adapter.d.cts +1 -0
  27. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-dialect.d.cts +1 -0
  28. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mssql/mssql-introspector.d.cts +1 -0
  29. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-adapter.d.cts +1 -0
  30. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-dialect.d.cts +1 -0
  31. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/mysql/mysql-introspector.d.cts +1 -0
  32. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-adapter.d.cts +1 -0
  33. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-dialect.d.cts +1 -0
  34. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/postgres/postgres-introspector.d.cts +1 -0
  35. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-adapter.d.cts +1 -0
  36. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-dialect.d.cts +1 -0
  37. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/dialect/sqlite/sqlite-introspector.d.cts +1 -0
  38. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/expression/expression-builder.d.cts +1 -0
  39. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/index.d.cts +1 -0
  40. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/kysely.d.cts +38 -0
  41. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/migration/file-migration-provider.d.cts +1 -0
  42. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/migration/migrator.d.cts +1 -0
  43. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/binary-operation-parser.d.cts +1 -0
  44. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/delete-from-parser.d.cts +1 -0
  45. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/expression-parser.d.cts +1 -0
  46. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/group-by-parser.d.cts +1 -0
  47. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/insert-values-parser.d.cts +1 -0
  48. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/join-parser.d.cts +1 -0
  49. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/merge-into-parser.d.cts +1 -0
  50. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/reference-parser.d.cts +1 -0
  51. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/returning-parser.d.cts +1 -0
  52. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/select-from-parser.d.cts +1 -0
  53. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/select-parser.d.cts +1 -0
  54. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/set-operation-parser.d.cts +1 -0
  55. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/tuple-parser.d.cts +1 -0
  56. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/unary-operation-parser.d.cts +1 -0
  57. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/update-parser.d.cts +1 -0
  58. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/update-set-parser.d.cts +1 -0
  59. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/value-parser.d.cts +1 -0
  60. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/parser/with-parser.d.cts +1 -0
  61. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/case-builder.d.cts +1 -0
  62. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/delete-query-builder.d.cts +1 -0
  63. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/having-interface.d.cts +1 -0
  64. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/insert-query-builder.d.cts +1 -0
  65. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/join-builder.d.cts +1 -0
  66. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/merge-query-builder.d.cts +1 -0
  67. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/on-conflict-builder.d.cts +1 -0
  68. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/output-interface.d.cts +1 -0
  69. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/returning-interface.d.cts +1 -0
  70. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/select-query-builder.d.cts +1 -0
  71. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/update-query-builder.d.cts +1 -0
  72. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-builder/where-interface.d.cts +1 -0
  73. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-creator.d.cts +1 -0
  74. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/default-query-executor.d.cts +1 -0
  75. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/noop-query-executor.d.cts +1 -0
  76. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor-base.d.cts +1 -0
  77. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor-provider.d.cts +1 -0
  78. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/query-executor/query-executor.d.cts +1 -0
  79. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/raw-builder/raw-builder.d.cts +1 -0
  80. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/raw-builder/sql.d.cts +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.cts +1 -0
  82. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.d.cts +1 -0
  83. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-builder.d.cts +1 -0
  84. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.d.cts +1 -0
  85. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/alter-table-executor.d.cts +1 -0
  86. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-index-builder.d.cts +1 -0
  87. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-schema-builder.d.cts +1 -0
  88. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-table-builder.d.cts +1 -0
  89. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-type-builder.d.cts +1 -0
  90. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/create-view-builder.d.cts +1 -0
  91. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-index-builder.d.cts +1 -0
  92. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-schema-builder.d.cts +1 -0
  93. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-table-builder.d.cts +1 -0
  94. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-type-builder.d.cts +1 -0
  95. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/drop-view-builder.d.cts +1 -0
  96. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.d.cts +1 -0
  97. package/dist/node_modules/.pnpm/kysely@0.28.5/node_modules/kysely/dist/esm/schema/schema.d.cts +1 -0
  98. package/dist/src/lib/posthog.cjs +8 -0
  99. package/dist/src/lib/posthog.cjs.map +1 -0
  100. package/dist/src/lib/posthog.d.cts +7 -0
  101. package/dist/src/lib/sentry.cjs +11 -0
  102. package/dist/src/lib/sentry.cjs.map +1 -0
  103. package/dist/src/lib/sentry.d.cts +1 -0
  104. package/dist/src/modules/access/access.repository.cjs +26 -0
  105. package/dist/src/modules/access/access.repository.cjs.map +1 -0
  106. package/dist/src/modules/access/access.repository.d.cts +2352 -0
  107. package/dist/src/modules/access/access.service.cjs +42 -0
  108. package/dist/src/modules/access/access.service.cjs.map +1 -0
  109. package/dist/src/modules/access/access.service.d.cts +25 -0
  110. package/dist/src/modules/access/access.utils.cjs +23 -0
  111. package/dist/src/modules/access/access.utils.cjs.map +1 -0
  112. package/dist/src/modules/access/access.utils.d.cts +19 -0
  113. package/dist/src/modules/ai/ai.db.cjs +46 -0
  114. package/dist/src/modules/ai/ai.db.cjs.map +1 -0
  115. package/dist/src/modules/ai/ai.db.d.cts +401 -0
  116. package/dist/src/modules/ai/ai.prompt.cjs +33 -0
  117. package/dist/src/modules/ai/ai.prompt.cjs.map +1 -0
  118. package/dist/src/modules/ai/ai.prompt.d.cts +30 -0
  119. package/dist/src/modules/ai/ai.prompts.cjs +18 -0
  120. package/dist/src/modules/ai/ai.prompts.cjs.map +1 -0
  121. package/dist/src/modules/ai/ai.prompts.d.cts +10 -0
  122. package/dist/src/modules/ai/ai.repository.cjs +25 -0
  123. package/dist/src/modules/ai/ai.repository.cjs.map +1 -0
  124. package/dist/src/modules/ai/ai.repository.d.cts +428 -0
  125. package/dist/src/modules/ai/ai.router.cjs +0 -0
  126. package/dist/src/modules/ai/ai.router.d.cts +1 -0
  127. package/dist/src/modules/ai/ai.service.cjs +312 -0
  128. package/dist/src/modules/ai/ai.service.cjs.map +1 -0
  129. package/dist/src/modules/ai/ai.service.d.cts +141 -0
  130. package/dist/src/modules/ai/ai.trpc.cjs +19 -0
  131. package/dist/src/modules/ai/ai.trpc.cjs.map +1 -0
  132. package/dist/src/modules/ai/ai.trpc.d.cts +31 -0
  133. package/dist/src/modules/ai/ideogram/ideogram.constants.cjs +191 -0
  134. package/dist/src/modules/ai/ideogram/ideogram.constants.cjs.map +1 -0
  135. package/dist/src/modules/ai/ideogram/ideogram.constants.d.cts +11 -0
  136. package/dist/src/modules/ai/ideogram/ideogram.dto.cjs +49 -0
  137. package/dist/src/modules/ai/ideogram/ideogram.dto.cjs.map +1 -0
  138. package/dist/src/modules/ai/ideogram/ideogram.dto.d.cts +234 -0
  139. package/dist/src/modules/ai/ideogram/ideogram.prompt.cjs +862 -0
  140. package/dist/src/modules/ai/ideogram/ideogram.prompt.cjs.map +1 -0
  141. package/dist/src/modules/ai/ideogram/ideogram.prompt.d.cts +7 -0
  142. package/dist/src/modules/ai/ideogram/ideogram.repository.cjs +34 -0
  143. package/dist/src/modules/ai/ideogram/ideogram.repository.cjs.map +1 -0
  144. package/dist/src/modules/ai/ideogram/ideogram.repository.d.cts +11 -0
  145. package/dist/src/modules/ai/ideogram/ideogram.service.cjs +12 -0
  146. package/dist/src/modules/ai/ideogram/ideogram.service.cjs.map +1 -0
  147. package/dist/src/modules/ai/ideogram/ideogram.service.d.cts +14 -0
  148. package/dist/src/modules/auth/auth.db.cjs +187 -0
  149. package/dist/src/modules/auth/auth.db.cjs.map +1 -0
  150. package/dist/src/modules/auth/auth.db.d.cts +2341 -0
  151. package/dist/src/modules/auth/auth.dto.cjs +50 -0
  152. package/dist/src/modules/auth/auth.dto.cjs.map +1 -0
  153. package/dist/src/modules/auth/auth.dto.d.cts +70 -0
  154. package/dist/src/modules/auth/auth.dto.d.mts +2 -2
  155. package/dist/src/modules/auth/auth.lib.cjs +234 -0
  156. package/dist/src/modules/auth/auth.lib.cjs.map +1 -0
  157. package/dist/src/modules/auth/auth.lib.d.cts +4894 -0
  158. package/dist/src/modules/auth/auth.lib.d.mts +1 -1
  159. package/dist/src/modules/auth/auth.middleware.cjs +41 -0
  160. package/dist/src/modules/auth/auth.middleware.cjs.map +1 -0
  161. package/dist/src/modules/auth/auth.middleware.d.cts +619 -0
  162. package/dist/src/modules/auth/auth.repository.cjs +403 -0
  163. package/dist/src/modules/auth/auth.repository.cjs.map +1 -0
  164. package/dist/src/modules/auth/auth.repository.d.cts +2453 -0
  165. package/dist/src/modules/auth/auth.service.cjs +229 -0
  166. package/dist/src/modules/auth/auth.service.cjs.map +1 -0
  167. package/dist/src/modules/auth/auth.service.d.cts +105 -0
  168. package/dist/src/modules/auth/auth.trpc.cjs +110 -0
  169. package/dist/src/modules/auth/auth.trpc.cjs.map +1 -0
  170. package/dist/src/modules/auth/auth.trpc.d.cts +303 -0
  171. package/dist/src/modules/auth/auth.trpc.d.mts +6 -6
  172. package/dist/src/modules/auth/auth.utils.cjs +80 -0
  173. package/dist/src/modules/auth/auth.utils.cjs.map +1 -0
  174. package/dist/src/modules/auth/auth.utils.d.cts +2356 -0
  175. package/dist/src/modules/base/base.abstract.cjs +62 -0
  176. package/dist/src/modules/base/base.abstract.cjs.map +1 -0
  177. package/dist/src/modules/base/base.abstract.d.cts +29 -0
  178. package/dist/src/modules/base/base.actor.cjs +83 -0
  179. package/dist/src/modules/base/base.actor.cjs.map +1 -0
  180. package/dist/src/modules/base/base.actor.d.cts +73 -0
  181. package/dist/src/modules/base/base.dto.cjs +98 -0
  182. package/dist/src/modules/base/base.dto.cjs.map +1 -0
  183. package/dist/src/modules/base/base.dto.d.cts +67 -0
  184. package/dist/src/modules/base/base.grants.cjs +107 -0
  185. package/dist/src/modules/base/base.grants.cjs.map +1 -0
  186. package/dist/src/modules/base/base.grants.d.cts +28 -0
  187. package/dist/src/modules/base/base.procedure.cjs +255 -0
  188. package/dist/src/modules/base/base.procedure.cjs.map +1 -0
  189. package/dist/src/modules/base/base.procedure.d.cts +111 -0
  190. package/dist/src/modules/base/base.repository.cjs +269 -0
  191. package/dist/src/modules/base/base.repository.cjs.map +1 -0
  192. package/dist/src/modules/base/base.repository.d.cts +125 -0
  193. package/dist/src/modules/base/base.repository.d.mts +2 -0
  194. package/dist/src/modules/base/base.repository.mjs +12 -0
  195. package/dist/src/modules/base/base.repository.mjs.map +1 -1
  196. package/dist/src/modules/base/base.service.cjs +119 -0
  197. package/dist/src/modules/base/base.service.cjs.map +1 -0
  198. package/dist/src/modules/base/base.service.d.cts +44 -0
  199. package/dist/src/modules/base/base.types.cjs +0 -0
  200. package/dist/src/modules/base/base.types.d.cts +5 -0
  201. package/dist/src/modules/billing/billing.db.cjs +38 -0
  202. package/dist/src/modules/billing/billing.db.cjs.map +1 -0
  203. package/dist/src/modules/billing/billing.db.d.cts +371 -0
  204. package/dist/src/modules/billing/billing.repository.cjs +190 -0
  205. package/dist/src/modules/billing/billing.repository.cjs.map +1 -0
  206. package/dist/src/modules/billing/billing.repository.d.cts +2787 -0
  207. package/dist/src/modules/billing/billing.router.cjs +43 -0
  208. package/dist/src/modules/billing/billing.router.cjs.map +1 -0
  209. package/dist/src/modules/billing/billing.router.d.cts +9 -0
  210. package/dist/src/modules/billing/billing.service.cjs +127 -0
  211. package/dist/src/modules/billing/billing.service.cjs.map +1 -0
  212. package/dist/src/modules/billing/billing.service.d.cts +53 -0
  213. package/dist/src/modules/billing/billing.trpc.cjs +19 -0
  214. package/dist/src/modules/billing/billing.trpc.cjs.map +1 -0
  215. package/dist/src/modules/billing/billing.trpc.d.cts +48 -0
  216. package/dist/src/modules/clay/clay.repository.cjs +29 -0
  217. package/dist/src/modules/clay/clay.repository.cjs.map +1 -0
  218. package/dist/src/modules/clay/clay.repository.d.cts +10 -0
  219. package/dist/src/modules/clay/clay.service.cjs +24 -0
  220. package/dist/src/modules/clay/clay.service.cjs.map +1 -0
  221. package/dist/src/modules/clay/clay.service.d.cts +32 -0
  222. package/dist/src/modules/connect/connect.db.cjs +37 -0
  223. package/dist/src/modules/connect/connect.db.cjs.map +1 -0
  224. package/dist/src/modules/connect/connect.db.d.cts +362 -0
  225. package/dist/src/modules/connect/connect.dto.cjs +45 -0
  226. package/dist/src/modules/connect/connect.dto.cjs.map +1 -0
  227. package/dist/src/modules/connect/connect.dto.d.cts +79 -0
  228. package/dist/src/modules/connect/connect.dto.d.mts +2 -2
  229. package/dist/src/modules/connect/connect.linkedin.cjs +48 -0
  230. package/dist/src/modules/connect/connect.linkedin.cjs.map +1 -0
  231. package/dist/src/modules/connect/connect.linkedin.d.cts +7 -0
  232. package/dist/src/modules/connect/connect.oauth.cjs +153 -0
  233. package/dist/src/modules/connect/connect.oauth.cjs.map +1 -0
  234. package/dist/src/modules/connect/connect.oauth.d.cts +32 -0
  235. package/dist/src/modules/connect/connect.repository.cjs +42 -0
  236. package/dist/src/modules/connect/connect.repository.cjs.map +1 -0
  237. package/dist/src/modules/connect/connect.repository.d.cts +419 -0
  238. package/dist/src/modules/connect/connect.repository.d.mts +1 -1
  239. package/dist/src/modules/connect/connect.router.cjs +48 -0
  240. package/dist/src/modules/connect/connect.router.cjs.map +1 -0
  241. package/dist/src/modules/connect/connect.router.d.cts +9 -0
  242. package/dist/src/modules/connect/connect.service.cjs +90 -0
  243. package/dist/src/modules/connect/connect.service.cjs.map +1 -0
  244. package/dist/src/modules/connect/connect.service.d.cts +103 -0
  245. package/dist/src/modules/connect/connect.service.d.mts +2 -2
  246. package/dist/src/modules/connect/connect.trpc.cjs +18 -0
  247. package/dist/src/modules/connect/connect.trpc.cjs.map +1 -0
  248. package/dist/src/modules/connect/connect.trpc.d.cts +53 -0
  249. package/dist/src/modules/connect/connect.types.cjs +0 -0
  250. package/dist/src/modules/connect/connect.types.d.cts +29 -0
  251. package/dist/src/modules/crypto/crypto.db.cjs +26 -0
  252. package/dist/src/modules/crypto/crypto.db.cjs.map +1 -0
  253. package/dist/src/modules/crypto/crypto.db.d.cts +157 -0
  254. package/dist/src/modules/crypto/crypto.repository.cjs +9 -0
  255. package/dist/src/modules/crypto/crypto.repository.cjs.map +1 -0
  256. package/dist/src/modules/crypto/crypto.repository.d.cts +163 -0
  257. package/dist/src/modules/crypto/crypto.service.cjs +46 -0
  258. package/dist/src/modules/crypto/crypto.service.cjs.map +1 -0
  259. package/dist/src/modules/crypto/crypto.service.d.cts +15 -0
  260. package/dist/src/modules/email/email.service.cjs +107 -0
  261. package/dist/src/modules/email/email.service.cjs.map +1 -0
  262. package/dist/src/modules/email/email.service.d.cts +62 -0
  263. package/dist/src/modules/file/file.repository.cjs +74 -0
  264. package/dist/src/modules/file/file.repository.cjs.map +1 -0
  265. package/dist/src/modules/file/file.repository.d.cts +17 -0
  266. package/dist/src/modules/file/file.router.cjs +94 -0
  267. package/dist/src/modules/file/file.router.cjs.map +1 -0
  268. package/dist/src/modules/file/file.router.d.cts +7 -0
  269. package/dist/src/modules/file/file.service.cjs +120 -0
  270. package/dist/src/modules/file/file.service.cjs.map +1 -0
  271. package/dist/src/modules/file/file.service.d.cts +30 -0
  272. package/dist/src/modules/recurrence/recurrence.db.cjs +55 -0
  273. package/dist/src/modules/recurrence/recurrence.db.cjs.map +1 -0
  274. package/dist/src/modules/recurrence/recurrence.db.d.cts +568 -0
  275. package/dist/src/modules/recurrence/recurrence.repository.cjs +31 -0
  276. package/dist/src/modules/recurrence/recurrence.repository.cjs.map +1 -0
  277. package/dist/src/modules/recurrence/recurrence.repository.d.cts +588 -0
  278. package/dist/src/modules/recurrence/recurrence.service.cjs +66 -0
  279. package/dist/src/modules/recurrence/recurrence.service.cjs.map +1 -0
  280. package/dist/src/modules/recurrence/recurrence.service.d.cts +88 -0
  281. package/dist/src/modules/recurrence/recurrence.service.d.mts +3 -2
  282. package/dist/src/modules/recurrence/recurrence.service.mjs +1 -1
  283. package/dist/src/modules/recurrence/recurrence.service.mjs.map +1 -1
  284. package/dist/src/modules/recurrence/recurrence.trpc.cjs +46 -0
  285. package/dist/src/modules/recurrence/recurrence.trpc.cjs.map +1 -0
  286. package/dist/src/modules/recurrence/recurrence.trpc.d.cts +216 -0
  287. package/dist/src/modules/recurrence/recurrence.trpc.d.mts +1 -0
  288. package/dist/src/modules/social/social.dto.cjs +26 -0
  289. package/dist/src/modules/social/social.dto.cjs.map +1 -0
  290. package/dist/src/modules/social/social.dto.d.cts +39 -0
  291. package/dist/src/modules/social/social.linkedin.cjs +349 -0
  292. package/dist/src/modules/social/social.linkedin.cjs.map +1 -0
  293. package/dist/src/modules/social/social.linkedin.d.cts +15 -0
  294. package/dist/src/modules/social/social.service.cjs +57 -0
  295. package/dist/src/modules/social/social.service.cjs.map +1 -0
  296. package/dist/src/modules/social/social.service.d.cts +34 -0
  297. package/dist/src/modules/social/social.types.cjs +0 -0
  298. package/dist/src/modules/social/social.types.d.cts +40 -0
  299. package/dist/src/modules/tag/tag.db.cjs +43 -0
  300. package/dist/src/modules/tag/tag.db.cjs.map +1 -0
  301. package/dist/src/modules/tag/tag.db.d.cts +352 -0
  302. package/dist/src/modules/tag/tag.dto.cjs +15 -0
  303. package/dist/src/modules/tag/tag.dto.cjs.map +1 -0
  304. package/dist/src/modules/tag/tag.dto.d.cts +1025 -0
  305. package/dist/src/modules/tag/tag.repository.cjs +116 -0
  306. package/dist/src/modules/tag/tag.repository.cjs.map +1 -0
  307. package/dist/src/modules/tag/tag.repository.d.cts +394 -0
  308. package/dist/src/modules/tag/tag.service.cjs +48 -0
  309. package/dist/src/modules/tag/tag.service.cjs.map +1 -0
  310. package/dist/src/modules/tag/tag.service.d.cts +120 -0
  311. package/dist/src/modules/tag/tag.trpc.cjs +32 -0
  312. package/dist/src/modules/tag/tag.trpc.cjs.map +1 -0
  313. package/dist/src/modules/tag/tag.trpc.d.cts +174 -0
  314. package/dist/src/modules/tag/tag.trpc.d.mts +1 -0
  315. package/dist/src/modules/utils/applyPagination.cjs +16 -0
  316. package/dist/src/modules/utils/applyPagination.cjs.map +1 -0
  317. package/dist/src/modules/utils/applyPagination.d.cts +10 -0
  318. package/dist/src/modules/utils/applySorting.cjs +20 -0
  319. package/dist/src/modules/utils/applySorting.cjs.map +1 -0
  320. package/dist/src/modules/utils/applySorting.d.cts +13 -0
  321. package/dist/src/modules/utils/getConditionsFromFilters.cjs +152 -0
  322. package/dist/src/modules/utils/getConditionsFromFilters.cjs.map +1 -0
  323. package/dist/src/modules/utils/getConditionsFromFilters.d.cts +9 -0
  324. package/dist/src/modules/utils/getGlobalSearchCondition.cjs +30 -0
  325. package/dist/src/modules/utils/getGlobalSearchCondition.cjs.map +1 -0
  326. package/dist/src/modules/utils/getGlobalSearchCondition.d.cts +18 -0
  327. package/dist/src/modules/utils/getGlobalSearchCondition.d.mts +18 -0
  328. package/dist/src/modules/utils/getGlobalSearchCondition.mjs +26 -0
  329. package/dist/src/modules/utils/getGlobalSearchCondition.mjs.map +1 -0
  330. package/dist/src/modules/video/video.service.cjs +114 -0
  331. package/dist/src/modules/video/video.service.cjs.map +1 -0
  332. package/dist/src/modules/video/video.service.d.cts +12 -0
  333. package/dist/src/modules/video/video.service.mjs.map +1 -1
  334. package/dist/src/modules/webhook/webhook.constants.cjs +13 -0
  335. package/dist/src/modules/webhook/webhook.constants.cjs.map +1 -0
  336. package/dist/src/modules/webhook/webhook.constants.d.cts +12 -0
  337. package/dist/src/modules/webhook/webhook.db.cjs +19 -0
  338. package/dist/src/modules/webhook/webhook.db.cjs.map +1 -0
  339. package/dist/src/modules/webhook/webhook.db.d.cts +142 -0
  340. package/dist/src/modules/webhook/webhook.dto.cjs +11 -0
  341. package/dist/src/modules/webhook/webhook.dto.cjs.map +1 -0
  342. package/dist/src/modules/webhook/webhook.dto.d.cts +402 -0
  343. package/dist/src/modules/webhook/webhook.repository.cjs +52 -0
  344. package/dist/src/modules/webhook/webhook.repository.cjs.map +1 -0
  345. package/dist/src/modules/webhook/webhook.repository.d.cts +154 -0
  346. package/dist/src/modules/webhook/webhook.router.cjs +26 -0
  347. package/dist/src/modules/webhook/webhook.router.cjs.map +1 -0
  348. package/dist/src/modules/webhook/webhook.router.d.cts +8 -0
  349. package/dist/src/modules/webhook/webhook.service.cjs +61 -0
  350. package/dist/src/modules/webhook/webhook.service.cjs.map +1 -0
  351. package/dist/src/modules/webhook/webhook.service.d.cts +14 -0
  352. package/dist/src/modules/workflow/workflow.db.cjs +35 -0
  353. package/dist/src/modules/workflow/workflow.db.cjs.map +1 -0
  354. package/dist/src/modules/workflow/workflow.db.d.cts +302 -0
  355. package/dist/src/modules/workflow/workflow.repository.cjs +95 -0
  356. package/dist/src/modules/workflow/workflow.repository.cjs.map +1 -0
  357. package/dist/src/modules/workflow/workflow.repository.d.cts +371 -0
  358. package/dist/src/modules/workflow/workflow.service.cjs +41 -0
  359. package/dist/src/modules/workflow/workflow.service.cjs.map +1 -0
  360. package/dist/src/modules/workflow/workflow.service.d.cts +68 -0
  361. package/dist/src/modules/workflow/workflow.trpc.cjs +19 -0
  362. package/dist/src/modules/workflow/workflow.trpc.cjs.map +1 -0
  363. package/dist/src/modules/workflow/workflow.trpc.d.cts +65 -0
  364. package/dist/src/modules/workflow/workflow.types.cjs +0 -0
  365. package/dist/src/modules/workflow/workflow.types.d.cts +25 -0
  366. package/dist/src/modules/workflow/workflow.utils.cjs +185 -0
  367. package/dist/src/modules/workflow/workflow.utils.cjs.map +1 -0
  368. package/dist/src/modules/workflow/workflow.utils.d.cts +36 -0
  369. package/dist/src/types.cjs +12 -0
  370. package/dist/src/types.cjs.map +1 -0
  371. package/dist/src/types.d.cts +344 -0
  372. package/dist/src/utils/errors.cjs +101 -0
  373. package/dist/src/utils/errors.cjs.map +1 -0
  374. package/dist/src/utils/errors.d.cts +62 -0
  375. package/dist/src/utils/logger.cjs +13 -0
  376. package/dist/src/utils/logger.cjs.map +1 -0
  377. package/dist/src/utils/logger.d.cts +7 -0
  378. package/dist/src/utils/posthog.cjs +31 -0
  379. package/dist/src/utils/posthog.cjs.map +1 -0
  380. package/dist/src/utils/posthog.d.cts +17 -0
  381. package/dist/src/utils/trpc.cjs +156 -0
  382. package/dist/src/utils/trpc.cjs.map +1 -0
  383. package/dist/src/utils/trpc.d.cts +54 -0
  384. package/dist/src/utils/types.cjs +0 -0
  385. package/dist/src/utils/types.d.cts +9 -0
  386. package/package.json +171 -45
@@ -0,0 +1,190 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../_virtual/_rolldown/runtime.cjs");
3
+ const require_src_utils_posthog = require("../../utils/posthog.cjs");
4
+ const require_src_modules_auth_auth_db = require("../auth/auth.db.cjs");
5
+ const require_src_modules_base_base_repository = require("../base/base.repository.cjs");
6
+ const require_src_modules_billing_billing_db = require("./billing.db.cjs");
7
+ let drizzle_orm = require("drizzle-orm");
8
+ let neverthrow = require("neverthrow");
9
+ //#region src/modules/billing/billing.repository.ts
10
+ ({
11
+ ...require_src_modules_auth_auth_db.auth_db_exports,
12
+ ...require_src_modules_billing_billing_db.billing_db_exports
13
+ });
14
+ var BillingRepository = class extends require_src_modules_base_base_repository.BaseTableRepository {
15
+ stripe;
16
+ plans;
17
+ trial;
18
+ constructor(options) {
19
+ const { libs, config, ...rest } = options;
20
+ super(rest);
21
+ this.stripe = libs.stripe;
22
+ this.plans = config.plans;
23
+ this.trial = config.trial;
24
+ }
25
+ hasTrial() {
26
+ return !!this.trial;
27
+ }
28
+ getPlanByPriceId(priceId) {
29
+ return this.plans.find((plan) => plan.priceId === priceId || plan.annualDiscountPriceId === priceId);
30
+ }
31
+ getCustomerByEmail(email) {
32
+ return this.throwableAsync(async () => {
33
+ return (0, neverthrow.ok)((await this.stripe.customers.list({
34
+ email,
35
+ limit: 1
36
+ })).data[0] ?? null);
37
+ });
38
+ }
39
+ getUserByCustomerId(customerId) {
40
+ return this.throwableAsync(async () => {
41
+ const [user] = await this.orm.select().from(this.schema.users).where((0, drizzle_orm.eq)(this.schema.users.stripeCustomerId, customerId)).limit(1);
42
+ return (0, neverthrow.ok)(user ?? null);
43
+ });
44
+ }
45
+ createCustomer({ email, name, userId }) {
46
+ return this.throwableAsync(async () => {
47
+ return (0, neverthrow.ok)(await this.stripe.customers.create({
48
+ email,
49
+ name,
50
+ metadata: { userId }
51
+ }));
52
+ });
53
+ }
54
+ async createTrialSubscription(customerId) {
55
+ if (!this.trial) return this.error("NOT_FOUND", "Trial plan not found");
56
+ const stripeSubscription = await this.createSubscription({
57
+ customerId,
58
+ priceId: this.trial.priceId,
59
+ trialDays: this.trial.freeTrial?.days ?? 7
60
+ });
61
+ if (stripeSubscription.isErr()) return (0, neverthrow.err)(stripeSubscription.error);
62
+ if (!stripeSubscription.value) return this.error("INTERNAL_SERVER_ERROR", "Failed to create trial subscription");
63
+ return (0, neverthrow.ok)(stripeSubscription.value);
64
+ }
65
+ createSubscription({ customerId, priceId, quantity = 1, trialDays }) {
66
+ return this.throwableAsync(async () => {
67
+ return (0, neverthrow.ok)(await this.stripe.subscriptions.create({
68
+ customer: customerId,
69
+ items: [{
70
+ price: priceId,
71
+ quantity
72
+ }],
73
+ ...trialDays ? {
74
+ trial_period_days: trialDays,
75
+ trial_settings: { end_behavior: { missing_payment_method: "cancel" } }
76
+ } : {}
77
+ }));
78
+ });
79
+ }
80
+ updateUserCustomerId({ userId, customerId }) {
81
+ return this.throwableAsync(async () => {
82
+ const [user] = await this.orm.update(this.schema.users).set({ stripeCustomerId: customerId }).where((0, drizzle_orm.eq)(this.schema.users.id, userId)).returning();
83
+ if (!user) return this.error("NOT_FOUND", "User not found");
84
+ return (0, neverthrow.ok)(user);
85
+ });
86
+ }
87
+ getLatestSubscription(referenceId) {
88
+ return this.throwableAsync(async () => {
89
+ return (0, neverthrow.ok)((await this.orm.select().from(this.schema.subscriptions).where((0, drizzle_orm.eq)(this.schema.subscriptions.referenceId, referenceId)).orderBy((0, drizzle_orm.desc)(this.schema.subscriptions.createdAt)).limit(1))[0] ?? null);
90
+ });
91
+ }
92
+ getActiveSubscription(referenceId) {
93
+ return this.throwableAsync(async () => {
94
+ const [subscription] = await this.orm.select().from(this.schema.subscriptions).where((0, drizzle_orm.and)((0, drizzle_orm.eq)(this.schema.subscriptions.referenceId, referenceId), (0, drizzle_orm.inArray)(this.schema.subscriptions.status, ["active", "trialing"]))).orderBy((0, drizzle_orm.desc)(this.schema.subscriptions.createdAt)).limit(1);
95
+ return (0, neverthrow.ok)(subscription ?? null);
96
+ });
97
+ }
98
+ listInvoices(customerId) {
99
+ return this.throwableAsync(async () => {
100
+ return (0, neverthrow.ok)((await this.stripe.invoices.list({ customer: customerId })).data);
101
+ });
102
+ }
103
+ createCheckoutSession({ customerId, priceId, userId }) {
104
+ return this.throwableAsync(async () => {
105
+ return (0, neverthrow.ok)(await this.stripe.checkout.sessions.create({
106
+ client_reference_id: userId,
107
+ customer: customerId,
108
+ success_url: `${process.env.VITE_SERVER_URL}/stripe/success`,
109
+ cancel_url: `${process.env.VITE_APP_URL}/billing`,
110
+ mode: "subscription",
111
+ line_items: [{
112
+ price: priceId,
113
+ quantity: 1
114
+ }]
115
+ }));
116
+ });
117
+ }
118
+ createBillingPortalSession(customerId) {
119
+ return this.throwableAsync(async () => {
120
+ return (0, neverthrow.ok)(await this.stripe.billingPortal.sessions.create({
121
+ customer: customerId,
122
+ return_url: `${process.env.VITE_SERVER_URL}/stripe/success`
123
+ }));
124
+ });
125
+ }
126
+ async syncStripeData({ customerId, userId }) {
127
+ return this.throwableAsync(async () => {
128
+ const [stripeSubscription] = (await this.stripe.subscriptions.list({
129
+ customer: customerId,
130
+ limit: 1,
131
+ status: "all",
132
+ expand: ["data.default_payment_method"]
133
+ })).data;
134
+ if (!stripeSubscription) return this.error("NOT_FOUND", "Subscription not found");
135
+ const plan = this.getPlanByPriceId(stripeSubscription.items.data[0]?.price.id);
136
+ if (!plan) return this.error("NOT_FOUND", `Plan not found for price ID: ${stripeSubscription.items.data[0]?.price.id}`);
137
+ const values = {
138
+ stripeCustomerId: customerId,
139
+ referenceId: userId,
140
+ plan: plan.name,
141
+ status: stripeSubscription.status,
142
+ seats: stripeSubscription.items.data[0]?.quantity || 1,
143
+ periodEnd: /* @__PURE__ */ new Date(stripeSubscription.items.data[0]?.current_period_end * 1e3),
144
+ periodStart: /* @__PURE__ */ new Date(stripeSubscription.items.data[0]?.current_period_start * 1e3),
145
+ priceId: stripeSubscription.items.data[0]?.price.id,
146
+ interval: stripeSubscription.items.data[0]?.price.recurring?.interval,
147
+ unitAmount: stripeSubscription.items.data[0]?.price.unit_amount,
148
+ discounts: stripeSubscription.discounts.map((discount) => typeof discount === "string" ? discount : discount.id),
149
+ stripeSubscriptionId: stripeSubscription.id,
150
+ cancelAtPeriodEnd: stripeSubscription.cancel_at_period_end,
151
+ cancelAt: stripeSubscription.cancel_at ? /* @__PURE__ */ new Date(stripeSubscription.cancel_at * 1e3) : null,
152
+ canceledAt: stripeSubscription.canceled_at ? /* @__PURE__ */ new Date(stripeSubscription.canceled_at * 1e3) : null,
153
+ ...stripeSubscription.trial_start && stripeSubscription.trial_end ? {
154
+ trialStart: /* @__PURE__ */ new Date(stripeSubscription.trial_start * 1e3),
155
+ trialEnd: /* @__PURE__ */ new Date(stripeSubscription.trial_end * 1e3)
156
+ } : {}
157
+ };
158
+ const existingSubscription = await this.getActiveSubscription(userId);
159
+ if (existingSubscription.isErr()) return (0, neverthrow.err)(existingSubscription.error);
160
+ if (!existingSubscription.value) {
161
+ await this.orm.insert(this.schema.subscriptions).values(values);
162
+ require_src_utils_posthog.posthogCapture({
163
+ distinctId: userId,
164
+ event: "stripe.subscription_created",
165
+ properties: values
166
+ });
167
+ return (0, neverthrow.ok)(true);
168
+ }
169
+ await this.orm.update(this.schema.subscriptions).set({
170
+ ...values,
171
+ updatedAt: /* @__PURE__ */ new Date()
172
+ }).where((0, drizzle_orm.eq)(this.schema.subscriptions.id, existingSubscription.value.id));
173
+ require_src_utils_posthog.posthogCapture({
174
+ distinctId: userId,
175
+ event: "stripe.subscription_updated",
176
+ properties: values
177
+ });
178
+ return (0, neverthrow.ok)(false);
179
+ });
180
+ }
181
+ constructEvent(body, signature, secret) {
182
+ return this.throwable(() => {
183
+ return (0, neverthrow.ok)(this.stripe.webhooks.constructEvent(body, signature, secret));
184
+ });
185
+ }
186
+ };
187
+ //#endregion
188
+ exports.BillingRepository = BillingRepository;
189
+
190
+ //# sourceMappingURL=billing.repository.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.repository.cjs","names":["auth","billing","BaseTableRepository"],"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":";;;;;;;;;CAYe;CAAE,GAAGA,iCAAAA;CAAM,GAAGC,uCAAAA;CAAS;AAItC,IAAa,oBAAb,cAAuCC,yCAAAA,oBAKrC;CACA;CACA;CACA;CAEA,YAAY,SAST;EACD,MAAM,EAAE,MAAM,QAAQ,GAAG,SAAS;AAClC,QAAM,KAAK;AACX,OAAK,SAAS,KAAK;AACnB,OAAK,QAAQ,OAAO;AACpB,OAAK,QAAQ,OAAO;;CAEtB,WAAoB;AAClB,SAAO,CAAC,CAAC,KAAK;;CAGhB,iBAAiB,SAAyC;AACxD,SAAO,KAAK,MAAM,MACf,SAAS,KAAK,YAAY,WAAW,KAAK,0BAA0B,QACtE;;CAGH,mBAAmB,OAA0D;AAC3E,SAAO,KAAK,eAAe,YAAY;AAKrC,WAAA,GAAA,WAAA,KAJkB,MAAM,KAAK,OAAO,UAAU,KAAK;IACjD;IACA,OAAO;IACR,CAAC,EACkB,KAAK,MAAM,KAAK;IACpC;;CAGJ,oBACE,YAC6D;AAC7D,SAAO,KAAK,eAAe,YAAY;GACrC,MAAM,CAAC,QAAQ,MAAM,KAAK,IACvB,QAAQ,CACR,KAAK,KAAK,OAAO,MAAM,CACvB,OAAA,GAAA,YAAA,IAAS,KAAK,OAAO,MAAM,kBAAkB,WAAW,CAAC,CACzD,MAAM,EAAE;AACX,WAAA,GAAA,WAAA,IAAU,QAAQ,KAAK;IACvB;;CAGJ,eAAe,EACb,OACA,MACA,UAKqC;AACrC,SAAO,KAAK,eAAe,YAAY;AAQrC,WAAA,GAAA,WAAA,IAPiB,MAAM,KAAK,OAAO,UAAU,OAAO;IAClD;IACA;IACA,UAAU,EACR,QACD;IACF,CAAC,CACi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