@m5kdev/backend 0.1.0 → 0.1.2
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.
- package/.cursor/rules/backend.mdc +70 -0
- package/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-check-types.log +5 -0
- package/.turbo/turbo-lint$colon$fix.log +255 -0
- package/CHANGELOG.md +19 -0
- package/dist/src/lib/posthog.d.ts +3 -0
- package/dist/src/lib/posthog.d.ts.map +1 -0
- package/dist/src/lib/posthog.js +7 -0
- package/dist/src/lib/sentry.d.ts +2 -0
- package/dist/src/lib/sentry.d.ts.map +1 -0
- package/dist/src/lib/sentry.js +9 -0
- package/dist/src/modules/access/access.repository.d.ts +2348 -0
- package/dist/src/modules/access/access.repository.d.ts.map +1 -0
- package/dist/src/modules/access/access.repository.js +32 -0
- package/dist/src/modules/access/access.service.d.ts +22 -0
- package/dist/src/modules/access/access.service.d.ts.map +1 -0
- package/dist/src/modules/access/access.service.js +51 -0
- package/dist/src/modules/access/access.test.d.ts +2 -0
- package/dist/src/modules/access/access.test.d.ts.map +1 -0
- package/dist/src/modules/access/access.test.js +182 -0
- package/dist/src/modules/access/access.utils.d.ts +17 -0
- package/dist/src/modules/access/access.utils.d.ts.map +1 -0
- package/dist/src/modules/access/access.utils.js +20 -0
- package/dist/src/modules/ai/ai.db.d.ts +396 -0
- package/dist/src/modules/ai/ai.db.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.db.js +39 -0
- package/dist/src/modules/ai/ai.prompt.d.ts +28 -0
- package/dist/src/modules/ai/ai.prompt.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.prompt.js +30 -0
- package/dist/src/modules/ai/ai.repository.d.ts +424 -0
- package/dist/src/modules/ai/ai.repository.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.repository.js +26 -0
- package/dist/src/modules/ai/ai.router.d.ts +2 -0
- package/dist/src/modules/ai/ai.router.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.router.js +132 -0
- package/dist/src/modules/ai/ai.service.d.ts +115 -0
- package/dist/src/modules/ai/ai.service.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.service.js +207 -0
- package/dist/src/modules/ai/ai.trpc.d.ts +59 -0
- package/dist/src/modules/ai/ai.trpc.d.ts.map +1 -0
- package/dist/src/modules/ai/ai.trpc.js +20 -0
- package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts +8 -0
- package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts.map +1 -0
- package/dist/src/modules/ai/ideogram/ideogram.constants.js +167 -0
- package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts +230 -0
- package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts.map +1 -0
- package/dist/src/modules/ai/ideogram/ideogram.dto.js +49 -0
- package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts +3 -0
- package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts.map +1 -0
- package/dist/src/modules/ai/ideogram/ideogram.prompt.js +860 -0
- package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts +7 -0
- package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts.map +1 -0
- package/dist/src/modules/ai/ideogram/ideogram.repository.js +46 -0
- package/dist/src/modules/ai/ideogram/ideogram.service.d.ts +10 -0
- package/dist/src/modules/ai/ideogram/ideogram.service.d.ts.map +1 -0
- package/dist/src/modules/ai/ideogram/ideogram.service.js +11 -0
- package/dist/src/modules/auth/auth.db.d.ts +2336 -0
- package/dist/src/modules/auth/auth.db.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.db.js +215 -0
- package/dist/src/modules/auth/auth.dto.d.ts +66 -0
- package/dist/src/modules/auth/auth.dto.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.dto.js +38 -0
- package/dist/src/modules/auth/auth.lib.d.ts +4874 -0
- package/dist/src/modules/auth/auth.lib.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.lib.js +284 -0
- package/dist/src/modules/auth/auth.middleware.d.ts +615 -0
- package/dist/src/modules/auth/auth.middleware.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.middleware.js +52 -0
- package/dist/src/modules/auth/auth.repository.d.ts +2417 -0
- package/dist/src/modules/auth/auth.repository.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.repository.js +541 -0
- package/dist/src/modules/auth/auth.service.d.ts +104 -0
- package/dist/src/modules/auth/auth.service.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.service.js +201 -0
- package/dist/src/modules/auth/auth.trpc.d.ts +309 -0
- package/dist/src/modules/auth/auth.trpc.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.trpc.js +157 -0
- package/dist/src/modules/auth/auth.utils.d.ts +2352 -0
- package/dist/src/modules/auth/auth.utils.d.ts.map +1 -0
- package/dist/src/modules/auth/auth.utils.js +97 -0
- package/dist/src/modules/base/base.abstract.d.ts +19 -0
- package/dist/src/modules/base/base.abstract.d.ts.map +1 -0
- package/dist/src/modules/base/base.abstract.js +53 -0
- package/dist/src/modules/base/base.dto.d.ts +70 -0
- package/dist/src/modules/base/base.dto.d.ts.map +1 -0
- package/dist/src/modules/base/base.dto.js +112 -0
- package/dist/src/modules/base/base.grants.d.ts +29 -0
- package/dist/src/modules/base/base.grants.d.ts.map +1 -0
- package/dist/src/modules/base/base.grants.js +123 -0
- package/dist/src/modules/base/base.grants.test.d.ts +2 -0
- package/dist/src/modules/base/base.grants.test.d.ts.map +1 -0
- package/dist/src/modules/base/base.grants.test.js +668 -0
- package/dist/src/modules/base/base.repository.d.ts +97 -0
- package/dist/src/modules/base/base.repository.d.ts.map +1 -0
- package/dist/src/modules/base/base.repository.js +307 -0
- package/dist/src/modules/base/base.service.d.ts +42 -0
- package/dist/src/modules/base/base.service.d.ts.map +1 -0
- package/dist/src/modules/base/base.service.js +109 -0
- package/dist/src/modules/base/base.types.d.ts +2 -0
- package/dist/src/modules/base/base.types.d.ts.map +1 -0
- package/dist/src/modules/base/base.types.js +2 -0
- package/dist/src/modules/billing/billing.db.d.ts +366 -0
- package/dist/src/modules/billing/billing.db.d.ts.map +1 -0
- package/dist/src/modules/billing/billing.db.js +29 -0
- package/dist/src/modules/billing/billing.repository.d.ts +2764 -0
- package/dist/src/modules/billing/billing.repository.d.ts.map +1 -0
- package/dist/src/modules/billing/billing.repository.js +235 -0
- package/dist/src/modules/billing/billing.router.d.ts +5 -0
- package/dist/src/modules/billing/billing.router.d.ts.map +1 -0
- package/dist/src/modules/billing/billing.router.js +56 -0
- package/dist/src/modules/billing/billing.service.d.ts +60 -0
- package/dist/src/modules/billing/billing.service.d.ts.map +1 -0
- package/dist/src/modules/billing/billing.service.js +147 -0
- package/dist/src/modules/billing/billing.trpc.d.ts +75 -0
- package/dist/src/modules/billing/billing.trpc.d.ts.map +1 -0
- package/dist/src/modules/billing/billing.trpc.js +17 -0
- package/dist/src/modules/clay/clay.repository.d.ts +6 -0
- package/dist/src/modules/clay/clay.repository.d.ts.map +1 -0
- package/dist/src/modules/clay/clay.repository.js +26 -0
- package/dist/src/modules/clay/clay.service.d.ts +29 -0
- package/dist/src/modules/clay/clay.service.d.ts.map +1 -0
- package/dist/src/modules/clay/clay.service.js +24 -0
- package/dist/src/modules/connect/connect.db.d.ts +357 -0
- package/dist/src/modules/connect/connect.db.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.db.js +30 -0
- package/dist/src/modules/connect/connect.dto.d.ts +75 -0
- package/dist/src/modules/connect/connect.dto.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.dto.js +36 -0
- package/dist/src/modules/connect/connect.linkedin.d.ts +3 -0
- package/dist/src/modules/connect/connect.linkedin.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.linkedin.js +53 -0
- package/dist/src/modules/connect/connect.oauth.d.ts +28 -0
- package/dist/src/modules/connect/connect.oauth.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.oauth.js +198 -0
- package/dist/src/modules/connect/connect.repository.d.ts +414 -0
- package/dist/src/modules/connect/connect.repository.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.repository.js +54 -0
- package/dist/src/modules/connect/connect.router.d.ts +5 -0
- package/dist/src/modules/connect/connect.router.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.router.js +54 -0
- package/dist/src/modules/connect/connect.service.d.ts +89 -0
- package/dist/src/modules/connect/connect.service.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.service.js +114 -0
- package/dist/src/modules/connect/connect.trpc.d.ts +81 -0
- package/dist/src/modules/connect/connect.trpc.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.trpc.js +21 -0
- package/dist/src/modules/connect/connect.types.d.ts +26 -0
- package/dist/src/modules/connect/connect.types.d.ts.map +1 -0
- package/dist/src/modules/connect/connect.types.js +2 -0
- package/dist/src/modules/crypto/crypto.db.d.ts +152 -0
- package/dist/src/modules/crypto/crypto.db.d.ts.map +1 -0
- package/dist/src/modules/crypto/crypto.db.js +17 -0
- package/dist/src/modules/crypto/crypto.repository.d.ts +160 -0
- package/dist/src/modules/crypto/crypto.repository.d.ts.map +1 -0
- package/dist/src/modules/crypto/crypto.repository.js +10 -0
- package/dist/src/modules/crypto/crypto.service.d.ts +11 -0
- package/dist/src/modules/crypto/crypto.service.d.ts.map +1 -0
- package/dist/src/modules/crypto/crypto.service.js +52 -0
- package/dist/src/modules/email/email.service.d.ts +57 -0
- package/dist/src/modules/email/email.service.d.ts.map +1 -0
- package/dist/src/modules/email/email.service.js +107 -0
- package/dist/src/modules/file/file.repository.d.ts +13 -0
- package/dist/src/modules/file/file.repository.d.ts.map +1 -0
- package/dist/src/modules/file/file.repository.js +79 -0
- package/dist/src/modules/file/file.router.d.ts +4 -0
- package/dist/src/modules/file/file.router.d.ts.map +1 -0
- package/dist/src/modules/file/file.router.js +99 -0
- package/dist/src/modules/file/file.service.d.ts +25 -0
- package/dist/src/modules/file/file.service.d.ts.map +1 -0
- package/dist/src/modules/file/file.service.js +150 -0
- package/dist/src/modules/recurrence/recurrence.db.d.ts +563 -0
- package/dist/src/modules/recurrence/recurrence.db.d.ts.map +1 -0
- package/dist/src/modules/recurrence/recurrence.db.js +66 -0
- package/dist/src/modules/recurrence/recurrence.repository.d.ts +585 -0
- package/dist/src/modules/recurrence/recurrence.repository.d.ts.map +1 -0
- package/dist/src/modules/recurrence/recurrence.repository.js +39 -0
- package/dist/src/modules/recurrence/recurrence.service.d.ts +30 -0
- package/dist/src/modules/recurrence/recurrence.service.d.ts.map +1 -0
- package/dist/src/modules/recurrence/recurrence.service.js +70 -0
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts +243 -0
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts.map +1 -0
- package/dist/src/modules/recurrence/recurrence.trpc.js +65 -0
- package/dist/src/modules/social/social.dto.d.ts +35 -0
- package/dist/src/modules/social/social.dto.d.ts.map +1 -0
- package/dist/src/modules/social/social.dto.js +18 -0
- package/dist/src/modules/social/social.linkedin.d.ts +11 -0
- package/dist/src/modules/social/social.linkedin.d.ts.map +1 -0
- package/dist/src/modules/social/social.linkedin.js +427 -0
- package/dist/src/modules/social/social.linkedin.test.d.ts +2 -0
- package/dist/src/modules/social/social.linkedin.test.d.ts.map +1 -0
- package/dist/src/modules/social/social.linkedin.test.js +235 -0
- package/dist/src/modules/social/social.service.d.ts +29 -0
- package/dist/src/modules/social/social.service.d.ts.map +1 -0
- package/dist/src/modules/social/social.service.js +76 -0
- package/dist/src/modules/social/social.types.d.ts +36 -0
- package/dist/src/modules/social/social.types.d.ts.map +1 -0
- package/dist/src/modules/social/social.types.js +2 -0
- package/dist/src/modules/tag/tag.db.d.ts +347 -0
- package/dist/src/modules/tag/tag.db.d.ts.map +1 -0
- package/dist/src/modules/tag/tag.db.js +42 -0
- package/dist/src/modules/tag/tag.dto.d.ts +1019 -0
- package/dist/src/modules/tag/tag.dto.d.ts.map +1 -0
- package/dist/src/modules/tag/tag.dto.js +9 -0
- package/dist/src/modules/tag/tag.repository.d.ts +384 -0
- package/dist/src/modules/tag/tag.repository.d.ts.map +1 -0
- package/dist/src/modules/tag/tag.repository.js +154 -0
- package/dist/src/modules/tag/tag.service.d.ts +36 -0
- package/dist/src/modules/tag/tag.service.d.ts.map +1 -0
- package/dist/src/modules/tag/tag.service.js +31 -0
- package/dist/src/modules/tag/tag.trpc.d.ts +191 -0
- package/dist/src/modules/tag/tag.trpc.d.ts.map +1 -0
- package/dist/src/modules/tag/tag.trpc.js +47 -0
- package/dist/src/modules/utils/applyPagination.d.ts +7 -0
- package/dist/src/modules/utils/applyPagination.d.ts.map +1 -0
- package/dist/src/modules/utils/applyPagination.js +16 -0
- package/dist/src/modules/utils/applySorting.d.ts +9 -0
- package/dist/src/modules/utils/applySorting.d.ts.map +1 -0
- package/dist/src/modules/utils/applySorting.js +18 -0
- package/dist/src/modules/utils/getConditionsFromFilters.d.ts +5 -0
- package/dist/src/modules/utils/getConditionsFromFilters.d.ts.map +1 -0
- package/dist/src/modules/utils/getConditionsFromFilters.js +200 -0
- package/dist/src/modules/video/video.service.d.ts +8 -0
- package/dist/src/modules/video/video.service.d.ts.map +1 -0
- package/dist/src/modules/video/video.service.js +84 -0
- package/dist/src/modules/webhook/webhook.constants.d.ts +9 -0
- package/dist/src/modules/webhook/webhook.constants.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.constants.js +10 -0
- package/dist/src/modules/webhook/webhook.db.d.ts +137 -0
- package/dist/src/modules/webhook/webhook.db.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.db.js +17 -0
- package/dist/src/modules/webhook/webhook.dto.d.ts +395 -0
- package/dist/src/modules/webhook/webhook.dto.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.dto.js +7 -0
- package/dist/src/modules/webhook/webhook.repository.d.ts +149 -0
- package/dist/src/modules/webhook/webhook.repository.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.repository.js +56 -0
- package/dist/src/modules/webhook/webhook.router.d.ts +4 -0
- package/dist/src/modules/webhook/webhook.router.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.router.js +30 -0
- package/dist/src/modules/webhook/webhook.service.d.ts +10 -0
- package/dist/src/modules/webhook/webhook.service.d.ts.map +1 -0
- package/dist/src/modules/webhook/webhook.service.js +68 -0
- package/dist/src/modules/workflow/workflow.db.d.ts +297 -0
- package/dist/src/modules/workflow/workflow.db.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.db.js +30 -0
- package/dist/src/modules/workflow/workflow.repository.d.ts +344 -0
- package/dist/src/modules/workflow/workflow.repository.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.repository.js +105 -0
- package/dist/src/modules/workflow/workflow.service.d.ts +22 -0
- package/dist/src/modules/workflow/workflow.service.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.service.js +37 -0
- package/dist/src/modules/workflow/workflow.trpc.d.ts +93 -0
- package/dist/src/modules/workflow/workflow.trpc.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.trpc.js +21 -0
- package/dist/src/modules/workflow/workflow.types.d.ts +21 -0
- package/dist/src/modules/workflow/workflow.types.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.types.js +2 -0
- package/dist/src/modules/workflow/workflow.utils.d.ts +22 -0
- package/dist/src/modules/workflow/workflow.utils.d.ts.map +1 -0
- package/dist/src/modules/workflow/workflow.utils.js +173 -0
- package/dist/src/test/stubs/utils.d.ts +3 -0
- package/dist/src/test/stubs/utils.d.ts.map +1 -0
- package/dist/src/test/stubs/utils.js +5 -0
- package/dist/src/trpc/context.d.ts +42 -0
- package/dist/src/trpc/context.d.ts.map +1 -0
- package/dist/src/trpc/context.js +17 -0
- package/dist/src/trpc/index.d.ts +4 -0
- package/dist/src/trpc/index.d.ts.map +1 -0
- package/dist/src/trpc/index.js +6 -0
- package/dist/src/trpc/procedures.d.ts +234 -0
- package/dist/src/trpc/procedures.d.ts.map +1 -0
- package/dist/src/trpc/procedures.js +32 -0
- package/dist/src/trpc/utils.d.ts +5 -0
- package/dist/src/trpc/utils.d.ts.map +1 -0
- package/dist/src/trpc/utils.js +20 -0
- package/dist/src/types.d.ts +486 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +13 -0
- package/dist/src/utils/errors.d.ts +50 -0
- package/dist/src/utils/errors.d.ts.map +1 -0
- package/dist/src/utils/errors.js +104 -0
- package/dist/src/utils/logger.d.ts +2 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +11 -0
- package/dist/src/utils/posthog.d.ts +14 -0
- package/dist/src/utils/posthog.d.ts.map +1 -0
- package/dist/src/utils/posthog.js +31 -0
- package/dist/src/utils/types.d.ts +5 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/utils/types.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.ts +19 -0
- package/package.json +3 -6
- package/tsconfig.json +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.repository.d.ts","sourceRoot":"","sources":["../../../../src/modules/billing/billing.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAChF,OAAO,EAAiB,KAAK,gBAAgB,EAAW,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIpE,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAI,CAAC;IAkBnF,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IASrE,qBAAqB,CAAC,EACpB,UAAU,EACV,OAAO,EACP,MAAM,GACP,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IAmB9C,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC;IAUzF,cAAc,CAAC,EACnB,UAAU,EACV,MAAM,GACP,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,iBAAiB,CAAC,OAAO,CAAC;IA6E9B,cAAc,CACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC;CAM9B"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BillingRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
6
|
+
const neverthrow_1 = require("neverthrow");
|
|
7
|
+
const auth = tslib_1.__importStar(require("#modules/auth/auth.db"));
|
|
8
|
+
const base_repository_1 = require("#modules/base/base.repository");
|
|
9
|
+
const billing = tslib_1.__importStar(require("#modules/billing/billing.db"));
|
|
10
|
+
const posthog_1 = require("#utils/posthog");
|
|
11
|
+
const schema = { ...auth, ...billing };
|
|
12
|
+
class BillingRepository extends base_repository_1.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
|
+
const customers = await this.stripe.customers.list({
|
|
32
|
+
email,
|
|
33
|
+
limit: 1,
|
|
34
|
+
});
|
|
35
|
+
return (0, neverthrow_1.ok)(customers.data[0] ?? null);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getUserByCustomerId(customerId) {
|
|
39
|
+
return this.throwableAsync(async () => {
|
|
40
|
+
const [user] = await this.orm
|
|
41
|
+
.select()
|
|
42
|
+
.from(this.schema.users)
|
|
43
|
+
.where((0, drizzle_orm_1.eq)(this.schema.users.stripeCustomerId, customerId))
|
|
44
|
+
.limit(1);
|
|
45
|
+
return (0, neverthrow_1.ok)(user ?? null);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
createCustomer({ email, name, userId, }) {
|
|
49
|
+
return this.throwableAsync(async () => {
|
|
50
|
+
const customer = await this.stripe.customers.create({
|
|
51
|
+
email,
|
|
52
|
+
name,
|
|
53
|
+
metadata: {
|
|
54
|
+
userId,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return (0, neverthrow_1.ok)(customer);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async createTrialSubscription(customerId) {
|
|
61
|
+
if (!this.trial)
|
|
62
|
+
return this.error("NOT_FOUND", "Trial plan not found");
|
|
63
|
+
const stripeSubscription = await this.createSubscription({
|
|
64
|
+
customerId,
|
|
65
|
+
priceId: this.trial.priceId,
|
|
66
|
+
trialDays: this.trial.freeTrial?.days ?? 7,
|
|
67
|
+
});
|
|
68
|
+
if (stripeSubscription.isErr())
|
|
69
|
+
return (0, neverthrow_1.err)(stripeSubscription.error);
|
|
70
|
+
if (!stripeSubscription.value)
|
|
71
|
+
return this.error("INTERNAL_SERVER_ERROR", "Failed to create trial subscription");
|
|
72
|
+
return (0, neverthrow_1.ok)(stripeSubscription.value);
|
|
73
|
+
}
|
|
74
|
+
createSubscription({ customerId, priceId, quantity = 1, trialDays, }) {
|
|
75
|
+
return this.throwableAsync(async () => {
|
|
76
|
+
const stripeSubscription = await this.stripe.subscriptions.create({
|
|
77
|
+
customer: customerId,
|
|
78
|
+
items: [{ price: priceId, quantity }], // quantity = seats if you want
|
|
79
|
+
...(trialDays
|
|
80
|
+
? {
|
|
81
|
+
trial_period_days: trialDays,
|
|
82
|
+
trial_settings: {
|
|
83
|
+
end_behavior: {
|
|
84
|
+
missing_payment_method: "cancel",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
: {}),
|
|
89
|
+
});
|
|
90
|
+
return (0, neverthrow_1.ok)(stripeSubscription);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
updateUserCustomerId({ userId, customerId, }) {
|
|
94
|
+
return this.throwableAsync(async () => {
|
|
95
|
+
const [user] = await this.orm
|
|
96
|
+
.update(this.schema.users)
|
|
97
|
+
.set({ stripeCustomerId: customerId })
|
|
98
|
+
.where((0, drizzle_orm_1.eq)(this.schema.users.id, userId))
|
|
99
|
+
.returning();
|
|
100
|
+
if (!user)
|
|
101
|
+
return this.error("NOT_FOUND", "User not found");
|
|
102
|
+
return (0, neverthrow_1.ok)(user);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
getLatestSubscription(referenceId) {
|
|
106
|
+
return this.throwableAsync(async () => {
|
|
107
|
+
const subscriptions = await this.orm
|
|
108
|
+
.select()
|
|
109
|
+
.from(this.schema.subscriptions)
|
|
110
|
+
.where((0, drizzle_orm_1.eq)(this.schema.subscriptions.referenceId, referenceId))
|
|
111
|
+
.orderBy((0, drizzle_orm_1.desc)(this.schema.subscriptions.createdAt))
|
|
112
|
+
.limit(1);
|
|
113
|
+
return (0, neverthrow_1.ok)(subscriptions[0] ?? null);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getActiveSubscription(referenceId) {
|
|
117
|
+
return this.throwableAsync(async () => {
|
|
118
|
+
const [subscription] = await this.orm
|
|
119
|
+
.select()
|
|
120
|
+
.from(this.schema.subscriptions)
|
|
121
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.subscriptions.referenceId, referenceId), (0, drizzle_orm_1.inArray)(this.schema.subscriptions.status, ["active", "trialing"])))
|
|
122
|
+
.orderBy((0, drizzle_orm_1.desc)(this.schema.subscriptions.createdAt))
|
|
123
|
+
.limit(1);
|
|
124
|
+
return (0, neverthrow_1.ok)(subscription ?? null);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
listInvoices(customerId) {
|
|
128
|
+
return this.throwableAsync(async () => {
|
|
129
|
+
const invoices = await this.stripe.invoices.list({
|
|
130
|
+
customer: customerId,
|
|
131
|
+
});
|
|
132
|
+
return (0, neverthrow_1.ok)(invoices.data);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
createCheckoutSession({ customerId, priceId, userId, }) {
|
|
136
|
+
return this.throwableAsync(async () => {
|
|
137
|
+
const session = await this.stripe.checkout.sessions.create({
|
|
138
|
+
client_reference_id: userId,
|
|
139
|
+
customer: customerId,
|
|
140
|
+
success_url: `${process.env.VITE_SERVER_URL}/stripe/success`,
|
|
141
|
+
cancel_url: `${process.env.VITE_APP_URL}/billing`,
|
|
142
|
+
mode: "subscription",
|
|
143
|
+
line_items: [
|
|
144
|
+
{
|
|
145
|
+
price: priceId,
|
|
146
|
+
quantity: 1,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
return (0, neverthrow_1.ok)(session);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
createBillingPortalSession(customerId) {
|
|
154
|
+
return this.throwableAsync(async () => {
|
|
155
|
+
const session = await this.stripe.billingPortal.sessions.create({
|
|
156
|
+
customer: customerId,
|
|
157
|
+
return_url: `${process.env.VITE_SERVER_URL}/stripe/success`,
|
|
158
|
+
});
|
|
159
|
+
return (0, neverthrow_1.ok)(session);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async syncStripeData({ customerId, userId, }) {
|
|
163
|
+
return this.throwableAsync(async () => {
|
|
164
|
+
// Fetch latest subscription data from Stripe
|
|
165
|
+
const stripeSubscriptions = await this.stripe.subscriptions.list({
|
|
166
|
+
customer: customerId,
|
|
167
|
+
limit: 1,
|
|
168
|
+
status: "all",
|
|
169
|
+
expand: ["data.default_payment_method"],
|
|
170
|
+
});
|
|
171
|
+
const [stripeSubscription] = stripeSubscriptions.data;
|
|
172
|
+
if (!stripeSubscription)
|
|
173
|
+
return this.error("NOT_FOUND", "Subscription not found");
|
|
174
|
+
const plan = this.getPlanByPriceId(stripeSubscription.items.data[0]?.price.id);
|
|
175
|
+
if (!plan)
|
|
176
|
+
return this.error("NOT_FOUND", `Plan not found for price ID: ${stripeSubscription.items.data[0]?.price.id}`);
|
|
177
|
+
const values = {
|
|
178
|
+
stripeCustomerId: customerId,
|
|
179
|
+
referenceId: userId,
|
|
180
|
+
plan: plan.name,
|
|
181
|
+
status: stripeSubscription.status,
|
|
182
|
+
seats: stripeSubscription.items.data[0]?.quantity || 1,
|
|
183
|
+
periodEnd: new Date(stripeSubscription.items.data[0]?.current_period_end * 1000),
|
|
184
|
+
periodStart: new Date(stripeSubscription.items.data[0]?.current_period_start * 1000),
|
|
185
|
+
priceId: stripeSubscription.items.data[0]?.price.id,
|
|
186
|
+
interval: stripeSubscription.items.data[0]?.price.recurring?.interval,
|
|
187
|
+
unitAmount: stripeSubscription.items.data[0]?.price.unit_amount,
|
|
188
|
+
discounts: stripeSubscription.discounts.map((discount) => typeof discount === "string" ? discount : discount.id),
|
|
189
|
+
stripeSubscriptionId: stripeSubscription.id,
|
|
190
|
+
cancelAtPeriodEnd: stripeSubscription.cancel_at_period_end,
|
|
191
|
+
cancelAt: stripeSubscription.cancel_at
|
|
192
|
+
? new Date(stripeSubscription.cancel_at * 1000)
|
|
193
|
+
: null,
|
|
194
|
+
canceledAt: stripeSubscription.canceled_at
|
|
195
|
+
? new Date(stripeSubscription.canceled_at * 1000)
|
|
196
|
+
: null,
|
|
197
|
+
...(stripeSubscription.trial_start && stripeSubscription.trial_end
|
|
198
|
+
? {
|
|
199
|
+
trialStart: new Date(stripeSubscription.trial_start * 1000),
|
|
200
|
+
trialEnd: new Date(stripeSubscription.trial_end * 1000),
|
|
201
|
+
}
|
|
202
|
+
: {}),
|
|
203
|
+
};
|
|
204
|
+
const existingSubscription = await this.getActiveSubscription(userId);
|
|
205
|
+
if (existingSubscription.isErr())
|
|
206
|
+
return (0, neverthrow_1.err)(existingSubscription.error);
|
|
207
|
+
if (!existingSubscription.value) {
|
|
208
|
+
await this.orm.insert(this.schema.subscriptions).values(values);
|
|
209
|
+
(0, posthog_1.posthogCapture)({
|
|
210
|
+
distinctId: userId,
|
|
211
|
+
event: "stripe.subscription_created",
|
|
212
|
+
properties: values,
|
|
213
|
+
});
|
|
214
|
+
return (0, neverthrow_1.ok)(true);
|
|
215
|
+
}
|
|
216
|
+
await this.orm
|
|
217
|
+
.update(this.schema.subscriptions)
|
|
218
|
+
.set({ ...values, updatedAt: new Date() })
|
|
219
|
+
.where((0, drizzle_orm_1.eq)(this.schema.subscriptions.id, existingSubscription.value.id));
|
|
220
|
+
(0, posthog_1.posthogCapture)({
|
|
221
|
+
distinctId: userId,
|
|
222
|
+
event: "stripe.subscription_updated",
|
|
223
|
+
properties: values,
|
|
224
|
+
});
|
|
225
|
+
return (0, neverthrow_1.ok)(false);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
constructEvent(body, signature, secret) {
|
|
229
|
+
return this.throwable(() => {
|
|
230
|
+
const event = this.stripe.webhooks.constructEvent(body, signature, secret);
|
|
231
|
+
return (0, neverthrow_1.ok)(event);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.BillingRepository = BillingRepository;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import type { AuthMiddleware } from "#modules/auth/auth.middleware";
|
|
3
|
+
import type { BillingService } from "#modules/billing/billing.service";
|
|
4
|
+
export declare function createBillingRouter(authMiddleware: AuthMiddleware, service: BillingService): Router;
|
|
5
|
+
//# sourceMappingURL=billing.router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.router.d.ts","sourceRoot":"","sources":["../../../../src/modules/billing/billing.router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,cAAc,GACtB,MAAM,CAoER"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBillingRouter = createBillingRouter;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const body_parser_1 = tslib_1.__importDefault(require("body-parser"));
|
|
6
|
+
const express_1 = require("express");
|
|
7
|
+
function createBillingRouter(authMiddleware, service) {
|
|
8
|
+
const billingRouter = (0, express_1.Router)();
|
|
9
|
+
billingRouter.get("/checkout/:priceId", authMiddleware, async (req, res) => {
|
|
10
|
+
const user = req.user;
|
|
11
|
+
const session = await service.createCheckoutSession({ priceId: req.params.priceId }, { user });
|
|
12
|
+
if (session.isErr()) {
|
|
13
|
+
return res.status(500).json({ message: session.error.message });
|
|
14
|
+
}
|
|
15
|
+
if (!session.value.url) {
|
|
16
|
+
return res.status(500).json({ message: "Failed to create checkout session" });
|
|
17
|
+
}
|
|
18
|
+
return res.redirect(session.value.url);
|
|
19
|
+
});
|
|
20
|
+
billingRouter.get("/portal", authMiddleware, async (req, res) => {
|
|
21
|
+
const user = req.user;
|
|
22
|
+
const session = await service.createBillingPortalSession({ user });
|
|
23
|
+
if (session.isErr()) {
|
|
24
|
+
return res.status(500).json({ message: session.error.message });
|
|
25
|
+
}
|
|
26
|
+
return res.redirect(session.value.url);
|
|
27
|
+
});
|
|
28
|
+
billingRouter.get("/success", authMiddleware, async (req, res) => {
|
|
29
|
+
const user = req.user;
|
|
30
|
+
if (!user.stripeCustomerId) {
|
|
31
|
+
return res.redirect(`${process.env.VITE_APP_URL}/billing`);
|
|
32
|
+
}
|
|
33
|
+
const result = await service.syncStripeData(user.stripeCustomerId);
|
|
34
|
+
if (result.isErr()) {
|
|
35
|
+
return res.redirect(`${process.env.VITE_APP_URL}/billing?error=SYNC_FAILED`);
|
|
36
|
+
}
|
|
37
|
+
return res.redirect(`${process.env.VITE_APP_URL}/billing`);
|
|
38
|
+
});
|
|
39
|
+
billingRouter.post("/webhook", body_parser_1.default.raw({ type: "application/json" }), async (req, res) => {
|
|
40
|
+
const signature = req.headers["stripe-signature"];
|
|
41
|
+
if (!signature)
|
|
42
|
+
return res.status(400).json({ message: "No signature" });
|
|
43
|
+
if (typeof signature !== "string")
|
|
44
|
+
return res.status(500).json({ message: "Signature is not a string" });
|
|
45
|
+
const event = service.constructEvent(req.body, signature);
|
|
46
|
+
if (event.isErr()) {
|
|
47
|
+
return res.status(500).json({ message: event.error.message });
|
|
48
|
+
}
|
|
49
|
+
const result = await service.processEvent(event.value);
|
|
50
|
+
if (result.isErr()) {
|
|
51
|
+
return res.status(500).json({ message: result.error.message });
|
|
52
|
+
}
|
|
53
|
+
return res.status(200).json({ received: true });
|
|
54
|
+
});
|
|
55
|
+
return billingRouter;
|
|
56
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import type { User } from "#modules/auth/auth.lib";
|
|
3
|
+
import type { ServerResult, ServerResultAsync } from "#modules/base/base.dto";
|
|
4
|
+
import { BaseService } from "#modules/base/base.service";
|
|
5
|
+
import type { BillingRepository } from "#modules/billing/billing.repository";
|
|
6
|
+
export declare class BillingService extends BaseService<{
|
|
7
|
+
billing: BillingRepository;
|
|
8
|
+
}, never> {
|
|
9
|
+
createUserCustomer({ user, }: {
|
|
10
|
+
user: {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
}): ServerResultAsync<Stripe.Customer>;
|
|
16
|
+
createUserHook({ user, }: {
|
|
17
|
+
user: {
|
|
18
|
+
id: string;
|
|
19
|
+
email: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
};
|
|
22
|
+
}): ServerResultAsync<boolean>;
|
|
23
|
+
getActiveSubscription({ user }: {
|
|
24
|
+
user: User;
|
|
25
|
+
}): Promise<ServerResult<{
|
|
26
|
+
id: string;
|
|
27
|
+
plan: string;
|
|
28
|
+
referenceId: string;
|
|
29
|
+
status: string;
|
|
30
|
+
stripeCustomerId?: string | null | undefined;
|
|
31
|
+
stripeSubscriptionId?: string | null | undefined;
|
|
32
|
+
periodStart?: Date | null | undefined;
|
|
33
|
+
periodEnd?: Date | null | undefined;
|
|
34
|
+
cancelAtPeriodEnd?: boolean | null | undefined;
|
|
35
|
+
cancelAt?: Date | null | undefined;
|
|
36
|
+
canceledAt?: Date | null | undefined;
|
|
37
|
+
seats?: number | null | undefined;
|
|
38
|
+
trialStart?: Date | null | undefined;
|
|
39
|
+
trialEnd?: Date | null | undefined;
|
|
40
|
+
priceId?: string | null | undefined;
|
|
41
|
+
interval?: string | null | undefined;
|
|
42
|
+
unitAmount?: number | null | undefined;
|
|
43
|
+
discounts?: string[] | null | undefined;
|
|
44
|
+
} | null>>;
|
|
45
|
+
listInvoices({ user }: {
|
|
46
|
+
user: User;
|
|
47
|
+
}): ServerResultAsync<Stripe.Invoice[]>;
|
|
48
|
+
createCheckoutSession({ priceId }: {
|
|
49
|
+
priceId: string;
|
|
50
|
+
}, { user }: {
|
|
51
|
+
user: User;
|
|
52
|
+
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
53
|
+
createBillingPortalSession({ user, }: {
|
|
54
|
+
user: User;
|
|
55
|
+
}): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
56
|
+
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe.Event>;
|
|
57
|
+
syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean>;
|
|
58
|
+
processEvent(event: Stripe.Event): ServerResultAsync<boolean>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=billing.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/billing/billing.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAyB7E,qBAAa,cAAe,SAAQ,WAAW,CAAC;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,EAAE,KAAK,CAAC;IAC9E,kBAAkB,CAAC,EACvB,IAAI,GACL,EAAE;QACD,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC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+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BillingService = void 0;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const base_service_1 = require("#modules/base/base.service");
|
|
6
|
+
const posthog_1 = require("#utils/posthog");
|
|
7
|
+
const allowedEvents = [
|
|
8
|
+
"checkout.session.completed",
|
|
9
|
+
"customer.subscription.created",
|
|
10
|
+
"customer.subscription.updated",
|
|
11
|
+
"customer.subscription.deleted",
|
|
12
|
+
"customer.subscription.paused",
|
|
13
|
+
"customer.subscription.resumed",
|
|
14
|
+
"customer.subscription.pending_update_applied",
|
|
15
|
+
"customer.subscription.pending_update_expired",
|
|
16
|
+
"customer.subscription.trial_will_end",
|
|
17
|
+
"invoice.paid",
|
|
18
|
+
"invoice.payment_failed",
|
|
19
|
+
"invoice.payment_action_required",
|
|
20
|
+
"invoice.upcoming",
|
|
21
|
+
"invoice.marked_uncollectible",
|
|
22
|
+
"invoice.payment_succeeded",
|
|
23
|
+
"payment_intent.succeeded",
|
|
24
|
+
"payment_intent.payment_failed",
|
|
25
|
+
"payment_intent.canceled",
|
|
26
|
+
];
|
|
27
|
+
class BillingService extends base_service_1.BaseService {
|
|
28
|
+
async createUserCustomer({ user, }) {
|
|
29
|
+
let stripeCustomer = null;
|
|
30
|
+
const existingCustomer = await this.repository.billing.getCustomerByEmail(user.email);
|
|
31
|
+
if (existingCustomer.isErr())
|
|
32
|
+
return (0, neverthrow_1.err)(existingCustomer.error);
|
|
33
|
+
stripeCustomer = existingCustomer.value;
|
|
34
|
+
if (!stripeCustomer) {
|
|
35
|
+
const newCustomer = await this.repository.billing.createCustomer({
|
|
36
|
+
email: user.email,
|
|
37
|
+
name: user.name,
|
|
38
|
+
userId: user.id,
|
|
39
|
+
});
|
|
40
|
+
if (newCustomer.isErr())
|
|
41
|
+
return (0, neverthrow_1.err)(newCustomer.error);
|
|
42
|
+
stripeCustomer = newCustomer.value;
|
|
43
|
+
}
|
|
44
|
+
if (!stripeCustomer)
|
|
45
|
+
return this.error("INTERNAL_SERVER_ERROR", "Failed to create or get stripe customer");
|
|
46
|
+
const updatedUser = await this.repository.billing.updateUserCustomerId({
|
|
47
|
+
userId: user.id,
|
|
48
|
+
customerId: stripeCustomer.id,
|
|
49
|
+
});
|
|
50
|
+
if (updatedUser.isErr())
|
|
51
|
+
return (0, neverthrow_1.err)(updatedUser.error);
|
|
52
|
+
return (0, neverthrow_1.ok)(stripeCustomer);
|
|
53
|
+
}
|
|
54
|
+
async createUserHook({ user, }) {
|
|
55
|
+
const stripeCustomer = await this.createUserCustomer({ user });
|
|
56
|
+
if (stripeCustomer.isErr())
|
|
57
|
+
return (0, neverthrow_1.err)(stripeCustomer.error);
|
|
58
|
+
if (this.repository.billing.hasTrial()) {
|
|
59
|
+
const existingSubscription = await this.repository.billing.getLatestSubscription(user.id);
|
|
60
|
+
if (existingSubscription.isErr())
|
|
61
|
+
return (0, neverthrow_1.err)(existingSubscription.error);
|
|
62
|
+
if (!existingSubscription.value) {
|
|
63
|
+
const subscription = await this.repository.billing.createTrialSubscription(stripeCustomer.value.id);
|
|
64
|
+
if (subscription.isErr())
|
|
65
|
+
return (0, neverthrow_1.err)(subscription.error);
|
|
66
|
+
}
|
|
67
|
+
const syncResult = await this.syncStripeData(stripeCustomer.value.id);
|
|
68
|
+
if (syncResult.isErr())
|
|
69
|
+
return (0, neverthrow_1.err)(syncResult.error);
|
|
70
|
+
if (syncResult.value === false)
|
|
71
|
+
return this.error("INTERNAL_SERVER_ERROR", "Sync did not create new subscription");
|
|
72
|
+
}
|
|
73
|
+
return (0, neverthrow_1.ok)(true);
|
|
74
|
+
}
|
|
75
|
+
async getActiveSubscription({ user }) {
|
|
76
|
+
return this.repository.billing.getActiveSubscription(user.id);
|
|
77
|
+
}
|
|
78
|
+
async listInvoices({ user }) {
|
|
79
|
+
if (!user.stripeCustomerId)
|
|
80
|
+
return this.error("NOT_FOUND", "User has no stripe customer id");
|
|
81
|
+
return this.repository.billing.listInvoices(user.stripeCustomerId);
|
|
82
|
+
}
|
|
83
|
+
async createCheckoutSession({ priceId }, { user }) {
|
|
84
|
+
let stripeCustomerId = user.stripeCustomerId;
|
|
85
|
+
if (!stripeCustomerId) {
|
|
86
|
+
const stripeCustomer = await this.createUserCustomer({ user });
|
|
87
|
+
if (stripeCustomer.isErr())
|
|
88
|
+
return (0, neverthrow_1.err)(stripeCustomer.error);
|
|
89
|
+
stripeCustomerId = stripeCustomer.value.id;
|
|
90
|
+
}
|
|
91
|
+
return this.repository.billing.createCheckoutSession({
|
|
92
|
+
customerId: stripeCustomerId,
|
|
93
|
+
priceId,
|
|
94
|
+
userId: user.id,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async createBillingPortalSession({ user, }) {
|
|
98
|
+
let stripeCustomerId = user.stripeCustomerId;
|
|
99
|
+
if (!stripeCustomerId) {
|
|
100
|
+
const stripeCustomer = await this.createUserCustomer({ user });
|
|
101
|
+
if (stripeCustomer.isErr())
|
|
102
|
+
return (0, neverthrow_1.err)(stripeCustomer.error);
|
|
103
|
+
stripeCustomerId = stripeCustomer.value.id;
|
|
104
|
+
}
|
|
105
|
+
return this.repository.billing.createBillingPortalSession(stripeCustomerId);
|
|
106
|
+
}
|
|
107
|
+
constructEvent(body, signature) {
|
|
108
|
+
if (!process.env.STRIPE_WEBHOOK_SECRET)
|
|
109
|
+
return this.error("INTERNAL_SERVER_ERROR", "Stripe webhook secret is not set");
|
|
110
|
+
return this.repository.billing.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET);
|
|
111
|
+
}
|
|
112
|
+
async syncStripeData(customerId, eventType) {
|
|
113
|
+
const user = await this.repository.billing.getUserByCustomerId(customerId);
|
|
114
|
+
if (user.isErr())
|
|
115
|
+
return (0, neverthrow_1.err)(user.error);
|
|
116
|
+
if (!user.value)
|
|
117
|
+
return this.error("NOT_FOUND", "User not found");
|
|
118
|
+
if (eventType) {
|
|
119
|
+
(0, posthog_1.posthogCapture)({
|
|
120
|
+
distinctId: user.value.id,
|
|
121
|
+
event: `stripe.${eventType}`,
|
|
122
|
+
properties: {
|
|
123
|
+
customerId,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return this.repository.billing.syncStripeData({ customerId, userId: user.value.id });
|
|
128
|
+
}
|
|
129
|
+
async processEvent(event) {
|
|
130
|
+
return this.throwableAsync(async () => {
|
|
131
|
+
// Skip processing if the event isn't one I'm tracking (list of all events below)
|
|
132
|
+
if (!allowedEvents.includes(event.type))
|
|
133
|
+
return (0, neverthrow_1.ok)(false);
|
|
134
|
+
// All the events I track have a customerId
|
|
135
|
+
const { customer: customerId } = event?.data?.object;
|
|
136
|
+
// This helps make it typesafe and also lets me know if my assumption is wrong
|
|
137
|
+
if (typeof customerId !== "string") {
|
|
138
|
+
return this.error("INTERNAL_SERVER_ERROR", `[STRIPE HOOK] Unexpected event structure: customer ID is not a string. Event type: ${event.type}`);
|
|
139
|
+
}
|
|
140
|
+
const result = await this.syncStripeData(customerId, event.type);
|
|
141
|
+
if (result.isErr())
|
|
142
|
+
return (0, neverthrow_1.err)(result.error);
|
|
143
|
+
return (0, neverthrow_1.ok)(true);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.BillingService = BillingService;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { BillingService } from "#modules/billing/billing.service";
|
|
2
|
+
export declare function createBillingTRPC(billingService: BillingService): import("@trpc/server").TRPCBuiltRouter<{
|
|
3
|
+
ctx: {
|
|
4
|
+
session: {
|
|
5
|
+
id: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
expiresAt: Date;
|
|
10
|
+
token: string;
|
|
11
|
+
ipAddress: string | null;
|
|
12
|
+
userAgent: string | null;
|
|
13
|
+
impersonatedBy: string | null;
|
|
14
|
+
activeOrganizationId: string | null;
|
|
15
|
+
activeOrganizationRole: string | null;
|
|
16
|
+
activeTeamId: string | null;
|
|
17
|
+
activeTeamRole: string | null;
|
|
18
|
+
};
|
|
19
|
+
user: {
|
|
20
|
+
name: string;
|
|
21
|
+
id: string;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
email: string;
|
|
24
|
+
emailVerified: boolean;
|
|
25
|
+
image: string | null;
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
role: string | null;
|
|
28
|
+
banned: boolean | null;
|
|
29
|
+
banReason: string | null;
|
|
30
|
+
banExpires: Date | null;
|
|
31
|
+
stripeCustomerId: string | null;
|
|
32
|
+
paymentCustomerId: string | null;
|
|
33
|
+
paymentPlanTier: string | null;
|
|
34
|
+
paymentPlanExpiresAt: Date | null;
|
|
35
|
+
preferences: string | null;
|
|
36
|
+
metadata: Record<string, unknown>;
|
|
37
|
+
onboarding: number | null;
|
|
38
|
+
flags: string | null;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
42
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
43
|
+
transformer: true;
|
|
44
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
45
|
+
getActiveSubscription: import("@trpc/server").TRPCQueryProcedure<{
|
|
46
|
+
input: void;
|
|
47
|
+
output: {
|
|
48
|
+
id: string;
|
|
49
|
+
plan: string;
|
|
50
|
+
referenceId: string;
|
|
51
|
+
status: string;
|
|
52
|
+
stripeCustomerId?: string | null | undefined;
|
|
53
|
+
stripeSubscriptionId?: string | null | undefined;
|
|
54
|
+
periodStart?: Date | null | undefined;
|
|
55
|
+
periodEnd?: Date | null | undefined;
|
|
56
|
+
cancelAtPeriodEnd?: boolean | null | undefined;
|
|
57
|
+
cancelAt?: Date | null | undefined;
|
|
58
|
+
canceledAt?: Date | null | undefined;
|
|
59
|
+
seats?: number | null | undefined;
|
|
60
|
+
trialStart?: Date | null | undefined;
|
|
61
|
+
trialEnd?: Date | null | undefined;
|
|
62
|
+
priceId?: string | null | undefined;
|
|
63
|
+
interval?: string | null | undefined;
|
|
64
|
+
unitAmount?: number | null | undefined;
|
|
65
|
+
discounts?: string[] | null | undefined;
|
|
66
|
+
} | null;
|
|
67
|
+
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
68
|
+
}>;
|
|
69
|
+
listInvoices: import("@trpc/server").TRPCQueryProcedure<{
|
|
70
|
+
input: void;
|
|
71
|
+
output: import("stripe").Stripe.Invoice[];
|
|
72
|
+
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
73
|
+
}>;
|
|
74
|
+
}>>;
|
|
75
|
+
//# sourceMappingURL=billing.trpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.trpc.d.ts","sourceRoot":"","sources":["../../../../src/modules/billing/billing.trpc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGvE,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAY/D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBillingTRPC = createBillingTRPC;
|
|
4
|
+
const billing_schema_1 = require("@m5kdev/commons/modules/billing/billing.schema");
|
|
5
|
+
const _trpc_1 = require("#trpc");
|
|
6
|
+
function createBillingTRPC(billingService) {
|
|
7
|
+
return (0, _trpc_1.router)({
|
|
8
|
+
getActiveSubscription: _trpc_1.procedure
|
|
9
|
+
.output(billing_schema_1.billingSchema.nullable())
|
|
10
|
+
.query(async ({ ctx: { user } }) => {
|
|
11
|
+
return (0, _trpc_1.handleTRPCResult)(await billingService.getActiveSubscription({ user }));
|
|
12
|
+
}),
|
|
13
|
+
listInvoices: _trpc_1.procedure.query(async ({ ctx: { user } }) => {
|
|
14
|
+
return (0, _trpc_1.handleTRPCResult)(await billingService.listInvoices({ user }));
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ServerResultAsync } from "#modules/base/base.dto";
|
|
2
|
+
import { BaseExternaRepository } from "#modules/base/base.repository";
|
|
3
|
+
export declare class ClayRepository extends BaseExternaRepository {
|
|
4
|
+
sendToWebhook(webhookUrl: string, row: Record<string, unknown>, callbackUrl: string): ServerResultAsync<void>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=clay.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clay.repository.d.ts","sourceRoot":"","sources":["../../../../src/modules/clay/clay.repository.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAItE,qBAAa,cAAe,SAAQ,qBAAqB;IACjD,aAAa,CACjB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,iBAAiB,CAAC,IAAI,CAAC;CAiB3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClayRepository = void 0;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const base_repository_1 = require("#modules/base/base.repository");
|
|
6
|
+
const { CLAY_WEBHOOK_AUTH_TOKEN } = process.env;
|
|
7
|
+
class ClayRepository extends base_repository_1.BaseExternaRepository {
|
|
8
|
+
async sendToWebhook(webhookUrl, row, callbackUrl) {
|
|
9
|
+
return this.throwableAsync(async () => {
|
|
10
|
+
const response = await fetch(webhookUrl, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
...(CLAY_WEBHOOK_AUTH_TOKEN ? { "x-clay-webhook-auth": CLAY_WEBHOOK_AUTH_TOKEN } : {}),
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({ ...row, callback: callbackUrl }),
|
|
17
|
+
});
|
|
18
|
+
if (!response.ok)
|
|
19
|
+
return this.error("BAD_REQUEST", `HTTP error! status: ${response.status}`, {
|
|
20
|
+
cause: response,
|
|
21
|
+
});
|
|
22
|
+
return (0, neverthrow_1.ok)();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ClayRepository = ClayRepository;
|