@windrun-huaiin/backend-core 10.0.1

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app/api/stripe/checkout/route.d.ts +19 -0
  3. package/dist/app/api/stripe/checkout/route.d.ts.map +1 -0
  4. package/dist/app/api/stripe/checkout/route.js +120 -0
  5. package/dist/app/api/stripe/checkout/route.mjs +118 -0
  6. package/dist/app/api/stripe/customer-portal/route.d.ts +11 -0
  7. package/dist/app/api/stripe/customer-portal/route.d.ts.map +1 -0
  8. package/dist/app/api/stripe/customer-portal/route.js +73 -0
  9. package/dist/app/api/stripe/customer-portal/route.mjs +71 -0
  10. package/dist/app/api/user/anonymous/init/route.d.ts +7 -0
  11. package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -0
  12. package/dist/app/api/user/anonymous/init/route.js +210 -0
  13. package/dist/app/api/user/anonymous/init/route.mjs +208 -0
  14. package/dist/app/api/webhook/clerk/user/route.d.ts +7 -0
  15. package/dist/app/api/webhook/clerk/user/route.d.ts.map +1 -0
  16. package/dist/app/api/webhook/clerk/user/route.js +202 -0
  17. package/dist/app/api/webhook/clerk/user/route.mjs +200 -0
  18. package/dist/app/api/webhook/stripe/route.d.ts +8 -0
  19. package/dist/app/api/webhook/stripe/route.d.ts.map +1 -0
  20. package/dist/app/api/webhook/stripe/route.js +70 -0
  21. package/dist/app/api/webhook/stripe/route.mjs +67 -0
  22. package/dist/index.d.ts +7 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +83 -0
  25. package/dist/index.mjs +18 -0
  26. package/dist/lib/auth-utils.d.ts +46 -0
  27. package/dist/lib/auth-utils.d.ts.map +1 -0
  28. package/dist/lib/auth-utils.js +107 -0
  29. package/dist/lib/auth-utils.mjs +102 -0
  30. package/dist/lib/credit-init.d.ts +8 -0
  31. package/dist/lib/credit-init.d.ts.map +1 -0
  32. package/dist/lib/credit-init.js +16 -0
  33. package/dist/lib/credit-init.mjs +10 -0
  34. package/dist/lib/index.d.ts +5 -0
  35. package/dist/lib/index.d.ts.map +1 -0
  36. package/dist/lib/index.js +31 -0
  37. package/dist/lib/index.mjs +4 -0
  38. package/dist/lib/money-price-config.d.ts +51 -0
  39. package/dist/lib/money-price-config.d.ts.map +1 -0
  40. package/dist/lib/money-price-config.js +156 -0
  41. package/dist/lib/money-price-config.mjs +151 -0
  42. package/dist/lib/stripe-config.d.ts +31 -0
  43. package/dist/lib/stripe-config.d.ts.map +1 -0
  44. package/dist/lib/stripe-config.js +278 -0
  45. package/dist/lib/stripe-config.mjs +268 -0
  46. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js +48 -0
  47. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs +45 -0
  48. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +54 -0
  49. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +51 -0
  50. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +44 -0
  51. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +35 -0
  52. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +31 -0
  53. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +18 -0
  54. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +587 -0
  55. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +527 -0
  56. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +447 -0
  57. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +399 -0
  58. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +245 -0
  59. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +232 -0
  60. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +68 -0
  61. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +62 -0
  62. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +39 -0
  63. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +37 -0
  64. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +80 -0
  65. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +75 -0
  66. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +101 -0
  67. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +86 -0
  68. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +102 -0
  69. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +76 -0
  70. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +56 -0
  71. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +52 -0
  72. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +1205 -0
  73. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +1157 -0
  74. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +407 -0
  75. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +374 -0
  76. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +9 -0
  77. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +7 -0
  78. package/dist/prisma/client.d.ts +2 -0
  79. package/dist/prisma/client.d.ts.map +1 -0
  80. package/dist/prisma/client.js +12 -0
  81. package/dist/prisma/client.mjs +1 -0
  82. package/dist/prisma/index.d.ts +4 -0
  83. package/dist/prisma/index.d.ts.map +1 -0
  84. package/dist/prisma/index.js +10 -0
  85. package/dist/prisma/index.mjs +2 -0
  86. package/dist/prisma/prisma-transaction-util.d.ts +3 -0
  87. package/dist/prisma/prisma-transaction-util.d.ts.map +1 -0
  88. package/dist/prisma/prisma-transaction-util.js +29 -0
  89. package/dist/prisma/prisma-transaction-util.mjs +27 -0
  90. package/dist/prisma/prisma.d.ts +4 -0
  91. package/dist/prisma/prisma.d.ts.map +1 -0
  92. package/dist/prisma/prisma.js +109 -0
  93. package/dist/prisma/prisma.mjs +106 -0
  94. package/dist/services/aggregate/billing.aggregate.service.d.ts +83 -0
  95. package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -0
  96. package/dist/services/aggregate/billing.aggregate.service.js +308 -0
  97. package/dist/services/aggregate/billing.aggregate.service.mjs +306 -0
  98. package/dist/services/aggregate/index.d.ts +3 -0
  99. package/dist/services/aggregate/index.d.ts.map +1 -0
  100. package/dist/services/aggregate/index.js +9 -0
  101. package/dist/services/aggregate/index.mjs +2 -0
  102. package/dist/services/aggregate/user.aggregate.service.d.ts +34 -0
  103. package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -0
  104. package/dist/services/aggregate/user.aggregate.service.js +136 -0
  105. package/dist/services/aggregate/user.aggregate.service.mjs +133 -0
  106. package/dist/services/context/index.d.ts +2 -0
  107. package/dist/services/context/index.d.ts.map +1 -0
  108. package/dist/services/context/index.js +13 -0
  109. package/dist/services/context/index.mjs +1 -0
  110. package/dist/services/context/user-context-service.d.ts +30 -0
  111. package/dist/services/context/user-context-service.d.ts.map +1 -0
  112. package/dist/services/context/user-context-service.js +170 -0
  113. package/dist/services/context/user-context-service.mjs +162 -0
  114. package/dist/services/database/apilog.service.d.ts +39 -0
  115. package/dist/services/database/apilog.service.d.ts.map +1 -0
  116. package/dist/services/database/apilog.service.js +174 -0
  117. package/dist/services/database/apilog.service.mjs +170 -0
  118. package/dist/services/database/constants.d.ts +73 -0
  119. package/dist/services/database/constants.d.ts.map +1 -0
  120. package/dist/services/database/constants.js +135 -0
  121. package/dist/services/database/constants.mjs +117 -0
  122. package/dist/services/database/credit.service.d.ts +107 -0
  123. package/dist/services/database/credit.service.d.ts.map +1 -0
  124. package/dist/services/database/credit.service.js +515 -0
  125. package/dist/services/database/credit.service.mjs +512 -0
  126. package/dist/services/database/creditAuditLog.service.d.ts +73 -0
  127. package/dist/services/database/creditAuditLog.service.d.ts.map +1 -0
  128. package/dist/services/database/creditAuditLog.service.js +305 -0
  129. package/dist/services/database/creditAuditLog.service.mjs +302 -0
  130. package/dist/services/database/index.d.ts +10 -0
  131. package/dist/services/database/index.d.ts.map +1 -0
  132. package/dist/services/database/index.js +38 -0
  133. package/dist/services/database/index.mjs +8 -0
  134. package/dist/services/database/prisma-model-type.d.ts +3 -0
  135. package/dist/services/database/prisma-model-type.d.ts.map +1 -0
  136. package/dist/services/database/subscription.service.d.ts +48 -0
  137. package/dist/services/database/subscription.service.d.ts.map +1 -0
  138. package/dist/services/database/subscription.service.js +267 -0
  139. package/dist/services/database/subscription.service.mjs +264 -0
  140. package/dist/services/database/transaction.service.d.ts +92 -0
  141. package/dist/services/database/transaction.service.d.ts.map +1 -0
  142. package/dist/services/database/transaction.service.js +326 -0
  143. package/dist/services/database/transaction.service.mjs +323 -0
  144. package/dist/services/database/user.service.d.ts +45 -0
  145. package/dist/services/database/user.service.d.ts.map +1 -0
  146. package/dist/services/database/user.service.js +180 -0
  147. package/dist/services/database/user.service.mjs +177 -0
  148. package/dist/services/database/userBackup.service.d.ts +45 -0
  149. package/dist/services/database/userBackup.service.d.ts.map +1 -0
  150. package/dist/services/database/userBackup.service.js +249 -0
  151. package/dist/services/database/userBackup.service.mjs +246 -0
  152. package/dist/services/stripe/index.d.ts +2 -0
  153. package/dist/services/stripe/index.d.ts.map +1 -0
  154. package/dist/services/stripe/index.js +7 -0
  155. package/dist/services/stripe/index.mjs +1 -0
  156. package/dist/services/stripe/webhook-handler.d.ts +6 -0
  157. package/dist/services/stripe/webhook-handler.d.ts.map +1 -0
  158. package/dist/services/stripe/webhook-handler.js +537 -0
  159. package/dist/services/stripe/webhook-handler.mjs +535 -0
  160. package/migrations/create.sql +176 -0
  161. package/migrations/db.init.sql +13 -0
  162. package/migrations/init-schema.sql +19 -0
  163. package/migrations/purge.sql +27 -0
  164. package/migrations/test-check.sql +167 -0
  165. package/package.json +123 -0
  166. package/prisma/schema.prisma +191 -0
  167. package/src/app/api/stripe/checkout/route.ts +145 -0
  168. package/src/app/api/stripe/customer-portal/route.ts +83 -0
  169. package/src/app/api/user/anonymous/init/route.ts +284 -0
  170. package/src/app/api/webhook/clerk/user/route.ts +249 -0
  171. package/src/app/api/webhook/stripe/route.ts +93 -0
  172. package/src/index.ts +6 -0
  173. package/src/lib/auth-utils.ts +101 -0
  174. package/src/lib/credit-init.ts +9 -0
  175. package/src/lib/index.ts +4 -0
  176. package/src/lib/money-price-config.ts +168 -0
  177. package/src/lib/stripe-config.ts +333 -0
  178. package/src/prisma/client.ts +2 -0
  179. package/src/prisma/index.ts +3 -0
  180. package/src/prisma/prisma-transaction-util.ts +24 -0
  181. package/src/prisma/prisma.ts +122 -0
  182. package/src/services/aggregate/billing.aggregate.service.ts +498 -0
  183. package/src/services/aggregate/index.ts +2 -0
  184. package/src/services/aggregate/user.aggregate.service.ts +168 -0
  185. package/src/services/context/index.ts +1 -0
  186. package/src/services/context/user-context-service.ts +200 -0
  187. package/src/services/database/apilog.service.ts +185 -0
  188. package/src/services/database/constants.ts +148 -0
  189. package/src/services/database/credit.service.ts +747 -0
  190. package/src/services/database/creditAuditLog.service.ts +402 -0
  191. package/src/services/database/index.ts +41 -0
  192. package/src/services/database/prisma-model-type.ts +13 -0
  193. package/src/services/database/subscription.service.ts +319 -0
  194. package/src/services/database/transaction.service.ts +447 -0
  195. package/src/services/database/user.service.ts +218 -0
  196. package/src/services/database/userBackup.service.ts +290 -0
  197. package/src/services/stripe/index.ts +1 -0
  198. package/src/services/stripe/webhook-handler.ts +648 -0
