@windrun-huaiin/backend-core 26.0.2 → 28.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/api/ai/route.d.ts +2 -0
- package/dist/app/api/ai/route.d.ts.map +1 -0
- package/dist/app/api/ai/route.js +10 -0
- package/dist/app/api/ai/route.mjs +1 -0
- package/dist/app/api/stripe/checkout/route.js +1 -1
- package/dist/app/api/stripe/checkout/route.mjs +1 -1
- package/dist/app/api/stripe/customer-portal/route.js +1 -1
- package/dist/app/api/stripe/customer-portal/route.mjs +1 -1
- package/dist/app/api/webhook/clerk/user/route.js +1 -1
- package/dist/app/api/webhook/clerk/user/route.mjs +1 -1
- package/dist/auth/auth-utils.js +1 -1
- package/dist/auth/auth-utils.mjs +1 -1
- package/dist/config/fingerprint.d.ts +2 -0
- package/dist/config/fingerprint.d.ts.map +1 -0
- package/dist/config/fingerprint.js +7 -0
- package/dist/config/fingerprint.mjs +1 -0
- package/dist/config/money-price.d.ts +2 -0
- package/dist/config/money-price.d.ts.map +1 -0
- package/dist/config/money-price.js +10 -0
- package/dist/config/money-price.mjs +1 -0
- package/dist/core-prisma/browser.d.ts +40 -0
- package/dist/core-prisma/browser.d.ts.map +1 -0
- package/dist/core-prisma/client.d.ts +57 -0
- package/dist/core-prisma/client.d.ts.map +1 -0
- package/dist/core-prisma/client.js +55 -0
- package/dist/core-prisma/client.mjs +33 -0
- package/dist/core-prisma/commonInputTypes.d.ts +495 -0
- package/dist/core-prisma/commonInputTypes.d.ts.map +1 -0
- package/dist/core-prisma/enums.d.ts +2 -0
- package/dist/core-prisma/enums.d.ts.map +1 -0
- package/dist/core-prisma/internal/class.d.ts +193 -0
- package/dist/core-prisma/internal/class.d.ts.map +1 -0
- package/dist/core-prisma/internal/class.js +108 -0
- package/dist/core-prisma/internal/class.mjs +87 -0
- package/dist/core-prisma/internal/prismaNamespace.d.ts +1180 -0
- package/dist/core-prisma/internal/prismaNamespace.d.ts.map +1 -0
- package/dist/core-prisma/internal/prismaNamespace.js +278 -0
- package/dist/core-prisma/internal/prismaNamespace.mjs +226 -0
- package/dist/core-prisma/internal/prismaNamespaceBrowser.d.ts +233 -0
- package/dist/core-prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -0
- package/dist/core-prisma/models/Apilog.d.ts +1088 -0
- package/dist/core-prisma/models/Apilog.d.ts.map +1 -0
- package/dist/core-prisma/models/Credit.d.ts +1554 -0
- package/dist/core-prisma/models/Credit.d.ts.map +1 -0
- package/dist/core-prisma/models/CreditAuditLog.d.ts +1362 -0
- package/dist/core-prisma/models/CreditAuditLog.d.ts.map +1 -0
- package/dist/core-prisma/models/Subscription.d.ts +1441 -0
- package/dist/core-prisma/models/Subscription.d.ts.map +1 -0
- package/dist/core-prisma/models/Transaction.d.ts +2222 -0
- package/dist/core-prisma/models/Transaction.d.ts.map +1 -0
- package/dist/core-prisma/models/User.d.ts +1775 -0
- package/dist/core-prisma/models/User.d.ts.map +1 -0
- package/dist/core-prisma/models/UserBackup.d.ts +1228 -0
- package/dist/core-prisma/models/UserBackup.d.ts.map +1 -0
- package/dist/core-prisma/models.d.ts +9 -0
- package/dist/core-prisma/models.d.ts.map +1 -0
- package/dist/credit/server.d.ts +2 -0
- package/dist/credit/server.d.ts.map +1 -0
- package/dist/credit/server.js +11 -0
- package/dist/credit/server.mjs +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -98
- package/dist/index.mjs +5 -14
- package/dist/lib/money-price-helper.d.ts.map +1 -1
- package/dist/lib/money-price-helper.js +1 -0
- package/dist/lib/money-price-helper.mjs +2 -1
- package/dist/lib/stripe-config.js +1 -1
- package/dist/lib/stripe-config.mjs +1 -1
- package/dist/pricing/server.d.ts +2 -0
- package/dist/pricing/server.d.ts.map +1 -0
- package/dist/pricing/server.js +7 -0
- package/dist/pricing/server.mjs +1 -0
- package/dist/prisma/index.d.ts +4 -1
- package/dist/prisma/index.d.ts.map +1 -1
- package/dist/prisma/index.js +6 -0
- package/dist/prisma/index.mjs +4 -1
- package/dist/prisma/prisma-transaction-util.d.ts +1 -1
- package/dist/prisma/prisma-transaction-util.d.ts.map +1 -1
- package/dist/prisma/prisma-transaction-util.js +1 -1
- package/dist/prisma/prisma-transaction-util.mjs +2 -2
- package/dist/prisma/prisma.d.ts +22 -3
- package/dist/prisma/prisma.d.ts.map +1 -1
- package/dist/prisma/prisma.js +83 -20
- package/dist/prisma/prisma.mjs +81 -21
- package/dist/services/aggregate/anonymous.aggregate.service.d.ts +2 -2
- package/dist/services/aggregate/anonymous.aggregate.service.d.ts.map +1 -1
- package/dist/services/aggregate/anonymous.aggregate.service.js +3 -2
- package/dist/services/aggregate/anonymous.aggregate.service.mjs +3 -2
- package/dist/services/aggregate/billing.aggregate.service.d.ts +2 -2
- package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -1
- package/dist/services/aggregate/billing.aggregate.service.js +1 -1
- package/dist/services/aggregate/billing.aggregate.service.mjs +1 -1
- package/dist/services/aggregate/user.aggregate.service.d.ts +1 -1
- package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -1
- package/dist/services/aggregate/user.aggregate.service.js +3 -3
- package/dist/services/aggregate/user.aggregate.service.mjs +3 -3
- package/dist/services/context/index.js +1 -0
- package/dist/services/context/index.mjs +1 -1
- package/dist/services/context/user-context-finalizer.d.ts +1 -0
- package/dist/services/context/user-context-finalizer.d.ts.map +1 -1
- package/dist/services/context/user-context-finalizer.js +17 -0
- package/dist/services/context/user-context-finalizer.mjs +17 -1
- package/dist/services/context/user-context-service.js +1 -1
- package/dist/services/context/user-context-service.mjs +1 -1
- package/dist/services/database/apilog.service.d.ts +2 -2
- package/dist/services/database/apilog.service.d.ts.map +1 -1
- package/dist/services/database/apilog.service.js +1 -0
- package/dist/services/database/apilog.service.mjs +1 -0
- package/dist/services/database/credit.service.d.ts +2 -2
- package/dist/services/database/credit.service.d.ts.map +1 -1
- package/dist/services/database/credit.service.js +5 -4
- package/dist/services/database/credit.service.mjs +3 -2
- package/dist/services/database/creditAuditLog.service.d.ts +2 -2
- package/dist/services/database/creditAuditLog.service.d.ts.map +1 -1
- package/dist/services/database/creditAuditLog.service.js +5 -4
- package/dist/services/database/creditAuditLog.service.mjs +3 -2
- package/dist/services/database/prisma-model-type.d.ts +2 -2
- package/dist/services/database/prisma-model-type.d.ts.map +1 -1
- package/dist/services/database/subscription.service.d.ts +1 -1
- package/dist/services/database/subscription.service.d.ts.map +1 -1
- package/dist/services/database/subscription.service.js +1 -0
- package/dist/services/database/subscription.service.mjs +1 -0
- package/dist/services/database/transaction.service.d.ts +3 -3
- package/dist/services/database/transaction.service.d.ts.map +1 -1
- package/dist/services/database/transaction.service.js +5 -4
- package/dist/services/database/transaction.service.mjs +3 -2
- package/dist/services/database/user.service.d.ts +2 -2
- package/dist/services/database/user.service.d.ts.map +1 -1
- package/dist/services/database/user.service.js +1 -0
- package/dist/services/database/user.service.mjs +1 -0
- package/dist/services/database/userBackup.service.d.ts +2 -2
- package/dist/services/database/userBackup.service.d.ts.map +1 -1
- package/dist/services/database/userBackup.service.js +1 -0
- package/dist/services/database/userBackup.service.mjs +1 -0
- package/dist/services/stripe/webhook-handler.js +1 -1
- package/dist/services/stripe/webhook-handler.mjs +1 -1
- package/dist/upstash/server.d.ts +3 -0
- package/dist/upstash/server.d.ts.map +1 -0
- package/dist/{lib/index.js → upstash/server.js} +7 -32
- package/dist/upstash/server.mjs +7 -0
- package/package.json +44 -12
- package/prisma/schema.prisma +3 -1
- package/src/app/api/ai/route.ts +6 -0
- package/src/app/api/stripe/checkout/route.ts +4 -4
- package/src/app/api/stripe/customer-portal/route.ts +3 -3
- package/src/app/api/user/anonymous/init/route.ts +5 -5
- package/src/app/api/webhook/clerk/user/route.ts +3 -3
- package/src/app/api/webhook/stripe/route.ts +3 -3
- package/src/config/fingerprint.ts +1 -0
- package/src/config/money-price.ts +1 -0
- package/src/core-prisma/browser.ts +54 -0
- package/src/core-prisma/client.ts +78 -0
- package/src/core-prisma/commonInputTypes.ts +565 -0
- package/src/core-prisma/enums.ts +15 -0
- package/src/core-prisma/internal/class.ts +293 -0
- package/src/core-prisma/internal/prismaNamespace.ts +1419 -0
- package/src/core-prisma/internal/prismaNamespaceBrowser.ts +259 -0
- package/src/core-prisma/models/Apilog.ts +1244 -0
- package/src/core-prisma/models/Credit.ts +1722 -0
- package/src/core-prisma/models/CreditAuditLog.ts +1536 -0
- package/src/core-prisma/models/Subscription.ts +1610 -0
- package/src/core-prisma/models/Transaction.ts +2398 -0
- package/src/core-prisma/models/User.ts +1982 -0
- package/src/core-prisma/models/UserBackup.ts +1384 -0
- package/src/core-prisma/models.ts +18 -0
- package/src/credit/server.ts +1 -0
- package/src/index.ts +0 -1
- package/src/lib/money-price-helper.ts +3 -0
- package/src/pricing/server.ts +1 -0
- package/src/prisma/index.ts +18 -1
- package/src/prisma/prisma-transaction-util.ts +3 -3
- package/src/prisma/prisma.ts +130 -21
- package/src/services/aggregate/anonymous.aggregate.service.ts +7 -7
- package/src/services/aggregate/billing.aggregate.service.ts +3 -3
- package/src/services/aggregate/user.aggregate.service.ts +7 -6
- package/src/services/context/user-context-finalizer.ts +16 -0
- package/src/services/database/apilog.service.ts +3 -3
- package/src/services/database/credit.service.ts +7 -7
- package/src/services/database/creditAuditLog.service.ts +4 -4
- package/src/services/database/prisma-model-type.ts +2 -2
- package/src/services/database/subscription.service.ts +3 -3
- package/src/services/database/transaction.service.ts +4 -4
- package/src/services/database/user.service.ts +4 -4
- package/src/services/database/userBackup.service.ts +4 -4
- package/src/services/stripe/webhook-handler.ts +6 -6
- package/src/upstash/server.ts +2 -0
- package/dist/lib/index.d.ts +0 -8
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.mjs +0 -12
- package/src/lib/index.ts +0 -7
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
// biome-ignore-all lint: generated file
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
/*
|
|
7
|
+
* This is a barrel export file for all models and their related types.
|
|
8
|
+
*
|
|
9
|
+
* 🟢 You can import this file directly.
|
|
10
|
+
*/
|
|
11
|
+
export type * from './models/User'
|
|
12
|
+
export type * from './models/Subscription'
|
|
13
|
+
export type * from './models/Credit'
|
|
14
|
+
export type * from './models/Transaction'
|
|
15
|
+
export type * from './models/CreditAuditLog'
|
|
16
|
+
export type * from './models/UserBackup'
|
|
17
|
+
export type * from './models/Apilog'
|
|
18
|
+
export type * from './commonInputTypes'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../lib/credit-init';
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import type { InitUserContext } from '@windrun-huaiin/third-ui/main/server';
|
|
6
6
|
import { getOptionalServerAuthIdentity } from '../auth/auth-utils';
|
|
7
7
|
import {
|
|
8
|
+
applyMoneyPriceMockUserDelay,
|
|
8
9
|
buildInitUserContextFromEntities,
|
|
9
10
|
fetchUserContextByClerkUserId,
|
|
10
11
|
finalizeUserContext,
|
|
@@ -21,6 +22,8 @@ async function readFingerprintIdFromRequest(): Promise<string | null> {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export async function getMoneyPriceInitUserContext(): Promise<InitUserContext> {
|
|
25
|
+
await applyMoneyPriceMockUserDelay();
|
|
26
|
+
|
|
24
27
|
const authIdentity = await getOptionalServerAuthIdentity();
|
|
25
28
|
const clerkUserId = authIdentity?.providerUserId ?? null;
|
|
26
29
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../lib/money-price-helper';
|
package/src/prisma/index.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
prisma,
|
|
3
|
+
createPrismaClient,
|
|
4
|
+
configureBackendCorePrisma,
|
|
5
|
+
getBackendCorePrisma,
|
|
6
|
+
checkAndFallbackWithNonTCClient,
|
|
7
|
+
} from './prisma';
|
|
8
|
+
export type { BackendCorePrismaClient, BackendCoreHostPrismaClient } from './prisma';
|
|
2
9
|
export { runInTransaction } from './prisma-transaction-util';
|
|
10
|
+
export type {
|
|
11
|
+
User,
|
|
12
|
+
Subscription,
|
|
13
|
+
Credit,
|
|
14
|
+
CreditAuditLog,
|
|
15
|
+
Transaction,
|
|
16
|
+
Apilog,
|
|
17
|
+
UserBackup,
|
|
18
|
+
} from '../core-prisma/client';
|
|
19
|
+
export { Prisma } from '../core-prisma/client';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Prisma } from '
|
|
1
|
+
import { getBackendCorePrisma } from './prisma';
|
|
2
|
+
import { Prisma } from '../core-prisma/client';
|
|
3
3
|
|
|
4
4
|
// 事务工具类,回滚时打印回滚日志
|
|
5
5
|
export async function runInTransaction<T>(
|
|
@@ -8,7 +8,7 @@ export async function runInTransaction<T>(
|
|
|
8
8
|
): Promise<T> {
|
|
9
9
|
const start = Date.now();
|
|
10
10
|
try {
|
|
11
|
-
return await
|
|
11
|
+
return await getBackendCorePrisma().$transaction(fn);
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
13
|
} catch (error: any) {
|
|
14
14
|
const duration = Date.now() - start;
|
package/src/prisma/prisma.ts
CHANGED
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
2
|
+
import { PrismaClient, Prisma } from '../core-prisma/client';
|
|
3
|
+
|
|
4
|
+
type AppPrismaClient = PrismaClient<'query' | 'info' | 'warn' | 'error'>;
|
|
5
|
+
export type BackendCorePrismaClient = AppPrismaClient;
|
|
6
|
+
export type BackendCoreHostPrismaClient = {
|
|
7
|
+
// Deliberately loose: host applications generate their own Prisma Client,
|
|
8
|
+
// so transaction overloads are structurally compatible at runtime but not
|
|
9
|
+
// nominally identical to backend-core's generated client types.
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
$transaction: any;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
$on?: any;
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
$executeRaw: any;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
$queryRaw: any;
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
user: any;
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
subscription: any;
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
credit: any;
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
transaction: any;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
creditAuditLog: any;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
userBackup: any;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
apilog: any;
|
|
32
|
+
};
|
|
2
33
|
|
|
3
34
|
const globalForPrisma = globalThis as unknown as {
|
|
4
|
-
prisma?:
|
|
35
|
+
prisma?: BackendCoreHostPrismaClient;
|
|
5
36
|
__prisma_query_logger_registered?: boolean;
|
|
6
37
|
__prisma_query_logger_id?: string;
|
|
38
|
+
__prisma_instance_id?: string;
|
|
39
|
+
__prisma_ssl_warning_logged?: boolean;
|
|
7
40
|
};
|
|
8
41
|
|
|
9
42
|
// ==================== 日志配置 ====================
|
|
10
43
|
const getLogConfig = () => {
|
|
44
|
+
if (process.env.PRISMA_DEBUG === 'true') {
|
|
45
|
+
return [
|
|
46
|
+
{ emit: 'event' as const, level: 'query' as const },
|
|
47
|
+
{ emit: 'stdout' as const, level: 'info' as const },
|
|
48
|
+
{ emit: 'stdout' as const, level: 'warn' as const },
|
|
49
|
+
{ emit: 'stdout' as const, level: 'error' as const },
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
|
|
11
53
|
const env = process.env.NODE_ENV || 'development';
|
|
12
54
|
switch (env) {
|
|
13
|
-
case 'development':
|
|
14
|
-
return [
|
|
15
|
-
{ emit: 'event' as const, level: 'query' as const },
|
|
16
|
-
{ emit: 'stdout' as const, level: 'info' as const },
|
|
17
|
-
{ emit: 'stdout' as const, level: 'warn' as const },
|
|
18
|
-
{ emit: 'stdout' as const, level: 'error' as const },
|
|
19
|
-
];
|
|
20
55
|
case 'test':
|
|
21
56
|
return [
|
|
22
57
|
{ emit: 'stdout' as const, level: 'warn' as const },
|
|
@@ -29,26 +64,99 @@ const getLogConfig = () => {
|
|
|
29
64
|
|
|
30
65
|
const logConfig = getLogConfig();
|
|
31
66
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
67
|
+
function isPrismaDebugEnabled() {
|
|
68
|
+
return process.env.PRISMA_DEBUG === 'true';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function createPrismaInstanceId(prefix = 'core-prisma') {
|
|
72
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createPrismaPgConfig(databaseUrl: string) {
|
|
76
|
+
const ca = process.env.SUPABASE_DB_CA_CERT;
|
|
77
|
+
|
|
78
|
+
if (!ca && !globalForPrisma.__prisma_ssl_warning_logged) {
|
|
79
|
+
console.warn(
|
|
80
|
+
'SUPABASE_DB_CA_CERT is not configured. Prisma will request TLS without certificate verification unless DATABASE_URL SSL parameters override this behavior. Configure SUPABASE_DB_CA_CERT for certificate verification.',
|
|
81
|
+
);
|
|
82
|
+
globalForPrisma.__prisma_ssl_warning_logged = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
connectionString: databaseUrl,
|
|
87
|
+
ssl: ca
|
|
88
|
+
? {
|
|
89
|
+
ca,
|
|
90
|
+
rejectUnauthorized: true,
|
|
91
|
+
}
|
|
92
|
+
: {
|
|
93
|
+
rejectUnauthorized: false,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function createPrismaClient(databaseUrl = process.env.DATABASE_URL): AppPrismaClient {
|
|
99
|
+
if (!databaseUrl) {
|
|
100
|
+
throw new Error('DATABASE_URL is required to create PrismaClient');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const adapter = new PrismaPg(createPrismaPgConfig(databaseUrl));
|
|
104
|
+
|
|
105
|
+
const instanceId = createPrismaInstanceId();
|
|
106
|
+
if (isPrismaDebugEnabled()) {
|
|
107
|
+
console.log(`Prisma Client Created | ID: ${instanceId}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const client = new PrismaClient({
|
|
111
|
+
adapter,
|
|
36
112
|
log: logConfig,
|
|
37
113
|
});
|
|
38
114
|
|
|
39
|
-
|
|
40
|
-
|
|
115
|
+
return configureBackendCorePrisma(client, instanceId) as AppPrismaClient;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function configureBackendCorePrisma(
|
|
119
|
+
prismaClient: BackendCoreHostPrismaClient,
|
|
120
|
+
instanceId = globalForPrisma.__prisma_instance_id ?? createPrismaInstanceId(),
|
|
121
|
+
): BackendCoreHostPrismaClient {
|
|
122
|
+
globalForPrisma.prisma = prismaClient;
|
|
123
|
+
globalForPrisma.__prisma_instance_id = instanceId;
|
|
124
|
+
registerDevelopmentQueryLogger(prismaClient, instanceId);
|
|
125
|
+
return prismaClient;
|
|
41
126
|
}
|
|
42
127
|
|
|
43
|
-
|
|
128
|
+
export function getBackendCorePrisma(): BackendCorePrismaClient {
|
|
129
|
+
if (!globalForPrisma.prisma) {
|
|
130
|
+
configureBackendCorePrisma(createPrismaClient());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return globalForPrisma.prisma as unknown as BackendCorePrismaClient;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Backward-compatible lazy export. Accessing a property creates the client,
|
|
137
|
+
// importing this module does not.
|
|
138
|
+
export const prisma = new Proxy({} as BackendCorePrismaClient, {
|
|
139
|
+
get(_target, property, receiver) {
|
|
140
|
+
return Reflect.get(getBackendCorePrisma(), property, receiver);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
function registerDevelopmentQueryLogger(prismaClient: BackendCoreHostPrismaClient, instanceId: string) {
|
|
145
|
+
if (!isPrismaDebugEnabled()) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
44
149
|
const REGISTERED_KEY = '__prisma_query_logger_registered';
|
|
45
150
|
const ID_KEY = '__prisma_query_logger_id';
|
|
46
151
|
|
|
47
152
|
if (globalForPrisma[REGISTERED_KEY]) {
|
|
48
|
-
console.log(
|
|
153
|
+
console.log(
|
|
154
|
+
`Prisma Query Logger Already Registered | Listener ID: ${globalForPrisma[ID_KEY]} | Instance ID: ${globalForPrisma.__prisma_instance_id}`,
|
|
155
|
+
);
|
|
49
156
|
} else {
|
|
50
157
|
const listenerId = `listener_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
|
|
51
158
|
globalForPrisma[ID_KEY] = listenerId;
|
|
159
|
+
console.log(`Prisma Query Logger Registered | Listener ID: ${listenerId} | Instance ID: ${instanceId}`);
|
|
52
160
|
|
|
53
161
|
// --- 自定义SQL拼接 ---
|
|
54
162
|
const interpolate = (query: string, params: string) => {
|
|
@@ -95,7 +203,7 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
95
203
|
};
|
|
96
204
|
|
|
97
205
|
const wrappedHandler = (event: Prisma.QueryEvent) => {
|
|
98
|
-
const ms = event.duration;
|
|
206
|
+
const ms = Math.round(event.duration);
|
|
99
207
|
const slow = ms >= 200 ? '🐌 SLOW SQL ' : '🚀 SQL';
|
|
100
208
|
|
|
101
209
|
const interpolatedSql = interpolate(event.query, event.params);
|
|
@@ -106,17 +214,18 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
106
214
|
.replace(/"/g, ''); // 彻底灭双引号
|
|
107
215
|
|
|
108
216
|
console.log('─'.repeat(60));
|
|
217
|
+
console.log(`Prisma Instance ID: ${instanceId} | Listener ID: ${listenerId}`);
|
|
109
218
|
console.log(`${clean};`);
|
|
110
219
|
console.log(`⏰ 耗时: ${ms}ms, ${slow}`);
|
|
111
220
|
};
|
|
112
221
|
// 注册包装后的 handler
|
|
113
|
-
|
|
222
|
+
prismaClient.$on?.('query' as never, wrappedHandler);
|
|
114
223
|
|
|
115
224
|
globalForPrisma[REGISTERED_KEY] = true;
|
|
116
225
|
}
|
|
117
226
|
}
|
|
118
227
|
|
|
119
228
|
// ==================== 便捷方法, 入参事务客户端不存在或者不传, 就返回全局非事务客户端 ====================
|
|
120
|
-
export function checkAndFallbackWithNonTCClient(tx?: Prisma.TransactionClient): Prisma.TransactionClient |
|
|
121
|
-
return tx ??
|
|
229
|
+
export function checkAndFallbackWithNonTCClient(tx?: Prisma.TransactionClient): Prisma.TransactionClient | BackendCorePrismaClient {
|
|
230
|
+
return tx ?? getBackendCorePrisma();
|
|
122
231
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { creditService, subscriptionService, userService } from '
|
|
2
|
-
import { UserStatus } from '
|
|
3
|
-
import type { Credit, Subscription, User } from '
|
|
4
|
-
import { freeAmount } from '
|
|
5
|
-
import { runInTransaction } from '
|
|
6
|
-
import { CreditType, OperationType } from '
|
|
7
|
-
import { Prisma } from '
|
|
1
|
+
import { creditService, subscriptionService, userService } from '@core/db';
|
|
2
|
+
import { UserStatus } from '@core/db/constants';
|
|
3
|
+
import type { Credit, Subscription, User } from '@core/db/prisma-model-type';
|
|
4
|
+
import { freeAmount } from '@core/lib/credit-init';
|
|
5
|
+
import { runInTransaction } from '@core/prisma/prisma-transaction-util';
|
|
6
|
+
import { CreditType, OperationType } from '@core/db/constants';
|
|
7
|
+
import { Prisma } from '@core/db/prisma-model-type';
|
|
8
8
|
|
|
9
9
|
const ANONYMOUS_INIT_LOCK_NAMESPACE = 92831;
|
|
10
10
|
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
SubscriptionStatus,
|
|
10
10
|
transactionService,
|
|
11
11
|
TransactionType,
|
|
12
|
-
} from '
|
|
13
|
-
import type { Subscription, Transaction } from '
|
|
14
|
-
import { runInTransaction } from '
|
|
12
|
+
} from '@core/db/index';
|
|
13
|
+
import type { Subscription, Transaction } from '@core/db/prisma-model-type';
|
|
14
|
+
import { runInTransaction } from '@core/prisma/prisma-transaction-util';
|
|
15
15
|
|
|
16
16
|
type NullableString = string | null | undefined;
|
|
17
17
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CreditType, OperationType, UserStatus } from '
|
|
2
|
-
import { creditService, subscriptionService, userService } from '
|
|
3
|
-
import type { Credit, Prisma, User } from '
|
|
4
|
-
import { freeAmount, freeRegisterAmount } from '
|
|
5
|
-
import { runInTransaction } from '
|
|
1
|
+
import { CreditType, OperationType, UserStatus } from '@core/db/constants';
|
|
2
|
+
import { creditService, subscriptionService, userService } from '@core/db/index';
|
|
3
|
+
import type { Credit, Prisma, User } from '@core/db/prisma-model-type';
|
|
4
|
+
import { freeAmount, freeRegisterAmount } from '@core/lib/credit-init';
|
|
5
|
+
import { runInTransaction } from '@core/prisma/prisma-transaction-util';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export class UserAggregateService {
|
|
@@ -81,6 +81,7 @@ export class UserAggregateService {
|
|
|
81
81
|
operationReferId: newUser.userId,
|
|
82
82
|
creditsChange: freeRegisterAmount,
|
|
83
83
|
},
|
|
84
|
+
tx
|
|
84
85
|
);
|
|
85
86
|
|
|
86
87
|
await subscriptionService.initializeSubscription(newUser.userId, tx);
|
|
@@ -135,7 +136,7 @@ export class UserAggregateService {
|
|
|
135
136
|
}
|
|
136
137
|
const userId = user.userId;
|
|
137
138
|
// 更改用户状态,保留user信息尤其是FingerprintId,防止反复注册薅羊毛
|
|
138
|
-
await userService.unregister(user.userId);
|
|
139
|
+
await userService.unregister(user.userId, tx);
|
|
139
140
|
// 清空积分
|
|
140
141
|
await creditService.purgeCredit(userId, 'soft_delete_user', userId, tx);
|
|
141
142
|
|
|
@@ -6,6 +6,22 @@ type FinalizableUserContext = {
|
|
|
6
6
|
xSubscription: XSubscription | null;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
const MAX_MONEY_PRICE_MOCK_DELAY_MS = 10000;
|
|
10
|
+
|
|
11
|
+
export async function applyMoneyPriceMockUserDelay(): Promise<void> {
|
|
12
|
+
if (process.env.MONEY_PRICE_MOCK_USER_ENABLED !== 'true') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const delaySeconds = Number(process.env.MONEY_PRICE_MOCK_USER_DELAY_SECONDS ?? 0);
|
|
17
|
+
if (!Number.isFinite(delaySeconds) || delaySeconds <= 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const delayMs = Math.min(Math.floor(delaySeconds * 1000), MAX_MONEY_PRICE_MOCK_DELAY_MS);
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Output finalizer for user-context payloads.
|
|
11
27
|
* Real data assembly should stay in user-context-service; any optional test-only
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import type { Prisma } from '
|
|
4
|
-
import type { Apilog } from '
|
|
5
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
+
import type { Prisma } from '@core/db/prisma-model-type';
|
|
4
|
+
import type { Apilog } from '@core/db/prisma-model-type';
|
|
5
|
+
import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
|
|
6
6
|
|
|
7
7
|
export type ApiType = 'from_clerk_in' | 'to_clerk_out' | 'from_stripe_in' | 'to_stripe_out';
|
|
8
8
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Prisma } from '
|
|
2
|
-
import type { Credit, CreditAuditLog } from '
|
|
3
|
-
import { CreditType, OperationType } from '
|
|
4
|
-
import { freeExpiredDays } from '
|
|
5
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
6
|
-
import { creditAuditLogService } from '
|
|
1
|
+
import { Prisma } from '@core/db/prisma-model-type';
|
|
2
|
+
import type { Credit, CreditAuditLog } from '@core/db/prisma-model-type';
|
|
3
|
+
import { CreditType, OperationType } from '@core/db/constants';
|
|
4
|
+
import { freeExpiredDays } from '@core/lib/credit-init';
|
|
5
|
+
import { checkAndFallbackWithNonTCClient, type BackendCorePrismaClient } from '@core/prisma/index';
|
|
6
|
+
import { creditAuditLogService } from '@core/db/creditAuditLog.service';
|
|
7
7
|
|
|
8
8
|
type CreditAmounts = {
|
|
9
9
|
free?: number;
|
|
@@ -222,7 +222,7 @@ export class CreditService {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
private async recordCreditAuditLog(
|
|
225
|
-
client: Prisma.TransactionClient,
|
|
225
|
+
client: Prisma.TransactionClient | BackendCorePrismaClient,
|
|
226
226
|
userId: string,
|
|
227
227
|
operationType: string,
|
|
228
228
|
amounts: Required<CreditAmounts>,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import { Prisma } from '
|
|
4
|
-
import type { CreditAuditLog } from '
|
|
5
|
-
import { CreditType, OperationType } from '
|
|
6
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
+
import { Prisma } from '@core/db/prisma-model-type';
|
|
4
|
+
import type { CreditAuditLog } from '@core/db/prisma-model-type';
|
|
5
|
+
import { CreditType, OperationType } from '@core/db/constants';
|
|
6
|
+
import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
|
|
7
7
|
|
|
8
8
|
export class CreditAuditLogService {
|
|
9
9
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SubscriptionStatus } from '
|
|
2
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
-
import type { Prisma, Subscription } from '
|
|
1
|
+
import { SubscriptionStatus } from '@core/db/constants';
|
|
2
|
+
import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
|
|
3
|
+
import type { Prisma, Subscription } from '@core/db/prisma-model-type';
|
|
4
4
|
|
|
5
5
|
export class SubscriptionService {
|
|
6
6
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import { Prisma } from '
|
|
4
|
-
import type { Transaction } from '
|
|
5
|
-
import { OrderStatus, TransactionType, PaySupplier, PaymentStatus } from '
|
|
6
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
+
import { Prisma } from '@core/db/prisma-model-type';
|
|
4
|
+
import type { Transaction } from '@core/db/prisma-model-type';
|
|
5
|
+
import { OrderStatus, TransactionType, PaySupplier, PaymentStatus } from '@core/db/constants';
|
|
6
|
+
import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
|
|
7
7
|
|
|
8
8
|
export class TransactionService {
|
|
9
9
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import type { Prisma } from '
|
|
4
|
-
import type { User } from '
|
|
5
|
-
import { UserStatus } from '
|
|
6
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
+
import type { Prisma } from '@core/db/prisma-model-type';
|
|
4
|
+
import type { User } from '@core/db/prisma-model-type';
|
|
5
|
+
import { UserStatus } from '@core/db/constants';
|
|
6
|
+
import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
|
|
7
7
|
|
|
8
8
|
export class UserService {
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import type { Prisma } from '
|
|
4
|
-
import type { UserBackup } from '
|
|
5
|
-
import { checkAndFallbackWithNonTCClient } from '
|
|
3
|
+
import type { Prisma } from '@core/db/prisma-model-type';
|
|
4
|
+
import type { UserBackup } from '@core/db/prisma-model-type';
|
|
5
|
+
import { checkAndFallbackWithNonTCClient, type BackendCorePrismaClient } from '@core/prisma/index';
|
|
6
6
|
|
|
7
7
|
export class UserBackupService {
|
|
8
8
|
|
|
@@ -135,7 +135,7 @@ export class UserBackupService {
|
|
|
135
135
|
throw new Error('No backup data available');
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
const restore = async (client: Prisma.TransactionClient) => {
|
|
138
|
+
const restore = async (client: Prisma.TransactionClient | BackendCorePrismaClient) => {
|
|
139
139
|
const user = await client.user.create({
|
|
140
140
|
data: {
|
|
141
141
|
fingerprintId: backupData.fingerprintId,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import { billingAggregateService } from '
|
|
3
|
+
import { billingAggregateService } from '@core/aggregate/billing.aggregate.service';
|
|
4
4
|
import {
|
|
5
5
|
Apilogger,
|
|
6
6
|
BillingReason,
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
subscriptionService,
|
|
10
10
|
transactionService,
|
|
11
11
|
TransactionType
|
|
12
|
-
} from '
|
|
13
|
-
import { Transaction } from '
|
|
14
|
-
import { oneTimeExpiredDays } from '
|
|
15
|
-
import { getCreditsFromPriceId } from '
|
|
16
|
-
import { fetchPaymentId, getStripe } from '
|
|
12
|
+
} from '@core/db/index';
|
|
13
|
+
import { Transaction } from '@core/db/prisma-model-type';
|
|
14
|
+
import { oneTimeExpiredDays } from '@core/lib/credit-init';
|
|
15
|
+
import { getCreditsFromPriceId } from '@core/lib/money-price-config';
|
|
16
|
+
import { fetchPaymentId, getStripe } from '@core/lib/stripe-config';
|
|
17
17
|
import Stripe from 'stripe';
|
|
18
18
|
import { viewLocalTime } from '@windrun-huaiin/lib/utils';
|
|
19
19
|
|
package/dist/lib/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './money-price-config';
|
|
2
|
-
export * from './money-price-helper';
|
|
3
|
-
export * from './fingerprint-config';
|
|
4
|
-
export * from './credit-init';
|
|
5
|
-
export * from './stripe-config';
|
|
6
|
-
export * from './upstash-config';
|
|
7
|
-
export * from './upstash';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
package/dist/lib/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { getActiveProviderConfig, getCreditsFromPriceId, getPriceConfig, moneyPriceConfig } from './money-price-config.mjs';
|
|
2
|
-
export { getMoneyPriceInitUserContext } from './money-price-helper.mjs';
|
|
3
|
-
export { fingerprintConfig } from './fingerprint-config.mjs';
|
|
4
|
-
export { creditsConfig, freeAmount, freeExpiredDays, freeRegisterAmount, oneTimeExpiredDays } from './credit-init.mjs';
|
|
5
|
-
export { ActiveSubscriptionExistsError, cancelSubscription, createCheckoutSession, createCustomerPortalSession, createOrGetCustomer, fetchPaymentId, getStripe, updateSubscription, validateStripeWebhook } from './stripe-config.mjs';
|
|
6
|
-
export { getPrefixedQstashQueueName, getPrefixedRedisKey, getPrefixedRedisKeys, getQstash, getQstashNamePrefix, getRedis, withQstash, withRedis } from './upstash-config.mjs';
|
|
7
|
-
export { acquireLock, releaseLock, withLock } from './upstash/redis-lock.mjs';
|
|
8
|
-
export { getTargetLikeCount, getUserLikedTargets, isTargetLiked, likeTarget, unlikeTarget } from './upstash/redis-like.mjs';
|
|
9
|
-
export { addFavorite, getFavoriteCount, getUserFavorites, isFavorited, removeFavorite } from './upstash/redis-favorite.mjs';
|
|
10
|
-
export { getCounter, getUniqueCounter, incrCounter, incrUniqueCounter } from './upstash/redis-counter.mjs';
|
|
11
|
-
export { del, deleteHashField, deleteKey, exists, expire, getHashAll, getHashField, getHashJson, getJson, getString, hexists, hkeys, hlen, hmget, hmset, listLength, mget, mgetJson, mset, msetJson, pipeline, popList, pushList, rangeList, sadd, scard, setHashField, setHashJson, setJson, setString, sismember, smembers, srem, ttl } from './upstash/redis-structures.mjs';
|
|
12
|
-
export { cancelSchedule, publishBroadcastMessage, publishDelayedMessage, publishFIFOQueueMessage, publishMessage, scheduleMessage, verifyQstashSignature } from './upstash/qstash.mjs';
|
package/src/lib/index.ts
DELETED