@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.
- package/LICENSE +21 -0
- package/dist/app/api/stripe/checkout/route.d.ts +19 -0
- package/dist/app/api/stripe/checkout/route.d.ts.map +1 -0
- package/dist/app/api/stripe/checkout/route.js +120 -0
- package/dist/app/api/stripe/checkout/route.mjs +118 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts +11 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts.map +1 -0
- package/dist/app/api/stripe/customer-portal/route.js +73 -0
- package/dist/app/api/stripe/customer-portal/route.mjs +71 -0
- package/dist/app/api/user/anonymous/init/route.d.ts +7 -0
- package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -0
- package/dist/app/api/user/anonymous/init/route.js +210 -0
- package/dist/app/api/user/anonymous/init/route.mjs +208 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts +7 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts.map +1 -0
- package/dist/app/api/webhook/clerk/user/route.js +202 -0
- package/dist/app/api/webhook/clerk/user/route.mjs +200 -0
- package/dist/app/api/webhook/stripe/route.d.ts +8 -0
- package/dist/app/api/webhook/stripe/route.d.ts.map +1 -0
- package/dist/app/api/webhook/stripe/route.js +70 -0
- package/dist/app/api/webhook/stripe/route.mjs +67 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.mjs +18 -0
- package/dist/lib/auth-utils.d.ts +46 -0
- package/dist/lib/auth-utils.d.ts.map +1 -0
- package/dist/lib/auth-utils.js +107 -0
- package/dist/lib/auth-utils.mjs +102 -0
- package/dist/lib/credit-init.d.ts +8 -0
- package/dist/lib/credit-init.d.ts.map +1 -0
- package/dist/lib/credit-init.js +16 -0
- package/dist/lib/credit-init.mjs +10 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +31 -0
- package/dist/lib/index.mjs +4 -0
- package/dist/lib/money-price-config.d.ts +51 -0
- package/dist/lib/money-price-config.d.ts.map +1 -0
- package/dist/lib/money-price-config.js +156 -0
- package/dist/lib/money-price-config.mjs +151 -0
- package/dist/lib/stripe-config.d.ts +31 -0
- package/dist/lib/stripe-config.d.ts.map +1 -0
- package/dist/lib/stripe-config.js +278 -0
- package/dist/lib/stripe-config.mjs +268 -0
- 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
- 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
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +54 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +51 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +44 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +35 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +31 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +18 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +587 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +527 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +447 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +399 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +245 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +232 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +68 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +62 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +39 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +37 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +80 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +75 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +101 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +86 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +102 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +76 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +56 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +52 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +1205 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +1157 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +407 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +374 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +9 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +7 -0
- package/dist/prisma/client.d.ts +2 -0
- package/dist/prisma/client.d.ts.map +1 -0
- package/dist/prisma/client.js +12 -0
- package/dist/prisma/client.mjs +1 -0
- package/dist/prisma/index.d.ts +4 -0
- package/dist/prisma/index.d.ts.map +1 -0
- package/dist/prisma/index.js +10 -0
- package/dist/prisma/index.mjs +2 -0
- package/dist/prisma/prisma-transaction-util.d.ts +3 -0
- package/dist/prisma/prisma-transaction-util.d.ts.map +1 -0
- package/dist/prisma/prisma-transaction-util.js +29 -0
- package/dist/prisma/prisma-transaction-util.mjs +27 -0
- package/dist/prisma/prisma.d.ts +4 -0
- package/dist/prisma/prisma.d.ts.map +1 -0
- package/dist/prisma/prisma.js +109 -0
- package/dist/prisma/prisma.mjs +106 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts +83 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/billing.aggregate.service.js +308 -0
- package/dist/services/aggregate/billing.aggregate.service.mjs +306 -0
- package/dist/services/aggregate/index.d.ts +3 -0
- package/dist/services/aggregate/index.d.ts.map +1 -0
- package/dist/services/aggregate/index.js +9 -0
- package/dist/services/aggregate/index.mjs +2 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts +34 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/user.aggregate.service.js +136 -0
- package/dist/services/aggregate/user.aggregate.service.mjs +133 -0
- package/dist/services/context/index.d.ts +2 -0
- package/dist/services/context/index.d.ts.map +1 -0
- package/dist/services/context/index.js +13 -0
- package/dist/services/context/index.mjs +1 -0
- package/dist/services/context/user-context-service.d.ts +30 -0
- package/dist/services/context/user-context-service.d.ts.map +1 -0
- package/dist/services/context/user-context-service.js +170 -0
- package/dist/services/context/user-context-service.mjs +162 -0
- package/dist/services/database/apilog.service.d.ts +39 -0
- package/dist/services/database/apilog.service.d.ts.map +1 -0
- package/dist/services/database/apilog.service.js +174 -0
- package/dist/services/database/apilog.service.mjs +170 -0
- package/dist/services/database/constants.d.ts +73 -0
- package/dist/services/database/constants.d.ts.map +1 -0
- package/dist/services/database/constants.js +135 -0
- package/dist/services/database/constants.mjs +117 -0
- package/dist/services/database/credit.service.d.ts +107 -0
- package/dist/services/database/credit.service.d.ts.map +1 -0
- package/dist/services/database/credit.service.js +515 -0
- package/dist/services/database/credit.service.mjs +512 -0
- package/dist/services/database/creditAuditLog.service.d.ts +73 -0
- package/dist/services/database/creditAuditLog.service.d.ts.map +1 -0
- package/dist/services/database/creditAuditLog.service.js +305 -0
- package/dist/services/database/creditAuditLog.service.mjs +302 -0
- package/dist/services/database/index.d.ts +10 -0
- package/dist/services/database/index.d.ts.map +1 -0
- package/dist/services/database/index.js +38 -0
- package/dist/services/database/index.mjs +8 -0
- package/dist/services/database/prisma-model-type.d.ts +3 -0
- package/dist/services/database/prisma-model-type.d.ts.map +1 -0
- package/dist/services/database/subscription.service.d.ts +48 -0
- package/dist/services/database/subscription.service.d.ts.map +1 -0
- package/dist/services/database/subscription.service.js +267 -0
- package/dist/services/database/subscription.service.mjs +264 -0
- package/dist/services/database/transaction.service.d.ts +92 -0
- package/dist/services/database/transaction.service.d.ts.map +1 -0
- package/dist/services/database/transaction.service.js +326 -0
- package/dist/services/database/transaction.service.mjs +323 -0
- package/dist/services/database/user.service.d.ts +45 -0
- package/dist/services/database/user.service.d.ts.map +1 -0
- package/dist/services/database/user.service.js +180 -0
- package/dist/services/database/user.service.mjs +177 -0
- package/dist/services/database/userBackup.service.d.ts +45 -0
- package/dist/services/database/userBackup.service.d.ts.map +1 -0
- package/dist/services/database/userBackup.service.js +249 -0
- package/dist/services/database/userBackup.service.mjs +246 -0
- package/dist/services/stripe/index.d.ts +2 -0
- package/dist/services/stripe/index.d.ts.map +1 -0
- package/dist/services/stripe/index.js +7 -0
- package/dist/services/stripe/index.mjs +1 -0
- package/dist/services/stripe/webhook-handler.d.ts +6 -0
- package/dist/services/stripe/webhook-handler.d.ts.map +1 -0
- package/dist/services/stripe/webhook-handler.js +537 -0
- package/dist/services/stripe/webhook-handler.mjs +535 -0
- package/migrations/create.sql +176 -0
- package/migrations/db.init.sql +13 -0
- package/migrations/init-schema.sql +19 -0
- package/migrations/purge.sql +27 -0
- package/migrations/test-check.sql +167 -0
- package/package.json +123 -0
- package/prisma/schema.prisma +191 -0
- package/src/app/api/stripe/checkout/route.ts +145 -0
- package/src/app/api/stripe/customer-portal/route.ts +83 -0
- package/src/app/api/user/anonymous/init/route.ts +284 -0
- package/src/app/api/webhook/clerk/user/route.ts +249 -0
- package/src/app/api/webhook/stripe/route.ts +93 -0
- package/src/index.ts +6 -0
- package/src/lib/auth-utils.ts +101 -0
- package/src/lib/credit-init.ts +9 -0
- package/src/lib/index.ts +4 -0
- package/src/lib/money-price-config.ts +168 -0
- package/src/lib/stripe-config.ts +333 -0
- package/src/prisma/client.ts +2 -0
- package/src/prisma/index.ts +3 -0
- package/src/prisma/prisma-transaction-util.ts +24 -0
- package/src/prisma/prisma.ts +122 -0
- package/src/services/aggregate/billing.aggregate.service.ts +498 -0
- package/src/services/aggregate/index.ts +2 -0
- package/src/services/aggregate/user.aggregate.service.ts +168 -0
- package/src/services/context/index.ts +1 -0
- package/src/services/context/user-context-service.ts +200 -0
- package/src/services/database/apilog.service.ts +185 -0
- package/src/services/database/constants.ts +148 -0
- package/src/services/database/credit.service.ts +747 -0
- package/src/services/database/creditAuditLog.service.ts +402 -0
- package/src/services/database/index.ts +41 -0
- package/src/services/database/prisma-model-type.ts +13 -0
- package/src/services/database/subscription.service.ts +319 -0
- package/src/services/database/transaction.service.ts +447 -0
- package/src/services/database/user.service.ts +218 -0
- package/src/services/database/userBackup.service.ts +290 -0
- package/src/services/stripe/index.ts +1 -0
- package/src/services/stripe/webhook-handler.ts +648 -0
|
@@ -0,0 +1,170 @@
|
|
|
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 { checkAndFallbackWithNonTCClient } from '../../prisma/prisma.mjs';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
class ApilogService {
|
|
6
|
+
// Create API log record with request
|
|
7
|
+
createApilog(data, tx) {
|
|
8
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
10
|
+
const log = yield client.apilog.create({
|
|
11
|
+
data: {
|
|
12
|
+
methodName: data.methodName,
|
|
13
|
+
request: data.request ? JSON.stringify(data.request) : null,
|
|
14
|
+
summary: data.summary ? JSON.stringify(data.summary) : null,
|
|
15
|
+
apiType: data.apiType,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
return log.id.toString();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// Update API log record with response
|
|
22
|
+
updateApilogResponse(logId, response, tx) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
25
|
+
yield client.apilog.update({
|
|
26
|
+
where: { id: BigInt(logId) },
|
|
27
|
+
data: {
|
|
28
|
+
response: response ? JSON.stringify(response) : null,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Get API log by ID
|
|
34
|
+
getApilog(logId, tx) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
37
|
+
return yield client.apilog.findUnique({
|
|
38
|
+
where: { id: BigInt(logId) },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// Get API logs with filters
|
|
43
|
+
getApilogList(params, tx) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const { apiType, methodName, limit = 50, offset = 0 } = params;
|
|
46
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
47
|
+
return yield client.apilog.findMany({
|
|
48
|
+
where: Object.assign(Object.assign({}, (apiType && { apiType })), (methodName && { methodName: { contains: methodName } })),
|
|
49
|
+
orderBy: { createdAt: 'desc' },
|
|
50
|
+
take: limit,
|
|
51
|
+
skip: offset,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Delete old API logs (cleanup)
|
|
56
|
+
deleteOldLogList() {
|
|
57
|
+
return __awaiter(this, arguments, void 0, function* (daysOld = 30, tx) {
|
|
58
|
+
const cutoffDate = new Date();
|
|
59
|
+
cutoffDate.setDate(cutoffDate.getDate() - daysOld);
|
|
60
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
61
|
+
const result = yield client.apilog.deleteMany({
|
|
62
|
+
where: {
|
|
63
|
+
createdAt: {
|
|
64
|
+
lt: cutoffDate,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return result.count;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Get API log statistics
|
|
72
|
+
getApilogStats(tx) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const client = checkAndFallbackWithNonTCClient(tx);
|
|
75
|
+
const [total, clerkIn, clerkOut, stripeIn, stripeOut] = yield Promise.all([
|
|
76
|
+
client.apilog.count(),
|
|
77
|
+
client.apilog.count({ where: { apiType: 'from_clerk_in' } }),
|
|
78
|
+
client.apilog.count({ where: { apiType: 'to_clerk_out' } }),
|
|
79
|
+
client.apilog.count({ where: { apiType: 'from_stripe_in' } }),
|
|
80
|
+
client.apilog.count({ where: { apiType: 'to_stripe_out' } }),
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
totalLogs: total,
|
|
84
|
+
clerkIncoming: clerkIn,
|
|
85
|
+
clerkOutgoing: clerkOut,
|
|
86
|
+
stripeIncoming: stripeIn,
|
|
87
|
+
stripeOutgoing: stripeOut,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// API Logger Helper Class for convenience
|
|
93
|
+
class Apilogger {
|
|
94
|
+
static createLogAsync(data) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
try {
|
|
97
|
+
return yield apilogService.createApilog(data);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.error('Failed to create API log:', error);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static updateResponseAsync(logId, response) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
try {
|
|
108
|
+
setImmediate(() => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
yield apilogService.updateApilogResponse(logId, response);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error('Failed to update API log response:', error);
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error('Failed to queue API log update:', error);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
static logClerkIncoming(methodName, summary, originalRequest) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
return yield this.createLogAsync({
|
|
125
|
+
methodName,
|
|
126
|
+
request: originalRequest,
|
|
127
|
+
summary,
|
|
128
|
+
apiType: 'from_clerk_in',
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
static logClerkOutgoing(methodName, request, summary) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return yield this.createLogAsync({
|
|
135
|
+
methodName,
|
|
136
|
+
request,
|
|
137
|
+
summary,
|
|
138
|
+
apiType: 'to_clerk_out',
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
static logStripeIncoming(methodName, summary, originalRequest) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
return yield this.createLogAsync({
|
|
145
|
+
methodName,
|
|
146
|
+
request: originalRequest,
|
|
147
|
+
summary,
|
|
148
|
+
apiType: 'from_stripe_in',
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
static logStripeOutgoing(methodName, request, summary) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
return yield this.createLogAsync({
|
|
155
|
+
methodName,
|
|
156
|
+
request,
|
|
157
|
+
summary,
|
|
158
|
+
apiType: 'to_stripe_out',
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
static updateResponse(logId, response) {
|
|
163
|
+
if (logId) {
|
|
164
|
+
this.updateResponseAsync(logId, response);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const apilogService = new ApilogService();
|
|
169
|
+
|
|
170
|
+
export { ApilogService, Apilogger, apilogService };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const UserStatus: {
|
|
2
|
+
readonly ANONYMOUS: "anonymous";
|
|
3
|
+
readonly REGISTERED: "registered";
|
|
4
|
+
readonly FROZEN: "frozen";
|
|
5
|
+
readonly DELETED: "deleted";
|
|
6
|
+
};
|
|
7
|
+
export declare const SubscriptionStatus: {
|
|
8
|
+
readonly INCOMPLETE: "incomplete";
|
|
9
|
+
readonly TRIALING: "trialing";
|
|
10
|
+
readonly ACTIVE: "active";
|
|
11
|
+
readonly PAST_DUE: "past_due";
|
|
12
|
+
readonly CANCELED: "canceled";
|
|
13
|
+
};
|
|
14
|
+
export declare const OrderStatus: {
|
|
15
|
+
readonly CREATED: "created";
|
|
16
|
+
readonly PENDING_UNPAID: "pending_unpaid";
|
|
17
|
+
readonly SUCCESS: "success";
|
|
18
|
+
readonly FAILED: "failed";
|
|
19
|
+
readonly REFUNDED: "refunded";
|
|
20
|
+
readonly CANCELED: "canceled";
|
|
21
|
+
};
|
|
22
|
+
export declare const TransactionType: {
|
|
23
|
+
readonly SUBSCRIPTION: "subscription";
|
|
24
|
+
readonly ONE_TIME: "one_time";
|
|
25
|
+
};
|
|
26
|
+
export declare const CreditType: {
|
|
27
|
+
readonly PAID: "paid";
|
|
28
|
+
readonly ONE_TIME_PAID: "one_time_paid";
|
|
29
|
+
readonly FREE: "free";
|
|
30
|
+
};
|
|
31
|
+
export declare const OperationType: {
|
|
32
|
+
readonly SYS_GIFT: "system_gift";
|
|
33
|
+
readonly CONSUME: "consume";
|
|
34
|
+
readonly RECHARGE: "recharge";
|
|
35
|
+
readonly FREEZE: "freeze";
|
|
36
|
+
readonly UNFREEZE: "unfreeze";
|
|
37
|
+
readonly ADJUST_INCREASE: "adjust_increase";
|
|
38
|
+
readonly ADJUST_DECREASE: "adjust_decrease";
|
|
39
|
+
readonly PURGE: "purge";
|
|
40
|
+
};
|
|
41
|
+
export declare const PaySupplier: {
|
|
42
|
+
readonly STRIPE: "Stripe";
|
|
43
|
+
readonly APPLE: "Apple";
|
|
44
|
+
readonly PAYPAL: "Paypal";
|
|
45
|
+
};
|
|
46
|
+
export declare const BillingReason: {
|
|
47
|
+
readonly SUBSCRIPTION_CREATE: "subscription_create";
|
|
48
|
+
readonly SUBSCRIPTION_CYCLE: "subscription_cycle";
|
|
49
|
+
};
|
|
50
|
+
export declare const PaymentStatus: {
|
|
51
|
+
readonly PAID: "paid";
|
|
52
|
+
readonly UN_PAID: "un_paid";
|
|
53
|
+
readonly NO_PAYMENT_REQUIRED: "no_payment_required";
|
|
54
|
+
};
|
|
55
|
+
export type UserStatus = typeof UserStatus[keyof typeof UserStatus];
|
|
56
|
+
export type SubscriptionStatus = typeof SubscriptionStatus[keyof typeof SubscriptionStatus];
|
|
57
|
+
export type OrderStatus = typeof OrderStatus[keyof typeof OrderStatus];
|
|
58
|
+
export type TransactionType = typeof TransactionType[keyof typeof TransactionType];
|
|
59
|
+
export type CreditType = typeof CreditType[keyof typeof CreditType];
|
|
60
|
+
export type OperationType = typeof OperationType[keyof typeof OperationType];
|
|
61
|
+
export type PaySupplier = typeof PaySupplier[keyof typeof PaySupplier];
|
|
62
|
+
export type BillingReason = typeof BillingReason[keyof typeof BillingReason];
|
|
63
|
+
export type PaymentStatus = typeof PaymentStatus[keyof typeof PaymentStatus];
|
|
64
|
+
export declare const isValidUserStatus: (status: string) => status is UserStatus;
|
|
65
|
+
export declare const isValidSubscriptionStatus: (status: string) => status is SubscriptionStatus;
|
|
66
|
+
export declare const isValidOrderStatus: (status: string) => status is OrderStatus;
|
|
67
|
+
export declare const isValidTransactionType: (type: string) => type is TransactionType;
|
|
68
|
+
export declare const isValidCreditType: (type: string) => type is CreditType;
|
|
69
|
+
export declare const isValidOperationType: (type: string) => type is OperationType;
|
|
70
|
+
export declare const isValidPaySupplier: (supplier: string) => supplier is PaySupplier;
|
|
71
|
+
export declare const isValidBillingReason: (reason: string) => reason is BillingReason;
|
|
72
|
+
export declare const isValidPaymentStatus: (status: string) => status is PaymentStatus;
|
|
73
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/services/database/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU;;;;;CASb,CAAC;AAEX,eAAO,MAAM,kBAAkB;;;;;;CAWrB,CAAC;AAEX,eAAO,MAAM,WAAW;;;;;;;CAad,CAAC;AAEX,eAAO,MAAM,eAAe;;;CAKlB,CAAC;AAEX,eAAO,MAAM,UAAU;;;;CAOb,CAAC;AAEX,eAAO,MAAM,aAAa;;;;;;;;;CAiBhB,CAAC;AAGX,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,eAAO,MAAM,aAAa;;;CAKhB,CAAC;AAEX,eAAO,MAAM,aAAa;;;;CAOhB,CAAC;AAIX,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AACpE,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAC5F,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,MAAM,O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
|
|
2
|
+
|
|
3
|
+
// Database Field Enums
|
|
4
|
+
// Keep in sync with DB CHECK constraints
|
|
5
|
+
const UserStatus = {
|
|
6
|
+
// 匿名用户
|
|
7
|
+
ANONYMOUS: 'anonymous',
|
|
8
|
+
// 注册用户
|
|
9
|
+
REGISTERED: 'registered',
|
|
10
|
+
// 管理员介入管控
|
|
11
|
+
FROZEN: 'frozen',
|
|
12
|
+
// 用户注销,数据软删除,用户数据将不可复用
|
|
13
|
+
DELETED: 'deleted',
|
|
14
|
+
};
|
|
15
|
+
const SubscriptionStatus = {
|
|
16
|
+
// 初始状态或注销后状态
|
|
17
|
+
INCOMPLETE: 'incomplete',
|
|
18
|
+
// 订阅试用期
|
|
19
|
+
TRIALING: 'trialing',
|
|
20
|
+
// 有效订阅激活
|
|
21
|
+
ACTIVE: 'active',
|
|
22
|
+
// 订阅过期
|
|
23
|
+
PAST_DUE: 'past_due',
|
|
24
|
+
// 取消订阅
|
|
25
|
+
CANCELED: 'canceled',
|
|
26
|
+
};
|
|
27
|
+
const OrderStatus = {
|
|
28
|
+
// 初始状态
|
|
29
|
+
CREATED: 'created',
|
|
30
|
+
// 中间状态,待支付,可能是支付失败事件触发
|
|
31
|
+
PENDING_UNPAID: 'pending_unpaid',
|
|
32
|
+
// 中间状态(也可是最终状态),支付成功,后续可变为「退款或取消」
|
|
33
|
+
SUCCESS: 'success',
|
|
34
|
+
// 中间状态(也可是最终状态),CheckOut失败或者是支付失败,后续可变为「退款或取消」
|
|
35
|
+
FAILED: 'failed',
|
|
36
|
+
// 最终状态,已退款
|
|
37
|
+
REFUNDED: 'refunded',
|
|
38
|
+
// 最终状态,已取消
|
|
39
|
+
CANCELED: 'canceled',
|
|
40
|
+
};
|
|
41
|
+
const TransactionType = {
|
|
42
|
+
// 订阅订单
|
|
43
|
+
SUBSCRIPTION: 'subscription',
|
|
44
|
+
// 即付订单
|
|
45
|
+
ONE_TIME: 'one_time',
|
|
46
|
+
};
|
|
47
|
+
const CreditType = {
|
|
48
|
+
// 订阅积分
|
|
49
|
+
PAID: 'paid',
|
|
50
|
+
// 即付积分
|
|
51
|
+
ONE_TIME_PAID: 'one_time_paid',
|
|
52
|
+
// 免费积分
|
|
53
|
+
FREE: 'free',
|
|
54
|
+
};
|
|
55
|
+
const OperationType = {
|
|
56
|
+
// 系统奖励积分
|
|
57
|
+
SYS_GIFT: 'system_gift',
|
|
58
|
+
// 用户消费积分
|
|
59
|
+
CONSUME: 'consume',
|
|
60
|
+
// 用户充值积分
|
|
61
|
+
RECHARGE: 'recharge',
|
|
62
|
+
// 管理员介入冻结积分
|
|
63
|
+
FREEZE: 'freeze',
|
|
64
|
+
// 管理员介入解冻积分
|
|
65
|
+
UNFREEZE: 'unfreeze',
|
|
66
|
+
// 管理员介入赠送积分
|
|
67
|
+
ADJUST_INCREASE: 'adjust_increase',
|
|
68
|
+
// 管理员介入抹去积分
|
|
69
|
+
ADJUST_DECREASE: 'adjust_decrease',
|
|
70
|
+
// 清理积分,事件触发或者是积分过期触发
|
|
71
|
+
PURGE: 'purge',
|
|
72
|
+
};
|
|
73
|
+
// 支付厂商类型
|
|
74
|
+
const PaySupplier = {
|
|
75
|
+
STRIPE: 'Stripe',
|
|
76
|
+
APPLE: 'Apple',
|
|
77
|
+
PAYPAL: 'Paypal',
|
|
78
|
+
};
|
|
79
|
+
const BillingReason = {
|
|
80
|
+
// 首次订阅
|
|
81
|
+
SUBSCRIPTION_CREATE: 'subscription_create',
|
|
82
|
+
// 续订
|
|
83
|
+
SUBSCRIPTION_CYCLE: 'subscription_cycle',
|
|
84
|
+
};
|
|
85
|
+
const PaymentStatus = {
|
|
86
|
+
// 已支付
|
|
87
|
+
PAID: 'paid',
|
|
88
|
+
// 待支付
|
|
89
|
+
UN_PAID: 'un_paid',
|
|
90
|
+
// 无需支付
|
|
91
|
+
NO_PAYMENT_REQUIRED: 'no_payment_required',
|
|
92
|
+
};
|
|
93
|
+
// Validation Functions
|
|
94
|
+
const isValidUserStatus = (status) => {
|
|
95
|
+
return Object.values(UserStatus).includes(status);
|
|
96
|
+
};
|
|
97
|
+
const isValidSubscriptionStatus = (status) => {
|
|
98
|
+
return Object.values(SubscriptionStatus).includes(status);
|
|
99
|
+
};
|
|
100
|
+
const isValidOrderStatus = (status) => {
|
|
101
|
+
return Object.values(OrderStatus).includes(status);
|
|
102
|
+
};
|
|
103
|
+
const isValidTransactionType = (type) => {
|
|
104
|
+
return Object.values(TransactionType).includes(type);
|
|
105
|
+
};
|
|
106
|
+
const isValidCreditType = (type) => {
|
|
107
|
+
return Object.values(CreditType).includes(type);
|
|
108
|
+
};
|
|
109
|
+
const isValidOperationType = (type) => {
|
|
110
|
+
return Object.values(OperationType).includes(type);
|
|
111
|
+
};
|
|
112
|
+
const isValidBillingReason = (reason) => {
|
|
113
|
+
return Object.values(BillingReason).includes(reason);
|
|
114
|
+
};
|
|
115
|
+
const isValidPaymentStatus = (status) => {
|
|
116
|
+
return Object.values(PaymentStatus).includes(status);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
exports.BillingReason = BillingReason;
|
|
120
|
+
exports.CreditType = CreditType;
|
|
121
|
+
exports.OperationType = OperationType;
|
|
122
|
+
exports.OrderStatus = OrderStatus;
|
|
123
|
+
exports.PaySupplier = PaySupplier;
|
|
124
|
+
exports.PaymentStatus = PaymentStatus;
|
|
125
|
+
exports.SubscriptionStatus = SubscriptionStatus;
|
|
126
|
+
exports.TransactionType = TransactionType;
|
|
127
|
+
exports.UserStatus = UserStatus;
|
|
128
|
+
exports.isValidBillingReason = isValidBillingReason;
|
|
129
|
+
exports.isValidCreditType = isValidCreditType;
|
|
130
|
+
exports.isValidOperationType = isValidOperationType;
|
|
131
|
+
exports.isValidOrderStatus = isValidOrderStatus;
|
|
132
|
+
exports.isValidPaymentStatus = isValidPaymentStatus;
|
|
133
|
+
exports.isValidSubscriptionStatus = isValidSubscriptionStatus;
|
|
134
|
+
exports.isValidTransactionType = isValidTransactionType;
|
|
135
|
+
exports.isValidUserStatus = isValidUserStatus;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Database Field Enums
|
|
2
|
+
// Keep in sync with DB CHECK constraints
|
|
3
|
+
const UserStatus = {
|
|
4
|
+
// 匿名用户
|
|
5
|
+
ANONYMOUS: 'anonymous',
|
|
6
|
+
// 注册用户
|
|
7
|
+
REGISTERED: 'registered',
|
|
8
|
+
// 管理员介入管控
|
|
9
|
+
FROZEN: 'frozen',
|
|
10
|
+
// 用户注销,数据软删除,用户数据将不可复用
|
|
11
|
+
DELETED: 'deleted',
|
|
12
|
+
};
|
|
13
|
+
const SubscriptionStatus = {
|
|
14
|
+
// 初始状态或注销后状态
|
|
15
|
+
INCOMPLETE: 'incomplete',
|
|
16
|
+
// 订阅试用期
|
|
17
|
+
TRIALING: 'trialing',
|
|
18
|
+
// 有效订阅激活
|
|
19
|
+
ACTIVE: 'active',
|
|
20
|
+
// 订阅过期
|
|
21
|
+
PAST_DUE: 'past_due',
|
|
22
|
+
// 取消订阅
|
|
23
|
+
CANCELED: 'canceled',
|
|
24
|
+
};
|
|
25
|
+
const OrderStatus = {
|
|
26
|
+
// 初始状态
|
|
27
|
+
CREATED: 'created',
|
|
28
|
+
// 中间状态,待支付,可能是支付失败事件触发
|
|
29
|
+
PENDING_UNPAID: 'pending_unpaid',
|
|
30
|
+
// 中间状态(也可是最终状态),支付成功,后续可变为「退款或取消」
|
|
31
|
+
SUCCESS: 'success',
|
|
32
|
+
// 中间状态(也可是最终状态),CheckOut失败或者是支付失败,后续可变为「退款或取消」
|
|
33
|
+
FAILED: 'failed',
|
|
34
|
+
// 最终状态,已退款
|
|
35
|
+
REFUNDED: 'refunded',
|
|
36
|
+
// 最终状态,已取消
|
|
37
|
+
CANCELED: 'canceled',
|
|
38
|
+
};
|
|
39
|
+
const TransactionType = {
|
|
40
|
+
// 订阅订单
|
|
41
|
+
SUBSCRIPTION: 'subscription',
|
|
42
|
+
// 即付订单
|
|
43
|
+
ONE_TIME: 'one_time',
|
|
44
|
+
};
|
|
45
|
+
const CreditType = {
|
|
46
|
+
// 订阅积分
|
|
47
|
+
PAID: 'paid',
|
|
48
|
+
// 即付积分
|
|
49
|
+
ONE_TIME_PAID: 'one_time_paid',
|
|
50
|
+
// 免费积分
|
|
51
|
+
FREE: 'free',
|
|
52
|
+
};
|
|
53
|
+
const OperationType = {
|
|
54
|
+
// 系统奖励积分
|
|
55
|
+
SYS_GIFT: 'system_gift',
|
|
56
|
+
// 用户消费积分
|
|
57
|
+
CONSUME: 'consume',
|
|
58
|
+
// 用户充值积分
|
|
59
|
+
RECHARGE: 'recharge',
|
|
60
|
+
// 管理员介入冻结积分
|
|
61
|
+
FREEZE: 'freeze',
|
|
62
|
+
// 管理员介入解冻积分
|
|
63
|
+
UNFREEZE: 'unfreeze',
|
|
64
|
+
// 管理员介入赠送积分
|
|
65
|
+
ADJUST_INCREASE: 'adjust_increase',
|
|
66
|
+
// 管理员介入抹去积分
|
|
67
|
+
ADJUST_DECREASE: 'adjust_decrease',
|
|
68
|
+
// 清理积分,事件触发或者是积分过期触发
|
|
69
|
+
PURGE: 'purge',
|
|
70
|
+
};
|
|
71
|
+
// 支付厂商类型
|
|
72
|
+
const PaySupplier = {
|
|
73
|
+
STRIPE: 'Stripe',
|
|
74
|
+
APPLE: 'Apple',
|
|
75
|
+
PAYPAL: 'Paypal',
|
|
76
|
+
};
|
|
77
|
+
const BillingReason = {
|
|
78
|
+
// 首次订阅
|
|
79
|
+
SUBSCRIPTION_CREATE: 'subscription_create',
|
|
80
|
+
// 续订
|
|
81
|
+
SUBSCRIPTION_CYCLE: 'subscription_cycle',
|
|
82
|
+
};
|
|
83
|
+
const PaymentStatus = {
|
|
84
|
+
// 已支付
|
|
85
|
+
PAID: 'paid',
|
|
86
|
+
// 待支付
|
|
87
|
+
UN_PAID: 'un_paid',
|
|
88
|
+
// 无需支付
|
|
89
|
+
NO_PAYMENT_REQUIRED: 'no_payment_required',
|
|
90
|
+
};
|
|
91
|
+
// Validation Functions
|
|
92
|
+
const isValidUserStatus = (status) => {
|
|
93
|
+
return Object.values(UserStatus).includes(status);
|
|
94
|
+
};
|
|
95
|
+
const isValidSubscriptionStatus = (status) => {
|
|
96
|
+
return Object.values(SubscriptionStatus).includes(status);
|
|
97
|
+
};
|
|
98
|
+
const isValidOrderStatus = (status) => {
|
|
99
|
+
return Object.values(OrderStatus).includes(status);
|
|
100
|
+
};
|
|
101
|
+
const isValidTransactionType = (type) => {
|
|
102
|
+
return Object.values(TransactionType).includes(type);
|
|
103
|
+
};
|
|
104
|
+
const isValidCreditType = (type) => {
|
|
105
|
+
return Object.values(CreditType).includes(type);
|
|
106
|
+
};
|
|
107
|
+
const isValidOperationType = (type) => {
|
|
108
|
+
return Object.values(OperationType).includes(type);
|
|
109
|
+
};
|
|
110
|
+
const isValidBillingReason = (reason) => {
|
|
111
|
+
return Object.values(BillingReason).includes(reason);
|
|
112
|
+
};
|
|
113
|
+
const isValidPaymentStatus = (status) => {
|
|
114
|
+
return Object.values(PaymentStatus).includes(status);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export { BillingReason, CreditType, OperationType, OrderStatus, PaySupplier, PaymentStatus, SubscriptionStatus, TransactionType, UserStatus, isValidBillingReason, isValidCreditType, isValidOperationType, isValidOrderStatus, isValidPaymentStatus, isValidSubscriptionStatus, isValidTransactionType, isValidUserStatus };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Prisma } from './prisma-model-type';
|
|
2
|
+
import type { Credit, CreditAuditLog } from './prisma-model-type';
|
|
3
|
+
type CreditAmounts = {
|
|
4
|
+
free?: number;
|
|
5
|
+
paid?: number;
|
|
6
|
+
oneTimePaid?: number;
|
|
7
|
+
};
|
|
8
|
+
type CreditLimitAdjustments = {
|
|
9
|
+
free?: number;
|
|
10
|
+
paid?: number;
|
|
11
|
+
oneTimePaid?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare class CreditService {
|
|
14
|
+
private normalizeAmounts;
|
|
15
|
+
private hasAnyChange;
|
|
16
|
+
private ensureNonNegative;
|
|
17
|
+
private ensureSufficientBalance;
|
|
18
|
+
private ensureSufficientLimits;
|
|
19
|
+
private buildIncrementData;
|
|
20
|
+
private buildDecrementData;
|
|
21
|
+
private executeCreditOperation;
|
|
22
|
+
private recordCreditAuditLog;
|
|
23
|
+
initializeCreditWithFree(init: {
|
|
24
|
+
userId: string;
|
|
25
|
+
feature: string;
|
|
26
|
+
creditType: string;
|
|
27
|
+
operationType: string;
|
|
28
|
+
operationReferId: string;
|
|
29
|
+
creditsChange: number;
|
|
30
|
+
}, tx?: Prisma.TransactionClient): Promise<Credit>;
|
|
31
|
+
payFailedWatcher(data: {
|
|
32
|
+
userId: string;
|
|
33
|
+
feature: string;
|
|
34
|
+
creditType: string;
|
|
35
|
+
operationType: string;
|
|
36
|
+
operationReferId: string;
|
|
37
|
+
creditsChange: number;
|
|
38
|
+
}, tx?: Prisma.TransactionClient): Promise<void>;
|
|
39
|
+
getCredit(userId: string, tx?: Prisma.TransactionClient): Promise<Credit | null>;
|
|
40
|
+
getTotalBalance(userId: string, tx?: Prisma.TransactionClient): Promise<number>;
|
|
41
|
+
rechargeCredit(userId: string, amounts: CreditAmounts, options: {
|
|
42
|
+
operationReferId: string;
|
|
43
|
+
feature?: string;
|
|
44
|
+
limitAdjustments?: CreditLimitAdjustments;
|
|
45
|
+
}, tx?: Prisma.TransactionClient): Promise<{
|
|
46
|
+
credit: Credit;
|
|
47
|
+
usage: CreditAuditLog[];
|
|
48
|
+
}>;
|
|
49
|
+
consumeCredit(userId: string, amounts: CreditAmounts, options: {
|
|
50
|
+
feature: string;
|
|
51
|
+
operationReferId: string;
|
|
52
|
+
}, tx?: Prisma.TransactionClient): Promise<{
|
|
53
|
+
credit: Credit;
|
|
54
|
+
usage: CreditAuditLog[];
|
|
55
|
+
}>;
|
|
56
|
+
freezeCredit(userId: string, amounts: CreditAmounts, reason: string, operationReferId: string, tx?: Prisma.TransactionClient): Promise<{
|
|
57
|
+
credit: Credit;
|
|
58
|
+
usage: CreditAuditLog[];
|
|
59
|
+
}>;
|
|
60
|
+
unfreezeCredit(userId: string, amounts: CreditAmounts, reason: string, operationReferId: string, tx?: Prisma.TransactionClient): Promise<{
|
|
61
|
+
credit: Credit;
|
|
62
|
+
usage: CreditAuditLog[];
|
|
63
|
+
}>;
|
|
64
|
+
refundCredit(userId: string, amounts: CreditAmounts, operationReferId: string, options?: {
|
|
65
|
+
feature?: string;
|
|
66
|
+
limitAdjustments?: CreditLimitAdjustments;
|
|
67
|
+
}, tx?: Prisma.TransactionClient): Promise<{
|
|
68
|
+
credit: Credit;
|
|
69
|
+
usage: CreditAuditLog[];
|
|
70
|
+
}>;
|
|
71
|
+
adjustCredit(userId: string, operationReferId: string, adjustments: {
|
|
72
|
+
balanceFree?: number;
|
|
73
|
+
balancePaid?: number;
|
|
74
|
+
balanceOneTimePaid?: number;
|
|
75
|
+
totalFreeLimit?: number;
|
|
76
|
+
totalPaidLimit?: number;
|
|
77
|
+
totalOneTimePaidLimit?: number;
|
|
78
|
+
}, tx?: Prisma.TransactionClient): Promise<Credit>;
|
|
79
|
+
private purgeCreditsByTypes;
|
|
80
|
+
purgePaidCredit(userId: string, reason: string, operationReferId: string, tx?: Prisma.TransactionClient): Promise<{
|
|
81
|
+
credit: Credit;
|
|
82
|
+
usage: CreditAuditLog[];
|
|
83
|
+
}>;
|
|
84
|
+
purgeFreeCredit(userId: string, reason: string, operationReferId: string, tx?: Prisma.TransactionClient): Promise<{
|
|
85
|
+
credit: Credit;
|
|
86
|
+
usage: CreditAuditLog[];
|
|
87
|
+
}>;
|
|
88
|
+
purgeCredit(userId: string, reason: string, operationReferId: string, tx?: Prisma.TransactionClient): Promise<{
|
|
89
|
+
credit: Credit;
|
|
90
|
+
usage: CreditAuditLog[];
|
|
91
|
+
}>;
|
|
92
|
+
getLowBalanceUsers(threshold?: number, tx?: Prisma.TransactionClient): Promise<Credit[]>;
|
|
93
|
+
getCreditStats(tx?: Prisma.TransactionClient): Promise<{
|
|
94
|
+
totalUsers: number;
|
|
95
|
+
totalFreeBalance: number;
|
|
96
|
+
totalPaidBalance: number;
|
|
97
|
+
totalOneTimePaidBalance: number;
|
|
98
|
+
avgFreeBalance: number;
|
|
99
|
+
avgPaidBalance: number;
|
|
100
|
+
avgOneTimePaidBalance: number;
|
|
101
|
+
zeroBalanceUsers: number;
|
|
102
|
+
}>;
|
|
103
|
+
hasEnoughCredits(userId: string, amount: number, tx?: Prisma.TransactionClient): Promise<boolean>;
|
|
104
|
+
}
|
|
105
|
+
export declare const creditService: CreditService;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=credit.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../../src/services/database/credit.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMlE,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAuDF,qBAAa,aAAa;IAExB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,kBAAkB;YA0BZ,sBAAsB;YAuDtB,oBAAoB;IA2D5B,wBAAwB,CAC5B,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CA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