@@ -0,0 +1,306 @@
1
+ import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
2
+ import { SubscriptionStatus, PaymentStatus, OrderStatus, TransactionType, PaySupplier, OperationType, CreditType } from '../database/constants.mjs';
3
+ import '../../prisma/prisma.mjs';
4
+ import { runInTransaction } from '../../prisma/prisma-transaction-util.mjs';
5
+ import { subscriptionService } from '../database/subscription.service.mjs';
6
+ import { creditService } from '../database/credit.service.mjs';
7
+ import { transactionService } from '../database/transaction.service.mjs';
8
+ import '@prisma/client';
9
+
10
+ class BillingAggregateService {
11
+ recordSubscriptionInitPayment(context) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
14
+ var _a, _b, _c, _d, _e, _f, _g, _h;
15
+ const now = new Date();
16
+ // 订阅截止时间统一为到期日最后1s
17
+ const originSubPeriodEnd = context.periodEnd;
18
+ const specialEnd = originSubPeriodEnd ? new Date(originSubPeriodEnd.setHours(23, 59, 59, 999)) : originSubPeriodEnd;
19
+ const updatedSubscription = yield subscriptionService.updateSubscription(context.subIdKey, {
20
+ status: SubscriptionStatus.ACTIVE,
21
+ orderId: (_a = context.orderId) !== null && _a !== void 0 ? _a : undefined,
22
+ paySubscriptionId: context.paySubscriptionId,
23
+ priceId: (_b = context.priceId) !== null && _b !== void 0 ? _b : undefined,
24
+ priceName: (_c = context.priceName) !== null && _c !== void 0 ? _c : undefined,
25
+ creditsAllocated: context.creditsGranted || 0,
26
+ subPeriodStart: context.periodStart,
27
+ subPeriodEnd: specialEnd,
28
+ updatedAt: now,
29
+ }, tx);
30
+ yield transactionService.update(context.orderId, {
31
+ orderStatus: OrderStatus.SUCCESS,
32
+ paymentStatus: PaymentStatus.PAID,
33
+ paySubscriptionId: context.paySubscriptionId,
34
+ subPeriodStart: context.periodStart,
35
+ subPeriodEnd: context.periodEnd,
36
+ payInvoiceId: context.invoiceId,
37
+ hostedInvoiceUrl: (_d = context.hostedInvoiceUrl) !== null && _d !== void 0 ? _d : undefined,
38
+ invoicePdf: (_e = context.invoicePdf) !== null && _e !== void 0 ? _e : undefined,
39
+ billingReason: (_f = context.billingReason) !== null && _f !== void 0 ? _f : undefined,
40
+ payTransactionId: (_g = context.paymentIntentId) !== null && _g !== void 0 ? _g : undefined,
41
+ paidEmail: (_h = context.paidEmail) !== null && _h !== void 0 ? _h : undefined,
42
+ paidAt: context.paidAt,
43
+ payUpdatedAt: now,
44
+ }, tx);
45
+ if (context.creditsGranted > 0) {
46
+ yield creditService.rechargeCredit(context.userId, { paid: context.creditsGranted }, {
47
+ feature: TransactionType.SUBSCRIPTION,
48
+ operationReferId: context.orderId,
49
+ }, tx);
50
+ }
51
+ yield tx.credit.update({
52
+ where: { userId: context.userId },
53
+ data: {
54
+ paidStart: context.periodStart,
55
+ paidEnd: context.periodEnd,
56
+ },
57
+ });
58
+ return updatedSubscription;
59
+ }));
60
+ });
61
+ }
62
+ completeOneTimeCheckout(params) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
65
+ var _a;
66
+ const now = new Date();
67
+ yield transactionService.update(params.orderId, {
68
+ orderStatus: OrderStatus.SUCCESS,
69
+ paymentStatus: params.paymentStatus,
70
+ payTransactionId: params.payTransactionId,
71
+ paidAt: now,
72
+ paidEmail: (_a = params.paidEmail) !== null && _a !== void 0 ? _a : undefined,
73
+ payUpdatedAt: now,
74
+ }, tx);
75
+ if (params.creditsGranted > 0) {
76
+ yield creditService.rechargeCredit(params.userId, { oneTimePaid: params.creditsGranted }, {
77
+ feature: TransactionType.ONE_TIME,
78
+ operationReferId: params.orderId,
79
+ }, tx);
80
+ }
81
+ yield tx.credit.update({
82
+ where: { userId: params.userId },
83
+ data: {
84
+ oneTimePaidStart: params.oneTimePaidStart,
85
+ oneTimePaidEnd: params.oneTimePaidEnd,
86
+ },
87
+ });
88
+ }));
89
+ });
90
+ }
91
+ recordInitialInvoiceDetails(params) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
94
+ var _a, _b, _c;
95
+ yield transactionService.update(params.orderId, {
96
+ payInvoiceId: params.invoiceId,
97
+ payTransactionId: params.paymentIntentId,
98
+ hostedInvoiceUrl: (_a = params.hostedInvoiceUrl) !== null && _a !== void 0 ? _a : undefined,
99
+ invoicePdf: (_b = params.invoicePdf) !== null && _b !== void 0 ? _b : undefined,
100
+ billingReason: (_c = params.billingReason) !== null && _c !== void 0 ? _c : undefined,
101
+ payUpdatedAt: new Date(),
102
+ }, tx);
103
+ }));
104
+ });
105
+ }
106
+ recordSubscriptionRenewalPayment(context) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
110
+ yield transactionService.createTransaction({
111
+ userId: context.userId,
112
+ orderId: context.orderId,
113
+ orderStatus: OrderStatus.SUCCESS,
114
+ paymentStatus: PaymentStatus.PAID,
115
+ paySupplier: PaySupplier.STRIPE,
116
+ paySubscriptionId: (_a = context.paySubscriptionId) !== null && _a !== void 0 ? _a : undefined,
117
+ subPeriodStart: (_b = context.periodStart) !== null && _b !== void 0 ? _b : undefined,
118
+ subPeriodEnd: (_c = context.periodEnd) !== null && _c !== void 0 ? _c : undefined,
119
+ payInvoiceId: context.invoiceId,
120
+ hostedInvoiceUrl: (_d = context.hostedInvoiceUrl) !== null && _d !== void 0 ? _d : undefined,
121
+ invoicePdf: (_e = context.invoicePdf) !== null && _e !== void 0 ? _e : undefined,
122
+ billingReason: (_f = context.billingReason) !== null && _f !== void 0 ? _f : undefined,
123
+ payTransactionId: (_g = context.paymentIntentId) !== null && _g !== void 0 ? _g : undefined,
124
+ priceId: (_h = context.priceId) !== null && _h !== void 0 ? _h : undefined,
125
+ priceName: (_j = context.priceName) !== null && _j !== void 0 ? _j : undefined,
126
+ type: TransactionType.SUBSCRIPTION,
127
+ amount: context.amountPaidCents / 100,
128
+ currency: context.currency.toUpperCase(),
129
+ creditsGranted: context.creditsGranted,
130
+ paidAt: (_k = context.paidAt) !== null && _k !== void 0 ? _k : undefined,
131
+ paidEmail: context.paidEmail,
132
+ payUpdatedAt: new Date(),
133
+ }, tx);
134
+ // 订阅截止时间统一为到期日最后1s
135
+ const originSubPeriodEnd = context.periodEnd;
136
+ const specialEnd = originSubPeriodEnd ? new Date(originSubPeriodEnd.setHours(23, 59, 59, 999)) : originSubPeriodEnd;
137
+ yield subscriptionService.updateSubscription(context.subIdKey, {
138
+ status: SubscriptionStatus.ACTIVE,
139
+ orderId: context.orderId,
140
+ subPeriodStart: context.periodStart,
141
+ subPeriodEnd: specialEnd,
142
+ updatedAt: new Date(),
143
+ }, tx);
144
+ if (context.creditsGranted > 0) {
145
+ yield creditService.rechargeCredit(context.userId, { paid: context.creditsGranted }, {
146
+ feature: `${TransactionType.SUBSCRIPTION}_renewal`,
147
+ operationReferId: context.orderId,
148
+ }, tx);
149
+ }
150
+ yield tx.credit.update({
151
+ where: { userId: context.userId },
152
+ data: {
153
+ paidStart: context.periodStart,
154
+ paidEnd: context.periodEnd,
155
+ },
156
+ });
157
+ }));
158
+ });
159
+ }
160
+ recordInitialPaymentFailure(params) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
163
+ var _a, _b;
164
+ yield transactionService.updateStatus(params.orderId, OrderStatus.FAILED, {
165
+ paymentStatus: PaymentStatus.UN_PAID,
166
+ payInvoiceId: params.invoiceId,
167
+ payTransactionId: params.paymentIntentId,
168
+ payUpdatedAt: new Date(),
169
+ paidDetail: (_a = params.detail) !== null && _a !== void 0 ? _a : undefined,
170
+ orderDetail: (_b = params.detail) !== null && _b !== void 0 ? _b : undefined,
171
+ }, tx);
172
+ }));
173
+ });
174
+ }
175
+ recordRenewalPaymentFailure(context) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
178
+ var _a, _b, _c, _d, _e, _f;
179
+ yield transactionService.createTransaction({
180
+ userId: context.userId,
181
+ orderId: context.orderId,
182
+ orderStatus: OrderStatus.FAILED,
183
+ paymentStatus: PaymentStatus.UN_PAID,
184
+ paySupplier: PaySupplier.STRIPE,
185
+ paySubscriptionId: (_a = context.paySubscriptionId) !== null && _a !== void 0 ? _a : undefined,
186
+ payInvoiceId: context.invoiceId,
187
+ billingReason: (_b = context.billingReason) !== null && _b !== void 0 ? _b : undefined,
188
+ payTransactionId: (_c = context.paymentIntentId) !== null && _c !== void 0 ? _c : undefined,
189
+ priceId: (_d = context.priceId) !== null && _d !== void 0 ? _d : undefined,
190
+ priceName: (_e = context.priceName) !== null && _e !== void 0 ? _e : undefined,
191
+ type: TransactionType.SUBSCRIPTION,
192
+ amount: context.amountPaidCents / 100,
193
+ currency: context.currency.toUpperCase(),
194
+ creditsGranted: 0,
195
+ paidAt: (_f = context.paidAt) !== null && _f !== void 0 ? _f : undefined,
196
+ paidEmail: context.paidEmail,
197
+ payUpdatedAt: new Date(),
198
+ orderDetail: 'Subscription renewal payment failed',
199
+ }, tx);
200
+ yield creditService.payFailedWatcher({
201
+ userId: context.userId,
202
+ feature: `${TransactionType.SUBSCRIPTION}_renewal_failed`,
203
+ operationReferId: context.orderId,
204
+ creditType: CreditType.PAID,
205
+ operationType: OperationType.RECHARGE,
206
+ creditsChange: 0,
207
+ }, tx);
208
+ yield subscriptionService.updateSubscription(context.subIdKey, {
209
+ status: SubscriptionStatus.PAST_DUE,
210
+ orderId: context.orderId,
211
+ updatedAt: new Date(),
212
+ }, tx);
213
+ }));
214
+ });
215
+ }
216
+ syncSubscriptionFromStripe(params) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
219
+ if (params.isUserCancel) {
220
+ // 记录用户取消订阅的时间信息
221
+ yield transactionService.update(params.orderId, {
222
+ subLastTryCancelAt: new Date(),
223
+ }, tx);
224
+ }
225
+ yield subscriptionService.updateSubscription(params.subscription.id, {
226
+ status: params.status,
227
+ subPeriodStart: params.periodStart,
228
+ subPeriodEnd: params.periodEnd,
229
+ updatedAt: new Date(),
230
+ }, tx);
231
+ }));
232
+ });
233
+ }
234
+ processSubscriptionCancel(context) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
237
+ var _a;
238
+ // 更新订单, 记录取消信息
239
+ yield transactionService.update(context.orderId, {
240
+ subPeriodCanceledAt: context.canceledAt,
241
+ subCancellationDetail: (_a = context.cancellationDetail) !== null && _a !== void 0 ? _a : undefined
242
+ }, tx);
243
+ // 更新订阅信息
244
+ yield subscriptionService.updateStatus(context.subIdKey, SubscriptionStatus.CANCELED, tx);
245
+ // 清理积分并留痕
246
+ yield creditService.purgePaidCredit(context.userId, 'cancel_subscription_purge', context.orderId, tx);
247
+ }));
248
+ });
249
+ }
250
+ processSubscriptionRefund(context) {
251
+ return __awaiter(this, void 0, void 0, function* () {
252
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
253
+ var _a, _b;
254
+ const now = new Date();
255
+ yield transactionService.update(context.transaction.orderId, {
256
+ orderStatus: OrderStatus.REFUNDED,
257
+ paymentStatus: PaymentStatus.UN_PAID,
258
+ payUpdatedAt: now,
259
+ }, tx);
260
+ const subscription = (_a = context.subscription) !== null && _a !== void 0 ? _a : (context.transaction.paySubscriptionId
261
+ ? yield subscriptionService.findByPaySubscriptionId(context.transaction.paySubscriptionId, tx)
262
+ : null);
263
+ if (subscription) {
264
+ yield subscriptionService.updateSubscription(subscription.id, {
265
+ status: SubscriptionStatus.CANCELED,
266
+ updatedAt: now,
267
+ }, tx);
268
+ }
269
+ const credit = yield creditService.getCredit(context.transaction.userId, tx);
270
+ const paidBalance = Math.max((_b = credit === null || credit === void 0 ? void 0 : credit.balancePaid) !== null && _b !== void 0 ? _b : 0, 0);
271
+ if (paidBalance > 0) {
272
+ yield creditService.consumeCredit(context.transaction.userId, { paid: paidBalance }, {
273
+ feature: OrderStatus.REFUNDED,
274
+ operationReferId: context.transaction.orderId,
275
+ }, tx);
276
+ }
277
+ }));
278
+ });
279
+ }
280
+ processOneTimeRefund(context) {
281
+ return __awaiter(this, void 0, void 0, function* () {
282
+ yield runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
283
+ var _a, _b;
284
+ const now = new Date();
285
+ yield transactionService.update(context.transaction.orderId, {
286
+ orderStatus: OrderStatus.REFUNDED,
287
+ paymentStatus: PaymentStatus.UN_PAID,
288
+ payUpdatedAt: now,
289
+ }, tx);
290
+ const credit = yield creditService.getCredit(context.transaction.userId, tx);
291
+ const currentBalance = Math.max((_a = credit === null || credit === void 0 ? void 0 : credit.balanceOneTimePaid) !== null && _a !== void 0 ? _a : 0, 0);
292
+ const granted = Math.max((_b = context.transaction.creditsGranted) !== null && _b !== void 0 ? _b : 0, 0);
293
+ const amountToConsume = Math.min(currentBalance, granted);
294
+ if (amountToConsume > 0) {
295
+ yield creditService.consumeCredit(context.transaction.userId, { oneTimePaid: amountToConsume }, {
296
+ feature: OrderStatus.REFUNDED,
297
+ operationReferId: context.transaction.orderId,
298
+ }, tx);
299
+ }
300
+ }));
301
+ });
302
+ }
303
+ }
304
+ const billingAggregateService = new BillingAggregateService();
305
+
306
+ export { billingAggregateService };
@@ -0,0 +1,3 @@
1
+ export { userAggregateService } from './user.aggregate.service';
2
+ export { billingAggregateService } from './billing.aggregate.service';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aggregate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var user_aggregate_service = require('./user.aggregate.service.js');
4
+ var billing_aggregate_service = require('./billing.aggregate.service.js');
5
+
6
+
7
+
8
+ exports.userAggregateService = user_aggregate_service.userAggregateService;
9
+ exports.billingAggregateService = billing_aggregate_service.billingAggregateService;
@@ -0,0 +1,2 @@
1
+ export { userAggregateService } from './user.aggregate.service.mjs';
2
+ export { billingAggregateService } from './billing.aggregate.service.mjs';
@@ -0,0 +1,34 @@
1
+ import type { Credit, Prisma, User } from '../database/prisma-model-type';
2
+ export declare class UserAggregateService {
3
+ initAnonymousUser(fingerprintId: string, options?: {
4
+ sourceRef?: Prisma.InputJsonValue;
5
+ }): Promise<{
6
+ newUser: User;
7
+ credit: Credit;
8
+ }>;
9
+ /**
10
+ * 创建新的注册用户
11
+ *
12
+ * 初始化步骤(与 credit 平行):
13
+ * 1. 创建 User 记录
14
+ * 2. 初始化 Credit 记录(免费积分)
15
+ * 3. 初始化 Subscription 记录(占位符,status=INCOMPLETE)
16
+ * 4. 记录 CreditUsage(审计)
17
+ *
18
+ * 后续当用户通过 Stripe 订阅时:
19
+ * - session.completed 或 invoice.paid 会 UPDATE subscription 记录
20
+ * - 不需要 CREATE,只需 UPDATE 确保逻辑一致
21
+ */
22
+ createNewRegisteredUser(clerkUserId: string, email?: string, fingerprintId?: string, userName?: string, sourceRef?: Prisma.InputJsonValue): Promise<{
23
+ newUser: User;
24
+ credit: Credit;
25
+ }>;
26
+ upgradeToRegistered(userId: string, email: string, clerkUserId: string, userName?: string): Promise<{
27
+ updateUser: User;
28
+ credit: Credit;
29
+ }>;
30
+ handleUserUnregister(clerkUserId: string): Promise<string | null>;
31
+ private findUserWithRelations;
32
+ }
33
+ export declare const userAggregateService: UserAggregateService;
34
+ //# sourceMappingURL=user.aggregate.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.aggregate.service.d.ts","sourceRoot":"","sources":["../../../src/services/aggregate/user.aggregate.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAK1E,qBAAa,oBAAoB;IAEzB,iBAAiB,CACrB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;KAAE,GAC/C,OAAO,CAAC;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;KAAE,CAAC;IA6B9C;;;;;;;;;;;;OAYG;IACG,uBAAuB,CAC3B,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,MAAM,EACtB,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,CAAC,cAAc,GAChC,OAAO,CAAC;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;KAAE,CAAC;IA+BxC,mBAAmB,CACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,UAAU,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;KAAE,CAAC;IA+B3C,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YAwBzD,qBAAqB;CAcpC;AAED,eAAO,MAAM,oBAAoB,sBAA6B,CAAC"}
@@ -0,0 +1,136 @@
1
+ 'use strict';
2
+
3
+ var tslib_es6 = require('../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
4
+ var constants = require('../database/constants.js');
5
+ var user_service = require('../database/user.service.js');
6
+ var subscription_service = require('../database/subscription.service.js');
7
+ var credit_service = require('../database/credit.service.js');
8
+ require('@prisma/client');
9
+ require('../../prisma/prisma.js');
10
+ var prismaTransactionUtil = require('../../prisma/prisma-transaction-util.js');
11
+ var creditInit = require('../../lib/credit-init.js');
12
+
13
+ class UserAggregateService {
14
+ initAnonymousUser(fingerprintId, options) {
15
+ return tslib_es6.__awaiter(this, void 0, void 0, function* () {
16
+ return prismaTransactionUtil.runInTransaction((tx) => tslib_es6.__awaiter(this, void 0, void 0, function* () {
17
+ const newUser = yield user_service.userService.createUser({
18
+ fingerprintId,
19
+ sourceRef: options === null || options === void 0 ? void 0 : options.sourceRef,
20
+ status: constants.UserStatus.ANONYMOUS,
21
+ }, tx);
22
+ const credit = yield credit_service.creditService.initializeCreditWithFree({
23
+ userId: newUser.userId,
24
+ feature: 'anonymous_user_init',
25
+ creditType: constants.CreditType.FREE,
26
+ operationType: constants.OperationType.SYS_GIFT,
27
+ operationReferId: newUser.userId,
28
+ creditsChange: creditInit.freeAmount,
29
+ }, tx);
30
+ yield subscription_service.subscriptionService.initializeSubscription(newUser.userId, tx);
31
+ return { newUser, credit };
32
+ }));
33
+ });
34
+ }
35
+ /**
36
+ * 创建新的注册用户
37
+ *
38
+ * 初始化步骤(与 credit 平行):
39
+ * 1. 创建 User 记录
40
+ * 2. 初始化 Credit 记录(免费积分)
41
+ * 3. 初始化 Subscription 记录(占位符,status=INCOMPLETE)
42
+ * 4. 记录 CreditUsage(审计)
43
+ *
44
+ * 后续当用户通过 Stripe 订阅时:
45
+ * - session.completed 或 invoice.paid 会 UPDATE subscription 记录
46
+ * - 不需要 CREATE,只需 UPDATE 确保逻辑一致
47
+ */
48
+ createNewRegisteredUser(clerkUserId, email, fingerprintId, userName, sourceRef) {
49
+ return tslib_es6.__awaiter(this, void 0, void 0, function* () {
50
+ return prismaTransactionUtil.runInTransaction((tx) => tslib_es6.__awaiter(this, void 0, void 0, function* () {
51
+ const newUser = yield user_service.userService.createUser({
52
+ clerkUserId,
53
+ email,
54
+ fingerprintId,
55
+ userName,
56
+ sourceRef,
57
+ status: constants.UserStatus.REGISTERED,
58
+ }, tx);
59
+ const credit = yield credit_service.creditService.initializeCreditWithFree({
60
+ userId: newUser.userId,
61
+ feature: 'user_registration_init',
62
+ creditType: constants.CreditType.FREE,
63
+ operationType: constants.OperationType.SYS_GIFT,
64
+ operationReferId: newUser.userId,
65
+ creditsChange: creditInit.freeRegisterAmount,
66
+ });
67
+ yield subscription_service.subscriptionService.initializeSubscription(newUser.userId, tx);
68
+ return { newUser, credit };
69
+ }));
70
+ });
71
+ }
72
+ // 注意积分审查日志的处理
73
+ upgradeToRegistered(userId, email, clerkUserId, userName) {
74
+ return tslib_es6.__awaiter(this, void 0, void 0, function* () {
75
+ return prismaTransactionUtil.runInTransaction((tx) => tslib_es6.__awaiter(this, void 0, void 0, function* () {
76
+ const updateUser = yield user_service.userService.upgradeToRegistered(userId, {
77
+ email,
78
+ clerkUserId,
79
+ userName
80
+ }, tx);
81
+ // 先清空匿名积分并审计日志留痕
82
+ yield credit_service.creditService.purgeFreeCredit(userId, 'user_registered_purge', userId, tx);
83
+ // 再初始化完成注册获得免费积分
84
+ const credit = yield credit_service.creditService.initializeCreditWithFree({
85
+ userId: updateUser.userId,
86
+ feature: 'user_registration_init',
87
+ creditType: constants.CreditType.FREE,
88
+ operationType: constants.OperationType.SYS_GIFT,
89
+ operationReferId: userId,
90
+ creditsChange: creditInit.freeRegisterAmount,
91
+ }, tx);
92
+ return { updateUser: updateUser, credit: credit };
93
+ }));
94
+ });
95
+ }
96
+ handleUserUnregister(clerkUserId) {
97
+ return tslib_es6.__awaiter(this, void 0, void 0, function* () {
98
+ return prismaTransactionUtil.runInTransaction((tx) => tslib_es6.__awaiter(this, void 0, void 0, function* () {
99
+ // 根据clerkUserId查找用户
100
+ const user = yield user_service.userService.findByClerkUserId(clerkUserId, tx);
101
+ if (!user) {
102
+ console.log(`User with clerkUserId ${clerkUserId} not found`);
103
+ return null;
104
+ }
105
+ const userId = user.userId;
106
+ // 更改用户状态,保留user信息尤其是FingerprintId,防止反复注册薅羊毛
107
+ yield user_service.userService.unregister(user.userId);
108
+ // 清空积分
109
+ yield credit_service.creditService.purgeCredit(userId, 'soft_delete_user', userId, tx);
110
+ const subscription = yield subscription_service.subscriptionService.getActiveSubscription(userId, tx);
111
+ if (subscription) {
112
+ // 如果有订阅信息,则要更新
113
+ yield subscription_service.subscriptionService.cancelSubscription(subscription.id, true, tx);
114
+ }
115
+ return user.userId;
116
+ }));
117
+ });
118
+ }
119
+ findUserWithRelations(userId, tx) {
120
+ return tslib_es6.__awaiter(this, void 0, void 0, function* () {
121
+ return tx.user.findUnique({
122
+ where: { userId },
123
+ include: {
124
+ credit: true,
125
+ subscription: true,
126
+ transactions: true,
127
+ creditAuditLogs: true,
128
+ },
129
+ });
130
+ });
131
+ }
132
+ }
133
+ const userAggregateService = new UserAggregateService();
134
+
135
+ exports.UserAggregateService = UserAggregateService;
136
+ exports.userAggregateService = userAggregateService;
@@ -0,0 +1,133 @@
1
+ import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
2
+ import { UserStatus, OperationType, CreditType } from '../database/constants.mjs';
3
+ import { userService } from '../database/user.service.mjs';
4
+ import { subscriptionService } from '../database/subscription.service.mjs';
5
+ import { creditService } from '../database/credit.service.mjs';
6
+ import '@prisma/client';
7
+ import '../../prisma/prisma.mjs';
8
+ import { runInTransaction } from '../../prisma/prisma-transaction-util.mjs';
9
+ import { freeAmount, freeRegisterAmount } from '../../lib/credit-init.mjs';
10
+
11
+ class UserAggregateService {
12
+ initAnonymousUser(fingerprintId, options) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ return runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
15
+ const newUser = yield userService.createUser({
16
+ fingerprintId,
17
+ sourceRef: options === null || options === void 0 ? void 0 : options.sourceRef,
18
+ status: UserStatus.ANONYMOUS,
19
+ }, tx);
20
+ const credit = yield creditService.initializeCreditWithFree({
21
+ userId: newUser.userId,
22
+ feature: 'anonymous_user_init',
23
+ creditType: CreditType.FREE,
24
+ operationType: OperationType.SYS_GIFT,
25
+ operationReferId: newUser.userId,
26
+ creditsChange: freeAmount,
27
+ }, tx);
28
+ yield subscriptionService.initializeSubscription(newUser.userId, tx);
29
+ return { newUser, credit };
30
+ }));
31
+ });
32
+ }
33
+ /**
34
+ * 创建新的注册用户
35
+ *
36
+ * 初始化步骤(与 credit 平行):
37
+ * 1. 创建 User 记录
38
+ * 2. 初始化 Credit 记录(免费积分)
39
+ * 3. 初始化 Subscription 记录(占位符,status=INCOMPLETE)
40
+ * 4. 记录 CreditUsage(审计)
41
+ *
42
+ * 后续当用户通过 Stripe 订阅时:
43
+ * - session.completed 或 invoice.paid 会 UPDATE subscription 记录
44
+ * - 不需要 CREATE,只需 UPDATE 确保逻辑一致
45
+ */
46
+ createNewRegisteredUser(clerkUserId, email, fingerprintId, userName, sourceRef) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
49
+ const newUser = yield userService.createUser({
50
+ clerkUserId,
51
+ email,
52
+ fingerprintId,
53
+ userName,
54
+ sourceRef,
55
+ status: UserStatus.REGISTERED,
56
+ }, tx);
57
+ const credit = yield creditService.initializeCreditWithFree({
58
+ userId: newUser.userId,
59
+ feature: 'user_registration_init',
60
+ creditType: CreditType.FREE,
61
+ operationType: OperationType.SYS_GIFT,
62
+ operationReferId: newUser.userId,
63
+ creditsChange: freeRegisterAmount,
64
+ });
65
+ yield subscriptionService.initializeSubscription(newUser.userId, tx);
66
+ return { newUser, credit };
67
+ }));
68
+ });
69
+ }
70
+ // 注意积分审查日志的处理
71
+ upgradeToRegistered(userId, email, clerkUserId, userName) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
74
+ const updateUser = yield userService.upgradeToRegistered(userId, {
75
+ email,
76
+ clerkUserId,
77
+ userName
78
+ }, tx);
79
+ // 先清空匿名积分并审计日志留痕
80
+ yield creditService.purgeFreeCredit(userId, 'user_registered_purge', userId, tx);
81
+ // 再初始化完成注册获得免费积分
82
+ const credit = yield creditService.initializeCreditWithFree({
83
+ userId: updateUser.userId,
84
+ feature: 'user_registration_init',
85
+ creditType: CreditType.FREE,
86
+ operationType: OperationType.SYS_GIFT,
87
+ operationReferId: userId,
88
+ creditsChange: freeRegisterAmount,
89
+ }, tx);
90
+ return { updateUser: updateUser, credit: credit };
91
+ }));
92
+ });
93
+ }
94
+ handleUserUnregister(clerkUserId) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ return runInTransaction((tx) => __awaiter(this, void 0, void 0, function* () {
97
+ // 根据clerkUserId查找用户
98
+ const user = yield userService.findByClerkUserId(clerkUserId, tx);
99
+ if (!user) {
100
+ console.log(`User with clerkUserId ${clerkUserId} not found`);
101
+ return null;
102
+ }
103
+ const userId = user.userId;
104
+ // 更改用户状态,保留user信息尤其是FingerprintId,防止反复注册薅羊毛
105
+ yield userService.unregister(user.userId);
106
+ // 清空积分
107
+ yield creditService.purgeCredit(userId, 'soft_delete_user', userId, tx);
108
+ const subscription = yield subscriptionService.getActiveSubscription(userId, tx);
109
+ if (subscription) {
110
+ // 如果有订阅信息,则要更新
111
+ yield subscriptionService.cancelSubscription(subscription.id, true, tx);
112
+ }
113
+ return user.userId;
114
+ }));
115
+ });
116
+ }
117
+ findUserWithRelations(userId, tx) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ return tx.user.findUnique({
120
+ where: { userId },
121
+ include: {
122
+ credit: true,
123
+ subscription: true,
124
+ transactions: true,
125
+ creditAuditLogs: true,
126
+ },
127
+ });
128
+ });
129
+ }
130
+ }
131
+ const userAggregateService = new UserAggregateService();
132
+
133
+ export { UserAggregateService, userAggregateService };
@@ -0,0 +1,2 @@
1
+ export * from './user-context-service';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var userContextService = require('./user-context-service.js');
4
+
5
+
6
+
7
+ exports.applyUserMockContext = userContextService.applyUserMockContext;
8
+ exports.buildInitUserContextFromEntities = userContextService.buildInitUserContextFromEntities;
9
+ exports.fetchLatestUserContextByFingerprintId = userContextService.fetchLatestUserContextByFingerprintId;
10
+ exports.fetchUserContextByClerkUserId = userContextService.fetchUserContextByClerkUserId;
11
+ exports.mapCreditToXCredit = userContextService.mapCreditToXCredit;
12
+ exports.mapSubscriptionToXSubscription = userContextService.mapSubscriptionToXSubscription;
13
+ exports.mapUserToXUser = userContextService.mapUserToXUser;
@@ -0,0 +1 @@
1
+ export { applyUserMockContext, buildInitUserContextFromEntities, fetchLatestUserContextByFingerprintId, fetchUserContextByClerkUserId, mapCreditToXCredit, mapSubscriptionToXSubscription, mapUserToXUser } from './user-context-service.mjs';